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 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
35 #define UNDEC_SM_PWDB entry_min_undec_sm_pwdb
37 static const u32 ofdmswing_table
[OFDM_TABLE_SIZE_92D
] = {
38 0x7f8001fe, /* 0, +6.0dB */
39 0x788001e2, /* 1, +5.5dB */
40 0x71c001c7, /* 2, +5.0dB */
41 0x6b8001ae, /* 3, +4.5dB */
42 0x65400195, /* 4, +4.0dB */
43 0x5fc0017f, /* 5, +3.5dB */
44 0x5a400169, /* 6, +3.0dB */
45 0x55400155, /* 7, +2.5dB */
46 0x50800142, /* 8, +2.0dB */
47 0x4c000130, /* 9, +1.5dB */
48 0x47c0011f, /* 10, +1.0dB */
49 0x43c0010f, /* 11, +0.5dB */
50 0x40000100, /* 12, +0dB */
51 0x3c8000f2, /* 13, -0.5dB */
52 0x390000e4, /* 14, -1.0dB */
53 0x35c000d7, /* 15, -1.5dB */
54 0x32c000cb, /* 16, -2.0dB */
55 0x300000c0, /* 17, -2.5dB */
56 0x2d4000b5, /* 18, -3.0dB */
57 0x2ac000ab, /* 19, -3.5dB */
58 0x288000a2, /* 20, -4.0dB */
59 0x26000098, /* 21, -4.5dB */
60 0x24000090, /* 22, -5.0dB */
61 0x22000088, /* 23, -5.5dB */
62 0x20000080, /* 24, -6.0dB */
63 0x1e400079, /* 25, -6.5dB */
64 0x1c800072, /* 26, -7.0dB */
65 0x1b00006c, /* 27. -7.5dB */
66 0x19800066, /* 28, -8.0dB */
67 0x18000060, /* 29, -8.5dB */
68 0x16c0005b, /* 30, -9.0dB */
69 0x15800056, /* 31, -9.5dB */
70 0x14400051, /* 32, -10.0dB */
71 0x1300004c, /* 33, -10.5dB */
72 0x12000048, /* 34, -11.0dB */
73 0x11000044, /* 35, -11.5dB */
74 0x10000040, /* 36, -12.0dB */
75 0x0f00003c, /* 37, -12.5dB */
76 0x0e400039, /* 38, -13.0dB */
77 0x0d800036, /* 39, -13.5dB */
78 0x0cc00033, /* 40, -14.0dB */
79 0x0c000030, /* 41, -14.5dB */
80 0x0b40002d, /* 42, -15.0dB */
83 static const u8 cckswing_table_ch1ch13
[CCK_TABLE_SIZE
][8] = {
84 {0x36, 0x35, 0x2e, 0x25, 0x1c, 0x12, 0x09, 0x04}, /* 0, +0dB */
85 {0x33, 0x32, 0x2b, 0x23, 0x1a, 0x11, 0x08, 0x04}, /* 1, -0.5dB */
86 {0x30, 0x2f, 0x29, 0x21, 0x19, 0x10, 0x08, 0x03}, /* 2, -1.0dB */
87 {0x2d, 0x2d, 0x27, 0x1f, 0x18, 0x0f, 0x08, 0x03}, /* 3, -1.5dB */
88 {0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03}, /* 4, -2.0dB */
89 {0x28, 0x28, 0x22, 0x1c, 0x15, 0x0d, 0x07, 0x03}, /* 5, -2.5dB */
90 {0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03}, /* 6, -3.0dB */
91 {0x24, 0x23, 0x1f, 0x19, 0x13, 0x0c, 0x06, 0x03}, /* 7, -3.5dB */
92 {0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02}, /* 8, -4.0dB */
93 {0x20, 0x20, 0x1b, 0x16, 0x11, 0x08, 0x05, 0x02}, /* 9, -4.5dB */
94 {0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02}, /* 10, -5.0dB */
95 {0x1d, 0x1c, 0x18, 0x14, 0x0f, 0x0a, 0x05, 0x02}, /* 11, -5.5dB */
96 {0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02}, /* 12, -6.0dB */
97 {0x1a, 0x19, 0x16, 0x12, 0x0d, 0x09, 0x04, 0x02}, /* 13, -6.5dB */
98 {0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02}, /* 14, -7.0dB */
99 {0x17, 0x16, 0x13, 0x10, 0x0c, 0x08, 0x04, 0x02}, /* 15, -7.5dB */
100 {0x16, 0x15, 0x12, 0x0f, 0x0b, 0x07, 0x04, 0x01}, /* 16, -8.0dB */
101 {0x14, 0x14, 0x11, 0x0e, 0x0b, 0x07, 0x03, 0x02}, /* 17, -8.5dB */
102 {0x13, 0x13, 0x10, 0x0d, 0x0a, 0x06, 0x03, 0x01}, /* 18, -9.0dB */
103 {0x12, 0x12, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 19, -9.5dB */
104 {0x11, 0x11, 0x0f, 0x0c, 0x09, 0x06, 0x03, 0x01}, /* 20, -10.0dB */
105 {0x10, 0x10, 0x0e, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 21, -10.5dB */
106 {0x0f, 0x0f, 0x0d, 0x0b, 0x08, 0x05, 0x03, 0x01}, /* 22, -11.0dB */
107 {0x0e, 0x0e, 0x0c, 0x0a, 0x08, 0x05, 0x02, 0x01}, /* 23, -11.5dB */
108 {0x0d, 0x0d, 0x0c, 0x0a, 0x07, 0x05, 0x02, 0x01}, /* 24, -12.0dB */
109 {0x0d, 0x0c, 0x0b, 0x09, 0x07, 0x04, 0x02, 0x01}, /* 25, -12.5dB */
110 {0x0c, 0x0c, 0x0a, 0x09, 0x06, 0x04, 0x02, 0x01}, /* 26, -13.0dB */
111 {0x0b, 0x0b, 0x0a, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 27, -13.5dB */
112 {0x0b, 0x0a, 0x09, 0x08, 0x06, 0x04, 0x02, 0x01}, /* 28, -14.0dB */
113 {0x0a, 0x0a, 0x09, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 29, -14.5dB */
114 {0x0a, 0x09, 0x08, 0x07, 0x05, 0x03, 0x02, 0x01}, /* 30, -15.0dB */
115 {0x09, 0x09, 0x08, 0x06, 0x05, 0x03, 0x01, 0x01}, /* 31, -15.5dB */
116 {0x09, 0x08, 0x07, 0x06, 0x04, 0x03, 0x01, 0x01} /* 32, -16.0dB */
119 static const u8 cckswing_table_ch14
[CCK_TABLE_SIZE
][8] = {
120 {0x36, 0x35, 0x2e, 0x1b, 0x00, 0x00, 0x00, 0x00}, /* 0, +0dB */
121 {0x33, 0x32, 0x2b, 0x19, 0x00, 0x00, 0x00, 0x00}, /* 1, -0.5dB */
122 {0x30, 0x2f, 0x29, 0x18, 0x00, 0x00, 0x00, 0x00}, /* 2, -1.0dB */
123 {0x2d, 0x2d, 0x17, 0x17, 0x00, 0x00, 0x00, 0x00}, /* 3, -1.5dB */
124 {0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00}, /* 4, -2.0dB */
125 {0x28, 0x28, 0x24, 0x14, 0x00, 0x00, 0x00, 0x00}, /* 5, -2.5dB */
126 {0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00}, /* 6, -3.0dB */
127 {0x24, 0x23, 0x1f, 0x12, 0x00, 0x00, 0x00, 0x00}, /* 7, -3.5dB */
128 {0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00}, /* 8, -4.0dB */
129 {0x20, 0x20, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x00}, /* 9, -4.5dB */
130 {0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00}, /* 10, -5.0dB */
131 {0x1d, 0x1c, 0x18, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 11, -5.5dB */
132 {0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00}, /* 12, -6.0dB */
133 {0x1a, 0x19, 0x16, 0x0d, 0x00, 0x00, 0x00, 0x00}, /* 13, -6.5dB */
134 {0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00}, /* 14, -7.0dB */
135 {0x17, 0x16, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 15, -7.5dB */
136 {0x16, 0x15, 0x12, 0x0b, 0x00, 0x00, 0x00, 0x00}, /* 16, -8.0dB */
137 {0x14, 0x14, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 17, -8.5dB */
138 {0x13, 0x13, 0x10, 0x0a, 0x00, 0x00, 0x00, 0x00}, /* 18, -9.0dB */
139 {0x12, 0x12, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 19, -9.5dB */
140 {0x11, 0x11, 0x0f, 0x09, 0x00, 0x00, 0x00, 0x00}, /* 20, -10.0dB */
141 {0x10, 0x10, 0x0e, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 21, -10.5dB */
142 {0x0f, 0x0f, 0x0d, 0x08, 0x00, 0x00, 0x00, 0x00}, /* 22, -11.0dB */
143 {0x0e, 0x0e, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 23, -11.5dB */
144 {0x0d, 0x0d, 0x0c, 0x07, 0x00, 0x00, 0x00, 0x00}, /* 24, -12.0dB */
145 {0x0d, 0x0c, 0x0b, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 25, -12.5dB */
146 {0x0c, 0x0c, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 26, -13.0dB */
147 {0x0b, 0x0b, 0x0a, 0x06, 0x00, 0x00, 0x00, 0x00}, /* 27, -13.5dB */
148 {0x0b, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 28, -14.0dB */
149 {0x0a, 0x0a, 0x09, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 29, -14.5dB */
150 {0x0a, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 30, -15.0dB */
151 {0x09, 0x09, 0x08, 0x05, 0x00, 0x00, 0x00, 0x00}, /* 31, -15.5dB */
152 {0x09, 0x08, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00} /* 32, -16.0dB */
155 static void rtl92d_dm_false_alarm_counter_statistics(struct ieee80211_hw
*hw
)
158 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
159 struct false_alarm_statistics
*falsealm_cnt
= &(rtlpriv
->falsealm_cnt
);
160 unsigned long flag
= 0;
162 /* hold ofdm counter */
163 rtl_set_bbreg(hw
, ROFDM0_LSTF
, BIT(31), 1); /* hold page C counter */
164 rtl_set_bbreg(hw
, ROFDM1_LSTF
, BIT(31), 1); /*hold page D counter */
166 ret_value
= rtl_get_bbreg(hw
, ROFDM0_FRAMESYNC
, MASKDWORD
);
167 falsealm_cnt
->cnt_fast_fsync_fail
= (ret_value
& 0xffff);
168 falsealm_cnt
->cnt_sb_search_fail
= ((ret_value
& 0xffff0000) >> 16);
169 ret_value
= rtl_get_bbreg(hw
, ROFDM_PHYCOUNTER1
, MASKDWORD
);
170 falsealm_cnt
->cnt_parity_fail
= ((ret_value
& 0xffff0000) >> 16);
171 ret_value
= rtl_get_bbreg(hw
, ROFDM_PHYCOUNTER2
, MASKDWORD
);
172 falsealm_cnt
->cnt_rate_illegal
= (ret_value
& 0xffff);
173 falsealm_cnt
->cnt_crc8_fail
= ((ret_value
& 0xffff0000) >> 16);
174 ret_value
= rtl_get_bbreg(hw
, ROFDM_PHYCOUNTER3
, MASKDWORD
);
175 falsealm_cnt
->cnt_mcs_fail
= (ret_value
& 0xffff);
176 falsealm_cnt
->cnt_ofdm_fail
= falsealm_cnt
->cnt_parity_fail
+
177 falsealm_cnt
->cnt_rate_illegal
+
178 falsealm_cnt
->cnt_crc8_fail
+
179 falsealm_cnt
->cnt_mcs_fail
+
180 falsealm_cnt
->cnt_fast_fsync_fail
+
181 falsealm_cnt
->cnt_sb_search_fail
;
183 if (rtlpriv
->rtlhal
.current_bandtype
!= BAND_ON_5G
) {
184 /* hold cck counter */
185 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
186 ret_value
= rtl_get_bbreg(hw
, RCCK0_FACOUNTERLOWER
, MASKBYTE0
);
187 falsealm_cnt
->cnt_cck_fail
= ret_value
;
188 ret_value
= rtl_get_bbreg(hw
, RCCK0_FACOUNTERUPPER
, MASKBYTE3
);
189 falsealm_cnt
->cnt_cck_fail
+= (ret_value
& 0xff) << 8;
190 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
192 falsealm_cnt
->cnt_cck_fail
= 0;
195 /* reset false alarm counter registers */
196 falsealm_cnt
->cnt_all
= falsealm_cnt
->cnt_fast_fsync_fail
+
197 falsealm_cnt
->cnt_sb_search_fail
+
198 falsealm_cnt
->cnt_parity_fail
+
199 falsealm_cnt
->cnt_rate_illegal
+
200 falsealm_cnt
->cnt_crc8_fail
+
201 falsealm_cnt
->cnt_mcs_fail
+
202 falsealm_cnt
->cnt_cck_fail
;
204 rtl_set_bbreg(hw
, ROFDM1_LSTF
, 0x08000000, 1);
205 /* update ofdm counter */
206 rtl_set_bbreg(hw
, ROFDM1_LSTF
, 0x08000000, 0);
207 /* update page C counter */
208 rtl_set_bbreg(hw
, ROFDM0_LSTF
, BIT(31), 0);
209 /* update page D counter */
210 rtl_set_bbreg(hw
, ROFDM1_LSTF
, BIT(31), 0);
211 if (rtlpriv
->rtlhal
.current_bandtype
!= BAND_ON_5G
) {
212 /* reset cck counter */
213 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
214 rtl_set_bbreg(hw
, RCCK0_FALSEALARMREPORT
, 0x0000c000, 0);
215 /* enable cck counter */
216 rtl_set_bbreg(hw
, RCCK0_FALSEALARMREPORT
, 0x0000c000, 2);
217 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
219 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
220 "Cnt_Fast_Fsync_fail = %x, Cnt_SB_Search_fail = %x\n",
221 falsealm_cnt
->cnt_fast_fsync_fail
,
222 falsealm_cnt
->cnt_sb_search_fail
);
223 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
224 "Cnt_Parity_Fail = %x, Cnt_Rate_Illegal = %x, Cnt_Crc8_fail = %x, Cnt_Mcs_fail = %x\n",
225 falsealm_cnt
->cnt_parity_fail
,
226 falsealm_cnt
->cnt_rate_illegal
,
227 falsealm_cnt
->cnt_crc8_fail
,
228 falsealm_cnt
->cnt_mcs_fail
);
229 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
230 "Cnt_Ofdm_fail = %x, Cnt_Cck_fail = %x, Cnt_all = %x\n",
231 falsealm_cnt
->cnt_ofdm_fail
,
232 falsealm_cnt
->cnt_cck_fail
,
233 falsealm_cnt
->cnt_all
);
236 static void rtl92d_dm_find_minimum_rssi(struct ieee80211_hw
*hw
)
238 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
239 struct dig_t
*de_digtable
= &rtlpriv
->dm_digtable
;
240 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
242 /* Determine the minimum RSSI */
243 if ((mac
->link_state
< MAC80211_LINKED
) &&
244 (rtlpriv
->dm
.UNDEC_SM_PWDB
== 0)) {
245 de_digtable
->min_undec_pwdb_for_dm
= 0;
246 RT_TRACE(rtlpriv
, COMP_BB_POWERSAVING
, DBG_LOUD
,
247 "Not connected to any\n");
249 if (mac
->link_state
>= MAC80211_LINKED
) {
250 if (mac
->opmode
== NL80211_IFTYPE_AP
||
251 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
252 de_digtable
->min_undec_pwdb_for_dm
=
253 rtlpriv
->dm
.UNDEC_SM_PWDB
;
254 RT_TRACE(rtlpriv
, COMP_BB_POWERSAVING
, DBG_LOUD
,
255 "AP Client PWDB = 0x%lx\n",
256 rtlpriv
->dm
.UNDEC_SM_PWDB
);
258 de_digtable
->min_undec_pwdb_for_dm
=
259 rtlpriv
->dm
.undec_sm_pwdb
;
260 RT_TRACE(rtlpriv
, COMP_BB_POWERSAVING
, DBG_LOUD
,
261 "STA Default Port PWDB = 0x%x\n",
262 de_digtable
->min_undec_pwdb_for_dm
);
265 de_digtable
->min_undec_pwdb_for_dm
= rtlpriv
->dm
.UNDEC_SM_PWDB
;
266 RT_TRACE(rtlpriv
, COMP_BB_POWERSAVING
, DBG_LOUD
,
267 "AP Ext Port or disconnect PWDB = 0x%x\n",
268 de_digtable
->min_undec_pwdb_for_dm
);
271 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "MinUndecoratedPWDBForDM =%d\n",
272 de_digtable
->min_undec_pwdb_for_dm
);
275 static void rtl92d_dm_cck_packet_detection_thresh(struct ieee80211_hw
*hw
)
277 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
278 struct dig_t
*de_digtable
= &rtlpriv
->dm_digtable
;
279 unsigned long flag
= 0;
281 if (de_digtable
->cursta_cstate
== DIG_STA_CONNECT
) {
282 if (de_digtable
->pre_cck_pd_state
== CCK_PD_STAGE_LOWRSSI
) {
283 if (de_digtable
->min_undec_pwdb_for_dm
<= 25)
284 de_digtable
->cur_cck_pd_state
=
285 CCK_PD_STAGE_LOWRSSI
;
287 de_digtable
->cur_cck_pd_state
=
288 CCK_PD_STAGE_HIGHRSSI
;
290 if (de_digtable
->min_undec_pwdb_for_dm
<= 20)
291 de_digtable
->cur_cck_pd_state
=
292 CCK_PD_STAGE_LOWRSSI
;
294 de_digtable
->cur_cck_pd_state
=
295 CCK_PD_STAGE_HIGHRSSI
;
298 de_digtable
->cur_cck_pd_state
= CCK_PD_STAGE_LOWRSSI
;
300 if (de_digtable
->pre_cck_pd_state
!= de_digtable
->cur_cck_pd_state
) {
301 if (de_digtable
->cur_cck_pd_state
== CCK_PD_STAGE_LOWRSSI
) {
302 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
303 rtl_set_bbreg(hw
, RCCK0_CCA
, MASKBYTE2
, 0x83);
304 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
306 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
307 rtl_set_bbreg(hw
, RCCK0_CCA
, MASKBYTE2
, 0xcd);
308 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
310 de_digtable
->pre_cck_pd_state
= de_digtable
->cur_cck_pd_state
;
312 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "CurSTAConnectState=%s\n",
313 de_digtable
->cursta_cstate
== DIG_STA_CONNECT
?
314 "DIG_STA_CONNECT " : "DIG_STA_DISCONNECT");
315 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "CCKPDStage=%s\n",
316 de_digtable
->cur_cck_pd_state
== CCK_PD_STAGE_LOWRSSI
?
317 "Low RSSI " : "High RSSI ");
318 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "is92d single phy =%x\n",
319 IS_92D_SINGLEPHY(rtlpriv
->rtlhal
.version
));
323 void rtl92d_dm_write_dig(struct ieee80211_hw
*hw
)
325 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
326 struct dig_t
*de_digtable
= &rtlpriv
->dm_digtable
;
328 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
329 "cur_igvalue = 0x%x, pre_igvalue = 0x%x, back_val = %d\n",
330 de_digtable
->cur_igvalue
, de_digtable
->pre_igvalue
,
331 de_digtable
->back_val
);
332 if (de_digtable
->dig_enable_flag
== false) {
333 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "DIG is disabled\n");
334 de_digtable
->pre_igvalue
= 0x17;
337 if (de_digtable
->pre_igvalue
!= de_digtable
->cur_igvalue
) {
338 rtl_set_bbreg(hw
, ROFDM0_XAAGCCORE1
, 0x7f,
339 de_digtable
->cur_igvalue
);
340 rtl_set_bbreg(hw
, ROFDM0_XBAGCCORE1
, 0x7f,
341 de_digtable
->cur_igvalue
);
342 de_digtable
->pre_igvalue
= de_digtable
->cur_igvalue
;
346 static void rtl92d_early_mode_enabled(struct rtl_priv
*rtlpriv
)
348 struct dig_t
*de_digtable
= &rtlpriv
->dm_digtable
;
350 if ((rtlpriv
->mac80211
.link_state
>= MAC80211_LINKED
) &&
351 (rtlpriv
->mac80211
.vendor
== PEER_CISCO
)) {
352 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "IOT_PEER = CISCO\n");
353 if (de_digtable
->last_min_undec_pwdb_for_dm
>= 50
354 && de_digtable
->min_undec_pwdb_for_dm
< 50) {
355 rtl_write_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
, 0x00);
356 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
358 } else if (de_digtable
->last_min_undec_pwdb_for_dm
<= 55 &&
359 de_digtable
->min_undec_pwdb_for_dm
> 55) {
360 rtl_write_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
, 0x0f);
361 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
364 } else if (!(rtl_read_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
) & 0xf)) {
365 rtl_write_byte(rtlpriv
, REG_EARLY_MODE_CONTROL
, 0x0f);
366 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "Early Mode On\n");
370 static void rtl92d_dm_dig(struct ieee80211_hw
*hw
)
372 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
373 struct dig_t
*de_digtable
= &rtlpriv
->dm_digtable
;
374 u8 value_igi
= de_digtable
->cur_igvalue
;
375 struct false_alarm_statistics
*falsealm_cnt
= &(rtlpriv
->falsealm_cnt
);
377 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "==>\n");
378 if (rtlpriv
->rtlhal
.earlymode_enable
) {
379 rtl92d_early_mode_enabled(rtlpriv
);
380 de_digtable
->last_min_undec_pwdb_for_dm
=
381 de_digtable
->min_undec_pwdb_for_dm
;
383 if (!rtlpriv
->dm
.dm_initialgain_enable
)
386 /* because we will send data pkt when scanning
387 * this will cause some ap like gear-3700 wep TP
388 * lower if we return here, this is the diff of
389 * mac80211 driver vs ieee80211 driver */
390 /* if (rtlpriv->mac80211.act_scanning)
393 /* Not STA mode return tmp */
394 if (rtlpriv
->mac80211
.opmode
!= NL80211_IFTYPE_STATION
)
396 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "progress\n");
397 /* Decide the current status and if modify initial gain or not */
398 if (rtlpriv
->mac80211
.link_state
>= MAC80211_LINKED
)
399 de_digtable
->cursta_cstate
= DIG_STA_CONNECT
;
401 de_digtable
->cursta_cstate
= DIG_STA_DISCONNECT
;
403 /* adjust initial gain according to false alarm counter */
404 if (falsealm_cnt
->cnt_all
< DM_DIG_FA_TH0
)
406 else if (falsealm_cnt
->cnt_all
< DM_DIG_FA_TH1
)
408 else if (falsealm_cnt
->cnt_all
< DM_DIG_FA_TH2
)
410 else if (falsealm_cnt
->cnt_all
>= DM_DIG_FA_TH2
)
412 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
413 "dm_DIG() Before: large_fa_hit=%d, forbidden_igi=%x\n",
414 de_digtable
->large_fa_hit
, de_digtable
->forbidden_igi
);
415 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
416 "dm_DIG() Before: Recover_cnt=%d, rx_gain_min=%x\n",
417 de_digtable
->recover_cnt
, de_digtable
->rx_gain_min
);
419 /* deal with abnormally large false alarm */
420 if (falsealm_cnt
->cnt_all
> 10000) {
421 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
422 "dm_DIG(): Abnormally false alarm case\n");
424 de_digtable
->large_fa_hit
++;
425 if (de_digtable
->forbidden_igi
< de_digtable
->cur_igvalue
) {
426 de_digtable
->forbidden_igi
= de_digtable
->cur_igvalue
;
427 de_digtable
->large_fa_hit
= 1;
429 if (de_digtable
->large_fa_hit
>= 3) {
430 if ((de_digtable
->forbidden_igi
+ 1) > DM_DIG_MAX
)
431 de_digtable
->rx_gain_min
= DM_DIG_MAX
;
433 de_digtable
->rx_gain_min
=
434 (de_digtable
->forbidden_igi
+ 1);
435 de_digtable
->recover_cnt
= 3600; /* 3600=2hr */
438 /* Recovery mechanism for IGI lower bound */
439 if (de_digtable
->recover_cnt
!= 0) {
440 de_digtable
->recover_cnt
--;
442 if (de_digtable
->large_fa_hit
== 0) {
443 if ((de_digtable
->forbidden_igi
- 1) <
445 de_digtable
->forbidden_igi
=
447 de_digtable
->rx_gain_min
=
451 de_digtable
->forbidden_igi
--;
452 de_digtable
->rx_gain_min
=
453 (de_digtable
->forbidden_igi
+ 1);
455 } else if (de_digtable
->large_fa_hit
== 3) {
456 de_digtable
->large_fa_hit
= 0;
460 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
461 "dm_DIG() After: large_fa_hit=%d, forbidden_igi=%x\n",
462 de_digtable
->large_fa_hit
, de_digtable
->forbidden_igi
);
463 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
464 "dm_DIG() After: recover_cnt=%d, rx_gain_min=%x\n",
465 de_digtable
->recover_cnt
, de_digtable
->rx_gain_min
);
467 if (value_igi
> DM_DIG_MAX
)
468 value_igi
= DM_DIG_MAX
;
469 else if (value_igi
< de_digtable
->rx_gain_min
)
470 value_igi
= de_digtable
->rx_gain_min
;
471 de_digtable
->cur_igvalue
= value_igi
;
472 rtl92d_dm_write_dig(hw
);
473 if (rtlpriv
->rtlhal
.current_bandtype
!= BAND_ON_5G
)
474 rtl92d_dm_cck_packet_detection_thresh(hw
);
475 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "<<==\n");
478 static void rtl92d_dm_init_dynamic_txpower(struct ieee80211_hw
*hw
)
480 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
482 rtlpriv
->dm
.dynamic_txpower_enable
= true;
483 rtlpriv
->dm
.last_dtp_lvl
= TXHIGHPWRLEVEL_NORMAL
;
484 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TXHIGHPWRLEVEL_NORMAL
;
487 static void rtl92d_dm_dynamic_txpower(struct ieee80211_hw
*hw
)
489 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
490 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
491 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
492 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
495 if ((!rtlpriv
->dm
.dynamic_txpower_enable
)
496 || rtlpriv
->dm
.dm_flag
& HAL_DM_HIPWR_DISABLE
) {
497 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TXHIGHPWRLEVEL_NORMAL
;
500 if ((mac
->link_state
< MAC80211_LINKED
) &&
501 (rtlpriv
->dm
.UNDEC_SM_PWDB
== 0)) {
502 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_TRACE
,
503 "Not connected to any\n");
504 rtlpriv
->dm
.dynamic_txhighpower_lvl
= TXHIGHPWRLEVEL_NORMAL
;
505 rtlpriv
->dm
.last_dtp_lvl
= TXHIGHPWRLEVEL_NORMAL
;
508 if (mac
->link_state
>= MAC80211_LINKED
) {
509 if (mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
511 rtlpriv
->dm
.UNDEC_SM_PWDB
;
512 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
513 "IBSS Client PWDB = 0x%lx\n",
517 rtlpriv
->dm
.undec_sm_pwdb
;
518 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
519 "STA Default Port PWDB = 0x%lx\n",
524 rtlpriv
->dm
.UNDEC_SM_PWDB
;
526 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
527 "AP Ext Port PWDB = 0x%lx\n",
530 if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
531 if (undec_sm_pwdb
>= 0x33) {
532 rtlpriv
->dm
.dynamic_txhighpower_lvl
=
533 TXHIGHPWRLEVEL_LEVEL2
;
534 RT_TRACE(rtlpriv
, COMP_HIPWR
, DBG_LOUD
,
535 "5G:TxHighPwrLevel_Level2 (TxPwr=0x0)\n");
536 } else if ((undec_sm_pwdb
< 0x33)
537 && (undec_sm_pwdb
>= 0x2b)) {
538 rtlpriv
->dm
.dynamic_txhighpower_lvl
=
539 TXHIGHPWRLEVEL_LEVEL1
;
540 RT_TRACE(rtlpriv
, COMP_HIPWR
, DBG_LOUD
,
541 "5G:TxHighPwrLevel_Level1 (TxPwr=0x10)\n");
542 } else if (undec_sm_pwdb
< 0x2b) {
543 rtlpriv
->dm
.dynamic_txhighpower_lvl
=
544 TXHIGHPWRLEVEL_NORMAL
;
545 RT_TRACE(rtlpriv
, COMP_HIPWR
, DBG_LOUD
,
546 "5G:TxHighPwrLevel_Normal\n");
550 TX_POWER_NEAR_FIELD_THRESH_LVL2
) {
551 rtlpriv
->dm
.dynamic_txhighpower_lvl
=
552 TXHIGHPWRLEVEL_LEVEL2
;
553 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
554 "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x0)\n");
557 (TX_POWER_NEAR_FIELD_THRESH_LVL2
- 3))
559 TX_POWER_NEAR_FIELD_THRESH_LVL1
)) {
561 rtlpriv
->dm
.dynamic_txhighpower_lvl
=
562 TXHIGHPWRLEVEL_LEVEL1
;
563 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
564 "TXHIGHPWRLEVEL_LEVEL1 (TxPwr=0x10)\n");
565 } else if (undec_sm_pwdb
<
566 (TX_POWER_NEAR_FIELD_THRESH_LVL1
- 5)) {
567 rtlpriv
->dm
.dynamic_txhighpower_lvl
=
568 TXHIGHPWRLEVEL_NORMAL
;
569 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
570 "TXHIGHPWRLEVEL_NORMAL\n");
573 if ((rtlpriv
->dm
.dynamic_txhighpower_lvl
!= rtlpriv
->dm
.last_dtp_lvl
)) {
574 RT_TRACE(rtlpriv
, COMP_POWER
, DBG_LOUD
,
575 "PHY_SetTxPowerLevel8192S() Channel = %d\n",
576 rtlphy
->current_channel
);
577 rtl92d_phy_set_txpower_level(hw
, rtlphy
->current_channel
);
579 rtlpriv
->dm
.last_dtp_lvl
= rtlpriv
->dm
.dynamic_txhighpower_lvl
;
582 static void rtl92d_dm_pwdb_monitor(struct ieee80211_hw
*hw
)
584 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
586 /* AP & ADHOC & MESH will return tmp */
587 if (rtlpriv
->mac80211
.opmode
!= NL80211_IFTYPE_STATION
)
589 /* Indicate Rx signal strength to FW. */
590 if (rtlpriv
->dm
.useramask
) {
591 u32 temp
= rtlpriv
->dm
.undec_sm_pwdb
;
595 /* fw v12 cmdid 5:use max macid ,for nic ,
596 * default macid is 0 ,max macid is 1 */
597 rtl92d_fill_h2c_cmd(hw
, H2C_RSSI_REPORT
, 3, (u8
*) (&temp
));
599 rtl_write_byte(rtlpriv
, 0x4fe,
600 (u8
) rtlpriv
->dm
.undec_sm_pwdb
);
604 void rtl92d_dm_init_edca_turbo(struct ieee80211_hw
*hw
)
606 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
608 rtlpriv
->dm
.current_turbo_edca
= false;
609 rtlpriv
->dm
.is_any_nonbepkts
= false;
610 rtlpriv
->dm
.is_cur_rdlstate
= false;
613 static void rtl92d_dm_check_edca_turbo(struct ieee80211_hw
*hw
)
615 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
616 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
617 static u64 last_txok_cnt
;
618 static u64 last_rxok_cnt
;
621 u32 edca_be_ul
= 0x5ea42b;
622 u32 edca_be_dl
= 0x5ea42b;
624 if (mac
->link_state
!= MAC80211_LINKED
) {
625 rtlpriv
->dm
.current_turbo_edca
= false;
629 /* Enable BEQ TxOP limit configuration in wireless G-mode. */
630 /* To check whether we shall force turn on TXOP configuration. */
631 if ((!rtlpriv
->dm
.disable_framebursting
) &&
632 (rtlpriv
->sec
.pairwise_enc_algorithm
== WEP40_ENCRYPTION
||
633 rtlpriv
->sec
.pairwise_enc_algorithm
== WEP104_ENCRYPTION
||
634 rtlpriv
->sec
.pairwise_enc_algorithm
== TKIP_ENCRYPTION
)) {
635 /* Force TxOP limit to 0x005e for UL. */
636 if (!(edca_be_ul
& 0xffff0000))
637 edca_be_ul
|= 0x005e0000;
638 /* Force TxOP limit to 0x005e for DL. */
639 if (!(edca_be_dl
& 0xffff0000))
640 edca_be_dl
|= 0x005e0000;
643 if ((!rtlpriv
->dm
.is_any_nonbepkts
) &&
644 (!rtlpriv
->dm
.disable_framebursting
)) {
645 cur_txok_cnt
= rtlpriv
->stats
.txbytesunicast
- last_txok_cnt
;
646 cur_rxok_cnt
= rtlpriv
->stats
.rxbytesunicast
- last_rxok_cnt
;
647 if (cur_rxok_cnt
> 4 * cur_txok_cnt
) {
648 if (!rtlpriv
->dm
.is_cur_rdlstate
||
649 !rtlpriv
->dm
.current_turbo_edca
) {
650 rtl_write_dword(rtlpriv
, REG_EDCA_BE_PARAM
,
652 rtlpriv
->dm
.is_cur_rdlstate
= true;
655 if (rtlpriv
->dm
.is_cur_rdlstate
||
656 !rtlpriv
->dm
.current_turbo_edca
) {
657 rtl_write_dword(rtlpriv
, REG_EDCA_BE_PARAM
,
659 rtlpriv
->dm
.is_cur_rdlstate
= false;
662 rtlpriv
->dm
.current_turbo_edca
= true;
664 if (rtlpriv
->dm
.current_turbo_edca
) {
666 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AC_PARAM
,
668 rtlpriv
->dm
.current_turbo_edca
= false;
673 rtlpriv
->dm
.is_any_nonbepkts
= false;
674 last_txok_cnt
= rtlpriv
->stats
.txbytesunicast
;
675 last_rxok_cnt
= rtlpriv
->stats
.rxbytesunicast
;
678 static void rtl92d_dm_rxgain_tracking_thermalmeter(struct ieee80211_hw
*hw
)
680 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
681 u8 index_mapping
[RX_INDEX_MAPPING_NUM
] = {
682 0x0f, 0x0f, 0x0d, 0x0c, 0x0b,
683 0x0a, 0x09, 0x08, 0x07, 0x06,
684 0x05, 0x04, 0x04, 0x03, 0x02
689 u4tmp
= (index_mapping
[(rtlpriv
->efuse
.eeprom_thermalmeter
-
690 rtlpriv
->dm
.thermalvalue_rxgain
)]) << 12;
691 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
692 "===> Rx Gain %x\n", u4tmp
);
693 for (i
= RF90_PATH_A
; i
< rtlpriv
->phy
.num_total_rfpath
; i
++)
694 rtl_set_rfreg(hw
, i
, 0x3C, RFREG_OFFSET_MASK
,
695 (rtlpriv
->phy
.reg_rf3c
[i
] & (~(0xF000))) | u4tmp
);
698 static void rtl92d_bandtype_2_4G(struct ieee80211_hw
*hw
, long *temp_cckg
,
701 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
703 unsigned long flag
= 0;
706 /* Query CCK default setting From 0xa24 */
707 rtl92d_acquire_cckandrw_pagea_ctl(hw
, &flag
);
708 temp_cck
= rtl_get_bbreg(hw
, RCCK0_TXFILTER2
,
709 MASKDWORD
) & MASKCCK
;
710 rtl92d_release_cckandrw_pagea_ctl(hw
, &flag
);
711 for (i
= 0; i
< CCK_TABLE_LENGTH
; i
++) {
712 if (rtlpriv
->dm
.cck_inch14
) {
713 if (!memcmp((void *)&temp_cck
,
714 (void *)&cckswing_table_ch14
[i
][2], 4)) {
715 *cck_index_old
= (u8
) i
;
716 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
717 "Initial reg0x%x = 0x%lx, cck_index=0x%x, ch 14 %d\n",
718 RCCK0_TXFILTER2
, temp_cck
,
720 rtlpriv
->dm
.cck_inch14
);
724 if (!memcmp((void *) &temp_cck
,
725 &cckswing_table_ch1ch13
[i
][2], 4)) {
726 *cck_index_old
= (u8
) i
;
727 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
728 "Initial reg0x%x = 0x%lx, cck_index = 0x%x, ch14 %d\n",
729 RCCK0_TXFILTER2
, temp_cck
,
731 rtlpriv
->dm
.cck_inch14
);
736 *temp_cckg
= temp_cck
;
739 static void rtl92d_bandtype_5G(struct rtl_hal
*rtlhal
, u8
*ofdm_index
,
740 bool *internal_pa
, u8 thermalvalue
, u8 delta
,
741 u8 rf
, struct rtl_efuse
*rtlefuse
,
742 struct rtl_priv
*rtlpriv
, struct rtl_phy
*rtlphy
,
743 u8 index_mapping
[5][INDEX_MAPPING_NUM
],
744 u8 index_mapping_pa
[8][INDEX_MAPPING_NUM
])
750 for (i
= 0; i
< rf
; i
++) {
751 if (rtlhal
->macphymode
== DUALMAC_DUALPHY
&&
752 rtlhal
->interfaceindex
== 1) /* MAC 1 5G */
753 *internal_pa
= rtlefuse
->internal_pa_5g
[1];
755 *internal_pa
= rtlefuse
->internal_pa_5g
[i
];
757 if (rtlhal
->interfaceindex
== 1 || i
== rf
)
761 if (rtlphy
->current_channel
>= 100 &&
762 rtlphy
->current_channel
<= 165)
765 if (rtlhal
->interfaceindex
== 1 || i
== rf
)
770 if (thermalvalue
> rtlefuse
->eeprom_thermalmeter
)
773 if (delta
> INDEX_MAPPING_NUM
- 1)
774 index
= index_mapping_pa
[offset
]
775 [INDEX_MAPPING_NUM
- 1];
778 index_mapping_pa
[offset
][delta
];
780 if (delta
> INDEX_MAPPING_NUM
- 1)
782 index_mapping
[offset
][INDEX_MAPPING_NUM
- 1];
784 index
= index_mapping
[offset
][delta
];
786 if (thermalvalue
> rtlefuse
->eeprom_thermalmeter
) {
787 if (*internal_pa
&& thermalvalue
> 0x12) {
788 ofdm_index
[i
] = rtlpriv
->dm
.ofdm_index
[i
] -
789 ((delta
/ 2) * 3 + (delta
% 2));
791 ofdm_index
[i
] -= index
;
794 ofdm_index
[i
] += index
;
799 static void rtl92d_dm_txpower_tracking_callback_thermalmeter(
800 struct ieee80211_hw
*hw
)
802 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
803 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
804 struct rtl_phy
*rtlphy
= &(rtlpriv
->phy
);
805 struct rtl_efuse
*rtlefuse
= rtl_efuse(rtl_priv(hw
));
806 u8 thermalvalue
, delta
, delta_lck
, delta_iqk
, delta_rxgain
;
807 u8 offset
, thermalvalue_avg_count
= 0;
808 u32 thermalvalue_avg
= 0;
809 bool internal_pa
= false;
810 long ele_a
= 0, ele_d
, temp_cck
, val_x
, value32
;
811 long val_y
, ele_c
= 0;
814 u8 ofdm_index_old
[3] = {0, 0, 0};
815 s8 cck_index_old
= 0;
818 bool is2t
= IS_92D_SINGLEPHY(rtlhal
->version
);
819 u8 ofdm_min_index
= 6, ofdm_min_index_internal_pa
= 3, rf
;
821 rtl92d_get_rightchnlplace_for_iqk(rtlphy
->current_channel
);
822 u8 index_mapping
[5][INDEX_MAPPING_NUM
] = {
823 /* 5G, path A/MAC 0, decrease power */
824 {0, 1, 3, 6, 8, 9, 11, 13, 14, 16, 17, 18, 18},
825 /* 5G, path A/MAC 0, increase power */
826 {0, 2, 4, 5, 7, 10, 12, 14, 16, 18, 18, 18, 18},
827 /* 5G, path B/MAC 1, decrease power */
828 {0, 2, 3, 6, 8, 9, 11, 13, 14, 16, 17, 18, 18},
829 /* 5G, path B/MAC 1, increase power */
830 {0, 2, 4, 5, 7, 10, 13, 16, 16, 18, 18, 18, 18},
831 /* 2.4G, for decreas power */
832 {0, 1, 2, 3, 4, 5, 6, 7, 7, 8, 9, 10, 10},
834 u8 index_mapping_internal_pa
[8][INDEX_MAPPING_NUM
] = {
835 /* 5G, path A/MAC 0, ch36-64, decrease power */
836 {0, 1, 2, 4, 6, 7, 9, 11, 12, 14, 15, 16, 16},
837 /* 5G, path A/MAC 0, ch36-64, increase power */
838 {0, 2, 4, 5, 7, 10, 12, 14, 16, 18, 18, 18, 18},
839 /* 5G, path A/MAC 0, ch100-165, decrease power */
840 {0, 1, 2, 3, 5, 6, 8, 10, 11, 13, 14, 15, 15},
841 /* 5G, path A/MAC 0, ch100-165, increase power */
842 {0, 2, 4, 5, 7, 10, 12, 14, 16, 18, 18, 18, 18},
843 /* 5G, path B/MAC 1, ch36-64, decrease power */
844 {0, 1, 2, 4, 6, 7, 9, 11, 12, 14, 15, 16, 16},
845 /* 5G, path B/MAC 1, ch36-64, increase power */
846 {0, 2, 4, 5, 7, 10, 13, 16, 16, 18, 18, 18, 18},
847 /* 5G, path B/MAC 1, ch100-165, decrease power */
848 {0, 1, 2, 3, 5, 6, 8, 9, 10, 12, 13, 14, 14},
849 /* 5G, path B/MAC 1, ch100-165, increase power */
850 {0, 2, 4, 5, 7, 10, 13, 16, 16, 18, 18, 18, 18},
853 rtlpriv
->dm
.txpower_trackinginit
= true;
854 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
, "\n");
855 thermalvalue
= (u8
) rtl_get_rfreg(hw
, RF90_PATH_A
, RF_T_METER
, 0xf800);
856 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
857 "Readback Thermal Meter = 0x%x pre thermal meter 0x%x eeprom_thermalmeter 0x%x\n",
859 rtlpriv
->dm
.thermalvalue
, rtlefuse
->eeprom_thermalmeter
);
860 rtl92d_phy_ap_calibrate(hw
, (thermalvalue
-
861 rtlefuse
->eeprom_thermalmeter
));
867 ele_d
= rtl_get_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
,
868 MASKDWORD
) & MASKOFDM_D
;
869 for (i
= 0; i
< OFDM_TABLE_SIZE_92D
; i
++) {
870 if (ele_d
== (ofdmswing_table
[i
] & MASKOFDM_D
)) {
871 ofdm_index_old
[0] = (u8
) i
;
873 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
874 "Initial pathA ele_d reg0x%x = 0x%lx, ofdm_index=0x%x\n",
875 ROFDM0_XATxIQIMBALANCE
,
876 ele_d
, ofdm_index_old
[0]);
881 ele_d
= rtl_get_bbreg(hw
, ROFDM0_XBTxIQIMBALANCE
,
882 MASKDWORD
) & MASKOFDM_D
;
883 for (i
= 0; i
< OFDM_TABLE_SIZE_92D
; i
++) {
885 (ofdmswing_table
[i
] & MASKOFDM_D
)) {
886 ofdm_index_old
[1] = (u8
) i
;
887 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
,
889 "Initial pathB ele_d reg 0x%x = 0x%lx, ofdm_index = 0x%x\n",
890 ROFDM0_XBTxIQIMBALANCE
, ele_d
,
896 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
897 rtl92d_bandtype_2_4G(hw
, &temp_cck
, &cck_index_old
);
899 temp_cck
= 0x090e1317;
903 if (!rtlpriv
->dm
.thermalvalue
) {
904 rtlpriv
->dm
.thermalvalue
=
905 rtlefuse
->eeprom_thermalmeter
;
906 rtlpriv
->dm
.thermalvalue_lck
= thermalvalue
;
907 rtlpriv
->dm
.thermalvalue_iqk
= thermalvalue
;
908 rtlpriv
->dm
.thermalvalue_rxgain
=
909 rtlefuse
->eeprom_thermalmeter
;
910 for (i
= 0; i
< rf
; i
++)
911 rtlpriv
->dm
.ofdm_index
[i
] = ofdm_index_old
[i
];
912 rtlpriv
->dm
.cck_index
= cck_index_old
;
914 if (rtlhal
->reloadtxpowerindex
) {
915 for (i
= 0; i
< rf
; i
++)
916 rtlpriv
->dm
.ofdm_index
[i
] = ofdm_index_old
[i
];
917 rtlpriv
->dm
.cck_index
= cck_index_old
;
918 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
919 "reload ofdm index for band switch\n");
921 rtlpriv
->dm
.thermalvalue_avg
922 [rtlpriv
->dm
.thermalvalue_avg_index
] = thermalvalue
;
923 rtlpriv
->dm
.thermalvalue_avg_index
++;
924 if (rtlpriv
->dm
.thermalvalue_avg_index
== AVG_THERMAL_NUM
)
925 rtlpriv
->dm
.thermalvalue_avg_index
= 0;
926 for (i
= 0; i
< AVG_THERMAL_NUM
; i
++) {
927 if (rtlpriv
->dm
.thermalvalue_avg
[i
]) {
929 rtlpriv
->dm
.thermalvalue_avg
[i
];
930 thermalvalue_avg_count
++;
933 if (thermalvalue_avg_count
)
934 thermalvalue
= (u8
) (thermalvalue_avg
/
935 thermalvalue_avg_count
);
936 if (rtlhal
->reloadtxpowerindex
) {
937 delta
= (thermalvalue
> rtlefuse
->eeprom_thermalmeter
) ?
938 (thermalvalue
- rtlefuse
->eeprom_thermalmeter
) :
939 (rtlefuse
->eeprom_thermalmeter
- thermalvalue
);
940 rtlhal
->reloadtxpowerindex
= false;
941 rtlpriv
->dm
.done_txpower
= false;
942 } else if (rtlpriv
->dm
.done_txpower
) {
943 delta
= (thermalvalue
> rtlpriv
->dm
.thermalvalue
) ?
944 (thermalvalue
- rtlpriv
->dm
.thermalvalue
) :
945 (rtlpriv
->dm
.thermalvalue
- thermalvalue
);
947 delta
= (thermalvalue
> rtlefuse
->eeprom_thermalmeter
) ?
948 (thermalvalue
- rtlefuse
->eeprom_thermalmeter
) :
949 (rtlefuse
->eeprom_thermalmeter
- thermalvalue
);
951 delta_lck
= (thermalvalue
> rtlpriv
->dm
.thermalvalue_lck
) ?
952 (thermalvalue
- rtlpriv
->dm
.thermalvalue_lck
) :
953 (rtlpriv
->dm
.thermalvalue_lck
- thermalvalue
);
954 delta_iqk
= (thermalvalue
> rtlpriv
->dm
.thermalvalue_iqk
) ?
955 (thermalvalue
- rtlpriv
->dm
.thermalvalue_iqk
) :
956 (rtlpriv
->dm
.thermalvalue_iqk
- thermalvalue
);
958 (thermalvalue
> rtlpriv
->dm
.thermalvalue_rxgain
) ?
959 (thermalvalue
- rtlpriv
->dm
.thermalvalue_rxgain
) :
960 (rtlpriv
->dm
.thermalvalue_rxgain
- thermalvalue
);
961 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
962 "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",
963 thermalvalue
, rtlpriv
->dm
.thermalvalue
,
964 rtlefuse
->eeprom_thermalmeter
, delta
, delta_lck
,
966 if ((delta_lck
> rtlefuse
->delta_lck
) &&
967 (rtlefuse
->delta_lck
!= 0)) {
968 rtlpriv
->dm
.thermalvalue_lck
= thermalvalue
;
969 rtl92d_phy_lc_calibrate(hw
);
971 if (delta
> 0 && rtlpriv
->dm
.txpower_track_control
) {
972 rtlpriv
->dm
.done_txpower
= true;
973 delta
= (thermalvalue
> rtlefuse
->eeprom_thermalmeter
) ?
974 (thermalvalue
- rtlefuse
->eeprom_thermalmeter
) :
975 (rtlefuse
->eeprom_thermalmeter
- thermalvalue
);
976 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
978 if (delta
> INDEX_MAPPING_NUM
- 1)
979 index
= index_mapping
[offset
]
980 [INDEX_MAPPING_NUM
- 1];
982 index
= index_mapping
[offset
][delta
];
983 if (thermalvalue
> rtlpriv
->dm
.thermalvalue
) {
984 for (i
= 0; i
< rf
; i
++)
985 ofdm_index
[i
] -= delta
;
988 for (i
= 0; i
< rf
; i
++)
989 ofdm_index
[i
] += index
;
992 } else if (rtlhal
->current_bandtype
== BAND_ON_5G
) {
993 rtl92d_bandtype_5G(rtlhal
, ofdm_index
,
994 &internal_pa
, thermalvalue
,
995 delta
, rf
, rtlefuse
, rtlpriv
,
996 rtlphy
, index_mapping
,
997 index_mapping_internal_pa
);
1000 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
1001 "temp OFDM_A_index=0x%x, OFDM_B_index = 0x%x,cck_index=0x%x\n",
1002 rtlpriv
->dm
.ofdm_index
[0],
1003 rtlpriv
->dm
.ofdm_index
[1],
1004 rtlpriv
->dm
.cck_index
);
1006 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
1007 "temp OFDM_A_index=0x%x,cck_index = 0x%x\n",
1008 rtlpriv
->dm
.ofdm_index
[0],
1009 rtlpriv
->dm
.cck_index
);
1011 for (i
= 0; i
< rf
; i
++) {
1012 if (ofdm_index
[i
] > OFDM_TABLE_SIZE_92D
- 1)
1013 ofdm_index
[i
] = OFDM_TABLE_SIZE_92D
- 1;
1014 else if (ofdm_index
[i
] < ofdm_min_index
)
1015 ofdm_index
[i
] = ofdm_min_index
;
1017 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1018 if (cck_index
> CCK_TABLE_SIZE
- 1) {
1019 cck_index
= CCK_TABLE_SIZE
- 1;
1020 } else if (internal_pa
||
1021 rtlhal
->current_bandtype
==
1024 ofdm_min_index_internal_pa
)
1026 ofdm_min_index_internal_pa
;
1027 } else if (cck_index
< 0) {
1032 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
1033 "new OFDM_A_index=0x%x, OFDM_B_index = 0x%x, cck_index=0x%x\n",
1034 ofdm_index
[0], ofdm_index
[1],
1037 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
1038 "new OFDM_A_index=0x%x,cck_index = 0x%x\n",
1039 ofdm_index
[0], cck_index
);
1041 ele_d
= (ofdmswing_table
[(u8
) ofdm_index
[0]] &
1043 val_x
= rtlphy
->iqk_matrix
1044 [indexforchannel
].value
[0][0];
1045 val_y
= rtlphy
->iqk_matrix
1046 [indexforchannel
].value
[0][1];
1048 if ((val_x
& 0x00000200) != 0)
1049 val_x
= val_x
| 0xFFFFFC00;
1051 ((val_x
* ele_d
) >> 8) & 0x000003FF;
1053 /* new element C = element D x Y */
1054 if ((val_y
& 0x00000200) != 0)
1055 val_y
= val_y
| 0xFFFFFC00;
1056 ele_c
= ((val_y
* ele_d
) >> 8) & 0x000003FF;
1058 /* wirte new elements A, C, D to regC80 and
1059 * regC94, element B is always 0 */
1060 value32
= (ele_d
<< 22) | ((ele_c
& 0x3F) <<
1062 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
,
1063 MASKDWORD
, value32
);
1065 value32
= (ele_c
& 0x000003C0) >> 6;
1066 rtl_set_bbreg(hw
, ROFDM0_XCTxAFE
, MASKH4BITS
,
1069 value32
= ((val_x
* ele_d
) >> 7) & 0x01;
1070 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
, BIT(24),
1074 rtl_set_bbreg(hw
, ROFDM0_XATxIQIMBALANCE
,
1077 [(u8
)ofdm_index
[0]]);
1078 rtl_set_bbreg(hw
, ROFDM0_XCTxAFE
, MASKH4BITS
,
1080 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
,
1084 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
1085 "TxPwrTracking for interface %d path A: X = 0x%lx, Y = 0x%lx ele_A = 0x%lx ele_C = 0x%lx ele_D = 0x%lx 0xe94 = 0x%lx 0xe9c = 0x%lx\n",
1086 rtlhal
->interfaceindex
,
1087 val_x
, val_y
, ele_a
, ele_c
, ele_d
,
1090 if (cck_index
>= CCK_TABLE_SIZE
)
1091 cck_index
= CCK_TABLE_SIZE
- 1;
1094 if (rtlhal
->current_bandtype
== BAND_ON_2_4G
) {
1095 /* Adjust CCK according to IQK result */
1096 if (!rtlpriv
->dm
.cck_inch14
) {
1097 rtl_write_byte(rtlpriv
, 0xa22,
1098 cckswing_table_ch1ch13
1099 [(u8
)cck_index
][0]);
1100 rtl_write_byte(rtlpriv
, 0xa23,
1101 cckswing_table_ch1ch13
1102 [(u8
)cck_index
][1]);
1103 rtl_write_byte(rtlpriv
, 0xa24,
1104 cckswing_table_ch1ch13
1105 [(u8
)cck_index
][2]);
1106 rtl_write_byte(rtlpriv
, 0xa25,
1107 cckswing_table_ch1ch13
1108 [(u8
)cck_index
][3]);
1109 rtl_write_byte(rtlpriv
, 0xa26,
1110 cckswing_table_ch1ch13
1111 [(u8
)cck_index
][4]);
1112 rtl_write_byte(rtlpriv
, 0xa27,
1113 cckswing_table_ch1ch13
1114 [(u8
)cck_index
][5]);
1115 rtl_write_byte(rtlpriv
, 0xa28,
1116 cckswing_table_ch1ch13
1117 [(u8
)cck_index
][6]);
1118 rtl_write_byte(rtlpriv
, 0xa29,
1119 cckswing_table_ch1ch13
1120 [(u8
)cck_index
][7]);
1122 rtl_write_byte(rtlpriv
, 0xa22,
1124 [(u8
)cck_index
][0]);
1125 rtl_write_byte(rtlpriv
, 0xa23,
1127 [(u8
)cck_index
][1]);
1128 rtl_write_byte(rtlpriv
, 0xa24,
1130 [(u8
)cck_index
][2]);
1131 rtl_write_byte(rtlpriv
, 0xa25,
1133 [(u8
)cck_index
][3]);
1134 rtl_write_byte(rtlpriv
, 0xa26,
1136 [(u8
)cck_index
][4]);
1137 rtl_write_byte(rtlpriv
, 0xa27,
1139 [(u8
)cck_index
][5]);
1140 rtl_write_byte(rtlpriv
, 0xa28,
1142 [(u8
)cck_index
][6]);
1143 rtl_write_byte(rtlpriv
, 0xa29,
1145 [(u8
)cck_index
][7]);
1149 ele_d
= (ofdmswing_table
[(u8
) ofdm_index
[1]] &
1151 val_x
= rtlphy
->iqk_matrix
1152 [indexforchannel
].value
[0][4];
1153 val_y
= rtlphy
->iqk_matrix
1154 [indexforchannel
].value
[0][5];
1156 if ((val_x
& 0x00000200) != 0)
1157 /* consider minus */
1158 val_x
= val_x
| 0xFFFFFC00;
1159 ele_a
= ((val_x
* ele_d
) >> 8) &
1161 /* new element C = element D x Y */
1162 if ((val_y
& 0x00000200) != 0)
1167 ele_d
) >> 8) & 0x00003FF;
1168 /* write new elements A, C, D to regC88
1169 * and regC9C, element B is always 0
1171 value32
= (ele_d
<< 22) |
1172 ((ele_c
& 0x3F) << 16) |
1175 ROFDM0_XBTxIQIMBALANCE
,
1176 MASKDWORD
, value32
);
1177 value32
= (ele_c
& 0x000003C0) >> 6;
1178 rtl_set_bbreg(hw
, ROFDM0_XDTxAFE
,
1179 MASKH4BITS
, value32
);
1180 value32
= ((val_x
* ele_d
) >> 7) & 0x01;
1181 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
,
1185 ROFDM0_XBTxIQIMBALANCE
,
1188 [(u8
) ofdm_index
[1]]);
1189 rtl_set_bbreg(hw
, ROFDM0_XDTxAFE
,
1191 rtl_set_bbreg(hw
, ROFDM0_ECCATHRESHOLD
,
1194 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
1195 "TxPwrTracking path B: X = 0x%lx, Y = 0x%lx ele_A = 0x%lx ele_C = 0x%lx ele_D = 0x%lx 0xeb4 = 0x%lx 0xebc = 0x%lx\n",
1196 val_x
, val_y
, ele_a
, ele_c
,
1197 ele_d
, val_x
, val_y
);
1199 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
1200 "TxPwrTracking 0xc80 = 0x%x, 0xc94 = 0x%x RF 0x24 = 0x%x\n",
1201 rtl_get_bbreg(hw
, 0xc80, MASKDWORD
),
1202 rtl_get_bbreg(hw
, 0xc94, MASKDWORD
),
1203 rtl_get_rfreg(hw
, RF90_PATH_A
, 0x24,
1204 RFREG_OFFSET_MASK
));
1206 if ((delta_iqk
> rtlefuse
->delta_iqk
) &&
1207 (rtlefuse
->delta_iqk
!= 0)) {
1208 rtl92d_phy_reset_iqk_result(hw
);
1209 rtlpriv
->dm
.thermalvalue_iqk
= thermalvalue
;
1210 rtl92d_phy_iq_calibrate(hw
);
1212 if (delta_rxgain
> 0 && rtlhal
->current_bandtype
== BAND_ON_5G
1213 && thermalvalue
<= rtlefuse
->eeprom_thermalmeter
) {
1214 rtlpriv
->dm
.thermalvalue_rxgain
= thermalvalue
;
1215 rtl92d_dm_rxgain_tracking_thermalmeter(hw
);
1217 if (rtlpriv
->dm
.txpower_track_control
)
1218 rtlpriv
->dm
.thermalvalue
= thermalvalue
;
1221 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
, "<===\n");
1224 static void rtl92d_dm_initialize_txpower_tracking(struct ieee80211_hw
*hw
)
1226 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1228 rtlpriv
->dm
.txpower_tracking
= true;
1229 rtlpriv
->dm
.txpower_trackinginit
= false;
1230 rtlpriv
->dm
.txpower_track_control
= true;
1231 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
1232 "pMgntInfo->txpower_tracking = %d\n",
1233 rtlpriv
->dm
.txpower_tracking
);
1236 void rtl92d_dm_check_txpower_tracking_thermal_meter(struct ieee80211_hw
*hw
)
1238 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1240 if (!rtlpriv
->dm
.txpower_tracking
)
1243 if (!rtlpriv
->dm
.tm_trigger
) {
1244 rtl_set_rfreg(hw
, RF90_PATH_A
, RF_T_METER
, BIT(17) |
1246 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
1247 "Trigger 92S Thermal Meter!!\n");
1248 rtlpriv
->dm
.tm_trigger
= 1;
1251 RT_TRACE(rtlpriv
, COMP_POWER_TRACKING
, DBG_LOUD
,
1252 "Schedule TxPowerTracking direct call!!\n");
1253 rtl92d_dm_txpower_tracking_callback_thermalmeter(hw
);
1254 rtlpriv
->dm
.tm_trigger
= 0;
1258 void rtl92d_dm_init_rate_adaptive_mask(struct ieee80211_hw
*hw
)
1260 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1261 struct rate_adaptive
*ra
= &(rtlpriv
->ra
);
1263 ra
->ratr_state
= DM_RATR_STA_INIT
;
1264 ra
->pre_ratr_state
= DM_RATR_STA_INIT
;
1265 if (rtlpriv
->dm
.dm_type
== DM_TYPE_BYDRIVER
)
1266 rtlpriv
->dm
.useramask
= true;
1268 rtlpriv
->dm
.useramask
= false;
1271 void rtl92d_dm_init(struct ieee80211_hw
*hw
)
1273 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1275 rtlpriv
->dm
.dm_type
= DM_TYPE_BYDRIVER
;
1276 rtl_dm_diginit(hw
, 0x20);
1277 rtlpriv
->dm_digtable
.rx_gain_max
= DM_DIG_FA_UPPER
;
1278 rtlpriv
->dm_digtable
.rx_gain_min
= DM_DIG_FA_LOWER
;
1279 rtl92d_dm_init_dynamic_txpower(hw
);
1280 rtl92d_dm_init_edca_turbo(hw
);
1281 rtl92d_dm_init_rate_adaptive_mask(hw
);
1282 rtl92d_dm_initialize_txpower_tracking(hw
);
1285 void rtl92d_dm_watchdog(struct ieee80211_hw
*hw
)
1287 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1288 bool fw_current_inpsmode
= false;
1289 bool fwps_awake
= true;
1291 /* 1. RF is OFF. (No need to do DM.)
1292 * 2. Fw is under power saving mode for FwLPS.
1293 * (Prevent from SW/FW I/O racing.)
1294 * 3. IPS workitem is scheduled. (Prevent from IPS sequence
1295 * to be swapped with DM.
1296 * 4. RFChangeInProgress is TRUE.
1297 * (Prevent from broken by IPS/HW/SW Rf off.) */
1299 if ((ppsc
->rfpwr_state
== ERFON
) && ((!fw_current_inpsmode
) &&
1300 fwps_awake
) && (!ppsc
->rfchange_inprogress
)) {
1301 rtl92d_dm_pwdb_monitor(hw
);
1302 rtl92d_dm_false_alarm_counter_statistics(hw
);
1303 rtl92d_dm_find_minimum_rssi(hw
);
1305 /* rtl92d_dm_dynamic_bb_powersaving(hw); */
1306 rtl92d_dm_dynamic_txpower(hw
);
1307 /* rtl92d_dm_check_txpower_tracking_thermal_meter(hw); */
1308 /* rtl92d_dm_refresh_rate_adaptive_mask(hw); */
1309 /* rtl92d_dm_interrupt_migration(hw); */
1310 rtl92d_dm_check_edca_turbo(hw
);