1 /******************************************************************************
3 * Copyright(c) 2009-2012 Realtek Corporation.
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.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * wlanfae <wlanfae@realtek.com>
23 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
24 * Hsinchu 300, Taiwan.
26 * Larry Finger <Larry.Finger@lwfinger.net>
28 *****************************************************************************/
38 static const u32 edca_setting_dl
[PEER_MAX
] = {
39 0xa44f, /* 0 UNKNOWN */
40 0x5ea44f, /* 1 REALTEK_90 */
41 0x5ea44f, /* 2 REALTEK_92SE */
49 static const u32 edca_setting_dl_gmode
[PEER_MAX
] = {
50 0x4322, /* 0 UNKNOWN */
51 0xa44f, /* 1 REALTEK_90 */
52 0x5ea44f, /* 2 REALTEK_92SE */
57 0x5ea44f, /* 7 MARV */
60 static const u32 edca_setting_ul
[PEER_MAX
] = {
61 0x5e4322, /* 0 UNKNOWN */
62 0xa44f, /* 1 REALTEK_90 */
63 0x5ea44f, /* 2 REALTEK_92SE */
64 0x5ea322, /* 3 BROAD */
67 0x3ea44f, /* 6 CISCO */
68 0x5ea44f, /* 7 MARV */
71 static void _rtl92s_dm_check_edca_turbo(struct ieee80211_hw
*hw
)
73 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
74 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
76 static u64 last_txok_cnt
;
77 static u64 last_rxok_cnt
;
81 u32 edca_be_ul
= edca_setting_ul
[mac
->vendor
];
82 u32 edca_be_dl
= edca_setting_dl
[mac
->vendor
];
83 u32 edca_gmode
= edca_setting_dl_gmode
[mac
->vendor
];
85 if (mac
->link_state
!= MAC80211_LINKED
) {
86 rtlpriv
->dm
.current_turbo_edca
= false;
87 goto dm_checkedcaturbo_exit
;
90 if ((!rtlpriv
->dm
.is_any_nonbepkts
) &&
91 (!rtlpriv
->dm
.disable_framebursting
)) {
92 cur_txok_cnt
= rtlpriv
->stats
.txbytesunicast
- last_txok_cnt
;
93 cur_rxok_cnt
= rtlpriv
->stats
.rxbytesunicast
- last_rxok_cnt
;
95 if (rtlpriv
->phy
.rf_type
== RF_1T2R
) {
96 if (cur_txok_cnt
> 4 * cur_rxok_cnt
) {
97 /* Uplink TP is present. */
98 if (rtlpriv
->dm
.is_cur_rdlstate
||
99 !rtlpriv
->dm
.current_turbo_edca
) {
100 rtl_write_dword(rtlpriv
, EDCAPARA_BE
,
102 rtlpriv
->dm
.is_cur_rdlstate
= false;
104 } else {/* Balance TP is present. */
105 if (!rtlpriv
->dm
.is_cur_rdlstate
||
106 !rtlpriv
->dm
.current_turbo_edca
) {
107 if (mac
->mode
== WIRELESS_MODE_G
||
108 mac
->mode
== WIRELESS_MODE_B
)
109 rtl_write_dword(rtlpriv
,
113 rtl_write_dword(rtlpriv
,
116 rtlpriv
->dm
.is_cur_rdlstate
= true;
119 rtlpriv
->dm
.current_turbo_edca
= true;
121 if (cur_rxok_cnt
> 4 * cur_txok_cnt
) {
122 if (!rtlpriv
->dm
.is_cur_rdlstate
||
123 !rtlpriv
->dm
.current_turbo_edca
) {
124 if (mac
->mode
== WIRELESS_MODE_G
||
125 mac
->mode
== WIRELESS_MODE_B
)
126 rtl_write_dword(rtlpriv
,
130 rtl_write_dword(rtlpriv
,
133 rtlpriv
->dm
.is_cur_rdlstate
= true;
136 if (rtlpriv
->dm
.is_cur_rdlstate
||
137 !rtlpriv
->dm
.current_turbo_edca
) {
138 rtl_write_dword(rtlpriv
, EDCAPARA_BE
,
140 rtlpriv
->dm
.is_cur_rdlstate
= false;
143 rtlpriv
->dm
.current_turbo_edca
= true;
146 if (rtlpriv
->dm
.current_turbo_edca
) {
148 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AC_PARAM
,
150 rtlpriv
->dm
.current_turbo_edca
= false;
154 dm_checkedcaturbo_exit
:
155 rtlpriv
->dm
.is_any_nonbepkts
= false;
156 last_txok_cnt
= rtlpriv
->stats
.txbytesunicast
;
157 last_rxok_cnt
= rtlpriv
->stats
.rxbytesunicast
;
160 static void _rtl92s_dm_txpowertracking_callback_thermalmeter(
161 struct ieee80211_hw
*hw
)
163 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
164 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
168 rtlpriv
->dm
.txpower_trackinginit
= true;
170 thermalvalue
= (u8
)rtl_get_rfreg(hw
, RF90_PATH_A
, RF_T_METER
, 0x1f);
172 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
173 "Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermal meter 0x%x\n",
175 rtlpriv
->dm
.thermalvalue
, rtlefuse
->eeprom_thermalmeter
);
178 rtlpriv
->dm
.thermalvalue
= thermalvalue
;
179 if (hal_get_firmwareversion(rtlpriv
) >= 0x35) {
180 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_TXPWR_TRACK_THERMAL
);
182 fw_cmd
= (FW_TXPWR_TRACK_THERMAL
|
183 (rtlpriv
->efuse
.thermalmeter
[0] << 8) |
184 (thermalvalue
<< 16));
186 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
187 "Write to FW Thermal Val = 0x%x\n", fw_cmd
);
189 rtl_write_dword(rtlpriv
, WFM5
, fw_cmd
);
190 rtl92s_phy_chk_fwcmd_iodone(hw
);
194 rtlpriv
->dm
.txpowercount
= 0;
197 static void _rtl92s_dm_check_txpowertracking_thermalmeter(
198 struct ieee80211_hw
*hw
)
200 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
201 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
202 static u8 tm_trigger
;
203 u8 tx_power_checkcnt
= 5;
206 if (rtlphy
->rf_type
== RF_2T2R
)
209 if (!rtlpriv
->dm
.txpower_tracking
)
212 if (rtlpriv
->dm
.txpowercount
<= tx_power_checkcnt
) {
213 rtlpriv
->dm
.txpowercount
++;
218 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_T_METER
,
219 RFREG_OFFSET_MASK
, 0x60);
222 _rtl92s_dm_txpowertracking_callback_thermalmeter(hw
);
227 static void _rtl92s_dm_refresh_rateadaptive_mask(struct ieee80211_hw
*hw
)
229 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
230 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
231 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
232 struct rate_adaptive
*ra
= &(rtlpriv
->ra
);
233 struct ieee80211_sta
*sta
= NULL
;
234 u32 low_rssi_thresh
= 0;
235 u32 middle_rssi_thresh
= 0;
236 u32 high_rssi_thresh
= 0;
238 if (is_hal_stop(rtlhal
))
241 if (!rtlpriv
->dm
.useramask
)
244 if (hal_get_firmwareversion(rtlpriv
) >= 61 &&
245 !rtlpriv
->dm
.inform_fw_driverctrldm
) {
246 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_CTRL_DM_BY_DRIVER
);
247 rtlpriv
->dm
.inform_fw_driverctrldm
= true;
250 if ((mac
->link_state
== MAC80211_LINKED
) &&
251 (mac
->opmode
== NL80211_IFTYPE_STATION
)) {
252 switch (ra
->pre_ratr_state
) {
253 case DM_RATR_STA_HIGH
:
254 high_rssi_thresh
= 40;
255 middle_rssi_thresh
= 30;
256 low_rssi_thresh
= 20;
258 case DM_RATR_STA_MIDDLE
:
259 high_rssi_thresh
= 44;
260 middle_rssi_thresh
= 30;
261 low_rssi_thresh
= 20;
263 case DM_RATR_STA_LOW
:
264 high_rssi_thresh
= 44;
265 middle_rssi_thresh
= 34;
266 low_rssi_thresh
= 20;
268 case DM_RATR_STA_ULTRALOW
:
269 high_rssi_thresh
= 44;
270 middle_rssi_thresh
= 34;
271 low_rssi_thresh
= 24;
274 high_rssi_thresh
= 44;
275 middle_rssi_thresh
= 34;
276 low_rssi_thresh
= 24;
280 if (rtlpriv
->dm
.undec_sm_pwdb
> (long)high_rssi_thresh
) {
281 ra
->ratr_state
= DM_RATR_STA_HIGH
;
282 } else if (rtlpriv
->dm
.undec_sm_pwdb
>
283 (long)middle_rssi_thresh
) {
284 ra
->ratr_state
= DM_RATR_STA_LOW
;
285 } else if (rtlpriv
->dm
.undec_sm_pwdb
>
286 (long)low_rssi_thresh
) {
287 ra
->ratr_state
= DM_RATR_STA_LOW
;
289 ra
->ratr_state
= DM_RATR_STA_ULTRALOW
;
292 if (ra
->pre_ratr_state
!= ra
->ratr_state
) {
293 RT_TRACE(rtlpriv
, COMP_RATE
, DBG_LOUD
,
294 "RSSI = %ld RSSI_LEVEL = %d PreState = %d, CurState = %d\n",
295 rtlpriv
->dm
.undec_sm_pwdb
, ra
->ratr_state
,
296 ra
->pre_ratr_state
, ra
->ratr_state
);
299 sta
= rtl_find_sta(hw
, mac
->bssid
);
301 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
,
305 ra
->pre_ratr_state
= ra
->ratr_state
;
310 static void _rtl92s_dm_switch_baseband_mrc(struct ieee80211_hw
*hw
)
312 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
313 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
314 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
315 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
317 bool enable_mrc
= true;
318 long tmpentry_maxpwdb
= 0;
322 if (is_hal_stop(rtlhal
))
325 if ((rtlphy
->rf_type
== RF_1T1R
) || (rtlphy
->rf_type
== RF_2T2R
))
328 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_MRC
, (u8
*)(¤t_mrc
));
330 if (mac
->link_state
>= MAC80211_LINKED
) {
331 if (rtlpriv
->dm
.undec_sm_pwdb
> tmpentry_maxpwdb
) {
332 rssi_a
= rtlpriv
->stats
.rx_rssi_percentage
[RF90_PATH_A
];
333 rssi_b
= rtlpriv
->stats
.rx_rssi_percentage
[RF90_PATH_B
];
337 /* MRC settings would NOT affect TP on Wireless B mode. */
338 if (mac
->mode
!= WIRELESS_MODE_B
) {
339 if ((rssi_a
== 0) && (rssi_b
== 0)) {
341 } else if (rssi_b
> 30) {
344 } else if (rssi_b
< 5) {
345 /* Turn off B-path */
347 /* Take care of RSSI differentiation. */
348 } else if (rssi_a
> 15 && (rssi_a
>= rssi_b
)) {
349 if ((rssi_a
- rssi_b
) > 15)
350 /* Turn off B-path */
352 else if ((rssi_a
- rssi_b
) < 10)
356 enable_mrc
= current_mrc
;
363 /* Update MRC settings if needed. */
364 if (enable_mrc
!= current_mrc
)
365 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_MRC
,
370 void rtl92s_dm_init_edca_turbo(struct ieee80211_hw
*hw
)
372 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
374 rtlpriv
->dm
.current_turbo_edca
= false;
375 rtlpriv
->dm
.is_any_nonbepkts
= false;
376 rtlpriv
->dm
.is_cur_rdlstate
= false;
379 static void _rtl92s_dm_init_rate_adaptive_mask(struct ieee80211_hw
*hw
)
381 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
382 struct rate_adaptive
*ra
= &(rtlpriv
->ra
);
384 ra
->ratr_state
= DM_RATR_STA_MAX
;
385 ra
->pre_ratr_state
= DM_RATR_STA_MAX
;
387 if (rtlpriv
->dm
.dm_type
== DM_TYPE_BYDRIVER
&&
388 hal_get_firmwareversion(rtlpriv
) >= 60)
389 rtlpriv
->dm
.useramask
= true;
391 rtlpriv
->dm
.useramask
= false;
393 rtlpriv
->dm
.useramask
= false;
394 rtlpriv
->dm
.inform_fw_driverctrldm
= false;
397 static void _rtl92s_dm_init_txpowertracking_thermalmeter(
398 struct ieee80211_hw
*hw
)
400 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
402 rtlpriv
->dm
.txpower_tracking
= true;
403 rtlpriv
->dm
.txpowercount
= 0;
404 rtlpriv
->dm
.txpower_trackinginit
= false;
407 static void _rtl92s_dm_false_alarm_counter_statistics(struct ieee80211_hw
*hw
)
409 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
410 struct false_alarm_statistics
*falsealm_cnt
= &(rtlpriv
->falsealm_cnt
);
413 ret_value
= rtl_get_bbreg(hw
, ROFDM_PHYCOUNTER1
, MASKDWORD
);
414 falsealm_cnt
->cnt_parity_fail
= ((ret_value
& 0xffff0000) >> 16);
416 ret_value
= rtl_get_bbreg(hw
, ROFDM_PHYCOUNTER2
, MASKDWORD
);
417 falsealm_cnt
->cnt_rate_illegal
= (ret_value
& 0xffff);
418 falsealm_cnt
->cnt_crc8_fail
= ((ret_value
& 0xffff0000) >> 16);
419 ret_value
= rtl_get_bbreg(hw
, ROFDM_PHYCOUNTER3
, MASKDWORD
);
420 falsealm_cnt
->cnt_mcs_fail
= (ret_value
& 0xffff);
422 falsealm_cnt
->cnt_ofdm_fail
= falsealm_cnt
->cnt_parity_fail
+
423 falsealm_cnt
->cnt_rate_illegal
+ falsealm_cnt
->cnt_crc8_fail
+
424 falsealm_cnt
->cnt_mcs_fail
;
426 /* read CCK false alarm */
427 ret_value
= rtl_get_bbreg(hw
, 0xc64, MASKDWORD
);
428 falsealm_cnt
->cnt_cck_fail
= (ret_value
& 0xffff);
429 falsealm_cnt
->cnt_all
= falsealm_cnt
->cnt_ofdm_fail
+
430 falsealm_cnt
->cnt_cck_fail
;
433 static void rtl92s_backoff_enable_flag(struct ieee80211_hw
*hw
)
435 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
436 struct dig_t
*digtable
= &rtlpriv
->dm_digtable
;
437 struct false_alarm_statistics
*falsealm_cnt
= &(rtlpriv
->falsealm_cnt
);
439 if (falsealm_cnt
->cnt_all
> digtable
->fa_highthresh
) {
440 if ((digtable
->back_val
- 6) <
441 digtable
->backoffval_range_min
)
442 digtable
->back_val
= digtable
->backoffval_range_min
;
444 digtable
->back_val
-= 6;
445 } else if (falsealm_cnt
->cnt_all
< digtable
->fa_lowthresh
) {
446 if ((digtable
->back_val
+ 6) >
447 digtable
->backoffval_range_max
)
449 digtable
->backoffval_range_max
;
451 digtable
->back_val
+= 6;
455 static void _rtl92s_dm_initial_gain_sta_beforeconnect(struct ieee80211_hw
*hw
)
457 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
458 struct dig_t
*digtable
= &rtlpriv
->dm_digtable
;
459 struct false_alarm_statistics
*falsealm_cnt
= &(rtlpriv
->falsealm_cnt
);
460 static u8 initialized
, force_write
;
463 if ((digtable
->pre_sta_cstate
== digtable
->cur_sta_cstate
) ||
464 (digtable
->cur_sta_cstate
== DIG_STA_BEFORE_CONNECT
)) {
465 if (digtable
->cur_sta_cstate
== DIG_STA_BEFORE_CONNECT
) {
466 if (rtlpriv
->psc
.rfpwr_state
!= ERFON
)
469 if (digtable
->backoff_enable_flag
)
470 rtl92s_backoff_enable_flag(hw
);
472 digtable
->back_val
= DM_DIG_BACKOFF
;
474 if ((digtable
->rssi_val
+ 10 - digtable
->back_val
) >
475 digtable
->rx_gain_max
)
476 digtable
->cur_igvalue
=
477 digtable
->rx_gain_max
;
478 else if ((digtable
->rssi_val
+ 10 - digtable
->back_val
)
479 < digtable
->rx_gain_min
)
480 digtable
->cur_igvalue
=
481 digtable
->rx_gain_min
;
483 digtable
->cur_igvalue
= digtable
->rssi_val
+ 10
484 - digtable
->back_val
;
486 if (falsealm_cnt
->cnt_all
> 10000)
487 digtable
->cur_igvalue
=
488 (digtable
->cur_igvalue
> 0x33) ?
489 digtable
->cur_igvalue
: 0x33;
491 if (falsealm_cnt
->cnt_all
> 16000)
492 digtable
->cur_igvalue
=
493 digtable
->rx_gain_max
;
494 /* connected -> connected or disconnected -> disconnected */
496 /* Firmware control DIG, do nothing in driver dm */
499 /* disconnected -> connected or connected ->
500 * disconnected or beforeconnect->(dis)connected */
503 digtable
->dig_ext_port_stage
= DIG_EXT_PORT_STAGE_MAX
;
504 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_DIG_ENABLE
);
506 digtable
->back_val
= DM_DIG_BACKOFF
;
507 digtable
->cur_igvalue
= rtlpriv
->phy
.default_initialgain
[0];
508 digtable
->pre_igvalue
= 0;
512 /* Forced writing to prevent from fw-dig overwriting. */
513 if (digtable
->pre_igvalue
!= rtl_get_bbreg(hw
, ROFDM0_XAAGCCORE1
,
517 if ((digtable
->pre_igvalue
!= digtable
->cur_igvalue
) ||
518 !initialized
|| force_write
) {
520 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_DIG_DISABLE
);
522 initial_gain
= (u8
)digtable
->cur_igvalue
;
524 /* Set initial gain. */
525 rtl_set_bbreg(hw
, ROFDM0_XAAGCCORE1
, MASKBYTE0
, initial_gain
);
526 rtl_set_bbreg(hw
, ROFDM0_XBAGCCORE1
, MASKBYTE0
, initial_gain
);
527 digtable
->pre_igvalue
= digtable
->cur_igvalue
;
533 static void _rtl92s_dm_ctrl_initgain_bytwoport(struct ieee80211_hw
*hw
)
535 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
536 struct dig_t
*dig
= &rtlpriv
->dm_digtable
;
538 if (rtlpriv
->mac80211
.act_scanning
)
541 /* Decide the current status and if modify initial gain or not */
542 if (rtlpriv
->mac80211
.link_state
>= MAC80211_LINKED
||
543 rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_ADHOC
)
544 dig
->cur_sta_cstate
= DIG_STA_CONNECT
;
546 dig
->cur_sta_cstate
= DIG_STA_DISCONNECT
;
548 dig
->rssi_val
= rtlpriv
->dm
.undec_sm_pwdb
;
550 /* Change dig mode to rssi */
551 if (dig
->cur_sta_cstate
!= DIG_STA_DISCONNECT
) {
552 if (dig
->dig_twoport_algorithm
==
553 DIG_TWO_PORT_ALGO_FALSE_ALARM
) {
554 dig
->dig_twoport_algorithm
= DIG_TWO_PORT_ALGO_RSSI
;
555 rtl92s_phy_set_fw_cmd(hw
, FW_CMD_DIG_MODE_SS
);
559 _rtl92s_dm_false_alarm_counter_statistics(hw
);
560 _rtl92s_dm_initial_gain_sta_beforeconnect(hw
);
562 dig
->pre_sta_cstate
= dig
->cur_sta_cstate
;
565 static void _rtl92s_dm_ctrl_initgain_byrssi(struct ieee80211_hw
*hw
)
567 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
568 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
569 struct dig_t
*digtable
= &rtlpriv
->dm_digtable
;
572 if (rtlphy
->rf_type
== RF_2T2R
)
575 if (!rtlpriv
->dm
.dm_initialgain_enable
)
578 if (digtable
->dig_enable_flag
== false)
581 _rtl92s_dm_ctrl_initgain_bytwoport(hw
);
584 static void _rtl92s_dm_dynamic_txpower(struct ieee80211_hw
*hw
)
586 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
587 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
588 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
590 long txpwr_threshold_lv1
, txpwr_threshold_lv2
;
593 if (rtlphy
->rf_type
== RF_2T2R
)
596 if (!rtlpriv
->dm
.dynamic_txpower_enable
||
597 rtlpriv
->dm
.dm_flag
& HAL_DM_HIPWR_DISABLE
) {
598 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TX_HIGHPWR_LEVEL_NORMAL
;
602 if ((mac
->link_state
< MAC80211_LINKED
) &&
603 (rtlpriv
->dm
.entry_min_undec_sm_pwdb
== 0)) {
604 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
605 "Not connected to any\n");
607 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TX_HIGHPWR_LEVEL_NORMAL
;
609 rtlpriv
->dm
.last_dtp_lvl
= TX_HIGHPWR_LEVEL_NORMAL
;
613 if (mac
->link_state
>= MAC80211_LINKED
) {
614 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
615 undec_sm_pwdb
= rtlpriv
->dm
.entry_min_undec_sm_pwdb
;
616 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
617 "AP Client PWDB = 0x%lx\n",
620 undec_sm_pwdb
= rtlpriv
->dm
.undec_sm_pwdb
;
621 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
622 "STA Default Port PWDB = 0x%lx\n",
626 undec_sm_pwdb
= rtlpriv
->dm
.entry_min_undec_sm_pwdb
;
628 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
629 "AP Ext Port PWDB = 0x%lx\n",
633 txpwr_threshold_lv2
= TX_POWER_NEAR_FIELD_THRESH_LVL2
;
634 txpwr_threshold_lv1
= TX_POWER_NEAR_FIELD_THRESH_LVL1
;
636 if (rtl_get_bbreg(hw
, 0xc90, MASKBYTE0
) == 1)
637 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TX_HIGHPWR_LEVEL_NORMAL
;
638 else if (undec_sm_pwdb
>= txpwr_threshold_lv2
)
639 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TX_HIGHPWR_LEVEL_NORMAL2
;
640 else if ((undec_sm_pwdb
< (txpwr_threshold_lv2
- 3)) &&
641 (undec_sm_pwdb
>= txpwr_threshold_lv1
))
642 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TX_HIGHPWR_LEVEL_NORMAL1
;
643 else if (undec_sm_pwdb
< (txpwr_threshold_lv1
- 3))
644 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TX_HIGHPWR_LEVEL_NORMAL
;
646 if ((rtlpriv
->dm
.dynamic_txhighpower_lvl
!= rtlpriv
->dm
.last_dtp_lvl
))
647 rtl92s_phy_set_txpower(hw
, rtlphy
->current_channel
);
649 rtlpriv
->dm
.last_dtp_lvl
= rtlpriv
->dm
.dynamic_txhighpower_lvl
;
652 static void _rtl92s_dm_init_dig(struct ieee80211_hw
*hw
)
654 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
655 struct dig_t
*digtable
= &rtlpriv
->dm_digtable
;
657 /* Disable DIG scheme now.*/
658 digtable
->dig_enable_flag
= true;
659 digtable
->backoff_enable_flag
= true;
661 if ((rtlpriv
->dm
.dm_type
== DM_TYPE_BYDRIVER
) &&
662 (hal_get_firmwareversion(rtlpriv
) >= 0x3c))
663 digtable
->dig_algorithm
= DIG_ALGO_BY_TOW_PORT
;
665 digtable
->dig_algorithm
=
666 DIG_ALGO_BEFORE_CONNECT_BY_RSSI_AND_ALARM
;
668 digtable
->dig_twoport_algorithm
= DIG_TWO_PORT_ALGO_RSSI
;
669 digtable
->dig_ext_port_stage
= DIG_EXT_PORT_STAGE_MAX
;
670 /* off=by real rssi value, on=by digtable->rssi_val for new dig */
671 digtable
->dig_dbgmode
= DM_DBG_OFF
;
672 digtable
->dig_slgorithm_switch
= 0;
674 /* 2007/10/04 MH Define init gain threshol. */
675 digtable
->dig_state
= DM_STA_DIG_MAX
;
676 digtable
->dig_highpwrstate
= DM_STA_DIG_MAX
;
678 digtable
->cur_sta_cstate
= DIG_STA_DISCONNECT
;
679 digtable
->pre_sta_cstate
= DIG_STA_DISCONNECT
;
680 digtable
->cur_ap_cstate
= DIG_AP_DISCONNECT
;
681 digtable
->pre_ap_cstate
= DIG_AP_DISCONNECT
;
683 digtable
->rssi_lowthresh
= DM_DIG_THRESH_LOW
;
684 digtable
->rssi_highthresh
= DM_DIG_THRESH_HIGH
;
686 digtable
->fa_lowthresh
= DM_FALSEALARM_THRESH_LOW
;
687 digtable
->fa_highthresh
= DM_FALSEALARM_THRESH_HIGH
;
689 digtable
->rssi_highpower_lowthresh
= DM_DIG_HIGH_PWR_THRESH_LOW
;
690 digtable
->rssi_highpower_highthresh
= DM_DIG_HIGH_PWR_THRESH_HIGH
;
692 /* for dig debug rssi value */
693 digtable
->rssi_val
= 50;
694 digtable
->back_val
= DM_DIG_BACKOFF
;
695 digtable
->rx_gain_max
= DM_DIG_MAX
;
697 digtable
->rx_gain_min
= DM_DIG_MIN
;
699 digtable
->backoffval_range_max
= DM_DIG_BACKOFF_MAX
;
700 digtable
->backoffval_range_min
= DM_DIG_BACKOFF_MIN
;
703 static void _rtl92s_dm_init_dynamic_txpower(struct ieee80211_hw
*hw
)
705 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
707 if ((hal_get_firmwareversion(rtlpriv
) >= 60) &&
708 (rtlpriv
->dm
.dm_type
== DM_TYPE_BYDRIVER
))
709 rtlpriv
->dm
.dynamic_txpower_enable
= true;
711 rtlpriv
->dm
.dynamic_txpower_enable
= false;
713 rtlpriv
->dm
.last_dtp_lvl
= TX_HIGHPWR_LEVEL_NORMAL
;
714 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TX_HIGHPWR_LEVEL_NORMAL
;
717 void rtl92s_dm_init(struct ieee80211_hw
*hw
)
719 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
721 rtlpriv
->dm
.dm_type
= DM_TYPE_BYDRIVER
;
722 rtlpriv
->dm
.undec_sm_pwdb
= -1;
724 _rtl92s_dm_init_dynamic_txpower(hw
);
725 rtl92s_dm_init_edca_turbo(hw
);
726 _rtl92s_dm_init_rate_adaptive_mask(hw
);
727 _rtl92s_dm_init_txpowertracking_thermalmeter(hw
);
728 _rtl92s_dm_init_dig(hw
);
730 rtl_write_dword(rtlpriv
, WFM5
, FW_CCA_CHK_ENABLE
);
733 void rtl92s_dm_watchdog(struct ieee80211_hw
*hw
)
735 _rtl92s_dm_check_edca_turbo(hw
);
736 _rtl92s_dm_check_txpowertracking_thermalmeter(hw
);
737 _rtl92s_dm_ctrl_initgain_byrssi(hw
);
738 _rtl92s_dm_dynamic_txpower(hw
);
739 _rtl92s_dm_refresh_rateadaptive_mask(hw
);
740 _rtl92s_dm_switch_baseband_mrc(hw
);