2 * Copyright (c) 2008-2011 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 <linux/slab.h>
19 #include <linux/module.h>
20 #include <linux/time.h>
21 #include <linux/bitops.h>
22 #include <asm/unaligned.h>
26 #include "ar9003_mac.h"
27 #include "ar9003_mci.h"
28 #include "ar9003_phy.h"
31 static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
33 MODULE_AUTHOR("Atheros Communications");
34 MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
35 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
36 MODULE_LICENSE("Dual BSD/GPL");
38 static void ath9k_hw_set_clockrate(struct ath_hw *ah)
40 struct ath_common *common = ath9k_hw_common(ah);
41 struct ath9k_channel *chan = ah->curchan;
42 unsigned int clockrate;
44 /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
45 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
47 else if (!chan) /* should really check for CCK instead */
48 clockrate = ATH9K_CLOCK_RATE_CCK;
49 else if (IS_CHAN_2GHZ(chan))
50 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
51 else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
52 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
54 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
57 if (IS_CHAN_HT40(chan))
59 if (IS_CHAN_HALF_RATE(chan))
61 if (IS_CHAN_QUARTER_RATE(chan))
65 common->clockrate = clockrate;
68 static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
70 struct ath_common *common = ath9k_hw_common(ah);
72 return usecs * common->clockrate;
75 bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
79 BUG_ON(timeout < AH_TIME_QUANTUM);
81 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
82 if ((REG_READ(ah, reg) & mask) == val)
85 udelay(AH_TIME_QUANTUM);
88 ath_dbg(ath9k_hw_common(ah), ANY,
89 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
90 timeout, reg, REG_READ(ah, reg), mask, val);
94 EXPORT_SYMBOL(ath9k_hw_wait);
96 void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
101 if (IS_CHAN_HALF_RATE(chan))
103 else if (IS_CHAN_QUARTER_RATE(chan))
106 udelay(hw_delay + BASE_ACTIVATE_DELAY);
109 void ath9k_hw_write_array(struct ath_hw *ah, const struct ar5416IniArray *array,
110 int column, unsigned int *writecnt)
114 ENABLE_REGWRITE_BUFFER(ah);
115 for (r = 0; r < array->ia_rows; r++) {
116 REG_WRITE(ah, INI_RA(array, r, 0),
117 INI_RA(array, r, column));
120 REGWRITE_BUFFER_FLUSH(ah);
123 u32 ath9k_hw_reverse_bits(u32 val, u32 n)
128 for (i = 0, retval = 0; i < n; i++) {
129 retval = (retval << 1) | (val & 1);
135 u16 ath9k_hw_computetxtime(struct ath_hw *ah,
137 u32 frameLen, u16 rateix,
140 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
146 case WLAN_RC_PHY_CCK:
147 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
150 numBits = frameLen << 3;
151 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
153 case WLAN_RC_PHY_OFDM:
154 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
155 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
156 numBits = OFDM_PLCP_BITS + (frameLen << 3);
157 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
158 txTime = OFDM_SIFS_TIME_QUARTER
159 + OFDM_PREAMBLE_TIME_QUARTER
160 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
161 } else if (ah->curchan &&
162 IS_CHAN_HALF_RATE(ah->curchan)) {
163 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
164 numBits = OFDM_PLCP_BITS + (frameLen << 3);
165 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
166 txTime = OFDM_SIFS_TIME_HALF +
167 OFDM_PREAMBLE_TIME_HALF
168 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
170 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
171 numBits = OFDM_PLCP_BITS + (frameLen << 3);
172 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
173 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
174 + (numSymbols * OFDM_SYMBOL_TIME);
178 ath_err(ath9k_hw_common(ah),
179 "Unknown phy %u (rate ix %u)\n", phy, rateix);
186 EXPORT_SYMBOL(ath9k_hw_computetxtime);
188 void ath9k_hw_get_channel_centers(struct ath_hw *ah,
189 struct ath9k_channel *chan,
190 struct chan_centers *centers)
194 if (!IS_CHAN_HT40(chan)) {
195 centers->ctl_center = centers->ext_center =
196 centers->synth_center = chan->channel;
200 if (IS_CHAN_HT40PLUS(chan)) {
201 centers->synth_center =
202 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
205 centers->synth_center =
206 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
210 centers->ctl_center =
211 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
212 /* 25 MHz spacing is supported by hw but not on upper layers */
213 centers->ext_center =
214 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
221 static void ath9k_hw_read_revisions(struct ath_hw *ah)
225 if (ah->get_mac_revision)
226 ah->hw_version.macRev = ah->get_mac_revision();
228 switch (ah->hw_version.devid) {
229 case AR5416_AR9100_DEVID:
230 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
232 case AR9300_DEVID_AR9330:
233 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
234 if (!ah->get_mac_revision) {
235 val = REG_READ(ah, AR_SREV);
236 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
239 case AR9300_DEVID_AR9340:
240 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
242 case AR9300_DEVID_QCA955X:
243 ah->hw_version.macVersion = AR_SREV_VERSION_9550;
245 case AR9300_DEVID_AR953X:
246 ah->hw_version.macVersion = AR_SREV_VERSION_9531;
250 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
253 val = REG_READ(ah, AR_SREV);
254 ah->hw_version.macVersion =
255 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
256 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
258 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
259 ah->is_pciexpress = true;
261 ah->is_pciexpress = (val &
262 AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
264 if (!AR_SREV_9100(ah))
265 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
267 ah->hw_version.macRev = val & AR_SREV_REVISION;
269 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
270 ah->is_pciexpress = true;
274 /************************************/
275 /* HW Attach, Detach, Init Routines */
276 /************************************/
278 static void ath9k_hw_disablepcie(struct ath_hw *ah)
280 if (!AR_SREV_5416(ah))
283 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
284 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
285 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
286 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
287 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
293 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
296 /* This should work for all families including legacy */
297 static bool ath9k_hw_chip_test(struct ath_hw *ah)
299 struct ath_common *common = ath9k_hw_common(ah);
300 u32 regAddr[2] = { AR_STA_ID0 };
302 static const u32 patternData[4] = {
303 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
307 if (!AR_SREV_9300_20_OR_LATER(ah)) {
309 regAddr[1] = AR_PHY_BASE + (8 << 2);
313 for (i = 0; i < loop_max; i++) {
314 u32 addr = regAddr[i];
317 regHold[i] = REG_READ(ah, addr);
318 for (j = 0; j < 0x100; j++) {
319 wrData = (j << 16) | j;
320 REG_WRITE(ah, addr, wrData);
321 rdData = REG_READ(ah, addr);
322 if (rdData != wrData) {
324 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
325 addr, wrData, rdData);
329 for (j = 0; j < 4; j++) {
330 wrData = patternData[j];
331 REG_WRITE(ah, addr, wrData);
332 rdData = REG_READ(ah, addr);
333 if (wrData != rdData) {
335 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
336 addr, wrData, rdData);
340 REG_WRITE(ah, regAddr[i], regHold[i]);
347 static void ath9k_hw_init_config(struct ath_hw *ah)
349 struct ath_common *common = ath9k_hw_common(ah);
351 ah->config.dma_beacon_response_time = 1;
352 ah->config.sw_beacon_response_time = 6;
353 ah->config.cwm_ignore_extcca = 0;
354 ah->config.analog_shiftreg = 1;
356 ah->config.rx_intr_mitigation = true;
358 if (AR_SREV_9300_20_OR_LATER(ah)) {
359 ah->config.rimt_last = 500;
360 ah->config.rimt_first = 2000;
362 ah->config.rimt_last = 250;
363 ah->config.rimt_first = 700;
367 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
368 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
369 * This means we use it for all AR5416 devices, and the few
370 * minor PCI AR9280 devices out there.
372 * Serialization is required because these devices do not handle
373 * well the case of two concurrent reads/writes due to the latency
374 * involved. During one read/write another read/write can be issued
375 * on another CPU while the previous read/write may still be working
376 * on our hardware, if we hit this case the hardware poops in a loop.
377 * We prevent this by serializing reads and writes.
379 * This issue is not present on PCI-Express devices or pre-AR5416
380 * devices (legacy, 802.11abg).
382 if (num_possible_cpus() > 1)
383 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
385 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
386 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
387 ((AR_SREV_9160(ah) || AR_SREV_9280(ah) || AR_SREV_9287(ah)) &&
388 !ah->is_pciexpress)) {
389 ah->config.serialize_regmode = SER_REG_MODE_ON;
391 ah->config.serialize_regmode = SER_REG_MODE_OFF;
395 ath_dbg(common, RESET, "serialize_regmode is %d\n",
396 ah->config.serialize_regmode);
398 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
399 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
401 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
404 static void ath9k_hw_init_defaults(struct ath_hw *ah)
406 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
408 regulatory->country_code = CTRY_DEFAULT;
409 regulatory->power_limit = MAX_RATE_POWER;
411 ah->hw_version.magic = AR5416_MAGIC;
412 ah->hw_version.subvendorid = 0;
414 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE |
415 AR_STA_ID1_MCAST_KSRCH;
416 if (AR_SREV_9100(ah))
417 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
419 ah->slottime = ATH9K_SLOT_TIME_9;
420 ah->globaltxtimeout = (u32) -1;
421 ah->power_mode = ATH9K_PM_UNDEFINED;
422 ah->htc_reset_init = true;
424 ah->ani_function = ATH9K_ANI_ALL;
425 if (!AR_SREV_9300_20_OR_LATER(ah))
426 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
428 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
429 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
431 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
434 static int ath9k_hw_init_macaddr(struct ath_hw *ah)
436 struct ath_common *common = ath9k_hw_common(ah);
440 static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
443 for (i = 0; i < 3; i++) {
444 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
446 common->macaddr[2 * i] = eeval >> 8;
447 common->macaddr[2 * i + 1] = eeval & 0xff;
449 if (sum == 0 || sum == 0xffff * 3)
450 return -EADDRNOTAVAIL;
455 static int ath9k_hw_post_init(struct ath_hw *ah)
457 struct ath_common *common = ath9k_hw_common(ah);
460 if (common->bus_ops->ath_bus_type != ATH_USB) {
461 if (!ath9k_hw_chip_test(ah))
465 if (!AR_SREV_9300_20_OR_LATER(ah)) {
466 ecode = ar9002_hw_rf_claim(ah);
471 ecode = ath9k_hw_eeprom_init(ah);
475 ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
476 ah->eep_ops->get_eeprom_ver(ah),
477 ah->eep_ops->get_eeprom_rev(ah));
479 ath9k_hw_ani_init(ah);
482 * EEPROM needs to be initialized before we do this.
483 * This is required for regulatory compliance.
485 if (AR_SREV_9300_20_OR_LATER(ah)) {
486 u16 regdmn = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
487 if ((regdmn & 0xF0) == CTL_FCC) {
488 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_2GHZ;
489 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_5GHZ;
496 static int ath9k_hw_attach_ops(struct ath_hw *ah)
498 if (!AR_SREV_9300_20_OR_LATER(ah))
499 return ar9002_hw_attach_ops(ah);
501 ar9003_hw_attach_ops(ah);
505 /* Called for all hardware families */
506 static int __ath9k_hw_init(struct ath_hw *ah)
508 struct ath_common *common = ath9k_hw_common(ah);
511 ath9k_hw_read_revisions(ah);
513 switch (ah->hw_version.macVersion) {
514 case AR_SREV_VERSION_5416_PCI:
515 case AR_SREV_VERSION_5416_PCIE:
516 case AR_SREV_VERSION_9160:
517 case AR_SREV_VERSION_9100:
518 case AR_SREV_VERSION_9280:
519 case AR_SREV_VERSION_9285:
520 case AR_SREV_VERSION_9287:
521 case AR_SREV_VERSION_9271:
522 case AR_SREV_VERSION_9300:
523 case AR_SREV_VERSION_9330:
524 case AR_SREV_VERSION_9485:
525 case AR_SREV_VERSION_9340:
526 case AR_SREV_VERSION_9462:
527 case AR_SREV_VERSION_9550:
528 case AR_SREV_VERSION_9565:
529 case AR_SREV_VERSION_9531:
533 "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
534 ah->hw_version.macVersion, ah->hw_version.macRev);
539 * Read back AR_WA into a permanent copy and set bits 14 and 17.
540 * We need to do this to avoid RMW of this register. We cannot
541 * read the reg when chip is asleep.
543 if (AR_SREV_9300_20_OR_LATER(ah)) {
544 ah->WARegVal = REG_READ(ah, AR_WA);
545 ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
546 AR_WA_ASPM_TIMER_BASED_DISABLE);
549 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
550 ath_err(common, "Couldn't reset chip\n");
554 if (AR_SREV_9565(ah)) {
555 ah->WARegVal |= AR_WA_BIT22;
556 REG_WRITE(ah, AR_WA, ah->WARegVal);
559 ath9k_hw_init_defaults(ah);
560 ath9k_hw_init_config(ah);
562 r = ath9k_hw_attach_ops(ah);
566 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
567 ath_err(common, "Couldn't wakeup chip\n");
571 if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
572 AR_SREV_9330(ah) || AR_SREV_9550(ah))
573 ah->is_pciexpress = false;
575 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
576 ath9k_hw_init_cal_settings(ah);
578 if (!ah->is_pciexpress)
579 ath9k_hw_disablepcie(ah);
581 r = ath9k_hw_post_init(ah);
585 ath9k_hw_init_mode_gain_regs(ah);
586 r = ath9k_hw_fill_cap_info(ah);
590 r = ath9k_hw_init_macaddr(ah);
592 ath_err(common, "Failed to initialize MAC address\n");
596 ath9k_hw_init_hang_checks(ah);
598 common->state = ATH_HW_INITIALIZED;
603 int ath9k_hw_init(struct ath_hw *ah)
606 struct ath_common *common = ath9k_hw_common(ah);
608 /* These are all the AR5008/AR9001/AR9002/AR9003 hardware family of chipsets */
609 switch (ah->hw_version.devid) {
610 case AR5416_DEVID_PCI:
611 case AR5416_DEVID_PCIE:
612 case AR5416_AR9100_DEVID:
613 case AR9160_DEVID_PCI:
614 case AR9280_DEVID_PCI:
615 case AR9280_DEVID_PCIE:
616 case AR9285_DEVID_PCIE:
617 case AR9287_DEVID_PCI:
618 case AR9287_DEVID_PCIE:
619 case AR2427_DEVID_PCIE:
620 case AR9300_DEVID_PCIE:
621 case AR9300_DEVID_AR9485_PCIE:
622 case AR9300_DEVID_AR9330:
623 case AR9300_DEVID_AR9340:
624 case AR9300_DEVID_QCA955X:
625 case AR9300_DEVID_AR9580:
626 case AR9300_DEVID_AR9462:
627 case AR9485_DEVID_AR1111:
628 case AR9300_DEVID_AR9565:
629 case AR9300_DEVID_AR953X:
632 if (common->bus_ops->ath_bus_type == ATH_USB)
634 ath_err(common, "Hardware device ID 0x%04x not supported\n",
635 ah->hw_version.devid);
639 ret = __ath9k_hw_init(ah);
642 "Unable to initialize hardware; initialization status: %d\n",
651 EXPORT_SYMBOL(ath9k_hw_init);
653 static void ath9k_hw_init_qos(struct ath_hw *ah)
655 ENABLE_REGWRITE_BUFFER(ah);
657 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
658 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
660 REG_WRITE(ah, AR_QOS_NO_ACK,
661 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
662 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
663 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
665 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
666 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
667 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
668 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
669 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
671 REGWRITE_BUFFER_FLUSH(ah);
674 u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
676 struct ath_common *common = ath9k_hw_common(ah);
679 REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
681 REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
683 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) {
687 if (WARN_ON_ONCE(i >= 100)) {
688 ath_err(common, "PLL4 meaurement not done\n");
695 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
697 EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
699 static void ath9k_hw_init_pll(struct ath_hw *ah,
700 struct ath9k_channel *chan)
704 if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
705 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
706 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
707 AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
708 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
709 AR_CH0_DPLL2_KD, 0x40);
710 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
711 AR_CH0_DPLL2_KI, 0x4);
713 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
714 AR_CH0_BB_DPLL1_REFDIV, 0x5);
715 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
716 AR_CH0_BB_DPLL1_NINI, 0x58);
717 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
718 AR_CH0_BB_DPLL1_NFRAC, 0x0);
720 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
721 AR_CH0_BB_DPLL2_OUTDIV, 0x1);
722 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
723 AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
724 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
725 AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
727 /* program BB PLL phase_shift to 0x6 */
728 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
729 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
731 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
732 AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
734 } else if (AR_SREV_9330(ah)) {
735 u32 ddr_dpll2, pll_control2, kd;
737 if (ah->is_clk_25mhz) {
738 ddr_dpll2 = 0x18e82f01;
739 pll_control2 = 0xe04a3d;
742 ddr_dpll2 = 0x19e82f01;
743 pll_control2 = 0x886666;
747 /* program DDR PLL ki and kd value */
748 REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
750 /* program DDR PLL phase_shift */
751 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
752 AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
754 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
757 /* program refdiv, nint, frac to RTC register */
758 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
760 /* program BB PLL kd and ki value */
761 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
762 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
764 /* program BB PLL phase_shift */
765 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
766 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
767 } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah)) {
768 u32 regval, pll2_divint, pll2_divfrac, refdiv;
770 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
773 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
776 if (ah->is_clk_25mhz) {
777 if (AR_SREV_9531(ah)) {
779 pll2_divfrac = 0xa3d2;
783 pll2_divfrac = 0x1eb85;
787 if (AR_SREV_9340(ah)) {
794 AR_SREV_9531(ah) ? 0x26665 : 0x26666;
799 regval = REG_READ(ah, AR_PHY_PLL_MODE);
800 if (AR_SREV_9531(ah))
801 regval |= (0x1 << 22);
803 regval |= (0x1 << 16);
804 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
807 REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
808 (pll2_divint << 18) | pll2_divfrac);
811 regval = REG_READ(ah, AR_PHY_PLL_MODE);
812 if (AR_SREV_9340(ah))
813 regval = (regval & 0x80071fff) |
818 else if (AR_SREV_9531(ah))
819 regval = (regval & 0x01c00fff) |
826 regval = (regval & 0x80071fff) |
831 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
833 if (AR_SREV_9531(ah))
834 REG_WRITE(ah, AR_PHY_PLL_MODE,
835 REG_READ(ah, AR_PHY_PLL_MODE) & 0xffbfffff);
837 REG_WRITE(ah, AR_PHY_PLL_MODE,
838 REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
843 pll = ath9k_hw_compute_pll_control(ah, chan);
844 if (AR_SREV_9565(ah))
846 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
848 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
852 /* Switch the core clock for ar9271 to 117Mhz */
853 if (AR_SREV_9271(ah)) {
855 REG_WRITE(ah, 0x50040, 0x304);
858 udelay(RTC_PLL_SETTLE_DELAY);
860 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
862 if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
863 if (ah->is_clk_25mhz) {
864 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
865 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
866 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
868 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
869 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
870 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
876 static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
877 enum nl80211_iftype opmode)
879 u32 sync_default = AR_INTR_SYNC_DEFAULT;
880 u32 imr_reg = AR_IMR_TXERR |
886 if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah))
887 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
889 if (AR_SREV_9300_20_OR_LATER(ah)) {
890 imr_reg |= AR_IMR_RXOK_HP;
891 if (ah->config.rx_intr_mitigation)
892 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
894 imr_reg |= AR_IMR_RXOK_LP;
897 if (ah->config.rx_intr_mitigation)
898 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
900 imr_reg |= AR_IMR_RXOK;
903 if (ah->config.tx_intr_mitigation)
904 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
906 imr_reg |= AR_IMR_TXOK;
908 ENABLE_REGWRITE_BUFFER(ah);
910 REG_WRITE(ah, AR_IMR, imr_reg);
911 ah->imrs2_reg |= AR_IMR_S2_GTT;
912 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
914 if (!AR_SREV_9100(ah)) {
915 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
916 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
917 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
920 REGWRITE_BUFFER_FLUSH(ah);
922 if (AR_SREV_9300_20_OR_LATER(ah)) {
923 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
924 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
925 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
926 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
930 static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
932 u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
933 val = min(val, (u32) 0xFFFF);
934 REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
937 void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
939 u32 val = ath9k_hw_mac_to_clks(ah, us);
940 val = min(val, (u32) 0xFFFF);
941 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
944 void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
946 u32 val = ath9k_hw_mac_to_clks(ah, us);
947 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
948 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
951 void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
953 u32 val = ath9k_hw_mac_to_clks(ah, us);
954 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
955 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
958 static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
961 ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
963 ah->globaltxtimeout = (u32) -1;
966 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
967 ah->globaltxtimeout = tu;
972 void ath9k_hw_init_global_settings(struct ath_hw *ah)
974 struct ath_common *common = ath9k_hw_common(ah);
975 const struct ath9k_channel *chan = ah->curchan;
976 int acktimeout, ctstimeout, ack_offset = 0;
979 int rx_lat = 0, tx_lat = 0, eifs = 0;
982 ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
988 if (ah->misc_mode != 0)
989 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
991 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
997 if (IS_CHAN_5GHZ(chan))
1002 if (IS_CHAN_HALF_RATE(chan)) {
1006 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1012 } else if (IS_CHAN_QUARTER_RATE(chan)) {
1014 rx_lat = (rx_lat * 4) - 1;
1016 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1023 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1024 eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
1025 reg = AR_USEC_ASYNC_FIFO;
1027 eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
1029 reg = REG_READ(ah, AR_USEC);
1031 rx_lat = MS(reg, AR_USEC_RX_LAT);
1032 tx_lat = MS(reg, AR_USEC_TX_LAT);
1034 slottime = ah->slottime;
1037 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1038 slottime += 3 * ah->coverage_class;
1039 acktimeout = slottime + sifstime + ack_offset;
1040 ctstimeout = acktimeout;
1043 * Workaround for early ACK timeouts, add an offset to match the
1044 * initval's 64us ack timeout value. Use 48us for the CTS timeout.
1045 * This was initially only meant to work around an issue with delayed
1046 * BA frames in some implementations, but it has been found to fix ACK
1047 * timeout issues in other cases as well.
1049 if (IS_CHAN_2GHZ(chan) &&
1050 !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
1051 acktimeout += 64 - sifstime - ah->slottime;
1052 ctstimeout += 48 - sifstime - ah->slottime;
1055 if (ah->dynack.enabled) {
1056 acktimeout = ah->dynack.ackto;
1057 ctstimeout = acktimeout;
1058 slottime = (acktimeout - 3) / 2;
1060 ah->dynack.ackto = acktimeout;
1063 ath9k_hw_set_sifs_time(ah, sifstime);
1064 ath9k_hw_setslottime(ah, slottime);
1065 ath9k_hw_set_ack_timeout(ah, acktimeout);
1066 ath9k_hw_set_cts_timeout(ah, ctstimeout);
1067 if (ah->globaltxtimeout != (u32) -1)
1068 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
1070 REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
1071 REG_RMW(ah, AR_USEC,
1072 (common->clockrate - 1) |
1073 SM(rx_lat, AR_USEC_RX_LAT) |
1074 SM(tx_lat, AR_USEC_TX_LAT),
1075 AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
1078 EXPORT_SYMBOL(ath9k_hw_init_global_settings);
1080 void ath9k_hw_deinit(struct ath_hw *ah)
1082 struct ath_common *common = ath9k_hw_common(ah);
1084 if (common->state < ATH_HW_INITIALIZED)
1087 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1089 EXPORT_SYMBOL(ath9k_hw_deinit);
1095 u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
1097 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1099 if (IS_CHAN_2GHZ(chan))
1107 /****************************************/
1108 /* Reset and Channel Switching Routines */
1109 /****************************************/
1111 static inline void ath9k_hw_set_dma(struct ath_hw *ah)
1113 struct ath_common *common = ath9k_hw_common(ah);
1116 ENABLE_REGWRITE_BUFFER(ah);
1119 * set AHB_MODE not to do cacheline prefetches
1121 if (!AR_SREV_9300_20_OR_LATER(ah))
1122 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
1125 * let mac dma reads be in 128 byte chunks
1127 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
1129 REGWRITE_BUFFER_FLUSH(ah);
1132 * Restore TX Trigger Level to its pre-reset value.
1133 * The initial value depends on whether aggregation is enabled, and is
1134 * adjusted whenever underruns are detected.
1136 if (!AR_SREV_9300_20_OR_LATER(ah))
1137 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
1139 ENABLE_REGWRITE_BUFFER(ah);
1142 * let mac dma writes be in 128 byte chunks
1144 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
1147 * Setup receive FIFO threshold to hold off TX activities
1149 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1151 if (AR_SREV_9300_20_OR_LATER(ah)) {
1152 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
1153 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
1155 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
1156 ah->caps.rx_status_len);
1160 * reduce the number of usable entries in PCU TXBUF to avoid
1161 * wrap around issues.
1163 if (AR_SREV_9285(ah)) {
1164 /* For AR9285 the number of Fifos are reduced to half.
1165 * So set the usable tx buf size also to half to
1166 * avoid data/delimiter underruns
1168 txbuf_size = AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE;
1169 } else if (AR_SREV_9340_13_OR_LATER(ah)) {
1170 /* Uses fewer entries for AR934x v1.3+ to prevent rx overruns */
1171 txbuf_size = AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE;
1173 txbuf_size = AR_PCU_TXBUF_CTRL_USABLE_SIZE;
1176 if (!AR_SREV_9271(ah))
1177 REG_WRITE(ah, AR_PCU_TXBUF_CTRL, txbuf_size);
1179 REGWRITE_BUFFER_FLUSH(ah);
1181 if (AR_SREV_9300_20_OR_LATER(ah))
1182 ath9k_hw_reset_txstatus_ring(ah);
1185 static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
1187 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1188 u32 set = AR_STA_ID1_KSRCH_MODE;
1191 case NL80211_IFTYPE_ADHOC:
1192 set |= AR_STA_ID1_ADHOC;
1193 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1195 case NL80211_IFTYPE_MESH_POINT:
1196 case NL80211_IFTYPE_AP:
1197 set |= AR_STA_ID1_STA_AP;
1199 case NL80211_IFTYPE_STATION:
1200 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1203 if (!ah->is_monitoring)
1207 REG_RMW(ah, AR_STA_ID1, set, mask);
1210 void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1211 u32 *coef_mantissa, u32 *coef_exponent)
1213 u32 coef_exp, coef_man;
1215 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1216 if ((coef_scaled >> coef_exp) & 0x1)
1219 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1221 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1223 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1224 *coef_exponent = coef_exp - 16;
1228 * call external reset function to reset WMAC if:
1229 * - doing a cold reset
1230 * - we have pending frames in the TX queues.
1232 static bool ath9k_hw_ar9330_reset_war(struct ath_hw *ah, int type)
1236 for (i = 0; i < AR_NUM_QCU; i++) {
1237 npend = ath9k_hw_numtxpending(ah, i);
1242 if (ah->external_reset &&
1243 (npend || type == ATH9K_RESET_COLD)) {
1246 ath_dbg(ath9k_hw_common(ah), RESET,
1247 "reset MAC via external reset\n");
1249 reset_err = ah->external_reset();
1251 ath_err(ath9k_hw_common(ah),
1252 "External reset failed, err=%d\n",
1257 REG_WRITE(ah, AR_RTC_RESET, 1);
1263 static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
1268 if (AR_SREV_9100(ah)) {
1269 REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
1270 AR_RTC_DERIVED_CLK_PERIOD, 1);
1271 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1274 ENABLE_REGWRITE_BUFFER(ah);
1276 if (AR_SREV_9300_20_OR_LATER(ah)) {
1277 REG_WRITE(ah, AR_WA, ah->WARegVal);
1281 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1282 AR_RTC_FORCE_WAKE_ON_INT);
1284 if (AR_SREV_9100(ah)) {
1285 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1286 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1288 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1289 if (AR_SREV_9340(ah))
1290 tmpReg &= AR9340_INTR_SYNC_LOCAL_TIMEOUT;
1292 tmpReg &= AR_INTR_SYNC_LOCAL_TIMEOUT |
1293 AR_INTR_SYNC_RADM_CPL_TIMEOUT;
1297 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1300 if (!AR_SREV_9300_20_OR_LATER(ah))
1302 REG_WRITE(ah, AR_RC, val);
1304 } else if (!AR_SREV_9300_20_OR_LATER(ah))
1305 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1307 rst_flags = AR_RTC_RC_MAC_WARM;
1308 if (type == ATH9K_RESET_COLD)
1309 rst_flags |= AR_RTC_RC_MAC_COLD;
1312 if (AR_SREV_9330(ah)) {
1313 if (!ath9k_hw_ar9330_reset_war(ah, type))
1317 if (ath9k_hw_mci_is_enabled(ah))
1318 ar9003_mci_check_gpm_offset(ah);
1320 REG_WRITE(ah, AR_RTC_RC, rst_flags);
1322 REGWRITE_BUFFER_FLUSH(ah);
1324 if (AR_SREV_9300_20_OR_LATER(ah))
1326 else if (AR_SREV_9100(ah))
1331 REG_WRITE(ah, AR_RTC_RC, 0);
1332 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
1333 ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
1337 if (!AR_SREV_9100(ah))
1338 REG_WRITE(ah, AR_RC, 0);
1340 if (AR_SREV_9100(ah))
1346 static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
1348 ENABLE_REGWRITE_BUFFER(ah);
1350 if (AR_SREV_9300_20_OR_LATER(ah)) {
1351 REG_WRITE(ah, AR_WA, ah->WARegVal);
1355 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1356 AR_RTC_FORCE_WAKE_ON_INT);
1358 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
1359 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1361 REG_WRITE(ah, AR_RTC_RESET, 0);
1363 REGWRITE_BUFFER_FLUSH(ah);
1367 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
1368 REG_WRITE(ah, AR_RC, 0);
1370 REG_WRITE(ah, AR_RTC_RESET, 1);
1372 if (!ath9k_hw_wait(ah,
1377 ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
1381 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1384 static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
1388 if (AR_SREV_9300_20_OR_LATER(ah)) {
1389 REG_WRITE(ah, AR_WA, ah->WARegVal);
1393 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1394 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1396 if (!ah->reset_power_on)
1397 type = ATH9K_RESET_POWER_ON;
1400 case ATH9K_RESET_POWER_ON:
1401 ret = ath9k_hw_set_reset_power_on(ah);
1403 ah->reset_power_on = true;
1405 case ATH9K_RESET_WARM:
1406 case ATH9K_RESET_COLD:
1407 ret = ath9k_hw_set_reset(ah, type);
1416 static bool ath9k_hw_chip_reset(struct ath_hw *ah,
1417 struct ath9k_channel *chan)
1419 int reset_type = ATH9K_RESET_WARM;
1421 if (AR_SREV_9280(ah)) {
1422 if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1423 reset_type = ATH9K_RESET_POWER_ON;
1425 reset_type = ATH9K_RESET_COLD;
1426 } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
1427 (REG_READ(ah, AR_CR) & AR_CR_RXE))
1428 reset_type = ATH9K_RESET_COLD;
1430 if (!ath9k_hw_set_reset_reg(ah, reset_type))
1433 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1436 ah->chip_fullsleep = false;
1438 if (AR_SREV_9330(ah))
1439 ar9003_hw_internal_regulator_apply(ah);
1440 ath9k_hw_init_pll(ah, chan);
1445 static bool ath9k_hw_channel_change(struct ath_hw *ah,
1446 struct ath9k_channel *chan)
1448 struct ath_common *common = ath9k_hw_common(ah);
1449 struct ath9k_hw_capabilities *pCap = &ah->caps;
1450 bool band_switch = false, mode_diff = false;
1451 u8 ini_reloaded = 0;
1455 if (pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) {
1456 u32 flags_diff = chan->channelFlags ^ ah->curchan->channelFlags;
1457 band_switch = !!(flags_diff & CHANNEL_5GHZ);
1458 mode_diff = !!(flags_diff & ~CHANNEL_HT);
1461 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1462 if (ath9k_hw_numtxpending(ah, qnum)) {
1463 ath_dbg(common, QUEUE,
1464 "Transmit frames pending on queue %d\n", qnum);
1469 if (!ath9k_hw_rfbus_req(ah)) {
1470 ath_err(common, "Could not kill baseband RX\n");
1474 if (band_switch || mode_diff) {
1475 ath9k_hw_mark_phy_inactive(ah);
1479 ath9k_hw_init_pll(ah, chan);
1481 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
1482 ath_err(common, "Failed to do fast channel change\n");
1487 ath9k_hw_set_channel_regs(ah, chan);
1489 r = ath9k_hw_rf_set_freq(ah, chan);
1491 ath_err(common, "Failed to set channel\n");
1494 ath9k_hw_set_clockrate(ah);
1495 ath9k_hw_apply_txpower(ah, chan, false);
1497 ath9k_hw_set_delta_slope(ah, chan);
1498 ath9k_hw_spur_mitigate_freq(ah, chan);
1500 if (band_switch || ini_reloaded)
1501 ah->eep_ops->set_board_values(ah, chan);
1503 ath9k_hw_init_bb(ah, chan);
1504 ath9k_hw_rfbus_done(ah);
1506 if (band_switch || ini_reloaded) {
1507 ah->ah_flags |= AH_FASTCC;
1508 ath9k_hw_init_cal(ah, chan);
1509 ah->ah_flags &= ~AH_FASTCC;
1515 static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1517 u32 gpio_mask = ah->gpio_mask;
1520 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1521 if (!(gpio_mask & 1))
1524 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1525 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1529 void ath9k_hw_check_nav(struct ath_hw *ah)
1531 struct ath_common *common = ath9k_hw_common(ah);
1534 val = REG_READ(ah, AR_NAV);
1535 if (val != 0xdeadbeef && val > 0x7fff) {
1536 ath_dbg(common, BSTUCK, "Abnormal NAV: 0x%x\n", val);
1537 REG_WRITE(ah, AR_NAV, 0);
1540 EXPORT_SYMBOL(ath9k_hw_check_nav);
1542 bool ath9k_hw_check_alive(struct ath_hw *ah)
1547 if (AR_SREV_9300(ah))
1548 return !ath9k_hw_detect_mac_hang(ah);
1550 if (AR_SREV_9285_12_OR_LATER(ah))
1553 last_val = REG_READ(ah, AR_OBS_BUS_1);
1555 reg = REG_READ(ah, AR_OBS_BUS_1);
1556 if (reg != last_val)
1561 if ((reg & 0x7E7FFFEF) == 0x00702400)
1564 switch (reg & 0x7E000B00) {
1572 } while (count-- > 0);
1576 EXPORT_SYMBOL(ath9k_hw_check_alive);
1578 static void ath9k_hw_init_mfp(struct ath_hw *ah)
1580 /* Setup MFP options for CCMP */
1581 if (AR_SREV_9280_20_OR_LATER(ah)) {
1582 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1583 * frames when constructing CCMP AAD. */
1584 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1586 ah->sw_mgmt_crypto = false;
1587 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1588 /* Disable hardware crypto for management frames */
1589 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1590 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1591 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1592 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1593 ah->sw_mgmt_crypto = true;
1595 ah->sw_mgmt_crypto = true;
1599 static void ath9k_hw_reset_opmode(struct ath_hw *ah,
1600 u32 macStaId1, u32 saveDefAntenna)
1602 struct ath_common *common = ath9k_hw_common(ah);
1604 ENABLE_REGWRITE_BUFFER(ah);
1606 REG_RMW(ah, AR_STA_ID1, macStaId1
1607 | AR_STA_ID1_RTS_USE_DEF
1608 | ah->sta_id1_defaults,
1609 ~AR_STA_ID1_SADH_MASK);
1610 ath_hw_setbssidmask(common);
1611 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1612 ath9k_hw_write_associd(ah);
1613 REG_WRITE(ah, AR_ISR, ~0);
1614 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1616 REGWRITE_BUFFER_FLUSH(ah);
1618 ath9k_hw_set_operating_mode(ah, ah->opmode);
1621 static void ath9k_hw_init_queues(struct ath_hw *ah)
1625 ENABLE_REGWRITE_BUFFER(ah);
1627 for (i = 0; i < AR_NUM_DCU; i++)
1628 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1630 REGWRITE_BUFFER_FLUSH(ah);
1633 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1634 ath9k_hw_resettxqueue(ah, i);
1638 * For big endian systems turn on swapping for descriptors
1640 static void ath9k_hw_init_desc(struct ath_hw *ah)
1642 struct ath_common *common = ath9k_hw_common(ah);
1644 if (AR_SREV_9100(ah)) {
1646 mask = REG_READ(ah, AR_CFG);
1647 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
1648 ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
1651 mask = INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1652 REG_WRITE(ah, AR_CFG, mask);
1653 ath_dbg(common, RESET, "Setting CFG 0x%x\n",
1654 REG_READ(ah, AR_CFG));
1657 if (common->bus_ops->ath_bus_type == ATH_USB) {
1658 /* Configure AR9271 target WLAN */
1659 if (AR_SREV_9271(ah))
1660 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
1662 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1665 else if (AR_SREV_9330(ah) || AR_SREV_9340(ah) ||
1666 AR_SREV_9550(ah) || AR_SREV_9531(ah))
1667 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
1669 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1675 * Fast channel change:
1676 * (Change synthesizer based on channel freq without resetting chip)
1678 static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
1680 struct ath_common *common = ath9k_hw_common(ah);
1681 struct ath9k_hw_capabilities *pCap = &ah->caps;
1684 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
1687 if (ah->chip_fullsleep)
1693 if (chan->channel == ah->curchan->channel)
1696 if ((ah->curchan->channelFlags | chan->channelFlags) &
1697 (CHANNEL_HALF | CHANNEL_QUARTER))
1701 * If cross-band fcc is not supoprted, bail out if channelFlags differ.
1703 if (!(pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) &&
1704 ((chan->channelFlags ^ ah->curchan->channelFlags) & ~CHANNEL_HT))
1707 if (!ath9k_hw_check_alive(ah))
1711 * For AR9462, make sure that calibration data for
1712 * re-using are present.
1714 if (AR_SREV_9462(ah) && (ah->caldata &&
1715 (!test_bit(TXIQCAL_DONE, &ah->caldata->cal_flags) ||
1716 !test_bit(TXCLCAL_DONE, &ah->caldata->cal_flags) ||
1717 !test_bit(RTT_DONE, &ah->caldata->cal_flags))))
1720 ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
1721 ah->curchan->channel, chan->channel);
1723 ret = ath9k_hw_channel_change(ah, chan);
1727 if (ath9k_hw_mci_is_enabled(ah))
1728 ar9003_mci_2g5g_switch(ah, false);
1730 ath9k_hw_loadnf(ah, ah->curchan);
1731 ath9k_hw_start_nfcal(ah, true);
1733 if (AR_SREV_9271(ah))
1734 ar9002_hw_load_ani_reg(ah, chan);
1741 u32 ath9k_hw_get_tsf_offset(struct timespec *last, struct timespec *cur)
1747 getrawmonotonic(&ts);
1751 usec = cur->tv_sec * 1000000ULL + cur->tv_nsec / 1000;
1752 usec -= last->tv_sec * 1000000ULL + last->tv_nsec / 1000;
1756 EXPORT_SYMBOL(ath9k_hw_get_tsf_offset);
1758 int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1759 struct ath9k_hw_cal_data *caldata, bool fastcc)
1761 struct ath_common *common = ath9k_hw_common(ah);
1768 bool start_mci_reset = false;
1769 bool save_fullsleep = ah->chip_fullsleep;
1771 if (ath9k_hw_mci_is_enabled(ah)) {
1772 start_mci_reset = ar9003_mci_start_reset(ah, chan);
1773 if (start_mci_reset)
1777 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1780 if (ah->curchan && !ah->chip_fullsleep)
1781 ath9k_hw_getnf(ah, ah->curchan);
1783 ah->caldata = caldata;
1784 if (caldata && (chan->channel != caldata->channel ||
1785 chan->channelFlags != caldata->channelFlags)) {
1786 /* Operating channel changed, reset channel calibration data */
1787 memset(caldata, 0, sizeof(*caldata));
1788 ath9k_init_nfcal_hist_buffer(ah, chan);
1789 } else if (caldata) {
1790 clear_bit(PAPRD_PACKET_SENT, &caldata->cal_flags);
1792 ah->noise = ath9k_hw_getchan_noise(ah, chan, chan->noisefloor);
1795 r = ath9k_hw_do_fastcc(ah, chan);
1800 if (ath9k_hw_mci_is_enabled(ah))
1801 ar9003_mci_stop_bt(ah, save_fullsleep);
1803 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1804 if (saveDefAntenna == 0)
1807 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1809 /* Save TSF before chip reset, a cold reset clears it */
1810 tsf = ath9k_hw_gettsf64(ah);
1811 usec = ktime_to_us(ktime_get_raw());
1813 saveLedState = REG_READ(ah, AR_CFG_LED) &
1814 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1815 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1817 ath9k_hw_mark_phy_inactive(ah);
1819 ah->paprd_table_write_done = false;
1821 /* Only required on the first reset */
1822 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1824 AR9271_RESET_POWER_DOWN_CONTROL,
1825 AR9271_RADIO_RF_RST);
1829 if (!ath9k_hw_chip_reset(ah, chan)) {
1830 ath_err(common, "Chip reset failed\n");
1834 /* Only required on the first reset */
1835 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1836 ah->htc_reset_init = false;
1838 AR9271_RESET_POWER_DOWN_CONTROL,
1839 AR9271_GATE_MAC_CTL);
1844 usec = ktime_to_us(ktime_get_raw()) - usec;
1845 ath9k_hw_settsf64(ah, tsf + usec);
1847 if (AR_SREV_9280_20_OR_LATER(ah))
1848 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
1850 if (!AR_SREV_9300_20_OR_LATER(ah))
1851 ar9002_hw_enable_async_fifo(ah);
1853 r = ath9k_hw_process_ini(ah, chan);
1857 ath9k_hw_set_rfmode(ah, chan);
1859 if (ath9k_hw_mci_is_enabled(ah))
1860 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
1863 * Some AR91xx SoC devices frequently fail to accept TSF writes
1864 * right after the chip reset. When that happens, write a new
1865 * value after the initvals have been applied, with an offset
1866 * based on measured time difference
1868 if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
1870 ath9k_hw_settsf64(ah, tsf);
1873 ath9k_hw_init_mfp(ah);
1875 ath9k_hw_set_delta_slope(ah, chan);
1876 ath9k_hw_spur_mitigate_freq(ah, chan);
1877 ah->eep_ops->set_board_values(ah, chan);
1879 ath9k_hw_reset_opmode(ah, macStaId1, saveDefAntenna);
1881 r = ath9k_hw_rf_set_freq(ah, chan);
1885 ath9k_hw_set_clockrate(ah);
1887 ath9k_hw_init_queues(ah);
1888 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
1889 ath9k_hw_ani_cache_ini_regs(ah);
1890 ath9k_hw_init_qos(ah);
1892 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1893 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
1895 ath9k_hw_init_global_settings(ah);
1897 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1898 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1899 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1900 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1901 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1902 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1903 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1906 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
1908 ath9k_hw_set_dma(ah);
1910 if (!ath9k_hw_mci_is_enabled(ah))
1911 REG_WRITE(ah, AR_OBS, 8);
1913 if (ah->config.rx_intr_mitigation) {
1914 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, ah->config.rimt_last);
1915 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, ah->config.rimt_first);
1918 if (ah->config.tx_intr_mitigation) {
1919 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1920 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1923 ath9k_hw_init_bb(ah, chan);
1926 clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
1927 clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
1929 if (!ath9k_hw_init_cal(ah, chan))
1932 if (ath9k_hw_mci_is_enabled(ah) && ar9003_mci_end_reset(ah, chan, caldata))
1935 ENABLE_REGWRITE_BUFFER(ah);
1937 ath9k_hw_restore_chainmask(ah);
1938 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1940 REGWRITE_BUFFER_FLUSH(ah);
1942 ath9k_hw_init_desc(ah);
1944 if (ath9k_hw_btcoex_is_enabled(ah))
1945 ath9k_hw_btcoex_enable(ah);
1947 if (ath9k_hw_mci_is_enabled(ah))
1948 ar9003_mci_check_bt(ah);
1950 ath9k_hw_loadnf(ah, chan);
1951 ath9k_hw_start_nfcal(ah, true);
1953 if (AR_SREV_9300_20_OR_LATER(ah))
1954 ar9003_hw_bb_watchdog_config(ah);
1956 if (ah->config.hw_hang_checks & HW_PHYRESTART_CLC_WAR)
1957 ar9003_hw_disable_phy_restart(ah);
1959 ath9k_hw_apply_gpio_override(ah);
1961 if (AR_SREV_9565(ah) && common->bt_ant_diversity)
1962 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON);
1964 if (ah->hw->conf.radar_enabled) {
1965 /* set HW specific DFS configuration */
1966 ah->radar_conf.ext_channel = IS_CHAN_HT40(chan);
1967 ath9k_hw_set_radar_params(ah);
1972 EXPORT_SYMBOL(ath9k_hw_reset);
1974 /******************************/
1975 /* Power Management (Chipset) */
1976 /******************************/
1979 * Notify Power Mgt is disabled in self-generated frames.
1980 * If requested, force chip to sleep.
1982 static void ath9k_set_power_sleep(struct ath_hw *ah)
1984 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1986 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
1987 REG_CLR_BIT(ah, AR_TIMER_MODE, 0xff);
1988 REG_CLR_BIT(ah, AR_NDP2_TIMER_MODE, 0xff);
1989 REG_CLR_BIT(ah, AR_SLP32_INC, 0xfffff);
1990 /* xxx Required for WLAN only case ? */
1991 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
1996 * Clear the RTC force wake bit to allow the
1997 * mac to go to sleep.
1999 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
2001 if (ath9k_hw_mci_is_enabled(ah))
2004 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
2005 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
2007 /* Shutdown chip. Active low */
2008 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
2009 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
2013 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
2014 if (AR_SREV_9300_20_OR_LATER(ah))
2015 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
2019 * Notify Power Management is enabled in self-generating
2020 * frames. If request, set power mode of chip to
2021 * auto/normal. Duration in units of 128us (1/8 TU).
2023 static void ath9k_set_power_network_sleep(struct ath_hw *ah)
2025 struct ath9k_hw_capabilities *pCap = &ah->caps;
2027 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2029 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
2030 /* Set WakeOnInterrupt bit; clear ForceWake bit */
2031 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
2032 AR_RTC_FORCE_WAKE_ON_INT);
2035 /* When chip goes into network sleep, it could be waken
2036 * up by MCI_INT interrupt caused by BT's HW messages
2037 * (LNA_xxx, CONT_xxx) which chould be in a very fast
2038 * rate (~100us). This will cause chip to leave and
2039 * re-enter network sleep mode frequently, which in
2040 * consequence will have WLAN MCI HW to generate lots of
2041 * SYS_WAKING and SYS_SLEEPING messages which will make
2042 * BT CPU to busy to process.
2044 if (ath9k_hw_mci_is_enabled(ah))
2045 REG_CLR_BIT(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
2046 AR_MCI_INTERRUPT_RX_HW_MSG_MASK);
2048 * Clear the RTC force wake bit to allow the
2049 * mac to go to sleep.
2051 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
2053 if (ath9k_hw_mci_is_enabled(ah))
2057 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
2058 if (AR_SREV_9300_20_OR_LATER(ah))
2059 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
2062 static bool ath9k_hw_set_power_awake(struct ath_hw *ah)
2067 /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
2068 if (AR_SREV_9300_20_OR_LATER(ah)) {
2069 REG_WRITE(ah, AR_WA, ah->WARegVal);
2073 if ((REG_READ(ah, AR_RTC_STATUS) &
2074 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2075 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
2078 if (!AR_SREV_9300_20_OR_LATER(ah))
2079 ath9k_hw_init_pll(ah, NULL);
2081 if (AR_SREV_9100(ah))
2082 REG_SET_BIT(ah, AR_RTC_RESET,
2085 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2086 AR_RTC_FORCE_WAKE_EN);
2087 if (AR_SREV_9100(ah))
2092 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2093 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2094 if (val == AR_RTC_STATUS_ON)
2097 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2098 AR_RTC_FORCE_WAKE_EN);
2101 ath_err(ath9k_hw_common(ah),
2102 "Failed to wakeup in %uus\n",
2103 POWER_UP_TIME / 20);
2107 if (ath9k_hw_mci_is_enabled(ah))
2108 ar9003_mci_set_power_awake(ah);
2110 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2115 bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
2117 struct ath_common *common = ath9k_hw_common(ah);
2119 static const char *modes[] = {
2126 if (ah->power_mode == mode)
2129 ath_dbg(common, RESET, "%s -> %s\n",
2130 modes[ah->power_mode], modes[mode]);
2133 case ATH9K_PM_AWAKE:
2134 status = ath9k_hw_set_power_awake(ah);
2136 case ATH9K_PM_FULL_SLEEP:
2137 if (ath9k_hw_mci_is_enabled(ah))
2138 ar9003_mci_set_full_sleep(ah);
2140 ath9k_set_power_sleep(ah);
2141 ah->chip_fullsleep = true;
2143 case ATH9K_PM_NETWORK_SLEEP:
2144 ath9k_set_power_network_sleep(ah);
2147 ath_err(common, "Unknown power mode %u\n", mode);
2150 ah->power_mode = mode;
2153 * XXX: If this warning never comes up after a while then
2154 * simply keep the ATH_DBG_WARN_ON_ONCE() but make
2155 * ath9k_hw_setpower() return type void.
2158 if (!(ah->ah_flags & AH_UNPLUGGED))
2159 ATH_DBG_WARN_ON_ONCE(!status);
2163 EXPORT_SYMBOL(ath9k_hw_setpower);
2165 /*******************/
2166 /* Beacon Handling */
2167 /*******************/
2169 void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
2173 ENABLE_REGWRITE_BUFFER(ah);
2175 switch (ah->opmode) {
2176 case NL80211_IFTYPE_ADHOC:
2177 REG_SET_BIT(ah, AR_TXCFG,
2178 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2179 case NL80211_IFTYPE_MESH_POINT:
2180 case NL80211_IFTYPE_AP:
2181 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
2182 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
2183 TU_TO_USEC(ah->config.dma_beacon_response_time));
2184 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
2185 TU_TO_USEC(ah->config.sw_beacon_response_time));
2187 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2190 ath_dbg(ath9k_hw_common(ah), BEACON,
2191 "%s: unsupported opmode: %d\n", __func__, ah->opmode);
2196 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
2197 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
2198 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
2200 REGWRITE_BUFFER_FLUSH(ah);
2202 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2204 EXPORT_SYMBOL(ath9k_hw_beaconinit);
2206 void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
2207 const struct ath9k_beacon_state *bs)
2209 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
2210 struct ath9k_hw_capabilities *pCap = &ah->caps;
2211 struct ath_common *common = ath9k_hw_common(ah);
2213 ENABLE_REGWRITE_BUFFER(ah);
2215 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, bs->bs_nexttbtt);
2216 REG_WRITE(ah, AR_BEACON_PERIOD, bs->bs_intval);
2217 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, bs->bs_intval);
2219 REGWRITE_BUFFER_FLUSH(ah);
2221 REG_RMW_FIELD(ah, AR_RSSI_THR,
2222 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2224 beaconintval = bs->bs_intval;
2226 if (bs->bs_sleepduration > beaconintval)
2227 beaconintval = bs->bs_sleepduration;
2229 dtimperiod = bs->bs_dtimperiod;
2230 if (bs->bs_sleepduration > dtimperiod)
2231 dtimperiod = bs->bs_sleepduration;
2233 if (beaconintval == dtimperiod)
2234 nextTbtt = bs->bs_nextdtim;
2236 nextTbtt = bs->bs_nexttbtt;
2238 ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2239 ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
2240 ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
2241 ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
2243 ENABLE_REGWRITE_BUFFER(ah);
2245 REG_WRITE(ah, AR_NEXT_DTIM, bs->bs_nextdtim - SLEEP_SLOP);
2246 REG_WRITE(ah, AR_NEXT_TIM, nextTbtt - SLEEP_SLOP);
2248 REG_WRITE(ah, AR_SLEEP1,
2249 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2250 | AR_SLEEP1_ASSUME_DTIM);
2252 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
2253 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2255 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2257 REG_WRITE(ah, AR_SLEEP2,
2258 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2260 REG_WRITE(ah, AR_TIM_PERIOD, beaconintval);
2261 REG_WRITE(ah, AR_DTIM_PERIOD, dtimperiod);
2263 REGWRITE_BUFFER_FLUSH(ah);
2265 REG_SET_BIT(ah, AR_TIMER_MODE,
2266 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2269 /* TSF Out of Range Threshold */
2270 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
2272 EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
2274 /*******************/
2275 /* HW Capabilities */
2276 /*******************/
2278 static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
2280 eeprom_chainmask &= chip_chainmask;
2281 if (eeprom_chainmask)
2282 return eeprom_chainmask;
2284 return chip_chainmask;
2288 * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
2289 * @ah: the atheros hardware data structure
2291 * We enable DFS support upstream on chipsets which have passed a series
2292 * of tests. The testing requirements are going to be documented. Desired
2293 * test requirements are documented at:
2295 * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
2297 * Once a new chipset gets properly tested an individual commit can be used
2298 * to document the testing for DFS for that chipset.
2300 static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
2303 switch (ah->hw_version.macVersion) {
2304 /* for temporary testing DFS with 9280 */
2305 case AR_SREV_VERSION_9280:
2306 /* AR9580 will likely be our first target to get testing on */
2307 case AR_SREV_VERSION_9580:
2314 int ath9k_hw_fill_cap_info(struct ath_hw *ah)
2316 struct ath9k_hw_capabilities *pCap = &ah->caps;
2317 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
2318 struct ath_common *common = ath9k_hw_common(ah);
2319 unsigned int chip_chainmask;
2322 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
2324 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
2325 regulatory->current_rd = eeval;
2327 if (ah->opmode != NL80211_IFTYPE_AP &&
2328 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
2329 if (regulatory->current_rd == 0x64 ||
2330 regulatory->current_rd == 0x65)
2331 regulatory->current_rd += 5;
2332 else if (regulatory->current_rd == 0x41)
2333 regulatory->current_rd = 0x43;
2334 ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
2335 regulatory->current_rd);
2338 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
2339 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2341 "no band has been marked as supported in EEPROM\n");
2345 if (eeval & AR5416_OPFLAGS_11A)
2346 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
2348 if (eeval & AR5416_OPFLAGS_11G)
2349 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
2351 if (AR_SREV_9485(ah) ||
2356 else if (AR_SREV_9462(ah))
2358 else if (!AR_SREV_9280_20_OR_LATER(ah))
2360 else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah))
2365 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
2367 * For AR9271 we will temporarilly uses the rx chainmax as read from
2370 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
2371 !(eeval & AR5416_OPFLAGS_11A) &&
2372 !(AR_SREV_9271(ah)))
2373 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
2374 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2375 else if (AR_SREV_9100(ah))
2376 pCap->rx_chainmask = 0x7;
2378 /* Use rx_chainmask from EEPROM. */
2379 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
2381 pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask);
2382 pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask);
2383 ah->txchainmask = pCap->tx_chainmask;
2384 ah->rxchainmask = pCap->rx_chainmask;
2386 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
2388 /* enable key search for every frame in an aggregate */
2389 if (AR_SREV_9300_20_OR_LATER(ah))
2390 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
2392 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
2394 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
2395 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2397 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2399 if (AR_SREV_9271(ah))
2400 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2401 else if (AR_DEVID_7010(ah))
2402 pCap->num_gpio_pins = AR7010_NUM_GPIO;
2403 else if (AR_SREV_9300_20_OR_LATER(ah))
2404 pCap->num_gpio_pins = AR9300_NUM_GPIO;
2405 else if (AR_SREV_9287_11_OR_LATER(ah))
2406 pCap->num_gpio_pins = AR9287_NUM_GPIO;
2407 else if (AR_SREV_9285_12_OR_LATER(ah))
2408 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2409 else if (AR_SREV_9280_20_OR_LATER(ah))
2410 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2412 pCap->num_gpio_pins = AR_NUM_GPIO;
2414 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
2415 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2417 pCap->rts_aggr_limit = (8 * 1024);
2419 #ifdef CONFIG_ATH9K_RFKILL
2420 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2421 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2423 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2424 ah->rfkill_polarity =
2425 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
2427 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2430 if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
2431 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2433 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
2435 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
2436 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2438 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2440 if (AR_SREV_9300_20_OR_LATER(ah)) {
2441 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
2442 if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah) && !AR_SREV_9565(ah))
2443 pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
2445 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2446 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2447 pCap->rx_status_len = sizeof(struct ar9003_rxs);
2448 pCap->tx_desc_len = sizeof(struct ar9003_txc);
2449 pCap->txs_len = sizeof(struct ar9003_txs);
2451 pCap->tx_desc_len = sizeof(struct ath_desc);
2452 if (AR_SREV_9280_20(ah))
2453 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
2456 if (AR_SREV_9300_20_OR_LATER(ah))
2457 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2459 if (AR_SREV_9300_20_OR_LATER(ah))
2460 ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
2462 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
2463 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
2465 if (AR_SREV_9285(ah)) {
2466 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
2468 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2469 if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1)) {
2470 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2471 ath_info(common, "Enable LNA combining\n");
2476 if (AR_SREV_9300_20_OR_LATER(ah)) {
2477 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
2478 pCap->hw_caps |= ATH9K_HW_CAP_APM;
2481 if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
2482 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2483 if ((ant_div_ctl1 >> 0x6) == 0x3) {
2484 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2485 ath_info(common, "Enable LNA combining\n");
2489 if (ath9k_hw_dfs_tested(ah))
2490 pCap->hw_caps |= ATH9K_HW_CAP_DFS;
2492 tx_chainmask = pCap->tx_chainmask;
2493 rx_chainmask = pCap->rx_chainmask;
2494 while (tx_chainmask || rx_chainmask) {
2495 if (tx_chainmask & BIT(0))
2496 pCap->max_txchains++;
2497 if (rx_chainmask & BIT(0))
2498 pCap->max_rxchains++;
2504 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
2505 if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE))
2506 pCap->hw_caps |= ATH9K_HW_CAP_MCI;
2508 if (AR_SREV_9462_20_OR_LATER(ah))
2509 pCap->hw_caps |= ATH9K_HW_CAP_RTT;
2512 if (AR_SREV_9462(ah))
2513 pCap->hw_caps |= ATH9K_HW_WOW_DEVICE_CAPABLE;
2515 if (AR_SREV_9300_20_OR_LATER(ah) &&
2516 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
2517 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
2522 /****************************/
2523 /* GPIO / RFKILL / Antennae */
2524 /****************************/
2526 static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
2530 u32 gpio_shift, tmp;
2533 addr = AR_GPIO_OUTPUT_MUX3;
2535 addr = AR_GPIO_OUTPUT_MUX2;
2537 addr = AR_GPIO_OUTPUT_MUX1;
2539 gpio_shift = (gpio % 6) * 5;
2541 if (AR_SREV_9280_20_OR_LATER(ah)
2542 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2543 REG_RMW(ah, addr, (type << gpio_shift),
2544 (0x1f << gpio_shift));
2546 tmp = REG_READ(ah, addr);
2547 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2548 tmp &= ~(0x1f << gpio_shift);
2549 tmp |= (type << gpio_shift);
2550 REG_WRITE(ah, addr, tmp);
2554 void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
2558 BUG_ON(gpio >= ah->caps.num_gpio_pins);
2560 if (AR_DEVID_7010(ah)) {
2562 REG_RMW(ah, AR7010_GPIO_OE,
2563 (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
2564 (AR7010_GPIO_OE_MASK << gpio_shift));
2568 gpio_shift = gpio << 1;
2571 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2572 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2574 EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
2576 u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
2578 #define MS_REG_READ(x, y) \
2579 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2581 if (gpio >= ah->caps.num_gpio_pins)
2584 if (AR_DEVID_7010(ah)) {
2586 val = REG_READ(ah, AR7010_GPIO_IN);
2587 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2588 } else if (AR_SREV_9300_20_OR_LATER(ah))
2589 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2590 AR_GPIO_BIT(gpio)) != 0;
2591 else if (AR_SREV_9271(ah))
2592 return MS_REG_READ(AR9271, gpio) != 0;
2593 else if (AR_SREV_9287_11_OR_LATER(ah))
2594 return MS_REG_READ(AR9287, gpio) != 0;
2595 else if (AR_SREV_9285_12_OR_LATER(ah))
2596 return MS_REG_READ(AR9285, gpio) != 0;
2597 else if (AR_SREV_9280_20_OR_LATER(ah))
2598 return MS_REG_READ(AR928X, gpio) != 0;
2600 return MS_REG_READ(AR, gpio) != 0;
2602 EXPORT_SYMBOL(ath9k_hw_gpio_get);
2604 void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
2609 if (AR_DEVID_7010(ah)) {
2611 REG_RMW(ah, AR7010_GPIO_OE,
2612 (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
2613 (AR7010_GPIO_OE_MASK << gpio_shift));
2617 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
2618 gpio_shift = 2 * gpio;
2621 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2622 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2624 EXPORT_SYMBOL(ath9k_hw_cfg_output);
2626 void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
2628 if (AR_DEVID_7010(ah)) {
2630 REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
2635 if (AR_SREV_9271(ah))
2638 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2641 EXPORT_SYMBOL(ath9k_hw_set_gpio);
2643 void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
2645 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2647 EXPORT_SYMBOL(ath9k_hw_setantenna);
2649 /*********************/
2650 /* General Operation */
2651 /*********************/
2653 u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
2655 u32 bits = REG_READ(ah, AR_RX_FILTER);
2656 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2658 if (phybits & AR_PHY_ERR_RADAR)
2659 bits |= ATH9K_RX_FILTER_PHYRADAR;
2660 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2661 bits |= ATH9K_RX_FILTER_PHYERR;
2665 EXPORT_SYMBOL(ath9k_hw_getrxfilter);
2667 void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
2671 ENABLE_REGWRITE_BUFFER(ah);
2673 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
2674 bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
2676 REG_WRITE(ah, AR_RX_FILTER, bits);
2679 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2680 phybits |= AR_PHY_ERR_RADAR;
2681 if (bits & ATH9K_RX_FILTER_PHYERR)
2682 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2683 REG_WRITE(ah, AR_PHY_ERR, phybits);
2686 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
2688 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
2690 REGWRITE_BUFFER_FLUSH(ah);
2692 EXPORT_SYMBOL(ath9k_hw_setrxfilter);
2694 bool ath9k_hw_phy_disable(struct ath_hw *ah)
2696 if (ath9k_hw_mci_is_enabled(ah))
2697 ar9003_mci_bt_gain_ctrl(ah);
2699 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2702 ath9k_hw_init_pll(ah, NULL);
2703 ah->htc_reset_init = true;
2706 EXPORT_SYMBOL(ath9k_hw_phy_disable);
2708 bool ath9k_hw_disable(struct ath_hw *ah)
2710 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
2713 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2716 ath9k_hw_init_pll(ah, NULL);
2719 EXPORT_SYMBOL(ath9k_hw_disable);
2721 static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
2723 enum eeprom_param gain_param;
2725 if (IS_CHAN_2GHZ(chan))
2726 gain_param = EEP_ANTENNA_GAIN_2G;
2728 gain_param = EEP_ANTENNA_GAIN_5G;
2730 return ah->eep_ops->get_eeprom(ah, gain_param);
2733 void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
2736 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2737 struct ieee80211_channel *channel;
2738 int chan_pwr, new_pwr, max_gain;
2739 int ant_gain, ant_reduction = 0;
2744 channel = chan->chan;
2745 chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
2746 new_pwr = min_t(int, chan_pwr, reg->power_limit);
2747 max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
2749 ant_gain = get_antenna_gain(ah, chan);
2750 if (ant_gain > max_gain)
2751 ant_reduction = ant_gain - max_gain;
2753 ah->eep_ops->set_txpower(ah, chan,
2754 ath9k_regd_get_ctl(reg, chan),
2755 ant_reduction, new_pwr, test);
2758 void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
2760 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2761 struct ath9k_channel *chan = ah->curchan;
2762 struct ieee80211_channel *channel = chan->chan;
2764 reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
2766 channel->max_power = MAX_RATE_POWER / 2;
2768 ath9k_hw_apply_txpower(ah, chan, test);
2771 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
2773 EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
2775 void ath9k_hw_setopmode(struct ath_hw *ah)
2777 ath9k_hw_set_operating_mode(ah, ah->opmode);
2779 EXPORT_SYMBOL(ath9k_hw_setopmode);
2781 void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
2783 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2784 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2786 EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
2788 void ath9k_hw_write_associd(struct ath_hw *ah)
2790 struct ath_common *common = ath9k_hw_common(ah);
2792 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2793 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2794 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
2796 EXPORT_SYMBOL(ath9k_hw_write_associd);
2798 #define ATH9K_MAX_TSF_READ 10
2800 u64 ath9k_hw_gettsf64(struct ath_hw *ah)
2802 u32 tsf_lower, tsf_upper1, tsf_upper2;
2805 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2806 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2807 tsf_lower = REG_READ(ah, AR_TSF_L32);
2808 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2809 if (tsf_upper2 == tsf_upper1)
2811 tsf_upper1 = tsf_upper2;
2814 WARN_ON( i == ATH9K_MAX_TSF_READ );
2816 return (((u64)tsf_upper1 << 32) | tsf_lower);
2818 EXPORT_SYMBOL(ath9k_hw_gettsf64);
2820 void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
2822 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
2823 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
2825 EXPORT_SYMBOL(ath9k_hw_settsf64);
2827 void ath9k_hw_reset_tsf(struct ath_hw *ah)
2829 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2830 AH_TSF_WRITE_TIMEOUT))
2831 ath_dbg(ath9k_hw_common(ah), RESET,
2832 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
2834 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
2836 EXPORT_SYMBOL(ath9k_hw_reset_tsf);
2838 void ath9k_hw_set_tsfadjust(struct ath_hw *ah, bool set)
2841 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
2843 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
2845 EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
2847 void ath9k_hw_set11nmac2040(struct ath_hw *ah, struct ath9k_channel *chan)
2851 if (IS_CHAN_HT40(chan) && !ah->config.cwm_ignore_extcca)
2852 macmode = AR_2040_JOINED_RX_CLEAR;
2856 REG_WRITE(ah, AR_2040_MODE, macmode);
2859 /* HW Generic timers configuration */
2861 static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2863 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2864 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2865 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2866 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2867 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2868 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2869 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2870 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2871 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2872 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2873 AR_NDP2_TIMER_MODE, 0x0002},
2874 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2875 AR_NDP2_TIMER_MODE, 0x0004},
2876 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2877 AR_NDP2_TIMER_MODE, 0x0008},
2878 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2879 AR_NDP2_TIMER_MODE, 0x0010},
2880 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2881 AR_NDP2_TIMER_MODE, 0x0020},
2882 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2883 AR_NDP2_TIMER_MODE, 0x0040},
2884 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2885 AR_NDP2_TIMER_MODE, 0x0080}
2888 /* HW generic timer primitives */
2890 u32 ath9k_hw_gettsf32(struct ath_hw *ah)
2892 return REG_READ(ah, AR_TSF_L32);
2894 EXPORT_SYMBOL(ath9k_hw_gettsf32);
2896 struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2897 void (*trigger)(void *),
2898 void (*overflow)(void *),
2902 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2903 struct ath_gen_timer *timer;
2905 if ((timer_index < AR_FIRST_NDP_TIMER) ||
2906 (timer_index >= ATH_MAX_GEN_TIMER))
2909 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
2913 /* allocate a hardware generic timer slot */
2914 timer_table->timers[timer_index] = timer;
2915 timer->index = timer_index;
2916 timer->trigger = trigger;
2917 timer->overflow = overflow;
2922 EXPORT_SYMBOL(ath_gen_timer_alloc);
2924 void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2925 struct ath_gen_timer *timer,
2929 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2932 timer_table->timer_mask |= BIT(timer->index);
2935 * Program generic timer registers
2937 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
2939 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
2941 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2942 gen_tmr_configuration[timer->index].mode_mask);
2944 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
2946 * Starting from AR9462, each generic timer can select which tsf
2947 * to use. But we still follow the old rule, 0 - 7 use tsf and
2950 if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
2951 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2952 (1 << timer->index));
2954 REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2955 (1 << timer->index));
2959 mask |= SM(AR_GENTMR_BIT(timer->index),
2960 AR_IMR_S5_GENTIMER_TRIG);
2961 if (timer->overflow)
2962 mask |= SM(AR_GENTMR_BIT(timer->index),
2963 AR_IMR_S5_GENTIMER_THRESH);
2965 REG_SET_BIT(ah, AR_IMR_S5, mask);
2967 if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
2968 ah->imask |= ATH9K_INT_GENTIMER;
2969 ath9k_hw_set_interrupts(ah);
2972 EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
2974 void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
2976 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2978 /* Clear generic timer enable bits. */
2979 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2980 gen_tmr_configuration[timer->index].mode_mask);
2982 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
2984 * Need to switch back to TSF if it was using TSF2.
2986 if ((timer->index >= AR_GEN_TIMER_BANK_1_LEN)) {
2987 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2988 (1 << timer->index));
2992 /* Disable both trigger and thresh interrupt masks */
2993 REG_CLR_BIT(ah, AR_IMR_S5,
2994 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2995 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
2997 timer_table->timer_mask &= ~BIT(timer->index);
2999 if (timer_table->timer_mask == 0) {
3000 ah->imask &= ~ATH9K_INT_GENTIMER;
3001 ath9k_hw_set_interrupts(ah);
3004 EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
3006 void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
3008 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3010 /* free the hardware generic timer slot */
3011 timer_table->timers[timer->index] = NULL;
3014 EXPORT_SYMBOL(ath_gen_timer_free);
3017 * Generic Timer Interrupts handling
3019 void ath_gen_timer_isr(struct ath_hw *ah)
3021 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
3022 struct ath_gen_timer *timer;
3023 unsigned long trigger_mask, thresh_mask;
3026 /* get hardware generic timer interrupt status */
3027 trigger_mask = ah->intr_gen_timer_trigger;
3028 thresh_mask = ah->intr_gen_timer_thresh;
3029 trigger_mask &= timer_table->timer_mask;
3030 thresh_mask &= timer_table->timer_mask;
3032 for_each_set_bit(index, &thresh_mask, ARRAY_SIZE(timer_table->timers)) {
3033 timer = timer_table->timers[index];
3036 if (!timer->overflow)
3039 trigger_mask &= ~BIT(index);
3040 timer->overflow(timer->arg);
3043 for_each_set_bit(index, &trigger_mask, ARRAY_SIZE(timer_table->timers)) {
3044 timer = timer_table->timers[index];
3047 if (!timer->trigger)
3049 timer->trigger(timer->arg);
3052 EXPORT_SYMBOL(ath_gen_timer_isr);
3061 } ath_mac_bb_names[] = {
3062 /* Devices with external radios */
3063 { AR_SREV_VERSION_5416_PCI, "5416" },
3064 { AR_SREV_VERSION_5416_PCIE, "5418" },
3065 { AR_SREV_VERSION_9100, "9100" },
3066 { AR_SREV_VERSION_9160, "9160" },
3067 /* Single-chip solutions */
3068 { AR_SREV_VERSION_9280, "9280" },
3069 { AR_SREV_VERSION_9285, "9285" },
3070 { AR_SREV_VERSION_9287, "9287" },
3071 { AR_SREV_VERSION_9271, "9271" },
3072 { AR_SREV_VERSION_9300, "9300" },
3073 { AR_SREV_VERSION_9330, "9330" },
3074 { AR_SREV_VERSION_9340, "9340" },
3075 { AR_SREV_VERSION_9485, "9485" },
3076 { AR_SREV_VERSION_9462, "9462" },
3077 { AR_SREV_VERSION_9550, "9550" },
3078 { AR_SREV_VERSION_9565, "9565" },
3079 { AR_SREV_VERSION_9531, "9531" },
3082 /* For devices with external radios */
3086 } ath_rf_names[] = {
3088 { AR_RAD5133_SREV_MAJOR, "5133" },
3089 { AR_RAD5122_SREV_MAJOR, "5122" },
3090 { AR_RAD2133_SREV_MAJOR, "2133" },
3091 { AR_RAD2122_SREV_MAJOR, "2122" }
3095 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3097 static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
3101 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3102 if (ath_mac_bb_names[i].version == mac_bb_version) {
3103 return ath_mac_bb_names[i].name;
3111 * Return the RF name. "????" is returned if the RF is unknown.
3112 * Used for devices with external radios.
3114 static const char *ath9k_hw_rf_name(u16 rf_version)
3118 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3119 if (ath_rf_names[i].version == rf_version) {
3120 return ath_rf_names[i].name;
3127 void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3131 /* chipsets >= AR9280 are single-chip */
3132 if (AR_SREV_9280_20_OR_LATER(ah)) {
3133 used = scnprintf(hw_name, len,
3134 "Atheros AR%s Rev:%x",
3135 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3136 ah->hw_version.macRev);
3139 used = scnprintf(hw_name, len,
3140 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3141 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3142 ah->hw_version.macRev,
3143 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev
3144 & AR_RADIO_SREV_MAJOR)),
3145 ah->hw_version.phyRev);
3148 hw_name[used] = '\0';
3150 EXPORT_SYMBOL(ath9k_hw_name);