1 /******************************************************************************
3 * Copyright(c) 2009-2014 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 *****************************************************************************/
37 static const u32 ofdmswing_table
[OFDM_TABLE_SIZE
] = {
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 rtl92ee_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
;
161 rtl_set_bbreg(hw
, DM_REG_OFDM_FA_HOLDC_11N
, BIT(31), 1);
162 rtl_set_bbreg(hw
, DM_REG_OFDM_FA_RSTD_11N
, BIT(31), 1);
164 ret_value
= rtl_get_bbreg(hw
, DM_REG_OFDM_FA_TYPE1_11N
, MASKDWORD
);
165 falsealm_cnt
->cnt_fast_fsync_fail
= (ret_value
& 0xffff);
166 falsealm_cnt
->cnt_sb_search_fail
= ((ret_value
& 0xffff0000) >> 16);
168 ret_value
= rtl_get_bbreg(hw
, DM_REG_OFDM_FA_TYPE2_11N
, MASKDWORD
);
169 falsealm_cnt
->cnt_ofdm_cca
= (ret_value
& 0xffff);
170 falsealm_cnt
->cnt_parity_fail
= ((ret_value
& 0xffff0000) >> 16);
172 ret_value
= rtl_get_bbreg(hw
, DM_REG_OFDM_FA_TYPE3_11N
, MASKDWORD
);
173 falsealm_cnt
->cnt_rate_illegal
= (ret_value
& 0xffff);
174 falsealm_cnt
->cnt_crc8_fail
= ((ret_value
& 0xffff0000) >> 16);
176 ret_value
= rtl_get_bbreg(hw
, DM_REG_OFDM_FA_TYPE4_11N
, MASKDWORD
);
177 falsealm_cnt
->cnt_mcs_fail
= (ret_value
& 0xffff);
179 falsealm_cnt
->cnt_ofdm_fail
= falsealm_cnt
->cnt_parity_fail
+
180 falsealm_cnt
->cnt_rate_illegal
+
181 falsealm_cnt
->cnt_crc8_fail
+
182 falsealm_cnt
->cnt_mcs_fail
+
183 falsealm_cnt
->cnt_fast_fsync_fail
+
184 falsealm_cnt
->cnt_sb_search_fail
;
186 ret_value
= rtl_get_bbreg(hw
, DM_REG_SC_CNT_11N
, MASKDWORD
);
187 falsealm_cnt
->cnt_bw_lsc
= (ret_value
& 0xffff);
188 falsealm_cnt
->cnt_bw_usc
= ((ret_value
& 0xffff0000) >> 16);
190 rtl_set_bbreg(hw
, DM_REG_CCK_FA_RST_11N
, BIT(12), 1);
191 rtl_set_bbreg(hw
, DM_REG_CCK_FA_RST_11N
, BIT(14), 1);
193 ret_value
= rtl_get_bbreg(hw
, DM_REG_CCK_FA_LSB_11N
, MASKBYTE0
);
194 falsealm_cnt
->cnt_cck_fail
= ret_value
;
196 ret_value
= rtl_get_bbreg(hw
, DM_REG_CCK_FA_MSB_11N
, MASKBYTE3
);
197 falsealm_cnt
->cnt_cck_fail
+= (ret_value
& 0xff) << 8;
199 ret_value
= rtl_get_bbreg(hw
, DM_REG_CCK_CCA_CNT_11N
, MASKDWORD
);
200 falsealm_cnt
->cnt_cck_cca
= ((ret_value
& 0xff) << 8) |
201 ((ret_value
& 0xFF00) >> 8);
203 falsealm_cnt
->cnt_all
= falsealm_cnt
->cnt_fast_fsync_fail
+
204 falsealm_cnt
->cnt_sb_search_fail
+
205 falsealm_cnt
->cnt_parity_fail
+
206 falsealm_cnt
->cnt_rate_illegal
+
207 falsealm_cnt
->cnt_crc8_fail
+
208 falsealm_cnt
->cnt_mcs_fail
+
209 falsealm_cnt
->cnt_cck_fail
;
211 falsealm_cnt
->cnt_cca_all
= falsealm_cnt
->cnt_ofdm_cca
+
212 falsealm_cnt
->cnt_cck_cca
;
214 /*reset false alarm counter registers*/
215 rtl_set_bbreg(hw
, DM_REG_OFDM_FA_RSTC_11N
, BIT(31), 1);
216 rtl_set_bbreg(hw
, DM_REG_OFDM_FA_RSTC_11N
, BIT(31), 0);
217 rtl_set_bbreg(hw
, DM_REG_OFDM_FA_RSTD_11N
, BIT(27), 1);
218 rtl_set_bbreg(hw
, DM_REG_OFDM_FA_RSTD_11N
, BIT(27), 0);
219 /*update ofdm counter*/
220 rtl_set_bbreg(hw
, DM_REG_OFDM_FA_HOLDC_11N
, BIT(31), 0);
221 rtl_set_bbreg(hw
, DM_REG_OFDM_FA_RSTD_11N
, BIT(31), 0);
222 /*reset CCK CCA counter*/
223 rtl_set_bbreg(hw
, DM_REG_CCK_FA_RST_11N
, BIT(13) | BIT(12), 0);
224 rtl_set_bbreg(hw
, DM_REG_CCK_FA_RST_11N
, BIT(13) | BIT(12), 2);
225 /*reset CCK FA counter*/
226 rtl_set_bbreg(hw
, DM_REG_CCK_FA_RST_11N
, BIT(15) | BIT(14), 0);
227 rtl_set_bbreg(hw
, DM_REG_CCK_FA_RST_11N
, BIT(15) | BIT(14), 2);
229 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_TRACE
,
230 "cnt_parity_fail = %d, cnt_rate_illegal = %d, cnt_crc8_fail = %d, cnt_mcs_fail = %d\n",
231 falsealm_cnt
->cnt_parity_fail
,
232 falsealm_cnt
->cnt_rate_illegal
,
233 falsealm_cnt
->cnt_crc8_fail
, falsealm_cnt
->cnt_mcs_fail
);
235 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_TRACE
,
236 "cnt_ofdm_fail = %x, cnt_cck_fail = %x, cnt_all = %x\n",
237 falsealm_cnt
->cnt_ofdm_fail
,
238 falsealm_cnt
->cnt_cck_fail
, falsealm_cnt
->cnt_all
);
241 static void rtl92ee_dm_cck_packet_detection_thresh(struct ieee80211_hw
*hw
)
243 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
244 struct dig_t
*dm_dig
= &rtlpriv
->dm_digtable
;
245 u8 cur_cck_cca_thresh
;
247 if (rtlpriv
->mac80211
.link_state
>= MAC80211_LINKED
) {
248 if (dm_dig
->rssi_val_min
> 25) {
249 cur_cck_cca_thresh
= 0xcd;
250 } else if ((dm_dig
->rssi_val_min
<= 25) &&
251 (dm_dig
->rssi_val_min
> 10)) {
252 cur_cck_cca_thresh
= 0x83;
254 if (rtlpriv
->falsealm_cnt
.cnt_cck_fail
> 1000)
255 cur_cck_cca_thresh
= 0x83;
257 cur_cck_cca_thresh
= 0x40;
260 if (rtlpriv
->falsealm_cnt
.cnt_cck_fail
> 1000)
261 cur_cck_cca_thresh
= 0x83;
263 cur_cck_cca_thresh
= 0x40;
265 rtl92ee_dm_write_cck_cca_thres(hw
, cur_cck_cca_thresh
);
268 static void rtl92ee_dm_dig(struct ieee80211_hw
*hw
)
270 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
271 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
272 struct dig_t
*dm_dig
= &rtlpriv
->dm_digtable
;
273 u8 dig_min_0
, dig_maxofmin
;
274 bool bfirstconnect
, bfirstdisconnect
;
275 u8 dm_dig_max
, dm_dig_min
;
276 u8 current_igi
= dm_dig
->cur_igvalue
;
280 if (mac
->act_scanning
)
283 dig_min_0
= dm_dig
->dig_min_0
;
284 bfirstconnect
= (mac
->link_state
>= MAC80211_LINKED
) &&
285 !dm_dig
->media_connect_0
;
286 bfirstdisconnect
= (mac
->link_state
< MAC80211_LINKED
) &&
287 dm_dig
->media_connect_0
;
290 dm_dig_min
= DM_DIG_MIN
;
291 dig_maxofmin
= DM_DIG_MAX_AP
;
293 if (mac
->link_state
>= MAC80211_LINKED
) {
294 if ((dm_dig
->rssi_val_min
+ 10) > dm_dig_max
)
295 dm_dig
->rx_gain_max
= dm_dig_max
;
296 else if ((dm_dig
->rssi_val_min
+ 10) < dm_dig_min
)
297 dm_dig
->rx_gain_max
= dm_dig_min
;
299 dm_dig
->rx_gain_max
= dm_dig
->rssi_val_min
+ 10;
301 if (rtlpriv
->dm
.one_entry_only
) {
303 if (dm_dig
->rssi_val_min
- offset
< dm_dig_min
)
304 dig_min_0
= dm_dig_min
;
305 else if (dm_dig
->rssi_val_min
- offset
>
307 dig_min_0
= dig_maxofmin
;
309 dig_min_0
= dm_dig
->rssi_val_min
- offset
;
311 dig_min_0
= dm_dig_min
;
315 dm_dig
->rx_gain_max
= dm_dig_max
;
316 dig_min_0
= dm_dig_min
;
317 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
, "no link\n");
320 if (rtlpriv
->falsealm_cnt
.cnt_all
> 10000) {
321 if (dm_dig
->large_fa_hit
!= 3)
322 dm_dig
->large_fa_hit
++;
323 if (dm_dig
->forbidden_igi
< current_igi
) {
324 dm_dig
->forbidden_igi
= current_igi
;
325 dm_dig
->large_fa_hit
= 1;
328 if (dm_dig
->large_fa_hit
>= 3) {
329 if (dm_dig
->forbidden_igi
+ 1 > dm_dig
->rx_gain_max
)
330 dm_dig
->rx_gain_min
=
333 dm_dig
->rx_gain_min
=
334 dm_dig
->forbidden_igi
+ 1;
335 dm_dig
->recover_cnt
= 3600;
338 if (dm_dig
->recover_cnt
!= 0) {
339 dm_dig
->recover_cnt
--;
341 if (dm_dig
->large_fa_hit
< 3) {
342 if ((dm_dig
->forbidden_igi
- 1) <
344 dm_dig
->forbidden_igi
= dig_min_0
;
345 dm_dig
->rx_gain_min
=
348 dm_dig
->forbidden_igi
--;
349 dm_dig
->rx_gain_min
=
350 dm_dig
->forbidden_igi
+ 1;
353 dm_dig
->large_fa_hit
= 0;
358 if (rtlpriv
->dm
.dbginfo
.num_qry_beacon_pkt
< 5)
359 dm_dig
->rx_gain_min
= dm_dig_min
;
361 if (dm_dig
->rx_gain_min
> dm_dig
->rx_gain_max
)
362 dm_dig
->rx_gain_min
= dm_dig
->rx_gain_max
;
364 if (mac
->link_state
>= MAC80211_LINKED
) {
366 if (dm_dig
->rssi_val_min
<= dig_maxofmin
)
367 current_igi
= dm_dig
->rssi_val_min
;
369 current_igi
= dig_maxofmin
;
371 dm_dig
->large_fa_hit
= 0;
373 if (rtlpriv
->falsealm_cnt
.cnt_all
> DM_DIG_FA_TH2
)
375 else if (rtlpriv
->falsealm_cnt
.cnt_all
> DM_DIG_FA_TH1
)
377 else if (rtlpriv
->falsealm_cnt
.cnt_all
< DM_DIG_FA_TH0
)
380 if (rtlpriv
->dm
.dbginfo
.num_qry_beacon_pkt
< 5 &&
381 rtlpriv
->falsealm_cnt
.cnt_all
< DM_DIG_FA_TH1
)
382 current_igi
= dm_dig
->rx_gain_min
;
385 if (bfirstdisconnect
) {
386 current_igi
= dm_dig
->rx_gain_min
;
388 if (rtlpriv
->falsealm_cnt
.cnt_all
> 10000)
390 else if (rtlpriv
->falsealm_cnt
.cnt_all
> 8000)
392 else if (rtlpriv
->falsealm_cnt
.cnt_all
< 500)
397 if (current_igi
> dm_dig
->rx_gain_max
)
398 current_igi
= dm_dig
->rx_gain_max
;
399 if (current_igi
< dm_dig
->rx_gain_min
)
400 current_igi
= dm_dig
->rx_gain_min
;
402 rtl92ee_dm_write_dig(hw
, current_igi
);
403 dm_dig
->media_connect_0
= ((mac
->link_state
>= MAC80211_LINKED
) ?
405 dm_dig
->dig_min_0
= dig_min_0
;
408 void rtl92ee_dm_write_cck_cca_thres(struct ieee80211_hw
*hw
, u8 cur_thres
)
410 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
411 struct dig_t
*dm_dig
= &rtlpriv
->dm_digtable
;
413 if (dm_dig
->cur_cck_cca_thres
!= cur_thres
)
414 rtl_write_byte(rtlpriv
, DM_REG_CCK_CCA_11N
, cur_thres
);
416 dm_dig
->pre_cck_cca_thres
= dm_dig
->cur_cck_cca_thres
;
417 dm_dig
->cur_cck_cca_thres
= cur_thres
;
420 void rtl92ee_dm_write_dig(struct ieee80211_hw
*hw
, u8 current_igi
)
422 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
423 struct dig_t
*dm_dig
= &rtlpriv
->dm_digtable
;
425 if (dm_dig
->stop_dig
)
428 if (dm_dig
->cur_igvalue
!= current_igi
) {
429 rtl_set_bbreg(hw
, ROFDM0_XAAGCCORE1
, 0x7f, current_igi
);
430 if (rtlpriv
->phy
.rf_type
!= RF_1T1R
)
431 rtl_set_bbreg(hw
, ROFDM0_XBAGCCORE1
, 0x7f, current_igi
);
433 dm_dig
->pre_igvalue
= dm_dig
->cur_igvalue
;
434 dm_dig
->cur_igvalue
= current_igi
;
437 static void rtl92ee_rssi_dump_to_register(struct ieee80211_hw
*hw
)
439 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
441 rtl_write_byte(rtlpriv
, RA_RSSIDUMP
,
442 rtlpriv
->stats
.rx_rssi_percentage
[0]);
443 rtl_write_byte(rtlpriv
, RB_RSSIDUMP
,
444 rtlpriv
->stats
.rx_rssi_percentage
[1]);
445 /*It seems the following values are not initialized.
446 *According to Windows code,
447 *these value will only be valid with JAGUAR chips
450 rtl_write_byte(rtlpriv
, RS1_RXEVMDUMP
, rtlpriv
->stats
.rx_evm_dbm
[0]);
451 rtl_write_byte(rtlpriv
, RS2_RXEVMDUMP
, rtlpriv
->stats
.rx_evm_dbm
[1]);
453 rtl_write_byte(rtlpriv
, RA_RXSNRDUMP
,
454 (u8
)(rtlpriv
->stats
.rx_snr_db
[0]));
455 rtl_write_byte(rtlpriv
, RB_RXSNRDUMP
,
456 (u8
)(rtlpriv
->stats
.rx_snr_db
[1]));
458 rtl_write_word(rtlpriv
, RA_CFOSHORTDUMP
,
459 rtlpriv
->stats
.rx_cfo_short
[0]);
460 rtl_write_word(rtlpriv
, RB_CFOSHORTDUMP
,
461 rtlpriv
->stats
.rx_cfo_short
[1]);
463 rtl_write_word(rtlpriv
, RA_CFOLONGDUMP
, rtlpriv
->stats
.rx_cfo_tail
[0]);
464 rtl_write_word(rtlpriv
, RB_CFOLONGDUMP
, rtlpriv
->stats
.rx_cfo_tail
[1]);
467 static void rtl92ee_dm_find_minimum_rssi(struct ieee80211_hw
*hw
)
469 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
470 struct dig_t
*rtl_dm_dig
= &rtlpriv
->dm_digtable
;
471 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
473 /* Determine the minimum RSSI */
474 if ((mac
->link_state
< MAC80211_LINKED
) &&
475 (rtlpriv
->dm
.entry_min_undec_sm_pwdb
== 0)) {
476 rtl_dm_dig
->min_undec_pwdb_for_dm
= 0;
477 RT_TRACE(rtlpriv
, COMP_BB_POWERSAVING
, DBG_LOUD
,
478 "Not connected to any\n");
480 if (mac
->link_state
>= MAC80211_LINKED
) {
481 if (mac
->opmode
== NL80211_IFTYPE_AP
||
482 mac
->opmode
== NL80211_IFTYPE_ADHOC
) {
483 rtl_dm_dig
->min_undec_pwdb_for_dm
=
484 rtlpriv
->dm
.entry_min_undec_sm_pwdb
;
485 RT_TRACE(rtlpriv
, COMP_BB_POWERSAVING
, DBG_LOUD
,
486 "AP Client PWDB = 0x%lx\n",
487 rtlpriv
->dm
.entry_min_undec_sm_pwdb
);
489 rtl_dm_dig
->min_undec_pwdb_for_dm
=
490 rtlpriv
->dm
.undec_sm_pwdb
;
491 RT_TRACE(rtlpriv
, COMP_BB_POWERSAVING
, DBG_LOUD
,
492 "STA Default Port PWDB = 0x%x\n",
493 rtl_dm_dig
->min_undec_pwdb_for_dm
);
496 rtl_dm_dig
->min_undec_pwdb_for_dm
=
497 rtlpriv
->dm
.entry_min_undec_sm_pwdb
;
498 RT_TRACE(rtlpriv
, COMP_BB_POWERSAVING
, DBG_LOUD
,
499 "AP Ext Port or disconnet PWDB = 0x%x\n",
500 rtl_dm_dig
->min_undec_pwdb_for_dm
);
502 RT_TRACE(rtlpriv
, COMP_DIG
, DBG_LOUD
,
503 "MinUndecoratedPWDBForDM =%d\n",
504 rtl_dm_dig
->min_undec_pwdb_for_dm
);
507 static void rtl92ee_dm_check_rssi_monitor(struct ieee80211_hw
*hw
)
509 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
510 struct dig_t
*dm_dig
= &rtlpriv
->dm_digtable
;
511 struct rtl_mac
*mac
= rtl_mac(rtlpriv
);
512 struct rtl_dm
*dm
= rtl_dm(rtlpriv
);
513 struct rtl_sta_info
*drv_priv
;
515 long max
= 0, min
= 0xff;
518 if (mac
->opmode
== NL80211_IFTYPE_AP
||
519 mac
->opmode
== NL80211_IFTYPE_ADHOC
||
520 mac
->opmode
== NL80211_IFTYPE_MESH_POINT
) {
521 /* AP & ADHOC & MESH */
522 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
523 list_for_each_entry(drv_priv
, &rtlpriv
->entry_list
, list
) {
524 struct rssi_sta
*stat
= &drv_priv
->rssi_stat
;
526 if (stat
->undec_sm_pwdb
< min
)
527 min
= stat
->undec_sm_pwdb
;
528 if (stat
->undec_sm_pwdb
> max
)
529 max
= stat
->undec_sm_pwdb
;
532 h2c
[2] = (u8
)(dm
->undec_sm_pwdb
& 0xFF);
535 rtl92ee_fill_h2c_cmd(hw
, H2C_92E_RSSI_REPORT
, 4, h2c
);
537 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
539 /* If associated entry is found */
541 dm
->entry_max_undec_sm_pwdb
= max
;
542 RTPRINT(rtlpriv
, FDM
, DM_PWDB
,
543 "EntryMaxPWDB = 0x%lx(%ld)\n", max
, max
);
545 dm
->entry_max_undec_sm_pwdb
= 0;
547 /* If associated entry is found */
549 dm
->entry_min_undec_sm_pwdb
= min
;
550 RTPRINT(rtlpriv
, FDM
, DM_PWDB
,
551 "EntryMinPWDB = 0x%lx(%ld)\n", min
, min
);
553 dm
->entry_min_undec_sm_pwdb
= 0;
557 /* Indicate Rx signal strength to FW. */
560 h2c
[2] = (u8
)(dm
->undec_sm_pwdb
& 0xFF);
563 rtl92ee_fill_h2c_cmd(hw
, H2C_92E_RSSI_REPORT
, 4, h2c
);
565 rtl_write_byte(rtlpriv
, 0x4fe, dm
->undec_sm_pwdb
);
567 rtl92ee_rssi_dump_to_register(hw
);
568 rtl92ee_dm_find_minimum_rssi(hw
);
569 dm_dig
->rssi_val_min
= rtlpriv
->dm_digtable
.min_undec_pwdb_for_dm
;
572 static void rtl92ee_dm_init_primary_cca_check(struct ieee80211_hw
*hw
)
574 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
575 struct rtl_hal
*rtlhal
= rtl_hal(rtlpriv
);
576 struct dynamic_primary_cca
*primarycca
= &rtlpriv
->primarycca
;
579 primarycca
->dup_rts_flag
= 0;
580 primarycca
->intf_flag
= 0;
581 primarycca
->intf_type
= 0;
582 primarycca
->monitor_flag
= 0;
583 primarycca
->ch_offset
= 0;
584 primarycca
->mf_state
= 0;
587 static bool rtl92ee_dm_is_edca_turbo_disable(struct ieee80211_hw
*hw
)
589 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
591 if (rtlpriv
->mac80211
.mode
== WIRELESS_MODE_B
)
597 void rtl92ee_dm_init_edca_turbo(struct ieee80211_hw
*hw
)
599 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
601 rtlpriv
->dm
.current_turbo_edca
= false;
602 rtlpriv
->dm
.is_cur_rdlstate
= false;
603 rtlpriv
->dm
.is_any_nonbepkts
= false;
606 static void rtl92ee_dm_check_edca_turbo(struct ieee80211_hw
*hw
)
608 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
610 static u64 last_txok_cnt
;
611 static u64 last_rxok_cnt
;
612 u64 cur_txok_cnt
= 0;
613 u64 cur_rxok_cnt
= 0;
614 u32 edca_be_ul
= 0x5ea42b;
615 u32 edca_be_dl
= 0x5ea42b; /*not sure*/
616 u32 edca_be
= 0x5ea42b;
617 bool is_cur_rdlstate
;
618 bool b_edca_turbo_on
= false;
620 if (rtlpriv
->dm
.dbginfo
.num_non_be_pkt
> 0x100)
621 rtlpriv
->dm
.is_any_nonbepkts
= true;
622 rtlpriv
->dm
.dbginfo
.num_non_be_pkt
= 0;
624 cur_txok_cnt
= rtlpriv
->stats
.txbytesunicast
- last_txok_cnt
;
625 cur_rxok_cnt
= rtlpriv
->stats
.rxbytesunicast
- last_rxok_cnt
;
627 /*b_bias_on_rx = false;*/
628 b_edca_turbo_on
= ((!rtlpriv
->dm
.is_any_nonbepkts
) &&
629 (!rtlpriv
->dm
.disable_framebursting
)) ?
632 if (rtl92ee_dm_is_edca_turbo_disable(hw
))
635 if (b_edca_turbo_on
) {
636 is_cur_rdlstate
= (cur_rxok_cnt
> cur_txok_cnt
* 4) ?
639 edca_be
= is_cur_rdlstate
? edca_be_dl
: edca_be_ul
;
640 rtl_write_dword(rtlpriv
, REG_EDCA_BE_PARAM
, edca_be
);
641 rtlpriv
->dm
.is_cur_rdlstate
= is_cur_rdlstate
;
642 rtlpriv
->dm
.current_turbo_edca
= true;
644 if (rtlpriv
->dm
.current_turbo_edca
) {
647 rtlpriv
->cfg
->ops
->set_hw_reg(hw
, HW_VAR_AC_PARAM
,
650 rtlpriv
->dm
.current_turbo_edca
= false;
654 rtlpriv
->dm
.is_any_nonbepkts
= false;
655 last_txok_cnt
= rtlpriv
->stats
.txbytesunicast
;
656 last_rxok_cnt
= rtlpriv
->stats
.rxbytesunicast
;
659 static void rtl92ee_dm_dynamic_edcca(struct ieee80211_hw
*hw
)
661 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
662 u8 reg_c50
, reg_c58
;
663 bool fw_current_in_ps_mode
= false;
665 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
666 (u8
*)(&fw_current_in_ps_mode
));
667 if (fw_current_in_ps_mode
)
670 reg_c50
= rtl_get_bbreg(hw
, ROFDM0_XAAGCCORE1
, MASKBYTE0
);
671 reg_c58
= rtl_get_bbreg(hw
, ROFDM0_XBAGCCORE1
, MASKBYTE0
);
673 if (reg_c50
> 0x28 && reg_c58
> 0x28) {
674 if (!rtlpriv
->rtlhal
.pre_edcca_enable
) {
675 rtl_write_byte(rtlpriv
, ROFDM0_ECCATHRESHOLD
, 0x03);
676 rtl_write_byte(rtlpriv
, ROFDM0_ECCATHRESHOLD
+ 2, 0x00);
677 rtlpriv
->rtlhal
.pre_edcca_enable
= true;
679 } else if (reg_c50
< 0x25 && reg_c58
< 0x25) {
680 if (rtlpriv
->rtlhal
.pre_edcca_enable
) {
681 rtl_write_byte(rtlpriv
, ROFDM0_ECCATHRESHOLD
, 0x7f);
682 rtl_write_byte(rtlpriv
, ROFDM0_ECCATHRESHOLD
+ 2, 0x7f);
683 rtlpriv
->rtlhal
.pre_edcca_enable
= false;
688 static void rtl92ee_dm_adaptivity(struct ieee80211_hw
*hw
)
690 rtl92ee_dm_dynamic_edcca(hw
);
693 static void rtl92ee_dm_write_dynamic_cca(struct ieee80211_hw
*hw
,
696 struct dynamic_primary_cca
*primarycca
= &rtl_priv(hw
)->primarycca
;
698 if (primarycca
->mf_state
!= cur_mf_state
)
699 rtl_set_bbreg(hw
, DM_REG_L1SBD_PD_CH_11N
, BIT(8) | BIT(7),
702 primarycca
->mf_state
= cur_mf_state
;
705 static void rtl92ee_dm_dynamic_primary_cca_ckeck(struct ieee80211_hw
*hw
)
707 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
708 struct false_alarm_statistics
*falsealm_cnt
= &rtlpriv
->falsealm_cnt
;
709 struct dynamic_primary_cca
*primarycca
= &rtlpriv
->primarycca
;
710 bool is40mhz
= false;
711 u64 ofdm_cca
, ofdm_fa
, bw_usc_cnt
, bw_lsc_cnt
;
714 static u8 count_down
= MONITOR_TIME
;
716 ofdm_cca
= falsealm_cnt
->cnt_ofdm_cca
;
717 ofdm_fa
= falsealm_cnt
->cnt_ofdm_fail
;
718 bw_usc_cnt
= falsealm_cnt
->cnt_bw_usc
;
719 bw_lsc_cnt
= falsealm_cnt
->cnt_bw_lsc
;
720 is40mhz
= rtlpriv
->mac80211
.bw_40
;
721 sec_ch_offset
= rtlpriv
->mac80211
.cur_40_prime_sc
;
722 /* NIC: 2: sec is below, 1: sec is above */
724 if (rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_AP
) {
725 cur_mf_state
= MF_USC_LSC
;
726 rtl92ee_dm_write_dynamic_cca(hw
, cur_mf_state
);
730 if (rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
)
736 if (primarycca
->pricca_flag
== 0) {
737 /* Primary channel is above
738 * NOTE: duplicate CTS can remove this condition
740 if (sec_ch_offset
== 2) {
741 if ((ofdm_cca
> OFDMCCA_TH
) &&
742 (bw_lsc_cnt
> (bw_usc_cnt
+ BW_IND_BIAS
)) &&
743 (ofdm_fa
> (ofdm_cca
>> 1))) {
744 primarycca
->intf_type
= 1;
745 primarycca
->intf_flag
= 1;
746 cur_mf_state
= MF_USC
;
747 rtl92ee_dm_write_dynamic_cca(hw
, cur_mf_state
);
748 primarycca
->pricca_flag
= 1;
749 } else if ((ofdm_cca
> OFDMCCA_TH
) &&
750 (bw_lsc_cnt
> (bw_usc_cnt
+ BW_IND_BIAS
)) &&
751 (ofdm_fa
< (ofdm_cca
>> 1))) {
752 primarycca
->intf_type
= 2;
753 primarycca
->intf_flag
= 1;
754 cur_mf_state
= MF_USC
;
755 rtl92ee_dm_write_dynamic_cca(hw
, cur_mf_state
);
756 primarycca
->pricca_flag
= 1;
757 primarycca
->dup_rts_flag
= 1;
758 rtlpriv
->rtlhal
.rts_en
= 1;
760 primarycca
->intf_type
= 0;
761 primarycca
->intf_flag
= 0;
762 cur_mf_state
= MF_USC_LSC
;
763 rtl92ee_dm_write_dynamic_cca(hw
, cur_mf_state
);
764 rtlpriv
->rtlhal
.rts_en
= 0;
765 primarycca
->dup_rts_flag
= 0;
767 } else if (sec_ch_offset
== 1) {
768 if ((ofdm_cca
> OFDMCCA_TH
) &&
769 (bw_usc_cnt
> (bw_lsc_cnt
+ BW_IND_BIAS
)) &&
770 (ofdm_fa
> (ofdm_cca
>> 1))) {
771 primarycca
->intf_type
= 1;
772 primarycca
->intf_flag
= 1;
773 cur_mf_state
= MF_LSC
;
774 rtl92ee_dm_write_dynamic_cca(hw
, cur_mf_state
);
775 primarycca
->pricca_flag
= 1;
776 } else if ((ofdm_cca
> OFDMCCA_TH
) &&
777 (bw_usc_cnt
> (bw_lsc_cnt
+ BW_IND_BIAS
)) &&
778 (ofdm_fa
< (ofdm_cca
>> 1))) {
779 primarycca
->intf_type
= 2;
780 primarycca
->intf_flag
= 1;
781 cur_mf_state
= MF_LSC
;
782 rtl92ee_dm_write_dynamic_cca(hw
, cur_mf_state
);
783 primarycca
->pricca_flag
= 1;
784 primarycca
->dup_rts_flag
= 1;
785 rtlpriv
->rtlhal
.rts_en
= 1;
787 primarycca
->intf_type
= 0;
788 primarycca
->intf_flag
= 0;
789 cur_mf_state
= MF_USC_LSC
;
790 rtl92ee_dm_write_dynamic_cca(hw
, cur_mf_state
);
791 rtlpriv
->rtlhal
.rts_en
= 0;
792 primarycca
->dup_rts_flag
= 0;
795 } else {/* PrimaryCCA->PriCCA_flag==1 */
797 if (count_down
== 0) {
798 count_down
= MONITOR_TIME
;
799 primarycca
->pricca_flag
= 0;
800 cur_mf_state
= MF_USC_LSC
;
802 rtl92ee_dm_write_dynamic_cca(hw
, cur_mf_state
);
803 rtlpriv
->rtlhal
.rts_en
= 0;
804 primarycca
->dup_rts_flag
= 0;
805 primarycca
->intf_type
= 0;
806 primarycca
->intf_flag
= 0;
811 static void rtl92ee_dm_dynamic_atc_switch(struct ieee80211_hw
*hw
)
813 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
814 struct rtl_dm
*rtldm
= rtl_dm(rtl_priv(hw
));
817 int cfo_khz_a
, cfo_khz_b
, cfo_ave
= 0, adjust_xtal
= 0;
820 if (rtlpriv
->mac80211
.link_state
< MAC80211_LINKED
) {
821 if (rtldm
->atc_status
== ATC_STATUS_OFF
) {
822 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(11),
824 rtldm
->atc_status
= ATC_STATUS_ON
;
826 /* Disable CFO tracking for BT */
827 if (rtlpriv
->cfg
->ops
->get_btc_status()) {
828 if (!rtlpriv
->btcoexist
.btc_ops
->
829 btc_is_bt_disabled(rtlpriv
)) {
830 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
831 "odm_DynamicATCSwitch(): Disable CFO tracking for BT!!\n");
835 /* Reset Crystal Cap */
836 if (rtldm
->crystal_cap
!= rtlpriv
->efuse
.crystalcap
) {
837 rtldm
->crystal_cap
= rtlpriv
->efuse
.crystalcap
;
838 crystal_cap
= rtldm
->crystal_cap
& 0x3f;
839 rtl_set_bbreg(hw
, REG_MAC_PHY_CTRL
, 0xFFF000,
840 (crystal_cap
| (crystal_cap
<< 6)));
843 cfo_khz_a
= (int)(rtldm
->cfo_tail
[0] * 3125) / 1280;
844 cfo_khz_b
= (int)(rtldm
->cfo_tail
[1] * 3125) / 1280;
845 packet_count
= rtldm
->packet_count
;
847 if (packet_count
== rtldm
->packet_count_pre
)
850 rtldm
->packet_count_pre
= packet_count
;
852 if (rtlpriv
->phy
.rf_type
== RF_1T1R
)
855 cfo_ave
= (int)(cfo_khz_a
+ cfo_khz_b
) >> 1;
857 cfo_ave_diff
= (rtldm
->cfo_ave_pre
>= cfo_ave
) ?
858 (rtldm
->cfo_ave_pre
- cfo_ave
) :
859 (cfo_ave
- rtldm
->cfo_ave_pre
);
861 if (cfo_ave_diff
> 20 && rtldm
->large_cfo_hit
== 0) {
862 rtldm
->large_cfo_hit
= 1;
865 rtldm
->large_cfo_hit
= 0;
867 rtldm
->cfo_ave_pre
= cfo_ave
;
869 if (cfo_ave
>= -rtldm
->cfo_threshold
&&
870 cfo_ave
<= rtldm
->cfo_threshold
&& rtldm
->is_freeze
== 0) {
871 if (rtldm
->cfo_threshold
== CFO_THRESHOLD_XTAL
) {
872 rtldm
->cfo_threshold
= CFO_THRESHOLD_XTAL
+ 10;
873 rtldm
->is_freeze
= 1;
875 rtldm
->cfo_threshold
= CFO_THRESHOLD_XTAL
;
879 if (cfo_ave
> rtldm
->cfo_threshold
&& rtldm
->crystal_cap
< 0x3f)
880 adjust_xtal
= ((cfo_ave
- CFO_THRESHOLD_XTAL
) >> 2) + 1;
881 else if ((cfo_ave
< -rtlpriv
->dm
.cfo_threshold
) &&
882 rtlpriv
->dm
.crystal_cap
> 0)
883 adjust_xtal
= ((cfo_ave
+ CFO_THRESHOLD_XTAL
) >> 2) - 1;
885 if (adjust_xtal
!= 0) {
886 rtldm
->is_freeze
= 0;
887 rtldm
->crystal_cap
+= adjust_xtal
;
889 if (rtldm
->crystal_cap
> 0x3f)
890 rtldm
->crystal_cap
= 0x3f;
891 else if (rtldm
->crystal_cap
< 0)
892 rtldm
->crystal_cap
= 0;
894 crystal_cap
= rtldm
->crystal_cap
& 0x3f;
895 rtl_set_bbreg(hw
, REG_MAC_PHY_CTRL
, 0xFFF000,
896 (crystal_cap
| (crystal_cap
<< 6)));
899 if (cfo_ave
< CFO_THRESHOLD_ATC
&&
900 cfo_ave
> -CFO_THRESHOLD_ATC
) {
901 if (rtldm
->atc_status
== ATC_STATUS_ON
) {
902 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(11),
904 rtldm
->atc_status
= ATC_STATUS_OFF
;
907 if (rtldm
->atc_status
== ATC_STATUS_OFF
) {
908 rtl_set_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(11),
910 rtldm
->atc_status
= ATC_STATUS_ON
;
916 static void rtl92ee_dm_init_txpower_tracking(struct ieee80211_hw
*hw
)
918 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
919 struct rtl_dm
*dm
= rtl_dm(rtlpriv
);
922 dm
->txpower_tracking
= true;
923 dm
->default_ofdm_index
= 30;
924 dm
->default_cck_index
= 20;
926 dm
->swing_idx_cck_base
= dm
->default_cck_index
;
927 dm
->cck_index
= dm
->default_cck_index
;
929 for (path
= RF90_PATH_A
; path
< MAX_RF_PATH
; path
++) {
930 dm
->swing_idx_ofdm_base
[path
] = dm
->default_ofdm_index
;
931 dm
->ofdm_index
[path
] = dm
->default_ofdm_index
;
932 dm
->delta_power_index
[path
] = 0;
933 dm
->delta_power_index_last
[path
] = 0;
934 dm
->power_index_offset
[path
] = 0;
938 void rtl92ee_dm_init_rate_adaptive_mask(struct ieee80211_hw
*hw
)
940 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
941 struct rate_adaptive
*p_ra
= &rtlpriv
->ra
;
943 p_ra
->ratr_state
= DM_RATR_STA_INIT
;
944 p_ra
->pre_ratr_state
= DM_RATR_STA_INIT
;
946 if (rtlpriv
->dm
.dm_type
== DM_TYPE_BYDRIVER
)
947 rtlpriv
->dm
.useramask
= true;
949 rtlpriv
->dm
.useramask
= false;
951 p_ra
->ldpc_thres
= 35;
952 p_ra
->use_ldpc
= false;
953 p_ra
->high_rssi_thresh_for_ra
= 50;
954 p_ra
->low_rssi_thresh_for_ra40m
= 20;
957 static bool _rtl92ee_dm_ra_state_check(struct ieee80211_hw
*hw
,
958 s32 rssi
, u8
*ratr_state
)
960 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
961 struct rate_adaptive
*p_ra
= &rtlpriv
->ra
;
962 const u8 go_up_gap
= 5;
963 u32 high_rssithresh_for_ra
= p_ra
->high_rssi_thresh_for_ra
;
964 u32 low_rssithresh_for_ra
= p_ra
->low_rssi_thresh_for_ra40m
;
967 /* Threshold Adjustment:
968 * when RSSI state trends to go up one or two levels,
969 * make sure RSSI is high enough.
970 * Here GoUpGap is added to solve
971 * the boundary's level alternation issue.
973 switch (*ratr_state
) {
974 case DM_RATR_STA_INIT
:
975 case DM_RATR_STA_HIGH
:
977 case DM_RATR_STA_MIDDLE
:
978 high_rssithresh_for_ra
+= go_up_gap
;
980 case DM_RATR_STA_LOW
:
981 high_rssithresh_for_ra
+= go_up_gap
;
982 low_rssithresh_for_ra
+= go_up_gap
;
985 RT_TRACE(rtlpriv
, COMP_RATR
, DBG_DMESG
,
986 "wrong rssi level setting %d !", *ratr_state
);
990 /* Decide RATRState by RSSI. */
991 if (rssi
> high_rssithresh_for_ra
)
992 state
= DM_RATR_STA_HIGH
;
993 else if (rssi
> low_rssithresh_for_ra
)
994 state
= DM_RATR_STA_MIDDLE
;
996 state
= DM_RATR_STA_LOW
;
998 if (*ratr_state
!= state
) {
1006 static void rtl92ee_dm_refresh_rate_adaptive_mask(struct ieee80211_hw
*hw
)
1008 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1009 struct rtl_hal
*rtlhal
= rtl_hal(rtl_priv(hw
));
1010 struct rtl_mac
*mac
= rtl_mac(rtl_priv(hw
));
1011 struct rate_adaptive
*p_ra
= &rtlpriv
->ra
;
1012 struct ieee80211_sta
*sta
= NULL
;
1014 if (is_hal_stop(rtlhal
)) {
1015 RT_TRACE(rtlpriv
, COMP_RATE
, DBG_LOUD
,
1016 "driver is going to unload\n");
1020 if (!rtlpriv
->dm
.useramask
) {
1021 RT_TRACE(rtlpriv
, COMP_RATE
, DBG_LOUD
,
1022 "driver does not control rate adaptive mask\n");
1026 if (mac
->link_state
== MAC80211_LINKED
&&
1027 mac
->opmode
== NL80211_IFTYPE_STATION
) {
1028 if (rtlpriv
->dm
.undec_sm_pwdb
< p_ra
->ldpc_thres
) {
1029 p_ra
->use_ldpc
= true;
1030 p_ra
->lower_rts_rate
= true;
1031 } else if (rtlpriv
->dm
.undec_sm_pwdb
>
1032 (p_ra
->ldpc_thres
- 5)) {
1033 p_ra
->use_ldpc
= false;
1034 p_ra
->lower_rts_rate
= false;
1036 if (_rtl92ee_dm_ra_state_check(hw
, rtlpriv
->dm
.undec_sm_pwdb
,
1037 &p_ra
->ratr_state
)) {
1039 sta
= rtl_find_sta(hw
, mac
->bssid
);
1041 rtlpriv
->cfg
->ops
->update_rate_tbl(hw
, sta
,
1045 p_ra
->pre_ratr_state
= p_ra
->ratr_state
;
1050 static void rtl92ee_dm_init_dynamic_atc_switch(struct ieee80211_hw
*hw
)
1052 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1054 rtlpriv
->dm
.crystal_cap
= rtlpriv
->efuse
.crystalcap
;
1056 rtlpriv
->dm
.atc_status
= rtl_get_bbreg(hw
, ROFDM1_CFOTRACKING
, BIT(11));
1057 rtlpriv
->dm
.cfo_threshold
= CFO_THRESHOLD_XTAL
;
1060 void rtl92ee_dm_init(struct ieee80211_hw
*hw
)
1062 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1063 u32 cur_igvalue
= rtl_get_bbreg(hw
, DM_REG_IGI_A_11N
, DM_BIT_IGI_11N
);
1065 rtlpriv
->dm
.dm_type
= DM_TYPE_BYDRIVER
;
1067 rtl_dm_diginit(hw
, cur_igvalue
);
1068 rtl92ee_dm_init_rate_adaptive_mask(hw
);
1069 rtl92ee_dm_init_primary_cca_check(hw
);
1070 rtl92ee_dm_init_edca_turbo(hw
);
1071 rtl92ee_dm_init_txpower_tracking(hw
);
1072 rtl92ee_dm_init_dynamic_atc_switch(hw
);
1075 static void rtl92ee_dm_common_info_self_update(struct ieee80211_hw
*hw
)
1077 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1078 struct rtl_sta_info
*drv_priv
;
1081 rtlpriv
->dm
.one_entry_only
= false;
1083 if (rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_STATION
&&
1084 rtlpriv
->mac80211
.link_state
>= MAC80211_LINKED
) {
1085 rtlpriv
->dm
.one_entry_only
= true;
1089 if (rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_AP
||
1090 rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_ADHOC
||
1091 rtlpriv
->mac80211
.opmode
== NL80211_IFTYPE_MESH_POINT
) {
1092 spin_lock_bh(&rtlpriv
->locks
.entry_list_lock
);
1093 list_for_each_entry(drv_priv
, &rtlpriv
->entry_list
, list
) {
1096 spin_unlock_bh(&rtlpriv
->locks
.entry_list_lock
);
1099 rtlpriv
->dm
.one_entry_only
= true;
1103 void rtl92ee_dm_dynamic_arfb_select(struct ieee80211_hw
*hw
,
1104 u8 rate
, bool collision_state
)
1106 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1108 if (rate
>= DESC92C_RATEMCS8
&& rate
<= DESC92C_RATEMCS12
) {
1109 if (collision_state
== 1) {
1110 if (rate
== DESC92C_RATEMCS12
) {
1111 rtl_write_dword(rtlpriv
, REG_DARFRC
, 0x0);
1112 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1114 } else if (rate
== DESC92C_RATEMCS11
) {
1115 rtl_write_dword(rtlpriv
, REG_DARFRC
, 0x0);
1116 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1118 } else if (rate
== DESC92C_RATEMCS10
) {
1119 rtl_write_dword(rtlpriv
, REG_DARFRC
, 0x0);
1120 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1122 } else if (rate
== DESC92C_RATEMCS9
) {
1123 rtl_write_dword(rtlpriv
, REG_DARFRC
, 0x0);
1124 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1127 rtl_write_dword(rtlpriv
, REG_DARFRC
, 0x0);
1128 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1131 } else { /* collision_state == 0 */
1132 if (rate
== DESC92C_RATEMCS12
) {
1133 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1135 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1137 } else if (rate
== DESC92C_RATEMCS11
) {
1138 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1140 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1142 } else if (rate
== DESC92C_RATEMCS10
) {
1143 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1145 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1147 } else if (rate
== DESC92C_RATEMCS9
) {
1148 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1150 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1153 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1155 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1159 } else { /* MCS13~MCS15, 1SS, G-mode */
1160 if (collision_state
== 1) {
1161 if (rate
== DESC92C_RATEMCS15
) {
1162 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1164 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1166 } else if (rate
== DESC92C_RATEMCS14
) {
1167 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1169 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1171 } else if (rate
== DESC92C_RATEMCS13
) {
1172 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1174 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1177 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1179 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1182 } else{ /* collision_state == 0 */
1183 if (rate
== DESC92C_RATEMCS15
) {
1184 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1186 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1188 } else if (rate
== DESC92C_RATEMCS14
) {
1189 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1191 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1193 } else if (rate
== DESC92C_RATEMCS13
) {
1194 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1196 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1199 rtl_write_dword(rtlpriv
, REG_DARFRC
,
1201 rtl_write_dword(rtlpriv
, REG_DARFRC
+ 4,
1208 void rtl92ee_dm_watchdog(struct ieee80211_hw
*hw
)
1210 struct rtl_priv
*rtlpriv
= rtl_priv(hw
);
1211 struct rtl_ps_ctl
*ppsc
= rtl_psc(rtl_priv(hw
));
1212 bool fw_current_inpsmode
= false;
1213 bool fw_ps_awake
= true;
1215 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_FW_PSMODE_STATUS
,
1216 (u8
*)(&fw_current_inpsmode
));
1217 rtlpriv
->cfg
->ops
->get_hw_reg(hw
, HW_VAR_FWLPS_RF_ON
,
1218 (u8
*)(&fw_ps_awake
));
1219 if (ppsc
->p2p_ps_info
.p2p_ps_mode
)
1220 fw_ps_awake
= false;
1222 if ((ppsc
->rfpwr_state
== ERFON
) &&
1223 ((!fw_current_inpsmode
) && fw_ps_awake
) &&
1224 (!ppsc
->rfchange_inprogress
)) {
1225 rtl92ee_dm_common_info_self_update(hw
);
1226 rtl92ee_dm_false_alarm_counter_statistics(hw
);
1227 rtl92ee_dm_check_rssi_monitor(hw
);
1229 rtl92ee_dm_adaptivity(hw
);
1230 rtl92ee_dm_cck_packet_detection_thresh(hw
);
1231 rtl92ee_dm_refresh_rate_adaptive_mask(hw
);
1232 rtl92ee_dm_check_edca_turbo(hw
);
1233 rtl92ee_dm_dynamic_atc_switch(hw
);
1234 rtl92ee_dm_dynamic_primary_cca_ckeck(hw
);