1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2007-2013  Realtek Corporation.*/
3 
4 #include "halbt_precomp.h"
5 
6 /***************************************************
7  *		Debug related function
8  ***************************************************/
9 
10 static const char *const gl_btc_wifi_bw_string[] = {
11 	"11bg",
12 	"HT20",
13 	"HT40",
14 	"HT80",
15 	"HT160"
16 };
17 
18 static const char *const gl_btc_wifi_freq_string[] = {
19 	"2.4G",
20 	"5G"
21 };
22 
23 static bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
24 {
25 	if (!btcoexist->binded || NULL == btcoexist->adapter)
26 		return false;
27 
28 	return true;
29 }
30 
31 static bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
32 {
33 	if (rtlpriv->link_info.busytraffic)
34 		return true;
35 	else
36 		return false;
37 }
38 
39 static void halbtc_dbg_init(void)
40 {
41 }
42 
43 /***************************************************
44  *		helper function
45  ***************************************************/
46 static bool is_any_client_connect_to_ap(struct btc_coexist *btcoexist)
47 {
48 	struct rtl_priv *rtlpriv = btcoexist->adapter;
49 	struct rtl_mac *mac = rtl_mac(rtlpriv);
50 	struct rtl_sta_info *drv_priv;
51 	u8 cnt = 0;
52 
53 	if (mac->opmode == NL80211_IFTYPE_ADHOC ||
54 	    mac->opmode == NL80211_IFTYPE_MESH_POINT ||
55 	    mac->opmode == NL80211_IFTYPE_AP) {
56 		if (in_interrupt() > 0) {
57 			list_for_each_entry(drv_priv, &rtlpriv->entry_list,
58 					    list) {
59 				cnt++;
60 			}
61 		} else {
62 			spin_lock_bh(&rtlpriv->locks.entry_list_lock);
63 			list_for_each_entry(drv_priv, &rtlpriv->entry_list,
64 					    list) {
65 				cnt++;
66 			}
67 			spin_unlock_bh(&rtlpriv->locks.entry_list_lock);
68 		}
69 	}
70 	if (cnt > 0)
71 		return true;
72 	else
73 		return false;
74 }
75 
76 static bool halbtc_legacy(struct rtl_priv *adapter)
77 {
78 	struct rtl_priv *rtlpriv = adapter;
79 	struct rtl_mac *mac = rtl_mac(rtlpriv);
80 
81 	bool is_legacy = false;
82 
83 	if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_G))
84 		is_legacy = true;
85 
86 	return is_legacy;
87 }
88 
89 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
90 {
91 	struct rtl_priv *rtlpriv = adapter;
92 
93 	if (rtlpriv->link_info.tx_busy_traffic)
94 		return true;
95 	else
96 		return false;
97 }
98 
99 static u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
100 {
101 	struct rtl_priv *rtlpriv = btcoexist->adapter;
102 	struct rtl_phy *rtlphy = &rtlpriv->phy;
103 	u32 wifi_bw = BTC_WIFI_BW_HT20;
104 
105 	if (halbtc_legacy(rtlpriv)) {
106 		wifi_bw = BTC_WIFI_BW_LEGACY;
107 	} else {
108 		switch (rtlphy->current_chan_bw) {
109 		case HT_CHANNEL_WIDTH_20:
110 			wifi_bw = BTC_WIFI_BW_HT20;
111 			break;
112 		case HT_CHANNEL_WIDTH_20_40:
113 			wifi_bw = BTC_WIFI_BW_HT40;
114 			break;
115 		case HT_CHANNEL_WIDTH_80:
116 			wifi_bw = BTC_WIFI_BW_HT80;
117 			break;
118 		}
119 	}
120 
121 	return wifi_bw;
122 }
123 
124 static u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
125 {
126 	struct rtl_priv *rtlpriv = btcoexist->adapter;
127 	struct rtl_phy	*rtlphy = &(rtlpriv->phy);
128 	u8 chnl = 1;
129 
130 	if (rtlphy->current_channel != 0)
131 		chnl = rtlphy->current_channel;
132 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
133 		 "static halbtc_get_wifi_central_chnl:%d\n", chnl);
134 	return chnl;
135 }
136 
137 static u8 rtl_get_hwpg_single_ant_path(struct rtl_priv *rtlpriv)
138 {
139 	return rtlpriv->btcoexist.btc_info.single_ant_path;
140 }
141 
142 static u8 rtl_get_hwpg_bt_type(struct rtl_priv *rtlpriv)
143 {
144 	return rtlpriv->btcoexist.btc_info.bt_type;
145 }
146 
147 static u8 rtl_get_hwpg_ant_num(struct rtl_priv *rtlpriv)
148 {
149 	u8 num;
150 
151 	if (rtlpriv->btcoexist.btc_info.ant_num == ANT_X2)
152 		num = 2;
153 	else
154 		num = 1;
155 
156 	return num;
157 }
158 
159 static u8 rtl_get_hwpg_package_type(struct rtl_priv *rtlpriv)
160 {
161 	struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
162 
163 	return rtlhal->package_type;
164 }
165 
166 static
167 u8 rtl_get_hwpg_rfe_type(struct rtl_priv *rtlpriv)
168 {
169 	struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
170 
171 	return rtlhal->rfe_type;
172 }
173 
174 static
175 bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
176 {
177 	if (IS_HARDWARE_TYPE_8812(btcoexist->adapter))
178 		return false;
179 	else
180 		return true;
181 }
182 
183 static
184 bool halbtc_send_bt_mp_operation(struct btc_coexist *btcoexist, u8 op_code,
185 				 u8 *cmd, u32 len, unsigned long wait_ms)
186 {
187 	struct rtl_priv *rtlpriv;
188 	const u8 oper_ver = 0;
189 	u8 req_num;
190 
191 	if (!halbtc_is_hw_mailbox_exist(btcoexist))
192 		return false;
193 
194 	if (wait_ms)	/* before h2c to avoid race condition */
195 		reinit_completion(&btcoexist->bt_mp_comp);
196 
197 	rtlpriv = btcoexist->adapter;
198 
199 	/* fill req_num by op_code, and rtl_btc_btmpinfo_notify() use it
200 	 * to know message type
201 	 */
202 	switch (op_code) {
203 	case BT_OP_GET_BT_VERSION:
204 		req_num = BT_SEQ_GET_BT_VERSION;
205 		break;
206 	case BT_OP_GET_AFH_MAP_L:
207 		req_num = BT_SEQ_GET_AFH_MAP_L;
208 		break;
209 	case BT_OP_GET_AFH_MAP_M:
210 		req_num = BT_SEQ_GET_AFH_MAP_M;
211 		break;
212 	case BT_OP_GET_AFH_MAP_H:
213 		req_num = BT_SEQ_GET_AFH_MAP_H;
214 		break;
215 	case BT_OP_GET_BT_COEX_SUPPORTED_FEATURE:
216 		req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_FEATURE;
217 		break;
218 	case BT_OP_GET_BT_COEX_SUPPORTED_VERSION:
219 		req_num = BT_SEQ_GET_BT_COEX_SUPPORTED_VERSION;
220 		break;
221 	case BT_OP_GET_BT_ANT_DET_VAL:
222 		req_num = BT_SEQ_GET_BT_ANT_DET_VAL;
223 		break;
224 	case BT_OP_GET_BT_BLE_SCAN_PARA:
225 		req_num = BT_SEQ_GET_BT_BLE_SCAN_PARA;
226 		break;
227 	case BT_OP_GET_BT_BLE_SCAN_TYPE:
228 		req_num = BT_SEQ_GET_BT_BLE_SCAN_TYPE;
229 		break;
230 	case BT_OP_GET_BT_DEVICE_INFO:
231 		req_num = BT_SEQ_GET_BT_DEVICE_INFO;
232 		break;
233 	case BT_OP_GET_BT_FORBIDDEN_SLOT_VAL:
234 		req_num = BT_SEQ_GET_BT_FORB_SLOT_VAL;
235 		break;
236 	case BT_OP_WRITE_REG_ADDR:
237 	case BT_OP_WRITE_REG_VALUE:
238 	case BT_OP_READ_REG:
239 	default:
240 		req_num = BT_SEQ_DONT_CARE;
241 		break;
242 	}
243 
244 	cmd[0] |= (oper_ver & 0x0f);		/* Set OperVer */
245 	cmd[0] |= ((req_num << 4) & 0xf0);	/* Set ReqNum */
246 	cmd[1] = op_code;
247 	rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, 0x67, len, cmd);
248 
249 	/* wait? */
250 	if (!wait_ms)
251 		return true;
252 
253 	RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
254 		 "btmpinfo wait req_num=%d wait=%ld\n", req_num, wait_ms);
255 
256 	if (in_interrupt())
257 		return false;
258 
259 	if (wait_for_completion_timeout(&btcoexist->bt_mp_comp,
260 					msecs_to_jiffies(wait_ms)) == 0) {
261 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
262 			 "btmpinfo wait (req_num=%d) timeout\n", req_num);
263 
264 		return false;	/* timeout */
265 	}
266 
267 	return true;
268 }
269 
270 static void halbtc_leave_lps(struct btc_coexist *btcoexist)
271 {
272 	struct rtl_priv *rtlpriv;
273 	bool ap_enable = false;
274 
275 	rtlpriv = btcoexist->adapter;
276 
277 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
278 			   &ap_enable);
279 
280 	if (ap_enable) {
281 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
282 			 "%s()<--dont leave lps under AP mode\n", __func__);
283 		return;
284 	}
285 
286 	btcoexist->bt_info.bt_ctrl_lps = true;
287 	btcoexist->bt_info.bt_lps_on = false;
288 	rtl_lps_leave(rtlpriv->mac80211.hw);
289 }
290 
291 static void halbtc_enter_lps(struct btc_coexist *btcoexist)
292 {
293 	struct rtl_priv *rtlpriv;
294 	bool ap_enable = false;
295 
296 	rtlpriv = btcoexist->adapter;
297 
298 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
299 			   &ap_enable);
300 
301 	if (ap_enable) {
302 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_DMESG,
303 			 "%s()<--dont enter lps under AP mode\n", __func__);
304 		return;
305 	}
306 
307 	btcoexist->bt_info.bt_ctrl_lps = true;
308 	btcoexist->bt_info.bt_lps_on = true;
309 	rtl_lps_enter(rtlpriv->mac80211.hw);
310 }
311 
312 static void halbtc_normal_lps(struct btc_coexist *btcoexist)
313 {
314 	struct rtl_priv *rtlpriv;
315 
316 	rtlpriv = btcoexist->adapter;
317 
318 	if (btcoexist->bt_info.bt_ctrl_lps) {
319 		btcoexist->bt_info.bt_lps_on = false;
320 		rtl_lps_leave(rtlpriv->mac80211.hw);
321 		btcoexist->bt_info.bt_ctrl_lps = false;
322 	}
323 }
324 
325 static void halbtc_pre_normal_lps(struct btc_coexist *btcoexist)
326 {
327 	struct rtl_priv *rtlpriv = btcoexist->adapter;
328 
329 	if (btcoexist->bt_info.bt_ctrl_lps) {
330 		btcoexist->bt_info.bt_lps_on = false;
331 		rtl_lps_leave(rtlpriv->mac80211.hw);
332 	}
333 }
334 
335 static void halbtc_post_normal_lps(struct btc_coexist *btcoexist)
336 {
337 	if (btcoexist->bt_info.bt_ctrl_lps)
338 		btcoexist->bt_info.bt_ctrl_lps = false;
339 }
340 
341 static void halbtc_leave_low_power(struct btc_coexist *btcoexist)
342 {
343 }
344 
345 static void halbtc_normal_low_power(struct btc_coexist *btcoexist)
346 {
347 }
348 
349 static void halbtc_disable_low_power(struct btc_coexist *btcoexist,
350 				     bool low_pwr_disable)
351 {
352 	/* TODO: original/leave 32k low power */
353 	btcoexist->bt_info.bt_disable_low_pwr = low_pwr_disable;
354 }
355 
356 static void halbtc_aggregation_check(struct btc_coexist *btcoexist)
357 {
358 	bool need_to_act = false;
359 	static unsigned long pre_time;
360 	unsigned long cur_time = 0;
361 	struct rtl_priv *rtlpriv = btcoexist->adapter;
362 
363 	/* To void continuous deleteBA=>addBA=>deleteBA=>addBA
364 	 * This function is not allowed to continuous called
365 	 * It can only be called after 8 seconds
366 	 */
367 
368 	cur_time = jiffies;
369 	if (jiffies_to_msecs(cur_time - pre_time) <= 8000) {
370 		/* over 8 seconds you can execute this function again. */
371 		return;
372 	}
373 	pre_time = cur_time;
374 
375 	if (btcoexist->bt_info.reject_agg_pkt) {
376 		need_to_act = true;
377 		btcoexist->bt_info.pre_reject_agg_pkt =
378 			btcoexist->bt_info.reject_agg_pkt;
379 	} else {
380 		if (btcoexist->bt_info.pre_reject_agg_pkt) {
381 			need_to_act = true;
382 			btcoexist->bt_info.pre_reject_agg_pkt =
383 				btcoexist->bt_info.reject_agg_pkt;
384 		}
385 
386 		if (btcoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
387 		    btcoexist->bt_info.bt_ctrl_agg_buf_size) {
388 			need_to_act = true;
389 			btcoexist->bt_info.pre_bt_ctrl_agg_buf_size =
390 				btcoexist->bt_info.bt_ctrl_agg_buf_size;
391 		}
392 
393 		if (btcoexist->bt_info.bt_ctrl_agg_buf_size) {
394 			if (btcoexist->bt_info.pre_agg_buf_size !=
395 			    btcoexist->bt_info.agg_buf_size) {
396 				need_to_act = true;
397 			}
398 			btcoexist->bt_info.pre_agg_buf_size =
399 				btcoexist->bt_info.agg_buf_size;
400 		}
401 
402 		if (need_to_act)
403 			rtl_rx_ampdu_apply(rtlpriv);
404 	}
405 }
406 
407 static u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
408 {
409 	u8 cmd_buffer[4] = {0};
410 
411 	if (btcoexist->bt_info.bt_real_fw_ver)
412 		goto label_done;
413 
414 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
415 	halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_VERSION,
416 				    cmd_buffer, 4, 200);
417 
418 label_done:
419 	return btcoexist->bt_info.bt_real_fw_ver;
420 }
421 
422 static u32 halbtc_get_bt_coex_supported_feature(void *btc_context)
423 {
424 	struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
425 	u8 cmd_buffer[4] = {0};
426 
427 	if (btcoexist->bt_info.bt_supported_feature)
428 		goto label_done;
429 
430 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
431 	halbtc_send_bt_mp_operation(btcoexist,
432 				    BT_OP_GET_BT_COEX_SUPPORTED_FEATURE,
433 				    cmd_buffer, 4, 200);
434 
435 label_done:
436 	return btcoexist->bt_info.bt_supported_feature;
437 }
438 
439 static u32 halbtc_get_bt_coex_supported_version(void *btc_context)
440 {
441 	struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
442 	u8 cmd_buffer[4] = {0};
443 
444 	if (btcoexist->bt_info.bt_supported_version)
445 		goto label_done;
446 
447 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
448 	halbtc_send_bt_mp_operation(btcoexist,
449 				    BT_OP_GET_BT_COEX_SUPPORTED_VERSION,
450 				    cmd_buffer, 4, 200);
451 
452 label_done:
453 	return btcoexist->bt_info.bt_supported_version;
454 }
455 
456 static u32 halbtc_get_bt_device_info(void *btc_context)
457 {
458 	struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
459 	u8 cmd_buffer[4] = {0};
460 
461 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
462 	halbtc_send_bt_mp_operation(btcoexist,
463 				    BT_OP_GET_BT_DEVICE_INFO,
464 				    cmd_buffer, 4, 200);
465 
466 	return btcoexist->bt_info.bt_device_info;
467 }
468 
469 static u32 halbtc_get_bt_forbidden_slot_val(void *btc_context)
470 {
471 	struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
472 	u8 cmd_buffer[4] = {0};
473 
474 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
475 	halbtc_send_bt_mp_operation(btcoexist,
476 				    BT_OP_GET_BT_FORBIDDEN_SLOT_VAL,
477 				    cmd_buffer, 4, 200);
478 
479 	return btcoexist->bt_info.bt_forb_slot_val;
480 }
481 
482 static u32 halbtc_get_wifi_link_status(struct btc_coexist *btcoexist)
483 {
484 	/* return value:
485 	 * [31:16] => connected port number
486 	 * [15:0]  => port connected bit define
487 	 */
488 	struct rtl_priv *rtlpriv = btcoexist->adapter;
489 	struct rtl_mac *mac = rtl_mac(rtlpriv);
490 	u32 ret_val = 0;
491 	u32 port_connected_status = 0, num_of_connected_port = 0;
492 
493 	if (mac->opmode == NL80211_IFTYPE_STATION &&
494 	    mac->link_state >= MAC80211_LINKED) {
495 		port_connected_status |= WIFI_STA_CONNECTED;
496 		num_of_connected_port++;
497 	}
498 	/* AP & ADHOC & MESH */
499 	if (is_any_client_connect_to_ap(btcoexist)) {
500 		port_connected_status |= WIFI_AP_CONNECTED;
501 		num_of_connected_port++;
502 	}
503 	/* TODO: P2P Connected Status */
504 
505 	ret_val = (num_of_connected_port << 16) | port_connected_status;
506 
507 	return ret_val;
508 }
509 
510 static s32 halbtc_get_wifi_rssi(struct rtl_priv *rtlpriv)
511 {
512 	return rtlpriv->dm.undec_sm_pwdb;
513 }
514 
515 static bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
516 {
517 	struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
518 	struct rtl_priv *rtlpriv = btcoexist->adapter;
519 	struct rtl_phy *rtlphy = &(rtlpriv->phy);
520 	struct rtl_mac *mac = rtl_mac(rtlpriv);
521 	struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
522 	bool *bool_tmp = (bool *)out_buf;
523 	int *s32_tmp = (int *)out_buf;
524 	u32 *u32_tmp = (u32 *)out_buf;
525 	u8 *u8_tmp = (u8 *)out_buf;
526 	bool tmp = false;
527 	bool ret = true;
528 
529 	if (!halbtc_is_bt_coexist_available(btcoexist))
530 		return false;
531 
532 	switch (get_type) {
533 	case BTC_GET_BL_HS_OPERATION:
534 		*bool_tmp = false;
535 		ret = false;
536 		break;
537 	case BTC_GET_BL_HS_CONNECTING:
538 		*bool_tmp = false;
539 		ret = false;
540 		break;
541 	case BTC_GET_BL_WIFI_CONNECTED:
542 		if (rtlpriv->mac80211.opmode == NL80211_IFTYPE_STATION &&
543 		    rtlpriv->mac80211.link_state >= MAC80211_LINKED)
544 			tmp = true;
545 		if (is_any_client_connect_to_ap(btcoexist))
546 			tmp = true;
547 		*bool_tmp = tmp;
548 		break;
549 	case BTC_GET_BL_WIFI_DUAL_BAND_CONNECTED:
550 		*u8_tmp = BTC_MULTIPORT_SCC;
551 		break;
552 	case BTC_GET_BL_WIFI_BUSY:
553 		if (halbtc_is_wifi_busy(rtlpriv))
554 			*bool_tmp = true;
555 		else
556 			*bool_tmp = false;
557 		break;
558 	case BTC_GET_BL_WIFI_SCAN:
559 		if (mac->act_scanning)
560 			*bool_tmp = true;
561 		else
562 			*bool_tmp = false;
563 		break;
564 	case BTC_GET_BL_WIFI_LINK:
565 		if (mac->link_state == MAC80211_LINKING)
566 			*bool_tmp = true;
567 		else
568 			*bool_tmp = false;
569 		break;
570 	case BTC_GET_BL_WIFI_ROAM:
571 		if (mac->link_state == MAC80211_LINKING)
572 			*bool_tmp = true;
573 		else
574 			*bool_tmp = false;
575 		break;
576 	case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
577 		*bool_tmp = rtlpriv->btcoexist.btc_info.in_4way;
578 		break;
579 	case BTC_GET_BL_WIFI_UNDER_5G:
580 		if (rtlhal->current_bandtype == BAND_ON_5G)
581 			*bool_tmp = true;
582 		else
583 			*bool_tmp = false;
584 		break;
585 	case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
586 		if (mac->opmode == NL80211_IFTYPE_AP)
587 			*bool_tmp = true;
588 		else
589 			*bool_tmp = false;
590 		break;
591 	case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
592 		if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
593 			*bool_tmp = false;
594 		else
595 			*bool_tmp = true;
596 		break;
597 	case BTC_GET_BL_WIFI_UNDER_B_MODE:
598 		if (rtlpriv->mac80211.mode == WIRELESS_MODE_B)
599 			*bool_tmp = true;
600 		else
601 			*bool_tmp = false;
602 		break;
603 	case BTC_GET_BL_EXT_SWITCH:
604 		*bool_tmp = false;
605 		break;
606 	case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
607 		*bool_tmp = false;
608 		break;
609 	case BTC_GET_BL_IS_ASUS_8723B:
610 		*bool_tmp = false;
611 		break;
612 	case BTC_GET_BL_RF4CE_CONNECTED:
613 		*bool_tmp = false;
614 		break;
615 	case BTC_GET_S4_WIFI_RSSI:
616 		*s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
617 		break;
618 	case BTC_GET_S4_HS_RSSI:
619 		*s32_tmp = 0;
620 		ret = false;
621 		break;
622 	case BTC_GET_U4_WIFI_BW:
623 		*u32_tmp = halbtc_get_wifi_bw(btcoexist);
624 		break;
625 	case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
626 		if (halbtc_is_wifi_uplink(rtlpriv))
627 			*u32_tmp = BTC_WIFI_TRAFFIC_TX;
628 		else
629 			*u32_tmp = BTC_WIFI_TRAFFIC_RX;
630 		break;
631 	case BTC_GET_U4_WIFI_FW_VER:
632 		*u32_tmp = (rtlhal->fw_version << 16) | rtlhal->fw_subversion;
633 		break;
634 	case BTC_GET_U4_WIFI_LINK_STATUS:
635 		*u32_tmp = halbtc_get_wifi_link_status(btcoexist);
636 		break;
637 	case BTC_GET_U4_BT_PATCH_VER:
638 		*u32_tmp = halbtc_get_bt_patch_version(btcoexist);
639 		break;
640 	case BTC_GET_U4_VENDOR:
641 		*u32_tmp = BTC_VENDOR_OTHER;
642 		break;
643 	case BTC_GET_U4_SUPPORTED_VERSION:
644 		*u32_tmp = halbtc_get_bt_coex_supported_version(btcoexist);
645 		break;
646 	case BTC_GET_U4_SUPPORTED_FEATURE:
647 		*u32_tmp = halbtc_get_bt_coex_supported_feature(btcoexist);
648 		break;
649 	case BTC_GET_U4_BT_DEVICE_INFO:
650 		*u32_tmp = halbtc_get_bt_device_info(btcoexist);
651 		break;
652 	case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL:
653 		*u32_tmp = halbtc_get_bt_forbidden_slot_val(btcoexist);
654 		break;
655 	case BTC_GET_U4_WIFI_IQK_TOTAL:
656 		*u32_tmp =
657 			btcoexist->btc_phydm_query_phy_counter(btcoexist,
658 							       DM_INFO_IQK_ALL);
659 		break;
660 	case BTC_GET_U4_WIFI_IQK_OK:
661 		*u32_tmp =
662 			btcoexist->btc_phydm_query_phy_counter(btcoexist,
663 							       DM_INFO_IQK_OK);
664 		break;
665 	case BTC_GET_U4_WIFI_IQK_FAIL:
666 		*u32_tmp =
667 			btcoexist->btc_phydm_query_phy_counter(btcoexist,
668 							       DM_INFO_IQK_NG);
669 		break;
670 	case BTC_GET_U1_WIFI_DOT11_CHNL:
671 		*u8_tmp = rtlphy->current_channel;
672 		break;
673 	case BTC_GET_U1_WIFI_CENTRAL_CHNL:
674 		*u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
675 		break;
676 	case BTC_GET_U1_WIFI_HS_CHNL:
677 		*u8_tmp = 0;
678 		ret = false;
679 		break;
680 	case BTC_GET_U1_AP_NUM:
681 		*u8_tmp = rtlpriv->btcoexist.btc_info.ap_num;
682 		break;
683 	case BTC_GET_U1_ANT_TYPE:
684 		*u8_tmp = (u8)BTC_ANT_TYPE_0;
685 		break;
686 	case BTC_GET_U1_IOT_PEER:
687 		*u8_tmp = 0;
688 		break;
689 
690 		/************* 1Ant **************/
691 	case BTC_GET_U1_LPS_MODE:
692 		*u8_tmp = btcoexist->pwr_mode_val[0];
693 		break;
694 
695 	default:
696 		ret = false;
697 		break;
698 	}
699 
700 	return ret;
701 }
702 
703 static bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
704 {
705 	struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
706 	bool *bool_tmp = (bool *)in_buf;
707 	u8 *u8_tmp = (u8 *)in_buf;
708 	u32 *u32_tmp = (u32 *)in_buf;
709 	bool ret = true;
710 
711 	if (!halbtc_is_bt_coexist_available(btcoexist))
712 		return false;
713 
714 	switch (set_type) {
715 	/* set some bool type variables. */
716 	case BTC_SET_BL_BT_DISABLE:
717 		btcoexist->bt_info.bt_disabled = *bool_tmp;
718 		break;
719 	case BTC_SET_BL_BT_TRAFFIC_BUSY:
720 		btcoexist->bt_info.bt_busy = *bool_tmp;
721 		break;
722 	case BTC_SET_BL_BT_LIMITED_DIG:
723 		btcoexist->bt_info.limited_dig = *bool_tmp;
724 		break;
725 	case BTC_SET_BL_FORCE_TO_ROAM:
726 		btcoexist->bt_info.force_to_roam = *bool_tmp;
727 		break;
728 	case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
729 		btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
730 		break;
731 	case BTC_SET_BL_BT_CTRL_AGG_SIZE:
732 		btcoexist->bt_info.bt_ctrl_agg_buf_size = *bool_tmp;
733 		break;
734 	case BTC_SET_BL_INC_SCAN_DEV_NUM:
735 		btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
736 		break;
737 	case BTC_SET_BL_BT_TX_RX_MASK:
738 		btcoexist->bt_info.bt_tx_rx_mask = *bool_tmp;
739 		break;
740 	case BTC_SET_BL_MIRACAST_PLUS_BT:
741 		btcoexist->bt_info.miracast_plus_bt = *bool_tmp;
742 		break;
743 		/* set some u1Byte type variables. */
744 	case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
745 		btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
746 		break;
747 	case BTC_SET_U1_AGG_BUF_SIZE:
748 		btcoexist->bt_info.agg_buf_size = *u8_tmp;
749 		break;
750 
751 	/* the following are some action which will be triggered */
752 	case BTC_SET_ACT_GET_BT_RSSI:
753 		ret = false;
754 		break;
755 	case BTC_SET_ACT_AGGREGATE_CTRL:
756 		halbtc_aggregation_check(btcoexist);
757 		break;
758 
759 	/* 1Ant */
760 	case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
761 		btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
762 		break;
763 	case BTC_SET_UI_SCAN_SIG_COMPENSATION:
764 		break;
765 	case BTC_SET_U1_LPS_VAL:
766 		btcoexist->bt_info.lps_val = *u8_tmp;
767 		break;
768 	case BTC_SET_U1_RPWM_VAL:
769 		btcoexist->bt_info.rpwm_val = *u8_tmp;
770 		break;
771 	/* the following are some action which will be triggered  */
772 	case BTC_SET_ACT_LEAVE_LPS:
773 		halbtc_leave_lps(btcoexist);
774 		break;
775 	case BTC_SET_ACT_ENTER_LPS:
776 		halbtc_enter_lps(btcoexist);
777 		break;
778 	case BTC_SET_ACT_NORMAL_LPS:
779 		halbtc_normal_lps(btcoexist);
780 		break;
781 	case BTC_SET_ACT_PRE_NORMAL_LPS:
782 		halbtc_pre_normal_lps(btcoexist);
783 		break;
784 	case BTC_SET_ACT_POST_NORMAL_LPS:
785 		halbtc_post_normal_lps(btcoexist);
786 		break;
787 	case BTC_SET_ACT_DISABLE_LOW_POWER:
788 		halbtc_disable_low_power(btcoexist, *bool_tmp);
789 		break;
790 	case BTC_SET_ACT_UPDATE_RAMASK:
791 		btcoexist->bt_info.ra_mask = *u32_tmp;
792 		break;
793 	case BTC_SET_ACT_SEND_MIMO_PS:
794 		break;
795 	case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
796 		break;
797 	case BTC_SET_ACT_CTRL_BT_COEX:
798 		break;
799 	case BTC_SET_ACT_CTRL_8723B_ANT:
800 		break;
801 	default:
802 		break;
803 	}
804 
805 	return ret;
806 }
807 
808 static void halbtc_display_coex_statistics(struct btc_coexist *btcoexist,
809 					   struct seq_file *m)
810 {
811 }
812 
813 static void halbtc_display_bt_link_info(struct btc_coexist *btcoexist,
814 					struct seq_file *m)
815 {
816 }
817 
818 static void halbtc_display_wifi_status(struct btc_coexist *btcoexist,
819 				       struct seq_file *m)
820 {
821 	struct rtl_priv *rtlpriv = btcoexist->adapter;
822 	s32 wifi_rssi = 0, bt_hs_rssi = 0;
823 	bool scan = false, link = false, roam = false, wifi_busy = false;
824 	bool wifi_under_b_mode = false;
825 	bool wifi_under_5g = false;
826 	u32 wifi_bw = BTC_WIFI_BW_HT20;
827 	u32 wifi_traffic_dir = BTC_WIFI_TRAFFIC_TX;
828 	u32 wifi_freq = BTC_FREQ_2_4G;
829 	u32 wifi_link_status = 0x0;
830 	bool bt_hs_on = false, under_ips = false, under_lps = false;
831 	bool low_power = false, dc_mode = false;
832 	u8 wifi_chnl = 0, wifi_hs_chnl = 0;
833 	u8 ap_num = 0;
834 
835 	wifi_link_status = halbtc_get_wifi_link_status(btcoexist);
836 	seq_printf(m, "\n %-35s = %d/ %d/ %d/ %d/ %d",
837 		   "STA/vWifi/HS/p2pGo/p2pGc",
838 		   ((wifi_link_status & WIFI_STA_CONNECTED) ? 1 : 0),
839 		   ((wifi_link_status & WIFI_AP_CONNECTED) ? 1 : 0),
840 		   ((wifi_link_status & WIFI_HS_CONNECTED) ? 1 : 0),
841 		   ((wifi_link_status & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
842 		   ((wifi_link_status & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
843 
844 	btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on);
845 	btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifi_chnl);
846 	btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl);
847 	seq_printf(m, "\n %-35s = %d / %d(%d)",
848 		   "Dot11 channel / HsChnl(High Speed)",
849 		   wifi_chnl, wifi_hs_chnl, bt_hs_on);
850 
851 	btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi);
852 	btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi);
853 	seq_printf(m, "\n %-35s = %d/ %d",
854 		   "Wifi rssi/ HS rssi",
855 		   wifi_rssi - 100, bt_hs_rssi - 100);
856 
857 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan);
858 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link);
859 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam);
860 	seq_printf(m, "\n %-35s = %d/ %d/ %d ",
861 		   "Wifi link/ roam/ scan",
862 		   link, roam, scan);
863 
864 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
865 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw);
866 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy);
867 	btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
868 			   &wifi_traffic_dir);
869 	btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num);
870 	wifi_freq = (wifi_under_5g ? BTC_FREQ_5G : BTC_FREQ_2_4G);
871 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_B_MODE,
872 			   &wifi_under_b_mode);
873 
874 	seq_printf(m, "\n %-35s = %s / %s/ %s/ AP=%d ",
875 		   "Wifi freq/ bw/ traffic",
876 		   gl_btc_wifi_freq_string[wifi_freq],
877 		   ((wifi_under_b_mode) ? "11b" :
878 		    gl_btc_wifi_bw_string[wifi_bw]),
879 		   ((!wifi_busy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX ==
880 					      wifi_traffic_dir) ? "uplink" :
881 					     "downlink")),
882 		   ap_num);
883 
884 	/* power status	 */
885 	dc_mode = true;	/*TODO*/
886 	under_ips = rtlpriv->psc.inactive_pwrstate == ERFOFF ? 1 : 0;
887 	under_lps = rtlpriv->psc.dot11_psmode == EACTIVE ? 0 : 1;
888 	low_power = 0; /*TODO*/
889 	seq_printf(m, "\n %-35s = %s%s%s%s",
890 		   "Power Status",
891 		   (dc_mode ? "DC mode" : "AC mode"),
892 		   (under_ips ? ", IPS ON" : ""),
893 		   (under_lps ? ", LPS ON" : ""),
894 		   (low_power ? ", 32k" : ""));
895 
896 	seq_printf(m,
897 		   "\n %-35s = %6ph (0x%x/0x%x)",
898 		   "Power mode cmd(lps/rpwm)",
899 		   btcoexist->pwr_mode_val,
900 		   btcoexist->bt_info.lps_val,
901 		   btcoexist->bt_info.rpwm_val);
902 }
903 
904 /************************************************************
905  *		IO related function
906  ************************************************************/
907 static u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
908 {
909 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
910 	struct rtl_priv *rtlpriv = btcoexist->adapter;
911 
912 	return	rtl_read_byte(rtlpriv, reg_addr);
913 }
914 
915 static u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
916 {
917 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
918 	struct rtl_priv *rtlpriv = btcoexist->adapter;
919 
920 	return	rtl_read_word(rtlpriv, reg_addr);
921 }
922 
923 static u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
924 {
925 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
926 	struct rtl_priv *rtlpriv = btcoexist->adapter;
927 
928 	return	rtl_read_dword(rtlpriv, reg_addr);
929 }
930 
931 static void halbtc_write_1byte(void *bt_context, u32 reg_addr, u32 data)
932 {
933 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
934 	struct rtl_priv *rtlpriv = btcoexist->adapter;
935 
936 	rtl_write_byte(rtlpriv, reg_addr, data);
937 }
938 
939 static void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr,
940 				       u32 bit_mask, u8 data)
941 {
942 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
943 	struct rtl_priv *rtlpriv = btcoexist->adapter;
944 	u8 original_value, bit_shift = 0;
945 	u8 i;
946 
947 	if (bit_mask != MASKDWORD) {/*if not "double word" write*/
948 		original_value = rtl_read_byte(rtlpriv, reg_addr);
949 		for (i = 0; i <= 7; i++) {
950 			if ((bit_mask>>i) & 0x1)
951 				break;
952 		}
953 		bit_shift = i;
954 		data = (original_value & (~bit_mask)) |
955 			((data << bit_shift) & bit_mask);
956 	}
957 	rtl_write_byte(rtlpriv, reg_addr, data);
958 }
959 
960 static void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
961 {
962 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
963 	struct rtl_priv *rtlpriv = btcoexist->adapter;
964 
965 	rtl_write_word(rtlpriv, reg_addr, data);
966 }
967 
968 static void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
969 {
970 	struct btc_coexist *btcoexist =
971 		(struct btc_coexist *)bt_context;
972 	struct rtl_priv *rtlpriv = btcoexist->adapter;
973 
974 	rtl_write_dword(rtlpriv, reg_addr, data);
975 }
976 
977 static void halbtc_write_local_reg_1byte(void *btc_context, u32 reg_addr,
978 					 u8 data)
979 {
980 	struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
981 	struct rtl_priv *rtlpriv = btcoexist->adapter;
982 
983 	if (btcoexist->chip_interface == BTC_INTF_SDIO)
984 		;
985 	else if (btcoexist->chip_interface == BTC_INTF_PCI)
986 		rtl_write_byte(rtlpriv, reg_addr, data);
987 	else if (btcoexist->chip_interface == BTC_INTF_USB)
988 		rtl_write_byte(rtlpriv, reg_addr, data);
989 }
990 
991 static void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask,
992 			     u32 data)
993 {
994 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
995 	struct rtl_priv *rtlpriv = btcoexist->adapter;
996 
997 	rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
998 }
999 
1000 static u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
1001 {
1002 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1003 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1004 
1005 	return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
1006 }
1007 
1008 static void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
1009 			     u32 bit_mask, u32 data)
1010 {
1011 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1012 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1013 
1014 	rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
1015 }
1016 
1017 static u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr,
1018 			    u32 bit_mask)
1019 {
1020 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1021 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1022 
1023 	return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
1024 }
1025 
1026 static void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id,
1027 				u32 cmd_len, u8 *cmd_buf)
1028 {
1029 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1030 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1031 
1032 	rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id,
1033 					cmd_len, cmd_buf);
1034 }
1035 
1036 void halbtc_send_wifi_port_id_cmd(void *bt_context)
1037 {
1038 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1039 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1040 	u8 cmd_buf[1] = {0};	/* port id [2:0] = 0 */
1041 
1042 	rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, H2C_BT_PORT_ID,
1043 					1, cmd_buf);
1044 }
1045 
1046 void halbtc_set_default_port_id_cmd(void *bt_context)
1047 {
1048 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1049 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1050 	struct ieee80211_hw *hw = rtlpriv->mac80211.hw;
1051 
1052 	if (!rtlpriv->cfg->ops->set_default_port_id_cmd)
1053 		return;
1054 
1055 	rtlpriv->cfg->ops->set_default_port_id_cmd(hw);
1056 }
1057 
1058 static
1059 void halbtc_set_bt_reg(void *btc_context, u8 reg_type, u32 offset, u32 set_val)
1060 {
1061 	struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1062 	u8 cmd_buffer1[4] = {0};
1063 	u8 cmd_buffer2[4] = {0};
1064 
1065 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1066 	*((__le16 *)&cmd_buffer1[2]) = cpu_to_le16((u16)set_val);
1067 	if (!halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_VALUE,
1068 					 cmd_buffer1, 4, 200))
1069 		return;
1070 
1071 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1072 	cmd_buffer2[2] = reg_type;
1073 	*((u8 *)&cmd_buffer2[3]) = (u8)offset;
1074 	halbtc_send_bt_mp_operation(btcoexist, BT_OP_WRITE_REG_ADDR,
1075 				    cmd_buffer2, 4, 200);
1076 }
1077 
1078 static void halbtc_display_dbg_msg(void *bt_context, u8 disp_type,
1079 				   struct seq_file *m)
1080 {
1081 	struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
1082 
1083 	switch (disp_type) {
1084 	case BTC_DBG_DISP_COEX_STATISTICS:
1085 		halbtc_display_coex_statistics(btcoexist, m);
1086 		break;
1087 	case BTC_DBG_DISP_BT_LINK_INFO:
1088 		halbtc_display_bt_link_info(btcoexist, m);
1089 		break;
1090 	case BTC_DBG_DISP_WIFI_STATUS:
1091 		halbtc_display_wifi_status(btcoexist, m);
1092 		break;
1093 	default:
1094 		break;
1095 	}
1096 }
1097 
1098 static u32 halbtc_get_bt_reg(void *btc_context, u8 reg_type, u32 offset)
1099 {
1100 	return 0;
1101 }
1102 
1103 static bool halbtc_under_ips(struct btc_coexist *btcoexist)
1104 {
1105 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1106 	struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
1107 	enum rf_pwrstate rtstate;
1108 
1109 	if (ppsc->inactiveps) {
1110 		rtstate = ppsc->rfpwr_state;
1111 
1112 		if (rtstate != ERFON &&
1113 		    ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
1114 			return true;
1115 		}
1116 	}
1117 
1118 	return false;
1119 }
1120 
1121 static
1122 u32 halbtc_get_phydm_version(void *btc_context)
1123 {
1124 	return 0;
1125 }
1126 
1127 static
1128 void halbtc_phydm_modify_ra_pcr_threshold(void *btc_context,
1129 					  u8 ra_offset_direction,
1130 					  u8 ra_threshold_offset)
1131 {
1132 }
1133 
1134 static
1135 u32 halbtc_phydm_query_phy_counter(void *btc_context, enum dm_info_query dm_id)
1136 {
1137 	return 0;
1138 }
1139 
1140 static u8 halbtc_get_ant_det_val_from_bt(void *btc_context)
1141 {
1142 	struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1143 	u8 cmd_buffer[4] = {0};
1144 
1145 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1146 	halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_ANT_DET_VAL,
1147 				    cmd_buffer, 4, 200);
1148 
1149 	/* need wait completion to return correct value */
1150 
1151 	return btcoexist->bt_info.bt_ant_det_val;
1152 }
1153 
1154 static u8 halbtc_get_ble_scan_type_from_bt(void *btc_context)
1155 {
1156 	struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1157 	u8 cmd_buffer[4] = {0};
1158 
1159 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1160 	halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_TYPE,
1161 				    cmd_buffer, 4, 200);
1162 
1163 	/* need wait completion to return correct value */
1164 
1165 	return btcoexist->bt_info.bt_ble_scan_type;
1166 }
1167 
1168 static u32 halbtc_get_ble_scan_para_from_bt(void *btc_context, u8 scan_type)
1169 {
1170 	struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1171 	u8 cmd_buffer[4] = {0};
1172 
1173 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1174 	halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_BT_BLE_SCAN_PARA,
1175 				    cmd_buffer, 4, 200);
1176 
1177 	/* need wait completion to return correct value */
1178 
1179 	return btcoexist->bt_info.bt_ble_scan_para;
1180 }
1181 
1182 static bool halbtc_get_bt_afh_map_from_bt(void *btc_context, u8 map_type,
1183 					  u8 *afh_map)
1184 {
1185 	struct btc_coexist *btcoexist = (struct btc_coexist *)btc_context;
1186 	u8 cmd_buffer[2] = {0};
1187 	bool ret;
1188 	u32 *afh_map_l = (u32 *)afh_map;
1189 	u32 *afh_map_m = (u32 *)(afh_map + 4);
1190 	u16 *afh_map_h = (u16 *)(afh_map + 8);
1191 
1192 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1193 	ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_L,
1194 					  cmd_buffer, 2, 200);
1195 	if (!ret)
1196 		goto exit;
1197 
1198 	*afh_map_l = btcoexist->bt_info.afh_map_l;
1199 
1200 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1201 	ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_M,
1202 					  cmd_buffer, 2, 200);
1203 	if (!ret)
1204 		goto exit;
1205 
1206 	*afh_map_m = btcoexist->bt_info.afh_map_m;
1207 
1208 	/* cmd_buffer[0] and [1] is filled by halbtc_send_bt_mp_operation() */
1209 	ret = halbtc_send_bt_mp_operation(btcoexist, BT_OP_GET_AFH_MAP_H,
1210 					  cmd_buffer, 2, 200);
1211 	if (!ret)
1212 		goto exit;
1213 
1214 	*afh_map_h = btcoexist->bt_info.afh_map_h;
1215 
1216 exit:
1217 	return ret;
1218 }
1219 
1220 /*****************************************************************
1221  *         Extern functions called by other module
1222  *****************************************************************/
1223 bool exhalbtc_initlize_variables(struct rtl_priv *rtlpriv)
1224 {
1225 	struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1226 
1227 	if (!btcoexist)
1228 		return false;
1229 
1230 	halbtc_dbg_init();
1231 
1232 	btcoexist->btc_read_1byte = halbtc_read_1byte;
1233 	btcoexist->btc_write_1byte = halbtc_write_1byte;
1234 	btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
1235 	btcoexist->btc_read_2byte = halbtc_read_2byte;
1236 	btcoexist->btc_write_2byte = halbtc_write_2byte;
1237 	btcoexist->btc_read_4byte = halbtc_read_4byte;
1238 	btcoexist->btc_write_4byte = halbtc_write_4byte;
1239 	btcoexist->btc_write_local_reg_1byte = halbtc_write_local_reg_1byte;
1240 
1241 	btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
1242 	btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
1243 
1244 	btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
1245 	btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
1246 
1247 	btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
1248 	btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
1249 
1250 	btcoexist->btc_get = halbtc_get;
1251 	btcoexist->btc_set = halbtc_set;
1252 	btcoexist->btc_set_bt_reg = halbtc_set_bt_reg;
1253 	btcoexist->btc_get_bt_reg = halbtc_get_bt_reg;
1254 
1255 	btcoexist->bt_info.bt_ctrl_buf_size = false;
1256 	btcoexist->bt_info.agg_buf_size = 5;
1257 
1258 	btcoexist->bt_info.increase_scan_dev_num = false;
1259 
1260 	btcoexist->btc_get_bt_coex_supported_feature =
1261 					halbtc_get_bt_coex_supported_feature;
1262 	btcoexist->btc_get_bt_coex_supported_version =
1263 					halbtc_get_bt_coex_supported_version;
1264 	btcoexist->btc_get_bt_phydm_version = halbtc_get_phydm_version;
1265 	btcoexist->btc_phydm_modify_ra_pcr_threshold =
1266 					halbtc_phydm_modify_ra_pcr_threshold;
1267 	btcoexist->btc_phydm_query_phy_counter = halbtc_phydm_query_phy_counter;
1268 	btcoexist->btc_get_ant_det_val_from_bt = halbtc_get_ant_det_val_from_bt;
1269 	btcoexist->btc_get_ble_scan_type_from_bt =
1270 					halbtc_get_ble_scan_type_from_bt;
1271 	btcoexist->btc_get_ble_scan_para_from_bt =
1272 					halbtc_get_ble_scan_para_from_bt;
1273 	btcoexist->btc_get_bt_afh_map_from_bt =
1274 					halbtc_get_bt_afh_map_from_bt;
1275 
1276 	init_completion(&btcoexist->bt_mp_comp);
1277 
1278 	return true;
1279 }
1280 
1281 bool exhalbtc_initlize_variables_wifi_only(struct rtl_priv *rtlpriv)
1282 {
1283 	struct wifi_only_cfg *wifionly_cfg = rtl_btc_wifi_only(rtlpriv);
1284 	struct wifi_only_haldata *wifionly_haldata;
1285 
1286 	if (!wifionly_cfg)
1287 		return false;
1288 
1289 	wifionly_cfg->adapter = rtlpriv;
1290 
1291 	switch (rtlpriv->rtlhal.interface) {
1292 	case INTF_PCI:
1293 		wifionly_cfg->chip_interface = WIFIONLY_INTF_PCI;
1294 		break;
1295 	case INTF_USB:
1296 		wifionly_cfg->chip_interface = WIFIONLY_INTF_USB;
1297 		break;
1298 	default:
1299 		wifionly_cfg->chip_interface = WIFIONLY_INTF_UNKNOWN;
1300 		break;
1301 	}
1302 
1303 	wifionly_haldata = &wifionly_cfg->haldata_info;
1304 
1305 	wifionly_haldata->customer_id = CUSTOMER_NORMAL;
1306 	wifionly_haldata->efuse_pg_antnum = rtl_get_hwpg_ant_num(rtlpriv);
1307 	wifionly_haldata->efuse_pg_antpath =
1308 					rtl_get_hwpg_single_ant_path(rtlpriv);
1309 	wifionly_haldata->rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1310 	wifionly_haldata->ant_div_cfg = 0;
1311 
1312 	return true;
1313 }
1314 
1315 bool exhalbtc_bind_bt_coex_withadapter(void *adapter)
1316 {
1317 	struct rtl_priv *rtlpriv = adapter;
1318 	struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1319 	u8 ant_num, chip_type, single_ant_path;
1320 
1321 	if (!btcoexist)
1322 		return false;
1323 
1324 	if (btcoexist->binded)
1325 		return false;
1326 
1327 	switch (rtlpriv->rtlhal.interface) {
1328 	case INTF_PCI:
1329 		btcoexist->chip_interface = BTC_INTF_PCI;
1330 		break;
1331 	case INTF_USB:
1332 		btcoexist->chip_interface = BTC_INTF_USB;
1333 		break;
1334 	default:
1335 		btcoexist->chip_interface = BTC_INTF_UNKNOWN;
1336 		break;
1337 	}
1338 
1339 	btcoexist->binded = true;
1340 	btcoexist->statistics.cnt_bind++;
1341 
1342 	btcoexist->adapter = adapter;
1343 
1344 	btcoexist->stack_info.profile_notified = false;
1345 
1346 	btcoexist->bt_info.bt_ctrl_agg_buf_size = false;
1347 	btcoexist->bt_info.agg_buf_size = 5;
1348 
1349 	btcoexist->bt_info.increase_scan_dev_num = false;
1350 	btcoexist->bt_info.miracast_plus_bt = false;
1351 
1352 	chip_type = rtl_get_hwpg_bt_type(rtlpriv);
1353 	exhalbtc_set_chip_type(btcoexist, chip_type);
1354 	ant_num = rtl_get_hwpg_ant_num(rtlpriv);
1355 	exhalbtc_set_ant_num(rtlpriv, BT_COEX_ANT_TYPE_PG, ant_num);
1356 
1357 	/* set default antenna position to main  port */
1358 	btcoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
1359 
1360 	single_ant_path = rtl_get_hwpg_single_ant_path(rtlpriv);
1361 	exhalbtc_set_single_ant_path(btcoexist, single_ant_path);
1362 
1363 	if (rtl_get_hwpg_package_type(rtlpriv) == 0)
1364 		btcoexist->board_info.tfbga_package = false;
1365 	else if (rtl_get_hwpg_package_type(rtlpriv) == 1)
1366 		btcoexist->board_info.tfbga_package = false;
1367 	else
1368 		btcoexist->board_info.tfbga_package = true;
1369 
1370 	if (btcoexist->board_info.tfbga_package)
1371 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1372 			 "[BTCoex], Package Type = TFBGA\n");
1373 	else
1374 		RT_TRACE(rtlpriv, COMP_BT_COEXIST, DBG_LOUD,
1375 			 "[BTCoex], Package Type = Non-TFBGA\n");
1376 
1377 	btcoexist->board_info.rfe_type = rtl_get_hwpg_rfe_type(rtlpriv);
1378 	btcoexist->board_info.ant_div_cfg = 0;
1379 
1380 	return true;
1381 }
1382 
1383 void exhalbtc_power_on_setting(struct btc_coexist *btcoexist)
1384 {
1385 	if (!halbtc_is_bt_coexist_available(btcoexist))
1386 		return;
1387 
1388 	btcoexist->statistics.cnt_power_on++;
1389 
1390 	if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1391 		if (btcoexist->board_info.btdm_ant_num == 2)
1392 			ex_btc8723b2ant_power_on_setting(btcoexist);
1393 		else if (btcoexist->board_info.btdm_ant_num == 1)
1394 			ex_btc8723b1ant_power_on_setting(btcoexist);
1395 	}
1396 }
1397 
1398 void exhalbtc_pre_load_firmware(struct btc_coexist *btcoexist)
1399 {
1400 	if (!halbtc_is_bt_coexist_available(btcoexist))
1401 		return;
1402 
1403 	btcoexist->statistics.cnt_pre_load_firmware++;
1404 
1405 	if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1406 		if (btcoexist->board_info.btdm_ant_num == 2)
1407 			ex_btc8723b2ant_pre_load_firmware(btcoexist);
1408 	}
1409 }
1410 
1411 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist, bool wifi_only)
1412 {
1413 	if (!halbtc_is_bt_coexist_available(btcoexist))
1414 		return;
1415 
1416 	btcoexist->statistics.cnt_init_hw_config++;
1417 
1418 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1419 		if (btcoexist->board_info.btdm_ant_num == 2)
1420 			ex_btc8821a2ant_init_hwconfig(btcoexist);
1421 		else if (btcoexist->board_info.btdm_ant_num == 1)
1422 			ex_btc8821a1ant_init_hwconfig(btcoexist, wifi_only);
1423 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1424 		if (btcoexist->board_info.btdm_ant_num == 2)
1425 			ex_btc8723b2ant_init_hwconfig(btcoexist);
1426 		else if (btcoexist->board_info.btdm_ant_num == 1)
1427 			ex_btc8723b1ant_init_hwconfig(btcoexist, wifi_only);
1428 	} else if (IS_HARDWARE_TYPE_8723A(btcoexist->adapter)) {
1429 		/* 8723A has no this function */
1430 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1431 		if (btcoexist->board_info.btdm_ant_num == 2)
1432 			ex_btc8192e2ant_init_hwconfig(btcoexist);
1433 	}
1434 }
1435 
1436 void exhalbtc_init_hw_config_wifi_only(struct wifi_only_cfg *wifionly_cfg)
1437 {
1438 }
1439 
1440 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
1441 {
1442 	if (!halbtc_is_bt_coexist_available(btcoexist))
1443 		return;
1444 
1445 	btcoexist->statistics.cnt_init_coex_dm++;
1446 
1447 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1448 		if (btcoexist->board_info.btdm_ant_num == 2)
1449 			ex_btc8821a2ant_init_coex_dm(btcoexist);
1450 		else if (btcoexist->board_info.btdm_ant_num == 1)
1451 			ex_btc8821a1ant_init_coex_dm(btcoexist);
1452 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1453 		if (btcoexist->board_info.btdm_ant_num == 2)
1454 			ex_btc8723b2ant_init_coex_dm(btcoexist);
1455 		else if (btcoexist->board_info.btdm_ant_num == 1)
1456 			ex_btc8723b1ant_init_coex_dm(btcoexist);
1457 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1458 		if (btcoexist->board_info.btdm_ant_num == 2)
1459 			ex_btc8192e2ant_init_coex_dm(btcoexist);
1460 	}
1461 
1462 	btcoexist->initialized = true;
1463 }
1464 
1465 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
1466 {
1467 	u8 ips_type;
1468 
1469 	if (!halbtc_is_bt_coexist_available(btcoexist))
1470 		return;
1471 	btcoexist->statistics.cnt_ips_notify++;
1472 	if (btcoexist->manual_control)
1473 		return;
1474 
1475 	if (ERFOFF == type)
1476 		ips_type = BTC_IPS_ENTER;
1477 	else
1478 		ips_type = BTC_IPS_LEAVE;
1479 
1480 	halbtc_leave_low_power(btcoexist);
1481 
1482 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1483 		if (btcoexist->board_info.btdm_ant_num == 2)
1484 			ex_btc8821a2ant_ips_notify(btcoexist, ips_type);
1485 		else if (btcoexist->board_info.btdm_ant_num == 1)
1486 			ex_btc8821a1ant_ips_notify(btcoexist, ips_type);
1487 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1488 		if (btcoexist->board_info.btdm_ant_num == 2)
1489 			ex_btc8723b2ant_ips_notify(btcoexist, ips_type);
1490 		else if (btcoexist->board_info.btdm_ant_num == 1)
1491 			ex_btc8723b1ant_ips_notify(btcoexist, ips_type);
1492 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1493 		if (btcoexist->board_info.btdm_ant_num == 2)
1494 			ex_btc8192e2ant_ips_notify(btcoexist, ips_type);
1495 	}
1496 
1497 	halbtc_normal_low_power(btcoexist);
1498 }
1499 
1500 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
1501 {
1502 	u8 lps_type;
1503 
1504 	if (!halbtc_is_bt_coexist_available(btcoexist))
1505 		return;
1506 	btcoexist->statistics.cnt_lps_notify++;
1507 	if (btcoexist->manual_control)
1508 		return;
1509 
1510 	if (EACTIVE == type)
1511 		lps_type = BTC_LPS_DISABLE;
1512 	else
1513 		lps_type = BTC_LPS_ENABLE;
1514 
1515 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1516 		if (btcoexist->board_info.btdm_ant_num == 2)
1517 			ex_btc8821a2ant_lps_notify(btcoexist, lps_type);
1518 		else if (btcoexist->board_info.btdm_ant_num == 1)
1519 			ex_btc8821a1ant_lps_notify(btcoexist, lps_type);
1520 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1521 		if (btcoexist->board_info.btdm_ant_num == 2)
1522 			ex_btc8723b2ant_lps_notify(btcoexist, lps_type);
1523 		else if (btcoexist->board_info.btdm_ant_num == 1)
1524 			ex_btc8723b1ant_lps_notify(btcoexist, lps_type);
1525 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1526 		if (btcoexist->board_info.btdm_ant_num == 2)
1527 			ex_btc8192e2ant_lps_notify(btcoexist, lps_type);
1528 	}
1529 }
1530 
1531 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
1532 {
1533 	u8 scan_type;
1534 
1535 	if (!halbtc_is_bt_coexist_available(btcoexist))
1536 		return;
1537 	btcoexist->statistics.cnt_scan_notify++;
1538 	if (btcoexist->manual_control)
1539 		return;
1540 
1541 	if (type)
1542 		scan_type = BTC_SCAN_START;
1543 	else
1544 		scan_type = BTC_SCAN_FINISH;
1545 
1546 	halbtc_leave_low_power(btcoexist);
1547 
1548 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1549 		if (btcoexist->board_info.btdm_ant_num == 2)
1550 			ex_btc8821a2ant_scan_notify(btcoexist, scan_type);
1551 		else if (btcoexist->board_info.btdm_ant_num == 1)
1552 			ex_btc8821a1ant_scan_notify(btcoexist, scan_type);
1553 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1554 		if (btcoexist->board_info.btdm_ant_num == 2)
1555 			ex_btc8723b2ant_scan_notify(btcoexist, scan_type);
1556 		else if (btcoexist->board_info.btdm_ant_num == 1)
1557 			ex_btc8723b1ant_scan_notify(btcoexist, scan_type);
1558 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1559 		if (btcoexist->board_info.btdm_ant_num == 2)
1560 			ex_btc8192e2ant_scan_notify(btcoexist, scan_type);
1561 	}
1562 
1563 	halbtc_normal_low_power(btcoexist);
1564 }
1565 
1566 void exhalbtc_scan_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1567 				    u8 is_5g)
1568 {
1569 }
1570 
1571 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
1572 {
1573 	u8 asso_type;
1574 	bool wifi_under_5g;
1575 
1576 	if (!halbtc_is_bt_coexist_available(btcoexist))
1577 		return;
1578 	btcoexist->statistics.cnt_connect_notify++;
1579 	if (btcoexist->manual_control)
1580 		return;
1581 
1582 	btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g);
1583 
1584 	if (action)
1585 		asso_type = BTC_ASSOCIATE_START;
1586 	else
1587 		asso_type = BTC_ASSOCIATE_FINISH;
1588 
1589 	halbtc_leave_low_power(btcoexist);
1590 
1591 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1592 		if (btcoexist->board_info.btdm_ant_num == 2)
1593 			ex_btc8821a2ant_connect_notify(btcoexist, asso_type);
1594 		else if (btcoexist->board_info.btdm_ant_num == 1)
1595 			ex_btc8821a1ant_connect_notify(btcoexist, asso_type);
1596 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1597 		if (btcoexist->board_info.btdm_ant_num == 2)
1598 			ex_btc8723b2ant_connect_notify(btcoexist, asso_type);
1599 		else if (btcoexist->board_info.btdm_ant_num == 1)
1600 			ex_btc8723b1ant_connect_notify(btcoexist, asso_type);
1601 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1602 		if (btcoexist->board_info.btdm_ant_num == 2)
1603 			ex_btc8192e2ant_connect_notify(btcoexist, asso_type);
1604 	}
1605 
1606 	halbtc_normal_low_power(btcoexist);
1607 }
1608 
1609 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist,
1610 				 enum rt_media_status media_status)
1611 {
1612 	u8 status;
1613 
1614 	if (!halbtc_is_bt_coexist_available(btcoexist))
1615 		return;
1616 	btcoexist->statistics.cnt_media_status_notify++;
1617 	if (btcoexist->manual_control)
1618 		return;
1619 
1620 	if (RT_MEDIA_CONNECT == media_status)
1621 		status = BTC_MEDIA_CONNECT;
1622 	else
1623 		status = BTC_MEDIA_DISCONNECT;
1624 
1625 	halbtc_leave_low_power(btcoexist);
1626 
1627 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1628 		if (btcoexist->board_info.btdm_ant_num == 2)
1629 			ex_btc8821a2ant_media_status_notify(btcoexist, status);
1630 		else if (btcoexist->board_info.btdm_ant_num == 1)
1631 			ex_btc8821a1ant_media_status_notify(btcoexist, status);
1632 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1633 		if (btcoexist->board_info.btdm_ant_num == 2)
1634 			ex_btc8723b2ant_media_status_notify(btcoexist, status);
1635 		else if (btcoexist->board_info.btdm_ant_num == 1)
1636 			ex_btc8723b1ant_media_status_notify(btcoexist, status);
1637 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1638 		if (btcoexist->board_info.btdm_ant_num == 2)
1639 			ex_btc8192e2ant_media_status_notify(btcoexist, status);
1640 	}
1641 
1642 	halbtc_normal_low_power(btcoexist);
1643 }
1644 
1645 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
1646 {
1647 	u8 packet_type;
1648 
1649 	if (!halbtc_is_bt_coexist_available(btcoexist))
1650 		return;
1651 	btcoexist->statistics.cnt_special_packet_notify++;
1652 	if (btcoexist->manual_control)
1653 		return;
1654 
1655 	if (pkt_type == PACKET_DHCP) {
1656 		packet_type = BTC_PACKET_DHCP;
1657 	} else if (pkt_type == PACKET_EAPOL) {
1658 		packet_type = BTC_PACKET_EAPOL;
1659 	} else if (pkt_type == PACKET_ARP) {
1660 		packet_type = BTC_PACKET_ARP;
1661 	} else {
1662 		packet_type = BTC_PACKET_UNKNOWN;
1663 		return;
1664 	}
1665 
1666 	halbtc_leave_low_power(btcoexist);
1667 
1668 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1669 		if (btcoexist->board_info.btdm_ant_num == 2)
1670 			ex_btc8821a2ant_special_packet_notify(btcoexist,
1671 							      packet_type);
1672 		else if (btcoexist->board_info.btdm_ant_num == 1)
1673 			ex_btc8821a1ant_special_packet_notify(btcoexist,
1674 							      packet_type);
1675 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1676 		if (btcoexist->board_info.btdm_ant_num == 2)
1677 			ex_btc8723b2ant_special_packet_notify(btcoexist,
1678 							      packet_type);
1679 		else if (btcoexist->board_info.btdm_ant_num == 1)
1680 			ex_btc8723b1ant_special_packet_notify(btcoexist,
1681 							      packet_type);
1682 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1683 		if (btcoexist->board_info.btdm_ant_num == 2)
1684 			ex_btc8192e2ant_special_packet_notify(btcoexist,
1685 							      packet_type);
1686 	}
1687 
1688 	halbtc_normal_low_power(btcoexist);
1689 }
1690 
1691 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist,
1692 			     u8 *tmp_buf, u8 length)
1693 {
1694 	if (!halbtc_is_bt_coexist_available(btcoexist))
1695 		return;
1696 	btcoexist->statistics.cnt_bt_info_notify++;
1697 
1698 	halbtc_leave_low_power(btcoexist);
1699 
1700 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1701 		if (btcoexist->board_info.btdm_ant_num == 2)
1702 			ex_btc8821a2ant_bt_info_notify(btcoexist, tmp_buf,
1703 						       length);
1704 		else if (btcoexist->board_info.btdm_ant_num == 1)
1705 			ex_btc8821a1ant_bt_info_notify(btcoexist, tmp_buf,
1706 						       length);
1707 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1708 		if (btcoexist->board_info.btdm_ant_num == 2)
1709 			ex_btc8723b2ant_bt_info_notify(btcoexist, tmp_buf,
1710 						       length);
1711 		else if (btcoexist->board_info.btdm_ant_num == 1)
1712 			ex_btc8723b1ant_bt_info_notify(btcoexist, tmp_buf,
1713 						       length);
1714 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1715 		if (btcoexist->board_info.btdm_ant_num == 2)
1716 			ex_btc8192e2ant_bt_info_notify(btcoexist, tmp_buf,
1717 						       length);
1718 	}
1719 
1720 	halbtc_normal_low_power(btcoexist);
1721 }
1722 
1723 void exhalbtc_rf_status_notify(struct btc_coexist *btcoexist, u8 type)
1724 {
1725 	if (!halbtc_is_bt_coexist_available(btcoexist))
1726 		return;
1727 
1728 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1729 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1730 		if (btcoexist->board_info.btdm_ant_num == 1)
1731 			ex_btc8723b1ant_rf_status_notify(btcoexist, type);
1732 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1733 	}
1734 }
1735 
1736 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1737 {
1738 	if (!halbtc_is_bt_coexist_available(btcoexist))
1739 		return;
1740 
1741 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1742 		if (btcoexist->board_info.btdm_ant_num == 2)
1743 			ex_btc8821a2ant_halt_notify(btcoexist);
1744 		else if (btcoexist->board_info.btdm_ant_num == 1)
1745 			ex_btc8821a1ant_halt_notify(btcoexist);
1746 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1747 		if (btcoexist->board_info.btdm_ant_num == 2)
1748 			ex_btc8723b2ant_halt_notify(btcoexist);
1749 		else if (btcoexist->board_info.btdm_ant_num == 1)
1750 			ex_btc8723b1ant_halt_notify(btcoexist);
1751 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1752 		if (btcoexist->board_info.btdm_ant_num == 2)
1753 			ex_btc8192e2ant_halt_notify(btcoexist);
1754 	}
1755 
1756 	btcoexist->binded = false;
1757 }
1758 
1759 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1760 {
1761 	if (!halbtc_is_bt_coexist_available(btcoexist))
1762 		return;
1763 
1764 	/* currently only 1ant we have to do the notification,
1765 	 * once pnp is notified to sleep state, we have to leave LPS that
1766 	 * we can sleep normally.
1767 	 */
1768 
1769 	if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1770 		if (btcoexist->board_info.btdm_ant_num == 1)
1771 			ex_btc8723b1ant_pnp_notify(btcoexist, pnp_state);
1772 		else if (btcoexist->board_info.btdm_ant_num == 2)
1773 			ex_btc8723b2ant_pnp_notify(btcoexist, pnp_state);
1774 	} else if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1775 		if (btcoexist->board_info.btdm_ant_num == 1)
1776 			ex_btc8821a1ant_pnp_notify(btcoexist, pnp_state);
1777 		else if (btcoexist->board_info.btdm_ant_num == 2)
1778 			ex_btc8821a2ant_pnp_notify(btcoexist, pnp_state);
1779 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1780 	}
1781 }
1782 
1783 void exhalbtc_coex_dm_switch(struct btc_coexist *btcoexist)
1784 {
1785 	struct rtl_priv *rtlpriv = btcoexist->adapter;
1786 
1787 	if (!halbtc_is_bt_coexist_available(btcoexist))
1788 		return;
1789 	btcoexist->statistics.cnt_coex_dm_switch++;
1790 
1791 	halbtc_leave_low_power(btcoexist);
1792 
1793 	if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1794 		if (btcoexist->board_info.btdm_ant_num == 1) {
1795 			btcoexist->stop_coex_dm = true;
1796 			ex_btc8723b1ant_coex_dm_reset(btcoexist);
1797 			exhalbtc_set_ant_num(rtlpriv,
1798 					     BT_COEX_ANT_TYPE_DETECTED, 2);
1799 			ex_btc8723b2ant_init_hwconfig(btcoexist);
1800 			ex_btc8723b2ant_init_coex_dm(btcoexist);
1801 			btcoexist->stop_coex_dm = false;
1802 		}
1803 	}
1804 
1805 	halbtc_normal_low_power(btcoexist);
1806 }
1807 
1808 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1809 {
1810 	if (!halbtc_is_bt_coexist_available(btcoexist))
1811 		return;
1812 	btcoexist->statistics.cnt_periodical++;
1813 
1814 	halbtc_leave_low_power(btcoexist);
1815 
1816 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1817 		if (btcoexist->board_info.btdm_ant_num == 2)
1818 			ex_btc8821a2ant_periodical(btcoexist);
1819 		else if (btcoexist->board_info.btdm_ant_num == 1)
1820 			if (!halbtc_under_ips(btcoexist))
1821 				ex_btc8821a1ant_periodical(btcoexist);
1822 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1823 		if (btcoexist->board_info.btdm_ant_num == 2)
1824 			ex_btc8723b2ant_periodical(btcoexist);
1825 		else if (btcoexist->board_info.btdm_ant_num == 1)
1826 			ex_btc8723b1ant_periodical(btcoexist);
1827 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1828 		if (btcoexist->board_info.btdm_ant_num == 2)
1829 			ex_btc8192e2ant_periodical(btcoexist);
1830 	}
1831 
1832 	halbtc_normal_low_power(btcoexist);
1833 }
1834 
1835 void exhalbtc_dbg_control(struct btc_coexist *btcoexist,
1836 			  u8 code, u8 len, u8 *data)
1837 {
1838 	if (!halbtc_is_bt_coexist_available(btcoexist))
1839 		return;
1840 	btcoexist->statistics.cnt_dbg_ctrl++;
1841 
1842 	halbtc_leave_low_power(btcoexist);
1843 
1844 	halbtc_normal_low_power(btcoexist);
1845 }
1846 
1847 void exhalbtc_antenna_detection(struct btc_coexist *btcoexist, u32 cent_freq,
1848 				u32 offset, u32 span, u32 seconds)
1849 {
1850 	if (!halbtc_is_bt_coexist_available(btcoexist))
1851 		return;
1852 }
1853 
1854 void exhalbtc_stack_update_profile_info(void)
1855 {
1856 }
1857 
1858 void exhalbtc_update_min_bt_rssi(struct btc_coexist *btcoexist, s8 bt_rssi)
1859 {
1860 	if (!halbtc_is_bt_coexist_available(btcoexist))
1861 		return;
1862 
1863 	btcoexist->stack_info.min_bt_rssi = bt_rssi;
1864 }
1865 
1866 void exhalbtc_set_hci_version(struct btc_coexist *btcoexist, u16 hci_version)
1867 {
1868 	if (!halbtc_is_bt_coexist_available(btcoexist))
1869 		return;
1870 
1871 	btcoexist->stack_info.hci_version = hci_version;
1872 }
1873 
1874 void exhalbtc_set_bt_patch_version(struct btc_coexist *btcoexist,
1875 				   u16 bt_hci_version, u16 bt_patch_version)
1876 {
1877 	if (!halbtc_is_bt_coexist_available(btcoexist))
1878 		return;
1879 
1880 	btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1881 	btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1882 }
1883 
1884 void exhalbtc_set_chip_type(struct btc_coexist *btcoexist, u8 chip_type)
1885 {
1886 	switch (chip_type) {
1887 	default:
1888 	case BT_2WIRE:
1889 	case BT_ISSC_3WIRE:
1890 	case BT_ACCEL:
1891 	case BT_RTL8756:
1892 		btcoexist->board_info.bt_chip_type = BTC_CHIP_UNDEF;
1893 		break;
1894 	case BT_CSR_BC4:
1895 		btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1896 		break;
1897 	case BT_CSR_BC8:
1898 		btcoexist->board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1899 		break;
1900 	case BT_RTL8723A:
1901 		btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1902 		break;
1903 	case BT_RTL8821A:
1904 		btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8821;
1905 		break;
1906 	case BT_RTL8723B:
1907 		btcoexist->board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1908 		break;
1909 	}
1910 }
1911 
1912 void exhalbtc_set_ant_num(struct rtl_priv *rtlpriv, u8 type, u8 ant_num)
1913 {
1914 	struct btc_coexist *btcoexist = rtl_btc_coexist(rtlpriv);
1915 
1916 	if (!btcoexist)
1917 		return;
1918 
1919 	if (BT_COEX_ANT_TYPE_PG == type) {
1920 		btcoexist->board_info.pg_ant_num = ant_num;
1921 		btcoexist->board_info.btdm_ant_num = ant_num;
1922 	} else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1923 		btcoexist->board_info.btdm_ant_num = ant_num;
1924 	} else if (type == BT_COEX_ANT_TYPE_DETECTED) {
1925 		btcoexist->board_info.btdm_ant_num = ant_num;
1926 		if (rtlpriv->cfg->mod_params->ant_sel == 1)
1927 			btcoexist->board_info.btdm_ant_pos =
1928 				BTC_ANTENNA_AT_AUX_PORT;
1929 		else
1930 			btcoexist->board_info.btdm_ant_pos =
1931 				BTC_ANTENNA_AT_MAIN_PORT;
1932 	}
1933 }
1934 
1935 /* Currently used by 8723b only, S0 or S1 */
1936 void exhalbtc_set_single_ant_path(struct btc_coexist *btcoexist,
1937 				  u8 single_ant_path)
1938 {
1939 	btcoexist->board_info.single_ant_path = single_ant_path;
1940 }
1941 
1942 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist,
1943 				   struct seq_file *m)
1944 {
1945 	if (!halbtc_is_bt_coexist_available(btcoexist))
1946 		return;
1947 
1948 	halbtc_leave_low_power(btcoexist);
1949 
1950 	if (IS_HARDWARE_TYPE_8821(btcoexist->adapter)) {
1951 		if (btcoexist->board_info.btdm_ant_num == 2)
1952 			ex_btc8821a2ant_display_coex_info(btcoexist, m);
1953 		else if (btcoexist->board_info.btdm_ant_num == 1)
1954 			ex_btc8821a1ant_display_coex_info(btcoexist, m);
1955 	} else if (IS_HARDWARE_TYPE_8723B(btcoexist->adapter)) {
1956 		if (btcoexist->board_info.btdm_ant_num == 2)
1957 			ex_btc8723b2ant_display_coex_info(btcoexist, m);
1958 		else if (btcoexist->board_info.btdm_ant_num == 1)
1959 			ex_btc8723b1ant_display_coex_info(btcoexist, m);
1960 	} else if (IS_HARDWARE_TYPE_8192E(btcoexist->adapter)) {
1961 		if (btcoexist->board_info.btdm_ant_num == 2)
1962 			ex_btc8192e2ant_display_coex_info(btcoexist, m);
1963 	}
1964 
1965 	halbtc_normal_low_power(btcoexist);
1966 }
1967 
1968 void exhalbtc_switch_band_notify(struct btc_coexist *btcoexist, u8 type)
1969 {
1970 	if (!halbtc_is_bt_coexist_available(btcoexist))
1971 		return;
1972 
1973 	if (btcoexist->manual_control)
1974 		return;
1975 
1976 	halbtc_leave_low_power(btcoexist);
1977 
1978 	halbtc_normal_low_power(btcoexist);
1979 }
1980 
1981 void exhalbtc_switch_band_notify_wifi_only(struct wifi_only_cfg *wifionly_cfg,
1982 					   u8 is_5g)
1983 {
1984 }
1985