Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Larry Finger | ca742cd | 2012-01-07 20:46:47 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012 Realtek Corporation. |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 14 | * The full GNU General Public License is included in this distribution in the |
| 15 | * file called LICENSE. |
| 16 | * |
| 17 | * Contact Information: |
| 18 | * wlanfae <wlanfae@realtek.com> |
| 19 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, |
| 20 | * Hsinchu 300, Taiwan. |
| 21 | * |
| 22 | * Larry Finger <Larry.Finger@lwfinger.net> |
| 23 | * |
| 24 | *****************************************************************************/ |
| 25 | |
| 26 | #include "../wifi.h" |
| 27 | #include "../base.h" |
Larry Finger | 6f8214b | 2015-01-06 09:58:04 -0600 | [diff] [blame] | 28 | #include "../core.h" |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 29 | #include "reg.h" |
| 30 | #include "def.h" |
| 31 | #include "phy.h" |
| 32 | #include "dm.h" |
| 33 | #include "fw.h" |
| 34 | |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 35 | static const u32 edca_setting_dl[PEER_MAX] = { |
| 36 | 0xa44f, /* 0 UNKNOWN */ |
| 37 | 0x5ea44f, /* 1 REALTEK_90 */ |
| 38 | 0x5ea44f, /* 2 REALTEK_92SE */ |
| 39 | 0xa630, /* 3 BROAD */ |
| 40 | 0xa44f, /* 4 RAL */ |
| 41 | 0xa630, /* 5 ATH */ |
| 42 | 0xa630, /* 6 CISCO */ |
| 43 | 0xa42b, /* 7 MARV */ |
| 44 | }; |
| 45 | |
| 46 | static const u32 edca_setting_dl_gmode[PEER_MAX] = { |
| 47 | 0x4322, /* 0 UNKNOWN */ |
| 48 | 0xa44f, /* 1 REALTEK_90 */ |
| 49 | 0x5ea44f, /* 2 REALTEK_92SE */ |
| 50 | 0xa42b, /* 3 BROAD */ |
| 51 | 0x5e4322, /* 4 RAL */ |
| 52 | 0x4322, /* 5 ATH */ |
| 53 | 0xa430, /* 6 CISCO */ |
| 54 | 0x5ea44f, /* 7 MARV */ |
| 55 | }; |
| 56 | |
| 57 | static const u32 edca_setting_ul[PEER_MAX] = { |
| 58 | 0x5e4322, /* 0 UNKNOWN */ |
| 59 | 0xa44f, /* 1 REALTEK_90 */ |
| 60 | 0x5ea44f, /* 2 REALTEK_92SE */ |
| 61 | 0x5ea322, /* 3 BROAD */ |
| 62 | 0x5ea422, /* 4 RAL */ |
| 63 | 0x5ea322, /* 5 ATH */ |
| 64 | 0x3ea44f, /* 6 CISCO */ |
| 65 | 0x5ea44f, /* 7 MARV */ |
| 66 | }; |
| 67 | |
| 68 | static void _rtl92s_dm_check_edca_turbo(struct ieee80211_hw *hw) |
| 69 | { |
| 70 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 71 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 72 | |
| 73 | static u64 last_txok_cnt; |
| 74 | static u64 last_rxok_cnt; |
| 75 | u64 cur_txok_cnt = 0; |
| 76 | u64 cur_rxok_cnt = 0; |
| 77 | |
| 78 | u32 edca_be_ul = edca_setting_ul[mac->vendor]; |
| 79 | u32 edca_be_dl = edca_setting_dl[mac->vendor]; |
| 80 | u32 edca_gmode = edca_setting_dl_gmode[mac->vendor]; |
| 81 | |
| 82 | if (mac->link_state != MAC80211_LINKED) { |
| 83 | rtlpriv->dm.current_turbo_edca = false; |
| 84 | goto dm_checkedcaturbo_exit; |
| 85 | } |
| 86 | |
| 87 | if ((!rtlpriv->dm.is_any_nonbepkts) && |
| 88 | (!rtlpriv->dm.disable_framebursting)) { |
| 89 | cur_txok_cnt = rtlpriv->stats.txbytesunicast - last_txok_cnt; |
| 90 | cur_rxok_cnt = rtlpriv->stats.rxbytesunicast - last_rxok_cnt; |
| 91 | |
| 92 | if (rtlpriv->phy.rf_type == RF_1T2R) { |
| 93 | if (cur_txok_cnt > 4 * cur_rxok_cnt) { |
| 94 | /* Uplink TP is present. */ |
| 95 | if (rtlpriv->dm.is_cur_rdlstate || |
| 96 | !rtlpriv->dm.current_turbo_edca) { |
| 97 | rtl_write_dword(rtlpriv, EDCAPARA_BE, |
| 98 | edca_be_ul); |
| 99 | rtlpriv->dm.is_cur_rdlstate = false; |
| 100 | } |
| 101 | } else {/* Balance TP is present. */ |
| 102 | if (!rtlpriv->dm.is_cur_rdlstate || |
| 103 | !rtlpriv->dm.current_turbo_edca) { |
| 104 | if (mac->mode == WIRELESS_MODE_G || |
| 105 | mac->mode == WIRELESS_MODE_B) |
| 106 | rtl_write_dword(rtlpriv, |
| 107 | EDCAPARA_BE, |
| 108 | edca_gmode); |
| 109 | else |
| 110 | rtl_write_dword(rtlpriv, |
| 111 | EDCAPARA_BE, |
| 112 | edca_be_dl); |
| 113 | rtlpriv->dm.is_cur_rdlstate = true; |
| 114 | } |
| 115 | } |
| 116 | rtlpriv->dm.current_turbo_edca = true; |
| 117 | } else { |
| 118 | if (cur_rxok_cnt > 4 * cur_txok_cnt) { |
| 119 | if (!rtlpriv->dm.is_cur_rdlstate || |
| 120 | !rtlpriv->dm.current_turbo_edca) { |
| 121 | if (mac->mode == WIRELESS_MODE_G || |
| 122 | mac->mode == WIRELESS_MODE_B) |
| 123 | rtl_write_dword(rtlpriv, |
| 124 | EDCAPARA_BE, |
| 125 | edca_gmode); |
| 126 | else |
| 127 | rtl_write_dword(rtlpriv, |
| 128 | EDCAPARA_BE, |
| 129 | edca_be_dl); |
| 130 | rtlpriv->dm.is_cur_rdlstate = true; |
| 131 | } |
| 132 | } else { |
| 133 | if (rtlpriv->dm.is_cur_rdlstate || |
| 134 | !rtlpriv->dm.current_turbo_edca) { |
| 135 | rtl_write_dword(rtlpriv, EDCAPARA_BE, |
| 136 | edca_be_ul); |
| 137 | rtlpriv->dm.is_cur_rdlstate = false; |
| 138 | } |
| 139 | } |
| 140 | rtlpriv->dm.current_turbo_edca = true; |
| 141 | } |
| 142 | } else { |
| 143 | if (rtlpriv->dm.current_turbo_edca) { |
| 144 | u8 tmp = AC0_BE; |
| 145 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_AC_PARAM, |
Joe Perches | 2c20889 | 2012-06-04 12:44:17 +0000 | [diff] [blame] | 146 | &tmp); |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 147 | rtlpriv->dm.current_turbo_edca = false; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | dm_checkedcaturbo_exit: |
| 152 | rtlpriv->dm.is_any_nonbepkts = false; |
| 153 | last_txok_cnt = rtlpriv->stats.txbytesunicast; |
| 154 | last_rxok_cnt = rtlpriv->stats.rxbytesunicast; |
| 155 | } |
| 156 | |
| 157 | static void _rtl92s_dm_txpowertracking_callback_thermalmeter( |
| 158 | struct ieee80211_hw *hw) |
| 159 | { |
| 160 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 161 | struct rtl_efuse *rtlefuse = rtl_efuse(rtl_priv(hw)); |
| 162 | u8 thermalvalue = 0; |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 163 | u32 fw_cmd = 0; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 164 | |
| 165 | rtlpriv->dm.txpower_trackinginit = true; |
| 166 | |
| 167 | thermalvalue = (u8)rtl_get_rfreg(hw, RF90_PATH_A, RF_T_METER, 0x1f); |
| 168 | |
| 169 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 170 | "Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermal meter 0x%x\n", |
| 171 | thermalvalue, |
| 172 | rtlpriv->dm.thermalvalue, rtlefuse->eeprom_thermalmeter); |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 173 | |
| 174 | if (thermalvalue) { |
| 175 | rtlpriv->dm.thermalvalue = thermalvalue; |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 176 | if (hal_get_firmwareversion(rtlpriv) >= 0x35) { |
| 177 | rtl92s_phy_set_fw_cmd(hw, FW_CMD_TXPWR_TRACK_THERMAL); |
| 178 | } else { |
| 179 | fw_cmd = (FW_TXPWR_TRACK_THERMAL | |
| 180 | (rtlpriv->efuse.thermalmeter[0] << 8) | |
| 181 | (thermalvalue << 16)); |
| 182 | |
| 183 | RT_TRACE(rtlpriv, COMP_POWER_TRACKING, DBG_LOUD, |
| 184 | "Write to FW Thermal Val = 0x%x\n", fw_cmd); |
| 185 | |
| 186 | rtl_write_dword(rtlpriv, WFM5, fw_cmd); |
| 187 | rtl92s_phy_chk_fwcmd_iodone(hw); |
| 188 | } |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | rtlpriv->dm.txpowercount = 0; |
| 192 | } |
| 193 | |
| 194 | static void _rtl92s_dm_check_txpowertracking_thermalmeter( |
| 195 | struct ieee80211_hw *hw) |
| 196 | { |
| 197 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 198 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 199 | u8 tx_power_checkcnt = 5; |
| 200 | |
| 201 | /* 2T2R TP issue */ |
| 202 | if (rtlphy->rf_type == RF_2T2R) |
| 203 | return; |
| 204 | |
| 205 | if (!rtlpriv->dm.txpower_tracking) |
| 206 | return; |
| 207 | |
| 208 | if (rtlpriv->dm.txpowercount <= tx_power_checkcnt) { |
| 209 | rtlpriv->dm.txpowercount++; |
| 210 | return; |
| 211 | } |
| 212 | |
Hans Ulli Kroll | 1637c1b | 2015-06-07 13:19:16 +0200 | [diff] [blame] | 213 | if (!rtlpriv->dm.tm_trigger) { |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 214 | rtl_set_rfreg(hw, RF90_PATH_A, RF_T_METER, |
| 215 | RFREG_OFFSET_MASK, 0x60); |
Hans Ulli Kroll | 1637c1b | 2015-06-07 13:19:16 +0200 | [diff] [blame] | 216 | rtlpriv->dm.tm_trigger = 1; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 217 | } else { |
| 218 | _rtl92s_dm_txpowertracking_callback_thermalmeter(hw); |
Hans Ulli Kroll | 1637c1b | 2015-06-07 13:19:16 +0200 | [diff] [blame] | 219 | rtlpriv->dm.tm_trigger = 0; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
| 223 | static void _rtl92s_dm_refresh_rateadaptive_mask(struct ieee80211_hw *hw) |
| 224 | { |
| 225 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 226 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 227 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 228 | struct rate_adaptive *ra = &(rtlpriv->ra); |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 229 | struct ieee80211_sta *sta = NULL; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 230 | u32 low_rssi_thresh = 0; |
| 231 | u32 middle_rssi_thresh = 0; |
| 232 | u32 high_rssi_thresh = 0; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 233 | |
| 234 | if (is_hal_stop(rtlhal)) |
| 235 | return; |
| 236 | |
| 237 | if (!rtlpriv->dm.useramask) |
| 238 | return; |
| 239 | |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 240 | if (hal_get_firmwareversion(rtlpriv) >= 61 && |
| 241 | !rtlpriv->dm.inform_fw_driverctrldm) { |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 242 | rtl92s_phy_set_fw_cmd(hw, FW_CMD_CTRL_DM_BY_DRIVER); |
| 243 | rtlpriv->dm.inform_fw_driverctrldm = true; |
| 244 | } |
| 245 | |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 246 | if ((mac->link_state == MAC80211_LINKED) && |
| 247 | (mac->opmode == NL80211_IFTYPE_STATION)) { |
| 248 | switch (ra->pre_ratr_state) { |
| 249 | case DM_RATR_STA_HIGH: |
| 250 | high_rssi_thresh = 40; |
| 251 | middle_rssi_thresh = 30; |
| 252 | low_rssi_thresh = 20; |
| 253 | break; |
| 254 | case DM_RATR_STA_MIDDLE: |
| 255 | high_rssi_thresh = 44; |
| 256 | middle_rssi_thresh = 30; |
| 257 | low_rssi_thresh = 20; |
| 258 | break; |
| 259 | case DM_RATR_STA_LOW: |
| 260 | high_rssi_thresh = 44; |
| 261 | middle_rssi_thresh = 34; |
| 262 | low_rssi_thresh = 20; |
| 263 | break; |
| 264 | case DM_RATR_STA_ULTRALOW: |
| 265 | high_rssi_thresh = 44; |
| 266 | middle_rssi_thresh = 34; |
| 267 | low_rssi_thresh = 24; |
| 268 | break; |
| 269 | default: |
| 270 | high_rssi_thresh = 44; |
| 271 | middle_rssi_thresh = 34; |
| 272 | low_rssi_thresh = 24; |
| 273 | break; |
| 274 | } |
| 275 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 276 | if (rtlpriv->dm.undec_sm_pwdb > (long)high_rssi_thresh) { |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 277 | ra->ratr_state = DM_RATR_STA_HIGH; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 278 | } else if (rtlpriv->dm.undec_sm_pwdb > |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 279 | (long)middle_rssi_thresh) { |
| 280 | ra->ratr_state = DM_RATR_STA_LOW; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 281 | } else if (rtlpriv->dm.undec_sm_pwdb > |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 282 | (long)low_rssi_thresh) { |
| 283 | ra->ratr_state = DM_RATR_STA_LOW; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 284 | } else { |
| 285 | ra->ratr_state = DM_RATR_STA_ULTRALOW; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | if (ra->pre_ratr_state != ra->ratr_state) { |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 289 | RT_TRACE(rtlpriv, COMP_RATE, DBG_LOUD, |
| 290 | "RSSI = %ld RSSI_LEVEL = %d PreState = %d, CurState = %d\n", |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 291 | rtlpriv->dm.undec_sm_pwdb, ra->ratr_state, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 292 | ra->pre_ratr_state, ra->ratr_state); |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 293 | |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 294 | rcu_read_lock(); |
| 295 | sta = rtl_find_sta(hw, mac->bssid); |
| 296 | if (sta) |
| 297 | rtlpriv->cfg->ops->update_rate_tbl(hw, sta, |
Ping-Ke Shih | 1d22b17 | 2017-09-29 14:47:59 -0500 | [diff] [blame^] | 298 | ra->ratr_state, |
| 299 | true); |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 300 | rcu_read_unlock(); |
| 301 | |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 302 | ra->pre_ratr_state = ra->ratr_state; |
| 303 | } |
| 304 | } |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | static void _rtl92s_dm_switch_baseband_mrc(struct ieee80211_hw *hw) |
| 308 | { |
| 309 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 310 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); |
| 311 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 312 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
| 313 | bool current_mrc; |
| 314 | bool enable_mrc = true; |
| 315 | long tmpentry_maxpwdb = 0; |
| 316 | u8 rssi_a = 0; |
| 317 | u8 rssi_b = 0; |
| 318 | |
| 319 | if (is_hal_stop(rtlhal)) |
| 320 | return; |
| 321 | |
| 322 | if ((rtlphy->rf_type == RF_1T1R) || (rtlphy->rf_type == RF_2T2R)) |
| 323 | return; |
| 324 | |
| 325 | rtlpriv->cfg->ops->get_hw_reg(hw, HW_VAR_MRC, (u8 *)(¤t_mrc)); |
| 326 | |
| 327 | if (mac->link_state >= MAC80211_LINKED) { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 328 | if (rtlpriv->dm.undec_sm_pwdb > tmpentry_maxpwdb) { |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 329 | rssi_a = rtlpriv->stats.rx_rssi_percentage[RF90_PATH_A]; |
| 330 | rssi_b = rtlpriv->stats.rx_rssi_percentage[RF90_PATH_B]; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | /* MRC settings would NOT affect TP on Wireless B mode. */ |
| 335 | if (mac->mode != WIRELESS_MODE_B) { |
| 336 | if ((rssi_a == 0) && (rssi_b == 0)) { |
| 337 | enable_mrc = true; |
| 338 | } else if (rssi_b > 30) { |
| 339 | /* Turn on B-Path */ |
| 340 | enable_mrc = true; |
| 341 | } else if (rssi_b < 5) { |
| 342 | /* Turn off B-path */ |
| 343 | enable_mrc = false; |
| 344 | /* Take care of RSSI differentiation. */ |
| 345 | } else if (rssi_a > 15 && (rssi_a >= rssi_b)) { |
| 346 | if ((rssi_a - rssi_b) > 15) |
| 347 | /* Turn off B-path */ |
| 348 | enable_mrc = false; |
| 349 | else if ((rssi_a - rssi_b) < 10) |
| 350 | /* Turn on B-Path */ |
| 351 | enable_mrc = true; |
| 352 | else |
| 353 | enable_mrc = current_mrc; |
| 354 | } else { |
| 355 | /* Turn on B-Path */ |
| 356 | enable_mrc = true; |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | /* Update MRC settings if needed. */ |
| 361 | if (enable_mrc != current_mrc) |
| 362 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_MRC, |
| 363 | (u8 *)&enable_mrc); |
| 364 | |
| 365 | } |
| 366 | |
| 367 | void rtl92s_dm_init_edca_turbo(struct ieee80211_hw *hw) |
| 368 | { |
| 369 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 370 | |
| 371 | rtlpriv->dm.current_turbo_edca = false; |
| 372 | rtlpriv->dm.is_any_nonbepkts = false; |
| 373 | rtlpriv->dm.is_cur_rdlstate = false; |
| 374 | } |
| 375 | |
| 376 | static void _rtl92s_dm_init_rate_adaptive_mask(struct ieee80211_hw *hw) |
| 377 | { |
| 378 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 379 | struct rate_adaptive *ra = &(rtlpriv->ra); |
| 380 | |
| 381 | ra->ratr_state = DM_RATR_STA_MAX; |
| 382 | ra->pre_ratr_state = DM_RATR_STA_MAX; |
| 383 | |
Larry Finger | 2455c92 | 2013-03-24 22:06:38 -0500 | [diff] [blame] | 384 | if (rtlpriv->dm.dm_type == DM_TYPE_BYDRIVER && |
| 385 | hal_get_firmwareversion(rtlpriv) >= 60) |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 386 | rtlpriv->dm.useramask = true; |
| 387 | else |
| 388 | rtlpriv->dm.useramask = false; |
| 389 | |
| 390 | rtlpriv->dm.useramask = false; |
| 391 | rtlpriv->dm.inform_fw_driverctrldm = false; |
| 392 | } |
| 393 | |
| 394 | static void _rtl92s_dm_init_txpowertracking_thermalmeter( |
| 395 | struct ieee80211_hw *hw) |
| 396 | { |
| 397 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 398 | |
| 399 | rtlpriv->dm.txpower_tracking = true; |
| 400 | rtlpriv->dm.txpowercount = 0; |
| 401 | rtlpriv->dm.txpower_trackinginit = false; |
| 402 | } |
| 403 | |
| 404 | static void _rtl92s_dm_false_alarm_counter_statistics(struct ieee80211_hw *hw) |
| 405 | { |
| 406 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 407 | struct false_alarm_statistics *falsealm_cnt = &(rtlpriv->falsealm_cnt); |
| 408 | u32 ret_value; |
| 409 | |
| 410 | ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER1, MASKDWORD); |
| 411 | falsealm_cnt->cnt_parity_fail = ((ret_value & 0xffff0000) >> 16); |
| 412 | |
| 413 | ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER2, MASKDWORD); |
| 414 | falsealm_cnt->cnt_rate_illegal = (ret_value & 0xffff); |
| 415 | falsealm_cnt->cnt_crc8_fail = ((ret_value & 0xffff0000) >> 16); |
| 416 | ret_value = rtl_get_bbreg(hw, ROFDM_PHYCOUNTER3, MASKDWORD); |
| 417 | falsealm_cnt->cnt_mcs_fail = (ret_value & 0xffff); |
| 418 | |
| 419 | falsealm_cnt->cnt_ofdm_fail = falsealm_cnt->cnt_parity_fail + |
| 420 | falsealm_cnt->cnt_rate_illegal + falsealm_cnt->cnt_crc8_fail + |
| 421 | falsealm_cnt->cnt_mcs_fail; |
| 422 | |
| 423 | /* read CCK false alarm */ |
| 424 | ret_value = rtl_get_bbreg(hw, 0xc64, MASKDWORD); |
| 425 | falsealm_cnt->cnt_cck_fail = (ret_value & 0xffff); |
| 426 | falsealm_cnt->cnt_all = falsealm_cnt->cnt_ofdm_fail + |
| 427 | falsealm_cnt->cnt_cck_fail; |
| 428 | } |
| 429 | |
| 430 | static void rtl92s_backoff_enable_flag(struct ieee80211_hw *hw) |
| 431 | { |
| 432 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 433 | struct dig_t *digtable = &rtlpriv->dm_digtable; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 434 | struct false_alarm_statistics *falsealm_cnt = &(rtlpriv->falsealm_cnt); |
| 435 | |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 436 | if (falsealm_cnt->cnt_all > digtable->fa_highthresh) { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 437 | if ((digtable->back_val - 6) < |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 438 | digtable->backoffval_range_min) |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 439 | digtable->back_val = digtable->backoffval_range_min; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 440 | else |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 441 | digtable->back_val -= 6; |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 442 | } else if (falsealm_cnt->cnt_all < digtable->fa_lowthresh) { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 443 | if ((digtable->back_val + 6) > |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 444 | digtable->backoffval_range_max) |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 445 | digtable->back_val = |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 446 | digtable->backoffval_range_max; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 447 | else |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 448 | digtable->back_val += 6; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
| 452 | static void _rtl92s_dm_initial_gain_sta_beforeconnect(struct ieee80211_hw *hw) |
| 453 | { |
| 454 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 455 | struct dig_t *digtable = &rtlpriv->dm_digtable; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 456 | struct false_alarm_statistics *falsealm_cnt = &(rtlpriv->falsealm_cnt); |
| 457 | static u8 initialized, force_write; |
| 458 | u8 initial_gain = 0; |
| 459 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 460 | if ((digtable->pre_sta_cstate == digtable->cur_sta_cstate) || |
| 461 | (digtable->cur_sta_cstate == DIG_STA_BEFORE_CONNECT)) { |
| 462 | if (digtable->cur_sta_cstate == DIG_STA_BEFORE_CONNECT) { |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 463 | if (rtlpriv->psc.rfpwr_state != ERFON) |
| 464 | return; |
| 465 | |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 466 | if (digtable->backoff_enable_flag) |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 467 | rtl92s_backoff_enable_flag(hw); |
| 468 | else |
Larry Finger | ed0fb7e | 2015-01-06 09:58:12 -0600 | [diff] [blame] | 469 | digtable->back_val = DM_DIG_BACKOFF_MAX; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 470 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 471 | if ((digtable->rssi_val + 10 - digtable->back_val) > |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 472 | digtable->rx_gain_max) |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 473 | digtable->cur_igvalue = |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 474 | digtable->rx_gain_max; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 475 | else if ((digtable->rssi_val + 10 - digtable->back_val) |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 476 | < digtable->rx_gain_min) |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 477 | digtable->cur_igvalue = |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 478 | digtable->rx_gain_min; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 479 | else |
Daniel Stamer | dac6797 | 2012-11-29 17:09:26 +0100 | [diff] [blame] | 480 | digtable->cur_igvalue = digtable->rssi_val + 10 |
| 481 | - digtable->back_val; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 482 | |
| 483 | if (falsealm_cnt->cnt_all > 10000) |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 484 | digtable->cur_igvalue = |
| 485 | (digtable->cur_igvalue > 0x33) ? |
| 486 | digtable->cur_igvalue : 0x33; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 487 | |
| 488 | if (falsealm_cnt->cnt_all > 16000) |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 489 | digtable->cur_igvalue = |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 490 | digtable->rx_gain_max; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 491 | /* connected -> connected or disconnected -> disconnected */ |
| 492 | } else { |
| 493 | /* Firmware control DIG, do nothing in driver dm */ |
| 494 | return; |
| 495 | } |
| 496 | /* disconnected -> connected or connected -> |
| 497 | * disconnected or beforeconnect->(dis)connected */ |
| 498 | } else { |
| 499 | /* Enable FW DIG */ |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 500 | digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 501 | rtl92s_phy_set_fw_cmd(hw, FW_CMD_DIG_ENABLE); |
| 502 | |
Larry Finger | ed0fb7e | 2015-01-06 09:58:12 -0600 | [diff] [blame] | 503 | digtable->back_val = DM_DIG_BACKOFF_MAX; |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 504 | digtable->cur_igvalue = rtlpriv->phy.default_initialgain[0]; |
| 505 | digtable->pre_igvalue = 0; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 506 | return; |
| 507 | } |
| 508 | |
| 509 | /* Forced writing to prevent from fw-dig overwriting. */ |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 510 | if (digtable->pre_igvalue != rtl_get_bbreg(hw, ROFDM0_XAAGCCORE1, |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 511 | MASKBYTE0)) |
| 512 | force_write = 1; |
| 513 | |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 514 | if ((digtable->pre_igvalue != digtable->cur_igvalue) || |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 515 | !initialized || force_write) { |
| 516 | /* Disable FW DIG */ |
| 517 | rtl92s_phy_set_fw_cmd(hw, FW_CMD_DIG_DISABLE); |
| 518 | |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 519 | initial_gain = (u8)digtable->cur_igvalue; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 520 | |
| 521 | /* Set initial gain. */ |
| 522 | rtl_set_bbreg(hw, ROFDM0_XAAGCCORE1, MASKBYTE0, initial_gain); |
| 523 | rtl_set_bbreg(hw, ROFDM0_XBAGCCORE1, MASKBYTE0, initial_gain); |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 524 | digtable->pre_igvalue = digtable->cur_igvalue; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 525 | initialized = 1; |
| 526 | force_write = 0; |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | static void _rtl92s_dm_ctrl_initgain_bytwoport(struct ieee80211_hw *hw) |
| 531 | { |
| 532 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Daniel Stamer | dac6797 | 2012-11-29 17:09:26 +0100 | [diff] [blame] | 533 | struct dig_t *dig = &rtlpriv->dm_digtable; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 534 | |
| 535 | if (rtlpriv->mac80211.act_scanning) |
| 536 | return; |
| 537 | |
| 538 | /* Decide the current status and if modify initial gain or not */ |
| 539 | if (rtlpriv->mac80211.link_state >= MAC80211_LINKED || |
| 540 | rtlpriv->mac80211.opmode == NL80211_IFTYPE_ADHOC) |
Daniel Stamer | dac6797 | 2012-11-29 17:09:26 +0100 | [diff] [blame] | 541 | dig->cur_sta_cstate = DIG_STA_CONNECT; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 542 | else |
Daniel Stamer | dac6797 | 2012-11-29 17:09:26 +0100 | [diff] [blame] | 543 | dig->cur_sta_cstate = DIG_STA_DISCONNECT; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 544 | |
Daniel Stamer | dac6797 | 2012-11-29 17:09:26 +0100 | [diff] [blame] | 545 | dig->rssi_val = rtlpriv->dm.undec_sm_pwdb; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 546 | |
| 547 | /* Change dig mode to rssi */ |
Daniel Stamer | dac6797 | 2012-11-29 17:09:26 +0100 | [diff] [blame] | 548 | if (dig->cur_sta_cstate != DIG_STA_DISCONNECT) { |
| 549 | if (dig->dig_twoport_algorithm == |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 550 | DIG_TWO_PORT_ALGO_FALSE_ALARM) { |
Daniel Stamer | dac6797 | 2012-11-29 17:09:26 +0100 | [diff] [blame] | 551 | dig->dig_twoport_algorithm = DIG_TWO_PORT_ALGO_RSSI; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 552 | rtl92s_phy_set_fw_cmd(hw, FW_CMD_DIG_MODE_SS); |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | _rtl92s_dm_false_alarm_counter_statistics(hw); |
| 557 | _rtl92s_dm_initial_gain_sta_beforeconnect(hw); |
| 558 | |
Daniel Stamer | dac6797 | 2012-11-29 17:09:26 +0100 | [diff] [blame] | 559 | dig->pre_sta_cstate = dig->cur_sta_cstate; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | static void _rtl92s_dm_ctrl_initgain_byrssi(struct ieee80211_hw *hw) |
| 563 | { |
| 564 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 565 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 566 | struct dig_t *digtable = &rtlpriv->dm_digtable; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 567 | |
| 568 | /* 2T2R TP issue */ |
| 569 | if (rtlphy->rf_type == RF_2T2R) |
| 570 | return; |
| 571 | |
| 572 | if (!rtlpriv->dm.dm_initialgain_enable) |
| 573 | return; |
| 574 | |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 575 | if (digtable->dig_enable_flag == false) |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 576 | return; |
| 577 | |
| 578 | _rtl92s_dm_ctrl_initgain_bytwoport(hw); |
| 579 | } |
| 580 | |
| 581 | static void _rtl92s_dm_dynamic_txpower(struct ieee80211_hw *hw) |
| 582 | { |
| 583 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 584 | struct rtl_phy *rtlphy = &(rtlpriv->phy); |
| 585 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 586 | long undec_sm_pwdb; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 587 | long txpwr_threshold_lv1, txpwr_threshold_lv2; |
| 588 | |
| 589 | /* 2T2R TP issue */ |
| 590 | if (rtlphy->rf_type == RF_2T2R) |
| 591 | return; |
| 592 | |
| 593 | if (!rtlpriv->dm.dynamic_txpower_enable || |
| 594 | rtlpriv->dm.dm_flag & HAL_DM_HIPWR_DISABLE) { |
| 595 | rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL; |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | if ((mac->link_state < MAC80211_LINKED) && |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 600 | (rtlpriv->dm.entry_min_undec_sm_pwdb == 0)) { |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 601 | RT_TRACE(rtlpriv, COMP_POWER, DBG_TRACE, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 602 | "Not connected to any\n"); |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 603 | |
| 604 | rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL; |
| 605 | |
| 606 | rtlpriv->dm.last_dtp_lvl = TX_HIGHPWR_LEVEL_NORMAL; |
| 607 | return; |
| 608 | } |
| 609 | |
| 610 | if (mac->link_state >= MAC80211_LINKED) { |
| 611 | if (mac->opmode == NL80211_IFTYPE_ADHOC) { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 612 | undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 613 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 614 | "AP Client PWDB = 0x%lx\n", |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 615 | undec_sm_pwdb); |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 616 | } else { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 617 | undec_sm_pwdb = rtlpriv->dm.undec_sm_pwdb; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 618 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 619 | "STA Default Port PWDB = 0x%lx\n", |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 620 | undec_sm_pwdb); |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 621 | } |
| 622 | } else { |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 623 | undec_sm_pwdb = rtlpriv->dm.entry_min_undec_sm_pwdb; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 624 | |
| 625 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, |
Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 626 | "AP Ext Port PWDB = 0x%lx\n", |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 627 | undec_sm_pwdb); |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | txpwr_threshold_lv2 = TX_POWER_NEAR_FIELD_THRESH_LVL2; |
| 631 | txpwr_threshold_lv1 = TX_POWER_NEAR_FIELD_THRESH_LVL1; |
| 632 | |
| 633 | if (rtl_get_bbreg(hw, 0xc90, MASKBYTE0) == 1) |
| 634 | rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 635 | else if (undec_sm_pwdb >= txpwr_threshold_lv2) |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 636 | rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL2; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 637 | else if ((undec_sm_pwdb < (txpwr_threshold_lv2 - 3)) && |
| 638 | (undec_sm_pwdb >= txpwr_threshold_lv1)) |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 639 | rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL1; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 640 | else if (undec_sm_pwdb < (txpwr_threshold_lv1 - 3)) |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 641 | rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL; |
| 642 | |
| 643 | if ((rtlpriv->dm.dynamic_txhighpower_lvl != rtlpriv->dm.last_dtp_lvl)) |
| 644 | rtl92s_phy_set_txpower(hw, rtlphy->current_channel); |
| 645 | |
| 646 | rtlpriv->dm.last_dtp_lvl = rtlpriv->dm.dynamic_txhighpower_lvl; |
| 647 | } |
| 648 | |
| 649 | static void _rtl92s_dm_init_dig(struct ieee80211_hw *hw) |
| 650 | { |
| 651 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 652 | struct dig_t *digtable = &rtlpriv->dm_digtable; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 653 | |
| 654 | /* Disable DIG scheme now.*/ |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 655 | digtable->dig_enable_flag = true; |
| 656 | digtable->backoff_enable_flag = true; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 657 | |
| 658 | if ((rtlpriv->dm.dm_type == DM_TYPE_BYDRIVER) && |
| 659 | (hal_get_firmwareversion(rtlpriv) >= 0x3c)) |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 660 | digtable->dig_algorithm = DIG_ALGO_BY_TOW_PORT; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 661 | else |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 662 | digtable->dig_algorithm = |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 663 | DIG_ALGO_BEFORE_CONNECT_BY_RSSI_AND_ALARM; |
| 664 | |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 665 | digtable->dig_twoport_algorithm = DIG_TWO_PORT_ALGO_RSSI; |
| 666 | digtable->dig_ext_port_stage = DIG_EXT_PORT_STAGE_MAX; |
| 667 | /* off=by real rssi value, on=by digtable->rssi_val for new dig */ |
| 668 | digtable->dig_dbgmode = DM_DBG_OFF; |
| 669 | digtable->dig_slgorithm_switch = 0; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 670 | |
| 671 | /* 2007/10/04 MH Define init gain threshol. */ |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 672 | digtable->dig_state = DM_STA_DIG_MAX; |
| 673 | digtable->dig_highpwrstate = DM_STA_DIG_MAX; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 674 | |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 675 | digtable->cur_sta_cstate = DIG_STA_DISCONNECT; |
| 676 | digtable->pre_sta_cstate = DIG_STA_DISCONNECT; |
| 677 | digtable->cur_ap_cstate = DIG_AP_DISCONNECT; |
| 678 | digtable->pre_ap_cstate = DIG_AP_DISCONNECT; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 679 | |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 680 | digtable->rssi_lowthresh = DM_DIG_THRESH_LOW; |
| 681 | digtable->rssi_highthresh = DM_DIG_THRESH_HIGH; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 682 | |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 683 | digtable->fa_lowthresh = DM_FALSEALARM_THRESH_LOW; |
| 684 | digtable->fa_highthresh = DM_FALSEALARM_THRESH_HIGH; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 685 | |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 686 | digtable->rssi_highpower_lowthresh = DM_DIG_HIGH_PWR_THRESH_LOW; |
| 687 | digtable->rssi_highpower_highthresh = DM_DIG_HIGH_PWR_THRESH_HIGH; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 688 | |
| 689 | /* for dig debug rssi value */ |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 690 | digtable->rssi_val = 50; |
Larry Finger | ed0fb7e | 2015-01-06 09:58:12 -0600 | [diff] [blame] | 691 | digtable->back_val = DM_DIG_BACKOFF_MAX; |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 692 | digtable->rx_gain_max = DM_DIG_MAX; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 693 | |
Larry Finger | e6deaf8 | 2013-03-24 22:06:55 -0500 | [diff] [blame] | 694 | digtable->rx_gain_min = DM_DIG_MIN; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 695 | |
Larry Finger | e060275 | 2012-04-19 16:32:44 -0500 | [diff] [blame] | 696 | digtable->backoffval_range_max = DM_DIG_BACKOFF_MAX; |
| 697 | digtable->backoffval_range_min = DM_DIG_BACKOFF_MIN; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | static void _rtl92s_dm_init_dynamic_txpower(struct ieee80211_hw *hw) |
| 701 | { |
| 702 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 703 | |
| 704 | if ((hal_get_firmwareversion(rtlpriv) >= 60) && |
| 705 | (rtlpriv->dm.dm_type == DM_TYPE_BYDRIVER)) |
| 706 | rtlpriv->dm.dynamic_txpower_enable = true; |
| 707 | else |
| 708 | rtlpriv->dm.dynamic_txpower_enable = false; |
| 709 | |
| 710 | rtlpriv->dm.last_dtp_lvl = TX_HIGHPWR_LEVEL_NORMAL; |
| 711 | rtlpriv->dm.dynamic_txhighpower_lvl = TX_HIGHPWR_LEVEL_NORMAL; |
| 712 | } |
| 713 | |
| 714 | void rtl92s_dm_init(struct ieee80211_hw *hw) |
| 715 | { |
| 716 | struct rtl_priv *rtlpriv = rtl_priv(hw); |
| 717 | |
| 718 | rtlpriv->dm.dm_type = DM_TYPE_BYDRIVER; |
Larry Finger | da17fcf | 2012-10-25 13:46:31 -0500 | [diff] [blame] | 719 | rtlpriv->dm.undec_sm_pwdb = -1; |
Chaoming Li | 9fe255e | 2011-05-03 09:47:55 -0500 | [diff] [blame] | 720 | |
| 721 | _rtl92s_dm_init_dynamic_txpower(hw); |
| 722 | rtl92s_dm_init_edca_turbo(hw); |
| 723 | _rtl92s_dm_init_rate_adaptive_mask(hw); |
| 724 | _rtl92s_dm_init_txpowertracking_thermalmeter(hw); |
| 725 | _rtl92s_dm_init_dig(hw); |
| 726 | |
| 727 | rtl_write_dword(rtlpriv, WFM5, FW_CCA_CHK_ENABLE); |
| 728 | } |
| 729 | |
| 730 | void rtl92s_dm_watchdog(struct ieee80211_hw *hw) |
| 731 | { |
| 732 | _rtl92s_dm_check_edca_turbo(hw); |
| 733 | _rtl92s_dm_check_txpowertracking_thermalmeter(hw); |
| 734 | _rtl92s_dm_ctrl_initgain_byrssi(hw); |
| 735 | _rtl92s_dm_dynamic_txpower(hw); |
| 736 | _rtl92s_dm_refresh_rateadaptive_mask(hw); |
| 737 | _rtl92s_dm_switch_baseband_mrc(hw); |
| 738 | } |
| 739 | |