]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/net/wireless/realtek/rtlwifi/btcoexist/halbtc8723b1ant.c
rtlwifi: btcoex: 23b 1ant: Add coex_table_type to log
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / realtek / rtlwifi / btcoexist / halbtc8723b1ant.c
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
26 /***************************************************************
27 * Description:
28 *
29 * This file is for RTL8723B Co-exist mechanism
30 *
31 * History
32 * 2012/11/15 Cosa first check in.
33 *
34 ***************************************************************/
35
36 /***************************************************************
37 * include files
38 ***************************************************************/
39 #include "halbt_precomp.h"
40 /***************************************************************
41 * Global variables, these are static variables
42 ***************************************************************/
43 static struct coex_dm_8723b_1ant glcoex_dm_8723b_1ant;
44 static struct coex_dm_8723b_1ant *coex_dm = &glcoex_dm_8723b_1ant;
45 static struct coex_sta_8723b_1ant glcoex_sta_8723b_1ant;
46 static struct coex_sta_8723b_1ant *coex_sta = &glcoex_sta_8723b_1ant;
47
48 static const char *const glbt_info_src_8723b_1ant[] = {
49 "BT Info[wifi fw]",
50 "BT Info[bt rsp]",
51 "BT Info[bt auto report]",
52 };
53
54 static u32 glcoex_ver_date_8723b_1ant = 20130918;
55 static u32 glcoex_ver_8723b_1ant = 0x47;
56
57 /***************************************************************
58 * local function proto type if needed
59 ***************************************************************/
60 /***************************************************************
61 * local function start with halbtc8723b1ant_
62 ***************************************************************/
63
64 static void halbtc8723b1ant_updatera_mask(struct btc_coexist *btcoexist,
65 bool force_exec, u32 dis_rate_mask)
66 {
67 coex_dm->curra_mask = dis_rate_mask;
68
69 if (force_exec || (coex_dm->prera_mask != coex_dm->curra_mask))
70 btcoexist->btc_set(btcoexist, BTC_SET_ACT_UPDATE_RAMASK,
71 &coex_dm->curra_mask);
72
73 coex_dm->prera_mask = coex_dm->curra_mask;
74 }
75
76 static void btc8723b1ant_auto_rate_fb_retry(struct btc_coexist *btcoexist,
77 bool force_exec, u8 type)
78 {
79 bool wifi_under_bmode = false;
80
81 coex_dm->cur_arfr_type = type;
82
83 if (force_exec || (coex_dm->pre_arfr_type != coex_dm->cur_arfr_type)) {
84 switch (coex_dm->cur_arfr_type) {
85 case 0: /* normal mode */
86 btcoexist->btc_write_4byte(btcoexist, 0x430,
87 coex_dm->backup_arfr_cnt1);
88 btcoexist->btc_write_4byte(btcoexist, 0x434,
89 coex_dm->backup_arfr_cnt2);
90 break;
91 case 1:
92 btcoexist->btc_get(btcoexist,
93 BTC_GET_BL_WIFI_UNDER_B_MODE,
94 &wifi_under_bmode);
95 if (wifi_under_bmode) {
96 btcoexist->btc_write_4byte(btcoexist,
97 0x430, 0x0);
98 btcoexist->btc_write_4byte(btcoexist,
99 0x434, 0x01010101);
100 } else {
101 btcoexist->btc_write_4byte(btcoexist,
102 0x430, 0x0);
103 btcoexist->btc_write_4byte(btcoexist,
104 0x434, 0x04030201);
105 }
106 break;
107 default:
108 break;
109 }
110 }
111
112 coex_dm->pre_arfr_type = coex_dm->cur_arfr_type;
113 }
114
115 static void halbtc8723b1ant_retry_limit(struct btc_coexist *btcoexist,
116 bool force_exec, u8 type)
117 {
118 coex_dm->cur_retry_limit_type = type;
119
120 if (force_exec || (coex_dm->pre_retry_limit_type !=
121 coex_dm->cur_retry_limit_type)) {
122 switch (coex_dm->cur_retry_limit_type) {
123 case 0: /* normal mode */
124 btcoexist->btc_write_2byte(btcoexist, 0x42a,
125 coex_dm->backup_retry_limit);
126 break;
127 case 1: /* retry limit = 8 */
128 btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808);
129 break;
130 default:
131 break;
132 }
133 }
134
135 coex_dm->pre_retry_limit_type = coex_dm->cur_retry_limit_type;
136 }
137
138 static void halbtc8723b1ant_ampdu_maxtime(struct btc_coexist *btcoexist,
139 bool force_exec, u8 type)
140 {
141 coex_dm->cur_ampdu_time_type = type;
142
143 if (force_exec || (coex_dm->pre_ampdu_time_type !=
144 coex_dm->cur_ampdu_time_type)) {
145 switch (coex_dm->cur_ampdu_time_type) {
146 case 0: /* normal mode */
147 btcoexist->btc_write_1byte(btcoexist, 0x456,
148 coex_dm->backup_ampdu_max_time);
149 break;
150 case 1: /* AMPDU timw = 0x38 * 32us */
151 btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38);
152 break;
153 default:
154 break;
155 }
156 }
157
158 coex_dm->pre_ampdu_time_type = coex_dm->cur_ampdu_time_type;
159 }
160
161 static void halbtc8723b1ant_limited_tx(struct btc_coexist *btcoexist,
162 bool force_exec, u8 ra_masktype,
163 u8 arfr_type, u8 retry_limit_type,
164 u8 ampdu_time_type)
165 {
166 switch (ra_masktype) {
167 case 0: /* normal mode */
168 halbtc8723b1ant_updatera_mask(btcoexist, force_exec, 0x0);
169 break;
170 case 1: /* disable cck 1/2 */
171 halbtc8723b1ant_updatera_mask(btcoexist, force_exec,
172 0x00000003);
173 break;
174 /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
175 case 2:
176 halbtc8723b1ant_updatera_mask(btcoexist, force_exec,
177 0x0001f1f7);
178 break;
179 default:
180 break;
181 }
182
183 btc8723b1ant_auto_rate_fb_retry(btcoexist, force_exec, arfr_type);
184 halbtc8723b1ant_retry_limit(btcoexist, force_exec, retry_limit_type);
185 halbtc8723b1ant_ampdu_maxtime(btcoexist, force_exec, ampdu_time_type);
186 }
187
188 static void halbtc8723b1ant_limited_rx(struct btc_coexist *btcoexist,
189 bool force_exec, bool rej_ap_agg_pkt,
190 bool bt_ctrl_agg_buf_size,
191 u8 agg_buf_size)
192 {
193 bool reject_rx_agg = rej_ap_agg_pkt;
194 bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
195 u8 rxaggsize = agg_buf_size;
196
197 /**********************************************
198 * Rx Aggregation related setting
199 **********************************************/
200 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT,
201 &reject_rx_agg);
202 /* decide BT control aggregation buf size or not */
203 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE,
204 &bt_ctrl_rx_agg_size);
205 /* aggregation buf size, only work
206 * when BT control Rx aggregation size.
207 */
208 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxaggsize);
209 /* real update aggregation setting */
210 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
211 }
212
213 static void halbtc8723b1ant_query_bt_info(struct btc_coexist *btcoexist)
214 {
215 u8 h2c_parameter[1] = {0};
216
217 coex_sta->c2h_bt_info_req_sent = true;
218
219 /* trigger */
220 h2c_parameter[0] |= BIT(0);
221
222 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter);
223 }
224
225 static void halbtc8723b1ant_monitor_bt_ctr(struct btc_coexist *btcoexist)
226 {
227 u32 reg_hp_txrx, reg_lp_txrx, u32tmp;
228 u32 reg_hp_tx = 0, reg_hp_rx = 0;
229 u32 reg_lp_tx = 0, reg_lp_rx = 0;
230 static u32 num_of_bt_counter_chk;
231
232 reg_hp_txrx = 0x770;
233 reg_lp_txrx = 0x774;
234
235 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx);
236 reg_hp_tx = u32tmp & MASKLWORD;
237 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
238
239 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx);
240 reg_lp_tx = u32tmp & MASKLWORD;
241 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
242
243 coex_sta->high_priority_tx = reg_hp_tx;
244 coex_sta->high_priority_rx = reg_hp_rx;
245 coex_sta->low_priority_tx = reg_lp_tx;
246 coex_sta->low_priority_rx = reg_lp_rx;
247
248 if ((coex_sta->low_priority_tx > 1050) &&
249 (!coex_sta->c2h_bt_inquiry_page))
250 coex_sta->pop_event_cnt++;
251
252 /* reset counter */
253 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
254
255 /* This part is for wifi FW and driver to update BT's status as
256 * disabled.
257 *
258 * The flow is as the following
259 * 1. disable BT
260 * 2. if all BT Tx/Rx counter = 0, after 6 sec we query bt info
261 * 3. Because BT will not rsp from mailbox, so wifi fw will know BT is
262 * disabled
263 *
264 * 4. FW will rsp c2h for BT that driver will know BT is disabled.
265 */
266 if ((reg_hp_tx == 0) && (reg_hp_rx == 0) && (reg_lp_tx == 0) &&
267 (reg_lp_rx == 0)) {
268 num_of_bt_counter_chk++;
269 if (num_of_bt_counter_chk == 3)
270 halbtc8723b1ant_query_bt_info(btcoexist);
271 } else {
272 num_of_bt_counter_chk = 0;
273 }
274 }
275
276 static void halbtc8723b1ant_monitor_wifi_ctr(struct btc_coexist *btcoexist)
277 {
278 s32 wifi_rssi = 0;
279 bool wifi_busy = false, wifi_under_b_mode = false;
280 static u8 cck_lock_counter;
281 u32 total_cnt;
282
283 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
284 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
285 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
286 &wifi_under_b_mode);
287
288 if (coex_sta->under_ips) {
289 coex_sta->crc_ok_cck = 0;
290 coex_sta->crc_ok_11g = 0;
291 coex_sta->crc_ok_11n = 0;
292 coex_sta->crc_ok_11n_agg = 0;
293
294 coex_sta->crc_err_cck = 0;
295 coex_sta->crc_err_11g = 0;
296 coex_sta->crc_err_11n = 0;
297 coex_sta->crc_err_11n_agg = 0;
298 } else {
299 coex_sta->crc_ok_cck =
300 btcoexist->btc_read_4byte(btcoexist, 0xf88);
301 coex_sta->crc_ok_11g =
302 btcoexist->btc_read_2byte(btcoexist, 0xf94);
303 coex_sta->crc_ok_11n =
304 btcoexist->btc_read_2byte(btcoexist, 0xf90);
305 coex_sta->crc_ok_11n_agg =
306 btcoexist->btc_read_2byte(btcoexist, 0xfb8);
307
308 coex_sta->crc_err_cck =
309 btcoexist->btc_read_4byte(btcoexist, 0xf84);
310 coex_sta->crc_err_11g =
311 btcoexist->btc_read_2byte(btcoexist, 0xf96);
312 coex_sta->crc_err_11n =
313 btcoexist->btc_read_2byte(btcoexist, 0xf92);
314 coex_sta->crc_err_11n_agg =
315 btcoexist->btc_read_2byte(btcoexist, 0xfba);
316 }
317
318 /* reset counter */
319 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x1);
320 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x0);
321
322 if ((wifi_busy) && (wifi_rssi >= 30) && (!wifi_under_b_mode)) {
323 total_cnt = coex_sta->crc_ok_cck + coex_sta->crc_ok_11g +
324 coex_sta->crc_ok_11n + coex_sta->crc_ok_11n_agg;
325
326 if ((coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) ||
327 (coex_dm->bt_status ==
328 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
329 (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_SCO_BUSY)) {
330 if (coex_sta->crc_ok_cck >
331 (total_cnt - coex_sta->crc_ok_cck)) {
332 if (cck_lock_counter < 3)
333 cck_lock_counter++;
334 } else {
335 if (cck_lock_counter > 0)
336 cck_lock_counter--;
337 }
338
339 } else {
340 if (cck_lock_counter > 0)
341 cck_lock_counter--;
342 }
343 } else {
344 if (cck_lock_counter > 0)
345 cck_lock_counter--;
346 }
347
348 if (!coex_sta->pre_ccklock) {
349 if (cck_lock_counter >= 3)
350 coex_sta->cck_lock = true;
351 else
352 coex_sta->cck_lock = false;
353 } else {
354 if (cck_lock_counter == 0)
355 coex_sta->cck_lock = false;
356 else
357 coex_sta->cck_lock = true;
358 }
359
360 if (coex_sta->cck_lock)
361 coex_sta->cck_ever_lock = true;
362
363 coex_sta->pre_ccklock = coex_sta->cck_lock;
364 }
365
366 static bool btc8723b1ant_is_wifi_status_changed(struct btc_coexist *btcoexist)
367 {
368 static bool pre_wifi_busy;
369 static bool pre_under_4way, pre_bt_hs_on;
370 bool wifi_busy = false, under_4way = false, bt_hs_on = false;
371 bool wifi_connected = false;
372
373 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
374 &wifi_connected);
375 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
376 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
377 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
378 &under_4way);
379
380 if (wifi_connected) {
381 if (wifi_busy != pre_wifi_busy) {
382 pre_wifi_busy = wifi_busy;
383 return true;
384 }
385 if (under_4way != pre_under_4way) {
386 pre_under_4way = under_4way;
387 return true;
388 }
389 if (bt_hs_on != pre_bt_hs_on) {
390 pre_bt_hs_on = bt_hs_on;
391 return true;
392 }
393 }
394
395 return false;
396 }
397
398 static void halbtc8723b1ant_update_bt_link_info(struct btc_coexist *btcoexist)
399 {
400 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
401 bool bt_hs_on = false;
402
403 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
404
405 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
406 bt_link_info->sco_exist = coex_sta->sco_exist;
407 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
408 bt_link_info->pan_exist = coex_sta->pan_exist;
409 bt_link_info->hid_exist = coex_sta->hid_exist;
410 bt_link_info->bt_hi_pri_link_exist = coex_sta->bt_hi_pri_link_exist;
411
412 /* work around for HS mode. */
413 if (bt_hs_on) {
414 bt_link_info->pan_exist = true;
415 bt_link_info->bt_link_exist = true;
416 }
417
418 /* check if Sco only */
419 if (bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
420 !bt_link_info->pan_exist && !bt_link_info->hid_exist)
421 bt_link_info->sco_only = true;
422 else
423 bt_link_info->sco_only = false;
424
425 /* check if A2dp only */
426 if (!bt_link_info->sco_exist && bt_link_info->a2dp_exist &&
427 !bt_link_info->pan_exist && !bt_link_info->hid_exist)
428 bt_link_info->a2dp_only = true;
429 else
430 bt_link_info->a2dp_only = false;
431
432 /* check if Pan only */
433 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
434 bt_link_info->pan_exist && !bt_link_info->hid_exist)
435 bt_link_info->pan_only = true;
436 else
437 bt_link_info->pan_only = false;
438
439 /* check if Hid only */
440 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist &&
441 !bt_link_info->pan_exist && bt_link_info->hid_exist)
442 bt_link_info->hid_only = true;
443 else
444 bt_link_info->hid_only = false;
445 }
446
447 static void halbtc8723b1ant_set_bt_auto_report(struct btc_coexist *btcoexist,
448 bool enable_auto_report)
449 {
450 u8 h2c_parameter[1] = {0};
451
452 h2c_parameter[0] = 0;
453
454 if (enable_auto_report)
455 h2c_parameter[0] |= BIT(0);
456
457 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter);
458 }
459
460 static void halbtc8723b1ant_bt_auto_report(struct btc_coexist *btcoexist,
461 bool force_exec,
462 bool enable_auto_report)
463 {
464 coex_dm->cur_bt_auto_report = enable_auto_report;
465
466 if (!force_exec) {
467 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report)
468 return;
469 }
470 halbtc8723b1ant_set_bt_auto_report(btcoexist,
471 coex_dm->cur_bt_auto_report);
472
473 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report;
474 }
475
476 static void btc8723b1ant_set_sw_pen_tx_rate_adapt(struct btc_coexist *btcoexist,
477 bool low_penalty_ra)
478 {
479 struct rtl_priv *rtlpriv = btcoexist->adapter;
480 u8 h2c_parameter[6] = {0};
481
482 h2c_parameter[0] = 0x6; /* opCode, 0x6= Retry_Penalty */
483
484 if (low_penalty_ra) {
485 h2c_parameter[1] |= BIT0;
486 /* normal rate except MCS7/6/5, OFDM54/48/36 */
487 h2c_parameter[2] = 0x00;
488 h2c_parameter[3] = 0xf7; /* MCS7 or OFDM54 */
489 h2c_parameter[4] = 0xf8; /* MCS6 or OFDM48 */
490 h2c_parameter[5] = 0xf9; /* MCS5 or OFDM36 */
491 }
492
493 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
494 "[BTCoex], set WiFi Low-Penalty Retry: %s",
495 (low_penalty_ra ? "ON!!" : "OFF!!"));
496
497 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter);
498 }
499
500 static void halbtc8723b1ant_low_penalty_ra(struct btc_coexist *btcoexist,
501 bool force_exec, bool low_penalty_ra)
502 {
503 coex_dm->cur_low_penalty_ra = low_penalty_ra;
504
505 if (!force_exec) {
506 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra)
507 return;
508 }
509 btc8723b1ant_set_sw_pen_tx_rate_adapt(btcoexist,
510 coex_dm->cur_low_penalty_ra);
511
512 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra;
513 }
514
515 static void halbtc8723b1ant_set_coex_table(struct btc_coexist *btcoexist,
516 u32 val0x6c0, u32 val0x6c4,
517 u32 val0x6c8, u8 val0x6cc)
518 {
519 struct rtl_priv *rtlpriv = btcoexist->adapter;
520
521 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
522 "[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0);
523 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0);
524
525 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
526 "[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4);
527 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4);
528
529 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
530 "[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8);
531 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8);
532
533 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
534 "[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc);
535 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc);
536 }
537
538 static void halbtc8723b1ant_coex_table(struct btc_coexist *btcoexist,
539 bool force_exec, u32 val0x6c0,
540 u32 val0x6c4, u32 val0x6c8,
541 u8 val0x6cc)
542 {
543 struct rtl_priv *rtlpriv = btcoexist->adapter;
544
545 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
546 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6cc = 0x%x\n",
547 (force_exec ? "force to" : ""),
548 val0x6c0, val0x6c4, val0x6cc);
549 coex_dm->cur_val0x6c0 = val0x6c0;
550 coex_dm->cur_val0x6c4 = val0x6c4;
551 coex_dm->cur_val0x6c8 = val0x6c8;
552 coex_dm->cur_val0x6cc = val0x6cc;
553
554 if (!force_exec) {
555 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) &&
556 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) &&
557 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) &&
558 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc))
559 return;
560 }
561 halbtc8723b1ant_set_coex_table(btcoexist, val0x6c0, val0x6c4,
562 val0x6c8, val0x6cc);
563
564 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0;
565 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4;
566 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8;
567 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc;
568 }
569
570 static void halbtc8723b1ant_coex_table_with_type(struct btc_coexist *btcoexist,
571 bool force_exec, u8 type)
572 {
573 coex_sta->coex_table_type = type;
574
575 switch (type) {
576 case 0:
577 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
578 0x55555555, 0xffffff, 0x3);
579 break;
580 case 1:
581 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
582 0x5a5a5a5a, 0xffffff, 0x3);
583 break;
584 case 2:
585 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
586 0x5a5a5a5a, 0xffffff, 0x3);
587 break;
588 case 3:
589 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
590 0xaaaaaaaa, 0xffffff, 0x3);
591 break;
592 case 4:
593 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
594 0x5aaa5aaa, 0xffffff, 0x3);
595 break;
596 case 5:
597 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x5a5a5a5a,
598 0xaaaa5a5a, 0xffffff, 0x3);
599 break;
600 case 6:
601 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0x55555555,
602 0xaaaa5a5a, 0xffffff, 0x3);
603 break;
604 case 7:
605 halbtc8723b1ant_coex_table(btcoexist, force_exec, 0xaaaaaaaa,
606 0xaaaaaaaa, 0xffffff, 0x3);
607 break;
608 default:
609 break;
610 }
611 }
612
613 static void
614 halbtc8723b1ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist,
615 bool enable)
616 {
617 struct rtl_priv *rtlpriv = btcoexist->adapter;
618 u8 h2c_parameter[1] = {0};
619
620 if (enable)
621 h2c_parameter[0] |= BIT0; /* function enable */
622
623 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
624 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
625 h2c_parameter[0]);
626
627 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter);
628 }
629
630 static void halbtc8723b1ant_ignore_wlan_act(struct btc_coexist *btcoexist,
631 bool force_exec, bool enable)
632 {
633 struct rtl_priv *rtlpriv = btcoexist->adapter;
634
635 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
636 "[BTCoex], %s turn Ignore WlanAct %s\n",
637 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF"));
638 coex_dm->cur_ignore_wlan_act = enable;
639
640 if (!force_exec) {
641 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
642 "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
643 coex_dm->pre_ignore_wlan_act,
644 coex_dm->cur_ignore_wlan_act);
645
646 if (coex_dm->pre_ignore_wlan_act ==
647 coex_dm->cur_ignore_wlan_act)
648 return;
649 }
650 halbtc8723b1ant_set_fw_ignore_wlan_act(btcoexist, enable);
651
652 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act;
653 }
654
655 static void halbtc8723b1ant_set_fw_ps_tdma(struct btc_coexist *btcoexist,
656 u8 byte1, u8 byte2, u8 byte3,
657 u8 byte4, u8 byte5)
658 {
659 struct rtl_priv *rtlpriv = btcoexist->adapter;
660 u8 h2c_parameter[5] = {0};
661 u8 real_byte1 = byte1, real_byte5 = byte5;
662 bool ap_enable = false;
663
664 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
665 &ap_enable);
666
667 if (ap_enable) {
668 if ((byte1 & BIT4) && !(byte1 & BIT5)) {
669 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
670 "[BTCoex], FW for 1Ant AP mode\n");
671 real_byte1 &= ~BIT4;
672 real_byte1 |= BIT5;
673
674 real_byte5 |= BIT5;
675 real_byte5 &= ~BIT6;
676 }
677 }
678
679 h2c_parameter[0] = real_byte1;
680 h2c_parameter[1] = byte2;
681 h2c_parameter[2] = byte3;
682 h2c_parameter[3] = byte4;
683 h2c_parameter[4] = real_byte5;
684
685 coex_dm->ps_tdma_para[0] = real_byte1;
686 coex_dm->ps_tdma_para[1] = byte2;
687 coex_dm->ps_tdma_para[2] = byte3;
688 coex_dm->ps_tdma_para[3] = byte4;
689 coex_dm->ps_tdma_para[4] = real_byte5;
690
691 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
692 "[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
693 h2c_parameter[0],
694 h2c_parameter[1] << 24 |
695 h2c_parameter[2] << 16 |
696 h2c_parameter[3] << 8 |
697 h2c_parameter[4]);
698
699 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter);
700 }
701
702 static void halbtc8723b1ant_set_lps_rpwm(struct btc_coexist *btcoexist,
703 u8 lps_val, u8 rpwm_val)
704 {
705 u8 lps = lps_val;
706 u8 rpwm = rpwm_val;
707
708 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps);
709 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
710 }
711
712 static void halbtc8723b1ant_lps_rpwm(struct btc_coexist *btcoexist,
713 bool force_exec,
714 u8 lps_val, u8 rpwm_val)
715 {
716 struct rtl_priv *rtlpriv = btcoexist->adapter;
717
718 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
719 "[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
720 (force_exec ? "force to" : ""), lps_val, rpwm_val);
721 coex_dm->cur_lps = lps_val;
722 coex_dm->cur_rpwm = rpwm_val;
723
724 if (!force_exec) {
725 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
726 "[BTCoex], LPS-RxBeaconMode = 0x%x , LPS-RPWM = 0x%x!!\n",
727 coex_dm->cur_lps, coex_dm->cur_rpwm);
728
729 if ((coex_dm->pre_lps == coex_dm->cur_lps) &&
730 (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) {
731 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
732 "[BTCoex], LPS-RPWM_Last = 0x%x , LPS-RPWM_Now = 0x%x!!\n",
733 coex_dm->pre_rpwm, coex_dm->cur_rpwm);
734
735 return;
736 }
737 }
738 halbtc8723b1ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val);
739
740 coex_dm->pre_lps = coex_dm->cur_lps;
741 coex_dm->pre_rpwm = coex_dm->cur_rpwm;
742 }
743
744 static void halbtc8723b1ant_sw_mechanism(struct btc_coexist *btcoexist,
745 bool low_penalty_ra)
746 {
747 struct rtl_priv *rtlpriv = btcoexist->adapter;
748
749 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
750 "[BTCoex], SM[LpRA] = %d\n", low_penalty_ra);
751
752 halbtc8723b1ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra);
753 }
754
755 static void halbtc8723b1ant_set_ant_path(struct btc_coexist *btcoexist,
756 u8 ant_pos_type, bool force_exec,
757 bool init_hw_cfg, bool wifi_off)
758 {
759 struct rtl_priv *rtlpriv = btcoexist->adapter;
760 struct btc_board_info *board_info = &btcoexist->board_info;
761 u32 fw_ver = 0, u32tmp = 0, cnt_bt_cal_chk = 0;
762 bool pg_ext_switch = false;
763 bool use_ext_switch = false;
764 bool is_in_mp_mode = false;
765 u8 h2c_parameter[2] = {0}, u8tmp = 0;
766
767 coex_dm->cur_ant_pos_type = ant_pos_type;
768
769 btcoexist->btc_get(btcoexist, BTC_GET_BL_EXT_SWITCH, &pg_ext_switch);
770 /* [31:16] = fw ver, [15:0] = fw sub ver */
771 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
772
773 if ((fw_ver < 0xc0000) || pg_ext_switch)
774 use_ext_switch = true;
775
776 if (init_hw_cfg) {
777 /* WiFi TRx Mask on */
778 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff,
779 0x780);
780 /* remove due to interrupt is disabled that polling c2h will
781 * fail and delay 100ms.
782 */
783
784 if (fw_ver >= 0x180000) {
785 /* Use H2C to set GNT_BT to HIGH */
786 h2c_parameter[0] = 1;
787 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1,
788 h2c_parameter);
789 } else {
790 /* set grant_bt to high */
791 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18);
792 }
793 /* set wlan_act control by PTA */
794 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
795
796 /* BT select s0/s1 is controlled by BT */
797 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x0);
798 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x39, 0x8, 0x1);
799 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff);
800 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x944, 0x3, 0x3);
801 btcoexist->btc_write_1byte(btcoexist, 0x930, 0x77);
802 } else if (wifi_off) {
803 if (fw_ver >= 0x180000) {
804 /* Use H2C to set GNT_BT to HIGH */
805 h2c_parameter[0] = 1;
806 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1,
807 h2c_parameter);
808 } else {
809 /* set grant_bt to high */
810 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18);
811 }
812 /* set wlan_act to always low */
813 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
814
815 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE,
816 &is_in_mp_mode);
817 if (!is_in_mp_mode)
818 /* BT select s0/s1 is controlled by BT */
819 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67,
820 0x20, 0x0);
821 else
822 /* BT select s0/s1 is controlled by WiFi */
823 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67,
824 0x20, 0x1);
825
826 /* 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL
827 * BT Vendor 0xac=0xf002
828 */
829 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
830 u32tmp &= ~BIT23;
831 u32tmp &= ~BIT24;
832 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
833 } else {
834 /* Use H2C to set GNT_BT to LOW */
835 if (fw_ver >= 0x180000) {
836 if (btcoexist->btc_read_1byte(btcoexist, 0x765) != 0) {
837 h2c_parameter[0] = 0;
838 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1,
839 h2c_parameter);
840 }
841 } else {
842 /* BT calibration check */
843 while (cnt_bt_cal_chk <= 20) {
844 u8tmp = btcoexist->btc_read_1byte(btcoexist,
845 0x49d);
846 cnt_bt_cal_chk++;
847 if (u8tmp & BIT(0)) {
848 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
849 DBG_LOUD,
850 "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n",
851 cnt_bt_cal_chk);
852 mdelay(50);
853 } else {
854 RT_TRACE(rtlpriv, COMP_BT_COEXIST,
855 DBG_LOUD,
856 "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n",
857 cnt_bt_cal_chk);
858 break;
859 }
860 }
861
862 /* set grant_bt to PTA */
863 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x0);
864 }
865
866 if (btcoexist->btc_read_1byte(btcoexist, 0x76e) != 0xc) {
867 /* set wlan_act control by PTA */
868 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc);
869 }
870
871 btcoexist->btc_write_1byte_bitmask(
872 btcoexist, 0x67, 0x20,
873 0x1); /* BT select s0/s1 is controlled by WiFi */
874 }
875
876 if (use_ext_switch) {
877 if (init_hw_cfg) {
878 /* 0x4c[23] = 0, 0x4c[24] = 1
879 * Antenna control by WL/BT
880 */
881 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
882 u32tmp &= ~BIT23;
883 u32tmp |= BIT24;
884 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
885
886 /* fixed internal switch S1->WiFi, S0->BT */
887 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0);
888
889 if (board_info->btdm_ant_pos ==
890 BTC_ANTENNA_AT_MAIN_PORT) {
891 /* tell firmware "no antenna inverse" */
892 h2c_parameter[0] = 0;
893 /* ext switch type */
894 h2c_parameter[1] = 1;
895 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
896 h2c_parameter);
897 } else {
898 /* tell firmware "antenna inverse" */
899 h2c_parameter[0] = 1;
900 /* ext switch type */
901 h2c_parameter[1] = 1;
902 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
903 h2c_parameter);
904 }
905 }
906
907 if (force_exec ||
908 (coex_dm->cur_ant_pos_type != coex_dm->pre_ant_pos_type)) {
909 /* ext switch setting */
910 switch (ant_pos_type) {
911 case BTC_ANT_PATH_WIFI:
912 if (board_info->btdm_ant_pos ==
913 BTC_ANTENNA_AT_MAIN_PORT)
914 btcoexist->btc_write_1byte_bitmask(
915 btcoexist, 0x92c, 0x3, 0x1);
916 else
917 btcoexist->btc_write_1byte_bitmask(
918 btcoexist, 0x92c, 0x3, 0x2);
919 break;
920 case BTC_ANT_PATH_BT:
921 if (board_info->btdm_ant_pos ==
922 BTC_ANTENNA_AT_MAIN_PORT)
923 btcoexist->btc_write_1byte_bitmask(
924 btcoexist, 0x92c, 0x3, 0x2);
925 else
926 btcoexist->btc_write_1byte_bitmask(
927 btcoexist, 0x92c, 0x3, 0x1);
928 break;
929 default:
930 case BTC_ANT_PATH_PTA:
931 if (board_info->btdm_ant_pos ==
932 BTC_ANTENNA_AT_MAIN_PORT)
933 btcoexist->btc_write_1byte_bitmask(
934 btcoexist, 0x92c, 0x3, 0x1);
935 else
936 btcoexist->btc_write_1byte_bitmask(
937 btcoexist, 0x92c, 0x3, 0x2);
938 break;
939 }
940 }
941 } else {
942 if (init_hw_cfg) {
943 /* 0x4c[23] = 1, 0x4c[24] = 0,
944 * Antenna control by 0x64
945 */
946 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c);
947 u32tmp |= BIT23;
948 u32tmp &= ~BIT24;
949 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp);
950
951 /* Fix Ext switch Main->S1, Aux->S0 */
952 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1,
953 0x0);
954
955 if (board_info->btdm_ant_pos ==
956 BTC_ANTENNA_AT_MAIN_PORT) {
957 /* tell firmware "no antenna inverse" */
958 h2c_parameter[0] = 0;
959 /* internal switch type */
960 h2c_parameter[1] = 0;
961 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
962 h2c_parameter);
963 } else {
964 /* tell firmware "antenna inverse" */
965 h2c_parameter[0] = 1;
966 /* internal switch type */
967 h2c_parameter[1] = 0;
968 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2,
969 h2c_parameter);
970 }
971 }
972
973 if (force_exec ||
974 (coex_dm->cur_ant_pos_type != coex_dm->pre_ant_pos_type)) {
975 /* internal switch setting */
976 switch (ant_pos_type) {
977 case BTC_ANT_PATH_WIFI:
978 if (board_info->btdm_ant_pos ==
979 BTC_ANTENNA_AT_MAIN_PORT)
980 btcoexist->btc_write_4byte(btcoexist,
981 0x948, 0x0);
982 else
983 btcoexist->btc_write_4byte(btcoexist,
984 0x948, 0x280);
985 break;
986 case BTC_ANT_PATH_BT:
987 if (board_info->btdm_ant_pos ==
988 BTC_ANTENNA_AT_MAIN_PORT)
989 btcoexist->btc_write_4byte(btcoexist,
990 0x948, 0x280);
991 else
992 btcoexist->btc_write_4byte(btcoexist,
993 0x948, 0x0);
994 break;
995 default:
996 case BTC_ANT_PATH_PTA:
997 if (board_info->btdm_ant_pos ==
998 BTC_ANTENNA_AT_MAIN_PORT)
999 btcoexist->btc_write_4byte(btcoexist,
1000 0x948, 0x200);
1001 else
1002 btcoexist->btc_write_4byte(btcoexist,
1003 0x948, 0x80);
1004 break;
1005 }
1006 }
1007 }
1008
1009 coex_dm->pre_ant_pos_type = coex_dm->cur_ant_pos_type;
1010 }
1011
1012 static void halbtc8723b1ant_ps_tdma(struct btc_coexist *btcoexist,
1013 bool force_exec, bool turn_on, u8 type)
1014 {
1015 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1016 bool wifi_busy = false;
1017 u8 rssi_adjust_val = 0;
1018 u8 ps_tdma_byte0_val = 0x51;
1019 u8 ps_tdma_byte3_val = 0x10;
1020 u8 ps_tdma_byte4_val = 0x50;
1021 s8 wifi_duration_adjust = 0x0;
1022 static bool pre_wifi_busy;
1023
1024 coex_dm->cur_ps_tdma_on = turn_on;
1025 coex_dm->cur_ps_tdma = type;
1026
1027 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1028
1029 if (wifi_busy != pre_wifi_busy) {
1030 force_exec = true;
1031 pre_wifi_busy = wifi_busy;
1032 }
1033
1034 if (!force_exec) {
1035 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) &&
1036 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma))
1037 return;
1038 }
1039
1040 if (coex_sta->scan_ap_num <= 5) {
1041 wifi_duration_adjust = 5;
1042
1043 if (coex_sta->a2dp_bit_pool >= 35)
1044 wifi_duration_adjust = -10;
1045 else if (coex_sta->a2dp_bit_pool >= 45)
1046 wifi_duration_adjust = -15;
1047 } else if (coex_sta->scan_ap_num >= 40) {
1048 wifi_duration_adjust = -15;
1049
1050 if (coex_sta->a2dp_bit_pool < 35)
1051 wifi_duration_adjust = -5;
1052 else if (coex_sta->a2dp_bit_pool < 45)
1053 wifi_duration_adjust = -10;
1054 } else if (coex_sta->scan_ap_num >= 20) {
1055 wifi_duration_adjust = -10;
1056
1057 if (coex_sta->a2dp_bit_pool >= 45)
1058 wifi_duration_adjust = -15;
1059 } else {
1060 wifi_duration_adjust = 0;
1061
1062 if (coex_sta->a2dp_bit_pool >= 35)
1063 wifi_duration_adjust = -10;
1064 else if (coex_sta->a2dp_bit_pool >= 45)
1065 wifi_duration_adjust = -15;
1066 }
1067
1068 if ((type == 1) || (type == 2) || (type == 9) || (type == 11) ||
1069 (type == 101) || (type == 102) || (type == 109) || (type == 101)) {
1070 if (!coex_sta->force_lps_on) {
1071 /* Native power save TDMA, only for A2DP-only case
1072 * 1/2/9/11 while wifi noisy threshold > 30
1073 */
1074
1075 /* no null-pkt */
1076 ps_tdma_byte0_val = 0x61;
1077 /* no tx-pause at BT-slot */
1078 ps_tdma_byte3_val = 0x11;
1079 /* 0x778 = d/1 toggle, no dynamic slot */
1080 ps_tdma_byte4_val = 0x10;
1081 } else {
1082 /* null-pkt */
1083 ps_tdma_byte0_val = 0x51;
1084 /* tx-pause at BT-slot */
1085 ps_tdma_byte3_val = 0x10;
1086 /* 0x778 = d/1 toggle, dynamic slot */
1087 ps_tdma_byte4_val = 0x50;
1088 }
1089 } else if ((type == 3) || (type == 13) || (type == 14) ||
1090 (type == 103) || (type == 113) || (type == 114)) {
1091 /* null-pkt */
1092 ps_tdma_byte0_val = 0x51;
1093 /* tx-pause at BT-slot */
1094 ps_tdma_byte3_val = 0x10;
1095 /* 0x778 = d/1 toggle, no dynamic slot */
1096 ps_tdma_byte4_val = 0x10;
1097 } else { /* native power save case */
1098 /* no null-pkt */
1099 ps_tdma_byte0_val = 0x61;
1100 /* no tx-pause at BT-slot */
1101 ps_tdma_byte3_val = 0x11;
1102 /* 0x778 = d/1 toggle, no dynamic slot */
1103 ps_tdma_byte4_val = 0x11;
1104 /* psTdmaByte4Va is not define for 0x778 = d/1, 1/1 case */
1105 }
1106
1107 /* if (bt_link_info->slave_role) */
1108 if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist))
1109 /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1110 ps_tdma_byte4_val = ps_tdma_byte4_val | 0x1;
1111
1112 if (type > 100) {
1113 /* set antenna control by SW */
1114 ps_tdma_byte0_val = ps_tdma_byte0_val | 0x82;
1115 /* set antenna no toggle, control by antenna diversity */
1116 ps_tdma_byte3_val = ps_tdma_byte3_val | 0x60;
1117 }
1118
1119 if (turn_on) {
1120 switch (type) {
1121 default:
1122 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x1a,
1123 0x1a, 0x0,
1124 ps_tdma_byte4_val);
1125 break;
1126 case 1:
1127 halbtc8723b1ant_set_fw_ps_tdma(
1128 btcoexist, ps_tdma_byte0_val,
1129 0x3a + wifi_duration_adjust, 0x03,
1130 ps_tdma_byte3_val, ps_tdma_byte4_val);
1131
1132 rssi_adjust_val = 11;
1133 break;
1134 case 2:
1135 halbtc8723b1ant_set_fw_ps_tdma(
1136 btcoexist, ps_tdma_byte0_val,
1137 0x2d + wifi_duration_adjust, 0x03,
1138 ps_tdma_byte3_val, ps_tdma_byte4_val);
1139 break;
1140 case 3:
1141 halbtc8723b1ant_set_fw_ps_tdma(
1142 btcoexist, ps_tdma_byte0_val, 0x30, 0x03,
1143 ps_tdma_byte3_val, ps_tdma_byte4_val);
1144 break;
1145 case 4:
1146 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15,
1147 0x3, 0x14, 0x0);
1148 break;
1149 case 5:
1150 halbtc8723b1ant_set_fw_ps_tdma(
1151 btcoexist, ps_tdma_byte0_val, 0x1f, 0x3,
1152 ps_tdma_byte3_val, 0x11);
1153 break;
1154 case 6:
1155 halbtc8723b1ant_set_fw_ps_tdma(
1156 btcoexist, ps_tdma_byte0_val, 0x20, 0x3,
1157 ps_tdma_byte3_val, 0x11);
1158 break;
1159 case 7:
1160 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xc,
1161 0x5, 0x0, 0x0);
1162 break;
1163 case 8:
1164 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25,
1165 0x3, 0x10, 0x0);
1166 break;
1167 case 9:
1168 halbtc8723b1ant_set_fw_ps_tdma(
1169 btcoexist, ps_tdma_byte0_val, 0x21, 0x3,
1170 ps_tdma_byte3_val, ps_tdma_byte4_val);
1171 break;
1172 case 10:
1173 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
1174 0xa, 0x0, 0x40);
1175 break;
1176 case 11:
1177 halbtc8723b1ant_set_fw_ps_tdma(
1178 btcoexist, ps_tdma_byte0_val, 0x21, 0x03,
1179 ps_tdma_byte3_val, ps_tdma_byte4_val);
1180 break;
1181 case 12:
1182 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x0a,
1183 0x0a, 0x0, 0x50);
1184 break;
1185 case 13:
1186 if (coex_sta->scan_ap_num <= 3)
1187 halbtc8723b1ant_set_fw_ps_tdma(
1188 btcoexist, ps_tdma_byte0_val, 0x40, 0x3,
1189 ps_tdma_byte3_val, ps_tdma_byte4_val);
1190 else
1191 halbtc8723b1ant_set_fw_ps_tdma(
1192 btcoexist, ps_tdma_byte0_val, 0x21, 0x3,
1193 ps_tdma_byte3_val, ps_tdma_byte4_val);
1194 break;
1195 case 14:
1196 if (coex_sta->scan_ap_num <= 3)
1197 halbtc8723b1ant_set_fw_ps_tdma(
1198 btcoexist, 0x51, 0x30, 0x3, 0x10, 0x50);
1199 else
1200 halbtc8723b1ant_set_fw_ps_tdma(
1201 btcoexist, ps_tdma_byte0_val, 0x21, 0x3,
1202 ps_tdma_byte3_val, ps_tdma_byte4_val);
1203 break;
1204 case 15:
1205 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x13, 0xa,
1206 0x3, 0x8, 0x0);
1207 break;
1208 case 16:
1209 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x15,
1210 0x3, 0x10, 0x0);
1211 break;
1212 case 18:
1213 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x93, 0x25,
1214 0x3, 0x10, 0x0);
1215 break;
1216 case 20:
1217 halbtc8723b1ant_set_fw_ps_tdma(
1218 btcoexist, ps_tdma_byte0_val, 0x3f, 0x03,
1219 ps_tdma_byte3_val, 0x10);
1220 break;
1221 case 21:
1222 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x61, 0x25,
1223 0x03, 0x11, 0x11);
1224 break;
1225 case 22:
1226 halbtc8723b1ant_set_fw_ps_tdma(
1227 btcoexist, ps_tdma_byte0_val, 0x25, 0x03,
1228 ps_tdma_byte3_val, 0x10);
1229 break;
1230 case 23:
1231 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
1232 0x3, 0x31, 0x18);
1233 break;
1234 case 24:
1235 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15,
1236 0x3, 0x31, 0x18);
1237 break;
1238 case 25:
1239 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
1240 0x3, 0x31, 0x18);
1241 break;
1242 case 26:
1243 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0xa,
1244 0x3, 0x31, 0x18);
1245 break;
1246 case 27:
1247 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25,
1248 0x3, 0x31, 0x98);
1249 break;
1250 case 28:
1251 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x69, 0x25,
1252 0x3, 0x31, 0x0);
1253 break;
1254 case 29:
1255 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xab, 0x1a,
1256 0x1a, 0x1, 0x10);
1257 break;
1258 case 30:
1259 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x51, 0x30,
1260 0x3, 0x10, 0x10);
1261 break;
1262 case 31:
1263 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x1a,
1264 0x1a, 0, 0x58);
1265 break;
1266 case 32:
1267 halbtc8723b1ant_set_fw_ps_tdma(
1268 btcoexist, ps_tdma_byte0_val, 0x35, 0x3,
1269 ps_tdma_byte3_val, ps_tdma_byte4_val);
1270 break;
1271 case 33:
1272 halbtc8723b1ant_set_fw_ps_tdma(
1273 btcoexist, ps_tdma_byte0_val, 0x35, 0x3,
1274 ps_tdma_byte3_val, 0x10);
1275 break;
1276 case 34:
1277 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x53, 0x1a,
1278 0x1a, 0x0, 0x10);
1279 break;
1280 case 35:
1281 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x63, 0x1a,
1282 0x1a, 0x0, 0x10);
1283 break;
1284 case 36:
1285 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x12,
1286 0x3, 0x14, 0x50);
1287 break;
1288 case 40:
1289 /* SoftAP only with no sta associated,BT disable ,TDMA
1290 * mode for power saving
1291 *
1292 * here softap mode screen off will cost 70-80mA for
1293 * phone
1294 */
1295 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x23, 0x18,
1296 0x00, 0x10, 0x24);
1297 break;
1298
1299 case 101:
1300 /* for 1-Ant translate to 2-Ant */
1301 halbtc8723b1ant_set_fw_ps_tdma(
1302 btcoexist, ps_tdma_byte0_val,
1303 0x3a + wifi_duration_adjust, 0x03,
1304 ps_tdma_byte3_val, ps_tdma_byte4_val);
1305 break;
1306 case 102:
1307 halbtc8723b1ant_set_fw_ps_tdma(
1308 btcoexist, ps_tdma_byte0_val,
1309 0x2d + wifi_duration_adjust, 0x03,
1310 ps_tdma_byte3_val, ps_tdma_byte4_val);
1311 break;
1312 case 103:
1313 halbtc8723b1ant_set_fw_ps_tdma(
1314 btcoexist, ps_tdma_byte0_val, 0x3a, 0x03,
1315 ps_tdma_byte3_val, ps_tdma_byte4_val);
1316 break;
1317 case 105:
1318 halbtc8723b1ant_set_fw_ps_tdma(
1319 btcoexist, ps_tdma_byte0_val, 0x15, 0x3,
1320 ps_tdma_byte3_val, 0x11);
1321 break;
1322 case 106:
1323 halbtc8723b1ant_set_fw_ps_tdma(
1324 btcoexist, ps_tdma_byte0_val, 0x20, 0x3,
1325 ps_tdma_byte3_val, 0x11);
1326 break;
1327 case 109:
1328 halbtc8723b1ant_set_fw_ps_tdma(
1329 btcoexist, ps_tdma_byte0_val, 0x21, 0x3,
1330 ps_tdma_byte3_val, ps_tdma_byte4_val);
1331 break;
1332 case 111:
1333 halbtc8723b1ant_set_fw_ps_tdma(
1334 btcoexist, ps_tdma_byte0_val, 0x21, 0x03,
1335 ps_tdma_byte3_val, ps_tdma_byte4_val);
1336 break;
1337 case 113:
1338 halbtc8723b1ant_set_fw_ps_tdma(
1339 btcoexist, ps_tdma_byte0_val, 0x21, 0x3,
1340 ps_tdma_byte3_val, ps_tdma_byte4_val);
1341 break;
1342 case 114:
1343 halbtc8723b1ant_set_fw_ps_tdma(
1344 btcoexist, ps_tdma_byte0_val, 0x21, 0x3,
1345 ps_tdma_byte3_val, ps_tdma_byte4_val);
1346 break;
1347 case 120:
1348 halbtc8723b1ant_set_fw_ps_tdma(
1349 btcoexist, ps_tdma_byte0_val, 0x3f, 0x03,
1350 ps_tdma_byte3_val, 0x10);
1351 break;
1352 case 122:
1353 halbtc8723b1ant_set_fw_ps_tdma(
1354 btcoexist, ps_tdma_byte0_val, 0x25, 0x03,
1355 ps_tdma_byte3_val, 0x10);
1356 break;
1357 case 132:
1358 halbtc8723b1ant_set_fw_ps_tdma(
1359 btcoexist, ps_tdma_byte0_val, 0x25, 0x03,
1360 ps_tdma_byte3_val, ps_tdma_byte4_val);
1361 break;
1362 case 133:
1363 halbtc8723b1ant_set_fw_ps_tdma(
1364 btcoexist, ps_tdma_byte0_val, 0x25, 0x03,
1365 ps_tdma_byte3_val, 0x11);
1366 break;
1367 }
1368 } else {
1369 /* disable PS tdma */
1370 switch (type) {
1371 case 8: /* PTA Control */
1372 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x8, 0x0,
1373 0x0, 0x0, 0x0);
1374 halbtc8723b1ant_set_ant_path(btcoexist,
1375 BTC_ANT_PATH_PTA,
1376 FORCE_EXEC,
1377 false, false);
1378 break;
1379 case 0:
1380 default:
1381 /* Software control, Antenna at BT side */
1382 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0,
1383 0x0, 0x0, 0x0);
1384 break;
1385 case 1: /* 2-Ant, 0x778=3, antenna control by ant diversity */
1386 halbtc8723b1ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0,
1387 0x48, 0x0);
1388 break;
1389 }
1390 }
1391 rssi_adjust_val = 0;
1392 btcoexist->btc_set(btcoexist,
1393 BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE,
1394 &rssi_adjust_val);
1395
1396 /* update pre state */
1397 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on;
1398 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma;
1399 }
1400
1401 void btc8723b1ant_tdma_dur_adj_for_acl(struct btc_coexist *btcoexist,
1402 u8 wifi_status)
1403 {
1404 struct rtl_priv *rtlpriv = btcoexist->adapter;
1405 static s32 up, dn, m, n, wait_count;
1406 /* 0: no change, +1: increase WiFi duration,
1407 * -1: decrease WiFi duration
1408 */
1409 s32 result;
1410 u8 retry_count = 0, bt_info_ext;
1411 bool wifi_busy = false;
1412
1413 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1414 "[BTCoex], TdmaDurationAdjustForAcl()\n");
1415
1416 if (wifi_status == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY)
1417 wifi_busy = true;
1418 else
1419 wifi_busy = false;
1420
1421 if ((wifi_status ==
1422 BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN) ||
1423 (wifi_status == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN) ||
1424 (wifi_status == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT)) {
1425 if (coex_dm->cur_ps_tdma != 1 && coex_dm->cur_ps_tdma != 2 &&
1426 coex_dm->cur_ps_tdma != 3 && coex_dm->cur_ps_tdma != 9) {
1427 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1428 true, 9);
1429 coex_dm->ps_tdma_du_adj_type = 9;
1430
1431 up = 0;
1432 dn = 0;
1433 m = 1;
1434 n = 3;
1435 result = 0;
1436 wait_count = 0;
1437 }
1438 return;
1439 }
1440
1441 if (!coex_dm->auto_tdma_adjust) {
1442 coex_dm->auto_tdma_adjust = true;
1443 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1444 "[BTCoex], first run TdmaDurationAdjust()!!\n");
1445
1446 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2);
1447 coex_dm->ps_tdma_du_adj_type = 2;
1448
1449 up = 0;
1450 dn = 0;
1451 m = 1;
1452 n = 3;
1453 result = 0;
1454 wait_count = 0;
1455 } else {
1456 /* acquire the BT TRx retry count from BT_Info byte2 */
1457 retry_count = coex_sta->bt_retry_cnt;
1458 bt_info_ext = coex_sta->bt_info_ext;
1459
1460 if ((coex_sta->low_priority_tx) > 1050 ||
1461 (coex_sta->low_priority_rx) > 1250)
1462 retry_count++;
1463
1464 result = 0;
1465 wait_count++;
1466 /* no retry in the last 2-second duration */
1467 if (retry_count == 0) {
1468 up++;
1469 dn--;
1470
1471 if (dn <= 0)
1472 dn = 0;
1473
1474 if (up >= n) {
1475 /* if retry count during continuous n*2 seconds
1476 * is 0, enlarge WiFi duration
1477 */
1478 wait_count = 0;
1479 n = 3;
1480 up = 0;
1481 dn = 0;
1482 result = 1;
1483 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1484 "[BTCoex], Increase wifi duration!!\n");
1485 }
1486 } else if (retry_count <= 3) {
1487 /* <=3 retry in the last 2-second duration */
1488 up--;
1489 dn++;
1490
1491 if (up <= 0)
1492 up = 0;
1493
1494 if (dn == 2) {
1495 /* if continuous 2 retry count(every 2 seconds)
1496 * >0 and < 3, reduce WiFi duration
1497 */
1498 if (wait_count <= 2)
1499 /* avoid loop between the two levels */
1500 m++;
1501 else
1502 m = 1;
1503
1504 if (m >= 20)
1505 /* maximum of m = 20 ' will recheck if
1506 * need to adjust wifi duration in
1507 * maximum time interval 120 seconds
1508 */
1509 m = 20;
1510
1511 n = 3 * m;
1512 up = 0;
1513 dn = 0;
1514 wait_count = 0;
1515 result = -1;
1516 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1517 "[BTCoex], Decrease wifi duration for retryCounter<3!!\n");
1518 }
1519 } else {
1520 /* retry count > 3, once retry count > 3, to reduce
1521 * WiFi duration
1522 */
1523 if (wait_count == 1)
1524 /* to avoid loop between the two levels */
1525 m++;
1526 else
1527 m = 1;
1528
1529 if (m >= 20)
1530 /* maximum of m = 20 ' will recheck if need to
1531 * adjust wifi duration in maximum time interval
1532 * 120 seconds
1533 */
1534 m = 20;
1535
1536 n = 3 * m;
1537 up = 0;
1538 dn = 0;
1539 wait_count = 0;
1540 result = -1;
1541 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1542 "[BTCoex], Decrease wifi duration for retryCounter>3!!\n");
1543 }
1544
1545 if (result == -1) {
1546 if (coex_dm->cur_ps_tdma == 1) {
1547 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1548 true, 2);
1549 coex_dm->ps_tdma_du_adj_type = 2;
1550 } else if (coex_dm->cur_ps_tdma == 2) {
1551 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1552 true, 9);
1553 coex_dm->ps_tdma_du_adj_type = 9;
1554 } else if (coex_dm->cur_ps_tdma == 9) {
1555 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1556 true, 11);
1557 coex_dm->ps_tdma_du_adj_type = 11;
1558 }
1559 } else if (result == 1) {
1560 if (coex_dm->cur_ps_tdma == 11) {
1561 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1562 true, 9);
1563 coex_dm->ps_tdma_du_adj_type = 9;
1564 } else if (coex_dm->cur_ps_tdma == 9) {
1565 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1566 true, 2);
1567 coex_dm->ps_tdma_du_adj_type = 2;
1568 } else if (coex_dm->cur_ps_tdma == 2) {
1569 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1570 true, 1);
1571 coex_dm->ps_tdma_du_adj_type = 1;
1572 }
1573 }
1574
1575 if (coex_dm->cur_ps_tdma != 1 && coex_dm->cur_ps_tdma != 2 &&
1576 coex_dm->cur_ps_tdma != 9 && coex_dm->cur_ps_tdma != 11) {
1577 /* recover to previous adjust type */
1578 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1579 coex_dm->ps_tdma_du_adj_type);
1580 }
1581 }
1582 }
1583
1584 static void halbtc8723b1ant_ps_tdma_chk_pwr_save(struct btc_coexist *btcoexist,
1585 bool new_ps_state)
1586 {
1587 u8 lps_mode = 0x0;
1588
1589 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode);
1590
1591 if (lps_mode) {
1592 /* already under LPS state */
1593 if (new_ps_state) {
1594 /* keep state under LPS, do nothing. */
1595 } else {
1596 /* will leave LPS state, turn off psTdma first */
1597 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1598 false, 0);
1599 }
1600 } else {
1601 /* NO PS state */
1602 if (new_ps_state) {
1603 /* will enter LPS state, turn off psTdma first */
1604 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1605 false, 0);
1606 } else {
1607 /* keep state under NO PS state, do nothing. */
1608 }
1609 }
1610 }
1611
1612 static void halbtc8723b1ant_power_save_state(struct btc_coexist *btcoexist,
1613 u8 ps_type, u8 lps_val,
1614 u8 rpwm_val)
1615 {
1616 bool low_pwr_disable = false;
1617
1618 switch (ps_type) {
1619 case BTC_PS_WIFI_NATIVE:
1620 /* recover to original 32k low power setting */
1621 low_pwr_disable = false;
1622 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1623 &low_pwr_disable);
1624 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1625 coex_sta->force_lps_on = false;
1626 break;
1627 case BTC_PS_LPS_ON:
1628 halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist, true);
1629 halbtc8723b1ant_lps_rpwm(btcoexist, NORMAL_EXEC, lps_val,
1630 rpwm_val);
1631 /* when coex force to enter LPS, do not enter 32k low power */
1632 low_pwr_disable = true;
1633 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER,
1634 &low_pwr_disable);
1635 /* power save must executed before psTdma */
1636 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1637 coex_sta->force_lps_on = true;
1638 break;
1639 case BTC_PS_LPS_OFF:
1640 halbtc8723b1ant_ps_tdma_chk_pwr_save(btcoexist, false);
1641 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
1642 coex_sta->force_lps_on = false;
1643 break;
1644 default:
1645 break;
1646 }
1647 }
1648
1649 static void halbtc8723b1ant_action_wifi_only(struct btc_coexist *btcoexist)
1650 {
1651 halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
1652 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
1653 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
1654 FORCE_EXEC, false, false);
1655 }
1656
1657 /* check if BT is disabled */
1658 static void halbtc8723b1ant_monitor_bt_enable_disable(struct btc_coexist
1659 *btcoexist)
1660 {
1661 struct rtl_priv *rtlpriv = btcoexist->adapter;
1662 static u32 bt_disable_cnt;
1663 bool bt_active = true, bt_disabled;
1664
1665 if (coex_sta->high_priority_tx == 0 &&
1666 coex_sta->high_priority_rx == 0 && coex_sta->low_priority_tx == 0 &&
1667 coex_sta->low_priority_rx == 0)
1668 bt_active = false;
1669 if (coex_sta->high_priority_tx == 0xffff &&
1670 coex_sta->high_priority_rx == 0xffff &&
1671 coex_sta->low_priority_tx == 0xffff &&
1672 coex_sta->low_priority_rx == 0xffff)
1673 bt_active = false;
1674 if (bt_active) {
1675 bt_disable_cnt = 0;
1676 bt_disabled = false;
1677 } else {
1678 bt_disable_cnt++;
1679 if (bt_disable_cnt >= 2)
1680 bt_disabled = true;
1681 }
1682 if (coex_sta->bt_disabled != bt_disabled) {
1683 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1684 "[BTCoex], BT is from %s to %s!!\n",
1685 (coex_sta->bt_disabled ? "disabled" : "enabled"),
1686 (bt_disabled ? "disabled" : "enabled"));
1687
1688 coex_sta->bt_disabled = bt_disabled;
1689 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_DISABLE,
1690 &bt_disabled);
1691 if (bt_disabled) {
1692 halbtc8723b1ant_action_wifi_only(btcoexist);
1693 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS,
1694 NULL);
1695 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS,
1696 NULL);
1697 }
1698 }
1699 }
1700
1701 /*****************************************************
1702 *
1703 * Non-Software Coex Mechanism start
1704 *
1705 *****************************************************/
1706
1707 static void halbtc8723b1ant_action_bt_whck_test(struct btc_coexist *btcoexist)
1708 {
1709 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0,
1710 0x0);
1711
1712 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1713 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC,
1714 false, false);
1715 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1716 }
1717
1718 static void halbtc8723b1ant_action_wifi_multiport(struct btc_coexist *btcoexist)
1719 {
1720 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1721 0x0, 0x0);
1722
1723 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1724 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1725 }
1726
1727 static void halbtc8723b1ant_action_hs(struct btc_coexist *btcoexist)
1728 {
1729 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1730 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1731 }
1732
1733 static void halbtc8723b1ant_action_bt_inquiry(struct btc_coexist *btcoexist)
1734 {
1735 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1736 bool wifi_connected = false, ap_enable = false;
1737 bool wifi_busy = false, bt_busy = false;
1738
1739 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
1740 &ap_enable);
1741 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1742 &wifi_connected);
1743 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
1744 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
1745
1746 if (coex_sta->bt_abnormal_scan) {
1747 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 33);
1748 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1749 } else if (!wifi_connected && !coex_sta->wifi_is_high_pri_task) {
1750 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1751 0x0, 0x0);
1752 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1753 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
1754 NORMAL_EXEC, false, false);
1755 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1756 } else if (bt_link_info->sco_exist || bt_link_info->hid_exist ||
1757 bt_link_info->a2dp_exist) {
1758 /* SCO/HID/A2DP busy */
1759 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1760 0x0, 0x0);
1761 if (coex_sta->c2h_bt_remote_name_req)
1762 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1763 33);
1764 else
1765 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1766 32);
1767
1768 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1769 } else if (bt_link_info->pan_exist || wifi_busy) {
1770 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1771 0x0, 0x0);
1772 if (coex_sta->c2h_bt_remote_name_req)
1773 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1774 33);
1775 else
1776 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true,
1777 32);
1778
1779 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 4);
1780 } else {
1781 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1782 0x0, 0x0);
1783 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1784 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
1785 NORMAL_EXEC, false, false);
1786 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1787 }
1788 }
1789
1790 static void btc8723b1ant_act_bt_sco_hid_only_busy(struct btc_coexist *btcoexist,
1791 u8 wifi_status)
1792 {
1793 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1794 bool wifi_connected = false;
1795
1796 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
1797 &wifi_connected);
1798
1799 /* tdma and coex table */
1800 if (bt_link_info->sco_exist) {
1801 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5);
1802 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1803 } else {
1804 /* HID */
1805 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 6);
1806 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 5);
1807 }
1808 }
1809
1810 static void halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
1811 struct btc_coexist *btcoexist,
1812 u8 wifi_status)
1813 {
1814 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1815
1816 if ((coex_sta->low_priority_rx >= 950) && (!coex_sta->under_ips))
1817 bt_link_info->slave_role = true;
1818 else
1819 bt_link_info->slave_role = false;
1820
1821 if (bt_link_info->hid_only) { /* HID */
1822 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist, wifi_status);
1823 coex_dm->auto_tdma_adjust = false;
1824 return;
1825 } else if (bt_link_info->a2dp_only) { /* A2DP */
1826 if (wifi_status == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE) {
1827 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1828 false, 8);
1829 halbtc8723b1ant_coex_table_with_type(btcoexist,
1830 NORMAL_EXEC, 2);
1831 coex_dm->auto_tdma_adjust = false;
1832 } else {
1833 btc8723b1ant_tdma_dur_adj_for_acl(btcoexist,
1834 wifi_status);
1835 halbtc8723b1ant_coex_table_with_type(btcoexist,
1836 NORMAL_EXEC, 1);
1837 coex_dm->auto_tdma_adjust = true;
1838 }
1839 } else if (bt_link_info->hid_exist &&
1840 bt_link_info->a2dp_exist) { /* HID + A2DP */
1841 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 14);
1842 coex_dm->auto_tdma_adjust = false;
1843
1844 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
1845 /* PAN(OPP,FTP), HID + PAN(OPP,FTP) */
1846 } else if (bt_link_info->pan_only ||
1847 (bt_link_info->hid_exist && bt_link_info->pan_exist)) {
1848 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3);
1849 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 6);
1850 coex_dm->auto_tdma_adjust = false;
1851 /* A2DP + PAN(OPP,FTP), HID + A2DP + PAN(OPP,FTP) */
1852 } else if ((bt_link_info->a2dp_exist && bt_link_info->pan_exist) ||
1853 (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
1854 bt_link_info->pan_exist)) {
1855 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13);
1856 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1857 coex_dm->auto_tdma_adjust = false;
1858 } else {
1859 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 11);
1860 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1861 coex_dm->auto_tdma_adjust = false;
1862 }
1863 }
1864
1865 static void btc8723b1ant_action_wifi_not_conn(struct btc_coexist *btcoexist)
1866 {
1867 /* power save state */
1868 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1869 0x0, 0x0);
1870
1871 /* tdma and coex table */
1872 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1873 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0);
1874 }
1875
1876 static void
1877 btc8723b1ant_action_wifi_not_conn_scan(struct btc_coexist *btcoexist)
1878 {
1879 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1880
1881 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1882 0x0, 0x0);
1883
1884 /* tdma and coex table */
1885 if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
1886 if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
1887 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1888 true, 22);
1889 halbtc8723b1ant_coex_table_with_type(btcoexist,
1890 NORMAL_EXEC, 1);
1891 } else if (bt_link_info->pan_only) {
1892 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1893 true, 20);
1894 halbtc8723b1ant_coex_table_with_type(btcoexist,
1895 NORMAL_EXEC, 2);
1896 } else {
1897 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1898 true, 20);
1899 halbtc8723b1ant_coex_table_with_type(btcoexist,
1900 NORMAL_EXEC, 1);
1901 }
1902 } else if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_SCO_BUSY ||
1903 coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY){
1904 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
1905 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1906 } else {
1907 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1908 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1909 }
1910 }
1911
1912 static void
1913 btc8723b1ant_act_wifi_not_conn_asso_auth(struct btc_coexist *btcoexist)
1914 {
1915 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1916
1917 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1918 0x0, 0x0);
1919
1920 if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) ||
1921 (bt_link_info->sco_exist) || (bt_link_info->hid_only) ||
1922 (bt_link_info->a2dp_only) || (bt_link_info->pan_only)) {
1923 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1924 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1925 } else {
1926 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1927 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1928 }
1929 }
1930
1931 static void btc8723b1ant_action_wifi_conn_scan(struct btc_coexist *btcoexist)
1932 {
1933 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1934
1935 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1936 0x0, 0x0);
1937
1938 /* tdma and coex table */
1939 if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
1940 if (bt_link_info->a2dp_exist && bt_link_info->pan_exist) {
1941 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1942 true, 22);
1943 halbtc8723b1ant_coex_table_with_type(btcoexist,
1944 NORMAL_EXEC, 1);
1945 } else if (bt_link_info->pan_only) {
1946 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1947 true, 20);
1948 halbtc8723b1ant_coex_table_with_type(btcoexist,
1949 NORMAL_EXEC, 2);
1950 } else {
1951 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
1952 true, 20);
1953 halbtc8723b1ant_coex_table_with_type(btcoexist,
1954 NORMAL_EXEC, 1);
1955 }
1956 } else if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_SCO_BUSY ||
1957 coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) {
1958 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
1959 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
1960 } else {
1961 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1962 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
1963 }
1964 }
1965
1966 static void halbtc8723b1ant_action_wifi_connected_special_packet(
1967 struct btc_coexist *btcoexist)
1968 {
1969 bool hs_connecting = false;
1970 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
1971
1972 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_CONNECTING, &hs_connecting);
1973
1974 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
1975 0x0, 0x0);
1976
1977 /* tdma and coex table */
1978 if ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == coex_dm->bt_status) ||
1979 (bt_link_info->sco_exist) || (bt_link_info->hid_only) ||
1980 (bt_link_info->a2dp_only) || (bt_link_info->pan_only)) {
1981 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 8);
1982 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7);
1983 } else {
1984 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 20);
1985 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 1);
1986 }
1987 }
1988
1989 static void halbtc8723b1ant_action_wifi_connected(struct btc_coexist *btcoexist)
1990 {
1991 struct rtl_priv *rtlpriv = btcoexist->adapter;
1992 bool wifi_busy = false;
1993 bool scan = false, link = false, roam = false;
1994 bool under_4way = false, ap_enable = false;
1995
1996 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1997 "[BTCoex], CoexForWifiConnect()===>\n");
1998
1999 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
2000 &under_4way);
2001 if (under_4way) {
2002 halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist);
2003 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2004 "[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n");
2005 return;
2006 }
2007
2008 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2009 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2010 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2011
2012 if (scan || link || roam) {
2013 if (scan)
2014 btc8723b1ant_action_wifi_conn_scan(btcoexist);
2015 else
2016 halbtc8723b1ant_action_wifi_connected_special_packet(
2017 btcoexist);
2018 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2019 "[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n");
2020 return;
2021 }
2022
2023 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
2024 &ap_enable);
2025 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2026 /* power save state */
2027 if (!ap_enable &&
2028 coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY &&
2029 !btcoexist->bt_link_info.hid_only) {
2030 if (!wifi_busy && btcoexist->bt_link_info.a2dp_only)
2031 halbtc8723b1ant_power_save_state(btcoexist,
2032 BTC_PS_WIFI_NATIVE,
2033 0x0, 0x0);
2034 else
2035 halbtc8723b1ant_power_save_state(btcoexist,
2036 BTC_PS_LPS_ON,
2037 0x50, 0x4);
2038 } else {
2039 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
2040 0x0, 0x0);
2041 }
2042 /* tdma and coex table */
2043 if (!wifi_busy) {
2044 if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
2045 halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
2046 btcoexist,
2047 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2048 } else if (coex_dm->bt_status ==
2049 BT_8723B_1ANT_BT_STATUS_SCO_BUSY ||
2050 coex_dm->bt_status ==
2051 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) {
2052 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
2053 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2054 } else {
2055 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
2056 false, 8);
2057 halbtc8723b1ant_coex_table_with_type(btcoexist,
2058 NORMAL_EXEC, 2);
2059 }
2060 } else {
2061 if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
2062 halbtc8723b1ant_action_wifi_connected_bt_acl_busy(
2063 btcoexist,
2064 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2065 } else if (coex_dm->bt_status ==
2066 BT_8723B_1ANT_BT_STATUS_SCO_BUSY ||
2067 coex_dm->bt_status ==
2068 BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) {
2069 btc8723b1ant_act_bt_sco_hid_only_busy(btcoexist,
2070 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2071 } else {
2072 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC,
2073 false, 8);
2074 halbtc8723b1ant_coex_table_with_type(btcoexist,
2075 NORMAL_EXEC, 2);
2076 }
2077 }
2078 }
2079
2080 static void halbtc8723b1ant_run_coexist_mechanism(struct btc_coexist *btcoexist)
2081 {
2082 struct rtl_priv *rtlpriv = btcoexist->adapter;
2083 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2084 bool wifi_connected = false, bt_hs_on = false;
2085 bool increase_scan_dev_num = false;
2086 bool bt_ctrl_agg_buf_size = false;
2087 u8 agg_buf_size = 5;
2088 u32 wifi_link_status = 0;
2089 u32 num_of_wifi_link = 0;
2090
2091 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2092 "[BTCoex], RunCoexistMechanism()===>\n");
2093
2094 if (btcoexist->manual_control) {
2095 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2096 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
2097 return;
2098 }
2099
2100 if (btcoexist->stop_coex_dm) {
2101 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2102 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
2103 return;
2104 }
2105
2106 if (coex_sta->under_ips) {
2107 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2108 "[BTCoex], wifi is under IPS !!!\n");
2109 return;
2110 }
2111
2112 if (coex_sta->bt_whck_test) {
2113 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2114 "[BTCoex], wifi is under IPS !!!\n");
2115 halbtc8723b1ant_action_bt_whck_test(btcoexist);
2116 return;
2117 }
2118
2119 if (coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_BUSY ||
2120 coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_SCO_BUSY ||
2121 coex_dm->bt_status == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
2122 increase_scan_dev_num = true;
2123
2124 btcoexist->btc_set(btcoexist, BTC_SET_BL_INC_SCAN_DEV_NUM,
2125 &increase_scan_dev_num);
2126
2127 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2128 &wifi_connected);
2129
2130 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2131 &wifi_link_status);
2132 num_of_wifi_link = wifi_link_status >> 16;
2133 if (num_of_wifi_link >= 2) {
2134 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2135 halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2136 bt_ctrl_agg_buf_size,
2137 agg_buf_size);
2138 halbtc8723b1ant_action_wifi_multiport(btcoexist);
2139 return;
2140 }
2141
2142 if (!bt_link_info->sco_exist && !bt_link_info->hid_exist) {
2143 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2144 } else {
2145 if (wifi_connected)
2146 halbtc8723b1ant_limited_tx(btcoexist,
2147 NORMAL_EXEC, 1, 1, 1, 1);
2148 else
2149 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC,
2150 0, 0, 0, 0);
2151 }
2152
2153 if (bt_link_info->sco_exist) {
2154 bt_ctrl_agg_buf_size = true;
2155 agg_buf_size = 0x3;
2156 } else if (bt_link_info->hid_exist) {
2157 bt_ctrl_agg_buf_size = true;
2158 agg_buf_size = 0x5;
2159 } else if (bt_link_info->a2dp_exist || bt_link_info->pan_exist) {
2160 bt_ctrl_agg_buf_size = true;
2161 agg_buf_size = 0x8;
2162 }
2163 halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2164 bt_ctrl_agg_buf_size, agg_buf_size);
2165
2166 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2167
2168 if (coex_sta->c2h_bt_inquiry_page) {
2169 halbtc8723b1ant_action_bt_inquiry(btcoexist);
2170 return;
2171 } else if (bt_hs_on) {
2172 halbtc8723b1ant_action_hs(btcoexist);
2173 return;
2174 }
2175
2176 if (!wifi_connected) {
2177 bool scan = false, link = false, roam = false;
2178
2179 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2180 "[BTCoex], wifi is non connected-idle !!!\n");
2181
2182 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2183 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2184 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2185
2186 if (scan || link || roam) {
2187 if (scan)
2188 btc8723b1ant_action_wifi_not_conn_scan(
2189 btcoexist);
2190 else
2191 btc8723b1ant_act_wifi_not_conn_asso_auth(
2192 btcoexist);
2193 } else {
2194 btc8723b1ant_action_wifi_not_conn(btcoexist);
2195 }
2196 } else { /* wifi LPS/Busy */
2197 halbtc8723b1ant_action_wifi_connected(btcoexist);
2198 }
2199 }
2200
2201 /* force coex mechanism to reset */
2202 static void halbtc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist)
2203 {
2204 /* sw all off */
2205 halbtc8723b1ant_sw_mechanism(btcoexist, false);
2206
2207 coex_sta->pop_event_cnt = 0;
2208 }
2209
2210 static void halbtc8723b1ant_init_hw_config(struct btc_coexist *btcoexist,
2211 bool backup, bool wifi_only)
2212 {
2213 struct rtl_priv *rtlpriv = btcoexist->adapter;
2214 u32 u32tmp = 0;
2215 u8 u8tmpa = 0, u8tmpb = 0;
2216
2217 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2218 "[BTCoex], 1Ant Init HW Config!!\n");
2219
2220 /* 0xf0[15:12] --> Chip Cut information */
2221 coex_sta->cut_version =
2222 (btcoexist->btc_read_1byte(btcoexist, 0xf1) & 0xf0) >> 4;
2223 /* enable TBTT interrupt */
2224 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x550, 0x8, 0x1);
2225
2226 /* 0x790[5:0] = 0x5 */
2227 btcoexist->btc_write_1byte(btcoexist, 0x790, 0x5);
2228
2229 /* Enable counter statistics */
2230 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x1);
2231 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1);
2232
2233 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
2234
2235 /* Antenna config */
2236 if (wifi_only)
2237 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_WIFI,
2238 FORCE_EXEC, true, false);
2239 else
2240 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
2241 FORCE_EXEC, true, false);
2242
2243 /* PTA parameter */
2244 halbtc8723b1ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0);
2245
2246 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948);
2247 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
2248 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67);
2249
2250 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2251 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
2252 u32tmp, u8tmpa, u8tmpb);
2253 }
2254
2255 /**************************************************************
2256 * extern function start with ex_halbtc8723b1ant_
2257 **************************************************************/
2258 void ex_halbtc8723b1ant_power_on_setting(struct btc_coexist *btcoexist)
2259 {
2260 struct rtl_priv *rtlpriv = btcoexist->adapter;
2261 struct btc_board_info *board_info = &btcoexist->board_info;
2262 u8 u8tmp = 0x0;
2263 u16 u16tmp = 0x0;
2264 u32 value;
2265
2266 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2267 "xxxxxxxxxxxxxxxx Execute 8723b 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n");
2268
2269 btcoexist->stop_coex_dm = true;
2270
2271 btcoexist->btc_write_1byte(btcoexist, 0x67, 0x20);
2272
2273 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
2274 u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2);
2275 btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT0 | BIT1);
2276
2277 /* set GRAN_BT = 1 */
2278 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18);
2279 /* set WLAN_ACT = 0 */
2280 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4);
2281
2282 /* S0 or S1 setting and Local register setting(By the setting fw can get
2283 * ant number, S0/S1, ... info)
2284 *
2285 * Local setting bit define
2286 * BIT0: "0" for no antenna inverse; "1" for antenna inverse
2287 * BIT1: "0" for internal switch; "1" for external switch
2288 * BIT2: "0" for one antenna; "1" for two antenna
2289 * NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and
2290 * BIT2 = 0
2291 */
2292 if (btcoexist->chip_interface == BTC_INTF_USB) {
2293 /* fixed at S0 for USB interface */
2294 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0);
2295
2296 u8tmp |= 0x1; /* antenna inverse */
2297 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp);
2298
2299 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
2300 } else {
2301 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
2302 if (board_info->single_ant_path == 0) {
2303 /* set to S1 */
2304 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x280);
2305 board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
2306 value = 1;
2307 } else if (board_info->single_ant_path == 1) {
2308 /* set to S0 */
2309 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0);
2310 u8tmp |= 0x1; /* antenna inverse */
2311 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
2312 value = 0;
2313 }
2314
2315 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ANTPOSREGRISTRY_CTRL,
2316 &value);
2317
2318 if (btcoexist->chip_interface == BTC_INTF_PCI)
2319 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384,
2320 u8tmp);
2321 else if (btcoexist->chip_interface == BTC_INTF_SDIO)
2322 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60,
2323 u8tmp);
2324 }
2325 }
2326
2327
2328 void ex_halbtc8723b1ant_init_hwconfig(struct btc_coexist *btcoexist,
2329 bool wifi_only)
2330 {
2331 halbtc8723b1ant_init_hw_config(btcoexist, true, wifi_only);
2332 btcoexist->stop_coex_dm = false;
2333 }
2334
2335 void ex_halbtc8723b1ant_init_coex_dm(struct btc_coexist *btcoexist)
2336 {
2337 struct rtl_priv *rtlpriv = btcoexist->adapter;
2338
2339 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2340 "[BTCoex], Coex Mechanism Init!!\n");
2341
2342 btcoexist->stop_coex_dm = false;
2343
2344 halbtc8723b1ant_init_coex_dm(btcoexist);
2345
2346 halbtc8723b1ant_query_bt_info(btcoexist);
2347 }
2348
2349 void ex_halbtc8723b1ant_display_coex_info(struct btc_coexist *btcoexist)
2350 {
2351 struct btc_board_info *board_info = &btcoexist->board_info;
2352 struct btc_stack_info *stack_info = &btcoexist->stack_info;
2353 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
2354 struct rtl_priv *rtlpriv = btcoexist->adapter;
2355 u8 u8tmp[4], i, bt_info_ext, pstdmacase = 0;
2356 u16 u16tmp[4];
2357 u32 u32tmp[4];
2358 bool roam = false, scan = false;
2359 bool link = false, wifi_under_5g = false;
2360 bool bt_hs_on = false, wifi_busy = false;
2361 s32 wifi_rssi = 0, bt_hs_rssi = 0;
2362 u32 wifi_bw, wifi_traffic_dir, fa_ofdm, fa_cck, wifi_link_status;
2363 u8 wifi_dot11_chnl, wifi_hs_chnl;
2364 u32 fw_ver = 0, bt_patch_ver = 0;
2365
2366 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2367 "\r\n ============[BT Coexist info]============");
2368
2369 if (btcoexist->manual_control) {
2370 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2371 "\r\n ============[Under Manual Control]==========");
2372 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2373 "\r\n ==========================================");
2374 }
2375 if (btcoexist->stop_coex_dm) {
2376 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2377 "\r\n ============[Coex is STOPPED]============");
2378 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2379 "\r\n ==========================================");
2380 }
2381
2382 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d",
2383 "Ant PG Num/ Ant Mech/ Ant Pos:",
2384 board_info->pg_ant_num, board_info->btdm_ant_num,
2385 board_info->btdm_ant_pos);
2386
2387 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %d",
2388 "BT stack/ hci ext ver",
2389 ((stack_info->profile_notified) ? "Yes" : "No"),
2390 stack_info->hci_version);
2391
2392 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
2393 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
2394 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2395 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)",
2396 "CoexVer/ FwVer/ PatchVer",
2397 glcoex_ver_date_8723b_1ant, glcoex_ver_8723b_1ant,
2398 fw_ver, bt_patch_ver, bt_patch_ver);
2399
2400 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2401 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL,
2402 &wifi_dot11_chnl);
2403 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
2404 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d / %d(%d)",
2405 "Dot11 channel / HsChnl(HsMode)",
2406 wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on);
2407
2408 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %3ph ",
2409 "H2C Wifi inform bt chnl Info",
2410 coex_dm->wifi_chnl_info);
2411
2412 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
2413 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
2414 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
2415 "Wifi rssi/ HS rssi", wifi_rssi, bt_hs_rssi);
2416
2417 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
2418 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
2419 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
2420 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d ",
2421 "Wifi link/ roam/ scan", link, roam, scan);
2422
2423 btcoexist->btc_get(btcoexist , BTC_GET_BL_WIFI_UNDER_5G,
2424 &wifi_under_5g);
2425 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2426 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2427 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
2428 &wifi_traffic_dir);
2429
2430 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s / %s/ %s ",
2431 "Wifi status", (wifi_under_5g ? "5G" : "2.4G"),
2432 ((wifi_bw == BTC_WIFI_BW_LEGACY) ? "Legacy" :
2433 ((wifi_bw == BTC_WIFI_BW_HT40) ? "HT40" : "HT20")),
2434 ((!wifi_busy) ? "idle" :
2435 ((wifi_traffic_dir == BTC_WIFI_TRAFFIC_TX) ?
2436 "uplink" : "downlink")));
2437
2438 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2439 &wifi_link_status);
2440 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
2441 "sta/vwifi/hs/p2pGo/p2pGc",
2442 ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
2443 ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
2444 ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
2445 ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
2446 ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
2447
2448 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = [%s/ %d/ %d] ",
2449 "BT [status/ rssi/ retryCnt]",
2450 ((coex_sta->bt_disabled) ? ("disabled") :
2451 ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page scan") :
2452 ((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE ==
2453 coex_dm->bt_status) ?
2454 "non-connected idle" :
2455 ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE ==
2456 coex_dm->bt_status) ?
2457 "connected-idle" : "busy")))),
2458 coex_sta->bt_rssi, coex_sta->bt_retry_cnt);
2459
2460 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2461 "\r\n %-35s = %d / %d / %d / %d",
2462 "SCO/HID/PAN/A2DP", bt_link_info->sco_exist,
2463 bt_link_info->hid_exist, bt_link_info->pan_exist,
2464 bt_link_info->a2dp_exist);
2465 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO);
2466
2467 bt_info_ext = coex_sta->bt_info_ext;
2468 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s",
2469 "BT Info A2DP rate",
2470 (bt_info_ext & BIT0) ? "Basic rate" : "EDR rate");
2471
2472 for (i = 0; i < BT_INFO_SRC_8723B_1ANT_MAX; i++) {
2473 if (coex_sta->bt_info_c2h_cnt[i]) {
2474 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2475 "\r\n %-35s = %7ph(%d)",
2476 glbt_info_src_8723b_1ant[i],
2477 coex_sta->bt_info_c2h[i],
2478 coex_sta->bt_info_c2h_cnt[i]);
2479 }
2480 }
2481 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2482 "\r\n %-35s = %s/%s, (0x%x/0x%x)",
2483 "PS state, IPS/LPS, (lps/rpwm)",
2484 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")),
2485 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF")),
2486 btcoexist->bt_info.lps_val,
2487 btcoexist->bt_info.rpwm_val);
2488 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
2489
2490 if (!btcoexist->manual_control) {
2491 /* Sw mechanism */
2492 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
2493 "============[Sw mechanism]============");
2494
2495 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/",
2496 "SM[LowPenaltyRA]", coex_dm->cur_low_penalty_ra);
2497
2498 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %s/ %s/ %d ",
2499 "DelBA/ BtCtrlAgg/ AggSize",
2500 (btcoexist->bt_info.reject_agg_pkt ? "Yes" : "No"),
2501 (btcoexist->bt_info.bt_ctrl_buf_size ? "Yes" : "No"),
2502 btcoexist->bt_info.agg_buf_size);
2503
2504 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ",
2505 "Rate Mask", btcoexist->bt_info.ra_mask);
2506
2507 /* Fw mechanism */
2508 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
2509 "============[Fw mechanism]============");
2510
2511 pstdmacase = coex_dm->cur_ps_tdma;
2512 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2513 "\r\n %-35s = %5ph case-%d (auto:%d)",
2514 "PS TDMA", coex_dm->ps_tdma_para,
2515 pstdmacase, coex_dm->auto_tdma_adjust);
2516
2517 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d ",
2518 "IgnWlanAct", coex_dm->cur_ignore_wlan_act);
2519
2520 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x ",
2521 "Latest error condition(should be 0)",
2522 coex_dm->error_condition);
2523 }
2524
2525 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d",
2526 "Coex Table Type", coex_sta->coex_table_type);
2527
2528 /* Hw setting */
2529 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s",
2530 "============[Hw setting]============");
2531
2532 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2533 "backup ARFR1/ARFR2/RL/AMaxTime", coex_dm->backup_arfr_cnt1,
2534 coex_dm->backup_arfr_cnt2, coex_dm->backup_retry_limit,
2535 coex_dm->backup_ampdu_max_time);
2536
2537 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x430);
2538 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x434);
2539 u16tmp[0] = btcoexist->btc_read_2byte(btcoexist, 0x42a);
2540 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x456);
2541 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x",
2542 "0x430/0x434/0x42a/0x456",
2543 u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0]);
2544
2545 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778);
2546 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6cc);
2547 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x880);
2548 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2549 "0x778/0x6cc/0x880[29:25]", u8tmp[0], u32tmp[0],
2550 (u32tmp[1] & 0x3e000000) >> 25);
2551
2552 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x948);
2553 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67);
2554 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x765);
2555 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2556 "0x948/ 0x67[5] / 0x765",
2557 u32tmp[0], ((u8tmp[0] & 0x20) >> 5), u8tmp[1]);
2558
2559 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x92c);
2560 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x930);
2561 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x944);
2562 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2563 "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
2564 u32tmp[0] & 0x3, u32tmp[1] & 0xff, u32tmp[2] & 0x3);
2565
2566 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x39);
2567 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40);
2568 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c);
2569 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64);
2570 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG,
2571 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
2572 "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
2573 ((u8tmp[0] & 0x8) >> 3), u8tmp[1],
2574 ((u32tmp[0] & 0x01800000) >> 23), u8tmp[2] & 0x1);
2575
2576 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550);
2577 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522);
2578 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
2579 "0x550(bcn ctrl)/0x522", u32tmp[0], u8tmp[0]);
2580
2581 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50);
2582 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c);
2583 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x",
2584 "0xc50(dig)/0x49c(null-drop)", u32tmp[0] & 0xff, u8tmp[0]);
2585
2586 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0);
2587 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4);
2588 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8);
2589 u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0);
2590
2591 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b);
2592 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c);
2593
2594 fa_ofdm = ((u32tmp[0] & 0xffff0000) >> 16) +
2595 ((u32tmp[1] & 0xffff0000) >> 16) +
2596 (u32tmp[1] & 0xffff) +
2597 (u32tmp[2] & 0xffff) +
2598 ((u32tmp[3] & 0xffff0000) >> 16) +
2599 (u32tmp[3] & 0xffff);
2600 fa_cck = (u8tmp[0] << 8) + u8tmp[1];
2601
2602 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2603 "OFDM-CCA/OFDM-FA/CCK-FA",
2604 u32tmp[0] & 0xffff, fa_ofdm, fa_cck);
2605
2606 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0);
2607 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4);
2608 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8);
2609 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x",
2610 "0x6c0/0x6c4/0x6c8(coexTable)",
2611 u32tmp[0], u32tmp[1], u32tmp[2]);
2612
2613 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
2614 "0x770(high-pri rx/tx)", coex_sta->high_priority_rx,
2615 coex_sta->high_priority_tx);
2616 RT_TRACE(rtlpriv, COMP_INIT, DBG_DMESG, "\r\n %-35s = %d/ %d",
2617 "0x774(low-pri rx/tx)", coex_sta->low_priority_rx,
2618 coex_sta->low_priority_tx);
2619 if (btcoexist->auto_report_1ant)
2620 halbtc8723b1ant_monitor_bt_ctr(btcoexist);
2621 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS);
2622 }
2623
2624 void ex_halbtc8723b1ant_ips_notify(struct btc_coexist *btcoexist, u8 type)
2625 {
2626 struct rtl_priv *rtlpriv = btcoexist->adapter;
2627
2628 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2629 return;
2630
2631 if (BTC_IPS_ENTER == type) {
2632 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2633 "[BTCoex], IPS ENTER notify\n");
2634 coex_sta->under_ips = true;
2635
2636 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
2637 FORCE_EXEC, false, true);
2638 /* set PTA control */
2639 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
2640 halbtc8723b1ant_coex_table_with_type(btcoexist,
2641 NORMAL_EXEC, 0);
2642 } else if (BTC_IPS_LEAVE == type) {
2643 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2644 "[BTCoex], IPS LEAVE notify\n");
2645 coex_sta->under_ips = false;
2646
2647 halbtc8723b1ant_init_hw_config(btcoexist, false, false);
2648 halbtc8723b1ant_init_coex_dm(btcoexist);
2649 halbtc8723b1ant_query_bt_info(btcoexist);
2650 }
2651 }
2652
2653 void ex_halbtc8723b1ant_lps_notify(struct btc_coexist *btcoexist, u8 type)
2654 {
2655 struct rtl_priv *rtlpriv = btcoexist->adapter;
2656
2657 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2658 return;
2659
2660 if (BTC_LPS_ENABLE == type) {
2661 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2662 "[BTCoex], LPS ENABLE notify\n");
2663 coex_sta->under_lps = true;
2664 } else if (BTC_LPS_DISABLE == type) {
2665 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2666 "[BTCoex], LPS DISABLE notify\n");
2667 coex_sta->under_lps = false;
2668 }
2669 }
2670
2671 void ex_halbtc8723b1ant_scan_notify(struct btc_coexist *btcoexist, u8 type)
2672 {
2673 struct rtl_priv *rtlpriv = btcoexist->adapter;
2674 bool wifi_connected = false, bt_hs_on = false;
2675 u8 u8tmpa, u8tmpb;
2676 u32 u32tmp;
2677 u32 wifi_link_status = 0;
2678 u32 num_of_wifi_link = 0;
2679 bool bt_ctrl_agg_buf_size = false;
2680 u8 agg_buf_size = 5;
2681
2682 if (btcoexist->manual_control || btcoexist->stop_coex_dm)
2683 return;
2684
2685 if (type == BTC_SCAN_START) {
2686 coex_sta->wifi_is_high_pri_task = true;
2687 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2688 "[BTCoex], SCAN START notify\n");
2689 /* Force antenna setup for no scan result issue */
2690 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
2691 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
2692 FORCE_EXEC, false, false);
2693 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948);
2694 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
2695 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67);
2696
2697 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2698 "[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
2699 u32tmp, u8tmpa, u8tmpb);
2700 } else {
2701 coex_sta->wifi_is_high_pri_task = false;
2702 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2703 "[BTCoex], SCAN FINISH notify\n");
2704
2705 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM,
2706 &coex_sta->scan_ap_num);
2707 }
2708
2709 if (coex_sta->bt_disabled)
2710 return;
2711
2712 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2713 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2714 &wifi_connected);
2715
2716 halbtc8723b1ant_query_bt_info(btcoexist);
2717
2718 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2719 &wifi_link_status);
2720 num_of_wifi_link = wifi_link_status >> 16;
2721 if (num_of_wifi_link >= 2) {
2722 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2723 halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2724 bt_ctrl_agg_buf_size, agg_buf_size);
2725 halbtc8723b1ant_action_wifi_multiport(btcoexist);
2726 return;
2727 }
2728
2729 if (coex_sta->c2h_bt_inquiry_page) {
2730 halbtc8723b1ant_action_bt_inquiry(btcoexist);
2731 return;
2732 } else if (bt_hs_on) {
2733 halbtc8723b1ant_action_hs(btcoexist);
2734 return;
2735 }
2736
2737 if (BTC_SCAN_START == type) {
2738 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2739 "[BTCoex], SCAN START notify\n");
2740 if (!wifi_connected)
2741 /* non-connected scan */
2742 btc8723b1ant_action_wifi_not_conn_scan(btcoexist);
2743 else
2744 /* wifi is connected */
2745 btc8723b1ant_action_wifi_conn_scan(btcoexist);
2746 } else if (BTC_SCAN_FINISH == type) {
2747 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2748 "[BTCoex], SCAN FINISH notify\n");
2749 if (!wifi_connected)
2750 /* non-connected scan */
2751 btc8723b1ant_action_wifi_not_conn(btcoexist);
2752 else
2753 halbtc8723b1ant_action_wifi_connected(btcoexist);
2754 }
2755 }
2756
2757 void ex_halbtc8723b1ant_connect_notify(struct btc_coexist *btcoexist, u8 type)
2758 {
2759 struct rtl_priv *rtlpriv = btcoexist->adapter;
2760 bool wifi_connected = false, bt_hs_on = false;
2761 u32 wifi_link_status = 0;
2762 u32 num_of_wifi_link = 0;
2763 bool bt_ctrl_agg_buf_size = false, under_4way = false;
2764 u8 agg_buf_size = 5;
2765
2766 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
2767 &under_4way);
2768
2769 if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
2770 coex_sta->bt_disabled)
2771 return;
2772
2773 if (type == BTC_ASSOCIATE_START) {
2774 coex_sta->wifi_is_high_pri_task = true;
2775
2776 /* Force antenna setup for no scan result issue */
2777 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
2778 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
2779 FORCE_EXEC, false, false);
2780 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2781 "[BTCoex], CONNECT START notify\n");
2782 coex_dm->arp_cnt = 0;
2783 } else {
2784 coex_sta->wifi_is_high_pri_task = false;
2785 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2786 "[BTCoex], CONNECT FINISH notify\n");
2787 }
2788
2789 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2790 &wifi_link_status);
2791 num_of_wifi_link = wifi_link_status>>16;
2792 if (num_of_wifi_link >= 2) {
2793 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2794 halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2795 bt_ctrl_agg_buf_size, agg_buf_size);
2796 halbtc8723b1ant_action_wifi_multiport(btcoexist);
2797 return;
2798 }
2799
2800 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2801 if (coex_sta->c2h_bt_inquiry_page) {
2802 halbtc8723b1ant_action_bt_inquiry(btcoexist);
2803 return;
2804 } else if (bt_hs_on) {
2805 halbtc8723b1ant_action_hs(btcoexist);
2806 return;
2807 }
2808
2809 if (BTC_ASSOCIATE_START == type) {
2810 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2811 "[BTCoex], CONNECT START notify\n");
2812 btc8723b1ant_act_wifi_not_conn_asso_auth(btcoexist);
2813 } else if (BTC_ASSOCIATE_FINISH == type) {
2814 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2815 "[BTCoex], CONNECT FINISH notify\n");
2816
2817 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
2818 &wifi_connected);
2819 if (!wifi_connected)
2820 /* non-connected scan */
2821 btc8723b1ant_action_wifi_not_conn(btcoexist);
2822 else
2823 halbtc8723b1ant_action_wifi_connected(btcoexist);
2824 }
2825 }
2826
2827 void ex_halbtc8723b1ant_media_status_notify(struct btc_coexist *btcoexist,
2828 u8 type)
2829 {
2830 struct rtl_priv *rtlpriv = btcoexist->adapter;
2831 u8 h2c_parameter[3] = {0};
2832 u32 wifi_bw;
2833 u8 wifi_central_chnl;
2834 bool wifi_under_b_mode = false;
2835
2836 if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
2837 coex_sta->bt_disabled)
2838 return;
2839
2840 if (type == BTC_MEDIA_CONNECT) {
2841 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2842 "[BTCoex], MEDIA connect notify\n");
2843 /* Force antenna setup for no scan result issue */
2844 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 8);
2845 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_PTA,
2846 FORCE_EXEC, false, false);
2847 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
2848 &wifi_under_b_mode);
2849
2850 /* Set CCK Tx/Rx high Pri except 11b mode */
2851 if (wifi_under_b_mode) {
2852 btcoexist->btc_write_1byte(btcoexist, 0x6cd,
2853 0x00); /* CCK Tx */
2854 btcoexist->btc_write_1byte(btcoexist, 0x6cf,
2855 0x00); /* CCK Rx */
2856 } else {
2857 btcoexist->btc_write_1byte(btcoexist, 0x6cd,
2858 0x00); /* CCK Tx */
2859 btcoexist->btc_write_1byte(btcoexist, 0x6cf,
2860 0x10); /* CCK Rx */
2861 }
2862
2863 coex_dm->backup_arfr_cnt1 =
2864 btcoexist->btc_read_4byte(btcoexist, 0x430);
2865 coex_dm->backup_arfr_cnt2 =
2866 btcoexist->btc_read_4byte(btcoexist, 0x434);
2867 coex_dm->backup_retry_limit =
2868 btcoexist->btc_read_2byte(btcoexist, 0x42a);
2869 coex_dm->backup_ampdu_max_time =
2870 btcoexist->btc_read_1byte(btcoexist, 0x456);
2871 } else {
2872 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2873 "[BTCoex], MEDIA disconnect notify\n");
2874 coex_dm->arp_cnt = 0;
2875
2876 btcoexist->btc_write_1byte(btcoexist, 0x6cd, 0x0); /* CCK Tx */
2877 btcoexist->btc_write_1byte(btcoexist, 0x6cf, 0x0); /* CCK Rx */
2878
2879 coex_sta->cck_ever_lock = false;
2880 }
2881
2882 /* only 2.4G we need to inform bt the chnl mask */
2883 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL,
2884 &wifi_central_chnl);
2885
2886 if (type == BTC_MEDIA_CONNECT && wifi_central_chnl <= 14) {
2887 h2c_parameter[0] = 0x0;
2888 h2c_parameter[1] = wifi_central_chnl;
2889 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
2890 if (BTC_WIFI_BW_HT40 == wifi_bw)
2891 h2c_parameter[2] = 0x30;
2892 else
2893 h2c_parameter[2] = 0x20;
2894 }
2895
2896 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
2897 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
2898 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
2899
2900 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2901 "[BTCoex], FW write 0x66 = 0x%x\n",
2902 h2c_parameter[0] << 16 | h2c_parameter[1] << 8 |
2903 h2c_parameter[2]);
2904
2905 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter);
2906 }
2907
2908 void ex_halbtc8723b1ant_special_packet_notify(struct btc_coexist *btcoexist,
2909 u8 type)
2910 {
2911 struct rtl_priv *rtlpriv = btcoexist->adapter;
2912 bool bt_hs_on = false;
2913 u32 wifi_link_status = 0;
2914 u32 num_of_wifi_link = 0;
2915 bool bt_ctrl_agg_buf_size = false, under_4way = false;
2916 u8 agg_buf_size = 5;
2917
2918 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS,
2919 &under_4way);
2920
2921 if (btcoexist->manual_control || btcoexist->stop_coex_dm ||
2922 coex_sta->bt_disabled)
2923 return;
2924
2925 if (type == BTC_PACKET_DHCP || type == BTC_PACKET_EAPOL ||
2926 type == BTC_PACKET_ARP) {
2927 if (type == BTC_PACKET_ARP) {
2928 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2929 "[BTCoex], special Packet ARP notify\n");
2930
2931 coex_dm->arp_cnt++;
2932 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2933 "[BTCoex], ARP Packet Count = %d\n",
2934 coex_dm->arp_cnt);
2935
2936 if ((coex_dm->arp_cnt >= 10) && (!under_4way))
2937 /* if APR PKT > 10 after connect, do not go to
2938 * ActionWifiConnectedSpecificPacket(btcoexist)
2939 */
2940 coex_sta->wifi_is_high_pri_task = false;
2941 else
2942 coex_sta->wifi_is_high_pri_task = true;
2943 } else {
2944 coex_sta->wifi_is_high_pri_task = true;
2945 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2946 "[BTCoex], special Packet DHCP or EAPOL notify\n");
2947 }
2948 } else {
2949 coex_sta->wifi_is_high_pri_task = false;
2950 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2951 "[BTCoex], special Packet [Type = %d] notify\n",
2952 type);
2953 }
2954
2955 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS,
2956 &wifi_link_status);
2957 num_of_wifi_link = wifi_link_status >> 16;
2958 if (num_of_wifi_link >= 2) {
2959 halbtc8723b1ant_limited_tx(btcoexist, NORMAL_EXEC, 0, 0, 0, 0);
2960 halbtc8723b1ant_limited_rx(btcoexist, NORMAL_EXEC, false,
2961 bt_ctrl_agg_buf_size, agg_buf_size);
2962 halbtc8723b1ant_action_wifi_multiport(btcoexist);
2963 return;
2964 }
2965
2966 coex_sta->special_pkt_period_cnt = 0;
2967
2968 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
2969 if (coex_sta->c2h_bt_inquiry_page) {
2970 halbtc8723b1ant_action_bt_inquiry(btcoexist);
2971 return;
2972 } else if (bt_hs_on) {
2973 halbtc8723b1ant_action_hs(btcoexist);
2974 return;
2975 }
2976
2977 if (BTC_PACKET_DHCP == type ||
2978 BTC_PACKET_EAPOL == type) {
2979 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
2980 "[BTCoex], special Packet(%d) notify\n", type);
2981 halbtc8723b1ant_action_wifi_connected_special_packet(btcoexist);
2982 }
2983 }
2984
2985 void ex_halbtc8723b1ant_bt_info_notify(struct btc_coexist *btcoexist,
2986 u8 *tmp_buf, u8 length)
2987 {
2988 struct rtl_priv *rtlpriv = btcoexist->adapter;
2989 u8 bt_info = 0;
2990 u8 i, rsp_source = 0;
2991 bool wifi_connected = false;
2992 bool bt_busy = false;
2993
2994 coex_sta->c2h_bt_info_req_sent = false;
2995
2996 rsp_source = tmp_buf[0] & 0xf;
2997 if (rsp_source >= BT_INFO_SRC_8723B_1ANT_MAX)
2998 rsp_source = BT_INFO_SRC_8723B_1ANT_WIFI_FW;
2999 coex_sta->bt_info_c2h_cnt[rsp_source]++;
3000
3001 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3002 "[BTCoex], Bt info[%d], length=%d, hex data = [",
3003 rsp_source, length);
3004 for (i = 0; i < length; i++) {
3005 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
3006 if (i == 1)
3007 bt_info = tmp_buf[i];
3008 if (i == length - 1)
3009 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3010 "0x%02x]\n", tmp_buf[i]);
3011 else
3012 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3013 "0x%02x, ", tmp_buf[i]);
3014 }
3015
3016 /* if 0xff, it means BT is under WHCK test */
3017 if (bt_info == 0xff)
3018 coex_sta->bt_whck_test = true;
3019 else
3020 coex_sta->bt_whck_test = false;
3021
3022 if (rsp_source != BT_INFO_SRC_8723B_1ANT_WIFI_FW) {
3023 coex_sta->bt_retry_cnt = /* [3:0] */
3024 coex_sta->bt_info_c2h[rsp_source][2] & 0xf;
3025
3026 if (coex_sta->bt_retry_cnt >= 1)
3027 coex_sta->pop_event_cnt++;
3028
3029 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20)
3030 coex_sta->c2h_bt_remote_name_req = true;
3031 else
3032 coex_sta->c2h_bt_remote_name_req = false;
3033
3034 coex_sta->bt_rssi =
3035 coex_sta->bt_info_c2h[rsp_source][3] * 2 - 90;
3036
3037 coex_sta->bt_info_ext =
3038 coex_sta->bt_info_c2h[rsp_source][4];
3039
3040 if (coex_sta->bt_info_c2h[rsp_source][1] == 0x49) {
3041 coex_sta->a2dp_bit_pool =
3042 coex_sta->bt_info_c2h[rsp_source][6];
3043 } else {
3044 coex_sta->a2dp_bit_pool = 0;
3045 }
3046
3047 coex_sta->bt_tx_rx_mask =
3048 (coex_sta->bt_info_c2h[rsp_source][2] & 0x40);
3049 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TX_RX_MASK,
3050 &coex_sta->bt_tx_rx_mask);
3051
3052 if (!coex_sta->bt_tx_rx_mask) {
3053 /* BT into is responded by BT FW and BT RF REG
3054 * 0x3C != 0x15 => Need to switch BT TRx Mask
3055 */
3056 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3057 "[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n");
3058 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
3059 0x3c, 0x15);
3060
3061 /* BT TRx Mask lock 0x2c[0], 0x30[0] = 0 */
3062 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
3063 0x2c, 0x7c44);
3064 btcoexist->btc_set_bt_reg(btcoexist, BTC_BT_REG_RF,
3065 0x30, 0x7c44);
3066 }
3067
3068 /* Here we need to resend some wifi info to BT
3069 * because bt is reset and loss of the info.
3070 */
3071 if (coex_sta->bt_info_ext & BIT1) {
3072 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3073 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
3074 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED,
3075 &wifi_connected);
3076 if (wifi_connected)
3077 ex_halbtc8723b1ant_media_status_notify(btcoexist,
3078 BTC_MEDIA_CONNECT);
3079 else
3080 ex_halbtc8723b1ant_media_status_notify(btcoexist,
3081 BTC_MEDIA_DISCONNECT);
3082 }
3083
3084 if (coex_sta->bt_info_ext & BIT3) {
3085 if (!btcoexist->manual_control &&
3086 !btcoexist->stop_coex_dm) {
3087 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3088 "[BTCoex], BT ext info bit3 check, set BT NOT ignore Wlan active!!\n");
3089 halbtc8723b1ant_ignore_wlan_act(btcoexist,
3090 FORCE_EXEC,
3091 false);
3092 }
3093 } else {
3094 /* BT already NOT ignore Wlan active, do nothing here.*/
3095 }
3096 if (!btcoexist->auto_report_1ant) {
3097 if (coex_sta->bt_info_ext & BIT4) {
3098 /* BT auto report already enabled, do nothing */
3099 } else {
3100 halbtc8723b1ant_bt_auto_report(btcoexist,
3101 FORCE_EXEC,
3102 true);
3103 }
3104 }
3105 }
3106
3107 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3108 if (bt_info & BT_INFO_8723B_1ANT_B_INQ_PAGE)
3109 coex_sta->c2h_bt_inquiry_page = true;
3110 else
3111 coex_sta->c2h_bt_inquiry_page = false;
3112
3113 coex_sta->num_of_profile = 0;
3114
3115 /* set link exist status */
3116 if (!(bt_info & BT_INFO_8723B_1ANT_B_CONNECTION)) {
3117 coex_sta->bt_link_exist = false;
3118 coex_sta->pan_exist = false;
3119 coex_sta->a2dp_exist = false;
3120 coex_sta->hid_exist = false;
3121 coex_sta->sco_exist = false;
3122
3123 coex_sta->bt_hi_pri_link_exist = false;
3124 } else {
3125 /* connection exists */
3126 coex_sta->bt_link_exist = true;
3127 if (bt_info & BT_INFO_8723B_1ANT_B_FTP) {
3128 coex_sta->pan_exist = true;
3129 coex_sta->num_of_profile++;
3130 } else {
3131 coex_sta->pan_exist = false;
3132 }
3133 if (bt_info & BT_INFO_8723B_1ANT_B_A2DP) {
3134 coex_sta->a2dp_exist = true;
3135 coex_sta->num_of_profile++;
3136 } else {
3137 coex_sta->a2dp_exist = false;
3138 }
3139 if (bt_info & BT_INFO_8723B_1ANT_B_HID) {
3140 coex_sta->hid_exist = true;
3141 coex_sta->num_of_profile++;
3142 } else {
3143 coex_sta->hid_exist = false;
3144 }
3145 if (bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO) {
3146 coex_sta->sco_exist = true;
3147 coex_sta->num_of_profile++;
3148 } else {
3149 coex_sta->sco_exist = false;
3150 }
3151
3152 if ((!coex_sta->hid_exist) &&
3153 (!coex_sta->c2h_bt_inquiry_page) &&
3154 (!coex_sta->sco_exist)) {
3155 if (coex_sta->high_priority_tx +
3156 coex_sta->high_priority_rx >=
3157 160) {
3158 coex_sta->hid_exist = true;
3159 coex_sta->wrong_profile_notification++;
3160 coex_sta->num_of_profile++;
3161 bt_info = bt_info | 0x28;
3162 }
3163 }
3164
3165 /* Add Hi-Pri Tx/Rx counter to avoid false detection */
3166 if (((coex_sta->hid_exist) || (coex_sta->sco_exist)) &&
3167 (coex_sta->high_priority_tx + coex_sta->high_priority_rx >=
3168 160) &&
3169 (!coex_sta->c2h_bt_inquiry_page))
3170 coex_sta->bt_hi_pri_link_exist = true;
3171
3172 if ((bt_info & BT_INFO_8723B_1ANT_B_ACL_BUSY) &&
3173 (coex_sta->num_of_profile == 0)) {
3174 if (coex_sta->low_priority_tx +
3175 coex_sta->low_priority_rx >=
3176 160) {
3177 coex_sta->pan_exist = true;
3178 coex_sta->num_of_profile++;
3179 coex_sta->wrong_profile_notification++;
3180 bt_info = bt_info | 0x88;
3181 }
3182 }
3183 }
3184
3185 halbtc8723b1ant_update_bt_link_info(btcoexist);
3186
3187 /* mask profile bit for connect-ilde identification
3188 * ( for CSR case: A2DP idle --> 0x41)
3189 */
3190 bt_info = bt_info & 0x1f;
3191
3192 if (!(bt_info & BT_INFO_8723B_1ANT_B_CONNECTION)) {
3193 coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
3194 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3195 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!\n");
3196 /* connection exists but no busy */
3197 } else if (bt_info == BT_INFO_8723B_1ANT_B_CONNECTION) {
3198 coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE;
3199 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3200 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
3201 } else if ((bt_info & BT_INFO_8723B_1ANT_B_SCO_ESCO) ||
3202 (bt_info & BT_INFO_8723B_1ANT_B_SCO_BUSY)) {
3203 coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_SCO_BUSY;
3204 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3205 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
3206 } else if (bt_info & BT_INFO_8723B_1ANT_B_ACL_BUSY) {
3207 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY != coex_dm->bt_status)
3208 coex_dm->auto_tdma_adjust = false;
3209
3210 coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_ACL_BUSY;
3211 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3212 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
3213 } else {
3214 coex_dm->bt_status = BT_8723B_1ANT_BT_STATUS_MAX;
3215 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3216 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!\n");
3217 }
3218
3219 if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) ||
3220 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) ||
3221 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status))
3222 bt_busy = true;
3223 else
3224 bt_busy = false;
3225 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
3226
3227 halbtc8723b1ant_run_coexist_mechanism(btcoexist);
3228 }
3229
3230 void ex_halbtc8723b1ant_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
3231 {
3232 struct rtl_priv *rtlpriv = btcoexist->adapter;
3233 u32 u32tmp;
3234 u8 u8tmpa, u8tmpb, u8tmpc;
3235
3236 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3237 "[BTCoex], RF Status notify\n");
3238
3239 if (type == BTC_RF_ON) {
3240 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3241 "[BTCoex], RF is turned ON!!\n");
3242 btcoexist->stop_coex_dm = false;
3243 } else if (type == BTC_RF_OFF) {
3244 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3245 "[BTCoex], RF is turned OFF!!\n");
3246
3247 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3248 0x0, 0x0);
3249 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3250 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
3251 FORCE_EXEC, false, true);
3252
3253 halbtc8723b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3254 btcoexist->stop_coex_dm = true;
3255
3256 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948);
3257 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765);
3258 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x67);
3259 u8tmpc = btcoexist->btc_read_1byte(btcoexist, 0x76e);
3260
3261 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3262 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n",
3263 u32tmp, u8tmpa, u8tmpb, u8tmpc);
3264 }
3265 }
3266
3267 void ex_halbtc8723b1ant_halt_notify(struct btc_coexist *btcoexist)
3268 {
3269 struct rtl_priv *rtlpriv = btcoexist->adapter;
3270
3271 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Halt notify\n");
3272
3273 btcoexist->stop_coex_dm = true;
3274
3275 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT, FORCE_EXEC,
3276 false, true);
3277
3278 halbtc8723b1ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true);
3279
3280 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3281 0x0, 0x0);
3282 halbtc8723b1ant_ps_tdma(btcoexist, FORCE_EXEC, false, 0);
3283
3284 ex_halbtc8723b1ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT);
3285
3286 btcoexist->stop_coex_dm = true;
3287 }
3288
3289 void ex_halbtc8723b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
3290 {
3291 struct rtl_priv *rtlpriv = btcoexist->adapter;
3292
3293 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Pnp notify\n");
3294
3295 if (BTC_WIFI_PNP_SLEEP == pnp_state) {
3296 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3297 "[BTCoex], Pnp notify to SLEEP\n");
3298 halbtc8723b1ant_set_ant_path(btcoexist, BTC_ANT_PATH_BT,
3299 FORCE_EXEC, false, true);
3300 halbtc8723b1ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE,
3301 0x0, 0x0);
3302 halbtc8723b1ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0);
3303 halbtc8723b1ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2);
3304
3305 /* Driver do not leave IPS/LPS when driver is going to sleep, so
3306 * BTCoexistence think wifi is still under IPS/LPS
3307 *
3308 * BT should clear UnderIPS/UnderLPS state to avoid mismatch
3309 * state after wakeup.
3310 */
3311 coex_sta->under_ips = false;
3312 coex_sta->under_lps = false;
3313 btcoexist->stop_coex_dm = true;
3314 } else if (BTC_WIFI_PNP_WAKE_UP == pnp_state) {
3315 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3316 "[BTCoex], Pnp notify to WAKE UP\n");
3317 btcoexist->stop_coex_dm = false;
3318 halbtc8723b1ant_init_hw_config(btcoexist, false, false);
3319 halbtc8723b1ant_init_coex_dm(btcoexist);
3320 halbtc8723b1ant_query_bt_info(btcoexist);
3321 }
3322 }
3323
3324 void ex_halbtc8723b1ant_coex_dm_reset(struct btc_coexist *btcoexist)
3325 {
3326 struct rtl_priv *rtlpriv = btcoexist->adapter;
3327
3328 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3329 "[BTCoex], *****************Coex DM Reset****************\n");
3330
3331 halbtc8723b1ant_init_hw_config(btcoexist, false, false);
3332 halbtc8723b1ant_init_coex_dm(btcoexist);
3333 }
3334
3335 void ex_halbtc8723b1ant_periodical(struct btc_coexist *btcoexist)
3336 {
3337 struct rtl_priv *rtlpriv = btcoexist->adapter;
3338 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info;
3339
3340 RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
3341 "[BTCoex], ==========================Periodical===========================\n");
3342
3343 if (!btcoexist->auto_report_1ant) {
3344 halbtc8723b1ant_query_bt_info(btcoexist);
3345 halbtc8723b1ant_monitor_bt_enable_disable(btcoexist);
3346 } else {
3347 halbtc8723b1ant_monitor_bt_ctr(btcoexist);
3348 halbtc8723b1ant_monitor_wifi_ctr(btcoexist);
3349
3350 if ((coex_sta->high_priority_tx + coex_sta->high_priority_rx < 50) &&
3351 bt_link_info->hid_exist)
3352 bt_link_info->hid_exist = false;
3353
3354 if (btc8723b1ant_is_wifi_status_changed(btcoexist) ||
3355 coex_dm->auto_tdma_adjust) {
3356 halbtc8723b1ant_run_coexist_mechanism(btcoexist);
3357 }
3358 coex_sta->special_pkt_period_cnt++;
3359 }
3360 }