30 #include <linux/export.h>
36 #define BT_RSSI_STATE_NORMAL_POWER BIT_OFFSET_LEN_MASK_32(0, 1)
37 #define BT_RSSI_STATE_AMDPU_OFF BIT_OFFSET_LEN_MASK_32(1, 1)
38 #define BT_RSSI_STATE_SPECIAL_LOW BIT_OFFSET_LEN_MASK_32(2, 1)
39 #define BT_RSSI_STATE_BG_EDCA_LOW BIT_OFFSET_LEN_MASK_32(3, 1)
40 #define BT_RSSI_STATE_TXPOWER_LOW BIT_OFFSET_LEN_MASK_32(4, 1)
42 #define RTLPRIV (struct rtl_priv *)
43 #define GET_UNDECORATED_AVERAGE_RSSI(_priv) \
44 ((RTLPRIV(_priv))->mac80211.opmode == \
45 NL80211_IFTYPE_ADHOC) ? \
46 ((RTLPRIV(_priv))->dm.entry_min_undecoratedsmoothed_pwdb) : \
47 ((RTLPRIV(_priv))->dm.undecorated_smoothed_pwdb)
90 {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04},
91 {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04},
92 {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03},
93 {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03},
94 {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03},
95 {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03},
96 {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03},
97 {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03},
98 {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02},
99 {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02},
100 {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02},
101 {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02},
102 {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02},
103 {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02},
104 {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02},
105 {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02},
106 {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01},
107 {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02},
108 {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01},
109 {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01},
110 {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01},
111 {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01},
112 {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01},
113 {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01},
114 {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01},
115 {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01},
116 {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01},
117 {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01},
118 {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01},
119 {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01},
120 {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01},
121 {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01},
122 {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01}
126 {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00},
127 {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00},
128 {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00},
129 {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00},
130 {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00},
131 {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00},
132 {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00},
133 {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00},
134 {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00},
135 {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00},
136 {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00},
137 {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00},
138 {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00},
139 {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00},
140 {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00},
141 {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00},
142 {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00},
143 {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00},
144 {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00},
145 {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00},
146 {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00},
147 {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00},
148 {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00},
149 {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00},
150 {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00},
151 {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00},
152 {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00},
153 {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00},
154 {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00},
155 {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00},
156 {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00},
157 {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00},
158 {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00}
194 if (rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb != 0)
196 (rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb >
197 rtlpriv->
dm.undecorated_smoothed_pwdb) ?
198 rtlpriv->
dm.undecorated_smoothed_pwdb :
199 rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb;
201 rssi_val_min = rtlpriv->
dm.undecorated_smoothed_pwdb;
204 rssi_val_min = rtlpriv->
dm.undecorated_smoothed_pwdb;
207 rssi_val_min = rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb;
213 static void rtl92c_dm_false_alarm_counter_statistics(
struct ieee80211_hw *hw)
224 falsealm_cnt->
cnt_crc8_fail = ((ret_value & 0xffff0000) >> 16);
250 "cnt_parity_fail = %d, cnt_rate_illegal = %d, cnt_crc8_fail = %d, cnt_mcs_fail = %d\n",
256 "cnt_ofdm_fail = %x, cnt_cck_fail = %x, cnt_all = %x\n",
261 static void rtl92c_dm_ctrl_initgain_by_fa(
struct ieee80211_hw *hw)
286 static void rtl92c_dm_ctrl_initgain_by_rssi(
struct ieee80211_hw *hw)
318 "rssi_val_min = %x backoff_val %x\n",
324 static void rtl92c_dm_initial_gain_multi_sta(
struct ieee80211_hw *hw)
330 long rssi_strength = rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb;
331 bool multi_sta =
false;
341 }
else if (initialized ==
false) {
349 if ((rssi_strength < dm_digtable->rssi_lowthresh) &&
361 rtl92c_dm_ctrl_initgain_by_fa(hw);
370 "curmultista_connectstate = %x dig_ext_port_stage %x\n",
375 static void rtl92c_dm_initial_gain_sta(
struct ieee80211_hw *hw)
381 "presta_connectstate = %x, cursta_connectstate = %x\n",
391 rtl92c_dm_initial_gain_min_pwdb(hw);
392 rtl92c_dm_ctrl_initgain_by_rssi(hw);
404 static void rtl92c_dm_cck_packet_detection_thresh(
struct ieee80211_hw *hw)
411 dm_digtable->
rssi_val_min = rtl92c_dm_initial_gain_min_pwdb(hw);
477 static void rtl92c_dm_ctrl_initgain_by_twoport(
struct ieee80211_hw *hw)
491 rtl92c_dm_initial_gain_sta(hw);
492 rtl92c_dm_initial_gain_multi_sta(hw);
493 rtl92c_dm_cck_packet_detection_thresh(hw);
504 if (rtlpriv->
dm.dm_initialgain_enable ==
false)
509 rtl92c_dm_ctrl_initgain_by_twoport(hw);
513 static void rtl92c_dm_init_dynamic_txpower(
struct ieee80211_hw *hw)
517 rtlpriv->
dm.dynamic_txpower_enable =
false;
529 "cur_igvalue = 0x%x, pre_igvalue = 0x%x, backoff_val = %d\n",
548 static void rtl92c_dm_pwdb_monitor(
struct ieee80211_hw *hw)
551 long tmpentry_max_pwdb = 0, tmpentry_min_pwdb = 0xff;
553 u8 h2c_parameter[3] = { 0 };
557 if (tmpentry_max_pwdb != 0) {
558 rtlpriv->
dm.entry_max_undecoratedsmoothed_pwdb =
561 rtlpriv->
dm.entry_max_undecoratedsmoothed_pwdb = 0;
564 if (tmpentry_min_pwdb != 0xff) {
565 rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb =
568 rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb = 0;
571 h2c_parameter[2] = (
u8) (rtlpriv->
dm.undecorated_smoothed_pwdb & 0xFF);
572 h2c_parameter[0] = 0;
580 rtlpriv->
dm.current_turbo_edca =
false;
581 rtlpriv->
dm.is_any_nonbepkts =
false;
582 rtlpriv->
dm.is_cur_rdlstate =
false;
586 static void rtl92c_dm_check_edca_turbo(
struct ieee80211_hw *hw)
592 static u64 last_txok_cnt;
593 static u64 last_rxok_cnt;
594 static u32 last_bt_edca_ul;
595 static u32 last_bt_edca_dl;
596 u64 cur_txok_cnt = 0;
597 u64 cur_rxok_cnt = 0;
598 u32 edca_be_ul = 0x5ea42b;
599 u32 edca_be_dl = 0x5ea42b;
600 bool bt_change_edca =
false;
602 if ((last_bt_edca_ul != rtlpcipriv->
bt_coexist.bt_edca_ul) ||
603 (last_bt_edca_dl != rtlpcipriv->
bt_coexist.bt_edca_dl)) {
604 rtlpriv->
dm.current_turbo_edca =
false;
605 last_bt_edca_ul = rtlpcipriv->
bt_coexist.bt_edca_ul;
606 last_bt_edca_dl = rtlpcipriv->
bt_coexist.bt_edca_dl;
610 edca_be_ul = rtlpcipriv->
bt_coexist.bt_edca_ul;
611 bt_change_edca =
true;
615 edca_be_ul = rtlpcipriv->
bt_coexist.bt_edca_dl;
616 bt_change_edca =
true;
620 rtlpriv->
dm.current_turbo_edca =
false;
625 if (!(edca_be_ul & 0xffff0000))
626 edca_be_ul |= 0x005e0000;
628 if (!(edca_be_dl & 0xffff0000))
629 edca_be_dl |= 0x005e0000;
632 if ((bt_change_edca) || ((!rtlpriv->
dm.is_any_nonbepkts) &&
633 (!rtlpriv->
dm.disable_framebursting))) {
635 cur_txok_cnt = rtlpriv->
stats.txbytesunicast - last_txok_cnt;
636 cur_rxok_cnt = rtlpriv->
stats.rxbytesunicast - last_rxok_cnt;
638 if (cur_rxok_cnt > 4 * cur_txok_cnt) {
639 if (!rtlpriv->
dm.is_cur_rdlstate ||
640 !rtlpriv->
dm.current_turbo_edca) {
641 rtl_write_dword(rtlpriv,
644 rtlpriv->
dm.is_cur_rdlstate =
true;
647 if (rtlpriv->
dm.is_cur_rdlstate ||
648 !rtlpriv->
dm.current_turbo_edca) {
649 rtl_write_dword(rtlpriv,
652 rtlpriv->
dm.is_cur_rdlstate =
false;
655 rtlpriv->
dm.current_turbo_edca =
true;
657 if (rtlpriv->
dm.current_turbo_edca) {
661 rtlpriv->
dm.current_turbo_edca =
false;
665 rtlpriv->
dm.is_any_nonbepkts =
false;
666 last_txok_cnt = rtlpriv->
stats.txbytesunicast;
667 last_rxok_cnt = rtlpriv->
stats.rxbytesunicast;
670 static void rtl92c_dm_txpower_tracking_callback_thermalmeter(
struct ieee80211_hw
678 long ele_a, ele_d, temp_cck, val_x, value32;
679 long val_y, ele_c = 0;
680 u8 ofdm_index[2], cck_index = 0, ofdm_index_old[2], cck_index_old = 0;
683 s8 txpwr_level[2] = {0, 0};
684 u8 ofdm_min_index = 6, rf;
686 rtlpriv->
dm.txpower_trackinginit =
true;
688 "rtl92c_dm_txpower_tracking_callback_thermalmeter\n");
693 "Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermalmeter 0x%x\n",
694 thermalvalue, rtlpriv->
dm.thermalvalue,
709 if (ele_d == (ofdmswing_table[i] &
MASKOFDM_D)) {
710 ofdm_index_old[0] = (
u8) i;
713 "Initial pathA ele_d reg0x%x = 0x%lx, ofdm_index=0x%x\n",
715 ele_d, ofdm_index_old[0]);
725 if (ele_d == (ofdmswing_table[i] &
730 "Initial pathB ele_d reg0x%x = 0x%lx, ofdm_index=0x%x\n",
742 if (rtlpriv->
dm.cck_inch14) {
743 if (
memcmp((
void *)&temp_cck,
744 (
void *)&cckswing_table_ch14[i][2],
746 cck_index_old = (
u8) i;
750 "Initial reg0x%x = 0x%lx, cck_index=0x%x, ch 14 %d\n",
753 rtlpriv->
dm.cck_inch14);
757 if (
memcmp((
void *)&temp_cck,
759 &cckswing_table_ch1ch13[i][2],
761 cck_index_old = (
u8) i;
765 "Initial reg0x%x = 0x%lx, cck_index=0x%x, ch14 %d\n",
768 rtlpriv->
dm.cck_inch14);
774 if (!rtlpriv->
dm.thermalvalue) {
775 rtlpriv->
dm.thermalvalue =
777 rtlpriv->
dm.thermalvalue_lck = thermalvalue;
778 rtlpriv->
dm.thermalvalue_iqk = thermalvalue;
779 for (i = 0; i < rf; i++)
780 rtlpriv->
dm.ofdm_index[i] = ofdm_index_old[i];
781 rtlpriv->
dm.cck_index = cck_index_old;
784 delta = (thermalvalue > rtlpriv->
dm.thermalvalue) ?
785 (thermalvalue - rtlpriv->
dm.thermalvalue) :
786 (rtlpriv->
dm.thermalvalue - thermalvalue);
788 delta_lck = (thermalvalue > rtlpriv->
dm.thermalvalue_lck) ?
789 (thermalvalue - rtlpriv->
dm.thermalvalue_lck) :
790 (rtlpriv->
dm.thermalvalue_lck - thermalvalue);
792 delta_iqk = (thermalvalue > rtlpriv->
dm.thermalvalue_iqk) ?
793 (thermalvalue - rtlpriv->
dm.thermalvalue_iqk) :
794 (rtlpriv->
dm.thermalvalue_iqk - thermalvalue);
797 "Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermalmeter 0x%x delta 0x%x delta_lck 0x%x delta_iqk 0x%x\n",
798 thermalvalue, rtlpriv->
dm.thermalvalue,
803 rtlpriv->
dm.thermalvalue_lck = thermalvalue;
807 if (delta > 0 && rtlpriv->
dm.txpower_track_control) {
808 if (thermalvalue > rtlpriv->
dm.thermalvalue) {
809 for (i = 0; i < rf; i++)
810 rtlpriv->
dm.ofdm_index[i] -= delta;
811 rtlpriv->
dm.cck_index -= delta;
813 for (i = 0; i < rf; i++)
814 rtlpriv->
dm.ofdm_index[i] += delta;
815 rtlpriv->
dm.cck_index += delta;
820 "temp OFDM_A_index=0x%x, OFDM_B_index=0x%x, cck_index=0x%x\n",
821 rtlpriv->
dm.ofdm_index[0],
822 rtlpriv->
dm.ofdm_index[1],
823 rtlpriv->
dm.cck_index);
826 "temp OFDM_A_index=0x%x, cck_index=0x%x\n",
827 rtlpriv->
dm.ofdm_index[0],
828 rtlpriv->
dm.cck_index);
832 for (i = 0; i < rf; i++)
834 rtlpriv->
dm.ofdm_index[i]
836 cck_index = rtlpriv->
dm.cck_index + 1;
838 for (i = 0; i < rf; i++)
840 rtlpriv->
dm.ofdm_index[i];
841 cck_index = rtlpriv->
dm.cck_index;
844 for (i = 0; i < rf; i++) {
845 if (txpwr_level[i] >= 0 &&
846 txpwr_level[i] <= 26) {
854 }
else if (delta > 5 && thermalvalue <
859 }
else if (txpwr_level[i] >= 27 &&
868 }
else if (txpwr_level[i] >= 32 &&
869 txpwr_level[i] <= 38 &&
877 if (txpwr_level[i] >= 0 && txpwr_level[i] <= 26) {
885 }
else if (delta > 5 && thermalvalue <
889 }
else if (txpwr_level[i] >= 27 &&
890 txpwr_level[i] <= 32 &&
898 }
else if (txpwr_level[i] >= 32 &&
899 txpwr_level[i] <= 38 &&
905 for (i = 0; i < rf; i++) {
909 else if (ofdm_index[i] < ofdm_min_index)
910 ofdm_index[
i] = ofdm_min_index;
915 else if (cck_index < 0)
920 "new OFDM_A_index=0x%x, OFDM_B_index=0x%x, cck_index=0x%x\n",
921 ofdm_index[0], ofdm_index[1],
925 "new OFDM_A_index=0x%x, cck_index=0x%x\n",
926 ofdm_index[0], cck_index);
930 if (rtlpriv->
dm.txpower_track_control && delta != 0) {
932 (ofdmswing_table[ofdm_index[0]] & 0xFFC00000) >> 22;
937 if ((val_x & 0x00000200) != 0)
938 val_x = val_x | 0xFFFFFC00;
939 ele_a = ((val_x * ele_d) >> 8) & 0x000003FF;
941 if ((val_y & 0x00000200) != 0)
942 val_y = val_y | 0xFFFFFC00;
943 ele_c = ((val_y * ele_d) >> 8) & 0x000003FF;
945 value32 = (ele_d << 22) |
946 ((ele_c & 0x3F) << 16) | ele_a;
951 value32 = (ele_c & 0x000003C0) >> 6;
955 value32 = ((val_x * ele_d) >> 7) & 0x01;
959 value32 = ((val_y * ele_d) >> 7) & 0x01;
965 ofdmswing_table[ofdm_index[0]]);
973 if (!rtlpriv->
dm.cck_inch14) {
974 rtl_write_byte(rtlpriv, 0xa22,
975 cckswing_table_ch1ch13[cck_index]
977 rtl_write_byte(rtlpriv, 0xa23,
978 cckswing_table_ch1ch13[cck_index]
980 rtl_write_byte(rtlpriv, 0xa24,
981 cckswing_table_ch1ch13[cck_index]
983 rtl_write_byte(rtlpriv, 0xa25,
984 cckswing_table_ch1ch13[cck_index]
986 rtl_write_byte(rtlpriv, 0xa26,
987 cckswing_table_ch1ch13[cck_index]
989 rtl_write_byte(rtlpriv, 0xa27,
990 cckswing_table_ch1ch13[cck_index]
992 rtl_write_byte(rtlpriv, 0xa28,
993 cckswing_table_ch1ch13[cck_index]
995 rtl_write_byte(rtlpriv, 0xa29,
996 cckswing_table_ch1ch13[cck_index]
999 rtl_write_byte(rtlpriv, 0xa22,
1000 cckswing_table_ch14[cck_index]
1002 rtl_write_byte(rtlpriv, 0xa23,
1003 cckswing_table_ch14[cck_index]
1005 rtl_write_byte(rtlpriv, 0xa24,
1006 cckswing_table_ch14[cck_index]
1008 rtl_write_byte(rtlpriv, 0xa25,
1009 cckswing_table_ch14[cck_index]
1011 rtl_write_byte(rtlpriv, 0xa26,
1012 cckswing_table_ch14[cck_index]
1014 rtl_write_byte(rtlpriv, 0xa27,
1015 cckswing_table_ch14[cck_index]
1017 rtl_write_byte(rtlpriv, 0xa28,
1018 cckswing_table_ch14[cck_index]
1020 rtl_write_byte(rtlpriv, 0xa29,
1021 cckswing_table_ch14[cck_index]
1026 ele_d = (ofdmswing_table[ofdm_index[1]] &
1033 if ((val_x & 0x00000200) != 0)
1034 val_x = val_x | 0xFFFFFC00;
1035 ele_a = ((val_x * ele_d) >> 8) &
1038 if ((val_y & 0x00000200) != 0)
1039 val_y = val_y | 0xFFFFFC00;
1040 ele_c = ((val_y * ele_d) >> 8) &
1043 value32 = (ele_d << 22) |
1044 ((ele_c & 0x3F) << 16) | ele_a;
1049 value32 = (ele_c & 0x000003C0) >> 6;
1053 value32 = ((val_x * ele_d) >> 7) & 0x01;
1057 value32 = ((val_y * ele_d) >> 7) & 0x01;
1064 ofdmswing_table[ofdm_index
1069 BIT(27) |
BIT(25), 0x00);
1075 if (delta_iqk > 3) {
1076 rtlpriv->
dm.thermalvalue_iqk = thermalvalue;
1080 if (rtlpriv->
dm.txpower_track_control)
1081 rtlpriv->
dm.thermalvalue = thermalvalue;
1088 static void rtl92c_dm_initialize_txpower_tracking_thermalmeter(
1093 rtlpriv->
dm.txpower_tracking =
true;
1094 rtlpriv->
dm.txpower_trackinginit =
false;
1097 "pMgntInfo->txpower_tracking = %d\n",
1098 rtlpriv->
dm.txpower_tracking);
1101 static void rtl92c_dm_initialize_txpower_tracking(
struct ieee80211_hw *hw)
1103 rtl92c_dm_initialize_txpower_tracking_thermalmeter(hw);
1106 static void rtl92c_dm_txpower_tracking_directcall(
struct ieee80211_hw *hw)
1108 rtl92c_dm_txpower_tracking_callback_thermalmeter(hw);
1111 static void rtl92c_dm_check_txpower_tracking_thermal_meter(
1115 static u8 tm_trigger;
1117 if (!rtlpriv->
dm.txpower_tracking)
1124 "Trigger 92S Thermal Meter!!\n");
1129 "Schedule TxPowerTracking direct call!!\n");
1130 rtl92c_dm_txpower_tracking_directcall(hw);
1137 rtl92c_dm_check_txpower_tracking_thermal_meter(hw);
1150 rtlpriv->
dm.useramask =
true;
1152 rtlpriv->
dm.useramask =
false;
1157 static void rtl92c_dm_refresh_rate_adaptive_mask(
struct ieee80211_hw *hw)
1163 u32 low_rssithresh_for_ra, high_rssithresh_for_ra;
1166 if (is_hal_stop(rtlhal)) {
1168 "<---- driver is going to unload\n");
1172 if (!rtlpriv->
dm.useramask) {
1174 "<---- driver does not control rate adaptive mask\n");
1182 high_rssithresh_for_ra = 50;
1183 low_rssithresh_for_ra = 20;
1186 high_rssithresh_for_ra = 55;
1187 low_rssithresh_for_ra = 20;
1190 high_rssithresh_for_ra = 50;
1191 low_rssithresh_for_ra = 25;
1194 high_rssithresh_for_ra = 50;
1195 low_rssithresh_for_ra = 20;
1199 if (rtlpriv->
dm.undecorated_smoothed_pwdb >
1200 (
long)high_rssithresh_for_ra)
1202 else if (rtlpriv->
dm.undecorated_smoothed_pwdb >
1203 (
long)low_rssithresh_for_ra)
1210 rtlpriv->
dm.undecorated_smoothed_pwdb);
1214 "PreState = %d, CurState = %d\n",
1219 rtlpriv->
cfg->ops->update_rate_tbl(hw, sta,
1228 static void rtl92c_dm_init_dynamic_bb_powersaving(
struct ieee80211_hw *hw)
1245 static u32 reg_874, reg_c70, reg_85c, reg_a74;
1247 if (initialize == 0) {
1257 reg_a74 = (rtl_get_bbreg(hw, 0xa74,
MASKDWORD) & 0xF000) >> 12;
1262 if (!bforce_in_normal) {
1291 rtl_set_bbreg(hw, 0xa74, 0xF000, 0x3);
1292 rtl_set_bbreg(hw, 0x818,
BIT(28), 0x0);
1293 rtl_set_bbreg(hw, 0x818,
BIT(28), 0x1);
1301 rtl_set_bbreg(hw, 0xa74, 0xF000, reg_a74);
1302 rtl_set_bbreg(hw, 0x818,
BIT(28), 0x0);
1310 static void rtl92c_dm_dynamic_bb_powersaving(
struct ieee80211_hw *hw)
1318 (rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb == 0)) {
1326 rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb;
1328 "AP Client PWDB = 0x%lx\n",
1332 rtlpriv->
dm.undecorated_smoothed_pwdb;
1334 "STA Default Port PWDB = 0x%lx\n",
1339 rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb;
1342 "AP Ext Port PWDB = 0x%lx\n",
1357 rtl92c_dm_diginit(hw);
1358 rtl92c_dm_init_dynamic_txpower(hw);
1361 rtl92c_dm_initialize_txpower_tracking(hw);
1362 rtl92c_dm_init_dynamic_bb_powersaving(hw);
1371 long undecorated_smoothed_pwdb;
1373 if (!rtlpriv->
dm.dynamic_txpower_enable)
1382 (rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb == 0)) {
1384 "Not connected to any\n");
1394 undecorated_smoothed_pwdb =
1395 rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb;
1397 "AP Client PWDB = 0x%lx\n",
1398 undecorated_smoothed_pwdb);
1400 undecorated_smoothed_pwdb =
1401 rtlpriv->
dm.undecorated_smoothed_pwdb;
1403 "STA Default Port PWDB = 0x%lx\n",
1404 undecorated_smoothed_pwdb);
1407 undecorated_smoothed_pwdb =
1408 rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb;
1411 "AP Ext Port PWDB = 0x%lx\n",
1412 undecorated_smoothed_pwdb);
1418 "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n");
1419 }
else if ((undecorated_smoothed_pwdb <
1421 (undecorated_smoothed_pwdb >=
1426 "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n");
1427 }
else if (undecorated_smoothed_pwdb <
1431 "TXHIGHPWRLEVEL_NORMAL\n");
1434 if ((rtlpriv->
dm.dynamic_txhighpower_lvl != rtlpriv->
dm.last_dtp_lvl)) {
1436 "PHY_SetTxPowerLevel8192S() Channel = %d\n",
1441 rtlpriv->
dm.last_dtp_lvl = rtlpriv->
dm.dynamic_txhighpower_lvl;
1449 bool fw_ps_awake =
true;
1452 (
u8 *) (&fw_current_inpsmode));
1454 (
u8 *) (&fw_ps_awake));
1459 rtl92c_dm_pwdb_monitor(hw);
1461 rtl92c_dm_false_alarm_counter_statistics(hw);
1462 rtl92c_dm_dynamic_bb_powersaving(hw);
1465 rtl92c_dm_refresh_rate_adaptive_mask(hw);
1467 rtl92c_dm_check_edca_turbo(hw);
1476 long undecorated_smoothed_pwdb;
1477 u8 curr_bt_rssi_state = 0x00;
1480 undecorated_smoothed_pwdb =
1483 if (rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb == 0)
1484 undecorated_smoothed_pwdb = 100;
1486 undecorated_smoothed_pwdb =
1487 rtlpriv->
dm.entry_min_undecoratedsmoothed_pwdb;
1492 if (undecorated_smoothed_pwdb >= 67)
1494 else if (undecorated_smoothed_pwdb < 62)
1498 if (undecorated_smoothed_pwdb >= 40)
1500 else if (undecorated_smoothed_pwdb <= 32)
1505 if (undecorated_smoothed_pwdb < 35)
1511 if (undecorated_smoothed_pwdb >= 30)
1513 else if (undecorated_smoothed_pwdb < 25)
1517 if (undecorated_smoothed_pwdb < 15)
1522 if (curr_bt_rssi_state != rtlpcipriv->
bt_coexist.bt_rssi_state) {
1523 rtlpcipriv->
bt_coexist.bt_rssi_state = curr_bt_rssi_state;
1531 static bool rtl92c_bt_state_change(
struct ieee80211_hw *hw)
1536 u32 polling, ratio_tx, ratio_pri;
1539 u8 cur_service_type;
1544 bt_state = rtl_read_byte(rtlpriv, 0x4fd);
1545 bt_tx = rtl_read_dword(rtlpriv, 0x488);
1546 bt_tx = bt_tx & 0x00ffffff;
1547 bt_pri = rtl_read_dword(rtlpriv, 0x48c);
1548 bt_pri = bt_pri & 0x00ffffff;
1549 polling = rtl_read_dword(rtlpriv, 0x490);
1551 if (bt_tx == 0xffffffff && bt_pri == 0xffffffff &&
1552 polling == 0xffffffff && bt_state == 0xff)
1556 if (bt_state != rtlpcipriv->
bt_coexist.bt_cur_state) {
1557 rtlpcipriv->
bt_coexist.bt_cur_state = bt_state;
1559 if (rtlpcipriv->
bt_coexist.reg_bt_sco == 3) {
1562 bt_state = bt_state |
1563 ((rtlpcipriv->
bt_coexist.bt_ant_isolation == 1) ?
1566 rtl_write_byte(rtlpriv, 0x4fd, bt_state);
1571 ratio_tx = bt_tx * 1000 / polling;
1572 ratio_pri = bt_pri * 1000 / polling;
1574 rtlpcipriv->
bt_coexist.ratio_pri = ratio_pri;
1576 if (bt_state && rtlpcipriv->
bt_coexist.reg_bt_sco == 3) {
1578 if ((ratio_tx < 30) && (ratio_pri < 30))
1580 else if ((ratio_pri > 110) && (ratio_pri < 250))
1581 cur_service_type =
BT_SCO;
1582 else if ((ratio_tx >= 200) && (ratio_pri >= 200))
1584 else if ((ratio_tx >= 350) && (ratio_tx < 500))
1586 else if (ratio_tx >= 500)
1587 cur_service_type =
BT_PAN;
1591 if (cur_service_type != rtlpcipriv->
bt_coexist.bt_service) {
1592 rtlpcipriv->
bt_coexist.bt_service = cur_service_type;
1593 bt_state = bt_state |
1594 ((rtlpcipriv->
bt_coexist.bt_ant_isolation == 1) ?
1602 rtl_write_word(rtlpriv, 0x504, 0x0ccc);
1603 rtl_write_byte(rtlpriv, 0x506, 0x54);
1604 rtl_write_byte(rtlpriv, 0x507, 0x54);
1606 rtl_write_byte(rtlpriv, 0x506, 0x00);
1607 rtl_write_byte(rtlpriv, 0x507, 0x00);
1610 rtl_write_byte(rtlpriv, 0x4fd, bt_state);
1619 static bool rtl92c_bt_wifi_connect_change(
struct ieee80211_hw *hw)
1622 static bool media_connect;
1625 media_connect =
false;
1627 if (!media_connect) {
1628 media_connect =
true;
1631 media_connect =
true;
1637 static void rtl92c_bt_set_normal(
struct ieee80211_hw *hw)
1644 rtlpcipriv->
bt_coexist.bt_edca_ul = 0x5ea72b;
1645 rtlpcipriv->
bt_coexist.bt_edca_dl = 0x5ea72b;
1647 rtlpcipriv->
bt_coexist.bt_edca_ul = 0x5eb82f;
1648 rtlpcipriv->
bt_coexist.bt_edca_dl = 0x5eb82f;
1651 rtlpcipriv->
bt_coexist.bt_edca_ul = 0x5ea72f;
1652 rtlpcipriv->
bt_coexist.bt_edca_dl = 0x5ea72f;
1654 rtlpcipriv->
bt_coexist.bt_edca_ul = 0x5ea32b;
1655 rtlpcipriv->
bt_coexist.bt_edca_dl = 0x5ea42b;
1667 rtlpcipriv->
bt_coexist.bt_edca_ul = 0x5eb82b;
1668 rtlpcipriv->
bt_coexist.bt_edca_dl = 0x5eb82b;
1672 static void rtl92c_bt_ant_isolation(
struct ieee80211_hw *hw)
1687 }
else if ((rtlpcipriv->
bt_coexist.bt_service ==
1707 rtl92c_bt_set_normal(hw);
1714 rtlpriv->
cfg->ops->set_rfreg(hw,
1719 rtlpriv->
cfg->ops->set_rfreg(hw,
1724 if (!rtlpriv->
dm.dynamic_txpower_enable) {
1728 rtlpriv->
dm.dynamic_txhighpower_lvl =
1731 rtlpriv->
dm.dynamic_txhighpower_lvl =
1735 rtlpriv->
dm.dynamic_txhighpower_lvl =
1739 rtlpriv->
phy.current_channel);
1743 static void rtl92c_check_bt_change(
struct ieee80211_hw *hw)
1750 rtl92c_bt_ant_isolation(hw);
1765 bool wifi_connect_change;
1766 bool bt_state_change;
1767 bool rssi_state_change;
1769 if ((rtlpcipriv->
bt_coexist.bt_coexistence) &&
1772 wifi_connect_change = rtl92c_bt_wifi_connect_change(hw);
1773 bt_state_change = rtl92c_bt_state_change(hw);
1776 if (wifi_connect_change || bt_state_change || rssi_state_change)
1777 rtl92c_check_bt_change(hw);