xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8189fs/hal/hal_btcoex.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /******************************************************************************
3  *
4  * Copyright(c) 2013 - 2017 Realtek Corporation.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms of version 2 of the GNU General Public License as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  *****************************************************************************/
16 #define __HAL_BTCOEX_C__
17 
18 #ifdef CONFIG_BT_COEXIST
19 
20 #include <hal_data.h>
21 #include <hal_btcoex.h>
22 #include "btc/mp_precomp.h"
23 
24 /* ************************************
25  *		Global variables
26  * ************************************ */
27 const char *const BtProfileString[] = {
28 	"NONE",
29 	"A2DP",
30 	"PAN",
31 	"HID",
32 	"SCO",
33 };
34 
35 const char *const BtSpecString[] = {
36 	"1.0b",
37 	"1.1",
38 	"1.2",
39 	"2.0+EDR",
40 	"2.1+EDR",
41 	"3.0+HS",
42 	"4.0",
43 };
44 
45 const char *const BtLinkRoleString[] = {
46 	"Master",
47 	"Slave",
48 };
49 
50 const char *const h2cStaString[] = {
51 	"successful",
52 	"h2c busy",
53 	"rf off",
54 	"fw not read",
55 };
56 
57 const char *const ioStaString[] = {
58 	"success",
59 	"can not IO",
60 	"rf off",
61 	"fw not read",
62 	"wait io timeout",
63 	"invalid len",
64 	"idle Q empty",
65 	"insert waitQ fail",
66 	"unknown fail",
67 	"wrong level",
68 	"h2c stopped",
69 };
70 
71 const char *const GLBtcWifiBwString[] = {
72 	"11bg",
73 	"HT20",
74 	"HT40",
75 	"VHT80",
76 	"VHT160"
77 };
78 
79 const char *const GLBtcWifiFreqString[] = {
80 	"2.4G",
81 	"5G",
82 	"2.4G+5G"
83 };
84 
85 const char *const GLBtcIotPeerString[] = {
86 	"UNKNOWN",
87 	"REALTEK",
88 	"REALTEK_92SE",
89 	"BROADCOM",
90 	"RALINK",
91 	"ATHEROS",
92 	"CISCO",
93 	"MERU",
94 	"MARVELL",
95 	"REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
96 	"SELF_SOFTAP", /* Self is SoftAP */
97 	"AIRGO",
98 	"INTEL",
99 	"RTK_APCLIENT",
100 	"REALTEK_81XX",
101 	"REALTEK_WOW",
102 	"REALTEK_JAGUAR_BCUTAP",
103 	"REALTEK_JAGUAR_CCUTAP"
104 };
105 
106 const char *const coexOpcodeString[] = {
107 	"Wifi status notify",
108 	"Wifi progress",
109 	"Wifi info",
110 	"Power state",
111 	"Set Control",
112 	"Get Control"
113 };
114 
115 const char *const coexIndTypeString[] = {
116 	"bt info",
117 	"pstdma",
118 	"limited tx/rx",
119 	"coex table",
120 	"request"
121 };
122 
123 const char *const coexH2cResultString[] = {
124 	"ok",
125 	"unknown",
126 	"un opcode",
127 	"opVer MM",
128 	"par Err",
129 	"par OoR",
130 	"reqNum MM",
131 	"halMac Fail",
132 	"h2c TimeOut",
133 	"Invalid c2h Len",
134 	"data overflow"
135 };
136 
137 #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS	8000
138 
139 struct btc_coexist GLBtCoexist;
140 BTC_OFFLOAD gl_coex_offload;
141 u8 GLBtcWiFiInScanState;
142 u8 GLBtcWiFiInIQKState;
143 u8 GLBtcWiFiInIPS;
144 u8 GLBtcWiFiInLPS;
145 u8 GLBtcBtCoexAliveRegistered;
146 
147 /*
148  * BT control H2C/C2H
149  */
150 /* EXT_EID */
151 typedef enum _bt_ext_eid {
152 	C2H_WIFI_FW_ACTIVE_RSP	= 0,
153 	C2H_TRIG_BY_BT_FW
154 } BT_EXT_EID;
155 
156 /* C2H_STATUS */
157 typedef enum _bt_c2h_status {
158 	BT_STATUS_OK = 0,
159 	BT_STATUS_VERSION_MISMATCH,
160 	BT_STATUS_UNKNOWN_OPCODE,
161 	BT_STATUS_ERROR_PARAMETER
162 } BT_C2H_STATUS;
163 
164 /* C2H BT OP CODES */
165 typedef enum _bt_op_code {
166 	BT_OP_GET_BT_VERSION					= 0x00,
167 	BT_OP_WRITE_REG_ADDR					= 0x0c,
168 	BT_OP_WRITE_REG_VALUE					= 0x0d,
169 
170 	BT_OP_READ_REG							= 0x11,
171 
172 	BT_LO_OP_GET_AFH_MAP_L					= 0x1e,
173 	BT_LO_OP_GET_AFH_MAP_M					= 0x1f,
174 	BT_LO_OP_GET_AFH_MAP_H					= 0x20,
175 
176 	BT_OP_GET_BT_COEX_SUPPORTED_FEATURE		= 0x2a,
177 	BT_OP_GET_BT_COEX_SUPPORTED_VERSION		= 0x2b,
178 	BT_OP_GET_BT_ANT_DET_VAL				= 0x2c,
179 	BT_OP_GET_BT_BLE_SCAN_TYPE				= 0x2d,
180 	BT_OP_GET_BT_BLE_SCAN_PARA				= 0x2e,
181 	BT_OP_GET_BT_DEVICE_INFO				= 0x30,
182 	BT_OP_GET_BT_FORBIDDEN_SLOT_VAL			= 0x31,
183 	BT_OP_SET_BT_LANCONSTRAIN_LEVEL			= 0x32,
184 	BT_OP_SET_BT_TEST_MODE_VAL				= 0x33,
185 	BT_OP_MAX
186 } BT_OP_CODE;
187 
188 #define BTC_MPOPER_TIMEOUT	50	/* unit: ms */
189 
190 #define C2H_MAX_SIZE		16
191 u8 GLBtcBtMpOperSeq;
192 _mutex GLBtcBtMpOperLock;
193 _timer GLBtcBtMpOperTimer;
194 _sema GLBtcBtMpRptSema;
195 u8 GLBtcBtMpRptSeq;
196 u8 GLBtcBtMpRptStatus;
197 u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE];
198 u8 GLBtcBtMpRptRspSize;
199 u8 GLBtcBtMpRptWait;
200 u8 GLBtcBtMpRptWiFiOK;
201 u8 GLBtcBtMpRptBTOK;
202 
203 /*
204  * Debug
205  */
206 u32 GLBtcDbgType[COMP_MAX];
207 u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
208 u8	gl_btc_trace_buf[BT_TMP_BUF_SIZE];
209 
210 typedef struct _btcoexdbginfo {
211 	u8 *info;
212 	u32 size; /* buffer total size */
213 	u32 len; /* now used length */
214 } BTCDBGINFO, *PBTCDBGINFO;
215 
216 BTCDBGINFO GLBtcDbgInfo;
217 
218 #define	BT_Operation(Adapter)						_FALSE
219 
DBG_BT_INFO_INIT(PBTCDBGINFO pinfo,u8 * pbuf,u32 size)220 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
221 {
222 	if (NULL == pinfo)
223 		return;
224 
225 	_rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
226 
227 	if (pbuf && size) {
228 		pinfo->info = pbuf;
229 		pinfo->size = size;
230 	}
231 }
232 
DBG_BT_INFO(u8 * dbgmsg)233 void DBG_BT_INFO(u8 *dbgmsg)
234 {
235 	PBTCDBGINFO pinfo;
236 	u32 msglen, buflen;
237 	u8 *pbuf;
238 
239 
240 	pinfo = &GLBtcDbgInfo;
241 
242 	if (NULL == pinfo->info)
243 		return;
244 
245 	msglen = strlen(dbgmsg);
246 	if (pinfo->len + msglen > pinfo->size)
247 		return;
248 
249 	pbuf = pinfo->info + pinfo->len;
250 	_rtw_memcpy(pbuf, dbgmsg, msglen);
251 	pinfo->len += msglen;
252 }
253 
254 /* ************************************
255  *		Debug related function
256  * ************************************ */
halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)257 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
258 {
259 	if (!pBtCoexist->bBinded ||
260 	    NULL == pBtCoexist->Adapter)
261 		return _FALSE;
262 	return _TRUE;
263 }
264 
halbtcoutsrc_DbgInit(void)265 static void halbtcoutsrc_DbgInit(void)
266 {
267 	u8	i;
268 
269 	for (i = 0; i < COMP_MAX; i++)
270 		GLBtcDbgType[i] = 0;
271 }
272 
halbtcoutsrc_EnterPwrLock(PBTC_COEXIST pBtCoexist)273 static void halbtcoutsrc_EnterPwrLock(PBTC_COEXIST pBtCoexist)
274 {
275 	struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
276 	struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
277 
278 	_enter_pwrlock(&pwrpriv->lock);
279 }
280 
halbtcoutsrc_ExitPwrLock(PBTC_COEXIST pBtCoexist)281 static void halbtcoutsrc_ExitPwrLock(PBTC_COEXIST pBtCoexist)
282 {
283 	struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
284 	struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
285 
286 	_exit_pwrlock(&pwrpriv->lock);
287 }
288 
halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)289 static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
290 {
291 	if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
292 	    || pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
293 	   )
294 		return _FALSE;
295 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
296 		return _FALSE;
297 	else
298 		return _TRUE;
299 }
300 
halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)301 static u8 halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
302 {
303 	PADAPTER padapter;
304 
305 
306 	padapter = pBtCoexist->Adapter;
307 
308 	pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
309 	pBtCoexist->bt_info.bt_lps_on = _FALSE;
310 
311 	return rtw_btcoex_LPS_Leave(padapter);
312 }
313 
halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)314 void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
315 {
316 	PADAPTER padapter;
317 
318 
319 	padapter = pBtCoexist->Adapter;
320 
321 	if (pBtCoexist->bdontenterLPS == _FALSE) {
322 		pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
323 		pBtCoexist->bt_info.bt_lps_on = _TRUE;
324 
325 		rtw_btcoex_LPS_Enter(padapter);
326 	}
327 }
328 
halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)329 void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
330 {
331 	PADAPTER padapter;
332 
333 
334 
335 	padapter = pBtCoexist->Adapter;
336 
337 	if (pBtCoexist->bt_info.bt_ctrl_lps) {
338 		pBtCoexist->bt_info.bt_lps_on = _FALSE;
339 		rtw_btcoex_LPS_Leave(padapter);
340 		pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;
341 
342 		/* recover the LPS state to the original */
343 #if 0
344 		padapter->hal_func.UpdateLPSStatusHandler(
345 			padapter,
346 			pPSC->RegLeisurePsMode,
347 			pPSC->RegPowerSaveMode);
348 #endif
349 	}
350 }
351 
halbtcoutsrc_Pre_NormalLps(PBTC_COEXIST pBtCoexist)352 void halbtcoutsrc_Pre_NormalLps(PBTC_COEXIST pBtCoexist)
353 {
354 	PADAPTER padapter;
355 
356 	padapter = pBtCoexist->Adapter;
357 
358 	if (pBtCoexist->bt_info.bt_ctrl_lps) {
359 		pBtCoexist->bt_info.bt_lps_on = _FALSE;
360 		rtw_btcoex_LPS_Leave(padapter);
361 	}
362 }
363 
halbtcoutsrc_Post_NormalLps(PBTC_COEXIST pBtCoexist)364 void halbtcoutsrc_Post_NormalLps(PBTC_COEXIST pBtCoexist)
365 {
366 	if (pBtCoexist->bt_info.bt_ctrl_lps)
367 		pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;
368 }
369 
370 /*
371  *  Constraint:
372  *	   1. this function will request pwrctrl->lock
373  */
halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)374 void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
375 {
376 #ifdef CONFIG_LPS_LCLK
377 	PADAPTER padapter;
378 	PHAL_DATA_TYPE pHalData;
379 	struct pwrctrl_priv *pwrctrl;
380 	s32 ready;
381 	systime stime;
382 	s32 utime;
383 	u32 timeout; /* unit: ms */
384 
385 
386 	padapter = pBtCoexist->Adapter;
387 	pHalData = GET_HAL_DATA(padapter);
388 	pwrctrl = adapter_to_pwrctl(padapter);
389 	ready = _FAIL;
390 #ifdef LPS_RPWM_WAIT_MS
391 	timeout = LPS_RPWM_WAIT_MS;
392 #else /* !LPS_RPWM_WAIT_MS */
393 	timeout = 30;
394 #endif /* !LPS_RPWM_WAIT_MS */
395 
396 	if (GLBtcBtCoexAliveRegistered == _TRUE)
397 		return;
398 
399 	stime = rtw_get_current_time();
400 	do {
401 		ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
402 		if (_SUCCESS == ready)
403 			break;
404 
405 		utime = rtw_get_passing_time_ms(stime);
406 		if (utime > timeout)
407 			break;
408 
409 		rtw_msleep_os(1);
410 	} while (1);
411 
412 	GLBtcBtCoexAliveRegistered = _TRUE;
413 #endif /* CONFIG_LPS_LCLK */
414 }
415 
416 /*
417  *  Constraint:
418  *	   1. this function will request pwrctrl->lock
419  */
halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)420 void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
421 {
422 #ifdef CONFIG_LPS_LCLK
423 	PADAPTER padapter;
424 
425 	if (GLBtcBtCoexAliveRegistered == _FALSE)
426 		return;
427 
428 	padapter = pBtCoexist->Adapter;
429 	rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
430 
431 	GLBtcBtCoexAliveRegistered = _FALSE;
432 #endif /* CONFIG_LPS_LCLK */
433 }
434 
halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist,u8 bLowPwrDisable)435 void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
436 {
437 	pBtCoexist->bt_info.bt_disable_low_pwr = bLowPwrDisable;
438 	if (bLowPwrDisable)
439 		halbtcoutsrc_LeaveLowPower(pBtCoexist);		/* leave 32k low power. */
440 	else
441 		halbtcoutsrc_NormalLowPower(pBtCoexist);	/* original 32k low power behavior. */
442 }
443 
halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)444 void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
445 {
446 	PADAPTER padapter;
447 	BOOLEAN bNeedToAct = _FALSE;
448 	static u32 preTime = 0;
449 	u32 curTime = 0;
450 
451 	padapter = pBtCoexist->Adapter;
452 
453 	/* ===================================== */
454 	/* To void continuous deleteBA=>addBA=>deleteBA=>addBA */
455 	/* This function is not allowed to continuous called. */
456 	/* It can only be called after 8 seconds. */
457 	/* ===================================== */
458 
459 	curTime = rtw_systime_to_ms(rtw_get_current_time());
460 	if ((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS)	/* over 8 seconds you can execute this function again. */
461 		return;
462 	else
463 		preTime = curTime;
464 
465 	if (pBtCoexist->bt_info.reject_agg_pkt) {
466 		bNeedToAct = _TRUE;
467 		pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
468 	} else {
469 		if (pBtCoexist->bt_info.pre_reject_agg_pkt) {
470 			bNeedToAct = _TRUE;
471 			pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
472 		}
473 
474 		if (pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
475 		    pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
476 			bNeedToAct = _TRUE;
477 			pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size = pBtCoexist->bt_info.bt_ctrl_agg_buf_size;
478 		}
479 
480 		if (pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
481 			if (pBtCoexist->bt_info.pre_agg_buf_size !=
482 			    pBtCoexist->bt_info.agg_buf_size)
483 				bNeedToAct = _TRUE;
484 			pBtCoexist->bt_info.pre_agg_buf_size = pBtCoexist->bt_info.agg_buf_size;
485 		}
486 	}
487 
488 	if (bNeedToAct)
489 		rtw_btcoex_rx_ampdu_apply(padapter);
490 }
491 
halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist)492 u8 halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist)
493 {
494 	PADAPTER padapter;
495 	PHAL_DATA_TYPE pHalData;
496 
497 	padapter = pBtCoexist->Adapter;
498 	pHalData = GET_HAL_DATA(padapter);
499 
500 	return pHalData->bautoload_fail_flag;
501 }
502 
halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist)503 u8 halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist)
504 {
505 	PADAPTER padapter;
506 
507 	padapter = pBtCoexist->Adapter;
508 
509 	return GET_HAL_DATA(padapter)->bFWReady;
510 }
511 
halbtcoutsrc_IsDualBandConnected(PADAPTER padapter)512 u8 halbtcoutsrc_IsDualBandConnected(PADAPTER padapter)
513 {
514 	u8 ret = BTC_MULTIPORT_SCC;
515 
516 #ifdef CONFIG_MCC_MODE
517 	if (MCC_EN(padapter) && (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))) {
518 		struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
519 		struct mcc_obj_priv *mccobjpriv = &(dvobj->mcc_objpriv);
520 		u8 band0 = mccobjpriv->iface[0]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
521 		u8 band1 = mccobjpriv->iface[1]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
522 
523 		if (band0 != band1)
524 			ret = BTC_MULTIPORT_MCC_DUAL_BAND;
525 		else
526 			ret = BTC_MULTIPORT_MCC_DUAL_CHANNEL;
527 	}
528 #endif
529 
530 	return ret;
531 }
532 
halbtcoutsrc_IsWifiBusy(PADAPTER padapter)533 u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
534 {
535 	if (rtw_mi_check_status(padapter, MI_AP_ASSOC))
536 		return _TRUE;
537 	if (rtw_mi_busy_traffic_check(padapter, _FALSE))
538 		return _TRUE;
539 
540 	return _FALSE;
541 }
542 
_halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)543 static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
544 {
545 	struct mlme_priv *pmlmepriv;
546 	u8 bp2p;
547 	u32 portConnectedStatus;
548 
549 
550 	pmlmepriv = &padapter->mlmepriv;
551 	bp2p = _FALSE;
552 	portConnectedStatus = 0;
553 
554 #ifdef CONFIG_P2P
555 	if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
556 		bp2p = _TRUE;
557 #endif /* CONFIG_P2P */
558 
559 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {
560 		if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
561 			if (_TRUE == bp2p)
562 				portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
563 			else
564 				portConnectedStatus |= WIFI_AP_CONNECTED;
565 		} else {
566 			if (_TRUE == bp2p)
567 				portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
568 			else
569 				portConnectedStatus |= WIFI_STA_CONNECTED;
570 		}
571 	}
572 
573 	return portConnectedStatus;
574 }
575 
halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)576 u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
577 {
578 	/* ================================= */
579 	/* return value: */
580 	/* [31:16]=> connected port number */
581 	/* [15:0]=> port connected bit define */
582 	/* ================================ */
583 
584 	PADAPTER padapter;
585 	u32 retVal;
586 	u32 portConnectedStatus, numOfConnectedPort;
587 	struct dvobj_priv *dvobj;
588 	_adapter *iface;
589 	int i;
590 
591 	padapter = pBtCoexist->Adapter;
592 	retVal = 0;
593 	portConnectedStatus = 0;
594 	numOfConnectedPort = 0;
595 	dvobj = adapter_to_dvobj(padapter);
596 
597 	for (i = 0; i < dvobj->iface_nums; i++) {
598 		iface = dvobj->padapters[i];
599 		if ((iface) && rtw_is_adapter_up(iface)) {
600 			retVal = _halbtcoutsrc_GetWifiLinkStatus(iface);
601 			if (retVal) {
602 				portConnectedStatus |= retVal;
603 				numOfConnectedPort++;
604 			}
605 		}
606 	}
607 	retVal = (numOfConnectedPort << 16) | portConnectedStatus;
608 
609 	return retVal;
610 }
611 
halbtcoutsrc_getwifilinkinfo(PBTC_COEXIST pBtCoexist)612 struct btc_wifi_link_info halbtcoutsrc_getwifilinkinfo(PBTC_COEXIST pBtCoexist)
613 {
614 	u8 n_assoc_iface = 0, i =0, mcc_en = _FALSE;
615 	PADAPTER adapter = NULL;
616 	PADAPTER iface = NULL;
617 	PADAPTER sta_iface = NULL, p2p_iface = NULL, ap_iface = NULL;
618 	BTC_LINK_MODE btc_link_moe = BTC_LINK_MAX;
619 	struct dvobj_priv *dvobj = NULL;
620 	struct mlme_ext_priv *mlmeext = NULL;
621 	struct btc_wifi_link_info wifi_link_info;
622 
623 	adapter = (PADAPTER)pBtCoexist->Adapter;
624 	dvobj = adapter_to_dvobj(adapter);
625 	n_assoc_iface = rtw_mi_get_assoc_if_num(adapter);
626 
627 	/* init value */
628 	wifi_link_info.link_mode = BTC_LINK_NONE;
629 	wifi_link_info.sta_center_channel = 0;
630 	wifi_link_info.p2p_center_channel = 0;
631 	wifi_link_info.bany_client_join_go = _FALSE;
632 	wifi_link_info.benable_noa = _FALSE;
633 	wifi_link_info.bhotspot = _FALSE;
634 
635 	for (i = 0; i < dvobj->iface_nums; i++) {
636 		iface = dvobj->padapters[i];
637 		if (!iface)
638 			continue;
639 
640 		mlmeext = &iface->mlmeextpriv;
641 		if (MLME_IS_GO(iface)) {
642 			wifi_link_info.link_mode = BTC_LINK_ONLY_GO;
643 			wifi_link_info.p2p_center_channel =
644 				rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
645 			p2p_iface	 = iface;
646 			if (rtw_linked_check(iface))
647 				wifi_link_info.bany_client_join_go = _TRUE;
648 		} else if (MLME_IS_GC(iface)) {
649 			wifi_link_info.link_mode = BTC_LINK_ONLY_GC;
650 			wifi_link_info.p2p_center_channel =
651 				rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
652 			p2p_iface = iface;
653 		} else if (MLME_IS_AP(iface)) {
654 			wifi_link_info.link_mode = BTC_LINK_ONLY_AP;
655 			ap_iface = iface;
656 			wifi_link_info.p2p_center_channel =
657 				rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
658 		} else if (MLME_IS_STA(iface) && rtw_linked_check(iface)) {
659 			wifi_link_info.link_mode = BTC_LINK_ONLY_STA;
660 			wifi_link_info.sta_center_channel =
661 				rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
662 			sta_iface = iface;
663 		}
664 	}
665 
666 #ifdef CONFIG_MCC_MODE
667 	if (MCC_EN(adapter)) {
668 		if (rtw_hal_check_mcc_status(adapter, MCC_STATUS_DOING_MCC))
669 			mcc_en = _TRUE;
670 	}
671 #endif/* CONFIG_MCC_MODE */
672 
673 	if (n_assoc_iface == 0) {
674 		wifi_link_info.link_mode = BTC_LINK_NONE;
675 	} else if (n_assoc_iface == 1) {
676 		/* by pass */
677 	} else if (n_assoc_iface == 2) {
678 		if (sta_iface && p2p_iface) {
679 			u8 band_sta = sta_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
680 			u8 band_p2p = p2p_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
681 			if (band_sta == band_p2p) {
682 				switch (band_sta) {
683 				case BAND_ON_2_4G:
684 					if (MLME_IS_GO(p2p_iface))
685 						wifi_link_info.link_mode =
686 							mcc_en == _TRUE ?  BTC_LINK_2G_MCC_GO_STA : BTC_LINK_2G_SCC_GO_STA;
687 					else if (MLME_IS_GC(p2p_iface))
688 						wifi_link_info.link_mode =
689 							mcc_en == _TRUE ?  BTC_LINK_2G_MCC_GC_STA : BTC_LINK_2G_SCC_GC_STA;
690 					break;
691 				case BAND_ON_5G:
692 					if (MLME_IS_GO(p2p_iface))
693 						wifi_link_info.link_mode =
694 							mcc_en == _TRUE ?  BTC_LINK_5G_MCC_GO_STA : BTC_LINK_5G_SCC_GO_STA;
695 					else if (MLME_IS_GC(p2p_iface))
696 						wifi_link_info.link_mode =
697 							mcc_en == _TRUE ?  BTC_LINK_5G_MCC_GC_STA : BTC_LINK_5G_SCC_GC_STA;
698 					break;
699 				default:
700 					break;
701 				}
702 			} else {
703 				if (MLME_IS_GO(p2p_iface))
704 					wifi_link_info.link_mode = BTC_LINK_25G_MCC_GO_STA;
705 				else if (MLME_IS_GC(p2p_iface))
706 					wifi_link_info.link_mode = BTC_LINK_25G_MCC_GC_STA;
707 			}
708 		}
709 	} else {
710 		if (pBtCoexist->board_info.btdm_ant_num == 1)
711 			RTW_ERR("%s do not support n_assoc_iface > 2 (ant_num == 1)", __func__);
712 	}
713 
714 	return wifi_link_info;
715 }
716 
717 
_btmpoper_timer_hdl(void * p)718 static void _btmpoper_timer_hdl(void *p)
719 {
720 	if (GLBtcBtMpRptWait == _TRUE) {
721 		GLBtcBtMpRptWait = _FALSE;
722 		_rtw_up_sema(&GLBtcBtMpRptSema);
723 	}
724 }
725 
726 /*
727  * !IMPORTANT!
728  *	Before call this function, caller should acquire "GLBtcBtMpOperLock"!
729  *	Othrewise there will be racing problem and something may go wrong.
730  */
_btmpoper_cmd(PBTC_COEXIST pBtCoexist,u8 opcode,u8 opcodever,u8 * cmd,u8 size)731 static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size)
732 {
733 	PADAPTER padapter;
734 	u8 buf[H2C_BTMP_OPER_LEN] = {0};
735 	u8 buflen;
736 	u8 seq;
737 	s32 ret;
738 
739 
740 	if (!cmd && size)
741 		size = 0;
742 	if ((size + 2) > H2C_BTMP_OPER_LEN)
743 		return BT_STATUS_H2C_LENGTH_EXCEEDED;
744 	buflen = size + 2;
745 
746 	seq = GLBtcBtMpOperSeq & 0xF;
747 	GLBtcBtMpOperSeq++;
748 
749 	buf[0] = (opcodever & 0xF) | (seq << 4);
750 	buf[1] = opcode;
751 	if (cmd && size)
752 		_rtw_memcpy(buf + 2, cmd, size);
753 
754 	GLBtcBtMpRptWait = _TRUE;
755 	GLBtcBtMpRptWiFiOK = _FALSE;
756 	GLBtcBtMpRptBTOK = _FALSE;
757 	GLBtcBtMpRptStatus = 0;
758 	padapter = pBtCoexist->Adapter;
759 	_set_timer(&GLBtcBtMpOperTimer, BTC_MPOPER_TIMEOUT);
760 	if (rtw_hal_fill_h2c_cmd(padapter, H2C_BT_MP_OPER, buflen, buf) == _FAIL) {
761 		_cancel_timer_ex(&GLBtcBtMpOperTimer);
762 		ret = BT_STATUS_H2C_FAIL;
763 		goto exit;
764 	}
765 
766 	_rtw_down_sema(&GLBtcBtMpRptSema);
767 	/* GLBtcBtMpRptWait should be _FALSE here*/
768 
769 	if (GLBtcBtMpRptWiFiOK == _FALSE) {
770 		RTW_ERR("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__);
771 		ret = BT_STATUS_H2C_TIMTOUT;
772 		goto exit;
773 	}
774 	if (GLBtcBtMpRptBTOK == _FALSE) {
775 		RTW_DBG("%s: Didn't get BT response!\n", __FUNCTION__);
776 		ret = BT_STATUS_H2C_BT_NO_RSP;
777 		goto exit;
778 	}
779 
780 	if (seq != GLBtcBtMpRptSeq) {
781 		RTW_ERR("%s: Sequence number not match!(%d!=%d)!\n",
782 			 __FUNCTION__, seq, GLBtcBtMpRptSeq);
783 		ret = BT_STATUS_C2H_REQNUM_MISMATCH;
784 		goto exit;
785 	}
786 
787 	switch (GLBtcBtMpRptStatus) {
788 	/* Examine the status reported from C2H */
789 	case BT_STATUS_OK:
790 		ret = BT_STATUS_BT_OP_SUCCESS;
791 		RTW_DBG("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__);
792 		break;
793 	case BT_STATUS_VERSION_MISMATCH:
794 		ret = BT_STATUS_OPCODE_L_VERSION_MISMATCH;
795 		RTW_DBG("%s: C2H status = BT_STATUS_OPCODE_L_VERSION_MISMATCH\n", __FUNCTION__);
796 		break;
797 	case BT_STATUS_UNKNOWN_OPCODE:
798 		ret = BT_STATUS_UNKNOWN_OPCODE_L;
799 		RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_OPCODE_L\n", __FUNCTION__);
800 		break;
801 	case BT_STATUS_ERROR_PARAMETER:
802 		ret = BT_STATUS_PARAMETER_FORMAT_ERROR_L;
803 		RTW_DBG("%s: C2H status = MP_BT_STATUS_PARAMETER_FORMAT_ERROR_L\n", __FUNCTION__);
804 		break;
805 	default:
806 		ret = BT_STATUS_UNKNOWN_STATUS_L;
807 		RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__);
808 		break;
809 	}
810 
811 exit:
812 	return ret;
813 }
814 
halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)815 u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
816 {
817 	if (pBtCoexist->bt_info.get_bt_fw_ver_cnt <= 5) {
818 		if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
819 			_irqL irqL;
820 			u8 ret;
821 
822 			_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
823 
824 			ret = _btmpoper_cmd(pBtCoexist, BT_OP_GET_BT_VERSION, 0, NULL, 0);
825 			if (BT_STATUS_BT_OP_SUCCESS == ret) {
826 				pBtCoexist->bt_info.bt_real_fw_ver = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
827 				pBtCoexist->bt_info.bt_fw_ver = *(GLBtcBtMpRptRsp + 2);
828 				pBtCoexist->bt_info.get_bt_fw_ver_cnt++;
829 			}
830 
831 			_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
832 		} else {
833 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
834 			u8 dataLen = 2;
835 			u8 buf[4] = {0};
836 
837 			buf[0] = 0x0;	/* OP_Code */
838 			buf[1] = 0x0;	/* OP_Code_Length */
839 			BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
840 #endif /* !CONFIG_BT_COEXIST_SOCKET_TRX */
841 		}
842 	}
843 
844 	return pBtCoexist->bt_info.bt_real_fw_ver;
845 }
846 
halbtcoutsrc_GetWifiRssi(PADAPTER padapter)847 s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
848 {
849 	return rtw_dm_get_min_rssi(padapter);
850 }
851 
halbtcoutsrc_GetBtCoexSupportedFeature(void * pBtcContext)852 u32 halbtcoutsrc_GetBtCoexSupportedFeature(void *pBtcContext)
853 {
854 	PBTC_COEXIST pBtCoexist;
855 	u32 ret = BT_STATUS_BT_OP_SUCCESS;
856 	u32 data = 0;
857 
858 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
859 
860 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
861 		u8 buf[3] = {0};
862 		_irqL irqL;
863 		u8 op_code;
864 		u8 status;
865 
866 		_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
867 
868 		op_code = BT_OP_GET_BT_COEX_SUPPORTED_FEATURE;
869 		status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
870 		if (status == BT_STATUS_BT_OP_SUCCESS)
871 			data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
872 		else
873 			ret = SET_BT_MP_OPER_RET(op_code, status);
874 
875 		_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
876 
877 	} else
878 		ret = BT_STATUS_NOT_IMPLEMENT;
879 
880 	return data;
881 }
882 
halbtcoutsrc_GetBtCoexSupportedVersion(void * pBtcContext)883 u32 halbtcoutsrc_GetBtCoexSupportedVersion(void *pBtcContext)
884 {
885 	PBTC_COEXIST pBtCoexist;
886 	u32 ret = BT_STATUS_BT_OP_SUCCESS;
887 	u32 data = 0xFFFF;
888 
889 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
890 
891 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
892 		u8 buf[3] = {0};
893 		_irqL irqL;
894 		u8 op_code;
895 		u8 status;
896 
897 		_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
898 
899 		op_code = BT_OP_GET_BT_COEX_SUPPORTED_VERSION;
900 		status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
901 		if (status == BT_STATUS_BT_OP_SUCCESS)
902 			data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
903 		else
904 			ret = SET_BT_MP_OPER_RET(op_code, status);
905 
906 		_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
907 
908 	} else
909 		ret = BT_STATUS_NOT_IMPLEMENT;
910 
911 	return data;
912 }
913 
halbtcoutsrc_GetBtDeviceInfo(void * pBtcContext)914 u32 halbtcoutsrc_GetBtDeviceInfo(void *pBtcContext)
915 {
916 	PBTC_COEXIST pBtCoexist;
917 	u32 ret = BT_STATUS_BT_OP_SUCCESS;
918 	u32 btDeviceInfo = 0;
919 
920 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
921 
922 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
923 		u8 buf[3] = {0};
924 		_irqL irqL;
925 		u8 op_code;
926 		u8 status;
927 
928 		_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
929 
930 		op_code = BT_OP_GET_BT_DEVICE_INFO;
931 		status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
932 		if (status == BT_STATUS_BT_OP_SUCCESS)
933 			btDeviceInfo = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
934 		else
935 			ret = SET_BT_MP_OPER_RET(op_code, status);
936 
937 		_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
938 
939 	} else
940 		ret = BT_STATUS_NOT_IMPLEMENT;
941 
942 	return btDeviceInfo;
943 }
944 
halbtcoutsrc_GetBtForbiddenSlotVal(void * pBtcContext)945 u32 halbtcoutsrc_GetBtForbiddenSlotVal(void *pBtcContext)
946 {
947 	PBTC_COEXIST pBtCoexist;
948 	u32 ret = BT_STATUS_BT_OP_SUCCESS;
949 	u32 btForbiddenSlotVal = 0;
950 
951 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
952 
953 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
954 		u8 buf[3] = {0};
955 		_irqL irqL;
956 		u8 op_code;
957 		u8 status;
958 
959 		_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
960 
961 		op_code = BT_OP_GET_BT_FORBIDDEN_SLOT_VAL;
962 		status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
963 		if (status == BT_STATUS_BT_OP_SUCCESS)
964 			btForbiddenSlotVal = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
965 		else
966 			ret = SET_BT_MP_OPER_RET(op_code, status);
967 
968 		_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
969 
970 	} else
971 		ret = BT_STATUS_NOT_IMPLEMENT;
972 
973 	return btForbiddenSlotVal;
974 }
975 
halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)976 static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
977 {
978 	struct mlme_priv *pmlmepriv;
979 	struct mlme_ext_priv *pmlmeext;
980 	static u8 scan_AP_num = 0;
981 
982 
983 	pmlmepriv = &padapter->mlmepriv;
984 	pmlmeext = &padapter->mlmeextpriv;
985 
986 	if (GLBtcWiFiInScanState == _FALSE) {
987 		if (pmlmepriv->num_of_scanned > 0xFF)
988 			scan_AP_num = 0xFF;
989 		else
990 			scan_AP_num = (u8)pmlmepriv->num_of_scanned;
991 	}
992 
993 	return scan_AP_num;
994 }
995 
halbtcoutsrc_Get(void * pBtcContext,u8 getType,void * pOutBuf)996 u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
997 {
998 	PBTC_COEXIST pBtCoexist;
999 	PADAPTER padapter;
1000 	PHAL_DATA_TYPE pHalData;
1001 	struct mlme_ext_priv *mlmeext;
1002 	struct btc_wifi_link_info *wifi_link_info;
1003 	u8 bSoftApExist, bVwifiExist;
1004 	u8 *pu8;
1005 	s32 *pS4Tmp;
1006 	u32 *pU4Tmp;
1007 	u8 *pU1Tmp;
1008 	u16 *pU2Tmp;
1009 	u8 ret;
1010 
1011 
1012 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1013 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1014 		return _FALSE;
1015 
1016 	padapter = pBtCoexist->Adapter;
1017 	pHalData = GET_HAL_DATA(padapter);
1018 	mlmeext = &padapter->mlmeextpriv;
1019 	bSoftApExist = _FALSE;
1020 	bVwifiExist = _FALSE;
1021 	pu8 = (u8 *)pOutBuf;
1022 	pS4Tmp = (s32 *)pOutBuf;
1023 	pU4Tmp = (u32 *)pOutBuf;
1024 	pU1Tmp = (u8 *)pOutBuf;
1025 	pU2Tmp = (u16*)pOutBuf;
1026 	wifi_link_info = (struct btc_wifi_link_info *)pOutBuf;
1027 	ret = _TRUE;
1028 
1029 	switch (getType) {
1030 	case BTC_GET_BL_HS_OPERATION:
1031 		*pu8 = _FALSE;
1032 		ret = _FALSE;
1033 		break;
1034 
1035 	case BTC_GET_BL_HS_CONNECTING:
1036 		*pu8 = _FALSE;
1037 		ret = _FALSE;
1038 		break;
1039 
1040 	case BTC_GET_BL_WIFI_FW_READY:
1041 		*pu8 = halbtcoutsrc_is_fw_ready(pBtCoexist);
1042 		break;
1043 
1044 	case BTC_GET_BL_WIFI_CONNECTED:
1045 		*pu8 = (rtw_mi_check_status(padapter, MI_LINKED)) ? _TRUE : _FALSE;
1046 		break;
1047 
1048 	case BTC_GET_BL_WIFI_DUAL_BAND_CONNECTED:
1049 		*pu8 = halbtcoutsrc_IsDualBandConnected(padapter);
1050 		break;
1051 
1052 	case BTC_GET_BL_WIFI_BUSY:
1053 		*pu8 = halbtcoutsrc_IsWifiBusy(padapter);
1054 		break;
1055 
1056 	case BTC_GET_BL_WIFI_SCAN:
1057 #if 0
1058 		*pu8 = (rtw_mi_check_fwstate(padapter, WIFI_SITE_MONITOR)) ? _TRUE : _FALSE;
1059 #else
1060 		/* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
1061 			WIFI_SITE_MONITOR in fwstate may not be cleared in time */
1062 		*pu8 = GLBtcWiFiInScanState;
1063 #endif
1064 		break;
1065 
1066 	case BTC_GET_BL_WIFI_LINK:
1067 		*pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
1068 		break;
1069 
1070 	case BTC_GET_BL_WIFI_ROAM:
1071 		*pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
1072 		break;
1073 
1074 	case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
1075 		*pu8 = _FALSE;
1076 		break;
1077 
1078 	case BTC_GET_BL_WIFI_UNDER_5G:
1079 		*pu8 = (pHalData->current_band_type == BAND_ON_5G) ? _TRUE : _FALSE;
1080 		break;
1081 
1082 	case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
1083 		*pu8 = (rtw_mi_check_status(padapter, MI_AP_MODE)) ? _TRUE : _FALSE;
1084 		break;
1085 
1086 	case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
1087 		*pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? _FALSE : _TRUE;
1088 		break;
1089 
1090 	case BTC_GET_BL_WIFI_UNDER_B_MODE:
1091 		if (mlmeext->cur_wireless_mode == WIRELESS_11B)
1092 			*pu8 = _TRUE;
1093 		else
1094 			*pu8 = _FALSE;
1095 		break;
1096 
1097 	case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
1098 		if (padapter->registrypriv.mp_mode == 0)
1099 			*pu8 = _FALSE;
1100 		else
1101 			*pu8 = _TRUE;
1102 		break;
1103 
1104 	case BTC_GET_BL_EXT_SWITCH:
1105 		*pu8 = _FALSE;
1106 		break;
1107 	case BTC_GET_BL_IS_ASUS_8723B:
1108 		/* Always return FALSE in linux driver since this case is added only for windows driver */
1109 		*pu8 = _FALSE;
1110 		break;
1111 
1112 	case BTC_GET_BL_RF4CE_CONNECTED:
1113 #ifdef CONFIG_RF4CE_COEXIST
1114 		if (hal_btcoex_get_rf4ce_link_state() == 0)
1115 			*pu8 = FALSE;
1116 		else
1117 			*pu8 = TRUE;
1118 #else
1119 		*pu8 = FALSE;
1120 #endif
1121 		break;
1122 
1123 	case BTC_GET_BL_WIFI_LW_PWR_STATE:
1124 		/* return false due to coex do not run during 32K */
1125 		*pu8 = FALSE;
1126 		break;
1127 
1128 	case BTC_GET_S4_WIFI_RSSI:
1129 		*pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
1130 		break;
1131 
1132 	case BTC_GET_S4_HS_RSSI:
1133 		*pS4Tmp = 0;
1134 		ret = _FALSE;
1135 		break;
1136 
1137 	case BTC_GET_U4_WIFI_BW:
1138 		if (IsLegacyOnly(mlmeext->cur_wireless_mode))
1139 			*pU4Tmp = BTC_WIFI_BW_LEGACY;
1140 		else {
1141 			switch (pHalData->current_channel_bw) {
1142 			case CHANNEL_WIDTH_20:
1143 				*pU4Tmp = BTC_WIFI_BW_HT20;
1144 				break;
1145 			case CHANNEL_WIDTH_40:
1146 				*pU4Tmp = BTC_WIFI_BW_HT40;
1147 				break;
1148 			case CHANNEL_WIDTH_80:
1149 				*pU4Tmp = BTC_WIFI_BW_HT80;
1150 				break;
1151 			case CHANNEL_WIDTH_160:
1152 				*pU4Tmp = BTC_WIFI_BW_HT160;
1153 				break;
1154 			default:
1155 				RTW_INFO("[BTCOEX] unknown bandwidth(%d)\n", pHalData->current_channel_bw);
1156 				*pU4Tmp = BTC_WIFI_BW_HT40;
1157 				break;
1158 			}
1159 
1160 		}
1161 		break;
1162 
1163 	case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: {
1164 		PRT_LINK_DETECT_T plinkinfo;
1165 		plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
1166 
1167 		if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
1168 			*pU4Tmp = BTC_WIFI_TRAFFIC_TX;
1169 		else
1170 			*pU4Tmp = BTC_WIFI_TRAFFIC_RX;
1171 	}
1172 		break;
1173 
1174 	case BTC_GET_U4_WIFI_FW_VER:
1175 		*pU4Tmp = pHalData->firmware_version << 16;
1176 		*pU4Tmp |= pHalData->firmware_sub_version;
1177 		break;
1178 
1179 	case BTC_GET_U4_WIFI_LINK_STATUS:
1180 		*pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
1181 		break;
1182 	case BTC_GET_BL_WIFI_LINK_INFO:
1183 		*wifi_link_info = halbtcoutsrc_getwifilinkinfo(pBtCoexist);
1184 		break;
1185 	case BTC_GET_U4_BT_PATCH_VER:
1186 		*pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
1187 		break;
1188 
1189 	case BTC_GET_U4_VENDOR:
1190 		*pU4Tmp = BTC_VENDOR_OTHER;
1191 		break;
1192 
1193 	case BTC_GET_U4_SUPPORTED_VERSION:
1194 		*pU4Tmp = halbtcoutsrc_GetBtCoexSupportedVersion(pBtCoexist);
1195 		break;
1196 	case BTC_GET_U4_SUPPORTED_FEATURE:
1197 		*pU4Tmp = halbtcoutsrc_GetBtCoexSupportedFeature(pBtCoexist);
1198 		break;
1199 
1200 	case BTC_GET_U4_BT_DEVICE_INFO:
1201 		*pU4Tmp = halbtcoutsrc_GetBtDeviceInfo(pBtCoexist);
1202 		break;
1203 
1204 	case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL:
1205 		*pU4Tmp = halbtcoutsrc_GetBtForbiddenSlotVal(pBtCoexist);
1206 		break;
1207 
1208 	case BTC_GET_U4_WIFI_IQK_TOTAL:
1209 		*pU4Tmp = pHalData->odmpriv.n_iqk_cnt;
1210 		break;
1211 
1212 	case BTC_GET_U4_WIFI_IQK_OK:
1213 		*pU4Tmp = pHalData->odmpriv.n_iqk_ok_cnt;
1214 		break;
1215 
1216 	case BTC_GET_U4_WIFI_IQK_FAIL:
1217 		*pU4Tmp = pHalData->odmpriv.n_iqk_fail_cnt;
1218 		break;
1219 
1220 	case BTC_GET_U1_WIFI_DOT11_CHNL:
1221 		*pU1Tmp = padapter->mlmeextpriv.cur_channel;
1222 		break;
1223 
1224 	case BTC_GET_U1_WIFI_CENTRAL_CHNL:
1225 		*pU1Tmp = pHalData->current_channel;
1226 		break;
1227 
1228 	case BTC_GET_U1_WIFI_HS_CHNL:
1229 		*pU1Tmp = 0;
1230 		ret = _FALSE;
1231 		break;
1232 
1233 	case BTC_GET_U1_WIFI_P2P_CHNL:
1234 #ifdef CONFIG_P2P
1235 		{
1236 			struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1237 
1238 			*pU1Tmp = pwdinfo->operating_channel;
1239 		}
1240 #else
1241 		*pU1Tmp = 0;
1242 #endif
1243 		break;
1244 
1245 	case BTC_GET_U1_MAC_PHY_MODE:
1246 		/*			*pU1Tmp = BTC_SMSP;
1247 		 *			*pU1Tmp = BTC_DMSP;
1248 		 *			*pU1Tmp = BTC_DMDP;
1249 		 *			*pU1Tmp = BTC_MP_UNKNOWN; */
1250 		break;
1251 
1252 	case BTC_GET_U1_AP_NUM:
1253 		*pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
1254 		break;
1255 	case BTC_GET_U1_ANT_TYPE:
1256 		switch (pHalData->bt_coexist.btAntisolation) {
1257 		case 0:
1258 			*pU1Tmp = (u8)BTC_ANT_TYPE_0;
1259 			pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_0;
1260 			break;
1261 		case 1:
1262 			*pU1Tmp = (u8)BTC_ANT_TYPE_1;
1263 			pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_1;
1264 			break;
1265 		case 2:
1266 			*pU1Tmp = (u8)BTC_ANT_TYPE_2;
1267 			pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_2;
1268 			break;
1269 		case 3:
1270 			*pU1Tmp = (u8)BTC_ANT_TYPE_3;
1271 			pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_3;
1272 			break;
1273 		case 4:
1274 			*pU1Tmp = (u8)BTC_ANT_TYPE_4;
1275 			pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_4;
1276 			break;
1277 		}
1278 		break;
1279 	case BTC_GET_U1_IOT_PEER:
1280 		*pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;
1281 		break;
1282 
1283 	/* =======1Ant=========== */
1284 	case BTC_GET_U1_LPS_MODE:
1285 		*pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
1286 		break;
1287 
1288 	case BTC_GET_U2_BEACON_PERIOD:
1289 		*pU2Tmp = mlmeext->mlmext_info.bcn_interval;
1290 		break;
1291 
1292 	default:
1293 		ret = _FALSE;
1294 		break;
1295 	}
1296 
1297 	return ret;
1298 }
1299 
halbtcoutsrc_LnaConstrainLvl(void * pBtcContext,u8 * lna_constrain_level)1300 u16 halbtcoutsrc_LnaConstrainLvl(void *pBtcContext, u8 *lna_constrain_level)
1301 {
1302 	PBTC_COEXIST pBtCoexist;
1303 	u16 ret = BT_STATUS_BT_OP_SUCCESS;
1304 
1305 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1306 
1307 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1308 		_irqL irqL;
1309 		u8 op_code;
1310 
1311 		_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1312 
1313 		ret = _btmpoper_cmd(pBtCoexist, BT_OP_SET_BT_LANCONSTRAIN_LEVEL, 0, lna_constrain_level, 1);
1314 
1315 		_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1316 	} else {
1317 		ret = BT_STATUS_NOT_IMPLEMENT;
1318 		RTW_INFO("%s halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == FALSE\n", __func__);
1319 	}
1320 
1321 	return ret;
1322 }
1323 
halbtcoutsrc_Set(void * pBtcContext,u8 setType,void * pInBuf)1324 u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
1325 {
1326 	PBTC_COEXIST pBtCoexist;
1327 	PADAPTER padapter;
1328 	PHAL_DATA_TYPE pHalData;
1329 	u8 *pu8;
1330 	u8 *pU1Tmp;
1331 	u32	*pU4Tmp;
1332 	u8 ret;
1333 	u8 result = _TRUE;
1334 
1335 
1336 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1337 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1338 		return _FALSE;
1339 
1340 	padapter = pBtCoexist->Adapter;
1341 	pHalData = GET_HAL_DATA(padapter);
1342 	pu8 = (u8 *)pInBuf;
1343 	pU1Tmp = (u8 *)pInBuf;
1344 	pU4Tmp = (u32 *)pInBuf;
1345 	ret = _TRUE;
1346 
1347 	switch (setType) {
1348 	/* set some u8 type variables. */
1349 	case BTC_SET_BL_BT_DISABLE:
1350 		pBtCoexist->bt_info.bt_disabled = *pu8;
1351 		break;
1352 
1353 	case BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE:
1354 		pBtCoexist->bt_info.bt_enable_disable_change = *pu8;
1355 		break;
1356 
1357 	case BTC_SET_BL_BT_TRAFFIC_BUSY:
1358 		pBtCoexist->bt_info.bt_busy = *pu8;
1359 		break;
1360 
1361 	case BTC_SET_BL_BT_LIMITED_DIG:
1362 		pBtCoexist->bt_info.limited_dig = *pu8;
1363 		break;
1364 
1365 	case BTC_SET_BL_FORCE_TO_ROAM:
1366 		pBtCoexist->bt_info.force_to_roam = *pu8;
1367 		break;
1368 
1369 	case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
1370 		pBtCoexist->bt_info.reject_agg_pkt = *pu8;
1371 		break;
1372 
1373 	case BTC_SET_BL_BT_CTRL_AGG_SIZE:
1374 		pBtCoexist->bt_info.bt_ctrl_agg_buf_size = *pu8;
1375 		break;
1376 
1377 	case BTC_SET_BL_INC_SCAN_DEV_NUM:
1378 		pBtCoexist->bt_info.increase_scan_dev_num = *pu8;
1379 		break;
1380 
1381 	case BTC_SET_BL_BT_TX_RX_MASK:
1382 		pBtCoexist->bt_info.bt_tx_rx_mask = *pu8;
1383 		break;
1384 
1385 	case BTC_SET_BL_MIRACAST_PLUS_BT:
1386 		pBtCoexist->bt_info.miracast_plus_bt = *pu8;
1387 		break;
1388 
1389 	/* set some u8 type variables. */
1390 	case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
1391 		pBtCoexist->bt_info.rssi_adjust_for_agc_table_on = *pU1Tmp;
1392 		break;
1393 
1394 	case BTC_SET_U1_AGG_BUF_SIZE:
1395 		pBtCoexist->bt_info.agg_buf_size = *pU1Tmp;
1396 		break;
1397 
1398 	/* the following are some action which will be triggered */
1399 	case BTC_SET_ACT_GET_BT_RSSI:
1400 #if 0
1401 		BT_SendGetBtRssiEvent(padapter);
1402 #else
1403 		ret = _FALSE;
1404 #endif
1405 		break;
1406 
1407 	case BTC_SET_ACT_AGGREGATE_CTRL:
1408 		halbtcoutsrc_AggregationCheck(pBtCoexist);
1409 		break;
1410 
1411 	/* =======1Ant=========== */
1412 	/* set some u8 type variables. */
1413 	case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
1414 		pBtCoexist->bt_info.rssi_adjust_for_1ant_coex_type = *pU1Tmp;
1415 		break;
1416 
1417 	case BTC_SET_U1_LPS_VAL:
1418 		pBtCoexist->bt_info.lps_val = *pU1Tmp;
1419 		break;
1420 
1421 	case BTC_SET_U1_RPWM_VAL:
1422 		pBtCoexist->bt_info.rpwm_val = *pU1Tmp;
1423 		break;
1424 
1425 	/* the following are some action which will be triggered */
1426 	case BTC_SET_ACT_LEAVE_LPS:
1427 		result = halbtcoutsrc_LeaveLps(pBtCoexist);
1428 		break;
1429 
1430 	case BTC_SET_ACT_ENTER_LPS:
1431 		halbtcoutsrc_EnterLps(pBtCoexist);
1432 		break;
1433 
1434 	case BTC_SET_ACT_NORMAL_LPS:
1435 		halbtcoutsrc_NormalLps(pBtCoexist);
1436 		break;
1437 
1438 	case BTC_SET_ACT_PRE_NORMAL_LPS:
1439 		halbtcoutsrc_Pre_NormalLps(pBtCoexist);
1440 		break;
1441 
1442 	case BTC_SET_ACT_POST_NORMAL_LPS:
1443 		halbtcoutsrc_Post_NormalLps(pBtCoexist);
1444 		break;
1445 
1446 	case BTC_SET_ACT_DISABLE_LOW_POWER:
1447 		halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
1448 		break;
1449 
1450 	case BTC_SET_ACT_UPDATE_RAMASK:
1451 		/*
1452 		pBtCoexist->bt_info.ra_mask = *pU4Tmp;
1453 
1454 		if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE) {
1455 			struct sta_info *psta;
1456 			PWLAN_BSSID_EX cur_network;
1457 
1458 			cur_network = &padapter->mlmeextpriv.mlmext_info.network;
1459 			psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
1460 			rtw_hal_update_ra_mask(psta);
1461 		}
1462 		*/
1463 		break;
1464 
1465 	case BTC_SET_ACT_SEND_MIMO_PS: {
1466 		u8 newMimoPsMode = 3;
1467 		struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1468 		struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1469 
1470 		/* *pU1Tmp = 0 use SM_PS static type */
1471 		/* *pU1Tmp = 1 disable SM_PS */
1472 		if (*pU1Tmp == 0)
1473 			newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
1474 		else if (*pU1Tmp == 1)
1475 			newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
1476 
1477 		if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) {
1478 			/* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */
1479 			issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1);
1480 		}
1481 	}
1482 	break;
1483 
1484 	case BTC_SET_ACT_CTRL_BT_INFO:
1485 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1486 		{
1487 			u8 dataLen = *pU1Tmp;
1488 			u8 tmpBuf[BTC_TMP_BUF_SHORT];
1489 			if (dataLen)
1490 				_rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
1491 			BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
1492 		}
1493 #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
1494 		ret = _FALSE;
1495 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
1496 		break;
1497 
1498 	case BTC_SET_ACT_CTRL_BT_COEX:
1499 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1500 		{
1501 			u8 dataLen = *pU1Tmp;
1502 			u8 tmpBuf[BTC_TMP_BUF_SHORT];
1503 			if (dataLen)
1504 				_rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
1505 			BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
1506 		}
1507 #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
1508 		ret = _FALSE;
1509 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
1510 		break;
1511 	case BTC_SET_ACT_CTRL_8723B_ANT:
1512 #if 0
1513 		{
1514 			u8	dataLen = *pU1Tmp;
1515 			u8	tmpBuf[BTC_TMP_BUF_SHORT];
1516 			if (dataLen)
1517 				PlatformMoveMemory(&tmpBuf[0], pU1Tmp + 1, dataLen);
1518 			BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
1519 		}
1520 #else
1521 		ret = _FALSE;
1522 #endif
1523 		break;
1524 	case BTC_SET_BL_BT_LNA_CONSTRAIN_LEVEL:
1525 		halbtcoutsrc_LnaConstrainLvl(pBtCoexist, pu8);
1526 		break;
1527 	/* ===================== */
1528 	default:
1529 		ret = _FALSE;
1530 		break;
1531 	}
1532 
1533 	return result;
1534 }
1535 
halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)1536 u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
1537 {
1538 	PADAPTER padapter;
1539 	struct pwrctrl_priv *pwrpriv;
1540 	u8 bMacPwrCtrlOn;
1541 
1542 	padapter = pBtCoexist->Adapter;
1543 	pwrpriv = &padapter->dvobj->pwrctl_priv;
1544 	bMacPwrCtrlOn = _FALSE;
1545 
1546 	if ((_TRUE == pwrpriv->bips_processing)
1547 	    && (IPS_NONE != pwrpriv->ips_mode_req)
1548 	   )
1549 		return _TRUE;
1550 
1551 	if (rf_off == pwrpriv->rf_pwrstate)
1552 		return _TRUE;
1553 
1554 	rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
1555 	if (_FALSE == bMacPwrCtrlOn)
1556 		return _TRUE;
1557 
1558 	return _FALSE;
1559 }
1560 
halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)1561 u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
1562 {
1563 	return GLBtcWiFiInLPS;
1564 }
1565 
halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)1566 u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
1567 {
1568 	/* todo: the method to check whether wifi is under 32K or not */
1569 	return _FALSE;
1570 }
1571 
halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)1572 void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
1573 {
1574 #if 0
1575 	PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1576 	PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1577 	PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
1578 	u8 *cliBuf = pBtCoexist->cliBuf;
1579 	u8			i, j;
1580 	u8			tmpbuf[BTC_TMP_BUF_SHORT];
1581 
1582 
1583 	if (gl_coex_offload.cnt_h2c_sent) {
1584 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex h2c notify]============");
1585 		CL_PRINTF(cliBuf);
1586 
1587 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = H2c(%d)/Ack(%d)", "Coex h2c/c2h overall statistics",
1588 			gl_coex_offload.cnt_h2c_sent, gl_coex_offload.cnt_c2h_ack);
1589 		for (j = 0; j < COL_STATUS_MAX; j++) {
1590 			if (gl_coex_offload.status[j]) {
1591 				CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.status[j]);
1592 				CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1593 			}
1594 		}
1595 		CL_PRINTF(cliBuf);
1596 	}
1597 	for (i = 0; i < COL_OP_WIFI_OPCODE_MAX; i++) {
1598 		if (gl_coex_offload.h2c_record[i].count) {
1599 			/*==========================================*/
1600 			/*	H2C result statistics*/
1601 			/*==========================================*/
1602 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexOpcodeString[i], gl_coex_offload.h2c_record[i].count);
1603 			for (j = 0; j < COL_STATUS_MAX; j++) {
1604 				if (gl_coex_offload.h2c_record[i].status[j]) {
1605 					CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.h2c_record[i].status[j]);
1606 					CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1607 				}
1608 			}
1609 			CL_PRINTF(cliBuf);
1610 			/*==========================================*/
1611 			/*	H2C/C2H content*/
1612 			/*==========================================*/
1613 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "H2C / C2H content");
1614 			for (j = 0; j < gl_coex_offload.h2c_record[i].h2c_len; j++) {
1615 				CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].h2c_buf[j]);
1616 				CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
1617 			}
1618 			if (gl_coex_offload.h2c_record[i].c2h_ack_len) {
1619 				CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, "/ ", 2);
1620 				for (j = 0; j < gl_coex_offload.h2c_record[i].c2h_ack_len; j++) {
1621 					CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].c2h_ack_buf[j]);
1622 					CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
1623 				}
1624 			}
1625 			CL_PRINTF(cliBuf);
1626 			/*==========================================*/
1627 		}
1628 	}
1629 
1630 	if (gl_coex_offload.cnt_c2h_ind) {
1631 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex c2h indication]============");
1632 		CL_PRINTF(cliBuf);
1633 
1634 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = Ind(%d)", "C2H indication statistics",
1635 			   gl_coex_offload.cnt_c2h_ind);
1636 		for (j = 0; j < COL_STATUS_MAX; j++) {
1637 			if (gl_coex_offload.c2h_ind_status[j]) {
1638 				CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_status[j]);
1639 				CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1640 			}
1641 		}
1642 		CL_PRINTF(cliBuf);
1643 	}
1644 	for (i = 0; i < COL_IND_MAX; i++) {
1645 		if (gl_coex_offload.c2h_ind_record[i].count) {
1646 			/*==========================================*/
1647 			/*	H2C result statistics*/
1648 			/*==========================================*/
1649 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexIndTypeString[i], gl_coex_offload.c2h_ind_record[i].count);
1650 			for (j = 0; j < COL_STATUS_MAX; j++) {
1651 				if (gl_coex_offload.c2h_ind_record[i].status[j]) {
1652 					CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_record[i].status[j]);
1653 					CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1654 				}
1655 			}
1656 			CL_PRINTF(cliBuf);
1657 			/*==========================================*/
1658 			/*	content*/
1659 			/*==========================================*/
1660 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "C2H indication content");
1661 			for (j = 0; j < gl_coex_offload.c2h_ind_record[i].ind_len; j++) {
1662 				CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.c2h_ind_record[i].ind_buf[j]);
1663 				CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
1664 			}
1665 			CL_PRINTF(cliBuf);
1666 			/*==========================================*/
1667 		}
1668 	}
1669 
1670 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
1671 	CL_PRINTF(cliBuf);
1672 
1673 #if (H2C_USE_IO_THREAD != 1)
1674 	for (i = 0; i < H2C_STATUS_MAX; i++) {
1675 		if (pHalData->h2cStatistics[i]) {
1676 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1677 				   h2cStaString[i], pHalData->h2cStatistics[i]);
1678 			CL_PRINTF(cliBuf);
1679 		}
1680 	}
1681 #else
1682 	for (i = 0; i < IO_STATUS_MAX; i++) {
1683 		if (Adapter->ioComStr.ioH2cStatistics[i]) {
1684 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1685 				ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);
1686 			CL_PRINTF(cliBuf);
1687 		}
1688 	}
1689 #endif
1690 #if 0
1691 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
1692 		   pHalData->LastHMEBoxNum);
1693 	CL_PRINTF(cliBuf);
1694 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
1695 		   pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
1696 	CL_PRINTF(cliBuf);
1697 
1698 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \
1699 		pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,
1700 		   DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);
1701 	CL_PRINTF(cliBuf);
1702 
1703 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
1704 		   DBG_Var.c2hPacketCnt);
1705 	CL_PRINTF(cliBuf);
1706 #endif
1707 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
1708 		pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
1709 	CL_PRINTF(cliBuf);
1710 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \
1711 		pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,
1712 		   pBtCoexist->statistics.cntRfStatusNotify);
1713 	CL_PRINTF(cliBuf);
1714 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \
1715 		pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,
1716 		pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,
1717 		   pBtCoexist->statistics.cntMediaStatusNotify);
1718 	CL_PRINTF(cliBuf);
1719 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind",
1720 		pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify,
1721 		   pBtCoexist->statistics.cntBind);
1722 	CL_PRINTF(cliBuf);
1723 #endif
1724 	PADAPTER		padapter = pBtCoexist->Adapter;
1725 	PHAL_DATA_TYPE	pHalData = GET_HAL_DATA(padapter);
1726 	u8				*cliBuf = pBtCoexist->cli_buf;
1727 
1728 	if (pHalData->EEPROMBluetoothCoexist == 1) {
1729 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex Status]============");
1730 		CL_PRINTF(cliBuf);
1731 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtDisabled", rtw_btcoex_IsBtDisabled(padapter));
1732 		CL_PRINTF(cliBuf);
1733 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtControlLps", rtw_btcoex_IsBtControlLps(padapter));
1734 		CL_PRINTF(cliBuf);
1735 	}
1736 }
1737 
halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)1738 void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
1739 {
1740 #if 0
1741 	PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1742 	PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1743 	u8 *cliBuf = pBtCoexist->cliBuf;
1744 	u8 i;
1745 
1746 
1747 	if (pBtCoexist->stack_info.profile_notified) {
1748 		for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {
1749 			if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
1750 				CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \
1751 					BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1752 					BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],
1753 					BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);
1754 				CL_PRINTF(cliBuf);
1755 			} else {
1756 				CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
1757 					BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1758 					BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);
1759 				CL_PRINTF(cliBuf);
1760 			}
1761 		}
1762 	}
1763 #endif
1764 }
1765 
halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)1766 void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
1767 {
1768 	PADAPTER	padapter = pBtCoexist->Adapter;
1769 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1770 	u8			*cliBuf = pBtCoexist->cli_buf;
1771 	s32			wifiRssi = 0, btHsRssi = 0;
1772 	BOOLEAN	bScan = _FALSE, bLink = _FALSE, bRoam = _FALSE, bWifiBusy = _FALSE, bWifiUnderBMode = _FALSE;
1773 	u32			wifiBw = BTC_WIFI_BW_HT20, wifiTrafficDir = BTC_WIFI_TRAFFIC_TX, wifiFreq = BTC_FREQ_2_4G;
1774 	u32			wifiLinkStatus = 0x0;
1775 	BOOLEAN	bBtHsOn = _FALSE, bLowPower = _FALSE;
1776 	u8			wifiChnl = 0, wifiP2PChnl = 0, nScanAPNum = 0, FwPSState;
1777 	u32			iqk_cnt_total = 0, iqk_cnt_ok = 0, iqk_cnt_fail = 0;
1778 	u16			wifiBcnInterval = 0;
1779 	PHAL_DATA_TYPE hal = GET_HAL_DATA(padapter);
1780 	struct btc_wifi_link_info wifi_link_info;
1781 
1782 	wifi_link_info = halbtcoutsrc_getwifilinkinfo(pBtCoexist);
1783 
1784 	switch (wifi_link_info.link_mode) {
1785 		case BTC_LINK_NONE:
1786 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1787 					"None", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1788 			wifiFreq = hal->current_channel > 14 ?  BTC_FREQ_5G : BTC_FREQ_2_4G;
1789 			break;
1790 		case BTC_LINK_ONLY_GO:
1791 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1792 					"ONLY_GO", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1793 			wifiFreq = hal->current_channel > 14 ?  BTC_FREQ_5G : BTC_FREQ_2_4G;
1794 			break;
1795 		case BTC_LINK_ONLY_GC:
1796 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1797 					"ONLY_GC", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1798 			wifiFreq = hal->current_channel > 14 ?  BTC_FREQ_5G : BTC_FREQ_2_4G;
1799 			break;
1800 		case BTC_LINK_ONLY_STA:
1801 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1802 					"ONLY_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1803 			wifiFreq = hal->current_channel > 14 ?  BTC_FREQ_5G : BTC_FREQ_2_4G;
1804 			break;
1805 		case BTC_LINK_ONLY_AP:
1806 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1807 					"ONLY_AP", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1808 			wifiFreq = hal->current_channel > 14 ?  BTC_FREQ_5G : BTC_FREQ_2_4G;
1809 			break;
1810 		case BTC_LINK_2G_MCC_GO_STA:
1811 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1812 					"24G_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1813 			wifiFreq = BTC_FREQ_2_4G;
1814 			break;
1815 		case BTC_LINK_5G_MCC_GO_STA:
1816 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1817 					"5G_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1818 			wifiFreq = BTC_FREQ_5G;
1819 			break;
1820 		case BTC_LINK_25G_MCC_GO_STA:
1821 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1822 					"2BANDS_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1823 			wifiFreq = BTC_FREQ_25G;
1824 			break;
1825 		case BTC_LINK_2G_MCC_GC_STA:
1826 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1827 					"24G_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1828 			wifiFreq = BTC_FREQ_2_4G;
1829 			break;
1830 		case BTC_LINK_5G_MCC_GC_STA:
1831 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1832 					"5G_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1833 			wifiFreq = BTC_FREQ_5G;
1834 			break;
1835 		case BTC_LINK_25G_MCC_GC_STA:
1836 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1837 					"2BANDS_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1838 			wifiFreq = BTC_FREQ_25G;
1839 			break;
1840 		case BTC_LINK_2G_SCC_GO_STA:
1841 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1842 					"24G_SCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1843 			wifiFreq = BTC_FREQ_2_4G;
1844 			break;
1845 		case BTC_LINK_5G_SCC_GO_STA:
1846 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1847 					"5G_SCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1848 			wifiFreq = BTC_FREQ_5G;
1849 			break;
1850 		case BTC_LINK_2G_SCC_GC_STA:
1851 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1852 					"24G_SCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1853 			wifiFreq = BTC_FREQ_2_4G;
1854 			break;
1855 		case BTC_LINK_5G_SCC_GC_STA:
1856 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1857 					"5G_SCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1858 			wifiFreq = BTC_FREQ_5G;
1859 			break;
1860 		default:
1861 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
1862 					"UNKNOWN", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
1863 			wifiFreq = hal->current_channel > 14 ?  BTC_FREQ_5G : BTC_FREQ_2_4G;
1864 			break;
1865 	}
1866 
1867 	CL_PRINTF(cliBuf);
1868 
1869 	wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
1870 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc",
1871 		((wifiLinkStatus & WIFI_STA_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_AP_CONNECTED) ? 1 : 0),
1872 		((wifiLinkStatus & WIFI_HS_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
1873 		((wifiLinkStatus & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
1874 	CL_PRINTF(cliBuf);
1875 
1876 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1877 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1878 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1879 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Link/ Roam/ Scan",
1880 		bLink, bRoam, bScan);
1881 	CL_PRINTF(cliBuf);
1882 
1883 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_TOTAL, &iqk_cnt_total);
1884 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_OK, &iqk_cnt_ok);
1885 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_FAIL, &iqk_cnt_fail);
1886 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d %s %s",
1887 		"IQK All/ OK/ Fail/AutoLoad/FWDL", iqk_cnt_total, iqk_cnt_ok, iqk_cnt_fail,
1888 		((halbtcoutsrc_is_autoload_fail(pBtCoexist) == _TRUE) ? "fail":"ok"), ((halbtcoutsrc_is_fw_ready(pBtCoexist) == _TRUE) ? "ok":"fail"));
1889 	CL_PRINTF(cliBuf);
1890 
1891 	if (wifiLinkStatus & WIFI_STA_CONNECTED) {
1892 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "IOT Peer", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor]);
1893 		CL_PRINTF(cliBuf);
1894 	}
1895 
1896 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
1897 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_U2_BEACON_PERIOD, &wifiBcnInterval);
1898 	wifiChnl = wifi_link_info.sta_center_channel;
1899 	wifiP2PChnl = wifi_link_info.p2p_center_channel;
1900 
1901 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dBm/ %d/ %d/ %d", "RSSI/ STA_Chnl/ P2P_Chnl/ BI",
1902 		wifiRssi-100, wifiChnl, wifiP2PChnl, wifiBcnInterval);
1903 	CL_PRINTF(cliBuf);
1904 
1905 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1906 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1907 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1908 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
1909 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);
1910 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ %d ", "Band/ BW/ Traffic/ APCnt",
1911 		GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode) ? "11b" : GLBtcWifiBwString[wifiBw]),
1912 		((!bWifiBusy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX == wifiTrafficDir) ? "uplink" : "downlink")),
1913 		   nScanAPNum);
1914 	CL_PRINTF(cliBuf);
1915 
1916 	/* power status */
1917 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \
1918 		((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE) ? "IPS ON" : "IPS OFF"),
1919 		((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE) ? ", LPS ON" : ", LPS OFF"),
1920 		((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE) ? ", 32k" : ""));
1921 	CL_PRINTF(cliBuf);
1922 
1923 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)", "Power mode cmd(lps/rpwm)",
1924 		   pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
1925 		   pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
1926 		   pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],
1927 		   pBtCoexist->bt_info.lps_val,
1928 		   pBtCoexist->bt_info.rpwm_val);
1929 	CL_PRINTF(cliBuf);
1930 }
1931 
halbtcoutsrc_DisplayDbgMsg(void * pBtcContext,u8 dispType)1932 void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
1933 {
1934 	PBTC_COEXIST pBtCoexist;
1935 
1936 
1937 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1938 	switch (dispType) {
1939 	case BTC_DBG_DISP_COEX_STATISTICS:
1940 		halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
1941 		break;
1942 	case BTC_DBG_DISP_BT_LINK_INFO:
1943 		halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
1944 		break;
1945 	case BTC_DBG_DISP_WIFI_STATUS:
1946 		halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
1947 		break;
1948 	default:
1949 		break;
1950 	}
1951 }
1952 
1953 /* ************************************
1954  *		IO related function
1955  * ************************************ */
halbtcoutsrc_Read1Byte(void * pBtcContext,u32 RegAddr)1956 u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
1957 {
1958 	PBTC_COEXIST pBtCoexist;
1959 	PADAPTER padapter;
1960 
1961 
1962 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1963 	padapter = pBtCoexist->Adapter;
1964 
1965 	return rtw_read8(padapter, RegAddr);
1966 }
1967 
halbtcoutsrc_Read2Byte(void * pBtcContext,u32 RegAddr)1968 u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
1969 {
1970 	PBTC_COEXIST pBtCoexist;
1971 	PADAPTER padapter;
1972 
1973 
1974 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1975 	padapter = pBtCoexist->Adapter;
1976 
1977 	return	rtw_read16(padapter, RegAddr);
1978 }
1979 
halbtcoutsrc_Read4Byte(void * pBtcContext,u32 RegAddr)1980 u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
1981 {
1982 	PBTC_COEXIST pBtCoexist;
1983 	PADAPTER padapter;
1984 
1985 
1986 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1987 	padapter = pBtCoexist->Adapter;
1988 
1989 	return	rtw_read32(padapter, RegAddr);
1990 }
1991 
halbtcoutsrc_Write1Byte(void * pBtcContext,u32 RegAddr,u8 Data)1992 void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1993 {
1994 	PBTC_COEXIST pBtCoexist;
1995 	PADAPTER padapter;
1996 
1997 
1998 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1999 	padapter = pBtCoexist->Adapter;
2000 
2001 	rtw_write8(padapter, RegAddr, Data);
2002 }
2003 
halbtcoutsrc_BitMaskWrite1Byte(void * pBtcContext,u32 regAddr,u8 bitMask,u8 data1b)2004 void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
2005 {
2006 	PBTC_COEXIST pBtCoexist;
2007 	PADAPTER padapter;
2008 	u8 originalValue, bitShift;
2009 	u8 i;
2010 
2011 
2012 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2013 	padapter = pBtCoexist->Adapter;
2014 	originalValue = 0;
2015 	bitShift = 0;
2016 
2017 	if (bitMask != 0xff) {
2018 		originalValue = rtw_read8(padapter, regAddr);
2019 
2020 		for (i = 0; i <= 7; i++) {
2021 			if ((bitMask >> i) & 0x1)
2022 				break;
2023 		}
2024 		bitShift = i;
2025 
2026 		data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
2027 	}
2028 
2029 	rtw_write8(padapter, regAddr, data1b);
2030 }
2031 
halbtcoutsrc_Write2Byte(void * pBtcContext,u32 RegAddr,u16 Data)2032 void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
2033 {
2034 	PBTC_COEXIST pBtCoexist;
2035 	PADAPTER padapter;
2036 
2037 
2038 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2039 	padapter = pBtCoexist->Adapter;
2040 
2041 	rtw_write16(padapter, RegAddr, Data);
2042 }
2043 
halbtcoutsrc_Write4Byte(void * pBtcContext,u32 RegAddr,u32 Data)2044 void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
2045 {
2046 	PBTC_COEXIST pBtCoexist;
2047 	PADAPTER padapter;
2048 
2049 
2050 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2051 	padapter = pBtCoexist->Adapter;
2052 
2053 	rtw_write32(padapter, RegAddr, Data);
2054 }
2055 
halbtcoutsrc_WriteLocalReg1Byte(void * pBtcContext,u32 RegAddr,u8 Data)2056 void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
2057 {
2058 	PBTC_COEXIST		pBtCoexist = (PBTC_COEXIST)pBtcContext;
2059 	PADAPTER			Adapter = pBtCoexist->Adapter;
2060 
2061 	if (BTC_INTF_SDIO == pBtCoexist->chip_interface)
2062 		rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
2063 	else
2064 		rtw_write8(Adapter, RegAddr, Data);
2065 }
2066 
halbtcoutsrc_SetBbReg(void * pBtcContext,u32 RegAddr,u32 BitMask,u32 Data)2067 void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
2068 {
2069 	PBTC_COEXIST pBtCoexist;
2070 	PADAPTER padapter;
2071 
2072 
2073 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2074 	padapter = pBtCoexist->Adapter;
2075 
2076 	phy_set_bb_reg(padapter, RegAddr, BitMask, Data);
2077 }
2078 
2079 
halbtcoutsrc_GetBbReg(void * pBtcContext,u32 RegAddr,u32 BitMask)2080 u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
2081 {
2082 	PBTC_COEXIST pBtCoexist;
2083 	PADAPTER padapter;
2084 
2085 
2086 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2087 	padapter = pBtCoexist->Adapter;
2088 
2089 	return phy_query_bb_reg(padapter, RegAddr, BitMask);
2090 }
2091 
halbtcoutsrc_SetRfReg(void * pBtcContext,enum rf_path eRFPath,u32 RegAddr,u32 BitMask,u32 Data)2092 void halbtcoutsrc_SetRfReg(void *pBtcContext, enum rf_path eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
2093 {
2094 	PBTC_COEXIST pBtCoexist;
2095 	PADAPTER padapter;
2096 
2097 
2098 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2099 	padapter = pBtCoexist->Adapter;
2100 
2101 	phy_set_rf_reg(padapter, eRFPath, RegAddr, BitMask, Data);
2102 }
2103 
halbtcoutsrc_GetRfReg(void * pBtcContext,enum rf_path eRFPath,u32 RegAddr,u32 BitMask)2104 u32 halbtcoutsrc_GetRfReg(void *pBtcContext, enum rf_path eRFPath, u32 RegAddr, u32 BitMask)
2105 {
2106 	PBTC_COEXIST pBtCoexist;
2107 	PADAPTER padapter;
2108 
2109 
2110 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2111 	padapter = pBtCoexist->Adapter;
2112 
2113 	return phy_query_rf_reg(padapter, eRFPath, RegAddr, BitMask);
2114 }
2115 
halbtcoutsrc_SetBtReg(void * pBtcContext,u8 RegType,u32 RegAddr,u32 Data)2116 u16 halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
2117 {
2118 	PBTC_COEXIST pBtCoexist;
2119 	u16 ret = BT_STATUS_BT_OP_SUCCESS;
2120 
2121 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2122 
2123 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2124 		u8 buf[3] = {0};
2125 		_irqL irqL;
2126 		u8 op_code;
2127 		u8 status;
2128 
2129 		_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2130 
2131 		Data = cpu_to_le32(Data);
2132 		op_code = BT_OP_WRITE_REG_VALUE;
2133 		status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Data, 3);
2134 		if (status != BT_STATUS_BT_OP_SUCCESS)
2135 			ret = SET_BT_MP_OPER_RET(op_code, status);
2136 		else {
2137 			buf[0] = RegType;
2138 			*(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
2139 			op_code = BT_OP_WRITE_REG_ADDR;
2140 			status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
2141 			if (status != BT_STATUS_BT_OP_SUCCESS)
2142 				ret = SET_BT_MP_OPER_RET(op_code, status);
2143 		}
2144 
2145 		_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2146 	} else
2147 		ret = BT_STATUS_NOT_IMPLEMENT;
2148 
2149 	return ret;
2150 }
2151 
halbtcoutsrc_SetBtAntDetection(void * pBtcContext,u8 txTime,u8 btChnl)2152 u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)
2153 {
2154 	/* Always return _FALSE since we don't implement this yet */
2155 #if 0
2156 	PBTC_COEXIST		pBtCoexist = (PBTC_COEXIST)pBtcContext;
2157 	PADAPTER			Adapter = pBtCoexist->Adapter;
2158 	u8				btCanTx = 0;
2159 	BOOLEAN			bStatus = FALSE;
2160 
2161 	bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);
2162 	if (bStatus && btCanTx)
2163 		return _TRUE;
2164 	else
2165 		return _FALSE;
2166 #else
2167 	return _FALSE;
2168 #endif
2169 }
2170 
2171 BOOLEAN
halbtcoutsrc_SetBtTRXMASK(void * pBtcContext,u8 bt_trx_mask)2172 halbtcoutsrc_SetBtTRXMASK(
2173 		void			*pBtcContext,
2174 		u8			bt_trx_mask
2175 	)
2176 {
2177 	/* Always return _FALSE since we don't implement this yet */
2178 #if 0
2179 	struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2180 	PADAPTER			Adapter = pBtCoexist->Adapter;
2181 	BOOLEAN				bStatus = FALSE;
2182 	u8				btCanTx = 0;
2183 
2184 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter) || IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)
2185 			|| IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
2186 
2187 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2188 		bStatus = NDBG_SetBtTRXMASK(Adapter, 1, bt_trx_mask, &btCanTx);
2189 	else
2190 		bStatus = NDBG_SetBtTRXMASK(Adapter, 2, bt_trx_mask, &btCanTx);
2191 	}
2192 
2193 
2194 	if (bStatus)
2195 		return TRUE;
2196 	else
2197 		return FALSE;
2198 #else
2199 	return _FALSE;
2200 #endif
2201 }
2202 
halbtcoutsrc_GetBtReg_with_status(void * pBtcContext,u8 RegType,u32 RegAddr,u32 * data)2203 u16 halbtcoutsrc_GetBtReg_with_status(void *pBtcContext, u8 RegType, u32 RegAddr, u32 *data)
2204 {
2205 	PBTC_COEXIST pBtCoexist;
2206 	u16 ret = BT_STATUS_BT_OP_SUCCESS;
2207 
2208 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2209 
2210 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2211 		u8 buf[3] = {0};
2212 		_irqL irqL;
2213 		u8 op_code;
2214 		u8 status;
2215 
2216 		buf[0] = RegType;
2217 		*(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
2218 
2219 		_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2220 
2221 		op_code = BT_OP_READ_REG;
2222 		status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
2223 		if (status == BT_STATUS_BT_OP_SUCCESS)
2224 			*data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
2225 		else
2226 			ret = SET_BT_MP_OPER_RET(op_code, status);
2227 
2228 		_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2229 
2230 	} else
2231 		ret = BT_STATUS_NOT_IMPLEMENT;
2232 
2233 	return ret;
2234 }
2235 
halbtcoutsrc_GetBtReg(void * pBtcContext,u8 RegType,u32 RegAddr)2236 u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
2237 {
2238 	u32 regVal;
2239 
2240 	return (BT_STATUS_BT_OP_SUCCESS == halbtcoutsrc_GetBtReg_with_status(pBtcContext, RegType, RegAddr, &regVal)) ? regVal : 0xffffffff;
2241 }
2242 
halbtcoutsrc_setbttestmode(void * pBtcContext,u8 Type)2243 u16 halbtcoutsrc_setbttestmode(void *pBtcContext, u8 Type)
2244 {
2245 	PBTC_COEXIST pBtCoexist;
2246 	u16 ret = BT_STATUS_BT_OP_SUCCESS;
2247 
2248 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2249 
2250 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2251 		_irqL irqL;
2252 		u8 op_code;
2253 		u8 status;
2254 
2255 		_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2256 
2257 		Type = cpu_to_le32(Type);
2258 		op_code = BT_OP_SET_BT_TEST_MODE_VAL;
2259 		status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Type, 3);
2260 		if (status != BT_STATUS_BT_OP_SUCCESS)
2261 			ret = SET_BT_MP_OPER_RET(op_code, status);
2262 
2263 		_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2264 	} else
2265 		ret = BT_STATUS_NOT_IMPLEMENT;
2266 
2267 	return ret;
2268 
2269 }
2270 
2271 
halbtcoutsrc_FillH2cCmd(void * pBtcContext,u8 elementId,u32 cmdLen,u8 * pCmdBuffer)2272 void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
2273 {
2274 	PBTC_COEXIST pBtCoexist;
2275 	PADAPTER padapter;
2276 
2277 
2278 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2279 	padapter = pBtCoexist->Adapter;
2280 
2281 	rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
2282 }
2283 
halbtcoutsrc_coex_offload_init(void)2284 static void halbtcoutsrc_coex_offload_init(void)
2285 {
2286 	u8	i;
2287 
2288 	gl_coex_offload.h2c_req_num = 0;
2289 	gl_coex_offload.cnt_h2c_sent = 0;
2290 	gl_coex_offload.cnt_c2h_ack = 0;
2291 	gl_coex_offload.cnt_c2h_ind = 0;
2292 
2293 	for (i = 0; i < COL_MAX_H2C_REQ_NUM; i++)
2294 		init_completion(&gl_coex_offload.c2h_event[i]);
2295 }
2296 
halbtcoutsrc_send_h2c(PADAPTER Adapter,PCOL_H2C pcol_h2c,u16 h2c_cmd_len)2297 static COL_H2C_STATUS halbtcoutsrc_send_h2c(PADAPTER Adapter, PCOL_H2C pcol_h2c, u16 h2c_cmd_len)
2298 {
2299 	COL_H2C_STATUS		h2c_status = COL_STATUS_C2H_OK;
2300 	u8				i;
2301 
2302 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
2303 	reinit_completion(&gl_coex_offload.c2h_event[pcol_h2c->req_num]);		/* set event to un signaled state */
2304 #else
2305 	INIT_COMPLETION(gl_coex_offload.c2h_event[pcol_h2c->req_num]);
2306 #endif
2307 
2308 	if (TRUE) {
2309 #if 0	/*(USE_HAL_MAC_API == 1) */
2310 		if (RT_STATUS_SUCCESS == HAL_MAC_Send_BT_COEX(&GET_HAL_MAC_INFO(Adapter), (u8 *)(pcol_h2c), (u32)h2c_cmd_len, 1)) {
2311 			if (!wait_for_completion_timeout(&gl_coex_offload.c2h_event[pcol_h2c->req_num], 20)) {
2312 				h2c_status = COL_STATUS_H2C_TIMTOUT;
2313 			}
2314 		} else {
2315 			h2c_status = COL_STATUS_H2C_HALMAC_FAIL;
2316 		}
2317 #endif
2318 	}
2319 
2320 	return h2c_status;
2321 }
2322 
halbtcoutsrc_check_c2h_ack(PADAPTER Adapter,PCOL_SINGLE_H2C_RECORD pH2cRecord)2323 static COL_H2C_STATUS halbtcoutsrc_check_c2h_ack(PADAPTER Adapter, PCOL_SINGLE_H2C_RECORD pH2cRecord)
2324 {
2325 	COL_H2C_STATUS	c2h_status = COL_STATUS_C2H_OK;
2326 	PCOL_H2C		p_h2c_cmd = (PCOL_H2C)&pH2cRecord->h2c_buf[0];
2327 	u8			req_num = p_h2c_cmd->req_num;
2328 	PCOL_C2H_ACK	p_c2h_ack = (PCOL_C2H_ACK)&gl_coex_offload.c2h_ack_buf[req_num];
2329 
2330 
2331 	if ((COL_C2H_ACK_HDR_LEN + p_c2h_ack->ret_len) > gl_coex_offload.c2h_ack_len[req_num]) {
2332 		c2h_status = COL_STATUS_COEX_DATA_OVERFLOW;
2333 		return c2h_status;
2334 	}
2335 	/* else */
2336 	{
2337 		_rtw_memmove(&pH2cRecord->c2h_ack_buf[0], &gl_coex_offload.c2h_ack_buf[req_num], gl_coex_offload.c2h_ack_len[req_num]);
2338 		pH2cRecord->c2h_ack_len = gl_coex_offload.c2h_ack_len[req_num];
2339 	}
2340 
2341 
2342 	if (p_c2h_ack->req_num != p_h2c_cmd->req_num) {
2343 		c2h_status = COL_STATUS_C2H_REQ_NUM_MISMATCH;
2344 	} else if (p_c2h_ack->opcode_ver != p_h2c_cmd->opcode_ver) {
2345 		c2h_status = COL_STATUS_C2H_OPCODE_VER_MISMATCH;
2346 	} else {
2347 		c2h_status = p_c2h_ack->status;
2348 	}
2349 
2350 	return c2h_status;
2351 }
2352 
halbtcoutsrc_CoexH2cProcess(void * pBtCoexist,u8 opcode,u8 opcode_ver,u8 * ph2c_par,u8 h2c_par_len)2353 COL_H2C_STATUS halbtcoutsrc_CoexH2cProcess(void *pBtCoexist,
2354 		u8 opcode, u8 opcode_ver, u8 *ph2c_par, u8 h2c_par_len)
2355 {
2356 	PADAPTER			Adapter = ((struct btc_coexist *)pBtCoexist)->Adapter;
2357 	u8				H2C_Parameter[BTC_TMP_BUF_SHORT] = {0};
2358 	PCOL_H2C			pcol_h2c = (PCOL_H2C)&H2C_Parameter[0];
2359 	u16				paraLen = 0;
2360 	COL_H2C_STATUS		h2c_status = COL_STATUS_C2H_OK, c2h_status = COL_STATUS_C2H_OK;
2361 	COL_H2C_STATUS		ret_status = COL_STATUS_C2H_OK;
2362 	u16				i, col_h2c_len = 0;
2363 
2364 	pcol_h2c->opcode = opcode;
2365 	pcol_h2c->opcode_ver = opcode_ver;
2366 	pcol_h2c->req_num = gl_coex_offload.h2c_req_num;
2367 	gl_coex_offload.h2c_req_num++;
2368 	gl_coex_offload.h2c_req_num %= 16;
2369 
2370 	_rtw_memmove(&pcol_h2c->buf[0], ph2c_par, h2c_par_len);
2371 
2372 
2373 	col_h2c_len = h2c_par_len + 2;	/* 2=sizeof(OPCode, OPCode_version and  Request number) */
2374 	BT_PrintData(Adapter, "[COL], H2C cmd: ", col_h2c_len, H2C_Parameter);
2375 
2376 	gl_coex_offload.cnt_h2c_sent++;
2377 
2378 	gl_coex_offload.h2c_record[opcode].count++;
2379 	gl_coex_offload.h2c_record[opcode].h2c_len = col_h2c_len;
2380 	_rtw_memmove((void *)&gl_coex_offload.h2c_record[opcode].h2c_buf[0], (void *)pcol_h2c, col_h2c_len);
2381 
2382 	h2c_status = halbtcoutsrc_send_h2c(Adapter, pcol_h2c, col_h2c_len);
2383 
2384 	gl_coex_offload.h2c_record[opcode].c2h_ack_len = 0;
2385 
2386 	if (COL_STATUS_C2H_OK == h2c_status) {
2387 		/* if reach here, it means H2C get the correct c2h response, */
2388 		c2h_status = halbtcoutsrc_check_c2h_ack(Adapter, &gl_coex_offload.h2c_record[opcode]);
2389 		ret_status = c2h_status;
2390 	} else {
2391 		/* check h2c status error, return error status code to upper layer. */
2392 		ret_status = h2c_status;
2393 	}
2394 	gl_coex_offload.h2c_record[opcode].status[ret_status]++;
2395 	gl_coex_offload.status[ret_status]++;
2396 
2397 	return ret_status;
2398 }
2399 
halbtcoutsrc_GetAntDetValFromBt(void * pBtcContext)2400 u8 halbtcoutsrc_GetAntDetValFromBt(void *pBtcContext)
2401 {
2402 	/* Always return 0 since we don't implement this yet */
2403 #if 0
2404 	struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2405 	PADAPTER			Adapter = pBtCoexist->Adapter;
2406 	u8				AntDetVal = 0x0;
2407 	u8				opcodeVer = 1;
2408 	BOOLEAN				status = false;
2409 
2410 	status = NDBG_GetAntDetValFromBt(Adapter, opcodeVer, &AntDetVal);
2411 
2412 	RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$ halbtcoutsrc_GetAntDetValFromBt(): status = %d, feature = %x\n", status, AntDetVal));
2413 
2414 	return AntDetVal;
2415 #else
2416 	return 0;
2417 #endif
2418 }
2419 
halbtcoutsrc_GetBleScanTypeFromBt(void * pBtcContext)2420 u8 halbtcoutsrc_GetBleScanTypeFromBt(void *pBtcContext)
2421 {
2422 	PBTC_COEXIST pBtCoexist;
2423 	u32 ret = BT_STATUS_BT_OP_SUCCESS;
2424 	u8 data = 0;
2425 
2426 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2427 
2428 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2429 		u8 buf[3] = {0};
2430 		_irqL irqL;
2431 		u8 op_code;
2432 		u8 status;
2433 
2434 
2435 		_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2436 
2437 		op_code = BT_OP_GET_BT_BLE_SCAN_TYPE;
2438 		status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2439 		if (status == BT_STATUS_BT_OP_SUCCESS)
2440 			data = *(u8 *)GLBtcBtMpRptRsp;
2441 		else
2442 			ret = SET_BT_MP_OPER_RET(op_code, status);
2443 
2444 		_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2445 
2446 	} else
2447 		ret = BT_STATUS_NOT_IMPLEMENT;
2448 
2449 	return data;
2450 }
2451 
halbtcoutsrc_GetBleScanParaFromBt(void * pBtcContext,u8 scanType)2452 u32 halbtcoutsrc_GetBleScanParaFromBt(void *pBtcContext, u8 scanType)
2453 {
2454 	PBTC_COEXIST pBtCoexist;
2455 	u32 ret = BT_STATUS_BT_OP_SUCCESS;
2456 	u32 data = 0;
2457 
2458 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
2459 
2460 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2461 		u8 buf[3] = {0};
2462 		_irqL irqL;
2463 		u8 op_code;
2464 		u8 status;
2465 
2466 		buf[0] = scanType;
2467 
2468 		_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2469 
2470 		op_code = BT_OP_GET_BT_BLE_SCAN_PARA;
2471 		status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 1);
2472 		if (status == BT_STATUS_BT_OP_SUCCESS)
2473 			data = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
2474 		else
2475 			ret = SET_BT_MP_OPER_RET(op_code, status);
2476 
2477 		_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2478 
2479 	} else
2480 		ret = BT_STATUS_NOT_IMPLEMENT;
2481 
2482 	return data;
2483 }
2484 
halbtcoutsrc_GetBtAFHMapFromBt(void * pBtcContext,u8 mapType,u8 * afhMap)2485 u8 halbtcoutsrc_GetBtAFHMapFromBt(void *pBtcContext, u8 mapType, u8 *afhMap)
2486 {
2487 	struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2488 	u8 buf[2] = {0};
2489 	_irqL irqL;
2490 	u8 op_code;
2491 	u32 *AfhMapL = (u32 *)&(afhMap[0]);
2492 	u32 *AfhMapM = (u32 *)&(afhMap[4]);
2493 	u16 *AfhMapH = (u16 *)&(afhMap[8]);
2494 	u8 status;
2495 	u32 ret = BT_STATUS_BT_OP_SUCCESS;
2496 
2497 	if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _FALSE)
2498 		return _FALSE;
2499 
2500 	buf[0] = 0;
2501 	buf[1] = mapType;
2502 
2503 	_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2504 
2505 	op_code = BT_LO_OP_GET_AFH_MAP_L;
2506 	status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2507 	if (status == BT_STATUS_BT_OP_SUCCESS)
2508 		*AfhMapL = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
2509 	else {
2510 		ret = SET_BT_MP_OPER_RET(op_code, status);
2511 		goto exit;
2512 	}
2513 
2514 	op_code = BT_LO_OP_GET_AFH_MAP_M;
2515 	status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2516 	if (status == BT_STATUS_BT_OP_SUCCESS)
2517 		*AfhMapM = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
2518 	else {
2519 		ret = SET_BT_MP_OPER_RET(op_code, status);
2520 		goto exit;
2521 	}
2522 
2523 	op_code = BT_LO_OP_GET_AFH_MAP_H;
2524 	status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2525 	if (status == BT_STATUS_BT_OP_SUCCESS)
2526 		*AfhMapH = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
2527 	else {
2528 		ret = SET_BT_MP_OPER_RET(op_code, status);
2529 		goto exit;
2530 	}
2531 
2532 exit:
2533 
2534 	_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2535 
2536 	return (ret == BT_STATUS_BT_OP_SUCCESS) ? _TRUE : _FALSE;
2537 }
2538 
halbtcoutsrc_GetPhydmVersion(void * pBtcContext)2539 u32 halbtcoutsrc_GetPhydmVersion(void *pBtcContext)
2540 {
2541 	struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2542 	PADAPTER		Adapter = pBtCoexist->Adapter;
2543 
2544 #ifdef CONFIG_RTL8192E
2545 	return RELEASE_VERSION_8192E;
2546 #endif
2547 
2548 #ifdef CONFIG_RTL8821A
2549 	return RELEASE_VERSION_8821A;
2550 #endif
2551 
2552 #ifdef CONFIG_RTL8723B
2553 	return RELEASE_VERSION_8723B;
2554 #endif
2555 
2556 #ifdef CONFIG_RTL8812A
2557 	return RELEASE_VERSION_8812A;
2558 #endif
2559 
2560 #ifdef CONFIG_RTL8703B
2561 	return RELEASE_VERSION_8703B;
2562 #endif
2563 
2564 #ifdef CONFIG_RTL8822B
2565 	return RELEASE_VERSION_8822B;
2566 #endif
2567 
2568 #ifdef CONFIG_RTL8723D
2569 	return RELEASE_VERSION_8723D;
2570 #endif
2571 
2572 #ifdef CONFIG_RTL8821C
2573 	return RELEASE_VERSION_8821C;
2574 #endif
2575 
2576 #ifdef CONFIG_RTL8192F
2577 	return RELEASE_VERSION_8192F;
2578 #endif
2579 
2580 #ifdef CONFIG_RTL8822C
2581 	return RELEASE_VERSION_8822C;
2582 #endif
2583 
2584 #ifdef CONFIG_RTL8814A
2585 	return RELEASE_VERSION_8814A;
2586 #endif
2587 }
2588 
halbtcoutsrc_SetTimer(void * pBtcContext,u32 type,u32 val)2589 u8 halbtcoutsrc_SetTimer(void *pBtcContext, u32 type, u32 val)
2590 {
2591 	struct btc_coexist *pBtCoexist=(struct btc_coexist *)pBtcContext;
2592 
2593 	if (type >= BTC_TIMER_MAX)
2594 		return _FALSE;
2595 
2596 	pBtCoexist->coex_sta.cnt_timer[type] = val;
2597 
2598 	RTW_DBG("[BTC], Set Timer: type = %d, val = %d\n", type, val);
2599 
2600 	return _TRUE;
2601 }
2602 
halbtcoutsrc_SetAtomic(void * btc_ctx,u32 * target,u32 val)2603 u32 halbtcoutsrc_SetAtomic (void *btc_ctx, u32 *target, u32 val)
2604 {
2605 	*target = val;
2606 	return _SUCCESS;
2607 }
2608 
halbtcoutsrc_phydm_modify_AntDiv_HwSw(void * pBtcContext,u8 is_hw)2609 void halbtcoutsrc_phydm_modify_AntDiv_HwSw(void *pBtcContext, u8 is_hw)
2610 {
2611 	/* empty function since we don't need it */
2612 }
2613 
halbtcoutsrc_phydm_modify_RA_PCR_threshold(void * pBtcContext,u8 RA_offset_direction,u8 RA_threshold_offset)2614 void halbtcoutsrc_phydm_modify_RA_PCR_threshold(void *pBtcContext, u8 RA_offset_direction, u8 RA_threshold_offset)
2615 {
2616 	struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2617 
2618 /* switch to #if 0 in case the phydm version does not provide the function */
2619 #if 1
2620 	phydm_modify_RA_PCR_threshold(pBtCoexist->odm_priv, RA_offset_direction, RA_threshold_offset);
2621 #endif
2622 }
2623 
halbtcoutsrc_phydm_query_PHY_counter(void * pBtcContext,u8 info_type)2624 u32 halbtcoutsrc_phydm_query_PHY_counter(void *pBtcContext, u8 info_type)
2625 {
2626 	struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2627 
2628 /* switch to #if 0 in case the phydm version does not provide the function */
2629 #if 1
2630 	return phydm_cmn_info_query((struct dm_struct *)pBtCoexist->odm_priv, (enum phydm_info_query)info_type);
2631 #else
2632 	return 0;
2633 #endif
2634 }
2635 
halbtcoutsrc_reduce_wl_tx_power(void * pBtcContext,s8 tx_power)2636 void halbtcoutsrc_reduce_wl_tx_power(void *pBtcContext, s8 tx_power)
2637 {
2638 	struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2639 	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA((PADAPTER)pBtCoexist->Adapter);
2640 
2641 	/* The reduction of wl tx pwr should be processed inside the set tx pwr lvl function */
2642 	if (IS_HARDWARE_TYPE_8822C(pBtCoexist->Adapter))
2643 		rtw_hal_set_tx_power_level(pBtCoexist->Adapter, pHalData->current_channel);
2644 }
2645 
2646 #if 0
2647 static void BT_CoexOffloadRecordErrC2hAck(PADAPTER	Adapter)
2648 {
2649 	PADAPTER		pDefaultAdapter = GetDefaultAdapter(Adapter);
2650 
2651 	if (pDefaultAdapter != Adapter)
2652 		return;
2653 
2654 	if (!hal_btcoex_IsBtExist(Adapter))
2655 		return;
2656 
2657 	gl_coex_offload.cnt_c2h_ack++;
2658 
2659 	gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;
2660 }
2661 
2662 static void BT_CoexOffloadC2hAckCheck(PADAPTER	Adapter, u8 *tmpBuf, u8 length)
2663 {
2664 	PADAPTER		pDefaultAdapter = GetDefaultAdapter(Adapter);
2665 	PCOL_C2H_ACK	p_c2h_ack = NULL;
2666 	u8			req_num = 0xff;
2667 
2668 	if (pDefaultAdapter != Adapter)
2669 		return;
2670 
2671 	if (!hal_btcoex_IsBtExist(Adapter))
2672 		return;
2673 
2674 	gl_coex_offload.cnt_c2h_ack++;
2675 
2676 	if (length < COL_C2H_ACK_HDR_LEN) {		/* c2h ack length must >= 3 (status, opcode_ver, req_num and ret_len) */
2677 		gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;
2678 	} else {
2679 		BT_PrintData(Adapter, "[COL], c2h ack:", length, tmpBuf);
2680 
2681 		p_c2h_ack = (PCOL_C2H_ACK)tmpBuf;
2682 		req_num = p_c2h_ack->req_num;
2683 
2684 		_rtw_memmove(&gl_coex_offload.c2h_ack_buf[req_num][0], tmpBuf, length);
2685 		gl_coex_offload.c2h_ack_len[req_num] = length;
2686 
2687 		complete(&gl_coex_offload.c2h_event[req_num]);
2688 	}
2689 }
2690 
2691 static void BT_CoexOffloadC2hIndCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length)
2692 {
2693 	PADAPTER		pDefaultAdapter = GetDefaultAdapter(Adapter);
2694 	PCOL_C2H_IND	p_c2h_ind = NULL;
2695 	u8			ind_type = 0, ind_version = 0, ind_length = 0;
2696 
2697 	if (pDefaultAdapter != Adapter)
2698 		return;
2699 
2700 	if (!hal_btcoex_IsBtExist(Adapter))
2701 		return;
2702 
2703 	gl_coex_offload.cnt_c2h_ind++;
2704 
2705 	if (length < COL_C2H_IND_HDR_LEN) {		/* c2h indication length must >= 3 (type, version and length) */
2706 		gl_coex_offload.c2h_ind_status[COL_STATUS_INVALID_C2H_LEN]++;
2707 	} else {
2708 		BT_PrintData(Adapter, "[COL], c2h indication:", length, tmpBuf);
2709 
2710 		p_c2h_ind = (PCOL_C2H_IND)tmpBuf;
2711 		ind_type = p_c2h_ind->type;
2712 		ind_version = p_c2h_ind->version;
2713 		ind_length = p_c2h_ind->length;
2714 
2715 		_rtw_memmove(&gl_coex_offload.c2h_ind_buf[0], tmpBuf, length);
2716 		gl_coex_offload.c2h_ind_len = length;
2717 
2718 		/* log */
2719 		gl_coex_offload.c2h_ind_record[ind_type].count++;
2720 		gl_coex_offload.c2h_ind_record[ind_type].status[COL_STATUS_C2H_OK]++;
2721 		_rtw_memmove(&gl_coex_offload.c2h_ind_record[ind_type].ind_buf[0], tmpBuf, length);
2722 		gl_coex_offload.c2h_ind_record[ind_type].ind_len = length;
2723 
2724 		gl_coex_offload.c2h_ind_status[COL_STATUS_C2H_OK]++;
2725 		/*TODO: need to check c2h indication length*/
2726 		/* TODO: Notification */
2727 	}
2728 }
2729 
2730 void BT_CoexOffloadC2hCheck(PADAPTER Adapter, u8 *Buffer, u8 Length)
2731 {
2732 #if 0 /*(USE_HAL_MAC_API == 1)*/
2733 	u8	c2hSubCmdId = 0, c2hAckLen = 0, h2cCmdId = 0, h2cSubCmdId = 0, c2hIndLen = 0;
2734 
2735 	BT_PrintData(Adapter, "[COL], c2h packet:", Length - 2, Buffer + 2);
2736 	c2hSubCmdId = (u8)C2H_HDR_GET_C2H_SUB_CMD_ID(Buffer);
2737 
2738 	if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR ||
2739 	    c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) {
2740 		if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR) {
2741 			/* coex c2h ack */
2742 			h2cCmdId = (u8)H2C_ACK_HDR_GET_H2C_CMD_ID(Buffer);
2743 			h2cSubCmdId = (u8)H2C_ACK_HDR_GET_H2C_SUB_CMD_ID(Buffer);
2744 			if (h2cCmdId == 0xff && h2cSubCmdId == 0x60) {
2745 				c2hAckLen = (u8)C2H_HDR_GET_LEN(Buffer);
2746 				if (c2hAckLen >= 8)
2747 					BT_CoexOffloadC2hAckCheck(Adapter, &Buffer[12], (u8)(c2hAckLen - 8));
2748 				else
2749 					BT_CoexOffloadRecordErrC2hAck(Adapter);
2750 			}
2751 		} else if (c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) {
2752 			/* coex c2h indication */
2753 			c2hIndLen = (u8)C2H_HDR_GET_LEN(Buffer);
2754 			BT_CoexOffloadC2hIndCheck(Adapter, &Buffer[4], (u8)c2hIndLen);
2755 		}
2756 	}
2757 #endif
2758 }
2759 #endif
2760 
2761 /* ************************************
2762  *		Extern functions called by other module
2763  * ************************************ */
EXhalbtcoutsrc_BindBtCoexWithAdapter(void * padapter)2764 u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
2765 {
2766 	PBTC_COEXIST		pBtCoexist = &GLBtCoexist;
2767 	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA((PADAPTER)padapter);
2768 
2769 	if (pBtCoexist->bBinded)
2770 		return _FALSE;
2771 	else
2772 		pBtCoexist->bBinded = _TRUE;
2773 
2774 	pBtCoexist->statistics.cnt_bind++;
2775 
2776 	pBtCoexist->Adapter = padapter;
2777 	pBtCoexist->odm_priv = (void *)&(pHalData->odmpriv);
2778 
2779 	pBtCoexist->stack_info.profile_notified = _FALSE;
2780 
2781 	pBtCoexist->bt_info.bt_ctrl_agg_buf_size = _FALSE;
2782 	pBtCoexist->bt_info.agg_buf_size = 5;
2783 
2784 	pBtCoexist->bt_info.increase_scan_dev_num = _FALSE;
2785 	pBtCoexist->bt_info.miracast_plus_bt = _FALSE;
2786 
2787 	/* for btc common architecture, inform chip type to coex. mechanism */
2788 	if(IS_HARDWARE_TYPE_8822C(padapter))
2789 		pBtCoexist->chip_type = BTC_CHIP_RTL8822C;
2790 	else if (IS_HARDWARE_TYPE_8822B(padapter))
2791 		pBtCoexist->chip_type = BTC_CHIP_RTL8822B;
2792 	else
2793 		pBtCoexist->chip_type = BTC_CHIP_UNDEF;
2794 
2795 	return _TRUE;
2796 }
2797 
EXhalbtcoutsrc_AntInfoSetting(void * padapter)2798 void EXhalbtcoutsrc_AntInfoSetting(void *padapter)
2799 {
2800 	PBTC_COEXIST		pBtCoexist = &GLBtCoexist;
2801 	u8	antNum = 1, singleAntPath = 0;
2802 
2803 	antNum = rtw_btcoex_get_pg_ant_num((PADAPTER)padapter);
2804 	EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
2805 
2806 	if (antNum == 1) {
2807 		singleAntPath = rtw_btcoex_get_pg_single_ant_path((PADAPTER)padapter);
2808 		EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
2809 	}
2810 
2811 	pBtCoexist->board_info.customerID = RT_CID_DEFAULT;
2812 	pBtCoexist->board_info.customer_id = RT_CID_DEFAULT;
2813 
2814 	/* set default antenna position to main  port */
2815 	pBtCoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
2816 
2817 	pBtCoexist->board_info.btdm_ant_det_finish = _FALSE;
2818 	pBtCoexist->board_info.btdm_ant_num_by_ant_det = 1;
2819 
2820 	pBtCoexist->board_info.tfbga_package = rtw_btcoex_is_tfbga_package_type((PADAPTER)padapter);
2821 
2822 	pBtCoexist->board_info.rfe_type = rtw_btcoex_get_pg_rfe_type((PADAPTER)padapter);
2823 
2824 	pBtCoexist->board_info.ant_div_cfg = rtw_btcoex_get_ant_div_cfg((PADAPTER)padapter);
2825 
2826 	pBtCoexist->board_info.ant_distance = 10;
2827 }
2828 
EXhalbtcoutsrc_InitlizeVariables(void * padapter)2829 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
2830 {
2831 	PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2832 
2833 	/* pBtCoexist->statistics.cntBind++; */
2834 
2835 	halbtcoutsrc_DbgInit();
2836 
2837 	halbtcoutsrc_coex_offload_init();
2838 
2839 #ifdef CONFIG_PCI_HCI
2840 	pBtCoexist->chip_interface = BTC_INTF_PCI;
2841 #elif defined(CONFIG_USB_HCI)
2842 	pBtCoexist->chip_interface = BTC_INTF_USB;
2843 #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
2844 	pBtCoexist->chip_interface = BTC_INTF_SDIO;
2845 #else
2846 	pBtCoexist->chip_interface = BTC_INTF_UNKNOWN;
2847 #endif
2848 
2849 	EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
2850 
2851 	pBtCoexist->btc_read_1byte = halbtcoutsrc_Read1Byte;
2852 	pBtCoexist->btc_write_1byte = halbtcoutsrc_Write1Byte;
2853 	pBtCoexist->btc_write_1byte_bitmask = halbtcoutsrc_BitMaskWrite1Byte;
2854 	pBtCoexist->btc_read_2byte = halbtcoutsrc_Read2Byte;
2855 	pBtCoexist->btc_write_2byte = halbtcoutsrc_Write2Byte;
2856 	pBtCoexist->btc_read_4byte = halbtcoutsrc_Read4Byte;
2857 	pBtCoexist->btc_write_4byte = halbtcoutsrc_Write4Byte;
2858 	pBtCoexist->btc_write_local_reg_1byte = halbtcoutsrc_WriteLocalReg1Byte;
2859 
2860 	pBtCoexist->btc_set_bb_reg = halbtcoutsrc_SetBbReg;
2861 	pBtCoexist->btc_get_bb_reg = halbtcoutsrc_GetBbReg;
2862 
2863 	pBtCoexist->btc_set_rf_reg = halbtcoutsrc_SetRfReg;
2864 	pBtCoexist->btc_get_rf_reg = halbtcoutsrc_GetRfReg;
2865 
2866 	pBtCoexist->btc_fill_h2c = halbtcoutsrc_FillH2cCmd;
2867 	pBtCoexist->btc_disp_dbg_msg = halbtcoutsrc_DisplayDbgMsg;
2868 
2869 	pBtCoexist->btc_get = halbtcoutsrc_Get;
2870 	pBtCoexist->btc_set = halbtcoutsrc_Set;
2871 	pBtCoexist->btc_get_bt_reg = halbtcoutsrc_GetBtReg;
2872 	pBtCoexist->btc_set_bt_reg = halbtcoutsrc_SetBtReg;
2873 	pBtCoexist->btc_set_bt_ant_detection = halbtcoutsrc_SetBtAntDetection;
2874 	pBtCoexist->btc_set_bt_trx_mask = halbtcoutsrc_SetBtTRXMASK;
2875 	pBtCoexist->btc_coex_h2c_process = halbtcoutsrc_CoexH2cProcess;
2876 	pBtCoexist->btc_get_bt_coex_supported_feature = halbtcoutsrc_GetBtCoexSupportedFeature;
2877 	pBtCoexist->btc_get_bt_coex_supported_version= halbtcoutsrc_GetBtCoexSupportedVersion;
2878 	pBtCoexist->btc_get_ant_det_val_from_bt = halbtcoutsrc_GetAntDetValFromBt;
2879 	pBtCoexist->btc_get_ble_scan_type_from_bt = halbtcoutsrc_GetBleScanTypeFromBt;
2880 	pBtCoexist->btc_get_ble_scan_para_from_bt = halbtcoutsrc_GetBleScanParaFromBt;
2881 	pBtCoexist->btc_get_bt_afh_map_from_bt = halbtcoutsrc_GetBtAFHMapFromBt;
2882 	pBtCoexist->btc_get_bt_phydm_version = halbtcoutsrc_GetPhydmVersion;
2883 	pBtCoexist->btc_set_timer = halbtcoutsrc_SetTimer;
2884 	pBtCoexist->btc_set_atomic= halbtcoutsrc_SetAtomic;
2885 	pBtCoexist->btc_phydm_modify_RA_PCR_threshold = halbtcoutsrc_phydm_modify_RA_PCR_threshold;
2886 	pBtCoexist->btc_phydm_query_PHY_counter = halbtcoutsrc_phydm_query_PHY_counter;
2887 	pBtCoexist->btc_reduce_wl_tx_power = halbtcoutsrc_reduce_wl_tx_power;
2888 	pBtCoexist->btc_phydm_modify_antdiv_hwsw = halbtcoutsrc_phydm_modify_AntDiv_HwSw;
2889 
2890 	pBtCoexist->cli_buf = &GLBtcDbgBuf[0];
2891 
2892 	GLBtcWiFiInScanState = _FALSE;
2893 
2894 	GLBtcWiFiInIQKState = _FALSE;
2895 
2896 	GLBtcWiFiInIPS = _FALSE;
2897 
2898 	GLBtcWiFiInLPS = _FALSE;
2899 
2900 	GLBtcBtCoexAliveRegistered = _FALSE;
2901 
2902 	/* BT Control H2C/C2H*/
2903 	GLBtcBtMpOperSeq = 0;
2904 	_rtw_mutex_init(&GLBtcBtMpOperLock);
2905 	rtw_init_timer(&GLBtcBtMpOperTimer, padapter, _btmpoper_timer_hdl, pBtCoexist);
2906 	_rtw_init_sema(&GLBtcBtMpRptSema, 0);
2907 	GLBtcBtMpRptSeq = 0;
2908 	GLBtcBtMpRptStatus = 0;
2909 	_rtw_memset(GLBtcBtMpRptRsp, 0, C2H_MAX_SIZE);
2910 	GLBtcBtMpRptRspSize = 0;
2911 	GLBtcBtMpRptWait = _FALSE;
2912 	GLBtcBtMpRptWiFiOK = _FALSE;
2913 	GLBtcBtMpRptBTOK = _FALSE;
2914 
2915 	return _TRUE;
2916 }
2917 
EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)2918 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
2919 {
2920 	HAL_DATA_TYPE	*pHalData = NULL;
2921 
2922 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2923 		return;
2924 
2925 	pHalData = GET_HAL_DATA((PADAPTER)pBtCoexist->Adapter);
2926 
2927 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
2928 	rtw_btc_ex_power_on_setting(pBtCoexist);
2929 
2930 #else
2931 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2932 #ifdef CONFIG_RTL8723B
2933 		if (pBtCoexist->board_info.btdm_ant_num == 2)
2934 			ex_halbtc8723b2ant_power_on_setting(pBtCoexist);
2935 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
2936 			ex_halbtc8723b1ant_power_on_setting(pBtCoexist);
2937 #endif
2938 	}
2939 
2940 #ifdef CONFIG_RTL8703B
2941 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2942 		if (pBtCoexist->board_info.btdm_ant_num == 1)
2943 			ex_halbtc8703b1ant_power_on_setting(pBtCoexist);
2944 	}
2945 #endif
2946 
2947 #ifdef CONFIG_RTL8723D
2948 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2949 		if (pBtCoexist->board_info.btdm_ant_num == 2)
2950 			ex_halbtc8723d2ant_power_on_setting(pBtCoexist);
2951 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
2952 			ex_halbtc8723d1ant_power_on_setting(pBtCoexist);
2953 	}
2954 #endif
2955 
2956 #ifdef CONFIG_RTL8821A
2957 	else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2958 		if (pBtCoexist->board_info.btdm_ant_num == 1)
2959 			ex_halbtc8821a1ant_power_on_setting(pBtCoexist);
2960 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
2961 			ex_halbtc8821a2ant_power_on_setting(pBtCoexist);
2962 	}
2963 #endif
2964 
2965 #ifdef CONFIG_RTL8822B
2966 	else if ((IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) && (pHalData->EEPROMBluetoothCoexist == _TRUE)) {
2967 		if (pBtCoexist->board_info.btdm_ant_num == 1)
2968 			ex_halbtc8822b1ant_power_on_setting(pBtCoexist);
2969 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
2970 			ex_halbtc8822b2ant_power_on_setting(pBtCoexist);
2971 	}
2972 #endif
2973 
2974 #ifdef CONFIG_RTL8821C
2975 	else if ((IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) && (pHalData->EEPROMBluetoothCoexist == _TRUE)) {
2976 		if (pBtCoexist->board_info.btdm_ant_num == 2)
2977 			ex_halbtc8821c2ant_power_on_setting(pBtCoexist);
2978 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
2979 			ex_halbtc8821c1ant_power_on_setting(pBtCoexist);
2980 	}
2981 #endif
2982 
2983 #ifdef CONFIG_RTL8814A
2984 	if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
2985 		if (pBtCoexist->board_info.btdm_ant_num == 2)
2986 			ex_halbtc8814a2ant_power_on_setting(pBtCoexist);
2987 		/* else if (pBtCoexist->board_info.btdm_ant_num == 1)
2988 			ex_halbtc8814a1ant_power_on_setting(pBtCoexist); */
2989 	}
2990 #endif
2991 
2992 #endif
2993 }
2994 
EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)2995 void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)
2996 {
2997 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2998 		return;
2999 
3000 	pBtCoexist->statistics.cnt_pre_load_firmware++;
3001 
3002 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3003 #ifdef CONFIG_RTL8723B
3004 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3005 			ex_halbtc8723b2ant_pre_load_firmware(pBtCoexist);
3006 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3007 			ex_halbtc8723b1ant_pre_load_firmware(pBtCoexist);
3008 #endif
3009 	}
3010 
3011 #ifdef CONFIG_RTL8723D
3012 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3013 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3014 			ex_halbtc8723d2ant_pre_load_firmware(pBtCoexist);
3015 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3016 			ex_halbtc8723d1ant_pre_load_firmware(pBtCoexist);
3017 	}
3018 #endif
3019 
3020 #ifdef CONFIG_RTL8821C
3021 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3022 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3023 			ex_halbtc8821c2ant_pre_load_firmware(pBtCoexist);
3024 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3025 			ex_halbtc8821c1ant_pre_load_firmware(pBtCoexist);
3026 	}
3027 #endif
3028 }
3029 
EXhalbtcoutsrc_init_hw_config(PBTC_COEXIST pBtCoexist,u8 bWifiOnly)3030 void EXhalbtcoutsrc_init_hw_config(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
3031 {
3032 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3033 		return;
3034 
3035 	pBtCoexist->statistics.cnt_init_hw_config++;
3036 
3037 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
3038 	rtw_btc_ex_init_hw_config(pBtCoexist, bWifiOnly);
3039 #else
3040 
3041 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3042 #ifdef CONFIG_RTL8821A
3043 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3044 			ex_halbtc8821a2ant_init_hw_config(pBtCoexist, bWifiOnly);
3045 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3046 			ex_halbtc8821a1ant_init_hw_config(pBtCoexist, bWifiOnly);
3047 #endif
3048 	}
3049 
3050 #ifdef CONFIG_RTL8723B
3051 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3052 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3053 			ex_halbtc8723b2ant_init_hw_config(pBtCoexist, bWifiOnly);
3054 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3055 			ex_halbtc8723b1ant_init_hw_config(pBtCoexist, bWifiOnly);
3056 	}
3057 #endif
3058 
3059 #ifdef CONFIG_RTL8703B
3060 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3061 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3062 			ex_halbtc8703b1ant_init_hw_config(pBtCoexist, bWifiOnly);
3063 	}
3064 #endif
3065 
3066 #ifdef CONFIG_RTL8723D
3067 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3068 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3069 			ex_halbtc8723d2ant_init_hw_config(pBtCoexist, bWifiOnly);
3070 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3071 			ex_halbtc8723d1ant_init_hw_config(pBtCoexist, bWifiOnly);
3072 	}
3073 #endif
3074 
3075 #ifdef CONFIG_RTL8192E
3076 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3077 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3078 			ex_halbtc8192e2ant_init_hw_config(pBtCoexist, bWifiOnly);
3079 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3080 			ex_halbtc8192e1ant_init_hw_config(pBtCoexist, bWifiOnly);
3081 	}
3082 #endif
3083 
3084 #ifdef CONFIG_RTL8812A
3085 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3086 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3087 			ex_halbtc8812a2ant_init_hw_config(pBtCoexist, bWifiOnly);
3088 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3089 			ex_halbtc8812a1ant_init_hw_config(pBtCoexist, bWifiOnly);
3090 	}
3091 #endif
3092 
3093 #ifdef CONFIG_RTL8822B
3094 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3095 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3096 			ex_halbtc8822b1ant_init_hw_config(pBtCoexist, bWifiOnly);
3097 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
3098 			ex_halbtc8822b2ant_init_hw_config(pBtCoexist, bWifiOnly);
3099 	}
3100 #endif
3101 
3102 #ifdef CONFIG_RTL8821C
3103 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3104 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3105 			ex_halbtc8821c2ant_init_hw_config(pBtCoexist, bWifiOnly);
3106 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3107 			ex_halbtc8821c1ant_init_hw_config(pBtCoexist, bWifiOnly);
3108 	}
3109 #endif
3110 
3111 #ifdef CONFIG_RTL8814A
3112 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
3113 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3114 			ex_halbtc8814a2ant_init_hw_config(pBtCoexist, bWifiOnly);
3115 	}
3116 #endif
3117 
3118 #endif
3119 }
3120 
EXhalbtcoutsrc_init_coex_dm(PBTC_COEXIST pBtCoexist)3121 void EXhalbtcoutsrc_init_coex_dm(PBTC_COEXIST pBtCoexist)
3122 {
3123 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3124 		return;
3125 
3126 	pBtCoexist->statistics.cnt_init_coex_dm++;
3127 
3128 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
3129 	rtw_btc_ex_init_coex_dm(pBtCoexist);
3130 #else
3131 
3132 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3133 #ifdef CONFIG_RTL8821A
3134 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3135 			ex_halbtc8821a2ant_init_coex_dm(pBtCoexist);
3136 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3137 			ex_halbtc8821a1ant_init_coex_dm(pBtCoexist);
3138 #endif
3139 	}
3140 
3141 #ifdef CONFIG_RTL8723B
3142 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3143 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3144 			ex_halbtc8723b2ant_init_coex_dm(pBtCoexist);
3145 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3146 			ex_halbtc8723b1ant_init_coex_dm(pBtCoexist);
3147 	}
3148 #endif
3149 
3150 #ifdef CONFIG_RTL8703B
3151 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3152 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3153 			ex_halbtc8703b1ant_init_coex_dm(pBtCoexist);
3154 	}
3155 #endif
3156 
3157 #ifdef CONFIG_RTL8723D
3158 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3159 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3160 			ex_halbtc8723d2ant_init_coex_dm(pBtCoexist);
3161 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3162 			ex_halbtc8723d1ant_init_coex_dm(pBtCoexist);
3163 	}
3164 #endif
3165 
3166 #ifdef CONFIG_RTL8192E
3167 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3168 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3169 			ex_halbtc8192e2ant_init_coex_dm(pBtCoexist);
3170 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3171 			ex_halbtc8192e1ant_init_coex_dm(pBtCoexist);
3172 	}
3173 #endif
3174 
3175 #ifdef CONFIG_RTL8812A
3176 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3177 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3178 			ex_halbtc8812a2ant_init_coex_dm(pBtCoexist);
3179 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3180 			ex_halbtc8812a1ant_init_coex_dm(pBtCoexist);
3181 	}
3182 #endif
3183 
3184 #ifdef CONFIG_RTL8822B
3185 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3186 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3187 			ex_halbtc8822b1ant_init_coex_dm(pBtCoexist);
3188 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
3189 			ex_halbtc8822b2ant_init_coex_dm(pBtCoexist);
3190 	}
3191 #endif
3192 
3193 #ifdef CONFIG_RTL8821C
3194 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3195 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3196 			ex_halbtc8821c2ant_init_coex_dm(pBtCoexist);
3197 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3198 			ex_halbtc8821c1ant_init_coex_dm(pBtCoexist);
3199 	}
3200 #endif
3201 
3202 #ifdef CONFIG_RTL8814A
3203 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
3204 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3205 			ex_halbtc8814a2ant_init_coex_dm(pBtCoexist);
3206 	}
3207 #endif
3208 
3209 #endif
3210 
3211 	pBtCoexist->initilized = _TRUE;
3212 }
3213 
EXhalbtcoutsrc_ips_notify(PBTC_COEXIST pBtCoexist,u8 type)3214 void EXhalbtcoutsrc_ips_notify(PBTC_COEXIST pBtCoexist, u8 type)
3215 {
3216 	u8	ipsType;
3217 
3218 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3219 		return;
3220 
3221 	pBtCoexist->statistics.cnt_ips_notify++;
3222 	if (pBtCoexist->manual_control)
3223 		return;
3224 
3225 	if (IPS_NONE == type) {
3226 		ipsType = BTC_IPS_LEAVE;
3227 		GLBtcWiFiInIPS = _FALSE;
3228 	} else {
3229 		ipsType = BTC_IPS_ENTER;
3230 		GLBtcWiFiInIPS = _TRUE;
3231 	}
3232 
3233 	/* All notify is called in cmd thread, don't need to leave low power again
3234 	*	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3235 
3236 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
3237 	rtw_btc_ex_ips_notify(pBtCoexist, ipsType);
3238 #else
3239 
3240 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3241 #ifdef CONFIG_RTL8821A
3242 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3243 			ex_halbtc8821a2ant_ips_notify(pBtCoexist, ipsType);
3244 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3245 			ex_halbtc8821a1ant_ips_notify(pBtCoexist, ipsType);
3246 #endif
3247 	}
3248 
3249 #ifdef CONFIG_RTL8723B
3250 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3251 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3252 			ex_halbtc8723b2ant_ips_notify(pBtCoexist, ipsType);
3253 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3254 			ex_halbtc8723b1ant_ips_notify(pBtCoexist, ipsType);
3255 	}
3256 #endif
3257 
3258 #ifdef CONFIG_RTL8703B
3259 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3260 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3261 			ex_halbtc8703b1ant_ips_notify(pBtCoexist, ipsType);
3262 	}
3263 #endif
3264 
3265 #ifdef CONFIG_RTL8723D
3266 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3267 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3268 			ex_halbtc8723d2ant_ips_notify(pBtCoexist, ipsType);
3269 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3270 			ex_halbtc8723d1ant_ips_notify(pBtCoexist, ipsType);
3271 	}
3272 #endif
3273 
3274 #ifdef CONFIG_RTL8192E
3275 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3276 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3277 			ex_halbtc8192e2ant_ips_notify(pBtCoexist, ipsType);
3278 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3279 			ex_halbtc8192e1ant_ips_notify(pBtCoexist, ipsType);
3280 	}
3281 #endif
3282 
3283 #ifdef CONFIG_RTL8812A
3284 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3285 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3286 			ex_halbtc8812a2ant_ips_notify(pBtCoexist, ipsType);
3287 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3288 			ex_halbtc8812a1ant_ips_notify(pBtCoexist, ipsType);
3289 	}
3290 #endif
3291 
3292 #ifdef CONFIG_RTL8822B
3293 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3294 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3295 			ex_halbtc8822b1ant_ips_notify(pBtCoexist, ipsType);
3296 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
3297 			ex_halbtc8822b2ant_ips_notify(pBtCoexist, ipsType);
3298 	}
3299 #endif
3300 
3301 #ifdef CONFIG_RTL8821C
3302 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3303 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3304 			ex_halbtc8821c2ant_ips_notify(pBtCoexist, ipsType);
3305 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3306 			ex_halbtc8821c1ant_ips_notify(pBtCoexist, ipsType);
3307 	}
3308 #endif
3309 
3310 #ifdef CONFIG_RTL8814A
3311 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
3312 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3313 			ex_halbtc8814a2ant_ips_notify(pBtCoexist, ipsType);
3314 	}
3315 #endif
3316 
3317 #endif
3318 	/*	halbtcoutsrc_NormalLowPower(pBtCoexist); */
3319 }
3320 
EXhalbtcoutsrc_lps_notify(PBTC_COEXIST pBtCoexist,u8 type)3321 void EXhalbtcoutsrc_lps_notify(PBTC_COEXIST pBtCoexist, u8 type)
3322 {
3323 	u8 lpsType;
3324 
3325 
3326 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3327 		return;
3328 
3329 	pBtCoexist->statistics.cnt_lps_notify++;
3330 	if (pBtCoexist->manual_control)
3331 		return;
3332 
3333 	if (PS_MODE_ACTIVE == type) {
3334 		lpsType = BTC_LPS_DISABLE;
3335 		GLBtcWiFiInLPS = _FALSE;
3336 	} else {
3337 		lpsType = BTC_LPS_ENABLE;
3338 		GLBtcWiFiInLPS = _TRUE;
3339 	}
3340 
3341 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
3342 	rtw_btc_ex_lps_notify(pBtCoexist, lpsType);
3343 #else
3344 
3345 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3346 #ifdef CONFIG_RTL8821A
3347 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3348 			ex_halbtc8821a2ant_lps_notify(pBtCoexist, lpsType);
3349 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3350 			ex_halbtc8821a1ant_lps_notify(pBtCoexist, lpsType);
3351 #endif
3352 	}
3353 
3354 #ifdef CONFIG_RTL8723B
3355 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3356 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3357 			ex_halbtc8723b2ant_lps_notify(pBtCoexist, lpsType);
3358 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3359 			ex_halbtc8723b1ant_lps_notify(pBtCoexist, lpsType);
3360 	}
3361 #endif
3362 
3363 #ifdef CONFIG_RTL8703B
3364 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3365 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3366 			ex_halbtc8703b1ant_lps_notify(pBtCoexist, lpsType);
3367 	}
3368 #endif
3369 
3370 #ifdef CONFIG_RTL8723D
3371 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3372 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3373 			ex_halbtc8723d2ant_lps_notify(pBtCoexist, lpsType);
3374 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3375 			ex_halbtc8723d1ant_lps_notify(pBtCoexist, lpsType);
3376 	}
3377 #endif
3378 
3379 #ifdef CONFIG_RTL8192E
3380 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3381 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3382 			ex_halbtc8192e2ant_lps_notify(pBtCoexist, lpsType);
3383 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3384 			ex_halbtc8192e1ant_lps_notify(pBtCoexist, lpsType);
3385 	}
3386 #endif
3387 
3388 #ifdef CONFIG_RTL8812A
3389 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3390 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3391 			ex_halbtc8812a2ant_lps_notify(pBtCoexist, lpsType);
3392 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3393 			ex_halbtc8812a1ant_lps_notify(pBtCoexist, lpsType);
3394 	}
3395 #endif
3396 
3397 #ifdef CONFIG_RTL8822B
3398 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3399 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3400 			ex_halbtc8822b1ant_lps_notify(pBtCoexist, lpsType);
3401 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
3402 			ex_halbtc8822b2ant_lps_notify(pBtCoexist, lpsType);
3403 	}
3404 #endif
3405 
3406 #ifdef CONFIG_RTL8821C
3407 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3408 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3409 			ex_halbtc8821c2ant_lps_notify(pBtCoexist, lpsType);
3410 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3411 			ex_halbtc8821c1ant_lps_notify(pBtCoexist, lpsType);
3412 	}
3413 #endif
3414 
3415 #ifdef CONFIG_RTL8814A
3416 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
3417 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3418 			ex_halbtc8814a2ant_lps_notify(pBtCoexist, lpsType);
3419 	}
3420 #endif
3421 
3422 #endif
3423 }
3424 
EXhalbtcoutsrc_scan_notify(PBTC_COEXIST pBtCoexist,u8 type)3425 void EXhalbtcoutsrc_scan_notify(PBTC_COEXIST pBtCoexist, u8 type)
3426 {
3427 	u8	scanType;
3428 
3429 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3430 		return;
3431 	pBtCoexist->statistics.cnt_scan_notify++;
3432 	if (pBtCoexist->manual_control)
3433 		return;
3434 
3435 	if (type) {
3436 		scanType = BTC_SCAN_START;
3437 		GLBtcWiFiInScanState = _TRUE;
3438 	} else {
3439 		scanType = BTC_SCAN_FINISH;
3440 		GLBtcWiFiInScanState = _FALSE;
3441 	}
3442 
3443 	/* All notify is called in cmd thread, don't need to leave low power again
3444 	*	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3445 
3446 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
3447 	rtw_btc_ex_scan_notify(pBtCoexist, scanType);
3448 #else
3449 
3450 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3451 #ifdef CONFIG_RTL8821A
3452 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3453 			ex_halbtc8821a2ant_scan_notify(pBtCoexist, scanType);
3454 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3455 			ex_halbtc8821a1ant_scan_notify(pBtCoexist, scanType);
3456 #endif
3457 	}
3458 
3459 #ifdef CONFIG_RTL8723B
3460 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3461 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3462 			ex_halbtc8723b2ant_scan_notify(pBtCoexist, scanType);
3463 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3464 			ex_halbtc8723b1ant_scan_notify(pBtCoexist, scanType);
3465 	}
3466 #endif
3467 
3468 #ifdef CONFIG_RTL8703B
3469 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3470 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3471 			ex_halbtc8703b1ant_scan_notify(pBtCoexist, scanType);
3472 	}
3473 #endif
3474 
3475 #ifdef CONFIG_RTL8723D
3476 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3477 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3478 			ex_halbtc8723d2ant_scan_notify(pBtCoexist, scanType);
3479 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3480 			ex_halbtc8723d1ant_scan_notify(pBtCoexist, scanType);
3481 	}
3482 #endif
3483 
3484 #ifdef CONFIG_RTL8192E
3485 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3486 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3487 			ex_halbtc8192e2ant_scan_notify(pBtCoexist, scanType);
3488 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3489 			ex_halbtc8192e1ant_scan_notify(pBtCoexist, scanType);
3490 	}
3491 #endif
3492 
3493 #ifdef CONFIG_RTL8812A
3494 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3495 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3496 			ex_halbtc8812a2ant_scan_notify(pBtCoexist, scanType);
3497 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3498 			ex_halbtc8812a1ant_scan_notify(pBtCoexist, scanType);
3499 	}
3500 #endif
3501 
3502 #ifdef CONFIG_RTL8822B
3503 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3504 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3505 			ex_halbtc8822b1ant_scan_notify(pBtCoexist, scanType);
3506 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
3507 			ex_halbtc8822b2ant_scan_notify(pBtCoexist, scanType);
3508 	}
3509 #endif
3510 
3511 #ifdef CONFIG_RTL8821C
3512 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3513 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3514 			ex_halbtc8821c2ant_scan_notify(pBtCoexist, scanType);
3515 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3516 			ex_halbtc8821c1ant_scan_notify(pBtCoexist, scanType);
3517 	}
3518 #endif
3519 
3520 #ifdef CONFIG_RTL8814A
3521 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
3522 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3523 			ex_halbtc8814a2ant_scan_notify(pBtCoexist, scanType);
3524 	}
3525 #endif
3526 
3527 #endif
3528 
3529 	/*	halbtcoutsrc_NormalLowPower(pBtCoexist); */
3530 }
3531 
EXhalbtcoutsrc_SetAntennaPathNotify(PBTC_COEXIST pBtCoexist,u8 type)3532 void EXhalbtcoutsrc_SetAntennaPathNotify(PBTC_COEXIST pBtCoexist, u8 type)
3533 {
3534 #if 0
3535 	u8	switchType;
3536 
3537 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3538 		return;
3539 
3540 	if (pBtCoexist->manual_control)
3541 		return;
3542 
3543 	halbtcoutsrc_LeaveLowPower(pBtCoexist);
3544 
3545 	switchType = type;
3546 
3547 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3548 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3549 			ex_halbtc8723b1ant_set_antenna_notify(pBtCoexist, type);
3550 	}
3551 	if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3552 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3553 			ex_halbtc8723d1ant_set_antenna_notify(pBtCoexist, type);
3554 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
3555 			ex_halbtc8723d2ant_set_antenna_notify(pBtCoexist, type);
3556 	}
3557 
3558 	halbtcoutsrc_NormalLowPower(pBtCoexist);
3559 #endif
3560 }
3561 
EXhalbtcoutsrc_connect_notify(PBTC_COEXIST pBtCoexist,u8 assoType)3562 void EXhalbtcoutsrc_connect_notify(PBTC_COEXIST pBtCoexist, u8 assoType)
3563 {
3564 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3565 		return;
3566 	pBtCoexist->statistics.cnt_connect_notify++;
3567 	if (pBtCoexist->manual_control)
3568 		return;
3569 
3570 	/* All notify is called in cmd thread, don't need to leave low power again
3571 	*	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3572 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
3573 	rtw_btc_ex_connect_notify(pBtCoexist, assoType);
3574 #else
3575 
3576 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3577 #ifdef CONFIG_RTL8821A
3578 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3579 			ex_halbtc8821a2ant_connect_notify(pBtCoexist, assoType);
3580 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3581 			ex_halbtc8821a1ant_connect_notify(pBtCoexist, assoType);
3582 #endif
3583 	}
3584 
3585 #ifdef CONFIG_RTL8723B
3586 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3587 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3588 			ex_halbtc8723b2ant_connect_notify(pBtCoexist, assoType);
3589 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3590 			ex_halbtc8723b1ant_connect_notify(pBtCoexist, assoType);
3591 	}
3592 #endif
3593 
3594 #ifdef CONFIG_RTL8703B
3595 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3596 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3597 			ex_halbtc8703b1ant_connect_notify(pBtCoexist, assoType);
3598 	}
3599 #endif
3600 
3601 #ifdef CONFIG_RTL8723D
3602 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3603 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3604 			ex_halbtc8723d2ant_connect_notify(pBtCoexist, assoType);
3605 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3606 			ex_halbtc8723d1ant_connect_notify(pBtCoexist, assoType);
3607 	}
3608 #endif
3609 
3610 #ifdef CONFIG_RTL8192E
3611 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3612 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3613 			ex_halbtc8192e2ant_connect_notify(pBtCoexist, assoType);
3614 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3615 			ex_halbtc8192e1ant_connect_notify(pBtCoexist, assoType);
3616 	}
3617 #endif
3618 
3619 #ifdef CONFIG_RTL8812A
3620 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3621 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3622 			ex_halbtc8812a2ant_connect_notify(pBtCoexist, assoType);
3623 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3624 			ex_halbtc8812a1ant_connect_notify(pBtCoexist, assoType);
3625 	}
3626 #endif
3627 
3628 #ifdef CONFIG_RTL8822B
3629 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3630 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3631 			ex_halbtc8822b1ant_connect_notify(pBtCoexist, assoType);
3632 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
3633 			ex_halbtc8822b2ant_connect_notify(pBtCoexist, assoType);
3634 	}
3635 #endif
3636 
3637 #ifdef CONFIG_RTL8821C
3638 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3639 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3640 			ex_halbtc8821c2ant_connect_notify(pBtCoexist, assoType);
3641 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3642 			ex_halbtc8821c1ant_connect_notify(pBtCoexist, assoType);
3643 	}
3644 #endif
3645 
3646 #ifdef CONFIG_RTL8814A
3647 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
3648 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3649 			ex_halbtc8814a2ant_connect_notify(pBtCoexist, assoType);
3650 	}
3651 #endif
3652 
3653 #endif
3654 
3655 	/*	halbtcoutsrc_NormalLowPower(pBtCoexist); */
3656 }
3657 
EXhalbtcoutsrc_media_status_notify(PBTC_COEXIST pBtCoexist,RT_MEDIA_STATUS mediaStatus)3658 void EXhalbtcoutsrc_media_status_notify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
3659 {
3660 	u8 mStatus = BTC_MEDIA_MAX;
3661 	PADAPTER adapter = NULL;
3662 	HAL_DATA_TYPE *hal = NULL;
3663 
3664 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3665 		return;
3666 
3667 	if (pBtCoexist->manual_control)
3668 		return;
3669 
3670 	pBtCoexist->statistics.cnt_media_status_notify++;
3671 	adapter = (PADAPTER)pBtCoexist->Adapter;
3672 	hal = GET_HAL_DATA(adapter);
3673 
3674 	if (RT_MEDIA_CONNECT == mediaStatus) {
3675 		if (hal->current_band_type == BAND_ON_2_4G)
3676 			mStatus = BTC_MEDIA_CONNECT;
3677 		else if (hal->current_band_type == BAND_ON_5G)
3678 			mStatus = BTC_MEDIA_CONNECT_5G;
3679 		else {
3680 			mStatus = BTC_MEDIA_CONNECT;
3681 			RTW_ERR("%s unknow band type\n", __func__);
3682 		}
3683 	} else
3684 		mStatus = BTC_MEDIA_DISCONNECT;
3685 
3686 	/* All notify is called in cmd thread, don't need to leave low power again
3687 	*	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3688 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
3689 	rtw_btc_ex_media_status_notify(pBtCoexist, mStatus);
3690 #else
3691 
3692 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3693 #ifdef CONFIG_RTL8821A
3694 		/* compatible for 8821A */
3695 		if (mStatus == BTC_MEDIA_CONNECT_5G)
3696 			mStatus = BTC_MEDIA_CONNECT;
3697 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3698 			ex_halbtc8821a2ant_media_status_notify(pBtCoexist, mStatus);
3699 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3700 			ex_halbtc8821a1ant_media_status_notify(pBtCoexist, mStatus);
3701 #endif
3702 	}
3703 
3704 #ifdef CONFIG_RTL8723B
3705 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3706 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3707 			ex_halbtc8723b2ant_media_status_notify(pBtCoexist, mStatus);
3708 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3709 			ex_halbtc8723b1ant_media_status_notify(pBtCoexist, mStatus);
3710 	}
3711 #endif
3712 
3713 #ifdef CONFIG_RTL8703B
3714 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3715 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3716 			ex_halbtc8703b1ant_media_status_notify(pBtCoexist, mStatus);
3717 	}
3718 #endif
3719 
3720 #ifdef CONFIG_RTL8723D
3721 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3722 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3723 			ex_halbtc8723d2ant_media_status_notify(pBtCoexist, mStatus);
3724 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3725 			ex_halbtc8723d1ant_media_status_notify(pBtCoexist, mStatus);
3726 	}
3727 #endif
3728 
3729 #ifdef CONFIG_RTL8192E
3730 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3731 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3732 			ex_halbtc8192e2ant_media_status_notify(pBtCoexist, mStatus);
3733 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3734 			ex_halbtc8192e1ant_media_status_notify(pBtCoexist, mStatus);
3735 	}
3736 #endif
3737 
3738 #ifdef CONFIG_RTL8812A
3739 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3740 		/* compatible for 8812A */
3741 		if (mStatus == BTC_MEDIA_CONNECT_5G)
3742 			mStatus = BTC_MEDIA_CONNECT;
3743 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3744 			ex_halbtc8812a2ant_media_status_notify(pBtCoexist, mStatus);
3745 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3746 			ex_halbtc8812a1ant_media_status_notify(pBtCoexist, mStatus);
3747 	}
3748 #endif
3749 
3750 #ifdef CONFIG_RTL8822B
3751 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3752 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3753 			ex_halbtc8822b1ant_media_status_notify(pBtCoexist, mStatus);
3754 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
3755 			ex_halbtc8822b2ant_media_status_notify(pBtCoexist, mStatus);
3756 	}
3757 #endif
3758 
3759 #ifdef CONFIG_RTL8821C
3760 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3761 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3762 			ex_halbtc8821c2ant_media_status_notify(pBtCoexist, mStatus);
3763 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3764 			ex_halbtc8821c1ant_media_status_notify(pBtCoexist, mStatus);
3765 	}
3766 #endif
3767 
3768 #ifdef CONFIG_RTL8814A
3769 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
3770 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3771 			ex_halbtc8814a2ant_media_status_notify(pBtCoexist, mStatus);
3772 	}
3773 #endif
3774 
3775 #endif
3776 
3777 	/*	halbtcoutsrc_NormalLowPower(pBtCoexist); */
3778 }
3779 
EXhalbtcoutsrc_specific_packet_notify(PBTC_COEXIST pBtCoexist,u8 pktType)3780 void EXhalbtcoutsrc_specific_packet_notify(PBTC_COEXIST pBtCoexist, u8 pktType)
3781 {
3782 	u8 packetType;
3783 	PADAPTER adapter = NULL;
3784 	HAL_DATA_TYPE *hal = NULL;
3785 
3786 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3787 		return;
3788 
3789 	if (pBtCoexist->manual_control)
3790 		return;
3791 
3792 	pBtCoexist->statistics.cnt_specific_packet_notify++;
3793 	adapter = (PADAPTER)pBtCoexist->Adapter;
3794 	hal = GET_HAL_DATA(adapter);
3795 
3796 	if (PACKET_DHCP == pktType)
3797 		packetType = BTC_PACKET_DHCP;
3798 	else if (PACKET_EAPOL == pktType)
3799 		packetType = BTC_PACKET_EAPOL;
3800 	else if (PACKET_ARP == pktType)
3801 		packetType = BTC_PACKET_ARP;
3802 	else {
3803 		packetType = BTC_PACKET_UNKNOWN;
3804 		return;
3805 	}
3806 
3807 	if (hal->current_band_type == BAND_ON_5G)
3808 		packetType |=  BTC_5G_BAND;
3809 
3810 	/* All notify is called in cmd thread, don't need to leave low power again
3811 	*	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3812 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
3813 	rtw_btc_ex_specific_packet_notify(pBtCoexist, packetType);
3814 #else
3815 
3816 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3817 #ifdef CONFIG_RTL8821A
3818 		/* compatible for 8821A */
3819 		if (hal->current_band_type == BAND_ON_5G)
3820 			packetType &= ~BTC_5G_BAND;
3821 
3822 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3823 			ex_halbtc8821a2ant_specific_packet_notify(pBtCoexist, packetType);
3824 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3825 			ex_halbtc8821a1ant_specific_packet_notify(pBtCoexist, packetType);
3826 #endif
3827 	}
3828 
3829 #ifdef CONFIG_RTL8723B
3830 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3831 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3832 			ex_halbtc8723b2ant_specific_packet_notify(pBtCoexist, packetType);
3833 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3834 			ex_halbtc8723b1ant_specific_packet_notify(pBtCoexist, packetType);
3835 	}
3836 #endif
3837 
3838 #ifdef CONFIG_RTL8703B
3839 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3840 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3841 			ex_halbtc8703b1ant_specific_packet_notify(pBtCoexist, packetType);
3842 	}
3843 #endif
3844 
3845 #ifdef CONFIG_RTL8723D
3846 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3847 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3848 			ex_halbtc8723d2ant_specific_packet_notify(pBtCoexist, packetType);
3849 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3850 			ex_halbtc8723d1ant_specific_packet_notify(pBtCoexist, packetType);
3851 	}
3852 #endif
3853 
3854 #ifdef CONFIG_RTL8192E
3855 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3856 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3857 			ex_halbtc8192e2ant_specific_packet_notify(pBtCoexist, packetType);
3858 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3859 			ex_halbtc8192e1ant_specific_packet_notify(pBtCoexist, packetType);
3860 	}
3861 #endif
3862 
3863 #ifdef CONFIG_RTL8812A
3864 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3865 		/* compatible for 8812A */
3866 		if (hal->current_band_type == BAND_ON_5G)
3867 			packetType &= ~BTC_5G_BAND;
3868 
3869 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3870 			ex_halbtc8812a2ant_specific_packet_notify(pBtCoexist, packetType);
3871 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3872 			ex_halbtc8812a1ant_specific_packet_notify(pBtCoexist, packetType);
3873 	}
3874 #endif
3875 
3876 #ifdef CONFIG_RTL8822B
3877 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3878 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3879 			ex_halbtc8822b1ant_specific_packet_notify(pBtCoexist, packetType);
3880 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
3881 			ex_halbtc8822b2ant_specific_packet_notify(pBtCoexist, packetType);
3882 	}
3883 #endif
3884 
3885 #ifdef CONFIG_RTL8821C
3886 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3887 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3888 			ex_halbtc8821c2ant_specific_packet_notify(pBtCoexist, packetType);
3889 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3890 			ex_halbtc8821c1ant_specific_packet_notify(pBtCoexist, packetType);
3891 	}
3892 #endif
3893 
3894 #ifdef CONFIG_RTL8814A
3895 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
3896 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3897 			ex_halbtc8814a2ant_specific_packet_notify(pBtCoexist, packetType);
3898 	}
3899 #endif
3900 
3901 #endif
3902 
3903 	/*	halbtcoutsrc_NormalLowPower(pBtCoexist); */
3904 }
3905 
EXhalbtcoutsrc_bt_info_notify(PBTC_COEXIST pBtCoexist,u8 * tmpBuf,u8 length)3906 void EXhalbtcoutsrc_bt_info_notify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
3907 {
3908 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3909 		return;
3910 
3911 	pBtCoexist->statistics.cnt_bt_info_notify++;
3912 
3913 	/* All notify is called in cmd thread, don't need to leave low power again
3914 	*	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3915 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
3916 	rtw_btc_ex_bt_info_notify(pBtCoexist, tmpBuf, length);
3917 #else
3918 
3919 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3920 #ifdef CONFIG_RTL8821A
3921 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3922 			ex_halbtc8821a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3923 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3924 			ex_halbtc8821a1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3925 #endif
3926 	}
3927 
3928 #ifdef CONFIG_RTL8723B
3929 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3930 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3931 			ex_halbtc8723b2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3932 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3933 			ex_halbtc8723b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3934 	}
3935 #endif
3936 
3937 #ifdef CONFIG_RTL8703B
3938 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3939 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3940 			ex_halbtc8703b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3941 	}
3942 #endif
3943 
3944 #ifdef CONFIG_RTL8723D
3945 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3946 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3947 			ex_halbtc8723d2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3948 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3949 			ex_halbtc8723d1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3950 	}
3951 #endif
3952 
3953 #ifdef CONFIG_RTL8192E
3954 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3955 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3956 			ex_halbtc8192e2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3957 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3958 			ex_halbtc8192e1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3959 	}
3960 #endif
3961 
3962 #ifdef CONFIG_RTL8812A
3963 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3964 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3965 			ex_halbtc8812a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3966 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3967 			ex_halbtc8812a1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3968 	}
3969 #endif
3970 
3971 #ifdef CONFIG_RTL8822B
3972 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3973 		if (pBtCoexist->board_info.btdm_ant_num == 1)
3974 			ex_halbtc8822b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3975 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
3976 			ex_halbtc8822b2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3977 	}
3978 #endif
3979 
3980 #ifdef CONFIG_RTL8821C
3981 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3982 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3983 			ex_halbtc8821c2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3984 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
3985 			ex_halbtc8821c1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3986 	}
3987 #endif
3988 
3989 #ifdef CONFIG_RTL8814A
3990 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
3991 		if (pBtCoexist->board_info.btdm_ant_num == 2)
3992 			ex_halbtc8814a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3993 	}
3994 #endif
3995 
3996 #endif
3997 
3998 	/*	halbtcoutsrc_NormalLowPower(pBtCoexist); */
3999 }
4000 
EXhalbtcoutsrc_WlFwDbgInfoNotify(PBTC_COEXIST pBtCoexist,u8 * tmpBuf,u8 length)4001 void EXhalbtcoutsrc_WlFwDbgInfoNotify(PBTC_COEXIST pBtCoexist, u8* tmpBuf, u8 length)
4002 {
4003 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4004 		return;
4005 
4006 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
4007 	rtw_btc_ex_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
4008 #else
4009 
4010 	if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
4011 #ifdef CONFIG_RTL8703B
4012 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4013 			ex_halbtc8703b1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
4014 #endif
4015 	}
4016 
4017 #ifdef CONFIG_RTL8723D
4018 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
4019 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4020 			ex_halbtc8723d1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
4021 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4022 			ex_halbtc8723d2ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
4023 	}
4024 #endif
4025 
4026 #ifdef CONFIG_RTL8821C
4027 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
4028 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4029 			ex_halbtc8821c2ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
4030 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4031 			ex_halbtc8821c1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);
4032 	}
4033 #endif
4034 
4035 #endif
4036 }
4037 
EXhalbtcoutsrc_rx_rate_change_notify(PBTC_COEXIST pBtCoexist,u8 is_data_frame,u8 btc_rate_id)4038 void EXhalbtcoutsrc_rx_rate_change_notify(PBTC_COEXIST pBtCoexist, u8 is_data_frame, u8 btc_rate_id)
4039 {
4040 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4041 		return;
4042 
4043 	pBtCoexist->statistics.cnt_rate_id_notify++;
4044 
4045 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
4046 	rtw_btc_ex_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
4047 #else
4048 
4049 	if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
4050 #ifdef CONFIG_RTL8703B
4051 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4052 			ex_halbtc8703b1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
4053 #endif
4054 	}
4055 
4056 #ifdef CONFIG_RTL8723D
4057 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
4058 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4059 			ex_halbtc8723d1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
4060 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4061 			ex_halbtc8723d2ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
4062 	}
4063 #endif
4064 
4065 #ifdef CONFIG_RTL8821C
4066 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
4067 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4068 			ex_halbtc8821c1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
4069 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4070 			ex_halbtc8821c2ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);
4071 	}
4072 #endif
4073 
4074 #endif
4075 }
4076 
4077 void
EXhalbtcoutsrc_RfStatusNotify(PBTC_COEXIST pBtCoexist,u8 type)4078 EXhalbtcoutsrc_RfStatusNotify(
4079 		PBTC_COEXIST		pBtCoexist,
4080 		u8				type
4081 )
4082 {
4083 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4084 		return;
4085 	pBtCoexist->statistics.cnt_rf_status_notify++;
4086 
4087 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
4088 	rtw_btc_ex_rf_status_notify(pBtCoexist, type);
4089 #else
4090 
4091 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
4092 #ifdef CONFIG_RTL8723B
4093 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4094 			ex_halbtc8723b1ant_rf_status_notify(pBtCoexist, type);
4095 #endif
4096 	}
4097 
4098 #ifdef CONFIG_RTL8703B
4099 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
4100 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4101 			ex_halbtc8703b1ant_rf_status_notify(pBtCoexist, type);
4102 	}
4103 #endif
4104 
4105 #ifdef CONFIG_RTL8723D
4106 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
4107 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4108 			ex_halbtc8723d1ant_rf_status_notify(pBtCoexist, type);
4109 	}
4110 #endif
4111 
4112 #ifdef CONFIG_RTL8822B
4113 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
4114 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4115 			ex_halbtc8822b1ant_rf_status_notify(pBtCoexist, type);
4116 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4117 			ex_halbtc8822b2ant_rf_status_notify(pBtCoexist, type);
4118 	}
4119 #endif
4120 
4121 #ifdef CONFIG_RTL8821C
4122 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
4123 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4124 			ex_halbtc8821c2ant_rf_status_notify(pBtCoexist, type);
4125 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4126 			ex_halbtc8821c1ant_rf_status_notify(pBtCoexist, type);
4127 	}
4128 #endif
4129 
4130 #ifdef CONFIG_RTL8814A
4131 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
4132 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4133 			ex_halbtc8814a2ant_rf_status_notify(pBtCoexist, type);
4134 	}
4135 #endif
4136 
4137 #endif
4138 }
4139 
EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist,u8 type)4140 void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)
4141 {
4142 #if 0
4143 	u8	stackOpType;
4144 
4145 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4146 		return;
4147 	pBtCoexist->statistics.cntStackOperationNotify++;
4148 	if (pBtCoexist->manual_control)
4149 		return;
4150 
4151 	if ((HCI_BT_OP_INQUIRY_START == type) ||
4152 	    (HCI_BT_OP_PAGING_START == type) ||
4153 	    (HCI_BT_OP_PAIRING_START == type))
4154 		stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START;
4155 	else if ((HCI_BT_OP_INQUIRY_FINISH == type) ||
4156 		 (HCI_BT_OP_PAGING_SUCCESS == type) ||
4157 		 (HCI_BT_OP_PAGING_UNSUCCESS == type) ||
4158 		 (HCI_BT_OP_PAIRING_FINISH == type))
4159 		stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
4160 	else
4161 		stackOpType = BTC_STACK_OP_NONE;
4162 
4163 #endif
4164 }
4165 
EXhalbtcoutsrc_halt_notify(PBTC_COEXIST pBtCoexist)4166 void EXhalbtcoutsrc_halt_notify(PBTC_COEXIST pBtCoexist)
4167 {
4168 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4169 		return;
4170 
4171 	pBtCoexist->statistics.cnt_halt_notify++;
4172 
4173 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
4174 	rtw_btc_ex_halt_notify(pBtCoexist);
4175 #else
4176 
4177 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
4178 #ifdef CONFIG_RTL8821A
4179 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4180 			ex_halbtc8821a2ant_halt_notify(pBtCoexist);
4181 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4182 			ex_halbtc8821a1ant_halt_notify(pBtCoexist);
4183 #endif
4184 	}
4185 
4186 #ifdef CONFIG_RTL8723B
4187 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
4188 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4189 			ex_halbtc8723b2ant_halt_notify(pBtCoexist);
4190 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4191 			ex_halbtc8723b1ant_halt_notify(pBtCoexist);
4192 	}
4193 #endif
4194 
4195 #ifdef CONFIG_RTL8703B
4196 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
4197 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4198 			ex_halbtc8703b1ant_halt_notify(pBtCoexist);
4199 	}
4200 #endif
4201 
4202 #ifdef CONFIG_RTL8723D
4203 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
4204 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4205 			ex_halbtc8723d2ant_halt_notify(pBtCoexist);
4206 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4207 			ex_halbtc8723d1ant_halt_notify(pBtCoexist);
4208 	}
4209 #endif
4210 
4211 #ifdef CONFIG_RTL8192E
4212 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
4213 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4214 			ex_halbtc8192e2ant_halt_notify(pBtCoexist);
4215 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4216 			ex_halbtc8192e1ant_halt_notify(pBtCoexist);
4217 	}
4218 #endif
4219 
4220 #ifdef CONFIG_RTL8812A
4221 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
4222 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4223 			ex_halbtc8812a2ant_halt_notify(pBtCoexist);
4224 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4225 			ex_halbtc8812a1ant_halt_notify(pBtCoexist);
4226 	}
4227 #endif
4228 
4229 #ifdef CONFIG_RTL8822B
4230 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
4231 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4232 			ex_halbtc8822b1ant_halt_notify(pBtCoexist);
4233 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4234 			ex_halbtc8822b2ant_halt_notify(pBtCoexist);
4235 	}
4236 #endif
4237 
4238 #ifdef CONFIG_RTL8821C
4239 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
4240 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4241 			ex_halbtc8821c2ant_halt_notify(pBtCoexist);
4242 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4243 			ex_halbtc8821c1ant_halt_notify(pBtCoexist);
4244 	}
4245 #endif
4246 
4247 #ifdef CONFIG_RTL8814A
4248 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
4249 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4250 			ex_halbtc8814a2ant_halt_notify(pBtCoexist);
4251 	}
4252 #endif
4253 
4254 #endif
4255 }
4256 
EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)4257 void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)
4258 {
4259 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
4260 		if (pBtCoexist->board_info.btdm_ant_num == 2) {
4261 			halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); /* BT goto standby while GNT_BT 1-->0 */
4262 		} else if (pBtCoexist->board_info.btdm_ant_num == 1) {
4263 			halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); /* BT goto standby while GNT_BT 1-->0 */
4264 		}
4265 	}
4266 }
4267 
EXhalbtcoutsrc_pnp_notify(PBTC_COEXIST pBtCoexist,u8 pnpState)4268 void EXhalbtcoutsrc_pnp_notify(PBTC_COEXIST pBtCoexist, u8 pnpState)
4269 {
4270 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4271 		return;
4272 
4273 	pBtCoexist->statistics.cnt_pnp_notify++;
4274 
4275 	/*  */
4276 	/* currently only 1ant we have to do the notification, */
4277 	/* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */
4278 	/*  */
4279 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
4280 	rtw_btc_ex_pnp_notify(pBtCoexist, pnpState);
4281 #else
4282 
4283 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
4284 #ifdef CONFIG_RTL8723B
4285 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4286 			ex_halbtc8723b1ant_pnp_notify(pBtCoexist, pnpState);
4287 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4288 			ex_halbtc8723b2ant_pnp_notify(pBtCoexist, pnpState);
4289 #endif
4290 	}
4291 
4292 #ifdef CONFIG_RTL8703B
4293 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
4294 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4295 			ex_halbtc8703b1ant_pnp_notify(pBtCoexist, pnpState);
4296 	}
4297 #endif
4298 
4299 #ifdef CONFIG_RTL8723D
4300 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
4301 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4302 			ex_halbtc8723d1ant_pnp_notify(pBtCoexist, pnpState);
4303 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4304 			ex_halbtc8723d2ant_pnp_notify(pBtCoexist, pnpState);
4305 	}
4306 #endif
4307 
4308 #ifdef CONFIG_RTL8821A
4309 	else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
4310 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4311 			ex_halbtc8821a1ant_pnp_notify(pBtCoexist, pnpState);
4312 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4313 			ex_halbtc8821a2ant_pnp_notify(pBtCoexist, pnpState);
4314 	}
4315 #endif
4316 
4317 #ifdef CONFIG_RTL8192E
4318 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
4319 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4320 			ex_halbtc8192e1ant_pnp_notify(pBtCoexist, pnpState);
4321 	}
4322 #endif
4323 
4324 #ifdef CONFIG_RTL8812A
4325 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
4326 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4327 			ex_halbtc8812a1ant_pnp_notify(pBtCoexist, pnpState);
4328 	}
4329 #endif
4330 
4331 #ifdef CONFIG_RTL8822B
4332 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
4333 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4334 			ex_halbtc8822b1ant_pnp_notify(pBtCoexist, pnpState);
4335 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4336 			ex_halbtc8822b2ant_pnp_notify(pBtCoexist, pnpState);
4337 	}
4338 #endif
4339 
4340 #ifdef CONFIG_RTL8821C
4341 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
4342 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4343 			ex_halbtc8821c2ant_pnp_notify(pBtCoexist, pnpState);
4344 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4345 			ex_halbtc8821c1ant_pnp_notify(pBtCoexist, pnpState);
4346 	}
4347 #endif
4348 
4349 #ifdef CONFIG_RTL8814A
4350 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
4351 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4352 			ex_halbtc8814a2ant_pnp_notify(pBtCoexist, pnpState);
4353 	}
4354 #endif
4355 
4356 #endif
4357 }
4358 
EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)4359 void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)
4360 {
4361 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4362 		return;
4363 	pBtCoexist->statistics.cnt_coex_dm_switch++;
4364 
4365 	halbtcoutsrc_LeaveLowPower(pBtCoexist);
4366 
4367 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
4368 #ifdef CONFIG_RTL8723B
4369 		if (pBtCoexist->board_info.btdm_ant_num == 1) {
4370 			pBtCoexist->stop_coex_dm = TRUE;
4371 			ex_halbtc8723b1ant_coex_dm_reset(pBtCoexist);
4372 			EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
4373 			ex_halbtc8723b2ant_init_hw_config(pBtCoexist, FALSE);
4374 			ex_halbtc8723b2ant_init_coex_dm(pBtCoexist);
4375 			pBtCoexist->stop_coex_dm = FALSE;
4376 		}
4377 #endif
4378 	}
4379 
4380 #ifdef CONFIG_RTL8723D
4381 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
4382 		if (pBtCoexist->board_info.btdm_ant_num == 1) {
4383 			pBtCoexist->stop_coex_dm = TRUE;
4384 			ex_halbtc8723d1ant_coex_dm_reset(pBtCoexist);
4385 			EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
4386 			ex_halbtc8723d2ant_init_hw_config(pBtCoexist, FALSE);
4387 			ex_halbtc8723d2ant_init_coex_dm(pBtCoexist);
4388 			pBtCoexist->stop_coex_dm = FALSE;
4389 		}
4390 	}
4391 #endif
4392 
4393 	halbtcoutsrc_NormalLowPower(pBtCoexist);
4394 }
4395 
4396 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
EXhalbtcoutsrc_TimerNotify(PBTC_COEXIST pBtCoexist,u32 timer_type)4397 void EXhalbtcoutsrc_TimerNotify(PBTC_COEXIST pBtCoexist, u32 timer_type)
4398 {
4399 	rtw_btc_ex_timerup_notify(pBtCoexist, timer_type);
4400 }
4401 
EXhalbtcoutsrc_WLStatusChangeNotify(PBTC_COEXIST pBtCoexist,u32 change_type)4402 void EXhalbtcoutsrc_WLStatusChangeNotify(PBTC_COEXIST pBtCoexist, u32 change_type)
4403 {
4404 	rtw_btc_ex_wl_status_change_notify(pBtCoexist, change_type);
4405 }
4406 
EXhalbtcoutsrc_CoexTimerCheck(PBTC_COEXIST pBtCoexist)4407 u32 EXhalbtcoutsrc_CoexTimerCheck(PBTC_COEXIST pBtCoexist)
4408 {
4409 	u32 i, timer_map = 0;
4410 
4411 	for (i = 0; i < BTC_TIMER_MAX; i++) {
4412 		if (pBtCoexist->coex_sta.cnt_timer[i] > 0) {
4413 			if (pBtCoexist->coex_sta.cnt_timer[i] == 1) {
4414 				timer_map |= BIT(i);
4415 				RTW_DBG("[BTC], %s(): timer_map = 0x%x\n", __func__, timer_map);
4416 			}
4417 
4418 			pBtCoexist->coex_sta.cnt_timer[i]--;
4419 		}
4420 	}
4421 
4422 	return timer_map;
4423 }
4424 
EXhalbtcoutsrc_WLStatusCheck(PBTC_COEXIST pBtCoexist)4425 u32 EXhalbtcoutsrc_WLStatusCheck(PBTC_COEXIST pBtCoexist)
4426 {
4427 	struct btc_wifi_link_info link_info;
4428 	const struct btc_chip_para *chip_para = pBtCoexist->chip_para;
4429 	u32 change_map = 0;
4430 	static bool wl_busy_pre;
4431 	bool	wl_busy = _FALSE;
4432 	s32 wl_rssi;
4433 	u32 traffic_dir;
4434 	u8 i, tmp;
4435 	static u8 rssi_step_pre = 4;
4436 
4437 	/* WL busy to idle or idle to busy */
4438 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &wl_busy);
4439 	if (wl_busy != wl_busy_pre) {
4440 		if (wl_busy)
4441 			change_map |=  BIT(BTC_WLSTATUS_CHANGE_TOBUSY);
4442 		else
4443 			change_map |=  BIT(BTC_WLSTATUS_CHANGE_TOIDLE);
4444 
4445 		wl_busy_pre = wl_busy;
4446 	}
4447 
4448 	/* WL RSSI */
4449 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wl_rssi);
4450 	tmp = (u8)(wl_rssi & 0xff);
4451 	for (i = 0; i < 4; i++) {
4452 		if (tmp >= chip_para->wl_rssi_step[i]) {
4453 			if (rssi_step_pre != i) {
4454 				rssi_step_pre = i;
4455 				change_map |=  BIT(BTC_WLSTATUS_CHANGE_RSSI);
4456 			}
4457 			break;
4458 		} else if (i == 3)
4459 			rssi_step_pre = 4;
4460 	}
4461 
4462 	/* WL Link info */
4463 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_LINK_INFO, &link_info);
4464 	if (link_info.link_mode != pBtCoexist->wifi_link_info.link_mode ||
4465 	    link_info.sta_center_channel !=
4466 	    		pBtCoexist->wifi_link_info.sta_center_channel ||
4467 	    link_info.p2p_center_channel !=
4468 	    		pBtCoexist->wifi_link_info.p2p_center_channel ||
4469 	    link_info.bany_client_join_go !=
4470 	    		pBtCoexist->wifi_link_info.bany_client_join_go) {
4471 		change_map |=  BIT(BTC_WLSTATUS_CHANGE_LINKINFO);
4472 		pBtCoexist->wifi_link_info = link_info;
4473 	}
4474 
4475 	/* WL Traffic Direction */
4476 	pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION,
4477 			    &traffic_dir);
4478 	if (wl_busy && traffic_dir !=
4479 			pBtCoexist->wifi_link_info_ext.traffic_dir) {
4480 		change_map |=  BIT(BTC_WLSTATUS_CHANGE_DIRECTION);
4481 		pBtCoexist->wifi_link_info_ext.traffic_dir = traffic_dir;
4482 	}
4483 
4484 	RTW_DBG("[BTC], %s(): change_map = 0x%x\n", __func__, change_map);
4485 
4486 	return change_map;
4487 }
4488 
EXhalbtcoutsrc_status_monitor(PBTC_COEXIST pBtCoexist)4489 void EXhalbtcoutsrc_status_monitor(PBTC_COEXIST pBtCoexist)
4490 {
4491 	u32 timer_up_type = 0, wl_status_change_type = 0;
4492 
4493 	timer_up_type = EXhalbtcoutsrc_CoexTimerCheck(pBtCoexist);
4494 	if (timer_up_type != 0)
4495 		EXhalbtcoutsrc_TimerNotify(pBtCoexist, timer_up_type);
4496 
4497 	wl_status_change_type =  EXhalbtcoutsrc_WLStatusCheck(pBtCoexist);
4498 	if (wl_status_change_type != 0)
4499 		EXhalbtcoutsrc_WLStatusChangeNotify(pBtCoexist, wl_status_change_type);
4500 
4501 	rtw_btc_ex_periodical(pBtCoexist);
4502 }
4503 #endif
4504 
EXhalbtcoutsrc_periodical(PBTC_COEXIST pBtCoexist)4505 void EXhalbtcoutsrc_periodical(PBTC_COEXIST pBtCoexist)
4506 {
4507 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4508 		return;
4509 	pBtCoexist->statistics.cnt_periodical++;
4510 
4511 	/* Periodical should be called in cmd thread, */
4512 	/* don't need to leave low power again
4513 	*	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
4514 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
4515 	EXhalbtcoutsrc_status_monitor(pBtCoexist);
4516 #else
4517 
4518 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
4519 #ifdef CONFIG_RTL8821A
4520 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4521 			ex_halbtc8821a2ant_periodical(pBtCoexist);
4522 		else if (pBtCoexist->board_info.btdm_ant_num == 1) {
4523 			if (!halbtcoutsrc_UnderIps(pBtCoexist))
4524 				ex_halbtc8821a1ant_periodical(pBtCoexist);
4525 		}
4526 #endif
4527 	}
4528 
4529 #ifdef CONFIG_RTL8723B
4530 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
4531 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4532 			ex_halbtc8723b2ant_periodical(pBtCoexist);
4533 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4534 			ex_halbtc8723b1ant_periodical(pBtCoexist);
4535 	}
4536 #endif
4537 
4538 #ifdef CONFIG_RTL8723D
4539 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
4540 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4541 			ex_halbtc8723d2ant_periodical(pBtCoexist);
4542 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4543 			ex_halbtc8723d1ant_periodical(pBtCoexist);
4544 	}
4545 #endif
4546 
4547 #ifdef CONFIG_RTL8703B
4548 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
4549 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4550 			ex_halbtc8703b1ant_periodical(pBtCoexist);
4551 	}
4552 #endif
4553 
4554 #ifdef CONFIG_RTL8192E
4555 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
4556 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4557 			ex_halbtc8192e2ant_periodical(pBtCoexist);
4558 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4559 			ex_halbtc8192e1ant_periodical(pBtCoexist);
4560 	}
4561 #endif
4562 
4563 #ifdef CONFIG_RTL8812A
4564 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
4565 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4566 			ex_halbtc8812a2ant_periodical(pBtCoexist);
4567 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4568 			ex_halbtc8812a1ant_periodical(pBtCoexist);
4569 	}
4570 #endif
4571 
4572 #ifdef CONFIG_RTL8822B
4573 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
4574 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4575 			ex_halbtc8822b1ant_periodical(pBtCoexist);
4576 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4577 			ex_halbtc8822b2ant_periodical(pBtCoexist);
4578 	}
4579 #endif
4580 
4581 #ifdef CONFIG_RTL8821C
4582 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
4583 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4584 			ex_halbtc8821c2ant_periodical(pBtCoexist);
4585 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4586 			ex_halbtc8821c1ant_periodical(pBtCoexist);
4587 	}
4588 #endif
4589 
4590 #ifdef CONFIG_RTL8814A
4591 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
4592 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4593 			ex_halbtc8814a2ant_periodical(pBtCoexist);
4594 	}
4595 #endif
4596 
4597 #endif
4598 
4599 	/*	halbtcoutsrc_NormalLowPower(pBtCoexist); */
4600 }
4601 
EXhalbtcoutsrc_dbg_control(PBTC_COEXIST pBtCoexist,u8 opCode,u8 opLen,u8 * pData)4602 void EXhalbtcoutsrc_dbg_control(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)
4603 {
4604 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4605 		return;
4606 
4607 	pBtCoexist->statistics.cnt_dbg_ctrl++;
4608 
4609 	/* This function doesn't be called yet, */
4610 	/* default no need to leave low power to avoid deadlock
4611 	*	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
4612 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
4613 	/* rtw_btc_ex_dbg_control(pBtCoexist, opCode, opLen, pData); */
4614 #else
4615 
4616 	if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
4617 #ifdef CONFIG_RTL8192E
4618 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4619 			ex_halbtc8192e1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
4620 #endif
4621 	}
4622 
4623 #ifdef CONFIG_RTL8812A
4624 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
4625 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4626 			ex_halbtc8812a2ant_dbg_control(pBtCoexist, opCode, opLen, pData);
4627 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4628 			ex_halbtc8812a1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
4629 	}
4630 #endif
4631 
4632 #ifdef CONFIG_RTL8822B
4633 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter))
4634 		if(pBtCoexist->board_info.btdm_ant_num == 1)
4635 			ex_halbtc8822b1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
4636 #endif
4637 
4638 #endif
4639 
4640 	/*	halbtcoutsrc_NormalLowPower(pBtCoexist); */
4641 }
4642 
4643 #if 0
4644 void
4645 EXhalbtcoutsrc_AntennaDetection(
4646 		PBTC_COEXIST			pBtCoexist,
4647 		u32					centFreq,
4648 		u32					offset,
4649 		u32					span,
4650 		u32					seconds
4651 )
4652 {
4653 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4654 		return;
4655 
4656 	/* Need to refine the following power save operations to enable this function in the future */
4657 #if 0
4658 	IPSDisable(pBtCoexist->Adapter, FALSE, 0);
4659 	LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);
4660 #endif
4661 
4662 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
4663 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4664 			ex_halbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds);
4665 	}
4666 
4667 	/* IPSReturn(pBtCoexist->Adapter, 0xff); */
4668 }
4669 #endif
4670 
EXhalbtcoutsrc_StackUpdateProfileInfo(void)4671 void EXhalbtcoutsrc_StackUpdateProfileInfo(void)
4672 {
4673 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
4674 	PBTC_COEXIST pBtCoexist = &GLBtCoexist;
4675 	PADAPTER padapter = NULL;
4676 	PBT_MGNT pBtMgnt = NULL;
4677 	u8 i;
4678 
4679 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4680 		return;
4681 
4682 	padapter = (PADAPTER)pBtCoexist->Adapter;
4683 	pBtMgnt = &padapter->coex_info.BtMgnt;
4684 
4685 	pBtCoexist->stack_info.profile_notified = _TRUE;
4686 
4687 	pBtCoexist->stack_info.num_of_link =
4688 		pBtMgnt->ExtConfig.NumberOfACL + pBtMgnt->ExtConfig.NumberOfSCO;
4689 
4690 	/* reset first */
4691 	pBtCoexist->stack_info.bt_link_exist = _FALSE;
4692 	pBtCoexist->stack_info.sco_exist = _FALSE;
4693 	pBtCoexist->stack_info.acl_exist = _FALSE;
4694 	pBtCoexist->stack_info.a2dp_exist = _FALSE;
4695 	pBtCoexist->stack_info.hid_exist = _FALSE;
4696 	pBtCoexist->stack_info.num_of_hid = 0;
4697 	pBtCoexist->stack_info.pan_exist = _FALSE;
4698 
4699 	if (!pBtMgnt->ExtConfig.NumberOfACL)
4700 		pBtCoexist->stack_info.min_bt_rssi = 0;
4701 
4702 	if (pBtCoexist->stack_info.num_of_link) {
4703 		pBtCoexist->stack_info.bt_link_exist = _TRUE;
4704 		if (pBtMgnt->ExtConfig.NumberOfSCO)
4705 			pBtCoexist->stack_info.sco_exist = _TRUE;
4706 		if (pBtMgnt->ExtConfig.NumberOfACL)
4707 			pBtCoexist->stack_info.acl_exist = _TRUE;
4708 	}
4709 
4710 	for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {
4711 		if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
4712 			pBtCoexist->stack_info.a2dp_exist = _TRUE;
4713 		else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
4714 			pBtCoexist->stack_info.pan_exist = _TRUE;
4715 		else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile) {
4716 			pBtCoexist->stack_info.hid_exist = _TRUE;
4717 			pBtCoexist->stack_info.num_of_hid++;
4718 		} else
4719 			pBtCoexist->stack_info.unknown_acl_exist = _TRUE;
4720 	}
4721 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
4722 }
4723 
EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)4724 void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)
4725 {
4726 	PBTC_COEXIST pBtCoexist = &GLBtCoexist;
4727 
4728 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4729 		return;
4730 
4731 	pBtCoexist->stack_info.min_bt_rssi = btRssi;
4732 }
4733 
EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)4734 void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)
4735 {
4736 	PBTC_COEXIST pBtCoexist = &GLBtCoexist;
4737 
4738 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4739 		return;
4740 
4741 	pBtCoexist->stack_info.hci_version = hciVersion;
4742 }
4743 
EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion,u16 btPatchVersion)4744 void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)
4745 {
4746 	PBTC_COEXIST pBtCoexist = &GLBtCoexist;
4747 
4748 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4749 		return;
4750 
4751 	pBtCoexist->bt_info.bt_real_fw_ver = btPatchVersion;
4752 	pBtCoexist->bt_info.bt_hci_ver = btHciVersion;
4753 }
4754 
4755 #if 0
4756 void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)
4757 {
4758 	GLBtCoexist.boardInfo.bBtExist = bBtExist;
4759 }
4760 #endif
EXhalbtcoutsrc_SetChipType(u8 chipType)4761 void EXhalbtcoutsrc_SetChipType(u8 chipType)
4762 {
4763 	switch (chipType) {
4764 	default:
4765 	case BT_2WIRE:
4766 	case BT_ISSC_3WIRE:
4767 	case BT_ACCEL:
4768 	case BT_RTL8756:
4769 		GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
4770 		break;
4771 	case BT_CSR_BC4:
4772 		GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
4773 		break;
4774 	case BT_CSR_BC8:
4775 		GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
4776 		break;
4777 	case BT_RTL8723A:
4778 		GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
4779 		break;
4780 	case BT_RTL8821:
4781 		GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
4782 		break;
4783 	case BT_RTL8723B:
4784 		GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
4785 		break;
4786 	}
4787 }
4788 
EXhalbtcoutsrc_SetAntNum(u8 type,u8 antNum)4789 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
4790 {
4791 	if (BT_COEX_ANT_TYPE_PG == type) {
4792 		GLBtCoexist.board_info.pg_ant_num = antNum;
4793 		GLBtCoexist.board_info.btdm_ant_num = antNum;
4794 #if 0
4795 		/* The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1 */
4796 		/* The antenna position should be determined by auto-detect mechanism */
4797 		/* The following is assumed to main, and those must be modified if y auto-detect mechanism is ready */
4798 		if ((GLBtCoexist.board_info.pg_ant_num == 2) && (GLBtCoexist.board_info.btdm_ant_num == 1))
4799 			GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
4800 		else
4801 			GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
4802 #endif
4803 	} else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
4804 		GLBtCoexist.board_info.btdm_ant_num = antNum;
4805 		/* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;	 */
4806 	} else if (BT_COEX_ANT_TYPE_DETECTED == type) {
4807 		GLBtCoexist.board_info.btdm_ant_num = antNum;
4808 		/* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
4809 	}
4810 }
4811 
4812 /*
4813  * Currently used by 8723b only, S0 or S1
4814  *   */
EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)4815 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
4816 {
4817 	GLBtCoexist.board_info.single_ant_path = singleAntPath;
4818 }
4819 
EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)4820 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
4821 {
4822 	HAL_DATA_TYPE	*pHalData = NULL;
4823 
4824 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4825 		return;
4826 
4827 	halbtcoutsrc_LeaveLowPower(pBtCoexist);
4828 
4829 	/* To prevent the racing with IPS enter */
4830 	halbtcoutsrc_EnterPwrLock(pBtCoexist);
4831 
4832 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
4833 	pHalData = GET_HAL_DATA((PADAPTER)pBtCoexist->Adapter);
4834 
4835 	if (pHalData->EEPROMBluetoothCoexist == _TRUE)
4836 		rtw_btc_ex_display_coex_info(pBtCoexist);
4837 #else
4838 
4839 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
4840 #ifdef CONFIG_RTL8821A
4841 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4842 			ex_halbtc8821a2ant_display_coex_info(pBtCoexist);
4843 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4844 			ex_halbtc8821a1ant_display_coex_info(pBtCoexist);
4845 #endif
4846 	}
4847 
4848 #ifdef CONFIG_RTL8723B
4849 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
4850 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4851 			ex_halbtc8723b2ant_display_coex_info(pBtCoexist);
4852 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4853 			ex_halbtc8723b1ant_display_coex_info(pBtCoexist);
4854 	}
4855 #endif
4856 
4857 #ifdef CONFIG_RTL8703B
4858 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
4859 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4860 			ex_halbtc8703b1ant_display_coex_info(pBtCoexist);
4861 	}
4862 #endif
4863 
4864 #ifdef CONFIG_RTL8723D
4865 	else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
4866 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4867 			ex_halbtc8723d2ant_display_coex_info(pBtCoexist);
4868 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4869 			ex_halbtc8723d1ant_display_coex_info(pBtCoexist);
4870 	}
4871 #endif
4872 
4873 #ifdef CONFIG_RTL8192E
4874 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
4875 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4876 			ex_halbtc8192e2ant_display_coex_info(pBtCoexist);
4877 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4878 			ex_halbtc8192e1ant_display_coex_info(pBtCoexist);
4879 	}
4880 #endif
4881 
4882 #ifdef CONFIG_RTL8812A
4883 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
4884 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4885 			ex_halbtc8812a2ant_display_coex_info(pBtCoexist);
4886 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4887 			ex_halbtc8812a1ant_display_coex_info(pBtCoexist);
4888 	}
4889 #endif
4890 
4891 #ifdef CONFIG_RTL8822B
4892 	else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
4893 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4894 			ex_halbtc8822b1ant_display_coex_info(pBtCoexist);
4895 		else if (pBtCoexist->board_info.btdm_ant_num == 2)
4896 			ex_halbtc8822b2ant_display_coex_info(pBtCoexist);
4897 	}
4898 #endif
4899 
4900 #ifdef CONFIG_RTL8821C
4901 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
4902 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4903 			ex_halbtc8821c2ant_display_coex_info(pBtCoexist);
4904 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
4905 			ex_halbtc8821c1ant_display_coex_info(pBtCoexist);
4906 	}
4907 #endif
4908 
4909 #ifdef CONFIG_RTL8814A
4910 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
4911 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4912 			ex_halbtc8814a2ant_display_coex_info(pBtCoexist);
4913 	}
4914 #endif
4915 
4916 #endif
4917 
4918 	halbtcoutsrc_ExitPwrLock(pBtCoexist);
4919 
4920 	halbtcoutsrc_NormalLowPower(pBtCoexist);
4921 }
4922 
EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)4923 void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)
4924 {
4925 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4926 		return;
4927 
4928 	halbtcoutsrc_LeaveLowPower(pBtCoexist);
4929 
4930 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
4931 #ifdef CONFIG_RTL8723B
4932 		if (pBtCoexist->board_info.btdm_ant_num == 1)
4933 			ex_halbtc8723b1ant_display_ant_detection(pBtCoexist);
4934 #endif
4935 	}
4936 
4937 	halbtcoutsrc_NormalLowPower(pBtCoexist);
4938 }
4939 
ex_halbtcoutsrc_pta_off_on_notify(PBTC_COEXIST pBtCoexist,u8 bBTON)4940 void ex_halbtcoutsrc_pta_off_on_notify(PBTC_COEXIST pBtCoexist, u8 bBTON)
4941 {
4942 	if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
4943 #ifdef CONFIG_RTL8812A
4944 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4945 			ex_halbtc8812a2ant_pta_off_on_notify(pBtCoexist, (bBTON == _TRUE) ? BTC_BT_ON : BTC_BT_OFF);
4946 #endif
4947 	}
4948 
4949 #ifdef CONFIG_RTL8814A
4950 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
4951 		if (pBtCoexist->board_info.btdm_ant_num == 2)
4952 			ex_halbtc8814a2ant_pta_off_on_notify(pBtCoexist, (bBTON == _TRUE) ? BTC_BT_ON : BTC_BT_OFF);
4953 	}
4954 #endif
4955 }
4956 
EXhalbtcoutsrc_set_rfe_type(u8 type)4957 void EXhalbtcoutsrc_set_rfe_type(u8 type)
4958 {
4959 	GLBtCoexist.board_info.rfe_type= type;
4960 }
4961 
4962 #ifdef CONFIG_RF4CE_COEXIST
EXhalbtcoutsrc_set_rf4ce_link_state(u8 state)4963 void EXhalbtcoutsrc_set_rf4ce_link_state(u8 state)
4964 {
4965 	GLBtCoexist.rf4ce_info.link_state = state;
4966 }
4967 
EXhalbtcoutsrc_get_rf4ce_link_state(void)4968 u8 EXhalbtcoutsrc_get_rf4ce_link_state(void)
4969 {
4970 	return GLBtCoexist.rf4ce_info.link_state;
4971 }
4972 #endif
4973 
EXhalbtcoutsrc_switchband_notify(struct btc_coexist * pBtCoexist,u8 type)4974 void EXhalbtcoutsrc_switchband_notify(struct btc_coexist *pBtCoexist, u8 type)
4975 {
4976 	if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
4977 		return;
4978 
4979 	if(pBtCoexist->manual_control)
4980 		return;
4981 
4982 	/* Driver should guarantee that the HW status isn't in low power mode */
4983 	/* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
4984 #if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)
4985 	rtw_btc_ex_switchband_notify(pBtCoexist, type);
4986 #else
4987 
4988 	if(IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
4989 #ifdef CONFIG_RTL8822B
4990 		if(pBtCoexist->board_info.btdm_ant_num == 1)
4991 			ex_halbtc8822b1ant_switchband_notify(pBtCoexist, type);
4992 		else if(pBtCoexist->board_info.btdm_ant_num == 2)
4993 			ex_halbtc8822b2ant_switchband_notify(pBtCoexist, type);
4994 #endif
4995 	}
4996 
4997 #ifdef CONFIG_RTL8821C
4998 	else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
4999 		if (pBtCoexist->board_info.btdm_ant_num == 2)
5000 			ex_halbtc8821c2ant_switchband_notify(pBtCoexist, type);
5001 		else if (pBtCoexist->board_info.btdm_ant_num == 1)
5002 			ex_halbtc8821c1ant_switchband_notify(pBtCoexist, type);
5003 	}
5004 #endif
5005 
5006 #ifdef CONFIG_RTL8814A
5007 	else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {
5008 		if (pBtCoexist->board_info.btdm_ant_num == 2)
5009 			ex_halbtc8814a2ant_switchband_notify(pBtCoexist, type);
5010 	}
5011 #endif
5012 
5013 #endif
5014 
5015 	/* halbtcoutsrc_NormalLowPower(pBtCoexist); */
5016 }
5017 
EXhalbtcoutsrc_rate_id_to_btc_rate_id(u8 rate_id)5018 u8 EXhalbtcoutsrc_rate_id_to_btc_rate_id(u8 rate_id)
5019 {
5020 	u8 btc_rate_id = BTC_UNKNOWN;
5021 
5022 	switch (rate_id) {
5023 		/* CCK rates */
5024 		case DESC_RATE1M:
5025 			btc_rate_id = BTC_CCK_1;
5026 			break;
5027 		case DESC_RATE2M:
5028 			btc_rate_id = BTC_CCK_2;
5029 			break;
5030 		case DESC_RATE5_5M:
5031 			btc_rate_id = BTC_CCK_5_5;
5032 			break;
5033 		case DESC_RATE11M:
5034 			btc_rate_id = BTC_CCK_11;
5035 			break;
5036 
5037 		/* OFDM rates */
5038 		case DESC_RATE6M:
5039 			btc_rate_id = BTC_OFDM_6;
5040 			break;
5041 		case DESC_RATE9M:
5042 			btc_rate_id = BTC_OFDM_9;
5043 			break;
5044 		case DESC_RATE12M:
5045 			btc_rate_id = BTC_OFDM_12;
5046 			break;
5047 		case DESC_RATE18M:
5048 			btc_rate_id = BTC_OFDM_18;
5049 			break;
5050 		case DESC_RATE24M:
5051 			btc_rate_id = BTC_OFDM_24;
5052 			break;
5053 		case DESC_RATE36M:
5054 			btc_rate_id = BTC_OFDM_36;
5055 			break;
5056 		case DESC_RATE48M:
5057 			btc_rate_id = BTC_OFDM_48;
5058 			break;
5059 		case DESC_RATE54M:
5060 			btc_rate_id = BTC_OFDM_54;
5061 			break;
5062 
5063 		/* MCS rates */
5064 		case DESC_RATEMCS0:
5065 			btc_rate_id = BTC_MCS_0;
5066 			break;
5067 		case DESC_RATEMCS1:
5068 			btc_rate_id = BTC_MCS_1;
5069 			break;
5070 		case DESC_RATEMCS2:
5071 			btc_rate_id = BTC_MCS_2;
5072 			break;
5073 		case DESC_RATEMCS3:
5074 			btc_rate_id = BTC_MCS_3;
5075 			break;
5076 		case DESC_RATEMCS4:
5077 			btc_rate_id = BTC_MCS_4;
5078 			break;
5079 		case DESC_RATEMCS5:
5080 			btc_rate_id = BTC_MCS_5;
5081 			break;
5082 		case DESC_RATEMCS6:
5083 			btc_rate_id = BTC_MCS_6;
5084 			break;
5085 		case DESC_RATEMCS7:
5086 			btc_rate_id = BTC_MCS_7;
5087 			break;
5088 		case DESC_RATEMCS8:
5089 			btc_rate_id = BTC_MCS_8;
5090 			break;
5091 		case DESC_RATEMCS9:
5092 			btc_rate_id = BTC_MCS_9;
5093 			break;
5094 		case DESC_RATEMCS10:
5095 			btc_rate_id = BTC_MCS_10;
5096 			break;
5097 		case DESC_RATEMCS11:
5098 			btc_rate_id = BTC_MCS_11;
5099 			break;
5100 		case DESC_RATEMCS12:
5101 			btc_rate_id = BTC_MCS_12;
5102 			break;
5103 		case DESC_RATEMCS13:
5104 			btc_rate_id = BTC_MCS_13;
5105 			break;
5106 		case DESC_RATEMCS14:
5107 			btc_rate_id = BTC_MCS_14;
5108 			break;
5109 		case DESC_RATEMCS15:
5110 			btc_rate_id = BTC_MCS_15;
5111 			break;
5112 		case DESC_RATEMCS16:
5113 			btc_rate_id = BTC_MCS_16;
5114 			break;
5115 		case DESC_RATEMCS17:
5116 			btc_rate_id = BTC_MCS_17;
5117 			break;
5118 		case DESC_RATEMCS18:
5119 			btc_rate_id = BTC_MCS_18;
5120 			break;
5121 		case DESC_RATEMCS19:
5122 			btc_rate_id = BTC_MCS_19;
5123 			break;
5124 		case DESC_RATEMCS20:
5125 			btc_rate_id = BTC_MCS_20;
5126 			break;
5127 		case DESC_RATEMCS21:
5128 			btc_rate_id = BTC_MCS_21;
5129 			break;
5130 		case DESC_RATEMCS22:
5131 			btc_rate_id = BTC_MCS_22;
5132 			break;
5133 		case DESC_RATEMCS23:
5134 			btc_rate_id = BTC_MCS_23;
5135 			break;
5136 		case DESC_RATEMCS24:
5137 			btc_rate_id = BTC_MCS_24;
5138 			break;
5139 		case DESC_RATEMCS25:
5140 			btc_rate_id = BTC_MCS_25;
5141 			break;
5142 		case DESC_RATEMCS26:
5143 			btc_rate_id = BTC_MCS_26;
5144 			break;
5145 		case DESC_RATEMCS27:
5146 			btc_rate_id = BTC_MCS_27;
5147 			break;
5148 		case DESC_RATEMCS28:
5149 			btc_rate_id = BTC_MCS_28;
5150 			break;
5151 		case DESC_RATEMCS29:
5152 			btc_rate_id = BTC_MCS_29;
5153 			break;
5154 		case DESC_RATEMCS30:
5155 			btc_rate_id = BTC_MCS_30;
5156 			break;
5157 		case DESC_RATEMCS31:
5158 			btc_rate_id = BTC_MCS_31;
5159 			break;
5160 
5161 		case DESC_RATEVHTSS1MCS0:
5162 			btc_rate_id = BTC_VHT_1SS_MCS_0;
5163 			break;
5164 		case DESC_RATEVHTSS1MCS1:
5165 			btc_rate_id = BTC_VHT_1SS_MCS_1;
5166 			break;
5167 		case DESC_RATEVHTSS1MCS2:
5168 			btc_rate_id = BTC_VHT_1SS_MCS_2;
5169 			break;
5170 		case DESC_RATEVHTSS1MCS3:
5171 			btc_rate_id = BTC_VHT_1SS_MCS_3;
5172 			break;
5173 		case DESC_RATEVHTSS1MCS4:
5174 			btc_rate_id = BTC_VHT_1SS_MCS_4;
5175 			break;
5176 		case DESC_RATEVHTSS1MCS5:
5177 			btc_rate_id = BTC_VHT_1SS_MCS_5;
5178 			break;
5179 		case DESC_RATEVHTSS1MCS6:
5180 			btc_rate_id = BTC_VHT_1SS_MCS_6;
5181 			break;
5182 		case DESC_RATEVHTSS1MCS7:
5183 			btc_rate_id = BTC_VHT_1SS_MCS_7;
5184 			break;
5185 		case DESC_RATEVHTSS1MCS8:
5186 			btc_rate_id = BTC_VHT_1SS_MCS_8;
5187 			break;
5188 		case DESC_RATEVHTSS1MCS9:
5189 			btc_rate_id = BTC_VHT_1SS_MCS_9;
5190 			break;
5191 
5192 		case DESC_RATEVHTSS2MCS0:
5193 			btc_rate_id = BTC_VHT_2SS_MCS_0;
5194 			break;
5195 		case DESC_RATEVHTSS2MCS1:
5196 			btc_rate_id = BTC_VHT_2SS_MCS_1;
5197 			break;
5198 		case DESC_RATEVHTSS2MCS2:
5199 			btc_rate_id = BTC_VHT_2SS_MCS_2;
5200 			break;
5201 		case DESC_RATEVHTSS2MCS3:
5202 			btc_rate_id = BTC_VHT_2SS_MCS_3;
5203 			break;
5204 		case DESC_RATEVHTSS2MCS4:
5205 			btc_rate_id = BTC_VHT_2SS_MCS_4;
5206 			break;
5207 		case DESC_RATEVHTSS2MCS5:
5208 			btc_rate_id = BTC_VHT_2SS_MCS_5;
5209 			break;
5210 		case DESC_RATEVHTSS2MCS6:
5211 			btc_rate_id = BTC_VHT_2SS_MCS_6;
5212 			break;
5213 		case DESC_RATEVHTSS2MCS7:
5214 			btc_rate_id = BTC_VHT_2SS_MCS_7;
5215 			break;
5216 		case DESC_RATEVHTSS2MCS8:
5217 			btc_rate_id = BTC_VHT_2SS_MCS_8;
5218 			break;
5219 		case DESC_RATEVHTSS2MCS9:
5220 			btc_rate_id = BTC_VHT_2SS_MCS_9;
5221 			break;
5222 
5223 		case DESC_RATEVHTSS3MCS0:
5224 			btc_rate_id = BTC_VHT_3SS_MCS_0;
5225 			break;
5226 		case DESC_RATEVHTSS3MCS1:
5227 			btc_rate_id = BTC_VHT_3SS_MCS_1;
5228 			break;
5229 		case DESC_RATEVHTSS3MCS2:
5230 			btc_rate_id = BTC_VHT_3SS_MCS_2;
5231 			break;
5232 		case DESC_RATEVHTSS3MCS3:
5233 			btc_rate_id = BTC_VHT_3SS_MCS_3;
5234 			break;
5235 		case DESC_RATEVHTSS3MCS4:
5236 			btc_rate_id = BTC_VHT_3SS_MCS_4;
5237 			break;
5238 		case DESC_RATEVHTSS3MCS5:
5239 			btc_rate_id = BTC_VHT_3SS_MCS_5;
5240 			break;
5241 		case DESC_RATEVHTSS3MCS6:
5242 			btc_rate_id = BTC_VHT_3SS_MCS_6;
5243 			break;
5244 		case DESC_RATEVHTSS3MCS7:
5245 			btc_rate_id = BTC_VHT_3SS_MCS_7;
5246 			break;
5247 		case DESC_RATEVHTSS3MCS8:
5248 			btc_rate_id = BTC_VHT_3SS_MCS_8;
5249 			break;
5250 		case DESC_RATEVHTSS3MCS9:
5251 			btc_rate_id = BTC_VHT_3SS_MCS_9;
5252 			break;
5253 
5254 		case DESC_RATEVHTSS4MCS0:
5255 			btc_rate_id = BTC_VHT_4SS_MCS_0;
5256 			break;
5257 		case DESC_RATEVHTSS4MCS1:
5258 			btc_rate_id = BTC_VHT_4SS_MCS_1;
5259 			break;
5260 		case DESC_RATEVHTSS4MCS2:
5261 			btc_rate_id = BTC_VHT_4SS_MCS_2;
5262 			break;
5263 		case DESC_RATEVHTSS4MCS3:
5264 			btc_rate_id = BTC_VHT_4SS_MCS_3;
5265 			break;
5266 		case DESC_RATEVHTSS4MCS4:
5267 			btc_rate_id = BTC_VHT_4SS_MCS_4;
5268 			break;
5269 		case DESC_RATEVHTSS4MCS5:
5270 			btc_rate_id = BTC_VHT_4SS_MCS_5;
5271 			break;
5272 		case DESC_RATEVHTSS4MCS6:
5273 			btc_rate_id = BTC_VHT_4SS_MCS_6;
5274 			break;
5275 		case DESC_RATEVHTSS4MCS7:
5276 			btc_rate_id = BTC_VHT_4SS_MCS_7;
5277 			break;
5278 		case DESC_RATEVHTSS4MCS8:
5279 			btc_rate_id = BTC_VHT_4SS_MCS_8;
5280 			break;
5281 		case DESC_RATEVHTSS4MCS9:
5282 			btc_rate_id = BTC_VHT_4SS_MCS_9;
5283 			break;
5284 	}
5285 
5286 	return btc_rate_id;
5287 }
5288 
5289 /*
5290  * Description:
5291  *	Run BT-Coexist mechansim or not
5292  *
5293  */
hal_btcoex_SetBTCoexist(PADAPTER padapter,u8 bBtExist)5294 void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)
5295 {
5296 	PHAL_DATA_TYPE	pHalData;
5297 
5298 
5299 	pHalData = GET_HAL_DATA(padapter);
5300 	pHalData->bt_coexist.bBtExist = bBtExist;
5301 }
5302 
5303 /*
5304  * Dewcription:
5305  *	Check is co-exist mechanism enabled or not
5306  *
5307  * Return:
5308  *	_TRUE	Enable BT co-exist mechanism
5309  *	_FALSE	Disable BT co-exist mechanism
5310  */
hal_btcoex_IsBtExist(PADAPTER padapter)5311 u8 hal_btcoex_IsBtExist(PADAPTER padapter)
5312 {
5313 	PHAL_DATA_TYPE	pHalData;
5314 
5315 
5316 	pHalData = GET_HAL_DATA(padapter);
5317 	return pHalData->bt_coexist.bBtExist;
5318 }
5319 
hal_btcoex_IsBtDisabled(PADAPTER padapter)5320 u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)
5321 {
5322 	if (!hal_btcoex_IsBtExist(padapter))
5323 		return _TRUE;
5324 
5325 	if (GLBtCoexist.bt_info.bt_disabled)
5326 		return _TRUE;
5327 	else
5328 		return _FALSE;
5329 }
5330 
hal_btcoex_SetChipType(PADAPTER padapter,u8 chipType)5331 void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)
5332 {
5333 	PHAL_DATA_TYPE	pHalData;
5334 
5335 	pHalData = GET_HAL_DATA(padapter);
5336 	pHalData->bt_coexist.btChipType = chipType;
5337 }
5338 
hal_btcoex_SetPgAntNum(PADAPTER padapter,u8 antNum)5339 void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)
5340 {
5341 	PHAL_DATA_TYPE	pHalData;
5342 
5343 	pHalData = GET_HAL_DATA(padapter);
5344 
5345 	pHalData->bt_coexist.btTotalAntNum = antNum;
5346 }
5347 
hal_btcoex_Initialize(PADAPTER padapter)5348 u8 hal_btcoex_Initialize(PADAPTER padapter)
5349 {
5350 	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(padapter);
5351 	u8 ret;
5352 
5353 	_rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
5354 
5355 	ret = EXhalbtcoutsrc_InitlizeVariables((void *)padapter);
5356 
5357 	return ret;
5358 }
5359 
hal_btcoex_PowerOnSetting(PADAPTER padapter)5360 void hal_btcoex_PowerOnSetting(PADAPTER padapter)
5361 {
5362 	EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
5363 }
5364 
hal_btcoex_AntInfoSetting(PADAPTER padapter)5365 void hal_btcoex_AntInfoSetting(PADAPTER padapter)
5366 {
5367 	hal_btcoex_SetBTCoexist(padapter, rtw_btcoex_get_bt_coexist(padapter));
5368 	hal_btcoex_SetChipType(padapter, rtw_btcoex_get_chip_type(padapter));
5369 	hal_btcoex_SetPgAntNum(padapter, rtw_btcoex_get_pg_ant_num(padapter));
5370 
5371 	EXhalbtcoutsrc_AntInfoSetting(padapter);
5372 }
5373 
hal_btcoex_PowerOffSetting(PADAPTER padapter)5374 void hal_btcoex_PowerOffSetting(PADAPTER padapter)
5375 {
5376 	/* Clear the WiFi on/off bit in scoreboard reg. if necessary */
5377 	if (IS_HARDWARE_TYPE_8703B(padapter) || IS_HARDWARE_TYPE_8723D(padapter)
5378 		|| IS_HARDWARE_TYPE_8821C(padapter) || IS_HARDWARE_TYPE_8822B(padapter)
5379 		|| IS_HARDWARE_TYPE_8822C(padapter))
5380 		rtw_write16(padapter, 0xaa, 0x8000);
5381 }
5382 
hal_btcoex_PreLoadFirmware(PADAPTER padapter)5383 void hal_btcoex_PreLoadFirmware(PADAPTER padapter)
5384 {
5385 	EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);
5386 }
5387 
hal_btcoex_InitHwConfig(PADAPTER padapter,u8 bWifiOnly)5388 void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)
5389 {
5390 	if (!hal_btcoex_IsBtExist(padapter))
5391 		return;
5392 
5393 	EXhalbtcoutsrc_init_hw_config(&GLBtCoexist, bWifiOnly);
5394 	EXhalbtcoutsrc_init_coex_dm(&GLBtCoexist);
5395 }
5396 
hal_btcoex_IpsNotify(PADAPTER padapter,u8 type)5397 void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)
5398 {
5399 	EXhalbtcoutsrc_ips_notify(&GLBtCoexist, type);
5400 }
5401 
hal_btcoex_LpsNotify(PADAPTER padapter,u8 type)5402 void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)
5403 {
5404 	EXhalbtcoutsrc_lps_notify(&GLBtCoexist, type);
5405 }
5406 
hal_btcoex_ScanNotify(PADAPTER padapter,u8 type)5407 void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)
5408 {
5409 	EXhalbtcoutsrc_scan_notify(&GLBtCoexist, type);
5410 }
5411 
hal_btcoex_ConnectNotify(PADAPTER padapter,u8 action)5412 void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
5413 {
5414 	u8 assoType = 0;
5415 	u8 is_5g_band = _FALSE;
5416 
5417 	is_5g_band = (padapter->mlmeextpriv.cur_channel > 14) ? _TRUE : _FALSE;
5418 
5419 	if (action == _TRUE) {
5420 		if (is_5g_band == _TRUE)
5421 			assoType = BTC_ASSOCIATE_5G_START;
5422 		else
5423 			assoType = BTC_ASSOCIATE_START;
5424 	}
5425 	else {
5426 		if (is_5g_band == _TRUE)
5427 			assoType = BTC_ASSOCIATE_5G_FINISH;
5428 		else
5429 			assoType = BTC_ASSOCIATE_FINISH;
5430 	}
5431 
5432 	EXhalbtcoutsrc_connect_notify(&GLBtCoexist, assoType);
5433 }
5434 
hal_btcoex_MediaStatusNotify(PADAPTER padapter,u8 mediaStatus)5435 void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
5436 {
5437 	EXhalbtcoutsrc_media_status_notify(&GLBtCoexist, mediaStatus);
5438 }
5439 
hal_btcoex_SpecialPacketNotify(PADAPTER padapter,u8 pktType)5440 void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
5441 {
5442 	EXhalbtcoutsrc_specific_packet_notify(&GLBtCoexist, pktType);
5443 }
5444 
hal_btcoex_IQKNotify(PADAPTER padapter,u8 state)5445 void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)
5446 {
5447 	GLBtcWiFiInIQKState = state;
5448 }
5449 
hal_btcoex_BtInfoNotify(PADAPTER padapter,u8 length,u8 * tmpBuf)5450 void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
5451 {
5452 	if (GLBtcWiFiInIQKState == _TRUE)
5453 		return;
5454 
5455 	EXhalbtcoutsrc_bt_info_notify(&GLBtCoexist, tmpBuf, length);
5456 }
5457 
hal_btcoex_BtMpRptNotify(PADAPTER padapter,u8 length,u8 * tmpBuf)5458 void hal_btcoex_BtMpRptNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
5459 {
5460 	u8 extid, status, len, seq;
5461 
5462 
5463 	if (GLBtcBtMpRptWait == _FALSE)
5464 		return;
5465 
5466 	if ((length < 3) || (!tmpBuf))
5467 		return;
5468 
5469 	extid = tmpBuf[0];
5470 	/* not response from BT FW then exit*/
5471 	switch (extid) {
5472 	case C2H_WIFI_FW_ACTIVE_RSP:
5473 		GLBtcBtMpRptWiFiOK = _TRUE;
5474 		break;
5475 
5476 	case C2H_TRIG_BY_BT_FW:
5477 		GLBtcBtMpRptBTOK = _TRUE;
5478 
5479 		status = tmpBuf[1] & 0xF;
5480 		len = length - 3;
5481 		seq = tmpBuf[2] >> 4;
5482 
5483 		GLBtcBtMpRptSeq = seq;
5484 		GLBtcBtMpRptStatus = status;
5485 		_rtw_memcpy(GLBtcBtMpRptRsp, tmpBuf + 3, len);
5486 		GLBtcBtMpRptRspSize = len;
5487 
5488 		break;
5489 
5490 	default:
5491 		return;
5492 	}
5493 
5494 	if ((GLBtcBtMpRptWiFiOK == _TRUE) && (GLBtcBtMpRptBTOK == _TRUE)) {
5495 		GLBtcBtMpRptWait = _FALSE;
5496 		_cancel_timer_ex(&GLBtcBtMpOperTimer);
5497 		_rtw_up_sema(&GLBtcBtMpRptSema);
5498 	}
5499 }
5500 
hal_btcoex_SuspendNotify(PADAPTER padapter,u8 state)5501 void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
5502 {
5503 	switch (state) {
5504 	case BTCOEX_SUSPEND_STATE_SUSPEND:
5505 		EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);
5506 		break;
5507 	case BTCOEX_SUSPEND_STATE_SUSPEND_KEEP_ANT:
5508 		/* should switch to "#if 1" once all ICs' coex. revision are upgraded to support the KEEP_ANT case */
5509 #if 0
5510 		EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);
5511 #else
5512 		EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);
5513 		EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);
5514 #endif
5515 		break;
5516 	case BTCOEX_SUSPEND_STATE_RESUME:
5517 #ifdef CONFIG_FW_MULTI_PORT_SUPPORT
5518 		/* re-download FW after resume, inform WL FW port number */
5519 		rtw_hal_set_wifi_btc_port_id_cmd(GLBtCoexist.Adapter);
5520 #endif
5521 		EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_WAKE_UP);
5522 		break;
5523 	}
5524 }
5525 
hal_btcoex_HaltNotify(PADAPTER padapter,u8 do_halt)5526 void hal_btcoex_HaltNotify(PADAPTER padapter, u8 do_halt)
5527 {
5528 	if (do_halt == 1)
5529 		EXhalbtcoutsrc_halt_notify(&GLBtCoexist);
5530 
5531 	GLBtCoexist.bBinded = _FALSE;
5532 	GLBtCoexist.Adapter = NULL;
5533 }
5534 
hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)5535 void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)
5536 {
5537 	EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);
5538 }
5539 
hal_btcoex_Hanlder(PADAPTER padapter)5540 void hal_btcoex_Hanlder(PADAPTER padapter)
5541 {
5542 	u32	bt_patch_ver;
5543 
5544 	EXhalbtcoutsrc_periodical(&GLBtCoexist);
5545 
5546 	if (GLBtCoexist.bt_info.bt_get_fw_ver == 0) {
5547 		GLBtCoexist.btc_get(&GLBtCoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
5548 		GLBtCoexist.bt_info.bt_get_fw_ver = bt_patch_ver;
5549 	}
5550 }
5551 
hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)5552 s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)
5553 {
5554 	return (s32)GLBtCoexist.bt_info.reject_agg_pkt;
5555 }
5556 
hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)5557 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
5558 {
5559 	return (s32)GLBtCoexist.bt_info.bt_ctrl_agg_buf_size;
5560 }
5561 
hal_btcoex_GetAMPDUSize(PADAPTER padapter)5562 u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)
5563 {
5564 	return (u32)GLBtCoexist.bt_info.agg_buf_size;
5565 }
5566 
hal_btcoex_SetManualControl(PADAPTER padapter,u8 bmanual)5567 void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)
5568 {
5569 	GLBtCoexist.manual_control = bmanual;
5570 }
5571 
hal_btcoex_1Ant(PADAPTER padapter)5572 u8 hal_btcoex_1Ant(PADAPTER padapter)
5573 {
5574 	if (hal_btcoex_IsBtExist(padapter) == _FALSE)
5575 		return _FALSE;
5576 
5577 	if (GLBtCoexist.board_info.btdm_ant_num == 1)
5578 		return _TRUE;
5579 
5580 	return _FALSE;
5581 }
5582 
hal_btcoex_IsBtControlLps(PADAPTER padapter)5583 u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)
5584 {
5585 	if (GLBtCoexist.bdontenterLPS == _TRUE)
5586 		return _TRUE;
5587 
5588 	if (hal_btcoex_IsBtExist(padapter) == _FALSE)
5589 		return _FALSE;
5590 
5591 	if (GLBtCoexist.bt_info.bt_disabled)
5592 		return _FALSE;
5593 
5594 	if (GLBtCoexist.bt_info.bt_ctrl_lps)
5595 		return _TRUE;
5596 
5597 	return _FALSE;
5598 }
5599 
hal_btcoex_IsLpsOn(PADAPTER padapter)5600 u8 hal_btcoex_IsLpsOn(PADAPTER padapter)
5601 {
5602 	if (GLBtCoexist.bdontenterLPS == _TRUE)
5603 		return _FALSE;
5604 
5605 	if (hal_btcoex_IsBtExist(padapter) == _FALSE)
5606 		return _FALSE;
5607 
5608 	if (GLBtCoexist.bt_info.bt_disabled)
5609 		return _FALSE;
5610 
5611 	if (GLBtCoexist.bt_info.bt_lps_on)
5612 		return _TRUE;
5613 
5614 	return _FALSE;
5615 }
5616 
hal_btcoex_RpwmVal(PADAPTER padapter)5617 u8 hal_btcoex_RpwmVal(PADAPTER padapter)
5618 {
5619 	return GLBtCoexist.bt_info.rpwm_val;
5620 }
5621 
hal_btcoex_LpsVal(PADAPTER padapter)5622 u8 hal_btcoex_LpsVal(PADAPTER padapter)
5623 {
5624 	return GLBtCoexist.bt_info.lps_val;
5625 }
5626 
hal_btcoex_GetRaMask(PADAPTER padapter)5627 u32 hal_btcoex_GetRaMask(PADAPTER padapter)
5628 {
5629 	if (!hal_btcoex_IsBtExist(padapter))
5630 		return 0;
5631 
5632 	if (GLBtCoexist.bt_info.bt_disabled)
5633 		return 0;
5634 
5635 	/* Modify by YiWei , suggest by Cosa and Jenyu
5636 	 * Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask.
5637 	 */
5638 	/*if (GLBtCoexist.board_info.btdm_ant_num != 1)
5639 		return 0;*/
5640 
5641 	return GLBtCoexist.bt_info.ra_mask;
5642 }
5643 
hal_btcoex_query_reduced_wl_pwr_lvl(PADAPTER padapter)5644 u8 hal_btcoex_query_reduced_wl_pwr_lvl(PADAPTER padapter)
5645 {
5646 	return GLBtCoexist.coex_dm.cur_wl_pwr_lvl;
5647 }
5648 
hal_btcoex_set_reduced_wl_pwr_lvl(PADAPTER padapter,u8 val)5649 void hal_btcoex_set_reduced_wl_pwr_lvl(PADAPTER padapter, u8 val)
5650 {
5651 	GLBtCoexist.coex_dm.cur_wl_pwr_lvl = val;
5652 }
5653 
hal_btcoex_do_reduce_wl_pwr_lvl(PADAPTER padapter)5654 void hal_btcoex_do_reduce_wl_pwr_lvl(PADAPTER padapter)
5655 {
5656 	halbtcoutsrc_reduce_wl_tx_power(&GLBtCoexist, 0);
5657 }
5658 
hal_btcoex_RecordPwrMode(PADAPTER padapter,u8 * pCmdBuf,u8 cmdLen)5659 void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
5660 {
5661 
5662 	_rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
5663 }
5664 
hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter,u8 * pbuf,u32 bufsize)5665 void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
5666 {
5667 	PBTCDBGINFO pinfo;
5668 
5669 
5670 	pinfo = &GLBtcDbgInfo;
5671 	DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
5672 	EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
5673 	DBG_BT_INFO_INIT(pinfo, NULL, 0);
5674 }
5675 
hal_btcoex_SetDBG(PADAPTER padapter,u32 * pDbgModule)5676 void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
5677 {
5678 	u32 i;
5679 
5680 
5681 	if (NULL == pDbgModule)
5682 		return;
5683 
5684 	for (i = 0; i < COMP_MAX; i++)
5685 		GLBtcDbgType[i] = pDbgModule[i];
5686 }
5687 
hal_btcoex_GetDBG(PADAPTER padapter,u8 * pStrBuf,u32 bufSize)5688 u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
5689 {
5690 	s32 count;
5691 	u8 *pstr;
5692 	u32 leftSize;
5693 
5694 
5695 	if ((NULL == pStrBuf) || (0 == bufSize))
5696 		return 0;
5697 
5698 	count = 0;
5699 	pstr = pStrBuf;
5700 	leftSize = bufSize;
5701 	/*	RTW_INFO(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize); */
5702 
5703 	count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
5704 	if ((count < 0) || (count >= leftSize))
5705 		goto exit;
5706 	pstr += count;
5707 	leftSize -= count;
5708 
5709 	count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
5710 	if ((count < 0) || (count >= leftSize))
5711 		goto exit;
5712 	pstr += count;
5713 	leftSize -= count;
5714 
5715 	count = rtw_sprintf(pstr, leftSize,
5716 			    "COMP_COEX: 0x%08X\n\n",
5717 			    GLBtcDbgType[COMP_COEX]);
5718 	if ((count < 0) || (count >= leftSize))
5719 		goto exit;
5720 	pstr += count;
5721 	leftSize -= count;
5722 
5723 #if 0
5724 	count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
5725 	if ((count < 0) || (count >= leftSize))
5726 		goto exit;
5727 	pstr += count;
5728 	leftSize -= count;
5729 	count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
5730 		    GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_INIT ? 1 : 0);
5731 	if ((count < 0) || (count >= leftSize))
5732 		goto exit;
5733 	pstr += count;
5734 	leftSize -= count;
5735 	count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
5736 		    GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_NOTIFY ? 1 : 0);
5737 	if ((count < 0) || (count >= leftSize))
5738 		goto exit;
5739 	pstr += count;
5740 	leftSize -= count;
5741 
5742 	count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
5743 	if ((count < 0) || (count >= leftSize))
5744 		goto exit;
5745 	pstr += count;
5746 	leftSize -= count;
5747 	count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
5748 		GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_RSSI_STATE ? 1 : 0);
5749 	if ((count < 0) || (count >= leftSize))
5750 		goto exit;
5751 	pstr += count;
5752 	leftSize -= count;
5753 	count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
5754 		GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_WIFI_RSSI_STATE ? 1 : 0);
5755 	if ((count < 0) || (count >= leftSize))
5756 		goto exit;
5757 	pstr += count;
5758 	leftSize -= count;
5759 	count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
5760 		    GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_MONITOR ? 1 : 0);
5761 	if ((count < 0) || (count >= leftSize))
5762 		goto exit;
5763 	pstr += count;
5764 	leftSize -= count;
5765 	count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
5766 		    GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE ? 1 : 0);
5767 	if ((count < 0) || (count >= leftSize))
5768 		goto exit;
5769 	pstr += count;
5770 	leftSize -= count;
5771 	count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
5772 		    GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW ? 1 : 0);
5773 	if ((count < 0) || (count >= leftSize))
5774 		goto exit;
5775 	pstr += count;
5776 	leftSize -= count;
5777 	count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
5778 		GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_DETAIL ? 1 : 0);
5779 	if ((count < 0) || (count >= leftSize))
5780 		goto exit;
5781 	pstr += count;
5782 	leftSize -= count;
5783 	count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
5784 		GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_EXEC ? 1 : 0);
5785 	if ((count < 0) || (count >= leftSize))
5786 		goto exit;
5787 	pstr += count;
5788 	leftSize -= count;
5789 	count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
5790 		    GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW ? 1 : 0);
5791 	if ((count < 0) || (count >= leftSize))
5792 		goto exit;
5793 	pstr += count;
5794 	leftSize -= count;
5795 	count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
5796 		GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_DETAIL ? 1 : 0);
5797 	if ((count < 0) || (count >= leftSize))
5798 		goto exit;
5799 	pstr += count;
5800 	leftSize -= count;
5801 	count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
5802 		GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_EXEC ? 1 : 0);
5803 	if ((count < 0) || (count >= leftSize))
5804 		goto exit;
5805 	pstr += count;
5806 	leftSize -= count;
5807 #endif
5808 
5809 exit:
5810 	count = pstr - pStrBuf;
5811 	/*	RTW_INFO(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count); */
5812 
5813 	return count;
5814 }
5815 
hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)5816 u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
5817 {
5818 	if (!hal_btcoex_IsBtExist(padapter))
5819 		return _FALSE;
5820 
5821 	if (GLBtCoexist.bt_info.increase_scan_dev_num)
5822 		return _TRUE;
5823 
5824 	return _FALSE;
5825 }
5826 
hal_btcoex_IsBtLinkExist(PADAPTER padapter)5827 u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)
5828 {
5829 	if (GLBtCoexist.bt_link_info.bt_link_exist)
5830 		return _TRUE;
5831 
5832 	return _FALSE;
5833 }
5834 
hal_btcoex_SetBtPatchVersion(PADAPTER padapter,u16 btHciVer,u16 btPatchVer)5835 void hal_btcoex_SetBtPatchVersion(PADAPTER padapter, u16 btHciVer, u16 btPatchVer)
5836 {
5837 	EXhalbtcoutsrc_SetBtPatchVersion(btHciVer, btPatchVer);
5838 }
5839 
hal_btcoex_SetHciVersion(PADAPTER padapter,u16 hciVersion)5840 void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)
5841 {
5842 	EXhalbtcoutsrc_SetHciVersion(hciVersion);
5843 }
5844 
hal_btcoex_StackUpdateProfileInfo(void)5845 void hal_btcoex_StackUpdateProfileInfo(void)
5846 {
5847 	EXhalbtcoutsrc_StackUpdateProfileInfo();
5848 }
5849 
hal_btcoex_pta_off_on_notify(PADAPTER padapter,u8 bBTON)5850 void hal_btcoex_pta_off_on_notify(PADAPTER padapter, u8 bBTON)
5851 {
5852 	ex_halbtcoutsrc_pta_off_on_notify(&GLBtCoexist, bBTON);
5853 }
5854 
5855 /*
5856  *	Description:
5857  *	Setting BT coex antenna isolation type .
5858  *	coex mechanisn/ spital stream/ best throughput
5859  *	anttype = 0	,	PSTDMA	/	2SS	/	0.5T	,	bad isolation , WiFi/BT ANT Distance<15cm , (<20dB) for 2,3 antenna
5860  *	anttype = 1	,	PSTDMA	/	1SS	/	0.5T	,	normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 2 antenna
5861  *	anttype = 2	,	TDMA	/	2SS	/	T ,		normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 3 antenna
5862  *	anttype = 3	,	no TDMA	/	1SS	/	0.5T	,	good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 2 antenna
5863  *	anttype = 4	,	no TDMA	/	2SS	/	T ,		good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 3 antenna
5864  *	wifi only throughput ~ T
5865  *	wifi/BT share one antenna with SPDT
5866  */
hal_btcoex_SetAntIsolationType(PADAPTER padapter,u8 anttype)5867 void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)
5868 {
5869 	PHAL_DATA_TYPE pHalData;
5870 	PBTC_COEXIST	pBtCoexist = &GLBtCoexist;
5871 
5872 	/*RTW_INFO("####%s , anttype = %d  , %d\n" , __func__ , anttype , __LINE__); */
5873 	pHalData = GET_HAL_DATA(padapter);
5874 
5875 
5876 	pHalData->bt_coexist.btAntisolation = anttype;
5877 
5878 	switch (pHalData->bt_coexist.btAntisolation) {
5879 	case 0:
5880 		pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_0;
5881 		break;
5882 	case 1:
5883 		pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_1;
5884 		break;
5885 	case 2:
5886 		pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_2;
5887 		break;
5888 	case 3:
5889 		pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_3;
5890 		break;
5891 	case 4:
5892 		pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_4;
5893 		break;
5894 	}
5895 
5896 }
5897 
5898 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
5899 int
hal_btcoex_ParseAntIsolationConfigFile(PADAPTER Adapter,char * buffer)5900 hal_btcoex_ParseAntIsolationConfigFile(
5901 	PADAPTER		Adapter,
5902 	char			*buffer
5903 )
5904 {
5905 	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(Adapter);
5906 	u32	i = 0 , j = 0;
5907 	char	*szLine , *ptmp;
5908 	int rtStatus = _SUCCESS;
5909 	char param_value_string[10];
5910 	u8 param_value;
5911 	u8 anttype = 4;
5912 
5913 	u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1;
5914 
5915 	typedef struct ant_isolation {
5916 		char *param_name;  /* antenna isolation config parameter name */
5917 		u8 *value; /* antenna isolation config parameter value */
5918 	} ANT_ISOLATION;
5919 
5920 	ANT_ISOLATION ant_isolation_param[] = {
5921 		{"ANT_NUMBER" , &ant_num},
5922 		{"ANT_DISTANCE" , &ant_distance},
5923 		{"RFE_TYPE" , &rfe_type},
5924 		{NULL , 0}
5925 	};
5926 
5927 
5928 
5929 	/* RTW_INFO("===>Hal_ParseAntIsolationConfigFile()\n" ); */
5930 
5931 	ptmp = buffer;
5932 	for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
5933 		/* skip comment */
5934 		if (IsCommentString(szLine))
5935 			continue;
5936 
5937 		/* RTW_INFO("%s : szLine = %s , strlen(szLine) = %d\n" , __func__ , szLine , strlen(szLine));*/
5938 		for (j = 0 ; ant_isolation_param[j].param_name != NULL ; j++) {
5939 			if (strstr(szLine , ant_isolation_param[j].param_name) != NULL) {
5940 				i = 0;
5941 				while (i < strlen(szLine)) {
5942 					if (szLine[i] != '"')
5943 						++i;
5944 					else {
5945 						/* skip only has one " */
5946 						if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) {
5947 							RTW_INFO("Fail to parse parameters , format error!\n");
5948 							break;
5949 						}
5950 						_rtw_memset((void *)param_value_string , 0 , 10);
5951 						if (!ParseQualifiedString(szLine , &i , param_value_string , '"' , '"')) {
5952 							RTW_INFO("Fail to parse parameters\n");
5953 							return _FAIL;
5954 						} else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value))
5955 							RTW_INFO("Fail to GetU1ByteIntegerFromStringInDecimal\n");
5956 
5957 						break;
5958 					}
5959 				}
5960 			}
5961 		}
5962 	}
5963 
5964 	/* YiWei 20140716 , for BT coex antenna isolation control */
5965 	/* rfe_type = 0 was SPDT , rfe_type = 1 was coupler */
5966 	if (ant_num == 3 && ant_distance >= 50)
5967 		anttype = 3;
5968 	else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1)
5969 		anttype = 2;
5970 	else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50)
5971 		anttype = 2;
5972 	else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1)
5973 		anttype = 2;
5974 	else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15))
5975 		anttype = 1;
5976 	else if (ant_num == 2 && rfe_type == 0)
5977 		anttype = 0;
5978 	else
5979 		anttype = 0;
5980 
5981 	hal_btcoex_SetAntIsolationType(Adapter, anttype);
5982 
5983 	RTW_INFO("%s : ant_num = %d\n" , __func__ , ant_num);
5984 	RTW_INFO("%s : ant_distance = %d\n" , __func__ , ant_distance);
5985 	RTW_INFO("%s : rfe_type = %d\n" , __func__ , rfe_type);
5986 	/* RTW_INFO("<===Hal_ParseAntIsolationConfigFile()\n"); */
5987 	return rtStatus;
5988 }
5989 
5990 
5991 int
hal_btcoex_AntIsolationConfig_ParaFile(PADAPTER Adapter,char * pFileName)5992 hal_btcoex_AntIsolationConfig_ParaFile(
5993 		PADAPTER	Adapter,
5994 		char		*pFileName
5995 )
5996 {
5997 	HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
5998 	int	rlen = 0 , rtStatus = _FAIL;
5999 
6000 	_rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN);
6001 
6002 	rtw_get_phy_file_path(Adapter, pFileName);
6003 	if (rtw_is_file_readable(rtw_phy_para_file_path) == _TRUE) {
6004 		rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
6005 		if (rlen > 0)
6006 			rtStatus = _SUCCESS;
6007 	}
6008 
6009 
6010 	if (rtStatus == _SUCCESS) {
6011 		/*RTW_INFO("%s(): read %s ok\n", __func__ , pFileName);*/
6012 		rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf);
6013 	} else
6014 		RTW_INFO("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName);
6015 
6016 	return rtStatus;
6017 }
6018 #endif /* CONFIG_LOAD_PHY_PARA_FROM_FILE */
6019 
hal_btcoex_btreg_read(PADAPTER padapter,u8 type,u16 addr,u32 * data)6020 u16 hal_btcoex_btreg_read(PADAPTER padapter, u8 type, u16 addr, u32 *data)
6021 {
6022 	u16 ret = 0;
6023 
6024 	halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
6025 
6026 	ret = halbtcoutsrc_GetBtReg_with_status(&GLBtCoexist, type, addr, data);
6027 
6028 	halbtcoutsrc_NormalLowPower(&GLBtCoexist);
6029 
6030 	return ret;
6031 }
6032 
hal_btcoex_btreg_write(PADAPTER padapter,u8 type,u16 addr,u16 val)6033 u16 hal_btcoex_btreg_write(PADAPTER padapter, u8 type, u16 addr, u16 val)
6034 {
6035 	u16 ret = 0;
6036 
6037 	halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
6038 
6039 	ret = halbtcoutsrc_SetBtReg(&GLBtCoexist, type, addr, val);
6040 
6041 	halbtcoutsrc_NormalLowPower(&GLBtCoexist);
6042 
6043 	return ret;
6044 }
6045 
hal_btcoex_set_rfe_type(u8 type)6046 void hal_btcoex_set_rfe_type(u8 type)
6047 {
6048 	EXhalbtcoutsrc_set_rfe_type(type);
6049 }
6050 
6051 #ifdef CONFIG_RF4CE_COEXIST
hal_btcoex_set_rf4ce_link_state(u8 state)6052 void hal_btcoex_set_rf4ce_link_state(u8 state)
6053 {
6054 	EXhalbtcoutsrc_set_rf4ce_link_state(state);
6055 }
6056 
hal_btcoex_get_rf4ce_link_state(void)6057 u8 hal_btcoex_get_rf4ce_link_state(void)
6058 {
6059 	return EXhalbtcoutsrc_get_rf4ce_link_state();
6060 }
6061 #endif /* CONFIG_RF4CE_COEXIST */
6062 
hal_btcoex_switchband_notify(u8 under_scan,u8 band_type)6063 void hal_btcoex_switchband_notify(u8 under_scan, u8 band_type)
6064 {
6065 	switch (band_type) {
6066 	case BAND_ON_2_4G:
6067 		if (under_scan)
6068 			EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G);
6069 		else
6070 			EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G_NOFORSCAN);
6071 		break;
6072 	case BAND_ON_5G:
6073 		EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_5G);
6074 		break;
6075 	default:
6076 		RTW_INFO("[BTCOEX] unkown switch band type\n");
6077 		break;
6078 	}
6079 }
6080 
hal_btcoex_WlFwDbgInfoNotify(PADAPTER padapter,u8 * tmpBuf,u8 length)6081 void hal_btcoex_WlFwDbgInfoNotify(PADAPTER padapter, u8* tmpBuf, u8 length)
6082 {
6083 	EXhalbtcoutsrc_WlFwDbgInfoNotify(&GLBtCoexist, tmpBuf, length);
6084 }
6085 
hal_btcoex_rx_rate_change_notify(PADAPTER padapter,u8 is_data_frame,u8 rate_id)6086 void hal_btcoex_rx_rate_change_notify(PADAPTER padapter, u8 is_data_frame, u8 rate_id)
6087 {
6088 	EXhalbtcoutsrc_rx_rate_change_notify(&GLBtCoexist, is_data_frame, EXhalbtcoutsrc_rate_id_to_btc_rate_id(rate_id));
6089 }
6090 
hal_btcoex_btset_testode(PADAPTER padapter,u8 type)6091 u16 hal_btcoex_btset_testode(PADAPTER padapter, u8 type)
6092 {
6093 	u16 ret = 0;
6094 
6095 	halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
6096 
6097 	ret = halbtcoutsrc_setbttestmode(&GLBtCoexist, type);
6098 
6099 	halbtcoutsrc_NormalLowPower(&GLBtCoexist);
6100 
6101 	return ret;
6102 }
6103 
6104 #endif /* CONFIG_BT_COEXIST */
6105