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