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