18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (c) 2012 Qualcomm Atheros, Inc. 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Permission to use, copy, modify, and/or distribute this software for any 58c2ecf20Sopenharmony_ci * purpose with or without fee is hereby granted, provided that the above 68c2ecf20Sopenharmony_ci * copyright notice and this permission notice appear in all copies. 78c2ecf20Sopenharmony_ci * 88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 98c2ecf20Sopenharmony_ci * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 108c2ecf20Sopenharmony_ci * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 118c2ecf20Sopenharmony_ci * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 128c2ecf20Sopenharmony_ci * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 148c2ecf20Sopenharmony_ci * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 158c2ecf20Sopenharmony_ci */ 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci#include <linux/export.h> 188c2ecf20Sopenharmony_ci#include "ath9k.h" 198c2ecf20Sopenharmony_ci#include "reg.h" 208c2ecf20Sopenharmony_ci#include "reg_wow.h" 218c2ecf20Sopenharmony_ci#include "hw-ops.h" 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic void ath9k_hw_set_sta_powersave(struct ath_hw *ah) 248c2ecf20Sopenharmony_ci{ 258c2ecf20Sopenharmony_ci if (!ath9k_hw_mci_is_enabled(ah)) 268c2ecf20Sopenharmony_ci goto set; 278c2ecf20Sopenharmony_ci /* 288c2ecf20Sopenharmony_ci * If MCI is being used, set PWR_SAV only when MCI's 298c2ecf20Sopenharmony_ci * PS state is disabled. 308c2ecf20Sopenharmony_ci */ 318c2ecf20Sopenharmony_ci if (ar9003_mci_state(ah, MCI_STATE_GET_WLAN_PS_STATE) != MCI_PS_DISABLE) 328c2ecf20Sopenharmony_ci return; 338c2ecf20Sopenharmony_ciset: 348c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); 358c2ecf20Sopenharmony_ci} 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic void ath9k_hw_set_powermode_wow_sleep(struct ath_hw *ah) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci ath9k_hw_set_sta_powersave(ah); 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci /* set rx disable bit */ 448c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_CR, AR_CR_RXD); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci if (!ath9k_hw_wait(ah, AR_CR, AR_CR_RXE, 0, AH_WAIT_TIMEOUT)) { 478c2ecf20Sopenharmony_ci ath_err(common, "Failed to stop Rx DMA in 10ms AR_CR=0x%08x AR_DIAG_SW=0x%08x\n", 488c2ecf20Sopenharmony_ci REG_READ(ah, AR_CR), REG_READ(ah, AR_DIAG_SW)); 498c2ecf20Sopenharmony_ci return; 508c2ecf20Sopenharmony_ci } 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci if (AR_SREV_9462(ah) || AR_SREV_9565(ah)) { 538c2ecf20Sopenharmony_ci if (!REG_READ(ah, AR_MAC_PCU_GEN_TIMER_TSF_SEL)) 548c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_DIRECT_CONNECT, AR_DC_TSF2_ENABLE); 558c2ecf20Sopenharmony_ci } else if (AR_SREV_9485(ah)){ 568c2ecf20Sopenharmony_ci if (!(REG_READ(ah, AR_NDP2_TIMER_MODE) & 578c2ecf20Sopenharmony_ci AR_GEN_TIMERS2_MODE_ENABLE_MASK)) 588c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_DIRECT_CONNECT, AR_DC_TSF2_ENABLE); 598c2ecf20Sopenharmony_ci } 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci if (ath9k_hw_mci_is_enabled(ah)) 628c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2); 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_ON_INT); 658c2ecf20Sopenharmony_ci} 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_cistatic void ath9k_wow_create_keep_alive_pattern(struct ath_hw *ah) 688c2ecf20Sopenharmony_ci{ 698c2ecf20Sopenharmony_ci struct ath_common *common = ath9k_hw_common(ah); 708c2ecf20Sopenharmony_ci u8 sta_mac_addr[ETH_ALEN], ap_mac_addr[ETH_ALEN]; 718c2ecf20Sopenharmony_ci u32 ctl[13] = {0}; 728c2ecf20Sopenharmony_ci u32 data_word[KAL_NUM_DATA_WORDS]; 738c2ecf20Sopenharmony_ci u8 i; 748c2ecf20Sopenharmony_ci u32 wow_ka_data_word0; 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci memcpy(sta_mac_addr, common->macaddr, ETH_ALEN); 778c2ecf20Sopenharmony_ci memcpy(ap_mac_addr, common->curbssid, ETH_ALEN); 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_ci /* set the transmit buffer */ 808c2ecf20Sopenharmony_ci ctl[0] = (KAL_FRAME_LEN | (MAX_RATE_POWER << 16)); 818c2ecf20Sopenharmony_ci ctl[1] = 0; 828c2ecf20Sopenharmony_ci ctl[4] = 0; 838c2ecf20Sopenharmony_ci ctl[7] = (ah->txchainmask) << 2; 848c2ecf20Sopenharmony_ci ctl[2] = 0xf << 16; /* tx_tries 0 */ 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci if (IS_CHAN_2GHZ(ah->curchan)) 878c2ecf20Sopenharmony_ci ctl[3] = 0x1b; /* CCK_1M */ 888c2ecf20Sopenharmony_ci else 898c2ecf20Sopenharmony_ci ctl[3] = 0xb; /* OFDM_6M */ 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_ci for (i = 0; i < KAL_NUM_DESC_WORDS; i++) 928c2ecf20Sopenharmony_ci REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + i * 4), ctl[i]); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci data_word[0] = (KAL_FRAME_TYPE << 2) | (KAL_FRAME_SUB_TYPE << 4) | 958c2ecf20Sopenharmony_ci (KAL_TO_DS << 8) | (KAL_DURATION_ID << 16); 968c2ecf20Sopenharmony_ci data_word[1] = (ap_mac_addr[3] << 24) | (ap_mac_addr[2] << 16) | 978c2ecf20Sopenharmony_ci (ap_mac_addr[1] << 8) | (ap_mac_addr[0]); 988c2ecf20Sopenharmony_ci data_word[2] = (sta_mac_addr[1] << 24) | (sta_mac_addr[0] << 16) | 998c2ecf20Sopenharmony_ci (ap_mac_addr[5] << 8) | (ap_mac_addr[4]); 1008c2ecf20Sopenharmony_ci data_word[3] = (sta_mac_addr[5] << 24) | (sta_mac_addr[4] << 16) | 1018c2ecf20Sopenharmony_ci (sta_mac_addr[3] << 8) | (sta_mac_addr[2]); 1028c2ecf20Sopenharmony_ci data_word[4] = (ap_mac_addr[3] << 24) | (ap_mac_addr[2] << 16) | 1038c2ecf20Sopenharmony_ci (ap_mac_addr[1] << 8) | (ap_mac_addr[0]); 1048c2ecf20Sopenharmony_ci data_word[5] = (ap_mac_addr[5] << 8) | (ap_mac_addr[4]); 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci if (AR_SREV_9462_20_OR_LATER(ah) || AR_SREV_9565(ah)) { 1078c2ecf20Sopenharmony_ci /* 1088c2ecf20Sopenharmony_ci * AR9462 2.0 and AR9565 have an extra descriptor word 1098c2ecf20Sopenharmony_ci * (time based discard) compared to other chips. 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_ci REG_WRITE(ah, (AR_WOW_KA_DESC_WORD2 + (12 * 4)), 0); 1128c2ecf20Sopenharmony_ci wow_ka_data_word0 = AR_WOW_TXBUF(13); 1138c2ecf20Sopenharmony_ci } else { 1148c2ecf20Sopenharmony_ci wow_ka_data_word0 = AR_WOW_TXBUF(12); 1158c2ecf20Sopenharmony_ci } 1168c2ecf20Sopenharmony_ci 1178c2ecf20Sopenharmony_ci for (i = 0; i < KAL_NUM_DATA_WORDS; i++) 1188c2ecf20Sopenharmony_ci REG_WRITE(ah, (wow_ka_data_word0 + i*4), data_word[i]); 1198c2ecf20Sopenharmony_ci} 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ciint ath9k_hw_wow_apply_pattern(struct ath_hw *ah, u8 *user_pattern, 1228c2ecf20Sopenharmony_ci u8 *user_mask, int pattern_count, 1238c2ecf20Sopenharmony_ci int pattern_len) 1248c2ecf20Sopenharmony_ci{ 1258c2ecf20Sopenharmony_ci int i; 1268c2ecf20Sopenharmony_ci u32 pattern_val, mask_val; 1278c2ecf20Sopenharmony_ci u32 set, clr; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci if (pattern_count >= ah->wow.max_patterns) 1308c2ecf20Sopenharmony_ci return -ENOSPC; 1318c2ecf20Sopenharmony_ci 1328c2ecf20Sopenharmony_ci if (pattern_count < MAX_NUM_PATTERN_LEGACY) 1338c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_WOW_PATTERN, BIT(pattern_count)); 1348c2ecf20Sopenharmony_ci else 1358c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_MAC_PCU_WOW4, BIT(pattern_count - 8)); 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci for (i = 0; i < MAX_PATTERN_SIZE; i += 4) { 1388c2ecf20Sopenharmony_ci memcpy(&pattern_val, user_pattern, 4); 1398c2ecf20Sopenharmony_ci REG_WRITE(ah, (AR_WOW_TB_PATTERN(pattern_count) + i), 1408c2ecf20Sopenharmony_ci pattern_val); 1418c2ecf20Sopenharmony_ci user_pattern += 4; 1428c2ecf20Sopenharmony_ci } 1438c2ecf20Sopenharmony_ci 1448c2ecf20Sopenharmony_ci for (i = 0; i < MAX_PATTERN_MASK_SIZE; i += 4) { 1458c2ecf20Sopenharmony_ci memcpy(&mask_val, user_mask, 4); 1468c2ecf20Sopenharmony_ci REG_WRITE(ah, (AR_WOW_TB_MASK(pattern_count) + i), mask_val); 1478c2ecf20Sopenharmony_ci user_mask += 4; 1488c2ecf20Sopenharmony_ci } 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci if (pattern_count < MAX_NUM_PATTERN_LEGACY) 1518c2ecf20Sopenharmony_ci ah->wow.wow_event_mask |= 1528c2ecf20Sopenharmony_ci BIT(pattern_count + AR_WOW_PAT_FOUND_SHIFT); 1538c2ecf20Sopenharmony_ci else 1548c2ecf20Sopenharmony_ci ah->wow.wow_event_mask2 |= 1558c2ecf20Sopenharmony_ci BIT((pattern_count - 8) + AR_WOW_PAT_FOUND_SHIFT); 1568c2ecf20Sopenharmony_ci 1578c2ecf20Sopenharmony_ci if (pattern_count < 4) { 1588c2ecf20Sopenharmony_ci set = (pattern_len & AR_WOW_LENGTH_MAX) << 1598c2ecf20Sopenharmony_ci AR_WOW_LEN1_SHIFT(pattern_count); 1608c2ecf20Sopenharmony_ci clr = AR_WOW_LENGTH1_MASK(pattern_count); 1618c2ecf20Sopenharmony_ci REG_RMW(ah, AR_WOW_LENGTH1, set, clr); 1628c2ecf20Sopenharmony_ci } else if (pattern_count < 8) { 1638c2ecf20Sopenharmony_ci set = (pattern_len & AR_WOW_LENGTH_MAX) << 1648c2ecf20Sopenharmony_ci AR_WOW_LEN2_SHIFT(pattern_count); 1658c2ecf20Sopenharmony_ci clr = AR_WOW_LENGTH2_MASK(pattern_count); 1668c2ecf20Sopenharmony_ci REG_RMW(ah, AR_WOW_LENGTH2, set, clr); 1678c2ecf20Sopenharmony_ci } else if (pattern_count < 12) { 1688c2ecf20Sopenharmony_ci set = (pattern_len & AR_WOW_LENGTH_MAX) << 1698c2ecf20Sopenharmony_ci AR_WOW_LEN3_SHIFT(pattern_count); 1708c2ecf20Sopenharmony_ci clr = AR_WOW_LENGTH3_MASK(pattern_count); 1718c2ecf20Sopenharmony_ci REG_RMW(ah, AR_WOW_LENGTH3, set, clr); 1728c2ecf20Sopenharmony_ci } else if (pattern_count < MAX_NUM_PATTERN) { 1738c2ecf20Sopenharmony_ci set = (pattern_len & AR_WOW_LENGTH_MAX) << 1748c2ecf20Sopenharmony_ci AR_WOW_LEN4_SHIFT(pattern_count); 1758c2ecf20Sopenharmony_ci clr = AR_WOW_LENGTH4_MASK(pattern_count); 1768c2ecf20Sopenharmony_ci REG_RMW(ah, AR_WOW_LENGTH4, set, clr); 1778c2ecf20Sopenharmony_ci } 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci return 0; 1808c2ecf20Sopenharmony_ci} 1818c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_wow_apply_pattern); 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ciu32 ath9k_hw_wow_wakeup(struct ath_hw *ah) 1848c2ecf20Sopenharmony_ci{ 1858c2ecf20Sopenharmony_ci u32 wow_status = 0; 1868c2ecf20Sopenharmony_ci u32 val = 0, rval; 1878c2ecf20Sopenharmony_ci 1888c2ecf20Sopenharmony_ci /* 1898c2ecf20Sopenharmony_ci * Read the WoW status register to know 1908c2ecf20Sopenharmony_ci * the wakeup reason. 1918c2ecf20Sopenharmony_ci */ 1928c2ecf20Sopenharmony_ci rval = REG_READ(ah, AR_WOW_PATTERN); 1938c2ecf20Sopenharmony_ci val = AR_WOW_STATUS(rval); 1948c2ecf20Sopenharmony_ci 1958c2ecf20Sopenharmony_ci /* 1968c2ecf20Sopenharmony_ci * Mask only the WoW events that we have enabled. Sometimes 1978c2ecf20Sopenharmony_ci * we have spurious WoW events from the AR_WOW_PATTERN 1988c2ecf20Sopenharmony_ci * register. This mask will clean it up. 1998c2ecf20Sopenharmony_ci */ 2008c2ecf20Sopenharmony_ci val &= ah->wow.wow_event_mask; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci if (val) { 2038c2ecf20Sopenharmony_ci if (val & AR_WOW_MAGIC_PAT_FOUND) 2048c2ecf20Sopenharmony_ci wow_status |= AH_WOW_MAGIC_PATTERN_EN; 2058c2ecf20Sopenharmony_ci if (AR_WOW_PATTERN_FOUND(val)) 2068c2ecf20Sopenharmony_ci wow_status |= AH_WOW_USER_PATTERN_EN; 2078c2ecf20Sopenharmony_ci if (val & AR_WOW_KEEP_ALIVE_FAIL) 2088c2ecf20Sopenharmony_ci wow_status |= AH_WOW_LINK_CHANGE; 2098c2ecf20Sopenharmony_ci if (val & AR_WOW_BEACON_FAIL) 2108c2ecf20Sopenharmony_ci wow_status |= AH_WOW_BEACON_MISS; 2118c2ecf20Sopenharmony_ci } 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci rval = REG_READ(ah, AR_MAC_PCU_WOW4); 2148c2ecf20Sopenharmony_ci val = AR_WOW_STATUS2(rval); 2158c2ecf20Sopenharmony_ci val &= ah->wow.wow_event_mask2; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_ci if (val) { 2188c2ecf20Sopenharmony_ci if (AR_WOW2_PATTERN_FOUND(val)) 2198c2ecf20Sopenharmony_ci wow_status |= AH_WOW_USER_PATTERN_EN; 2208c2ecf20Sopenharmony_ci } 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci /* 2238c2ecf20Sopenharmony_ci * set and clear WOW_PME_CLEAR registers for the chip to 2248c2ecf20Sopenharmony_ci * generate next wow signal. 2258c2ecf20Sopenharmony_ci * disable D3 before accessing other registers ? 2268c2ecf20Sopenharmony_ci */ 2278c2ecf20Sopenharmony_ci 2288c2ecf20Sopenharmony_ci /* do we need to check the bit value 0x01000000 (7-10) ?? */ 2298c2ecf20Sopenharmony_ci REG_RMW(ah, AR_PCIE_PM_CTRL, AR_PMCTRL_WOW_PME_CLR, 2308c2ecf20Sopenharmony_ci AR_PMCTRL_PWR_STATE_D1D3); 2318c2ecf20Sopenharmony_ci 2328c2ecf20Sopenharmony_ci /* 2338c2ecf20Sopenharmony_ci * Clear all events. 2348c2ecf20Sopenharmony_ci */ 2358c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WOW_PATTERN, 2368c2ecf20Sopenharmony_ci AR_WOW_CLEAR_EVENTS(REG_READ(ah, AR_WOW_PATTERN))); 2378c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_MAC_PCU_WOW4, 2388c2ecf20Sopenharmony_ci AR_WOW_CLEAR_EVENTS2(REG_READ(ah, AR_MAC_PCU_WOW4))); 2398c2ecf20Sopenharmony_ci 2408c2ecf20Sopenharmony_ci /* 2418c2ecf20Sopenharmony_ci * restore the beacon threshold to init value 2428c2ecf20Sopenharmony_ci */ 2438c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR); 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci /* 2468c2ecf20Sopenharmony_ci * Restore the way the PCI-E reset, Power-On-Reset, external 2478c2ecf20Sopenharmony_ci * PCIE_POR_SHORT pins are tied to its original value. 2488c2ecf20Sopenharmony_ci * Previously just before WoW sleep, we untie the PCI-E 2498c2ecf20Sopenharmony_ci * reset to our Chip's Power On Reset so that any PCI-E 2508c2ecf20Sopenharmony_ci * reset from the bus will not reset our chip 2518c2ecf20Sopenharmony_ci */ 2528c2ecf20Sopenharmony_ci if (ah->is_pciexpress) 2538c2ecf20Sopenharmony_ci ath9k_hw_configpcipowersave(ah, false); 2548c2ecf20Sopenharmony_ci 2558c2ecf20Sopenharmony_ci if (AR_SREV_9462(ah) || AR_SREV_9565(ah) || AR_SREV_9485(ah)) { 2568c2ecf20Sopenharmony_ci u32 dc = REG_READ(ah, AR_DIRECT_CONNECT); 2578c2ecf20Sopenharmony_ci 2588c2ecf20Sopenharmony_ci if (!(dc & AR_DC_TSF2_ENABLE)) 2598c2ecf20Sopenharmony_ci ath9k_hw_gen_timer_start_tsf2(ah); 2608c2ecf20Sopenharmony_ci } 2618c2ecf20Sopenharmony_ci 2628c2ecf20Sopenharmony_ci ah->wow.wow_event_mask = 0; 2638c2ecf20Sopenharmony_ci ah->wow.wow_event_mask2 = 0; 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci return wow_status; 2668c2ecf20Sopenharmony_ci} 2678c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_wow_wakeup); 2688c2ecf20Sopenharmony_ci 2698c2ecf20Sopenharmony_cistatic void ath9k_hw_wow_set_arwr_reg(struct ath_hw *ah) 2708c2ecf20Sopenharmony_ci{ 2718c2ecf20Sopenharmony_ci u32 wa_reg; 2728c2ecf20Sopenharmony_ci 2738c2ecf20Sopenharmony_ci if (!ah->is_pciexpress) 2748c2ecf20Sopenharmony_ci return; 2758c2ecf20Sopenharmony_ci 2768c2ecf20Sopenharmony_ci /* 2778c2ecf20Sopenharmony_ci * We need to untie the internal POR (power-on-reset) 2788c2ecf20Sopenharmony_ci * to the external PCI-E reset. We also need to tie 2798c2ecf20Sopenharmony_ci * the PCI-E Phy reset to the PCI-E reset. 2808c2ecf20Sopenharmony_ci */ 2818c2ecf20Sopenharmony_ci wa_reg = REG_READ(ah, AR_WA); 2828c2ecf20Sopenharmony_ci wa_reg &= ~AR_WA_UNTIE_RESET_EN; 2838c2ecf20Sopenharmony_ci wa_reg |= AR_WA_RESET_EN; 2848c2ecf20Sopenharmony_ci wa_reg |= AR_WA_POR_SHORT; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WA, wa_reg); 2878c2ecf20Sopenharmony_ci} 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_civoid ath9k_hw_wow_enable(struct ath_hw *ah, u32 pattern_enable) 2908c2ecf20Sopenharmony_ci{ 2918c2ecf20Sopenharmony_ci u32 wow_event_mask; 2928c2ecf20Sopenharmony_ci u32 keep_alive, magic_pattern, host_pm_ctrl; 2938c2ecf20Sopenharmony_ci 2948c2ecf20Sopenharmony_ci wow_event_mask = ah->wow.wow_event_mask; 2958c2ecf20Sopenharmony_ci 2968c2ecf20Sopenharmony_ci /* 2978c2ecf20Sopenharmony_ci * AR_PMCTRL_HOST_PME_EN - Override PME enable in configuration 2988c2ecf20Sopenharmony_ci * space and allow MAC to generate WoW anyway. 2998c2ecf20Sopenharmony_ci * 3008c2ecf20Sopenharmony_ci * AR_PMCTRL_PWR_PM_CTRL_ENA - ??? 3018c2ecf20Sopenharmony_ci * 3028c2ecf20Sopenharmony_ci * AR_PMCTRL_AUX_PWR_DET - PCI core SYS_AUX_PWR_DET signal, 3038c2ecf20Sopenharmony_ci * needs to be set for WoW in PCI mode. 3048c2ecf20Sopenharmony_ci * 3058c2ecf20Sopenharmony_ci * AR_PMCTRL_WOW_PME_CLR - WoW Clear Signal going to the MAC. 3068c2ecf20Sopenharmony_ci * 3078c2ecf20Sopenharmony_ci * Set the power states appropriately and enable PME. 3088c2ecf20Sopenharmony_ci * 3098c2ecf20Sopenharmony_ci * Set and clear WOW_PME_CLEAR for the chip 3108c2ecf20Sopenharmony_ci * to generate next wow signal. 3118c2ecf20Sopenharmony_ci */ 3128c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PCIE_PM_CTRL, AR_PMCTRL_HOST_PME_EN | 3138c2ecf20Sopenharmony_ci AR_PMCTRL_PWR_PM_CTRL_ENA | 3148c2ecf20Sopenharmony_ci AR_PMCTRL_AUX_PWR_DET | 3158c2ecf20Sopenharmony_ci AR_PMCTRL_WOW_PME_CLR); 3168c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PCIE_PM_CTRL, AR_PMCTRL_WOW_PME_CLR); 3178c2ecf20Sopenharmony_ci 3188c2ecf20Sopenharmony_ci /* 3198c2ecf20Sopenharmony_ci * Random Backoff. 3208c2ecf20Sopenharmony_ci * 3218c2ecf20Sopenharmony_ci * 31:28 in AR_WOW_PATTERN : Indicates the number of bits used in the 3228c2ecf20Sopenharmony_ci * contention window. For value N, 3238c2ecf20Sopenharmony_ci * the random backoff will be selected between 3248c2ecf20Sopenharmony_ci * 0 and (2 ^ N) - 1. 3258c2ecf20Sopenharmony_ci */ 3268c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_WOW_PATTERN, 3278c2ecf20Sopenharmony_ci AR_WOW_BACK_OFF_SHIFT(AR_WOW_PAT_BACKOFF)); 3288c2ecf20Sopenharmony_ci 3298c2ecf20Sopenharmony_ci /* 3308c2ecf20Sopenharmony_ci * AIFS time, Slot time, Keep Alive count. 3318c2ecf20Sopenharmony_ci */ 3328c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_WOW_COUNT, AR_WOW_AIFS_CNT(AR_WOW_CNT_AIFS_CNT) | 3338c2ecf20Sopenharmony_ci AR_WOW_SLOT_CNT(AR_WOW_CNT_SLOT_CNT) | 3348c2ecf20Sopenharmony_ci AR_WOW_KEEP_ALIVE_CNT(AR_WOW_CNT_KA_CNT)); 3358c2ecf20Sopenharmony_ci /* 3368c2ecf20Sopenharmony_ci * Beacon timeout. 3378c2ecf20Sopenharmony_ci */ 3388c2ecf20Sopenharmony_ci if (pattern_enable & AH_WOW_BEACON_MISS) 3398c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WOW_BCN_TIMO, AR_WOW_BEACON_TIMO); 3408c2ecf20Sopenharmony_ci else 3418c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WOW_BCN_TIMO, AR_WOW_BEACON_TIMO_MAX); 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci /* 3448c2ecf20Sopenharmony_ci * Keep alive timeout in ms. 3458c2ecf20Sopenharmony_ci */ 3468c2ecf20Sopenharmony_ci if (!pattern_enable) 3478c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WOW_KEEP_ALIVE_TIMO, AR_WOW_KEEP_ALIVE_NEVER); 3488c2ecf20Sopenharmony_ci else 3498c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WOW_KEEP_ALIVE_TIMO, KAL_TIMEOUT * 32); 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci /* 3528c2ecf20Sopenharmony_ci * Keep alive delay in us. 3538c2ecf20Sopenharmony_ci */ 3548c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WOW_KEEP_ALIVE_DELAY, KAL_DELAY * 1000); 3558c2ecf20Sopenharmony_ci 3568c2ecf20Sopenharmony_ci /* 3578c2ecf20Sopenharmony_ci * Create keep alive pattern to respond to beacons. 3588c2ecf20Sopenharmony_ci */ 3598c2ecf20Sopenharmony_ci ath9k_wow_create_keep_alive_pattern(ah); 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci /* 3628c2ecf20Sopenharmony_ci * Configure keep alive register. 3638c2ecf20Sopenharmony_ci */ 3648c2ecf20Sopenharmony_ci keep_alive = REG_READ(ah, AR_WOW_KEEP_ALIVE); 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci /* Send keep alive timeouts anyway */ 3678c2ecf20Sopenharmony_ci keep_alive &= ~AR_WOW_KEEP_ALIVE_AUTO_DIS; 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci if (pattern_enable & AH_WOW_LINK_CHANGE) { 3708c2ecf20Sopenharmony_ci keep_alive &= ~AR_WOW_KEEP_ALIVE_FAIL_DIS; 3718c2ecf20Sopenharmony_ci wow_event_mask |= AR_WOW_KEEP_ALIVE_FAIL; 3728c2ecf20Sopenharmony_ci } else { 3738c2ecf20Sopenharmony_ci keep_alive |= AR_WOW_KEEP_ALIVE_FAIL_DIS; 3748c2ecf20Sopenharmony_ci } 3758c2ecf20Sopenharmony_ci 3768c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WOW_KEEP_ALIVE, keep_alive); 3778c2ecf20Sopenharmony_ci 3788c2ecf20Sopenharmony_ci /* 3798c2ecf20Sopenharmony_ci * We are relying on a bmiss failure, ensure we have 3808c2ecf20Sopenharmony_ci * enough threshold to prevent false positives. 3818c2ecf20Sopenharmony_ci */ 3828c2ecf20Sopenharmony_ci REG_RMW_FIELD(ah, AR_RSSI_THR, AR_RSSI_THR_BM_THR, 3838c2ecf20Sopenharmony_ci AR_WOW_BMISSTHRESHOLD); 3848c2ecf20Sopenharmony_ci 3858c2ecf20Sopenharmony_ci if (pattern_enable & AH_WOW_BEACON_MISS) { 3868c2ecf20Sopenharmony_ci wow_event_mask |= AR_WOW_BEACON_FAIL; 3878c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_WOW_BCN_EN, AR_WOW_BEACON_FAIL_EN); 3888c2ecf20Sopenharmony_ci } else { 3898c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_WOW_BCN_EN, AR_WOW_BEACON_FAIL_EN); 3908c2ecf20Sopenharmony_ci } 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_ci /* 3938c2ecf20Sopenharmony_ci * Enable the magic packet registers. 3948c2ecf20Sopenharmony_ci */ 3958c2ecf20Sopenharmony_ci magic_pattern = REG_READ(ah, AR_WOW_PATTERN); 3968c2ecf20Sopenharmony_ci magic_pattern |= AR_WOW_MAC_INTR_EN; 3978c2ecf20Sopenharmony_ci 3988c2ecf20Sopenharmony_ci if (pattern_enable & AH_WOW_MAGIC_PATTERN_EN) { 3998c2ecf20Sopenharmony_ci magic_pattern |= AR_WOW_MAGIC_EN; 4008c2ecf20Sopenharmony_ci wow_event_mask |= AR_WOW_MAGIC_PAT_FOUND; 4018c2ecf20Sopenharmony_ci } else { 4028c2ecf20Sopenharmony_ci magic_pattern &= ~AR_WOW_MAGIC_EN; 4038c2ecf20Sopenharmony_ci } 4048c2ecf20Sopenharmony_ci 4058c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WOW_PATTERN, magic_pattern); 4068c2ecf20Sopenharmony_ci 4078c2ecf20Sopenharmony_ci /* 4088c2ecf20Sopenharmony_ci * Enable pattern matching for packets which are less 4098c2ecf20Sopenharmony_ci * than 256 bytes. 4108c2ecf20Sopenharmony_ci */ 4118c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_WOW_PATTERN_MATCH_LT_256B, 4128c2ecf20Sopenharmony_ci AR_WOW_PATTERN_SUPPORTED); 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci /* 4158c2ecf20Sopenharmony_ci * Set the power states appropriately and enable PME. 4168c2ecf20Sopenharmony_ci */ 4178c2ecf20Sopenharmony_ci host_pm_ctrl = REG_READ(ah, AR_PCIE_PM_CTRL); 4188c2ecf20Sopenharmony_ci host_pm_ctrl |= AR_PMCTRL_PWR_STATE_D1D3 | 4198c2ecf20Sopenharmony_ci AR_PMCTRL_HOST_PME_EN | 4208c2ecf20Sopenharmony_ci AR_PMCTRL_PWR_PM_CTRL_ENA; 4218c2ecf20Sopenharmony_ci host_pm_ctrl &= ~AR_PCIE_PM_CTRL_ENA; 4228c2ecf20Sopenharmony_ci 4238c2ecf20Sopenharmony_ci if (AR_SREV_9462(ah)) { 4248c2ecf20Sopenharmony_ci /* 4258c2ecf20Sopenharmony_ci * This is needed to prevent the chip waking up 4268c2ecf20Sopenharmony_ci * the host within 3-4 seconds with certain 4278c2ecf20Sopenharmony_ci * platform/BIOS. 4288c2ecf20Sopenharmony_ci */ 4298c2ecf20Sopenharmony_ci host_pm_ctrl &= ~AR_PMCTRL_PWR_STATE_D1D3; 4308c2ecf20Sopenharmony_ci host_pm_ctrl |= AR_PMCTRL_PWR_STATE_D1D3_REAL; 4318c2ecf20Sopenharmony_ci } 4328c2ecf20Sopenharmony_ci 4338c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_PCIE_PM_CTRL, host_pm_ctrl); 4348c2ecf20Sopenharmony_ci 4358c2ecf20Sopenharmony_ci /* 4368c2ecf20Sopenharmony_ci * Enable sequence number generation when asleep. 4378c2ecf20Sopenharmony_ci */ 4388c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PRESERVE_SEQNUM); 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci /* To bring down WOW power low margin */ 4418c2ecf20Sopenharmony_ci REG_SET_BIT(ah, AR_PCIE_PHY_REG3, BIT(13)); 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci ath9k_hw_wow_set_arwr_reg(ah); 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci if (ath9k_hw_mci_is_enabled(ah)) 4468c2ecf20Sopenharmony_ci REG_WRITE(ah, AR_RTC_KEEP_AWAKE, 0x2); 4478c2ecf20Sopenharmony_ci 4488c2ecf20Sopenharmony_ci /* HW WoW */ 4498c2ecf20Sopenharmony_ci REG_CLR_BIT(ah, AR_PCU_MISC_MODE3, BIT(5)); 4508c2ecf20Sopenharmony_ci 4518c2ecf20Sopenharmony_ci ath9k_hw_set_powermode_wow_sleep(ah); 4528c2ecf20Sopenharmony_ci ah->wow.wow_event_mask = wow_event_mask; 4538c2ecf20Sopenharmony_ci} 4548c2ecf20Sopenharmony_ciEXPORT_SYMBOL(ath9k_hw_wow_enable); 455