1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3 *
4 * Copyright(c) 2016 - 2017 Realtek Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 *****************************************************************************/
16 #include "mp_precomp.h"
17
18 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
19
20 #if (RTL8821C_SUPPORT == 1)
21 static u8 *trace_buf = &gl_btc_trace_buf[0];
22
23 const char *const glbt_info_src_8821c_1ant[] = {
24 "BT Info[wifi fw]",
25 "BT Info[bt rsp]",
26 "BT Info[bt auto report]",
27 };
28
29 u32 glcoex_ver_date_8821c_1ant = 20200730;
30 u32 glcoex_ver_8821c_1ant = 0x51;
31 u32 glcoex_ver_btdesired_8821c_1ant = 0x50;
32 u32 glcoex_ver_wldesired_8821c_1ant = 0x170011;
33
34 #if 0
35 static
36 u8 halbtc8821c1ant_bt_rssi_state(struct btc_coexist *btc, u8 level_num,
37 u8 rssi_thresh, u8 rssi_thresh1)
38 {
39 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
40 s32 bt_rssi = 0;
41 u8 bt_rssi_state = coex_sta->pre_bt_rssi_state;
42
43 bt_rssi = coex_sta->bt_rssi;
44
45 if (level_num == 2) {
46 if (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW ||
47 coex_sta->pre_bt_rssi_state ==
48 BTC_RSSI_STATE_STAY_LOW) {
49 if (bt_rssi >= (rssi_thresh +
50 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
51 bt_rssi_state = BTC_RSSI_STATE_HIGH;
52 else
53 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
54 } else {
55 if (bt_rssi < rssi_thresh)
56 bt_rssi_state = BTC_RSSI_STATE_LOW;
57 else
58 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
59 }
60 } else if (level_num == 3) {
61 if (rssi_thresh > rssi_thresh1) {
62 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
63 "[BTCoex], BT Rssi thresh error!!\n");
64 BTC_TRACE(trace_buf);
65 return coex_sta->pre_bt_rssi_state;
66 }
67
68 if (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW ||
69 coex_sta->pre_bt_rssi_state ==
70 BTC_RSSI_STATE_STAY_LOW) {
71 if (bt_rssi >= (rssi_thresh +
72 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
73 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
74 else
75 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW;
76 } else if (coex_sta->pre_bt_rssi_state ==
77 BTC_RSSI_STATE_MEDIUM ||
78 coex_sta->pre_bt_rssi_state ==
79 BTC_RSSI_STATE_STAY_MEDIUM) {
80 if (bt_rssi >= (rssi_thresh1 +
81 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT))
82 bt_rssi_state = BTC_RSSI_STATE_HIGH;
83 else if (bt_rssi < rssi_thresh)
84 bt_rssi_state = BTC_RSSI_STATE_LOW;
85 else
86 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
87 } else {
88 if (bt_rssi < rssi_thresh1)
89 bt_rssi_state = BTC_RSSI_STATE_MEDIUM;
90 else
91 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
92 }
93 }
94
95 coex_sta->pre_bt_rssi_state = bt_rssi_state;
96
97 return bt_rssi_state;
98 }
99 #endif
100
101 #if 0
102 static
103 u8 halbtc8821c1ant_wifi_rssi_state(struct btc_coexist *btc, u8 index,
104 u8 level_num, u8 rssi_thresh,
105 u8 rssi_thresh1)
106 {
107 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
108 s32 wifi_rssi = 0;
109 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index];
110
111 btc->btc_get(btc, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
112
113 if (level_num == 2) {
114 if (coex_sta->pre_wifi_rssi_state[index] ==
115 BTC_RSSI_STATE_LOW ||
116 coex_sta->pre_wifi_rssi_state[index] ==
117 BTC_RSSI_STATE_STAY_LOW) {
118 if (wifi_rssi >= rssi_thresh +
119 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)
120 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
121 else
122 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
123 } else {
124 if (wifi_rssi < rssi_thresh)
125 wifi_rssi_state = BTC_RSSI_STATE_LOW;
126 else
127 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
128 }
129 } else if (level_num == 3) {
130 if (rssi_thresh > rssi_thresh1) {
131 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
132 "[BTCoex], wifi RSSI thresh error!!\n");
133 BTC_TRACE(trace_buf);
134 return coex_sta->pre_wifi_rssi_state[index];
135 }
136
137 if (coex_sta->pre_wifi_rssi_state[index] ==
138 BTC_RSSI_STATE_LOW ||
139 coex_sta->pre_wifi_rssi_state[index] ==
140 BTC_RSSI_STATE_STAY_LOW) {
141 if (wifi_rssi >= rssi_thresh +
142 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)
143 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
144 else
145 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW;
146 } else if (coex_sta->pre_wifi_rssi_state[index] ==
147 BTC_RSSI_STATE_MEDIUM ||
148 coex_sta->pre_wifi_rssi_state[index] ==
149 BTC_RSSI_STATE_STAY_MEDIUM) {
150 if (wifi_rssi >= rssi_thresh1 +
151 BTC_RSSI_COEX_THRESH_TOL_8821C_1ANT)
152 wifi_rssi_state = BTC_RSSI_STATE_HIGH;
153 else if (wifi_rssi < rssi_thresh)
154 wifi_rssi_state = BTC_RSSI_STATE_LOW;
155 else
156 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM;
157 } else {
158 if (wifi_rssi < rssi_thresh1)
159 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM;
160 else
161 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH;
162 }
163 }
164
165 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state;
166
167 return wifi_rssi_state;
168 }
169 #endif
170
171 static void
halbtc8821c1ant_limited_tx(struct btc_coexist * btc,boolean force_exec,boolean tx_limit_en,boolean ampdu_limit_en)172 halbtc8821c1ant_limited_tx(struct btc_coexist *btc, boolean force_exec,
173 boolean tx_limit_en, boolean ampdu_limit_en)
174 {
175 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
176 struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
177 &btc->wifi_link_info_8821c_1ant;
178 boolean wifi_under_b_mode = FALSE;
179
180 /* Force Max Tx retry limit = 8*/
181 if (!coex_sta->wl_tx_limit_en) {
182 coex_sta->wl_0x430_backup = btc->btc_read_4byte(btc, 0x430);
183 coex_sta->wl_0x434_backup = btc->btc_read_4byte(btc, 0x434);
184 coex_sta->wl_0x42a_backup = btc->btc_read_2byte(btc, 0x42a);
185 }
186
187 if (!coex_sta->wl_ampdu_limit_en)
188 coex_sta->wl_0x455_backup = btc->btc_read_1byte(btc, 0x455);
189
190 if (!force_exec && tx_limit_en == coex_sta->wl_tx_limit_en &&
191 ampdu_limit_en == coex_sta->wl_ampdu_limit_en)
192 return;
193
194 coex_sta->wl_tx_limit_en = tx_limit_en;
195 coex_sta->wl_ampdu_limit_en = ampdu_limit_en;
196
197 if (tx_limit_en) {
198 /* Set BT polluted packet on for Tx rate adaptive not
199 * including Tx retry break by PTA, 0x45c[19] =1
200 * Set queue life time to avoid can't reach tx retry limit
201 * if tx is always break by GNT_BT.
202 */
203 btc->btc_write_1byte_bitmask(btc, 0x45e, 0x8, 0x1);
204 btc->btc_write_1byte_bitmask(btc, 0x426, 0xf, 0xf);
205
206 /* Max Tx retry limit = 8*/
207 btc->btc_write_2byte(btc, 0x42a, 0x0808);
208
209 btc->btc_get(btc, BTC_GET_BL_WIFI_UNDER_B_MODE,
210 &wifi_under_b_mode);
211
212 /* Auto rate fallback step within 8 retry*/
213 if (wifi_under_b_mode) {
214 btc->btc_write_4byte(btc, 0x430, 0x1000000);
215 btc->btc_write_4byte(btc, 0x434, 0x1010101);
216 } else {
217 btc->btc_write_4byte(btc, 0x430, 0x1000000);
218 btc->btc_write_4byte(btc, 0x434, 0x4030201);
219 }
220 } else {
221 /* Set BT polluted packet on for Tx rate adaptive not
222 *including Tx retry break by PTA, 0x45c[19] =1
223 */
224 btc->btc_write_1byte_bitmask(btc, 0x45e, 0x8, 0x0);
225 btc->btc_write_1byte_bitmask(btc, 0x426, 0xf, 0x0);
226
227 /* Set queue life time to avoid can't reach tx retry limit
228 * if tx is always break by GNT_BT.
229 */
230 if (wifi_link_info_ext->num_of_active_port == 1)
231 btc->btc_write_1byte_bitmask(btc, 0x426, 0xf, 0x0);
232
233 /* Recovery Max Tx retry limit*/
234 btc->btc_write_2byte(btc, 0x42a, coex_sta->wl_0x42a_backup);
235 btc->btc_write_4byte(btc, 0x430, coex_sta->wl_0x430_backup);
236 btc->btc_write_4byte(btc, 0x434, coex_sta->wl_0x434_backup);
237 }
238
239 if (ampdu_limit_en)
240 btc->btc_write_1byte(btc, 0x455, 0x20);
241 else
242 btc->btc_write_1byte(btc, 0x455, coex_sta->wl_0x455_backup);
243 }
244
245 static void
halbtc8821c1ant_limited_rx(struct btc_coexist * btc,boolean force_exec,boolean rej_ap_agg_pkt,boolean bt_ctrl_agg_buf_size,u8 agg_buf_size)246 halbtc8821c1ant_limited_rx(struct btc_coexist *btc, boolean force_exec,
247 boolean rej_ap_agg_pkt, boolean bt_ctrl_agg_buf_size,
248 u8 agg_buf_size)
249 {
250 #if 1
251 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
252 boolean reject_rx_agg = rej_ap_agg_pkt;
253 boolean bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size;
254 u8 rx_agg_size = agg_buf_size;
255
256 if (!force_exec &&
257 bt_ctrl_agg_buf_size == coex_sta->wl_rxagg_limit_en &&
258 agg_buf_size == coex_sta->wl_rxagg_size)
259 return;
260
261 coex_sta->wl_rxagg_limit_en = bt_ctrl_agg_buf_size;
262 coex_sta->wl_rxagg_size = agg_buf_size;
263
264 /*btc->btc_set(btc, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &reject_rx_agg);*/
265 /* decide BT control aggregation buf size or not */
266 btc->btc_set(btc, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bt_ctrl_rx_agg_size);
267 /* aggregation buf size, only work
268 * when BT control Rx aggregation size
269 */
270 btc->btc_set(btc, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size);
271 /* real update aggregation setting */
272 btc->btc_set(btc, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
273 #endif
274 }
275
276 static void
halbtc8821c1ant_ccklock_action(struct btc_coexist * btc)277 halbtc8821c1ant_ccklock_action(struct btc_coexist *btc)
278 {
279 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
280 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
281 u8 h2c_parameter[2] = {0};
282 static u8 cnt;
283 boolean wifi_busy = FALSE;
284
285 btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
286
287 if (bt_link_info->a2dp_exist && coex_sta->bt_ble_hid_exist) {
288 if (!coex_sta->is_no_wl_5ms_extend) {
289 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
290 "[BTCoex], set h2c 0x69 opcode 12 to turn off 5ms WL slot extend!!\n");
291 BTC_TRACE(trace_buf);
292
293 h2c_parameter[0] = 0xc;
294 h2c_parameter[1] = 0x1;
295 btc->btc_fill_h2c(btc, 0x69, 2, h2c_parameter);
296 coex_sta->is_no_wl_5ms_extend = TRUE;
297 cnt = 0;
298 }
299 return;
300 }
301
302 if (!coex_sta->gl_wifi_busy ||
303 coex_sta->wl_iot_peer == BTC_IOT_PEER_CISCO) {
304 cnt = 0;
305 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
306 "[BTCoex], wifi is not busy or CISCO AP, return!!\n");
307 BTC_TRACE(trace_buf);
308 return;
309 }
310
311 if (!coex_sta->is_no_wl_5ms_extend && coex_sta->force_lps_ctrl &&
312 !coex_sta->cck_lock_ever) {
313 if (coex_sta->wl_fw_dbg_info[7] <= 5 && wifi_busy)
314 cnt++;
315 else
316 cnt = 0;
317
318 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
319 "[BTCoex], 5ms WL slot extend cnt = %d!!\n", cnt);
320 BTC_TRACE(trace_buf);
321
322 if (cnt == 7) {
323 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
324 "[BTCoex], set h2c 0x69 opcode 12 to turn off 5ms WL slot extend!!\n");
325 BTC_TRACE(trace_buf);
326
327 h2c_parameter[0] = 0xc;
328 h2c_parameter[1] = 0x1;
329 btc->btc_fill_h2c(btc, 0x69, 2, h2c_parameter);
330 coex_sta->is_no_wl_5ms_extend = TRUE;
331 cnt = 0;
332 }
333 } else if (coex_sta->is_no_wl_5ms_extend && coex_sta->cck_lock) {
334 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
335 "[BTCoex], set h2c 0x69 opcode 12 to turn on 5ms WL slot extend!!\n");
336 BTC_TRACE(trace_buf);
337
338 h2c_parameter[0] = 0xc;
339 h2c_parameter[1] = 0x0;
340 btc->btc_fill_h2c(btc, 0x69, 2, h2c_parameter);
341 coex_sta->is_no_wl_5ms_extend = FALSE;
342 }
343 }
344
345 static void
halbtc8821c1ant_ccklock_detect(struct btc_coexist * btc)346 halbtc8821c1ant_ccklock_detect(struct btc_coexist *btc)
347 {
348 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
349 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
350 struct wifi_link_info_8821c_1ant *link_info_ext =
351 &btc->wifi_link_info_8821c_1ant;
352 boolean is_cck_lock_rate = FALSE;
353
354 if (coex_dm->bt_status == BTC_BTSTATUS_INQ_PAGE ||
355 coex_sta->is_setup_link)
356 return;
357
358 if (coex_sta->wl_rx_rate <= BTC_CCK_2 ||
359 coex_sta->wl_rts_rx_rate <= BTC_CCK_2)
360 is_cck_lock_rate = TRUE;
361
362 if (link_info_ext->is_connected && coex_sta->gl_wifi_busy &&
363 (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_BUSY ||
364 coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_SCO_BUSY ||
365 coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_SCO_BUSY)) {
366 if (is_cck_lock_rate) {
367 coex_sta->cck_lock = TRUE;
368
369 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
370 "[BTCoex], cck locking...\n");
371 BTC_TRACE(trace_buf);
372 } else {
373 coex_sta->cck_lock = FALSE;
374
375 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
376 "[BTCoex], cck unlock...\n");
377 BTC_TRACE(trace_buf);
378 }
379 } else {
380 coex_sta->cck_lock = FALSE;
381 }
382 }
383
384 static void
halbtc8821c1ant_set_tdma_timer_base(struct btc_coexist * btc,u8 type)385 halbtc8821c1ant_set_tdma_timer_base(struct btc_coexist *btc, u8 type)
386 {
387 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
388 u16 tbtt_interval = 100;
389 u8 h2c_para[2] = {0xb, 0x1};
390
391 btc->btc_get(btc, BTC_GET_U2_BEACON_PERIOD, &tbtt_interval);
392
393 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
394 "[BTCoex], tbtt_interval = %d\n", tbtt_interval);
395 BTC_TRACE(trace_buf);
396
397 /* Add for JIRA coex-256 */
398 if (type == 3 && tbtt_interval >= 100) { /* 50ms-slot */
399 if (coex_sta->tdma_timer_base == 3)
400 return;
401
402 h2c_para[1] = (tbtt_interval / 50) - 1;
403 h2c_para[1] = h2c_para[1] | 0xc0; /* 50ms-slot */
404 coex_sta->tdma_timer_base = 3;
405 } else if (tbtt_interval < 80 && tbtt_interval > 0) {
406 if (coex_sta->tdma_timer_base == 2)
407 return;
408 h2c_para[1] = (100 / tbtt_interval);
409
410 if (100 % tbtt_interval != 0)
411 h2c_para[1] = h2c_para[1] + 1;
412
413 h2c_para[1] = h2c_para[1] & 0x3f;
414 coex_sta->tdma_timer_base = 2;
415 } else if (tbtt_interval >= 180) {
416 if (coex_sta->tdma_timer_base == 1)
417 return;
418 h2c_para[1] = (tbtt_interval / 100);
419
420 if (tbtt_interval % 100 <= 80)
421 h2c_para[1] = h2c_para[1] - 1;
422
423 h2c_para[1] = h2c_para[1] & 0x3f;
424 h2c_para[1] = h2c_para[1] | 0x80;
425 coex_sta->tdma_timer_base = 1;
426 } else {
427 if (coex_sta->tdma_timer_base == 0)
428 return;
429 h2c_para[1] = 0x1;
430 coex_sta->tdma_timer_base = 0;
431 }
432
433 btc->btc_fill_h2c(btc, 0x69, 2, h2c_para);
434
435 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
436 "[BTCoex], %s() h2c_0x69 = 0x%x\n", __func__, h2c_para[1]);
437 BTC_TRACE(trace_buf);
438 }
439
440 static
halbtc8821c1ant_low_penalty_ra(struct btc_coexist * btc,boolean force_exec,boolean low_penalty_ra,u8 thres)441 void halbtc8821c1ant_low_penalty_ra(struct btc_coexist *btc,
442 boolean force_exec, boolean low_penalty_ra,
443 u8 thres)
444 {
445 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
446 static u8 cur_thres;
447
448 if (!force_exec) {
449 if (low_penalty_ra == coex_dm->cur_low_penalty_ra &&
450 thres == cur_thres)
451 return;
452 }
453
454 if (low_penalty_ra)
455 btc->btc_phydm_modify_RA_PCR_threshold(btc, 0, thres);
456 else
457 btc->btc_phydm_modify_RA_PCR_threshold(btc, 0, 0);
458
459 coex_dm->cur_low_penalty_ra = low_penalty_ra;
460 cur_thres = thres;
461 }
462
463 static
halbtc8821c1ant_write_scbd(struct btc_coexist * btc,u16 bitpos,boolean state)464 void halbtc8821c1ant_write_scbd(struct btc_coexist *btc, u16 bitpos,
465 boolean state)
466 {
467 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
468 static u16 originalval = 0x8002, preval;
469
470 if (state)
471 originalval = originalval | bitpos;
472 else
473 originalval = originalval & (~bitpos);
474
475 coex_sta->score_board_WB = originalval;
476
477 if (originalval != preval) {
478 preval = originalval;
479 btc->btc_write_2byte(btc, 0xaa, originalval);
480 } else {
481 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
482 "[BTCoex], %s: return for nochange\n", __func__);
483 BTC_TRACE(trace_buf);
484 }
485 }
486
487 static
halbtc8821c1ant_read_scbd(struct btc_coexist * btc,u16 * score_board_val)488 void halbtc8821c1ant_read_scbd(struct btc_coexist *btc,
489 u16 *score_board_val)
490 {
491 *score_board_val = (btc->btc_read_2byte(btc, 0xaa)) & 0x7fff;
492 }
493
494 static
halbtc8821c1ant_query_bt_info(struct btc_coexist * btc)495 void halbtc8821c1ant_query_bt_info(struct btc_coexist *btc)
496 {
497 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
498 u8 h2c_parameter[1] = {0};
499
500 if (coex_sta->bt_disabled) {
501 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
502 "[BTCoex], No query BT info because BT is disabled!\n");
503 BTC_TRACE(trace_buf);
504 return;
505 }
506
507 h2c_parameter[0] |= BIT(0); /* trigger */
508
509 btc->btc_fill_h2c(btc, 0x61, 1, h2c_parameter);
510
511 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
512 "[BTCoex], WL query BT info!!\n");
513 BTC_TRACE(trace_buf);
514 }
515
516 static
halbtc8821c1ant_enable_gnt_to_gpio(struct btc_coexist * btc,boolean isenable)517 void halbtc8821c1ant_enable_gnt_to_gpio(struct btc_coexist *btc,
518 boolean isenable)
519 {
520 static u8 bit_val[5] = {0, 0, 0, 0, 0};
521 static boolean state;
522
523 if (!btc->dbg_mode)
524 return;
525
526 if (state == isenable)
527 return;
528
529 state = isenable;
530
531 if (isenable) {
532 /* enable GNT_WL, GNT_BT to GPIO for debug */
533 btc->btc_write_1byte_bitmask(btc, 0x73, 0x8, 0x1);
534
535 /* store original value */
536 /*0x66[4] */
537 bit_val[0] = (btc->btc_read_1byte(btc, 0x66) & BIT(4)) >> 4;
538 /*0x66[8] */
539 bit_val[1] = (btc->btc_read_1byte(btc, 0x67) & BIT(0));
540 /*0x40[19] */
541 bit_val[2] = (btc->btc_read_1byte(btc, 0x42) & BIT(3)) >> 3;
542 /*0x64[15] */
543 bit_val[3] = (btc->btc_read_1byte(btc, 0x65) & BIT(7)) >> 7;
544 /*0x70[18] */
545 bit_val[4] = (btc->btc_read_1byte(btc, 0x72) & BIT(2)) >> 2;
546
547 /* switch GPIO Mux */
548 /*0x66[4] = 0 */
549 btc->btc_write_1byte_bitmask(btc, 0x66, BIT(4), 0x0);
550 /*0x66[8] = 0 */
551 btc->btc_write_1byte_bitmask(btc, 0x67, BIT(0), 0x0);
552 /*0x40[19] = 0 */
553 btc->btc_write_1byte_bitmask(btc, 0x42, BIT(3), 0x0);
554 /*0x64[15] = 0 */
555 btc->btc_write_1byte_bitmask(btc, 0x65, BIT(7), 0x0);
556 /*0x70[18] = 0 */
557 btc->btc_write_1byte_bitmask(btc, 0x72, BIT(2), 0x0);
558 } else {
559 btc->btc_write_1byte_bitmask(btc, 0x73, 0x8, 0x0);
560
561 /* Restore original value */
562 /* switch GPIO Mux */
563 /*0x66[4] = 0 */
564 btc->btc_write_1byte_bitmask(btc, 0x66, BIT(4), bit_val[0]);
565 /*0x66[8] = 0 */
566 btc->btc_write_1byte_bitmask(btc, 0x67, BIT(0), bit_val[1]);
567 /*0x40[19] = 0 */
568 btc->btc_write_1byte_bitmask(btc, 0x42, BIT(3), bit_val[2]);
569 /*0x64[15] = 0 */
570 btc->btc_write_1byte_bitmask(btc, 0x65, BIT(7), bit_val[3]);
571 /*0x70[18] = 0 */
572 btc->btc_write_1byte_bitmask(btc, 0x72, BIT(2), bit_val[4]);
573 }
574 }
575
576 static
halbtc8821c1ant_monitor_bt_ctr(struct btc_coexist * btc)577 boolean halbtc8821c1ant_monitor_bt_ctr(struct btc_coexist *btc)
578 {
579 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
580 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
581 u32 reg_hp_txrx, reg_lp_txrx, u32tmp, cnt_bt_all;
582 u32 reg_hp_tx = 0, reg_hp_rx = 0, reg_lp_tx = 0, reg_lp_rx = 0;
583 static u8 cnt_overhead;
584 static u32 cnt_bt_pre = 0;
585 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
586 boolean is_run_coex = FALSE;
587
588 /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
589 /* if (! (btc->btc_read_1byte(btc, 0x76e) & 0x8) ) */
590
591 reg_hp_txrx = 0x770;
592 reg_lp_txrx = 0x774;
593
594 u32tmp = btc->btc_read_4byte(btc, reg_hp_txrx);
595 reg_hp_tx = u32tmp & MASKLWORD;
596 reg_hp_rx = (u32tmp & MASKHWORD) >> 16;
597
598 u32tmp = btc->btc_read_4byte(btc, reg_lp_txrx);
599 reg_lp_tx = u32tmp & MASKLWORD;
600 reg_lp_rx = (u32tmp & MASKHWORD) >> 16;
601
602 coex_sta->high_priority_tx = reg_hp_tx;
603 coex_sta->high_priority_rx = reg_hp_rx;
604 coex_sta->low_priority_tx = reg_lp_tx;
605 coex_sta->low_priority_rx = reg_lp_rx;
606
607 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
608 "[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
609 reg_hp_rx, reg_hp_tx, reg_lp_rx, reg_lp_tx);
610
611 BTC_TRACE(trace_buf);
612
613 /* reset counter */
614 btc->btc_write_1byte(btc, 0x76e, 0xc);
615
616 if (coex_sta->under_lps || coex_sta->under_ips ||
617 (coex_sta->high_priority_tx == 65535 &&
618 coex_sta->high_priority_rx == 65535 &&
619 coex_sta->low_priority_tx == 65535 &&
620 coex_sta->low_priority_rx == 65535))
621 coex_sta->bt_ctr_ok = FALSE;
622 else
623 coex_sta->bt_ctr_ok = TRUE;
624
625 if (!coex_sta->bt_ctr_ok)
626 return FALSE;
627
628 if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_NCON_IDLE) {
629 if (coex_sta->high_priority_rx >= 15) {
630 if (cnt_overhead < 3)
631 cnt_overhead++;
632 if (cnt_overhead == 3)
633 coex_sta->is_hi_pri_rx_overhead = TRUE;
634 } else {
635 if (cnt_overhead > 0)
636 cnt_overhead--;
637 if (cnt_overhead == 0)
638 coex_sta->is_hi_pri_rx_overhead = FALSE;
639 }
640 } else {
641 coex_sta->is_hi_pri_rx_overhead = FALSE;
642 }
643
644 if (coex_sta->low_priority_tx > 1150 && !coex_sta->c2h_bt_inquiry_page)
645 coex_sta->pop_event_cnt++;
646
647 if (bt_link_info->hid_only) {
648 if (coex_sta->low_priority_tx > 100)
649 coex_sta->is_hid_low_pri_tx_overhead = true;
650 else
651 coex_sta->is_hid_low_pri_tx_overhead = false;
652 }
653
654 cnt_bt_all = coex_sta->high_priority_tx +
655 coex_sta->high_priority_rx +
656 coex_sta->low_priority_tx +
657 coex_sta->low_priority_rx;
658
659 if ((cnt_bt_pre > (cnt_bt_all + 50) ||
660 cnt_bt_all > (cnt_bt_pre + 50)) &&
661 coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_NCON_IDLE)
662 is_run_coex = TRUE;
663
664 cnt_bt_pre = cnt_bt_all;
665
666 return is_run_coex;
667 }
668
669 static
halbtc8821c1ant_monitor_wifi_ctr(struct btc_coexist * btc)670 void halbtc8821c1ant_monitor_wifi_ctr(struct btc_coexist *btc)
671 {
672 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
673 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
674 boolean wifi_busy = FALSE, wifi_scan = FALSE;
675 static u8 wl_noisy_count0, wl_noisy_count1 = 3, wl_noisy_count2;
676 u32 cnt_cck, fw_ver = 0;
677 static u8 cnt_ccklocking;
678 u8 h2c_parameter[1] = {0};
679
680 btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
681 btc->btc_get(btc, BTC_GET_BL_WIFI_SCAN, &wifi_scan);
682 btc->btc_get(btc, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
683
684 /* Only enable for windows in old fw version (COEX-308)
685 * because 8821cu H2C 0x69 unknown fail @ linux
686 */
687 if (btc->chip_interface != BTC_INTF_USB ||
688 (fw_ver < 0x170000 && fw_ver < 0x17000c) ||
689 (fw_ver < 0x180000 && fw_ver < 0x180009) ||
690 (fw_ver < 0x190000 && fw_ver < 0x190002)) {
691 /*send h2c to query WL FW dbg info */
692 if (coex_dm->cur_ps_tdma_on) {
693 h2c_parameter[0] = 0x8;
694 btc->btc_fill_h2c(btc, 0x69, 1, h2c_parameter);
695 }
696 }
697
698 coex_sta->crc_ok_cck =
699 btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_OK_CCK);
700 coex_sta->crc_ok_11g =
701 btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_OK_LEGACY);
702 coex_sta->crc_ok_11n =
703 btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_OK_HT);
704 coex_sta->crc_ok_11n_vht =
705 btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_OK_VHT);
706
707 coex_sta->crc_err_cck =
708 btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_ERROR_CCK);
709 coex_sta->crc_err_11g =
710 btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_ERROR_LEGACY);
711 coex_sta->crc_err_11n =
712 btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_ERROR_HT);
713 coex_sta->crc_err_11n_vht =
714 btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CRC32_ERROR_VHT);
715
716 /* CCK lock identification */
717 if (coex_sta->cck_lock)
718 cnt_ccklocking++;
719 else if (cnt_ccklocking != 0)
720 cnt_ccklocking--;
721
722 if (cnt_ccklocking >= 3) {
723 cnt_ccklocking = 3;
724 coex_sta->cck_lock_ever = TRUE;
725 }
726
727 /* WiFi environment noisy identification */
728 cnt_cck = coex_sta->crc_ok_cck + coex_sta->crc_err_cck;
729
730 if (!wifi_busy && !coex_sta->cck_lock) {
731 if (cnt_cck > 250) {
732 if (wl_noisy_count2 < 3)
733 wl_noisy_count2++;
734
735 if (wl_noisy_count2 == 3) {
736 wl_noisy_count0 = 0;
737 wl_noisy_count1 = 0;
738 }
739
740 } else if (cnt_cck < 100) {
741 if (wl_noisy_count0 < 3)
742 wl_noisy_count0++;
743
744 if (wl_noisy_count0 == 3) {
745 wl_noisy_count1 = 0;
746 wl_noisy_count2 = 0;
747 }
748
749 } else {
750 if (wl_noisy_count1 < 3)
751 wl_noisy_count1++;
752
753 if (wl_noisy_count1 == 3) {
754 wl_noisy_count0 = 0;
755 wl_noisy_count2 = 0;
756 }
757 }
758
759 if (wl_noisy_count2 == 3)
760 coex_sta->wl_noisy_level = 2;
761 else if (wl_noisy_count1 == 3)
762 coex_sta->wl_noisy_level = 1;
763 else
764 coex_sta->wl_noisy_level = 0;
765 }
766 }
767
768 static
halbtc8821c1ant_monitor_bt_enable(struct btc_coexist * btc)769 void halbtc8821c1ant_monitor_bt_enable(struct btc_coexist *btc)
770 {
771 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
772 static u32 bt_disable_cnt;
773 boolean bt_active = TRUE, bt_disabled = FALSE;
774 u16 u16tmp;
775
776 /* Read BT on/off status from scoreboard[1],
777 * enable this only if BT patch support this feature
778 */
779 halbtc8821c1ant_read_scbd(btc, &u16tmp);
780 bt_active = u16tmp & BIT(1);
781
782 if (bt_active) {
783 bt_disable_cnt = 0;
784 bt_disabled = FALSE;
785 btc->btc_set(btc, BTC_SET_BL_BT_DISABLE, &bt_disabled);
786 } else {
787 bt_disable_cnt++;
788 if (bt_disable_cnt >= 2) {
789 bt_disabled = TRUE;
790 bt_disable_cnt = 2;
791 }
792
793 btc->btc_set(btc, BTC_SET_BL_BT_DISABLE, &bt_disabled);
794 }
795
796 if (coex_sta->bt_disabled != bt_disabled) {
797 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
798 "[BTCoex], BT is from %s to %s!!\n",
799 (coex_sta->bt_disabled ? "disabled" : "enabled"),
800 (bt_disabled ? "disabled" : "enabled"));
801 BTC_TRACE(trace_buf);
802 coex_sta->bt_disabled = bt_disabled;
803
804 /*for win10 BT disable->enable trigger wifi scan issue */
805 if (!coex_sta->bt_disabled) {
806 coex_sta->is_bt_reenable = TRUE;
807 coex_sta->cnt_bt_reenable = 15;
808 } else {
809 coex_sta->is_bt_reenable = FALSE;
810 coex_sta->cnt_bt_reenable = 0;
811 }
812 }
813 }
814
815 static
halbtc8821c1ant_moniter_wifibt_status(struct btc_coexist * btc)816 boolean halbtc8821c1ant_moniter_wifibt_status(struct btc_coexist *btc)
817 {
818 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
819 struct rfe_type_8821c_1ant *rfe_type = &btc->rfe_type_8821c_1ant;
820 struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
821 &btc->wifi_link_info_8821c_1ant;
822 static boolean pre_wifi_busy, pre_under_4way,
823 pre_bt_off,
824 pre_bt_slave, pre_hid_low_pri_tx_overhead,
825 pre_wifi_under_lps, pre_bt_setup_link,
826 pre_cck_lock, pre_cck_lock_warn;
827 static u8 pre_hid_busy_num, pre_wl_noisy_level;
828 boolean wifi_busy = FALSE, under_4way = FALSE;
829 boolean wifi_connected = FALSE;
830 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
831 static u8 cnt_wifi_busytoidle;
832 u32 num_of_wifi_link = 0, wifi_link_mode = 0;
833 static u32 pre_num_of_wifi_link, pre_wifi_link_mode;
834 boolean miracast_plus_bt = FALSE;
835 u8 lna_lvl = 1;
836
837 btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
838 btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
839 btc->btc_get(btc, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &under_4way);
840
841 if (wifi_busy) {
842 coex_sta->gl_wifi_busy = TRUE;
843 cnt_wifi_busytoidle = 6;
844 } else {
845 if (coex_sta->gl_wifi_busy && cnt_wifi_busytoidle > 0)
846 cnt_wifi_busytoidle--;
847 else if (cnt_wifi_busytoidle == 0)
848 coex_sta->gl_wifi_busy = FALSE;
849 }
850
851 if (coex_sta->bt_disabled != pre_bt_off) {
852 pre_bt_off = coex_sta->bt_disabled;
853
854 if (coex_sta->bt_disabled)
855 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
856 "[BTCoex], BT is disabled !!\n");
857 else
858 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
859 "[BTCoex], BT is enabled !!\n");
860
861 BTC_TRACE(trace_buf);
862
863 coex_sta->bt_coex_supported_feature = 0;
864 coex_sta->bt_coex_supported_version = 0;
865 coex_sta->bt_ble_scan_type = 0;
866 coex_sta->bt_ble_scan_para[0] = 0;
867 coex_sta->bt_ble_scan_para[1] = 0;
868 coex_sta->bt_ble_scan_para[2] = 0;
869 coex_sta->bt_reg_vendor_ac = 0xffff;
870 coex_sta->bt_reg_vendor_ae = 0xffff;
871 coex_sta->bt_a2dp_vendor_id = 0;
872 coex_sta->bt_a2dp_device_name = 0;
873 btc->bt_info.bt_get_fw_ver = 0;
874 return TRUE;
875 }
876
877 num_of_wifi_link = wifi_link_info_ext->num_of_active_port;
878
879 if (num_of_wifi_link != pre_num_of_wifi_link) {
880 pre_num_of_wifi_link = num_of_wifi_link;
881
882 if (wifi_link_info_ext->is_p2p_connected) {
883 if (bt_link_info->bt_link_exist)
884 miracast_plus_bt = TRUE;
885 else
886 miracast_plus_bt = FALSE;
887
888 btc->btc_set(btc, BTC_SET_BL_MIRACAST_PLUS_BT,
889 &miracast_plus_bt);
890 }
891 return TRUE;
892 }
893
894 wifi_link_mode = btc->wifi_link_info.link_mode;
895 if (wifi_link_mode != pre_wifi_link_mode) {
896 pre_wifi_link_mode = wifi_link_mode;
897 return TRUE;
898 }
899
900 if (wifi_connected) {
901 if (wifi_busy != pre_wifi_busy) {
902 pre_wifi_busy = wifi_busy;
903 return TRUE;
904 }
905 if (under_4way != pre_under_4way) {
906 pre_under_4way = under_4way;
907 return TRUE;
908 }
909 if (coex_sta->wl_noisy_level != pre_wl_noisy_level) {
910 pre_wl_noisy_level = coex_sta->wl_noisy_level;
911 return TRUE;
912 }
913 if (coex_sta->under_lps != pre_wifi_under_lps) {
914 pre_wifi_under_lps = coex_sta->under_lps;
915 if (coex_sta->under_lps)
916 return TRUE;
917 }
918 if (coex_sta->cck_lock != pre_cck_lock) {
919 pre_cck_lock = coex_sta->cck_lock;
920 return TRUE;
921 }
922 if (coex_sta->cck_lock_warn != pre_cck_lock_warn) {
923 pre_cck_lock_warn = coex_sta->cck_lock_warn;
924 return TRUE;
925 }
926 }
927
928 if (!coex_sta->bt_disabled) {
929 #if 0
930 if (coex_sta->acl_busy != pre_bt_acl_busy) {
931 pre_bt_acl_busy = coex_sta->acl_busy;
932 btc->btc_set(btc, BTC_SET_BL_BT_LNA_CONSTRAIN_LEVEL,
933 &lna_lvl);
934 return TRUE;
935 }
936 #endif
937 if (coex_sta->hid_busy_num != pre_hid_busy_num) {
938 pre_hid_busy_num = coex_sta->hid_busy_num;
939 return TRUE;
940 }
941
942 if (bt_link_info->slave_role != pre_bt_slave) {
943 pre_bt_slave = bt_link_info->slave_role;
944 return TRUE;
945 }
946
947 if (pre_hid_low_pri_tx_overhead !=
948 coex_sta->is_hid_low_pri_tx_overhead) {
949 pre_hid_low_pri_tx_overhead =
950 coex_sta->is_hid_low_pri_tx_overhead;
951 return TRUE;
952 }
953
954 if (pre_bt_setup_link != coex_sta->is_setup_link) {
955 pre_bt_setup_link = coex_sta->is_setup_link;
956 return TRUE;
957 }
958 }
959 return FALSE;
960 }
961
962 static
halbtc8821c1ant_update_wifi_link_info(struct btc_coexist * btc,u8 reason)963 void halbtc8821c1ant_update_wifi_link_info(struct btc_coexist *btc, u8 reason)
964 {
965 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
966 struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
967 &btc->wifi_link_info_8821c_1ant;
968 struct btc_wifi_link_info wifi_link_info;
969 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
970 u8 wifi_central_chnl = 0, num_of_wifi_link = 0;
971 boolean isunder5G = FALSE, ismcc25g = FALSE, isp2pconnected = FALSE;
972 u32 wifi_link_status = 0;
973
974 btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED,
975 &wifi_link_info_ext->is_connected);
976
977 btc->btc_get(btc, BTC_GET_U4_WIFI_LINK_STATUS, &wifi_link_status);
978 wifi_link_info_ext->port_connect_status = wifi_link_status & 0xffff;
979
980 btc->btc_get(btc, BTC_GET_BL_WIFI_LINK_INFO, &wifi_link_info);
981 btc->wifi_link_info = wifi_link_info;
982
983 btc->btc_get(btc, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifi_central_chnl);
984 coex_sta->wl_center_channel = wifi_central_chnl;
985
986 /* Check scan/connect/special-pkt action first */
987 switch (reason) {
988 case BT_8821C_1ANT_RSN_5GSCANSTART:
989 case BT_8821C_1ANT_RSN_5GSWITCHBAND:
990 case BT_8821C_1ANT_RSN_5GCONSTART:
991 isunder5G = TRUE;
992 break;
993 case BT_8821C_1ANT_RSN_2GSCANSTART:
994 case BT_8821C_1ANT_RSN_2GSWITCHBAND:
995 case BT_8821C_1ANT_RSN_2GCONSTART:
996 isunder5G = FALSE;
997 break;
998 case BT_8821C_1ANT_RSN_2GCONFINISH:
999 case BT_8821C_1ANT_RSN_5GCONFINISH:
1000 case BT_8821C_1ANT_RSN_2GMEDIA:
1001 case BT_8821C_1ANT_RSN_5GMEDIA:
1002 case BT_8821C_1ANT_RSN_BTINFO:
1003 case BT_8821C_1ANT_RSN_PERIODICAL:
1004 case BT_8821C_1ANT_RSN_5GSPECIALPKT:
1005 case BT_8821C_1ANT_RSN_2GSPECIALPKT:
1006 default:
1007 switch (wifi_link_info.link_mode) {
1008 case BTC_LINK_5G_MCC_GO_STA:
1009 case BTC_LINK_5G_MCC_GC_STA:
1010 case BTC_LINK_5G_SCC_GO_STA:
1011 case BTC_LINK_5G_SCC_GC_STA:
1012 isunder5G = TRUE;
1013 break;
1014 case BTC_LINK_2G_MCC_GO_STA:
1015 case BTC_LINK_2G_MCC_GC_STA:
1016 case BTC_LINK_2G_SCC_GO_STA:
1017 case BTC_LINK_2G_SCC_GC_STA:
1018 isunder5G = FALSE;
1019 break;
1020 case BTC_LINK_25G_MCC_GO_STA:
1021 case BTC_LINK_25G_MCC_GC_STA:
1022 isunder5G = FALSE;
1023 ismcc25g = TRUE;
1024 break;
1025 case BTC_LINK_ONLY_STA:
1026 if (wifi_link_info.sta_center_channel > 14)
1027 isunder5G = TRUE;
1028 else
1029 isunder5G = FALSE;
1030 break;
1031 case BTC_LINK_ONLY_GO:
1032 case BTC_LINK_ONLY_GC:
1033 case BTC_LINK_ONLY_AP:
1034 default:
1035 if (wifi_link_info.p2p_center_channel > 14)
1036 isunder5G = TRUE;
1037 else
1038 isunder5G = FALSE;
1039
1040 break;
1041 }
1042 break;
1043 }
1044
1045 wifi_link_info_ext->is_all_under_5g = isunder5G;
1046 wifi_link_info_ext->is_mcc_25g = ismcc25g;
1047
1048 if (wifi_link_status & WIFI_STA_CONNECTED)
1049 num_of_wifi_link++;
1050
1051 if (wifi_link_status & WIFI_AP_CONNECTED)
1052 num_of_wifi_link++;
1053
1054 if (wifi_link_status & WIFI_P2P_GO_CONNECTED) {
1055 num_of_wifi_link++;
1056 isp2pconnected = TRUE;
1057 }
1058
1059 if (wifi_link_status & WIFI_P2P_GC_CONNECTED) {
1060 num_of_wifi_link++;
1061 isp2pconnected = TRUE;
1062 }
1063
1064 wifi_link_info_ext->num_of_active_port = num_of_wifi_link;
1065 wifi_link_info_ext->is_p2p_connected = isp2pconnected;
1066
1067 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1068 "[BTCoex], wifi_link_info: link_mode=%d, STA_Ch=%d, P2P_Ch=%d, AnyClient_Join_Go=%d !\n",
1069 btc->wifi_link_info.link_mode,
1070 btc->wifi_link_info.sta_center_channel,
1071 btc->wifi_link_info.p2p_center_channel,
1072 btc->wifi_link_info.bany_client_join_go);
1073 BTC_TRACE(trace_buf);
1074
1075 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1076 "[BTCoex], wifi_link_info: center_ch=%d, is_all_under_5g=%d, is_mcc_25g=%d!\n",
1077 coex_sta->wl_center_channel,
1078 wifi_link_info_ext->is_all_under_5g,
1079 wifi_link_info_ext->is_mcc_25g);
1080 BTC_TRACE(trace_buf);
1081
1082 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1083 "[BTCoex], wifi_link_info: port_connect_status=0x%x, active_port_cnt=%d, P2P_Connect=%d!\n",
1084 wifi_link_info_ext->port_connect_status,
1085 wifi_link_info_ext->num_of_active_port,
1086 wifi_link_info_ext->is_p2p_connected);
1087 BTC_TRACE(trace_buf);
1088
1089 switch (reason) {
1090 case BT_8821C_1ANT_RSN_2GSCANSTART:
1091 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1092 "[BTCoex], Update reason = %s\n", "2GSCANSTART");
1093 break;
1094 case BT_8821C_1ANT_RSN_5GSCANSTART:
1095 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1096 "[BTCoex], Update reason = %s\n", "5GSCANSTART");
1097 break;
1098 case BT_8821C_1ANT_RSN_SCANFINISH:
1099 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1100 "[BTCoex], Update reason = %s\n", "SCANFINISH");
1101 break;
1102 case BT_8821C_1ANT_RSN_2GSWITCHBAND:
1103 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1104 "[BTCoex], Update reason = %s\n", "2GSWITCHBAND");
1105 break;
1106 case BT_8821C_1ANT_RSN_5GSWITCHBAND:
1107 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1108 "[BTCoex], Update reason = %s\n", "5GSWITCHBAND");
1109 break;
1110 case BT_8821C_1ANT_RSN_2GCONSTART:
1111 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1112 "[BTCoex], Update reason = %s\n", "2GCONNECTSTART");
1113 break;
1114 case BT_8821C_1ANT_RSN_5GCONSTART:
1115 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1116 "[BTCoex], Update reason = %s\n", "5GCONNECTSTART");
1117 break;
1118 case BT_8821C_1ANT_RSN_2GCONFINISH:
1119 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1120 "[BTCoex], Update reason = %s\n",
1121 "2GCONNECTFINISH");
1122 break;
1123 case BT_8821C_1ANT_RSN_5GCONFINISH:
1124 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1125 "[BTCoex], Update reason = %s\n",
1126 "5GCONNECTFINISH");
1127 break;
1128 case BT_8821C_1ANT_RSN_2GMEDIA:
1129 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1130 "[BTCoex], Update reason = %s\n", "2GMEDIASTATUS");
1131 break;
1132 case BT_8821C_1ANT_RSN_5GMEDIA:
1133 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1134 "[BTCoex], Update reason = %s\n", "5GMEDIASTATUS");
1135 break;
1136 case BT_8821C_1ANT_RSN_MEDIADISCON:
1137 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1138 "[BTCoex], Update reason = %s\n",
1139 "MEDIADISCONNECT");
1140 break;
1141 case BT_8821C_1ANT_RSN_2GSPECIALPKT:
1142 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1143 "[BTCoex], Update reason = %s\n", "2GSPECIALPKT");
1144 break;
1145 case BT_8821C_1ANT_RSN_5GSPECIALPKT:
1146 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1147 "[BTCoex], Update reason = %s\n", "5GSPECIALPKT");
1148 break;
1149 case BT_8821C_1ANT_RSN_BTINFO:
1150 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1151 "[BTCoex], Update reason = %s\n", "BTINFO");
1152 break;
1153 case BT_8821C_1ANT_RSN_PERIODICAL:
1154 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1155 "[BTCoex], Update reason = %s\n", "PERIODICAL");
1156 break;
1157 case BT_8821C_1ANT_RSN_PNP:
1158 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1159 "[BTCoex], Update reason = %s\n", "PNPNotify");
1160 break;
1161 default:
1162 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1163 "[BTCoex], Update reason = %s\n", "UNKNOWN");
1164 break;
1165 }
1166
1167 BTC_TRACE(trace_buf);
1168
1169 if (btc->manual_control || btc->stop_coex_dm)
1170 return;
1171
1172 if (wifi_link_info_ext->is_all_under_5g || num_of_wifi_link == 0 ||
1173 coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_NCON_IDLE) {
1174 halbtc8821c1ant_low_penalty_ra(btc, NM_EXCU, FALSE, 0);
1175 halbtc8821c1ant_limited_tx(btc, NM_EXCU, FALSE, FALSE);
1176 halbtc8821c1ant_limited_rx(btc, NM_EXCU, FALSE, TRUE, 64);
1177 } else if (wifi_link_info_ext->num_of_active_port > 1) {
1178 halbtc8821c1ant_low_penalty_ra(btc, NM_EXCU, TRUE, 30);
1179 halbtc8821c1ant_limited_tx(btc, NM_EXCU, FALSE, TRUE);
1180 halbtc8821c1ant_limited_rx(btc, NM_EXCU, FALSE, TRUE, 16);
1181 } else {
1182 halbtc8821c1ant_low_penalty_ra(btc, NM_EXCU, TRUE, 15);
1183
1184 if (coex_sta->hid_exist || coex_sta->hid_pair_cnt > 0 ||
1185 coex_sta->sco_exist) {
1186 halbtc8821c1ant_limited_tx(btc, NM_EXCU, TRUE, TRUE);
1187 if (coex_sta->bt_ble_hid_exist &&
1188 coex_sta->wl_iot_peer != BTC_IOT_PEER_ATHEROS)
1189 halbtc8821c1ant_limited_rx(btc, NM_EXCU, FALSE,
1190 TRUE, 4);
1191 } else {
1192 halbtc8821c1ant_limited_tx(btc, NM_EXCU, TRUE, FALSE);
1193 halbtc8821c1ant_limited_rx(btc, NM_EXCU, FALSE, TRUE,
1194 64);
1195 }
1196
1197 }
1198 /* coex-276 P2P-Go beacon request can't release issue
1199 * Only PCIe/USB can set 0x454[6] = 1 to solve this issue,
1200 * WL SDIO/USB interface need driver support.
1201 */
1202 #ifdef PLATFORM_WINDOWS
1203 if (btc->chip_interface != BTC_INTF_SDIO)
1204 btc->btc_write_1byte_bitmask(btc, 0x454, BIT(6), 0x1);
1205 else
1206 btc->btc_write_1byte_bitmask(btc, 0x454, BIT(6), 0x0);
1207 #endif
1208 }
1209
1210 static
halbtc8821c1ant_update_bt_link_info(struct btc_coexist * btc)1211 void halbtc8821c1ant_update_bt_link_info(struct btc_coexist *btc)
1212 {
1213 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
1214 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
1215 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
1216 boolean bt_busy = FALSE, increase_scan_dev_num = FALSE;
1217 u32 val = 0;
1218 static u8 pre_num_of_profile, cur_num_of_profile, cnt, ble_cnt;
1219
1220 if (++ble_cnt >= 3)
1221 ble_cnt = 0;
1222
1223 if (coex_sta->is_ble_scan_en && ble_cnt == 0) {
1224 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1225 "[BTCoex], BT ext info bit4 check, query BLE Scan type!!\n");
1226 BTC_TRACE(trace_buf);
1227 coex_sta->bt_ble_scan_type =
1228 btc->btc_get_ble_scan_type_from_bt(btc);
1229
1230 if ((coex_sta->bt_ble_scan_type & 0x1) == 0x1)
1231 coex_sta->bt_ble_scan_para[0] =
1232 btc->btc_get_ble_scan_para_from_bt(btc, 0x1);
1233 if ((coex_sta->bt_ble_scan_type & 0x2) == 0x2)
1234 coex_sta->bt_ble_scan_para[1] =
1235 btc->btc_get_ble_scan_para_from_bt(btc, 0x2);
1236 if ((coex_sta->bt_ble_scan_type & 0x4) == 0x4)
1237 coex_sta->bt_ble_scan_para[2] =
1238 btc->btc_get_ble_scan_para_from_bt(btc, 0x4);
1239 }
1240
1241 coex_sta->num_of_profile = 0;
1242
1243 /* set link exist status */
1244 if (!(coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_CONNECTION)) {
1245 coex_sta->bt_link_exist = FALSE;
1246 coex_sta->pan_exist = FALSE;
1247 coex_sta->a2dp_exist = FALSE;
1248 coex_sta->hid_exist = FALSE;
1249 coex_sta->sco_exist = FALSE;
1250 coex_sta->msft_mr_exist = FALSE;
1251 } else { /* connection exists */
1252 coex_sta->bt_link_exist = TRUE;
1253 if (coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_FTP) {
1254 coex_sta->pan_exist = TRUE;
1255 coex_sta->num_of_profile++;
1256 } else {
1257 coex_sta->pan_exist = FALSE;
1258 }
1259
1260 if (coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_A2DP) {
1261 coex_sta->a2dp_exist = TRUE;
1262 coex_sta->num_of_profile++;
1263 } else {
1264 coex_sta->a2dp_exist = FALSE;
1265 }
1266
1267 if (coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_HID) {
1268 coex_sta->hid_exist = TRUE;
1269 coex_sta->num_of_profile++;
1270 } else {
1271 coex_sta->hid_exist = FALSE;
1272 }
1273
1274 if (coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_SCO_ESCO) {
1275 coex_sta->sco_exist = TRUE;
1276 coex_sta->num_of_profile++;
1277 } else {
1278 coex_sta->sco_exist = FALSE;
1279 }
1280 #if 0
1281 if (coex_sta->hid_busy_num == 0 &&
1282 coex_sta->hid_pair_cnt > 0 &&
1283 coex_sta->low_priority_tx > 1000 &&
1284 coex_sta->low_priority_rx > 1000 &&
1285 !coex_sta->c2h_bt_inquiry_page)
1286 coex_sta->msft_mr_exist = true;
1287 else
1288 coex_sta->msft_mr_exist = false;
1289 #endif
1290 }
1291
1292 bt_link_info->bt_link_exist = coex_sta->bt_link_exist;
1293 bt_link_info->sco_exist = coex_sta->sco_exist;
1294 bt_link_info->a2dp_exist = coex_sta->a2dp_exist;
1295 bt_link_info->pan_exist = coex_sta->pan_exist;
1296 bt_link_info->hid_exist = coex_sta->hid_exist;
1297 bt_link_info->acl_busy = coex_sta->acl_busy;
1298
1299 /* check if Sco only */
1300 if (bt_link_info->sco_exist &&
1301 !bt_link_info->a2dp_exist &&
1302 !bt_link_info->pan_exist &&
1303 !bt_link_info->hid_exist)
1304 bt_link_info->sco_only = TRUE;
1305 else
1306 bt_link_info->sco_only = FALSE;
1307
1308 /* check if A2dp only */
1309 if (!bt_link_info->sco_exist &&
1310 bt_link_info->a2dp_exist &&
1311 !bt_link_info->pan_exist &&
1312 !bt_link_info->hid_exist)
1313 bt_link_info->a2dp_only = TRUE;
1314 else
1315 bt_link_info->a2dp_only = FALSE;
1316
1317 /* check if Pan only */
1318 if (!bt_link_info->sco_exist &&
1319 !bt_link_info->a2dp_exist &&
1320 bt_link_info->pan_exist &&
1321 !bt_link_info->hid_exist)
1322 bt_link_info->pan_only = TRUE;
1323 else
1324 bt_link_info->pan_only = FALSE;
1325
1326 /* check if Hid only */
1327 if (!bt_link_info->sco_exist &&
1328 !bt_link_info->a2dp_exist &&
1329 !bt_link_info->pan_exist &&
1330 bt_link_info->hid_exist)
1331 bt_link_info->hid_only = TRUE;
1332 else
1333 bt_link_info->hid_only = FALSE;
1334
1335 if (coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_INQ_PAGE) {
1336 coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_INQ_PAGE;
1337 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1338 "[BTCoex], BtInfoNotify(), BT Inq/page!!!\n");
1339 } else if (!(coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_CONNECTION)) {
1340 coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_NCON_IDLE;
1341 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1342 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n");
1343 } else if (coex_sta->bt_info_lb2 == BT_INFO_8821C_1ANT_B_CONNECTION) {
1344 /* connection exists but no busy */
1345
1346 if (coex_sta->msft_mr_exist) {
1347 coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_ACL_BUSY;
1348 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1349 "[BTCoex], BtInfoNotify(), BT ACL busy!!\n");
1350 } else {
1351 coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_CON_IDLE;
1352 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1353 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n");
1354 }
1355 } else if (((coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_SCO_ESCO) ||
1356 (coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_SCO_BUSY)) &&
1357 (coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_ACL_BUSY)) {
1358 coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_ACL_SCO_BUSY;
1359 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1360 "[BTCoex], BtInfoNotify(), BT ACL SCO busy!!!\n");
1361 } else if ((coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_SCO_ESCO) ||
1362 (coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_SCO_BUSY)) {
1363 coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_SCO_BUSY;
1364 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1365 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n");
1366 } else if (coex_sta->bt_info_lb2 & BT_INFO_8821C_1ANT_B_ACL_BUSY) {
1367 coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_ACL_BUSY;
1368 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1369 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n");
1370 } else {
1371 coex_dm->bt_status = BT_8821C_1ANT_BSTATUS_MAX;
1372 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1373 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n");
1374 }
1375
1376 BTC_TRACE(trace_buf);
1377
1378 if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_BUSY ||
1379 coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_SCO_BUSY ||
1380 coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_SCO_BUSY) {
1381 bt_busy = TRUE;
1382 increase_scan_dev_num = TRUE;
1383 } else {
1384 bt_busy = FALSE;
1385 increase_scan_dev_num = FALSE;
1386 }
1387
1388 btc->btc_set(btc, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy);
1389 btc->btc_set(btc, BTC_SET_BL_INC_SCAN_DEV_NUM, &increase_scan_dev_num);
1390
1391 cur_num_of_profile = coex_sta->num_of_profile;
1392
1393 if (cur_num_of_profile != pre_num_of_profile)
1394 cnt = 2;
1395
1396 if (bt_link_info->a2dp_exist && cnt > 0) {
1397 cnt--;
1398 if (coex_sta->bt_a2dp_vendor_id == 0 &&
1399 coex_sta->bt_a2dp_device_name == 0) {
1400 btc->btc_get(btc, BTC_GET_U4_BT_DEVICE_INFO, &val);
1401
1402 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1403 "[BTCoex], BtInfoNotify(), get BT DEVICE_INFO = %x\n",
1404 val);
1405 BTC_TRACE(trace_buf);
1406
1407 coex_sta->bt_a2dp_vendor_id = (u8)(val & 0xff);
1408 coex_sta->bt_a2dp_device_name = (val & 0xffffff00) >> 8;
1409
1410 btc->btc_get(btc, BTC_GET_U4_BT_A2DP_FLUSH_VAL, &val);
1411 coex_sta->bt_a2dp_flush_time = val;
1412 }
1413 } else if (!bt_link_info->a2dp_exist) {
1414 coex_sta->bt_a2dp_vendor_id = 0;
1415 coex_sta->bt_a2dp_device_name = 0;
1416 coex_sta->bt_a2dp_flush_time = 0;
1417 }
1418
1419 pre_num_of_profile = coex_sta->num_of_profile;
1420 }
1421
1422 static
halbtc8821c1ant_update_wifi_ch_info(struct btc_coexist * btc,u8 type)1423 void halbtc8821c1ant_update_wifi_ch_info(struct btc_coexist *btc, u8 type)
1424 {
1425 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
1426 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
1427 struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
1428 &btc->wifi_link_info_8821c_1ant;
1429 u8 h2c_parameter[3] = {0}, i;
1430 u32 wifi_bw;
1431 u8 wl_ch = 0;
1432 u8 wl_5g_ch[] = {0};
1433 u8 bt_skip_ch[] = {0};
1434 u8 bt_skip_span[] = {0};
1435
1436 if (btc->manual_control)
1437 return;
1438
1439 btc->btc_get(btc, BTC_GET_U4_WIFI_BW, &wifi_bw);
1440
1441 if (btc->stop_coex_dm || btc->wl_rf_state_off) {
1442 wl_ch = 0;
1443 } else if (type != BTC_MEDIA_DISCONNECT ||
1444 (type == BTC_MEDIA_DISCONNECT &&
1445 wifi_link_info_ext->num_of_active_port > 0)) {
1446 if (wifi_link_info_ext->num_of_active_port == 1) {
1447 if (wifi_link_info_ext->is_p2p_connected)
1448 wl_ch = btc->wifi_link_info.p2p_center_channel;
1449 else
1450 wl_ch = btc->wifi_link_info.sta_center_channel;
1451 } else { /* port > 2 */
1452 if (btc->wifi_link_info.p2p_center_channel > 14 &&
1453 btc->wifi_link_info.sta_center_channel > 14)
1454 wl_ch = btc->wifi_link_info.p2p_center_channel;
1455 else if (btc->wifi_link_info.p2p_center_channel <= 14)
1456 wl_ch = btc->wifi_link_info.p2p_center_channel;
1457 else if (btc->wifi_link_info.sta_center_channel <= 14)
1458 wl_ch = btc->wifi_link_info.sta_center_channel;
1459 }
1460 }
1461
1462 if (wl_ch > 0) {
1463 if (wl_ch <= 14) {
1464 /* no AFH notify for shared-antenna */
1465 h2c_parameter[0] = 0x0;
1466 h2c_parameter[1] = 0x0;
1467 h2c_parameter[2] = 0x0;
1468 #if 0
1469 h2c_parameter[0] = 0x1;
1470 h2c_parameter[1] = wl_ch;
1471
1472 if (wifi_bw == BTC_WIFI_BW_HT40)
1473 h2c_parameter[2] = 0x36;
1474 else
1475 h2c_parameter[2] = 0x24;
1476 #endif
1477 }
1478 }
1479
1480 /* Only send mailbox if ch info change */
1481 if (coex_dm->wifi_chnl_info[0] != h2c_parameter[0] &&
1482 coex_dm->wifi_chnl_info[1] != h2c_parameter[1] &&
1483 coex_dm->wifi_chnl_info[2] != h2c_parameter[2]) {
1484
1485 coex_dm->wifi_chnl_info[0] = h2c_parameter[0];
1486 coex_dm->wifi_chnl_info[1] = h2c_parameter[1];
1487 coex_dm->wifi_chnl_info[2] = h2c_parameter[2];
1488 btc->btc_fill_h2c(btc, 0x66, 3, h2c_parameter);
1489 }
1490
1491 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1492 "[BTCoex], para[0:2] = 0x%x 0x%x 0x%x\n", h2c_parameter[0],
1493 h2c_parameter[1], h2c_parameter[2]);
1494 BTC_TRACE(trace_buf);
1495 }
1496
1497 static u32
halbtc8821c1ant_wait_indirect_reg_ready(struct btc_coexist * btc)1498 halbtc8821c1ant_wait_indirect_reg_ready(struct btc_coexist *btc)
1499 {
1500 u32 delay_count = 0;
1501
1502 /* wait for ready bit before access 0x1700 */
1503 while (1) {
1504 if ((btc->btc_read_1byte(btc, 0x1703) & BIT(5)) == 0) {
1505 delay_ms(10);
1506 if (++delay_count >= 10)
1507 break;
1508 } else {
1509 break;
1510 }
1511 }
1512
1513 return delay_count;
1514 }
1515
1516 static
halbtc8821c1ant_read_indirect_reg(struct btc_coexist * btc,u16 reg_addr)1517 u32 halbtc8821c1ant_read_indirect_reg(struct btc_coexist *btc, u16 reg_addr)
1518 {
1519 u32 j = 0, delay_count = 0;
1520
1521 /* wait for ready bit before access 0x1700 */
1522 halbtc8821c1ant_wait_indirect_reg_ready(btc);
1523
1524 btc->btc_write_4byte(btc, 0x1700, 0x800F0000 | reg_addr);
1525
1526 return btc->btc_read_4byte(btc, 0x1708);
1527 }
1528
1529 static
halbtc8821c1ant_write_indirect_reg(struct btc_coexist * btc,u16 reg_addr,u32 bit_mask,u32 reg_value)1530 void halbtc8821c1ant_write_indirect_reg(struct btc_coexist *btc, u16 reg_addr,
1531 u32 bit_mask, u32 reg_value)
1532 {
1533 u32 val, i = 0, j = 0, bitpos = 0, delay_count = 0;
1534
1535 if (bit_mask == 0x0)
1536 return;
1537
1538 if (bit_mask == 0xffffffff) {
1539 /* wait for ready bit before access 0x1700/0x1704 */
1540 halbtc8821c1ant_wait_indirect_reg_ready(btc);
1541
1542 /* put write data */
1543 btc->btc_write_4byte(btc, 0x1704, reg_value);
1544
1545 btc->btc_write_4byte(btc, 0x1700, 0xc00F0000 | reg_addr);
1546 } else {
1547 for (i = 0; i <= 31; i++) {
1548 if (((bit_mask >> i) & 0x1) == 0x1) {
1549 bitpos = i;
1550 break;
1551 }
1552 }
1553
1554 /* read back register value before write */
1555 val = halbtc8821c1ant_read_indirect_reg(btc, reg_addr);
1556 val = (val & (~bit_mask)) | (reg_value << bitpos);
1557
1558 /* wait for ready bit before access 0x1700/0x1704 */
1559 halbtc8821c1ant_wait_indirect_reg_ready(btc);
1560
1561 /* put write data */
1562 btc->btc_write_4byte(btc, 0x1704, val);
1563 btc->btc_write_4byte(btc, 0x1700, 0xc00F0000 | reg_addr);
1564 }
1565 }
1566
1567 static
halbtc8821c1ant_ltecoex_enable(struct btc_coexist * btc,boolean enable)1568 void halbtc8821c1ant_ltecoex_enable(struct btc_coexist *btc, boolean enable)
1569 {
1570 u8 val;
1571
1572 /* 0x38[7] */
1573 val = (enable) ? 1 : 0;
1574 halbtc8821c1ant_write_indirect_reg(btc, 0x38, BIT(7), val);
1575 }
1576
1577 static
halbtc8821c1ant_ltecoex_table(struct btc_coexist * btc,u8 table_type,u16 val)1578 void halbtc8821c1ant_ltecoex_table(struct btc_coexist *btc, u8 table_type,
1579 u16 val)
1580 {
1581 u16 reg_addr = 0x0000;
1582
1583 switch (table_type) {
1584 case BT_8821C_1ANT_CTT_WL_VS_LTE:
1585 reg_addr = 0xa0;
1586 break;
1587 case BT_8821C_1ANT_CTT_BT_VS_LTE:
1588 reg_addr = 0xa4;
1589 break;
1590 }
1591
1592 /* 0xa0[15:0] or 0xa4[15:0] */
1593 if (reg_addr != 0x0000)
1594 halbtc8821c1ant_write_indirect_reg(btc, reg_addr, 0xffff, val);
1595 }
1596
1597 static
halbtc8821c1ant_coex_ctrl_owner(struct btc_coexist * btc,boolean wifi_control)1598 void halbtc8821c1ant_coex_ctrl_owner(struct btc_coexist *btc,
1599 boolean wifi_control)
1600 {
1601 u8 val;
1602
1603 /* 0x70[26] */
1604 val = (wifi_control) ? 1 : 0;
1605 btc->btc_write_1byte_bitmask(btc, 0x73, BIT(2), val);
1606 }
1607
1608 static void
halbtc8821c1ant_set_gnt_bt(struct btc_coexist * btc,u8 state)1609 halbtc8821c1ant_set_gnt_bt(struct btc_coexist *btc, u8 state)
1610 {
1611 switch (state) {
1612 case BTC_GNT_SET_SW_LOW:
1613 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0xc000, 0x1);
1614 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0x0c00, 0x1);
1615 break;
1616 case BTC_GNT_SET_SW_HIGH:
1617 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0xc000, 0x3);
1618 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0x0c00, 0x3);
1619 break;
1620 case BTC_GNT_SET_HW_PTA:
1621 default:
1622 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0xc000, 0x0);
1623 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0x0c00, 0x0);
1624 break;
1625 }
1626 }
1627
1628 static void
halbtc8821c1ant_set_gnt_wl(struct btc_coexist * btc,u8 state)1629 halbtc8821c1ant_set_gnt_wl(struct btc_coexist *btc, u8 state)
1630 {
1631 switch (state) {
1632 case BTC_GNT_SET_SW_LOW:
1633 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0x3000, 0x1);
1634 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0x0300, 0x1);
1635 break;
1636 case BTC_GNT_SET_SW_HIGH:
1637 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0x3000, 0x3);
1638 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0x0300, 0x3);
1639 break;
1640 case BTC_GNT_SET_HW_PTA:
1641 default:
1642 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0x3000, 0x0);
1643 halbtc8821c1ant_write_indirect_reg(btc, 0x38, 0x0300, 0x0);
1644 break;
1645 }
1646 }
1647
1648 static
halbtc8821c1ant_set_table(struct btc_coexist * btc,boolean force_exec,u32 val0x6c0,u32 val0x6c4,u32 val0x6c8,u8 val0x6cc)1649 void halbtc8821c1ant_set_table(struct btc_coexist *btc, boolean force_exec,
1650 u32 val0x6c0, u32 val0x6c4, u32 val0x6c8,
1651 u8 val0x6cc)
1652 {
1653 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
1654 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
1655
1656 if (!force_exec && !coex_sta->wl_slot_toggle_change) {
1657 coex_dm->cur_val0x6c0 = btc->btc_read_4byte(btc, 0x6c0);
1658 coex_dm->cur_val0x6c4 = btc->btc_read_4byte(btc, 0x6c4);
1659
1660 if (val0x6c0 == coex_dm->cur_val0x6c0 &&
1661 val0x6c4 == coex_dm->cur_val0x6c4)
1662 return;
1663 }
1664
1665 btc->btc_write_4byte(btc, 0x6c0, val0x6c0);
1666 btc->btc_write_4byte(btc, 0x6c4, val0x6c4);
1667 btc->btc_write_4byte(btc, 0x6c8, val0x6c8);
1668 btc->btc_write_1byte(btc, 0x6cc, val0x6cc);
1669
1670 coex_dm->cur_val0x6c8 = val0x6c8;
1671 coex_dm->cur_val0x6cc = val0x6cc;
1672 }
1673
1674 static
halbtc8821c1ant_table(struct btc_coexist * btc,boolean force_exec,u8 type)1675 void halbtc8821c1ant_table(struct btc_coexist *btc, boolean force_exec, u8 type)
1676 {
1677 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
1678 u32 break_table;
1679 u8 select_table;
1680
1681 coex_sta->coex_table_type = type;
1682
1683 if (coex_sta->concurrent_rx_mode_on == TRUE) {
1684 /* set WL hi-pri can break BT */
1685 break_table = 0xf0ffffff;
1686 /* set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS) */
1687 select_table = 0x1b;
1688 } else {
1689 break_table = 0xffffff;
1690 select_table = 0x13;
1691 }
1692
1693 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
1694 "[BTCoex], ********** Table-%d **********\n",
1695 coex_sta->coex_table_type);
1696 BTC_TRACE(trace_buf);
1697
1698 switch (type) {
1699 case 0:
1700 halbtc8821c1ant_set_table(btc, force_exec, 0x55555555,
1701 0x55555555, break_table,
1702 select_table);
1703 break;
1704 case 1:
1705 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1706 0x5a5a5a5a, break_table,
1707 select_table);
1708 break;
1709 case 2:
1710 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1711 0xaaaaaaaa, break_table,
1712 select_table);
1713 break;
1714 case 3:
1715 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1716 0x6a5a5aaa, break_table,
1717 select_table);
1718 break;
1719 case 4:
1720 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1721 0x5a5a5a5a, break_table,
1722 select_table);
1723 break;
1724 case 5:
1725 halbtc8821c1ant_set_table(btc, force_exec, 0x6a5a5a5a,
1726 0x5a5a5a5a, break_table,
1727 select_table);
1728 break;
1729 case 6:
1730 halbtc8821c1ant_set_table(btc, force_exec, 0x6a5a56aa,
1731 0x6a5a56aa, break_table,
1732 select_table);
1733 break;
1734 case 7:
1735 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1736 0xaaaa5aaa, break_table,
1737 select_table);
1738 break;
1739 case 8:
1740 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1741 0x6aaa6aaa, break_table,
1742 select_table);
1743 break;
1744 case 9:
1745 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1746 0xaaaaaaaa, break_table,
1747 select_table);
1748 break;
1749 case 10:
1750 halbtc8821c1ant_set_table(btc, force_exec, 0xaaaaaaaa,
1751 0xaaaaaaaa, break_table,
1752 select_table);
1753 break;
1754 case 11:
1755 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1756 0x6a5a5a5a, break_table,
1757 select_table);
1758 break;
1759 case 12:
1760 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1761 0x5aaa5a5a, break_table,
1762 select_table);
1763 break;
1764 case 13:
1765 halbtc8821c1ant_set_table(btc, force_exec, 0xaa5555aa,
1766 0x5a5a5a5a, break_table,
1767 select_table);
1768 break;
1769 case 14:
1770 halbtc8821c1ant_set_table(btc, force_exec, 0x6a5a5aaa,
1771 0x6a5a5aaa, break_table,
1772 select_table);
1773 break;
1774 case 15:
1775 halbtc8821c1ant_set_table(btc, force_exec, 0xffffffff,
1776 0x5a5a5a5a, break_table,
1777 select_table);
1778 break;
1779 case 16:
1780 halbtc8821c1ant_set_table(btc, force_exec, 0x55555555,
1781 0x5a5a5a5a, break_table,
1782 select_table);
1783 break;
1784 case 17:
1785 halbtc8821c1ant_set_table(btc, force_exec, 0x55555555,
1786 0xaaaaaaaa, break_table,
1787 select_table);
1788 break;
1789 case 18:
1790 halbtc8821c1ant_set_table(btc, force_exec, 0x656a656a,
1791 0x656a656a, break_table,
1792 select_table);
1793 break;
1794 case 19:
1795 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1796 0x66555555, break_table,
1797 select_table);
1798 break;
1799 case 20:
1800 halbtc8821c1ant_set_table(btc, force_exec, 0x6a5a5a5a,
1801 0x6a5a5a5a, break_table,
1802 select_table);
1803 break;
1804 case 21:
1805 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1806 0x6a5a6a5a, break_table,
1807 select_table);
1808 break;
1809 case 22:
1810 halbtc8821c1ant_set_table(btc, force_exec, 0x56555555,
1811 0x5a5a5aaa, break_table,
1812 select_table);
1813 break;
1814 case 23:
1815 halbtc8821c1ant_set_table(btc, force_exec, 0xffffffff,
1816 0x5aaa5aaa, break_table,
1817 select_table);
1818 break;
1819 case 24:
1820 halbtc8821c1ant_set_table(btc, force_exec, 0xffffffff,
1821 0x5a5a5aaa, break_table,
1822 select_table);
1823 break;
1824 case 25:
1825 halbtc8821c1ant_set_table(btc, force_exec, 0x66555555,
1826 0x5a5a5aaa, break_table,
1827 select_table);
1828 break;
1829 default:
1830 break;
1831 }
1832 }
1833
1834 static void
halbtc8821c1ant_wltoggle_table(IN struct btc_coexist * btc,IN boolean force_exec,IN u8 interval,IN u8 val0x6c4_b0,IN u8 val0x6c4_b1,IN u8 val0x6c4_b2,IN u8 val0x6c4_b3)1835 halbtc8821c1ant_wltoggle_table(IN struct btc_coexist *btc,
1836 IN boolean force_exec, IN u8 interval,
1837 IN u8 val0x6c4_b0, IN u8 val0x6c4_b1,
1838 IN u8 val0x6c4_b2, IN u8 val0x6c4_b3)
1839 {
1840 static u8 pre_h2c_parameter[6] = {0};
1841 u8 cur_h2c_parameter[6] = {0};
1842 u8 i, match_cnt = 0;
1843
1844 cur_h2c_parameter[0] = 0x7; /* op_code, 0x7= wlan toggle slot*/
1845
1846 cur_h2c_parameter[1] = interval;
1847 cur_h2c_parameter[2] = val0x6c4_b0;
1848 cur_h2c_parameter[3] = val0x6c4_b1;
1849 cur_h2c_parameter[4] = val0x6c4_b2;
1850 cur_h2c_parameter[5] = val0x6c4_b3;
1851 #if 0
1852 if (!force_exec) {
1853 for (i = 1; i <= 5; i++) {
1854 if (cur_h2c_parameter[i] != pre_h2c_parameter[i])
1855 break;
1856
1857 match_cnt++;
1858 }
1859
1860 if (match_cnt == 5)
1861 return;
1862 }
1863 #endif
1864 for (i = 1; i <= 5; i++)
1865 pre_h2c_parameter[i] = cur_h2c_parameter[i];
1866
1867 btc->btc_fill_h2c(btc, 0x69, 6, cur_h2c_parameter);
1868 }
1869
1870 static
halbtc8821c1ant_ignore_wlan_act(struct btc_coexist * btc,boolean force_exec,boolean enable)1871 void halbtc8821c1ant_ignore_wlan_act(struct btc_coexist *btc,
1872 boolean force_exec, boolean enable)
1873 {
1874 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
1875 u8 h2c_parameter[1] = {0};
1876
1877 if (btc->manual_control || btc->stop_coex_dm)
1878 return;
1879
1880 if (!force_exec) {
1881 if (enable == coex_dm->cur_ignore_wlan_act)
1882 return;
1883 }
1884
1885 if (enable)
1886 h2c_parameter[0] |= BIT(0); /* function enable */
1887
1888 btc->btc_fill_h2c(btc, 0x63, 1, h2c_parameter);
1889
1890 coex_dm->cur_ignore_wlan_act = enable;
1891 }
1892
1893 static
halbtc8821c1ant_lps_rpwm(struct btc_coexist * btc,boolean force_exec,u8 lps_val,u8 rpwm_val)1894 void halbtc8821c1ant_lps_rpwm(struct btc_coexist *btc, boolean force_exec,
1895 u8 lps_val, u8 rpwm_val)
1896 {
1897 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
1898
1899 if (!force_exec) {
1900 if (lps_val == coex_dm->cur_lps &&
1901 rpwm_val == coex_dm->cur_rpwm)
1902 return;
1903 }
1904
1905 btc->btc_set(btc, BTC_SET_U1_LPS_VAL, &lps_val);
1906 btc->btc_set(btc, BTC_SET_U1_RPWM_VAL, &rpwm_val);
1907
1908 coex_dm->cur_lps = lps_val;
1909 coex_dm->cur_rpwm = rpwm_val;
1910 }
1911
1912 #if 0
1913 static
1914 void halbtc8821c1ant_multiport_tdma(struct btc_coexist *btc, u8 multi_port_mode)
1915 {
1916 struct btc_multi_port_tdma_info multiport_tdma_para;
1917 static u8 pre_state = BTC_MULTI_PORT_TDMA_MODE_NONE;
1918
1919 if (multi_port_mode == pre_state)
1920 return;
1921
1922 multiport_tdma_para.btc_multi_port_tdma_mode = multi_port_mode;
1923
1924 switch (multi_port_mode) {
1925 case BTC_MULTI_PORT_TDMA_MODE_NONE:
1926 multiport_tdma_para.start_time_from_bcn = 0;
1927 multiport_tdma_para.bt_time = 0;
1928 break;
1929 case BTC_MULTI_PORT_TDMA_MODE_2G_SCC_GO:
1930 multiport_tdma_para.start_time_from_bcn = 65;
1931 multiport_tdma_para.bt_time = 35;
1932 break;
1933 case BTC_MULTI_PORT_TDMA_MODE_2G_P2P_GO:
1934 multiport_tdma_para.start_time_from_bcn = 55;
1935 multiport_tdma_para.bt_time = 45;
1936 break;
1937 }
1938
1939 btc->btc_set(btc, BTC_SET_WIFI_BT_COEX_MODE, &multiport_tdma_para);
1940
1941 pre_state = multi_port_mode;
1942 }
1943 #endif
1944
1945 static
halbtc8821c1ant_tdma_check(struct btc_coexist * btc,boolean new_ps_state)1946 void halbtc8821c1ant_tdma_check(struct btc_coexist *btc, boolean new_ps_state)
1947 {
1948 u8 lps_mode = 0x0;
1949 u8 h2c_parameter[5] = {0x8, 0, 0, 0, 0};
1950
1951 btc->btc_get(btc, BTC_GET_U1_LPS_MODE, &lps_mode);
1952
1953 if (lps_mode) { /* already under LPS state */
1954 if (new_ps_state) {
1955 /* keep state under LPS, do nothing. */
1956 } else {
1957 /* will leave LPS state, turn off psTdma first */
1958 btc->btc_fill_h2c(btc, 0x60, 5, h2c_parameter);
1959 }
1960 } else { /* NO PS state */
1961 if (new_ps_state) {
1962 /* will enter LPS state, turn off psTdma first */
1963 btc->btc_fill_h2c(btc, 0x60, 5, h2c_parameter);
1964 } else {
1965 /* keep state under NO PS state, do nothing. */
1966 }
1967 }
1968 }
1969
1970 static
halbtc8821c1ant_power_save_state(struct btc_coexist * btc,u8 ps_type,u8 lps_val,u8 rpwm_val)1971 boolean halbtc8821c1ant_power_save_state(struct btc_coexist *btc, u8 ps_type,
1972 u8 lps_val, u8 rpwm_val)
1973 {
1974 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
1975 boolean low_pwr_disable = FALSE, result = TRUE;
1976
1977 switch (ps_type) {
1978 case BTC_PS_WIFI_NATIVE:
1979 /* recover to original 32k low power setting */
1980 coex_sta->force_lps_ctrl = FALSE;
1981 low_pwr_disable = FALSE;
1982 /* btc->btc_set(btc, BTC_SET_ACT_DISABLE_LOW_POWER,
1983 * &low_pwr_disable);
1984 */
1985 btc->btc_set(btc, BTC_SET_ACT_PRE_NORMAL_LPS, NULL);
1986 break;
1987 case BTC_PS_LPS_ON:
1988 coex_sta->force_lps_ctrl = TRUE;
1989 halbtc8821c1ant_tdma_check(btc, TRUE);
1990 halbtc8821c1ant_lps_rpwm(btc, NM_EXCU, lps_val, rpwm_val);
1991 /* when coex force to enter LPS, do not enter 32k low power. */
1992 low_pwr_disable = TRUE;
1993 btc->btc_set(btc, BTC_SET_ACT_DISABLE_LOW_POWER,
1994 &low_pwr_disable);
1995 /* power save must executed before psTdma.*/
1996 btc->btc_set(btc, BTC_SET_ACT_ENTER_LPS, NULL);
1997 break;
1998 case BTC_PS_LPS_OFF:
1999 coex_sta->force_lps_ctrl = TRUE;
2000 halbtc8821c1ant_tdma_check(btc, FALSE);
2001 result = btc->btc_set(btc, BTC_SET_ACT_LEAVE_LPS, NULL);
2002 break;
2003 default:
2004 break;
2005 }
2006
2007 return result;
2008 }
2009
2010 static
halbtc8821c1ant_set_tdma(struct btc_coexist * btc,u8 byte1,u8 byte2,u8 byte3,u8 byte4,u8 byte5)2011 void halbtc8821c1ant_set_tdma(struct btc_coexist *btc, u8 byte1, u8 byte2,
2012 u8 byte3, u8 byte4, u8 byte5)
2013 {
2014 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
2015 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
2016 u8 h2c_parameter[5] = {0};
2017 u8 real_byte1 = byte1, real_byte5 = byte5;
2018 boolean ap_enable = FALSE, result = FALSE;
2019 u8 ps_type = BTC_PS_WIFI_NATIVE;
2020
2021 if (byte5 & BIT(2))
2022 coex_sta->is_tdma_btautoslot = TRUE;
2023 else
2024 coex_sta->is_tdma_btautoslot = FALSE;
2025
2026 if (btc->wifi_link_info.link_mode == BTC_LINK_ONLY_GO &&
2027 btc->wifi_link_info.bhotspot &&
2028 btc->wifi_link_info.bany_client_join_go)
2029 ap_enable = TRUE;
2030
2031 if ((ap_enable) && (byte1 & BIT(4) && !(byte1 & BIT(5)))) {
2032 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2033 "[BTCoex], %s == FW for 1Ant AP mode\n", __func__);
2034 BTC_TRACE(trace_buf);
2035 real_byte1 &= ~BIT(4);
2036 real_byte1 |= BIT(5);
2037
2038 real_byte5 |= BIT(5);
2039 real_byte5 &= ~BIT(6);
2040
2041 ps_type = BTC_PS_WIFI_NATIVE;
2042 halbtc8821c1ant_power_save_state(btc, ps_type, 0x0, 0x0);
2043 } else if (byte1 & BIT(4) && !(byte1 & BIT(5))) {
2044 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2045 "[BTCoex], %s == Force LPS (byte1 = 0x%x)\n",
2046 __func__, byte1);
2047 BTC_TRACE(trace_buf);
2048
2049 ps_type = BTC_PS_LPS_OFF;
2050 if (!halbtc8821c1ant_power_save_state(btc, ps_type, 0x50, 0x4))
2051 result = TRUE;
2052 } else {
2053 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2054 "[BTCoex], %s == native power save (byte1 = 0x%x)\n",
2055 __func__, byte1);
2056 BTC_TRACE(trace_buf);
2057
2058 ps_type = BTC_PS_WIFI_NATIVE;
2059 halbtc8821c1ant_power_save_state(btc, ps_type, 0x0, 0x0);
2060 }
2061
2062 coex_sta->is_set_ps_state_fail = result;
2063
2064 if (!coex_sta->is_set_ps_state_fail) {
2065 h2c_parameter[0] = real_byte1;
2066 h2c_parameter[1] = byte2;
2067 h2c_parameter[2] = byte3;
2068 h2c_parameter[3] = byte4;
2069 h2c_parameter[4] = real_byte5;
2070
2071 coex_dm->ps_tdma_para[0] = real_byte1;
2072 coex_dm->ps_tdma_para[1] = byte2;
2073 coex_dm->ps_tdma_para[2] = byte3;
2074 coex_dm->ps_tdma_para[3] = byte4;
2075 coex_dm->ps_tdma_para[4] = real_byte5;
2076
2077 btc->btc_fill_h2c(btc, 0x60, 5, h2c_parameter);
2078
2079 if (real_byte1 & BIT(2)) {
2080 coex_sta->wl_slot_toggle = TRUE;
2081 coex_sta->wl_slot_toggle_change = FALSE;
2082 } else {
2083 if (coex_sta->wl_slot_toggle)
2084 coex_sta->wl_slot_toggle_change = TRUE;
2085 else
2086 coex_sta->wl_slot_toggle_change = FALSE;
2087 coex_sta->wl_slot_toggle = FALSE;
2088 }
2089 } else {
2090 coex_sta->cnt_set_ps_state_fail++;
2091 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2092 "[BTCoex], %s == Force Leave LPS Fail (cnt = %d)\n",
2093 __func__, coex_sta->cnt_set_ps_state_fail);
2094 BTC_TRACE(trace_buf);
2095 }
2096
2097 if (ps_type == BTC_PS_WIFI_NATIVE)
2098 btc->btc_set(btc, BTC_SET_ACT_POST_NORMAL_LPS, NULL);
2099 }
2100
2101 static
halbtc8821c1ant_tdma(struct btc_coexist * btc,boolean force_exec,boolean turn_on,u32 tcase)2102 void halbtc8821c1ant_tdma(struct btc_coexist *btc, boolean force_exec,
2103 boolean turn_on, u32 tcase)
2104 {
2105 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
2106 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
2107 u8 type;
2108 boolean wifi_busy;
2109
2110 btc->btc_set_atomic(btc, &coex_dm->setting_tdma, TRUE);
2111
2112 btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
2113
2114 /* tcase: bit0~7 --> tdma case index
2115 * bit8 --> for 4-slot (50ms) mode
2116 */
2117 if (tcase & TDMA_4SLOT)/* 4-slot (50ms) mode */
2118 halbtc8821c1ant_set_tdma_timer_base(btc, 3);
2119 else
2120 halbtc8821c1ant_set_tdma_timer_base(btc, 0);
2121
2122 type = (u8)(tcase & 0xff);
2123
2124 /* To avoid TDMA H2C fail before Last LPS enter */
2125 if (!force_exec && coex_sta->coex_run_reason != BTC_RSN_LPS) {
2126 if (turn_on == coex_dm->cur_ps_tdma_on &&
2127 type == coex_dm->cur_ps_tdma) {
2128 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2129 "[BTCoex], Skip TDMA because no change TDMA(%s, %d)\n",
2130 (coex_dm->cur_ps_tdma_on ? "on" : "off"),
2131 coex_dm->cur_ps_tdma);
2132 BTC_TRACE(trace_buf);
2133
2134 btc->btc_set_atomic(btc, &coex_dm->setting_tdma, FALSE);
2135 return;
2136 }
2137 }
2138
2139 if (!wifi_busy ||
2140 (coex_sta->a2dp_exist &&
2141 (coex_sta->bt_inq_page_remain || coex_sta->is_bt_multi_link)))
2142 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_TDMA,
2143 FALSE);
2144 else
2145 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_TDMA,
2146 TRUE);
2147
2148 if (turn_on) {
2149 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2150 "[BTCoex], ********** TDMA(on, %d) **********\n",
2151 type);
2152 BTC_TRACE(trace_buf);
2153
2154 /* enable TBTT nterrupt */
2155 btc->btc_write_1byte_bitmask(btc, 0x550, 0x8, 0x1);
2156
2157 switch (type) {
2158 default:
2159 halbtc8821c1ant_set_tdma(btc, 0x61, 0x35, 0x03, 0x11,
2160 0x11);
2161 break;
2162 case 3:
2163 halbtc8821c1ant_set_tdma(btc, 0x51, 0x30, 0x03, 0x10,
2164 0x50);
2165 break;
2166 case 4:
2167 halbtc8821c1ant_set_tdma(btc, 0x51, 0x21, 0x03, 0x10,
2168 0x50);
2169 break;
2170 case 5:
2171 halbtc8821c1ant_set_tdma(btc, 0x61, 0x3a, 0x03, 0x11,
2172 0x11);
2173 break;
2174 case 6:
2175 halbtc8821c1ant_set_tdma(btc, 0x61, 0x20, 0x03, 0x11,
2176 0x10);
2177 break;
2178 case 7:
2179 halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x03, 0x10,
2180 0x54);
2181 break;
2182 case 8:
2183 halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x03, 0x10,
2184 0x54);
2185 break;
2186 case 9:
2187 halbtc8821c1ant_set_tdma(btc, 0x55, 0x08, 0x03, 0x10,
2188 0x54);
2189 break;
2190 case 10:
2191 halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x07, 0x10,
2192 0x55);
2193 break;
2194 case 11:
2195 halbtc8821c1ant_set_tdma(btc, 0x61, 0x25, 0x03, 0x11,
2196 0x11);
2197 break;
2198 case 12:
2199 halbtc8821c1ant_set_tdma(btc, 0x51, 0x35, 0x03, 0x10,
2200 0x50);
2201 break;
2202 case 13:
2203 halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x07, 0x10,
2204 0x54);
2205 break;
2206 case 14:
2207 halbtc8821c1ant_set_tdma(btc, 0x51, 0x15, 0x03, 0x10,
2208 0x50);
2209 break;
2210 case 15: /* not use */
2211 halbtc8821c1ant_set_tdma(btc, 0x51, 0x20, 0x03, 0x10,
2212 0x50);
2213 break;
2214 case 16:
2215 halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x03, 0x10,
2216 0x50);
2217 break;
2218 case 17:
2219 halbtc8821c1ant_set_tdma(btc, 0x61, 0x08, 0x03, 0x11,
2220 0x14);
2221 break;
2222 case 18:
2223 halbtc8821c1ant_set_tdma(btc, 0x51, 0x30, 0x03, 0x10,
2224 0x50);
2225 break;
2226 case 19:
2227 halbtc8821c1ant_set_tdma(btc, 0x61, 0x08, 0x03, 0x11,
2228 0x11);
2229 break;
2230 case 20:
2231 halbtc8821c1ant_set_tdma(btc, 0x51, 0x10, 0x03, 0x10,
2232 0x50);
2233 break;
2234 case 21:
2235 halbtc8821c1ant_set_tdma(btc, 0x61, 0x30, 0x03, 0x11,
2236 0x10);
2237 break;
2238 case 22:
2239 halbtc8821c1ant_set_tdma(btc, 0x61, 0x25, 0x03, 0x11,
2240 0x10);
2241 break;
2242 case 23:
2243 halbtc8821c1ant_set_tdma(btc, 0x61, 0x10, 0x03, 0x11,
2244 0x10);
2245 break;
2246 case 24:
2247 halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x03, 0x10,
2248 0x54);
2249 break;
2250 case 25:
2251 halbtc8821c1ant_set_tdma(btc, 0x51, 0x3a, 0x03, 0x10,
2252 0x50);
2253 break;
2254 case 26:
2255 halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x03, 0x10,
2256 0x55);
2257 break;
2258 case 27:
2259 halbtc8821c1ant_set_tdma(btc, 0x61, 0x08, 0x03, 0x11,
2260 0x15);
2261 break;
2262 case 28:
2263 halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x0b, 0x10,
2264 0x54);
2265 break;
2266 case 32:
2267 halbtc8821c1ant_set_tdma(btc, 0x61, 0x35, 0x03, 0x11,
2268 0x11);
2269 break;
2270 case 33:
2271 halbtc8821c1ant_set_tdma(btc, 0x61, 0x35, 0x03, 0x11,
2272 0x10);
2273 break;
2274 case 34:
2275 halbtc8821c1ant_set_tdma(btc, 0x61, 0x3f, 0x03, 0x11,
2276 0x10);
2277 break;
2278 case 36:
2279 halbtc8821c1ant_set_tdma(btc, 0x61, 0x45, 0x03, 0x11,
2280 0x10);
2281 break;
2282 case 37:
2283 halbtc8821c1ant_set_tdma(btc, 0x61, 0x3a, 0x03, 0x11,
2284 0x11);
2285 break;
2286 case 38:
2287 halbtc8821c1ant_set_tdma(btc, 0x65, 0x10, 0x03, 0x11,
2288 0x11);
2289 break;
2290 case 39:
2291 halbtc8821c1ant_set_tdma(btc, 0x55, 0x08, 0x3, 0x10,
2292 0x54);
2293 break;
2294 case 50:
2295 halbtc8821c1ant_set_tdma(btc, 0x51, 0x4a, 0x3, 0x10,
2296 0x50);
2297 break;
2298 case 51:
2299 halbtc8821c1ant_set_tdma(btc, 0x51, 0x08, 0x3, 0x30,
2300 0x54);
2301 break;
2302 }
2303 } else {
2304
2305 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2306 "[BTCoex], ********** TDMA(off, %d) **********\n",
2307 type);
2308 BTC_TRACE(trace_buf);
2309
2310 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_TDMA, FALSE);
2311
2312 /* disable PS tdma */
2313 switch (type) {
2314 case 8: /* PTA Control */
2315 halbtc8821c1ant_set_tdma(btc, 0x8, 0x0, 0x0, 0x0, 0x0);
2316 break;
2317 case 0:
2318 default: /* Software control, Antenna at BT side */
2319 halbtc8821c1ant_set_tdma(btc, 0x0, 0x0, 0x0, 0x0, 0x0);
2320 break;
2321 case 1: /* 2-Ant, 0x778=3, antenna control
2322 * by antenna diversity
2323 */
2324 halbtc8821c1ant_set_tdma(btc, 0x0, 0x0, 0x0, 0x48, 0x0);
2325 break;
2326 }
2327 }
2328
2329 coex_dm->cur_ps_tdma_on = turn_on;
2330 coex_dm->cur_ps_tdma = type;
2331
2332 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "change TDMA(%s, %d)\n",
2333 (coex_dm->cur_ps_tdma_on ? "on" : "off"),
2334 coex_dm->cur_ps_tdma);
2335 BTC_TRACE(trace_buf);
2336
2337 btc->btc_set_atomic(btc, &coex_dm->setting_tdma, FALSE);
2338 }
2339
2340 static
halbtc8821c1ant_set_ant_switch(struct btc_coexist * btc,boolean force_exec,u8 ctrl_type,u8 pos_type)2341 void halbtc8821c1ant_set_ant_switch(struct btc_coexist *btc,
2342 boolean force_exec, u8 ctrl_type,
2343 u8 pos_type)
2344 {
2345 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
2346 struct rfe_type_8821c_1ant *rfe_type = &btc->rfe_type_8821c_1ant;
2347 struct btc_board_info *board_info = &btc->board_info;
2348 boolean polarity_inverse = FALSE;
2349 u8 val = 0;
2350 u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
2351
2352 if (!rfe_type->ext_ant_switch_exist)
2353 return;
2354
2355 if (!force_exec) {
2356 if (((ctrl_type << 8) + pos_type) ==
2357 coex_dm->cur_ext_ant_switch_status)
2358 return;
2359 }
2360
2361 coex_dm->cur_ext_ant_switch_status = (ctrl_type << 8) + pos_type;
2362
2363 /* swap control polarity if use different switch control polarity
2364 * Normal switch polarity for DPDT,
2365 * 0xcb4[29:28] = 2b'01 => BTG to Main, WLG to Aux,
2366 * 0xcb4[29:28] = 2b'10 => BTG to Aux, WLG to Main
2367 * Normal switch polarity for SPDT,
2368 * 0xcb4[29:28] = 2b'01 => Ant to BTG,
2369 * 0xcb4[29:28] = 2b'10 => Ant to WLG
2370 */
2371 if (rfe_type->ext_ant_switch_ctrl_polarity)
2372 polarity_inverse = !polarity_inverse;
2373
2374 /* swap control polarity if 1-Ant at Aux */
2375 if (rfe_type->ant_at_main_port == FALSE)
2376 polarity_inverse = !polarity_inverse;
2377
2378 switch (pos_type) {
2379 default:
2380 case BT_8821C_1ANT_TO_BT:
2381 case BT_8821C_1ANT_TO_NOCARE:
2382 case BT_8821C_1ANT_TO_WLA:
2383
2384 break;
2385 case BT_8821C_1ANT_TO_WLG:
2386 if (!rfe_type->wlg_locate_at_btg)
2387 polarity_inverse = !polarity_inverse;
2388 break;
2389 }
2390
2391 if (board_info->ant_div_cfg)
2392 ctrl_type = BT_8821C_1ANT_CTRL_BY_ANTDIV;
2393
2394
2395 switch (ctrl_type) {
2396 default:
2397 case BT_8821C_1ANT_CTRL_BY_BBSW:
2398 /* 0x4c[23] = 0 */
2399 btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x0);
2400 /* 0x4c[24] = 1 */
2401 btc->btc_write_1byte_bitmask(btc, 0x4f, 0x01, 0x1);
2402 /* BB SW, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
2403 btc->btc_write_1byte_bitmask(btc, 0xcb4, 0xff, 0x77);
2404 /* 0xcb4[29:28] = 2b'01 for no switch_polarity_inverse,
2405 * DPDT_SEL_N =1, DPDT_SEL_P =0
2406 */
2407 val = (!polarity_inverse ? 0x1 : 0x2);
2408 btc->btc_write_1byte_bitmask(btc, 0xcb7, 0x30, val);
2409 break;
2410 case BT_8821C_1ANT_CTRL_BY_PTA:
2411 /* 0x4c[23] = 0 */
2412 btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x0);
2413 /* 0x4c[24] = 1 */
2414 btc->btc_write_1byte_bitmask(btc, 0x4f, 0x01, 0x1);
2415 /* PTA, DPDT use RFE_ctrl8 and RFE_ctrl9 as control pin */
2416 btc->btc_write_1byte_bitmask(btc, 0xcb4, 0xff, 0x66);
2417 /* 0xcb4[29:28] = 2b'10 for no switch_polatiry_inverse,
2418 * DPDT_SEL_N =1, DPDT_SEL_P =0 @ GNT_BT=1
2419 */
2420 val = (!polarity_inverse ? 0x2 : 0x1);
2421 btc->btc_write_1byte_bitmask(btc, 0xcb7, 0x30, val);
2422 break;
2423 case BT_8821C_1ANT_CTRL_BY_ANTDIV:
2424 /* 0x4c[23] = 0 */
2425 btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x0);
2426 /* 0x4c[24] = 1 */
2427 btc->btc_write_1byte_bitmask(btc, 0x4f, 0x01, 0x1);
2428 btc->btc_write_1byte_bitmask(btc, 0xcb4, 0xff, 0x88);
2429
2430 /* no regval_0xcb7 setup required, because antenna switch
2431 * control value by antenna diversity
2432 */
2433 break;
2434 case BT_8821C_1ANT_CTRL_BY_MAC:
2435 /* 0x4c[23] = 1 */
2436 btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x1);
2437 /* 0x64[0] = 1b'0 for no switch_polarity_inverse,
2438 * DPDT_SEL_N =1, DPDT_SEL_P =0
2439 */
2440 val = (!polarity_inverse ? 0x0 : 0x1);
2441 btc->btc_write_1byte_bitmask(btc, 0x64, 0x1, val);
2442 break;
2443 case BT_8821C_1ANT_CTRL_BY_FW:
2444 /* 0x4c[23] = 0 */
2445 btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x0);
2446 /* 0x4c[24] = 1 */
2447 btc->btc_write_1byte_bitmask(btc, 0x4f, 0x01, 0x1);
2448 break;
2449 case BT_8821C_1ANT_CTRL_BY_BT:
2450 /* 0x4c[23] = 0 */
2451 btc->btc_write_1byte_bitmask(btc, 0x4e, 0x80, 0x0);
2452 /* 0x4c[24] = 0 */
2453 btc->btc_write_1byte_bitmask(btc, 0x4f, 0x01, 0x0);
2454 /* no setup required, because antenna switch control value
2455 * by BT vendor 0xac[1:0]
2456 */
2457 break;
2458 }
2459
2460 /* PAPE, LNA_ON control by BT while WLAN off for current leakage issue */
2461 if (ctrl_type == BT_8821C_1ANT_CTRL_BY_BT) {
2462 /* PAPE 0x64[29] = 0 */
2463 btc->btc_write_1byte_bitmask(btc, 0x67, 0x20, 0x0);
2464 /* LNA_ON 0x64[28] = 0 */
2465 btc->btc_write_1byte_bitmask(btc, 0x67, 0x10, 0x0);
2466 } else {
2467 /* PAPE 0x64[29] = 1 */
2468 btc->btc_write_1byte_bitmask(btc, 0x67, 0x20, 0x1);
2469 /* LNA_ON 0x64[28] = 1 */
2470 btc->btc_write_1byte_bitmask(btc, 0x67, 0x10, 0x1);
2471 }
2472 }
2473
2474 static
halbtc8821c1ant_set_rfe_type(struct btc_coexist * btc)2475 void halbtc8821c1ant_set_rfe_type(struct btc_coexist *btc)
2476 {
2477 struct btc_board_info *board_info = &btc->board_info;
2478 struct rfe_type_8821c_1ant *rfe_type = &btc->rfe_type_8821c_1ant;
2479
2480 /* the following setup should be got from Efuse in the future */
2481 rfe_type->rfe_module_type = board_info->rfe_type & 0x1f;
2482
2483 rfe_type->ext_ant_switch_ctrl_polarity = 0;
2484
2485 switch (rfe_type->rfe_module_type) {
2486 case 0:
2487 case 8:
2488 default: /*2-Ant, DPDT, WLG*/
2489 rfe_type->ext_ant_switch_exist = TRUE;
2490 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_DPDT;
2491 rfe_type->wlg_locate_at_btg = FALSE;
2492 rfe_type->ant_at_main_port = TRUE;
2493 break;
2494 case 1:
2495 case 9: /*1-Ant, Main, WLG */
2496 rfe_type->ext_ant_switch_exist = TRUE;
2497 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_SPDT;
2498 rfe_type->wlg_locate_at_btg = FALSE;
2499 rfe_type->ant_at_main_port = TRUE;
2500 break;
2501 case 2:
2502 case 10: /*1-Ant, Main, BTG */
2503 rfe_type->ext_ant_switch_exist = TRUE;
2504 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_SPDT;
2505 rfe_type->wlg_locate_at_btg = TRUE;
2506 rfe_type->ant_at_main_port = TRUE;
2507 break;
2508 case 3:
2509 case 11: /*1-Ant, Aux, WLG */
2510 rfe_type->ext_ant_switch_exist = TRUE;
2511 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_DPDT;
2512 rfe_type->wlg_locate_at_btg = FALSE;
2513 rfe_type->ant_at_main_port = FALSE;
2514 break;
2515 case 4:
2516 case 12: /*1-Ant, Aux, BTG */
2517 rfe_type->ext_ant_switch_exist = TRUE;
2518 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_DPDT;
2519 rfe_type->wlg_locate_at_btg = TRUE;
2520 rfe_type->ant_at_main_port = FALSE;
2521 break;
2522 case 5:
2523 case 13: /*2-Ant, no switch, WLG*/
2524 rfe_type->ext_ant_switch_exist = FALSE;
2525 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_SWITCH_NONE;
2526 rfe_type->wlg_locate_at_btg = FALSE;
2527 rfe_type->ant_at_main_port = TRUE;
2528 break;
2529 case 6:
2530 case 14: /*2-Ant, no antenna switch, WLG*/
2531 rfe_type->ext_ant_switch_exist = FALSE;
2532 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_SWITCH_NONE;
2533 rfe_type->wlg_locate_at_btg = FALSE;
2534 rfe_type->ant_at_main_port = TRUE;
2535 break;
2536 case 7:
2537 case 15: /*2-Ant, DPDT, BTG*/
2538 rfe_type->ext_ant_switch_exist = TRUE;
2539 rfe_type->ext_ant_switch_type = BT_8821C_1ANT_USE_DPDT;
2540 rfe_type->wlg_locate_at_btg = TRUE;
2541 rfe_type->ant_at_main_port = TRUE;
2542 break;
2543 }
2544 }
2545
2546 static
halbtc8821c1ant_set_ant_path(struct btc_coexist * btc,u8 ant_pos_type,boolean force_exec,u8 phase)2547 void halbtc8821c1ant_set_ant_path(struct btc_coexist *btc,
2548 u8 ant_pos_type, boolean force_exec,
2549 u8 phase)
2550 {
2551 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
2552 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
2553 struct rfe_type_8821c_1ant *rfe_type = &btc->rfe_type_8821c_1ant;
2554 u32 cnt_bt_cal_chk = 0, u32tmp1 = 0, u32tmp2 = 0;
2555 u8 u8tmp = 0, ctrl_type, pos_type;
2556
2557 if (!force_exec) {
2558 if (coex_dm->cur_ant_pos_type == ((ant_pos_type << 8) + phase))
2559 return;
2560 }
2561
2562 coex_dm->cur_ant_pos_type = (ant_pos_type << 8) + phase;
2563
2564 if (btc->dbg_mode) {
2565 u32tmp1 = btc->btc_read_4byte(btc, 0xcbc);
2566 u32tmp2 = btc->btc_read_4byte(btc, 0xcb4);
2567 u8tmp = btc->btc_read_1byte(btc, 0x73);
2568
2569 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2570 "[BTCoex], (Before Ant Setup) 0xcb4 = 0x%x, 0xcbc = 0x%x, 0x73 = 0x%x\n",
2571 u32tmp1, u32tmp2, u8tmp);
2572 BTC_TRACE(trace_buf);
2573 }
2574
2575 switch (phase) {
2576 case BT_8821C_1ANT_PHASE_POWERON:
2577
2578 /* set Path control owner to BT at power-on step */
2579 halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_BTSIDE);
2580
2581 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2582 ant_pos_type = BTC_ANT_PATH_BT;
2583
2584 coex_sta->run_time_state = FALSE;
2585 break;
2586 case BT_8821C_1ANT_PHASE_INIT:
2587 /* Disable LTE Coex Function in WiFi side (
2588 * this should be on if LTE coex is required)
2589 */
2590 halbtc8821c1ant_ltecoex_enable(btc, 0x0);
2591
2592 /* GNT_WL_LTE always = 1
2593 * (this should be config if LTE coex is required)
2594 */
2595 halbtc8821c1ant_ltecoex_table(btc, BT_8821C_1ANT_CTT_WL_VS_LTE,
2596 0xffff);
2597
2598 /* GNT_BT_LTE always = 1
2599 * (this should be config if LTE coex is required)
2600 */
2601 halbtc8821c1ant_ltecoex_table(btc, BT_8821C_1ANT_CTT_BT_VS_LTE,
2602 0xffff);
2603
2604 /* Wait If BT IQK running, because Path control owner is at
2605 * BT during BT IQK (setup by WiFi firmware)
2606 */
2607 while (cnt_bt_cal_chk <= 20) {
2608 u8tmp = btc->btc_read_1byte(btc, 0x49c);
2609 cnt_bt_cal_chk++;
2610 if (u8tmp & BIT(1)) {
2611 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2612 "[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n",
2613 cnt_bt_cal_chk);
2614 BTC_TRACE(trace_buf);
2615 delay_ms(10);
2616 } else {
2617 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2618 "[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n",
2619 cnt_bt_cal_chk);
2620 BTC_TRACE(trace_buf);
2621 break;
2622 }
2623 }
2624
2625 /* set Path control owner to WL at initial step */
2626 halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
2627
2628 /* set GNT_BT to SW high */
2629 halbtc8821c1ant_set_gnt_bt(btc, BTC_GNT_SET_SW_HIGH);
2630 /* Set GNT_WL to SW low */
2631 halbtc8821c1ant_set_gnt_wl(btc, BTC_GNT_SET_SW_LOW);
2632
2633 coex_sta->run_time_state = FALSE;
2634
2635 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2636 ant_pos_type = BTC_ANT_PATH_BT;
2637 break;
2638 case BT_8821C_1ANT_PHASE_WONLY:
2639 /* Disable LTE Coex Function in WiFi side
2640 *(this should be on if LTE coex is required)
2641 */
2642 halbtc8821c1ant_ltecoex_enable(btc, 0x0);
2643
2644 /* GNT_WL_LTE always = 1
2645 *(this should be config if LTE coex is required)
2646 */
2647 halbtc8821c1ant_ltecoex_table(btc, BT_8821C_1ANT_CTT_WL_VS_LTE,
2648 0xffff);
2649
2650 /* GNT_BT_LTE always = 1
2651 *(this should be config if LTE coex is required)
2652 */
2653 halbtc8821c1ant_ltecoex_table(btc, BT_8821C_1ANT_CTT_BT_VS_LTE,
2654 0xffff);
2655
2656 /* set Path control owner to WL at initial step */
2657 halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
2658
2659 /* set GNT_BT to SW Low */
2660 halbtc8821c1ant_set_gnt_bt(btc, BTC_GNT_SET_SW_LOW);
2661 /* Set GNT_WL to SW high */
2662 halbtc8821c1ant_set_gnt_wl(btc, BTC_GNT_SET_SW_HIGH);
2663
2664 coex_sta->run_time_state = FALSE;
2665
2666 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2667 ant_pos_type = BTC_ANT_PATH_WIFI;
2668 break;
2669 case BT_8821C_1ANT_PHASE_WOFF:
2670 /* Disable LTE Coex Function in WiFi side */
2671 halbtc8821c1ant_ltecoex_enable(btc, 0x0);
2672
2673 /* set Path control owner to BT */
2674 halbtc8821c1ant_coex_ctrl_owner(btc,
2675 BT_8821C_1ANT_PCO_BTSIDE);
2676
2677 coex_sta->run_time_state = FALSE;
2678 break;
2679 case BT_8821C_1ANT_PHASE_2G:
2680 while (cnt_bt_cal_chk <= 20) {
2681 /* 0x49c[0]=1 WL IQK, 0x49c[1]=1 BT IQK*/
2682 u8tmp = btc->btc_read_1byte(btc, 0x49c);
2683
2684 cnt_bt_cal_chk++;
2685 if (u8tmp & BIT(0)) {
2686 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2687 "[BTCoex], ########### WL is IQK (wait cnt=%d)\n",
2688 cnt_bt_cal_chk);
2689 BTC_TRACE(trace_buf);
2690 delay_ms(10);
2691 } else if (u8tmp & BIT(1)) {
2692 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2693 "[BTCoex], ########### BT is IQK (wait cnt=%d)\n",
2694 cnt_bt_cal_chk);
2695 BTC_TRACE(trace_buf);
2696 delay_ms(10);
2697 } else {
2698 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2699 "[BTCoex], ********** WL and BT is NOT IQK (wait cnt=%d)\n",
2700 cnt_bt_cal_chk);
2701 BTC_TRACE(trace_buf);
2702 break;
2703 }
2704 }
2705
2706 /* set Path control owner to WL at runtime step */
2707 halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
2708
2709 /* set GNT_BT to PTA */
2710 halbtc8821c1ant_set_gnt_bt(btc, BTC_GNT_SET_HW_PTA);
2711
2712 halbtc8821c1ant_set_gnt_wl(btc, BTC_GNT_SET_HW_PTA);
2713
2714 coex_sta->run_time_state = TRUE;
2715
2716 if (ant_pos_type == BTC_ANT_PATH_AUTO) {
2717 if (rfe_type->wlg_locate_at_btg)
2718 ant_pos_type = BTC_ANT_PATH_WIFI;
2719 else
2720 ant_pos_type = BTC_ANT_PATH_PTA;
2721 }
2722 break;
2723 case BT_8821C_1ANT_PHASE_5G:
2724
2725 /* set Path control owner to WL at runtime step */
2726 halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
2727
2728 /* set GNT_BT to SW Hi */
2729 halbtc8821c1ant_set_gnt_bt(btc, BTC_GNT_SET_HW_PTA);
2730
2731 /* Set GNT_WL to SW Hi */
2732 halbtc8821c1ant_set_gnt_wl(btc, BTC_GNT_SET_SW_HIGH);
2733
2734 coex_sta->run_time_state = TRUE;
2735
2736 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2737 ant_pos_type = BTC_ANT_PATH_WIFI5G;
2738 break;
2739 case BT_8821C_1ANT_PHASE_BTMP:
2740 /* Disable LTE Coex Function in WiFi side */
2741 halbtc8821c1ant_ltecoex_enable(btc, 0x0);
2742
2743 /* set Path control owner to WL */
2744 halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
2745
2746 /* set GNT_BT to SW Hi */
2747 halbtc8821c1ant_set_gnt_bt(btc, BTC_GNT_SET_SW_HIGH);
2748
2749 /* Set GNT_WL to SW Lo */
2750 halbtc8821c1ant_set_gnt_wl(btc, BTC_GNT_SET_SW_LOW);
2751
2752 coex_sta->run_time_state = FALSE;
2753
2754 /* Set Ext Ant Switch to BT side at BT MP mode */
2755 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2756 ant_pos_type = BTC_ANT_PATH_BT;
2757 break;
2758 case BT_8821C_1ANT_PHASE_ANTDET:
2759 halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
2760
2761 /* set GNT_BT to high */
2762 halbtc8821c1ant_set_gnt_bt(btc, BTC_GNT_SET_SW_HIGH);
2763 /* Set GNT_WL to high */
2764 halbtc8821c1ant_set_gnt_wl(btc, BTC_GNT_SET_SW_HIGH);
2765
2766 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2767 ant_pos_type = BTC_ANT_PATH_BT;
2768
2769 coex_sta->run_time_state = FALSE;
2770 break;
2771 case BT_8821C_1ANT_PHASE_MCC:
2772 /* set Path control owner to WL at runtime step */
2773 halbtc8821c1ant_coex_ctrl_owner(btc, BT_8821C_1ANT_PCO_WLSIDE);
2774
2775 /* set GNT_BT to PTA */
2776 halbtc8821c1ant_set_gnt_bt(btc, BTC_GNT_SET_HW_PTA);
2777
2778 halbtc8821c1ant_set_gnt_wl(btc, BTC_GNT_SET_HW_PTA);
2779
2780 coex_sta->run_time_state = TRUE;
2781
2782 if (ant_pos_type == BTC_ANT_PATH_AUTO)
2783 ant_pos_type = BTC_ANT_PATH_BT;
2784 break;
2785 }
2786
2787 if (phase == BT_8821C_1ANT_PHASE_WOFF) {
2788 /* Set Ext Ant Switch to BT control at wifi off step */
2789 ctrl_type = BT_8821C_1ANT_CTRL_BY_BT;
2790 pos_type = BT_8821C_1ANT_TO_NOCARE;
2791 } else if (phase == BT_8821C_1ANT_PHASE_MCC) {
2792 ctrl_type = BT_8821C_1ANT_CTRL_BY_FW;
2793 pos_type = BT_8821C_1ANT_TO_NOCARE;
2794 } else {
2795 switch (ant_pos_type) {
2796 case BTC_ANT_PATH_WIFI:
2797 ctrl_type = BT_8821C_1ANT_CTRL_BY_BBSW;
2798 pos_type = BT_8821C_1ANT_TO_WLG;
2799 break;
2800 case BTC_ANT_PATH_WIFI5G:
2801 ctrl_type = BT_8821C_1ANT_CTRL_BY_BBSW;
2802 pos_type = BT_8821C_1ANT_TO_WLA;
2803 break;
2804 case BTC_ANT_PATH_BT:
2805 ctrl_type = BT_8821C_1ANT_CTRL_BY_BBSW;
2806 pos_type = BT_8821C_1ANT_TO_BT;
2807 break;
2808 default:
2809 case BTC_ANT_PATH_PTA:
2810 ctrl_type = BT_8821C_1ANT_CTRL_BY_PTA;
2811 pos_type = BT_8821C_1ANT_TO_NOCARE;
2812 break;
2813 }
2814 }
2815
2816 halbtc8821c1ant_set_ant_switch(btc, force_exec, ctrl_type, pos_type);
2817
2818 if (btc->dbg_mode) {
2819 u32tmp1 = btc->btc_read_4byte(btc, 0xcbc);
2820 u32tmp2 = btc->btc_read_4byte(btc, 0xcb4);
2821 u8tmp = btc->btc_read_1byte(btc, 0x73);
2822
2823 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2824 "[BTCoex], (After Ant Setup) 0xcb4 = 0x%x, 0xcbc = 0x%x, 0x73 = 0x%x\n",
2825 u32tmp1, u32tmp2, u8tmp);
2826 BTC_TRACE(trace_buf);
2827 }
2828 }
2829
2830 static
halbtc8821c1ant_action_algorithm(struct btc_coexist * btc)2831 u8 halbtc8821c1ant_action_algorithm(struct btc_coexist *btc)
2832 {
2833 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
2834 u8 algorithm = BT_8821C_1ANT_COEX_UNDEFINED;
2835 u8 profile_map = 0;
2836
2837 if (bt_link_info->sco_exist)
2838 profile_map = profile_map | BIT(0);
2839
2840 if (bt_link_info->hid_exist)
2841 profile_map = profile_map | BIT(1);
2842
2843 if (bt_link_info->a2dp_exist)
2844 profile_map = profile_map | BIT(2);
2845
2846 if (bt_link_info->pan_exist)
2847 profile_map = profile_map | BIT(3);
2848
2849 switch (profile_map) {
2850 case 0:
2851 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2852 "[BTCoex], No BT link exists!!!\n");
2853 BTC_TRACE(trace_buf);
2854 algorithm = BT_8821C_1ANT_COEX_UNDEFINED;
2855 break;
2856 case 1:
2857 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2858 "[BTCoex], BT Profile = SCO only\n");
2859 BTC_TRACE(trace_buf);
2860 algorithm = BT_8821C_1ANT_COEX_SCO;
2861 break;
2862 case 2:
2863 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2864 "[BTCoex], BT Profile = HID only\n");
2865 BTC_TRACE(trace_buf);
2866 algorithm = BT_8821C_1ANT_COEX_HID;
2867 break;
2868 case 3:
2869 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2870 "[BTCoex], BT Profile = SCO + HID ==> HID\n");
2871 BTC_TRACE(trace_buf);
2872 algorithm = BT_8821C_1ANT_COEX_HID;
2873 break;
2874 case 4:
2875 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2876 "[BTCoex], BT Profile = A2DP only\n");
2877 BTC_TRACE(trace_buf);
2878 algorithm = BT_8821C_1ANT_COEX_A2DP;
2879 break;
2880 case 5:
2881 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2882 "[BTCoex], BT Profile = SCO + A2DP ==> HID + A2DP\n");
2883 BTC_TRACE(trace_buf);
2884 algorithm = BT_8821C_1ANT_COEX_HID_A2DP;
2885 break;
2886 case 6:
2887 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2888 "[BTCoex], BT Profile = HID + A2DP\n");
2889 BTC_TRACE(trace_buf);
2890 algorithm = BT_8821C_1ANT_COEX_HID_A2DP;
2891 break;
2892 case 7:
2893 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2894 "[BTCoex], BT Profile = SCO + HID + A2DP ==> HID + A2DP\n");
2895 BTC_TRACE(trace_buf);
2896 algorithm = BT_8821C_1ANT_COEX_HID_A2DP;
2897 break;
2898 case 8:
2899 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2900 "[BTCoex], BT Profile = PAN(EDR) only\n");
2901 BTC_TRACE(trace_buf);
2902 algorithm = BT_8821C_1ANT_COEX_PAN;
2903 break;
2904 case 9:
2905 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2906 "[BTCoex], BT Profile = SCO + PAN(EDR) ==> HID + PAN(EDR)\n");
2907 BTC_TRACE(trace_buf);
2908 algorithm = BT_8821C_1ANT_COEX_PAN_HID;
2909 break;
2910 case 10:
2911 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2912 "[BTCoex], BT Profile = HID + PAN(EDR)\n");
2913 BTC_TRACE(trace_buf);
2914 algorithm = BT_8821C_1ANT_COEX_PAN_HID;
2915 break;
2916 case 11:
2917 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2918 "[BTCoex], BT Profile = SCO + HID + PAN(EDR) ==> HID + PAN(EDR)\n");
2919 BTC_TRACE(trace_buf);
2920 algorithm = BT_8821C_1ANT_COEX_PAN_HID;
2921 break;
2922 case 12:
2923 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2924 "[BTCoex], BT Profile = A2DP + PAN(EDR)\n");
2925 BTC_TRACE(trace_buf);
2926 algorithm = BT_8821C_1ANT_COEX_PAN_A2DP;
2927 break;
2928 case 13:
2929 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2930 "[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> A2DP + PAN(EDR)\n");
2931 BTC_TRACE(trace_buf);
2932 algorithm = BT_8821C_1ANT_COEX_PAN_A2DP;
2933 break;
2934 case 14:
2935 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2936 "[BTCoex], BT Profile = HID + A2DP + PAN(EDR) ==> A2DP + PAN(EDR)\n");
2937 BTC_TRACE(trace_buf);
2938 algorithm = BT_8821C_1ANT_COEX_PAN_A2DP;
2939 break;
2940 case 15:
2941 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
2942 "[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR) ==> A2DP + PAN(EDR)\n");
2943 BTC_TRACE(trace_buf);
2944 algorithm = BT_8821C_1ANT_COEX_PAN_A2DP;
2945 break;
2946 }
2947
2948 return algorithm;
2949 }
2950
2951 static
halbtc8821c1ant_action_coex_all_off(struct btc_coexist * btc)2952 void halbtc8821c1ant_action_coex_all_off(struct btc_coexist *btc)
2953 {
2954 halbtc8821c1ant_table(btc, NM_EXCU, 0);
2955 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 0);
2956 }
2957
2958 static
halbtc8821c1ant_action_bt_whql_test(struct btc_coexist * btc)2959 void halbtc8821c1ant_action_bt_whql_test(struct btc_coexist *btc)
2960 {
2961 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
2962 BT_8821C_1ANT_PHASE_2G);
2963 halbtc8821c1ant_table(btc, NM_EXCU, 0);
2964 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
2965 }
2966
2967 static
halbtc8821c1ant_action_bt_relink(struct btc_coexist * btc)2968 void halbtc8821c1ant_action_bt_relink(struct btc_coexist *btc)
2969 {
2970 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
2971 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
2972
2973 if (coex_sta->gl_wifi_busy) {
2974 halbtc8821c1ant_table(btc, NM_EXCU, 4);
2975
2976 if (bt_link_info->hid_only)
2977 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE,
2978 20 | TDMA_4SLOT);
2979 else
2980 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 20);
2981 } else {
2982 halbtc8821c1ant_table(btc, NM_EXCU, 0);
2983 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
2984 }
2985 }
2986
2987 static
halbtc8821c1ant_action_bt_idle(struct btc_coexist * btc)2988 void halbtc8821c1ant_action_bt_idle(struct btc_coexist *btc)
2989 {
2990 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
2991 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
2992
2993 if (!coex_sta->gl_wifi_busy) {
2994 halbtc8821c1ant_table(btc, NM_EXCU, 4);
2995 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 32);
2996 } else { /* if wl busy */
2997 /*for initiator scan on*/
2998 if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_NCON_IDLE) {
2999 halbtc8821c1ant_table(btc, NM_EXCU, 2);
3000 if (coex_sta->bt_ble_scan_type & 0x2)
3001 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 36);
3002 else
3003 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 34);
3004 } else {
3005 halbtc8821c1ant_table(btc, NM_EXCU, 3);
3006 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 33);
3007 }
3008 }
3009 }
3010
3011 static
halbtc8821c1ant_action_bt_inquiry(struct btc_coexist * btc)3012 void halbtc8821c1ant_action_bt_inquiry(struct btc_coexist *btc)
3013 {
3014 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3015 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
3016 boolean wifi_connected = FALSE, wifi_busy = FALSE;
3017
3018 btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
3019 btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3020
3021 if (coex_sta->is_wifi_linkscan_process ||
3022 coex_sta->wifi_high_pri_task1 ||
3023 coex_sta->wifi_high_pri_task2) {
3024 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3025 "[BTCoex], bt inq/page + wifi hi-pri task\n");
3026 BTC_TRACE(trace_buf);
3027
3028 halbtc8821c1ant_table(btc, NM_EXCU, 2);
3029
3030 if (bt_link_info->bt_link_exist)
3031 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 23);
3032 else if (coex_sta->wifi_high_pri_task1)
3033 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 36);
3034 else if (!coex_sta->bt_create_connection)
3035 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 21);
3036 else
3037 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 6);
3038 } else if (wifi_busy) {
3039 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3040 "[BTCoex], bt inq/page + wifi busy\n");
3041 BTC_TRACE(trace_buf);
3042
3043 halbtc8821c1ant_table(btc, NM_EXCU, 2);
3044 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 20);
3045 } else if (wifi_connected) {
3046 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3047 "[BTCoex], bt inq/page + wifi connected\n");
3048 BTC_TRACE(trace_buf);
3049
3050 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3051 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 19);
3052 } else {
3053 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3054 "[BTCoex], bt inq/page + wifi not-connected\n");
3055 BTC_TRACE(trace_buf);
3056 halbtc8821c1ant_table(btc, NM_EXCU, 0);
3057 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3058 }
3059 }
3060
3061 static
halbtc8821c1ant_action_bt_sco_hid_busy(struct btc_coexist * btc)3062 void halbtc8821c1ant_action_bt_sco_hid_busy(struct btc_coexist *btc)
3063 {
3064 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3065 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
3066 boolean is_bt_ctr_hi = FALSE;
3067
3068 if (coex_sta->bt_ctr_ok &&
3069 (coex_sta->low_priority_rx + coex_sta->low_priority_tx > 360))
3070 is_bt_ctr_hi = TRUE;
3071 else
3072 is_bt_ctr_hi = FALSE;
3073
3074 if (bt_link_info->sco_exist) {
3075 if (coex_sta->is_bt_multi_link) {
3076 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3077 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 25);
3078 } else {
3079 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3080 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 5);
3081 }
3082 } else if (coex_sta->is_hid_rcu) {
3083 if (coex_sta->wl_noisy_level > 0) {
3084 halbtc8821c1ant_table(btc, NM_EXCU, 16);
3085 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 37);
3086 } else {
3087 halbtc8821c1ant_table(btc, NM_EXCU, 17);
3088 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 6);
3089 }
3090 } else {
3091 /* for HID exist */
3092 if (coex_sta->bt_a2dp_active ||
3093 coex_sta->bt_a2dp_active_remain) {
3094 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3095 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 18);
3096 } else if (bt_link_info->hid_only &&
3097 (coex_sta->is_bt_multi_link &&
3098 (is_bt_ctr_hi || bt_link_info->slave_role))) {
3099 if (coex_sta->gl_wifi_busy &&
3100 (coex_sta->wl_rx_rate <= 3 ||
3101 coex_sta->wl_rts_rx_rate <= 3))
3102 halbtc8821c1ant_table(btc, NM_EXCU, 8);
3103 else
3104 halbtc8821c1ant_table(btc, NM_EXCU, 3);
3105 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE,
3106 20 | TDMA_4SLOT);
3107 } else if (coex_sta->bt_418_hid_exist &&
3108 coex_sta->gl_wifi_busy) {
3109 halbtc8821c1ant_table(btc, NM_EXCU, 22);
3110 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 19
3111 | TDMA_4SLOT);
3112 } else if (coex_sta->bt_ble_hid_exist &&
3113 coex_sta->gl_wifi_busy) {
3114 halbtc8821c1ant_table(btc, NM_EXCU, 22);
3115 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 6);
3116 } else {
3117 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3118 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 6);
3119 }
3120 }
3121 }
3122
3123 static
halbtc8821c1ant_action_bt_acl_busy(struct btc_coexist * btc)3124 void halbtc8821c1ant_action_bt_acl_busy(struct btc_coexist *btc)
3125 {
3126 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3127 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
3128 boolean wifi_busy = FALSE, wifi_turbo = FALSE, ap_enable = FALSE;
3129 u32 slot_type = 0;
3130
3131 btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
3132 btc->btc_get(btc, BTC_GET_U1_AP_NUM, &coex_sta->scan_ap_num);
3133 btc->btc_get(btc, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &ap_enable);
3134
3135 if (!wifi_busy)
3136 wifi_busy = coex_sta->gl_wifi_busy;
3137
3138 if (coex_sta->gl_wifi_busy && coex_sta->wl_noisy_level == 0)
3139 wifi_turbo = TRUE;
3140
3141 if (bt_link_info->a2dp_exist && coex_sta->is_bt_a2dp_sink) {
3142 if (ap_enable) { /* A2DP Sink */
3143 halbtc8821c1ant_table(btc, NM_EXCU, 0);
3144 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3145 } else {
3146 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3147 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 4);
3148 }
3149 } else if (bt_link_info->a2dp_only) { /* A2DP */
3150 if (wifi_busy && (coex_sta->bt_ble_scan_type & 0x2))
3151 halbtc8821c1ant_table(btc, NM_EXCU, 3);
3152 else
3153 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3154
3155 if (coex_sta->connect_ap_period_cnt > 0 || !wifi_busy)
3156 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE,
3157 26 | TDMA_4SLOT);
3158 else
3159 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE,
3160 7 | TDMA_4SLOT);
3161 } else if ((bt_link_info->a2dp_exist && bt_link_info->pan_exist) ||
3162 (bt_link_info->hid_exist && bt_link_info->a2dp_exist &&
3163 bt_link_info->pan_exist)) {
3164 /* A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP) */
3165 if (bt_link_info->hid_exist)
3166 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3167 else if (wifi_turbo)
3168 halbtc8821c1ant_table(btc, NM_EXCU, 3);
3169 else
3170 halbtc8821c1ant_table(btc, NM_EXCU, 4);
3171
3172 if (wifi_busy)
3173 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 13);
3174 else
3175 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 14);
3176 } else if (bt_link_info->hid_exist && coex_sta->is_hid_rcu &&
3177 bt_link_info->a2dp_exist) {
3178 /* RCU + A2DP */
3179 halbtc8821c1ant_table(btc, NM_EXCU, 16);
3180
3181 if (coex_sta->connect_ap_period_cnt > 0 || !wifi_busy)
3182 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE,
3183 26 | TDMA_4SLOT);
3184 else
3185 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE,
3186 7 | TDMA_4SLOT);
3187 } else if (bt_link_info->hid_exist && bt_link_info->a2dp_exist) {
3188 /* HID+A2DP */
3189
3190 /*4-slot will not be applied when AP is CISCO*/
3191 if (coex_sta->wl_iot_peer == BTC_IOT_PEER_CISCO ||
3192 coex_sta->bt_ble_hid_exist)
3193 slot_type = 0;
3194 else
3195 slot_type = TDMA_4SLOT;
3196
3197 if (coex_sta->connect_ap_period_cnt > 0 || !wifi_busy) {
3198 halbtc8821c1ant_table(btc, FC_EXCU, 4);
3199 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE,
3200 26 | slot_type);
3201 } else if (coex_sta->bt_418_hid_exist) {
3202 halbtc8821c1ant_table(btc, FC_EXCU, 4);
3203 halbtc8821c1ant_wltoggle_table(btc, NM_EXCU, 1,
3204 0xaa, 0x5a, 0x5a, 0x5a);
3205 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE,
3206 39 | slot_type);
3207 } else if (coex_sta->bt_ble_hid_exist) {
3208 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE,
3209 8 | slot_type);
3210 } else {
3211 halbtc8821c1ant_table(btc, FC_EXCU, 4);
3212 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE,
3213 7 | slot_type);
3214 }
3215 } else if (bt_link_info->pan_only ||
3216 (bt_link_info->hid_exist && bt_link_info->pan_exist)) {
3217 /* PAN(OPP,FTP), HID+PAN(OPP,FTP) */
3218 if (bt_link_info->hid_exist)
3219 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3220 else if (wifi_turbo)
3221 halbtc8821c1ant_table(btc, NM_EXCU, 3);
3222 else
3223 halbtc8821c1ant_table(btc, NM_EXCU, 4);
3224
3225 if (!wifi_busy)
3226 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 4);
3227 else
3228 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 3);
3229 } else {
3230 /* BT no-profile busy (0x9) */
3231 halbtc8821c1ant_table(btc, NM_EXCU, 4);
3232 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 33);
3233 }
3234 }
3235
3236 static
halbtc8821c1ant_action_bt_mr(struct btc_coexist * btc)3237 void halbtc8821c1ant_action_bt_mr(struct btc_coexist *btc)
3238 {
3239 struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
3240 &btc->wifi_link_info_8821c_1ant;
3241
3242 if (!wifi_link_info_ext->is_all_under_5g) {
3243 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
3244 BT_8821C_1ANT_PHASE_2G);
3245
3246 halbtc8821c1ant_table(btc, NM_EXCU, 8);
3247 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 32);
3248 } else {
3249 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
3250 BT_8821C_1ANT_PHASE_5G);
3251
3252 halbtc8821c1ant_table(btc, NM_EXCU, 0);
3253 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3254 }
3255 }
3256
3257 static
halbtc8821c1ant_action_wifi_under5g(struct btc_coexist * btc)3258 void halbtc8821c1ant_action_wifi_under5g(struct btc_coexist *btc)
3259 {
3260 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
3261 BT_8821C_1ANT_PHASE_5G);
3262 halbtc8821c1ant_table(btc, NM_EXCU, 0);
3263 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3264 }
3265
3266 static
halbtc8821c1ant_action_wifi_only(struct btc_coexist * btc)3267 void halbtc8821c1ant_action_wifi_only(struct btc_coexist *btc)
3268 {
3269 halbtc8821c1ant_table(btc, FC_EXCU, 10);
3270 halbtc8821c1ant_tdma(btc, FC_EXCU, FALSE, 8);
3271 }
3272
3273 static
halbtc8821c1ant_action_wifi_native_lps(struct btc_coexist * btc)3274 void halbtc8821c1ant_action_wifi_native_lps(struct btc_coexist *btc)
3275 {
3276 halbtc8821c1ant_table(btc, NM_EXCU, 21);
3277 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3278 }
3279
3280 static
halbtc8821c1ant_action_wifi_linkscan(struct btc_coexist * btc)3281 void halbtc8821c1ant_action_wifi_linkscan(struct btc_coexist *btc)
3282 {
3283 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
3284
3285 if (bt_link_info->pan_exist) {
3286 halbtc8821c1ant_table(btc, NM_EXCU, 4);
3287 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 22);
3288 } else if (bt_link_info->a2dp_exist) {
3289 halbtc8821c1ant_table(btc, NM_EXCU, 4);
3290 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 27);
3291 } else {
3292 halbtc8821c1ant_table(btc, NM_EXCU, 4);
3293 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 21);
3294 }
3295 }
3296
3297 static
halbtc8821c1ant_action_wifi_not_connected(struct btc_coexist * btc)3298 void halbtc8821c1ant_action_wifi_not_connected(struct btc_coexist *btc)
3299 {
3300 /* tdma and coex table */
3301 halbtc8821c1ant_table(btc, NM_EXCU, 0);
3302 halbtc8821c1ant_tdma(btc, FC_EXCU, FALSE, 8);
3303 }
3304
3305 static
halbtc8821c1ant_action_wifi_connected(struct btc_coexist * btc)3306 void halbtc8821c1ant_action_wifi_connected(struct btc_coexist *btc)
3307 {
3308 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
3309 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
3310
3311 coex_dm->cur_algorithm = halbtc8821c1ant_action_algorithm(btc);
3312
3313 if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_BUSY ||
3314 coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_ACL_SCO_BUSY) {
3315
3316 if (bt_link_info->hid_only || bt_link_info->sco_exist)
3317 /* HID only or SCO*/
3318 halbtc8821c1ant_action_bt_sco_hid_busy(btc);
3319 else
3320 halbtc8821c1ant_action_bt_acl_busy(btc);
3321
3322 } else if (coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_SCO_BUSY) {
3323 halbtc8821c1ant_action_bt_sco_hid_busy(btc);
3324 } else {
3325 halbtc8821c1ant_action_bt_idle(btc);
3326 }
3327 }
3328
3329 static
halbtc8821c1ant_action_wifi_multiport25g(struct btc_coexist * btc)3330 void halbtc8821c1ant_action_wifi_multiport25g(struct btc_coexist *btc)
3331 {
3332 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3333
3334 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
3335 BT_8821C_1ANT_PHASE_MCC);
3336
3337 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_BTCQDDR, TRUE);
3338
3339 if (coex_sta->is_setup_link || coex_sta->bt_relink_downcount != 0) {
3340 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3341 "[BTCoex], wifi_multiport25g(), BT Relink!!\n");
3342 BTC_TRACE(trace_buf);
3343
3344 halbtc8821c1ant_table(btc, NM_EXCU, 15);
3345 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3346 } else if (coex_sta->c2h_bt_inquiry_page) {
3347 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3348 "[BTCoex], wifi_multiport25g(), BT Inq-Page!!\n");
3349 BTC_TRACE(trace_buf);
3350
3351 halbtc8821c1ant_table(btc, NM_EXCU, 15);
3352 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3353 } else {
3354 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3355 "[BTCoex], wifi_multiport25g(), BT idle or busy!!\n");
3356 BTC_TRACE(trace_buf);
3357
3358 if (coex_sta->gl_wifi_busy) {
3359 if (coex_sta->wl_rx_rate <= 3 ||
3360 coex_sta->wl_rts_rx_rate <= 3)
3361 halbtc8821c1ant_table(btc, NM_EXCU, 23);
3362 else if (coex_sta->bt_418_hid_exist ||
3363 coex_sta->bt_ble_hid_exist)
3364 halbtc8821c1ant_table(btc, NM_EXCU, 24);
3365 else
3366 halbtc8821c1ant_table(btc, NM_EXCU, 15);
3367 } else {
3368 halbtc8821c1ant_table(btc, NM_EXCU, 15);
3369 }
3370
3371 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3372 }
3373 }
3374
halbtc8821c1ant_action_wifi_scc2g(struct btc_coexist * btc)3375 static void halbtc8821c1ant_action_wifi_scc2g(struct btc_coexist *btc)
3376 {
3377 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3378
3379 if (coex_sta->num_of_profile == 1) {
3380 if (coex_sta->hid_exist || coex_sta->sco_exist) {
3381 if (coex_sta->is_hid_low_pri_tx_overhead) {
3382 halbtc8821c1ant_table(btc, NM_EXCU, 4);
3383 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 50);
3384 } else {
3385 halbtc8821c1ant_table(btc, NM_EXCU, 0);
3386 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 0);
3387 }
3388 } else if (coex_sta->a2dp_exist) {
3389 halbtc8821c1ant_table(btc, NM_EXCU, 11);
3390 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 51);
3391 } else { /* PAN or OPP */
3392 halbtc8821c1ant_table(btc, NM_EXCU, 11);
3393 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 50);
3394 }
3395 } else {
3396 if ((coex_sta->hid_exist || coex_sta->sco_exist) &&
3397 coex_sta->a2dp_exist) {
3398 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3399 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 51);
3400 } else if (coex_sta->pan_exist && coex_sta->a2dp_exist) {
3401 halbtc8821c1ant_table(btc, NM_EXCU, 11);
3402 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 51);
3403 } else { /* hid + pan */
3404 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3405 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 50);
3406 }
3407 }
3408 }
3409
3410 static
halbtc8821c1ant_action_wifi_multiport2g(struct btc_coexist * btc)3411 void halbtc8821c1ant_action_wifi_multiport2g(struct btc_coexist *btc)
3412 {
3413 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3414 struct btc_concurrent_setting multiport_tdma_para;
3415 u32 traffic_dir;
3416
3417 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_BTCQDDR, TRUE);
3418 btc->btc_get(btc, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &traffic_dir);
3419
3420 if (coex_sta->is_setup_link || coex_sta->bt_relink_downcount != 0) {
3421 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3422 "[BTCoex], wifi_multiport2g, BT Relink!!\n");
3423 BTC_TRACE(trace_buf);
3424
3425 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
3426 BT_8821C_1ANT_PHASE_2G);
3427
3428 halbtc8821c1ant_table(btc, NM_EXCU, 0);
3429 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3430 } else if (coex_sta->c2h_bt_inquiry_page) {
3431 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3432 "[BTCoex], wifi_multiport2g, BT Inq-Page!!\n");
3433 BTC_TRACE(trace_buf);
3434
3435 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
3436 BT_8821C_1ANT_PHASE_2G);
3437
3438 halbtc8821c1ant_table(btc, NM_EXCU, 1);
3439 halbtc8821c1ant_tdma(btc, NM_EXCU, TRUE, 33);
3440 } else if (coex_sta->num_of_profile == 0) {
3441 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3442 "[BTCoex], wifi_multiport2g, BT idle!!\n");
3443 BTC_TRACE(trace_buf);
3444
3445 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
3446 BT_8821C_1ANT_PHASE_2G);
3447
3448 if (btc->chip_interface == BTC_INTF_PCI &&
3449 (btc->wifi_link_info.link_mode == BTC_LINK_ONLY_GO ||
3450 btc->wifi_link_info.link_mode == BTC_LINK_ONLY_GC))
3451 halbtc8821c1ant_table(btc, NM_EXCU, 10);
3452 else
3453 halbtc8821c1ant_table(btc, NM_EXCU, 19);
3454
3455 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3456 } else if (coex_sta->is_wifi_linkscan_process) {
3457 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3458 "[BTCoex], wifi_multiport2g, WL scan!!\n");
3459 BTC_TRACE(trace_buf);
3460
3461 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
3462 BT_8821C_1ANT_PHASE_2G);
3463 halbtc8821c1ant_action_wifi_linkscan(btc);
3464 } else {
3465
3466 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
3467 BT_8821C_1ANT_PHASE_2G);
3468
3469 switch (btc->wifi_link_info.link_mode) {
3470 case BTC_LINK_2G_SCC_GC_STA:
3471 case BTC_LINK_2G_SCC_GO_STA:
3472 halbtc8821c1ant_action_wifi_scc2g(btc);
3473 break;
3474 case BTC_LINK_ONLY_GO:
3475 case BTC_LINK_ONLY_GC:
3476 #ifdef PLATFORM_WINDOWS
3477 if (btc->chip_interface == BTC_INTF_PCI &&
3478 coex_sta->a2dp_exist && !coex_sta->is_bt_multi_link)
3479 halbtc8821c1ant_table(btc, NM_EXCU, 10);
3480 else
3481 #endif
3482 halbtc8821c1ant_table(btc, NM_EXCU, 19);
3483 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3484 break;
3485 default:
3486 halbtc8821c1ant_table(btc, NM_EXCU, 19);
3487 halbtc8821c1ant_tdma(btc, NM_EXCU, FALSE, 8);
3488 break;
3489 }
3490 }
3491 }
3492
3493 static
halbtc8821c1ant_run_coex(struct btc_coexist * btc,u8 reason)3494 void halbtc8821c1ant_run_coex(struct btc_coexist *btc, u8 reason)
3495 {
3496 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3497 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
3498 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
3499 struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
3500 &btc->wifi_link_info_8821c_1ant;
3501 boolean wifi_connected = FALSE, wifi_32k = FALSE;
3502 boolean scan = FALSE, link = FALSE, roam = FALSE, under_4way = FALSE;
3503
3504 btc->btc_get(btc, BTC_GET_BL_WIFI_SCAN, &scan);
3505 btc->btc_get(btc, BTC_GET_BL_WIFI_LINK, &link);
3506 btc->btc_get(btc, BTC_GET_BL_WIFI_ROAM, &roam);
3507 btc->btc_get(btc, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &under_4way);
3508 btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
3509 btc->btc_get(btc, BTC_GET_BL_WIFI_LW_PWR_STATE, &wifi_32k);
3510
3511 if (scan || link || roam || under_4way ||
3512 reason == BT_8821C_1ANT_RSN_2GSCANSTART ||
3513 reason == BT_8821C_1ANT_RSN_2GSWITCHBAND ||
3514 reason == BT_8821C_1ANT_RSN_2GCONSTART ||
3515 reason == BT_8821C_1ANT_RSN_2GSPECIALPKT) {
3516 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3517 "[BTCoex], scan = %d, link = %d, roam = %d 4way = %d!!!\n",
3518 scan, link, roam, under_4way);
3519 BTC_TRACE(trace_buf);
3520 coex_sta->is_wifi_linkscan_process = TRUE;
3521 } else {
3522 coex_sta->is_wifi_linkscan_process = FALSE;
3523 }
3524
3525 /* update wifi_link_info variable */
3526 halbtc8821c1ant_update_wifi_link_info(btc, reason);
3527
3528 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3529 "[BTCoex], RunCoexistMechanism()===> reason = %d\n",
3530 reason);
3531 BTC_TRACE(trace_buf);
3532
3533 coex_sta->coex_run_reason = reason;
3534
3535 if (btc->manual_control) {
3536 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3537 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n");
3538 BTC_TRACE(trace_buf);
3539 return;
3540 }
3541
3542 if (btc->stop_coex_dm) {
3543 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3544 "[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n");
3545 BTC_TRACE(trace_buf);
3546 return;
3547 }
3548
3549 if (coex_sta->under_ips) {
3550 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3551 "[BTCoex], RunCoexistMechanism(), return for wifi is under IPS !!!\n");
3552 BTC_TRACE(trace_buf);
3553 return;
3554 }
3555
3556 if (coex_sta->under_lps && wifi_32k) {
3557 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3558 "[BTCoex], RunCoexistMechanism(), return for wifi is under LPS-32K !!!\n");
3559 BTC_TRACE(trace_buf);
3560 return;
3561 }
3562
3563 if (!coex_sta->run_time_state) {
3564 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3565 "[BTCoex], return for run_time_state = FALSE !!!\n");
3566 BTC_TRACE(trace_buf);
3567 return;
3568 }
3569
3570 if (coex_sta->freeze_coexrun_by_btinfo && !coex_sta->is_setup_link) {
3571 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3572 "[BTCoex], return for freeze_coexrun_by_btinfo\n");
3573 BTC_TRACE(trace_buf);
3574 return;
3575 }
3576
3577 coex_sta->coex_run_cnt++;
3578
3579 if (coex_sta->msft_mr_exist && wifi_connected) {
3580 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3581 "[BTCoex], RunCoexistMechanism(), microsoft MR!!\n");
3582 BTC_TRACE(trace_buf);
3583
3584 coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_BTMR;
3585 halbtc8821c1ant_action_bt_mr(btc);
3586 return;
3587 }
3588
3589 if (wifi_link_info_ext->is_all_under_5g) {
3590 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3591 "[BTCoex], WiFi is under 5G!!!\n");
3592 BTC_TRACE(trace_buf);
3593
3594 coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_5G;
3595 halbtc8821c1ant_action_wifi_under5g(btc);
3596 return;
3597 }
3598
3599 if (wifi_link_info_ext->is_mcc_25g) { /* not iclude scan action */
3600
3601 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3602 "[BTCoex], WiFi is under mcc dual-band!!!\n");
3603 BTC_TRACE(trace_buf);
3604
3605 coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_25GMPORT;
3606 halbtc8821c1ant_action_wifi_multiport25g(btc);
3607 return;
3608 }
3609
3610 if (wifi_link_info_ext->num_of_active_port > 1 ||
3611 (btc->wifi_link_info.link_mode == BTC_LINK_ONLY_GO &&
3612 !btc->wifi_link_info.bhotspot &&
3613 btc->wifi_link_info.bany_client_join_go)) {
3614 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3615 "[BTCoex], WiFi is under scc-2g/mcc-2g/p2pGO-only!!!\n");
3616 BTC_TRACE(trace_buf);
3617
3618 if (btc->wifi_link_info.link_mode == BTC_LINK_ONLY_GO)
3619 coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_2GGO;
3620 else
3621 coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_2GMPORT;
3622 halbtc8821c1ant_action_wifi_multiport2g(btc);
3623 return;
3624 }
3625
3626 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3627 "[BTCoex], WiFi is single-port 2G!!!\n");
3628 BTC_TRACE(trace_buf);
3629
3630 coex_sta->wl_coex_mode = BT_8821C_1ANT_WLINK_2G1PORT;
3631
3632 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, NM_EXCU,
3633 BT_8821C_1ANT_PHASE_2G);
3634
3635 /*For Asus airpods 2 + HID glitch issue (COEX-303)
3636 For HP LE HID + A2DP issue (COEX-291)*/
3637 if ((coex_sta->bt_a2dp_vendor_id == 0x4c && coex_sta->is_bt_multi_link)
3638 || (coex_sta->bt_ble_hid_exist && bt_link_info->a2dp_exist))
3639 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_BTCQDDR,
3640 FALSE);
3641 else
3642 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_BTCQDDR,
3643 TRUE);
3644
3645
3646 if (coex_sta->bt_disabled) {
3647 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3648 "[BTCoex], BT is disabled !!!\n");
3649 BTC_TRACE(trace_buf);
3650 halbtc8821c1ant_action_wifi_only(btc);
3651 return;
3652 }
3653
3654 if (coex_sta->under_lps && !coex_sta->force_lps_ctrl &&
3655 !coex_sta->acl_busy) {
3656 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3657 "[BTCoex], RunCoexistMechanism(), wifi is under LPS !!!\n");
3658 BTC_TRACE(trace_buf);
3659 halbtc8821c1ant_action_wifi_native_lps(btc);
3660 return;
3661 }
3662
3663 if (coex_sta->bt_whck_test) {
3664 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3665 "[BTCoex], BT is under WHCK TEST!!!\n");
3666 BTC_TRACE(trace_buf);
3667 halbtc8821c1ant_action_bt_whql_test(btc);
3668 return;
3669 }
3670
3671 if (coex_sta->is_setup_link || coex_sta->bt_relink_downcount != 0) {
3672 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3673 "[BTCoex], BT is re-link !!!\n");
3674 BTC_TRACE(trace_buf);
3675 halbtc8821c1ant_action_bt_relink(btc);
3676 return;
3677 }
3678
3679 if (coex_sta->c2h_bt_inquiry_page) {
3680 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3681 "[BTCoex], BT is under inquiry/page scan !!\n");
3682 BTC_TRACE(trace_buf);
3683 halbtc8821c1ant_action_bt_inquiry(btc);
3684 return;
3685 }
3686
3687 if ((coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_NCON_IDLE ||
3688 coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_CON_IDLE) &&
3689 wifi_link_info_ext->is_connected) {
3690 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3691 "############# [BTCoex], BT Is idle\n");
3692 BTC_TRACE(trace_buf);
3693 halbtc8821c1ant_action_bt_idle(btc);
3694 return;
3695 }
3696
3697 if (coex_sta->is_wifi_linkscan_process) {
3698 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3699 "[BTCoex], wifi is under linkscan process!!\n");
3700 BTC_TRACE(trace_buf);
3701 halbtc8821c1ant_action_wifi_linkscan(btc);
3702 return;
3703 }
3704
3705 if (wifi_connected) {
3706 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3707 "[BTCoex], wifi is under connected!!\n");
3708 BTC_TRACE(trace_buf);
3709
3710 halbtc8821c1ant_action_wifi_connected(btc);
3711 } else {
3712 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3713 "[BTCoex], wifi is under not-connected!!\n");
3714 BTC_TRACE(trace_buf);
3715
3716 halbtc8821c1ant_action_wifi_not_connected(btc);
3717 }
3718 }
3719
halbtc8821c1ant_init_coex_var(struct btc_coexist * btc)3720 static void halbtc8821c1ant_init_coex_var(struct btc_coexist *btc)
3721 {
3722 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3723
3724 /* Reset Coex variable */
3725 btc->btc_set(btc, BTC_SET_RESET_COEX_VAR, NULL);
3726
3727 coex_sta->bt_reg_vendor_ac = 0xffff;
3728 coex_sta->bt_reg_vendor_ae = 0xffff;
3729
3730 coex_sta->isolation_btween_wb = BT_8821C_1ANT_DEFAULT_ISOLATION;
3731 btc->bt_info.bt_get_fw_ver = 0;
3732 }
3733
3734 static
halbtc8821c1ant_init_coex_dm(struct btc_coexist * btc)3735 void halbtc8821c1ant_init_coex_dm(struct btc_coexist *btc)
3736 {
3737 }
3738
3739 static
halbtc8821c1ant_init_hw_config(struct btc_coexist * btc,boolean back_up,boolean wifi_only)3740 void halbtc8821c1ant_init_hw_config(struct btc_coexist *btc, boolean back_up,
3741 boolean wifi_only)
3742 {
3743 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3744 u32 u32tmp1 = 0, u32tmp2 = 0, u32tmp3 = 0;
3745 u16 u16tmp1 = 0;
3746 u8 i;
3747 struct btc_board_info *board_info = &btc->board_info;
3748
3749 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], %s()!\n", __func__);
3750 BTC_TRACE(trace_buf);
3751
3752 #if 0
3753 u32tmp3 = btc->btc_read_4byte(btc, 0xcb4);
3754 u32tmp1 = halbtc8821c1ant_read_indirect_reg(btc, 0x38);
3755 u32tmp2 = halbtc8821c1ant_read_indirect_reg(btc, 0x54);
3756
3757 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3758 "[BTCoex],(Before Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
3759 u32tmp3, u32tmp1, u32tmp2);
3760 BTC_TRACE(trace_buf);
3761 #endif
3762
3763 halbtc8821c1ant_init_coex_var(btc);
3764
3765 /* 0xf0[15:12] --> kt_ver */
3766 coex_sta->kt_ver = (btc->btc_read_1byte(btc, 0xf1) & 0xf0) >> 4;
3767
3768 /* enable TBTT nterrupt */
3769 btc->btc_write_1byte_bitmask(btc, 0x550, 0x8, 0x1);
3770
3771 /* BT report packet sample rate */
3772 btc->btc_write_1byte(btc, 0x790, 0x5);
3773
3774 /* Init 0x778 = 0x1 for 1-Ant */
3775 btc->btc_write_1byte(btc, 0x778, 0x1);
3776
3777 /* Enable PTA (3-wire function form BT side) */
3778 btc->btc_write_1byte_bitmask(btc, 0x40, 0x20, 0x1);
3779 btc->btc_write_1byte_bitmask(btc, 0x41, 0x02, 0x1);
3780
3781 /* Enable PTA (tx/rx signal form WiFi side) */
3782 btc->btc_write_1byte_bitmask(btc, 0x4c6, 0x30, 0x1);
3783
3784 /* set GNT_BT=1 for coex table select both */
3785 btc->btc_write_1byte_bitmask(btc, 0x763, 0x10, 0x1);
3786
3787 /* beacon queue always hi-pri */
3788 btc->btc_write_1byte_bitmask(btc, 0x6cf, BIT(3), 0x1);
3789
3790 halbtc8821c1ant_enable_gnt_to_gpio(btc, TRUE);
3791
3792 /* Antenna config */
3793 if (btc->wl_rf_state_off) {
3794 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
3795 BT_8821C_1ANT_PHASE_WOFF);
3796 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ALL, FALSE);
3797 btc->stop_coex_dm = TRUE;
3798
3799 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3800 "[BTCoex], %s: RF Off\n", __func__);
3801 BTC_TRACE(trace_buf);
3802 } else if (wifi_only) {
3803 coex_sta->concurrent_rx_mode_on = FALSE;
3804 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_WIFI, FC_EXCU,
3805 BT_8821C_1ANT_PHASE_WONLY);
3806 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
3807 BT_8821C_1ANT_SCBD_ONOFF,
3808 TRUE);
3809 btc->stop_coex_dm = TRUE;
3810 } else {
3811 coex_sta->concurrent_rx_mode_on = TRUE;
3812 btc->btc_set_rf_reg(btc, BTC_RF_A, 0x1, 0x2, 0x0);
3813
3814 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
3815 BT_8821C_1ANT_PHASE_INIT);
3816 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
3817 BT_8821C_1ANT_SCBD_ONOFF,
3818 TRUE);
3819 btc->stop_coex_dm = FALSE;
3820 }
3821
3822 /* PTA parameter */
3823 halbtc8821c1ant_table(btc, FC_EXCU, 0);
3824 halbtc8821c1ant_tdma(btc, FC_EXCU, FALSE, 8);
3825
3826 halbtc8821c1ant_query_bt_info(btc);
3827 #if 0
3828 u32tmp3 = btc->btc_read_4byte(btc, 0xcb4);
3829 u32tmp1 = halbtc8821c1ant_read_indirect_reg(btc, 0x38);
3830 u32tmp2 = halbtc8821c1ant_read_indirect_reg(btc, 0x54);
3831
3832 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3833 "[BTCoex], (After Init HW config) 0xcb4 = 0x%x, 0x38= 0x%x, 0x54= 0x%x\n",
3834 u32tmp3, u32tmp1, u32tmp2);
3835 BTC_TRACE(trace_buf);
3836 #endif
3837 }
3838
ex_halbtc8821c1ant_power_on_setting(struct btc_coexist * btc)3839 void ex_halbtc8821c1ant_power_on_setting(struct btc_coexist *btc)
3840 {
3841 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3842 struct btc_board_info *board_info = &btc->board_info;
3843 u8 u8tmp = 0x0;
3844 u16 u16tmp = 0x0;
3845 u32 value = 0;
3846
3847 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3848 "[BTCoex], Execute %s !!\n", __func__);
3849 BTC_TRACE(trace_buf);
3850
3851 btc->stop_coex_dm = TRUE;
3852 btc->wl_rf_state_off = FALSE;
3853
3854 /* enable BB, REG_SYS_FUNC_EN such that we can write BB Register correctly. */
3855 u16tmp = btc->btc_read_2byte(btc, 0x2);
3856 btc->btc_write_2byte(btc, 0x2, u16tmp | BIT(0) | BIT(1));
3857
3858 /* Local setting bit define
3859 * BIT0: "0" for no antenna inverse; "1" for antenna inverse
3860 * BIT1: "0" for internal switch; "1" for external switch
3861 * BIT2: "0" for one antenna; "1" for two antenna
3862 * NOTE: here default all internal switch
3863 * and 1-antenna ==> BIT1=0 and BIT2=0
3864 */
3865
3866 /* Set Antenna Path to BT side */
3867 /* Check efuse 0xc3[6] for Single Antenna Path */
3868 if (board_info->single_ant_path == 0) {
3869 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT;
3870 u8tmp = 1;
3871 } else if (board_info->single_ant_path == 1) {
3872 board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
3873 u8tmp = 0;
3874 }
3875
3876 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3877 "[BTCoex], (Power On) single_ant_path = %d, btdm_ant_pos = %d\n",
3878 board_info->single_ant_path , board_info->btdm_ant_pos);
3879 BTC_TRACE(trace_buf);
3880
3881 /* Setup RF front end type */
3882 halbtc8821c1ant_set_rfe_type(btc);
3883
3884 /* Set Antenna Path to BT side */
3885 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
3886 BT_8821C_1ANT_PHASE_POWERON);
3887
3888 halbtc8821c1ant_table(btc, FC_EXCU, 0);
3889
3890 /* Save"single antenna position" info in Local register setting for
3891 * FW reading, because FW may not ready at power on
3892 */
3893 if (btc->chip_interface == BTC_INTF_PCI)
3894 btc->btc_write_local_reg_1byte(btc, 0x3e0, u8tmp);
3895 else if (btc->chip_interface == BTC_INTF_USB)
3896 btc->btc_write_local_reg_1byte(btc, 0xfe08, u8tmp);
3897 else if (btc->chip_interface == BTC_INTF_SDIO)
3898 btc->btc_write_local_reg_1byte(btc, 0x60, u8tmp);
3899
3900 /* enable GNT_WL/GNT_BT debug signal to GPIO14/15 */
3901 halbtc8821c1ant_enable_gnt_to_gpio(btc, TRUE);
3902
3903 if (btc->dbg_mode) {
3904 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3905 "[BTCoex], LTE coex Reg 0x38 (Power-On) = 0x%x\n",
3906 halbtc8821c1ant_read_indirect_reg(btc, 0x38));
3907 BTC_TRACE(trace_buf);
3908
3909 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
3910 "[BTCoex], MACReg 0x70/ BBReg 0xcb4 (Power-On) = 0x%x/ 0x%x\n",
3911 btc->btc_read_4byte(btc, 0x70),
3912 btc->btc_read_4byte(btc, 0xcb4));
3913 BTC_TRACE(trace_buf);
3914 }
3915 }
3916
ex_halbtc8821c1ant_pre_load_firmware(struct btc_coexist * btc)3917 void ex_halbtc8821c1ant_pre_load_firmware(struct btc_coexist *btc)
3918 {
3919 }
3920
ex_halbtc8821c1ant_init_hw_config(struct btc_coexist * btc,boolean wifi_only)3921 void ex_halbtc8821c1ant_init_hw_config(struct btc_coexist *btc,
3922 boolean wifi_only)
3923 {
3924 halbtc8821c1ant_init_hw_config(btc, TRUE, wifi_only);
3925 }
3926
ex_halbtc8821c1ant_init_coex_dm(struct btc_coexist * btc)3927 void ex_halbtc8821c1ant_init_coex_dm(struct btc_coexist *btc)
3928 {
3929 btc->stop_coex_dm = FALSE;
3930 btc->auto_report = TRUE;
3931 btc->dbg_mode = FALSE;
3932 halbtc8821c1ant_init_coex_dm(btc);
3933 }
3934
ex_halbtc8821c1ant_display_simple_coex_info(struct btc_coexist * btc)3935 void ex_halbtc8821c1ant_display_simple_coex_info(struct btc_coexist *btc)
3936 {
3937 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
3938 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
3939 struct btc_board_info *board_info = &btc->board_info;
3940 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
3941
3942 u8 *cli_buf = btc->cli_buf;
3943 u32 bt_patch_ver = 0, bt_coex_ver = 0;
3944 static u8 cnt;
3945 u8 * const p = &coex_sta->bt_afh_map[0];
3946
3947 if (!coex_sta->bt_disabled &&
3948 (coex_sta->bt_coex_supported_version == 0 ||
3949 coex_sta->bt_coex_supported_version == 0xffff) &&
3950 cnt == 0) {
3951 btc->btc_get(btc, BTC_GET_U4_SUPPORTED_FEATURE,
3952 &coex_sta->bt_coex_supported_feature);
3953
3954 btc->btc_get(btc, BTC_GET_U4_SUPPORTED_VERSION,
3955 &coex_sta->bt_coex_supported_version);
3956
3957 coex_sta->bt_reg_vendor_ac = (u16)(btc->btc_get_bt_reg(btc, 3,
3958 0xac) &
3959 0xffff);
3960
3961 coex_sta->bt_reg_vendor_ae = (u16)(btc->btc_get_bt_reg(btc, 3,
3962 0xae) &
3963 0xffff);
3964
3965 btc->btc_get(btc, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3966 btc->bt_info.bt_get_fw_ver = bt_patch_ver;
3967
3968 if (coex_sta->num_of_profile > 0)
3969 btc->btc_get_bt_afh_map_from_bt(btc, 0, p);
3970 }
3971
3972 if (++cnt >= 3)
3973 cnt = 0;
3974
3975 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3976 "\r\n _____[BT Coexist info]____");
3977 CL_PRINTF(cli_buf);
3978
3979 if (btc->manual_control) {
3980 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3981 "\r\n __[Under Manual Control]_");
3982 CL_PRINTF(cli_buf);
3983 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3984 "\r\n _________________________");
3985 CL_PRINTF(cli_buf);
3986 }
3987
3988 if (btc->stop_coex_dm) {
3989 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3990 "\r\n ____[Coex is STOPPED]____");
3991 CL_PRINTF(cli_buf);
3992 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3993 "\r\n _________________________");
3994 CL_PRINTF(cli_buf);
3995 }
3996
3997 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
3998 "\r\n %-35s = %d/ %d/ %s / 0x%x",
3999 "Ant PG Num/ Mech/ Pos/ RFE",
4000 board_info->pg_ant_num, board_info->btdm_ant_num,
4001 (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4002 ? "Main" : "Aux"),
4003 board_info->rfe_type);
4004 CL_PRINTF(cli_buf);
4005
4006 bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8);
4007
4008 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4009 "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
4010 "CoexVer WL/ BT_Desired/ BT_Report",
4011 glcoex_ver_date_8821c_1ant, glcoex_ver_8821c_1ant,
4012 glcoex_ver_btdesired_8821c_1ant,
4013 bt_coex_ver,
4014 (bt_coex_ver == 0xff ? "Unknown" :
4015 (coex_sta->bt_disabled ? "BT-disable" :
4016 (bt_coex_ver >= glcoex_ver_btdesired_8821c_1ant ?
4017 "Match" : "Mis-Match"))));
4018 CL_PRINTF(cli_buf);
4019
4020 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s ", "BT status",
4021 ((coex_sta->bt_disabled) ? ("disabled") :
4022 ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry/page")
4023 : ((BT_8821C_1ANT_BSTATUS_NCON_IDLE ==
4024 coex_dm->bt_status) ? "non-connected idle" :
4025 ((BT_8821C_1ANT_BSTATUS_CON_IDLE ==
4026 coex_dm->bt_status) ? "connected-idle" : "busy")))));
4027 CL_PRINTF(cli_buf);
4028
4029 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4030 "0x770(Hi-pri rx/tx)",
4031 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4032 CL_PRINTF(cli_buf);
4033
4034 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s",
4035 "0x774(Lo-pri rx/tx)",
4036 coex_sta->low_priority_rx, coex_sta->low_priority_tx,
4037 (bt_link_info->slave_role ? "(Slave!!)" : " "));
4038 CL_PRINTF(cli_buf);
4039 }
4040
ex_halbtc8821c1ant_display_coex_info(struct btc_coexist * btc)4041 void ex_halbtc8821c1ant_display_coex_info(struct btc_coexist *btc)
4042 {
4043 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
4044 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
4045 struct btc_board_info *board_info = &btc->board_info;
4046 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
4047
4048 u8 *cli_buf = btc->cli_buf;
4049 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0;
4050 u16 u16tmp[4];
4051 u32 u32tmp[4];
4052 u32 fa_ofdm, fa_cck, cca_ofdm, cca_cck;
4053 u32 fw_ver = 0, bt_patch_ver = 0, bt_coex_ver = 0;
4054 static u8 pop_report_in_10s;
4055 u32 phyver = 0, val = 0;
4056 boolean lte_coex_on = FALSE, is_bt_reply = FALSE;
4057 static u8 cnt;
4058 u8 * const p = &coex_sta->bt_afh_map[0];
4059
4060 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4061 "\r\n ============[BT Coexist info 8821C]============");
4062 CL_PRINTF(cli_buf);
4063
4064 if (btc->manual_control) {
4065 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4066 "\r\n ============[Under Manual Control]============");
4067 CL_PRINTF(cli_buf);
4068 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4069 "\r\n ==========================================");
4070 CL_PRINTF(cli_buf);
4071 } else if (btc->stop_coex_dm) {
4072 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4073 "\r\n ============[Coex is STOPPED]============");
4074 CL_PRINTF(cli_buf);
4075 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4076 "\r\n ==========================================");
4077 CL_PRINTF(cli_buf);
4078 } else if (!coex_sta->run_time_state) {
4079 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4080 "\r\n ============[Run Time State = False]============");
4081 CL_PRINTF(cli_buf);
4082 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4083 "\r\n ==========================================");
4084 CL_PRINTF(cli_buf);
4085 } else if (coex_sta->freeze_coexrun_by_btinfo) {
4086 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4087 "\r\n ============[freeze_coexrun_by_btinfo]============");
4088 CL_PRINTF(cli_buf);
4089 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4090 "\r\n ==========================================");
4091 CL_PRINTF(cli_buf);
4092 }
4093
4094 if (!coex_sta->bt_disabled && cnt == 0) {
4095 if (coex_sta->bt_coex_supported_version == 0 ||
4096 coex_sta->bt_coex_supported_version == 0xffff) {
4097 btc->btc_get(btc, BTC_GET_U4_SUPPORTED_VERSION,
4098 &coex_sta->bt_coex_supported_version);
4099
4100 if (coex_sta->bt_coex_supported_version > 0 &&
4101 coex_sta->bt_coex_supported_version < 0xffff)
4102 is_bt_reply = TRUE;
4103 } else {
4104 is_bt_reply = TRUE;
4105 }
4106
4107 if (coex_sta->num_of_profile > 0)
4108 btc->btc_get_bt_afh_map_from_bt(btc, 0, p);
4109 }
4110
4111 if (is_bt_reply) {
4112 if (coex_sta->bt_coex_supported_feature == 0)
4113 btc->btc_get(btc, BTC_GET_U4_SUPPORTED_FEATURE,
4114 &coex_sta->bt_coex_supported_feature);
4115
4116 if (coex_sta->bt_reg_vendor_ac == 0xffff) {
4117 val = btc->btc_get_bt_reg(btc, 3, 0xac);
4118 coex_sta->bt_reg_vendor_ac = (u16)(val & 0xffff);
4119 }
4120
4121 if (coex_sta->bt_reg_vendor_ae == 0xffff) {
4122 val = btc->btc_get_bt_reg(btc, 3, 0xae);
4123 coex_sta->bt_reg_vendor_ae = (u16)(val & 0xffff);
4124 }
4125
4126 if (btc->bt_info.bt_get_fw_ver == 0) {
4127 btc->btc_get(btc, BTC_GET_U4_BT_PATCH_VER,
4128 &bt_patch_ver);
4129 btc->bt_info.bt_get_fw_ver = bt_patch_ver;
4130 }
4131 }
4132
4133 if (++cnt >= 3)
4134 cnt = 0;
4135
4136 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4137 "\r\n %-35s = %d/ %s/ %s / 0x%x",
4138 "Ant PG Num/ Mech/ Pos/ RFE",
4139 board_info->pg_ant_num,
4140 (board_info->btdm_ant_num == 1 ? "Shared" : "Non-Shared"),
4141 (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT
4142 ? "Main" : "Aux"),
4143 board_info->rfe_type);
4144 CL_PRINTF(cli_buf);
4145
4146 bt_patch_ver = btc->bt_info.bt_get_fw_ver;
4147 btc->btc_get(btc, BTC_GET_U4_WIFI_FW_VER, &fw_ver);
4148 phyver = btc->btc_get_bt_phydm_version(btc);
4149 bt_coex_ver = ((coex_sta->bt_coex_supported_version & 0xff00) >> 8);
4150
4151 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4152 "\r\n %-35s = %d_%02x/ 0x%02x/ 0x%02x (%s)",
4153 "CoexVer WL/ BT_Desired/ BT_Report",
4154 glcoex_ver_date_8821c_1ant, glcoex_ver_8821c_1ant,
4155 glcoex_ver_btdesired_8821c_1ant,
4156 bt_coex_ver,
4157 (bt_coex_ver == 0xff ? "Unknown" :
4158 (coex_sta->bt_disabled ? "BT-disable" :
4159 (bt_coex_ver >= glcoex_ver_btdesired_8821c_1ant ?
4160 "Match" : "Mis-Match"))));
4161 CL_PRINTF(cli_buf);
4162
4163 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4164 "\r\n %-35s = 0x%x(%s)/ 0x%x/ v%d/ %c",
4165 "W_FW/ B_FW/ Phy/ Kt", fw_ver,
4166 (fw_ver >= glcoex_ver_wldesired_8821c_1ant ?
4167 "Match" :
4168 "Mis-Match"),
4169 bt_patch_ver, phyver, coex_sta->kt_ver + 65);
4170 CL_PRINTF(cli_buf);
4171
4172 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4173 "\r\n %-35s = %02x %02x %02x (RF-Ch = %d)",
4174 "AFH Map to BT",
4175 coex_dm->wifi_chnl_info[0], coex_dm->wifi_chnl_info[1],
4176 coex_dm->wifi_chnl_info[2], coex_sta->wl_center_channel);
4177 CL_PRINTF(cli_buf);
4178
4179 /* wifi status */
4180 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4181 "============[Wifi Status]============");
4182 CL_PRINTF(cli_buf);
4183 btc->btc_disp_dbg_msg(btc, BTC_DBG_DISP_WIFI_STATUS);
4184
4185 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4186 "============[BT Status]============");
4187 CL_PRINTF(cli_buf);
4188
4189 pop_report_in_10s++;
4190 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4191 "\r\n %-35s = %s/ %ddBm/ %d/ %d",
4192 "BT status/ rssi/ retryCnt/ popCnt",
4193 ((coex_sta->bt_disabled) ? ("disabled") :
4194 ((coex_sta->c2h_bt_inquiry_page) ? ("inquiry-page") :
4195 ((coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_NCON_IDLE)
4196 ? "non-connected-idle" :
4197 ((coex_dm->bt_status == BT_8821C_1ANT_BSTATUS_CON_IDLE)
4198 ? "connected-idle" : "busy")))),
4199 coex_sta->bt_rssi - 100, coex_sta->bt_retry_cnt,
4200 coex_sta->pop_event_cnt);
4201 CL_PRINTF(cli_buf);
4202
4203 if (pop_report_in_10s >= 5) {
4204 coex_sta->pop_event_cnt = 0;
4205 pop_report_in_10s = 0;
4206 }
4207
4208 if (coex_sta->num_of_profile != 0)
4209 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4210 "\r\n %-35s = %s%s%s%s%s%s (multilink = %d)",
4211 "Profiles", ((bt_link_info->a2dp_exist) ?
4212 ((coex_sta->is_bt_a2dp_sink) ? "A2DP sink," :
4213 "A2DP,") : ""),
4214 ((bt_link_info->sco_exist) ? "HFP," : ""),
4215 ((bt_link_info->hid_exist) ?
4216 ((coex_sta->is_hid_rcu) ? "HID(RCU)" :
4217 ((coex_sta->hid_busy_num >= 2) ? "HID(4/18)," :
4218 (coex_sta->bt_ble_hid_exist ? "HID(BLE)" :
4219 "HID(2/18),"))) : ""), ((bt_link_info->pan_exist) ?
4220 ((coex_sta->is_bt_opp_exist) ? "OPP," : "PAN,") :
4221 ""), ((coex_sta->voice_over_HOGP) ? "Voice," : ""),
4222 ((coex_sta->msft_mr_exist) ? "MR" : ""),
4223 coex_sta->is_bt_multi_link);
4224 else
4225 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s",
4226 "Profiles",
4227 (coex_sta->msft_mr_exist) ? "MR" : "None");
4228
4229 CL_PRINTF(cli_buf);
4230
4231 if (bt_link_info->a2dp_exist) {
4232 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4233 "\r\n %-35s = %s/ %d/ 0x%x/ 0x%x/ %d",
4234 "CQDDR/Bitpool/V_ID/D_name/Flush",
4235 ((coex_sta->is_A2DP_3M) ? "On" : "Off"),
4236 coex_sta->a2dp_bit_pool,
4237 coex_sta->bt_a2dp_vendor_id,
4238 coex_sta->bt_a2dp_device_name,
4239 coex_sta->bt_a2dp_flush_time);
4240 CL_PRINTF(cli_buf);
4241 }
4242
4243 if (bt_link_info->hid_exist) {
4244 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d",
4245 "HID PairNum",
4246 coex_sta->hid_pair_cnt);
4247 CL_PRINTF(cli_buf);
4248 }
4249
4250 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %s/ 0x%x",
4251 "Role/RoleSwCnt/IgnWlact/Feature",
4252 (bt_link_info->slave_role ? "Slave" : "Master"),
4253 coex_sta->cnt_role_switch,
4254 (coex_dm->cur_ignore_wlan_act ? "Yes" : "No"),
4255 coex_sta->bt_coex_supported_feature);
4256 CL_PRINTF(cli_buf);
4257
4258 if (coex_sta->is_ble_scan_en) {
4259 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4260 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4261 "BLEScan Type/TV/Init/Ble",
4262 coex_sta->bt_ble_scan_type,
4263 (coex_sta->bt_ble_scan_type & 0x1 ?
4264 coex_sta->bt_ble_scan_para[0] : 0x0),
4265 (coex_sta->bt_ble_scan_type & 0x2 ?
4266 coex_sta->bt_ble_scan_para[1] : 0x0),
4267 (coex_sta->bt_ble_scan_type & 0x4 ?
4268 coex_sta->bt_ble_scan_para[2] : 0x0));
4269 CL_PRINTF(cli_buf);
4270 }
4271
4272 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4273 "\r\n %-35s = %d/ %d/ %d/ %d/ %d %s",
4274 "ReInit/ReLink/IgnWlact/Page/NameReq",
4275 coex_sta->cnt_reinit,
4276 coex_sta->cnt_setup_link,
4277 coex_sta->cnt_ign_wlan_act,
4278 coex_sta->cnt_page,
4279 coex_sta->cnt_remote_name_req,
4280 (coex_sta->is_setup_link ? "(Relink!!)" : ""));
4281 CL_PRINTF(cli_buf);
4282
4283 halbtc8821c1ant_read_scbd(btc, &u16tmp[0]);
4284
4285 if (coex_sta->bt_reg_vendor_ae == 0xffff ||
4286 coex_sta->bt_reg_vendor_ac == 0xffff)
4287 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4288 "\r\n %-35s = x/ x/ 0x%04x",
4289 "0xae[4]/0xac[1:0]/ScBd(B->W)", u16tmp[0]);
4290 else
4291 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4292 "\r\n %-35s = 0x%x/ 0x%x/ 0x%04x",
4293 "0xae[4]/0xac[1:0]/ScBd(B->W)",
4294 (int)((coex_sta->bt_reg_vendor_ae & BIT(4)) >> 4),
4295 coex_sta->bt_reg_vendor_ac & 0x3, u16tmp[0]);
4296 CL_PRINTF(cli_buf);
4297
4298 if (coex_sta->num_of_profile > 0) {
4299 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4300 "\r\n %-35s = %02x%02x%02x%02x %02x%02x%02x%02x %02x%02x",
4301 "AFH MAP",
4302 coex_sta->bt_afh_map[0],
4303 coex_sta->bt_afh_map[1],
4304 coex_sta->bt_afh_map[2],
4305 coex_sta->bt_afh_map[3],
4306 coex_sta->bt_afh_map[4],
4307 coex_sta->bt_afh_map[5],
4308 coex_sta->bt_afh_map[6],
4309 coex_sta->bt_afh_map[7],
4310 coex_sta->bt_afh_map[8],
4311 coex_sta->bt_afh_map[9]);
4312 CL_PRINTF(cli_buf);
4313 }
4314
4315 for (i = 0; i < BT_8821C_1ANT_INFO_SRC_MAX; i++) {
4316 if (coex_sta->bt_info_c2h_cnt[i]) {
4317 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4318 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x (%d)",
4319 glbt_info_src_8821c_1ant[i],
4320 coex_sta->bt_info_c2h[i][0],
4321 coex_sta->bt_info_c2h[i][1],
4322 coex_sta->bt_info_c2h[i][2],
4323 coex_sta->bt_info_c2h[i][3],
4324 coex_sta->bt_info_c2h[i][4],
4325 coex_sta->bt_info_c2h[i][5],
4326 coex_sta->bt_info_c2h[i][6],
4327 coex_sta->bt_info_c2h_cnt[i]);
4328 CL_PRINTF(cli_buf);
4329 }
4330 }
4331
4332
4333 if (btc->manual_control)
4334 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4335 "============[mechanisms] (before Manual)============");
4336 else
4337 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4338 "============[Mechanisms]============");
4339
4340 CL_PRINTF(cli_buf);
4341
4342 ps_tdma_case = coex_dm->cur_ps_tdma;
4343 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4344 "\r\n %-35s = %02x %02x %02x %02x %02x (case-%d, %s, Timer:%d)",
4345 "TDMA",
4346 coex_dm->ps_tdma_para[0], coex_dm->ps_tdma_para[1],
4347 coex_dm->ps_tdma_para[2], coex_dm->ps_tdma_para[3],
4348 coex_dm->ps_tdma_para[4], ps_tdma_case,
4349 (coex_dm->cur_ps_tdma_on ? "On" : "Off"),
4350 coex_sta->tdma_timer_base);
4351 CL_PRINTF(cli_buf);
4352
4353 switch (coex_sta->wl_coex_mode) {
4354 case BT_8821C_1ANT_WLINK_2G1PORT:
4355 default:
4356 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4357 "\r\n %-35s = %s", "Coex_Mode", "2G-SP");
4358 break;
4359 case BT_8821C_1ANT_WLINK_2GMPORT:
4360 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4361 "\r\n %-35s = %s", "Coex_Mode", "2G-MP");
4362 break;
4363 case BT_8821C_1ANT_WLINK_25GMPORT:
4364 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4365 "\r\n %-35s = %s", "Coex_Mode", "25G-MP");
4366 break;
4367 case BT_8821C_1ANT_WLINK_5G:
4368 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4369 "\r\n %-35s = %s", "Coex_Mode", "5G");
4370 break;
4371 case BT_8821C_1ANT_WLINK_2GGO:
4372 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4373 "\r\n %-35s = %s", "Coex_Mode", "2G-P2P");
4374 break;
4375 case BT_8821C_1ANT_WLINK_BTMR:
4376 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4377 "\r\n %-35s = %s", "Coex_Mode", "BT-MR");
4378 break;
4379 }
4380 CL_PRINTF(cli_buf);
4381
4382 u32tmp[0] = btc->btc_read_4byte(btc, 0x6c0);
4383 u32tmp[1] = btc->btc_read_4byte(btc, 0x6c4);
4384 u32tmp[2] = btc->btc_read_4byte(btc, 0x6c8);
4385 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4386 "\r\n %-35s = %d/ 0x%x/ 0x%x/ 0x%x",
4387 "Table/0x6c0/0x6c4/0x6c8",
4388 coex_sta->coex_table_type, u32tmp[0], u32tmp[1], u32tmp[2]);
4389 CL_PRINTF(cli_buf);
4390
4391 u8tmp[0] = btc->btc_read_1byte(btc, 0x778);
4392 u32tmp[0] = btc->btc_read_4byte(btc, 0x6cc);
4393 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4394 "\r\n %-35s = 0x%x/ 0x%x/ 0x%04x/ %d/ %d",
4395 "0x778/0x6cc/ScBd(W->B)/RunCnt/Rsn", u8tmp[0], u32tmp[0],
4396 coex_sta->score_board_WB, coex_sta->coex_run_cnt,
4397 coex_sta->coex_run_reason);
4398 CL_PRINTF(cli_buf);
4399
4400 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %d/ %d",
4401 "AntDiv/BtCtrlLPS/LPRA/PsFail/g_busy",
4402 (board_info->ant_div_cfg ? "On" : "Off"),
4403 (coex_sta->force_lps_ctrl ? "On" : "Off"),
4404 (coex_dm->cur_low_penalty_ra ? "On" : "Off"),
4405 coex_sta->cnt_set_ps_state_fail,
4406 coex_sta->gl_wifi_busy);
4407 CL_PRINTF(cli_buf);
4408
4409 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d",
4410 "Null All/Retry/Ack/BT_Empty/BT_Late",
4411 coex_sta->wl_fw_dbg_info[1],
4412 coex_sta->wl_fw_dbg_info[2],
4413 coex_sta->wl_fw_dbg_info[3],
4414 coex_sta->wl_fw_dbg_info[4],
4415 coex_sta->wl_fw_dbg_info[5]);
4416 CL_PRINTF(cli_buf);
4417
4418 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s/ %d",
4419 "cnt TDMA_Togg/LK5ms/LK5ms_off/fw",
4420 coex_sta->wl_fw_dbg_info[6], coex_sta->wl_fw_dbg_info[7],
4421 ((coex_sta->is_no_wl_5ms_extend) ? "Yes" : "No"),
4422 coex_sta->cnt_wl_fw_notify);
4423 CL_PRINTF(cli_buf);
4424
4425 u32tmp[0] = halbtc8821c1ant_read_indirect_reg(btc, 0x38);
4426 lte_coex_on = ((u32tmp[0] & BIT(7)) >> 7) ? TRUE : FALSE;
4427
4428 if (lte_coex_on) {
4429 u32tmp[0] = halbtc8821c1ant_read_indirect_reg(btc, 0xa0);
4430 u32tmp[1] = halbtc8821c1ant_read_indirect_reg(btc, 0xa4);
4431
4432 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x",
4433 "LTE Coex Table W_L/B_L", u32tmp[0] & 0xffff,
4434 u32tmp[1] & 0xffff);
4435 CL_PRINTF(cli_buf);
4436
4437 u32tmp[0] = halbtc8821c1ant_read_indirect_reg(btc, 0xa8);
4438 u32tmp[1] = halbtc8821c1ant_read_indirect_reg(btc, 0xac);
4439 u32tmp[2] = halbtc8821c1ant_read_indirect_reg(btc, 0xb0);
4440 u32tmp[3] = halbtc8821c1ant_read_indirect_reg(btc, 0xb4);
4441
4442 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4443 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4444 "LTE Break Table W_L/B_L/L_W/L_B",
4445 u32tmp[0] & 0xffff, u32tmp[1] & 0xffff,
4446 u32tmp[2] & 0xffff, u32tmp[3] & 0xffff);
4447 CL_PRINTF(cli_buf);
4448 }
4449
4450 /* Hw setting */
4451 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s",
4452 "============[Hw setting]============");
4453 CL_PRINTF(cli_buf);
4454
4455 u32tmp[0] = halbtc8821c1ant_read_indirect_reg(btc, 0x38);
4456 u32tmp[1] = halbtc8821c1ant_read_indirect_reg(btc, 0x54);
4457 u8tmp[0] = btc->btc_read_1byte(btc, 0x73);
4458
4459 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s",
4460 "LTE Coex/Path Owner",
4461 ((lte_coex_on) ? "On" : "Off") ,
4462 ((u8tmp[0] & BIT(2)) ? "WL" : "BT"));
4463 CL_PRINTF(cli_buf);
4464
4465 if (lte_coex_on) {
4466 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4467 "\r\n %-35s = %d/ %d/ %d/ %d",
4468 "LTE 3Wire/OPMode/UART/UARTMode",
4469 (int)((u32tmp[0] & BIT(6)) >> 6),
4470 (int)((u32tmp[0] & (BIT(5) | BIT(4))) >> 4),
4471 (int)((u32tmp[0] & BIT(3)) >> 3),
4472 (int)(u32tmp[0] & (BIT(2) | BIT(1) | BIT(0))));
4473 CL_PRINTF(cli_buf);
4474
4475 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4476 "LTE_Busy/UART_Busy",
4477 (int)((u32tmp[1] & BIT(1)) >> 1),
4478 (int)(u32tmp[1] & BIT(0)));
4479 CL_PRINTF(cli_buf);
4480 }
4481 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4482 "\r\n %-35s = %s (BB:%s)/ %s (BB:%s)/ %s (gnt_err = %d)",
4483 "GNT_WL_Ctrl/GNT_BT_Ctrl/Dbg",
4484 ((u32tmp[0] & BIT(12)) ? "SW" : "HW"),
4485 ((u32tmp[0] & BIT(8)) ? "SW" : "HW"),
4486 ((u32tmp[0] & BIT(14)) ? "SW" : "HW"),
4487 ((u32tmp[0] & BIT(10)) ? "SW" : "HW"),
4488 ((u8tmp[0] & BIT(3)) ? "On" : "Off"),
4489 coex_sta->gnt_error_cnt);
4490 CL_PRINTF(cli_buf);
4491
4492 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ 0x%x",
4493 "GNT_WL/GNT_BT/ RF_0x1",
4494 (int)((u32tmp[1] & BIT(2)) >> 2),
4495 (int)((u32tmp[1] & BIT(3)) >> 3),
4496 btc->btc_get_rf_reg(btc, BTC_RF_A, 0x1, 0xfffff));
4497 CL_PRINTF(cli_buf);
4498
4499
4500 u32tmp[0] = btc->btc_read_4byte(btc, 0xcb0);
4501 u32tmp[1] = btc->btc_read_4byte(btc, 0xcb4);
4502 u8tmp[0] = btc->btc_read_1byte(btc, 0xcba);
4503
4504 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4505 "\r\n %-35s = 0x%04x/ 0x%04x/ 0x%02x %s",
4506 "0xcb0/0xcb4/0xcb8[23:16]",
4507 u32tmp[0], u32tmp[1], u8tmp[0],
4508 ((u8tmp[0] & 0x1) == 0x1 ? "(BTG)" : "(WL_A+G)"));
4509 CL_PRINTF(cli_buf);
4510
4511 u32tmp[0] = btc->btc_read_4byte(btc, 0x430);
4512 u32tmp[1] = btc->btc_read_4byte(btc, 0x434);
4513 u16tmp[0] = btc->btc_read_2byte(btc, 0x42a);
4514 u8tmp[0] = btc->btc_read_1byte(btc, 0x426);
4515 u8tmp[1] = btc->btc_read_1byte(btc, 0x45e);
4516 u8tmp[2] = btc->btc_read_1byte(btc, 0x455);
4517 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4518 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x/ 0x%x/ 0x%x",
4519 "430/434/42a/426/45e[3]/455",
4520 u32tmp[0], u32tmp[1], u16tmp[0], u8tmp[0],
4521 (int)((u8tmp[1] & BIT(3)) >> 3), u8tmp[2]);
4522 CL_PRINTF(cli_buf);
4523
4524 u32tmp[0] = btc->btc_read_4byte(btc, 0x4c);
4525 u8tmp[2] = btc->btc_read_1byte(btc, 0x64);
4526 u8tmp[0] = btc->btc_read_1byte(btc, 0x4c6);
4527 u8tmp[1] = btc->btc_read_1byte(btc, 0x40);
4528
4529 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4530 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4531 "4c[24:23]/64[0]/4c6[4]/40[5]",
4532 (int)(u32tmp[0] & (BIT(24) | BIT(23))) >> 23,
4533 u8tmp[2] & 0x1, (int)((u8tmp[0] & BIT(4)) >> 4),
4534 (int)((u8tmp[1] & BIT(5)) >> 5));
4535 CL_PRINTF(cli_buf);
4536
4537 u32tmp[0] = btc->btc_read_4byte(btc, 0x550);
4538 u8tmp[0] = btc->btc_read_1byte(btc, 0x522);
4539 u8tmp[1] = btc->btc_read_1byte(btc, 0x953);
4540 u8tmp[2] = btc->btc_read_1byte(btc, 0xc50);
4541 u8tmp[3] = btc->btc_read_1byte(btc, 0x60a);
4542
4543 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4544 "\r\n %-35s = 0x%x/ 0x%x/ %s/ 0x%x/ 0x%x",
4545 "0x550/0x522/4-RxAGC/0xc50/0x60a",
4546 u32tmp[0], u8tmp[0], (u8tmp[1] & 0x2) ? "On" : "Off",
4547 u8tmp[2], u8tmp[3]);
4548 CL_PRINTF(cli_buf);
4549
4550 fa_ofdm = btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_FA_OFDM);
4551 fa_cck = btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_FA_CCK);
4552 cca_ofdm = btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CCA_OFDM);
4553 cca_cck = btc->btc_phydm_query_PHY_counter(btc, PHYDM_INFO_CCA_CCK);
4554
4555 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4556 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x",
4557 "CCK-CCA/CCK-FA/OFDM-CCA/OFDM-FA",
4558 cca_cck, fa_cck, cca_ofdm, fa_ofdm);
4559 CL_PRINTF(cli_buf);
4560
4561 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
4562 "CRC_OK CCK/11g/11n/11ac",
4563 coex_sta->crc_ok_cck, coex_sta->crc_ok_11g,
4564 coex_sta->crc_ok_11n, coex_sta->crc_ok_11n_vht);
4565 CL_PRINTF(cli_buf);
4566
4567 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d",
4568 "CRC_Err CCK/11g/11n/11ac",
4569 coex_sta->crc_err_cck, coex_sta->crc_err_11g,
4570 coex_sta->crc_err_11n, coex_sta->crc_err_11n_vht);
4571 CL_PRINTF(cli_buf);
4572
4573 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE,
4574 "\r\n %-35s = %d/ %d/ %s-%d/ %d (Tx macid: %d)",
4575 "Rate RxD/RxRTS/TxD/TxRetry_ratio",
4576 coex_sta->wl_rx_rate, coex_sta->wl_rts_rx_rate,
4577 (coex_sta->wl_tx_rate & 0x80 ? "SGI" : "LGI"),
4578 coex_sta->wl_tx_rate & 0x7f,
4579 coex_sta->wl_tx_retry_ratio,
4580 coex_sta->wl_tx_macid);
4581 CL_PRINTF(cli_buf);
4582
4583 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s/ %s/ %d",
4584 "HiPr/ Locking/ warn/ Locked/ Noisy",
4585 (coex_sta->wifi_high_pri_task1 ? "Yes" : "No"),
4586 (coex_sta->cck_lock ? "Yes" : "No"),
4587 (coex_sta->cck_lock_warn ? "Yes" : "No"),
4588 (coex_sta->cck_lock_ever ? "Yes" : "No"),
4589 coex_sta->wl_noisy_level);
4590 CL_PRINTF(cli_buf);
4591
4592 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d",
4593 "0x770(Hi-pri rx/tx)",
4594 coex_sta->high_priority_rx, coex_sta->high_priority_tx);
4595 CL_PRINTF(cli_buf);
4596
4597 CL_SPRINTF(cli_buf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d %s",
4598 "0x774(Lo-pri rx/tx)",
4599 coex_sta->low_priority_rx, coex_sta->low_priority_tx,
4600 (bt_link_info->slave_role ? "(Slave!!)" : " "));
4601 CL_PRINTF(cli_buf);
4602
4603 btc->btc_disp_dbg_msg(btc, BTC_DBG_DISP_COEX_STATISTICS);
4604 }
4605
ex_halbtc8821c1ant_ips_notify(struct btc_coexist * btc,u8 type)4606 void ex_halbtc8821c1ant_ips_notify(struct btc_coexist *btc, u8 type)
4607 {
4608 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
4609
4610 if (btc->manual_control || btc->stop_coex_dm)
4611 return;
4612
4613 if (type == BTC_IPS_ENTER) {
4614 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4615 "[BTCoex], IPS ENTER notify\n");
4616 BTC_TRACE(trace_buf);
4617 coex_sta->under_ips = TRUE;
4618
4619 /* Write WL "Active" in Score-board for LPS off */
4620 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
4621 BT_8821C_1ANT_SCBD_ONOFF |
4622 BT_8821C_1ANT_SCBD_SCAN |
4623 BT_8821C_1ANT_SCBD_UNDERTEST,
4624 FALSE);
4625
4626 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
4627 BT_8821C_1ANT_PHASE_WOFF);
4628 halbtc8821c1ant_action_coex_all_off(btc);
4629 } else if (type == BTC_IPS_LEAVE) {
4630 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4631 "[BTCoex], IPS LEAVE notify\n");
4632 BTC_TRACE(trace_buf);
4633
4634 halbtc8821c1ant_init_hw_config(btc, FALSE, FALSE);
4635 halbtc8821c1ant_init_coex_dm(btc);
4636
4637 coex_sta->under_ips = FALSE;
4638 }
4639 }
4640
ex_halbtc8821c1ant_lps_notify(struct btc_coexist * btc,u8 type)4641 void ex_halbtc8821c1ant_lps_notify(struct btc_coexist *btc, u8 type)
4642 {
4643 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
4644
4645 if (btc->manual_control || btc->stop_coex_dm)
4646 return;
4647
4648 if (type == BTC_LPS_ENABLE) {
4649 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4650 "[BTCoex], LPS ENABLE notify\n");
4651 BTC_TRACE(trace_buf);
4652 coex_sta->under_lps = TRUE;
4653
4654 if (coex_sta->force_lps_ctrl == TRUE) { /* LPS No-32K */
4655 /* Write WL "Active" in Score-board for PS-TDMA */
4656 halbtc8821c1ant_write_scbd(btc,
4657 BT_8821C_1ANT_SCBD_ACTIVE,
4658 TRUE);
4659 } else { /* LPS-32K, need check if this h2c 0x71 can work??
4660 *(2015/08/28)
4661 * Write WL "Non-Active" in Score-board for Native-PS
4662 */
4663 halbtc8821c1ant_write_scbd(btc,
4664 BT_8821C_1ANT_SCBD_ACTIVE,
4665 FALSE);
4666
4667 halbtc8821c1ant_action_wifi_native_lps(btc);
4668 }
4669 } else if (type == BTC_LPS_DISABLE) {
4670 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4671 "[BTCoex], LPS DISABLE notify\n");
4672 BTC_TRACE(trace_buf);
4673 coex_sta->under_lps = FALSE;
4674
4675 /* Write WL "Active" in Score-board for LPS off */
4676 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE,
4677 TRUE);
4678
4679 if (!coex_sta->force_lps_ctrl) {
4680 halbtc8821c1ant_query_bt_info(btc);
4681 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_LPS);
4682 }
4683 }
4684 }
4685
ex_halbtc8821c1ant_scan_notify(struct btc_coexist * btc,u8 type)4686 void ex_halbtc8821c1ant_scan_notify(struct btc_coexist *btc,
4687 u8 type)
4688 {
4689 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
4690 boolean wifi_connected = FALSE;
4691
4692 if (btc->manual_control ||
4693 btc->stop_coex_dm)
4694 return;
4695
4696 coex_sta->freeze_coexrun_by_btinfo = FALSE;
4697
4698 btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
4699
4700 if (wifi_connected)
4701 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4702 "[BTCoex], ********** WL connected before SCAN\n");
4703 else
4704 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4705 "[BTCoex], ********** WL is not connected before SCAN\n");
4706
4707 BTC_TRACE(trace_buf);
4708
4709 if (type != BTC_SCAN_FINISH) {
4710
4711 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
4712 BT_8821C_1ANT_SCBD_SCAN |
4713 BT_8821C_1ANT_SCBD_ONOFF,
4714 TRUE);
4715 }
4716
4717 if (type == BTC_SCAN_START_5G) {
4718 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4719 "[BTCoex], SCAN START notify (5G)\n");
4720 BTC_TRACE(trace_buf);
4721
4722 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
4723 BT_8821C_1ANT_PHASE_5G);
4724
4725 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_5GSCANSTART);
4726 } else if (type == BTC_SCAN_START_2G || type == BTC_SCAN_START) {
4727 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4728 "[BTCoex], SCAN START notify (2G)\n");
4729 BTC_TRACE(trace_buf);
4730
4731 if (!wifi_connected)
4732 coex_sta->wifi_high_pri_task2 = TRUE;
4733
4734 /* Force antenna setup for no scan result issue */
4735 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
4736 BT_8821C_1ANT_PHASE_2G);
4737
4738 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_2GSCANSTART);
4739 } else {
4740 btc->btc_get(btc, BTC_GET_U1_AP_NUM, &coex_sta->scan_ap_num);
4741
4742 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4743 "[BTCoex], SCAN FINISH notify (Scan-AP = %d)\n",
4744 coex_sta->scan_ap_num);
4745 BTC_TRACE(trace_buf);
4746
4747 coex_sta->wifi_high_pri_task2 = FALSE;
4748
4749 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_SCANFINISH);
4750 }
4751 }
4752
ex_halbtc8821c1ant_switchband_notify(struct btc_coexist * btc,u8 type)4753 void ex_halbtc8821c1ant_switchband_notify(struct btc_coexist *btc, u8 type)
4754 {
4755 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
4756
4757 if (btc->manual_control || btc->stop_coex_dm)
4758 return;
4759
4760 coex_sta->switch_band_notify_to = type;
4761
4762 if (type == BTC_SWITCH_TO_5G) {
4763 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4764 "[BTCoex], switchband_notify --- switch to 5G\n");
4765 BTC_TRACE(trace_buf);
4766
4767 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_5GSWITCHBAND);
4768
4769 } else if (type == BTC_SWITCH_TO_24G_NOFORSCAN) {
4770 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4771 "[BTCoex], switchband_notify --- BTC_SWITCH_TO_2G (no for scan)\n");
4772 BTC_TRACE(trace_buf);
4773
4774 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_2GSWITCHBAND);
4775
4776 } else {
4777 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4778 "[BTCoex], switchband_notify --- switch to 2G\n");
4779 BTC_TRACE(trace_buf);
4780
4781 ex_halbtc8821c1ant_scan_notify(btc, BTC_SCAN_START_2G);
4782 }
4783
4784 coex_sta->switch_band_notify_to = BTC_NOT_SWITCH;
4785 }
4786
ex_halbtc8821c1ant_connect_notify(struct btc_coexist * btc,u8 type)4787 void ex_halbtc8821c1ant_connect_notify(struct btc_coexist *btc, u8 type)
4788 {
4789 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
4790 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
4791
4792 if (btc->manual_control || btc->stop_coex_dm)
4793 return;
4794
4795 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
4796 BT_8821C_1ANT_SCBD_SCAN |
4797 BT_8821C_1ANT_SCBD_ONOFF,
4798 TRUE);
4799
4800 if (type == BTC_ASSOCIATE_5G_START ||
4801 type == BTC_ASSOCIATE_5G_FINISH) {
4802 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
4803 BT_8821C_1ANT_PHASE_5G);
4804
4805 if (type == BTC_ASSOCIATE_5G_START) {
4806 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4807 "[BTCoex], CONNECT START notify (5G)\n");
4808 BTC_TRACE(trace_buf);
4809
4810 halbtc8821c1ant_run_coex(btc,
4811 BT_8821C_1ANT_RSN_5GCONSTART);
4812 } else {
4813 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4814 "[BTCoex], CONNECT FINISH notify (5G)\n");
4815 BTC_TRACE(trace_buf);
4816
4817 halbtc8821c1ant_run_coex(btc,
4818 BT_8821C_1ANT_RSN_5GCONFINISH);
4819 }
4820
4821 } else if (type == BTC_ASSOCIATE_START) {
4822 coex_sta->wifi_high_pri_task1 = TRUE;
4823 coex_dm->arp_cnt = 0;
4824 coex_sta->connect_ap_period_cnt = 2;
4825
4826 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4827 "[BTCoex], CONNECT START notify (2G)\n");
4828 BTC_TRACE(trace_buf);
4829
4830 /* Force antenna setup for no scan result issue */
4831 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
4832 BT_8821C_1ANT_PHASE_2G);
4833
4834 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_2GCONSTART);
4835
4836 /* To keep TDMA case during connect process,
4837 * to avoid changed by Btinfo and runcoexmechanism
4838 */
4839 coex_sta->freeze_coexrun_by_btinfo = TRUE;
4840 } else {
4841 coex_sta->wifi_high_pri_task1 = FALSE;
4842 coex_sta->freeze_coexrun_by_btinfo = FALSE;
4843
4844 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4845 "[BTCoex], CONNECT FINISH notify (2G)\n");
4846 BTC_TRACE(trace_buf);
4847
4848 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_2GCONFINISH);
4849 }
4850 }
4851
ex_halbtc8821c1ant_media_status_notify(struct btc_coexist * btc,u8 type)4852 void ex_halbtc8821c1ant_media_status_notify(struct btc_coexist *btc, u8 type)
4853 {
4854 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
4855 boolean wifi_under_b_mode = FALSE;
4856 u8 h2c_parameter[2] = {0};
4857
4858 if (btc->manual_control || btc->stop_coex_dm)
4859 return;
4860
4861 if (type == BTC_MEDIA_CONNECT || type == BTC_MEDIA_CONNECT_5G) {
4862
4863 halbtc8821c1ant_write_scbd(btc,
4864 BT_8821C_1ANT_SCBD_ACTIVE |
4865 BT_8821C_1ANT_SCBD_ONOFF,
4866 TRUE);
4867
4868 if (type == BTC_MEDIA_CONNECT_5G) {
4869
4870 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4871 "[BTCoex], media_status_notify --- 5G\n");
4872 BTC_TRACE(trace_buf);
4873
4874 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO,
4875 FC_EXCU,
4876 BT_8821C_1ANT_PHASE_5G);
4877
4878 halbtc8821c1ant_run_coex(btc,
4879 BT_8821C_1ANT_RSN_5GMEDIA);
4880 } else {
4881 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4882 "[BTCoex], media_status_notify --- 2G\n");
4883 BTC_TRACE(trace_buf);
4884
4885 /* Force antenna setup for no scan result issue */
4886 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO,
4887 FC_EXCU,
4888 BT_8821C_1ANT_PHASE_2G);
4889
4890 btc->btc_get(btc, BTC_GET_BL_WIFI_UNDER_B_MODE,
4891 &wifi_under_b_mode);
4892
4893 /* Set CCK Tx/Rx high Pri except 11b mode */
4894 if (wifi_under_b_mode)
4895 btc->btc_write_1byte_bitmask(btc, 0x6cf, BIT(4),
4896 0x0);
4897 else
4898 btc->btc_write_1byte_bitmask(btc, 0x6cf, BIT(4),
4899 0x1);
4900 /*Leap-AP protection will reopen when connecting AP*/
4901 h2c_parameter[0] = 0xc;
4902 h2c_parameter[1] = 0x0;
4903 btc->btc_fill_h2c(btc, 0x69, 2, h2c_parameter);
4904 coex_sta->is_no_wl_5ms_extend = FALSE;
4905
4906 halbtc8821c1ant_run_coex(btc,
4907 BT_8821C_1ANT_RSN_2GMEDIA);
4908 }
4909 } else {
4910
4911 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4912 "[BTCoex], media disconnect notify\n");
4913 BTC_TRACE(trace_buf);
4914
4915 btc->btc_write_1byte_bitmask(btc, 0x6cf, BIT(4), 0x0);
4916
4917 coex_sta->cck_lock_ever = FALSE;
4918 coex_sta->cck_lock_warn = FALSE;
4919 coex_sta->cck_lock = FALSE;
4920 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_MEDIADISCON);
4921 }
4922 btc->btc_get(btc, BTC_GET_U1_IOT_PEER, &coex_sta->wl_iot_peer);
4923 halbtc8821c1ant_update_wifi_ch_info(btc, type);
4924 }
4925
ex_halbtc8821c1ant_specific_packet_notify(struct btc_coexist * btc,u8 type)4926 void ex_halbtc8821c1ant_specific_packet_notify(struct btc_coexist *btc, u8 type)
4927 {
4928 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
4929 struct coex_dm_8821c_1ant *coex_dm = &btc->coex_dm_8821c_1ant;
4930 boolean under_4way = FALSE;
4931
4932 if (btc->manual_control || btc->stop_coex_dm)
4933 return;
4934
4935 if (type & BTC_5G_BAND) {
4936 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4937 "[BTCoex], 5g special packet notify\n");
4938 BTC_TRACE(trace_buf);
4939
4940 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_5GSPECIALPKT);
4941 return;
4942 }
4943
4944 btc->btc_get(btc, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &under_4way);
4945
4946 if (under_4way) {
4947 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4948 "[BTCoex], specific Packet ---- under_4way!!\n");
4949 BTC_TRACE(trace_buf);
4950
4951 coex_sta->wifi_high_pri_task1 = TRUE;
4952 coex_sta->specific_pkt_period_cnt = 2;
4953 } else if (type == BTC_PACKET_ARP) {
4954 coex_dm->arp_cnt++;
4955 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4956 "[BTCoex], specific Packet ARP notify -cnt = %d\n",
4957 coex_dm->arp_cnt);
4958 BTC_TRACE(trace_buf);
4959
4960 } else {
4961 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
4962 "[BTCoex], specific Packet DHCP or EAPOL notify [Type = %d]\n",
4963 type);
4964 BTC_TRACE(trace_buf);
4965
4966 coex_sta->wifi_high_pri_task1 = TRUE;
4967 coex_sta->specific_pkt_period_cnt = 2;
4968 }
4969
4970 if (coex_sta->wifi_high_pri_task1) {
4971 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_SCAN, TRUE);
4972 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_2GSPECIALPKT);
4973 }
4974 }
4975
ex_halbtc8821c1ant_bt_info_notify(struct btc_coexist * btc,u8 * tmp_buf,u8 length)4976 void ex_halbtc8821c1ant_bt_info_notify(struct btc_coexist *btc, u8 *tmp_buf,
4977 u8 length)
4978 {
4979 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
4980 struct btc_bt_link_info *bt_link_info = &btc->bt_link_info;
4981 u8 i, rsp_source = 0;
4982 boolean wifi_connected = FALSE;
4983 boolean wifi_busy = FALSE;
4984 static boolean is_scoreboard_scan;
4985 const u16 type_is_scan = BT_8821C_1ANT_SCBD_SCAN;
4986 u8 type;
4987
4988 rsp_source = tmp_buf[0] & 0xf;
4989 if (rsp_source >= BT_8821C_1ANT_INFO_SRC_MAX)
4990 rsp_source = BT_8821C_1ANT_INFO_SRC_WIFI_FW;
4991 coex_sta->bt_info_c2h_cnt[rsp_source]++;
4992
4993 if (rsp_source == BT_8821C_1ANT_INFO_SRC_BT_RSP ||
4994 rsp_source == BT_8821C_1ANT_INFO_SRC_BT_ACT) {
4995 if (coex_sta->bt_disabled) {
4996 coex_sta->bt_disabled = FALSE;
4997 coex_sta->is_bt_reenable = TRUE;
4998 coex_sta->cnt_bt_reenable = 15;
4999
5000 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5001 "[BTCoex], BT enable detected by bt_info\n");
5002 BTC_TRACE(trace_buf);
5003 }
5004 }
5005
5006 if (rsp_source == BT_8821C_1ANT_INFO_SRC_WIFI_FW) {
5007 #if 0
5008 halbtc8821c1ant_update_bt_link_info(btc);
5009 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_BTINFO);
5010 #endif
5011 return;
5012 }
5013
5014 if (length != 7) {
5015 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5016 "[BTCoex], Bt_info length = %d invalid!!\n",
5017 length);
5018 BTC_TRACE(trace_buf);
5019 return;
5020 }
5021
5022 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5023 "[BTCoex], Bt_info[%d], len=%d, data=[%02x %02x %02x %02x %02x %02x]\n",
5024 tmp_buf[0], length, tmp_buf[1], tmp_buf[2], tmp_buf[3],
5025 tmp_buf[4], tmp_buf[5], tmp_buf[6]);
5026 BTC_TRACE(trace_buf);
5027
5028 for (i = 0; i < 7; i++)
5029 coex_sta->bt_info_c2h[rsp_source][i] = tmp_buf[i];
5030
5031 if (coex_sta->bt_info_c2h[rsp_source][1] == coex_sta->bt_info_lb2 &&
5032 coex_sta->bt_info_c2h[rsp_source][2] == coex_sta->bt_info_lb3 &&
5033 coex_sta->bt_info_c2h[rsp_source][3] == coex_sta->bt_info_hb0 &&
5034 coex_sta->bt_info_c2h[rsp_source][4] == coex_sta->bt_info_hb1 &&
5035 coex_sta->bt_info_c2h[rsp_source][5] == coex_sta->bt_info_hb2 &&
5036 coex_sta->bt_info_c2h[rsp_source][6] == coex_sta->bt_info_hb3) {
5037 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5038 "[BTCoex], Return because Btinfo duplicate!!\n");
5039 BTC_TRACE(trace_buf);
5040 return;
5041 }
5042
5043 coex_sta->bt_info_lb2 = coex_sta->bt_info_c2h[rsp_source][1];
5044 coex_sta->bt_info_lb3 = coex_sta->bt_info_c2h[rsp_source][2];
5045 coex_sta->bt_info_hb0 = coex_sta->bt_info_c2h[rsp_source][3];
5046 coex_sta->bt_info_hb1 = coex_sta->bt_info_c2h[rsp_source][4];
5047 coex_sta->bt_info_hb2 = coex_sta->bt_info_c2h[rsp_source][5];
5048 coex_sta->bt_info_hb3 = coex_sta->bt_info_c2h[rsp_source][6];
5049
5050 /* if 0xff, it means BT is under WHCK test */
5051 coex_sta->bt_whck_test =
5052 ((coex_sta->bt_info_lb2 == 0xff) ? TRUE : FALSE);
5053
5054 coex_sta->bt_create_connection =
5055 ((coex_sta->bt_info_lb3 & BIT(7)) ? TRUE : FALSE);
5056
5057 /* unit: %, value-100 to translate to unit: dBm */
5058 coex_sta->bt_rssi = coex_sta->bt_info_hb0 * 2 + 10;
5059
5060 coex_sta->c2h_bt_remote_name_req =
5061 ((coex_sta->bt_info_lb3 & BIT(5)) ? TRUE : FALSE);
5062
5063 coex_sta->is_A2DP_3M =
5064 ((coex_sta->bt_info_lb3 & BIT(4)) ? TRUE : FALSE);
5065
5066 coex_sta->acl_busy =
5067 ((coex_sta->bt_info_lb2 & BIT(3)) ? TRUE : FALSE);
5068
5069 coex_sta->voice_over_HOGP =
5070 ((coex_sta->bt_info_hb1 & BIT(4)) ? TRUE : FALSE);
5071
5072 coex_sta->c2h_bt_inquiry_page =
5073 ((coex_sta->bt_info_lb2 & BIT(2)) ? TRUE : FALSE);
5074
5075 if (coex_sta->bt_inq_page_pre != coex_sta->c2h_bt_inquiry_page) {
5076 coex_sta->bt_inq_page_pre = coex_sta->c2h_bt_inquiry_page;
5077 coex_sta->bt_inq_page_remain = TRUE;
5078
5079 if (!coex_sta->c2h_bt_inquiry_page)
5080 coex_sta->bt_inq_page_downcount = 2;
5081 }
5082
5083 if ((coex_sta->bt_info_lb2 & 0x49) == 0x49)
5084 coex_sta->a2dp_bit_pool = (coex_sta->bt_info_hb3 & 0x7f);
5085 else
5086 coex_sta->a2dp_bit_pool = 0;
5087
5088 coex_sta->is_bt_a2dp_sink =
5089 (coex_sta->bt_info_hb3 & BIT(7)) ? TRUE : FALSE;
5090
5091 coex_sta->bt_retry_cnt = coex_sta->bt_info_lb3 & 0xf;
5092
5093 bt_link_info->slave_role = coex_sta->bt_info_hb2 & 0x8;
5094
5095 coex_sta->bt_a2dp_active = coex_sta->bt_info_hb2 & 0x4;
5096
5097 /*for a2dp_active = 0 but bt pkt remain exist ->
5098 * Use PS-TDMA to protect WL RX*/
5099 if (!coex_sta->bt_a2dp_active && coex_sta->bt_a2dp_active_pre) {
5100 coex_sta->bt_a2dp_active_remain = TRUE;
5101 coex_sta->bt_a2dp_active_downcount = 5;
5102 }
5103
5104 coex_sta->bt_a2dp_active_pre = coex_sta->bt_a2dp_active;
5105
5106 coex_sta->hid_busy_num = (coex_sta->bt_info_hb2 & 0x30) >> 4;
5107
5108 coex_sta->hid_pair_cnt = (coex_sta->bt_info_hb2 & 0xc0) >> 6;
5109
5110 if (coex_sta->hid_pair_cnt > 0 && coex_sta->hid_busy_num >= 2) {
5111 coex_sta->bt_418_hid_exist = TRUE;
5112 } else if (coex_sta->hid_pair_cnt == 0 ||
5113 coex_sta->hid_busy_num == 1) {
5114 coex_sta->bt_418_hid_exist = FALSE;
5115 coex_sta->bt_ble_hid_exist = FALSE;
5116 }
5117
5118 coex_sta->is_bt_opp_exist =
5119 (coex_sta->bt_info_hb2 & BIT(0)) ? TRUE : FALSE;
5120
5121 if (coex_sta->bt_retry_cnt >= 1)
5122 coex_sta->pop_event_cnt++;
5123
5124 if (coex_sta->c2h_bt_remote_name_req)
5125 coex_sta->cnt_remote_name_req++;
5126
5127 if (coex_sta->bt_info_hb1 & BIT(1))
5128 coex_sta->cnt_reinit++;
5129
5130 if ((coex_sta->bt_info_hb1 & BIT(2)) ||
5131 (coex_sta->bt_create_connection &&
5132 coex_sta->wl_pnp_wakeup_downcnt > 0)) {
5133 coex_sta->cnt_setup_link++;
5134 coex_sta->is_setup_link = TRUE;
5135
5136 if (coex_sta->is_bt_reenable)
5137 coex_sta->bt_relink_downcount = 6;
5138 else
5139 coex_sta->bt_relink_downcount = 2;
5140 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5141 "[BTCoex], Re-Link start in BT info!!\n");
5142 BTC_TRACE(trace_buf);
5143 }
5144
5145 if (coex_sta->bt_info_hb1 & BIT(3))
5146 coex_sta->cnt_ign_wlan_act++;
5147
5148 if (coex_sta->bt_info_hb1 & BIT(6))
5149 coex_sta->cnt_role_switch++;
5150
5151 if (coex_sta->bt_info_hb1 & BIT(7))
5152 coex_sta->is_bt_multi_link = TRUE;
5153 else
5154 coex_sta->is_bt_multi_link = FALSE;
5155
5156 if (coex_sta->bt_info_lb2 & BIT(5)) {
5157 if (coex_sta->bt_info_hb1 & BIT(0)) {
5158 /*BLE HID*/
5159 coex_sta->bt_ble_hid_exist = TRUE;
5160 coex_sta->is_hid_rcu = FALSE;
5161 }
5162 } else if (coex_sta->bt_info_hb1 & BIT(0)) {
5163 /*RCU*/
5164 coex_sta->is_hid_rcu = TRUE;
5165 } else {
5166 coex_sta->bt_ble_hid_exist = FALSE;
5167 coex_sta->is_hid_rcu = FALSE;
5168 }
5169
5170 if (coex_sta->bt_info_hb1 & BIT(5))
5171 coex_sta->is_ble_scan_en = TRUE;
5172 else
5173 coex_sta->is_ble_scan_en = FALSE;
5174
5175 if (coex_sta->bt_create_connection) {
5176 coex_sta->cnt_page++;
5177
5178 btc->btc_get(btc, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
5179
5180 if (coex_sta->is_wifi_linkscan_process ||
5181 coex_sta->wifi_high_pri_task1 ||
5182 coex_sta->wifi_high_pri_task2 || wifi_busy) {
5183 is_scoreboard_scan = TRUE;
5184 halbtc8821c1ant_write_scbd(btc, type_is_scan, TRUE);
5185 } else {
5186 halbtc8821c1ant_write_scbd(btc, type_is_scan, FALSE);
5187 }
5188 } else {
5189 if (is_scoreboard_scan) {
5190 halbtc8821c1ant_write_scbd(btc, type_is_scan, FALSE);
5191 is_scoreboard_scan = FALSE;
5192 }
5193 }
5194
5195 /* Here we need to resend some wifi info to BT */
5196 /* because bt is reset and loss of the info. */
5197 btc->btc_get(btc, BTC_GET_BL_WIFI_CONNECTED, &wifi_connected);
5198 /* Re-Init */
5199 if ((coex_sta->bt_info_hb1 & BIT(1))) {
5200 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5201 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n");
5202 BTC_TRACE(trace_buf);
5203 if (wifi_connected)
5204 type = BTC_MEDIA_CONNECT;
5205 else
5206 type = BTC_MEDIA_DISCONNECT;
5207 halbtc8821c1ant_update_wifi_ch_info(btc, type);
5208 }
5209
5210 /* If Ignore_WLanAct && not SetUp_Link */
5211 if ((coex_sta->bt_info_hb1 & BIT(3)) &&
5212 (!(coex_sta->bt_info_hb1 & BIT(2)))) {
5213 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5214 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n");
5215 BTC_TRACE(trace_buf);
5216 halbtc8821c1ant_ignore_wlan_act(btc, FC_EXCU, FALSE);
5217 }
5218
5219 halbtc8821c1ant_update_bt_link_info(btc);
5220 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_BTINFO);
5221 }
5222
ex_halbtc8821c1ant_wl_fwdbginfo_notify(struct btc_coexist * btc,u8 * tmp_buf,u8 length)5223 void ex_halbtc8821c1ant_wl_fwdbginfo_notify(struct btc_coexist *btc,
5224 u8 *tmp_buf, u8 length)
5225 {
5226 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
5227 u8 i = 0;
5228 static u8 tmp_buf_pre[10];
5229
5230 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5231 "[BTCoex], WiFi Fw Dbg info = %d %d %d %d %d %d %d %d (len = %d)\n",
5232 tmp_buf[0], tmp_buf[1], tmp_buf[2], tmp_buf[3], tmp_buf[4],
5233 tmp_buf[5], tmp_buf[6], tmp_buf[7], length);
5234 BTC_TRACE(trace_buf);
5235
5236 if (tmp_buf[0] == 0x8) {
5237 for (i = 1; i <= 7; i++) {
5238 coex_sta->wl_fw_dbg_info[i] =
5239 (tmp_buf[i] >= tmp_buf_pre[i]) ?
5240 (tmp_buf[i] - tmp_buf_pre[i]) :
5241 (255 - tmp_buf_pre[i] + tmp_buf[i]);
5242
5243 tmp_buf_pre[i] = tmp_buf[i];
5244 }
5245 }
5246
5247 coex_sta->cnt_wl_fw_notify++;
5248 halbtc8821c1ant_ccklock_action(btc);
5249 }
5250
ex_halbtc8821c1ant_rx_rate_change_notify(struct btc_coexist * btc,BOOLEAN is_data_frame,u8 btc_rate_id)5251 void ex_halbtc8821c1ant_rx_rate_change_notify(struct btc_coexist *btc,
5252 BOOLEAN is_data_frame,
5253 u8 btc_rate_id)
5254 {
5255 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
5256
5257 if (is_data_frame) {
5258 coex_sta->wl_rx_rate = btc_rate_id;
5259
5260 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5261 "[BTCoex], rx_rate_change_notify data rate id = %d, RTS_Rate = %d\n",
5262 coex_sta->wl_rx_rate, coex_sta->wl_rts_rx_rate);
5263 BTC_TRACE(trace_buf);
5264 } else {
5265 coex_sta->wl_rts_rx_rate = btc_rate_id;
5266
5267 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5268 "[BTCoex], rts_rate_change_notify RTS rate id = %d, RTS_Rate = %d\n",
5269 coex_sta->wl_rts_rx_rate, coex_sta->wl_rts_rx_rate);
5270 BTC_TRACE(trace_buf);
5271 }
5272
5273 halbtc8821c1ant_ccklock_detect(btc);
5274 }
5275
ex_halbtc8821c1ant_tx_rate_change_notify(struct btc_coexist * btc,u8 tx_rate,u8 tx_retry_ratio,u8 macid)5276 void ex_halbtc8821c1ant_tx_rate_change_notify(struct btc_coexist *btc,
5277 u8 tx_rate, u8 tx_retry_ratio,
5278 u8 macid)
5279 {
5280 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
5281
5282 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5283 "[BTCoex], tx_rate_change_notify Tx_Rate = %d, Tx_Retry_Ratio = %d, macid =%d\n",
5284 tx_rate, tx_retry_ratio, macid);
5285 BTC_TRACE(trace_buf);
5286
5287 coex_sta->wl_tx_rate = tx_rate;
5288 coex_sta->wl_tx_retry_ratio = tx_retry_ratio;
5289 coex_sta->wl_tx_macid = macid;
5290 }
5291
ex_halbtc8821c1ant_rf_status_notify(struct btc_coexist * btc,u8 type)5292 void ex_halbtc8821c1ant_rf_status_notify(struct btc_coexist *btc, u8 type)
5293 {
5294 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
5295
5296 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], RF Status notify\n");
5297 BTC_TRACE(trace_buf);
5298
5299 if (type == BTC_RF_ON) {
5300 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5301 "[BTCoex], RF is turned ON!!\n");
5302 BTC_TRACE(trace_buf);
5303
5304 btc->stop_coex_dm = FALSE;
5305 btc->wl_rf_state_off = FALSE;
5306 } else if (type == BTC_RF_OFF) {
5307 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5308 "[BTCoex], RF is turned OFF!!\n");
5309 BTC_TRACE(trace_buf);
5310
5311 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
5312 BT_8821C_1ANT_SCBD_ONOFF |
5313 BT_8821C_1ANT_SCBD_SCAN |
5314 BT_8821C_1ANT_SCBD_UNDERTEST,
5315 FALSE);
5316
5317 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
5318 BT_8821C_1ANT_PHASE_WOFF);
5319
5320 halbtc8821c1ant_action_coex_all_off(btc);
5321
5322 btc->stop_coex_dm = TRUE;
5323 btc->wl_rf_state_off = TRUE;
5324
5325 /* must place in the last step */
5326 halbtc8821c1ant_update_wifi_ch_info(btc, BTC_MEDIA_DISCONNECT);
5327 }
5328 }
5329
ex_halbtc8821c1ant_halt_notify(struct btc_coexist * btc)5330 void ex_halbtc8821c1ant_halt_notify(struct btc_coexist *btc)
5331 {
5332 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE, "[BTCoex], Halt notify\n");
5333 BTC_TRACE(trace_buf);
5334
5335 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
5336 BT_8821C_1ANT_SCBD_ONOFF |
5337 BT_8821C_1ANT_SCBD_SCAN |
5338 BT_8821C_1ANT_SCBD_UNDERTEST,
5339 FALSE);
5340
5341 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
5342 BT_8821C_1ANT_PHASE_WOFF);
5343
5344 halbtc8821c1ant_action_coex_all_off(btc);
5345
5346 btc->stop_coex_dm = TRUE;
5347
5348 /* must place in the last step */
5349 halbtc8821c1ant_update_wifi_ch_info(btc, BTC_MEDIA_DISCONNECT);
5350 }
5351
ex_halbtc8821c1ant_pnp_notify(struct btc_coexist * btc,u8 pnp_state)5352 void ex_halbtc8821c1ant_pnp_notify(struct btc_coexist *btc, u8 pnp_state)
5353 {
5354 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
5355 struct wifi_link_info_8821c_1ant *wifi_link_info_ext =
5356 &btc->wifi_link_info_8821c_1ant;
5357 static u8 pre_pnp_state;
5358 u8 phase;
5359
5360 if (pnp_state == BTC_WIFI_PNP_SLEEP ||
5361 pnp_state == BTC_WIFI_PNP_SLEEP_KEEP_ANT) {
5362 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5363 "[BTCoex], Pnp notify to SLEEP\n");
5364 BTC_TRACE(trace_buf);
5365
5366 halbtc8821c1ant_write_scbd(btc, BT_8821C_1ANT_SCBD_ACTIVE |
5367 BT_8821C_1ANT_SCBD_ONOFF |
5368 BT_8821C_1ANT_SCBD_SCAN |
5369 BT_8821C_1ANT_SCBD_UNDERTEST,
5370 FALSE);
5371
5372 if (pnp_state == BTC_WIFI_PNP_SLEEP_KEEP_ANT) {
5373 if (wifi_link_info_ext->is_all_under_5g)
5374 phase = BT_8821C_1ANT_PHASE_5G;
5375 else
5376 phase = BT_8821C_1ANT_PHASE_2G;
5377 } else {
5378 phase = BT_8821C_1ANT_PHASE_WOFF;
5379 }
5380
5381 halbtc8821c1ant_set_ant_path(btc, BTC_ANT_PATH_AUTO, FC_EXCU,
5382 phase);
5383 btc->stop_coex_dm = TRUE;
5384 } else {
5385
5386 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5387 "[BTCoex], Pnp notify to WAKE UP\n");
5388 BTC_TRACE(trace_buf);
5389 coex_sta->wl_pnp_wakeup_downcnt = 3;
5390
5391 /*WoWLAN*/
5392 if (pre_pnp_state == BTC_WIFI_PNP_SLEEP_KEEP_ANT ||
5393 pnp_state == BTC_WIFI_PNP_WOWLAN) {
5394 coex_sta->run_time_state = TRUE;
5395 btc->stop_coex_dm = FALSE;
5396 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_PNP);
5397 }
5398 }
5399 pre_pnp_state = pnp_state;
5400 }
5401
ex_halbtc8821c1ant_coex_dm_reset(struct btc_coexist * btc)5402 void ex_halbtc8821c1ant_coex_dm_reset(struct btc_coexist *btc)
5403 {
5404 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5405 "[BTCoex], *****************Coex DM Reset*****************\n");
5406 BTC_TRACE(trace_buf);
5407
5408 halbtc8821c1ant_init_hw_config(btc, FALSE, FALSE);
5409 halbtc8821c1ant_init_coex_dm(btc);
5410 }
5411
ex_halbtc8821c1ant_periodical(struct btc_coexist * btc)5412 void ex_halbtc8821c1ant_periodical(struct btc_coexist *btc)
5413 {
5414 struct coex_sta_8821c_1ant *coex_sta = &btc->coex_sta_8821c_1ant;
5415 struct btc_board_info *board_info = &btc->board_info;
5416 boolean wifi_busy = FALSE;
5417 u16 bt_scoreboard_val = 0;
5418 boolean bt_relink_finish = FALSE, is_defreeze = FALSE,
5419 bt_ctr_change = FALSE;
5420 static u8 freeze_cnt;
5421
5422 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5423 "[BTCoex], ************* Periodical *************\n");
5424 BTC_TRACE(trace_buf);
5425
5426 if (!btc->auto_report)
5427 halbtc8821c1ant_query_bt_info(btc);
5428
5429 bt_ctr_change = halbtc8821c1ant_monitor_bt_ctr(btc);
5430 halbtc8821c1ant_monitor_wifi_ctr(btc);
5431 halbtc8821c1ant_update_wifi_link_info(btc,
5432 BT_8821C_1ANT_RSN_PERIODICAL);
5433 halbtc8821c1ant_monitor_bt_enable(btc);
5434
5435 if (coex_sta->bt_relink_downcount != 0) {
5436 coex_sta->bt_relink_downcount--;
5437
5438 if (coex_sta->bt_relink_downcount == 0) {
5439 coex_sta->is_setup_link = FALSE;
5440 bt_relink_finish = TRUE;
5441 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5442 "[BTCoex], Re-Link stop by periodical count-down!!\n");
5443 BTC_TRACE(trace_buf);
5444 }
5445 }
5446
5447 if (coex_sta->bt_inq_page_downcount != 0) {
5448 coex_sta->bt_inq_page_downcount--;
5449 if (coex_sta->bt_relink_downcount == 0) {
5450 coex_sta->bt_inq_page_remain = FALSE;
5451 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5452 "[BTCoex], BT inquiry-page disappear!!\n");
5453 BTC_TRACE(trace_buf);
5454 }
5455 }
5456
5457 if (coex_sta->bt_a2dp_active_downcount != 0) {
5458 coex_sta->bt_a2dp_active_downcount--;
5459 if (coex_sta->bt_a2dp_active_downcount == 0) {
5460 coex_sta->bt_a2dp_active_remain = FALSE;
5461 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5462 "[BTCoex], BT A2DP active disappear!!\n");
5463 BTC_TRACE(trace_buf);
5464 }
5465 }
5466
5467 if (coex_sta->freeze_coexrun_by_btinfo) {
5468 freeze_cnt++;
5469
5470 if (freeze_cnt >= 5) {
5471 freeze_cnt = 0;
5472 coex_sta->freeze_coexrun_by_btinfo = FALSE;
5473 is_defreeze = TRUE;
5474 }
5475 } else {
5476 freeze_cnt = 0;
5477 }
5478
5479 /* for 4-way, DHCP, EAPOL packet */
5480 if (coex_sta->specific_pkt_period_cnt > 0) {
5481 coex_sta->specific_pkt_period_cnt--;
5482
5483 if (!coex_sta->freeze_coexrun_by_btinfo &&
5484 coex_sta->specific_pkt_period_cnt == 0)
5485 coex_sta->wifi_high_pri_task1 = FALSE;
5486
5487 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5488 "[BTCoex], Hi-Pri Task = %s\n",
5489 (coex_sta->wifi_high_pri_task1 ? "Yes" : "No"));
5490 BTC_TRACE(trace_buf);
5491 }
5492
5493 /*for A2DP glitch during connecting AP*/
5494 if (coex_sta->connect_ap_period_cnt > 0)
5495 coex_sta->connect_ap_period_cnt--;
5496
5497 if (coex_sta->wl_pnp_wakeup_downcnt > 0) {
5498 coex_sta->wl_pnp_wakeup_downcnt--;
5499 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5500 "[BTCoex], wl_pnp_wakeup_downcnt = %d!!\n",
5501 coex_sta->wl_pnp_wakeup_downcnt);
5502 BTC_TRACE(trace_buf);
5503 }
5504
5505 if (coex_sta->cnt_bt_reenable > 0) {
5506 coex_sta->cnt_bt_reenable--;
5507 if (coex_sta->cnt_bt_reenable == 0) {
5508 coex_sta->is_bt_reenable = FALSE;
5509 BTC_SPRINTF(trace_buf, BT_TMP_BUF_SIZE,
5510 "[BTCoex], BT renable 30s finish!!\n");
5511 BTC_TRACE(trace_buf);
5512 }
5513 }
5514
5515 if (halbtc8821c1ant_moniter_wifibt_status(btc) || bt_relink_finish ||
5516 coex_sta->is_set_ps_state_fail || is_defreeze || bt_ctr_change)
5517 halbtc8821c1ant_run_coex(btc, BT_8821C_1ANT_RSN_PERIODICAL);
5518 }
5519
5520 /*#pragma optimize( "", off )*/
5521 #endif
5522
5523 #endif /* #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) */
5524
5525
5526