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