1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2012 Realtek Corporation.*/
4 /**************************************************************
7 * This file is for RTL8821A Co-exist mechanism
10 * 2012/11/15 Cosa first check in.
12 **************************************************************/
14 /**************************************************************
16 **************************************************************/
17 #include "halbt_precomp.h"
18 /**************************************************************
19 * Global variables, these are static variables
20 **************************************************************/
21 static struct coex_dm_8821a_1ant glcoex_dm_8821a_1ant
;
22 static struct coex_dm_8821a_1ant
*coex_dm
= &glcoex_dm_8821a_1ant
;
23 static struct coex_sta_8821a_1ant glcoex_sta_8821a_1ant
;
24 static struct coex_sta_8821a_1ant
*coex_sta
= &glcoex_sta_8821a_1ant
;
25 static void btc8821a1ant_act_bt_sco_hid_only_busy(struct btc_coexist
*btcoexist
,
28 static const char *const glbt_info_src_8821a_1ant
[] = {
31 "BT Info[bt auto report]",
34 static u32 glcoex_ver_date_8821a_1ant
= 20130816;
35 static u32 glcoex_ver_8821a_1ant
= 0x41;
37 /**************************************************************
38 * local function proto type if needed
40 * local function start with btc8821a1ant_
41 **************************************************************/
42 static u8
btc8821a1ant_bt_rssi_state(struct btc_coexist
*btcoexist
,
43 u8 level_num
, u8 rssi_thresh
,
46 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
48 u8 bt_rssi_state
= coex_sta
->pre_bt_rssi_state
;
50 bt_rssi
= coex_sta
->bt_rssi
;
53 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
54 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
55 if (bt_rssi
>= (rssi_thresh
+
56 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT
)) {
57 bt_rssi_state
= BTC_RSSI_STATE_HIGH
;
58 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
59 "[BTCoex], BT Rssi state switch to High\n");
61 bt_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
62 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
63 "[BTCoex], BT Rssi state stay at Low\n");
66 if (bt_rssi
< rssi_thresh
) {
67 bt_rssi_state
= BTC_RSSI_STATE_LOW
;
68 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
69 "[BTCoex], BT Rssi state switch to Low\n");
71 bt_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
72 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
73 "[BTCoex], BT Rssi state stay at High\n");
76 } else if (level_num
== 3) {
77 if (rssi_thresh
> rssi_thresh1
) {
78 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
79 "[BTCoex], BT Rssi thresh error!!\n");
80 return coex_sta
->pre_bt_rssi_state
;
83 if ((coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_LOW
) ||
84 (coex_sta
->pre_bt_rssi_state
== BTC_RSSI_STATE_STAY_LOW
)) {
85 if (bt_rssi
>= (rssi_thresh
+
86 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT
)) {
87 bt_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
88 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
89 "[BTCoex], BT Rssi state switch to Medium\n");
91 bt_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
92 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
93 "[BTCoex], BT Rssi state stay at Low\n");
95 } else if ((coex_sta
->pre_bt_rssi_state
==
96 BTC_RSSI_STATE_MEDIUM
) ||
97 (coex_sta
->pre_bt_rssi_state
==
98 BTC_RSSI_STATE_STAY_MEDIUM
)) {
99 if (bt_rssi
>= (rssi_thresh1
+
100 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT
)) {
101 bt_rssi_state
= BTC_RSSI_STATE_HIGH
;
102 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
103 "[BTCoex], BT Rssi state switch to High\n");
104 } else if (bt_rssi
< rssi_thresh
) {
105 bt_rssi_state
= BTC_RSSI_STATE_LOW
;
106 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
107 "[BTCoex], BT Rssi state switch to Low\n");
109 bt_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
110 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
111 "[BTCoex], BT Rssi state stay at Medium\n");
114 if (bt_rssi
< rssi_thresh1
) {
115 bt_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
116 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
117 "[BTCoex], BT Rssi state switch to Medium\n");
119 bt_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
120 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
121 "[BTCoex], BT Rssi state stay at High\n");
125 coex_sta
->pre_bt_rssi_state
= bt_rssi_state
;
127 return bt_rssi_state
;
130 static u8
btc8821a1ant_wifi_rssi_state(struct btc_coexist
*btcoexist
,
131 u8 index
, u8 level_num
, u8 rssi_thresh
,
134 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
136 u8 wifi_rssi_state
= coex_sta
->pre_wifi_rssi_state
[index
];
138 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
140 if (level_num
== 2) {
141 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
142 BTC_RSSI_STATE_LOW
) ||
143 (coex_sta
->pre_wifi_rssi_state
[index
] ==
144 BTC_RSSI_STATE_STAY_LOW
)) {
145 if (wifi_rssi
>= (rssi_thresh
+
146 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT
)) {
147 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
148 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
149 "[BTCoex], wifi RSSI state switch to High\n");
151 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
152 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
153 "[BTCoex], wifi RSSI state stay at Low\n");
156 if (wifi_rssi
< rssi_thresh
) {
157 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
158 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
159 "[BTCoex], wifi RSSI state switch to Low\n");
161 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
162 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
163 "[BTCoex], wifi RSSI state stay at High\n");
166 } else if (level_num
== 3) {
167 if (rssi_thresh
> rssi_thresh1
) {
168 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
169 "[BTCoex], wifi RSSI thresh error!!\n");
170 return coex_sta
->pre_wifi_rssi_state
[index
];
173 if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
174 BTC_RSSI_STATE_LOW
) ||
175 (coex_sta
->pre_wifi_rssi_state
[index
] ==
176 BTC_RSSI_STATE_STAY_LOW
)) {
177 if (wifi_rssi
>= (rssi_thresh
+
178 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT
)) {
179 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
180 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
181 "[BTCoex], wifi RSSI state switch to Medium\n");
183 wifi_rssi_state
= BTC_RSSI_STATE_STAY_LOW
;
184 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
185 "[BTCoex], wifi RSSI state stay at Low\n");
187 } else if ((coex_sta
->pre_wifi_rssi_state
[index
] ==
188 BTC_RSSI_STATE_MEDIUM
) ||
189 (coex_sta
->pre_wifi_rssi_state
[index
] ==
190 BTC_RSSI_STATE_STAY_MEDIUM
)) {
191 if (wifi_rssi
>= (rssi_thresh1
+
192 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT
)) {
193 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
194 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
195 "[BTCoex], wifi RSSI state switch to High\n");
196 } else if (wifi_rssi
< rssi_thresh
) {
197 wifi_rssi_state
= BTC_RSSI_STATE_LOW
;
198 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
199 "[BTCoex], wifi RSSI state switch to Low\n");
201 wifi_rssi_state
= BTC_RSSI_STATE_STAY_MEDIUM
;
202 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
203 "[BTCoex], wifi RSSI state stay at Medium\n");
206 if (wifi_rssi
< rssi_thresh1
) {
207 wifi_rssi_state
= BTC_RSSI_STATE_MEDIUM
;
208 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
209 "[BTCoex], wifi RSSI state switch to Medium\n");
211 wifi_rssi_state
= BTC_RSSI_STATE_STAY_HIGH
;
212 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
213 "[BTCoex], wifi RSSI state stay at High\n");
217 coex_sta
->pre_wifi_rssi_state
[index
] = wifi_rssi_state
;
219 return wifi_rssi_state
;
222 static void btc8821a1ant_update_ra_mask(struct btc_coexist
*btcoexist
,
223 bool force_exec
, u32 dis_rate_mask
)
225 coex_dm
->cur_ra_mask
= dis_rate_mask
;
228 (coex_dm
->pre_ra_mask
!= coex_dm
->cur_ra_mask
)) {
229 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_UPDATE_RAMASK
,
230 &coex_dm
->cur_ra_mask
);
232 coex_dm
->pre_ra_mask
= coex_dm
->cur_ra_mask
;
235 static void btc8821a1ant_auto_rate_fb_retry(struct btc_coexist
*btcoexist
,
236 bool force_exec
, u8 type
)
238 bool wifi_under_b_mode
= false;
240 coex_dm
->cur_arfr_type
= type
;
243 (coex_dm
->pre_arfr_type
!= coex_dm
->cur_arfr_type
)) {
244 switch (coex_dm
->cur_arfr_type
) {
245 case 0: /* normal mode */
246 btcoexist
->btc_write_4byte(btcoexist
, 0x430,
247 coex_dm
->backup_arfr_cnt1
);
248 btcoexist
->btc_write_4byte(btcoexist
, 0x434,
249 coex_dm
->backup_arfr_cnt2
);
252 btcoexist
->btc_get(btcoexist
,
253 BTC_GET_BL_WIFI_UNDER_B_MODE
,
255 if (wifi_under_b_mode
) {
256 btcoexist
->btc_write_4byte(btcoexist
, 0x430,
258 btcoexist
->btc_write_4byte(btcoexist
, 0x434,
261 btcoexist
->btc_write_4byte(btcoexist
, 0x430,
263 btcoexist
->btc_write_4byte(btcoexist
, 0x434,
272 coex_dm
->pre_arfr_type
= coex_dm
->cur_arfr_type
;
275 static void btc8821a1ant_retry_limit(struct btc_coexist
*btcoexist
,
276 bool force_exec
, u8 type
)
278 coex_dm
->cur_retry_limit_type
= type
;
281 (coex_dm
->pre_retry_limit_type
!= coex_dm
->cur_retry_limit_type
)) {
282 switch (coex_dm
->cur_retry_limit_type
) {
283 case 0: /* normal mode */
284 btcoexist
->btc_write_2byte(btcoexist
, 0x42a,
285 coex_dm
->backup_retry_limit
);
287 case 1: /* retry limit = 8 */
288 btcoexist
->btc_write_2byte(btcoexist
, 0x42a, 0x0808);
294 coex_dm
->pre_retry_limit_type
= coex_dm
->cur_retry_limit_type
;
297 static void btc8821a1ant_ampdu_max_time(struct btc_coexist
*btcoexist
,
298 bool force_exec
, u8 type
)
300 coex_dm
->cur_ampdu_time_type
= type
;
303 (coex_dm
->pre_ampdu_time_type
!= coex_dm
->cur_ampdu_time_type
)) {
304 switch (coex_dm
->cur_ampdu_time_type
) {
305 case 0: /* normal mode */
306 btcoexist
->btc_write_1byte(btcoexist
, 0x456,
307 coex_dm
->backup_ampdu_max_time
);
309 case 1: /* AMPDU time = 0x38 * 32us */
310 btcoexist
->btc_write_1byte(btcoexist
, 0x456, 0x38);
317 coex_dm
->pre_ampdu_time_type
= coex_dm
->cur_ampdu_time_type
;
320 static void btc8821a1ant_limited_tx(struct btc_coexist
*btcoexist
,
321 bool force_exec
, u8 ra_mask_type
,
322 u8 arfr_type
, u8 retry_limit_type
,
325 switch (ra_mask_type
) {
326 case 0: /* normal mode */
327 btc8821a1ant_update_ra_mask(btcoexist
, force_exec
, 0x0);
329 case 1: /* disable cck 1/2 */
330 btc8821a1ant_update_ra_mask(btcoexist
, force_exec
,
333 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
334 btc8821a1ant_update_ra_mask(btcoexist
, force_exec
,
341 btc8821a1ant_auto_rate_fb_retry(btcoexist
, force_exec
, arfr_type
);
342 btc8821a1ant_retry_limit(btcoexist
, force_exec
, retry_limit_type
);
343 btc8821a1ant_ampdu_max_time(btcoexist
, force_exec
, ampdu_time_type
);
346 static void btc8821a1ant_limited_rx(struct btc_coexist
*btcoexist
,
347 bool force_exec
, bool rej_ap_agg_pkt
,
348 bool bt_ctrl_agg_buf_size
, u8 agg_buf_size
)
350 bool reject_rx_agg
= rej_ap_agg_pkt
;
351 bool bt_ctrl_rx_agg_size
= bt_ctrl_agg_buf_size
;
352 u8 rx_agg_size
= agg_buf_size
;
354 /* Rx Aggregation related setting */
355 btcoexist
->btc_set(btcoexist
,
356 BTC_SET_BL_TO_REJ_AP_AGG_PKT
, &reject_rx_agg
);
357 /* decide BT control aggregation buf size or not */
358 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_CTRL_AGG_SIZE
,
359 &bt_ctrl_rx_agg_size
);
360 /* aggregation buf size, only work when BT control Rx agg size */
361 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_AGG_BUF_SIZE
, &rx_agg_size
);
362 /* real update aggregation setting */
363 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_AGGREGATE_CTRL
, NULL
);
366 static void btc8821a1ant_monitor_bt_ctr(struct btc_coexist
*btcoexist
)
368 u32 reg_hp_tx_rx
, reg_lp_tx_rx
, u4_tmp
;
369 u32 reg_hp_tx
= 0, reg_hp_rx
= 0, reg_lp_tx
= 0, reg_lp_rx
= 0;
371 reg_hp_tx_rx
= 0x770;
372 reg_lp_tx_rx
= 0x774;
374 u4_tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_hp_tx_rx
);
375 reg_hp_tx
= u4_tmp
& MASKLWORD
;
376 reg_hp_rx
= (u4_tmp
& MASKHWORD
) >> 16;
378 u4_tmp
= btcoexist
->btc_read_4byte(btcoexist
, reg_lp_tx_rx
);
379 reg_lp_tx
= u4_tmp
& MASKLWORD
;
380 reg_lp_rx
= (u4_tmp
& MASKHWORD
) >> 16;
382 coex_sta
->high_priority_tx
= reg_hp_tx
;
383 coex_sta
->high_priority_rx
= reg_hp_rx
;
384 coex_sta
->low_priority_tx
= reg_lp_tx
;
385 coex_sta
->low_priority_rx
= reg_lp_rx
;
388 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
391 static void btc8821a1ant_query_bt_info(struct btc_coexist
*btcoexist
)
393 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
394 u8 h2c_parameter
[1] = {0};
396 coex_sta
->c2h_bt_info_req_sent
= true;
398 h2c_parameter
[0] |= BIT0
; /* trigger */
400 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
401 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
404 btcoexist
->btc_fill_h2c(btcoexist
, 0x61, 1, h2c_parameter
);
407 static void btc8821a1ant_update_bt_link_info(struct btc_coexist
*btcoexist
)
409 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
410 bool bt_hs_on
= false;
412 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
414 bt_link_info
->bt_link_exist
= coex_sta
->bt_link_exist
;
415 bt_link_info
->sco_exist
= coex_sta
->sco_exist
;
416 bt_link_info
->a2dp_exist
= coex_sta
->a2dp_exist
;
417 bt_link_info
->pan_exist
= coex_sta
->pan_exist
;
418 bt_link_info
->hid_exist
= coex_sta
->hid_exist
;
420 /* work around for HS mode */
422 bt_link_info
->pan_exist
= true;
423 bt_link_info
->bt_link_exist
= true;
426 /* check if Sco only */
427 if (bt_link_info
->sco_exist
&&
428 !bt_link_info
->a2dp_exist
&&
429 !bt_link_info
->pan_exist
&&
430 !bt_link_info
->hid_exist
)
431 bt_link_info
->sco_only
= true;
433 bt_link_info
->sco_only
= false;
435 /* check if A2dp only */
436 if (!bt_link_info
->sco_exist
&&
437 bt_link_info
->a2dp_exist
&&
438 !bt_link_info
->pan_exist
&&
439 !bt_link_info
->hid_exist
)
440 bt_link_info
->a2dp_only
= true;
442 bt_link_info
->a2dp_only
= false;
444 /* check if Pan only */
445 if (!bt_link_info
->sco_exist
&&
446 !bt_link_info
->a2dp_exist
&&
447 bt_link_info
->pan_exist
&&
448 !bt_link_info
->hid_exist
)
449 bt_link_info
->pan_only
= true;
451 bt_link_info
->pan_only
= false;
453 /* check if Hid only */
454 if (!bt_link_info
->sco_exist
&&
455 !bt_link_info
->a2dp_exist
&&
456 !bt_link_info
->pan_exist
&&
457 bt_link_info
->hid_exist
)
458 bt_link_info
->hid_only
= true;
460 bt_link_info
->hid_only
= false;
463 static u8
btc8821a1ant_action_algorithm(struct btc_coexist
*btcoexist
)
465 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
466 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
467 bool bt_hs_on
= false;
468 u8 algorithm
= BT_8821A_1ANT_COEX_ALGO_UNDEFINED
;
469 u8 num_of_diff_profile
= 0;
471 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
473 if (!bt_link_info
->bt_link_exist
) {
474 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
475 "[BTCoex], No BT link exists!!!\n");
479 if (bt_link_info
->sco_exist
)
480 num_of_diff_profile
++;
481 if (bt_link_info
->hid_exist
)
482 num_of_diff_profile
++;
483 if (bt_link_info
->pan_exist
)
484 num_of_diff_profile
++;
485 if (bt_link_info
->a2dp_exist
)
486 num_of_diff_profile
++;
488 if (num_of_diff_profile
== 1) {
489 if (bt_link_info
->sco_exist
) {
490 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
491 "[BTCoex], BT Profile = SCO only\n");
492 algorithm
= BT_8821A_1ANT_COEX_ALGO_SCO
;
494 if (bt_link_info
->hid_exist
) {
495 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
496 "[BTCoex], BT Profile = HID only\n");
497 algorithm
= BT_8821A_1ANT_COEX_ALGO_HID
;
498 } else if (bt_link_info
->a2dp_exist
) {
499 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
500 "[BTCoex], BT Profile = A2DP only\n");
501 algorithm
= BT_8821A_1ANT_COEX_ALGO_A2DP
;
502 } else if (bt_link_info
->pan_exist
) {
504 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
506 "[BTCoex], BT Profile = PAN(HS) only\n");
507 algorithm
= BT_8821A_1ANT_COEX_ALGO_PANHS
;
509 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
511 "[BTCoex], BT Profile = PAN(EDR) only\n");
512 algorithm
= BT_8821A_1ANT_COEX_ALGO_PANEDR
;
516 } else if (num_of_diff_profile
== 2) {
517 if (bt_link_info
->sco_exist
) {
518 if (bt_link_info
->hid_exist
) {
519 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
520 "[BTCoex], BT Profile = SCO + HID\n");
521 algorithm
= BT_8821A_1ANT_COEX_ALGO_HID
;
522 } else if (bt_link_info
->a2dp_exist
) {
523 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
524 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
525 algorithm
= BT_8821A_1ANT_COEX_ALGO_SCO
;
526 } else if (bt_link_info
->pan_exist
) {
528 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
530 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
531 algorithm
= BT_8821A_1ANT_COEX_ALGO_SCO
;
533 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
535 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
536 algorithm
= BT_8821A_1ANT_COEX_ALGO_PANEDR_HID
;
540 if (bt_link_info
->hid_exist
&&
541 bt_link_info
->a2dp_exist
) {
542 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
543 "[BTCoex], BT Profile = HID + A2DP\n");
544 algorithm
= BT_8821A_1ANT_COEX_ALGO_HID_A2DP
;
545 } else if (bt_link_info
->hid_exist
&&
546 bt_link_info
->pan_exist
) {
548 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
550 "[BTCoex], BT Profile = HID + PAN(HS)\n");
551 algorithm
= BT_8821A_1ANT_COEX_ALGO_HID_A2DP
;
553 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
555 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
556 algorithm
= BT_8821A_1ANT_COEX_ALGO_PANEDR_HID
;
558 } else if (bt_link_info
->pan_exist
&&
559 bt_link_info
->a2dp_exist
) {
561 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
563 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
564 algorithm
= BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS
;
566 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
568 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
569 algorithm
= BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP
;
573 } else if (num_of_diff_profile
== 3) {
574 if (bt_link_info
->sco_exist
) {
575 if (bt_link_info
->hid_exist
&&
576 bt_link_info
->a2dp_exist
) {
577 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
578 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
579 algorithm
= BT_8821A_1ANT_COEX_ALGO_HID
;
580 } else if (bt_link_info
->hid_exist
&&
581 bt_link_info
->pan_exist
) {
583 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
585 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
586 algorithm
= BT_8821A_1ANT_COEX_ALGO_HID_A2DP
;
588 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
590 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
591 algorithm
= BT_8821A_1ANT_COEX_ALGO_PANEDR_HID
;
593 } else if (bt_link_info
->pan_exist
&&
594 bt_link_info
->a2dp_exist
) {
596 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
598 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
599 algorithm
= BT_8821A_1ANT_COEX_ALGO_SCO
;
601 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
603 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
604 algorithm
= BT_8821A_1ANT_COEX_ALGO_PANEDR_HID
;
608 if (bt_link_info
->hid_exist
&&
609 bt_link_info
->pan_exist
&&
610 bt_link_info
->a2dp_exist
) {
612 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
614 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
615 algorithm
= BT_8821A_1ANT_COEX_ALGO_HID_A2DP
;
617 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
619 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
620 algorithm
= BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR
;
624 } else if (num_of_diff_profile
>= 3) {
625 if (bt_link_info
->sco_exist
) {
626 if (bt_link_info
->hid_exist
&&
627 bt_link_info
->pan_exist
&&
628 bt_link_info
->a2dp_exist
) {
630 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
632 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
635 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
,
637 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
638 algorithm
= BT_8821A_1ANT_COEX_ALGO_PANEDR_HID
;
646 static void btc8821a1ant_set_sw_penalty_tx_rate(struct btc_coexist
*btcoexist
,
649 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
650 u8 h2c_parameter
[6] = {0};
652 h2c_parameter
[0] = 0x6; /* opCode, 0x6= Retry_Penalty*/
654 if (low_penalty_ra
) {
655 h2c_parameter
[1] |= BIT0
;
656 /* normal rate except MCS7/6/5, OFDM54/48/36 */
657 h2c_parameter
[2] = 0x00;
658 h2c_parameter
[3] = 0xf7; /* MCS7 or OFDM54 */
659 h2c_parameter
[4] = 0xf8; /* MCS6 or OFDM48 */
660 h2c_parameter
[5] = 0xf9; /* MCS5 or OFDM36 */
663 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
664 "[BTCoex], set WiFi Low-Penalty Retry: %s",
665 (low_penalty_ra
? "ON!!" : "OFF!!"));
667 btcoexist
->btc_fill_h2c(btcoexist
, 0x69, 6, h2c_parameter
);
670 static void btc8821a1ant_low_penalty_ra(struct btc_coexist
*btcoexist
,
671 bool force_exec
, bool low_penalty_ra
)
673 coex_dm
->cur_low_penalty_ra
= low_penalty_ra
;
676 if (coex_dm
->pre_low_penalty_ra
== coex_dm
->cur_low_penalty_ra
)
679 btc8821a1ant_set_sw_penalty_tx_rate(btcoexist
,
680 coex_dm
->cur_low_penalty_ra
);
682 coex_dm
->pre_low_penalty_ra
= coex_dm
->cur_low_penalty_ra
;
685 static void btc8821a1ant_set_coex_table(struct btc_coexist
*btcoexist
,
686 u32 val0x6c0
, u32 val0x6c4
,
687 u32 val0x6c8
, u8 val0x6cc
)
689 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
691 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
692 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0
);
693 btcoexist
->btc_write_4byte(btcoexist
, 0x6c0, val0x6c0
);
695 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
696 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4
);
697 btcoexist
->btc_write_4byte(btcoexist
, 0x6c4, val0x6c4
);
699 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
700 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8
);
701 btcoexist
->btc_write_4byte(btcoexist
, 0x6c8, val0x6c8
);
703 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
704 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc
);
705 btcoexist
->btc_write_1byte(btcoexist
, 0x6cc, val0x6cc
);
708 static void btc8821a1ant_coex_table(struct btc_coexist
*btcoexist
,
709 bool force_exec
, u32 val0x6c0
, u32 val0x6c4
,
710 u32 val0x6c8
, u8 val0x6cc
)
712 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
714 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
715 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
716 (force_exec
? "force to" : ""), val0x6c0
, val0x6c4
,
718 coex_dm
->cur_val_0x6c0
= val0x6c0
;
719 coex_dm
->cur_val_0x6c4
= val0x6c4
;
720 coex_dm
->cur_val_0x6c8
= val0x6c8
;
721 coex_dm
->cur_val_0x6cc
= val0x6cc
;
724 if ((coex_dm
->pre_val_0x6c0
== coex_dm
->cur_val_0x6c0
) &&
725 (coex_dm
->pre_val_0x6c4
== coex_dm
->cur_val_0x6c4
) &&
726 (coex_dm
->pre_val_0x6c8
== coex_dm
->cur_val_0x6c8
) &&
727 (coex_dm
->pre_val_0x6cc
== coex_dm
->cur_val_0x6cc
))
730 btc8821a1ant_set_coex_table(btcoexist
, val0x6c0
, val0x6c4
,
733 coex_dm
->pre_val_0x6c0
= coex_dm
->cur_val_0x6c0
;
734 coex_dm
->pre_val_0x6c4
= coex_dm
->cur_val_0x6c4
;
735 coex_dm
->pre_val_0x6c8
= coex_dm
->cur_val_0x6c8
;
736 coex_dm
->pre_val_0x6cc
= coex_dm
->cur_val_0x6cc
;
739 static void btc8821a1ant_coex_table_with_type(struct btc_coexist
*btcoexist
,
740 bool force_exec
, u8 type
)
744 btc8821a1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
745 0x55555555, 0xffffff, 0x3);
748 btc8821a1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
749 0x5a5a5a5a, 0xffffff, 0x3);
752 btc8821a1ant_coex_table(btcoexist
, force_exec
, 0x5a5a5a5a,
753 0x5a5a5a5a, 0xffffff, 0x3);
756 btc8821a1ant_coex_table(btcoexist
, force_exec
, 0x5a5a5a5a,
757 0xaaaaaaaa, 0xffffff, 0x3);
760 btc8821a1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
761 0x5a5a5a5a, 0xffffff, 0x3);
764 btc8821a1ant_coex_table(btcoexist
, force_exec
, 0x5a5a5a5a,
765 0xaaaa5a5a, 0xffffff, 0x3);
768 btc8821a1ant_coex_table(btcoexist
, force_exec
, 0x55555555,
769 0xaaaa5a5a, 0xffffff, 0x3);
772 btc8821a1ant_coex_table(btcoexist
, force_exec
, 0xaaaaaaaa,
773 0xaaaaaaaa, 0xffffff, 0x3);
780 static void btc8821a1ant_set_fw_ignore_wlan_act(struct btc_coexist
*btcoexist
,
783 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
784 u8 h2c_parameter
[1] = {0};
787 h2c_parameter
[0] |= BIT0
; /* function enable */
789 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
790 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
793 btcoexist
->btc_fill_h2c(btcoexist
, 0x63, 1, h2c_parameter
);
796 static void btc8821a1ant_ignore_wlan_act(struct btc_coexist
*btcoexist
,
797 bool force_exec
, bool enable
)
799 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
801 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
802 "[BTCoex], %s turn Ignore WlanAct %s\n",
803 (force_exec
? "force to" : ""), (enable
? "ON" : "OFF"));
804 coex_dm
->cur_ignore_wlan_act
= enable
;
807 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
808 "[BTCoex], pre_ignore_wlan_act = %d, cur_ignore_wlan_act = %d!!\n",
809 coex_dm
->pre_ignore_wlan_act
,
810 coex_dm
->cur_ignore_wlan_act
);
812 if (coex_dm
->pre_ignore_wlan_act
==
813 coex_dm
->cur_ignore_wlan_act
)
816 btc8821a1ant_set_fw_ignore_wlan_act(btcoexist
, enable
);
818 coex_dm
->pre_ignore_wlan_act
= coex_dm
->cur_ignore_wlan_act
;
821 static void btc8821a1ant_set_fw_ps_tdma(struct btc_coexist
*btcoexist
, u8 byte1
,
822 u8 byte2
, u8 byte3
, u8 byte4
, u8 byte5
)
824 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
825 u8 h2c_parameter
[5] = {0};
826 u8 real_byte1
= byte1
, real_byte5
= byte5
;
827 bool ap_enable
= false;
829 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
833 if (byte1
& BIT4
&& !(byte1
& BIT5
)) {
834 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
835 "[BTCoex], FW for 1Ant AP mode\n");
844 h2c_parameter
[0] = real_byte1
;
845 h2c_parameter
[1] = byte2
;
846 h2c_parameter
[2] = byte3
;
847 h2c_parameter
[3] = byte4
;
848 h2c_parameter
[4] = real_byte5
;
850 coex_dm
->ps_tdma_para
[0] = real_byte1
;
851 coex_dm
->ps_tdma_para
[1] = byte2
;
852 coex_dm
->ps_tdma_para
[2] = byte3
;
853 coex_dm
->ps_tdma_para
[3] = byte4
;
854 coex_dm
->ps_tdma_para
[4] = real_byte5
;
856 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
857 "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
859 h2c_parameter
[1] << 24 |
860 h2c_parameter
[2] << 16 |
861 h2c_parameter
[3] << 8 |
863 btcoexist
->btc_fill_h2c(btcoexist
, 0x60, 5, h2c_parameter
);
866 static void btc8821a1ant_set_lps_rpwm(struct btc_coexist
*btcoexist
,
867 u8 lps_val
, u8 rpwm_val
)
872 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_LPS_VAL
, &lps
);
873 btcoexist
->btc_set(btcoexist
, BTC_SET_U1_RPWM_VAL
, &rpwm
);
876 static void btc8821a1ant_lps_rpwm(struct btc_coexist
*btcoexist
,
877 bool force_exec
, u8 lps_val
, u8 rpwm_val
)
879 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
881 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
882 "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
883 (force_exec
? "force to" : ""), lps_val
, rpwm_val
);
884 coex_dm
->cur_lps
= lps_val
;
885 coex_dm
->cur_rpwm
= rpwm_val
;
888 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
889 "[BTCoex], LPS-RxBeaconMode = 0x%x, LPS-RPWM = 0x%x!!\n",
890 coex_dm
->cur_lps
, coex_dm
->cur_rpwm
);
892 if ((coex_dm
->pre_lps
== coex_dm
->cur_lps
) &&
893 (coex_dm
->pre_rpwm
== coex_dm
->cur_rpwm
)) {
894 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
895 "[BTCoex], LPS-RPWM_Last = 0x%x, LPS-RPWM_Now = 0x%x!!\n",
896 coex_dm
->pre_rpwm
, coex_dm
->cur_rpwm
);
901 btc8821a1ant_set_lps_rpwm(btcoexist
, lps_val
, rpwm_val
);
903 coex_dm
->pre_lps
= coex_dm
->cur_lps
;
904 coex_dm
->pre_rpwm
= coex_dm
->cur_rpwm
;
907 static void btc8821a1ant_sw_mechanism(struct btc_coexist
*btcoexist
,
910 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
912 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
913 "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra
);
915 btc8821a1ant_low_penalty_ra(btcoexist
, NORMAL_EXEC
, low_penalty_ra
);
918 static void btc8821a1ant_set_ant_path(struct btc_coexist
*btcoexist
,
919 u8 ant_pos_type
, bool init_hw_cfg
,
922 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
924 u8 h2c_parameter
[2] = {0};
927 /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna control by WL/BT */
928 u4_tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
931 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u4_tmp
);
933 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x975, 0x3, 0x3);
934 btcoexist
->btc_write_1byte(btcoexist
, 0xcb4, 0x77);
936 if (board_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
) {
937 /* tell firmware "antenna inverse"
938 * WRONG firmware antenna control code, need fw to fix
940 h2c_parameter
[0] = 1;
941 h2c_parameter
[1] = 1;
942 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
945 /* tell firmware "no antenna inverse"
946 * WRONG firmware antenna control code, need fw to fix
948 h2c_parameter
[0] = 0;
949 h2c_parameter
[1] = 1;
950 btcoexist
->btc_fill_h2c(btcoexist
, 0x65, 2,
953 } else if (wifi_off
) {
954 /* 0x4c[24:23] = 00, Set Antenna control
955 * by BT_RFE_CTRL BT Vendor 0xac = 0xf002
957 u4_tmp
= btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
960 btcoexist
->btc_write_4byte(btcoexist
, 0x4c, u4_tmp
);
963 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x765, 0x18, 0x3);
966 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x765, 0x18, 0x0);
969 /* ext switch setting */
970 switch (ant_pos_type
) {
971 case BTC_ANT_PATH_WIFI
:
972 btcoexist
->btc_write_1byte(btcoexist
, 0xcb4, 0x77);
973 if (board_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
974 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xcb7,
977 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xcb7,
980 case BTC_ANT_PATH_BT
:
981 btcoexist
->btc_write_1byte(btcoexist
, 0xcb4, 0x77);
982 if (board_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
983 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xcb7,
986 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xcb7,
990 case BTC_ANT_PATH_PTA
:
991 btcoexist
->btc_write_1byte(btcoexist
, 0xcb4, 0x66);
992 if (board_info
->btdm_ant_pos
== BTC_ANTENNA_AT_MAIN_PORT
)
993 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xcb7,
996 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0xcb7,
1002 static void btc8821a1ant_ps_tdma(struct btc_coexist
*btcoexist
,
1003 bool force_exec
, bool turn_on
, u8 type
)
1005 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1006 u8 rssi_adjust_val
= 0;
1008 coex_dm
->cur_ps_tdma_on
= turn_on
;
1009 coex_dm
->cur_ps_tdma
= type
;
1012 if (coex_dm
->cur_ps_tdma_on
) {
1013 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1014 "[BTCoex], ********** TDMA(on, %d) **********\n",
1015 coex_dm
->cur_ps_tdma
);
1017 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1018 "[BTCoex], ********** TDMA(off, %d) **********\n",
1019 coex_dm
->cur_ps_tdma
);
1021 if ((coex_dm
->pre_ps_tdma_on
== coex_dm
->cur_ps_tdma_on
) &&
1022 (coex_dm
->pre_ps_tdma
== coex_dm
->cur_ps_tdma
))
1028 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x1a,
1032 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x3a,
1034 rssi_adjust_val
= 11;
1037 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x2b,
1039 rssi_adjust_val
= 14;
1042 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x1d,
1046 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x15,
1048 rssi_adjust_val
= 17;
1051 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x15,
1055 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x20,
1059 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xc,
1063 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x25,
1067 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x21,
1069 rssi_adjust_val
= 18;
1072 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xa,
1076 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x15,
1078 rssi_adjust_val
= 20;
1081 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x0a,
1085 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x12,
1089 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x1e,
1093 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x13, 0xa,
1097 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x15,
1099 rssi_adjust_val
= 18;
1102 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x93, 0x25,
1104 rssi_adjust_val
= 14;
1107 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x35,
1111 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x25,
1115 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x25,
1119 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1121 rssi_adjust_val
= 22;
1124 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x15,
1126 rssi_adjust_val
= 22;
1129 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1131 rssi_adjust_val
= 22;
1134 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0xa,
1136 rssi_adjust_val
= 22;
1139 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0xe3, 0x25,
1141 rssi_adjust_val
= 22;
1144 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x69, 0x25,
1148 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0xab, 0x1a,
1152 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x30,
1156 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x1a,
1160 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x61, 0x35,
1164 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0xa3, 0x25,
1168 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x53, 0x1a,
1172 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x63, 0x1a,
1176 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0xd3, 0x12,
1180 /* SoftAP only with no sta associated, BT disable, TDMA
1181 * mode for power saving
1183 * here softap mode screen off will cost 70-80mA for
1186 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x23, 0x18,
1190 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x15,
1194 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x20,
1198 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x51, 0x30,
1203 /* disable PS tdma */
1207 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x8, 0x0, 0x0,
1209 btc8821a1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
1214 /* Software control, Antenna at BT side */
1215 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1217 btc8821a1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
1221 /* Software control, Antenna at WiFi side */
1222 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1224 btc8821a1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_WIFI
,
1229 btc8821a1ant_set_fw_ps_tdma(btcoexist
, 0x0, 0x0, 0x0,
1231 btc8821a1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
1236 rssi_adjust_val
= 0;
1237 btcoexist
->btc_set(btcoexist
,
1238 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE
, &rssi_adjust_val
);
1240 /* update pre state */
1241 coex_dm
->pre_ps_tdma_on
= coex_dm
->cur_ps_tdma_on
;
1242 coex_dm
->pre_ps_tdma
= coex_dm
->cur_ps_tdma
;
1245 static bool btc8821a1ant_is_common_action(struct btc_coexist
*btcoexist
)
1247 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1248 bool common
= false, wifi_connected
= false, wifi_busy
= false;
1250 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1252 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1254 if (!wifi_connected
&&
1255 BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE
==
1256 coex_dm
->bt_status
) {
1257 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1258 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
1259 btc8821a1ant_sw_mechanism(btcoexist
, false);
1262 } else if (wifi_connected
&&
1263 (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE
==
1264 coex_dm
->bt_status
)) {
1265 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1266 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
1267 btc8821a1ant_sw_mechanism(btcoexist
, false);
1270 } else if (!wifi_connected
&&
1271 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE
==
1272 coex_dm
->bt_status
)) {
1273 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1274 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
1275 btc8821a1ant_sw_mechanism(btcoexist
, false);
1278 } else if (wifi_connected
&&
1279 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE
==
1280 coex_dm
->bt_status
)) {
1281 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1282 "[BTCoex], Wifi connected + BT connected-idle!!\n");
1283 btc8821a1ant_sw_mechanism(btcoexist
, false);
1286 } else if (!wifi_connected
&&
1287 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE
!=
1288 coex_dm
->bt_status
)) {
1289 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1290 "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
1291 btc8821a1ant_sw_mechanism(btcoexist
, false);
1296 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1297 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
1299 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1300 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
1309 static void btc8821a1ant_ps_tdma_check_for_pwr_save(struct btc_coexist
*btcoex
,
1314 btcoex
->btc_get(btcoex
, BTC_GET_U1_LPS_MODE
, &lps_mode
);
1317 /* already under LPS state */
1319 /* keep state under LPS, do nothing */
1321 /* will leave LPS state, turn off psTdma first */
1322 btc8821a1ant_ps_tdma(btcoex
, NORMAL_EXEC
, false, 0);
1327 /* will enter LPS state, turn off psTdma first */
1328 btc8821a1ant_ps_tdma(btcoex
, NORMAL_EXEC
, false, 0);
1330 /* keep state under NO PS state, do nothing */
1335 static void btc8821a1ant_power_save_state(struct btc_coexist
*btcoexist
,
1336 u8 ps_type
, u8 lps_val
, u8 rpwm_val
)
1338 bool low_pwr_disable
= false;
1341 case BTC_PS_WIFI_NATIVE
:
1342 /* recover to original 32k low power setting */
1343 low_pwr_disable
= false;
1344 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1346 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_NORMAL_LPS
, NULL
);
1349 btc8821a1ant_ps_tdma_check_for_pwr_save(btcoexist
,
1351 btc8821a1ant_lps_rpwm(btcoexist
, NORMAL_EXEC
, lps_val
,
1353 /* when coex force to enter LPS, do not enter 32k low power */
1354 low_pwr_disable
= true;
1355 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_DISABLE_LOW_POWER
,
1357 /* power save must executed before psTdma */
1358 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_ENTER_LPS
, NULL
);
1360 case BTC_PS_LPS_OFF
:
1361 btc8821a1ant_ps_tdma_check_for_pwr_save(btcoexist
, false);
1362 btcoexist
->btc_set(btcoexist
, BTC_SET_ACT_LEAVE_LPS
, NULL
);
1369 static void btc8821a1ant_coex_under_5g(struct btc_coexist
*btcoexist
)
1371 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1373 btc8821a1ant_ignore_wlan_act(btcoexist
, NORMAL_EXEC
, true);
1375 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 10);
1377 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1379 btc8821a1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
1381 btc8821a1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false, false, 5);
1384 /***********************************************
1386 * Software Coex Mechanism start
1388 ***********************************************/
1390 /* SCO only or SCO+PAN(HS) */
1391 static void btc8821a1ant_action_sco(struct btc_coexist
*btcoexist
)
1393 btc8821a1ant_sw_mechanism(btcoexist
, true);
1396 static void btc8821a1ant_action_hid(struct btc_coexist
*btcoexist
)
1398 btc8821a1ant_sw_mechanism(btcoexist
, true);
1401 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
1402 static void btc8821a1ant_action_a2dp(struct btc_coexist
*btcoexist
)
1404 btc8821a1ant_sw_mechanism(btcoexist
, false);
1407 static void btc8821a1ant_action_a2dp_pan_hs(struct btc_coexist
*btcoexist
)
1409 btc8821a1ant_sw_mechanism(btcoexist
, false);
1412 static void btc8821a1ant_action_pan_edr(struct btc_coexist
*btcoexist
)
1414 btc8821a1ant_sw_mechanism(btcoexist
, false);
1418 static void btc8821a1ant_action_pan_hs(struct btc_coexist
*btcoexist
)
1420 btc8821a1ant_sw_mechanism(btcoexist
, false);
1424 static void btc8821a1ant_action_pan_edr_a2dp(struct btc_coexist
*btcoexist
)
1426 btc8821a1ant_sw_mechanism(btcoexist
, false);
1429 static void btc8821a1ant_action_pan_edr_hid(struct btc_coexist
*btcoexist
)
1431 btc8821a1ant_sw_mechanism(btcoexist
, true);
1434 /* HID+A2DP+PAN(EDR) */
1435 static void btc8821a1ant_action_hid_a2dp_pan_edr(struct btc_coexist
*btcoexist
)
1437 btc8821a1ant_sw_mechanism(btcoexist
, true);
1440 static void btc8821a1ant_action_hid_a2dp(struct btc_coexist
*btcoexist
)
1442 btc8821a1ant_sw_mechanism(btcoexist
, true);
1445 /***********************************************
1447 * Non-Software Coex Mechanism start
1449 ***********************************************/
1451 void btc8821a1ant_action_wifi_multi_port(struct btc_coexist
*btcoexist
)
1453 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1455 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1456 /* tdma and coex table */
1457 if (coex_dm
->bt_status
== BT_8821A_1ANT_BT_STATUS_ACL_BUSY
) {
1458 if (bt_link_info
->a2dp_exist
) {
1459 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1460 btc8821a1ant_coex_table_with_type(btcoexist
,
1462 } else if (bt_link_info
->a2dp_exist
&&
1463 bt_link_info
->pan_exist
) {
1464 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1465 btc8821a1ant_coex_table_with_type(btcoexist
,
1468 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1469 btc8821a1ant_coex_table_with_type(btcoexist
,
1472 } else if ((coex_dm
->bt_status
== BT_8821A_1ANT_BT_STATUS_SCO_BUSY
) ||
1473 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY
==
1474 coex_dm
->bt_status
)) {
1475 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist
,
1476 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN
);
1478 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1479 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1484 void btc8821a1ant_action_wifi_not_connected_asso_auth(
1485 struct btc_coexist
*btcoexist
)
1487 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1489 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0,
1492 /* tdma and coex table */
1493 if ((bt_link_info
->sco_exist
) || (bt_link_info
->hid_exist
)) {
1494 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1495 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1496 } else if ((bt_link_info
->a2dp_exist
) || (bt_link_info
->pan_exist
)) {
1497 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1498 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1500 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1501 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1506 static void btc8821a1ant_action_hs(struct btc_coexist
*btcoexist
)
1508 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 5);
1509 btc8821a1ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 2);
1512 static void btc8821a1ant_action_bt_inquiry(struct btc_coexist
*btcoexist
)
1514 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1515 bool wifi_connected
= false;
1516 bool ap_enable
= false;
1517 bool wifi_busy
= false, bt_busy
= false;
1519 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1521 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
1523 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1524 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
1526 if (!wifi_connected
&& !coex_sta
->wifi_is_high_pri_task
) {
1527 btc8821a1ant_power_save_state(btcoexist
,
1528 BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1529 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1530 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1531 } else if ((bt_link_info
->sco_exist
) || (bt_link_info
->a2dp_exist
) ||
1532 (bt_link_info
->hid_only
)) {
1533 /* SCO/HID-only busy */
1534 btc8821a1ant_power_save_state(btcoexist
,
1535 BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1536 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 32);
1537 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1538 } else if ((bt_link_info
->a2dp_exist
) && (bt_link_info
->hid_exist
)) {
1540 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1542 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1544 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1545 } else if ((bt_link_info
->pan_exist
) || (wifi_busy
)) {
1546 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1548 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1550 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1552 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1554 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1555 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 7);
1559 static void btc8821a1ant_act_bt_sco_hid_only_busy(struct btc_coexist
*btcoexist
,
1562 /* tdma and coex table */
1563 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 5);
1565 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1568 static void btc8821a1ant_act_wifi_con_bt_acl_busy(struct btc_coexist
*btcoexist
,
1573 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1575 bt_rssi_state
= btc8821a1ant_bt_rssi_state(btcoexist
, 2, 28, 0);
1577 if (bt_link_info
->hid_only
) {
1579 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist
,
1581 coex_dm
->auto_tdma_adjust
= false;
1583 } else if (bt_link_info
->a2dp_only
) {
1585 if (wifi_status
== BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE
) {
1586 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 32);
1587 btc8821a1ant_coex_table_with_type(btcoexist
,
1589 coex_dm
->auto_tdma_adjust
= false;
1590 } else if ((bt_rssi_state
!= BTC_RSSI_STATE_HIGH
) &&
1591 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1592 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1593 btc8821a1ant_coex_table_with_type(btcoexist
,
1596 /* for low BT RSSI */
1597 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1598 btc8821a1ant_coex_table_with_type(btcoexist
,
1600 coex_dm
->auto_tdma_adjust
= false;
1602 } else if (bt_link_info
->hid_exist
&& bt_link_info
->a2dp_exist
) {
1604 if ((bt_rssi_state
== BTC_RSSI_STATE_HIGH
) ||
1605 (bt_rssi_state
== BTC_RSSI_STATE_STAY_HIGH
)) {
1606 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1608 coex_dm
->auto_tdma_adjust
= false;
1611 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
,
1613 coex_dm
->auto_tdma_adjust
= false;
1616 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1617 } else if ((bt_link_info
->pan_only
) ||
1618 (bt_link_info
->hid_exist
&& bt_link_info
->pan_exist
)) {
1619 /* PAN(OPP, FTP), HID+PAN(OPP, FTP) */
1620 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 3);
1621 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 6);
1622 coex_dm
->auto_tdma_adjust
= false;
1623 } else if (((bt_link_info
->a2dp_exist
) && (bt_link_info
->pan_exist
)) ||
1624 (bt_link_info
->hid_exist
&& bt_link_info
->a2dp_exist
&&
1625 bt_link_info
->pan_exist
)) {
1626 /* A2DP+PAN(OPP, FTP), HID+A2DP+PAN(OPP, FTP) */
1627 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 43);
1628 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1629 coex_dm
->auto_tdma_adjust
= false;
1631 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 11);
1632 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1633 coex_dm
->auto_tdma_adjust
= false;
1638 void btc8821a1ant_action_wifi_not_connected(struct btc_coexist
*btcoexist
)
1640 /* power save state */
1641 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1643 /* tdma and coex table */
1644 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1645 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 0);
1648 static void btc8821a1ant_act_wifi_not_conn_scan(struct btc_coexist
*btcoexist
)
1650 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1652 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1654 /* tdma and coex table */
1655 if (coex_dm
->bt_status
== BT_8821A_1ANT_BT_STATUS_ACL_BUSY
) {
1656 if (bt_link_info
->a2dp_exist
) {
1657 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1658 btc8821a1ant_coex_table_with_type(btcoexist
,
1660 } else if (bt_link_info
->a2dp_exist
&&
1661 bt_link_info
->pan_exist
) {
1662 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 22);
1663 btc8821a1ant_coex_table_with_type(btcoexist
,
1666 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1667 btc8821a1ant_coex_table_with_type(btcoexist
,
1670 } else if ((coex_dm
->bt_status
== BT_8821A_1ANT_BT_STATUS_SCO_BUSY
) ||
1671 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY
==
1672 coex_dm
->bt_status
)) {
1673 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist
,
1674 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN
);
1676 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1677 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1682 void btc8821a1ant_action_wifi_connected_scan(struct btc_coexist
*btcoexist
)
1684 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1686 /* power save state */
1687 btc8821a1ant_power_save_state(btcoexist
,
1688 BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1690 /* tdma and coex table */
1691 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) {
1692 if (bt_link_info
->a2dp_exist
) {
1693 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1694 btc8821a1ant_coex_table_with_type(btcoexist
,
1697 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1698 btc8821a1ant_coex_table_with_type(btcoexist
,
1701 } else if ((coex_dm
->bt_status
== BT_8821A_1ANT_BT_STATUS_SCO_BUSY
) ||
1702 (coex_dm
->bt_status
==
1703 BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY
)) {
1704 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist
,
1705 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN
);
1707 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1708 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1712 static void btc8821a1ant_act_wifi_conn_sp_pkt(struct btc_coexist
*btcoexist
)
1714 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1716 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
1719 /* tdma and coex table */
1720 if ((bt_link_info
->sco_exist
) || (bt_link_info
->hid_exist
) ||
1721 (bt_link_info
->a2dp_exist
)) {
1722 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 32);
1723 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1726 if ((bt_link_info
->hid_exist
) && (bt_link_info
->a2dp_exist
)) {
1727 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 14);
1728 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 1);
1729 } else if (bt_link_info
->pan_exist
) {
1730 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, true, 20);
1731 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 4);
1733 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1734 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
1738 static void btc8821a1ant_action_wifi_connected(struct btc_coexist
*btcoexist
)
1740 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1741 bool wifi_busy
= false;
1742 bool scan
= false, link
= false, roam
= false;
1743 bool under_4way
= false;
1744 bool ap_enable
= false;
1746 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1747 "[BTCoex], CoexForWifiConnect()===>\n");
1749 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_4_WAY_PROGRESS
,
1752 btc8821a1ant_act_wifi_conn_sp_pkt(btcoexist
);
1753 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1754 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
1758 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
1759 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
1760 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
1761 if (scan
|| link
|| roam
) {
1763 btc8821a1ant_action_wifi_connected_scan(btcoexist
);
1765 btc8821a1ant_act_wifi_conn_sp_pkt(btcoexist
);
1767 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1768 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
1772 /* power save state*/
1773 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
,
1775 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
, &wifi_busy
);
1776 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY
==
1777 coex_dm
->bt_status
&& !ap_enable
&&
1778 !btcoexist
->bt_link_info
.hid_only
) {
1779 if (!wifi_busy
&& btcoexist
->bt_link_info
.a2dp_only
)
1781 btc8821a1ant_power_save_state(btcoexist
,
1782 BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
1784 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_LPS_ON
,
1787 btc8821a1ant_power_save_state(btcoexist
,
1792 /* tdma and coex table */
1794 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) {
1795 btc8821a1ant_act_wifi_con_bt_acl_busy(btcoexist
,
1796 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE
);
1797 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY
==
1798 coex_dm
->bt_status
) ||
1799 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY
==
1800 coex_dm
->bt_status
)) {
1801 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist
,
1802 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE
);
1804 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1805 btc8821a1ant_coex_table_with_type(btcoexist
,
1809 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) {
1810 btc8821a1ant_act_wifi_con_bt_acl_busy(btcoexist
,
1811 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY
);
1812 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY
==
1813 coex_dm
->bt_status
) ||
1814 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY
==
1815 coex_dm
->bt_status
)) {
1816 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist
,
1817 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY
);
1819 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 8);
1820 btc8821a1ant_coex_table_with_type(btcoexist
,
1826 static void btc8821a1ant_run_sw_coex_mech(struct btc_coexist
*btcoexist
)
1828 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1831 algorithm
= btc8821a1ant_action_algorithm(btcoexist
);
1832 coex_dm
->cur_algorithm
= algorithm
;
1834 if (!btc8821a1ant_is_common_action(btcoexist
)) {
1835 switch (coex_dm
->cur_algorithm
) {
1836 case BT_8821A_1ANT_COEX_ALGO_SCO
:
1837 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1838 "[BTCoex], Action algorithm = SCO\n");
1839 btc8821a1ant_action_sco(btcoexist
);
1841 case BT_8821A_1ANT_COEX_ALGO_HID
:
1842 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1843 "[BTCoex], Action algorithm = HID\n");
1844 btc8821a1ant_action_hid(btcoexist
);
1846 case BT_8821A_1ANT_COEX_ALGO_A2DP
:
1847 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1848 "[BTCoex], Action algorithm = A2DP\n");
1849 btc8821a1ant_action_a2dp(btcoexist
);
1851 case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS
:
1852 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1853 "[BTCoex], Action algorithm = A2DP+PAN(HS)\n");
1854 btc8821a1ant_action_a2dp_pan_hs(btcoexist
);
1856 case BT_8821A_1ANT_COEX_ALGO_PANEDR
:
1857 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1858 "[BTCoex], Action algorithm = PAN(EDR)\n");
1859 btc8821a1ant_action_pan_edr(btcoexist
);
1861 case BT_8821A_1ANT_COEX_ALGO_PANHS
:
1862 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1863 "[BTCoex], Action algorithm = HS mode\n");
1864 btc8821a1ant_action_pan_hs(btcoexist
);
1866 case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP
:
1867 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1868 "[BTCoex], Action algorithm = PAN+A2DP\n");
1869 btc8821a1ant_action_pan_edr_a2dp(btcoexist
);
1871 case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID
:
1872 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1873 "[BTCoex], Action algorithm = PAN(EDR)+HID\n");
1874 btc8821a1ant_action_pan_edr_hid(btcoexist
);
1876 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR
:
1877 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1878 "[BTCoex], Action algorithm = HID+A2DP+PAN\n");
1879 btc8821a1ant_action_hid_a2dp_pan_edr(btcoexist
);
1881 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP
:
1882 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1883 "[BTCoex], Action algorithm = HID+A2DP\n");
1884 btc8821a1ant_action_hid_a2dp(btcoexist
);
1887 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1888 "[BTCoex], Action algorithm = coexist All Off!!\n");
1889 /*btc8821a1ant_coex_all_off(btcoexist);*/
1892 coex_dm
->pre_algorithm
= coex_dm
->cur_algorithm
;
1896 static void btc8821a1ant_run_coexist_mechanism(struct btc_coexist
*btcoexist
)
1898 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
1899 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
1900 bool wifi_connected
= false, bt_hs_on
= false;
1901 bool increase_scan_dev_num
= false;
1902 bool bt_ctrl_agg_buf_size
= false;
1903 u8 agg_buf_size
= 5;
1904 u8 wifi_rssi_state
= BTC_RSSI_STATE_HIGH
;
1905 u32 wifi_link_status
= 0;
1906 u32 num_of_wifi_link
= 0;
1907 bool wifi_under_5g
= false;
1909 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1910 "[BTCoex], RunCoexistMechanism()===>\n");
1912 if (btcoexist
->manual_control
) {
1913 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1914 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
1918 if (btcoexist
->stop_coex_dm
) {
1919 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1920 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
1924 if (coex_sta
->under_ips
) {
1925 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1926 "[BTCoex], wifi is under IPS !!!\n");
1930 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
1931 if (wifi_under_5g
) {
1932 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
1933 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
1934 btc8821a1ant_coex_under_5g(btcoexist
);
1938 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) ||
1939 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY
== coex_dm
->bt_status
) ||
1940 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY
== coex_dm
->bt_status
))
1941 increase_scan_dev_num
= true;
1943 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_INC_SCAN_DEV_NUM
,
1944 &increase_scan_dev_num
);
1946 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
1949 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
1951 num_of_wifi_link
= wifi_link_status
>> 16;
1952 if ((num_of_wifi_link
>= 2) ||
1953 (wifi_link_status
& WIFI_P2P_GO_CONNECTED
)) {
1954 btc8821a1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
1955 btc8821a1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
1956 bt_ctrl_agg_buf_size
, agg_buf_size
);
1957 btc8821a1ant_action_wifi_multi_port(btcoexist
);
1961 if (!bt_link_info
->sco_exist
&& !bt_link_info
->hid_exist
) {
1962 btc8821a1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
1964 if (wifi_connected
) {
1966 btc8821a1ant_wifi_rssi_state(btcoexist
, 1, 2,
1968 btc8821a1ant_limited_tx(btcoexist
,
1972 btc8821a1ant_limited_tx(btcoexist
, NORMAL_EXEC
,
1977 if (bt_link_info
->sco_exist
) {
1978 bt_ctrl_agg_buf_size
= true;
1980 } else if (bt_link_info
->hid_exist
) {
1981 bt_ctrl_agg_buf_size
= true;
1983 } else if (bt_link_info
->a2dp_exist
|| bt_link_info
->pan_exist
) {
1984 bt_ctrl_agg_buf_size
= true;
1987 btc8821a1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
1988 bt_ctrl_agg_buf_size
, agg_buf_size
);
1990 btc8821a1ant_run_sw_coex_mech(btcoexist
);
1992 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
1993 if (coex_sta
->c2h_bt_inquiry_page
) {
1994 btc8821a1ant_action_bt_inquiry(btcoexist
);
1996 } else if (bt_hs_on
) {
1997 btc8821a1ant_action_hs(btcoexist
);
2001 if (!wifi_connected
) {
2002 bool scan
= false, link
= false, roam
= false;
2004 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2005 "[BTCoex], wifi is non connected-idle !!!\n");
2007 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2008 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2009 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2011 if (scan
|| link
|| roam
) {
2013 btc8821a1ant_act_wifi_not_conn_scan(btcoexist
);
2015 btc8821a1ant_action_wifi_not_connected_asso_auth(
2018 btc8821a1ant_action_wifi_not_connected(btcoexist
);
2022 btc8821a1ant_action_wifi_connected(btcoexist
);
2026 static void btc8821a1ant_init_coex_dm(struct btc_coexist
*btcoexist
)
2028 /* force to reset coex mechanism
2031 btc8821a1ant_sw_mechanism(btcoexist
, false);
2033 btc8821a1ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 0);
2036 static void btc8821a1ant_init_hw_config(struct btc_coexist
*btcoexist
,
2037 bool back_up
, bool wifi_only
)
2039 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2041 bool wifi_under_5g
= false;
2043 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2044 "[BTCoex], 1Ant Init HW Config!!\n");
2050 coex_dm
->backup_arfr_cnt1
= btcoexist
->btc_read_4byte(btcoexist
,
2052 coex_dm
->backup_arfr_cnt2
= btcoexist
->btc_read_4byte(btcoexist
,
2054 coex_dm
->backup_retry_limit
=
2055 btcoexist
->btc_read_2byte(btcoexist
, 0x42a);
2056 coex_dm
->backup_ampdu_max_time
=
2057 btcoexist
->btc_read_1byte(btcoexist
, 0x456);
2060 /* 0x790[5:0] = 0x5 */
2061 u1_tmp
= btcoexist
->btc_read_1byte(btcoexist
, 0x790);
2064 btcoexist
->btc_write_1byte(btcoexist
, 0x790, u1_tmp
);
2066 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2068 /* Antenna config */
2070 btc8821a1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
,
2073 btc8821a1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_PTA
,
2076 btc8821a1ant_coex_table_with_type(btcoexist
, FORCE_EXEC
, 0);
2078 /* Enable counter statistics
2079 * 0x76e[3] =1, WLAN_Act control by PTA
2081 btcoexist
->btc_write_1byte(btcoexist
, 0x76e, 0xc);
2082 btcoexist
->btc_write_1byte(btcoexist
, 0x778, 0x3);
2083 btcoexist
->btc_write_1byte_bitmask(btcoexist
, 0x40, 0x20, 0x1);
2086 /**************************************************************
2087 * extern function start with ex_btc8821a1ant_
2088 **************************************************************/
2089 void ex_btc8821a1ant_init_hwconfig(struct btc_coexist
*btcoexist
, bool wifionly
)
2091 btc8821a1ant_init_hw_config(btcoexist
, true, wifionly
);
2092 btcoexist
->auto_report_1ant
= true;
2095 void ex_btc8821a1ant_init_coex_dm(struct btc_coexist
*btcoexist
)
2097 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2099 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2100 "[BTCoex], Coex Mechanism Init!!\n");
2102 btcoexist
->stop_coex_dm
= false;
2104 btc8821a1ant_init_coex_dm(btcoexist
);
2106 btc8821a1ant_query_bt_info(btcoexist
);
2109 void ex_btc8821a1ant_display_coex_info(struct btc_coexist
*btcoexist
,
2112 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
2113 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
2114 struct btc_bt_link_info
*bt_link_info
= &btcoexist
->bt_link_info
;
2115 u8 u1_tmp
[4], i
, bt_info_ext
, ps_tdma_case
= 0;
2118 bool roam
= false, scan
= false, link
= false, wifi_under_5g
= false;
2119 bool bt_hs_on
= false, wifi_busy
= false;
2120 long wifi_rssi
= 0, bt_hs_rssi
= 0;
2121 u32 wifi_bw
, wifi_traffic_dir
;
2122 u8 wifi_dot11_chnl
, wifi_hs_chnl
;
2123 u32 fw_ver
= 0, bt_patch_ver
= 0;
2125 seq_puts(m
, "\n ============[BT Coexist info]============");
2127 if (btcoexist
->manual_control
) {
2128 seq_puts(m
, "\n ============[Under Manual Control]============");
2129 seq_puts(m
, "\n ==========================================");
2131 if (btcoexist
->stop_coex_dm
) {
2132 seq_puts(m
, "\n ============[Coex is STOPPED]============");
2133 seq_puts(m
, "\n ==========================================");
2136 seq_printf(m
, "\n %-35s = %d/ %d/ %d",
2137 "Ant PG Num/ Ant Mech/ Ant Pos:",
2138 board_info
->pg_ant_num
,
2139 board_info
->btdm_ant_num
,
2140 board_info
->btdm_ant_pos
);
2142 seq_printf(m
, "\n %-35s = %s / %d", "BT stack/ hci ext ver",
2143 ((stack_info
->profile_notified
) ? "Yes" : "No"),
2144 stack_info
->hci_version
);
2146 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
,
2148 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
2149 seq_printf(m
, "\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
2150 "CoexVer/ FwVer/ PatchVer",
2151 glcoex_ver_date_8821a_1ant
,
2152 glcoex_ver_8821a_1ant
,
2153 fw_ver
, bt_patch_ver
,
2156 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
,
2158 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_DOT11_CHNL
,
2160 btcoexist
->btc_get(btcoexist
, BTC_GET_U1_WIFI_HS_CHNL
,
2162 seq_printf(m
, "\n %-35s = %d / %d(%d)",
2163 "Dot11 channel / HsChnl(HsMode)",
2164 wifi_dot11_chnl
, wifi_hs_chnl
, bt_hs_on
);
2166 seq_printf(m
, "\n %-35s = %3ph ",
2167 "H2C Wifi inform bt chnl Info",
2168 coex_dm
->wifi_chnl_info
);
2170 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_WIFI_RSSI
, &wifi_rssi
);
2171 btcoexist
->btc_get(btcoexist
, BTC_GET_S4_HS_RSSI
, &bt_hs_rssi
);
2172 seq_printf(m
, "\n %-35s = %d/ %d", "Wifi rssi/ HS rssi",
2173 (int)wifi_rssi
, (int)bt_hs_rssi
);
2175 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_SCAN
, &scan
);
2176 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_LINK
, &link
);
2177 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_ROAM
, &roam
);
2178 seq_printf(m
, "\n %-35s = %d/ %d/ %d ", "Wifi link/ roam/ scan",
2181 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
,
2183 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
,
2185 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_BUSY
,
2187 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION
,
2189 seq_printf(m
, "\n %-35s = %s / %s/ %s ", "Wifi status",
2190 (wifi_under_5g
? "5G" : "2.4G"),
2191 ((wifi_bw
== BTC_WIFI_BW_LEGACY
) ? "Legacy" :
2192 (((wifi_bw
== BTC_WIFI_BW_HT40
) ? "HT40" : "HT20"))),
2193 ((!wifi_busy
) ? "idle" :
2194 ((wifi_traffic_dir
== BTC_WIFI_TRAFFIC_TX
) ?
2195 "uplink" : "downlink")));
2196 seq_printf(m
, "\n %-35s = [%s/ %d/ %d] ",
2197 "BT [status/ rssi/ retryCnt]",
2198 ((coex_sta
->bt_disabled
) ? ("disabled") :
2199 ((coex_sta
->c2h_bt_inquiry_page
) ? ("inquiry/page scan") :
2200 ((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE
==
2201 coex_dm
->bt_status
) ?
2202 "non-connected idle" :
2203 ((BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE
==
2204 coex_dm
->bt_status
) ?
2205 "connected-idle" : "busy")))),
2206 coex_sta
->bt_rssi
, coex_sta
->bt_retry_cnt
);
2208 seq_printf(m
, "\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
2209 bt_link_info
->sco_exist
,
2210 bt_link_info
->hid_exist
,
2211 bt_link_info
->pan_exist
,
2212 bt_link_info
->a2dp_exist
);
2213 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_BT_LINK_INFO
, m
);
2215 bt_info_ext
= coex_sta
->bt_info_ext
;
2216 seq_printf(m
, "\n %-35s = %s",
2217 "BT Info A2DP rate",
2218 (bt_info_ext
& BIT0
) ?
2219 "Basic rate" : "EDR rate");
2221 for (i
= 0; i
< BT_INFO_SRC_8821A_1ANT_MAX
; i
++) {
2222 if (coex_sta
->bt_info_c2h_cnt
[i
]) {
2223 seq_printf(m
, "\n %-35s = %7ph(%d)",
2224 glbt_info_src_8821a_1ant
[i
],
2225 coex_sta
->bt_info_c2h
[i
],
2226 coex_sta
->bt_info_c2h_cnt
[i
]);
2229 seq_printf(m
, "\n %-35s = %s/%s, (0x%x/0x%x)",
2230 "PS state, IPS/LPS, (lps/rpwm)",
2231 ((coex_sta
->under_ips
? "IPS ON" : "IPS OFF")),
2232 ((coex_sta
->under_lps
? "LPS ON" : "LPS OFF")),
2233 btcoexist
->bt_info
.lps_val
,
2234 btcoexist
->bt_info
.rpwm_val
);
2235 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_FW_PWR_MODE_CMD
, m
);
2237 if (!btcoexist
->manual_control
) {
2239 seq_printf(m
, "\n %-35s",
2240 "============[Sw mechanism]============");
2242 seq_printf(m
, "\n %-35s = %d", "SM[LowPenaltyRA]",
2243 coex_dm
->cur_low_penalty_ra
);
2245 seq_printf(m
, "\n %-35s = %s/ %s/ %d ",
2246 "DelBA/ BtCtrlAgg/ AggSize",
2247 (btcoexist
->bt_info
.reject_agg_pkt
? "Yes" : "No"),
2248 (btcoexist
->bt_info
.bt_ctrl_buf_size
? "Yes" : "No"),
2249 btcoexist
->bt_info
.agg_buf_size
);
2250 seq_printf(m
, "\n %-35s = 0x%x ", "Rate Mask",
2251 btcoexist
->bt_info
.ra_mask
);
2254 seq_printf(m
, "\n %-35s",
2255 "============[Fw mechanism]============");
2257 ps_tdma_case
= coex_dm
->cur_ps_tdma
;
2258 seq_printf(m
, "\n %-35s = %5ph case-%d (auto:%d)",
2260 coex_dm
->ps_tdma_para
,
2262 coex_dm
->auto_tdma_adjust
);
2264 seq_printf(m
, "\n %-35s = 0x%x ",
2265 "Latest error condition(should be 0)",
2266 coex_dm
->error_condition
);
2268 seq_printf(m
, "\n %-35s = %d ", "IgnWlanAct",
2269 coex_dm
->cur_ignore_wlan_act
);
2273 seq_printf(m
, "\n %-35s", "============[Hw setting]============");
2275 seq_printf(m
, "\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2276 "backup ARFR1/ARFR2/RL/AMaxTime",
2277 coex_dm
->backup_arfr_cnt1
,
2278 coex_dm
->backup_arfr_cnt2
,
2279 coex_dm
->backup_retry_limit
,
2280 coex_dm
->backup_ampdu_max_time
);
2282 u4_tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x430);
2283 u4_tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x434);
2284 u2_tmp
[0] = btcoexist
->btc_read_2byte(btcoexist
, 0x42a);
2285 u1_tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x456);
2286 seq_printf(m
, "\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2287 "0x430/0x434/0x42a/0x456",
2288 u4_tmp
[0], u4_tmp
[1], u2_tmp
[0], u1_tmp
[0]);
2290 u1_tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x778);
2291 u4_tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xc58);
2292 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x", "0x778/ 0xc58[29:25]",
2293 u1_tmp
[0], (u4_tmp
[0] & 0x3e000000) >> 25);
2295 u1_tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x8db);
2296 seq_printf(m
, "\n %-35s = 0x%x", "0x8db[6:5]",
2297 ((u1_tmp
[0] & 0x60) >> 5));
2299 u1_tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x975);
2300 u4_tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xcb4);
2301 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
2302 "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]",
2303 (u4_tmp
[0] & 0x30000000) >> 28,
2307 u1_tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x40);
2308 u4_tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x4c);
2309 u1_tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0x64);
2310 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x",
2311 "0x40/0x4c[24:23]/0x64[0]",
2312 u1_tmp
[0], ((u4_tmp
[0] & 0x01800000) >> 23),
2315 u4_tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x550);
2316 u1_tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x522);
2317 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522",
2318 u4_tmp
[0], u1_tmp
[0]);
2320 u4_tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xc50);
2321 seq_printf(m
, "\n %-35s = 0x%x", "0xc50(dig)",
2324 u4_tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0xf48);
2325 u1_tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5d);
2326 u1_tmp
[1] = btcoexist
->btc_read_1byte(btcoexist
, 0xa5c);
2327 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x", "OFDM-FA/ CCK-FA",
2328 u4_tmp
[0], (u1_tmp
[0] << 8) + u1_tmp
[1]);
2330 u4_tmp
[0] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c0);
2331 u4_tmp
[1] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c4);
2332 u4_tmp
[2] = btcoexist
->btc_read_4byte(btcoexist
, 0x6c8);
2333 u1_tmp
[0] = btcoexist
->btc_read_1byte(btcoexist
, 0x6cc);
2334 seq_printf(m
, "\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2335 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
2336 u4_tmp
[0], u4_tmp
[1], u4_tmp
[2], u1_tmp
[0]);
2338 seq_printf(m
, "\n %-35s = %d/ %d", "0x770(high-pri rx/tx)",
2339 coex_sta
->high_priority_rx
, coex_sta
->high_priority_tx
);
2340 seq_printf(m
, "\n %-35s = %d/ %d", "0x774(low-pri rx/tx)",
2341 coex_sta
->low_priority_rx
, coex_sta
->low_priority_tx
);
2342 if (btcoexist
->auto_report_1ant
)
2343 btc8821a1ant_monitor_bt_ctr(btcoexist
);
2344 btcoexist
->btc_disp_dbg_msg(btcoexist
, BTC_DBG_DISP_COEX_STATISTICS
, m
);
2347 void ex_btc8821a1ant_ips_notify(struct btc_coexist
*btcoexist
, u8 type
)
2349 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2350 bool wifi_under_5g
= false;
2352 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2354 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2355 if (wifi_under_5g
) {
2356 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2357 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2358 btc8821a1ant_coex_under_5g(btcoexist
);
2362 if (BTC_IPS_ENTER
== type
) {
2363 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2364 "[BTCoex], IPS ENTER notify\n");
2365 coex_sta
->under_ips
= true;
2366 btc8821a1ant_set_ant_path(btcoexist
,
2367 BTC_ANT_PATH_BT
, false, true);
2368 /* set PTA control */
2369 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
2370 btc8821a1ant_coex_table_with_type(btcoexist
,
2372 } else if (BTC_IPS_LEAVE
== type
) {
2373 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2374 "[BTCoex], IPS LEAVE notify\n");
2375 coex_sta
->under_ips
= false;
2377 btc8821a1ant_init_hw_config(btcoexist
, false, false);
2378 btc8821a1ant_init_coex_dm(btcoexist
);
2379 btc8821a1ant_query_bt_info(btcoexist
);
2383 void ex_btc8821a1ant_lps_notify(struct btc_coexist
*btcoexist
, u8 type
)
2385 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2387 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2390 if (BTC_LPS_ENABLE
== type
) {
2391 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2392 "[BTCoex], LPS ENABLE notify\n");
2393 coex_sta
->under_lps
= true;
2394 } else if (BTC_LPS_DISABLE
== type
) {
2395 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2396 "[BTCoex], LPS DISABLE notify\n");
2397 coex_sta
->under_lps
= false;
2401 void ex_btc8821a1ant_scan_notify(struct btc_coexist
*btcoexist
, u8 type
)
2403 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2404 bool wifi_connected
= false, bt_hs_on
= false;
2405 bool bt_ctrl_agg_buf_size
= false;
2406 bool wifi_under_5g
= false;
2407 u32 wifi_link_status
= 0;
2408 u32 num_of_wifi_link
= 0;
2409 u8 agg_buf_size
= 5;
2411 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
)
2413 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2414 if (wifi_under_5g
) {
2415 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2416 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2417 btc8821a1ant_coex_under_5g(btcoexist
);
2421 if (type
== BTC_SCAN_START
) {
2422 coex_sta
->wifi_is_high_pri_task
= true;
2423 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2424 "[BTCoex], SCAN START notify\n");
2426 /* Force antenna setup for no scan result issue */
2427 btc8821a1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 8);
2429 coex_sta
->wifi_is_high_pri_task
= false;
2430 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2431 "[BTCoex], SCAN FINISH notify\n");
2434 if (coex_sta
->bt_disabled
)
2437 btcoexist
->btc_get(btcoexist
,
2438 BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2439 btcoexist
->btc_get(btcoexist
,
2440 BTC_GET_BL_WIFI_CONNECTED
, &wifi_connected
);
2442 btc8821a1ant_query_bt_info(btcoexist
);
2444 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2446 num_of_wifi_link
= wifi_link_status
>> 16;
2447 if (num_of_wifi_link
>= 2) {
2448 btc8821a1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2449 btc8821a1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2450 bt_ctrl_agg_buf_size
, agg_buf_size
);
2451 btc8821a1ant_action_wifi_multi_port(btcoexist
);
2455 if (coex_sta
->c2h_bt_inquiry_page
) {
2456 btc8821a1ant_action_bt_inquiry(btcoexist
);
2458 } else if (bt_hs_on
) {
2459 btc8821a1ant_action_hs(btcoexist
);
2463 if (BTC_SCAN_START
== type
) {
2464 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2465 "[BTCoex], SCAN START notify\n");
2466 if (!wifi_connected
) {
2467 /* non-connected scan */
2468 btc8821a1ant_act_wifi_not_conn_scan(btcoexist
);
2470 /* wifi is connected */
2471 btc8821a1ant_action_wifi_connected_scan(btcoexist
);
2473 } else if (BTC_SCAN_FINISH
== type
) {
2474 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2475 "[BTCoex], SCAN FINISH notify\n");
2476 if (!wifi_connected
) {
2477 /* non-connected scan */
2478 btc8821a1ant_action_wifi_not_connected(btcoexist
);
2480 btc8821a1ant_action_wifi_connected(btcoexist
);
2485 void ex_btc8821a1ant_connect_notify(struct btc_coexist
*btcoexist
, u8 type
)
2487 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2488 bool wifi_connected
= false, bt_hs_on
= false;
2489 u32 wifi_link_status
= 0;
2490 u32 num_of_wifi_link
= 0;
2491 bool bt_ctrl_agg_buf_size
= false;
2492 bool wifi_under_5g
= false;
2493 u8 agg_buf_size
= 5;
2495 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2496 coex_sta
->bt_disabled
)
2498 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2499 if (wifi_under_5g
) {
2500 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2501 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2502 btc8821a1ant_coex_under_5g(btcoexist
);
2506 if (type
== BTC_ASSOCIATE_START
) {
2507 coex_sta
->wifi_is_high_pri_task
= true;
2508 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2509 "[BTCoex], CONNECT START notify\n");
2510 coex_dm
->arp_cnt
= 0;
2512 coex_sta
->wifi_is_high_pri_task
= false;
2513 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2514 "[BTCoex], CONNECT FINISH notify\n");
2515 coex_dm
->arp_cnt
= 0;
2518 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2520 num_of_wifi_link
= wifi_link_status
>> 16;
2521 if (num_of_wifi_link
>= 2) {
2522 btc8821a1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2523 btc8821a1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2524 bt_ctrl_agg_buf_size
, agg_buf_size
);
2525 btc8821a1ant_action_wifi_multi_port(btcoexist
);
2529 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2530 if (coex_sta
->c2h_bt_inquiry_page
) {
2531 btc8821a1ant_action_bt_inquiry(btcoexist
);
2533 } else if (bt_hs_on
) {
2534 btc8821a1ant_action_hs(btcoexist
);
2538 if (BTC_ASSOCIATE_START
== type
) {
2539 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2540 "[BTCoex], CONNECT START notify\n");
2541 btc8821a1ant_act_wifi_not_conn_scan(btcoexist
);
2542 } else if (BTC_ASSOCIATE_FINISH
== type
) {
2543 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2544 "[BTCoex], CONNECT FINISH notify\n");
2546 btcoexist
->btc_get(btcoexist
,
2547 BTC_GET_BL_WIFI_CONNECTED
, &wifi_connected
);
2548 if (!wifi_connected
) {
2549 /* non-connected scan */
2550 btc8821a1ant_action_wifi_not_connected(btcoexist
);
2552 btc8821a1ant_action_wifi_connected(btcoexist
);
2557 void ex_btc8821a1ant_media_status_notify(struct btc_coexist
*btcoexist
,
2560 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2561 u8 h2c_parameter
[3] = {0};
2563 u8 wifi_central_chnl
;
2564 bool wifi_under_5g
= false;
2566 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2567 coex_sta
->bt_disabled
)
2569 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2570 if (wifi_under_5g
) {
2571 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2572 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2573 btc8821a1ant_coex_under_5g(btcoexist
);
2577 if (BTC_MEDIA_CONNECT
== type
) {
2578 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2579 "[BTCoex], MEDIA connect notify\n");
2581 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2582 "[BTCoex], MEDIA disconnect notify\n");
2583 coex_dm
->arp_cnt
= 0;
2586 /* only 2.4G we need to inform bt the chnl mask */
2587 btcoexist
->btc_get(btcoexist
,
2588 BTC_GET_U1_WIFI_CENTRAL_CHNL
,
2589 &wifi_central_chnl
);
2590 if ((type
== BTC_MEDIA_CONNECT
) &&
2591 (wifi_central_chnl
<= 14)) {
2592 h2c_parameter
[0] = 0x0;
2593 h2c_parameter
[1] = wifi_central_chnl
;
2594 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_BW
, &wifi_bw
);
2595 if (wifi_bw
== BTC_WIFI_BW_HT40
)
2596 h2c_parameter
[2] = 0x30;
2598 h2c_parameter
[2] = 0x20;
2601 coex_dm
->wifi_chnl_info
[0] = h2c_parameter
[0];
2602 coex_dm
->wifi_chnl_info
[1] = h2c_parameter
[1];
2603 coex_dm
->wifi_chnl_info
[2] = h2c_parameter
[2];
2605 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2606 "[BTCoex], FW write 0x66 = 0x%x\n",
2607 h2c_parameter
[0] << 16 |
2608 h2c_parameter
[1] << 8 |
2611 btcoexist
->btc_fill_h2c(btcoexist
, 0x66, 3, h2c_parameter
);
2614 void ex_btc8821a1ant_special_packet_notify(struct btc_coexist
*btcoexist
,
2617 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2618 bool bt_hs_on
= false;
2619 bool bt_ctrl_agg_buf_size
= false;
2620 bool wifi_under_5g
= false;
2621 u32 wifi_link_status
= 0;
2622 u32 num_of_wifi_link
= 0;
2623 u8 agg_buf_size
= 5;
2625 if (btcoexist
->manual_control
|| btcoexist
->stop_coex_dm
||
2626 coex_sta
->bt_disabled
)
2629 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2630 if (wifi_under_5g
) {
2631 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2632 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2633 btc8821a1ant_coex_under_5g(btcoexist
);
2637 if (type
== BTC_PACKET_DHCP
|| type
== BTC_PACKET_EAPOL
||
2638 type
== BTC_PACKET_ARP
) {
2639 coex_sta
->wifi_is_high_pri_task
= true;
2641 if (type
== BTC_PACKET_ARP
) {
2642 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2643 "[BTCoex], specific Packet ARP notify\n");
2645 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2646 "[BTCoex], specific Packet DHCP or EAPOL notify\n");
2649 coex_sta
->wifi_is_high_pri_task
= false;
2650 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2651 "[BTCoex], specific Packet [Type = %d] notify\n",
2655 coex_sta
->special_pkt_period_cnt
= 0;
2657 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_LINK_STATUS
,
2659 num_of_wifi_link
= wifi_link_status
>> 16;
2660 if (num_of_wifi_link
>= 2) {
2661 btc8821a1ant_limited_tx(btcoexist
, NORMAL_EXEC
, 0, 0, 0, 0);
2662 btc8821a1ant_limited_rx(btcoexist
, NORMAL_EXEC
, false,
2663 bt_ctrl_agg_buf_size
, agg_buf_size
);
2664 btc8821a1ant_action_wifi_multi_port(btcoexist
);
2668 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_HS_OPERATION
, &bt_hs_on
);
2669 if (coex_sta
->c2h_bt_inquiry_page
) {
2670 btc8821a1ant_action_bt_inquiry(btcoexist
);
2672 } else if (bt_hs_on
) {
2673 btc8821a1ant_action_hs(btcoexist
);
2677 if (type
== BTC_PACKET_DHCP
|| type
== BTC_PACKET_EAPOL
||
2678 type
== BTC_PACKET_ARP
) {
2679 if (type
== BTC_PACKET_ARP
) {
2681 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2682 "[BTCoex], ARP Packet Count = %d\n",
2684 if (coex_dm
->arp_cnt
>= 10)
2685 /* if APR PKT > 10 after connect, do not go to
2686 * btc8821a1ant_act_wifi_conn_sp_pkt
2691 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2692 "[BTCoex], special Packet(%d) notify\n", type
);
2693 btc8821a1ant_act_wifi_conn_sp_pkt(btcoexist
);
2697 void ex_btc8821a1ant_bt_info_notify(struct btc_coexist
*btcoexist
,
2698 u8
*tmp_buf
, u8 length
)
2700 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2704 bool wifi_connected
= false;
2705 bool bt_busy
= false;
2706 bool wifi_under_5g
= false;
2708 coex_sta
->c2h_bt_info_req_sent
= false;
2710 btcoexist
->btc_get(btcoexist
,
2711 BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2713 rsp_source
= tmp_buf
[0] & 0xf;
2714 if (rsp_source
>= BT_INFO_SRC_8821A_1ANT_MAX
)
2715 rsp_source
= BT_INFO_SRC_8821A_1ANT_WIFI_FW
;
2716 coex_sta
->bt_info_c2h_cnt
[rsp_source
]++;
2718 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2719 "[BTCoex], Bt info[%d], length = %d, hex data = [",
2720 rsp_source
, length
);
2721 for (i
= 0; i
< length
; i
++) {
2722 coex_sta
->bt_info_c2h
[rsp_source
][i
] = tmp_buf
[i
];
2724 bt_info
= tmp_buf
[i
];
2725 if (i
== length
- 1) {
2726 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2727 "0x%02x]\n", tmp_buf
[i
]);
2729 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2730 "0x%02x, ", tmp_buf
[i
]);
2734 if (BT_INFO_SRC_8821A_1ANT_WIFI_FW
!= rsp_source
) {
2736 coex_sta
->bt_retry_cnt
=
2737 coex_sta
->bt_info_c2h
[rsp_source
][2] & 0xf;
2740 coex_sta
->bt_info_c2h
[rsp_source
][3] * 2 + 10;
2742 coex_sta
->bt_info_ext
= coex_sta
->bt_info_c2h
[rsp_source
][4];
2744 coex_sta
->bt_tx_rx_mask
=
2745 (coex_sta
->bt_info_c2h
[rsp_source
][2] & 0x40);
2746 btcoexist
->btc_set(btcoexist
, BTC_SET_BL_BT_TX_RX_MASK
,
2747 &coex_sta
->bt_tx_rx_mask
);
2748 if (!coex_sta
->bt_tx_rx_mask
) {
2749 /* BT into is responded by BT FW and BT RF REG 0x3C !=
2750 * 0x15 => Need to switch BT TRx Mask
2752 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2753 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
2754 btcoexist
->btc_set_bt_reg(btcoexist
, BTC_BT_REG_RF
,
2758 /* Here we need to resend some wifi info to BT
2759 * because bt is reset and lost the info
2761 if (coex_sta
->bt_info_ext
& BIT1
) {
2762 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2763 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
2764 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_CONNECTED
,
2766 if (wifi_connected
) {
2767 ex_btc8821a1ant_media_status_notify(btcoexist
,
2770 ex_btc8821a1ant_media_status_notify(btcoexist
,
2771 BTC_MEDIA_DISCONNECT
);
2775 if ((coex_sta
->bt_info_ext
& BIT3
) && !wifi_under_5g
) {
2776 if (!btcoexist
->manual_control
&&
2777 !btcoexist
->stop_coex_dm
) {
2778 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2779 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
2780 btc8821a1ant_ignore_wlan_act(btcoexist
,
2787 /* check BIT2 first ==> check if bt is under inquiry or page scan */
2788 if (bt_info
& BT_INFO_8821A_1ANT_B_INQ_PAGE
)
2789 coex_sta
->c2h_bt_inquiry_page
= true;
2791 coex_sta
->c2h_bt_inquiry_page
= false;
2793 /* set link exist status */
2794 if (!(bt_info
& BT_INFO_8821A_1ANT_B_CONNECTION
)) {
2795 coex_sta
->bt_link_exist
= false;
2796 coex_sta
->pan_exist
= false;
2797 coex_sta
->a2dp_exist
= false;
2798 coex_sta
->hid_exist
= false;
2799 coex_sta
->sco_exist
= false;
2801 /* connection exists */
2802 coex_sta
->bt_link_exist
= true;
2803 if (bt_info
& BT_INFO_8821A_1ANT_B_FTP
)
2804 coex_sta
->pan_exist
= true;
2806 coex_sta
->pan_exist
= false;
2807 if (bt_info
& BT_INFO_8821A_1ANT_B_A2DP
)
2808 coex_sta
->a2dp_exist
= true;
2810 coex_sta
->a2dp_exist
= false;
2811 if (bt_info
& BT_INFO_8821A_1ANT_B_HID
)
2812 coex_sta
->hid_exist
= true;
2814 coex_sta
->hid_exist
= false;
2815 if (bt_info
& BT_INFO_8821A_1ANT_B_SCO_ESCO
)
2816 coex_sta
->sco_exist
= true;
2818 coex_sta
->sco_exist
= false;
2821 btc8821a1ant_update_bt_link_info(btcoexist
);
2823 /* mask profile bit for connect-ilde identification
2824 * (for CSR case: A2DP idle --> 0x41)
2826 bt_info
= bt_info
& 0x1f;
2828 if (!(bt_info
& BT_INFO_8821A_1ANT_B_CONNECTION
)) {
2829 coex_dm
->bt_status
= BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE
;
2830 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2831 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
2832 } else if (bt_info
== BT_INFO_8821A_1ANT_B_CONNECTION
) {
2833 /* connection exists but no busy */
2834 coex_dm
->bt_status
= BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE
;
2835 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2836 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
2837 } else if ((bt_info
&BT_INFO_8821A_1ANT_B_SCO_ESCO
) ||
2838 (bt_info
& BT_INFO_8821A_1ANT_B_SCO_BUSY
)) {
2839 coex_dm
->bt_status
= BT_8821A_1ANT_BT_STATUS_SCO_BUSY
;
2840 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2841 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
2842 } else if (bt_info
& BT_INFO_8821A_1ANT_B_ACL_BUSY
) {
2843 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY
!= coex_dm
->bt_status
)
2844 coex_dm
->auto_tdma_adjust
= false;
2845 coex_dm
->bt_status
= BT_8821A_1ANT_BT_STATUS_ACL_BUSY
;
2846 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2847 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
2849 coex_dm
->bt_status
= BT_8821A_1ANT_BT_STATUS_MAX
;
2850 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2851 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
2854 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY
== coex_dm
->bt_status
) ||
2855 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY
== coex_dm
->bt_status
) ||
2856 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY
== coex_dm
->bt_status
))
2860 btcoexist
->btc_set(btcoexist
,
2861 BTC_SET_BL_BT_TRAFFIC_BUSY
, &bt_busy
);
2863 btc8821a1ant_run_coexist_mechanism(btcoexist
);
2866 void ex_btc8821a1ant_halt_notify(struct btc_coexist
*btcoexist
)
2868 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2869 bool wifi_under_5g
= false;
2871 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2872 "[BTCoex], Halt notify\n");
2873 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2874 if (wifi_under_5g
) {
2875 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2876 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2877 btc8821a1ant_coex_under_5g(btcoexist
);
2882 btcoexist
->stop_coex_dm
= true;
2884 btc8821a1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
, false, true);
2885 btc8821a1ant_ignore_wlan_act(btcoexist
, FORCE_EXEC
, true);
2887 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
, 0x0, 0x0);
2888 btc8821a1ant_ps_tdma(btcoexist
, FORCE_EXEC
, false, 0);
2890 ex_btc8821a1ant_media_status_notify(btcoexist
, BTC_MEDIA_DISCONNECT
);
2893 void ex_btc8821a1ant_pnp_notify(struct btc_coexist
*btcoexist
, u8 pnp_state
)
2895 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2896 bool wifi_under_5g
= false;
2898 btcoexist
->btc_get(btcoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &wifi_under_5g
);
2899 if (wifi_under_5g
) {
2900 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2901 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
2902 btc8821a1ant_coex_under_5g(btcoexist
);
2906 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2907 "[BTCoex], Pnp notify\n");
2909 if (BTC_WIFI_PNP_SLEEP
== pnp_state
) {
2910 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2911 "[BTCoex], Pnp notify to SLEEP\n");
2912 /* BT should clear UnderIPS/UnderLPS state to avoid mismatch
2913 * state after wakeup.
2915 coex_sta
->under_ips
= false;
2916 coex_sta
->under_lps
= false;
2917 btcoexist
->stop_coex_dm
= true;
2918 btc8821a1ant_power_save_state(btcoexist
, BTC_PS_WIFI_NATIVE
,
2920 btc8821a1ant_ps_tdma(btcoexist
, NORMAL_EXEC
, false, 0);
2921 btc8821a1ant_coex_table_with_type(btcoexist
, NORMAL_EXEC
, 2);
2922 btc8821a1ant_set_ant_path(btcoexist
, BTC_ANT_PATH_BT
, false,
2924 } else if (BTC_WIFI_PNP_WAKE_UP
== pnp_state
) {
2925 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2926 "[BTCoex], Pnp notify to WAKE UP\n");
2927 btcoexist
->stop_coex_dm
= false;
2928 btc8821a1ant_init_hw_config(btcoexist
, false, false);
2929 btc8821a1ant_init_coex_dm(btcoexist
);
2930 btc8821a1ant_query_bt_info(btcoexist
);
2934 void ex_btc8821a1ant_periodical(struct btc_coexist
*btcoexist
)
2936 struct rtl_priv
*rtlpriv
= btcoexist
->adapter
;
2937 static u8 dis_ver_info_cnt
;
2938 u32 fw_ver
= 0, bt_patch_ver
= 0;
2939 struct btc_board_info
*board_info
= &btcoexist
->board_info
;
2940 struct btc_stack_info
*stack_info
= &btcoexist
->stack_info
;
2942 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2943 "[BTCoex], ==========================Periodical===========================\n");
2945 if (dis_ver_info_cnt
<= 5) {
2946 dis_ver_info_cnt
+= 1;
2947 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2948 "[BTCoex], ****************************************************************\n");
2949 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2950 "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
2951 board_info
->pg_ant_num
,
2952 board_info
->btdm_ant_num
,
2953 board_info
->btdm_ant_pos
);
2954 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2955 "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
2956 stack_info
->profile_notified
? "Yes" : "No",
2957 stack_info
->hci_version
);
2958 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_BT_PATCH_VER
,
2960 btcoexist
->btc_get(btcoexist
, BTC_GET_U4_WIFI_FW_VER
, &fw_ver
);
2961 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2962 "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
2963 glcoex_ver_date_8821a_1ant
,
2964 glcoex_ver_8821a_1ant
,
2965 fw_ver
, bt_patch_ver
,
2967 RT_TRACE(rtlpriv
, COMP_BT_COEXIST
, DBG_LOUD
,
2968 "[BTCoex], ****************************************************************\n");
2971 if (!btcoexist
->auto_report_1ant
) {
2972 btc8821a1ant_query_bt_info(btcoexist
);
2973 btc8821a1ant_monitor_bt_ctr(btcoexist
);
2975 coex_sta
->special_pkt_period_cnt
++;