1*48fa0b4dSLarry Finger // SPDX-License-Identifier: GPL-2.0 2*48fa0b4dSLarry Finger /* Copyright(c) 2009-2012 Realtek Corporation.*/ 3f1d2b4d3SLarry Finger 4f1d2b4d3SLarry Finger #include "../wifi.h" 5f1d2b4d3SLarry Finger #include "../efuse.h" 6f1d2b4d3SLarry Finger #include "../base.h" 7f1d2b4d3SLarry Finger #include "../regd.h" 8f1d2b4d3SLarry Finger #include "../cam.h" 9f1d2b4d3SLarry Finger #include "../ps.h" 10f1d2b4d3SLarry Finger #include "../pci.h" 11f1d2b4d3SLarry Finger #include "reg.h" 12f1d2b4d3SLarry Finger #include "def.h" 13f1d2b4d3SLarry Finger #include "phy.h" 14f1d2b4d3SLarry Finger #include "../rtl8723com/phy_common.h" 15f1d2b4d3SLarry Finger #include "dm.h" 16f1d2b4d3SLarry Finger #include "../rtl8723com/dm_common.h" 17f1d2b4d3SLarry Finger #include "fw.h" 18f1d2b4d3SLarry Finger #include "../rtl8723com/fw_common.h" 19f1d2b4d3SLarry Finger #include "led.h" 20f1d2b4d3SLarry Finger #include "hw.h" 21f1d2b4d3SLarry Finger #include "../pwrseqcmd.h" 22f1d2b4d3SLarry Finger #include "pwrseq.h" 23f1d2b4d3SLarry Finger #include "btc.h" 24f1d2b4d3SLarry Finger 25f1d2b4d3SLarry Finger #define LLT_CONFIG 5 26f1d2b4d3SLarry Finger 27f1d2b4d3SLarry Finger static void _rtl8723e_set_bcn_ctrl_reg(struct ieee80211_hw *hw, 28f1d2b4d3SLarry Finger u8 set_bits, u8 clear_bits) 29f1d2b4d3SLarry Finger { 30f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 31f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 32f1d2b4d3SLarry Finger 33f1d2b4d3SLarry Finger rtlpci->reg_bcn_ctrl_val |= set_bits; 34f1d2b4d3SLarry Finger rtlpci->reg_bcn_ctrl_val &= ~clear_bits; 35f1d2b4d3SLarry Finger 36f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_BCN_CTRL, (u8) rtlpci->reg_bcn_ctrl_val); 37f1d2b4d3SLarry Finger } 38f1d2b4d3SLarry Finger 39f1d2b4d3SLarry Finger static void _rtl8723e_stop_tx_beacon(struct ieee80211_hw *hw) 40f1d2b4d3SLarry Finger { 41f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 42f1d2b4d3SLarry Finger u8 tmp1byte; 43f1d2b4d3SLarry Finger 44f1d2b4d3SLarry Finger tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2); 45f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte & (~BIT(6))); 46f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0x64); 47f1d2b4d3SLarry Finger tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2); 48f1d2b4d3SLarry Finger tmp1byte &= ~(BIT(0)); 49f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte); 50f1d2b4d3SLarry Finger } 51f1d2b4d3SLarry Finger 52f1d2b4d3SLarry Finger static void _rtl8723e_resume_tx_beacon(struct ieee80211_hw *hw) 53f1d2b4d3SLarry Finger { 54f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 55f1d2b4d3SLarry Finger u8 tmp1byte; 56f1d2b4d3SLarry Finger 57f1d2b4d3SLarry Finger tmp1byte = rtl_read_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2); 58f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, tmp1byte | BIT(6)); 59f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff); 60f1d2b4d3SLarry Finger tmp1byte = rtl_read_byte(rtlpriv, REG_TBTT_PROHIBIT + 2); 61f1d2b4d3SLarry Finger tmp1byte |= BIT(1); 62f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 2, tmp1byte); 63f1d2b4d3SLarry Finger } 64f1d2b4d3SLarry Finger 65f1d2b4d3SLarry Finger static void _rtl8723e_enable_bcn_sub_func(struct ieee80211_hw *hw) 66f1d2b4d3SLarry Finger { 67f1d2b4d3SLarry Finger _rtl8723e_set_bcn_ctrl_reg(hw, 0, BIT(1)); 68f1d2b4d3SLarry Finger } 69f1d2b4d3SLarry Finger 70f1d2b4d3SLarry Finger static void _rtl8723e_disable_bcn_sub_func(struct ieee80211_hw *hw) 71f1d2b4d3SLarry Finger { 72f1d2b4d3SLarry Finger _rtl8723e_set_bcn_ctrl_reg(hw, BIT(1), 0); 73f1d2b4d3SLarry Finger } 74f1d2b4d3SLarry Finger 75f1d2b4d3SLarry Finger void rtl8723e_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val) 76f1d2b4d3SLarry Finger { 77f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 78f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 79f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 80f1d2b4d3SLarry Finger 81f1d2b4d3SLarry Finger switch (variable) { 82f1d2b4d3SLarry Finger case HW_VAR_RCR: 83f1d2b4d3SLarry Finger *((u32 *)(val)) = rtlpci->receive_config; 84f1d2b4d3SLarry Finger break; 85f1d2b4d3SLarry Finger case HW_VAR_RF_STATE: 86f1d2b4d3SLarry Finger *((enum rf_pwrstate *)(val)) = ppsc->rfpwr_state; 87f1d2b4d3SLarry Finger break; 88f1d2b4d3SLarry Finger case HW_VAR_FWLPS_RF_ON:{ 89f1d2b4d3SLarry Finger enum rf_pwrstate rfstate; 90f1d2b4d3SLarry Finger u32 val_rcr; 91f1d2b4d3SLarry Finger 92f1d2b4d3SLarry Finger rtlpriv->cfg->ops->get_hw_reg(hw, 93f1d2b4d3SLarry Finger HW_VAR_RF_STATE, 94f1d2b4d3SLarry Finger (u8 *)(&rfstate)); 95f1d2b4d3SLarry Finger if (rfstate == ERFOFF) { 96f1d2b4d3SLarry Finger *((bool *)(val)) = true; 97f1d2b4d3SLarry Finger } else { 98f1d2b4d3SLarry Finger val_rcr = rtl_read_dword(rtlpriv, REG_RCR); 99f1d2b4d3SLarry Finger val_rcr &= 0x00070000; 100f1d2b4d3SLarry Finger if (val_rcr) 101f1d2b4d3SLarry Finger *((bool *)(val)) = false; 102f1d2b4d3SLarry Finger else 103f1d2b4d3SLarry Finger *((bool *)(val)) = true; 104f1d2b4d3SLarry Finger } 105f1d2b4d3SLarry Finger break; 106f1d2b4d3SLarry Finger } 107f1d2b4d3SLarry Finger case HW_VAR_FW_PSMODE_STATUS: 108f1d2b4d3SLarry Finger *((bool *)(val)) = ppsc->fw_current_inpsmode; 109f1d2b4d3SLarry Finger break; 110f1d2b4d3SLarry Finger case HW_VAR_CORRECT_TSF:{ 111f1d2b4d3SLarry Finger u64 tsf; 112f1d2b4d3SLarry Finger u32 *ptsf_low = (u32 *)&tsf; 113f1d2b4d3SLarry Finger u32 *ptsf_high = ((u32 *)&tsf) + 1; 114f1d2b4d3SLarry Finger 115f1d2b4d3SLarry Finger *ptsf_high = rtl_read_dword(rtlpriv, (REG_TSFTR + 4)); 116f1d2b4d3SLarry Finger *ptsf_low = rtl_read_dword(rtlpriv, REG_TSFTR); 117f1d2b4d3SLarry Finger 118f1d2b4d3SLarry Finger *((u64 *)(val)) = tsf; 119f1d2b4d3SLarry Finger 120f1d2b4d3SLarry Finger break; 121f1d2b4d3SLarry Finger } 1221cc49a5bSLarry Finger case HAL_DEF_WOWLAN: 1231cc49a5bSLarry Finger break; 124f1d2b4d3SLarry Finger default: 125f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD, 126ad574889SJoe Perches "switch case %#x not processed\n", variable); 127f1d2b4d3SLarry Finger break; 128f1d2b4d3SLarry Finger } 129f1d2b4d3SLarry Finger } 130f1d2b4d3SLarry Finger 131f1d2b4d3SLarry Finger void rtl8723e_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val) 132f1d2b4d3SLarry Finger { 133f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 134f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 135f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 136f1d2b4d3SLarry Finger struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 137f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 138f1d2b4d3SLarry Finger u8 idx; 139f1d2b4d3SLarry Finger 140f1d2b4d3SLarry Finger switch (variable) { 141f1d2b4d3SLarry Finger case HW_VAR_ETHER_ADDR:{ 142f1d2b4d3SLarry Finger for (idx = 0; idx < ETH_ALEN; idx++) { 143f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, (REG_MACID + idx), 144f1d2b4d3SLarry Finger val[idx]); 145f1d2b4d3SLarry Finger } 146f1d2b4d3SLarry Finger break; 147f1d2b4d3SLarry Finger } 148f1d2b4d3SLarry Finger case HW_VAR_BASIC_RATE:{ 149f1d2b4d3SLarry Finger u16 b_rate_cfg = ((u16 *)val)[0]; 150f1d2b4d3SLarry Finger u8 rate_index = 0; 151f1d2b4d3SLarry Finger 152f1d2b4d3SLarry Finger b_rate_cfg = b_rate_cfg & 0x15f; 153f1d2b4d3SLarry Finger b_rate_cfg |= 0x01; 154f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RRSR, b_rate_cfg & 0xff); 155f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RRSR + 1, 156f1d2b4d3SLarry Finger (b_rate_cfg >> 8) & 0xff); 157f1d2b4d3SLarry Finger while (b_rate_cfg > 0x1) { 158f1d2b4d3SLarry Finger b_rate_cfg = (b_rate_cfg >> 1); 159f1d2b4d3SLarry Finger rate_index++; 160f1d2b4d3SLarry Finger } 161f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, 162f1d2b4d3SLarry Finger rate_index); 163f1d2b4d3SLarry Finger break; 164f1d2b4d3SLarry Finger } 165f1d2b4d3SLarry Finger case HW_VAR_BSSID:{ 166f1d2b4d3SLarry Finger for (idx = 0; idx < ETH_ALEN; idx++) { 167f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, (REG_BSSID + idx), 168f1d2b4d3SLarry Finger val[idx]); 169f1d2b4d3SLarry Finger } 170f1d2b4d3SLarry Finger break; 171f1d2b4d3SLarry Finger } 172f1d2b4d3SLarry Finger case HW_VAR_SIFS:{ 173f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_SIFS_CTX + 1, val[0]); 174f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_SIFS_TRX + 1, val[1]); 175f1d2b4d3SLarry Finger 176f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_SPEC_SIFS + 1, val[0]); 177f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_MAC_SPEC_SIFS + 1, val[0]); 178f1d2b4d3SLarry Finger 179f1d2b4d3SLarry Finger if (!mac->ht_enable) 180f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM, 181f1d2b4d3SLarry Finger 0x0e0e); 182f1d2b4d3SLarry Finger else 183f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_RESP_SIFS_OFDM, 184f1d2b4d3SLarry Finger *((u16 *)val)); 185f1d2b4d3SLarry Finger break; 186f1d2b4d3SLarry Finger } 187f1d2b4d3SLarry Finger case HW_VAR_SLOT_TIME:{ 188f1d2b4d3SLarry Finger u8 e_aci; 189f1d2b4d3SLarry Finger 190f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, 191f1d2b4d3SLarry Finger "HW_VAR_SLOT_TIME %x\n", val[0]); 192f1d2b4d3SLarry Finger 193f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_SLOT, val[0]); 194f1d2b4d3SLarry Finger 195f1d2b4d3SLarry Finger for (e_aci = 0; e_aci < AC_MAX; e_aci++) { 196f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, 197f1d2b4d3SLarry Finger HW_VAR_AC_PARAM, 198f1d2b4d3SLarry Finger (u8 *)(&e_aci)); 199f1d2b4d3SLarry Finger } 200f1d2b4d3SLarry Finger break; 201f1d2b4d3SLarry Finger } 202f1d2b4d3SLarry Finger case HW_VAR_ACK_PREAMBLE:{ 203f1d2b4d3SLarry Finger u8 reg_tmp; 204f1d2b4d3SLarry Finger u8 short_preamble = (bool)(*(u8 *)val); 205f1d2b4d3SLarry Finger 206f1d2b4d3SLarry Finger reg_tmp = (mac->cur_40_prime_sc) << 5; 207f1d2b4d3SLarry Finger if (short_preamble) 208f1d2b4d3SLarry Finger reg_tmp |= 0x80; 209f1d2b4d3SLarry Finger 210f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RRSR + 2, reg_tmp); 211f1d2b4d3SLarry Finger break; 212f1d2b4d3SLarry Finger } 213f1d2b4d3SLarry Finger case HW_VAR_AMPDU_MIN_SPACE:{ 214f1d2b4d3SLarry Finger u8 min_spacing_to_set; 215f1d2b4d3SLarry Finger u8 sec_min_space; 216f1d2b4d3SLarry Finger 217f1d2b4d3SLarry Finger min_spacing_to_set = *((u8 *)val); 218f1d2b4d3SLarry Finger if (min_spacing_to_set <= 7) { 219f1d2b4d3SLarry Finger sec_min_space = 0; 220f1d2b4d3SLarry Finger 221f1d2b4d3SLarry Finger if (min_spacing_to_set < sec_min_space) 222f1d2b4d3SLarry Finger min_spacing_to_set = sec_min_space; 223f1d2b4d3SLarry Finger 224f1d2b4d3SLarry Finger mac->min_space_cfg = ((mac->min_space_cfg & 225f1d2b4d3SLarry Finger 0xf8) | 226f1d2b4d3SLarry Finger min_spacing_to_set); 227f1d2b4d3SLarry Finger 228f1d2b4d3SLarry Finger *val = min_spacing_to_set; 229f1d2b4d3SLarry Finger 230f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, 231f1d2b4d3SLarry Finger "Set HW_VAR_AMPDU_MIN_SPACE: %#x\n", 232f1d2b4d3SLarry Finger mac->min_space_cfg); 233f1d2b4d3SLarry Finger 234f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, 235f1d2b4d3SLarry Finger mac->min_space_cfg); 236f1d2b4d3SLarry Finger } 237f1d2b4d3SLarry Finger break; 238f1d2b4d3SLarry Finger } 239f1d2b4d3SLarry Finger case HW_VAR_SHORTGI_DENSITY:{ 240f1d2b4d3SLarry Finger u8 density_to_set; 241f1d2b4d3SLarry Finger 242f1d2b4d3SLarry Finger density_to_set = *((u8 *)val); 243f1d2b4d3SLarry Finger mac->min_space_cfg |= (density_to_set << 3); 244f1d2b4d3SLarry Finger 245f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, 246f1d2b4d3SLarry Finger "Set HW_VAR_SHORTGI_DENSITY: %#x\n", 247f1d2b4d3SLarry Finger mac->min_space_cfg); 248f1d2b4d3SLarry Finger 249f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, 250f1d2b4d3SLarry Finger mac->min_space_cfg); 251f1d2b4d3SLarry Finger 252f1d2b4d3SLarry Finger break; 253f1d2b4d3SLarry Finger } 254f1d2b4d3SLarry Finger case HW_VAR_AMPDU_FACTOR:{ 255f1d2b4d3SLarry Finger u8 regtoset_normal[4] = { 0x41, 0xa8, 0x72, 0xb9 }; 256f1d2b4d3SLarry Finger u8 regtoset_bt[4] = {0x31, 0x74, 0x42, 0x97}; 257f1d2b4d3SLarry Finger u8 factor_toset; 258f1d2b4d3SLarry Finger u8 *p_regtoset = NULL; 259f1d2b4d3SLarry Finger u8 index = 0; 260f1d2b4d3SLarry Finger 261f1d2b4d3SLarry Finger if ((rtlpriv->btcoexist.bt_coexistence) && 262f1d2b4d3SLarry Finger (rtlpriv->btcoexist.bt_coexist_type == 263f1d2b4d3SLarry Finger BT_CSR_BC4)) 264f1d2b4d3SLarry Finger p_regtoset = regtoset_bt; 265f1d2b4d3SLarry Finger else 266f1d2b4d3SLarry Finger p_regtoset = regtoset_normal; 267f1d2b4d3SLarry Finger 268f1d2b4d3SLarry Finger factor_toset = *((u8 *)val); 269f1d2b4d3SLarry Finger if (factor_toset <= 3) { 270f1d2b4d3SLarry Finger factor_toset = (1 << (factor_toset + 2)); 271f1d2b4d3SLarry Finger if (factor_toset > 0xf) 272f1d2b4d3SLarry Finger factor_toset = 0xf; 273f1d2b4d3SLarry Finger 274f1d2b4d3SLarry Finger for (index = 0; index < 4; index++) { 275f1d2b4d3SLarry Finger if ((p_regtoset[index] & 0xf0) > 276f1d2b4d3SLarry Finger (factor_toset << 4)) 277f1d2b4d3SLarry Finger p_regtoset[index] = 278f1d2b4d3SLarry Finger (p_regtoset[index] & 0x0f) | 279f1d2b4d3SLarry Finger (factor_toset << 4); 280f1d2b4d3SLarry Finger 281f1d2b4d3SLarry Finger if ((p_regtoset[index] & 0x0f) > 282f1d2b4d3SLarry Finger factor_toset) 283f1d2b4d3SLarry Finger p_regtoset[index] = 284f1d2b4d3SLarry Finger (p_regtoset[index] & 0xf0) | 285f1d2b4d3SLarry Finger (factor_toset); 286f1d2b4d3SLarry Finger 287f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 288f1d2b4d3SLarry Finger (REG_AGGLEN_LMT + index), 289f1d2b4d3SLarry Finger p_regtoset[index]); 290f1d2b4d3SLarry Finger } 291f1d2b4d3SLarry Finger 292f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_MLME, DBG_LOUD, 293f1d2b4d3SLarry Finger "Set HW_VAR_AMPDU_FACTOR: %#x\n", 294f1d2b4d3SLarry Finger factor_toset); 295f1d2b4d3SLarry Finger } 296f1d2b4d3SLarry Finger break; 297f1d2b4d3SLarry Finger } 298f1d2b4d3SLarry Finger case HW_VAR_AC_PARAM:{ 299f1d2b4d3SLarry Finger u8 e_aci = *((u8 *)val); 300f1d2b4d3SLarry Finger 301f1d2b4d3SLarry Finger rtl8723_dm_init_edca_turbo(hw); 302f1d2b4d3SLarry Finger 303f1d2b4d3SLarry Finger if (rtlpci->acm_method != EACMWAY2_SW) 304f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, 305f1d2b4d3SLarry Finger HW_VAR_ACM_CTRL, 306f1d2b4d3SLarry Finger (u8 *)(&e_aci)); 307f1d2b4d3SLarry Finger break; 308f1d2b4d3SLarry Finger } 309f1d2b4d3SLarry Finger case HW_VAR_ACM_CTRL:{ 310f1d2b4d3SLarry Finger u8 e_aci = *((u8 *)val); 311f1d2b4d3SLarry Finger union aci_aifsn *p_aci_aifsn = 312f1d2b4d3SLarry Finger (union aci_aifsn *)(&mac->ac[0].aifs); 313f1d2b4d3SLarry Finger u8 acm = p_aci_aifsn->f.acm; 314f1d2b4d3SLarry Finger u8 acm_ctrl = rtl_read_byte(rtlpriv, REG_ACMHWCTRL); 315f1d2b4d3SLarry Finger 316f1d2b4d3SLarry Finger acm_ctrl = 317f1d2b4d3SLarry Finger acm_ctrl | ((rtlpci->acm_method == 2) ? 0x0 : 0x1); 318f1d2b4d3SLarry Finger 319f1d2b4d3SLarry Finger if (acm) { 320f1d2b4d3SLarry Finger switch (e_aci) { 321f1d2b4d3SLarry Finger case AC0_BE: 322f1d2b4d3SLarry Finger acm_ctrl |= ACMHW_BEQEN; 323f1d2b4d3SLarry Finger break; 324f1d2b4d3SLarry Finger case AC2_VI: 325f1d2b4d3SLarry Finger acm_ctrl |= ACMHW_VIQEN; 326f1d2b4d3SLarry Finger break; 327f1d2b4d3SLarry Finger case AC3_VO: 328f1d2b4d3SLarry Finger acm_ctrl |= ACMHW_VOQEN; 329f1d2b4d3SLarry Finger break; 330f1d2b4d3SLarry Finger default: 331f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, 332f1d2b4d3SLarry Finger "HW_VAR_ACM_CTRL acm set failed: eACI is %d\n", 333f1d2b4d3SLarry Finger acm); 334f1d2b4d3SLarry Finger break; 335f1d2b4d3SLarry Finger } 336f1d2b4d3SLarry Finger } else { 337f1d2b4d3SLarry Finger switch (e_aci) { 338f1d2b4d3SLarry Finger case AC0_BE: 339f1d2b4d3SLarry Finger acm_ctrl &= (~ACMHW_BEQEN); 340f1d2b4d3SLarry Finger break; 341f1d2b4d3SLarry Finger case AC2_VI: 342f1d2b4d3SLarry Finger acm_ctrl &= (~ACMHW_VIQEN); 343f1d2b4d3SLarry Finger break; 344f1d2b4d3SLarry Finger case AC3_VO: 345f1d2b4d3SLarry Finger acm_ctrl &= (~ACMHW_VOQEN); 346f1d2b4d3SLarry Finger break; 347f1d2b4d3SLarry Finger default: 348f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD, 349ad574889SJoe Perches "switch case %#x not processed\n", 350ad574889SJoe Perches e_aci); 351f1d2b4d3SLarry Finger break; 352f1d2b4d3SLarry Finger } 353f1d2b4d3SLarry Finger } 354f1d2b4d3SLarry Finger 355f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_QOS, DBG_TRACE, 356f1d2b4d3SLarry Finger "SetHwReg8190pci(): [HW_VAR_ACM_CTRL] Write 0x%X\n", 357f1d2b4d3SLarry Finger acm_ctrl); 358f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_ACMHWCTRL, acm_ctrl); 359f1d2b4d3SLarry Finger break; 360f1d2b4d3SLarry Finger } 361f1d2b4d3SLarry Finger case HW_VAR_RCR:{ 362f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RCR, ((u32 *)(val))[0]); 363f1d2b4d3SLarry Finger rtlpci->receive_config = ((u32 *)(val))[0]; 364f1d2b4d3SLarry Finger break; 365f1d2b4d3SLarry Finger } 366f1d2b4d3SLarry Finger case HW_VAR_RETRY_LIMIT:{ 367f1d2b4d3SLarry Finger u8 retry_limit = ((u8 *)(val))[0]; 368f1d2b4d3SLarry Finger 369f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_RL, 370f1d2b4d3SLarry Finger retry_limit << RETRY_LIMIT_SHORT_SHIFT | 371f1d2b4d3SLarry Finger retry_limit << RETRY_LIMIT_LONG_SHIFT); 372f1d2b4d3SLarry Finger break; 373f1d2b4d3SLarry Finger } 374f1d2b4d3SLarry Finger case HW_VAR_DUAL_TSF_RST: 375f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_DUAL_TSF_RST, (BIT(0) | BIT(1))); 376f1d2b4d3SLarry Finger break; 377f1d2b4d3SLarry Finger case HW_VAR_EFUSE_BYTES: 378f1d2b4d3SLarry Finger rtlefuse->efuse_usedbytes = *((u16 *)val); 379f1d2b4d3SLarry Finger break; 380f1d2b4d3SLarry Finger case HW_VAR_EFUSE_USAGE: 381f1d2b4d3SLarry Finger rtlefuse->efuse_usedpercentage = *((u8 *)val); 382f1d2b4d3SLarry Finger break; 383f1d2b4d3SLarry Finger case HW_VAR_IO_CMD: 384f1d2b4d3SLarry Finger rtl8723e_phy_set_io_cmd(hw, (*(enum io_type *)val)); 385f1d2b4d3SLarry Finger break; 386f1d2b4d3SLarry Finger case HW_VAR_WPA_CONFIG: 387f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_SECCFG, *((u8 *)val)); 388f1d2b4d3SLarry Finger break; 389f1d2b4d3SLarry Finger case HW_VAR_SET_RPWM:{ 390f1d2b4d3SLarry Finger u8 rpwm_val; 391f1d2b4d3SLarry Finger 392f1d2b4d3SLarry Finger rpwm_val = rtl_read_byte(rtlpriv, REG_PCIE_HRPWM); 393f1d2b4d3SLarry Finger udelay(1); 394f1d2b4d3SLarry Finger 395f1d2b4d3SLarry Finger if (rpwm_val & BIT(7)) { 396f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, 397f1d2b4d3SLarry Finger (*(u8 *)val)); 398f1d2b4d3SLarry Finger } else { 399f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_PCIE_HRPWM, 400f1d2b4d3SLarry Finger ((*(u8 *)val) | BIT(7))); 401f1d2b4d3SLarry Finger } 402f1d2b4d3SLarry Finger 403f1d2b4d3SLarry Finger break; 404f1d2b4d3SLarry Finger } 405f1d2b4d3SLarry Finger case HW_VAR_H2C_FW_PWRMODE:{ 406f1d2b4d3SLarry Finger u8 psmode = (*(u8 *)val); 407f1d2b4d3SLarry Finger 408f1d2b4d3SLarry Finger if (psmode != FW_PS_ACTIVE_MODE) 409f1d2b4d3SLarry Finger rtl8723e_dm_rf_saving(hw, true); 410f1d2b4d3SLarry Finger 411f1d2b4d3SLarry Finger rtl8723e_set_fw_pwrmode_cmd(hw, (*(u8 *)val)); 412f1d2b4d3SLarry Finger break; 413f1d2b4d3SLarry Finger } 414f1d2b4d3SLarry Finger case HW_VAR_FW_PSMODE_STATUS: 415f1d2b4d3SLarry Finger ppsc->fw_current_inpsmode = *((bool *)val); 416f1d2b4d3SLarry Finger break; 417f1d2b4d3SLarry Finger case HW_VAR_H2C_FW_JOINBSSRPT:{ 418f1d2b4d3SLarry Finger u8 mstatus = (*(u8 *)val); 419f1d2b4d3SLarry Finger u8 tmp_regcr, tmp_reg422; 420f1d2b4d3SLarry Finger bool b_recover = false; 421f1d2b4d3SLarry Finger 422f1d2b4d3SLarry Finger if (mstatus == RT_MEDIA_CONNECT) { 423f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AID, 424f1d2b4d3SLarry Finger NULL); 425f1d2b4d3SLarry Finger 426f1d2b4d3SLarry Finger tmp_regcr = rtl_read_byte(rtlpriv, REG_CR + 1); 427f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_CR + 1, 428f1d2b4d3SLarry Finger (tmp_regcr | BIT(0))); 429f1d2b4d3SLarry Finger 430f1d2b4d3SLarry Finger _rtl8723e_set_bcn_ctrl_reg(hw, 0, BIT(3)); 431f1d2b4d3SLarry Finger _rtl8723e_set_bcn_ctrl_reg(hw, BIT(4), 0); 432f1d2b4d3SLarry Finger 433f1d2b4d3SLarry Finger tmp_reg422 = 434f1d2b4d3SLarry Finger rtl_read_byte(rtlpriv, 435f1d2b4d3SLarry Finger REG_FWHW_TXQ_CTRL + 2); 436f1d2b4d3SLarry Finger if (tmp_reg422 & BIT(6)) 437f1d2b4d3SLarry Finger b_recover = true; 438f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 2, 439f1d2b4d3SLarry Finger tmp_reg422 & (~BIT(6))); 440f1d2b4d3SLarry Finger 441f1d2b4d3SLarry Finger rtl8723e_set_fw_rsvdpagepkt(hw, 0); 442f1d2b4d3SLarry Finger 443f1d2b4d3SLarry Finger _rtl8723e_set_bcn_ctrl_reg(hw, BIT(3), 0); 444f1d2b4d3SLarry Finger _rtl8723e_set_bcn_ctrl_reg(hw, 0, BIT(4)); 445f1d2b4d3SLarry Finger 446f1d2b4d3SLarry Finger if (b_recover) { 447f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 448f1d2b4d3SLarry Finger REG_FWHW_TXQ_CTRL + 2, 449f1d2b4d3SLarry Finger tmp_reg422); 450f1d2b4d3SLarry Finger } 451f1d2b4d3SLarry Finger 452f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_CR + 1, 453f1d2b4d3SLarry Finger (tmp_regcr & ~(BIT(0)))); 454f1d2b4d3SLarry Finger } 455f1d2b4d3SLarry Finger rtl8723e_set_fw_joinbss_report_cmd(hw, (*(u8 *)val)); 456f1d2b4d3SLarry Finger 457f1d2b4d3SLarry Finger break; 458f1d2b4d3SLarry Finger } 459f1d2b4d3SLarry Finger case HW_VAR_H2C_FW_P2P_PS_OFFLOAD:{ 460f1d2b4d3SLarry Finger rtl8723e_set_p2p_ps_offload_cmd(hw, (*(u8 *)val)); 461f1d2b4d3SLarry Finger break; 462f1d2b4d3SLarry Finger } 463f1d2b4d3SLarry Finger case HW_VAR_AID:{ 464f1d2b4d3SLarry Finger u16 u2btmp; 465f1d2b4d3SLarry Finger 466f1d2b4d3SLarry Finger u2btmp = rtl_read_word(rtlpriv, REG_BCN_PSR_RPT); 467f1d2b4d3SLarry Finger u2btmp &= 0xC000; 468f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_BCN_PSR_RPT, 469f1d2b4d3SLarry Finger (u2btmp | mac->assoc_id)); 470f1d2b4d3SLarry Finger 471f1d2b4d3SLarry Finger break; 472f1d2b4d3SLarry Finger } 473f1d2b4d3SLarry Finger case HW_VAR_CORRECT_TSF:{ 474f1d2b4d3SLarry Finger u8 btype_ibss = ((u8 *)(val))[0]; 475f1d2b4d3SLarry Finger 476f1d2b4d3SLarry Finger if (btype_ibss) 477f1d2b4d3SLarry Finger _rtl8723e_stop_tx_beacon(hw); 478f1d2b4d3SLarry Finger 479f1d2b4d3SLarry Finger _rtl8723e_set_bcn_ctrl_reg(hw, 0, BIT(3)); 480f1d2b4d3SLarry Finger 481f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_TSFTR, 482f1d2b4d3SLarry Finger (u32)(mac->tsf & 0xffffffff)); 483f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_TSFTR + 4, 484f1d2b4d3SLarry Finger (u32)((mac->tsf >> 32) & 0xffffffff)); 485f1d2b4d3SLarry Finger 486f1d2b4d3SLarry Finger _rtl8723e_set_bcn_ctrl_reg(hw, BIT(3), 0); 487f1d2b4d3SLarry Finger 488f1d2b4d3SLarry Finger if (btype_ibss) 489f1d2b4d3SLarry Finger _rtl8723e_resume_tx_beacon(hw); 490f1d2b4d3SLarry Finger 491f1d2b4d3SLarry Finger break; 492f1d2b4d3SLarry Finger } 493f1d2b4d3SLarry Finger case HW_VAR_FW_LPS_ACTION:{ 494f1d2b4d3SLarry Finger bool b_enter_fwlps = *((bool *)val); 495f1d2b4d3SLarry Finger u8 rpwm_val, fw_pwrmode; 496f1d2b4d3SLarry Finger bool fw_current_inps; 497f1d2b4d3SLarry Finger 498f1d2b4d3SLarry Finger if (b_enter_fwlps) { 499f1d2b4d3SLarry Finger rpwm_val = 0x02; /* RF off */ 500f1d2b4d3SLarry Finger fw_current_inps = true; 501f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, 502f1d2b4d3SLarry Finger HW_VAR_FW_PSMODE_STATUS, 503f1d2b4d3SLarry Finger (u8 *)(&fw_current_inps)); 504f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, 505f1d2b4d3SLarry Finger HW_VAR_H2C_FW_PWRMODE, 506f1d2b4d3SLarry Finger (u8 *)(&ppsc->fwctrl_psmode)); 507f1d2b4d3SLarry Finger 508f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, 509f1d2b4d3SLarry Finger HW_VAR_SET_RPWM, 510f1d2b4d3SLarry Finger (u8 *)(&rpwm_val)); 511f1d2b4d3SLarry Finger } else { 512f1d2b4d3SLarry Finger rpwm_val = 0x0C; /* RF on */ 513f1d2b4d3SLarry Finger fw_pwrmode = FW_PS_ACTIVE_MODE; 514f1d2b4d3SLarry Finger fw_current_inps = false; 515f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, 516f1d2b4d3SLarry Finger HW_VAR_SET_RPWM, 517f1d2b4d3SLarry Finger (u8 *)(&rpwm_val)); 518f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, 519f1d2b4d3SLarry Finger HW_VAR_H2C_FW_PWRMODE, 520f1d2b4d3SLarry Finger (u8 *)(&fw_pwrmode)); 521f1d2b4d3SLarry Finger 522f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, 523f1d2b4d3SLarry Finger HW_VAR_FW_PSMODE_STATUS, 524f1d2b4d3SLarry Finger (u8 *)(&fw_current_inps)); 525f1d2b4d3SLarry Finger } 526f1d2b4d3SLarry Finger break; 527f1d2b4d3SLarry Finger } 528f1d2b4d3SLarry Finger default: 529f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD, 530ad574889SJoe Perches "switch case %#x not processed\n", variable); 531f1d2b4d3SLarry Finger break; 532f1d2b4d3SLarry Finger } 533f1d2b4d3SLarry Finger } 534f1d2b4d3SLarry Finger 535f1d2b4d3SLarry Finger static bool _rtl8723e_llt_write(struct ieee80211_hw *hw, u32 address, u32 data) 536f1d2b4d3SLarry Finger { 537f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 538f1d2b4d3SLarry Finger bool status = true; 539f1d2b4d3SLarry Finger long count = 0; 540f1d2b4d3SLarry Finger u32 value = _LLT_INIT_ADDR(address) | 541f1d2b4d3SLarry Finger _LLT_INIT_DATA(data) | _LLT_OP(_LLT_WRITE_ACCESS); 542f1d2b4d3SLarry Finger 543f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_LLT_INIT, value); 544f1d2b4d3SLarry Finger 545f1d2b4d3SLarry Finger do { 546f1d2b4d3SLarry Finger value = rtl_read_dword(rtlpriv, REG_LLT_INIT); 547f1d2b4d3SLarry Finger if (_LLT_NO_ACTIVE == _LLT_OP_VALUE(value)) 548f1d2b4d3SLarry Finger break; 549f1d2b4d3SLarry Finger 550f1d2b4d3SLarry Finger if (count > POLLING_LLT_THRESHOLD) { 551a67005bcSLarry Finger pr_err("Failed to polling write LLT done at address %d!\n", 552f1d2b4d3SLarry Finger address); 553f1d2b4d3SLarry Finger status = false; 554f1d2b4d3SLarry Finger break; 555f1d2b4d3SLarry Finger } 556f1d2b4d3SLarry Finger } while (++count); 557f1d2b4d3SLarry Finger 558f1d2b4d3SLarry Finger return status; 559f1d2b4d3SLarry Finger } 560f1d2b4d3SLarry Finger 561f1d2b4d3SLarry Finger static bool _rtl8723e_llt_table_init(struct ieee80211_hw *hw) 562f1d2b4d3SLarry Finger { 563f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 564f1d2b4d3SLarry Finger unsigned short i; 565f1d2b4d3SLarry Finger u8 txpktbuf_bndy; 566f1d2b4d3SLarry Finger u8 maxpage; 567f1d2b4d3SLarry Finger bool status; 568f1d2b4d3SLarry Finger u8 ubyte; 569f1d2b4d3SLarry Finger 570f1d2b4d3SLarry Finger #if LLT_CONFIG == 1 571f1d2b4d3SLarry Finger maxpage = 255; 572f1d2b4d3SLarry Finger txpktbuf_bndy = 252; 573f1d2b4d3SLarry Finger #elif LLT_CONFIG == 2 574f1d2b4d3SLarry Finger maxpage = 127; 575f1d2b4d3SLarry Finger txpktbuf_bndy = 124; 576f1d2b4d3SLarry Finger #elif LLT_CONFIG == 3 577f1d2b4d3SLarry Finger maxpage = 255; 578f1d2b4d3SLarry Finger txpktbuf_bndy = 174; 579f1d2b4d3SLarry Finger #elif LLT_CONFIG == 4 580f1d2b4d3SLarry Finger maxpage = 255; 581f1d2b4d3SLarry Finger txpktbuf_bndy = 246; 582f1d2b4d3SLarry Finger #elif LLT_CONFIG == 5 583f1d2b4d3SLarry Finger maxpage = 255; 584f1d2b4d3SLarry Finger txpktbuf_bndy = 246; 585f1d2b4d3SLarry Finger #endif 586f1d2b4d3SLarry Finger 587f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_CR, 0x8B); 588f1d2b4d3SLarry Finger 589f1d2b4d3SLarry Finger #if LLT_CONFIG == 1 590f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x1c); 591f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RQPN, 0x80a71c1c); 592f1d2b4d3SLarry Finger #elif LLT_CONFIG == 2 593f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RQPN, 0x845B1010); 594f1d2b4d3SLarry Finger #elif LLT_CONFIG == 3 595f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RQPN, 0x84838484); 596f1d2b4d3SLarry Finger #elif LLT_CONFIG == 4 597f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RQPN, 0x80bd1c1c); 598f1d2b4d3SLarry Finger #elif LLT_CONFIG == 5 599f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_RQPN_NPQ, 0x0000); 600f1d2b4d3SLarry Finger 601f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RQPN, 0x80ac1c29); 602f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RQPN_NPQ, 0x03); 603f1d2b4d3SLarry Finger #endif 604f1d2b4d3SLarry Finger 605f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_TRXFF_BNDY, (0x27FF0000 | txpktbuf_bndy)); 606f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_TDECTRL + 1, txpktbuf_bndy); 607f1d2b4d3SLarry Finger 608f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_TXPKTBUF_BCNQ_BDNY, txpktbuf_bndy); 609f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_TXPKTBUF_MGQ_BDNY, txpktbuf_bndy); 610f1d2b4d3SLarry Finger 611f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x45D, txpktbuf_bndy); 612f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_PBP, 0x11); 613f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RX_DRVINFO_SZ, 0x4); 614f1d2b4d3SLarry Finger 615f1d2b4d3SLarry Finger for (i = 0; i < (txpktbuf_bndy - 1); i++) { 616f1d2b4d3SLarry Finger status = _rtl8723e_llt_write(hw, i, i + 1); 617f1d2b4d3SLarry Finger if (true != status) 618f1d2b4d3SLarry Finger return status; 619f1d2b4d3SLarry Finger } 620f1d2b4d3SLarry Finger 621f1d2b4d3SLarry Finger status = _rtl8723e_llt_write(hw, (txpktbuf_bndy - 1), 0xFF); 622f1d2b4d3SLarry Finger if (true != status) 623f1d2b4d3SLarry Finger return status; 624f1d2b4d3SLarry Finger 625f1d2b4d3SLarry Finger for (i = txpktbuf_bndy; i < maxpage; i++) { 626f1d2b4d3SLarry Finger status = _rtl8723e_llt_write(hw, i, (i + 1)); 627f1d2b4d3SLarry Finger if (true != status) 628f1d2b4d3SLarry Finger return status; 629f1d2b4d3SLarry Finger } 630f1d2b4d3SLarry Finger 631f1d2b4d3SLarry Finger status = _rtl8723e_llt_write(hw, maxpage, txpktbuf_bndy); 632f1d2b4d3SLarry Finger if (true != status) 633f1d2b4d3SLarry Finger return status; 634f1d2b4d3SLarry Finger 635f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_CR, 0xff); 636f1d2b4d3SLarry Finger ubyte = rtl_read_byte(rtlpriv, REG_RQPN + 3); 637f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RQPN + 3, ubyte | BIT(7)); 638f1d2b4d3SLarry Finger 639f1d2b4d3SLarry Finger return true; 640f1d2b4d3SLarry Finger } 641f1d2b4d3SLarry Finger 642f1d2b4d3SLarry Finger static void _rtl8723e_gen_refresh_led_state(struct ieee80211_hw *hw) 643f1d2b4d3SLarry Finger { 644f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 645f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 646d5efe153SLarry Finger struct rtl_led *pled0 = &rtlpriv->ledctl.sw_led0; 647f1d2b4d3SLarry Finger 648f1d2b4d3SLarry Finger if (rtlpriv->rtlhal.up_first_time) 649f1d2b4d3SLarry Finger return; 650f1d2b4d3SLarry Finger 651f1d2b4d3SLarry Finger if (ppsc->rfoff_reason == RF_CHANGE_BY_IPS) 652f1d2b4d3SLarry Finger rtl8723e_sw_led_on(hw, pled0); 653f1d2b4d3SLarry Finger else if (ppsc->rfoff_reason == RF_CHANGE_BY_INIT) 654f1d2b4d3SLarry Finger rtl8723e_sw_led_on(hw, pled0); 655f1d2b4d3SLarry Finger else 656f1d2b4d3SLarry Finger rtl8723e_sw_led_off(hw, pled0); 657f1d2b4d3SLarry Finger } 658f1d2b4d3SLarry Finger 659f1d2b4d3SLarry Finger static bool _rtl8712e_init_mac(struct ieee80211_hw *hw) 660f1d2b4d3SLarry Finger { 661f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 662f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 663f1d2b4d3SLarry Finger 664f1d2b4d3SLarry Finger unsigned char bytetmp; 665f1d2b4d3SLarry Finger unsigned short wordtmp; 666f1d2b4d3SLarry Finger u16 retry = 0; 667f1d2b4d3SLarry Finger u16 tmpu2b; 668f1d2b4d3SLarry Finger bool mac_func_enable; 669f1d2b4d3SLarry Finger 670f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x00); 671f1d2b4d3SLarry Finger bytetmp = rtl_read_byte(rtlpriv, REG_CR); 672f1d2b4d3SLarry Finger if (bytetmp == 0xFF) 673f1d2b4d3SLarry Finger mac_func_enable = true; 674f1d2b4d3SLarry Finger else 675f1d2b4d3SLarry Finger mac_func_enable = false; 676f1d2b4d3SLarry Finger 677f1d2b4d3SLarry Finger /* HW Power on sequence */ 678f1d2b4d3SLarry Finger if (!rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, 679f1d2b4d3SLarry Finger PWR_INTF_PCI_MSK, Rtl8723_NIC_ENABLE_FLOW)) 680f1d2b4d3SLarry Finger return false; 681f1d2b4d3SLarry Finger 682f1d2b4d3SLarry Finger bytetmp = rtl_read_byte(rtlpriv, REG_PCIE_CTRL_REG+2); 683f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG+2, bytetmp | BIT(4)); 684f1d2b4d3SLarry Finger 685f1d2b4d3SLarry Finger /* eMAC time out function enable, 0x369[7]=1 */ 686f1d2b4d3SLarry Finger bytetmp = rtl_read_byte(rtlpriv, 0x369); 687f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x369, bytetmp | BIT(7)); 688f1d2b4d3SLarry Finger 689f1d2b4d3SLarry Finger /* ePHY reg 0x1e bit[4]=1 using MDIO interface, 690f1d2b4d3SLarry Finger * we should do this before Enabling ASPM backdoor. 691f1d2b4d3SLarry Finger */ 692f1d2b4d3SLarry Finger do { 693f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, 0x358, 0x5e); 694f1d2b4d3SLarry Finger udelay(100); 695f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, 0x356, 0xc280); 696f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, 0x354, 0xc290); 697f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, 0x358, 0x3e); 698f1d2b4d3SLarry Finger udelay(100); 699f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, 0x358, 0x5e); 700f1d2b4d3SLarry Finger udelay(100); 701f1d2b4d3SLarry Finger tmpu2b = rtl_read_word(rtlpriv, 0x356); 702f1d2b4d3SLarry Finger retry++; 703f1d2b4d3SLarry Finger } while (tmpu2b != 0xc290 && retry < 100); 704f1d2b4d3SLarry Finger 705f1d2b4d3SLarry Finger if (retry >= 100) { 706f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, 707f1d2b4d3SLarry Finger "InitMAC(): ePHY configure fail!!!\n"); 708f1d2b4d3SLarry Finger return false; 709f1d2b4d3SLarry Finger } 710f1d2b4d3SLarry Finger 711f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_CR, 0x2ff); 712f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_CR + 1, 0x06); 713f1d2b4d3SLarry Finger 714f1d2b4d3SLarry Finger if (!mac_func_enable) { 715f1d2b4d3SLarry Finger if (!_rtl8723e_llt_table_init(hw)) 716f1d2b4d3SLarry Finger return false; 717f1d2b4d3SLarry Finger } 718f1d2b4d3SLarry Finger 719f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_HISR, 0xffffffff); 720f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_HISRE, 0xff); 721f1d2b4d3SLarry Finger 722f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_TRXFF_BNDY + 2, 0x27ff); 723f1d2b4d3SLarry Finger 724f1d2b4d3SLarry Finger wordtmp = rtl_read_word(rtlpriv, REG_TRXDMA_CTRL); 725f1d2b4d3SLarry Finger wordtmp &= 0xf; 726f1d2b4d3SLarry Finger wordtmp |= 0xF771; 727f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_TRXDMA_CTRL, wordtmp); 728f1d2b4d3SLarry Finger 729f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_FWHW_TXQ_CTRL + 1, 0x1F); 730f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config); 731f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_RXFLTMAP2, 0xFFFF); 732f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_TCR, rtlpci->transmit_config); 733f1d2b4d3SLarry Finger 734f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x4d0, 0x0); 735f1d2b4d3SLarry Finger 736f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_BCNQ_DESA, 737f1d2b4d3SLarry Finger ((u64) rtlpci->tx_ring[BEACON_QUEUE].dma) & 738f1d2b4d3SLarry Finger DMA_BIT_MASK(32)); 739f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_MGQ_DESA, 740f1d2b4d3SLarry Finger (u64) rtlpci->tx_ring[MGNT_QUEUE].dma & 741f1d2b4d3SLarry Finger DMA_BIT_MASK(32)); 742f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_VOQ_DESA, 743f1d2b4d3SLarry Finger (u64) rtlpci->tx_ring[VO_QUEUE].dma & DMA_BIT_MASK(32)); 744f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_VIQ_DESA, 745f1d2b4d3SLarry Finger (u64) rtlpci->tx_ring[VI_QUEUE].dma & DMA_BIT_MASK(32)); 746f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_BEQ_DESA, 747f1d2b4d3SLarry Finger (u64) rtlpci->tx_ring[BE_QUEUE].dma & DMA_BIT_MASK(32)); 748f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_BKQ_DESA, 749f1d2b4d3SLarry Finger (u64) rtlpci->tx_ring[BK_QUEUE].dma & DMA_BIT_MASK(32)); 750f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_HQ_DESA, 751f1d2b4d3SLarry Finger (u64) rtlpci->tx_ring[HIGH_QUEUE].dma & 752f1d2b4d3SLarry Finger DMA_BIT_MASK(32)); 753f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RX_DESA, 754f1d2b4d3SLarry Finger (u64) rtlpci->rx_ring[RX_MPDU_QUEUE].dma & 755f1d2b4d3SLarry Finger DMA_BIT_MASK(32)); 756f1d2b4d3SLarry Finger 757f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_PCIE_CTRL_REG + 3, 0x74); 758f1d2b4d3SLarry Finger 759f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_INT_MIG, 0); 760f1d2b4d3SLarry Finger 761f1d2b4d3SLarry Finger bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL); 762f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_APSD_CTRL, bytetmp & ~BIT(6)); 763f1d2b4d3SLarry Finger do { 764f1d2b4d3SLarry Finger retry++; 765f1d2b4d3SLarry Finger bytetmp = rtl_read_byte(rtlpriv, REG_APSD_CTRL); 766f1d2b4d3SLarry Finger } while ((retry < 200) && (bytetmp & BIT(7))); 767f1d2b4d3SLarry Finger 768f1d2b4d3SLarry Finger _rtl8723e_gen_refresh_led_state(hw); 769f1d2b4d3SLarry Finger 770f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_MCUTST_1, 0x0); 771f1d2b4d3SLarry Finger 772f1d2b4d3SLarry Finger return true; 773f1d2b4d3SLarry Finger } 774f1d2b4d3SLarry Finger 775f1d2b4d3SLarry Finger static void _rtl8723e_hw_configure(struct ieee80211_hw *hw) 776f1d2b4d3SLarry Finger { 777f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 778f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 779f1d2b4d3SLarry Finger u8 reg_bw_opmode; 780b9bcce36SKevin Lo u32 reg_prsr; 781f1d2b4d3SLarry Finger 782f1d2b4d3SLarry Finger reg_bw_opmode = BW_OPMODE_20MHZ; 783f1d2b4d3SLarry Finger reg_prsr = RATE_ALL_CCK | RATE_ALL_OFDM_AG; 784f1d2b4d3SLarry Finger 785f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_INIRTS_RATE_SEL, 0x8); 786f1d2b4d3SLarry Finger 787f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_BWOPMODE, reg_bw_opmode); 788f1d2b4d3SLarry Finger 789f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RRSR, reg_prsr); 790f1d2b4d3SLarry Finger 791f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_SLOT, 0x09); 792f1d2b4d3SLarry Finger 793f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_AMPDU_MIN_SPACE, 0x0); 794f1d2b4d3SLarry Finger 795f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_FWHW_TXQ_CTRL, 0x1F80); 796f1d2b4d3SLarry Finger 797f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_RL, 0x0707); 798f1d2b4d3SLarry Finger 799f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_BAR_MODE_CTRL, 0x02012802); 800f1d2b4d3SLarry Finger 801f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_HWSEQ_CTRL, 0xFF); 802f1d2b4d3SLarry Finger 803f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_DARFRC, 0x01000000); 804f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_DARFRC + 4, 0x07060504); 805f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RARFRC, 0x01000000); 806f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RARFRC + 4, 0x07060504); 807f1d2b4d3SLarry Finger 808f1d2b4d3SLarry Finger if ((rtlpriv->btcoexist.bt_coexistence) && 809f1d2b4d3SLarry Finger (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4)) 810f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0x97427431); 811f1d2b4d3SLarry Finger else 812f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_AGGLEN_LMT, 0xb972a841); 813f1d2b4d3SLarry Finger 814f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_ATIMWND, 0x2); 815f1d2b4d3SLarry Finger 816f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_BCN_MAX_ERR, 0xff); 817f1d2b4d3SLarry Finger 818f1d2b4d3SLarry Finger rtlpci->reg_bcn_ctrl_val = 0x1f; 819f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_BCN_CTRL, rtlpci->reg_bcn_ctrl_val); 820f1d2b4d3SLarry Finger 821f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff); 822f1d2b4d3SLarry Finger 823f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_TBTT_PROHIBIT + 1, 0xff); 824f1d2b4d3SLarry Finger 825f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_PIFS, 0x1C); 826f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_AGGR_BREAK_TIME, 0x16); 827f1d2b4d3SLarry Finger 828f1d2b4d3SLarry Finger if ((rtlpriv->btcoexist.bt_coexistence) && 829f1d2b4d3SLarry Finger (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4)) { 830f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020); 831f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_PROT_MODE_CTRL, 0x0402); 832f1d2b4d3SLarry Finger } else { 833f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020); 834f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_NAV_PROT_LEN, 0x0020); 835f1d2b4d3SLarry Finger } 836f1d2b4d3SLarry Finger 837f1d2b4d3SLarry Finger if ((rtlpriv->btcoexist.bt_coexistence) && 838f1d2b4d3SLarry Finger (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4)) 839f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x03086666); 840f1d2b4d3SLarry Finger else 841f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_FAST_EDCA_CTRL, 0x086666); 842f1d2b4d3SLarry Finger 843f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_ACKTO, 0x40); 844f1d2b4d3SLarry Finger 845f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_SPEC_SIFS, 0x1010); 846f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_MAC_SPEC_SIFS, 0x1010); 847f1d2b4d3SLarry Finger 848f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_SIFS_CTX, 0x1010); 849f1d2b4d3SLarry Finger 850f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_SIFS_TRX, 0x1010); 851f1d2b4d3SLarry Finger 852f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_MAR, 0xffffffff); 853f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_MAR + 4, 0xffffffff); 854f1d2b4d3SLarry Finger 855f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, 0x394, 0x1); 856f1d2b4d3SLarry Finger } 857f1d2b4d3SLarry Finger 858f1d2b4d3SLarry Finger static void _rtl8723e_enable_aspm_back_door(struct ieee80211_hw *hw) 859f1d2b4d3SLarry Finger { 860f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 861f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 862f1d2b4d3SLarry Finger 863f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x34b, 0x93); 864f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, 0x350, 0x870c); 865f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x352, 0x1); 866f1d2b4d3SLarry Finger 867f1d2b4d3SLarry Finger if (ppsc->support_backdoor) 868f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x349, 0x1b); 869f1d2b4d3SLarry Finger else 870f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x349, 0x03); 871f1d2b4d3SLarry Finger 872f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, 0x350, 0x2718); 873f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x352, 0x1); 874f1d2b4d3SLarry Finger } 875f1d2b4d3SLarry Finger 876f1d2b4d3SLarry Finger void rtl8723e_enable_hw_security_config(struct ieee80211_hw *hw) 877f1d2b4d3SLarry Finger { 878f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 879f1d2b4d3SLarry Finger u8 sec_reg_value; 880f1d2b4d3SLarry Finger 881f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 882f1d2b4d3SLarry Finger "PairwiseEncAlgorithm = %d GroupEncAlgorithm = %d\n", 883f1d2b4d3SLarry Finger rtlpriv->sec.pairwise_enc_algorithm, 884f1d2b4d3SLarry Finger rtlpriv->sec.group_enc_algorithm); 885f1d2b4d3SLarry Finger 886f1d2b4d3SLarry Finger if (rtlpriv->cfg->mod_params->sw_crypto || rtlpriv->sec.use_sw_sec) { 887f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 888f1d2b4d3SLarry Finger "not open hw encryption\n"); 889f1d2b4d3SLarry Finger return; 890f1d2b4d3SLarry Finger } 891f1d2b4d3SLarry Finger 892f1d2b4d3SLarry Finger sec_reg_value = SCR_TXENCENABLE | SCR_RXDECENABLE; 893f1d2b4d3SLarry Finger 894f1d2b4d3SLarry Finger if (rtlpriv->sec.use_defaultkey) { 895f1d2b4d3SLarry Finger sec_reg_value |= SCR_TXUSEDK; 896f1d2b4d3SLarry Finger sec_reg_value |= SCR_RXUSEDK; 897f1d2b4d3SLarry Finger } 898f1d2b4d3SLarry Finger 899f1d2b4d3SLarry Finger sec_reg_value |= (SCR_RXBCUSEDK | SCR_TXBCUSEDK); 900f1d2b4d3SLarry Finger 901f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_CR + 1, 0x02); 902f1d2b4d3SLarry Finger 903f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 904f1d2b4d3SLarry Finger "The SECR-value %x\n", sec_reg_value); 905f1d2b4d3SLarry Finger 906f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_WPA_CONFIG, &sec_reg_value); 907f1d2b4d3SLarry Finger 908f1d2b4d3SLarry Finger } 909f1d2b4d3SLarry Finger 910f1d2b4d3SLarry Finger int rtl8723e_hw_init(struct ieee80211_hw *hw) 911f1d2b4d3SLarry Finger { 912f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 913f1d2b4d3SLarry Finger struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 914f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 915f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &(rtlpriv->phy); 916f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 917f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 918f1d2b4d3SLarry Finger bool rtstatus = true; 919f1d2b4d3SLarry Finger int err; 920f1d2b4d3SLarry Finger u8 tmp_u1b; 921f1d2b4d3SLarry Finger unsigned long flags; 922f1d2b4d3SLarry Finger 923f1d2b4d3SLarry Finger rtlpriv->rtlhal.being_init_adapter = true; 924f1d2b4d3SLarry Finger /* As this function can take a very long time (up to 350 ms) 925f1d2b4d3SLarry Finger * and can be called with irqs disabled, reenable the irqs 926f1d2b4d3SLarry Finger * to let the other devices continue being serviced. 927f1d2b4d3SLarry Finger * 928f1d2b4d3SLarry Finger * It is safe doing so since our own interrupts will only be enabled 929f1d2b4d3SLarry Finger * in a subsequent step. 930f1d2b4d3SLarry Finger */ 931f1d2b4d3SLarry Finger local_save_flags(flags); 932f1d2b4d3SLarry Finger local_irq_enable(); 933f1d2b4d3SLarry Finger rtlhal->fw_ready = false; 934f1d2b4d3SLarry Finger 935f1d2b4d3SLarry Finger rtlpriv->intf_ops->disable_aspm(hw); 936f1d2b4d3SLarry Finger rtstatus = _rtl8712e_init_mac(hw); 937f1d2b4d3SLarry Finger if (rtstatus != true) { 938a67005bcSLarry Finger pr_err("Init MAC failed\n"); 939f1d2b4d3SLarry Finger err = 1; 940f1d2b4d3SLarry Finger goto exit; 941f1d2b4d3SLarry Finger } 942f1d2b4d3SLarry Finger 943f1d2b4d3SLarry Finger err = rtl8723_download_fw(hw, false, FW_8723A_POLLING_TIMEOUT_COUNT); 944f1d2b4d3SLarry Finger if (err) { 945f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, 946f1d2b4d3SLarry Finger "Failed to download FW. Init HW without FW now..\n"); 947f1d2b4d3SLarry Finger err = 1; 948f1d2b4d3SLarry Finger goto exit; 949f1d2b4d3SLarry Finger } 950f1d2b4d3SLarry Finger rtlhal->fw_ready = true; 951f1d2b4d3SLarry Finger 952f1d2b4d3SLarry Finger rtlhal->last_hmeboxnum = 0; 953f1d2b4d3SLarry Finger rtl8723e_phy_mac_config(hw); 954f1d2b4d3SLarry Finger /* because last function modify RCR, so we update 955f1d2b4d3SLarry Finger * rcr var here, or TP will unstable for receive_config 956f1d2b4d3SLarry Finger * is wrong, RX RCR_ACRC32 will cause TP unstable & Rx 957f1d2b4d3SLarry Finger * RCR_APP_ICV will cause mac80211 unassoc for cisco 1252 958f1d2b4d3SLarry Finger */ 959f1d2b4d3SLarry Finger rtlpci->receive_config = rtl_read_dword(rtlpriv, REG_RCR); 960f1d2b4d3SLarry Finger rtlpci->receive_config &= ~(RCR_ACRC32 | RCR_AICV); 961f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_RCR, rtlpci->receive_config); 962f1d2b4d3SLarry Finger 963f1d2b4d3SLarry Finger rtl8723e_phy_bb_config(hw); 964f1d2b4d3SLarry Finger rtlphy->rf_mode = RF_OP_BY_SW_3WIRE; 965f1d2b4d3SLarry Finger rtl8723e_phy_rf_config(hw); 966f1d2b4d3SLarry Finger if (IS_VENDOR_UMC_A_CUT(rtlhal->version)) { 967f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G1, MASKDWORD, 0x30255); 968f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, RF_RX_G2, MASKDWORD, 0x50a00); 969f1d2b4d3SLarry Finger } else if (IS_81xxC_VENDOR_UMC_B_CUT(rtlhal->version)) { 970f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, 0x0C, MASKDWORD, 0x894AE); 971f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, 0x0A, MASKDWORD, 0x1AF31); 972f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, RF_IPA, MASKDWORD, 0x8F425); 973f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, RF_SYN_G2, MASKDWORD, 0x4F200); 974f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK1, MASKDWORD, 0x44053); 975f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, RF_RCK2, MASKDWORD, 0x80201); 976f1d2b4d3SLarry Finger } 977f1d2b4d3SLarry Finger rtlphy->rfreg_chnlval[0] = rtl_get_rfreg(hw, (enum radio_path)0, 978f1d2b4d3SLarry Finger RF_CHNLBW, RFREG_OFFSET_MASK); 979f1d2b4d3SLarry Finger rtlphy->rfreg_chnlval[1] = rtl_get_rfreg(hw, (enum radio_path)1, 980f1d2b4d3SLarry Finger RF_CHNLBW, RFREG_OFFSET_MASK); 981f1d2b4d3SLarry Finger rtl_set_bbreg(hw, RFPGA0_RFMOD, BCCKEN, 0x1); 982f1d2b4d3SLarry Finger rtl_set_bbreg(hw, RFPGA0_RFMOD, BOFDMEN, 0x1); 983f1d2b4d3SLarry Finger rtl_set_bbreg(hw, RFPGA0_ANALOGPARAMETER2, BIT(10), 1); 984f1d2b4d3SLarry Finger _rtl8723e_hw_configure(hw); 985f1d2b4d3SLarry Finger rtl_cam_reset_all_entry(hw); 986f1d2b4d3SLarry Finger rtl8723e_enable_hw_security_config(hw); 987f1d2b4d3SLarry Finger 988f1d2b4d3SLarry Finger ppsc->rfpwr_state = ERFON; 989f1d2b4d3SLarry Finger 990f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_ETHER_ADDR, mac->mac_addr); 991f1d2b4d3SLarry Finger _rtl8723e_enable_aspm_back_door(hw); 992f1d2b4d3SLarry Finger rtlpriv->intf_ops->enable_aspm(hw); 993f1d2b4d3SLarry Finger 994f1d2b4d3SLarry Finger rtl8723e_bt_hw_init(hw); 995f1d2b4d3SLarry Finger 996f1d2b4d3SLarry Finger if (ppsc->rfpwr_state == ERFON) { 997f1d2b4d3SLarry Finger rtl8723e_phy_set_rfpath_switch(hw, 1); 998f1d2b4d3SLarry Finger if (rtlphy->iqk_initialized) { 999f1d2b4d3SLarry Finger rtl8723e_phy_iq_calibrate(hw, true); 1000f1d2b4d3SLarry Finger } else { 1001f1d2b4d3SLarry Finger rtl8723e_phy_iq_calibrate(hw, false); 1002f1d2b4d3SLarry Finger rtlphy->iqk_initialized = true; 1003f1d2b4d3SLarry Finger } 1004f1d2b4d3SLarry Finger 1005f1d2b4d3SLarry Finger rtl8723e_dm_check_txpower_tracking(hw); 1006f1d2b4d3SLarry Finger rtl8723e_phy_lc_calibrate(hw); 1007f1d2b4d3SLarry Finger } 1008f1d2b4d3SLarry Finger 1009f1d2b4d3SLarry Finger tmp_u1b = efuse_read_1byte(hw, 0x1FA); 1010f1d2b4d3SLarry Finger if (!(tmp_u1b & BIT(0))) { 1011f1d2b4d3SLarry Finger rtl_set_rfreg(hw, RF90_PATH_A, 0x15, 0x0F, 0x05); 1012f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "PA BIAS path A\n"); 1013f1d2b4d3SLarry Finger } 1014f1d2b4d3SLarry Finger 1015f1d2b4d3SLarry Finger if (!(tmp_u1b & BIT(4))) { 1016f1d2b4d3SLarry Finger tmp_u1b = rtl_read_byte(rtlpriv, 0x16); 1017f1d2b4d3SLarry Finger tmp_u1b &= 0x0F; 1018f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x80); 1019f1d2b4d3SLarry Finger udelay(10); 1020f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x16, tmp_u1b | 0x90); 1021f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, "under 1.5V\n"); 1022f1d2b4d3SLarry Finger } 1023f1d2b4d3SLarry Finger rtl8723e_dm_init(hw); 1024f1d2b4d3SLarry Finger exit: 1025f1d2b4d3SLarry Finger local_irq_restore(flags); 1026f1d2b4d3SLarry Finger rtlpriv->rtlhal.being_init_adapter = false; 1027f1d2b4d3SLarry Finger return err; 1028f1d2b4d3SLarry Finger } 1029f1d2b4d3SLarry Finger 1030f1d2b4d3SLarry Finger static enum version_8723e _rtl8723e_read_chip_version(struct ieee80211_hw *hw) 1031f1d2b4d3SLarry Finger { 1032f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1033f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &(rtlpriv->phy); 1034f1d2b4d3SLarry Finger enum version_8723e version = 0x0000; 1035f1d2b4d3SLarry Finger u32 value32; 1036f1d2b4d3SLarry Finger 1037f1d2b4d3SLarry Finger value32 = rtl_read_dword(rtlpriv, REG_SYS_CFG); 1038f1d2b4d3SLarry Finger if (value32 & TRP_VAUX_EN) { 1039f1d2b4d3SLarry Finger version = (enum version_8723e)(version | 1040f1d2b4d3SLarry Finger ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0)); 1041f1d2b4d3SLarry Finger /* RTL8723 with BT function. */ 1042f1d2b4d3SLarry Finger version = (enum version_8723e)(version | 1043f1d2b4d3SLarry Finger ((value32 & BT_FUNC) ? CHIP_8723 : 0)); 1044f1d2b4d3SLarry Finger 1045f1d2b4d3SLarry Finger } else { 1046f1d2b4d3SLarry Finger /* Normal mass production chip. */ 1047f1d2b4d3SLarry Finger version = (enum version_8723e) NORMAL_CHIP; 1048f1d2b4d3SLarry Finger version = (enum version_8723e)(version | 1049f1d2b4d3SLarry Finger ((value32 & VENDOR_ID) ? CHIP_VENDOR_UMC : 0)); 1050f1d2b4d3SLarry Finger /* RTL8723 with BT function. */ 1051f1d2b4d3SLarry Finger version = (enum version_8723e)(version | 1052f1d2b4d3SLarry Finger ((value32 & BT_FUNC) ? CHIP_8723 : 0)); 1053f1d2b4d3SLarry Finger if (IS_CHIP_VENDOR_UMC(version)) 1054f1d2b4d3SLarry Finger version = (enum version_8723e)(version | 1055f1d2b4d3SLarry Finger ((value32 & CHIP_VER_RTL_MASK)));/* IC version (CUT) */ 1056f1d2b4d3SLarry Finger if (IS_8723_SERIES(version)) { 1057f1d2b4d3SLarry Finger value32 = rtl_read_dword(rtlpriv, REG_GPIO_OUTSTS); 1058f1d2b4d3SLarry Finger /* ROM code version. */ 1059f1d2b4d3SLarry Finger version = (enum version_8723e)(version | 1060f1d2b4d3SLarry Finger ((value32 & RF_RL_ID)>>20)); 1061f1d2b4d3SLarry Finger } 1062f1d2b4d3SLarry Finger } 1063f1d2b4d3SLarry Finger 1064f1d2b4d3SLarry Finger if (IS_8723_SERIES(version)) { 1065f1d2b4d3SLarry Finger value32 = rtl_read_dword(rtlpriv, REG_MULTI_FUNC_CTRL); 1066f1d2b4d3SLarry Finger rtlphy->polarity_ctl = ((value32 & WL_HWPDN_SL) ? 1067f1d2b4d3SLarry Finger RT_POLARITY_HIGH_ACT : 1068f1d2b4d3SLarry Finger RT_POLARITY_LOW_ACT); 1069f1d2b4d3SLarry Finger } 1070f1d2b4d3SLarry Finger switch (version) { 1071f1d2b4d3SLarry Finger case VERSION_TEST_UMC_CHIP_8723: 1072f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 1073f1d2b4d3SLarry Finger "Chip Version ID: VERSION_TEST_UMC_CHIP_8723.\n"); 1074f1d2b4d3SLarry Finger break; 1075f1d2b4d3SLarry Finger case VERSION_NORMAL_UMC_CHIP_8723_1T1R_A_CUT: 1076f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 1077f1d2b4d3SLarry Finger "Chip Version ID: VERSION_NORMAL_UMC_CHIP_8723_1T1R_A_CUT.\n"); 1078f1d2b4d3SLarry Finger break; 1079f1d2b4d3SLarry Finger case VERSION_NORMAL_UMC_CHIP_8723_1T1R_B_CUT: 1080f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 1081f1d2b4d3SLarry Finger "Chip Version ID: VERSION_NORMAL_UMC_CHIP_8723_1T1R_B_CUT.\n"); 1082f1d2b4d3SLarry Finger break; 1083f1d2b4d3SLarry Finger default: 1084a67005bcSLarry Finger pr_err("Chip Version ID: Unknown. Bug?\n"); 1085f1d2b4d3SLarry Finger break; 1086f1d2b4d3SLarry Finger } 1087f1d2b4d3SLarry Finger 1088f1d2b4d3SLarry Finger if (IS_8723_SERIES(version)) 1089f1d2b4d3SLarry Finger rtlphy->rf_type = RF_1T1R; 1090f1d2b4d3SLarry Finger 1091f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Chip RF Type: %s\n", 1092f1d2b4d3SLarry Finger (rtlphy->rf_type == RF_2T2R) ? "RF_2T2R" : "RF_1T1R"); 1093f1d2b4d3SLarry Finger 1094f1d2b4d3SLarry Finger return version; 1095f1d2b4d3SLarry Finger } 1096f1d2b4d3SLarry Finger 1097f1d2b4d3SLarry Finger static int _rtl8723e_set_media_status(struct ieee80211_hw *hw, 1098f1d2b4d3SLarry Finger enum nl80211_iftype type) 1099f1d2b4d3SLarry Finger { 1100f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1101f1d2b4d3SLarry Finger u8 bt_msr = rtl_read_byte(rtlpriv, MSR) & 0xfc; 1102f1d2b4d3SLarry Finger enum led_ctl_mode ledaction = LED_CTL_NO_LINK; 1103f1d2b4d3SLarry Finger u8 mode = MSR_NOLINK; 1104f1d2b4d3SLarry Finger 1105f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_BCN_CTRL, 0); 1106f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BEACON, DBG_LOUD, 1107f1d2b4d3SLarry Finger "clear 0x550 when set HW_VAR_MEDIA_STATUS\n"); 1108f1d2b4d3SLarry Finger 1109f1d2b4d3SLarry Finger switch (type) { 1110f1d2b4d3SLarry Finger case NL80211_IFTYPE_UNSPECIFIED: 1111f1d2b4d3SLarry Finger mode = MSR_NOLINK; 1112f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 1113f1d2b4d3SLarry Finger "Set Network type to NO LINK!\n"); 1114f1d2b4d3SLarry Finger break; 1115f1d2b4d3SLarry Finger case NL80211_IFTYPE_ADHOC: 1116f1d2b4d3SLarry Finger mode = MSR_ADHOC; 1117f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 1118f1d2b4d3SLarry Finger "Set Network type to Ad Hoc!\n"); 1119f1d2b4d3SLarry Finger break; 1120f1d2b4d3SLarry Finger case NL80211_IFTYPE_STATION: 1121f1d2b4d3SLarry Finger mode = MSR_INFRA; 1122f1d2b4d3SLarry Finger ledaction = LED_CTL_LINK; 1123f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 1124f1d2b4d3SLarry Finger "Set Network type to STA!\n"); 1125f1d2b4d3SLarry Finger break; 1126f1d2b4d3SLarry Finger case NL80211_IFTYPE_AP: 1127f1d2b4d3SLarry Finger mode = MSR_AP; 1128f1d2b4d3SLarry Finger ledaction = LED_CTL_LINK; 1129f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_TRACE, 1130f1d2b4d3SLarry Finger "Set Network type to AP!\n"); 1131f1d2b4d3SLarry Finger break; 1132f1d2b4d3SLarry Finger default: 1133a67005bcSLarry Finger pr_err("Network type %d not support!\n", type); 1134f1d2b4d3SLarry Finger return 1; 1135f1d2b4d3SLarry Finger break; 1136f1d2b4d3SLarry Finger } 1137f1d2b4d3SLarry Finger 1138f1d2b4d3SLarry Finger /* MSR_INFRA == Link in infrastructure network; 1139f1d2b4d3SLarry Finger * MSR_ADHOC == Link in ad hoc network; 1140f1d2b4d3SLarry Finger * Therefore, check link state is necessary. 1141f1d2b4d3SLarry Finger * 1142f1d2b4d3SLarry Finger * MSR_AP == AP mode; link state is not cared here. 1143f1d2b4d3SLarry Finger */ 1144f1d2b4d3SLarry Finger if (mode != MSR_AP && 1145f1d2b4d3SLarry Finger rtlpriv->mac80211.link_state < MAC80211_LINKED) { 1146f1d2b4d3SLarry Finger mode = MSR_NOLINK; 1147f1d2b4d3SLarry Finger ledaction = LED_CTL_NO_LINK; 1148f1d2b4d3SLarry Finger } 1149f1d2b4d3SLarry Finger if (mode == MSR_NOLINK || mode == MSR_INFRA) { 1150f1d2b4d3SLarry Finger _rtl8723e_stop_tx_beacon(hw); 1151f1d2b4d3SLarry Finger _rtl8723e_enable_bcn_sub_func(hw); 1152f1d2b4d3SLarry Finger } else if (mode == MSR_ADHOC || mode == MSR_AP) { 1153f1d2b4d3SLarry Finger _rtl8723e_resume_tx_beacon(hw); 1154f1d2b4d3SLarry Finger _rtl8723e_disable_bcn_sub_func(hw); 1155f1d2b4d3SLarry Finger } else { 1156f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, 1157f1d2b4d3SLarry Finger "Set HW_VAR_MEDIA_STATUS: No such media status(%x).\n", 1158f1d2b4d3SLarry Finger mode); 1159f1d2b4d3SLarry Finger } 1160f1d2b4d3SLarry Finger 1161f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, MSR, bt_msr | mode); 1162f1d2b4d3SLarry Finger rtlpriv->cfg->ops->led_control(hw, ledaction); 1163f1d2b4d3SLarry Finger if (mode == MSR_AP) 1164f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x00); 1165f1d2b4d3SLarry Finger else 1166f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_BCNTCFG + 1, 0x66); 1167f1d2b4d3SLarry Finger return 0; 1168f1d2b4d3SLarry Finger } 1169f1d2b4d3SLarry Finger 1170f1d2b4d3SLarry Finger void rtl8723e_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid) 1171f1d2b4d3SLarry Finger { 1172f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1173f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 1174f1d2b4d3SLarry Finger u32 reg_rcr = rtlpci->receive_config; 1175f1d2b4d3SLarry Finger 1176f1d2b4d3SLarry Finger if (rtlpriv->psc.rfpwr_state != ERFON) 1177f1d2b4d3SLarry Finger return; 1178f1d2b4d3SLarry Finger 1179f1d2b4d3SLarry Finger if (check_bssid) { 1180f1d2b4d3SLarry Finger reg_rcr |= (RCR_CBSSID_DATA | RCR_CBSSID_BCN); 1181f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_RCR, 1182f1d2b4d3SLarry Finger (u8 *)(®_rcr)); 1183f1d2b4d3SLarry Finger _rtl8723e_set_bcn_ctrl_reg(hw, 0, BIT(4)); 1184f1d2b4d3SLarry Finger } else if (!check_bssid) { 1185f1d2b4d3SLarry Finger reg_rcr &= (~(RCR_CBSSID_DATA | RCR_CBSSID_BCN)); 1186f1d2b4d3SLarry Finger _rtl8723e_set_bcn_ctrl_reg(hw, BIT(4), 0); 1187f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, 1188f1d2b4d3SLarry Finger HW_VAR_RCR, (u8 *)(®_rcr)); 1189f1d2b4d3SLarry Finger } 1190f1d2b4d3SLarry Finger } 1191f1d2b4d3SLarry Finger 1192f1d2b4d3SLarry Finger int rtl8723e_set_network_type(struct ieee80211_hw *hw, 1193f1d2b4d3SLarry Finger enum nl80211_iftype type) 1194f1d2b4d3SLarry Finger { 1195f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1196f1d2b4d3SLarry Finger 1197f1d2b4d3SLarry Finger if (_rtl8723e_set_media_status(hw, type)) 1198f1d2b4d3SLarry Finger return -EOPNOTSUPP; 1199f1d2b4d3SLarry Finger 1200f1d2b4d3SLarry Finger if (rtlpriv->mac80211.link_state == MAC80211_LINKED) { 1201f1d2b4d3SLarry Finger if (type != NL80211_IFTYPE_AP) 1202f1d2b4d3SLarry Finger rtl8723e_set_check_bssid(hw, true); 1203f1d2b4d3SLarry Finger } else { 1204f1d2b4d3SLarry Finger rtl8723e_set_check_bssid(hw, false); 1205f1d2b4d3SLarry Finger } 1206f1d2b4d3SLarry Finger 1207f1d2b4d3SLarry Finger return 0; 1208f1d2b4d3SLarry Finger } 1209f1d2b4d3SLarry Finger 1210f1d2b4d3SLarry Finger /* don't set REG_EDCA_BE_PARAM here 1211f1d2b4d3SLarry Finger * because mac80211 will send pkt when scan 1212f1d2b4d3SLarry Finger */ 1213f1d2b4d3SLarry Finger void rtl8723e_set_qos(struct ieee80211_hw *hw, int aci) 1214f1d2b4d3SLarry Finger { 1215f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1216f1d2b4d3SLarry Finger 1217f1d2b4d3SLarry Finger rtl8723_dm_init_edca_turbo(hw); 1218f1d2b4d3SLarry Finger switch (aci) { 1219f1d2b4d3SLarry Finger case AC1_BK: 1220f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_EDCA_BK_PARAM, 0xa44f); 1221f1d2b4d3SLarry Finger break; 1222f1d2b4d3SLarry Finger case AC0_BE: 1223f1d2b4d3SLarry Finger break; 1224f1d2b4d3SLarry Finger case AC2_VI: 1225f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_EDCA_VI_PARAM, 0x5e4322); 1226f1d2b4d3SLarry Finger break; 1227f1d2b4d3SLarry Finger case AC3_VO: 1228f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_EDCA_VO_PARAM, 0x2f3222); 1229f1d2b4d3SLarry Finger break; 1230f1d2b4d3SLarry Finger default: 1231531940f9SLarry Finger WARN_ONCE(true, "rtl8723ae: invalid aci: %d !\n", aci); 1232f1d2b4d3SLarry Finger break; 1233f1d2b4d3SLarry Finger } 1234f1d2b4d3SLarry Finger } 1235f1d2b4d3SLarry Finger 1236f1d2b4d3SLarry Finger void rtl8723e_enable_interrupt(struct ieee80211_hw *hw) 1237f1d2b4d3SLarry Finger { 1238f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1239f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 1240f1d2b4d3SLarry Finger 1241f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, 0x3a8, rtlpci->irq_mask[0] & 0xFFFFFFFF); 1242f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, 0x3ac, rtlpci->irq_mask[1] & 0xFFFFFFFF); 1243f1d2b4d3SLarry Finger rtlpci->irq_enabled = true; 1244f1d2b4d3SLarry Finger } 1245f1d2b4d3SLarry Finger 1246f1d2b4d3SLarry Finger void rtl8723e_disable_interrupt(struct ieee80211_hw *hw) 1247f1d2b4d3SLarry Finger { 1248f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1249f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 1250f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, 0x3a8, IMR8190_DISABLED); 1251f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, 0x3ac, IMR8190_DISABLED); 1252f1d2b4d3SLarry Finger rtlpci->irq_enabled = false; 1253f1d2b4d3SLarry Finger /*synchronize_irq(rtlpci->pdev->irq);*/ 1254f1d2b4d3SLarry Finger } 1255f1d2b4d3SLarry Finger 1256f1d2b4d3SLarry Finger static void _rtl8723e_poweroff_adapter(struct ieee80211_hw *hw) 1257f1d2b4d3SLarry Finger { 1258f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1259f1d2b4d3SLarry Finger struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 1260f1d2b4d3SLarry Finger u8 u1b_tmp; 1261f1d2b4d3SLarry Finger 1262f1d2b4d3SLarry Finger /* Combo (PCIe + USB) Card and PCIe-MF Card */ 1263f1d2b4d3SLarry Finger /* 1. Run LPS WL RFOFF flow */ 1264f1d2b4d3SLarry Finger rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, 1265f1d2b4d3SLarry Finger PWR_INTF_PCI_MSK, Rtl8723_NIC_LPS_ENTER_FLOW); 1266f1d2b4d3SLarry Finger 1267f1d2b4d3SLarry Finger /* 2. 0x1F[7:0] = 0 */ 1268f1d2b4d3SLarry Finger /* turn off RF */ 1269f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RF_CTRL, 0x00); 1270f1d2b4d3SLarry Finger if ((rtl_read_byte(rtlpriv, REG_MCUFWDL) & BIT(7)) && 1271f1d2b4d3SLarry Finger rtlhal->fw_ready) { 1272f1d2b4d3SLarry Finger rtl8723ae_firmware_selfreset(hw); 1273f1d2b4d3SLarry Finger } 1274f1d2b4d3SLarry Finger 1275f1d2b4d3SLarry Finger /* Reset MCU. Suggested by Filen. */ 1276f1d2b4d3SLarry Finger u1b_tmp = rtl_read_byte(rtlpriv, REG_SYS_FUNC_EN+1); 1277f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_SYS_FUNC_EN+1, (u1b_tmp & (~BIT(2)))); 1278f1d2b4d3SLarry Finger 1279f1d2b4d3SLarry Finger /* g. MCUFWDL 0x80[1:0]=0 */ 1280f1d2b4d3SLarry Finger /* reset MCU ready status */ 1281f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_MCUFWDL, 0x00); 1282f1d2b4d3SLarry Finger 1283f1d2b4d3SLarry Finger /* HW card disable configuration. */ 1284f1d2b4d3SLarry Finger rtl_hal_pwrseqcmdparsing(rtlpriv, PWR_CUT_ALL_MSK, PWR_FAB_ALL_MSK, 1285f1d2b4d3SLarry Finger PWR_INTF_PCI_MSK, Rtl8723_NIC_DISABLE_FLOW); 1286f1d2b4d3SLarry Finger 1287f1d2b4d3SLarry Finger /* Reset MCU IO Wrapper */ 1288f1d2b4d3SLarry Finger u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1); 1289f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, (u1b_tmp & (~BIT(0)))); 1290f1d2b4d3SLarry Finger u1b_tmp = rtl_read_byte(rtlpriv, REG_RSV_CTRL + 1); 1291f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RSV_CTRL + 1, u1b_tmp | BIT(0)); 1292f1d2b4d3SLarry Finger 1293f1d2b4d3SLarry Finger /* 7. RSV_CTRL 0x1C[7:0] = 0x0E */ 1294f1d2b4d3SLarry Finger /* lock ISO/CLK/Power control register */ 1295f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RSV_CTRL, 0x0e); 1296f1d2b4d3SLarry Finger } 1297f1d2b4d3SLarry Finger 1298f1d2b4d3SLarry Finger void rtl8723e_card_disable(struct ieee80211_hw *hw) 1299f1d2b4d3SLarry Finger { 1300f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1301f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 1302f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1303f1d2b4d3SLarry Finger enum nl80211_iftype opmode; 1304f1d2b4d3SLarry Finger 1305f1d2b4d3SLarry Finger mac->link_state = MAC80211_NOLINK; 1306f1d2b4d3SLarry Finger opmode = NL80211_IFTYPE_UNSPECIFIED; 1307f1d2b4d3SLarry Finger _rtl8723e_set_media_status(hw, opmode); 1308f1d2b4d3SLarry Finger if (rtlpriv->rtlhal.driver_is_goingto_unload || 1309f1d2b4d3SLarry Finger ppsc->rfoff_reason > RF_CHANGE_BY_PS) 1310f1d2b4d3SLarry Finger rtlpriv->cfg->ops->led_control(hw, LED_CTL_POWER_OFF); 1311f1d2b4d3SLarry Finger RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); 1312f1d2b4d3SLarry Finger _rtl8723e_poweroff_adapter(hw); 1313f1d2b4d3SLarry Finger 1314f1d2b4d3SLarry Finger /* after power off we should do iqk again */ 1315f1d2b4d3SLarry Finger rtlpriv->phy.iqk_initialized = false; 1316f1d2b4d3SLarry Finger } 1317f1d2b4d3SLarry Finger 1318f1d2b4d3SLarry Finger void rtl8723e_interrupt_recognized(struct ieee80211_hw *hw, 131978aa6012SLarry Finger struct rtl_int *intvec) 1320f1d2b4d3SLarry Finger { 1321f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1322f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 1323f1d2b4d3SLarry Finger 132478aa6012SLarry Finger intvec->inta = rtl_read_dword(rtlpriv, 0x3a0) & rtlpci->irq_mask[0]; 132578aa6012SLarry Finger rtl_write_dword(rtlpriv, 0x3a0, intvec->inta); 1326f1d2b4d3SLarry Finger } 1327f1d2b4d3SLarry Finger 1328f1d2b4d3SLarry Finger void rtl8723e_set_beacon_related_registers(struct ieee80211_hw *hw) 1329f1d2b4d3SLarry Finger { 1330f1d2b4d3SLarry Finger 1331f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1332f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1333f1d2b4d3SLarry Finger u16 bcn_interval, atim_window; 1334f1d2b4d3SLarry Finger 1335f1d2b4d3SLarry Finger bcn_interval = mac->beacon_interval; 1336f1d2b4d3SLarry Finger atim_window = 2; /*FIX MERGE */ 1337f1d2b4d3SLarry Finger rtl8723e_disable_interrupt(hw); 1338f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_ATIMWND, atim_window); 1339f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval); 1340f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_BCNTCFG, 0x660f); 1341f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_CCK, 0x18); 1342f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_RXTSF_OFFSET_OFDM, 0x18); 1343f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, 0x606, 0x30); 1344f1d2b4d3SLarry Finger rtl8723e_enable_interrupt(hw); 1345f1d2b4d3SLarry Finger } 1346f1d2b4d3SLarry Finger 1347f1d2b4d3SLarry Finger void rtl8723e_set_beacon_interval(struct ieee80211_hw *hw) 1348f1d2b4d3SLarry Finger { 1349f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1350f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1351f1d2b4d3SLarry Finger u16 bcn_interval = mac->beacon_interval; 1352f1d2b4d3SLarry Finger 1353f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BEACON, DBG_DMESG, 1354f1d2b4d3SLarry Finger "beacon_interval:%d\n", bcn_interval); 1355f1d2b4d3SLarry Finger rtl8723e_disable_interrupt(hw); 1356f1d2b4d3SLarry Finger rtl_write_word(rtlpriv, REG_BCN_INTERVAL, bcn_interval); 1357f1d2b4d3SLarry Finger rtl8723e_enable_interrupt(hw); 1358f1d2b4d3SLarry Finger } 1359f1d2b4d3SLarry Finger 1360f1d2b4d3SLarry Finger void rtl8723e_update_interrupt_mask(struct ieee80211_hw *hw, 1361f1d2b4d3SLarry Finger u32 add_msr, u32 rm_msr) 1362f1d2b4d3SLarry Finger { 1363f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1364f1d2b4d3SLarry Finger struct rtl_pci *rtlpci = rtl_pcidev(rtl_pcipriv(hw)); 1365f1d2b4d3SLarry Finger 1366f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INTR, DBG_LOUD, 1367f1d2b4d3SLarry Finger "add_msr:%x, rm_msr:%x\n", add_msr, rm_msr); 1368f1d2b4d3SLarry Finger 1369f1d2b4d3SLarry Finger if (add_msr) 1370f1d2b4d3SLarry Finger rtlpci->irq_mask[0] |= add_msr; 1371f1d2b4d3SLarry Finger if (rm_msr) 1372f1d2b4d3SLarry Finger rtlpci->irq_mask[0] &= (~rm_msr); 1373f1d2b4d3SLarry Finger rtl8723e_disable_interrupt(hw); 1374f1d2b4d3SLarry Finger rtl8723e_enable_interrupt(hw); 1375f1d2b4d3SLarry Finger } 1376f1d2b4d3SLarry Finger 1377f1d2b4d3SLarry Finger static u8 _rtl8723e_get_chnl_group(u8 chnl) 1378f1d2b4d3SLarry Finger { 1379f1d2b4d3SLarry Finger u8 group; 1380f1d2b4d3SLarry Finger 1381f1d2b4d3SLarry Finger if (chnl < 3) 1382f1d2b4d3SLarry Finger group = 0; 1383f1d2b4d3SLarry Finger else if (chnl < 9) 1384f1d2b4d3SLarry Finger group = 1; 1385f1d2b4d3SLarry Finger else 1386f1d2b4d3SLarry Finger group = 2; 1387f1d2b4d3SLarry Finger return group; 1388f1d2b4d3SLarry Finger } 1389f1d2b4d3SLarry Finger 1390f1d2b4d3SLarry Finger static void _rtl8723e_read_txpower_info_from_hwpg(struct ieee80211_hw *hw, 1391f1d2b4d3SLarry Finger bool autoload_fail, 1392f1d2b4d3SLarry Finger u8 *hwinfo) 1393f1d2b4d3SLarry Finger { 1394f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1395f1d2b4d3SLarry Finger struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 1396f1d2b4d3SLarry Finger u8 rf_path, index, tempval; 1397f1d2b4d3SLarry Finger u16 i; 1398f1d2b4d3SLarry Finger 1399f1d2b4d3SLarry Finger for (rf_path = 0; rf_path < 1; rf_path++) { 1400f1d2b4d3SLarry Finger for (i = 0; i < 3; i++) { 1401f1d2b4d3SLarry Finger if (!autoload_fail) { 1402f1d2b4d3SLarry Finger rtlefuse->eeprom_chnlarea_txpwr_cck[rf_path][i] = 1403f1d2b4d3SLarry Finger hwinfo[EEPROM_TXPOWERCCK + rf_path * 3 + i]; 1404f1d2b4d3SLarry Finger rtlefuse->eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] = 1405f1d2b4d3SLarry Finger hwinfo[EEPROM_TXPOWERHT40_1S + rf_path * 3 + i]; 1406f1d2b4d3SLarry Finger } else { 1407f1d2b4d3SLarry Finger rtlefuse->eeprom_chnlarea_txpwr_cck[rf_path][i] = 1408f1d2b4d3SLarry Finger EEPROM_DEFAULT_TXPOWERLEVEL; 1409f1d2b4d3SLarry Finger rtlefuse->eeprom_chnlarea_txpwr_ht40_1s[rf_path][i] = 1410f1d2b4d3SLarry Finger EEPROM_DEFAULT_TXPOWERLEVEL; 1411f1d2b4d3SLarry Finger } 1412f1d2b4d3SLarry Finger } 1413f1d2b4d3SLarry Finger } 1414f1d2b4d3SLarry Finger 1415f1d2b4d3SLarry Finger for (i = 0; i < 3; i++) { 1416f1d2b4d3SLarry Finger if (!autoload_fail) 1417f1d2b4d3SLarry Finger tempval = hwinfo[EEPROM_TXPOWERHT40_2SDIFF + i]; 1418f1d2b4d3SLarry Finger else 1419f1d2b4d3SLarry Finger tempval = EEPROM_DEFAULT_HT40_2SDIFF; 1420f1d2b4d3SLarry Finger rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_A][i] = 1421f1d2b4d3SLarry Finger (tempval & 0xf); 1422f1d2b4d3SLarry Finger rtlefuse->eprom_chnl_txpwr_ht40_2sdf[RF90_PATH_B][i] = 1423f1d2b4d3SLarry Finger ((tempval & 0xf0) >> 4); 1424f1d2b4d3SLarry Finger } 1425f1d2b4d3SLarry Finger 1426f1d2b4d3SLarry Finger for (rf_path = 0; rf_path < 2; rf_path++) 1427f1d2b4d3SLarry Finger for (i = 0; i < 3; i++) 1428f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_EEPROM, 1429f1d2b4d3SLarry Finger "RF(%d) EEPROM CCK Area(%d) = 0x%x\n", rf_path, 1430f1d2b4d3SLarry Finger i, rtlefuse->eeprom_chnlarea_txpwr_cck 1431f1d2b4d3SLarry Finger [rf_path][i]); 1432f1d2b4d3SLarry Finger for (rf_path = 0; rf_path < 2; rf_path++) 1433f1d2b4d3SLarry Finger for (i = 0; i < 3; i++) 1434f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_EEPROM, 1435f1d2b4d3SLarry Finger "RF(%d) EEPROM HT40 1S Area(%d) = 0x%x\n", 1436f1d2b4d3SLarry Finger rf_path, i, 1437f1d2b4d3SLarry Finger rtlefuse->eeprom_chnlarea_txpwr_ht40_1s 1438f1d2b4d3SLarry Finger [rf_path][i]); 1439f1d2b4d3SLarry Finger for (rf_path = 0; rf_path < 2; rf_path++) 1440f1d2b4d3SLarry Finger for (i = 0; i < 3; i++) 1441f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_EEPROM, 1442f1d2b4d3SLarry Finger "RF(%d) EEPROM HT40 2S Diff Area(%d) = 0x%x\n", 1443f1d2b4d3SLarry Finger rf_path, i, 1444f1d2b4d3SLarry Finger rtlefuse->eprom_chnl_txpwr_ht40_2sdf 1445f1d2b4d3SLarry Finger [rf_path][i]); 1446f1d2b4d3SLarry Finger 1447f1d2b4d3SLarry Finger for (rf_path = 0; rf_path < 2; rf_path++) { 1448f1d2b4d3SLarry Finger for (i = 0; i < 14; i++) { 1449f1d2b4d3SLarry Finger index = _rtl8723e_get_chnl_group((u8)i); 1450f1d2b4d3SLarry Finger 1451f1d2b4d3SLarry Finger rtlefuse->txpwrlevel_cck[rf_path][i] = 1452f1d2b4d3SLarry Finger rtlefuse->eeprom_chnlarea_txpwr_cck 1453f1d2b4d3SLarry Finger [rf_path][index]; 1454f1d2b4d3SLarry Finger rtlefuse->txpwrlevel_ht40_1s[rf_path][i] = 1455f1d2b4d3SLarry Finger rtlefuse->eeprom_chnlarea_txpwr_ht40_1s 1456f1d2b4d3SLarry Finger [rf_path][index]; 1457f1d2b4d3SLarry Finger 1458f1d2b4d3SLarry Finger if ((rtlefuse->eeprom_chnlarea_txpwr_ht40_1s 1459f1d2b4d3SLarry Finger [rf_path][index] - 1460f1d2b4d3SLarry Finger rtlefuse->eprom_chnl_txpwr_ht40_2sdf 1461f1d2b4d3SLarry Finger [rf_path][index]) > 0) { 1462f1d2b4d3SLarry Finger rtlefuse->txpwrlevel_ht40_2s[rf_path][i] = 1463f1d2b4d3SLarry Finger rtlefuse->eeprom_chnlarea_txpwr_ht40_1s 1464f1d2b4d3SLarry Finger [rf_path][index] - 1465f1d2b4d3SLarry Finger rtlefuse->eprom_chnl_txpwr_ht40_2sdf 1466f1d2b4d3SLarry Finger [rf_path][index]; 1467f1d2b4d3SLarry Finger } else { 1468f1d2b4d3SLarry Finger rtlefuse->txpwrlevel_ht40_2s[rf_path][i] = 0; 1469f1d2b4d3SLarry Finger } 1470f1d2b4d3SLarry Finger } 1471f1d2b4d3SLarry Finger 1472f1d2b4d3SLarry Finger for (i = 0; i < 14; i++) { 1473f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, 1474f1d2b4d3SLarry Finger "RF(%d)-Ch(%d) [CCK / HT40_1S / HT40_2S] = [0x%x / 0x%x / 0x%x]\n", 1475f1d2b4d3SLarry Finger rf_path, i, 1476f1d2b4d3SLarry Finger rtlefuse->txpwrlevel_cck[rf_path][i], 1477f1d2b4d3SLarry Finger rtlefuse->txpwrlevel_ht40_1s[rf_path][i], 1478f1d2b4d3SLarry Finger rtlefuse->txpwrlevel_ht40_2s[rf_path][i]); 1479f1d2b4d3SLarry Finger } 1480f1d2b4d3SLarry Finger } 1481f1d2b4d3SLarry Finger 1482f1d2b4d3SLarry Finger for (i = 0; i < 3; i++) { 1483f1d2b4d3SLarry Finger if (!autoload_fail) { 1484f1d2b4d3SLarry Finger rtlefuse->eeprom_pwrlimit_ht40[i] = 1485f1d2b4d3SLarry Finger hwinfo[EEPROM_TXPWR_GROUP + i]; 1486f1d2b4d3SLarry Finger rtlefuse->eeprom_pwrlimit_ht20[i] = 1487f1d2b4d3SLarry Finger hwinfo[EEPROM_TXPWR_GROUP + 3 + i]; 1488f1d2b4d3SLarry Finger } else { 1489f1d2b4d3SLarry Finger rtlefuse->eeprom_pwrlimit_ht40[i] = 0; 1490f1d2b4d3SLarry Finger rtlefuse->eeprom_pwrlimit_ht20[i] = 0; 1491f1d2b4d3SLarry Finger } 1492f1d2b4d3SLarry Finger } 1493f1d2b4d3SLarry Finger 1494f1d2b4d3SLarry Finger for (rf_path = 0; rf_path < 2; rf_path++) { 1495f1d2b4d3SLarry Finger for (i = 0; i < 14; i++) { 1496f1d2b4d3SLarry Finger index = _rtl8723e_get_chnl_group((u8)i); 1497f1d2b4d3SLarry Finger 1498f1d2b4d3SLarry Finger if (rf_path == RF90_PATH_A) { 1499f1d2b4d3SLarry Finger rtlefuse->pwrgroup_ht20[rf_path][i] = 1500f1d2b4d3SLarry Finger (rtlefuse->eeprom_pwrlimit_ht20[index] & 0xf); 1501f1d2b4d3SLarry Finger rtlefuse->pwrgroup_ht40[rf_path][i] = 1502f1d2b4d3SLarry Finger (rtlefuse->eeprom_pwrlimit_ht40[index] & 0xf); 1503f1d2b4d3SLarry Finger } else if (rf_path == RF90_PATH_B) { 1504f1d2b4d3SLarry Finger rtlefuse->pwrgroup_ht20[rf_path][i] = 1505f1d2b4d3SLarry Finger ((rtlefuse->eeprom_pwrlimit_ht20[index] & 1506f1d2b4d3SLarry Finger 0xf0) >> 4); 1507f1d2b4d3SLarry Finger rtlefuse->pwrgroup_ht40[rf_path][i] = 1508f1d2b4d3SLarry Finger ((rtlefuse->eeprom_pwrlimit_ht40[index] & 1509f1d2b4d3SLarry Finger 0xf0) >> 4); 1510f1d2b4d3SLarry Finger } 1511f1d2b4d3SLarry Finger 1512f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, 1513f1d2b4d3SLarry Finger "RF-%d pwrgroup_ht20[%d] = 0x%x\n", rf_path, i, 1514f1d2b4d3SLarry Finger rtlefuse->pwrgroup_ht20[rf_path][i]); 1515f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, 1516f1d2b4d3SLarry Finger "RF-%d pwrgroup_ht40[%d] = 0x%x\n", rf_path, i, 1517f1d2b4d3SLarry Finger rtlefuse->pwrgroup_ht40[rf_path][i]); 1518f1d2b4d3SLarry Finger } 1519f1d2b4d3SLarry Finger } 1520f1d2b4d3SLarry Finger 1521f1d2b4d3SLarry Finger for (i = 0; i < 14; i++) { 1522f1d2b4d3SLarry Finger index = _rtl8723e_get_chnl_group((u8)i); 1523f1d2b4d3SLarry Finger 1524f1d2b4d3SLarry Finger if (!autoload_fail) 1525f1d2b4d3SLarry Finger tempval = hwinfo[EEPROM_TXPOWERHT20DIFF + index]; 1526f1d2b4d3SLarry Finger else 1527f1d2b4d3SLarry Finger tempval = EEPROM_DEFAULT_HT20_DIFF; 1528f1d2b4d3SLarry Finger 1529f1d2b4d3SLarry Finger rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] = (tempval & 0xF); 1530f1d2b4d3SLarry Finger rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] = 1531f1d2b4d3SLarry Finger ((tempval >> 4) & 0xF); 1532f1d2b4d3SLarry Finger 1533f1d2b4d3SLarry Finger if (rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] & BIT(3)) 1534f1d2b4d3SLarry Finger rtlefuse->txpwr_ht20diff[RF90_PATH_A][i] |= 0xF0; 1535f1d2b4d3SLarry Finger 1536f1d2b4d3SLarry Finger if (rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] & BIT(3)) 1537f1d2b4d3SLarry Finger rtlefuse->txpwr_ht20diff[RF90_PATH_B][i] |= 0xF0; 1538f1d2b4d3SLarry Finger 1539f1d2b4d3SLarry Finger index = _rtl8723e_get_chnl_group((u8)i); 1540f1d2b4d3SLarry Finger 1541f1d2b4d3SLarry Finger if (!autoload_fail) 1542f1d2b4d3SLarry Finger tempval = hwinfo[EEPROM_TXPOWER_OFDMDIFF + index]; 1543f1d2b4d3SLarry Finger else 1544f1d2b4d3SLarry Finger tempval = EEPROM_DEFAULT_LEGACYHTTXPOWERDIFF; 1545f1d2b4d3SLarry Finger 1546f1d2b4d3SLarry Finger rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i] = (tempval & 0xF); 1547f1d2b4d3SLarry Finger rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i] = 1548f1d2b4d3SLarry Finger ((tempval >> 4) & 0xF); 1549f1d2b4d3SLarry Finger } 1550f1d2b4d3SLarry Finger 1551f1d2b4d3SLarry Finger rtlefuse->legacy_ht_txpowerdiff = 1552f1d2b4d3SLarry Finger rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][7]; 1553f1d2b4d3SLarry Finger 1554f1d2b4d3SLarry Finger for (i = 0; i < 14; i++) 1555f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, 1556f1d2b4d3SLarry Finger "RF-A Ht20 to HT40 Diff[%d] = 0x%x\n", i, 1557f1d2b4d3SLarry Finger rtlefuse->txpwr_ht20diff[RF90_PATH_A][i]); 1558f1d2b4d3SLarry Finger for (i = 0; i < 14; i++) 1559f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, 1560f1d2b4d3SLarry Finger "RF-A Legacy to Ht40 Diff[%d] = 0x%x\n", i, 1561f1d2b4d3SLarry Finger rtlefuse->txpwr_legacyhtdiff[RF90_PATH_A][i]); 1562f1d2b4d3SLarry Finger for (i = 0; i < 14; i++) 1563f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, 1564f1d2b4d3SLarry Finger "RF-B Ht20 to HT40 Diff[%d] = 0x%x\n", i, 1565f1d2b4d3SLarry Finger rtlefuse->txpwr_ht20diff[RF90_PATH_B][i]); 1566f1d2b4d3SLarry Finger for (i = 0; i < 14; i++) 1567f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, 1568f1d2b4d3SLarry Finger "RF-B Legacy to HT40 Diff[%d] = 0x%x\n", i, 1569f1d2b4d3SLarry Finger rtlefuse->txpwr_legacyhtdiff[RF90_PATH_B][i]); 1570f1d2b4d3SLarry Finger 1571f1d2b4d3SLarry Finger if (!autoload_fail) 1572f1d2b4d3SLarry Finger rtlefuse->eeprom_regulatory = (hwinfo[RF_OPTION1] & 0x7); 1573f1d2b4d3SLarry Finger else 1574f1d2b4d3SLarry Finger rtlefuse->eeprom_regulatory = 0; 1575f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, 1576f1d2b4d3SLarry Finger "eeprom_regulatory = 0x%x\n", rtlefuse->eeprom_regulatory); 1577f1d2b4d3SLarry Finger 1578f1d2b4d3SLarry Finger if (!autoload_fail) 1579f1d2b4d3SLarry Finger rtlefuse->eeprom_tssi[RF90_PATH_A] = hwinfo[EEPROM_TSSI_A]; 1580f1d2b4d3SLarry Finger else 1581f1d2b4d3SLarry Finger rtlefuse->eeprom_tssi[RF90_PATH_A] = EEPROM_DEFAULT_TSSI; 1582f1d2b4d3SLarry Finger 1583f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, 1584f1d2b4d3SLarry Finger "TSSI_A = 0x%x, TSSI_B = 0x%x\n", 1585f1d2b4d3SLarry Finger rtlefuse->eeprom_tssi[RF90_PATH_A], 1586f1d2b4d3SLarry Finger rtlefuse->eeprom_tssi[RF90_PATH_B]); 1587f1d2b4d3SLarry Finger 1588f1d2b4d3SLarry Finger if (!autoload_fail) 1589f1d2b4d3SLarry Finger tempval = hwinfo[EEPROM_THERMAL_METER]; 1590f1d2b4d3SLarry Finger else 1591f1d2b4d3SLarry Finger tempval = EEPROM_DEFAULT_THERMALMETER; 1592f1d2b4d3SLarry Finger rtlefuse->eeprom_thermalmeter = (tempval & 0x1f); 1593f1d2b4d3SLarry Finger 1594f1d2b4d3SLarry Finger if (rtlefuse->eeprom_thermalmeter == 0x1f || autoload_fail) 1595f1d2b4d3SLarry Finger rtlefuse->apk_thermalmeterignore = true; 1596f1d2b4d3SLarry Finger 1597f1d2b4d3SLarry Finger rtlefuse->thermalmeter[0] = rtlefuse->eeprom_thermalmeter; 1598f1d2b4d3SLarry Finger RTPRINT(rtlpriv, FINIT, INIT_TXPOWER, 1599f1d2b4d3SLarry Finger "thermalmeter = 0x%x\n", rtlefuse->eeprom_thermalmeter); 1600f1d2b4d3SLarry Finger } 1601f1d2b4d3SLarry Finger 1602f1d2b4d3SLarry Finger static void _rtl8723e_read_adapter_info(struct ieee80211_hw *hw, 1603f1d2b4d3SLarry Finger bool b_pseudo_test) 1604f1d2b4d3SLarry Finger { 1605f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1606f1d2b4d3SLarry Finger struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 1607f1d2b4d3SLarry Finger struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 16088aaf6916SLarry Finger int params[] = {RTL8190_EEPROM_ID, EEPROM_VID, EEPROM_DID, 16098aaf6916SLarry Finger EEPROM_SVID, EEPROM_SMID, EEPROM_MAC_ADDR, 16108aaf6916SLarry Finger EEPROM_CHANNELPLAN, EEPROM_VERSION, EEPROM_CUSTOMER_ID, 16118aaf6916SLarry Finger COUNTRY_CODE_WORLD_WIDE_13}; 16128aaf6916SLarry Finger u8 *hwinfo; 1613f1d2b4d3SLarry Finger 1614f1d2b4d3SLarry Finger if (b_pseudo_test) { 1615f1d2b4d3SLarry Finger /* need add */ 1616f1d2b4d3SLarry Finger return; 1617f1d2b4d3SLarry Finger } 16188aaf6916SLarry Finger hwinfo = kzalloc(HWSET_MAX_SIZE, GFP_KERNEL); 16198aaf6916SLarry Finger if (!hwinfo) 16205345ea6aSArnd Bergmann return; 16215345ea6aSArnd Bergmann 16228aaf6916SLarry Finger if (rtl_get_hwinfo(hw, rtlpriv, HWSET_MAX_SIZE, hwinfo, params)) 16238aaf6916SLarry Finger goto exit; 1624f1d2b4d3SLarry Finger 1625f1d2b4d3SLarry Finger _rtl8723e_read_txpower_info_from_hwpg(hw, rtlefuse->autoload_failflag, 1626f1d2b4d3SLarry Finger hwinfo); 1627f1d2b4d3SLarry Finger 1628f1d2b4d3SLarry Finger rtl8723e_read_bt_coexist_info_from_hwpg(hw, 1629f1d2b4d3SLarry Finger rtlefuse->autoload_failflag, hwinfo); 1630f1d2b4d3SLarry Finger 1631238ad2ddSLarry Finger if (rtlhal->oem_id != RT_CID_DEFAULT) 16323eeacaa9SChristian Engelmayer goto exit; 1633238ad2ddSLarry Finger 1634f1d2b4d3SLarry Finger switch (rtlefuse->eeprom_oemid) { 1635f1d2b4d3SLarry Finger case EEPROM_CID_DEFAULT: 1636238ad2ddSLarry Finger switch (rtlefuse->eeprom_did) { 1637238ad2ddSLarry Finger case 0x8176: 1638238ad2ddSLarry Finger switch (rtlefuse->eeprom_svid) { 1639238ad2ddSLarry Finger case 0x10EC: 1640238ad2ddSLarry Finger switch (rtlefuse->eeprom_smid) { 1641238ad2ddSLarry Finger case 0x6151 ... 0x6152: 1642238ad2ddSLarry Finger case 0x6154 ... 0x6155: 1643238ad2ddSLarry Finger case 0x6177 ... 0x6180: 1644238ad2ddSLarry Finger case 0x7151 ... 0x7152: 1645238ad2ddSLarry Finger case 0x7154 ... 0x7155: 1646238ad2ddSLarry Finger case 0x7177 ... 0x7180: 1647238ad2ddSLarry Finger case 0x8151 ... 0x8152: 1648238ad2ddSLarry Finger case 0x8154 ... 0x8155: 1649238ad2ddSLarry Finger case 0x8181 ... 0x8182: 1650238ad2ddSLarry Finger case 0x8184 ... 0x8185: 1651238ad2ddSLarry Finger case 0x9151 ... 0x9152: 1652238ad2ddSLarry Finger case 0x9154 ... 0x9155: 1653238ad2ddSLarry Finger case 0x9181 ... 0x9182: 1654238ad2ddSLarry Finger case 0x9184 ... 0x9185: 1655f1d2b4d3SLarry Finger rtlhal->oem_id = RT_CID_TOSHIBA; 1656238ad2ddSLarry Finger break; 1657238ad2ddSLarry Finger case 0x6191 ... 0x6193: 1658238ad2ddSLarry Finger case 0x7191 ... 0x7193: 1659238ad2ddSLarry Finger case 0x8191 ... 0x8193: 1660238ad2ddSLarry Finger case 0x9191 ... 0x9193: 1661f1d2b4d3SLarry Finger rtlhal->oem_id = RT_CID_819X_SAMSUNG; 1662238ad2ddSLarry Finger break; 1663238ad2ddSLarry Finger case 0x8197: 1664238ad2ddSLarry Finger case 0x9196: 1665f1d2b4d3SLarry Finger rtlhal->oem_id = RT_CID_819X_CLEVO; 1666238ad2ddSLarry Finger break; 1667238ad2ddSLarry Finger case 0x8203: 1668f1d2b4d3SLarry Finger rtlhal->oem_id = RT_CID_819X_PRONETS; 1669238ad2ddSLarry Finger break; 1670238ad2ddSLarry Finger case 0x8195: 1671238ad2ddSLarry Finger case 0x9195: 1672238ad2ddSLarry Finger case 0x7194: 1673238ad2ddSLarry Finger case 0x8200 ... 0x8202: 1674238ad2ddSLarry Finger case 0x9200: 1675238ad2ddSLarry Finger rtlhal->oem_id = RT_CID_819X_LENOVO; 1676238ad2ddSLarry Finger break; 1677238ad2ddSLarry Finger } 1678238ad2ddSLarry Finger case 0x1025: 1679f1d2b4d3SLarry Finger rtlhal->oem_id = RT_CID_819X_ACER; 1680238ad2ddSLarry Finger break; 1681238ad2ddSLarry Finger case 0x1028: 1682238ad2ddSLarry Finger switch (rtlefuse->eeprom_smid) { 1683238ad2ddSLarry Finger case 0x8194: 1684238ad2ddSLarry Finger case 0x8198: 1685238ad2ddSLarry Finger case 0x9197 ... 0x9198: 1686238ad2ddSLarry Finger rtlhal->oem_id = RT_CID_819X_DELL; 1687238ad2ddSLarry Finger break; 1688238ad2ddSLarry Finger } 1689238ad2ddSLarry Finger break; 1690238ad2ddSLarry Finger case 0x103C: 1691238ad2ddSLarry Finger switch (rtlefuse->eeprom_smid) { 1692238ad2ddSLarry Finger case 0x1629: 1693238ad2ddSLarry Finger rtlhal->oem_id = RT_CID_819X_HP; 1694238ad2ddSLarry Finger } 1695238ad2ddSLarry Finger break; 1696238ad2ddSLarry Finger case 0x1A32: 1697238ad2ddSLarry Finger switch (rtlefuse->eeprom_smid) { 1698238ad2ddSLarry Finger case 0x2315: 1699238ad2ddSLarry Finger rtlhal->oem_id = RT_CID_819X_QMI; 1700238ad2ddSLarry Finger break; 1701238ad2ddSLarry Finger } 1702238ad2ddSLarry Finger break; 1703238ad2ddSLarry Finger case 0x1043: 1704238ad2ddSLarry Finger switch (rtlefuse->eeprom_smid) { 1705238ad2ddSLarry Finger case 0x84B5: 1706f1d2b4d3SLarry Finger rtlhal->oem_id = 1707f1d2b4d3SLarry Finger RT_CID_819X_EDIMAX_ASUS; 1708238ad2ddSLarry Finger } 1709238ad2ddSLarry Finger break; 1710238ad2ddSLarry Finger } 1711238ad2ddSLarry Finger break; 1712238ad2ddSLarry Finger case 0x8178: 1713238ad2ddSLarry Finger switch (rtlefuse->eeprom_svid) { 1714238ad2ddSLarry Finger case 0x10ec: 1715238ad2ddSLarry Finger switch (rtlefuse->eeprom_smid) { 1716238ad2ddSLarry Finger case 0x6181 ... 0x6182: 1717238ad2ddSLarry Finger case 0x6184 ... 0x6185: 1718238ad2ddSLarry Finger case 0x7181 ... 0x7182: 1719238ad2ddSLarry Finger case 0x7184 ... 0x7185: 1720238ad2ddSLarry Finger case 0x8181 ... 0x8182: 1721238ad2ddSLarry Finger case 0x8184 ... 0x8185: 1722238ad2ddSLarry Finger case 0x9181 ... 0x9182: 1723238ad2ddSLarry Finger case 0x9184 ... 0x9185: 1724238ad2ddSLarry Finger rtlhal->oem_id = RT_CID_TOSHIBA; 1725238ad2ddSLarry Finger break; 1726238ad2ddSLarry Finger case 0x8186: 1727238ad2ddSLarry Finger rtlhal->oem_id = 1728238ad2ddSLarry Finger RT_CID_819X_PRONETS; 1729238ad2ddSLarry Finger break; 1730238ad2ddSLarry Finger } 1731238ad2ddSLarry Finger break; 1732238ad2ddSLarry Finger case 0x1025: 1733238ad2ddSLarry Finger rtlhal->oem_id = RT_CID_819X_ACER; 1734238ad2ddSLarry Finger break; 1735238ad2ddSLarry Finger case 0x1043: 1736238ad2ddSLarry Finger switch (rtlefuse->eeprom_smid) { 1737238ad2ddSLarry Finger case 0x8486: 1738238ad2ddSLarry Finger rtlhal->oem_id = 1739238ad2ddSLarry Finger RT_CID_819X_EDIMAX_ASUS; 1740238ad2ddSLarry Finger } 1741238ad2ddSLarry Finger break; 1742238ad2ddSLarry Finger } 1743238ad2ddSLarry Finger break; 1744f1d2b4d3SLarry Finger } 1745f1d2b4d3SLarry Finger break; 1746f1d2b4d3SLarry Finger case EEPROM_CID_TOSHIBA: 1747f1d2b4d3SLarry Finger rtlhal->oem_id = RT_CID_TOSHIBA; 1748f1d2b4d3SLarry Finger break; 1749f1d2b4d3SLarry Finger case EEPROM_CID_CCX: 1750f1d2b4d3SLarry Finger rtlhal->oem_id = RT_CID_CCX; 1751f1d2b4d3SLarry Finger break; 1752f1d2b4d3SLarry Finger case EEPROM_CID_QMI: 1753f1d2b4d3SLarry Finger rtlhal->oem_id = RT_CID_819X_QMI; 1754f1d2b4d3SLarry Finger break; 1755f1d2b4d3SLarry Finger case EEPROM_CID_WHQL: 1756f1d2b4d3SLarry Finger break; 1757f1d2b4d3SLarry Finger default: 1758f1d2b4d3SLarry Finger rtlhal->oem_id = RT_CID_DEFAULT; 1759f1d2b4d3SLarry Finger break; 1760f1d2b4d3SLarry Finger } 17618aaf6916SLarry Finger exit: 17628aaf6916SLarry Finger kfree(hwinfo); 1763f1d2b4d3SLarry Finger } 1764f1d2b4d3SLarry Finger 1765f1d2b4d3SLarry Finger static void _rtl8723e_hal_customized_behavior(struct ieee80211_hw *hw) 1766f1d2b4d3SLarry Finger { 1767f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1768f1d2b4d3SLarry Finger struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 1769f1d2b4d3SLarry Finger 1770d5efe153SLarry Finger rtlpriv->ledctl.led_opendrain = true; 1771f1d2b4d3SLarry Finger switch (rtlhal->oem_id) { 1772f1d2b4d3SLarry Finger case RT_CID_819X_HP: 1773d5efe153SLarry Finger rtlpriv->ledctl.led_opendrain = true; 1774f1d2b4d3SLarry Finger break; 1775f1d2b4d3SLarry Finger case RT_CID_819X_LENOVO: 1776f1d2b4d3SLarry Finger case RT_CID_DEFAULT: 1777f1d2b4d3SLarry Finger case RT_CID_TOSHIBA: 1778f1d2b4d3SLarry Finger case RT_CID_CCX: 1779f1d2b4d3SLarry Finger case RT_CID_819X_ACER: 1780f1d2b4d3SLarry Finger case RT_CID_WHQL: 1781f1d2b4d3SLarry Finger default: 1782f1d2b4d3SLarry Finger break; 1783f1d2b4d3SLarry Finger } 1784f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, 1785f1d2b4d3SLarry Finger "RT Customized ID: 0x%02X\n", rtlhal->oem_id); 1786f1d2b4d3SLarry Finger } 1787f1d2b4d3SLarry Finger 1788f1d2b4d3SLarry Finger void rtl8723e_read_eeprom_info(struct ieee80211_hw *hw) 1789f1d2b4d3SLarry Finger { 1790f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1791f1d2b4d3SLarry Finger struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 1792f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &(rtlpriv->phy); 1793f1d2b4d3SLarry Finger struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 1794f1d2b4d3SLarry Finger u8 tmp_u1b; 1795f1d2b4d3SLarry Finger u32 value32; 1796f1d2b4d3SLarry Finger 1797f1d2b4d3SLarry Finger value32 = rtl_read_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST]); 1798f1d2b4d3SLarry Finger value32 = (value32 & ~EFUSE_SEL_MASK) | EFUSE_SEL(EFUSE_WIFI_SEL_0); 1799f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, rtlpriv->cfg->maps[EFUSE_TEST], value32); 1800f1d2b4d3SLarry Finger 1801f1d2b4d3SLarry Finger rtlhal->version = _rtl8723e_read_chip_version(hw); 1802f1d2b4d3SLarry Finger 1803f1d2b4d3SLarry Finger if (get_rf_type(rtlphy) == RF_1T1R) 1804f1d2b4d3SLarry Finger rtlpriv->dm.rfpath_rxenable[0] = true; 1805f1d2b4d3SLarry Finger else 1806f1d2b4d3SLarry Finger rtlpriv->dm.rfpath_rxenable[0] = 1807f1d2b4d3SLarry Finger rtlpriv->dm.rfpath_rxenable[1] = true; 1808f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "VersionID = 0x%4x\n", 1809f1d2b4d3SLarry Finger rtlhal->version); 1810f1d2b4d3SLarry Finger 1811f1d2b4d3SLarry Finger tmp_u1b = rtl_read_byte(rtlpriv, REG_9346CR); 1812f1d2b4d3SLarry Finger if (tmp_u1b & BIT(4)) { 1813f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EEPROM\n"); 1814f1d2b4d3SLarry Finger rtlefuse->epromtype = EEPROM_93C46; 1815f1d2b4d3SLarry Finger } else { 1816f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "Boot from EFUSE\n"); 1817f1d2b4d3SLarry Finger rtlefuse->epromtype = EEPROM_BOOT_EFUSE; 1818f1d2b4d3SLarry Finger } 1819f1d2b4d3SLarry Finger if (tmp_u1b & BIT(5)) { 1820f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_INIT, DBG_LOUD, "Autoload OK\n"); 1821f1d2b4d3SLarry Finger rtlefuse->autoload_failflag = false; 1822f1d2b4d3SLarry Finger _rtl8723e_read_adapter_info(hw, false); 1823f1d2b4d3SLarry Finger } else { 1824f1d2b4d3SLarry Finger rtlefuse->autoload_failflag = true; 1825f1d2b4d3SLarry Finger _rtl8723e_read_adapter_info(hw, false); 1826a67005bcSLarry Finger pr_err("Autoload ERR!!\n"); 1827f1d2b4d3SLarry Finger } 1828f1d2b4d3SLarry Finger _rtl8723e_hal_customized_behavior(hw); 1829f1d2b4d3SLarry Finger } 1830f1d2b4d3SLarry Finger 1831f1d2b4d3SLarry Finger static void rtl8723e_update_hal_rate_table(struct ieee80211_hw *hw, 1832f1d2b4d3SLarry Finger struct ieee80211_sta *sta) 1833f1d2b4d3SLarry Finger { 1834f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1835f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &(rtlpriv->phy); 1836f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1837f1d2b4d3SLarry Finger struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 1838f1d2b4d3SLarry Finger u32 ratr_value; 1839f1d2b4d3SLarry Finger u8 ratr_index = 0; 1840f1d2b4d3SLarry Finger u8 b_nmode = mac->ht_enable; 1841f1d2b4d3SLarry Finger u16 shortgi_rate; 1842f1d2b4d3SLarry Finger u32 tmp_ratr_value; 1843f1d2b4d3SLarry Finger u8 curtxbw_40mhz = mac->bw_40; 1844f1d2b4d3SLarry Finger u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ? 1845f1d2b4d3SLarry Finger 1 : 0; 1846f1d2b4d3SLarry Finger u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ? 1847f1d2b4d3SLarry Finger 1 : 0; 1848f1d2b4d3SLarry Finger enum wireless_mode wirelessmode = mac->mode; 1849f1d2b4d3SLarry Finger u32 ratr_mask; 1850f1d2b4d3SLarry Finger 1851f1d2b4d3SLarry Finger if (rtlhal->current_bandtype == BAND_ON_5G) 1852f1d2b4d3SLarry Finger ratr_value = sta->supp_rates[1] << 4; 1853f1d2b4d3SLarry Finger else 1854f1d2b4d3SLarry Finger ratr_value = sta->supp_rates[0]; 1855f1d2b4d3SLarry Finger if (mac->opmode == NL80211_IFTYPE_ADHOC) 1856f1d2b4d3SLarry Finger ratr_value = 0xfff; 1857f1d2b4d3SLarry Finger ratr_value |= (sta->ht_cap.mcs.rx_mask[1] << 20 | 1858f1d2b4d3SLarry Finger sta->ht_cap.mcs.rx_mask[0] << 12); 1859f1d2b4d3SLarry Finger switch (wirelessmode) { 1860f1d2b4d3SLarry Finger case WIRELESS_MODE_B: 1861f1d2b4d3SLarry Finger if (ratr_value & 0x0000000c) 1862f1d2b4d3SLarry Finger ratr_value &= 0x0000000d; 1863f1d2b4d3SLarry Finger else 1864f1d2b4d3SLarry Finger ratr_value &= 0x0000000f; 1865f1d2b4d3SLarry Finger break; 1866f1d2b4d3SLarry Finger case WIRELESS_MODE_G: 1867f1d2b4d3SLarry Finger ratr_value &= 0x00000FF5; 1868f1d2b4d3SLarry Finger break; 1869f1d2b4d3SLarry Finger case WIRELESS_MODE_N_24G: 1870f1d2b4d3SLarry Finger case WIRELESS_MODE_N_5G: 1871f1d2b4d3SLarry Finger b_nmode = 1; 1872f1d2b4d3SLarry Finger if (get_rf_type(rtlphy) == RF_1T2R || 1873f1d2b4d3SLarry Finger get_rf_type(rtlphy) == RF_1T1R) 1874f1d2b4d3SLarry Finger ratr_mask = 0x000ff005; 1875f1d2b4d3SLarry Finger else 1876f1d2b4d3SLarry Finger ratr_mask = 0x0f0ff005; 1877f1d2b4d3SLarry Finger 1878f1d2b4d3SLarry Finger ratr_value &= ratr_mask; 1879f1d2b4d3SLarry Finger break; 1880f1d2b4d3SLarry Finger default: 1881f1d2b4d3SLarry Finger if (rtlphy->rf_type == RF_1T2R) 1882f1d2b4d3SLarry Finger ratr_value &= 0x000ff0ff; 1883f1d2b4d3SLarry Finger else 1884f1d2b4d3SLarry Finger ratr_value &= 0x0f0ff0ff; 1885f1d2b4d3SLarry Finger 1886f1d2b4d3SLarry Finger break; 1887f1d2b4d3SLarry Finger } 1888f1d2b4d3SLarry Finger 1889f1d2b4d3SLarry Finger if ((rtlpriv->btcoexist.bt_coexistence) && 1890f1d2b4d3SLarry Finger (rtlpriv->btcoexist.bt_coexist_type == BT_CSR_BC4) && 1891f1d2b4d3SLarry Finger (rtlpriv->btcoexist.bt_cur_state) && 1892f1d2b4d3SLarry Finger (rtlpriv->btcoexist.bt_ant_isolation) && 1893f1d2b4d3SLarry Finger ((rtlpriv->btcoexist.bt_service == BT_SCO) || 1894f1d2b4d3SLarry Finger (rtlpriv->btcoexist.bt_service == BT_BUSY))) 1895f1d2b4d3SLarry Finger ratr_value &= 0x0fffcfc0; 1896f1d2b4d3SLarry Finger else 1897f1d2b4d3SLarry Finger ratr_value &= 0x0FFFFFFF; 1898f1d2b4d3SLarry Finger 1899f1d2b4d3SLarry Finger if (b_nmode && 1900f1d2b4d3SLarry Finger ((curtxbw_40mhz && curshortgi_40mhz) || 1901f1d2b4d3SLarry Finger (!curtxbw_40mhz && curshortgi_20mhz))) { 1902f1d2b4d3SLarry Finger ratr_value |= 0x10000000; 1903f1d2b4d3SLarry Finger tmp_ratr_value = (ratr_value >> 12); 1904f1d2b4d3SLarry Finger 1905f1d2b4d3SLarry Finger for (shortgi_rate = 15; shortgi_rate > 0; shortgi_rate--) { 1906f1d2b4d3SLarry Finger if ((1 << shortgi_rate) & tmp_ratr_value) 1907f1d2b4d3SLarry Finger break; 1908f1d2b4d3SLarry Finger } 1909f1d2b4d3SLarry Finger 1910f1d2b4d3SLarry Finger shortgi_rate = (shortgi_rate << 12) | (shortgi_rate << 8) | 1911f1d2b4d3SLarry Finger (shortgi_rate << 4) | (shortgi_rate); 1912f1d2b4d3SLarry Finger } 1913f1d2b4d3SLarry Finger 1914f1d2b4d3SLarry Finger rtl_write_dword(rtlpriv, REG_ARFR0 + ratr_index * 4, ratr_value); 1915f1d2b4d3SLarry Finger 1916f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, 1917f1d2b4d3SLarry Finger "%x\n", rtl_read_dword(rtlpriv, REG_ARFR0)); 1918f1d2b4d3SLarry Finger } 1919f1d2b4d3SLarry Finger 1920f1d2b4d3SLarry Finger static void rtl8723e_update_hal_rate_mask(struct ieee80211_hw *hw, 1921f1d2b4d3SLarry Finger struct ieee80211_sta *sta, 19221d22b177SPing-Ke Shih u8 rssi_level, bool update_bw) 1923f1d2b4d3SLarry Finger { 1924f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 1925f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &(rtlpriv->phy); 1926f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 1927f1d2b4d3SLarry Finger struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 1928f1d2b4d3SLarry Finger struct rtl_sta_info *sta_entry = NULL; 1929f1d2b4d3SLarry Finger u32 ratr_bitmap; 1930f1d2b4d3SLarry Finger u8 ratr_index; 1931f1d2b4d3SLarry Finger u8 curtxbw_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) 1932f1d2b4d3SLarry Finger ? 1 : 0; 1933f1d2b4d3SLarry Finger u8 curshortgi_40mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_40) ? 1934f1d2b4d3SLarry Finger 1 : 0; 1935f1d2b4d3SLarry Finger u8 curshortgi_20mhz = (sta->ht_cap.cap & IEEE80211_HT_CAP_SGI_20) ? 1936f1d2b4d3SLarry Finger 1 : 0; 1937f1d2b4d3SLarry Finger enum wireless_mode wirelessmode = 0; 1938f1d2b4d3SLarry Finger bool shortgi = false; 1939f1d2b4d3SLarry Finger u8 rate_mask[5]; 1940f1d2b4d3SLarry Finger u8 macid = 0; 1941f1d2b4d3SLarry Finger /*u8 mimo_ps = IEEE80211_SMPS_OFF;*/ 1942f1d2b4d3SLarry Finger 1943f1d2b4d3SLarry Finger sta_entry = (struct rtl_sta_info *)sta->drv_priv; 1944f1d2b4d3SLarry Finger wirelessmode = sta_entry->wireless_mode; 1945f1d2b4d3SLarry Finger if (mac->opmode == NL80211_IFTYPE_STATION) 1946f1d2b4d3SLarry Finger curtxbw_40mhz = mac->bw_40; 1947f1d2b4d3SLarry Finger else if (mac->opmode == NL80211_IFTYPE_AP || 1948f1d2b4d3SLarry Finger mac->opmode == NL80211_IFTYPE_ADHOC) 1949f1d2b4d3SLarry Finger macid = sta->aid + 1; 1950f1d2b4d3SLarry Finger 1951f1d2b4d3SLarry Finger if (rtlhal->current_bandtype == BAND_ON_5G) 1952f1d2b4d3SLarry Finger ratr_bitmap = sta->supp_rates[1] << 4; 1953f1d2b4d3SLarry Finger else 1954f1d2b4d3SLarry Finger ratr_bitmap = sta->supp_rates[0]; 1955f1d2b4d3SLarry Finger if (mac->opmode == NL80211_IFTYPE_ADHOC) 1956f1d2b4d3SLarry Finger ratr_bitmap = 0xfff; 1957f1d2b4d3SLarry Finger ratr_bitmap |= (sta->ht_cap.mcs.rx_mask[1] << 20 | 1958f1d2b4d3SLarry Finger sta->ht_cap.mcs.rx_mask[0] << 12); 1959f1d2b4d3SLarry Finger switch (wirelessmode) { 1960f1d2b4d3SLarry Finger case WIRELESS_MODE_B: 1961f1d2b4d3SLarry Finger ratr_index = RATR_INX_WIRELESS_B; 1962f1d2b4d3SLarry Finger if (ratr_bitmap & 0x0000000c) 1963f1d2b4d3SLarry Finger ratr_bitmap &= 0x0000000d; 1964f1d2b4d3SLarry Finger else 1965f1d2b4d3SLarry Finger ratr_bitmap &= 0x0000000f; 1966f1d2b4d3SLarry Finger break; 1967f1d2b4d3SLarry Finger case WIRELESS_MODE_G: 1968f1d2b4d3SLarry Finger ratr_index = RATR_INX_WIRELESS_GB; 1969f1d2b4d3SLarry Finger 1970f1d2b4d3SLarry Finger if (rssi_level == 1) 1971f1d2b4d3SLarry Finger ratr_bitmap &= 0x00000f00; 1972f1d2b4d3SLarry Finger else if (rssi_level == 2) 1973f1d2b4d3SLarry Finger ratr_bitmap &= 0x00000ff0; 1974f1d2b4d3SLarry Finger else 1975f1d2b4d3SLarry Finger ratr_bitmap &= 0x00000ff5; 1976f1d2b4d3SLarry Finger break; 1977f1d2b4d3SLarry Finger case WIRELESS_MODE_A: 1978f1d2b4d3SLarry Finger ratr_index = RATR_INX_WIRELESS_G; 1979f1d2b4d3SLarry Finger ratr_bitmap &= 0x00000ff0; 1980f1d2b4d3SLarry Finger break; 1981f1d2b4d3SLarry Finger case WIRELESS_MODE_N_24G: 1982f1d2b4d3SLarry Finger case WIRELESS_MODE_N_5G: 1983f1d2b4d3SLarry Finger ratr_index = RATR_INX_WIRELESS_NGB; 1984f1d2b4d3SLarry Finger if (rtlphy->rf_type == RF_1T2R || 1985f1d2b4d3SLarry Finger rtlphy->rf_type == RF_1T1R) { 1986f1d2b4d3SLarry Finger if (curtxbw_40mhz) { 1987f1d2b4d3SLarry Finger if (rssi_level == 1) 1988f1d2b4d3SLarry Finger ratr_bitmap &= 0x000f0000; 1989f1d2b4d3SLarry Finger else if (rssi_level == 2) 1990f1d2b4d3SLarry Finger ratr_bitmap &= 0x000ff000; 1991f1d2b4d3SLarry Finger else 1992f1d2b4d3SLarry Finger ratr_bitmap &= 0x000ff015; 1993f1d2b4d3SLarry Finger } else { 1994f1d2b4d3SLarry Finger if (rssi_level == 1) 1995f1d2b4d3SLarry Finger ratr_bitmap &= 0x000f0000; 1996f1d2b4d3SLarry Finger else if (rssi_level == 2) 1997f1d2b4d3SLarry Finger ratr_bitmap &= 0x000ff000; 1998f1d2b4d3SLarry Finger else 1999f1d2b4d3SLarry Finger ratr_bitmap &= 0x000ff005; 2000f1d2b4d3SLarry Finger } 2001f1d2b4d3SLarry Finger } else { 2002f1d2b4d3SLarry Finger if (curtxbw_40mhz) { 2003f1d2b4d3SLarry Finger if (rssi_level == 1) 2004f1d2b4d3SLarry Finger ratr_bitmap &= 0x0f0f0000; 2005f1d2b4d3SLarry Finger else if (rssi_level == 2) 2006f1d2b4d3SLarry Finger ratr_bitmap &= 0x0f0ff000; 2007f1d2b4d3SLarry Finger else 2008f1d2b4d3SLarry Finger ratr_bitmap &= 0x0f0ff015; 2009f1d2b4d3SLarry Finger } else { 2010f1d2b4d3SLarry Finger if (rssi_level == 1) 2011f1d2b4d3SLarry Finger ratr_bitmap &= 0x0f0f0000; 2012f1d2b4d3SLarry Finger else if (rssi_level == 2) 2013f1d2b4d3SLarry Finger ratr_bitmap &= 0x0f0ff000; 2014f1d2b4d3SLarry Finger else 2015f1d2b4d3SLarry Finger ratr_bitmap &= 0x0f0ff005; 2016f1d2b4d3SLarry Finger } 2017f1d2b4d3SLarry Finger } 2018f1d2b4d3SLarry Finger 2019f1d2b4d3SLarry Finger if ((curtxbw_40mhz && curshortgi_40mhz) || 2020f1d2b4d3SLarry Finger (!curtxbw_40mhz && curshortgi_20mhz)) { 2021f1d2b4d3SLarry Finger if (macid == 0) 2022f1d2b4d3SLarry Finger shortgi = true; 2023f1d2b4d3SLarry Finger else if (macid == 1) 2024f1d2b4d3SLarry Finger shortgi = false; 2025f1d2b4d3SLarry Finger } 2026f1d2b4d3SLarry Finger break; 2027f1d2b4d3SLarry Finger default: 2028f1d2b4d3SLarry Finger ratr_index = RATR_INX_WIRELESS_NGB; 2029f1d2b4d3SLarry Finger 2030f1d2b4d3SLarry Finger if (rtlphy->rf_type == RF_1T2R) 2031f1d2b4d3SLarry Finger ratr_bitmap &= 0x000ff0ff; 2032f1d2b4d3SLarry Finger else 2033f1d2b4d3SLarry Finger ratr_bitmap &= 0x0f0ff0ff; 2034f1d2b4d3SLarry Finger break; 2035f1d2b4d3SLarry Finger } 2036f1d2b4d3SLarry Finger sta_entry->ratr_index = ratr_index; 2037f1d2b4d3SLarry Finger 2038f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, 2039f1d2b4d3SLarry Finger "ratr_bitmap :%x\n", ratr_bitmap); 2040f1d2b4d3SLarry Finger *(u32 *)&rate_mask = (ratr_bitmap & 0x0fffffff) | 2041f1d2b4d3SLarry Finger (ratr_index << 28); 2042f1d2b4d3SLarry Finger rate_mask[4] = macid | (shortgi ? 0x20 : 0x00) | 0x80; 2043f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_RATR, DBG_DMESG, 2044f1d2b4d3SLarry Finger "Rate_index:%x, ratr_val:%x, %x:%x:%x:%x:%x\n", 2045f1d2b4d3SLarry Finger ratr_index, ratr_bitmap, 2046f1d2b4d3SLarry Finger rate_mask[0], rate_mask[1], 2047f1d2b4d3SLarry Finger rate_mask[2], rate_mask[3], 2048f1d2b4d3SLarry Finger rate_mask[4]); 2049f1d2b4d3SLarry Finger rtl8723e_fill_h2c_cmd(hw, H2C_RA_MASK, 5, rate_mask); 2050f1d2b4d3SLarry Finger } 2051f1d2b4d3SLarry Finger 2052f1d2b4d3SLarry Finger void rtl8723e_update_hal_rate_tbl(struct ieee80211_hw *hw, 20531d22b177SPing-Ke Shih struct ieee80211_sta *sta, u8 rssi_level, 20541d22b177SPing-Ke Shih bool update_bw) 2055f1d2b4d3SLarry Finger { 2056f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 2057f1d2b4d3SLarry Finger 2058f1d2b4d3SLarry Finger if (rtlpriv->dm.useramask) 20591d22b177SPing-Ke Shih rtl8723e_update_hal_rate_mask(hw, sta, rssi_level, update_bw); 2060f1d2b4d3SLarry Finger else 2061f1d2b4d3SLarry Finger rtl8723e_update_hal_rate_table(hw, sta); 2062f1d2b4d3SLarry Finger } 2063f1d2b4d3SLarry Finger 2064f1d2b4d3SLarry Finger void rtl8723e_update_channel_access_setting(struct ieee80211_hw *hw) 2065f1d2b4d3SLarry Finger { 2066f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 2067f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 2068f1d2b4d3SLarry Finger u16 sifs_timer; 2069f1d2b4d3SLarry Finger 2070f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SLOT_TIME, &mac->slot_time); 2071f1d2b4d3SLarry Finger if (!mac->ht_enable) 2072f1d2b4d3SLarry Finger sifs_timer = 0x0a0a; 2073f1d2b4d3SLarry Finger else 2074f1d2b4d3SLarry Finger sifs_timer = 0x1010; 2075f1d2b4d3SLarry Finger rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SIFS, (u8 *)&sifs_timer); 2076f1d2b4d3SLarry Finger } 2077f1d2b4d3SLarry Finger 2078f1d2b4d3SLarry Finger bool rtl8723e_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid) 2079f1d2b4d3SLarry Finger { 2080f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 2081f1d2b4d3SLarry Finger struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); 2082f1d2b4d3SLarry Finger struct rtl_phy *rtlphy = &(rtlpriv->phy); 208376d7b12cSChristos Gkekas enum rf_pwrstate e_rfpowerstate_toset; 2084f1d2b4d3SLarry Finger u8 u1tmp; 2085f1d2b4d3SLarry Finger bool b_actuallyset = false; 2086f1d2b4d3SLarry Finger 2087f1d2b4d3SLarry Finger if (rtlpriv->rtlhal.being_init_adapter) 2088f1d2b4d3SLarry Finger return false; 2089f1d2b4d3SLarry Finger 2090f1d2b4d3SLarry Finger if (ppsc->swrf_processing) 2091f1d2b4d3SLarry Finger return false; 2092f1d2b4d3SLarry Finger 2093f1d2b4d3SLarry Finger spin_lock(&rtlpriv->locks.rf_ps_lock); 2094f1d2b4d3SLarry Finger if (ppsc->rfchange_inprogress) { 2095f1d2b4d3SLarry Finger spin_unlock(&rtlpriv->locks.rf_ps_lock); 2096f1d2b4d3SLarry Finger return false; 2097f1d2b4d3SLarry Finger } else { 2098f1d2b4d3SLarry Finger ppsc->rfchange_inprogress = true; 2099f1d2b4d3SLarry Finger spin_unlock(&rtlpriv->locks.rf_ps_lock); 2100f1d2b4d3SLarry Finger } 2101f1d2b4d3SLarry Finger 2102f1d2b4d3SLarry Finger rtl_write_byte(rtlpriv, REG_GPIO_IO_SEL_2, 2103f1d2b4d3SLarry Finger rtl_read_byte(rtlpriv, REG_GPIO_IO_SEL_2)&~(BIT(1))); 2104f1d2b4d3SLarry Finger 2105f1d2b4d3SLarry Finger u1tmp = rtl_read_byte(rtlpriv, REG_GPIO_PIN_CTRL_2); 2106f1d2b4d3SLarry Finger 2107f1d2b4d3SLarry Finger if (rtlphy->polarity_ctl) 2108f1d2b4d3SLarry Finger e_rfpowerstate_toset = (u1tmp & BIT(1)) ? ERFOFF : ERFON; 2109f1d2b4d3SLarry Finger else 2110f1d2b4d3SLarry Finger e_rfpowerstate_toset = (u1tmp & BIT(1)) ? ERFON : ERFOFF; 2111f1d2b4d3SLarry Finger 2112f1d2b4d3SLarry Finger if (ppsc->hwradiooff && (e_rfpowerstate_toset == ERFON)) { 2113f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, 2114f1d2b4d3SLarry Finger "GPIOChangeRF - HW Radio ON, RF ON\n"); 2115f1d2b4d3SLarry Finger 2116f1d2b4d3SLarry Finger e_rfpowerstate_toset = ERFON; 2117f1d2b4d3SLarry Finger ppsc->hwradiooff = false; 2118f1d2b4d3SLarry Finger b_actuallyset = true; 2119f1d2b4d3SLarry Finger } else if (!ppsc->hwradiooff && (e_rfpowerstate_toset == ERFOFF)) { 2120f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, 2121f1d2b4d3SLarry Finger "GPIOChangeRF - HW Radio OFF, RF OFF\n"); 2122f1d2b4d3SLarry Finger 2123f1d2b4d3SLarry Finger e_rfpowerstate_toset = ERFOFF; 2124f1d2b4d3SLarry Finger ppsc->hwradiooff = true; 2125f1d2b4d3SLarry Finger b_actuallyset = true; 2126f1d2b4d3SLarry Finger } 2127f1d2b4d3SLarry Finger 2128f1d2b4d3SLarry Finger if (b_actuallyset) { 2129f1d2b4d3SLarry Finger spin_lock(&rtlpriv->locks.rf_ps_lock); 2130f1d2b4d3SLarry Finger ppsc->rfchange_inprogress = false; 2131f1d2b4d3SLarry Finger spin_unlock(&rtlpriv->locks.rf_ps_lock); 2132f1d2b4d3SLarry Finger } else { 2133f1d2b4d3SLarry Finger if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_HALT_NIC) 2134f1d2b4d3SLarry Finger RT_SET_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); 2135f1d2b4d3SLarry Finger 2136f1d2b4d3SLarry Finger spin_lock(&rtlpriv->locks.rf_ps_lock); 2137f1d2b4d3SLarry Finger ppsc->rfchange_inprogress = false; 2138f1d2b4d3SLarry Finger spin_unlock(&rtlpriv->locks.rf_ps_lock); 2139f1d2b4d3SLarry Finger } 2140f1d2b4d3SLarry Finger 2141f1d2b4d3SLarry Finger *valid = 1; 2142f1d2b4d3SLarry Finger return !ppsc->hwradiooff; 2143f1d2b4d3SLarry Finger 2144f1d2b4d3SLarry Finger } 2145f1d2b4d3SLarry Finger 2146f1d2b4d3SLarry Finger void rtl8723e_set_key(struct ieee80211_hw *hw, u32 key_index, 2147f1d2b4d3SLarry Finger u8 *p_macaddr, bool is_group, u8 enc_algo, 2148f1d2b4d3SLarry Finger bool is_wepkey, bool clear_all) 2149f1d2b4d3SLarry Finger { 2150f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 2151f1d2b4d3SLarry Finger struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 2152f1d2b4d3SLarry Finger struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 2153f1d2b4d3SLarry Finger u8 *macaddr = p_macaddr; 2154f1d2b4d3SLarry Finger u32 entry_id = 0; 2155f1d2b4d3SLarry Finger bool is_pairwise = false; 2156f1d2b4d3SLarry Finger 2157f1d2b4d3SLarry Finger static u8 cam_const_addr[4][6] = { 2158f1d2b4d3SLarry Finger {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, 2159f1d2b4d3SLarry Finger {0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, 2160f1d2b4d3SLarry Finger {0x00, 0x00, 0x00, 0x00, 0x00, 0x02}, 2161f1d2b4d3SLarry Finger {0x00, 0x00, 0x00, 0x00, 0x00, 0x03} 2162f1d2b4d3SLarry Finger }; 2163f1d2b4d3SLarry Finger static u8 cam_const_broad[] = { 2164f1d2b4d3SLarry Finger 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 2165f1d2b4d3SLarry Finger }; 2166f1d2b4d3SLarry Finger 2167f1d2b4d3SLarry Finger if (clear_all) { 2168f1d2b4d3SLarry Finger u8 idx = 0; 2169f1d2b4d3SLarry Finger u8 cam_offset = 0; 2170f1d2b4d3SLarry Finger u8 clear_number = 5; 2171f1d2b4d3SLarry Finger 2172f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, "clear_all\n"); 2173f1d2b4d3SLarry Finger 2174f1d2b4d3SLarry Finger for (idx = 0; idx < clear_number; idx++) { 2175f1d2b4d3SLarry Finger rtl_cam_mark_invalid(hw, cam_offset + idx); 2176f1d2b4d3SLarry Finger rtl_cam_empty_entry(hw, cam_offset + idx); 2177f1d2b4d3SLarry Finger 2178f1d2b4d3SLarry Finger if (idx < 5) { 2179f1d2b4d3SLarry Finger memset(rtlpriv->sec.key_buf[idx], 0, 2180f1d2b4d3SLarry Finger MAX_KEY_LEN); 2181f1d2b4d3SLarry Finger rtlpriv->sec.key_len[idx] = 0; 2182f1d2b4d3SLarry Finger } 2183f1d2b4d3SLarry Finger } 2184f1d2b4d3SLarry Finger 2185f1d2b4d3SLarry Finger } else { 2186f1d2b4d3SLarry Finger switch (enc_algo) { 2187f1d2b4d3SLarry Finger case WEP40_ENCRYPTION: 2188f1d2b4d3SLarry Finger enc_algo = CAM_WEP40; 2189f1d2b4d3SLarry Finger break; 2190f1d2b4d3SLarry Finger case WEP104_ENCRYPTION: 2191f1d2b4d3SLarry Finger enc_algo = CAM_WEP104; 2192f1d2b4d3SLarry Finger break; 2193f1d2b4d3SLarry Finger case TKIP_ENCRYPTION: 2194f1d2b4d3SLarry Finger enc_algo = CAM_TKIP; 2195f1d2b4d3SLarry Finger break; 2196f1d2b4d3SLarry Finger case AESCCMP_ENCRYPTION: 2197f1d2b4d3SLarry Finger enc_algo = CAM_AES; 2198f1d2b4d3SLarry Finger break; 2199f1d2b4d3SLarry Finger default: 2200f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_ERR, DBG_LOUD, 2201ad574889SJoe Perches "switch case %#x not processed\n", enc_algo); 2202f1d2b4d3SLarry Finger enc_algo = CAM_TKIP; 2203f1d2b4d3SLarry Finger break; 2204f1d2b4d3SLarry Finger } 2205f1d2b4d3SLarry Finger 2206f1d2b4d3SLarry Finger if (is_wepkey || rtlpriv->sec.use_defaultkey) { 2207f1d2b4d3SLarry Finger macaddr = cam_const_addr[key_index]; 2208f1d2b4d3SLarry Finger entry_id = key_index; 2209f1d2b4d3SLarry Finger } else { 2210f1d2b4d3SLarry Finger if (is_group) { 2211f1d2b4d3SLarry Finger macaddr = cam_const_broad; 2212f1d2b4d3SLarry Finger entry_id = key_index; 2213f1d2b4d3SLarry Finger } else { 2214f1d2b4d3SLarry Finger if (mac->opmode == NL80211_IFTYPE_AP) { 2215f1d2b4d3SLarry Finger entry_id = 2216f1d2b4d3SLarry Finger rtl_cam_get_free_entry(hw, p_macaddr); 2217f1d2b4d3SLarry Finger if (entry_id >= TOTAL_CAM_ENTRY) { 2218a67005bcSLarry Finger pr_err("Can not find free hw security cam entry\n"); 2219f1d2b4d3SLarry Finger return; 2220f1d2b4d3SLarry Finger } 2221f1d2b4d3SLarry Finger } else { 2222f1d2b4d3SLarry Finger entry_id = CAM_PAIRWISE_KEY_POSITION; 2223f1d2b4d3SLarry Finger } 2224f1d2b4d3SLarry Finger 2225f1d2b4d3SLarry Finger key_index = PAIRWISE_KEYIDX; 2226f1d2b4d3SLarry Finger is_pairwise = true; 2227f1d2b4d3SLarry Finger } 2228f1d2b4d3SLarry Finger } 2229f1d2b4d3SLarry Finger 2230f1d2b4d3SLarry Finger if (rtlpriv->sec.key_len[key_index] == 0) { 2231f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 2232f1d2b4d3SLarry Finger "delete one entry, entry_id is %d\n", 2233f1d2b4d3SLarry Finger entry_id); 2234f1d2b4d3SLarry Finger if (mac->opmode == NL80211_IFTYPE_AP) 2235f1d2b4d3SLarry Finger rtl_cam_del_entry(hw, p_macaddr); 2236f1d2b4d3SLarry Finger rtl_cam_delete_one_entry(hw, p_macaddr, entry_id); 2237f1d2b4d3SLarry Finger } else { 2238f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 2239f1d2b4d3SLarry Finger "add one entry\n"); 2240f1d2b4d3SLarry Finger if (is_pairwise) { 2241f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 22426b9e6f62SColin Ian King "set Pairwise key\n"); 2243f1d2b4d3SLarry Finger 2244f1d2b4d3SLarry Finger rtl_cam_add_one_entry(hw, macaddr, key_index, 2245f1d2b4d3SLarry Finger entry_id, enc_algo, 2246f1d2b4d3SLarry Finger CAM_CONFIG_NO_USEDK, 2247f1d2b4d3SLarry Finger rtlpriv->sec.key_buf[key_index]); 2248f1d2b4d3SLarry Finger } else { 2249f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_SEC, DBG_DMESG, 2250f1d2b4d3SLarry Finger "set group key\n"); 2251f1d2b4d3SLarry Finger 2252f1d2b4d3SLarry Finger if (mac->opmode == NL80211_IFTYPE_ADHOC) { 2253f1d2b4d3SLarry Finger rtl_cam_add_one_entry(hw, 2254f1d2b4d3SLarry Finger rtlefuse->dev_addr, 2255f1d2b4d3SLarry Finger PAIRWISE_KEYIDX, 2256f1d2b4d3SLarry Finger CAM_PAIRWISE_KEY_POSITION, 2257f1d2b4d3SLarry Finger enc_algo, 2258f1d2b4d3SLarry Finger CAM_CONFIG_NO_USEDK, 2259f1d2b4d3SLarry Finger rtlpriv->sec.key_buf 2260f1d2b4d3SLarry Finger [entry_id]); 2261f1d2b4d3SLarry Finger } 2262f1d2b4d3SLarry Finger 2263f1d2b4d3SLarry Finger rtl_cam_add_one_entry(hw, macaddr, key_index, 2264f1d2b4d3SLarry Finger entry_id, enc_algo, 2265f1d2b4d3SLarry Finger CAM_CONFIG_NO_USEDK, 2266f1d2b4d3SLarry Finger rtlpriv->sec.key_buf[entry_id]); 2267f1d2b4d3SLarry Finger } 2268f1d2b4d3SLarry Finger 2269f1d2b4d3SLarry Finger } 2270f1d2b4d3SLarry Finger } 2271f1d2b4d3SLarry Finger } 2272f1d2b4d3SLarry Finger 2273f1d2b4d3SLarry Finger static void rtl8723e_bt_var_init(struct ieee80211_hw *hw) 2274f1d2b4d3SLarry Finger { 2275f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 2276f1d2b4d3SLarry Finger 2277f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_coexistence = 2278f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_coexist; 2279f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_ant_num = 2280f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_ant_num; 2281f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_coexist_type = 2282f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_type; 2283f1d2b4d3SLarry Finger 2284f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_ant_isolation = 2285f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_ant_isol; 2286f1d2b4d3SLarry Finger 2287f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_radio_shared_type = 2288f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_radio_shared; 2289f1d2b4d3SLarry Finger 2290f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2291e8dc072dSColin Ian King "BT Coexistence = 0x%x\n", 2292f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_coexistence); 2293f1d2b4d3SLarry Finger 2294f1d2b4d3SLarry Finger if (rtlpriv->btcoexist.bt_coexistence) { 2295f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_busy_traffic = false; 2296f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_traffic_mode_set = false; 2297f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_non_traffic_mode_set = false; 2298f1d2b4d3SLarry Finger 2299f1d2b4d3SLarry Finger rtlpriv->btcoexist.cstate = 0; 2300f1d2b4d3SLarry Finger rtlpriv->btcoexist.previous_state = 0; 2301f1d2b4d3SLarry Finger 2302f1d2b4d3SLarry Finger if (rtlpriv->btcoexist.bt_ant_num == ANT_X2) { 2303f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2304f1d2b4d3SLarry Finger "BlueTooth BT_Ant_Num = Antx2\n"); 2305f1d2b4d3SLarry Finger } else if (rtlpriv->btcoexist.bt_ant_num == ANT_X1) { 2306f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2307f1d2b4d3SLarry Finger "BlueTooth BT_Ant_Num = Antx1\n"); 2308f1d2b4d3SLarry Finger } 2309f1d2b4d3SLarry Finger switch (rtlpriv->btcoexist.bt_coexist_type) { 2310f1d2b4d3SLarry Finger case BT_2WIRE: 2311f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2312f1d2b4d3SLarry Finger "BlueTooth BT_CoexistType = BT_2Wire\n"); 2313f1d2b4d3SLarry Finger break; 2314f1d2b4d3SLarry Finger case BT_ISSC_3WIRE: 2315f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2316f1d2b4d3SLarry Finger "BlueTooth BT_CoexistType = BT_ISSC_3Wire\n"); 2317f1d2b4d3SLarry Finger break; 2318f1d2b4d3SLarry Finger case BT_ACCEL: 2319f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2320f1d2b4d3SLarry Finger "BlueTooth BT_CoexistType = BT_ACCEL\n"); 2321f1d2b4d3SLarry Finger break; 2322f1d2b4d3SLarry Finger case BT_CSR_BC4: 2323f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2324f1d2b4d3SLarry Finger "BlueTooth BT_CoexistType = BT_CSR_BC4\n"); 2325f1d2b4d3SLarry Finger break; 2326f1d2b4d3SLarry Finger case BT_CSR_BC8: 2327f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2328f1d2b4d3SLarry Finger "BlueTooth BT_CoexistType = BT_CSR_BC8\n"); 2329f1d2b4d3SLarry Finger break; 2330f1d2b4d3SLarry Finger case BT_RTL8756: 2331f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2332f1d2b4d3SLarry Finger "BlueTooth BT_CoexistType = BT_RTL8756\n"); 2333f1d2b4d3SLarry Finger break; 2334f1d2b4d3SLarry Finger default: 2335f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2336f1d2b4d3SLarry Finger "BlueTooth BT_CoexistType = Unknown\n"); 2337f1d2b4d3SLarry Finger break; 2338f1d2b4d3SLarry Finger } 2339f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2340f1d2b4d3SLarry Finger "BlueTooth BT_Ant_isolation = %d\n", 2341f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_ant_isolation); 2342f1d2b4d3SLarry Finger RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_TRACE, 2343f1d2b4d3SLarry Finger "BT_RadioSharedType = 0x%x\n", 2344f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_radio_shared_type); 2345f1d2b4d3SLarry Finger rtlpriv->btcoexist.bt_active_zero_cnt = 0; 2346f1d2b4d3SLarry Finger rtlpriv->btcoexist.cur_bt_disabled = false; 2347f1d2b4d3SLarry Finger rtlpriv->btcoexist.pre_bt_disabled = false; 2348f1d2b4d3SLarry Finger } 2349f1d2b4d3SLarry Finger } 2350f1d2b4d3SLarry Finger 2351f1d2b4d3SLarry Finger void rtl8723e_read_bt_coexist_info_from_hwpg(struct ieee80211_hw *hw, 2352f1d2b4d3SLarry Finger bool auto_load_fail, u8 *hwinfo) 2353f1d2b4d3SLarry Finger { 2354f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 2355f1d2b4d3SLarry Finger u8 value; 2356f1d2b4d3SLarry Finger u32 tmpu_32; 2357f1d2b4d3SLarry Finger 2358f1d2b4d3SLarry Finger if (!auto_load_fail) { 2359f1d2b4d3SLarry Finger tmpu_32 = rtl_read_dword(rtlpriv, REG_MULTI_FUNC_CTRL); 2360f1d2b4d3SLarry Finger if (tmpu_32 & BIT(18)) 2361f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_coexist = 1; 2362f1d2b4d3SLarry Finger else 2363f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_coexist = 0; 2364f1d2b4d3SLarry Finger value = hwinfo[RF_OPTION4]; 2365f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_type = BT_RTL8723A; 2366f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_ant_num = (value & 0x1); 2367f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_ant_isol = ((value & 0x10) >> 4); 2368f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_radio_shared = 2369f1d2b4d3SLarry Finger ((value & 0x20) >> 5); 2370f1d2b4d3SLarry Finger } else { 2371f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_coexist = 0; 2372f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_type = BT_RTL8723A; 2373f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_ant_num = ANT_X2; 2374f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_ant_isol = 0; 2375f1d2b4d3SLarry Finger rtlpriv->btcoexist.eeprom_bt_radio_shared = BT_RADIO_SHARED; 2376f1d2b4d3SLarry Finger } 2377f1d2b4d3SLarry Finger 2378f1d2b4d3SLarry Finger rtl8723e_bt_var_init(hw); 2379f1d2b4d3SLarry Finger } 2380f1d2b4d3SLarry Finger 2381f1d2b4d3SLarry Finger void rtl8723e_bt_reg_init(struct ieee80211_hw *hw) 2382f1d2b4d3SLarry Finger { 2383f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 2384f1d2b4d3SLarry Finger 2385f1d2b4d3SLarry Finger /* 0:Low, 1:High, 2:From Efuse. */ 2386f1d2b4d3SLarry Finger rtlpriv->btcoexist.reg_bt_iso = 2; 2387f1d2b4d3SLarry Finger /* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter. */ 2388f1d2b4d3SLarry Finger rtlpriv->btcoexist.reg_bt_sco = 3; 2389f1d2b4d3SLarry Finger /* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */ 2390f1d2b4d3SLarry Finger rtlpriv->btcoexist.reg_bt_sco = 0; 2391f1d2b4d3SLarry Finger } 2392f1d2b4d3SLarry Finger 2393f1d2b4d3SLarry Finger void rtl8723e_bt_hw_init(struct ieee80211_hw *hw) 2394f1d2b4d3SLarry Finger { 2395f1d2b4d3SLarry Finger struct rtl_priv *rtlpriv = rtl_priv(hw); 2396f1d2b4d3SLarry Finger 2397f1d2b4d3SLarry Finger if (rtlpriv->cfg->ops->get_btc_status()) 2398f1d2b4d3SLarry Finger rtlpriv->btcoexist.btc_ops->btc_init_hw_config(rtlpriv); 2399f1d2b4d3SLarry Finger } 2400f1d2b4d3SLarry Finger 2401f1d2b4d3SLarry Finger void rtl8723e_suspend(struct ieee80211_hw *hw) 2402f1d2b4d3SLarry Finger { 2403f1d2b4d3SLarry Finger } 2404f1d2b4d3SLarry Finger 2405f1d2b4d3SLarry Finger void rtl8723e_resume(struct ieee80211_hw *hw) 2406f1d2b4d3SLarry Finger { 2407f1d2b4d3SLarry Finger } 2408