]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8821a1ant.c
rtlwifi: btcoex: 21a 1ant: fw settings for softap mode
[mirror_ubuntu-bionic-kernel.git] / drivers / net / wireless / realtek / rtlwifi / btcoexist / halbtc8821a1ant.c
CommitLineData
2ec7f01c
LF
1/******************************************************************************
2 *
3 * Copyright(c) 2012 Realtek Corporation.
4 *
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.
8 *
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
12 * more details.
13 *
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
16 *
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
21 *
22 * Larry Finger <Larry.Finger@lwfinger.net>
23 *
24 *****************************************************************************/
25
c6821613 26/**************************************************************
2ec7f01c
LF
27 * Description:
28 *
29 * This file is for RTL8821A Co-exist mechanism
30 *
31 * History
32 * 2012/11/15 Cosa first check in.
33 *
c6821613
YHC
34 **************************************************************/
35
36/**************************************************************
2ec7f01c 37 * include files
c6821613 38 **************************************************************/
2ec7f01c 39#include "halbt_precomp.h"
c6821613 40/**************************************************************
2ec7f01c 41 * Global variables, these are static variables
c6821613 42 **************************************************************/
2ec7f01c
LF
43static struct coex_dm_8821a_1ant glcoex_dm_8821a_1ant;
44static struct coex_dm_8821a_1ant *coex_dm = &glcoex_dm_8821a_1ant;
45static struct coex_sta_8821a_1ant glcoex_sta_8821a_1ant;
46static struct coex_sta_8821a_1ant *coex_sta = &glcoex_sta_8821a_1ant;
47
48static const char *const glbt_info_src_8821a_1ant[] = {
49 "BT Info[wifi fw]",
50 "BT Info[bt rsp]",
51 "BT Info[bt auto report]",
52};
53
c6821613
YHC
54static u32 glcoex_ver_date_8821a_1ant = 20130816;
55static u32 glcoex_ver_8821a_1ant = 0x41;
2ec7f01c 56
c6821613 57/**************************************************************
2ec7f01c
LF
58 * local function proto type if needed
59 *
c6821613
YHC
60 * local function start with btc8821a1ant_
61 **************************************************************/
62static u8 btc8821a1ant_bt_rssi_state(struct btc_coexist *btcoexist,
63 u8 level_num, u8 rssi_thresh,
64 u8 rssi_thresh1)
2ec7f01c 65{
bed4ff58 66 struct rtl_priv *rtlpriv = btcoexist->adapter;
c6821613
YHC
67 long bt_rssi = 0;
68 u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
2ec7f01c
LF
69
70 bt_rssi = coex_sta->bt_rssi;
71
72 if (level_num == 2) {
73 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
74 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
75 if (bt_rssi >= (rssi_thresh +
76 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
77 bt_rssi_state = BTC_RSSI_STATE_HIGH;
bed4ff58
LF
78 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
79 "[BTCoex], BT Rssi state switch to High\n");
2ec7f01c
LF
80 } else {
81 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
bed4ff58
LF
82 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
83 "[BTCoex], BT Rssi state stay at Low\n");
2ec7f01c
LF
84 }
85 } else {
86 if (bt_rssi < rssi_thresh) {
87 bt_rssi_state = BTC_RSSI_STATE_LOW;
bed4ff58
LF
88 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
89 "[BTCoex], BT Rssi state switch to Low\n");
2ec7f01c
LF
90 } else {
91 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
bed4ff58
LF
92 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
93 "[BTCoex], BT Rssi state stay at High\n");
2ec7f01c
LF
94 }
95 }
96 } else if (level_num == 3) {
97 if (rssi_thresh > rssi_thresh1) {
bed4ff58
LF
98 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
99 "[BTCoex], BT Rssi thresh error!!\n");
2ec7f01c
LF
100 return coex_sta->pre_bt_rssi_state;
101 }
102
103 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) ||
104 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) {
105 if (bt_rssi >= (rssi_thresh +
106 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
107 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
bed4ff58
LF
108 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
109 "[BTCoex], BT Rssi state switch to Medium\n");
2ec7f01c
LF
110 } else {
111 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
bed4ff58
LF
112 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
113 "[BTCoex], BT Rssi state stay at Low\n");
2ec7f01c
LF
114 }
115 } else if ((coex_sta->pre_bt_rssi_state ==
116 BTC_RSSI_STATE_MEDIUM) ||
117 (coex_sta->pre_bt_rssi_state ==
118 BTC_RSSI_STATE_STAY_MEDIUM)) {
119 if (bt_rssi >= (rssi_thresh1 +
120 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
121 bt_rssi_state = BTC_RSSI_STATE_HIGH;
bed4ff58
LF
122 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
123 "[BTCoex], BT Rssi state switch to High\n");
2ec7f01c
LF
124 } else if (bt_rssi < rssi_thresh) {
125 bt_rssi_state = BTC_RSSI_STATE_LOW;
bed4ff58
LF
126 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
127 "[BTCoex], BT Rssi state switch to Low\n");
2ec7f01c
LF
128 } else {
129 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
bed4ff58
LF
130 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
131 "[BTCoex], BT Rssi state stay at Medium\n");
2ec7f01c
LF
132 }
133 } else {
134 if (bt_rssi < rssi_thresh1) {
135 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
bed4ff58
LF
136 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
137 "[BTCoex], BT Rssi state switch to Medium\n");
2ec7f01c
LF
138 } else {
139 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
bed4ff58
LF
140 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
141 "[BTCoex], BT Rssi state stay at High\n");
2ec7f01c
LF
142 }
143 }
144 }
145 coex_sta->pre_bt_rssi_state = bt_rssi_state;
146
147 return bt_rssi_state;
148}
149
c6821613
YHC
150static u8 btc8821a1ant_wifi_rssi_state(struct btc_coexist *btcoexist,
151 u8 index, u8 level_num, u8 rssi_thresh,
152 u8 rssi_thresh1)
2ec7f01c 153{
bed4ff58 154 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c
LF
155 long wifi_rssi = 0;
156 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
157
158 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
159
160 if (level_num == 2) {
161 if ((coex_sta->pre_wifi_rssi_state[index] ==
162 BTC_RSSI_STATE_LOW) ||
163 (coex_sta->pre_wifi_rssi_state[index] ==
164 BTC_RSSI_STATE_STAY_LOW)) {
c6821613
YHC
165 if (wifi_rssi >= (rssi_thresh +
166 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
2ec7f01c 167 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
bed4ff58
LF
168 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
169 "[BTCoex], wifi RSSI state switch to High\n");
2ec7f01c
LF
170 } else {
171 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
bed4ff58
LF
172 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
173 "[BTCoex], wifi RSSI state stay at Low\n");
2ec7f01c
LF
174 }
175 } else {
176 if (wifi_rssi < rssi_thresh) {
177 wifi_rssi_state = BTC_RSSI_STATE_LOW;
bed4ff58
LF
178 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
179 "[BTCoex], wifi RSSI state switch to Low\n");
2ec7f01c
LF
180 } else {
181 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
bed4ff58
LF
182 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
183 "[BTCoex], wifi RSSI state stay at High\n");
2ec7f01c
LF
184 }
185 }
186 } else if (level_num == 3) {
187 if (rssi_thresh > rssi_thresh1) {
bed4ff58
LF
188 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
189 "[BTCoex], wifi RSSI thresh error!!\n");
2ec7f01c
LF
190 return coex_sta->pre_wifi_rssi_state[index];
191 }
192
193 if ((coex_sta->pre_wifi_rssi_state[index] ==
194 BTC_RSSI_STATE_LOW) ||
195 (coex_sta->pre_wifi_rssi_state[index] ==
196 BTC_RSSI_STATE_STAY_LOW)) {
c6821613
YHC
197 if (wifi_rssi >= (rssi_thresh +
198 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
2ec7f01c 199 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
bed4ff58
LF
200 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
201 "[BTCoex], wifi RSSI state switch to Medium\n");
2ec7f01c
LF
202 } else {
203 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
bed4ff58
LF
204 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
205 "[BTCoex], wifi RSSI state stay at Low\n");
2ec7f01c
LF
206 }
207 } else if ((coex_sta->pre_wifi_rssi_state[index] ==
208 BTC_RSSI_STATE_MEDIUM) ||
209 (coex_sta->pre_wifi_rssi_state[index] ==
210 BTC_RSSI_STATE_STAY_MEDIUM)) {
c6821613
YHC
211 if (wifi_rssi >= (rssi_thresh1 +
212 BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT)) {
2ec7f01c 213 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
bed4ff58
LF
214 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
215 "[BTCoex], wifi RSSI state switch to High\n");
2ec7f01c
LF
216 } else if (wifi_rssi < rssi_thresh) {
217 wifi_rssi_state = BTC_RSSI_STATE_LOW;
bed4ff58
LF
218 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
219 "[BTCoex], wifi RSSI state switch to Low\n");
2ec7f01c
LF
220 } else {
221 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
bed4ff58
LF
222 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
223 "[BTCoex], wifi RSSI state stay at Medium\n");
2ec7f01c
LF
224 }
225 } else {
226 if (wifi_rssi < rssi_thresh1) {
227 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
bed4ff58
LF
228 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
229 "[BTCoex], wifi RSSI state switch to Medium\n");
2ec7f01c
LF
230 } else {
231 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
bed4ff58
LF
232 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
233 "[BTCoex], wifi RSSI state stay at High\n");
2ec7f01c
LF
234 }
235 }
236 }
237 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
238
239 return wifi_rssi_state;
240}
241
c6821613
YHC
242static void btc8821a1ant_update_ra_mask(struct btc_coexist *btcoexist,
243 bool force_exec, u32 dis_rate_mask)
2ec7f01c
LF
244{
245 coex_dm->cur_ra_mask = dis_rate_mask;
246
247 if (force_exec ||
248 (coex_dm->pre_ra_mask != coex_dm->cur_ra_mask)) {
c6821613 249 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
2ec7f01c
LF
250 &coex_dm->cur_ra_mask);
251 }
252 coex_dm->pre_ra_mask = coex_dm->cur_ra_mask;
253}
254
255static void btc8821a1ant_auto_rate_fb_retry(struct btc_coexist *btcoexist,
256 bool force_exec, u8 type)
257{
c6821613 258 bool wifi_under_b_mode = false;
2ec7f01c
LF
259
260 coex_dm->cur_arfr_type = type;
261
262 if (force_exec ||
263 (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
264 switch (coex_dm->cur_arfr_type) {
c6821613 265 case 0: /* normal mode */
2ec7f01c
LF
266 btcoexist->btc_write_4byte(btcoexist, 0x430,
267 coex_dm->backup_arfr_cnt1);
268 btcoexist->btc_write_4byte(btcoexist, 0x434,
269 coex_dm->backup_arfr_cnt2);
270 break;
271 case 1:
272 btcoexist->btc_get(btcoexist,
273 BTC_GET_BL_WIFI_UNDER_B_MODE,
274 &wifi_under_b_mode);
275 if (wifi_under_b_mode) {
276 btcoexist->btc_write_4byte(btcoexist, 0x430,
277 0x0);
278 btcoexist->btc_write_4byte(btcoexist, 0x434,
279 0x01010101);
280 } else {
281 btcoexist->btc_write_4byte(btcoexist, 0x430,
282 0x0);
283 btcoexist->btc_write_4byte(btcoexist, 0x434,
284 0x04030201);
285 }
286 break;
287 default:
288 break;
289 }
290 }
291
292 coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
293}
294
c6821613
YHC
295static void btc8821a1ant_retry_limit(struct btc_coexist *btcoexist,
296 bool force_exec, u8 type)
2ec7f01c
LF
297{
298 coex_dm->cur_retry_limit_type = type;
299
300 if (force_exec ||
301 (coex_dm->pre_retry_limit_type != coex_dm->cur_retry_limit_type)) {
302 switch (coex_dm->cur_retry_limit_type) {
c6821613 303 case 0: /* normal mode */
2ec7f01c
LF
304 btcoexist->btc_write_2byte(btcoexist, 0x42a,
305 coex_dm->backup_retry_limit);
306 break;
c6821613 307 case 1: /* retry limit = 8 */
2ec7f01c
LF
308 btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808);
309 break;
310 default:
311 break;
312 }
313 }
314 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
315}
316
c6821613
YHC
317static void btc8821a1ant_ampdu_max_time(struct btc_coexist *btcoexist,
318 bool force_exec, u8 type)
2ec7f01c
LF
319{
320 coex_dm->cur_ampdu_time_type = type;
321
322 if (force_exec ||
323 (coex_dm->pre_ampdu_time_type != coex_dm->cur_ampdu_time_type)) {
324 switch (coex_dm->cur_ampdu_time_type) {
c6821613 325 case 0: /* normal mode */
2ec7f01c
LF
326 btcoexist->btc_write_1byte(btcoexist, 0x456,
327 coex_dm->backup_ampdu_max_time);
328 break;
c6821613 329 case 1: /* AMPDU time = 0x38 * 32us */
2ec7f01c
LF
330 btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38);
331 break;
332 default:
333 break;
334 }
335 }
336
337 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
338}
339
c6821613
YHC
340static void btc8821a1ant_limited_tx(struct btc_coexist *btcoexist,
341 bool force_exec, u8 ra_mask_type,
342 u8 arfr_type, u8 retry_limit_type,
343 u8 ampdu_time_type)
2ec7f01c
LF
344{
345 switch (ra_mask_type) {
c6821613
YHC
346 case 0: /* normal mode */
347 btc8821a1ant_update_ra_mask(btcoexist, force_exec, 0x0);
2ec7f01c 348 break;
c6821613
YHC
349 case 1: /* disable cck 1/2 */
350 btc8821a1ant_update_ra_mask(btcoexist, force_exec,
351 0x00000003);
2ec7f01c 352 break;
c6821613
YHC
353 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
354 btc8821a1ant_update_ra_mask(btcoexist, force_exec,
355 0x0001f1f7);
2ec7f01c
LF
356 break;
357 default:
358 break;
359 }
360
361 btc8821a1ant_auto_rate_fb_retry(btcoexist, force_exec, arfr_type);
c6821613
YHC
362 btc8821a1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
363 btc8821a1ant_ampdu_max_time(btcoexist, force_exec, ampdu_time_type);
2ec7f01c
LF
364}
365
c6821613
YHC
366static void btc8821a1ant_limited_rx(struct btc_coexist *btcoexist,
367 bool force_exec, bool rej_ap_agg_pkt,
368 bool bt_ctrl_agg_buf_size, u8 agg_buf_size)
2ec7f01c
LF
369{
370 bool reject_rx_agg = rej_ap_agg_pkt;
371 bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
372 u8 rx_agg_size = agg_buf_size;
373
c6821613 374 /* Rx Aggregation related setting */
2ec7f01c
LF
375 btcoexist->btc_set(btcoexist,
376 BTC_SET_BL_TO_REJ_AP_AGG_PKT, &reject_rx_agg);
c6821613 377 /* decide BT control aggregation buf size or not */
2ec7f01c
LF
378 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
379 &bt_ctrl_rx_agg_size);
c6821613 380 /* aggregation buf size, only work when BT control Rx agg size */
2ec7f01c 381 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
c6821613 382 /* real update aggregation setting */
2ec7f01c
LF
383 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
384}
385
c6821613 386static void btc8821a1ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
2ec7f01c 387{
c6821613
YHC
388 u32 reg_hp_tx_rx, reg_lp_tx_rx, u4_tmp;
389 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
2ec7f01c
LF
390
391 reg_hp_tx_rx = 0x770;
392 reg_lp_tx_rx = 0x774;
393
394 u4_tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_tx_rx);
395 reg_hp_tx = u4_tmp & MASKLWORD;
c6821613 396 reg_hp_rx = (u4_tmp & MASKHWORD) >> 16;
2ec7f01c
LF
397
398 u4_tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_tx_rx);
399 reg_lp_tx = u4_tmp & MASKLWORD;
c6821613 400 reg_lp_rx = (u4_tmp & MASKHWORD) >> 16;
2ec7f01c
LF
401
402 coex_sta->high_priority_tx = reg_hp_tx;
403 coex_sta->high_priority_rx = reg_hp_rx;
404 coex_sta->low_priority_tx = reg_lp_tx;
405 coex_sta->low_priority_rx = reg_lp_rx;
406
c6821613 407 /* reset counter */
2ec7f01c
LF
408 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
409}
410
c6821613 411static void btc8821a1ant_query_bt_info(struct btc_coexist *btcoexist)
2ec7f01c 412{
bed4ff58 413 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c
LF
414 u8 h2c_parameter[1] = {0};
415
416 coex_sta->c2h_bt_info_req_sent = true;
417
c6821613 418 h2c_parameter[0] |= BIT0; /* trigger */
2ec7f01c 419
bed4ff58
LF
420 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
421 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
422 h2c_parameter[0]);
2ec7f01c
LF
423
424 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
425}
426
c6821613 427static void btc8821a1ant_update_bt_link_info(struct btc_coexist *btcoexist)
2ec7f01c
LF
428{
429 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
c6821613 430 bool bt_hs_on = false;
2ec7f01c
LF
431
432 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
433
434 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
435 bt_link_info->sco_exist = coex_sta->sco_exist;
436 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
437 bt_link_info->pan_exist = coex_sta->pan_exist;
438 bt_link_info->hid_exist = coex_sta->hid_exist;
439
c6821613 440 /* work around for HS mode */
2ec7f01c
LF
441 if (bt_hs_on) {
442 bt_link_info->pan_exist = true;
443 bt_link_info->bt_link_exist = true;
444 }
445
c6821613 446 /* check if Sco only */
2ec7f01c
LF
447 if (bt_link_info->sco_exist &&
448 !bt_link_info->a2dp_exist &&
449 !bt_link_info->pan_exist &&
450 !bt_link_info->hid_exist)
451 bt_link_info->sco_only = true;
452 else
453 bt_link_info->sco_only = false;
454
c6821613 455 /* check if A2dp only */
2ec7f01c
LF
456 if (!bt_link_info->sco_exist &&
457 bt_link_info->a2dp_exist &&
458 !bt_link_info->pan_exist &&
459 !bt_link_info->hid_exist)
460 bt_link_info->a2dp_only = true;
461 else
462 bt_link_info->a2dp_only = false;
463
c6821613 464 /* check if Pan only */
2ec7f01c
LF
465 if (!bt_link_info->sco_exist &&
466 !bt_link_info->a2dp_exist &&
467 bt_link_info->pan_exist &&
468 !bt_link_info->hid_exist)
469 bt_link_info->pan_only = true;
470 else
471 bt_link_info->pan_only = false;
472
c6821613 473 /* check if Hid only */
2ec7f01c
LF
474 if (!bt_link_info->sco_exist &&
475 !bt_link_info->a2dp_exist &&
476 !bt_link_info->pan_exist &&
477 bt_link_info->hid_exist)
478 bt_link_info->hid_only = true;
479 else
480 bt_link_info->hid_only = false;
481}
482
c6821613 483static u8 btc8821a1ant_action_algorithm(struct btc_coexist *btcoexist)
2ec7f01c 484{
bed4ff58 485 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c 486 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
c6821613
YHC
487 bool bt_hs_on = false;
488 u8 algorithm = BT_8821A_1ANT_COEX_ALGO_UNDEFINED;
489 u8 num_of_diff_profile = 0;
2ec7f01c
LF
490
491 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
492
493 if (!bt_link_info->bt_link_exist) {
bed4ff58
LF
494 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
495 "[BTCoex], No BT link exists!!!\n");
2ec7f01c
LF
496 return algorithm;
497 }
498
499 if (bt_link_info->sco_exist)
500 num_of_diff_profile++;
501 if (bt_link_info->hid_exist)
502 num_of_diff_profile++;
503 if (bt_link_info->pan_exist)
504 num_of_diff_profile++;
505 if (bt_link_info->a2dp_exist)
506 num_of_diff_profile++;
507
508 if (num_of_diff_profile == 1) {
509 if (bt_link_info->sco_exist) {
bed4ff58
LF
510 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
511 "[BTCoex], BT Profile = SCO only\n");
2ec7f01c
LF
512 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
513 } else {
514 if (bt_link_info->hid_exist) {
bed4ff58
LF
515 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
516 "[BTCoex], BT Profile = HID only\n");
2ec7f01c
LF
517 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
518 } else if (bt_link_info->a2dp_exist) {
bed4ff58
LF
519 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
520 "[BTCoex], BT Profile = A2DP only\n");
2ec7f01c
LF
521 algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP;
522 } else if (bt_link_info->pan_exist) {
523 if (bt_hs_on) {
bed4ff58
LF
524 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
525 DBG_LOUD,
526 "[BTCoex], BT Profile = PAN(HS) only\n");
2ec7f01c
LF
527 algorithm = BT_8821A_1ANT_COEX_ALGO_PANHS;
528 } else {
bed4ff58
LF
529 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
530 DBG_LOUD,
531 "[BTCoex], BT Profile = PAN(EDR) only\n");
2ec7f01c
LF
532 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR;
533 }
534 }
535 }
536 } else if (num_of_diff_profile == 2) {
537 if (bt_link_info->sco_exist) {
538 if (bt_link_info->hid_exist) {
bed4ff58
LF
539 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
540 "[BTCoex], BT Profile = SCO + HID\n");
2ec7f01c
LF
541 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
542 } else if (bt_link_info->a2dp_exist) {
bed4ff58
LF
543 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
544 "[BTCoex], BT Profile = SCO + A2DP ==> SCO\n");
2ec7f01c
LF
545 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
546 } else if (bt_link_info->pan_exist) {
547 if (bt_hs_on) {
bed4ff58
LF
548 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
549 DBG_LOUD,
550 "[BTCoex], BT Profile = SCO + PAN(HS)\n");
2ec7f01c
LF
551 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
552 } else {
bed4ff58
LF
553 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
554 DBG_LOUD,
555 "[BTCoex], BT Profile = SCO + PAN(EDR)\n");
2ec7f01c
LF
556 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
557 }
558 }
559 } else {
560 if (bt_link_info->hid_exist &&
561 bt_link_info->a2dp_exist) {
bed4ff58
LF
562 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
563 "[BTCoex], BT Profile = HID + A2DP\n");
2ec7f01c
LF
564 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
565 } else if (bt_link_info->hid_exist &&
566 bt_link_info->pan_exist) {
567 if (bt_hs_on) {
bed4ff58
LF
568 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
569 DBG_LOUD,
570 "[BTCoex], BT Profile = HID + PAN(HS)\n");
2ec7f01c
LF
571 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
572 } else {
bed4ff58
LF
573 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
574 DBG_LOUD,
575 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
2ec7f01c
LF
576 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
577 }
578 } else if (bt_link_info->pan_exist &&
579 bt_link_info->a2dp_exist) {
580 if (bt_hs_on) {
bed4ff58
LF
581 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
582 DBG_LOUD,
583 "[BTCoex], BT Profile = A2DP + PAN(HS)\n");
2ec7f01c
LF
584 algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS;
585 } else {
bed4ff58
LF
586 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
587 DBG_LOUD,
588 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
2ec7f01c
LF
589 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP;
590 }
591 }
592 }
593 } else if (num_of_diff_profile == 3) {
594 if (bt_link_info->sco_exist) {
595 if (bt_link_info->hid_exist &&
596 bt_link_info->a2dp_exist) {
bed4ff58
LF
597 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
598 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n");
2ec7f01c
LF
599 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;
600 } else if (bt_link_info->hid_exist &&
c6821613 601 bt_link_info->pan_exist) {
2ec7f01c 602 if (bt_hs_on) {
bed4ff58
LF
603 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
604 DBG_LOUD,
605 "[BTCoex], BT Profile = SCO + HID + PAN(HS)\n");
2ec7f01c
LF
606 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
607 } else {
bed4ff58
LF
608 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
609 DBG_LOUD,
610 "[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n");
2ec7f01c
LF
611 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
612 }
613 } else if (bt_link_info->pan_exist &&
c6821613 614 bt_link_info->a2dp_exist) {
2ec7f01c 615 if (bt_hs_on) {
bed4ff58
LF
616 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
617 DBG_LOUD,
618 "[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n");
2ec7f01c
LF
619 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;
620 } else {
bed4ff58
LF
621 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
622 DBG_LOUD,
623 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n");
2ec7f01c
LF
624 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
625 }
626 }
627 } else {
628 if (bt_link_info->hid_exist &&
629 bt_link_info->pan_exist &&
630 bt_link_info->a2dp_exist) {
631 if (bt_hs_on) {
bed4ff58
LF
632 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
633 DBG_LOUD,
634 "[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n");
2ec7f01c
LF
635 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;
636 } else {
bed4ff58
LF
637 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
638 DBG_LOUD,
639 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n");
2ec7f01c
LF
640 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
641 }
642 }
643 }
644 } else if (num_of_diff_profile >= 3) {
645 if (bt_link_info->sco_exist) {
646 if (bt_link_info->hid_exist &&
647 bt_link_info->pan_exist &&
648 bt_link_info->a2dp_exist) {
649 if (bt_hs_on) {
bed4ff58
LF
650 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
651 DBG_LOUD,
652 "[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n");
2ec7f01c
LF
653
654 } else {
bed4ff58
LF
655 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
656 DBG_LOUD,
657 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n");
2ec7f01c
LF
658 algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;
659 }
660 }
661 }
662 }
663 return algorithm;
664}
665
c6821613
YHC
666static void btc8821a1ant_set_sw_penalty_tx_rate(struct btc_coexist *btcoexist,
667 bool low_penalty_ra)
2ec7f01c 668{
bed4ff58 669 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c
LF
670 u8 h2c_parameter[6] = {0};
671
672 h2c_parameter[0] = 0x6; /* opCode, 0x6= Retry_Penalty*/
673
674 if (low_penalty_ra) {
675 h2c_parameter[1] |= BIT0;
c6821613 676 /* normal rate except MCS7/6/5, OFDM54/48/36 */
2ec7f01c 677 h2c_parameter[2] = 0x00;
c6821613
YHC
678 h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */
679 h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */
680 h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */
2ec7f01c
LF
681 }
682
bed4ff58
LF
683 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
684 "[BTCoex], set WiFi Low-Penalty Retry: %s",
685 (low_penalty_ra ? "ON!!" : "OFF!!"));
2ec7f01c
LF
686
687 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
688}
689
c6821613
YHC
690static void btc8821a1ant_low_penalty_ra(struct btc_coexist *btcoexist,
691 bool force_exec, bool low_penalty_ra)
2ec7f01c
LF
692{
693 coex_dm->cur_low_penalty_ra = low_penalty_ra;
694
695 if (!force_exec) {
696 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
697 return;
698 }
c6821613
YHC
699 btc8821a1ant_set_sw_penalty_tx_rate(btcoexist,
700 coex_dm->cur_low_penalty_ra);
2ec7f01c
LF
701
702 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
703}
704
c6821613
YHC
705static void btc8821a1ant_set_coex_table(struct btc_coexist *btcoexist,
706 u32 val0x6c0, u32 val0x6c4,
707 u32 val0x6c8, u8 val0x6cc)
2ec7f01c 708{
bed4ff58
LF
709 struct rtl_priv *rtlpriv = btcoexist->adapter;
710
711 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
712 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0);
2ec7f01c
LF
713 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
714
bed4ff58
LF
715 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
716 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4);
2ec7f01c
LF
717 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
718
bed4ff58
LF
719 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
720 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8);
2ec7f01c
LF
721 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
722
bed4ff58
LF
723 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
724 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc);
2ec7f01c
LF
725 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
726}
727
c6821613
YHC
728static void btc8821a1ant_coex_table(struct btc_coexist *btcoexist,
729 bool force_exec, u32 val0x6c0, u32 val0x6c4,
730 u32 val0x6c8, u8 val0x6cc)
2ec7f01c 731{
bed4ff58
LF
732 struct rtl_priv *rtlpriv = btcoexist->adapter;
733
734 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
735 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
466414a0
JP
736 (force_exec ? "force to" : ""), val0x6c0, val0x6c4,
737 val0x6c8, val0x6cc);
2ec7f01c
LF
738 coex_dm->cur_val_0x6c0 = val0x6c0;
739 coex_dm->cur_val_0x6c4 = val0x6c4;
740 coex_dm->cur_val_0x6c8 = val0x6c8;
741 coex_dm->cur_val_0x6cc = val0x6cc;
742
743 if (!force_exec) {
744 if ((coex_dm->pre_val_0x6c0 == coex_dm->cur_val_0x6c0) &&
745 (coex_dm->pre_val_0x6c4 == coex_dm->cur_val_0x6c4) &&
746 (coex_dm->pre_val_0x6c8 == coex_dm->cur_val_0x6c8) &&
747 (coex_dm->pre_val_0x6cc == coex_dm->cur_val_0x6cc))
748 return;
749 }
c6821613
YHC
750 btc8821a1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4,
751 val0x6c8, val0x6cc);
2ec7f01c
LF
752
753 coex_dm->pre_val_0x6c0 = coex_dm->cur_val_0x6c0;
754 coex_dm->pre_val_0x6c4 = coex_dm->cur_val_0x6c4;
755 coex_dm->pre_val_0x6c8 = coex_dm->cur_val_0x6c8;
756 coex_dm->pre_val_0x6cc = coex_dm->cur_val_0x6cc;
757}
758
c6821613
YHC
759static void btc8821a1ant_coex_table_with_type(struct btc_coexist *btcoexist,
760 bool force_exec, u8 type)
2ec7f01c
LF
761{
762 switch (type) {
763 case 0:
c6821613
YHC
764 btc8821a1ant_coex_table(btcoexist, force_exec, 0x55555555,
765 0x55555555, 0xffffff, 0x3);
2ec7f01c
LF
766 break;
767 case 1:
c6821613
YHC
768 btc8821a1ant_coex_table(btcoexist, force_exec, 0x55555555,
769 0x5a5a5a5a, 0xffffff, 0x3);
770 break;
2ec7f01c 771 case 2:
c6821613
YHC
772 btc8821a1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
773 0x5a5a5a5a, 0xffffff, 0x3);
2ec7f01c
LF
774 break;
775 case 3:
c6821613
YHC
776 btc8821a1ant_coex_table(btcoexist, force_exec, 0x55555555,
777 0xaaaaaaaa, 0xffffff, 0x3);
2ec7f01c
LF
778 break;
779 case 4:
c6821613
YHC
780 btc8821a1ant_coex_table(btcoexist, force_exec, 0xffffffff,
781 0xffffffff, 0xffffff, 0x3);
2ec7f01c
LF
782 break;
783 case 5:
c6821613
YHC
784 btc8821a1ant_coex_table(btcoexist, force_exec, 0x5fff5fff,
785 0x5fff5fff, 0xffffff, 0x3);
2ec7f01c
LF
786 break;
787 case 6:
c6821613
YHC
788 btc8821a1ant_coex_table(btcoexist, force_exec, 0x55ff55ff,
789 0x5a5a5a5a, 0xffffff, 0x3);
2ec7f01c
LF
790 break;
791 case 7:
c6821613
YHC
792 btc8821a1ant_coex_table(btcoexist, force_exec, 0x5afa5afa,
793 0x5afa5afa, 0xffffff, 0x3);
2ec7f01c
LF
794 break;
795 default:
796 break;
797 }
798}
799
800static void btc8821a1ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist,
801 bool enable)
802{
bed4ff58 803 struct rtl_priv *rtlpriv = btcoexist->adapter;
c6821613 804 u8 h2c_parameter[1] = {0};
2ec7f01c
LF
805
806 if (enable)
c6821613 807 h2c_parameter[0] |= BIT0; /* function enable */
2ec7f01c 808
bed4ff58
LF
809 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
810 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
811 h2c_parameter[0]);
2ec7f01c
LF
812
813 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
814}
815
c6821613
YHC
816static void btc8821a1ant_ignore_wlan_act(struct btc_coexist *btcoexist,
817 bool force_exec, bool enable)
2ec7f01c 818{
bed4ff58
LF
819 struct rtl_priv *rtlpriv = btcoexist->adapter;
820
821 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
822 "[BTCoex], %s turn Ignore WlanAct %s\n",
823 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
2ec7f01c
LF
824 coex_dm->cur_ignore_wlan_act = enable;
825
826 if (!force_exec) {
bed4ff58
LF
827 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
828 "[BTCoex], pre_ignore_wlan_act = %d, cur_ignore_wlan_act = %d!!\n",
829 coex_dm->pre_ignore_wlan_act,
830 coex_dm->cur_ignore_wlan_act);
2ec7f01c
LF
831
832 if (coex_dm->pre_ignore_wlan_act ==
833 coex_dm->cur_ignore_wlan_act)
834 return;
835 }
836 btc8821a1ant_set_fw_ignore_wlan_act(btcoexist, enable);
837
838 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
839}
840
c6821613
YHC
841static void btc8821a1ant_set_fw_ps_tdma(struct btc_coexist *btcoexist, u8 byte1,
842 u8 byte2, u8 byte3, u8 byte4, u8 byte5)
2ec7f01c 843{
bed4ff58 844 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c 845 u8 h2c_parameter[5] = {0};
1bdd8339
YHC
846 u8 real_byte1 = byte1, real_byte5 = byte5;
847 bool ap_enable = false;
2ec7f01c 848
1bdd8339
YHC
849 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
850 &ap_enable);
851
852 if (ap_enable) {
853 if (byte1 & BIT4 && !(byte1 & BIT5)) {
854 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
855 "[BTCoex], FW for 1Ant AP mode\n");
856 real_byte1 &= ~BIT4;
857 real_byte1 |= BIT5;
858
859 real_byte5 |= BIT5;
860 real_byte5 &= ~BIT6;
861 }
862 }
863
864 h2c_parameter[0] = real_byte1;
2ec7f01c
LF
865 h2c_parameter[1] = byte2;
866 h2c_parameter[2] = byte3;
867 h2c_parameter[3] = byte4;
1bdd8339 868 h2c_parameter[4] = real_byte5;
2ec7f01c 869
1bdd8339 870 coex_dm->ps_tdma_para[0] = real_byte1;
2ec7f01c
LF
871 coex_dm->ps_tdma_para[1] = byte2;
872 coex_dm->ps_tdma_para[2] = byte3;
873 coex_dm->ps_tdma_para[3] = byte4;
1bdd8339 874 coex_dm->ps_tdma_para[4] = real_byte5;
2ec7f01c 875
bed4ff58
LF
876 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
877 "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
878 h2c_parameter[0],
879 h2c_parameter[1] << 24 |
880 h2c_parameter[2] << 16 |
881 h2c_parameter[3] << 8 |
882 h2c_parameter[4]);
2ec7f01c
LF
883 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
884}
885
c6821613
YHC
886static void btc8821a1ant_set_lps_rpwm(struct btc_coexist *btcoexist,
887 u8 lps_val, u8 rpwm_val)
2ec7f01c 888{
c6821613
YHC
889 u8 lps = lps_val;
890 u8 rpwm = rpwm_val;
2ec7f01c
LF
891
892 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
893 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
894}
895
c6821613
YHC
896static void btc8821a1ant_lps_rpwm(struct btc_coexist *btcoexist,
897 bool force_exec, u8 lps_val, u8 rpwm_val)
2ec7f01c 898{
bed4ff58
LF
899 struct rtl_priv *rtlpriv = btcoexist->adapter;
900
901 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
902 "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
903 (force_exec ? "force to" : ""), lps_val, rpwm_val);
2ec7f01c
LF
904 coex_dm->cur_lps = lps_val;
905 coex_dm->cur_rpwm = rpwm_val;
906
907 if (!force_exec) {
bed4ff58
LF
908 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
909 "[BTCoex], LPS-RxBeaconMode = 0x%x, LPS-RPWM = 0x%x!!\n",
910 coex_dm->cur_lps, coex_dm->cur_rpwm);
2ec7f01c
LF
911
912 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
913 (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) {
bed4ff58
LF
914 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
915 "[BTCoex], LPS-RPWM_Last = 0x%x, LPS-RPWM_Now = 0x%x!!\n",
916 coex_dm->pre_rpwm, coex_dm->cur_rpwm);
2ec7f01c
LF
917
918 return;
919 }
920 }
c6821613 921 btc8821a1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
2ec7f01c
LF
922
923 coex_dm->pre_lps = coex_dm->cur_lps;
924 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
925}
926
c6821613
YHC
927static void btc8821a1ant_sw_mechanism(struct btc_coexist *btcoexist,
928 bool low_penalty_ra)
2ec7f01c 929{
bed4ff58
LF
930 struct rtl_priv *rtlpriv = btcoexist->adapter;
931
932 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
933 "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra);
2ec7f01c 934
c6821613 935 btc8821a1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
2ec7f01c
LF
936}
937
c6821613
YHC
938static void btc8821a1ant_set_ant_path(struct btc_coexist *btcoexist,
939 u8 ant_pos_type, bool init_hw_cfg,
940 bool wifi_off)
2ec7f01c
LF
941{
942 struct btc_board_info *board_info = &btcoexist->board_info;
943 u32 u4_tmp = 0;
944 u8 h2c_parameter[2] = {0};
945
946 if (init_hw_cfg) {
c6821613 947 /* 0x4c[23] = 0, 0x4c[24] = 1 Antenna control by WL/BT */
2ec7f01c
LF
948 u4_tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
949 u4_tmp &= ~BIT23;
950 u4_tmp |= BIT24;
951 btcoexist->btc_write_4byte(btcoexist, 0x4c, u4_tmp);
952
953 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x975, 0x3, 0x3);
954 btcoexist->btc_write_1byte(btcoexist, 0xcb4, 0x77);
955
956 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) {
c6821613
YHC
957 /* tell firmware "antenna inverse"
958 * WRONG firmware antenna control code, need fw to fix
2ec7f01c
LF
959 */
960 h2c_parameter[0] = 1;
961 h2c_parameter[1] = 1;
962 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
963 h2c_parameter);
c6821613 964 /* Main Ant to BT for IPS case 0x4c[23] = 1 */
2ec7f01c
LF
965 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64,
966 0x1, 0x1);
967 } else {
c6821613
YHC
968 /* tell firmware "no antenna inverse"
969 * WRONG firmware antenna control code, need fw to fix
2ec7f01c
LF
970 */
971 h2c_parameter[0] = 0;
972 h2c_parameter[1] = 1;
973 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
974 h2c_parameter);
c6821613 975 /* Aux Ant to BT for IPS case 0x4c[23] = 1 */
2ec7f01c
LF
976 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64,
977 0x1, 0x0);
978 }
979 } else if (wifi_off) {
980 /* 0x4c[24:23] = 00, Set Antenna control
c6821613 981 * by BT_RFE_CTRL BT Vendor 0xac = 0xf002
2ec7f01c
LF
982 */
983 u4_tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
984 u4_tmp &= ~BIT23;
985 u4_tmp &= ~BIT24;
986 btcoexist->btc_write_4byte(btcoexist, 0x4c, u4_tmp);
987 }
988
c6821613 989 /* ext switch setting */
2ec7f01c
LF
990 switch (ant_pos_type) {
991 case BTC_ANT_PATH_WIFI:
992 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT)
993 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
994 0x30, 0x1);
995 else
996 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
997 0x30, 0x2);
998 break;
999 case BTC_ANT_PATH_BT:
1000 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT)
1001 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
1002 0x30, 0x2);
1003 else
1004 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
1005 0x30, 0x1);
1006 break;
1007 default:
1008 case BTC_ANT_PATH_PTA:
1009 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT)
1010 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
1011 0x30, 0x1);
1012 else
1013 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xcb7,
1014 0x30, 0x2);
1015 break;
1016 }
1017}
1018
c6821613
YHC
1019static void btc8821a1ant_ps_tdma(struct btc_coexist *btcoexist,
1020 bool force_exec, bool turn_on, u8 type)
2ec7f01c 1021{
bed4ff58 1022 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c
LF
1023 u8 rssi_adjust_val = 0;
1024
1025 coex_dm->cur_ps_tdma_on = turn_on;
1026 coex_dm->cur_ps_tdma = type;
1027
1028 if (!force_exec) {
1029 if (coex_dm->cur_ps_tdma_on) {
bed4ff58
LF
1030 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1031 "[BTCoex], ********** TDMA(on, %d) **********\n",
1032 coex_dm->cur_ps_tdma);
2ec7f01c 1033 } else {
bed4ff58
LF
1034 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1035 "[BTCoex], ********** TDMA(off, %d) **********\n",
1036 coex_dm->cur_ps_tdma);
2ec7f01c
LF
1037 }
1038 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1039 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1040 return;
1041 }
1042 if (turn_on) {
1043 switch (type) {
1044 default:
c6821613
YHC
1045 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1a,
1046 0x1a, 0x0, 0x50);
2ec7f01c
LF
1047 break;
1048 case 1:
c6821613
YHC
1049 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x3a,
1050 0x03, 0x10, 0x50);
2ec7f01c
LF
1051 rssi_adjust_val = 11;
1052 break;
1053 case 2:
c6821613
YHC
1054 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x2b,
1055 0x03, 0x10, 0x50);
2ec7f01c
LF
1056 rssi_adjust_val = 14;
1057 break;
1058 case 3:
c6821613
YHC
1059 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1d,
1060 0x1d, 0x0, 0x10);
2ec7f01c
LF
1061 break;
1062 case 4:
c6821613
YHC
1063 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15,
1064 0x3, 0x14, 0x0);
2ec7f01c
LF
1065 rssi_adjust_val = 17;
1066 break;
1067 case 5:
c6821613
YHC
1068 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x15,
1069 0x3, 0x11, 0x10);
2ec7f01c
LF
1070 break;
1071 case 6:
c6821613
YHC
1072 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
1073 0x3, 0x0, 0x0);
2ec7f01c
LF
1074 break;
1075 case 7:
c6821613
YHC
1076 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xc,
1077 0x5, 0x0, 0x0);
2ec7f01c
LF
1078 break;
1079 case 8:
c6821613
YHC
1080 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25,
1081 0x3, 0x10, 0x0);
2ec7f01c
LF
1082 break;
1083 case 9:
c6821613
YHC
1084 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x21,
1085 0x3, 0x10, 0x50);
2ec7f01c
LF
1086 rssi_adjust_val = 18;
1087 break;
1088 case 10:
c6821613
YHC
1089 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
1090 0xa, 0x0, 0x40);
2ec7f01c
LF
1091 break;
1092 case 11:
c6821613
YHC
1093 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x14,
1094 0x03, 0x10, 0x10);
2ec7f01c
LF
1095 rssi_adjust_val = 20;
1096 break;
1097 case 12:
c6821613
YHC
1098 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x0a,
1099 0x0a, 0x0, 0x50);
2ec7f01c
LF
1100 break;
1101 case 13:
c6821613
YHC
1102 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x18,
1103 0x18, 0x0, 0x10);
2ec7f01c
LF
1104 break;
1105 case 14:
c6821613
YHC
1106 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x21,
1107 0x3, 0x10, 0x10);
2ec7f01c
LF
1108 break;
1109 case 15:
c6821613
YHC
1110 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
1111 0x3, 0x8, 0x0);
2ec7f01c
LF
1112 break;
1113 case 16:
c6821613
YHC
1114 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15,
1115 0x3, 0x10, 0x0);
2ec7f01c
LF
1116 rssi_adjust_val = 18;
1117 break;
1118 case 18:
c6821613
YHC
1119 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25,
1120 0x3, 0x10, 0x0);
2ec7f01c
LF
1121 rssi_adjust_val = 14;
1122 break;
1123 case 20:
c6821613
YHC
1124 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x35,
1125 0x03, 0x11, 0x10);
2ec7f01c
LF
1126 break;
1127 case 21:
c6821613
YHC
1128 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x15,
1129 0x03, 0x11, 0x10);
2ec7f01c
LF
1130 break;
1131 case 22:
c6821613
YHC
1132 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x25,
1133 0x03, 0x11, 0x10);
2ec7f01c
LF
1134 break;
1135 case 23:
c6821613
YHC
1136 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
1137 0x3, 0x31, 0x18);
2ec7f01c
LF
1138 rssi_adjust_val = 22;
1139 break;
1140 case 24:
c6821613
YHC
1141 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15,
1142 0x3, 0x31, 0x18);
2ec7f01c
LF
1143 rssi_adjust_val = 22;
1144 break;
1145 case 25:
c6821613
YHC
1146 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
1147 0x3, 0x31, 0x18);
2ec7f01c
LF
1148 rssi_adjust_val = 22;
1149 break;
1150 case 26:
c6821613
YHC
1151 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
1152 0x3, 0x31, 0x18);
2ec7f01c
LF
1153 rssi_adjust_val = 22;
1154 break;
1155 case 27:
c6821613
YHC
1156 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
1157 0x3, 0x31, 0x98);
2ec7f01c
LF
1158 rssi_adjust_val = 22;
1159 break;
1160 case 28:
c6821613
YHC
1161 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x69, 0x25,
1162 0x3, 0x31, 0x0);
2ec7f01c
LF
1163 break;
1164 case 29:
c6821613
YHC
1165 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xab, 0x1a,
1166 0x1a, 0x1, 0x10);
2ec7f01c
LF
1167 break;
1168 case 30:
c6821613
YHC
1169 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x14,
1170 0x3, 0x10, 0x50);
2ec7f01c
LF
1171 break;
1172 case 31:
c6821613
YHC
1173 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x1a,
1174 0x1a, 0, 0x58);
2ec7f01c
LF
1175 break;
1176 case 32:
c6821613
YHC
1177 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x61, 0xa,
1178 0x3, 0x10, 0x0);
2ec7f01c
LF
1179 break;
1180 case 33:
c6821613
YHC
1181 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x25,
1182 0x3, 0x30, 0x90);
2ec7f01c
LF
1183 break;
1184 case 34:
c6821613
YHC
1185 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x53, 0x1a,
1186 0x1a, 0x0, 0x10);
2ec7f01c
LF
1187 break;
1188 case 35:
c6821613
YHC
1189 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x63, 0x1a,
1190 0x1a, 0x0, 0x10);
2ec7f01c
LF
1191 break;
1192 case 36:
c6821613
YHC
1193 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x12,
1194 0x3, 0x14, 0x50);
2ec7f01c
LF
1195 break;
1196 }
1197 } else {
c6821613 1198 /* disable PS tdma */
2ec7f01c 1199 switch (type) {
c6821613
YHC
1200 case 8:
1201 /* PTA Control */
1202 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x8, 0x0, 0x0,
1203 0x0, 0x0);
1204 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
1205 false, false);
2ec7f01c
LF
1206 break;
1207 case 0:
c6821613
YHC
1208 default:
1209 /* Software control, Antenna at BT side */
1210 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
1211 0x0, 0x0);
1212 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
1213 false, false);
2ec7f01c 1214 break;
c6821613
YHC
1215 case 9:
1216 /* Software control, Antenna at WiFi side */
1217 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
1218 0x0, 0x0);
1219 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI,
1220 false, false);
2ec7f01c 1221 break;
c6821613
YHC
1222 case 10:
1223 /* under 5G */
1224 btc8821a1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
1225 0x8, 0x0);
1226 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
1227 false, false);
2ec7f01c
LF
1228 break;
1229 }
1230 }
1231 rssi_adjust_val = 0;
1232 btcoexist->btc_set(btcoexist,
1233 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssi_adjust_val);
1234
c6821613 1235 /* update pre state */
2ec7f01c
LF
1236 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1237 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1238}
1239
c6821613 1240static bool btc8821a1ant_is_common_action(struct btc_coexist *btcoexist)
2ec7f01c 1241{
bed4ff58 1242 struct rtl_priv *rtlpriv = btcoexist->adapter;
c6821613 1243 bool common = false, wifi_connected = false, wifi_busy = false;
2ec7f01c
LF
1244
1245 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1246 &wifi_connected);
1247 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1248
1249 if (!wifi_connected &&
1250 BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1251 coex_dm->bt_status) {
bed4ff58
LF
1252 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1253 "[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n");
c6821613 1254 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c
LF
1255
1256 common = true;
1257 } else if (wifi_connected &&
1258 (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
1259 coex_dm->bt_status)) {
bed4ff58
LF
1260 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1261 "[BTCoex], Wifi connected + BT non connected-idle!!\n");
c6821613 1262 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c
LF
1263
1264 common = true;
1265 } else if (!wifi_connected &&
1266 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
1267 coex_dm->bt_status)) {
bed4ff58
LF
1268 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1269 "[BTCoex], Wifi non connected-idle + BT connected-idle!!\n");
c6821613 1270 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c
LF
1271
1272 common = true;
1273 } else if (wifi_connected &&
1274 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
c6821613 1275 coex_dm->bt_status)) {
bed4ff58
LF
1276 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1277 "[BTCoex], Wifi connected + BT connected-idle!!\n");
c6821613 1278 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c
LF
1279
1280 common = true;
1281 } else if (!wifi_connected &&
1282 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE !=
1283 coex_dm->bt_status)) {
bed4ff58
LF
1284 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1285 "[BTCoex], Wifi non connected-idle + BT Busy!!\n");
c6821613 1286 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c
LF
1287
1288 common = true;
1289 } else {
1290 if (wifi_busy) {
bed4ff58
LF
1291 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1292 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n");
2ec7f01c 1293 } else {
bed4ff58
LF
1294 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1295 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n");
2ec7f01c
LF
1296 }
1297
1298 common = false;
1299 }
1300
1301 return common;
1302}
1303
2ec7f01c
LF
1304static void btc8821a1ant_ps_tdma_check_for_pwr_save(struct btc_coexist *btcoex,
1305 bool new_ps_state)
1306{
c6821613 1307 u8 lps_mode = 0x0;
2ec7f01c
LF
1308
1309 btcoex->btc_get(btcoex, BTC_GET_U1_LPS_MODE, &lps_mode);
1310
1311 if (lps_mode) {
c6821613 1312 /* already under LPS state */
2ec7f01c 1313 if (new_ps_state) {
c6821613 1314 /* keep state under LPS, do nothing */
2ec7f01c 1315 } else {
c6821613
YHC
1316 /* will leave LPS state, turn off psTdma first */
1317 btc8821a1ant_ps_tdma(btcoex, NORMAL_EXEC, false, 0);
2ec7f01c
LF
1318 }
1319 } else {
1320 /* NO PS state*/
1321 if (new_ps_state) {
c6821613
YHC
1322 /* will enter LPS state, turn off psTdma first */
1323 btc8821a1ant_ps_tdma(btcoex, NORMAL_EXEC, false, 0);
2ec7f01c 1324 } else {
c6821613 1325 /* keep state under NO PS state, do nothing */
2ec7f01c
LF
1326 }
1327 }
1328}
1329
c6821613
YHC
1330static void btc8821a1ant_power_save_state(struct btc_coexist *btcoexist,
1331 u8 ps_type, u8 lps_val, u8 rpwm_val)
2ec7f01c
LF
1332{
1333 bool low_pwr_disable = false;
1334
1335 switch (ps_type) {
1336 case BTC_PS_WIFI_NATIVE:
c6821613 1337 /* recover to original 32k low power setting */
2ec7f01c
LF
1338 low_pwr_disable = false;
1339 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1340 &low_pwr_disable);
1341 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1342 break;
1343 case BTC_PS_LPS_ON:
1344 btc8821a1ant_ps_tdma_check_for_pwr_save(btcoexist,
1345 true);
c6821613
YHC
1346 btc8821a1ant_lps_rpwm(btcoexist, NORMAL_EXEC, lps_val,
1347 rpwm_val);
1348 /* when coex force to enter LPS, do not enter 32k low power */
2ec7f01c
LF
1349 low_pwr_disable = true;
1350 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1351 &low_pwr_disable);
c6821613 1352 /* power save must executed before psTdma */
2ec7f01c
LF
1353 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1354 break;
1355 case BTC_PS_LPS_OFF:
1356 btc8821a1ant_ps_tdma_check_for_pwr_save(btcoexist, false);
1357 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
1358 break;
1359 default:
1360 break;
1361 }
1362}
1363
c6821613 1364static void btc8821a1ant_coex_under_5g(struct btc_coexist *btcoexist)
2ec7f01c 1365{
c6821613
YHC
1366 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1367 0x0, 0x0);
1368 btc8821a1ant_ignore_wlan_act(btcoexist, NORMAL_EXEC, true);
2ec7f01c 1369
c6821613 1370 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 10);
2ec7f01c 1371
c6821613 1372 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2ec7f01c 1373
c6821613 1374 btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2ec7f01c 1375
c6821613 1376 btc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 5);
2ec7f01c
LF
1377}
1378
27a31a60
YHC
1379/***********************************************
1380 *
1381 * Software Coex Mechanism start
1382 *
1383 ***********************************************/
2ec7f01c 1384
c6821613
YHC
1385/* SCO only or SCO+PAN(HS) */
1386static void btc8821a1ant_action_sco(struct btc_coexist *btcoexist)
2ec7f01c 1387{
c6821613 1388 btc8821a1ant_sw_mechanism(btcoexist, true);
2ec7f01c
LF
1389}
1390
c6821613 1391static void btc8821a1ant_action_hid(struct btc_coexist *btcoexist)
2ec7f01c 1392{
c6821613 1393 btc8821a1ant_sw_mechanism(btcoexist, true);
2ec7f01c
LF
1394}
1395
c6821613
YHC
1396/* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
1397static void btc8821a1ant_action_a2dp(struct btc_coexist *btcoexist)
2ec7f01c 1398{
c6821613 1399 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c
LF
1400}
1401
c6821613 1402static void btc8821a1ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist)
2ec7f01c 1403{
c6821613 1404 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c
LF
1405}
1406
c6821613 1407static void btc8821a1ant_action_pan_edr(struct btc_coexist *btcoexist)
2ec7f01c 1408{
c6821613 1409 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c
LF
1410}
1411
c6821613
YHC
1412/* PAN(HS) only */
1413static void btc8821a1ant_action_pan_hs(struct btc_coexist *btcoexist)
2ec7f01c 1414{
c6821613 1415 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c
LF
1416}
1417
c6821613
YHC
1418/* PAN(EDR)+A2DP */
1419static void btc8821a1ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist)
2ec7f01c 1420{
c6821613 1421 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c
LF
1422}
1423
c6821613 1424static void btc8821a1ant_action_pan_edr_hid(struct btc_coexist *btcoexist)
2ec7f01c 1425{
c6821613 1426 btc8821a1ant_sw_mechanism(btcoexist, true);
2ec7f01c
LF
1427}
1428
c6821613 1429/* HID+A2DP+PAN(EDR) */
2ec7f01c
LF
1430static void btc8821a1ant_action_hid_a2dp_pan_edr(struct btc_coexist *btcoexist)
1431{
c6821613 1432 btc8821a1ant_sw_mechanism(btcoexist, true);
2ec7f01c
LF
1433}
1434
c6821613 1435static void btc8821a1ant_action_hid_a2dp(struct btc_coexist *btcoexist)
2ec7f01c 1436{
c6821613 1437 btc8821a1ant_sw_mechanism(btcoexist, true);
2ec7f01c
LF
1438}
1439
c6821613
YHC
1440/***********************************************
1441 *
1442 * Non-Software Coex Mechanism start
1443 *
1444 ***********************************************/
2ec7f01c 1445
c6821613 1446static void btc8821a1ant_action_hs(struct btc_coexist *btcoexist)
2ec7f01c 1447{
c6821613
YHC
1448 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1449 btc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 2);
2ec7f01c
LF
1450}
1451
c6821613 1452static void btc8821a1ant_action_bt_inquiry(struct btc_coexist *btcoexist)
2ec7f01c
LF
1453{
1454 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1455 bool wifi_connected = false;
1456
1457 btcoexist->btc_get(btcoexist,
1458 BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
1459
1460 if (!wifi_connected) {
c6821613
YHC
1461 btc8821a1ant_power_save_state(btcoexist,
1462 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1463 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1464 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1465 } else if ((bt_link_info->sco_exist) ||
1466 (bt_link_info->hid_only)) {
c6821613
YHC
1467 /* SCO/HID-only busy */
1468 btc8821a1ant_power_save_state(btcoexist,
1469 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1470 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 32);
1471 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c 1472 } else {
c6821613
YHC
1473 btc8821a1ant_power_save_state(btcoexist, BTC_PS_LPS_ON,
1474 0x50, 0x4);
1475 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 30);
1476 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1477 }
1478}
1479
1480static void btc8821a1ant_act_bt_sco_hid_only_busy(struct btc_coexist *btcoexist,
1481 u8 wifi_status) {
c6821613
YHC
1482 /* tdma and coex table */
1483 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
2ec7f01c 1484
c6821613
YHC
1485 if (BT_8821A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN ==
1486 wifi_status)
1487 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1488 else
1489 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1490}
1491
1492static void btc8821a1ant_act_wifi_con_bt_acl_busy(struct btc_coexist *btcoexist,
1493 u8 wifi_status)
1494{
c6821613 1495 u8 bt_rssi_state;
2ec7f01c
LF
1496
1497 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1498
c6821613 1499 bt_rssi_state = btc8821a1ant_bt_rssi_state(btcoexist, 2, 28, 0);
2ec7f01c
LF
1500
1501 if (bt_link_info->hid_only) {
c6821613 1502 /* HID */
2ec7f01c
LF
1503 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist,
1504 wifi_status);
1505 coex_dm->auto_tdma_adjust = false;
1506 return;
1507 } else if (bt_link_info->a2dp_only) {
c6821613 1508 /* A2DP */
27a31a60
YHC
1509 if ((bt_rssi_state != BTC_RSSI_STATE_HIGH) &&
1510 (bt_rssi_state != BTC_RSSI_STATE_STAY_HIGH)) {
c6821613
YHC
1511 /* for low BT RSSI */
1512 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1513 true, 11);
2ec7f01c
LF
1514 coex_dm->auto_tdma_adjust = false;
1515 }
1516
c6821613 1517 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c 1518 } else if (bt_link_info->hid_exist && bt_link_info->a2dp_exist) {
c6821613 1519 /* HID+A2DP */
2ec7f01c
LF
1520 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) ||
1521 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
c6821613
YHC
1522 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1523 true, 14);
2ec7f01c
LF
1524 coex_dm->auto_tdma_adjust = false;
1525 } else {
1526 /*for low BT RSSI*/
c6821613
YHC
1527 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1528 true, 11);
2ec7f01c
LF
1529 coex_dm->auto_tdma_adjust = false;
1530 }
1531
c6821613 1532 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1533 } else if ((bt_link_info->pan_only) ||
1534 (bt_link_info->hid_exist && bt_link_info->pan_exist)) {
c6821613
YHC
1535 /* PAN(OPP, FTP), HID+PAN(OPP, FTP) */
1536 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1537 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1538 coex_dm->auto_tdma_adjust = false;
1539 } else if (((bt_link_info->a2dp_exist) && (bt_link_info->pan_exist)) ||
1540 (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
1541 bt_link_info->pan_exist)) {
c6821613
YHC
1542 /* A2DP+PAN(OPP, FTP), HID+A2DP+PAN(OPP, FTP) */
1543 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
1544 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1545 coex_dm->auto_tdma_adjust = false;
1546 } else {
c6821613
YHC
1547 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1548 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1549 coex_dm->auto_tdma_adjust = false;
1550 }
1551}
1552
c6821613
YHC
1553static
1554void btc8821a1ant_action_wifi_not_connected(struct btc_coexist *btcoexist)
2ec7f01c 1555{
c6821613
YHC
1556 /* power save state */
1557 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2ec7f01c 1558
c6821613
YHC
1559 /* tdma and coex table */
1560 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1561 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
2ec7f01c
LF
1562}
1563
1564static void btc8821a1ant_act_wifi_not_conn_scan(struct btc_coexist *btcoexist)
1565{
c6821613
YHC
1566 btc8821a1ant_power_save_state(btcoexist,
1567 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2ec7f01c 1568
c6821613
YHC
1569 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1570 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1571}
1572
c6821613
YHC
1573static
1574void btc8821a1ant_action_wifi_connected_scan(struct btc_coexist *btcoexist)
1575{
2ec7f01c
LF
1576 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1577
c6821613
YHC
1578 /* power save state */
1579 btc8821a1ant_power_save_state(btcoexist,
1580 BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2ec7f01c 1581
c6821613 1582 /* tdma and coex table */
2ec7f01c
LF
1583 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1584 if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
c6821613
YHC
1585 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22);
1586 btc8821a1ant_coex_table_with_type(btcoexist,
1587 NORMAL_EXEC, 1);
2ec7f01c 1588 } else {
c6821613
YHC
1589 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1590 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1591 }
1592 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
1593 coex_dm->bt_status) ||
1594 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1595 coex_dm->bt_status)) {
1596 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist,
1597 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1598 } else {
c6821613
YHC
1599 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1600 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1601 }
1602}
1603
1604static void btc8821a1ant_act_wifi_conn_sp_pkt(struct btc_coexist *btcoexist)
1605{
1606 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
c6821613 1607 bool hs_connecting = false;
2ec7f01c
LF
1608
1609 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_CONNECTING, &hs_connecting);
1610
c6821613
YHC
1611 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1612 0x0, 0x0);
2ec7f01c 1613
c6821613
YHC
1614 /* tdma and coex table */
1615 if (coex_dm->bt_status == BT_8821A_1ANT_BT_STATUS_ACL_BUSY) {
2ec7f01c 1616 if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
c6821613
YHC
1617 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1618 true, 22);
1619 btc8821a1ant_coex_table_with_type(btcoexist,
1620 NORMAL_EXEC, 1);
2ec7f01c 1621 } else {
c6821613
YHC
1622 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1623 true, 20);
1624 btc8821a1ant_coex_table_with_type(btcoexist,
1625 NORMAL_EXEC, 1);
2ec7f01c
LF
1626 }
1627 } else {
c6821613
YHC
1628 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1629 btc8821a1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
2ec7f01c
LF
1630 }
1631}
1632
c6821613 1633static void btc8821a1ant_action_wifi_connected(struct btc_coexist *btcoexist)
2ec7f01c 1634{
bed4ff58 1635 struct rtl_priv *rtlpriv = btcoexist->adapter;
c6821613
YHC
1636 bool wifi_busy = false;
1637 bool scan = false, link = false, roam = false;
1638 bool under_4way = false;
2ec7f01c 1639
bed4ff58
LF
1640 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1641 "[BTCoex], CoexForWifiConnect()===>\n");
2ec7f01c 1642
c6821613
YHC
1643 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
1644 &under_4way);
2ec7f01c
LF
1645 if (under_4way) {
1646 btc8821a1ant_act_wifi_conn_sp_pkt(btcoexist);
bed4ff58
LF
1647 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1648 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
2ec7f01c
LF
1649 return;
1650 }
1651
1652 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1653 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1654 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1655 if (scan || link || roam) {
c6821613 1656 btc8821a1ant_action_wifi_connected_scan(btcoexist);
bed4ff58
LF
1657 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1658 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
2ec7f01c
LF
1659 return;
1660 }
1661
1662 /* power save state*/
1663 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY ==
1664 coex_dm->bt_status && !btcoexist->bt_link_info.hid_only)
c6821613
YHC
1665 btc8821a1ant_power_save_state(btcoexist,
1666 BTC_PS_LPS_ON, 0x50, 0x4);
2ec7f01c 1667 else
c6821613
YHC
1668 btc8821a1ant_power_save_state(btcoexist,
1669 BTC_PS_WIFI_NATIVE,
1670 0x0, 0x0);
2ec7f01c 1671
c6821613 1672 /* tdma and coex table */
2ec7f01c
LF
1673 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1674 if (!wifi_busy) {
1675 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1676 btc8821a1ant_act_wifi_con_bt_acl_busy(btcoexist,
1677 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1678 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
1679 coex_dm->bt_status) ||
1680 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1681 coex_dm->bt_status)) {
1682 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist,
1683 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1684 } else {
c6821613
YHC
1685 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1686 true, 5);
1687 btc8821a1ant_coex_table_with_type(btcoexist,
1688 NORMAL_EXEC, 2);
2ec7f01c
LF
1689 }
1690 } else {
1691 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) {
1692 btc8821a1ant_act_wifi_con_bt_acl_busy(btcoexist,
1693 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
1694 } else if ((BT_8821A_1ANT_BT_STATUS_SCO_BUSY ==
1695 coex_dm->bt_status) ||
1696 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY ==
1697 coex_dm->bt_status)) {
1698 btc8821a1ant_act_bt_sco_hid_only_busy(btcoexist,
1699 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);
1700 } else {
c6821613
YHC
1701 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1702 btc8821a1ant_coex_table_with_type(btcoexist,
1703 NORMAL_EXEC, 2);
2ec7f01c
LF
1704 }
1705 }
1706}
1707
1708static void btc8821a1ant_run_sw_coex_mech(struct btc_coexist *btcoexist)
1709{
bed4ff58 1710 struct rtl_priv *rtlpriv = btcoexist->adapter;
c6821613 1711 u8 algorithm = 0;
2ec7f01c 1712
c6821613 1713 algorithm = btc8821a1ant_action_algorithm(btcoexist);
2ec7f01c
LF
1714 coex_dm->cur_algorithm = algorithm;
1715
c6821613 1716 if (!btc8821a1ant_is_common_action(btcoexist)) {
2ec7f01c
LF
1717 switch (coex_dm->cur_algorithm) {
1718 case BT_8821A_1ANT_COEX_ALGO_SCO:
bed4ff58
LF
1719 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1720 "[BTCoex], Action algorithm = SCO\n");
c6821613 1721 btc8821a1ant_action_sco(btcoexist);
2ec7f01c
LF
1722 break;
1723 case BT_8821A_1ANT_COEX_ALGO_HID:
bed4ff58
LF
1724 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1725 "[BTCoex], Action algorithm = HID\n");
c6821613 1726 btc8821a1ant_action_hid(btcoexist);
2ec7f01c
LF
1727 break;
1728 case BT_8821A_1ANT_COEX_ALGO_A2DP:
bed4ff58
LF
1729 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1730 "[BTCoex], Action algorithm = A2DP\n");
c6821613 1731 btc8821a1ant_action_a2dp(btcoexist);
2ec7f01c
LF
1732 break;
1733 case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS:
bed4ff58
LF
1734 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1735 "[BTCoex], Action algorithm = A2DP+PAN(HS)\n");
c6821613 1736 btc8821a1ant_action_a2dp_pan_hs(btcoexist);
2ec7f01c
LF
1737 break;
1738 case BT_8821A_1ANT_COEX_ALGO_PANEDR:
bed4ff58
LF
1739 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1740 "[BTCoex], Action algorithm = PAN(EDR)\n");
c6821613 1741 btc8821a1ant_action_pan_edr(btcoexist);
2ec7f01c
LF
1742 break;
1743 case BT_8821A_1ANT_COEX_ALGO_PANHS:
bed4ff58
LF
1744 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1745 "[BTCoex], Action algorithm = HS mode\n");
c6821613 1746 btc8821a1ant_action_pan_hs(btcoexist);
2ec7f01c
LF
1747 break;
1748 case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP:
bed4ff58
LF
1749 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1750 "[BTCoex], Action algorithm = PAN+A2DP\n");
c6821613 1751 btc8821a1ant_action_pan_edr_a2dp(btcoexist);
2ec7f01c
LF
1752 break;
1753 case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID:
bed4ff58
LF
1754 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1755 "[BTCoex], Action algorithm = PAN(EDR)+HID\n");
c6821613 1756 btc8821a1ant_action_pan_edr_hid(btcoexist);
2ec7f01c
LF
1757 break;
1758 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
bed4ff58
LF
1759 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1760 "[BTCoex], Action algorithm = HID+A2DP+PAN\n");
2ec7f01c
LF
1761 btc8821a1ant_action_hid_a2dp_pan_edr(btcoexist);
1762 break;
1763 case BT_8821A_1ANT_COEX_ALGO_HID_A2DP:
bed4ff58
LF
1764 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1765 "[BTCoex], Action algorithm = HID+A2DP\n");
c6821613 1766 btc8821a1ant_action_hid_a2dp(btcoexist);
2ec7f01c
LF
1767 break;
1768 default:
bed4ff58
LF
1769 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1770 "[BTCoex], Action algorithm = coexist All Off!!\n");
c6821613 1771 /*btc8821a1ant_coex_all_off(btcoexist);*/
2ec7f01c
LF
1772 break;
1773 }
1774 coex_dm->pre_algorithm = coex_dm->cur_algorithm;
1775 }
1776}
1777
c6821613 1778static void btc8821a1ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
2ec7f01c 1779{
bed4ff58 1780 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c 1781 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
c6821613
YHC
1782 bool wifi_connected = false, bt_hs_on = false;
1783 bool increase_scan_dev_num = false;
1784 bool bt_ctrl_agg_buf_size = false;
1785 u8 agg_buf_size = 5;
1786 u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
1787 bool wifi_under_5g = false;
2ec7f01c 1788
bed4ff58
LF
1789 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1790 "[BTCoex], RunCoexistMechanism()===>\n");
2ec7f01c
LF
1791
1792 if (btcoexist->manual_control) {
bed4ff58
LF
1793 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1794 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2ec7f01c
LF
1795 return;
1796 }
1797
1798 if (btcoexist->stop_coex_dm) {
bed4ff58
LF
1799 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1800 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2ec7f01c
LF
1801 return;
1802 }
1803
1804 if (coex_sta->under_ips) {
bed4ff58
LF
1805 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1806 "[BTCoex], wifi is under IPS !!!\n");
2ec7f01c
LF
1807 return;
1808 }
1809
1810 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
1811 if (wifi_under_5g) {
bed4ff58
LF
1812 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1813 "[BTCoex], RunCoexistMechanism(), return for 5G <===\n");
c6821613 1814 btc8821a1ant_coex_under_5g(btcoexist);
2ec7f01c
LF
1815 return;
1816 }
1817
1818 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
1819 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
1820 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
1821 increase_scan_dev_num = true;
1822
1823 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
1824 &increase_scan_dev_num);
1825
c6821613
YHC
1826 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1827 &wifi_connected);
2ec7f01c
LF
1828
1829 if (!bt_link_info->sco_exist && !bt_link_info->hid_exist) {
c6821613 1830 btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2ec7f01c
LF
1831 } else {
1832 if (wifi_connected) {
1833 wifi_rssi_state =
c6821613
YHC
1834 btc8821a1ant_wifi_rssi_state(btcoexist, 1, 2,
1835 30, 0);
1836 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) ||
1837 (wifi_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) {
1838 btc8821a1ant_limited_tx(btcoexist,
1839 NORMAL_EXEC, 1, 1,
1840 1, 1);
1841 } else {
1842 btc8821a1ant_limited_tx(btcoexist,
1843 NORMAL_EXEC, 1, 1,
1844 1, 1);
1845 }
2ec7f01c 1846 } else {
c6821613
YHC
1847 btc8821a1ant_limited_tx(btcoexist, NORMAL_EXEC,
1848 0, 0, 0, 0);
2ec7f01c
LF
1849 }
1850 }
1851
1852 if (bt_link_info->sco_exist) {
1853 bt_ctrl_agg_buf_size = true;
1854 agg_buf_size = 0x3;
1855 } else if (bt_link_info->hid_exist) {
1856 bt_ctrl_agg_buf_size = true;
1857 agg_buf_size = 0x5;
1858 } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
1859 bt_ctrl_agg_buf_size = true;
1860 agg_buf_size = 0x8;
1861 }
c6821613
YHC
1862 btc8821a1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
1863 bt_ctrl_agg_buf_size, agg_buf_size);
2ec7f01c
LF
1864
1865 btc8821a1ant_run_sw_coex_mech(btcoexist);
1866
1867 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
1868 if (coex_sta->c2h_bt_inquiry_page) {
c6821613 1869 btc8821a1ant_action_bt_inquiry(btcoexist);
2ec7f01c
LF
1870 return;
1871 } else if (bt_hs_on) {
c6821613 1872 btc8821a1ant_action_hs(btcoexist);
2ec7f01c
LF
1873 return;
1874 }
1875
1876 if (!wifi_connected) {
c6821613 1877 bool scan = false, link = false, roam = false;
2ec7f01c 1878
bed4ff58
LF
1879 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1880 "[BTCoex], wifi is non connected-idle !!!\n");
2ec7f01c
LF
1881
1882 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
1883 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
1884 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
1885
1886 if (scan || link || roam)
1887 btc8821a1ant_act_wifi_not_conn_scan(btcoexist);
1888 else
c6821613 1889 btc8821a1ant_action_wifi_not_connected(btcoexist);
2ec7f01c 1890 } else {
c6821613
YHC
1891 /* wifi LPS/Busy */
1892 btc8821a1ant_action_wifi_connected(btcoexist);
2ec7f01c
LF
1893 }
1894}
1895
c6821613 1896static void btc8821a1ant_init_coex_dm(struct btc_coexist *btcoexist)
2ec7f01c 1897{
c6821613
YHC
1898 /* force to reset coex mechanism
1899 * sw all off
1900 */
1901 btc8821a1ant_sw_mechanism(btcoexist, false);
2ec7f01c 1902
c6821613
YHC
1903 btc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1904 btc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2ec7f01c
LF
1905}
1906
c6821613
YHC
1907static void btc8821a1ant_init_hw_config(struct btc_coexist *btcoexist,
1908 bool back_up)
2ec7f01c 1909{
bed4ff58 1910 struct rtl_priv *rtlpriv = btcoexist->adapter;
c6821613
YHC
1911 u8 u1_tmp = 0;
1912 bool wifi_under_5g = false;
2ec7f01c 1913
bed4ff58
LF
1914 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1915 "[BTCoex], 1Ant Init HW Config!!\n");
2ec7f01c
LF
1916
1917 if (back_up) {
1918 coex_dm->backup_arfr_cnt1 = btcoexist->btc_read_4byte(btcoexist,
1919 0x430);
1920 coex_dm->backup_arfr_cnt2 = btcoexist->btc_read_4byte(btcoexist,
1921 0x434);
1922 coex_dm->backup_retry_limit =
c6821613 1923 btcoexist->btc_read_2byte(btcoexist, 0x42a);
2ec7f01c 1924 coex_dm->backup_ampdu_max_time =
c6821613 1925 btcoexist->btc_read_1byte(btcoexist, 0x456);
2ec7f01c
LF
1926 }
1927
c6821613 1928 /* 0x790[5:0] = 0x5 */
2ec7f01c
LF
1929 u1_tmp = btcoexist->btc_read_1byte(btcoexist, 0x790);
1930 u1_tmp &= 0xc0;
1931 u1_tmp |= 0x5;
1932 btcoexist->btc_write_1byte(btcoexist, 0x790, u1_tmp);
1933
1934 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
1935
c6821613 1936 /* Antenna config */
2ec7f01c 1937 if (wifi_under_5g)
c6821613
YHC
1938 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
1939 true, false);
2ec7f01c 1940 else
c6821613
YHC
1941 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
1942 true, false);
1943 /* PTA parameter */
1944 btc8821a1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
1945
1946 /* Enable counter statistics
1947 * 0x76e[3] =1, WLAN_Act control by PTA
1948 */
2ec7f01c
LF
1949 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
1950 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3);
1951 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
1952}
1953
c6821613
YHC
1954/**************************************************************
1955 * extern function start with ex_btc8821a1ant_
1956 **************************************************************/
1957void ex_btc8821a1ant_init_hwconfig(struct btc_coexist *btcoexist)
2ec7f01c 1958{
c6821613 1959 btc8821a1ant_init_hw_config(btcoexist, true);
2ec7f01c
LF
1960}
1961
c6821613 1962void ex_btc8821a1ant_init_coex_dm(struct btc_coexist *btcoexist)
2ec7f01c 1963{
bed4ff58
LF
1964 struct rtl_priv *rtlpriv = btcoexist->adapter;
1965
1966 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1967 "[BTCoex], Coex Mechanism Init!!\n");
2ec7f01c
LF
1968
1969 btcoexist->stop_coex_dm = false;
1970
c6821613 1971 btc8821a1ant_init_coex_dm(btcoexist);
2ec7f01c 1972
c6821613 1973 btc8821a1ant_query_bt_info(btcoexist);
2ec7f01c
LF
1974}
1975
c6821613 1976void ex_btc8821a1ant_display_coex_info(struct btc_coexist *btcoexist)
2ec7f01c
LF
1977{
1978 struct btc_board_info *board_info = &btcoexist->board_info;
1979 struct btc_stack_info *stack_info = &btcoexist->stack_info;
1980 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
5eef40e5 1981 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c
LF
1982 u8 u1_tmp[4], i, bt_info_ext, ps_tdma_case = 0;
1983 u16 u2_tmp[4];
1984 u32 u4_tmp[4];
1985 bool roam = false, scan = false, link = false, wifi_under_5g = false;
1986 bool bt_hs_on = false, wifi_busy = false;
1987 long wifi_rssi = 0, bt_hs_rssi = 0;
1988 u32 wifi_bw, wifi_traffic_dir;
1989 u8 wifi_dot11_chnl, wifi_hs_chnl;
1990 u32 fw_ver = 0, bt_patch_ver = 0;
1991
5eef40e5 1992 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58 1993 "\r\n ============[BT Coexist info]============");
2ec7f01c
LF
1994
1995 if (btcoexist->manual_control) {
5eef40e5 1996 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58 1997 "\r\n ============[Under Manual Control]============");
5eef40e5 1998 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58 1999 "\r\n ==========================================");
2ec7f01c
LF
2000 }
2001 if (btcoexist->stop_coex_dm) {
5eef40e5 2002 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58 2003 "\r\n ============[Coex is STOPPED]============");
5eef40e5 2004 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58 2005 "\r\n ==========================================");
2ec7f01c
LF
2006 }
2007
2008 if (!board_info->bt_exist) {
5eef40e5 2009 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n BT not exists !!!");
2ec7f01c
LF
2010 return;
2011 }
2012
5eef40e5 2013 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2014 "\r\n %-35s = %d/ %d/ %d",
2015 "Ant PG Num/ Ant Mech/ Ant Pos:",
2016 board_info->pg_ant_num,
2017 board_info->btdm_ant_num,
2018 board_info->btdm_ant_pos);
2ec7f01c 2019
5eef40e5 2020 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2021 "\r\n %-35s = %s / %d", "BT stack/ hci ext ver",
2022 ((stack_info->profile_notified) ? "Yes" : "No"),
2023 stack_info->hci_version);
2ec7f01c
LF
2024
2025 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
2026 &bt_patch_ver);
2027 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
5eef40e5 2028 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2029 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
2030 "CoexVer/ FwVer/ PatchVer",
2031 glcoex_ver_date_8821a_1ant,
2032 glcoex_ver_8821a_1ant,
2033 fw_ver, bt_patch_ver,
2034 bt_patch_ver);
2ec7f01c
LF
2035
2036 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION,
2037 &bt_hs_on);
2038 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL,
2039 &wifi_dot11_chnl);
2040 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL,
2041 &wifi_hs_chnl);
5eef40e5 2042 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2043 "\r\n %-35s = %d / %d(%d)",
2044 "Dot11 channel / HsChnl(HsMode)",
2045 wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on);
2ec7f01c 2046
5eef40e5 2047 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2048 "\r\n %-35s = %3ph ",
2049 "H2C Wifi inform bt chnl Info",
2050 coex_dm->wifi_chnl_info);
2ec7f01c
LF
2051
2052 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
2053 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
5eef40e5 2054 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2055 "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi",
2056 (int)wifi_rssi, (int)bt_hs_rssi);
2ec7f01c
LF
2057
2058 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2059 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2060 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
5eef40e5 2061 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2062 "\r\n %-35s = %d/ %d/ %d ", "Wifi link/ roam/ scan",
2063 link, roam, scan);
2ec7f01c
LF
2064
2065 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G,
2066 &wifi_under_5g);
2067 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW,
2068 &wifi_bw);
2069 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY,
2070 &wifi_busy);
2071 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
2072 &wifi_traffic_dir);
5eef40e5 2073 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2074 "\r\n %-35s = %s / %s/ %s ", "Wifi status",
2075 (wifi_under_5g ? "5G" : "2.4G"),
2076 ((wifi_bw == BTC_WIFI_BW_LEGACY) ? "Legacy" :
2077 (((wifi_bw == BTC_WIFI_BW_HT40) ? "HT40" : "HT20"))),
2078 ((!wifi_busy) ? "idle" :
2079 ((wifi_traffic_dir == BTC_WIFI_TRAFFIC_TX) ?
2080 "uplink" : "downlink")));
5eef40e5 2081 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2ec7f01c
LF
2082 "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]",
2083 ((btcoexist->bt_info.bt_disabled) ? ("disabled") :
2084 ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") :
2085 ((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2086 coex_dm->bt_status) ?
2087 "non-connected idle" :
2088 ((BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE ==
2089 coex_dm->bt_status) ?
2090 "connected-idle" : "busy")))),
2091 coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
2ec7f01c 2092
5eef40e5 2093 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2094 "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
2095 bt_link_info->sco_exist,
2096 bt_link_info->hid_exist,
2097 bt_link_info->pan_exist,
2098 bt_link_info->a2dp_exist);
2ec7f01c
LF
2099 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
2100
2101 bt_info_ext = coex_sta->bt_info_ext;
5eef40e5 2102 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2103 "\r\n %-35s = %s",
2104 "BT Info A2DP rate",
2105 (bt_info_ext & BIT0) ?
2106 "Basic rate" : "EDR rate");
2ec7f01c
LF
2107
2108 for (i = 0; i < BT_INFO_SRC_8821A_1ANT_MAX; i++) {
2109 if (coex_sta->bt_info_c2h_cnt[i]) {
5eef40e5 2110 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2111 "\r\n %-35s = %7ph(%d)",
2112 glbt_info_src_8821a_1ant[i],
2113 coex_sta->bt_info_c2h[i],
2114 coex_sta->bt_info_c2h_cnt[i]);
2ec7f01c
LF
2115 }
2116 }
5eef40e5 2117 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2118 "\r\n %-35s = %s/%s, (0x%x/0x%x)",
2119 "PS state, IPS/LPS, (lps/rpwm)",
2120 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
c6821613 2121 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")),
bed4ff58
LF
2122 btcoexist->bt_info.lps_val,
2123 btcoexist->bt_info.rpwm_val);
2ec7f01c
LF
2124 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
2125
2126 if (!btcoexist->manual_control) {
2127 /* Sw mechanism*/
5eef40e5 2128 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2129 "\r\n %-35s",
2130 "============[Sw mechanism]============");
2ec7f01c 2131
5eef40e5 2132 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2133 "\r\n %-35s = %d", "SM[LowPenaltyRA]",
2134 coex_dm->cur_low_penalty_ra);
2ec7f01c 2135
5eef40e5 2136 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2137 "\r\n %-35s = %s/ %s/ %d ",
2138 "DelBA/ BtCtrlAgg/ AggSize",
2139 (btcoexist->bt_info.reject_agg_pkt ? "Yes" : "No"),
2140 (btcoexist->bt_info.bt_ctrl_buf_size ? "Yes" : "No"),
2141 btcoexist->bt_info.agg_buf_size);
5eef40e5 2142 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2143 "\r\n %-35s = 0x%x ", "Rate Mask",
2144 btcoexist->bt_info.ra_mask);
2ec7f01c 2145
c6821613 2146 /* Fw mechanism */
5eef40e5 2147 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
bed4ff58 2148 "============[Fw mechanism]============");
2ec7f01c
LF
2149
2150 ps_tdma_case = coex_dm->cur_ps_tdma;
5eef40e5 2151 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2152 "\r\n %-35s = %5ph case-%d (auto:%d)",
2153 "PS TDMA",
2154 coex_dm->ps_tdma_para,
2155 ps_tdma_case,
2156 coex_dm->auto_tdma_adjust);
2ec7f01c 2157
5eef40e5 2158 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2159 "\r\n %-35s = 0x%x ",
2160 "Latest error condition(should be 0)",
2ec7f01c 2161 coex_dm->error_condition);
2ec7f01c 2162
5eef40e5 2163 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2164 "\r\n %-35s = %d ", "IgnWlanAct",
2165 coex_dm->cur_ignore_wlan_act);
2ec7f01c
LF
2166 }
2167
c6821613 2168 /* Hw setting */
5eef40e5 2169 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58 2170 "\r\n %-35s", "============[Hw setting]============");
2ec7f01c 2171
5eef40e5 2172 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2173 "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2174 "backup ARFR1/ARFR2/RL/AMaxTime",
2175 coex_dm->backup_arfr_cnt1,
2176 coex_dm->backup_arfr_cnt2,
2177 coex_dm->backup_retry_limit,
2178 coex_dm->backup_ampdu_max_time);
2ec7f01c
LF
2179
2180 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
2181 u4_tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
2182 u2_tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
2183 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
5eef40e5 2184 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2185 "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2186 "0x430/0x434/0x42a/0x456",
2187 u4_tmp[0], u4_tmp[1], u2_tmp[0], u1_tmp[0]);
2ec7f01c
LF
2188
2189 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
2190 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc58);
5eef40e5 2191 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2192 "\r\n %-35s = 0x%x/ 0x%x", "0x778/ 0xc58[29:25]",
2193 u1_tmp[0], (u4_tmp[0] & 0x3e000000) >> 25);
2ec7f01c
LF
2194
2195 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x8db);
5eef40e5 2196 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2197 "\r\n %-35s = 0x%x", "0x8db[6:5]",
2198 ((u1_tmp[0] & 0x60) >> 5));
2ec7f01c
LF
2199
2200 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x975);
2201 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xcb4);
5eef40e5 2202 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2203 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2204 "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]",
2205 (u4_tmp[0] & 0x30000000) >> 28,
2206 u4_tmp[0] & 0xff,
2207 u1_tmp[0] & 0x3);
2ec7f01c
LF
2208
2209 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x40);
2210 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
2211 u1_tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x64);
5eef40e5 2212 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2213 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2214 "0x40/0x4c[24:23]/0x64[0]",
2215 u1_tmp[0], ((u4_tmp[0] & 0x01800000) >> 23), u1_tmp[1] & 0x1);
2ec7f01c
LF
2216
2217 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
2218 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
5eef40e5 2219 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2220 "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522",
2221 u4_tmp[0], u1_tmp[0]);
2ec7f01c
LF
2222
2223 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
5eef40e5 2224 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2225 "\r\n %-35s = 0x%x", "0xc50(dig)",
2226 u4_tmp[0] & 0xff);
2ec7f01c
LF
2227
2228 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xf48);
2229 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5d);
2230 u1_tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
5eef40e5 2231 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2232 "\r\n %-35s = 0x%x/ 0x%x", "OFDM-FA/ CCK-FA",
2233 u4_tmp[0], (u1_tmp[0] << 8) + u1_tmp[1]);
2ec7f01c
LF
2234
2235 u4_tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
2236 u4_tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
2237 u4_tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
2238 u1_tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc);
5eef40e5 2239 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2240 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2241 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)",
2ec7f01c 2242 u4_tmp[0], u4_tmp[1], u4_tmp[2], u1_tmp[0]);
2ec7f01c 2243
5eef40e5 2244 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2245 "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)",
2246 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
5eef40e5 2247 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
bed4ff58
LF
2248 "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)",
2249 coex_sta->low_priority_rx, coex_sta->low_priority_tx);
2ec7f01c 2250#if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 1)
c6821613 2251 btc8821a1ant_monitor_bt_ctr(btcoexist);
2ec7f01c
LF
2252#endif
2253 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
2254}
2255
c6821613 2256void ex_btc8821a1ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
2ec7f01c 2257{
bed4ff58
LF
2258 struct rtl_priv *rtlpriv = btcoexist->adapter;
2259
2ec7f01c
LF
2260 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2261 return;
2262
2263 if (BTC_IPS_ENTER == type) {
bed4ff58
LF
2264 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2265 "[BTCoex], IPS ENTER notify\n");
2ec7f01c 2266 coex_sta->under_ips = true;
c6821613
YHC
2267 btc8821a1ant_set_ant_path(btcoexist,
2268 BTC_ANT_PATH_BT, false, true);
2269 /* set PTA control */
2270 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
2271 btc8821a1ant_coex_table_with_type(btcoexist,
2272 NORMAL_EXEC, 0);
2ec7f01c 2273 } else if (BTC_IPS_LEAVE == type) {
bed4ff58
LF
2274 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2275 "[BTCoex], IPS LEAVE notify\n");
2ec7f01c
LF
2276 coex_sta->under_ips = false;
2277
c6821613 2278 btc8821a1ant_run_coexist_mechanism(btcoexist);
2ec7f01c
LF
2279 }
2280}
2281
c6821613 2282void ex_btc8821a1ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
2ec7f01c 2283{
bed4ff58
LF
2284 struct rtl_priv *rtlpriv = btcoexist->adapter;
2285
2ec7f01c
LF
2286 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2287 return;
2288
2289 if (BTC_LPS_ENABLE == type) {
bed4ff58
LF
2290 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2291 "[BTCoex], LPS ENABLE notify\n");
c6821613 2292 coex_sta->under_lps = true;
2ec7f01c 2293 } else if (BTC_LPS_DISABLE == type) {
bed4ff58
LF
2294 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2295 "[BTCoex], LPS DISABLE notify\n");
c6821613 2296 coex_sta->under_lps = false;
2ec7f01c
LF
2297 }
2298}
2299
c6821613 2300void ex_btc8821a1ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
2ec7f01c 2301{
bed4ff58 2302 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c
LF
2303 bool wifi_connected = false, bt_hs_on = false;
2304
2305 if (btcoexist->manual_control ||
2306 btcoexist->stop_coex_dm ||
2307 btcoexist->bt_info.bt_disabled)
2308 return;
2309
2310 btcoexist->btc_get(btcoexist,
2311 BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2312 btcoexist->btc_get(btcoexist,
2313 BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
2314
c6821613 2315 btc8821a1ant_query_bt_info(btcoexist);
2ec7f01c
LF
2316
2317 if (coex_sta->c2h_bt_inquiry_page) {
c6821613 2318 btc8821a1ant_action_bt_inquiry(btcoexist);
2ec7f01c
LF
2319 return;
2320 } else if (bt_hs_on) {
c6821613 2321 btc8821a1ant_action_hs(btcoexist);
2ec7f01c
LF
2322 return;
2323 }
2324
2325 if (BTC_SCAN_START == type) {
bed4ff58
LF
2326 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2327 "[BTCoex], SCAN START notify\n");
2ec7f01c 2328 if (!wifi_connected) {
c6821613 2329 /* non-connected scan */
2ec7f01c
LF
2330 btc8821a1ant_act_wifi_not_conn_scan(btcoexist);
2331 } else {
c6821613
YHC
2332 /* wifi is connected */
2333 btc8821a1ant_action_wifi_connected_scan(btcoexist);
2ec7f01c
LF
2334 }
2335 } else if (BTC_SCAN_FINISH == type) {
bed4ff58
LF
2336 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2337 "[BTCoex], SCAN FINISH notify\n");
2ec7f01c 2338 if (!wifi_connected) {
c6821613
YHC
2339 /* non-connected scan */
2340 btc8821a1ant_action_wifi_not_connected(btcoexist);
2ec7f01c 2341 } else {
c6821613 2342 btc8821a1ant_action_wifi_connected(btcoexist);
2ec7f01c
LF
2343 }
2344 }
2345}
2346
c6821613 2347void ex_btc8821a1ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
2ec7f01c 2348{
bed4ff58 2349 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c
LF
2350 bool wifi_connected = false, bt_hs_on = false;
2351
2352 if (btcoexist->manual_control ||
2353 btcoexist->stop_coex_dm ||
2354 btcoexist->bt_info.bt_disabled)
2355 return;
2356
2357 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2358 if (coex_sta->c2h_bt_inquiry_page) {
c6821613 2359 btc8821a1ant_action_bt_inquiry(btcoexist);
2ec7f01c
LF
2360 return;
2361 } else if (bt_hs_on) {
c6821613 2362 btc8821a1ant_action_hs(btcoexist);
2ec7f01c
LF
2363 return;
2364 }
2365
2366 if (BTC_ASSOCIATE_START == type) {
bed4ff58
LF
2367 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2368 "[BTCoex], CONNECT START notify\n");
2ec7f01c
LF
2369 btc8821a1ant_act_wifi_not_conn_scan(btcoexist);
2370 } else if (BTC_ASSOCIATE_FINISH == type) {
bed4ff58
LF
2371 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2372 "[BTCoex], CONNECT FINISH notify\n");
2ec7f01c
LF
2373
2374 btcoexist->btc_get(btcoexist,
2375 BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
2376 if (!wifi_connected) {
c6821613
YHC
2377 /* non-connected scan */
2378 btc8821a1ant_action_wifi_not_connected(btcoexist);
2ec7f01c 2379 } else {
c6821613 2380 btc8821a1ant_action_wifi_connected(btcoexist);
2ec7f01c
LF
2381 }
2382 }
2383}
2384
c6821613
YHC
2385void ex_btc8821a1ant_media_status_notify(struct btc_coexist *btcoexist,
2386 u8 type)
2ec7f01c 2387{
bed4ff58 2388 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c
LF
2389 u8 h2c_parameter[3] = {0};
2390 u32 wifi_bw;
2391 u8 wifi_central_chnl;
2392
2393 if (btcoexist->manual_control ||
2394 btcoexist->stop_coex_dm ||
2395 btcoexist->bt_info.bt_disabled)
2396 return;
2397
2398 if (BTC_MEDIA_CONNECT == type) {
bed4ff58
LF
2399 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2400 "[BTCoex], MEDIA connect notify\n");
2ec7f01c 2401 } else {
bed4ff58
LF
2402 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2403 "[BTCoex], MEDIA disconnect notify\n");
2ec7f01c
LF
2404 }
2405
c6821613 2406 /* only 2.4G we need to inform bt the chnl mask */
2ec7f01c
LF
2407 btcoexist->btc_get(btcoexist,
2408 BTC_GET_U1_WIFI_CENTRAL_CHNL,
2409 &wifi_central_chnl);
c6821613 2410 if ((type == BTC_MEDIA_CONNECT) &&
2ec7f01c 2411 (wifi_central_chnl <= 14)) {
2ec7f01c
LF
2412 h2c_parameter[0] = 0x0;
2413 h2c_parameter[1] = wifi_central_chnl;
2414 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
c6821613 2415 if (wifi_bw == BTC_WIFI_BW_HT40)
2ec7f01c
LF
2416 h2c_parameter[2] = 0x30;
2417 else
2418 h2c_parameter[2] = 0x20;
2419 }
2420
2421 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
2422 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
2423 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
2424
bed4ff58
LF
2425 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2426 "[BTCoex], FW write 0x66 = 0x%x\n",
2427 h2c_parameter[0] << 16 |
2428 h2c_parameter[1] << 8 |
2429 h2c_parameter[2]);
2ec7f01c
LF
2430
2431 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
2432}
2433
c6821613
YHC
2434void ex_btc8821a1ant_special_packet_notify(struct btc_coexist *btcoexist,
2435 u8 type)
2ec7f01c 2436{
bed4ff58 2437 struct rtl_priv *rtlpriv = btcoexist->adapter;
2ec7f01c
LF
2438 bool bt_hs_on = false;
2439
2440 if (btcoexist->manual_control ||
2441 btcoexist->stop_coex_dm ||
2442 btcoexist->bt_info.bt_disabled)
2443 return;
2444
2445 coex_sta->special_pkt_period_cnt = 0;
2446
2447 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2448 if (coex_sta->c2h_bt_inquiry_page) {
c6821613 2449 btc8821a1ant_action_bt_inquiry(btcoexist);
2ec7f01c
LF
2450 return;
2451 } else if (bt_hs_on) {
c6821613 2452 btc8821a1ant_action_hs(btcoexist);
2ec7f01c
LF
2453 return;
2454 }
2455
2456 if (BTC_PACKET_DHCP == type ||
2457 BTC_PACKET_EAPOL == type) {
bed4ff58
LF
2458 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2459 "[BTCoex], special Packet(%d) notify\n", type);
2ec7f01c
LF
2460 btc8821a1ant_act_wifi_conn_sp_pkt(btcoexist);
2461 }
2462}
2463
c6821613
YHC
2464void ex_btc8821a1ant_bt_info_notify(struct btc_coexist *btcoexist,
2465 u8 *tmp_buf, u8 length)
2ec7f01c 2466{
bed4ff58 2467 struct rtl_priv *rtlpriv = btcoexist->adapter;
c6821613 2468 u8 i;
2ec7f01c 2469 u8 bt_info = 0;
c6821613 2470 u8 rsp_source = 0;
2ec7f01c
LF
2471 bool wifi_connected = false;
2472 bool bt_busy = false;
2473 bool wifi_under_5g = false;
2474
2475 coex_sta->c2h_bt_info_req_sent = false;
2476
2477 btcoexist->btc_get(btcoexist,
2478 BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
2479
c6821613 2480 rsp_source = tmp_buf[0] & 0xf;
2ec7f01c
LF
2481 if (rsp_source >= BT_INFO_SRC_8821A_1ANT_MAX)
2482 rsp_source = BT_INFO_SRC_8821A_1ANT_WIFI_FW;
2483 coex_sta->bt_info_c2h_cnt[rsp_source]++;
2484
bed4ff58
LF
2485 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2486 "[BTCoex], Bt info[%d], length = %d, hex data = [",
2487 rsp_source, length);
2ec7f01c
LF
2488 for (i = 0; i < length; i++) {
2489 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
2490 if (i == 1)
2491 bt_info = tmp_buf[i];
c6821613 2492 if (i == length - 1) {
bed4ff58
LF
2493 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2494 "0x%02x]\n", tmp_buf[i]);
2ec7f01c 2495 } else {
bed4ff58
LF
2496 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2497 "0x%02x, ", tmp_buf[i]);
2ec7f01c
LF
2498 }
2499 }
2500
2501 if (BT_INFO_SRC_8821A_1ANT_WIFI_FW != rsp_source) {
2502 coex_sta->bt_retry_cnt = /* [3:0]*/
2503 coex_sta->bt_info_c2h[rsp_source][2]&0xf;
2504
2505 coex_sta->bt_rssi =
2506 coex_sta->bt_info_c2h[rsp_source][3]*2+10;
2507
2508 coex_sta->bt_info_ext =
2509 coex_sta->bt_info_c2h[rsp_source][4];
2510
c6821613
YHC
2511 /* Here we need to resend some wifi info to BT
2512 * because bt is reset and lost the info
2513 */
2ec7f01c 2514 if (coex_sta->bt_info_ext & BIT1) {
bed4ff58
LF
2515 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2516 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
c6821613 2517 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2ec7f01c
LF
2518 &wifi_connected);
2519 if (wifi_connected) {
c6821613 2520 ex_btc8821a1ant_media_status_notify(btcoexist,
2ec7f01c
LF
2521 BTC_MEDIA_CONNECT);
2522 } else {
c6821613 2523 ex_btc8821a1ant_media_status_notify(btcoexist,
2ec7f01c
LF
2524 BTC_MEDIA_DISCONNECT);
2525 }
2526 }
2527
2528 if ((coex_sta->bt_info_ext & BIT3) && !wifi_under_5g) {
2529 if (!btcoexist->manual_control &&
2530 !btcoexist->stop_coex_dm) {
bed4ff58
LF
2531 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2532 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
c6821613
YHC
2533 btc8821a1ant_ignore_wlan_act(btcoexist,
2534 FORCE_EXEC,
2535 false);
2ec7f01c
LF
2536 }
2537 }
2ec7f01c
LF
2538 }
2539
c6821613 2540 /* check BIT2 first ==> check if bt is under inquiry or page scan */
2ec7f01c
LF
2541 if (bt_info & BT_INFO_8821A_1ANT_B_INQ_PAGE)
2542 coex_sta->c2h_bt_inquiry_page = true;
2543 else
2544 coex_sta->c2h_bt_inquiry_page = false;
2545
c6821613
YHC
2546 /* set link exist status */
2547 if (!(bt_info & BT_INFO_8821A_1ANT_B_CONNECTION)) {
2ec7f01c
LF
2548 coex_sta->bt_link_exist = false;
2549 coex_sta->pan_exist = false;
2550 coex_sta->a2dp_exist = false;
2551 coex_sta->hid_exist = false;
2552 coex_sta->sco_exist = false;
2553 } else {
c6821613 2554 /* connection exists */
2ec7f01c
LF
2555 coex_sta->bt_link_exist = true;
2556 if (bt_info & BT_INFO_8821A_1ANT_B_FTP)
2557 coex_sta->pan_exist = true;
2558 else
2559 coex_sta->pan_exist = false;
2560 if (bt_info & BT_INFO_8821A_1ANT_B_A2DP)
2561 coex_sta->a2dp_exist = true;
2562 else
2563 coex_sta->a2dp_exist = false;
2564 if (bt_info & BT_INFO_8821A_1ANT_B_HID)
2565 coex_sta->hid_exist = true;
2566 else
2567 coex_sta->hid_exist = false;
2568 if (bt_info & BT_INFO_8821A_1ANT_B_SCO_ESCO)
2569 coex_sta->sco_exist = true;
2570 else
2571 coex_sta->sco_exist = false;
2572 }
2573
c6821613 2574 btc8821a1ant_update_bt_link_info(btcoexist);
2ec7f01c
LF
2575
2576 if (!(bt_info&BT_INFO_8821A_1ANT_B_CONNECTION)) {
2577 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
bed4ff58
LF
2578 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2579 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
2ec7f01c 2580 } else if (bt_info == BT_INFO_8821A_1ANT_B_CONNECTION) {
c6821613 2581 /* connection exists but no busy */
2ec7f01c 2582 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE;
bed4ff58
LF
2583 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2584 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
2ec7f01c
LF
2585 } else if ((bt_info&BT_INFO_8821A_1ANT_B_SCO_ESCO) ||
2586 (bt_info&BT_INFO_8821A_1ANT_B_SCO_BUSY)) {
2587 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_SCO_BUSY;
bed4ff58
LF
2588 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2589 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
2ec7f01c
LF
2590 } else if (bt_info&BT_INFO_8821A_1ANT_B_ACL_BUSY) {
2591 if (BT_8821A_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
2592 coex_dm->auto_tdma_adjust = false;
2593 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_ACL_BUSY;
bed4ff58
LF
2594 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2595 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
2ec7f01c
LF
2596 } else {
2597 coex_dm->bt_status = BT_8821A_1ANT_BT_STATUS_MAX;
bed4ff58
LF
2598 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2599 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
2ec7f01c
LF
2600 }
2601
2602 if ((BT_8821A_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
2603 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
2604 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
2605 bt_busy = true;
2606 else
2607 bt_busy = false;
2608 btcoexist->btc_set(btcoexist,
2609 BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
2610
c6821613 2611 btc8821a1ant_run_coexist_mechanism(btcoexist);
2ec7f01c
LF
2612}
2613
c6821613 2614void ex_btc8821a1ant_halt_notify(struct btc_coexist *btcoexist)
2ec7f01c 2615{
bed4ff58
LF
2616 struct rtl_priv *rtlpriv = btcoexist->adapter;
2617
2618 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2619 "[BTCoex], Halt notify\n");
2ec7f01c
LF
2620
2621 btcoexist->stop_coex_dm = true;
2622
c6821613
YHC
2623 btc8821a1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, false, true);
2624 btc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
2ec7f01c 2625
c6821613
YHC
2626 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2627 btc8821a1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
2ec7f01c 2628
c6821613 2629 ex_btc8821a1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
2ec7f01c
LF
2630}
2631
c6821613 2632void ex_btc8821a1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
2ec7f01c 2633{
bed4ff58
LF
2634 struct rtl_priv *rtlpriv = btcoexist->adapter;
2635
2636 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2637 "[BTCoex], Pnp notify\n");
2ec7f01c
LF
2638
2639 if (BTC_WIFI_PNP_SLEEP == pnp_state) {
bed4ff58
LF
2640 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2641 "[BTCoex], Pnp notify to SLEEP\n");
2ec7f01c 2642 btcoexist->stop_coex_dm = true;
c6821613
YHC
2643 btc8821a1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
2644 btc8821a1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2645 0x0, 0x0);
2646 btc8821a1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 9);
2ec7f01c 2647 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
bed4ff58
LF
2648 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2649 "[BTCoex], Pnp notify to WAKE UP\n");
2ec7f01c 2650 btcoexist->stop_coex_dm = false;
c6821613
YHC
2651 btc8821a1ant_init_hw_config(btcoexist, false);
2652 btc8821a1ant_init_coex_dm(btcoexist);
2653 btc8821a1ant_query_bt_info(btcoexist);
2ec7f01c
LF
2654 }
2655}
2656
c6821613 2657void ex_btc8821a1ant_periodical(struct btc_coexist *btcoexist)
bed4ff58
LF
2658{
2659 struct rtl_priv *rtlpriv = btcoexist->adapter;
c6821613
YHC
2660 static u8 dis_ver_info_cnt;
2661 u32 fw_ver = 0, bt_patch_ver = 0;
2ec7f01c
LF
2662 struct btc_board_info *board_info = &btcoexist->board_info;
2663 struct btc_stack_info *stack_info = &btcoexist->stack_info;
2664
bed4ff58
LF
2665 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2666 "[BTCoex], ==========================Periodical===========================\n");
2ec7f01c
LF
2667
2668 if (dis_ver_info_cnt <= 5) {
2669 dis_ver_info_cnt += 1;
bed4ff58
LF
2670 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2671 "[BTCoex], ****************************************************************\n");
2672 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2673 "[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
466414a0
JP
2674 board_info->pg_ant_num,
2675 board_info->btdm_ant_num,
2676 board_info->btdm_ant_pos);
bed4ff58
LF
2677 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2678 "[BTCoex], BT stack/ hci ext ver = %s / %d\n",
466414a0
JP
2679 stack_info->profile_notified ? "Yes" : "No",
2680 stack_info->hci_version);
2ec7f01c
LF
2681 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER,
2682 &bt_patch_ver);
2683 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
bed4ff58
LF
2684 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2685 "[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
466414a0
JP
2686 glcoex_ver_date_8821a_1ant,
2687 glcoex_ver_8821a_1ant,
2688 fw_ver, bt_patch_ver,
2689 bt_patch_ver);
bed4ff58
LF
2690 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2691 "[BTCoex], ****************************************************************\n");
2ec7f01c
LF
2692 }
2693
2694#if (BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)
c6821613
YHC
2695 btc8821a1ant_query_bt_info(btcoexist);
2696 btc8821a1ant_monitor_bt_ctr(btcoexist);
2ec7f01c 2697#else
2ec7f01c
LF
2698 coex_sta->special_pkt_period_cnt++;
2699#endif
2700}