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