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