18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci/* Copyright(c) 2009-2012 Realtek Corporation.*/ 38c2ecf20Sopenharmony_ci 48c2ecf20Sopenharmony_ci#include "../wifi.h" 58c2ecf20Sopenharmony_ci#include "../base.h" 68c2ecf20Sopenharmony_ci#include "../core.h" 78c2ecf20Sopenharmony_ci#include "reg.h" 88c2ecf20Sopenharmony_ci#include "def.h" 98c2ecf20Sopenharmony_ci#include "phy.h" 108c2ecf20Sopenharmony_ci#include "dm.h" 118c2ecf20Sopenharmony_ci#include "fw.h" 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_cistatic const u32 edca_setting_dl[PEER_MAX] = { 148c2ecf20Sopenharmony_ci 0xa44f, /* 0 UNKNOWN */ 158c2ecf20Sopenharmony_ci 0x5ea44f, /* 1 REALTEK_90 */ 168c2ecf20Sopenharmony_ci 0x5ea44f, /* 2 REALTEK_92SE */ 178c2ecf20Sopenharmony_ci 0xa630, /* 3 BROAD */ 188c2ecf20Sopenharmony_ci 0xa44f, /* 4 RAL */ 198c2ecf20Sopenharmony_ci 0xa630, /* 5 ATH */ 208c2ecf20Sopenharmony_ci 0xa630, /* 6 CISCO */ 218c2ecf20Sopenharmony_ci 0xa42b, /* 7 MARV */ 228c2ecf20Sopenharmony_ci}; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_cistatic const u32 edca_setting_dl_gmode[PEER_MAX] = { 258c2ecf20Sopenharmony_ci 0x4322, /* 0 UNKNOWN */ 268c2ecf20Sopenharmony_ci 0xa44f, /* 1 REALTEK_90 */ 278c2ecf20Sopenharmony_ci 0x5ea44f, /* 2 REALTEK_92SE */ 288c2ecf20Sopenharmony_ci 0xa42b, /* 3 BROAD */ 298c2ecf20Sopenharmony_ci 0x5e4322, /* 4 RAL */ 308c2ecf20Sopenharmony_ci 0x4322, /* 5 ATH */ 318c2ecf20Sopenharmony_ci 0xa430, /* 6 CISCO */ 328c2ecf20Sopenharmony_ci 0x5ea44f, /* 7 MARV */ 338c2ecf20Sopenharmony_ci}; 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_cistatic const u32 edca_setting_ul[PEER_MAX] = { 368c2ecf20Sopenharmony_ci 0x5e4322, /* 0 UNKNOWN */ 378c2ecf20Sopenharmony_ci 0xa44f, /* 1 REALTEK_90 */ 388c2ecf20Sopenharmony_ci 0x5ea44f, /* 2 REALTEK_92SE */ 398c2ecf20Sopenharmony_ci 0x5ea322, /* 3 BROAD */ 408c2ecf20Sopenharmony_ci 0x5ea422, /* 4 RAL */ 418c2ecf20Sopenharmony_ci 0x5ea322, /* 5 ATH */ 428c2ecf20Sopenharmony_ci 0x3ea44f, /* 6 CISCO */ 438c2ecf20Sopenharmony_ci 0x5ea44f, /* 7 MARV */ 448c2ecf20Sopenharmony_ci}; 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic void _rtl92s_dm_check_edca_turbo(struct ieee80211_hw *hw) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 498c2ecf20Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci static u64 last_txok_cnt; 528c2ecf20Sopenharmony_ci static u64 last_rxok_cnt; 538c2ecf20Sopenharmony_ci u64 cur_txok_cnt = 0; 548c2ecf20Sopenharmony_ci u64 cur_rxok_cnt = 0; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci u32 edca_be_ul = edca_setting_ul[mac->vendor]; 578c2ecf20Sopenharmony_ci u32 edca_be_dl = edca_setting_dl[mac->vendor]; 588c2ecf20Sopenharmony_ci u32 edca_gmode = edca_setting_dl_gmode[mac->vendor]; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci if (mac->link_state != MAC80211_LINKED) { 618c2ecf20Sopenharmony_ci rtlpriv->dm.current_turbo_edca = false; 628c2ecf20Sopenharmony_ci goto dm_checkedcaturbo_exit; 638c2ecf20Sopenharmony_ci } 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci if ((!rtlpriv->dm.is_any_nonbepkts) && 668c2ecf20Sopenharmony_ci (!rtlpriv->dm.disable_framebursting)) { 678c2ecf20Sopenharmony_ci cur_txok_cnt = rtlpriv->stats.txbytesunicast - last_txok_cnt; 688c2ecf20Sopenharmony_ci cur_rxok_cnt = rtlpriv->stats.rxbytesunicast - last_rxok_cnt; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci if (rtlpriv->phy.rf_type == RF_1T2R) { 718c2ecf20Sopenharmony_ci if (cur_txok_cnt > 4 * cur_rxok_cnt) { 728c2ecf20Sopenharmony_ci /* Uplink TP is present. */ 738c2ecf20Sopenharmony_ci if (rtlpriv->dm.is_cur_rdlstate || 748c2ecf20Sopenharmony_ci !rtlpriv->dm.current_turbo_edca) { 758c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, EDCAPARA_BE, 768c2ecf20Sopenharmony_ci edca_be_ul); 778c2ecf20Sopenharmony_ci rtlpriv->dm.is_cur_rdlstate = false; 788c2ecf20Sopenharmony_ci } 798c2ecf20Sopenharmony_ci } else {/* Balance TP is present. */ 808c2ecf20Sopenharmony_ci if (!rtlpriv->dm.is_cur_rdlstate || 818c2ecf20Sopenharmony_ci !rtlpriv->dm.current_turbo_edca) { 828c2ecf20Sopenharmony_ci if (mac->mode == WIRELESS_MODE_G || 838c2ecf20Sopenharmony_ci mac->mode == WIRELESS_MODE_B) 848c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, 858c2ecf20Sopenharmony_ci EDCAPARA_BE, 868c2ecf20Sopenharmony_ci edca_gmode); 878c2ecf20Sopenharmony_ci else 888c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, 898c2ecf20Sopenharmony_ci EDCAPARA_BE, 908c2ecf20Sopenharmony_ci edca_be_dl); 918c2ecf20Sopenharmony_ci rtlpriv->dm.is_cur_rdlstate = true; 928c2ecf20Sopenharmony_ci } 938c2ecf20Sopenharmony_ci } 948c2ecf20Sopenharmony_ci rtlpriv->dm.current_turbo_edca = true; 958c2ecf20Sopenharmony_ci } else { 968c2ecf20Sopenharmony_ci if (cur_rxok_cnt > 4 * cur_txok_cnt) { 978c2ecf20Sopenharmony_ci if (!rtlpriv->dm.is_cur_rdlstate || 988c2ecf20Sopenharmony_ci !rtlpriv->dm.current_turbo_edca) { 998c2ecf20Sopenharmony_ci if (mac->mode == WIRELESS_MODE_G || 1008c2ecf20Sopenharmony_ci mac->mode == WIRELESS_MODE_B) 1018c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, 1028c2ecf20Sopenharmony_ci EDCAPARA_BE, 1038c2ecf20Sopenharmony_ci edca_gmode); 1048c2ecf20Sopenharmony_ci else 1058c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, 1068c2ecf20Sopenharmony_ci EDCAPARA_BE, 1078c2ecf20Sopenharmony_ci edca_be_dl); 1088c2ecf20Sopenharmony_ci rtlpriv->dm.is_cur_rdlstate = true; 1098c2ecf20Sopenharmony_ci } 1108c2ecf20Sopenharmony_ci } else { 1118c2ecf20Sopenharmony_ci if (rtlpriv->dm.is_cur_rdlstate || 1128c2ecf20Sopenharmony_ci !rtlpriv->dm.current_turbo_edca) { 1138c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, EDCAPARA_BE, 1148c2ecf20Sopenharmony_ci edca_be_ul); 1158c2ecf20Sopenharmony_ci rtlpriv->dm.is_cur_rdlstate = false; 1168c2ecf20Sopenharmony_ci } 1178c2ecf20Sopenharmony_ci } 1188c2ecf20Sopenharmony_ci rtlpriv->dm.current_turbo_edca = true; 1198c2ecf20Sopenharmony_ci } 1208c2ecf20Sopenharmony_ci } else { 1218c2ecf20Sopenharmony_ci if (rtlpriv->dm.current_turbo_edca) { 1228c2ecf20Sopenharmony_ci u8 tmp = AC0_BE; 1238c2ecf20Sopenharmony_ci rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM, 1248c2ecf20Sopenharmony_ci &tmp); 1258c2ecf20Sopenharmony_ci rtlpriv->dm.current_turbo_edca = false; 1268c2ecf20Sopenharmony_ci } 1278c2ecf20Sopenharmony_ci } 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_cidm_checkedcaturbo_exit: 1308c2ecf20Sopenharmony_ci rtlpriv->dm.is_any_nonbepkts = false; 1318c2ecf20Sopenharmony_ci last_txok_cnt = rtlpriv->stats.txbytesunicast; 1328c2ecf20Sopenharmony_ci last_rxok_cnt = rtlpriv->stats.rxbytesunicast; 1338c2ecf20Sopenharmony_ci} 1348c2ecf20Sopenharmony_ci 1358c2ecf20Sopenharmony_cistatic void _rtl92s_dm_txpowertracking_callback_thermalmeter( 1368c2ecf20Sopenharmony_ci struct ieee80211_hw *hw) 1378c2ecf20Sopenharmony_ci{ 1388c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 1398c2ecf20Sopenharmony_ci struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); 1408c2ecf20Sopenharmony_ci u8 thermalvalue = 0; 1418c2ecf20Sopenharmony_ci u32 fw_cmd = 0; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_ci rtlpriv->dm.txpower_trackinginit = true; 1448c2ecf20Sopenharmony_ci 1458c2ecf20Sopenharmony_ci thermalvalue = (u8)rtl_get_rfreg(hw, RF90_PATH_A, RF_T_METER, 0x1f); 1468c2ecf20Sopenharmony_ci 1478c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, 1488c2ecf20Sopenharmony_ci "Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermal meter 0x%x\n", 1498c2ecf20Sopenharmony_ci thermalvalue, 1508c2ecf20Sopenharmony_ci rtlpriv->dm.thermalvalue, rtlefuse->eeprom_thermalmeter); 1518c2ecf20Sopenharmony_ci 1528c2ecf20Sopenharmony_ci if (thermalvalue) { 1538c2ecf20Sopenharmony_ci rtlpriv->dm.thermalvalue = thermalvalue; 1548c2ecf20Sopenharmony_ci if (hal_get_firmwareversion(rtlpriv) >= 0x35) { 1558c2ecf20Sopenharmony_ci rtl92s_phy_set_fw_cmd(hw, FW_CMD_TXPWR_TRACK_THERMAL); 1568c2ecf20Sopenharmony_ci } else { 1578c2ecf20Sopenharmony_ci fw_cmd = (FW_TXPWR_TRACK_THERMAL | 1588c2ecf20Sopenharmony_ci (rtlpriv->efuse.thermalmeter[0] << 8) | 1598c2ecf20Sopenharmony_ci (thermalvalue << 16)); 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, 1628c2ecf20Sopenharmony_ci "Write to FW Thermal Val = 0x%x\n", fw_cmd); 1638c2ecf20Sopenharmony_ci 1648c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, WFM5, fw_cmd); 1658c2ecf20Sopenharmony_ci rtl92s_phy_chk_fwcmd_iodone(hw); 1668c2ecf20Sopenharmony_ci } 1678c2ecf20Sopenharmony_ci } 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci rtlpriv->dm.txpowercount = 0; 1708c2ecf20Sopenharmony_ci} 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_cistatic void _rtl92s_dm_check_txpowertracking_thermalmeter( 1738c2ecf20Sopenharmony_ci struct ieee80211_hw *hw) 1748c2ecf20Sopenharmony_ci{ 1758c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 1768c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 1778c2ecf20Sopenharmony_ci u8 tx_power_checkcnt = 5; 1788c2ecf20Sopenharmony_ci 1798c2ecf20Sopenharmony_ci /* 2T2R TP issue */ 1808c2ecf20Sopenharmony_ci if (rtlphy->rf_type == RF_2T2R) 1818c2ecf20Sopenharmony_ci return; 1828c2ecf20Sopenharmony_ci 1838c2ecf20Sopenharmony_ci if (!rtlpriv->dm.txpower_tracking) 1848c2ecf20Sopenharmony_ci return; 1858c2ecf20Sopenharmony_ci 1868c2ecf20Sopenharmony_ci if (rtlpriv->dm.txpowercount <= tx_power_checkcnt) { 1878c2ecf20Sopenharmony_ci rtlpriv->dm.txpowercount++; 1888c2ecf20Sopenharmony_ci return; 1898c2ecf20Sopenharmony_ci } 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci if (!rtlpriv->dm.tm_trigger) { 1928c2ecf20Sopenharmony_ci rtl_set_rfreg(hw, RF90_PATH_A, RF_T_METER, 1938c2ecf20Sopenharmony_ci RFREG_OFFSET_MASK, 0x60); 1948c2ecf20Sopenharmony_ci rtlpriv->dm.tm_trigger = 1; 1958c2ecf20Sopenharmony_ci } else { 1968c2ecf20Sopenharmony_ci _rtl92s_dm_txpowertracking_callback_thermalmeter(hw); 1978c2ecf20Sopenharmony_ci rtlpriv->dm.tm_trigger = 0; 1988c2ecf20Sopenharmony_ci } 1998c2ecf20Sopenharmony_ci} 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_cistatic void _rtl92s_dm_refresh_rateadaptive_mask(struct ieee80211_hw *hw) 2028c2ecf20Sopenharmony_ci{ 2038c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 2048c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 2058c2ecf20Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 2068c2ecf20Sopenharmony_ci struct rate_adaptive *ra = &(rtlpriv->ra); 2078c2ecf20Sopenharmony_ci struct ieee80211_sta *sta = NULL; 2088c2ecf20Sopenharmony_ci u32 low_rssi_thresh = 0; 2098c2ecf20Sopenharmony_ci u32 middle_rssi_thresh = 0; 2108c2ecf20Sopenharmony_ci u32 high_rssi_thresh = 0; 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ci if (is_hal_stop(rtlhal)) 2138c2ecf20Sopenharmony_ci return; 2148c2ecf20Sopenharmony_ci 2158c2ecf20Sopenharmony_ci if (!rtlpriv->dm.useramask) 2168c2ecf20Sopenharmony_ci return; 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci if (hal_get_firmwareversion(rtlpriv) >= 61 && 2198c2ecf20Sopenharmony_ci !rtlpriv->dm.inform_fw_driverctrldm) { 2208c2ecf20Sopenharmony_ci rtl92s_phy_set_fw_cmd(hw, FW_CMD_CTRL_DM_BY_DRIVER); 2218c2ecf20Sopenharmony_ci rtlpriv->dm.inform_fw_driverctrldm = true; 2228c2ecf20Sopenharmony_ci } 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci if ((mac->link_state == MAC80211_LINKED) && 2258c2ecf20Sopenharmony_ci (mac->opmode == NL80211_IFTYPE_STATION)) { 2268c2ecf20Sopenharmony_ci switch (ra->pre_ratr_state) { 2278c2ecf20Sopenharmony_ci case DM_RATR_STA_HIGH: 2288c2ecf20Sopenharmony_ci high_rssi_thresh = 40; 2298c2ecf20Sopenharmony_ci middle_rssi_thresh = 30; 2308c2ecf20Sopenharmony_ci low_rssi_thresh = 20; 2318c2ecf20Sopenharmony_ci break; 2328c2ecf20Sopenharmony_ci case DM_RATR_STA_MIDDLE: 2338c2ecf20Sopenharmony_ci high_rssi_thresh = 44; 2348c2ecf20Sopenharmony_ci middle_rssi_thresh = 30; 2358c2ecf20Sopenharmony_ci low_rssi_thresh = 20; 2368c2ecf20Sopenharmony_ci break; 2378c2ecf20Sopenharmony_ci case DM_RATR_STA_LOW: 2388c2ecf20Sopenharmony_ci high_rssi_thresh = 44; 2398c2ecf20Sopenharmony_ci middle_rssi_thresh = 34; 2408c2ecf20Sopenharmony_ci low_rssi_thresh = 20; 2418c2ecf20Sopenharmony_ci break; 2428c2ecf20Sopenharmony_ci case DM_RATR_STA_ULTRALOW: 2438c2ecf20Sopenharmony_ci high_rssi_thresh = 44; 2448c2ecf20Sopenharmony_ci middle_rssi_thresh = 34; 2458c2ecf20Sopenharmony_ci low_rssi_thresh = 24; 2468c2ecf20Sopenharmony_ci break; 2478c2ecf20Sopenharmony_ci default: 2488c2ecf20Sopenharmony_ci high_rssi_thresh = 44; 2498c2ecf20Sopenharmony_ci middle_rssi_thresh = 34; 2508c2ecf20Sopenharmony_ci low_rssi_thresh = 24; 2518c2ecf20Sopenharmony_ci break; 2528c2ecf20Sopenharmony_ci } 2538c2ecf20Sopenharmony_ci 2548c2ecf20Sopenharmony_ci if (rtlpriv->dm.undec_sm_pwdb > (long)high_rssi_thresh) { 2558c2ecf20Sopenharmony_ci ra->ratr_state = DM_RATR_STA_HIGH; 2568c2ecf20Sopenharmony_ci } else if (rtlpriv->dm.undec_sm_pwdb > 2578c2ecf20Sopenharmony_ci (long)middle_rssi_thresh) { 2588c2ecf20Sopenharmony_ci ra->ratr_state = DM_RATR_STA_LOW; 2598c2ecf20Sopenharmony_ci } else if (rtlpriv->dm.undec_sm_pwdb > 2608c2ecf20Sopenharmony_ci (long)low_rssi_thresh) { 2618c2ecf20Sopenharmony_ci ra->ratr_state = DM_RATR_STA_LOW; 2628c2ecf20Sopenharmony_ci } else { 2638c2ecf20Sopenharmony_ci ra->ratr_state = DM_RATR_STA_ULTRALOW; 2648c2ecf20Sopenharmony_ci } 2658c2ecf20Sopenharmony_ci 2668c2ecf20Sopenharmony_ci if (ra->pre_ratr_state != ra->ratr_state) { 2678c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_RATE, DBG_LOUD, 2688c2ecf20Sopenharmony_ci "RSSI = %ld RSSI_LEVEL = %d PreState = %d, CurState = %d\n", 2698c2ecf20Sopenharmony_ci rtlpriv->dm.undec_sm_pwdb, ra->ratr_state, 2708c2ecf20Sopenharmony_ci ra->pre_ratr_state, ra->ratr_state); 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci rcu_read_lock(); 2738c2ecf20Sopenharmony_ci sta = rtl_find_sta(hw, mac->bssid); 2748c2ecf20Sopenharmony_ci if (sta) 2758c2ecf20Sopenharmony_ci rtlpriv->cfg->ops->update_rate_tbl(hw, sta, 2768c2ecf20Sopenharmony_ci ra->ratr_state, 2778c2ecf20Sopenharmony_ci true); 2788c2ecf20Sopenharmony_ci rcu_read_unlock(); 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci ra->pre_ratr_state = ra->ratr_state; 2818c2ecf20Sopenharmony_ci } 2828c2ecf20Sopenharmony_ci } 2838c2ecf20Sopenharmony_ci} 2848c2ecf20Sopenharmony_ci 2858c2ecf20Sopenharmony_cistatic void _rtl92s_dm_switch_baseband_mrc(struct ieee80211_hw *hw) 2868c2ecf20Sopenharmony_ci{ 2878c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 2888c2ecf20Sopenharmony_ci struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); 2898c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 2908c2ecf20Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 2918c2ecf20Sopenharmony_ci bool current_mrc; 2928c2ecf20Sopenharmony_ci bool enable_mrc = true; 2938c2ecf20Sopenharmony_ci long tmpentry_maxpwdb = 0; 2948c2ecf20Sopenharmony_ci u8 rssi_a = 0; 2958c2ecf20Sopenharmony_ci u8 rssi_b = 0; 2968c2ecf20Sopenharmony_ci 2978c2ecf20Sopenharmony_ci if (is_hal_stop(rtlhal)) 2988c2ecf20Sopenharmony_ci return; 2998c2ecf20Sopenharmony_ci 3008c2ecf20Sopenharmony_ci if ((rtlphy->rf_type == RF_1T1R) || (rtlphy->rf_type == RF_2T2R)) 3018c2ecf20Sopenharmony_ci return; 3028c2ecf20Sopenharmony_ci 3038c2ecf20Sopenharmony_ci rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_MRC, (u8 *)(¤t_mrc)); 3048c2ecf20Sopenharmony_ci 3058c2ecf20Sopenharmony_ci if (mac->link_state >= MAC80211_LINKED) { 3068c2ecf20Sopenharmony_ci if (rtlpriv->dm.undec_sm_pwdb > tmpentry_maxpwdb) { 3078c2ecf20Sopenharmony_ci rssi_a = rtlpriv->stats.rx_rssi_percentage[RF90_PATH_A]; 3088c2ecf20Sopenharmony_ci rssi_b = rtlpriv->stats.rx_rssi_percentage[RF90_PATH_B]; 3098c2ecf20Sopenharmony_ci } 3108c2ecf20Sopenharmony_ci } 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci /* MRC settings would NOT affect TP on Wireless B mode. */ 3138c2ecf20Sopenharmony_ci if (mac->mode != WIRELESS_MODE_B) { 3148c2ecf20Sopenharmony_ci if ((rssi_a == 0) && (rssi_b == 0)) { 3158c2ecf20Sopenharmony_ci enable_mrc = true; 3168c2ecf20Sopenharmony_ci } else if (rssi_b > 30) { 3178c2ecf20Sopenharmony_ci /* Turn on B-Path */ 3188c2ecf20Sopenharmony_ci enable_mrc = true; 3198c2ecf20Sopenharmony_ci } else if (rssi_b < 5) { 3208c2ecf20Sopenharmony_ci /* Turn off B-path */ 3218c2ecf20Sopenharmony_ci enable_mrc = false; 3228c2ecf20Sopenharmony_ci /* Take care of RSSI differentiation. */ 3238c2ecf20Sopenharmony_ci } else if (rssi_a > 15 && (rssi_a >= rssi_b)) { 3248c2ecf20Sopenharmony_ci if ((rssi_a - rssi_b) > 15) 3258c2ecf20Sopenharmony_ci /* Turn off B-path */ 3268c2ecf20Sopenharmony_ci enable_mrc = false; 3278c2ecf20Sopenharmony_ci else if ((rssi_a - rssi_b) < 10) 3288c2ecf20Sopenharmony_ci /* Turn on B-Path */ 3298c2ecf20Sopenharmony_ci enable_mrc = true; 3308c2ecf20Sopenharmony_ci else 3318c2ecf20Sopenharmony_ci enable_mrc = current_mrc; 3328c2ecf20Sopenharmony_ci } else { 3338c2ecf20Sopenharmony_ci /* Turn on B-Path */ 3348c2ecf20Sopenharmony_ci enable_mrc = true; 3358c2ecf20Sopenharmony_ci } 3368c2ecf20Sopenharmony_ci } 3378c2ecf20Sopenharmony_ci 3388c2ecf20Sopenharmony_ci /* Update MRC settings if needed. */ 3398c2ecf20Sopenharmony_ci if (enable_mrc != current_mrc) 3408c2ecf20Sopenharmony_ci rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_MRC, 3418c2ecf20Sopenharmony_ci (u8 *)&enable_mrc); 3428c2ecf20Sopenharmony_ci 3438c2ecf20Sopenharmony_ci} 3448c2ecf20Sopenharmony_ci 3458c2ecf20Sopenharmony_civoid rtl92s_dm_init_edca_turbo(struct ieee80211_hw *hw) 3468c2ecf20Sopenharmony_ci{ 3478c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3488c2ecf20Sopenharmony_ci 3498c2ecf20Sopenharmony_ci rtlpriv->dm.current_turbo_edca = false; 3508c2ecf20Sopenharmony_ci rtlpriv->dm.is_any_nonbepkts = false; 3518c2ecf20Sopenharmony_ci rtlpriv->dm.is_cur_rdlstate = false; 3528c2ecf20Sopenharmony_ci} 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_cistatic void _rtl92s_dm_init_rate_adaptive_mask(struct ieee80211_hw *hw) 3558c2ecf20Sopenharmony_ci{ 3568c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3578c2ecf20Sopenharmony_ci struct rate_adaptive *ra = &(rtlpriv->ra); 3588c2ecf20Sopenharmony_ci 3598c2ecf20Sopenharmony_ci ra->ratr_state = DM_RATR_STA_MAX; 3608c2ecf20Sopenharmony_ci ra->pre_ratr_state = DM_RATR_STA_MAX; 3618c2ecf20Sopenharmony_ci 3628c2ecf20Sopenharmony_ci if (rtlpriv->dm.dm_type == DM_TYPE_BYDRIVER && 3638c2ecf20Sopenharmony_ci hal_get_firmwareversion(rtlpriv) >= 60) 3648c2ecf20Sopenharmony_ci rtlpriv->dm.useramask = true; 3658c2ecf20Sopenharmony_ci else 3668c2ecf20Sopenharmony_ci rtlpriv->dm.useramask = false; 3678c2ecf20Sopenharmony_ci 3688c2ecf20Sopenharmony_ci rtlpriv->dm.useramask = false; 3698c2ecf20Sopenharmony_ci rtlpriv->dm.inform_fw_driverctrldm = false; 3708c2ecf20Sopenharmony_ci} 3718c2ecf20Sopenharmony_ci 3728c2ecf20Sopenharmony_cistatic void _rtl92s_dm_init_txpowertracking_thermalmeter( 3738c2ecf20Sopenharmony_ci struct ieee80211_hw *hw) 3748c2ecf20Sopenharmony_ci{ 3758c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_ci rtlpriv->dm.txpower_tracking = true; 3788c2ecf20Sopenharmony_ci rtlpriv->dm.txpowercount = 0; 3798c2ecf20Sopenharmony_ci rtlpriv->dm.txpower_trackinginit = false; 3808c2ecf20Sopenharmony_ci} 3818c2ecf20Sopenharmony_ci 3828c2ecf20Sopenharmony_cistatic void _rtl92s_dm_false_alarm_counter_statistics(struct ieee80211_hw *hw) 3838c2ecf20Sopenharmony_ci{ 3848c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 3858c2ecf20Sopenharmony_ci struct false_alarm_statistics *falsealm_cnt = &(rtlpriv->falsealm_cnt); 3868c2ecf20Sopenharmony_ci u32 ret_value; 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER1, MASKDWORD); 3898c2ecf20Sopenharmony_ci falsealm_cnt->cnt_parity_fail = ((ret_value & 0xffff0000) >> 16); 3908c2ecf20Sopenharmony_ci 3918c2ecf20Sopenharmony_ci ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER2, MASKDWORD); 3928c2ecf20Sopenharmony_ci falsealm_cnt->cnt_rate_illegal = (ret_value & 0xffff); 3938c2ecf20Sopenharmony_ci falsealm_cnt->cnt_crc8_fail = ((ret_value & 0xffff0000) >> 16); 3948c2ecf20Sopenharmony_ci ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER3, MASKDWORD); 3958c2ecf20Sopenharmony_ci falsealm_cnt->cnt_mcs_fail = (ret_value & 0xffff); 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_ci falsealm_cnt->cnt_ofdm_fail = falsealm_cnt->cnt_parity_fail + 3988c2ecf20Sopenharmony_ci falsealm_cnt->cnt_rate_illegal + falsealm_cnt->cnt_crc8_fail + 3998c2ecf20Sopenharmony_ci falsealm_cnt->cnt_mcs_fail; 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci /* read CCK false alarm */ 4028c2ecf20Sopenharmony_ci ret_value = rtl_get_bbreg(hw, 0xc64, MASKDWORD); 4038c2ecf20Sopenharmony_ci falsealm_cnt->cnt_cck_fail = (ret_value & 0xffff); 4048c2ecf20Sopenharmony_ci falsealm_cnt->cnt_all = falsealm_cnt->cnt_ofdm_fail + 4058c2ecf20Sopenharmony_ci falsealm_cnt->cnt_cck_fail; 4068c2ecf20Sopenharmony_ci} 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_cistatic void rtl92s_backoff_enable_flag(struct ieee80211_hw *hw) 4098c2ecf20Sopenharmony_ci{ 4108c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 4118c2ecf20Sopenharmony_ci struct dig_t *digtable = &rtlpriv->dm_digtable; 4128c2ecf20Sopenharmony_ci struct false_alarm_statistics *falsealm_cnt = &(rtlpriv->falsealm_cnt); 4138c2ecf20Sopenharmony_ci 4148c2ecf20Sopenharmony_ci if (falsealm_cnt->cnt_all > digtable->fa_highthresh) { 4158c2ecf20Sopenharmony_ci if ((digtable->back_val - 6) < 4168c2ecf20Sopenharmony_ci digtable->backoffval_range_min) 4178c2ecf20Sopenharmony_ci digtable->back_val = digtable->backoffval_range_min; 4188c2ecf20Sopenharmony_ci else 4198c2ecf20Sopenharmony_ci digtable->back_val -= 6; 4208c2ecf20Sopenharmony_ci } else if (falsealm_cnt->cnt_all < digtable->fa_lowthresh) { 4218c2ecf20Sopenharmony_ci if ((digtable->back_val + 6) > 4228c2ecf20Sopenharmony_ci digtable->backoffval_range_max) 4238c2ecf20Sopenharmony_ci digtable->back_val = 4248c2ecf20Sopenharmony_ci digtable->backoffval_range_max; 4258c2ecf20Sopenharmony_ci else 4268c2ecf20Sopenharmony_ci digtable->back_val += 6; 4278c2ecf20Sopenharmony_ci } 4288c2ecf20Sopenharmony_ci} 4298c2ecf20Sopenharmony_ci 4308c2ecf20Sopenharmony_cistatic void _rtl92s_dm_initial_gain_sta_beforeconnect(struct ieee80211_hw *hw) 4318c2ecf20Sopenharmony_ci{ 4328c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 4338c2ecf20Sopenharmony_ci struct dig_t *digtable = &rtlpriv->dm_digtable; 4348c2ecf20Sopenharmony_ci struct false_alarm_statistics *falsealm_cnt = &(rtlpriv->falsealm_cnt); 4358c2ecf20Sopenharmony_ci static u8 initialized, force_write; 4368c2ecf20Sopenharmony_ci u8 initial_gain = 0; 4378c2ecf20Sopenharmony_ci 4388c2ecf20Sopenharmony_ci if ((digtable->pre_sta_cstate == digtable->cur_sta_cstate) || 4398c2ecf20Sopenharmony_ci (digtable->cur_sta_cstate == DIG_STA_BEFORE_CONNECT)) { 4408c2ecf20Sopenharmony_ci if (digtable->cur_sta_cstate == DIG_STA_BEFORE_CONNECT) { 4418c2ecf20Sopenharmony_ci if (rtlpriv->psc.rfpwr_state != ERFON) 4428c2ecf20Sopenharmony_ci return; 4438c2ecf20Sopenharmony_ci 4448c2ecf20Sopenharmony_ci if (digtable->backoff_enable_flag) 4458c2ecf20Sopenharmony_ci rtl92s_backoff_enable_flag(hw); 4468c2ecf20Sopenharmony_ci else 4478c2ecf20Sopenharmony_ci digtable->back_val = DM_DIG_BACKOFF_MAX; 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_ci if ((digtable->rssi_val + 10 - digtable->back_val) > 4508c2ecf20Sopenharmony_ci digtable->rx_gain_max) 4518c2ecf20Sopenharmony_ci digtable->cur_igvalue = 4528c2ecf20Sopenharmony_ci digtable->rx_gain_max; 4538c2ecf20Sopenharmony_ci else if ((digtable->rssi_val + 10 - digtable->back_val) 4548c2ecf20Sopenharmony_ci < digtable->rx_gain_min) 4558c2ecf20Sopenharmony_ci digtable->cur_igvalue = 4568c2ecf20Sopenharmony_ci digtable->rx_gain_min; 4578c2ecf20Sopenharmony_ci else 4588c2ecf20Sopenharmony_ci digtable->cur_igvalue = digtable->rssi_val + 10 4598c2ecf20Sopenharmony_ci - digtable->back_val; 4608c2ecf20Sopenharmony_ci 4618c2ecf20Sopenharmony_ci if (falsealm_cnt->cnt_all > 10000) 4628c2ecf20Sopenharmony_ci digtable->cur_igvalue = 4638c2ecf20Sopenharmony_ci (digtable->cur_igvalue > 0x33) ? 4648c2ecf20Sopenharmony_ci digtable->cur_igvalue : 0x33; 4658c2ecf20Sopenharmony_ci 4668c2ecf20Sopenharmony_ci if (falsealm_cnt->cnt_all > 16000) 4678c2ecf20Sopenharmony_ci digtable->cur_igvalue = 4688c2ecf20Sopenharmony_ci digtable->rx_gain_max; 4698c2ecf20Sopenharmony_ci /* connected -> connected or disconnected -> disconnected */ 4708c2ecf20Sopenharmony_ci } else { 4718c2ecf20Sopenharmony_ci /* Firmware control DIG, do nothing in driver dm */ 4728c2ecf20Sopenharmony_ci return; 4738c2ecf20Sopenharmony_ci } 4748c2ecf20Sopenharmony_ci /* disconnected -> connected or connected -> 4758c2ecf20Sopenharmony_ci * disconnected or beforeconnect->(dis)connected */ 4768c2ecf20Sopenharmony_ci } else { 4778c2ecf20Sopenharmony_ci /* Enable FW DIG */ 4788c2ecf20Sopenharmony_ci digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX; 4798c2ecf20Sopenharmony_ci rtl92s_phy_set_fw_cmd(hw, FW_CMD_DIG_ENABLE); 4808c2ecf20Sopenharmony_ci 4818c2ecf20Sopenharmony_ci digtable->back_val = DM_DIG_BACKOFF_MAX; 4828c2ecf20Sopenharmony_ci digtable->cur_igvalue = rtlpriv->phy.default_initialgain[0]; 4838c2ecf20Sopenharmony_ci digtable->pre_igvalue = 0; 4848c2ecf20Sopenharmony_ci return; 4858c2ecf20Sopenharmony_ci } 4868c2ecf20Sopenharmony_ci 4878c2ecf20Sopenharmony_ci /* Forced writing to prevent from fw-dig overwriting. */ 4888c2ecf20Sopenharmony_ci if (digtable->pre_igvalue != rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, 4898c2ecf20Sopenharmony_ci MASKBYTE0)) 4908c2ecf20Sopenharmony_ci force_write = 1; 4918c2ecf20Sopenharmony_ci 4928c2ecf20Sopenharmony_ci if ((digtable->pre_igvalue != digtable->cur_igvalue) || 4938c2ecf20Sopenharmony_ci !initialized || force_write) { 4948c2ecf20Sopenharmony_ci /* Disable FW DIG */ 4958c2ecf20Sopenharmony_ci rtl92s_phy_set_fw_cmd(hw, FW_CMD_DIG_DISABLE); 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci initial_gain = (u8)digtable->cur_igvalue; 4988c2ecf20Sopenharmony_ci 4998c2ecf20Sopenharmony_ci /* Set initial gain. */ 5008c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XAAGCCORE1, MASKBYTE0, initial_gain); 5018c2ecf20Sopenharmony_ci rtl_set_bbreg(hw, ROFDM0_XBAGCCORE1, MASKBYTE0, initial_gain); 5028c2ecf20Sopenharmony_ci digtable->pre_igvalue = digtable->cur_igvalue; 5038c2ecf20Sopenharmony_ci initialized = 1; 5048c2ecf20Sopenharmony_ci force_write = 0; 5058c2ecf20Sopenharmony_ci } 5068c2ecf20Sopenharmony_ci} 5078c2ecf20Sopenharmony_ci 5088c2ecf20Sopenharmony_cistatic void _rtl92s_dm_ctrl_initgain_bytwoport(struct ieee80211_hw *hw) 5098c2ecf20Sopenharmony_ci{ 5108c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 5118c2ecf20Sopenharmony_ci struct dig_t *dig = &rtlpriv->dm_digtable; 5128c2ecf20Sopenharmony_ci 5138c2ecf20Sopenharmony_ci if (rtlpriv->mac80211.act_scanning) 5148c2ecf20Sopenharmony_ci return; 5158c2ecf20Sopenharmony_ci 5168c2ecf20Sopenharmony_ci /* Decide the current status and if modify initial gain or not */ 5178c2ecf20Sopenharmony_ci if (rtlpriv->mac80211.link_state >= MAC80211_LINKED || 5188c2ecf20Sopenharmony_ci rtlpriv->mac80211.opmode == NL80211_IFTYPE_ADHOC) 5198c2ecf20Sopenharmony_ci dig->cur_sta_cstate = DIG_STA_CONNECT; 5208c2ecf20Sopenharmony_ci else 5218c2ecf20Sopenharmony_ci dig->cur_sta_cstate = DIG_STA_DISCONNECT; 5228c2ecf20Sopenharmony_ci 5238c2ecf20Sopenharmony_ci dig->rssi_val = rtlpriv->dm.undec_sm_pwdb; 5248c2ecf20Sopenharmony_ci 5258c2ecf20Sopenharmony_ci /* Change dig mode to rssi */ 5268c2ecf20Sopenharmony_ci if (dig->cur_sta_cstate != DIG_STA_DISCONNECT) { 5278c2ecf20Sopenharmony_ci if (dig->dig_twoport_algorithm == 5288c2ecf20Sopenharmony_ci DIG_TWO_PORT_ALGO_FALSE_ALARM) { 5298c2ecf20Sopenharmony_ci dig->dig_twoport_algorithm = DIG_TWO_PORT_ALGO_RSSI; 5308c2ecf20Sopenharmony_ci rtl92s_phy_set_fw_cmd(hw, FW_CMD_DIG_MODE_SS); 5318c2ecf20Sopenharmony_ci } 5328c2ecf20Sopenharmony_ci } 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci _rtl92s_dm_false_alarm_counter_statistics(hw); 5358c2ecf20Sopenharmony_ci _rtl92s_dm_initial_gain_sta_beforeconnect(hw); 5368c2ecf20Sopenharmony_ci 5378c2ecf20Sopenharmony_ci dig->pre_sta_cstate = dig->cur_sta_cstate; 5388c2ecf20Sopenharmony_ci} 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_cistatic void _rtl92s_dm_ctrl_initgain_byrssi(struct ieee80211_hw *hw) 5418c2ecf20Sopenharmony_ci{ 5428c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 5438c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 5448c2ecf20Sopenharmony_ci struct dig_t *digtable = &rtlpriv->dm_digtable; 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_ci /* 2T2R TP issue */ 5478c2ecf20Sopenharmony_ci if (rtlphy->rf_type == RF_2T2R) 5488c2ecf20Sopenharmony_ci return; 5498c2ecf20Sopenharmony_ci 5508c2ecf20Sopenharmony_ci if (!rtlpriv->dm.dm_initialgain_enable) 5518c2ecf20Sopenharmony_ci return; 5528c2ecf20Sopenharmony_ci 5538c2ecf20Sopenharmony_ci if (digtable->dig_enable_flag == false) 5548c2ecf20Sopenharmony_ci return; 5558c2ecf20Sopenharmony_ci 5568c2ecf20Sopenharmony_ci _rtl92s_dm_ctrl_initgain_bytwoport(hw); 5578c2ecf20Sopenharmony_ci} 5588c2ecf20Sopenharmony_ci 5598c2ecf20Sopenharmony_cistatic void _rtl92s_dm_dynamic_txpower(struct ieee80211_hw *hw) 5608c2ecf20Sopenharmony_ci{ 5618c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 5628c2ecf20Sopenharmony_ci struct rtl_phy *rtlphy = &(rtlpriv->phy); 5638c2ecf20Sopenharmony_ci struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); 5648c2ecf20Sopenharmony_ci long undec_sm_pwdb; 5658c2ecf20Sopenharmony_ci long txpwr_threshold_lv1, txpwr_threshold_lv2; 5668c2ecf20Sopenharmony_ci 5678c2ecf20Sopenharmony_ci /* 2T2R TP issue */ 5688c2ecf20Sopenharmony_ci if (rtlphy->rf_type == RF_2T2R) 5698c2ecf20Sopenharmony_ci return; 5708c2ecf20Sopenharmony_ci 5718c2ecf20Sopenharmony_ci if (!rtlpriv->dm.dynamic_txpower_enable || 5728c2ecf20Sopenharmony_ci rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) { 5738c2ecf20Sopenharmony_ci rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL; 5748c2ecf20Sopenharmony_ci return; 5758c2ecf20Sopenharmony_ci } 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ci if ((mac->link_state < MAC80211_LINKED) && 5788c2ecf20Sopenharmony_ci (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) { 5798c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_TRACE, 5808c2ecf20Sopenharmony_ci "Not connected to any\n"); 5818c2ecf20Sopenharmony_ci 5828c2ecf20Sopenharmony_ci rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL; 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci rtlpriv->dm.last_dtp_lvl = TX_HIGHPWR_LEVEL_NORMAL; 5858c2ecf20Sopenharmony_ci return; 5868c2ecf20Sopenharmony_ci } 5878c2ecf20Sopenharmony_ci 5888c2ecf20Sopenharmony_ci if (mac->link_state >= MAC80211_LINKED) { 5898c2ecf20Sopenharmony_ci if (mac->opmode == NL80211_IFTYPE_ADHOC) { 5908c2ecf20Sopenharmony_ci undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; 5918c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD, 5928c2ecf20Sopenharmony_ci "AP Client PWDB = 0x%lx\n", 5938c2ecf20Sopenharmony_ci undec_sm_pwdb); 5948c2ecf20Sopenharmony_ci } else { 5958c2ecf20Sopenharmony_ci undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; 5968c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD, 5978c2ecf20Sopenharmony_ci "STA Default Port PWDB = 0x%lx\n", 5988c2ecf20Sopenharmony_ci undec_sm_pwdb); 5998c2ecf20Sopenharmony_ci } 6008c2ecf20Sopenharmony_ci } else { 6018c2ecf20Sopenharmony_ci undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; 6028c2ecf20Sopenharmony_ci 6038c2ecf20Sopenharmony_ci rtl_dbg(rtlpriv, COMP_POWER, DBG_LOUD, 6048c2ecf20Sopenharmony_ci "AP Ext Port PWDB = 0x%lx\n", 6058c2ecf20Sopenharmony_ci undec_sm_pwdb); 6068c2ecf20Sopenharmony_ci } 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci txpwr_threshold_lv2 = TX_POWER_NEAR_FIELD_THRESH_LVL2; 6098c2ecf20Sopenharmony_ci txpwr_threshold_lv1 = TX_POWER_NEAR_FIELD_THRESH_LVL1; 6108c2ecf20Sopenharmony_ci 6118c2ecf20Sopenharmony_ci if (rtl_get_bbreg(hw, 0xc90, MASKBYTE0) == 1) 6128c2ecf20Sopenharmony_ci rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL; 6138c2ecf20Sopenharmony_ci else if (undec_sm_pwdb >= txpwr_threshold_lv2) 6148c2ecf20Sopenharmony_ci rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL2; 6158c2ecf20Sopenharmony_ci else if ((undec_sm_pwdb < (txpwr_threshold_lv2 - 3)) && 6168c2ecf20Sopenharmony_ci (undec_sm_pwdb >= txpwr_threshold_lv1)) 6178c2ecf20Sopenharmony_ci rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL1; 6188c2ecf20Sopenharmony_ci else if (undec_sm_pwdb < (txpwr_threshold_lv1 - 3)) 6198c2ecf20Sopenharmony_ci rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL; 6208c2ecf20Sopenharmony_ci 6218c2ecf20Sopenharmony_ci if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) 6228c2ecf20Sopenharmony_ci rtl92s_phy_set_txpower(hw, rtlphy->current_channel); 6238c2ecf20Sopenharmony_ci 6248c2ecf20Sopenharmony_ci rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl; 6258c2ecf20Sopenharmony_ci} 6268c2ecf20Sopenharmony_ci 6278c2ecf20Sopenharmony_cistatic void _rtl92s_dm_init_dig(struct ieee80211_hw *hw) 6288c2ecf20Sopenharmony_ci{ 6298c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 6308c2ecf20Sopenharmony_ci struct dig_t *digtable = &rtlpriv->dm_digtable; 6318c2ecf20Sopenharmony_ci 6328c2ecf20Sopenharmony_ci /* Disable DIG scheme now.*/ 6338c2ecf20Sopenharmony_ci digtable->dig_enable_flag = true; 6348c2ecf20Sopenharmony_ci digtable->backoff_enable_flag = true; 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ci if ((rtlpriv->dm.dm_type == DM_TYPE_BYDRIVER) && 6378c2ecf20Sopenharmony_ci (hal_get_firmwareversion(rtlpriv) >= 0x3c)) 6388c2ecf20Sopenharmony_ci digtable->dig_algorithm = DIG_ALGO_BY_TOW_PORT; 6398c2ecf20Sopenharmony_ci else 6408c2ecf20Sopenharmony_ci digtable->dig_algorithm = 6418c2ecf20Sopenharmony_ci DIG_ALGO_BEFORE_CONNECT_BY_RSSI_AND_ALARM; 6428c2ecf20Sopenharmony_ci 6438c2ecf20Sopenharmony_ci digtable->dig_twoport_algorithm = DIG_TWO_PORT_ALGO_RSSI; 6448c2ecf20Sopenharmony_ci digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX; 6458c2ecf20Sopenharmony_ci /* off=by real rssi value, on=by digtable->rssi_val for new dig */ 6468c2ecf20Sopenharmony_ci digtable->dig_dbgmode = DM_DBG_OFF; 6478c2ecf20Sopenharmony_ci digtable->dig_slgorithm_switch = 0; 6488c2ecf20Sopenharmony_ci 6498c2ecf20Sopenharmony_ci /* 2007/10/04 MH Define init gain threshol. */ 6508c2ecf20Sopenharmony_ci digtable->dig_state = DM_STA_DIG_MAX; 6518c2ecf20Sopenharmony_ci digtable->dig_highpwrstate = DM_STA_DIG_MAX; 6528c2ecf20Sopenharmony_ci 6538c2ecf20Sopenharmony_ci digtable->cur_sta_cstate = DIG_STA_DISCONNECT; 6548c2ecf20Sopenharmony_ci digtable->pre_sta_cstate = DIG_STA_DISCONNECT; 6558c2ecf20Sopenharmony_ci digtable->cur_ap_cstate = DIG_AP_DISCONNECT; 6568c2ecf20Sopenharmony_ci digtable->pre_ap_cstate = DIG_AP_DISCONNECT; 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci digtable->rssi_lowthresh = DM_DIG_THRESH_LOW; 6598c2ecf20Sopenharmony_ci digtable->rssi_highthresh = DM_DIG_THRESH_HIGH; 6608c2ecf20Sopenharmony_ci 6618c2ecf20Sopenharmony_ci digtable->fa_lowthresh = DM_FALSEALARM_THRESH_LOW; 6628c2ecf20Sopenharmony_ci digtable->fa_highthresh = DM_FALSEALARM_THRESH_HIGH; 6638c2ecf20Sopenharmony_ci 6648c2ecf20Sopenharmony_ci digtable->rssi_highpower_lowthresh = DM_DIG_HIGH_PWR_THRESH_LOW; 6658c2ecf20Sopenharmony_ci digtable->rssi_highpower_highthresh = DM_DIG_HIGH_PWR_THRESH_HIGH; 6668c2ecf20Sopenharmony_ci 6678c2ecf20Sopenharmony_ci /* for dig debug rssi value */ 6688c2ecf20Sopenharmony_ci digtable->rssi_val = 50; 6698c2ecf20Sopenharmony_ci digtable->back_val = DM_DIG_BACKOFF_MAX; 6708c2ecf20Sopenharmony_ci digtable->rx_gain_max = DM_DIG_MAX; 6718c2ecf20Sopenharmony_ci 6728c2ecf20Sopenharmony_ci digtable->rx_gain_min = DM_DIG_MIN; 6738c2ecf20Sopenharmony_ci 6748c2ecf20Sopenharmony_ci digtable->backoffval_range_max = DM_DIG_BACKOFF_MAX; 6758c2ecf20Sopenharmony_ci digtable->backoffval_range_min = DM_DIG_BACKOFF_MIN; 6768c2ecf20Sopenharmony_ci} 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_cistatic void _rtl92s_dm_init_dynamic_txpower(struct ieee80211_hw *hw) 6798c2ecf20Sopenharmony_ci{ 6808c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 6818c2ecf20Sopenharmony_ci 6828c2ecf20Sopenharmony_ci if ((hal_get_firmwareversion(rtlpriv) >= 60) && 6838c2ecf20Sopenharmony_ci (rtlpriv->dm.dm_type == DM_TYPE_BYDRIVER)) 6848c2ecf20Sopenharmony_ci rtlpriv->dm.dynamic_txpower_enable = true; 6858c2ecf20Sopenharmony_ci else 6868c2ecf20Sopenharmony_ci rtlpriv->dm.dynamic_txpower_enable = false; 6878c2ecf20Sopenharmony_ci 6888c2ecf20Sopenharmony_ci rtlpriv->dm.last_dtp_lvl = TX_HIGHPWR_LEVEL_NORMAL; 6898c2ecf20Sopenharmony_ci rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL; 6908c2ecf20Sopenharmony_ci} 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_civoid rtl92s_dm_init(struct ieee80211_hw *hw) 6938c2ecf20Sopenharmony_ci{ 6948c2ecf20Sopenharmony_ci struct rtl_priv *rtlpriv = rtl_priv(hw); 6958c2ecf20Sopenharmony_ci 6968c2ecf20Sopenharmony_ci rtlpriv->dm.dm_type = DM_TYPE_BYDRIVER; 6978c2ecf20Sopenharmony_ci rtlpriv->dm.undec_sm_pwdb = -1; 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_ci _rtl92s_dm_init_dynamic_txpower(hw); 7008c2ecf20Sopenharmony_ci rtl92s_dm_init_edca_turbo(hw); 7018c2ecf20Sopenharmony_ci _rtl92s_dm_init_rate_adaptive_mask(hw); 7028c2ecf20Sopenharmony_ci _rtl92s_dm_init_txpowertracking_thermalmeter(hw); 7038c2ecf20Sopenharmony_ci _rtl92s_dm_init_dig(hw); 7048c2ecf20Sopenharmony_ci 7058c2ecf20Sopenharmony_ci rtl_write_dword(rtlpriv, WFM5, FW_CCA_CHK_ENABLE); 7068c2ecf20Sopenharmony_ci} 7078c2ecf20Sopenharmony_ci 7088c2ecf20Sopenharmony_civoid rtl92s_dm_watchdog(struct ieee80211_hw *hw) 7098c2ecf20Sopenharmony_ci{ 7108c2ecf20Sopenharmony_ci _rtl92s_dm_check_edca_turbo(hw); 7118c2ecf20Sopenharmony_ci _rtl92s_dm_check_txpowertracking_thermalmeter(hw); 7128c2ecf20Sopenharmony_ci _rtl92s_dm_ctrl_initgain_byrssi(hw); 7138c2ecf20Sopenharmony_ci _rtl92s_dm_dynamic_txpower(hw); 7148c2ecf20Sopenharmony_ci _rtl92s_dm_refresh_rateadaptive_mask(hw); 7158c2ecf20Sopenharmony_ci _rtl92s_dm_switch_baseband_mrc(hw); 7168c2ecf20Sopenharmony_ci} 7178c2ecf20Sopenharmony_ci 718