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>
27 #include "ar9003_mac.h"
28 #include "ar9003_mci.h"
29 #include "ar9003_phy.h"
33 static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type);
35 MODULE_AUTHOR("Atheros Communications");
36 MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
37 MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
38 MODULE_LICENSE("Dual BSD/GPL");
40 static void ath9k_hw_set_clockrate(struct ath_hw *ah)
42 struct ath_common *common = ath9k_hw_common(ah);
43 struct ath9k_channel *chan = ah->curchan;
44 unsigned int clockrate;
46 /* AR9287 v1.3+ uses async FIFO and runs the MAC at 117 MHz */
47 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah))
49 else if (!chan) /* should really check for CCK instead */
50 clockrate = ATH9K_CLOCK_RATE_CCK;
51 else if (IS_CHAN_2GHZ(chan))
52 clockrate = ATH9K_CLOCK_RATE_2GHZ_OFDM;
53 else if (ah->caps.hw_caps & ATH9K_HW_CAP_FASTCLOCK)
54 clockrate = ATH9K_CLOCK_FAST_RATE_5GHZ_OFDM;
56 clockrate = ATH9K_CLOCK_RATE_5GHZ_OFDM;
59 if (IS_CHAN_HT40(chan))
61 if (IS_CHAN_HALF_RATE(chan))
63 if (IS_CHAN_QUARTER_RATE(chan))
67 common->clockrate = clockrate;
70 static u32 ath9k_hw_mac_to_clks(struct ath_hw *ah, u32 usecs)
72 struct ath_common *common = ath9k_hw_common(ah);
74 return usecs * common->clockrate;
77 bool ath9k_hw_wait(struct ath_hw *ah, u32 reg, u32 mask, u32 val, u32 timeout)
81 BUG_ON(timeout < AH_TIME_QUANTUM);
83 for (i = 0; i < (timeout / AH_TIME_QUANTUM); i++) {
84 if ((REG_READ(ah, reg) & mask) == val)
87 udelay(AH_TIME_QUANTUM);
90 ath_dbg(ath9k_hw_common(ah), ANY,
91 "timeout (%d us) on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
92 timeout, reg, REG_READ(ah, reg), mask, val);
96 EXPORT_SYMBOL(ath9k_hw_wait);
98 void ath9k_hw_synth_delay(struct ath_hw *ah, struct ath9k_channel *chan,
103 if (IS_CHAN_HALF_RATE(chan))
105 else if (IS_CHAN_QUARTER_RATE(chan))
108 udelay(hw_delay + BASE_ACTIVATE_DELAY);
111 void ath9k_hw_write_array(struct ath_hw *ah, const struct ar5416IniArray *array,
112 int column, unsigned int *writecnt)
116 ENABLE_REGWRITE_BUFFER(ah);
117 for (r = 0; r < array->ia_rows; r++) {
118 REG_WRITE(ah, INI_RA(array, r, 0),
119 INI_RA(array, r, column));
122 REGWRITE_BUFFER_FLUSH(ah);
125 u32 ath9k_hw_reverse_bits(u32 val, u32 n)
130 for (i = 0, retval = 0; i < n; i++) {
131 retval = (retval << 1) | (val & 1);
137 u16 ath9k_hw_computetxtime(struct ath_hw *ah,
139 u32 frameLen, u16 rateix,
142 u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
148 case WLAN_RC_PHY_CCK:
149 phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
152 numBits = frameLen << 3;
153 txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
155 case WLAN_RC_PHY_OFDM:
156 if (ah->curchan && IS_CHAN_QUARTER_RATE(ah->curchan)) {
157 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
158 numBits = OFDM_PLCP_BITS + (frameLen << 3);
159 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
160 txTime = OFDM_SIFS_TIME_QUARTER
161 + OFDM_PREAMBLE_TIME_QUARTER
162 + (numSymbols * OFDM_SYMBOL_TIME_QUARTER);
163 } else if (ah->curchan &&
164 IS_CHAN_HALF_RATE(ah->curchan)) {
165 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_HALF) / 1000;
166 numBits = OFDM_PLCP_BITS + (frameLen << 3);
167 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
168 txTime = OFDM_SIFS_TIME_HALF +
169 OFDM_PREAMBLE_TIME_HALF
170 + (numSymbols * OFDM_SYMBOL_TIME_HALF);
172 bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME) / 1000;
173 numBits = OFDM_PLCP_BITS + (frameLen << 3);
174 numSymbols = DIV_ROUND_UP(numBits, bitsPerSymbol);
175 txTime = OFDM_SIFS_TIME + OFDM_PREAMBLE_TIME
176 + (numSymbols * OFDM_SYMBOL_TIME);
180 ath_err(ath9k_hw_common(ah),
181 "Unknown phy %u (rate ix %u)\n", phy, rateix);
188 EXPORT_SYMBOL(ath9k_hw_computetxtime);
190 void ath9k_hw_get_channel_centers(struct ath_hw *ah,
191 struct ath9k_channel *chan,
192 struct chan_centers *centers)
196 if (!IS_CHAN_HT40(chan)) {
197 centers->ctl_center = centers->ext_center =
198 centers->synth_center = chan->channel;
202 if (IS_CHAN_HT40PLUS(chan)) {
203 centers->synth_center =
204 chan->channel + HT40_CHANNEL_CENTER_SHIFT;
207 centers->synth_center =
208 chan->channel - HT40_CHANNEL_CENTER_SHIFT;
212 centers->ctl_center =
213 centers->synth_center - (extoff * HT40_CHANNEL_CENTER_SHIFT);
214 /* 25 MHz spacing is supported by hw but not on upper layers */
215 centers->ext_center =
216 centers->synth_center + (extoff * HT40_CHANNEL_CENTER_SHIFT);
223 static void ath9k_hw_read_revisions(struct ath_hw *ah)
227 switch (ah->hw_version.devid) {
228 case AR5416_AR9100_DEVID:
229 ah->hw_version.macVersion = AR_SREV_VERSION_9100;
231 case AR9300_DEVID_AR9330:
232 ah->hw_version.macVersion = AR_SREV_VERSION_9330;
233 if (ah->get_mac_revision) {
234 ah->hw_version.macRev = ah->get_mac_revision();
236 val = REG_READ(ah, AR_SREV);
237 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
240 case AR9300_DEVID_AR9340:
241 ah->hw_version.macVersion = AR_SREV_VERSION_9340;
242 val = REG_READ(ah, AR_SREV);
243 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
245 case AR9300_DEVID_QCA955X:
246 ah->hw_version.macVersion = AR_SREV_VERSION_9550;
248 case AR9300_DEVID_AR953X:
249 ah->hw_version.macVersion = AR_SREV_VERSION_9531;
253 val = REG_READ(ah, AR_SREV) & AR_SREV_ID;
256 val = REG_READ(ah, AR_SREV);
257 ah->hw_version.macVersion =
258 (val & AR_SREV_VERSION2) >> AR_SREV_TYPE2_S;
259 ah->hw_version.macRev = MS(val, AR_SREV_REVISION2);
261 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
262 ah->is_pciexpress = true;
264 ah->is_pciexpress = (val &
265 AR_SREV_TYPE2_HOST_MODE) ? 0 : 1;
267 if (!AR_SREV_9100(ah))
268 ah->hw_version.macVersion = MS(val, AR_SREV_VERSION);
270 ah->hw_version.macRev = val & AR_SREV_REVISION;
272 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCIE)
273 ah->is_pciexpress = true;
277 /************************************/
278 /* HW Attach, Detach, Init Routines */
279 /************************************/
281 static void ath9k_hw_disablepcie(struct ath_hw *ah)
283 if (!AR_SREV_5416(ah))
286 REG_WRITE(ah, AR_PCIE_SERDES, 0x9248fc00);
287 REG_WRITE(ah, AR_PCIE_SERDES, 0x24924924);
288 REG_WRITE(ah, AR_PCIE_SERDES, 0x28000029);
289 REG_WRITE(ah, AR_PCIE_SERDES, 0x57160824);
290 REG_WRITE(ah, AR_PCIE_SERDES, 0x25980579);
291 REG_WRITE(ah, AR_PCIE_SERDES, 0x00000000);
292 REG_WRITE(ah, AR_PCIE_SERDES, 0x1aaabe40);
293 REG_WRITE(ah, AR_PCIE_SERDES, 0xbe105554);
294 REG_WRITE(ah, AR_PCIE_SERDES, 0x000e1007);
296 REG_WRITE(ah, AR_PCIE_SERDES2, 0x00000000);
299 /* This should work for all families including legacy */
300 static bool ath9k_hw_chip_test(struct ath_hw *ah)
302 struct ath_common *common = ath9k_hw_common(ah);
303 u32 regAddr[2] = { AR_STA_ID0 };
305 static const u32 patternData[4] = {
306 0x55555555, 0xaaaaaaaa, 0x66666666, 0x99999999
310 if (!AR_SREV_9300_20_OR_LATER(ah)) {
312 regAddr[1] = AR_PHY_BASE + (8 << 2);
316 for (i = 0; i < loop_max; i++) {
317 u32 addr = regAddr[i];
320 regHold[i] = REG_READ(ah, addr);
321 for (j = 0; j < 0x100; j++) {
322 wrData = (j << 16) | j;
323 REG_WRITE(ah, addr, wrData);
324 rdData = REG_READ(ah, addr);
325 if (rdData != wrData) {
327 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
328 addr, wrData, rdData);
332 for (j = 0; j < 4; j++) {
333 wrData = patternData[j];
334 REG_WRITE(ah, addr, wrData);
335 rdData = REG_READ(ah, addr);
336 if (wrData != rdData) {
338 "address test failed addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
339 addr, wrData, rdData);
343 REG_WRITE(ah, regAddr[i], regHold[i]);
350 static void ath9k_hw_init_config(struct ath_hw *ah)
352 struct ath_common *common = ath9k_hw_common(ah);
354 ah->config.dma_beacon_response_time = 1;
355 ah->config.sw_beacon_response_time = 6;
356 ah->config.cwm_ignore_extcca = 0;
357 ah->config.analog_shiftreg = 1;
359 ah->config.rx_intr_mitigation = true;
362 * We need this for PCI devices only (Cardbus, PCI, miniPCI)
363 * _and_ if on non-uniprocessor systems (Multiprocessor/HT).
364 * This means we use it for all AR5416 devices, and the few
365 * minor PCI AR9280 devices out there.
367 * Serialization is required because these devices do not handle
368 * well the case of two concurrent reads/writes due to the latency
369 * involved. During one read/write another read/write can be issued
370 * on another CPU while the previous read/write may still be working
371 * on our hardware, if we hit this case the hardware poops in a loop.
372 * We prevent this by serializing reads and writes.
374 * This issue is not present on PCI-Express devices or pre-AR5416
375 * devices (legacy, 802.11abg).
377 if (num_possible_cpus() > 1)
378 ah->config.serialize_regmode = SER_REG_MODE_AUTO;
380 if (NR_CPUS > 1 && ah->config.serialize_regmode == SER_REG_MODE_AUTO) {
381 if (ah->hw_version.macVersion == AR_SREV_VERSION_5416_PCI ||
382 ((AR_SREV_9160(ah) || AR_SREV_9280(ah) || AR_SREV_9287(ah)) &&
383 !ah->is_pciexpress)) {
384 ah->config.serialize_regmode = SER_REG_MODE_ON;
386 ah->config.serialize_regmode = SER_REG_MODE_OFF;
390 ath_dbg(common, RESET, "serialize_regmode is %d\n",
391 ah->config.serialize_regmode);
393 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
394 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD >> 1;
396 ah->config.max_txtrig_level = MAX_TX_FIFO_THRESHOLD;
399 static void ath9k_hw_init_defaults(struct ath_hw *ah)
401 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
403 regulatory->country_code = CTRY_DEFAULT;
404 regulatory->power_limit = MAX_RATE_POWER;
406 ah->hw_version.magic = AR5416_MAGIC;
407 ah->hw_version.subvendorid = 0;
409 ah->sta_id1_defaults = AR_STA_ID1_CRPT_MIC_ENABLE |
410 AR_STA_ID1_MCAST_KSRCH;
411 if (AR_SREV_9100(ah))
412 ah->sta_id1_defaults |= AR_STA_ID1_AR9100_BA_FIX;
414 ah->slottime = ATH9K_SLOT_TIME_9;
415 ah->globaltxtimeout = (u32) -1;
416 ah->power_mode = ATH9K_PM_UNDEFINED;
417 ah->htc_reset_init = true;
419 ah->ani_function = ATH9K_ANI_ALL;
420 if (!AR_SREV_9300_20_OR_LATER(ah))
421 ah->ani_function &= ~ATH9K_ANI_MRC_CCK;
423 if (AR_SREV_9285(ah) || AR_SREV_9271(ah))
424 ah->tx_trig_level = (AR_FTRIG_256B >> AR_FTRIG_S);
426 ah->tx_trig_level = (AR_FTRIG_512B >> AR_FTRIG_S);
429 static int ath9k_hw_init_macaddr(struct ath_hw *ah)
431 struct ath_common *common = ath9k_hw_common(ah);
435 static const u32 EEP_MAC[] = { EEP_MAC_LSW, EEP_MAC_MID, EEP_MAC_MSW };
438 for (i = 0; i < 3; i++) {
439 eeval = ah->eep_ops->get_eeprom(ah, EEP_MAC[i]);
441 common->macaddr[2 * i] = eeval >> 8;
442 common->macaddr[2 * i + 1] = eeval & 0xff;
444 if (sum == 0 || sum == 0xffff * 3)
445 return -EADDRNOTAVAIL;
450 static int ath9k_hw_post_init(struct ath_hw *ah)
452 struct ath_common *common = ath9k_hw_common(ah);
455 if (common->bus_ops->ath_bus_type != ATH_USB) {
456 if (!ath9k_hw_chip_test(ah))
460 if (!AR_SREV_9300_20_OR_LATER(ah)) {
461 ecode = ar9002_hw_rf_claim(ah);
466 ecode = ath9k_hw_eeprom_init(ah);
470 ath_dbg(ath9k_hw_common(ah), CONFIG, "Eeprom VER: %d, REV: %d\n",
471 ah->eep_ops->get_eeprom_ver(ah),
472 ah->eep_ops->get_eeprom_rev(ah));
474 ath9k_hw_ani_init(ah);
477 * EEPROM needs to be initialized before we do this.
478 * This is required for regulatory compliance.
480 if (AR_SREV_9300_20_OR_LATER(ah)) {
481 u16 regdmn = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
482 if ((regdmn & 0xF0) == CTL_FCC) {
483 ah->nf_2g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_2GHZ;
484 ah->nf_5g.max = AR_PHY_CCA_MAX_GOOD_VAL_9300_FCC_5GHZ;
491 static int ath9k_hw_attach_ops(struct ath_hw *ah)
493 if (!AR_SREV_9300_20_OR_LATER(ah))
494 return ar9002_hw_attach_ops(ah);
496 ar9003_hw_attach_ops(ah);
500 /* Called for all hardware families */
501 static int __ath9k_hw_init(struct ath_hw *ah)
503 struct ath_common *common = ath9k_hw_common(ah);
506 ath9k_hw_read_revisions(ah);
508 switch (ah->hw_version.macVersion) {
509 case AR_SREV_VERSION_5416_PCI:
510 case AR_SREV_VERSION_5416_PCIE:
511 case AR_SREV_VERSION_9160:
512 case AR_SREV_VERSION_9100:
513 case AR_SREV_VERSION_9280:
514 case AR_SREV_VERSION_9285:
515 case AR_SREV_VERSION_9287:
516 case AR_SREV_VERSION_9271:
517 case AR_SREV_VERSION_9300:
518 case AR_SREV_VERSION_9330:
519 case AR_SREV_VERSION_9485:
520 case AR_SREV_VERSION_9340:
521 case AR_SREV_VERSION_9462:
522 case AR_SREV_VERSION_9550:
523 case AR_SREV_VERSION_9565:
524 case AR_SREV_VERSION_9531:
528 "Mac Chip Rev 0x%02x.%x is not supported by this driver\n",
529 ah->hw_version.macVersion, ah->hw_version.macRev);
534 * Read back AR_WA into a permanent copy and set bits 14 and 17.
535 * We need to do this to avoid RMW of this register. We cannot
536 * read the reg when chip is asleep.
538 if (AR_SREV_9300_20_OR_LATER(ah)) {
539 ah->WARegVal = REG_READ(ah, AR_WA);
540 ah->WARegVal |= (AR_WA_D3_L1_DISABLE |
541 AR_WA_ASPM_TIMER_BASED_DISABLE);
544 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
545 ath_err(common, "Couldn't reset chip\n");
549 if (AR_SREV_9565(ah)) {
550 ah->WARegVal |= AR_WA_BIT22;
551 REG_WRITE(ah, AR_WA, ah->WARegVal);
554 ath9k_hw_init_defaults(ah);
555 ath9k_hw_init_config(ah);
557 r = ath9k_hw_attach_ops(ah);
561 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
562 ath_err(common, "Couldn't wakeup chip\n");
566 if (AR_SREV_9271(ah) || AR_SREV_9100(ah) || AR_SREV_9340(ah) ||
567 AR_SREV_9330(ah) || AR_SREV_9550(ah))
568 ah->is_pciexpress = false;
570 ah->hw_version.phyRev = REG_READ(ah, AR_PHY_CHIP_ID);
571 ath9k_hw_init_cal_settings(ah);
573 if (!ah->is_pciexpress)
574 ath9k_hw_disablepcie(ah);
576 r = ath9k_hw_post_init(ah);
580 ath9k_hw_init_mode_gain_regs(ah);
581 r = ath9k_hw_fill_cap_info(ah);
585 r = ath9k_hw_init_macaddr(ah);
587 ath_err(common, "Failed to initialize MAC address\n");
591 ath9k_hw_init_hang_checks(ah);
593 common->state = ATH_HW_INITIALIZED;
598 int ath9k_hw_init(struct ath_hw *ah)
601 struct ath_common *common = ath9k_hw_common(ah);
603 /* These are all the AR5008/AR9001/AR9002/AR9003 hardware family of chipsets */
604 switch (ah->hw_version.devid) {
605 case AR5416_DEVID_PCI:
606 case AR5416_DEVID_PCIE:
607 case AR5416_AR9100_DEVID:
608 case AR9160_DEVID_PCI:
609 case AR9280_DEVID_PCI:
610 case AR9280_DEVID_PCIE:
611 case AR9285_DEVID_PCIE:
612 case AR9287_DEVID_PCI:
613 case AR9287_DEVID_PCIE:
614 case AR2427_DEVID_PCIE:
615 case AR9300_DEVID_PCIE:
616 case AR9300_DEVID_AR9485_PCIE:
617 case AR9300_DEVID_AR9330:
618 case AR9300_DEVID_AR9340:
619 case AR9300_DEVID_QCA955X:
620 case AR9300_DEVID_AR9580:
621 case AR9300_DEVID_AR9462:
622 case AR9485_DEVID_AR1111:
623 case AR9300_DEVID_AR9565:
624 case AR9300_DEVID_AR953X:
627 if (common->bus_ops->ath_bus_type == ATH_USB)
629 ath_err(common, "Hardware device ID 0x%04x not supported\n",
630 ah->hw_version.devid);
634 ret = __ath9k_hw_init(ah);
637 "Unable to initialize hardware; initialization status: %d\n",
644 EXPORT_SYMBOL(ath9k_hw_init);
646 static void ath9k_hw_init_qos(struct ath_hw *ah)
648 ENABLE_REGWRITE_BUFFER(ah);
650 REG_WRITE(ah, AR_MIC_QOS_CONTROL, 0x100aa);
651 REG_WRITE(ah, AR_MIC_QOS_SELECT, 0x3210);
653 REG_WRITE(ah, AR_QOS_NO_ACK,
654 SM(2, AR_QOS_NO_ACK_TWO_BIT) |
655 SM(5, AR_QOS_NO_ACK_BIT_OFF) |
656 SM(0, AR_QOS_NO_ACK_BYTE_OFF));
658 REG_WRITE(ah, AR_TXOP_X, AR_TXOP_X_VAL);
659 REG_WRITE(ah, AR_TXOP_0_3, 0xFFFFFFFF);
660 REG_WRITE(ah, AR_TXOP_4_7, 0xFFFFFFFF);
661 REG_WRITE(ah, AR_TXOP_8_11, 0xFFFFFFFF);
662 REG_WRITE(ah, AR_TXOP_12_15, 0xFFFFFFFF);
664 REGWRITE_BUFFER_FLUSH(ah);
667 u32 ar9003_get_pll_sqsum_dvc(struct ath_hw *ah)
669 struct ath_common *common = ath9k_hw_common(ah);
672 REG_CLR_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
674 REG_SET_BIT(ah, PLL3, PLL3_DO_MEAS_MASK);
676 while ((REG_READ(ah, PLL4) & PLL4_MEAS_DONE) == 0) {
680 if (WARN_ON_ONCE(i >= 100)) {
681 ath_err(common, "PLL4 meaurement not done\n");
688 return (REG_READ(ah, PLL3) & SQSUM_DVC_MASK) >> 3;
690 EXPORT_SYMBOL(ar9003_get_pll_sqsum_dvc);
692 static void ath9k_hw_init_pll(struct ath_hw *ah,
693 struct ath9k_channel *chan)
697 if (AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
698 /* program BB PLL ki and kd value, ki=0x4, kd=0x40 */
699 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
700 AR_CH0_BB_DPLL2_PLL_PWD, 0x1);
701 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
702 AR_CH0_DPLL2_KD, 0x40);
703 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
704 AR_CH0_DPLL2_KI, 0x4);
706 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
707 AR_CH0_BB_DPLL1_REFDIV, 0x5);
708 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
709 AR_CH0_BB_DPLL1_NINI, 0x58);
710 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL1,
711 AR_CH0_BB_DPLL1_NFRAC, 0x0);
713 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
714 AR_CH0_BB_DPLL2_OUTDIV, 0x1);
715 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
716 AR_CH0_BB_DPLL2_LOCAL_PLL, 0x1);
717 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
718 AR_CH0_BB_DPLL2_EN_NEGTRIG, 0x1);
720 /* program BB PLL phase_shift to 0x6 */
721 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
722 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x6);
724 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2,
725 AR_CH0_BB_DPLL2_PLL_PWD, 0x0);
727 } else if (AR_SREV_9330(ah)) {
728 u32 ddr_dpll2, pll_control2, kd;
730 if (ah->is_clk_25mhz) {
731 ddr_dpll2 = 0x18e82f01;
732 pll_control2 = 0xe04a3d;
735 ddr_dpll2 = 0x19e82f01;
736 pll_control2 = 0x886666;
740 /* program DDR PLL ki and kd value */
741 REG_WRITE(ah, AR_CH0_DDR_DPLL2, ddr_dpll2);
743 /* program DDR PLL phase_shift */
744 REG_RMW_FIELD(ah, AR_CH0_DDR_DPLL3,
745 AR_CH0_DPLL3_PHASE_SHIFT, 0x1);
747 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
750 /* program refdiv, nint, frac to RTC register */
751 REG_WRITE(ah, AR_RTC_PLL_CONTROL2, pll_control2);
753 /* program BB PLL kd and ki value */
754 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KD, kd);
755 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL2, AR_CH0_DPLL2_KI, 0x06);
757 /* program BB PLL phase_shift */
758 REG_RMW_FIELD(ah, AR_CH0_BB_DPLL3,
759 AR_CH0_BB_DPLL3_PHASE_SHIFT, 0x1);
760 } else if (AR_SREV_9340(ah) || AR_SREV_9550(ah) || AR_SREV_9531(ah)) {
761 u32 regval, pll2_divint, pll2_divfrac, refdiv;
763 REG_WRITE(ah, AR_RTC_PLL_CONTROL, 0x1142c);
766 REG_SET_BIT(ah, AR_PHY_PLL_MODE, 0x1 << 16);
769 if (ah->is_clk_25mhz) {
770 if (AR_SREV_9531(ah)) {
772 pll2_divfrac = 0xa3d2;
776 pll2_divfrac = 0x1eb85;
780 if (AR_SREV_9340(ah)) {
786 pll2_divfrac = 0x26666;
791 regval = REG_READ(ah, AR_PHY_PLL_MODE);
792 if (AR_SREV_9531(ah))
793 regval |= (0x1 << 22);
795 regval |= (0x1 << 16);
796 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
799 REG_WRITE(ah, AR_PHY_PLL_CONTROL, (refdiv << 27) |
800 (pll2_divint << 18) | pll2_divfrac);
803 regval = REG_READ(ah, AR_PHY_PLL_MODE);
804 if (AR_SREV_9340(ah))
805 regval = (regval & 0x80071fff) |
810 else if (AR_SREV_9531(ah))
811 regval = (regval & 0x01c00fff) |
818 regval = (regval & 0x80071fff) |
823 REG_WRITE(ah, AR_PHY_PLL_MODE, regval);
825 if (AR_SREV_9531(ah))
826 REG_WRITE(ah, AR_PHY_PLL_MODE,
827 REG_READ(ah, AR_PHY_PLL_MODE) & 0xffbfffff);
829 REG_WRITE(ah, AR_PHY_PLL_MODE,
830 REG_READ(ah, AR_PHY_PLL_MODE) & 0xfffeffff);
835 pll = ath9k_hw_compute_pll_control(ah, chan);
836 if (AR_SREV_9565(ah))
838 REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
840 if (AR_SREV_9485(ah) || AR_SREV_9340(ah) || AR_SREV_9330(ah) ||
844 /* Switch the core clock for ar9271 to 117Mhz */
845 if (AR_SREV_9271(ah)) {
847 REG_WRITE(ah, 0x50040, 0x304);
850 udelay(RTC_PLL_SETTLE_DELAY);
852 REG_WRITE(ah, AR_RTC_SLEEP_CLK, AR_RTC_FORCE_DERIVED_CLK);
854 if (AR_SREV_9340(ah) || AR_SREV_9550(ah)) {
855 if (ah->is_clk_25mhz) {
856 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x17c << 1);
857 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f3d7);
858 REG_WRITE(ah, AR_SLP32_INC, 0x0001e7ae);
860 REG_WRITE(ah, AR_RTC_DERIVED_CLK, 0x261 << 1);
861 REG_WRITE(ah, AR_SLP32_MODE, 0x0010f400);
862 REG_WRITE(ah, AR_SLP32_INC, 0x0001e800);
868 static void ath9k_hw_init_interrupt_masks(struct ath_hw *ah,
869 enum nl80211_iftype opmode)
871 u32 sync_default = AR_INTR_SYNC_DEFAULT;
872 u32 imr_reg = AR_IMR_TXERR |
878 if (AR_SREV_9340(ah) || AR_SREV_9550(ah))
879 sync_default &= ~AR_INTR_SYNC_HOST1_FATAL;
881 if (AR_SREV_9300_20_OR_LATER(ah)) {
882 imr_reg |= AR_IMR_RXOK_HP;
883 if (ah->config.rx_intr_mitigation)
884 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
886 imr_reg |= AR_IMR_RXOK_LP;
889 if (ah->config.rx_intr_mitigation)
890 imr_reg |= AR_IMR_RXINTM | AR_IMR_RXMINTR;
892 imr_reg |= AR_IMR_RXOK;
895 if (ah->config.tx_intr_mitigation)
896 imr_reg |= AR_IMR_TXINTM | AR_IMR_TXMINTR;
898 imr_reg |= AR_IMR_TXOK;
900 ENABLE_REGWRITE_BUFFER(ah);
902 REG_WRITE(ah, AR_IMR, imr_reg);
903 ah->imrs2_reg |= AR_IMR_S2_GTT;
904 REG_WRITE(ah, AR_IMR_S2, ah->imrs2_reg);
906 if (!AR_SREV_9100(ah)) {
907 REG_WRITE(ah, AR_INTR_SYNC_CAUSE, 0xFFFFFFFF);
908 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, sync_default);
909 REG_WRITE(ah, AR_INTR_SYNC_MASK, 0);
912 REGWRITE_BUFFER_FLUSH(ah);
914 if (AR_SREV_9300_20_OR_LATER(ah)) {
915 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_ENABLE, 0);
916 REG_WRITE(ah, AR_INTR_PRIO_ASYNC_MASK, 0);
917 REG_WRITE(ah, AR_INTR_PRIO_SYNC_ENABLE, 0);
918 REG_WRITE(ah, AR_INTR_PRIO_SYNC_MASK, 0);
922 static void ath9k_hw_set_sifs_time(struct ath_hw *ah, u32 us)
924 u32 val = ath9k_hw_mac_to_clks(ah, us - 2);
925 val = min(val, (u32) 0xFFFF);
926 REG_WRITE(ah, AR_D_GBL_IFS_SIFS, val);
929 static void ath9k_hw_setslottime(struct ath_hw *ah, u32 us)
931 u32 val = ath9k_hw_mac_to_clks(ah, us);
932 val = min(val, (u32) 0xFFFF);
933 REG_WRITE(ah, AR_D_GBL_IFS_SLOT, val);
936 static void ath9k_hw_set_ack_timeout(struct ath_hw *ah, u32 us)
938 u32 val = ath9k_hw_mac_to_clks(ah, us);
939 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_ACK));
940 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_ACK, val);
943 static void ath9k_hw_set_cts_timeout(struct ath_hw *ah, u32 us)
945 u32 val = ath9k_hw_mac_to_clks(ah, us);
946 val = min(val, (u32) MS(0xFFFFFFFF, AR_TIME_OUT_CTS));
947 REG_RMW_FIELD(ah, AR_TIME_OUT, AR_TIME_OUT_CTS, val);
950 static bool ath9k_hw_set_global_txtimeout(struct ath_hw *ah, u32 tu)
953 ath_dbg(ath9k_hw_common(ah), XMIT, "bad global tx timeout %u\n",
955 ah->globaltxtimeout = (u32) -1;
958 REG_RMW_FIELD(ah, AR_GTXTO, AR_GTXTO_TIMEOUT_LIMIT, tu);
959 ah->globaltxtimeout = tu;
964 void ath9k_hw_init_global_settings(struct ath_hw *ah)
966 struct ath_common *common = ath9k_hw_common(ah);
967 const struct ath9k_channel *chan = ah->curchan;
968 int acktimeout, ctstimeout, ack_offset = 0;
971 int rx_lat = 0, tx_lat = 0, eifs = 0;
974 ath_dbg(ath9k_hw_common(ah), RESET, "ah->misc_mode 0x%x\n",
980 if (ah->misc_mode != 0)
981 REG_SET_BIT(ah, AR_PCU_MISC, ah->misc_mode);
983 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
989 if (IS_CHAN_5GHZ(chan))
994 if (IS_CHAN_HALF_RATE(chan)) {
998 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1004 } else if (IS_CHAN_QUARTER_RATE(chan)) {
1006 rx_lat = (rx_lat * 4) - 1;
1008 if (IS_CHAN_A_FAST_CLOCK(ah, chan))
1015 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1016 eifs = AR_D_GBL_IFS_EIFS_ASYNC_FIFO;
1017 reg = AR_USEC_ASYNC_FIFO;
1019 eifs = REG_READ(ah, AR_D_GBL_IFS_EIFS)/
1021 reg = REG_READ(ah, AR_USEC);
1023 rx_lat = MS(reg, AR_USEC_RX_LAT);
1024 tx_lat = MS(reg, AR_USEC_TX_LAT);
1026 slottime = ah->slottime;
1029 /* As defined by IEEE 802.11-2007 17.3.8.6 */
1030 slottime += 3 * ah->coverage_class;
1031 acktimeout = slottime + sifstime + ack_offset;
1032 ctstimeout = acktimeout;
1035 * Workaround for early ACK timeouts, add an offset to match the
1036 * initval's 64us ack timeout value. Use 48us for the CTS timeout.
1037 * This was initially only meant to work around an issue with delayed
1038 * BA frames in some implementations, but it has been found to fix ACK
1039 * timeout issues in other cases as well.
1041 if (IS_CHAN_2GHZ(chan) &&
1042 !IS_CHAN_HALF_RATE(chan) && !IS_CHAN_QUARTER_RATE(chan)) {
1043 acktimeout += 64 - sifstime - ah->slottime;
1044 ctstimeout += 48 - sifstime - ah->slottime;
1047 ath9k_hw_set_sifs_time(ah, sifstime);
1048 ath9k_hw_setslottime(ah, slottime);
1049 ath9k_hw_set_ack_timeout(ah, acktimeout);
1050 ath9k_hw_set_cts_timeout(ah, ctstimeout);
1051 if (ah->globaltxtimeout != (u32) -1)
1052 ath9k_hw_set_global_txtimeout(ah, ah->globaltxtimeout);
1054 REG_WRITE(ah, AR_D_GBL_IFS_EIFS, ath9k_hw_mac_to_clks(ah, eifs));
1055 REG_RMW(ah, AR_USEC,
1056 (common->clockrate - 1) |
1057 SM(rx_lat, AR_USEC_RX_LAT) |
1058 SM(tx_lat, AR_USEC_TX_LAT),
1059 AR_USEC_TX_LAT | AR_USEC_RX_LAT | AR_USEC_USEC);
1062 EXPORT_SYMBOL(ath9k_hw_init_global_settings);
1064 void ath9k_hw_deinit(struct ath_hw *ah)
1066 struct ath_common *common = ath9k_hw_common(ah);
1068 if (common->state < ATH_HW_INITIALIZED)
1071 ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
1073 EXPORT_SYMBOL(ath9k_hw_deinit);
1079 u32 ath9k_regd_get_ctl(struct ath_regulatory *reg, struct ath9k_channel *chan)
1081 u32 ctl = ath_regd_get_band_ctl(reg, chan->chan->band);
1083 if (IS_CHAN_2GHZ(chan))
1091 /****************************************/
1092 /* Reset and Channel Switching Routines */
1093 /****************************************/
1095 static inline void ath9k_hw_set_dma(struct ath_hw *ah)
1097 struct ath_common *common = ath9k_hw_common(ah);
1100 ENABLE_REGWRITE_BUFFER(ah);
1103 * set AHB_MODE not to do cacheline prefetches
1105 if (!AR_SREV_9300_20_OR_LATER(ah))
1106 REG_SET_BIT(ah, AR_AHB_MODE, AR_AHB_PREFETCH_RD_EN);
1109 * let mac dma reads be in 128 byte chunks
1111 REG_RMW(ah, AR_TXCFG, AR_TXCFG_DMASZ_128B, AR_TXCFG_DMASZ_MASK);
1113 REGWRITE_BUFFER_FLUSH(ah);
1116 * Restore TX Trigger Level to its pre-reset value.
1117 * The initial value depends on whether aggregation is enabled, and is
1118 * adjusted whenever underruns are detected.
1120 if (!AR_SREV_9300_20_OR_LATER(ah))
1121 REG_RMW_FIELD(ah, AR_TXCFG, AR_FTRIG, ah->tx_trig_level);
1123 ENABLE_REGWRITE_BUFFER(ah);
1126 * let mac dma writes be in 128 byte chunks
1128 REG_RMW(ah, AR_RXCFG, AR_RXCFG_DMASZ_128B, AR_RXCFG_DMASZ_MASK);
1131 * Setup receive FIFO threshold to hold off TX activities
1133 REG_WRITE(ah, AR_RXFIFO_CFG, 0x200);
1135 if (AR_SREV_9300_20_OR_LATER(ah)) {
1136 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_HP, 0x1);
1137 REG_RMW_FIELD(ah, AR_RXBP_THRESH, AR_RXBP_THRESH_LP, 0x1);
1139 ath9k_hw_set_rx_bufsize(ah, common->rx_bufsize -
1140 ah->caps.rx_status_len);
1144 * reduce the number of usable entries in PCU TXBUF to avoid
1145 * wrap around issues.
1147 if (AR_SREV_9285(ah)) {
1148 /* For AR9285 the number of Fifos are reduced to half.
1149 * So set the usable tx buf size also to half to
1150 * avoid data/delimiter underruns
1152 txbuf_size = AR_9285_PCU_TXBUF_CTRL_USABLE_SIZE;
1153 } else if (AR_SREV_9340_13_OR_LATER(ah)) {
1154 /* Uses fewer entries for AR934x v1.3+ to prevent rx overruns */
1155 txbuf_size = AR_9340_PCU_TXBUF_CTRL_USABLE_SIZE;
1157 txbuf_size = AR_PCU_TXBUF_CTRL_USABLE_SIZE;
1160 if (!AR_SREV_9271(ah))
1161 REG_WRITE(ah, AR_PCU_TXBUF_CTRL, txbuf_size);
1163 REGWRITE_BUFFER_FLUSH(ah);
1165 if (AR_SREV_9300_20_OR_LATER(ah))
1166 ath9k_hw_reset_txstatus_ring(ah);
1169 static void ath9k_hw_set_operating_mode(struct ath_hw *ah, int opmode)
1171 u32 mask = AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC;
1172 u32 set = AR_STA_ID1_KSRCH_MODE;
1175 case NL80211_IFTYPE_ADHOC:
1176 set |= AR_STA_ID1_ADHOC;
1177 REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1179 case NL80211_IFTYPE_MESH_POINT:
1180 case NL80211_IFTYPE_AP:
1181 set |= AR_STA_ID1_STA_AP;
1183 case NL80211_IFTYPE_STATION:
1184 REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
1187 if (!ah->is_monitoring)
1191 REG_RMW(ah, AR_STA_ID1, set, mask);
1194 void ath9k_hw_get_delta_slope_vals(struct ath_hw *ah, u32 coef_scaled,
1195 u32 *coef_mantissa, u32 *coef_exponent)
1197 u32 coef_exp, coef_man;
1199 for (coef_exp = 31; coef_exp > 0; coef_exp--)
1200 if ((coef_scaled >> coef_exp) & 0x1)
1203 coef_exp = 14 - (coef_exp - COEF_SCALE_S);
1205 coef_man = coef_scaled + (1 << (COEF_SCALE_S - coef_exp - 1));
1207 *coef_mantissa = coef_man >> (COEF_SCALE_S - coef_exp);
1208 *coef_exponent = coef_exp - 16;
1212 * call external reset function to reset WMAC if:
1213 * - doing a cold reset
1214 * - we have pending frames in the TX queues.
1216 static bool ath9k_hw_ar9330_reset_war(struct ath_hw *ah, int type)
1220 for (i = 0; i < AR_NUM_QCU; i++) {
1221 npend = ath9k_hw_numtxpending(ah, i);
1226 if (ah->external_reset &&
1227 (npend || type == ATH9K_RESET_COLD)) {
1230 ath_dbg(ath9k_hw_common(ah), RESET,
1231 "reset MAC via external reset\n");
1233 reset_err = ah->external_reset();
1235 ath_err(ath9k_hw_common(ah),
1236 "External reset failed, err=%d\n",
1241 REG_WRITE(ah, AR_RTC_RESET, 1);
1247 static bool ath9k_hw_set_reset(struct ath_hw *ah, int type)
1252 if (AR_SREV_9100(ah)) {
1253 REG_RMW_FIELD(ah, AR_RTC_DERIVED_CLK,
1254 AR_RTC_DERIVED_CLK_PERIOD, 1);
1255 (void)REG_READ(ah, AR_RTC_DERIVED_CLK);
1258 ENABLE_REGWRITE_BUFFER(ah);
1260 if (AR_SREV_9300_20_OR_LATER(ah)) {
1261 REG_WRITE(ah, AR_WA, ah->WARegVal);
1265 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1266 AR_RTC_FORCE_WAKE_ON_INT);
1268 if (AR_SREV_9100(ah)) {
1269 rst_flags = AR_RTC_RC_MAC_WARM | AR_RTC_RC_MAC_COLD |
1270 AR_RTC_RC_COLD_RESET | AR_RTC_RC_WARM_RESET;
1272 tmpReg = REG_READ(ah, AR_INTR_SYNC_CAUSE);
1273 if (AR_SREV_9340(ah))
1274 tmpReg &= AR9340_INTR_SYNC_LOCAL_TIMEOUT;
1276 tmpReg &= AR_INTR_SYNC_LOCAL_TIMEOUT |
1277 AR_INTR_SYNC_RADM_CPL_TIMEOUT;
1281 REG_WRITE(ah, AR_INTR_SYNC_ENABLE, 0);
1284 if (!AR_SREV_9300_20_OR_LATER(ah))
1286 REG_WRITE(ah, AR_RC, val);
1288 } else if (!AR_SREV_9300_20_OR_LATER(ah))
1289 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1291 rst_flags = AR_RTC_RC_MAC_WARM;
1292 if (type == ATH9K_RESET_COLD)
1293 rst_flags |= AR_RTC_RC_MAC_COLD;
1296 if (AR_SREV_9330(ah)) {
1297 if (!ath9k_hw_ar9330_reset_war(ah, type))
1301 if (ath9k_hw_mci_is_enabled(ah))
1302 ar9003_mci_check_gpm_offset(ah);
1304 REG_WRITE(ah, AR_RTC_RC, rst_flags);
1306 REGWRITE_BUFFER_FLUSH(ah);
1308 if (AR_SREV_9300_20_OR_LATER(ah))
1310 else if (AR_SREV_9100(ah))
1315 REG_WRITE(ah, AR_RTC_RC, 0);
1316 if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0, AH_WAIT_TIMEOUT)) {
1317 ath_dbg(ath9k_hw_common(ah), RESET, "RTC stuck in MAC reset\n");
1321 if (!AR_SREV_9100(ah))
1322 REG_WRITE(ah, AR_RC, 0);
1324 if (AR_SREV_9100(ah))
1330 static bool ath9k_hw_set_reset_power_on(struct ath_hw *ah)
1332 ENABLE_REGWRITE_BUFFER(ah);
1334 if (AR_SREV_9300_20_OR_LATER(ah)) {
1335 REG_WRITE(ah, AR_WA, ah->WARegVal);
1339 REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
1340 AR_RTC_FORCE_WAKE_ON_INT);
1342 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
1343 REG_WRITE(ah, AR_RC, AR_RC_AHB);
1345 REG_WRITE(ah, AR_RTC_RESET, 0);
1347 REGWRITE_BUFFER_FLUSH(ah);
1351 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
1352 REG_WRITE(ah, AR_RC, 0);
1354 REG_WRITE(ah, AR_RTC_RESET, 1);
1356 if (!ath9k_hw_wait(ah,
1361 ath_dbg(ath9k_hw_common(ah), RESET, "RTC not waking up\n");
1365 return ath9k_hw_set_reset(ah, ATH9K_RESET_WARM);
1368 static bool ath9k_hw_set_reset_reg(struct ath_hw *ah, u32 type)
1372 if (AR_SREV_9300_20_OR_LATER(ah)) {
1373 REG_WRITE(ah, AR_WA, ah->WARegVal);
1377 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1378 AR_RTC_FORCE_WAKE_EN | AR_RTC_FORCE_WAKE_ON_INT);
1380 if (!ah->reset_power_on)
1381 type = ATH9K_RESET_POWER_ON;
1384 case ATH9K_RESET_POWER_ON:
1385 ret = ath9k_hw_set_reset_power_on(ah);
1387 ah->reset_power_on = true;
1389 case ATH9K_RESET_WARM:
1390 case ATH9K_RESET_COLD:
1391 ret = ath9k_hw_set_reset(ah, type);
1400 static bool ath9k_hw_chip_reset(struct ath_hw *ah,
1401 struct ath9k_channel *chan)
1403 int reset_type = ATH9K_RESET_WARM;
1405 if (AR_SREV_9280(ah)) {
1406 if (ah->eep_ops->get_eeprom(ah, EEP_OL_PWRCTRL))
1407 reset_type = ATH9K_RESET_POWER_ON;
1409 reset_type = ATH9K_RESET_COLD;
1410 } else if (ah->chip_fullsleep || REG_READ(ah, AR_Q_TXE) ||
1411 (REG_READ(ah, AR_CR) & AR_CR_RXE))
1412 reset_type = ATH9K_RESET_COLD;
1414 if (!ath9k_hw_set_reset_reg(ah, reset_type))
1417 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1420 ah->chip_fullsleep = false;
1422 if (AR_SREV_9330(ah))
1423 ar9003_hw_internal_regulator_apply(ah);
1424 ath9k_hw_init_pll(ah, chan);
1429 static bool ath9k_hw_channel_change(struct ath_hw *ah,
1430 struct ath9k_channel *chan)
1432 struct ath_common *common = ath9k_hw_common(ah);
1433 struct ath9k_hw_capabilities *pCap = &ah->caps;
1434 bool band_switch = false, mode_diff = false;
1435 u8 ini_reloaded = 0;
1439 if (pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) {
1440 u32 flags_diff = chan->channelFlags ^ ah->curchan->channelFlags;
1441 band_switch = !!(flags_diff & CHANNEL_5GHZ);
1442 mode_diff = !!(flags_diff & ~CHANNEL_HT);
1445 for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
1446 if (ath9k_hw_numtxpending(ah, qnum)) {
1447 ath_dbg(common, QUEUE,
1448 "Transmit frames pending on queue %d\n", qnum);
1453 if (!ath9k_hw_rfbus_req(ah)) {
1454 ath_err(common, "Could not kill baseband RX\n");
1458 if (band_switch || mode_diff) {
1459 ath9k_hw_mark_phy_inactive(ah);
1463 ath9k_hw_init_pll(ah, chan);
1465 if (ath9k_hw_fast_chan_change(ah, chan, &ini_reloaded)) {
1466 ath_err(common, "Failed to do fast channel change\n");
1471 ath9k_hw_set_channel_regs(ah, chan);
1473 r = ath9k_hw_rf_set_freq(ah, chan);
1475 ath_err(common, "Failed to set channel\n");
1478 ath9k_hw_set_clockrate(ah);
1479 ath9k_hw_apply_txpower(ah, chan, false);
1481 ath9k_hw_set_delta_slope(ah, chan);
1482 ath9k_hw_spur_mitigate_freq(ah, chan);
1484 if (band_switch || ini_reloaded)
1485 ah->eep_ops->set_board_values(ah, chan);
1487 ath9k_hw_init_bb(ah, chan);
1488 ath9k_hw_rfbus_done(ah);
1490 if (band_switch || ini_reloaded) {
1491 ah->ah_flags |= AH_FASTCC;
1492 ath9k_hw_init_cal(ah, chan);
1493 ah->ah_flags &= ~AH_FASTCC;
1499 static void ath9k_hw_apply_gpio_override(struct ath_hw *ah)
1501 u32 gpio_mask = ah->gpio_mask;
1504 for (i = 0; gpio_mask; i++, gpio_mask >>= 1) {
1505 if (!(gpio_mask & 1))
1508 ath9k_hw_cfg_output(ah, i, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
1509 ath9k_hw_set_gpio(ah, i, !!(ah->gpio_val & BIT(i)));
1513 void ath9k_hw_check_nav(struct ath_hw *ah)
1515 struct ath_common *common = ath9k_hw_common(ah);
1518 val = REG_READ(ah, AR_NAV);
1519 if (val != 0xdeadbeef && val > 0x7fff) {
1520 ath_dbg(common, BSTUCK, "Abnormal NAV: 0x%x\n", val);
1521 REG_WRITE(ah, AR_NAV, 0);
1524 EXPORT_SYMBOL(ath9k_hw_check_nav);
1526 bool ath9k_hw_check_alive(struct ath_hw *ah)
1531 if (AR_SREV_9300(ah))
1532 return !ath9k_hw_detect_mac_hang(ah);
1534 if (AR_SREV_9285_12_OR_LATER(ah))
1538 reg = REG_READ(ah, AR_OBS_BUS_1);
1540 if ((reg & 0x7E7FFFEF) == 0x00702400)
1543 switch (reg & 0x7E000B00) {
1551 } while (count-- > 0);
1555 EXPORT_SYMBOL(ath9k_hw_check_alive);
1557 static void ath9k_hw_init_mfp(struct ath_hw *ah)
1559 /* Setup MFP options for CCMP */
1560 if (AR_SREV_9280_20_OR_LATER(ah)) {
1561 /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
1562 * frames when constructing CCMP AAD. */
1563 REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
1565 ah->sw_mgmt_crypto = false;
1566 } else if (AR_SREV_9160_10_OR_LATER(ah)) {
1567 /* Disable hardware crypto for management frames */
1568 REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
1569 AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
1570 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1571 AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
1572 ah->sw_mgmt_crypto = true;
1574 ah->sw_mgmt_crypto = true;
1578 static void ath9k_hw_reset_opmode(struct ath_hw *ah,
1579 u32 macStaId1, u32 saveDefAntenna)
1581 struct ath_common *common = ath9k_hw_common(ah);
1583 ENABLE_REGWRITE_BUFFER(ah);
1585 REG_RMW(ah, AR_STA_ID1, macStaId1
1586 | AR_STA_ID1_RTS_USE_DEF
1587 | ah->sta_id1_defaults,
1588 ~AR_STA_ID1_SADH_MASK);
1589 ath_hw_setbssidmask(common);
1590 REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
1591 ath9k_hw_write_associd(ah);
1592 REG_WRITE(ah, AR_ISR, ~0);
1593 REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
1595 REGWRITE_BUFFER_FLUSH(ah);
1597 ath9k_hw_set_operating_mode(ah, ah->opmode);
1600 static void ath9k_hw_init_queues(struct ath_hw *ah)
1604 ENABLE_REGWRITE_BUFFER(ah);
1606 for (i = 0; i < AR_NUM_DCU; i++)
1607 REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
1609 REGWRITE_BUFFER_FLUSH(ah);
1612 for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
1613 ath9k_hw_resettxqueue(ah, i);
1617 * For big endian systems turn on swapping for descriptors
1619 static void ath9k_hw_init_desc(struct ath_hw *ah)
1621 struct ath_common *common = ath9k_hw_common(ah);
1623 if (AR_SREV_9100(ah)) {
1625 mask = REG_READ(ah, AR_CFG);
1626 if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
1627 ath_dbg(common, RESET, "CFG Byte Swap Set 0x%x\n",
1630 mask = INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
1631 REG_WRITE(ah, AR_CFG, mask);
1632 ath_dbg(common, RESET, "Setting CFG 0x%x\n",
1633 REG_READ(ah, AR_CFG));
1636 if (common->bus_ops->ath_bus_type == ATH_USB) {
1637 /* Configure AR9271 target WLAN */
1638 if (AR_SREV_9271(ah))
1639 REG_WRITE(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB);
1641 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1644 else if (AR_SREV_9330(ah) || AR_SREV_9340(ah) ||
1645 AR_SREV_9550(ah) || AR_SREV_9531(ah))
1646 REG_RMW(ah, AR_CFG, AR_CFG_SWRB | AR_CFG_SWTB, 0);
1648 REG_WRITE(ah, AR_CFG, AR_CFG_SWTD | AR_CFG_SWRD);
1654 * Fast channel change:
1655 * (Change synthesizer based on channel freq without resetting chip)
1657 static int ath9k_hw_do_fastcc(struct ath_hw *ah, struct ath9k_channel *chan)
1659 struct ath_common *common = ath9k_hw_common(ah);
1660 struct ath9k_hw_capabilities *pCap = &ah->caps;
1663 if (AR_SREV_9280(ah) && common->bus_ops->ath_bus_type == ATH_PCI)
1666 if (ah->chip_fullsleep)
1672 if (chan->channel == ah->curchan->channel)
1675 if ((ah->curchan->channelFlags | chan->channelFlags) &
1676 (CHANNEL_HALF | CHANNEL_QUARTER))
1680 * If cross-band fcc is not supoprted, bail out if channelFlags differ.
1682 if (!(pCap->hw_caps & ATH9K_HW_CAP_FCC_BAND_SWITCH) &&
1683 ((chan->channelFlags ^ ah->curchan->channelFlags) & ~CHANNEL_HT))
1686 if (!ath9k_hw_check_alive(ah))
1690 * For AR9462, make sure that calibration data for
1691 * re-using are present.
1693 if (AR_SREV_9462(ah) && (ah->caldata &&
1694 (!test_bit(TXIQCAL_DONE, &ah->caldata->cal_flags) ||
1695 !test_bit(TXCLCAL_DONE, &ah->caldata->cal_flags) ||
1696 !test_bit(RTT_DONE, &ah->caldata->cal_flags))))
1699 ath_dbg(common, RESET, "FastChannelChange for %d -> %d\n",
1700 ah->curchan->channel, chan->channel);
1702 ret = ath9k_hw_channel_change(ah, chan);
1706 if (ath9k_hw_mci_is_enabled(ah))
1707 ar9003_mci_2g5g_switch(ah, false);
1709 ath9k_hw_loadnf(ah, ah->curchan);
1710 ath9k_hw_start_nfcal(ah, true);
1712 if (AR_SREV_9271(ah))
1713 ar9002_hw_load_ani_reg(ah, chan);
1720 int ath9k_hw_reset(struct ath_hw *ah, struct ath9k_channel *chan,
1721 struct ath9k_hw_cal_data *caldata, bool fastcc)
1723 struct ath_common *common = ath9k_hw_common(ah);
1731 bool start_mci_reset = false;
1732 bool save_fullsleep = ah->chip_fullsleep;
1734 if (ath9k_hw_mci_is_enabled(ah)) {
1735 start_mci_reset = ar9003_mci_start_reset(ah, chan);
1736 if (start_mci_reset)
1740 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
1743 if (ah->curchan && !ah->chip_fullsleep)
1744 ath9k_hw_getnf(ah, ah->curchan);
1746 ah->caldata = caldata;
1747 if (caldata && (chan->channel != caldata->channel ||
1748 chan->channelFlags != caldata->channelFlags)) {
1749 /* Operating channel changed, reset channel calibration data */
1750 memset(caldata, 0, sizeof(*caldata));
1751 ath9k_init_nfcal_hist_buffer(ah, chan);
1752 } else if (caldata) {
1753 clear_bit(PAPRD_PACKET_SENT, &caldata->cal_flags);
1755 ah->noise = ath9k_hw_getchan_noise(ah, chan, chan->noisefloor);
1758 r = ath9k_hw_do_fastcc(ah, chan);
1763 if (ath9k_hw_mci_is_enabled(ah))
1764 ar9003_mci_stop_bt(ah, save_fullsleep);
1766 saveDefAntenna = REG_READ(ah, AR_DEF_ANTENNA);
1767 if (saveDefAntenna == 0)
1770 macStaId1 = REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B;
1772 /* Save TSF before chip reset, a cold reset clears it */
1773 tsf = ath9k_hw_gettsf64(ah);
1774 getrawmonotonic(&ts);
1775 usec = ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000;
1777 saveLedState = REG_READ(ah, AR_CFG_LED) &
1778 (AR_CFG_LED_ASSOC_CTL | AR_CFG_LED_MODE_SEL |
1779 AR_CFG_LED_BLINK_THRESH_SEL | AR_CFG_LED_BLINK_SLOW);
1781 ath9k_hw_mark_phy_inactive(ah);
1783 ah->paprd_table_write_done = false;
1785 /* Only required on the first reset */
1786 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1788 AR9271_RESET_POWER_DOWN_CONTROL,
1789 AR9271_RADIO_RF_RST);
1793 if (!ath9k_hw_chip_reset(ah, chan)) {
1794 ath_err(common, "Chip reset failed\n");
1798 /* Only required on the first reset */
1799 if (AR_SREV_9271(ah) && ah->htc_reset_init) {
1800 ah->htc_reset_init = false;
1802 AR9271_RESET_POWER_DOWN_CONTROL,
1803 AR9271_GATE_MAC_CTL);
1808 getrawmonotonic(&ts);
1809 usec = ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000 - usec;
1810 ath9k_hw_settsf64(ah, tsf + usec);
1812 if (AR_SREV_9280_20_OR_LATER(ah))
1813 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
1815 if (!AR_SREV_9300_20_OR_LATER(ah))
1816 ar9002_hw_enable_async_fifo(ah);
1818 r = ath9k_hw_process_ini(ah, chan);
1822 ath9k_hw_set_rfmode(ah, chan);
1824 if (ath9k_hw_mci_is_enabled(ah))
1825 ar9003_mci_reset(ah, false, IS_CHAN_2GHZ(chan), save_fullsleep);
1828 * Some AR91xx SoC devices frequently fail to accept TSF writes
1829 * right after the chip reset. When that happens, write a new
1830 * value after the initvals have been applied, with an offset
1831 * based on measured time difference
1833 if (AR_SREV_9100(ah) && (ath9k_hw_gettsf64(ah) < tsf)) {
1835 ath9k_hw_settsf64(ah, tsf);
1838 ath9k_hw_init_mfp(ah);
1840 ath9k_hw_set_delta_slope(ah, chan);
1841 ath9k_hw_spur_mitigate_freq(ah, chan);
1842 ah->eep_ops->set_board_values(ah, chan);
1844 ath9k_hw_reset_opmode(ah, macStaId1, saveDefAntenna);
1846 r = ath9k_hw_rf_set_freq(ah, chan);
1850 ath9k_hw_set_clockrate(ah);
1852 ath9k_hw_init_queues(ah);
1853 ath9k_hw_init_interrupt_masks(ah, ah->opmode);
1854 ath9k_hw_ani_cache_ini_regs(ah);
1855 ath9k_hw_init_qos(ah);
1857 if (ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
1858 ath9k_hw_cfg_gpio_input(ah, ah->rfkill_gpio);
1860 ath9k_hw_init_global_settings(ah);
1862 if (AR_SREV_9287(ah) && AR_SREV_9287_13_OR_LATER(ah)) {
1863 REG_SET_BIT(ah, AR_MAC_PCU_LOGIC_ANALYZER,
1864 AR_MAC_PCU_LOGIC_ANALYZER_DISBUG20768);
1865 REG_RMW_FIELD(ah, AR_AHB_MODE, AR_AHB_CUSTOM_BURST_EN,
1866 AR_AHB_CUSTOM_BURST_ASYNC_FIFO_VAL);
1867 REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
1868 AR_PCU_MISC_MODE2_ENABLE_AGGWEP);
1871 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM);
1873 ath9k_hw_set_dma(ah);
1875 if (!ath9k_hw_mci_is_enabled(ah))
1876 REG_WRITE(ah, AR_OBS, 8);
1878 if (ah->config.rx_intr_mitigation) {
1879 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_LAST, 500);
1880 REG_RMW_FIELD(ah, AR_RIMT, AR_RIMT_FIRST, 2000);
1883 if (ah->config.tx_intr_mitigation) {
1884 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_LAST, 300);
1885 REG_RMW_FIELD(ah, AR_TIMT, AR_TIMT_FIRST, 750);
1888 ath9k_hw_init_bb(ah, chan);
1891 clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
1892 clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
1894 if (!ath9k_hw_init_cal(ah, chan))
1897 if (ath9k_hw_mci_is_enabled(ah) && ar9003_mci_end_reset(ah, chan, caldata))
1900 ENABLE_REGWRITE_BUFFER(ah);
1902 ath9k_hw_restore_chainmask(ah);
1903 REG_WRITE(ah, AR_CFG_LED, saveLedState | AR_CFG_SCLK_32KHZ);
1905 REGWRITE_BUFFER_FLUSH(ah);
1907 ath9k_hw_init_desc(ah);
1909 if (ath9k_hw_btcoex_is_enabled(ah))
1910 ath9k_hw_btcoex_enable(ah);
1912 if (ath9k_hw_mci_is_enabled(ah))
1913 ar9003_mci_check_bt(ah);
1915 ath9k_hw_loadnf(ah, chan);
1916 ath9k_hw_start_nfcal(ah, true);
1918 if (AR_SREV_9300_20_OR_LATER(ah))
1919 ar9003_hw_bb_watchdog_config(ah);
1921 if (ah->config.hw_hang_checks & HW_PHYRESTART_CLC_WAR)
1922 ar9003_hw_disable_phy_restart(ah);
1924 ath9k_hw_apply_gpio_override(ah);
1926 if (AR_SREV_9565(ah) && common->bt_ant_diversity)
1927 REG_SET_BIT(ah, AR_BTCOEX_WL_LNADIV, AR_BTCOEX_WL_LNADIV_FORCE_ON);
1931 EXPORT_SYMBOL(ath9k_hw_reset);
1933 /******************************/
1934 /* Power Management (Chipset) */
1935 /******************************/
1938 * Notify Power Mgt is disabled in self-generated frames.
1939 * If requested, force chip to sleep.
1941 static void ath9k_set_power_sleep(struct ath_hw *ah)
1943 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1945 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
1946 REG_CLR_BIT(ah, AR_TIMER_MODE, 0xff);
1947 REG_CLR_BIT(ah, AR_NDP2_TIMER_MODE, 0xff);
1948 REG_CLR_BIT(ah, AR_SLP32_INC, 0xfffff);
1949 /* xxx Required for WLAN only case ? */
1950 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
1955 * Clear the RTC force wake bit to allow the
1956 * mac to go to sleep.
1958 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
1960 if (ath9k_hw_mci_is_enabled(ah))
1963 if (!AR_SREV_9100(ah) && !AR_SREV_9300_20_OR_LATER(ah))
1964 REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
1966 /* Shutdown chip. Active low */
1967 if (!AR_SREV_5416(ah) && !AR_SREV_9271(ah)) {
1968 REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
1972 /* Clear Bit 14 of AR_WA after putting chip into Full Sleep mode. */
1973 if (AR_SREV_9300_20_OR_LATER(ah))
1974 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
1978 * Notify Power Management is enabled in self-generating
1979 * frames. If request, set power mode of chip to
1980 * auto/normal. Duration in units of 128us (1/8 TU).
1982 static void ath9k_set_power_network_sleep(struct ath_hw *ah)
1984 struct ath9k_hw_capabilities *pCap = &ah->caps;
1986 REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
1988 if (!(pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)) {
1989 /* Set WakeOnInterrupt bit; clear ForceWake bit */
1990 REG_WRITE(ah, AR_RTC_FORCE_WAKE,
1991 AR_RTC_FORCE_WAKE_ON_INT);
1994 /* When chip goes into network sleep, it could be waken
1995 * up by MCI_INT interrupt caused by BT's HW messages
1996 * (LNA_xxx, CONT_xxx) which chould be in a very fast
1997 * rate (~100us). This will cause chip to leave and
1998 * re-enter network sleep mode frequently, which in
1999 * consequence will have WLAN MCI HW to generate lots of
2000 * SYS_WAKING and SYS_SLEEPING messages which will make
2001 * BT CPU to busy to process.
2003 if (ath9k_hw_mci_is_enabled(ah))
2004 REG_CLR_BIT(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
2005 AR_MCI_INTERRUPT_RX_HW_MSG_MASK);
2007 * Clear the RTC force wake bit to allow the
2008 * mac to go to sleep.
2010 REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
2012 if (ath9k_hw_mci_is_enabled(ah))
2016 /* Clear Bit 14 of AR_WA after putting chip into Net Sleep mode. */
2017 if (AR_SREV_9300_20_OR_LATER(ah))
2018 REG_WRITE(ah, AR_WA, ah->WARegVal & ~AR_WA_D3_L1_DISABLE);
2021 static bool ath9k_hw_set_power_awake(struct ath_hw *ah)
2026 /* Set Bits 14 and 17 of AR_WA before powering on the chip. */
2027 if (AR_SREV_9300_20_OR_LATER(ah)) {
2028 REG_WRITE(ah, AR_WA, ah->WARegVal);
2032 if ((REG_READ(ah, AR_RTC_STATUS) &
2033 AR_RTC_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
2034 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
2037 if (!AR_SREV_9300_20_OR_LATER(ah))
2038 ath9k_hw_init_pll(ah, NULL);
2040 if (AR_SREV_9100(ah))
2041 REG_SET_BIT(ah, AR_RTC_RESET,
2044 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2045 AR_RTC_FORCE_WAKE_EN);
2047 if (AR_SREV_9100(ah))
2052 for (i = POWER_UP_TIME / 50; i > 0; i--) {
2053 val = REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
2054 if (val == AR_RTC_STATUS_ON)
2057 REG_SET_BIT(ah, AR_RTC_FORCE_WAKE,
2058 AR_RTC_FORCE_WAKE_EN);
2061 ath_err(ath9k_hw_common(ah),
2062 "Failed to wakeup in %uus\n",
2063 POWER_UP_TIME / 20);
2067 if (ath9k_hw_mci_is_enabled(ah))
2068 ar9003_mci_set_power_awake(ah);
2070 REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
2075 bool ath9k_hw_setpower(struct ath_hw *ah, enum ath9k_power_mode mode)
2077 struct ath_common *common = ath9k_hw_common(ah);
2079 static const char *modes[] = {
2086 if (ah->power_mode == mode)
2089 ath_dbg(common, RESET, "%s -> %s\n",
2090 modes[ah->power_mode], modes[mode]);
2093 case ATH9K_PM_AWAKE:
2094 status = ath9k_hw_set_power_awake(ah);
2096 case ATH9K_PM_FULL_SLEEP:
2097 if (ath9k_hw_mci_is_enabled(ah))
2098 ar9003_mci_set_full_sleep(ah);
2100 ath9k_set_power_sleep(ah);
2101 ah->chip_fullsleep = true;
2103 case ATH9K_PM_NETWORK_SLEEP:
2104 ath9k_set_power_network_sleep(ah);
2107 ath_err(common, "Unknown power mode %u\n", mode);
2110 ah->power_mode = mode;
2113 * XXX: If this warning never comes up after a while then
2114 * simply keep the ATH_DBG_WARN_ON_ONCE() but make
2115 * ath9k_hw_setpower() return type void.
2118 if (!(ah->ah_flags & AH_UNPLUGGED))
2119 ATH_DBG_WARN_ON_ONCE(!status);
2123 EXPORT_SYMBOL(ath9k_hw_setpower);
2125 /*******************/
2126 /* Beacon Handling */
2127 /*******************/
2129 void ath9k_hw_beaconinit(struct ath_hw *ah, u32 next_beacon, u32 beacon_period)
2133 ENABLE_REGWRITE_BUFFER(ah);
2135 switch (ah->opmode) {
2136 case NL80211_IFTYPE_ADHOC:
2137 REG_SET_BIT(ah, AR_TXCFG,
2138 AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
2139 case NL80211_IFTYPE_MESH_POINT:
2140 case NL80211_IFTYPE_AP:
2141 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, next_beacon);
2142 REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, next_beacon -
2143 TU_TO_USEC(ah->config.dma_beacon_response_time));
2144 REG_WRITE(ah, AR_NEXT_SWBA, next_beacon -
2145 TU_TO_USEC(ah->config.sw_beacon_response_time));
2147 AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
2150 ath_dbg(ath9k_hw_common(ah), BEACON,
2151 "%s: unsupported opmode: %d\n", __func__, ah->opmode);
2156 REG_WRITE(ah, AR_BEACON_PERIOD, beacon_period);
2157 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, beacon_period);
2158 REG_WRITE(ah, AR_SWBA_PERIOD, beacon_period);
2160 REGWRITE_BUFFER_FLUSH(ah);
2162 REG_SET_BIT(ah, AR_TIMER_MODE, flags);
2164 EXPORT_SYMBOL(ath9k_hw_beaconinit);
2166 void ath9k_hw_set_sta_beacon_timers(struct ath_hw *ah,
2167 const struct ath9k_beacon_state *bs)
2169 u32 nextTbtt, beaconintval, dtimperiod, beacontimeout;
2170 struct ath9k_hw_capabilities *pCap = &ah->caps;
2171 struct ath_common *common = ath9k_hw_common(ah);
2173 ENABLE_REGWRITE_BUFFER(ah);
2175 REG_WRITE(ah, AR_NEXT_TBTT_TIMER, bs->bs_nexttbtt);
2176 REG_WRITE(ah, AR_BEACON_PERIOD, bs->bs_intval);
2177 REG_WRITE(ah, AR_DMA_BEACON_PERIOD, bs->bs_intval);
2179 REGWRITE_BUFFER_FLUSH(ah);
2181 REG_RMW_FIELD(ah, AR_RSSI_THR,
2182 AR_RSSI_THR_BM_THR, bs->bs_bmissthreshold);
2184 beaconintval = bs->bs_intval;
2186 if (bs->bs_sleepduration > beaconintval)
2187 beaconintval = bs->bs_sleepduration;
2189 dtimperiod = bs->bs_dtimperiod;
2190 if (bs->bs_sleepduration > dtimperiod)
2191 dtimperiod = bs->bs_sleepduration;
2193 if (beaconintval == dtimperiod)
2194 nextTbtt = bs->bs_nextdtim;
2196 nextTbtt = bs->bs_nexttbtt;
2198 ath_dbg(common, BEACON, "next DTIM %d\n", bs->bs_nextdtim);
2199 ath_dbg(common, BEACON, "next beacon %d\n", nextTbtt);
2200 ath_dbg(common, BEACON, "beacon period %d\n", beaconintval);
2201 ath_dbg(common, BEACON, "DTIM period %d\n", dtimperiod);
2203 ENABLE_REGWRITE_BUFFER(ah);
2205 REG_WRITE(ah, AR_NEXT_DTIM, bs->bs_nextdtim - SLEEP_SLOP);
2206 REG_WRITE(ah, AR_NEXT_TIM, nextTbtt - SLEEP_SLOP);
2208 REG_WRITE(ah, AR_SLEEP1,
2209 SM((CAB_TIMEOUT_VAL << 3), AR_SLEEP1_CAB_TIMEOUT)
2210 | AR_SLEEP1_ASSUME_DTIM);
2212 if (pCap->hw_caps & ATH9K_HW_CAP_AUTOSLEEP)
2213 beacontimeout = (BEACON_TIMEOUT_VAL << 3);
2215 beacontimeout = MIN_BEACON_TIMEOUT_VAL;
2217 REG_WRITE(ah, AR_SLEEP2,
2218 SM(beacontimeout, AR_SLEEP2_BEACON_TIMEOUT));
2220 REG_WRITE(ah, AR_TIM_PERIOD, beaconintval);
2221 REG_WRITE(ah, AR_DTIM_PERIOD, dtimperiod);
2223 REGWRITE_BUFFER_FLUSH(ah);
2225 REG_SET_BIT(ah, AR_TIMER_MODE,
2226 AR_TBTT_TIMER_EN | AR_TIM_TIMER_EN |
2229 /* TSF Out of Range Threshold */
2230 REG_WRITE(ah, AR_TSFOOR_THRESHOLD, bs->bs_tsfoor_threshold);
2232 EXPORT_SYMBOL(ath9k_hw_set_sta_beacon_timers);
2234 /*******************/
2235 /* HW Capabilities */
2236 /*******************/
2238 static u8 fixup_chainmask(u8 chip_chainmask, u8 eeprom_chainmask)
2240 eeprom_chainmask &= chip_chainmask;
2241 if (eeprom_chainmask)
2242 return eeprom_chainmask;
2244 return chip_chainmask;
2248 * ath9k_hw_dfs_tested - checks if DFS has been tested with used chipset
2249 * @ah: the atheros hardware data structure
2251 * We enable DFS support upstream on chipsets which have passed a series
2252 * of tests. The testing requirements are going to be documented. Desired
2253 * test requirements are documented at:
2255 * http://wireless.kernel.org/en/users/Drivers/ath9k/dfs
2257 * Once a new chipset gets properly tested an individual commit can be used
2258 * to document the testing for DFS for that chipset.
2260 static bool ath9k_hw_dfs_tested(struct ath_hw *ah)
2263 switch (ah->hw_version.macVersion) {
2264 /* for temporary testing DFS with 9280 */
2265 case AR_SREV_VERSION_9280:
2266 /* AR9580 will likely be our first target to get testing on */
2267 case AR_SREV_VERSION_9580:
2274 int ath9k_hw_fill_cap_info(struct ath_hw *ah)
2276 struct ath9k_hw_capabilities *pCap = &ah->caps;
2277 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
2278 struct ath_common *common = ath9k_hw_common(ah);
2279 unsigned int chip_chainmask;
2282 u8 ant_div_ctl1, tx_chainmask, rx_chainmask;
2284 eeval = ah->eep_ops->get_eeprom(ah, EEP_REG_0);
2285 regulatory->current_rd = eeval;
2287 if (ah->opmode != NL80211_IFTYPE_AP &&
2288 ah->hw_version.subvendorid == AR_SUBVENDOR_ID_NEW_A) {
2289 if (regulatory->current_rd == 0x64 ||
2290 regulatory->current_rd == 0x65)
2291 regulatory->current_rd += 5;
2292 else if (regulatory->current_rd == 0x41)
2293 regulatory->current_rd = 0x43;
2294 ath_dbg(common, REGULATORY, "regdomain mapped to 0x%x\n",
2295 regulatory->current_rd);
2298 eeval = ah->eep_ops->get_eeprom(ah, EEP_OP_MODE);
2299 if ((eeval & (AR5416_OPFLAGS_11G | AR5416_OPFLAGS_11A)) == 0) {
2301 "no band has been marked as supported in EEPROM\n");
2305 if (eeval & AR5416_OPFLAGS_11A)
2306 pCap->hw_caps |= ATH9K_HW_CAP_5GHZ;
2308 if (eeval & AR5416_OPFLAGS_11G)
2309 pCap->hw_caps |= ATH9K_HW_CAP_2GHZ;
2311 if (AR_SREV_9485(ah) ||
2316 else if (AR_SREV_9462(ah))
2318 else if (!AR_SREV_9280_20_OR_LATER(ah))
2320 else if (!AR_SREV_9300_20_OR_LATER(ah) || AR_SREV_9340(ah))
2325 pCap->tx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_TX_MASK);
2327 * For AR9271 we will temporarilly uses the rx chainmax as read from
2330 if ((ah->hw_version.devid == AR5416_DEVID_PCI) &&
2331 !(eeval & AR5416_OPFLAGS_11A) &&
2332 !(AR_SREV_9271(ah)))
2333 /* CB71: GPIO 0 is pulled down to indicate 3 rx chains */
2334 pCap->rx_chainmask = ath9k_hw_gpio_get(ah, 0) ? 0x5 : 0x7;
2335 else if (AR_SREV_9100(ah))
2336 pCap->rx_chainmask = 0x7;
2338 /* Use rx_chainmask from EEPROM. */
2339 pCap->rx_chainmask = ah->eep_ops->get_eeprom(ah, EEP_RX_MASK);
2341 pCap->tx_chainmask = fixup_chainmask(chip_chainmask, pCap->tx_chainmask);
2342 pCap->rx_chainmask = fixup_chainmask(chip_chainmask, pCap->rx_chainmask);
2343 ah->txchainmask = pCap->tx_chainmask;
2344 ah->rxchainmask = pCap->rx_chainmask;
2346 ah->misc_mode |= AR_PCU_MIC_NEW_LOC_ENA;
2348 /* enable key search for every frame in an aggregate */
2349 if (AR_SREV_9300_20_OR_LATER(ah))
2350 ah->misc_mode |= AR_PCU_ALWAYS_PERFORM_KEYSEARCH;
2352 common->crypt_caps |= ATH_CRYPT_CAP_CIPHER_AESCCM;
2354 if (ah->hw_version.devid != AR2427_DEVID_PCIE)
2355 pCap->hw_caps |= ATH9K_HW_CAP_HT;
2357 pCap->hw_caps &= ~ATH9K_HW_CAP_HT;
2359 if (AR_SREV_9271(ah))
2360 pCap->num_gpio_pins = AR9271_NUM_GPIO;
2361 else if (AR_DEVID_7010(ah))
2362 pCap->num_gpio_pins = AR7010_NUM_GPIO;
2363 else if (AR_SREV_9300_20_OR_LATER(ah))
2364 pCap->num_gpio_pins = AR9300_NUM_GPIO;
2365 else if (AR_SREV_9287_11_OR_LATER(ah))
2366 pCap->num_gpio_pins = AR9287_NUM_GPIO;
2367 else if (AR_SREV_9285_12_OR_LATER(ah))
2368 pCap->num_gpio_pins = AR9285_NUM_GPIO;
2369 else if (AR_SREV_9280_20_OR_LATER(ah))
2370 pCap->num_gpio_pins = AR928X_NUM_GPIO;
2372 pCap->num_gpio_pins = AR_NUM_GPIO;
2374 if (AR_SREV_9160_10_OR_LATER(ah) || AR_SREV_9100(ah))
2375 pCap->rts_aggr_limit = ATH_AMPDU_LIMIT_MAX;
2377 pCap->rts_aggr_limit = (8 * 1024);
2379 #ifdef CONFIG_ATH9K_RFKILL
2380 ah->rfsilent = ah->eep_ops->get_eeprom(ah, EEP_RF_SILENT);
2381 if (ah->rfsilent & EEP_RFSILENT_ENABLED) {
2383 MS(ah->rfsilent, EEP_RFSILENT_GPIO_SEL);
2384 ah->rfkill_polarity =
2385 MS(ah->rfsilent, EEP_RFSILENT_POLARITY);
2387 pCap->hw_caps |= ATH9K_HW_CAP_RFSILENT;
2390 if (AR_SREV_9271(ah) || AR_SREV_9300_20_OR_LATER(ah))
2391 pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
2393 pCap->hw_caps &= ~ATH9K_HW_CAP_AUTOSLEEP;
2395 if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
2396 pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
2398 pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
2400 if (AR_SREV_9300_20_OR_LATER(ah)) {
2401 pCap->hw_caps |= ATH9K_HW_CAP_EDMA | ATH9K_HW_CAP_FASTCLOCK;
2402 if (!AR_SREV_9330(ah) && !AR_SREV_9485(ah) && !AR_SREV_9565(ah))
2403 pCap->hw_caps |= ATH9K_HW_CAP_LDPC;
2405 pCap->rx_hp_qdepth = ATH9K_HW_RX_HP_QDEPTH;
2406 pCap->rx_lp_qdepth = ATH9K_HW_RX_LP_QDEPTH;
2407 pCap->rx_status_len = sizeof(struct ar9003_rxs);
2408 pCap->tx_desc_len = sizeof(struct ar9003_txc);
2409 pCap->txs_len = sizeof(struct ar9003_txs);
2411 pCap->tx_desc_len = sizeof(struct ath_desc);
2412 if (AR_SREV_9280_20(ah))
2413 pCap->hw_caps |= ATH9K_HW_CAP_FASTCLOCK;
2416 if (AR_SREV_9300_20_OR_LATER(ah))
2417 pCap->hw_caps |= ATH9K_HW_CAP_RAC_SUPPORTED;
2419 if (AR_SREV_9300_20_OR_LATER(ah))
2420 ah->ent_mode = REG_READ(ah, AR_ENT_OTP);
2422 if (AR_SREV_9287_11_OR_LATER(ah) || AR_SREV_9271(ah))
2423 pCap->hw_caps |= ATH9K_HW_CAP_SGI_20;
2425 if (AR_SREV_9285(ah)) {
2426 if (ah->eep_ops->get_eeprom(ah, EEP_MODAL_VER) >= 3) {
2428 ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2429 if ((ant_div_ctl1 & 0x1) && ((ant_div_ctl1 >> 3) & 0x1)) {
2430 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2431 ath_info(common, "Enable LNA combining\n");
2436 if (AR_SREV_9300_20_OR_LATER(ah)) {
2437 if (ah->eep_ops->get_eeprom(ah, EEP_CHAIN_MASK_REDUCE))
2438 pCap->hw_caps |= ATH9K_HW_CAP_APM;
2441 if (AR_SREV_9330(ah) || AR_SREV_9485(ah) || AR_SREV_9565(ah)) {
2442 ant_div_ctl1 = ah->eep_ops->get_eeprom(ah, EEP_ANT_DIV_CTL1);
2443 if ((ant_div_ctl1 >> 0x6) == 0x3) {
2444 pCap->hw_caps |= ATH9K_HW_CAP_ANT_DIV_COMB;
2445 ath_info(common, "Enable LNA combining\n");
2449 if (ath9k_hw_dfs_tested(ah))
2450 pCap->hw_caps |= ATH9K_HW_CAP_DFS;
2452 tx_chainmask = pCap->tx_chainmask;
2453 rx_chainmask = pCap->rx_chainmask;
2454 while (tx_chainmask || rx_chainmask) {
2455 if (tx_chainmask & BIT(0))
2456 pCap->max_txchains++;
2457 if (rx_chainmask & BIT(0))
2458 pCap->max_rxchains++;
2464 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
2465 if (!(ah->ent_mode & AR_ENT_OTP_49GHZ_DISABLE))
2466 pCap->hw_caps |= ATH9K_HW_CAP_MCI;
2468 if (AR_SREV_9462_20_OR_LATER(ah))
2469 pCap->hw_caps |= ATH9K_HW_CAP_RTT;
2472 if (AR_SREV_9462(ah))
2473 pCap->hw_caps |= ATH9K_HW_WOW_DEVICE_CAPABLE;
2475 if (AR_SREV_9300_20_OR_LATER(ah) &&
2476 ah->eep_ops->get_eeprom(ah, EEP_PAPRD))
2477 pCap->hw_caps |= ATH9K_HW_CAP_PAPRD;
2482 /****************************/
2483 /* GPIO / RFKILL / Antennae */
2484 /****************************/
2486 static void ath9k_hw_gpio_cfg_output_mux(struct ath_hw *ah,
2490 u32 gpio_shift, tmp;
2493 addr = AR_GPIO_OUTPUT_MUX3;
2495 addr = AR_GPIO_OUTPUT_MUX2;
2497 addr = AR_GPIO_OUTPUT_MUX1;
2499 gpio_shift = (gpio % 6) * 5;
2501 if (AR_SREV_9280_20_OR_LATER(ah)
2502 || (addr != AR_GPIO_OUTPUT_MUX1)) {
2503 REG_RMW(ah, addr, (type << gpio_shift),
2504 (0x1f << gpio_shift));
2506 tmp = REG_READ(ah, addr);
2507 tmp = ((tmp & 0x1F0) << 1) | (tmp & ~0x1F0);
2508 tmp &= ~(0x1f << gpio_shift);
2509 tmp |= (type << gpio_shift);
2510 REG_WRITE(ah, addr, tmp);
2514 void ath9k_hw_cfg_gpio_input(struct ath_hw *ah, u32 gpio)
2518 BUG_ON(gpio >= ah->caps.num_gpio_pins);
2520 if (AR_DEVID_7010(ah)) {
2522 REG_RMW(ah, AR7010_GPIO_OE,
2523 (AR7010_GPIO_OE_AS_INPUT << gpio_shift),
2524 (AR7010_GPIO_OE_MASK << gpio_shift));
2528 gpio_shift = gpio << 1;
2531 (AR_GPIO_OE_OUT_DRV_NO << gpio_shift),
2532 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2534 EXPORT_SYMBOL(ath9k_hw_cfg_gpio_input);
2536 u32 ath9k_hw_gpio_get(struct ath_hw *ah, u32 gpio)
2538 #define MS_REG_READ(x, y) \
2539 (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
2541 if (gpio >= ah->caps.num_gpio_pins)
2544 if (AR_DEVID_7010(ah)) {
2546 val = REG_READ(ah, AR7010_GPIO_IN);
2547 return (MS(val, AR7010_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) == 0;
2548 } else if (AR_SREV_9300_20_OR_LATER(ah))
2549 return (MS(REG_READ(ah, AR_GPIO_IN), AR9300_GPIO_IN_VAL) &
2550 AR_GPIO_BIT(gpio)) != 0;
2551 else if (AR_SREV_9271(ah))
2552 return MS_REG_READ(AR9271, gpio) != 0;
2553 else if (AR_SREV_9287_11_OR_LATER(ah))
2554 return MS_REG_READ(AR9287, gpio) != 0;
2555 else if (AR_SREV_9285_12_OR_LATER(ah))
2556 return MS_REG_READ(AR9285, gpio) != 0;
2557 else if (AR_SREV_9280_20_OR_LATER(ah))
2558 return MS_REG_READ(AR928X, gpio) != 0;
2560 return MS_REG_READ(AR, gpio) != 0;
2562 EXPORT_SYMBOL(ath9k_hw_gpio_get);
2564 void ath9k_hw_cfg_output(struct ath_hw *ah, u32 gpio,
2569 if (AR_DEVID_7010(ah)) {
2571 REG_RMW(ah, AR7010_GPIO_OE,
2572 (AR7010_GPIO_OE_AS_OUTPUT << gpio_shift),
2573 (AR7010_GPIO_OE_MASK << gpio_shift));
2577 ath9k_hw_gpio_cfg_output_mux(ah, gpio, ah_signal_type);
2578 gpio_shift = 2 * gpio;
2581 (AR_GPIO_OE_OUT_DRV_ALL << gpio_shift),
2582 (AR_GPIO_OE_OUT_DRV << gpio_shift));
2584 EXPORT_SYMBOL(ath9k_hw_cfg_output);
2586 void ath9k_hw_set_gpio(struct ath_hw *ah, u32 gpio, u32 val)
2588 if (AR_DEVID_7010(ah)) {
2590 REG_RMW(ah, AR7010_GPIO_OUT, ((val&1) << gpio),
2595 if (AR_SREV_9271(ah))
2598 REG_RMW(ah, AR_GPIO_IN_OUT, ((val & 1) << gpio),
2601 EXPORT_SYMBOL(ath9k_hw_set_gpio);
2603 void ath9k_hw_setantenna(struct ath_hw *ah, u32 antenna)
2605 REG_WRITE(ah, AR_DEF_ANTENNA, (antenna & 0x7));
2607 EXPORT_SYMBOL(ath9k_hw_setantenna);
2609 /*********************/
2610 /* General Operation */
2611 /*********************/
2613 u32 ath9k_hw_getrxfilter(struct ath_hw *ah)
2615 u32 bits = REG_READ(ah, AR_RX_FILTER);
2616 u32 phybits = REG_READ(ah, AR_PHY_ERR);
2618 if (phybits & AR_PHY_ERR_RADAR)
2619 bits |= ATH9K_RX_FILTER_PHYRADAR;
2620 if (phybits & (AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING))
2621 bits |= ATH9K_RX_FILTER_PHYERR;
2625 EXPORT_SYMBOL(ath9k_hw_getrxfilter);
2627 void ath9k_hw_setrxfilter(struct ath_hw *ah, u32 bits)
2631 ENABLE_REGWRITE_BUFFER(ah);
2633 if (AR_SREV_9462(ah) || AR_SREV_9565(ah))
2634 bits |= ATH9K_RX_FILTER_CONTROL_WRAPPER;
2636 REG_WRITE(ah, AR_RX_FILTER, bits);
2639 if (bits & ATH9K_RX_FILTER_PHYRADAR)
2640 phybits |= AR_PHY_ERR_RADAR;
2641 if (bits & ATH9K_RX_FILTER_PHYERR)
2642 phybits |= AR_PHY_ERR_OFDM_TIMING | AR_PHY_ERR_CCK_TIMING;
2643 REG_WRITE(ah, AR_PHY_ERR, phybits);
2646 REG_SET_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
2648 REG_CLR_BIT(ah, AR_RXCFG, AR_RXCFG_ZLFDMA);
2650 REGWRITE_BUFFER_FLUSH(ah);
2652 EXPORT_SYMBOL(ath9k_hw_setrxfilter);
2654 bool ath9k_hw_phy_disable(struct ath_hw *ah)
2656 if (ath9k_hw_mci_is_enabled(ah))
2657 ar9003_mci_bt_gain_ctrl(ah);
2659 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_WARM))
2662 ath9k_hw_init_pll(ah, NULL);
2663 ah->htc_reset_init = true;
2666 EXPORT_SYMBOL(ath9k_hw_phy_disable);
2668 bool ath9k_hw_disable(struct ath_hw *ah)
2670 if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
2673 if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_COLD))
2676 ath9k_hw_init_pll(ah, NULL);
2679 EXPORT_SYMBOL(ath9k_hw_disable);
2681 static int get_antenna_gain(struct ath_hw *ah, struct ath9k_channel *chan)
2683 enum eeprom_param gain_param;
2685 if (IS_CHAN_2GHZ(chan))
2686 gain_param = EEP_ANTENNA_GAIN_2G;
2688 gain_param = EEP_ANTENNA_GAIN_5G;
2690 return ah->eep_ops->get_eeprom(ah, gain_param);
2693 void ath9k_hw_apply_txpower(struct ath_hw *ah, struct ath9k_channel *chan,
2696 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2697 struct ieee80211_channel *channel;
2698 int chan_pwr, new_pwr, max_gain;
2699 int ant_gain, ant_reduction = 0;
2704 channel = chan->chan;
2705 chan_pwr = min_t(int, channel->max_power * 2, MAX_RATE_POWER);
2706 new_pwr = min_t(int, chan_pwr, reg->power_limit);
2707 max_gain = chan_pwr - new_pwr + channel->max_antenna_gain * 2;
2709 ant_gain = get_antenna_gain(ah, chan);
2710 if (ant_gain > max_gain)
2711 ant_reduction = ant_gain - max_gain;
2713 ah->eep_ops->set_txpower(ah, chan,
2714 ath9k_regd_get_ctl(reg, chan),
2715 ant_reduction, new_pwr, test);
2718 void ath9k_hw_set_txpowerlimit(struct ath_hw *ah, u32 limit, bool test)
2720 struct ath_regulatory *reg = ath9k_hw_regulatory(ah);
2721 struct ath9k_channel *chan = ah->curchan;
2722 struct ieee80211_channel *channel = chan->chan;
2724 reg->power_limit = min_t(u32, limit, MAX_RATE_POWER);
2726 channel->max_power = MAX_RATE_POWER / 2;
2728 ath9k_hw_apply_txpower(ah, chan, test);
2731 channel->max_power = DIV_ROUND_UP(reg->max_power_level, 2);
2733 EXPORT_SYMBOL(ath9k_hw_set_txpowerlimit);
2735 void ath9k_hw_setopmode(struct ath_hw *ah)
2737 ath9k_hw_set_operating_mode(ah, ah->opmode);
2739 EXPORT_SYMBOL(ath9k_hw_setopmode);
2741 void ath9k_hw_setmcastfilter(struct ath_hw *ah, u32 filter0, u32 filter1)
2743 REG_WRITE(ah, AR_MCAST_FIL0, filter0);
2744 REG_WRITE(ah, AR_MCAST_FIL1, filter1);
2746 EXPORT_SYMBOL(ath9k_hw_setmcastfilter);
2748 void ath9k_hw_write_associd(struct ath_hw *ah)
2750 struct ath_common *common = ath9k_hw_common(ah);
2752 REG_WRITE(ah, AR_BSS_ID0, get_unaligned_le32(common->curbssid));
2753 REG_WRITE(ah, AR_BSS_ID1, get_unaligned_le16(common->curbssid + 4) |
2754 ((common->curaid & 0x3fff) << AR_BSS_ID1_AID_S));
2756 EXPORT_SYMBOL(ath9k_hw_write_associd);
2758 #define ATH9K_MAX_TSF_READ 10
2760 u64 ath9k_hw_gettsf64(struct ath_hw *ah)
2762 u32 tsf_lower, tsf_upper1, tsf_upper2;
2765 tsf_upper1 = REG_READ(ah, AR_TSF_U32);
2766 for (i = 0; i < ATH9K_MAX_TSF_READ; i++) {
2767 tsf_lower = REG_READ(ah, AR_TSF_L32);
2768 tsf_upper2 = REG_READ(ah, AR_TSF_U32);
2769 if (tsf_upper2 == tsf_upper1)
2771 tsf_upper1 = tsf_upper2;
2774 WARN_ON( i == ATH9K_MAX_TSF_READ );
2776 return (((u64)tsf_upper1 << 32) | tsf_lower);
2778 EXPORT_SYMBOL(ath9k_hw_gettsf64);
2780 void ath9k_hw_settsf64(struct ath_hw *ah, u64 tsf64)
2782 REG_WRITE(ah, AR_TSF_L32, tsf64 & 0xffffffff);
2783 REG_WRITE(ah, AR_TSF_U32, (tsf64 >> 32) & 0xffffffff);
2785 EXPORT_SYMBOL(ath9k_hw_settsf64);
2787 void ath9k_hw_reset_tsf(struct ath_hw *ah)
2789 if (!ath9k_hw_wait(ah, AR_SLP32_MODE, AR_SLP32_TSF_WRITE_STATUS, 0,
2790 AH_TSF_WRITE_TIMEOUT))
2791 ath_dbg(ath9k_hw_common(ah), RESET,
2792 "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
2794 REG_WRITE(ah, AR_RESET_TSF, AR_RESET_TSF_ONCE);
2796 EXPORT_SYMBOL(ath9k_hw_reset_tsf);
2798 void ath9k_hw_set_tsfadjust(struct ath_hw *ah, bool set)
2801 ah->misc_mode |= AR_PCU_TX_ADD_TSF;
2803 ah->misc_mode &= ~AR_PCU_TX_ADD_TSF;
2805 EXPORT_SYMBOL(ath9k_hw_set_tsfadjust);
2807 void ath9k_hw_set11nmac2040(struct ath_hw *ah, struct ath9k_channel *chan)
2811 if (IS_CHAN_HT40(chan) && !ah->config.cwm_ignore_extcca)
2812 macmode = AR_2040_JOINED_RX_CLEAR;
2816 REG_WRITE(ah, AR_2040_MODE, macmode);
2819 /* HW Generic timers configuration */
2821 static const struct ath_gen_timer_configuration gen_tmr_configuration[] =
2823 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2824 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2825 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2826 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2827 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2828 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2829 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2830 {AR_NEXT_NDP_TIMER, AR_NDP_PERIOD, AR_TIMER_MODE, 0x0080},
2831 {AR_NEXT_NDP2_TIMER, AR_NDP2_PERIOD, AR_NDP2_TIMER_MODE, 0x0001},
2832 {AR_NEXT_NDP2_TIMER + 1*4, AR_NDP2_PERIOD + 1*4,
2833 AR_NDP2_TIMER_MODE, 0x0002},
2834 {AR_NEXT_NDP2_TIMER + 2*4, AR_NDP2_PERIOD + 2*4,
2835 AR_NDP2_TIMER_MODE, 0x0004},
2836 {AR_NEXT_NDP2_TIMER + 3*4, AR_NDP2_PERIOD + 3*4,
2837 AR_NDP2_TIMER_MODE, 0x0008},
2838 {AR_NEXT_NDP2_TIMER + 4*4, AR_NDP2_PERIOD + 4*4,
2839 AR_NDP2_TIMER_MODE, 0x0010},
2840 {AR_NEXT_NDP2_TIMER + 5*4, AR_NDP2_PERIOD + 5*4,
2841 AR_NDP2_TIMER_MODE, 0x0020},
2842 {AR_NEXT_NDP2_TIMER + 6*4, AR_NDP2_PERIOD + 6*4,
2843 AR_NDP2_TIMER_MODE, 0x0040},
2844 {AR_NEXT_NDP2_TIMER + 7*4, AR_NDP2_PERIOD + 7*4,
2845 AR_NDP2_TIMER_MODE, 0x0080}
2848 /* HW generic timer primitives */
2850 u32 ath9k_hw_gettsf32(struct ath_hw *ah)
2852 return REG_READ(ah, AR_TSF_L32);
2854 EXPORT_SYMBOL(ath9k_hw_gettsf32);
2856 struct ath_gen_timer *ath_gen_timer_alloc(struct ath_hw *ah,
2857 void (*trigger)(void *),
2858 void (*overflow)(void *),
2862 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2863 struct ath_gen_timer *timer;
2865 if ((timer_index < AR_FIRST_NDP_TIMER) ||
2866 (timer_index >= ATH_MAX_GEN_TIMER))
2869 timer = kzalloc(sizeof(struct ath_gen_timer), GFP_KERNEL);
2873 /* allocate a hardware generic timer slot */
2874 timer_table->timers[timer_index] = timer;
2875 timer->index = timer_index;
2876 timer->trigger = trigger;
2877 timer->overflow = overflow;
2882 EXPORT_SYMBOL(ath_gen_timer_alloc);
2884 void ath9k_hw_gen_timer_start(struct ath_hw *ah,
2885 struct ath_gen_timer *timer,
2889 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2892 timer_table->timer_mask |= BIT(timer->index);
2895 * Program generic timer registers
2897 REG_WRITE(ah, gen_tmr_configuration[timer->index].next_addr,
2899 REG_WRITE(ah, gen_tmr_configuration[timer->index].period_addr,
2901 REG_SET_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2902 gen_tmr_configuration[timer->index].mode_mask);
2904 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
2906 * Starting from AR9462, each generic timer can select which tsf
2907 * to use. But we still follow the old rule, 0 - 7 use tsf and
2910 if ((timer->index < AR_GEN_TIMER_BANK_1_LEN))
2911 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2912 (1 << timer->index));
2914 REG_SET_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2915 (1 << timer->index));
2919 mask |= SM(AR_GENTMR_BIT(timer->index),
2920 AR_IMR_S5_GENTIMER_TRIG);
2921 if (timer->overflow)
2922 mask |= SM(AR_GENTMR_BIT(timer->index),
2923 AR_IMR_S5_GENTIMER_THRESH);
2925 REG_SET_BIT(ah, AR_IMR_S5, mask);
2927 if ((ah->imask & ATH9K_INT_GENTIMER) == 0) {
2928 ah->imask |= ATH9K_INT_GENTIMER;
2929 ath9k_hw_set_interrupts(ah);
2932 EXPORT_SYMBOL(ath9k_hw_gen_timer_start);
2934 void ath9k_hw_gen_timer_stop(struct ath_hw *ah, struct ath_gen_timer *timer)
2936 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2938 /* Clear generic timer enable bits. */
2939 REG_CLR_BIT(ah, gen_tmr_configuration[timer->index].mode_addr,
2940 gen_tmr_configuration[timer->index].mode_mask);
2942 if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) {
2944 * Need to switch back to TSF if it was using TSF2.
2946 if ((timer->index >= AR_GEN_TIMER_BANK_1_LEN)) {
2947 REG_CLR_BIT(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL,
2948 (1 << timer->index));
2952 /* Disable both trigger and thresh interrupt masks */
2953 REG_CLR_BIT(ah, AR_IMR_S5,
2954 (SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_THRESH) |
2955 SM(AR_GENTMR_BIT(timer->index), AR_IMR_S5_GENTIMER_TRIG)));
2957 timer_table->timer_mask &= ~BIT(timer->index);
2959 if (timer_table->timer_mask == 0) {
2960 ah->imask &= ~ATH9K_INT_GENTIMER;
2961 ath9k_hw_set_interrupts(ah);
2964 EXPORT_SYMBOL(ath9k_hw_gen_timer_stop);
2966 void ath_gen_timer_free(struct ath_hw *ah, struct ath_gen_timer *timer)
2968 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2970 /* free the hardware generic timer slot */
2971 timer_table->timers[timer->index] = NULL;
2974 EXPORT_SYMBOL(ath_gen_timer_free);
2977 * Generic Timer Interrupts handling
2979 void ath_gen_timer_isr(struct ath_hw *ah)
2981 struct ath_gen_timer_table *timer_table = &ah->hw_gen_timers;
2982 struct ath_gen_timer *timer;
2983 unsigned long trigger_mask, thresh_mask;
2986 /* get hardware generic timer interrupt status */
2987 trigger_mask = ah->intr_gen_timer_trigger;
2988 thresh_mask = ah->intr_gen_timer_thresh;
2989 trigger_mask &= timer_table->timer_mask;
2990 thresh_mask &= timer_table->timer_mask;
2992 for_each_set_bit(index, &thresh_mask, ARRAY_SIZE(timer_table->timers)) {
2993 timer = timer_table->timers[index];
2996 if (!timer->overflow)
2999 trigger_mask &= ~BIT(index);
3000 timer->overflow(timer->arg);
3003 for_each_set_bit(index, &trigger_mask, ARRAY_SIZE(timer_table->timers)) {
3004 timer = timer_table->timers[index];
3007 if (!timer->trigger)
3009 timer->trigger(timer->arg);
3012 EXPORT_SYMBOL(ath_gen_timer_isr);
3021 } ath_mac_bb_names[] = {
3022 /* Devices with external radios */
3023 { AR_SREV_VERSION_5416_PCI, "5416" },
3024 { AR_SREV_VERSION_5416_PCIE, "5418" },
3025 { AR_SREV_VERSION_9100, "9100" },
3026 { AR_SREV_VERSION_9160, "9160" },
3027 /* Single-chip solutions */
3028 { AR_SREV_VERSION_9280, "9280" },
3029 { AR_SREV_VERSION_9285, "9285" },
3030 { AR_SREV_VERSION_9287, "9287" },
3031 { AR_SREV_VERSION_9271, "9271" },
3032 { AR_SREV_VERSION_9300, "9300" },
3033 { AR_SREV_VERSION_9330, "9330" },
3034 { AR_SREV_VERSION_9340, "9340" },
3035 { AR_SREV_VERSION_9485, "9485" },
3036 { AR_SREV_VERSION_9462, "9462" },
3037 { AR_SREV_VERSION_9550, "9550" },
3038 { AR_SREV_VERSION_9565, "9565" },
3041 /* For devices with external radios */
3045 } ath_rf_names[] = {
3047 { AR_RAD5133_SREV_MAJOR, "5133" },
3048 { AR_RAD5122_SREV_MAJOR, "5122" },
3049 { AR_RAD2133_SREV_MAJOR, "2133" },
3050 { AR_RAD2122_SREV_MAJOR, "2122" }
3054 * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
3056 static const char *ath9k_hw_mac_bb_name(u32 mac_bb_version)
3060 for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
3061 if (ath_mac_bb_names[i].version == mac_bb_version) {
3062 return ath_mac_bb_names[i].name;
3070 * Return the RF name. "????" is returned if the RF is unknown.
3071 * Used for devices with external radios.
3073 static const char *ath9k_hw_rf_name(u16 rf_version)
3077 for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
3078 if (ath_rf_names[i].version == rf_version) {
3079 return ath_rf_names[i].name;
3086 void ath9k_hw_name(struct ath_hw *ah, char *hw_name, size_t len)
3090 /* chipsets >= AR9280 are single-chip */
3091 if (AR_SREV_9280_20_OR_LATER(ah)) {
3092 used = scnprintf(hw_name, len,
3093 "Atheros AR%s Rev:%x",
3094 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3095 ah->hw_version.macRev);
3098 used = scnprintf(hw_name, len,
3099 "Atheros AR%s MAC/BB Rev:%x AR%s RF Rev:%x",
3100 ath9k_hw_mac_bb_name(ah->hw_version.macVersion),
3101 ah->hw_version.macRev,
3102 ath9k_hw_rf_name((ah->hw_version.analog5GhzRev
3103 & AR_RADIO_SREV_MAJOR)),
3104 ah->hw_version.phyRev);
3107 hw_name[used] = '\0';
3109 EXPORT_SYMBOL(ath9k_hw_name);