xref: /OK3568_Linux_fs/kernel/drivers/net/wireless/rockchip_wlan/rtl8189es/hal/hal_btcoex.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2013 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #define __HAL_BTCOEX_C__
21 
22 #ifdef CONFIG_BT_COEXIST
23 
24 #include <hal_data.h>
25 #include <hal_btcoex.h>
26 #include <Mp_Precomp.h>
27 
28 //====================================
29 //		Global variables
30 //====================================
31 const char *const BtProfileString[] =
32 {
33 	"NONE",
34 	"A2DP",
35 	"PAN",
36 	"HID",
37 	"SCO",
38 };
39 
40 const char *const BtSpecString[] =
41 {
42 	"1.0b",
43 	"1.1",
44 	"1.2",
45 	"2.0+EDR",
46 	"2.1+EDR",
47 	"3.0+HS",
48 	"4.0",
49 };
50 
51 const char *const BtLinkRoleString[] =
52 {
53 	"Master",
54 	"Slave",
55 };
56 
57 const char *const h2cStaString[] =
58 {
59 	"successful",
60 	"h2c busy",
61 	"rf off",
62 	"fw not read",
63 };
64 
65 const char *const ioStaString[] =
66 {
67 	"success",
68 	"can not IO",
69 	"rf off",
70 	"fw not read",
71 	"wait io timeout",
72 	"invalid len",
73 	"idle Q empty",
74 	"insert waitQ fail",
75 	"unknown fail",
76 	"wrong level",
77 	"h2c stopped",
78 };
79 
80 const char *const GLBtcWifiBwString[]={
81 	"11bg",
82 	"HT20",
83 	"HT40",
84 	"HT80",
85 	"HT160"
86 };
87 
88 const char *const GLBtcWifiFreqString[]={
89 	"2.4G",
90 	"5G"
91 };
92 
93 const char *const GLBtcIotPeerString[] = {
94 	"UNKNOWN",
95 	"REALTEK",
96 	"REALTEK_92SE",
97 	"BROADCOM",
98 	"RALINK",
99 	"ATHEROS",
100 	"CISCO",
101 	"MERU",
102 	"MARVELL",
103 	"REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
104 	"SELF_SOFTAP", /* Self is SoftAP */
105 	"AIRGO",
106 	"INTEL",
107 	"RTK_APCLIENT",
108 	"REALTEK_81XX",
109 	"REALTEK_WOW",
110 	"REALTEK_JAGUAR_BCUTAP",
111 	"REALTEK_JAGUAR_CCUTAP"
112 };
113 
114 #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS	8000
115 
116 BTC_COEXIST GLBtCoexist;
117 u8 GLBtcWiFiInScanState;
118 u8 GLBtcWiFiInIQKState;
119 u8 GLBtcWiFiInIPS;
120 u8 GLBtcWiFiInLPS;
121 u8 GLBtcBtCoexAliveRegistered;
122 
123 u32 GLBtcDbgType[COMP_MAX];
124 u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
125 
126 typedef struct _btcoexdbginfo
127 {
128 	u8 *info;
129 	u32 size; // buffer total size
130 	u32 len; // now used length
131 } BTCDBGINFO, *PBTCDBGINFO;
132 
133 BTCDBGINFO GLBtcDbgInfo;
134 
135 #define	BT_Operation(Adapter)						_FALSE
136 
DBG_BT_INFO_INIT(PBTCDBGINFO pinfo,u8 * pbuf,u32 size)137 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
138 {
139 	if (NULL == pinfo) return;
140 
141 	_rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
142 
143 	if (pbuf && size) {
144 		pinfo->info = pbuf;
145 		pinfo->size = size;
146 	}
147 }
148 
DBG_BT_INFO(u8 * dbgmsg)149 void DBG_BT_INFO(u8 *dbgmsg)
150 {
151 	PBTCDBGINFO pinfo;
152 	u32 msglen, buflen;
153 	u8 *pbuf;
154 
155 
156 	pinfo = &GLBtcDbgInfo;
157 
158 	if (NULL == pinfo->info)
159 		return;
160 
161 	msglen = strlen(dbgmsg);
162 	if (pinfo->len + msglen > pinfo->size)
163 		return;
164 
165 	pbuf = pinfo->info + pinfo->len;
166 	_rtw_memcpy(pbuf, dbgmsg, msglen);
167 	pinfo->len += msglen;
168 }
169 
170 //====================================
171 //		Debug related function
172 //====================================
halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)173 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
174 {
175 	if (!pBtCoexist->bBinded ||
176 		NULL == pBtCoexist->Adapter)
177 	{
178 		return _FALSE;
179 	}
180 	return _TRUE;
181 }
182 
halbtcoutsrc_DbgInit(void)183 static void halbtcoutsrc_DbgInit(void)
184 {
185 	u8	i;
186 
187 	for (i = 0; i < COMP_MAX; i++)
188 		GLBtcDbgType[i] = 0;
189 }
190 
halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)191 static u8 halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)
192 {
193 	if (pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC4
194 		|| pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC8
195 	){
196 		return _TRUE;
197 	}
198 	return _FALSE;
199 }
200 
halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)201 static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
202 {
203 	if (pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC4
204 		|| pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC8
205 	){
206 		return _FALSE;
207 	}
208 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
209 	{
210 		return _FALSE;
211 	}
212 	else
213 		return _TRUE;
214 }
215 
halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)216 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
217 {
218 	PADAPTER padapter;
219 
220 
221 	padapter = pBtCoexist->Adapter;
222 
223 	pBtCoexist->btInfo.bBtCtrlLps = _TRUE;
224 	pBtCoexist->btInfo.bBtLpsOn = _FALSE;
225 
226 	rtw_btcoex_LPS_Leave(padapter);
227 }
228 
halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)229 void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
230 {
231 	PADAPTER padapter;
232 
233 
234 	padapter = pBtCoexist->Adapter;
235 
236 	pBtCoexist->btInfo.bBtCtrlLps = _TRUE;
237 	pBtCoexist->btInfo.bBtLpsOn = _TRUE;
238 
239 	rtw_btcoex_LPS_Enter(padapter);
240 }
241 
halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)242 void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
243 {
244 	PADAPTER padapter;
245 
246 
247 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Normal LPS behavior!!!\n"));
248 
249 	padapter = pBtCoexist->Adapter;
250 
251 	if (pBtCoexist->btInfo.bBtCtrlLps)
252 	{
253 		pBtCoexist->btInfo.bBtLpsOn = _FALSE;
254 		rtw_btcoex_LPS_Leave(padapter);
255 		pBtCoexist->btInfo.bBtCtrlLps = _FALSE;
256 
257 		// recover the LPS state to the original
258 #if 0
259 		padapter->HalFunc.UpdateLPSStatusHandler(
260 			padapter,
261 			pPSC->RegLeisurePsMode,
262 			pPSC->RegPowerSaveMode);
263 #endif
264 	}
265 }
266 
267 /*
268  *  Constraint:
269  *	   1. this function will request pwrctrl->lock
270  */
halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)271 void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
272 {
273 #ifdef CONFIG_LPS_LCLK
274 	PADAPTER padapter;
275 	PHAL_DATA_TYPE pHalData;
276 	struct pwrctrl_priv *pwrctrl;
277 	s32 ready;
278 	u32 stime;
279 	s32 utime;
280 	u32 timeout; // unit: ms
281 
282 
283 	padapter = pBtCoexist->Adapter;
284 	pHalData = GET_HAL_DATA(padapter);
285 	pwrctrl = adapter_to_pwrctl(padapter);
286 	ready = _FAIL;
287 #ifdef LPS_RPWM_WAIT_MS
288 	timeout = LPS_RPWM_WAIT_MS;
289 #else // !LPS_RPWM_WAIT_MS
290 	timeout = 30;
291 #endif // !LPS_RPWM_WAIT_MS
292 
293 	if (GLBtcBtCoexAliveRegistered == _TRUE)
294 		return;
295 
296 	stime = rtw_get_current_time();
297 	do {
298 		ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
299 		if (_SUCCESS == ready)
300 			break;
301 
302 		utime = rtw_get_passing_time_ms(stime);
303 		if (utime > timeout)
304 			break;
305 
306 		rtw_msleep_os(1);
307 	} while (1);
308 
309 	GLBtcBtCoexAliveRegistered = _TRUE;
310 #endif // CONFIG_LPS_LCLK
311 }
312 
313 /*
314  *  Constraint:
315  *	   1. this function will request pwrctrl->lock
316  */
halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)317 void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
318 {
319 #ifdef CONFIG_LPS_LCLK
320 	PADAPTER padapter;
321 
322 	if (GLBtcBtCoexAliveRegistered == _FALSE)
323 		return;
324 
325 	padapter = pBtCoexist->Adapter;
326 	rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
327 
328 	GLBtcBtCoexAliveRegistered = _FALSE;
329 #endif // CONFIG_LPS_LCLK
330 }
331 
halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist,u8 bLowPwrDisable)332 void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
333 {
334 	pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
335 	if (bLowPwrDisable)
336 		halbtcoutsrc_LeaveLowPower(pBtCoexist);		// leave 32k low power.
337 	else
338 		halbtcoutsrc_NormalLowPower(pBtCoexist);	// original 32k low power behavior.
339 }
340 
halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)341 void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
342 {
343 	PADAPTER padapter;
344 	BOOLEAN bNeedToAct = _FALSE;
345 	static u32 preTime = 0;
346 	u32 curTime = 0;
347 
348 	padapter = pBtCoexist->Adapter;
349 
350 	//=====================================
351 	// To void continuous deleteBA=>addBA=>deleteBA=>addBA
352 	// This function is not allowed to continuous called.
353 	// It can only be called after 8 seconds.
354 	//=====================================
355 
356 	curTime = rtw_systime_to_ms(rtw_get_current_time());
357 	if((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS)	// over 8 seconds you can execute this function again.
358 	{
359 		return;
360 	}
361 	else
362 	{
363 		preTime = curTime;
364 	}
365 
366 	if (pBtCoexist->btInfo.bRejectAggPkt)
367 	{
368 		bNeedToAct = _TRUE;
369 		pBtCoexist->btInfo.bPreRejectAggPkt = pBtCoexist->btInfo.bRejectAggPkt;
370 	}
371 	else
372 	{
373 		if(pBtCoexist->btInfo.bPreRejectAggPkt)
374 		{
375 			bNeedToAct = _TRUE;
376 			pBtCoexist->btInfo.bPreRejectAggPkt = pBtCoexist->btInfo.bRejectAggPkt;
377 		}
378 
379 		if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
380 			pBtCoexist->btInfo.bBtCtrlAggBufSize)
381 		{
382 			bNeedToAct = _TRUE;
383 			pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
384 		}
385 
386 		if (pBtCoexist->btInfo.bBtCtrlAggBufSize)
387 		{
388 			if (pBtCoexist->btInfo.preAggBufSize !=
389 				pBtCoexist->btInfo.aggBufSize)
390 			{
391 				bNeedToAct = _TRUE;
392 			}
393 			pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
394 		}
395 	}
396 
397 	if (bNeedToAct)
398 		rtw_btcoex_rx_ampdu_apply(padapter);
399 }
400 
halbtcoutsrc_IsWifiBusy(PADAPTER padapter)401 u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
402 {
403 	struct mlme_priv *pmlmepriv;
404 
405 
406 	pmlmepriv = &padapter->mlmepriv;
407 
408 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
409 	{
410 		if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
411 			return _TRUE;
412 		if (_TRUE == pmlmepriv->LinkDetectInfo.bBusyTraffic)
413 			return _TRUE;
414 	}
415 
416 #if defined(CONFIG_CONCURRENT_MODE)
417 	pmlmepriv = &padapter->pbuddy_adapter->mlmepriv;
418 
419 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
420 	{
421 		if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
422 			return _TRUE;
423 		if (_TRUE == pmlmepriv->LinkDetectInfo.bBusyTraffic)
424 			return _TRUE;
425 	}
426 #endif
427 
428 	return _FALSE;
429 }
430 
_halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)431 static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
432 {
433 	struct mlme_priv *pmlmepriv;
434 	u8 bp2p;
435 	u32 portConnectedStatus;
436 
437 
438 	pmlmepriv = &padapter->mlmepriv;
439 	bp2p = _FALSE;
440 	portConnectedStatus = 0;
441 
442 #ifdef CONFIG_P2P
443 	if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
444 		bp2p = _TRUE;
445 #endif // CONFIG_P2P
446 
447 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
448 	{
449 		if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
450 		{
451 			if (_TRUE == bp2p)
452 				portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
453 			else
454 				portConnectedStatus |= WIFI_AP_CONNECTED;
455 		}
456 		else
457 		{
458 			if (_TRUE == bp2p)
459 				portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
460 			else
461 				portConnectedStatus |= WIFI_STA_CONNECTED;
462 		}
463 	}
464 
465 	return portConnectedStatus;
466 }
467 
halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)468 u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
469 {
470 	//=================================
471 	// return value:
472 	// [31:16]=> connected port number
473 	// [15:0]=> port connected bit define
474 	//================================
475 
476 	PADAPTER padapter;
477 	u32 retVal;
478 	u32 portConnectedStatus, numOfConnectedPort;
479 
480 
481 	padapter = pBtCoexist->Adapter;
482 	retVal = 0;
483 	portConnectedStatus = 0;
484 	numOfConnectedPort = 0;
485 
486 	retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
487 	if (retVal)
488 	{
489 		portConnectedStatus |= retVal;
490 		numOfConnectedPort++;
491 	}
492 
493 #ifdef CONFIG_CONCURRENT_MODE
494 	if (padapter->pbuddy_adapter)
495 	{
496 		retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter->pbuddy_adapter);
497 		if (retVal)
498 		{
499 			portConnectedStatus |= retVal;
500 			numOfConnectedPort++;
501 		}
502 	}
503 #endif // CONFIG_CONCURRENT_MODE
504 
505 	retVal = (numOfConnectedPort << 16) | portConnectedStatus;
506 
507 	return retVal;
508 }
509 
halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)510 u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
511 {
512 	u16 btRealFwVer = 0x0;
513 	u8 btFwVer = 0x0;
514 	u8 cnt = 0;
515 
516 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
517 	if (!pBtCoexist->btInfo.btRealFwVer && cnt<=5)
518 	{
519 #if 0
520 		if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist))
521 		{	// mailbox exists, through mailbox
522 			if (NDBG_GetBtFwVersion(pBtCoexist->Adapter, &btRealFwVer, &btFwVer))
523 			{
524 				pBtCoexist->btInfo.btRealFwVer = btRealFwVer;
525 				pBtCoexist->btInfo.btFwVer = btFwVer;
526 			}
527 			else
528 			{
529 				pBtCoexist->btInfo.btRealFwVer = 0x0;
530 				pBtCoexist->btInfo.btFwVer = 0x0;
531 			}
532 		}
533 		else	// no mailbox, query bt patch version through stack.
534 #endif
535 		// query bt patch version through socket.
536 		{
537 			u1Byte	dataLen=2;
538 			u1Byte	buf[4] = {0};
539 			buf[0] = 0x0;	// OP_Code
540 			buf[1] = 0x0;	// OP_Code_Length
541 			BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
542 		}
543 		cnt++;
544 	}
545 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
546 	return pBtCoexist->btInfo.btRealFwVer;
547 }
548 
halbtcoutsrc_GetWifiRssi(PADAPTER padapter)549 s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
550 {
551 	PHAL_DATA_TYPE pHalData;
552 	s32 UndecoratedSmoothedPWDB = 0;
553 
554 	pHalData = GET_HAL_DATA(padapter);
555 
556 	UndecoratedSmoothedPWDB = pHalData->EntryMinUndecoratedSmoothedPWDB;
557 
558 	return UndecoratedSmoothedPWDB;
559 }
560 
halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)561 static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
562 {
563 	struct mlme_priv *pmlmepriv;
564 	struct mlme_ext_priv *pmlmeext;
565 	static u8 scan_AP_num = 0;
566 
567 
568 	pmlmepriv = &padapter->mlmepriv;
569 	pmlmeext = &padapter->mlmeextpriv;
570 
571 	if (GLBtcWiFiInScanState == _FALSE) {
572 		if (pmlmepriv->num_of_scanned > 0xFF)
573 			scan_AP_num = 0xFF;
574 		else
575 			scan_AP_num = (u8)pmlmepriv->num_of_scanned;
576 	}
577 
578 	return scan_AP_num;
579 }
580 
halbtcoutsrc_Get(void * pBtcContext,u8 getType,void * pOutBuf)581 u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
582 {
583 	PBTC_COEXIST pBtCoexist;
584 	PADAPTER padapter;
585 	PHAL_DATA_TYPE pHalData;
586 	struct mlme_ext_priv *mlmeext;
587 	u8 bSoftApExist, bVwifiExist;
588 	u8 *pu8;
589 	s32 *pS4Tmp;
590 	u32 *pU4Tmp;
591 	u8 *pU1Tmp;
592 	u8 ret;
593 
594 
595 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
596 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
597 		return _FALSE;
598 
599 	padapter = pBtCoexist->Adapter;
600 	pHalData = GET_HAL_DATA(padapter);
601 	mlmeext = &padapter->mlmeextpriv;
602 	bSoftApExist = _FALSE;
603 	bVwifiExist = _FALSE;
604 	pu8 = (u8*)pOutBuf;
605 	pS4Tmp = (s32*)pOutBuf;
606 	pU4Tmp = (u32*)pOutBuf;
607 	pU1Tmp = (u8*)pOutBuf;
608 	ret = _TRUE;
609 
610 	switch (getType)
611 	{
612 		case BTC_GET_BL_HS_OPERATION:
613 			*pu8 = _FALSE;
614 			ret = _FALSE;
615 			break;
616 
617 		case BTC_GET_BL_HS_CONNECTING:
618 			*pu8 = _FALSE;
619 			ret = _FALSE;
620 			break;
621 
622 		case BTC_GET_BL_WIFI_CONNECTED:
623 			*pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
624 #ifdef CONFIG_CONCURRENT_MODE
625 			if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
626 			{
627 				*pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_ASOC_STATE);
628 			}
629 #endif // CONFIG_CONCURRENT_MODE
630 			break;
631 
632 		case BTC_GET_BL_WIFI_BUSY:
633 			*pu8 = halbtcoutsrc_IsWifiBusy(padapter);
634 			break;
635 
636 		case BTC_GET_BL_WIFI_SCAN:
637 #if 0
638 			*pu8 = check_fwstate(&padapter->mlmepriv, WIFI_SITE_MONITOR);
639 #ifdef CONFIG_CONCURRENT_MODE
640 			if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
641 			{
642 				*pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_SITE_MONITOR);
643 			}
644 #endif // CONFIG_CONCURRENT_MODE
645 #else
646 			/* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
647 				WIFI_SITE_MONITOR in fwstate may not be cleared in time */
648 			*pu8 = GLBtcWiFiInScanState;
649 #endif
650 			break;
651 
652 		case BTC_GET_BL_WIFI_LINK:
653 			*pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
654 #ifdef CONFIG_CONCURRENT_MODE
655 			if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
656 			{
657 				*pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_UNDER_LINKING);
658 			}
659 #endif // CONFIG_CONCURRENT_MODE
660 			break;
661 
662 		case BTC_GET_BL_WIFI_ROAM:
663 			*pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
664 #ifdef CONFIG_CONCURRENT_MODE
665 			if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
666 			{
667 				*pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_UNDER_LINKING);
668 			}
669 #endif // CONFIG_CONCURRENT_MODE
670 			break;
671 
672 		case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
673 			*pu8 = _FALSE;
674 			break;
675 
676 		case BTC_GET_BL_WIFI_UNDER_5G:
677 			*pu8 = (pHalData->CurrentBandType == 1)? _TRUE : _FALSE;
678 			break;
679 
680 		case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
681 			*pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
682 #ifdef CONFIG_CONCURRENT_MODE
683 			if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
684 			{
685 				*pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_AP_STATE);
686 			}
687 #endif // CONFIG_CONCURRENT_MODE
688 			break;
689 
690 		case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
691 			*pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0? _FALSE: _TRUE;
692 			break;
693 
694 		case BTC_GET_BL_WIFI_UNDER_B_MODE:
695 			if (mlmeext->cur_wireless_mode == WIRELESS_11B)
696 				*pu8 = _TRUE;
697 			else
698 				*pu8 = _FALSE;
699 			break;
700 
701 		case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
702 			if (padapter->registrypriv.mp_mode == 0)
703 			{
704 				*pu8 = _FALSE;
705 			}
706 			else
707 			{
708 				*pu8 = _TRUE;
709 			}
710 			break;
711 
712 		case BTC_GET_BL_EXT_SWITCH:
713 			*pu8 = _FALSE;
714 			break;
715 		case BTC_GET_BL_IS_ASUS_8723B:
716 			/* Always return FALSE in linux driver since this case is added only for windows driver */
717 			*pu8 = _FALSE;
718 			break;
719 
720 		case BTC_GET_S4_WIFI_RSSI:
721 			*pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
722 			break;
723 
724 		case BTC_GET_S4_HS_RSSI:
725 			*pS4Tmp = 0;
726 			ret = _FALSE;
727 			break;
728 
729 		case BTC_GET_U4_WIFI_BW:
730 			if (IsLegacyOnly(mlmeext->cur_wireless_mode))
731 				*pU4Tmp = BTC_WIFI_BW_LEGACY;
732 			else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
733 				*pU4Tmp = BTC_WIFI_BW_HT20;
734 			else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
735 				*pU4Tmp = BTC_WIFI_BW_HT40;
736 			else
737 				*pU4Tmp = BTC_WIFI_BW_HT40; /* todo */
738 			break;
739 
740 		case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
741 			{
742 				PRT_LINK_DETECT_T plinkinfo;
743 				plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
744 
745 				if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
746 					*pU4Tmp = BTC_WIFI_TRAFFIC_TX;
747 				else
748 					*pU4Tmp = BTC_WIFI_TRAFFIC_RX;
749 			}
750 			break;
751 
752 		case BTC_GET_U4_WIFI_FW_VER:
753 			*pU4Tmp = pHalData->FirmwareVersion << 16;
754 			*pU4Tmp |= pHalData->FirmwareSubVersion;
755 			break;
756 
757 		case BTC_GET_U4_WIFI_LINK_STATUS:
758 			*pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
759 			break;
760 
761 		case BTC_GET_U4_BT_PATCH_VER:
762 			*pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
763 			break;
764 
765 		case BTC_GET_U1_WIFI_DOT11_CHNL:
766 			*pU1Tmp = padapter->mlmeextpriv.cur_channel;
767 			break;
768 
769 		case BTC_GET_U1_WIFI_CENTRAL_CHNL:
770 			*pU1Tmp = pHalData->CurrentChannel;
771 			break;
772 
773 		case BTC_GET_U1_WIFI_HS_CHNL:
774 			*pU1Tmp = 0;
775 			ret = _FALSE;
776 			break;
777 
778 		case BTC_GET_U1_MAC_PHY_MODE:
779 //			*pU1Tmp = BTC_SMSP;
780 //			*pU1Tmp = BTC_DMSP;
781 //			*pU1Tmp = BTC_DMDP;
782 //			*pU1Tmp = BTC_MP_UNKNOWN;
783 			break;
784 
785 		case BTC_GET_U1_AP_NUM:
786 			*pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
787 			break;
788 		case BTC_GET_U1_ANT_TYPE:
789 			switch(pHalData->bt_coexist.btAntisolation)
790 			{
791 				case 0:
792 					*pU1Tmp = (u1Byte)BTC_ANT_TYPE_0;
793 					pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_0;
794 					break;
795 				case 1:
796 					*pU1Tmp = (u1Byte)BTC_ANT_TYPE_1;
797 					pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_1;
798 					break;
799 				case 2:
800 					*pU1Tmp = (u1Byte)BTC_ANT_TYPE_2;
801 					pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_2;
802 					break;
803 				case 3:
804 					*pU1Tmp = (u1Byte)BTC_ANT_TYPE_3;
805 					pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_3;
806 					break;
807 				case 4:
808 					*pU1Tmp = (u1Byte)BTC_ANT_TYPE_4;
809 					pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_4;
810 					break;
811 			}
812 			break;
813 		case BTC_GET_U1_IOT_PEER:
814 			*pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;
815 			break;
816 
817 		//=======1Ant===========
818 		case BTC_GET_U1_LPS_MODE:
819 			*pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
820 			break;
821 
822 		default:
823 			ret = _FALSE;
824 			break;
825 	}
826 
827 	return ret;
828 }
829 
halbtcoutsrc_Set(void * pBtcContext,u8 setType,void * pInBuf)830 u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
831 {
832 	PBTC_COEXIST pBtCoexist;
833 	PADAPTER padapter;
834 	PHAL_DATA_TYPE pHalData;
835 	u8 *pu8;
836 	u8 *pU1Tmp;
837 	u32	*pU4Tmp;
838 	u8 ret;
839 
840 
841 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
842 	padapter = pBtCoexist->Adapter;
843 	pHalData = GET_HAL_DATA(padapter);
844 	pu8 = (u8*)pInBuf;
845 	pU1Tmp = (u8*)pInBuf;
846 	pU4Tmp = (u32*)pInBuf;
847 	ret = _TRUE;
848 
849 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
850 		return _FALSE;
851 
852 	switch (setType)
853 	{
854 		// set some u8 type variables.
855 		case BTC_SET_BL_BT_DISABLE:
856 			pBtCoexist->btInfo.bBtDisabled = *pu8;
857 			break;
858 
859 		case BTC_SET_BL_BT_TRAFFIC_BUSY:
860 			pBtCoexist->btInfo.bBtBusy = *pu8;
861 			break;
862 
863 		case BTC_SET_BL_BT_LIMITED_DIG:
864 			pBtCoexist->btInfo.bLimitedDig = *pu8;
865 			break;
866 
867 		case BTC_SET_BL_FORCE_TO_ROAM:
868 			pBtCoexist->btInfo.bForceToRoam = *pu8;
869 			break;
870 
871 		case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
872 			pBtCoexist->btInfo.bRejectAggPkt = *pu8;
873 			break;
874 
875 		case BTC_SET_BL_BT_CTRL_AGG_SIZE:
876 			pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
877 			break;
878 
879 		case BTC_SET_BL_INC_SCAN_DEV_NUM:
880 			pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
881 			break;
882 
883 		case BTC_SET_BL_BT_TX_RX_MASK:
884 			pBtCoexist->btInfo.bBtTxRxMask = *pu8;
885 			break;
886 
887 		case BTC_SET_BL_MIRACAST_PLUS_BT:
888 			pBtCoexist->btInfo.bMiracastPlusBt = *pu8;
889 			break;
890 
891 		// set some u8 type variables.
892 		case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
893 			pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pU1Tmp;
894 			break;
895 
896 		case BTC_SET_U1_AGG_BUF_SIZE:
897 			pBtCoexist->btInfo.aggBufSize = *pU1Tmp;
898 			break;
899 
900 		// the following are some action which will be triggered
901 		case BTC_SET_ACT_GET_BT_RSSI:
902 #if 0
903 			BT_SendGetBtRssiEvent(padapter);
904 #else
905 			ret = _FALSE;
906 #endif
907 			break;
908 
909 		case BTC_SET_ACT_AGGREGATE_CTRL:
910 			halbtcoutsrc_AggregationCheck(pBtCoexist);
911 			break;
912 
913 		//=======1Ant===========
914 		// set some u8 type variables.
915 		case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
916 			pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pU1Tmp;
917 			break;
918 
919 		case BTC_SET_U1_LPS_VAL:
920 			pBtCoexist->btInfo.lpsVal = *pU1Tmp;
921 			break;
922 
923 		case BTC_SET_U1_RPWM_VAL:
924 			pBtCoexist->btInfo.rpwmVal = *pU1Tmp;
925 			break;
926 
927 		// the following are some action which will be triggered
928 		case BTC_SET_ACT_LEAVE_LPS:
929 			halbtcoutsrc_LeaveLps(pBtCoexist);
930 			break;
931 
932 		case BTC_SET_ACT_ENTER_LPS:
933 			halbtcoutsrc_EnterLps(pBtCoexist);
934 			break;
935 
936 		case BTC_SET_ACT_NORMAL_LPS:
937 			halbtcoutsrc_NormalLps(pBtCoexist);
938 			break;
939 
940 		case BTC_SET_ACT_DISABLE_LOW_POWER:
941 			halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
942 			break;
943 
944 		case BTC_SET_ACT_UPDATE_RAMASK:
945 			pBtCoexist->btInfo.raMask = *pU4Tmp;
946 
947 			if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE)
948 			{
949 				struct sta_info *psta;
950 				PWLAN_BSSID_EX cur_network;
951 
952 				cur_network = &padapter->mlmeextpriv.mlmext_info.network;
953 				psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
954 				rtw_hal_update_ra_mask(psta, 0);
955 			}
956 			break;
957 
958 		case BTC_SET_ACT_SEND_MIMO_PS:
959 			{
960 				u8 newMimoPsMode = 3;
961 				struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
962 				struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
963 
964 				/* *pU1Tmp = 0 use SM_PS static type */
965 				/* *pU1Tmp = 1 disable SM_PS */
966 				if (*pU1Tmp == 0)
967 					newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
968 				else if (*pU1Tmp == 1)
969 					newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
970 
971 				if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) {
972 					/* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */
973 					issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1);
974 				}
975 			}
976 			break;
977 
978 		case BTC_SET_ACT_CTRL_BT_INFO:
979 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
980 			{
981 				u8 dataLen = *pU1Tmp;
982 				u8 tmpBuf[20];
983 				if (dataLen)
984 				{
985 					_rtw_memcpy(tmpBuf, pU1Tmp+1, dataLen);
986 				}
987 				BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
988 			}
989 #else //!CONFIG_BT_COEXIST_SOCKET_TRX
990 			ret = _FALSE;
991 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
992 			break;
993 
994 		case BTC_SET_ACT_CTRL_BT_COEX:
995 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
996 			{
997 				u8 dataLen = *pU1Tmp;
998 				u8 tmpBuf[20];
999 				if (dataLen)
1000 				{
1001 					_rtw_memcpy(tmpBuf, pU1Tmp+1, dataLen);
1002 				}
1003 				BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
1004 			}
1005 #else //!CONFIG_BT_COEXIST_SOCKET_TRX
1006 			ret = _FALSE;
1007 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
1008 			break;
1009 		case BTC_SET_ACT_CTRL_8723B_ANT:
1010 #if 0
1011 			{
1012 				u1Byte	dataLen=*pU1Tmp;
1013 				u1Byte	tmpBuf[20];
1014 				if(dataLen)
1015 				{
1016 					PlatformMoveMemory(&tmpBuf[0], pU1Tmp+1, dataLen);
1017 				}
1018 				BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
1019 			}
1020 #else
1021 			ret = _FALSE;
1022 #endif
1023 			break;
1024 		//=====================
1025 		default:
1026 			ret = _FALSE;
1027 			break;
1028 	}
1029 
1030 	return ret;
1031 }
1032 
halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)1033 u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
1034 {
1035 	PADAPTER padapter;
1036 	struct pwrctrl_priv *pwrpriv;
1037 	u8 bMacPwrCtrlOn;
1038 
1039 	padapter = pBtCoexist->Adapter;
1040 	pwrpriv = &padapter->dvobj->pwrctl_priv;
1041 	bMacPwrCtrlOn = _FALSE;
1042 
1043 	if ((_TRUE == pwrpriv->bips_processing)
1044 		&& (IPS_NONE != pwrpriv->ips_mode_req)
1045 		)
1046 	{
1047 		return _TRUE;
1048 	}
1049 
1050 	if (rf_off == pwrpriv->rf_pwrstate)
1051 	{
1052 		return _TRUE;
1053 	}
1054 
1055 	rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
1056 	if (_FALSE == bMacPwrCtrlOn)
1057 	{
1058 		return _TRUE;
1059 	}
1060 
1061 	return _FALSE;
1062 }
1063 
halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)1064 u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
1065 {
1066 	return GLBtcWiFiInLPS;
1067 }
1068 
halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)1069 u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
1070 {
1071 	/* todo: the method to check whether wifi is under 32K or not */
1072 	return _FALSE;
1073 }
1074 
halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)1075 void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
1076 {
1077 #if 0
1078 	PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1079 	PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1080 	PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
1081 	u8 *cliBuf = pBtCoexist->cliBuf;
1082 	u8 i;
1083 
1084 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
1085 	CL_PRINTF(cliBuf);
1086 
1087 #if (H2C_USE_IO_THREAD != 1)
1088 	for(i=0; i<H2C_STATUS_MAX; i++)
1089 	{
1090 		if (pHalData->h2cStatistics[i])
1091 		{
1092 			CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1093 				h2cStaString[i], pHalData->h2cStatistics[i]);
1094 			CL_PRINTF(cliBuf);
1095 		}
1096 	}
1097 #else
1098 		for(i=0; i<IO_STATUS_MAX; i++)
1099 		{
1100 			if(Adapter->ioComStr.ioH2cStatistics[i])
1101 			{
1102 				CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1103 					ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);
1104 				CL_PRINTF(cliBuf);
1105 			}
1106 		}
1107 #endif
1108 #if 0
1109 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
1110 		pHalData->LastHMEBoxNum);
1111 	CL_PRINTF(cliBuf);
1112 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
1113 		pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
1114 	CL_PRINTF(cliBuf);
1115 
1116 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \
1117 		pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,
1118 		DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);
1119 	CL_PRINTF(cliBuf);
1120 
1121 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
1122 		DBG_Var.c2hPacketCnt);
1123 	CL_PRINTF(cliBuf);
1124 #endif
1125 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
1126 		pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
1127 	CL_PRINTF(cliBuf);
1128 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \
1129 		pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,
1130 		pBtCoexist->statistics.cntRfStatusNotify);
1131 	CL_PRINTF(cliBuf);
1132 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \
1133 		pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,
1134 		pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,
1135 		pBtCoexist->statistics.cntMediaStatusNotify);
1136 	CL_PRINTF(cliBuf);
1137 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind",
1138 		pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify,
1139 		pBtCoexist->statistics.cntBind);
1140 	CL_PRINTF(cliBuf);
1141 #endif
1142 }
1143 
halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)1144 void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
1145 {
1146 #if 0
1147 	PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1148 	PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1149 	u8 *cliBuf = pBtCoexist->cliBuf;
1150 	u8 i;
1151 
1152 
1153 	if (pBtCoexist->stackInfo.bProfileNotified)
1154 	{
1155 		for (i=0; i<pBtMgnt->ExtConfig.NumberOfACL; i++)
1156 		{
1157 			if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1)
1158 			{
1159 				CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \
1160 					BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1161 					BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],
1162 					BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);
1163 				CL_PRINTF(cliBuf);				}
1164 			else
1165 			{
1166 				CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
1167 					BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1168 					BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);
1169 				CL_PRINTF(cliBuf);
1170 			}
1171 		}
1172 	}
1173 #endif
1174 }
1175 
halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)1176 void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
1177 {
1178 	PADAPTER	padapter = pBtCoexist->Adapter;
1179 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1180 	u8* 			cliBuf=pBtCoexist->cliBuf;
1181 	s32			wifiRssi=0, btHsRssi=0;
1182 	BOOLEAN	bScan=_FALSE, bLink=_FALSE, bRoam=_FALSE, bWifiBusy=_FALSE, bWifiUnderBMode=_FALSE;
1183 	u32			wifiBw=BTC_WIFI_BW_HT20, wifiTrafficDir=BTC_WIFI_TRAFFIC_TX, wifiFreq=BTC_FREQ_2_4G;
1184 	u32			wifiLinkStatus=0x0;
1185 	BOOLEAN	bBtHsOn=_FALSE, bLowPower=_FALSE;
1186 	u8			wifiChnl=0, wifiHsChnl=0, nScanAPNum = 0, FwPSState;
1187 
1188 	wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
1189 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc", \
1190 		((wifiLinkStatus&WIFI_STA_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_AP_CONNECTED)? 1:0),
1191 		((wifiLinkStatus&WIFI_HS_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_P2P_GO_CONNECTED)? 1:0),
1192 		((wifiLinkStatus&WIFI_P2P_GC_CONNECTED)? 1:0) );
1193 	CL_PRINTF(cliBuf);
1194 
1195 	if (wifiLinkStatus&WIFI_STA_CONNECTED) {
1196 		CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "IOT Peer", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor]);
1197 		CL_PRINTF(cliBuf);
1198 	}
1199 
1200 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1201 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiChnl);
1202 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl);	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(High Speed)", \
1203 		wifiChnl, wifiHsChnl, bBtHsOn);
1204 	CL_PRINTF(cliBuf);
1205 
1206 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
1207 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);
1208 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \
1209 		wifiRssi-100, btHsRssi-100);
1210 	CL_PRINTF(cliBuf);
1211 
1212 
1213 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1214 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1215 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1216 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \
1217 		bLink, bRoam, bScan);
1218 	CL_PRINTF(cliBuf);
1219 
1220 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifiFreq);
1221 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1222 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1223 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1224 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
1225 	pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);
1226 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ AP=%d ", "Wifi freq/ bw/ traffic", \
1227 		GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode)? "11b": GLBtcWifiBwString[wifiBw]),
1228 		((!bWifiBusy)? "idle": ((BTC_WIFI_TRAFFIC_TX==wifiTrafficDir)? "uplink":"downlink")),
1229 		nScanAPNum);
1230 	CL_PRINTF(cliBuf);
1231 
1232 	// power status
1233 	CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \
1234 		((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE)? "IPS ON":"IPS OFF"),
1235 		((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE)? ", LPS ON":", LPS OFF"),
1236 		((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE)? ", 32k":""));
1237 	CL_PRINTF(cliBuf);
1238 
1239 	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)", \
1240 		pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
1241 		pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
1242 		pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],
1243 		pBtCoexist->btInfo.lpsVal,
1244 		pBtCoexist->btInfo.rpwmVal);
1245 	CL_PRINTF(cliBuf);
1246 }
1247 
halbtcoutsrc_DisplayDbgMsg(void * pBtcContext,u8 dispType)1248 void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
1249 {
1250 	PBTC_COEXIST pBtCoexist;
1251 
1252 
1253 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1254 	switch(dispType)
1255 	{
1256 		case BTC_DBG_DISP_COEX_STATISTICS:
1257 			halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
1258 			break;
1259 		case BTC_DBG_DISP_BT_LINK_INFO:
1260 			halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
1261 			break;
1262 		case BTC_DBG_DISP_WIFI_STATUS:
1263 			halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
1264 			break;
1265 		default:
1266 			break;
1267 	}
1268 }
1269 
1270 //====================================
1271 //		IO related function
1272 //====================================
halbtcoutsrc_Read1Byte(void * pBtcContext,u32 RegAddr)1273 u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
1274 {
1275 	PBTC_COEXIST pBtCoexist;
1276 	PADAPTER padapter;
1277 
1278 
1279 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1280 	padapter = pBtCoexist->Adapter;
1281 
1282 	return rtw_read8(padapter, RegAddr);
1283 }
1284 
halbtcoutsrc_Read2Byte(void * pBtcContext,u32 RegAddr)1285 u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
1286 {
1287 	PBTC_COEXIST pBtCoexist;
1288 	PADAPTER padapter;
1289 
1290 
1291 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1292 	padapter = pBtCoexist->Adapter;
1293 
1294 	return	rtw_read16(padapter, RegAddr);
1295 }
1296 
halbtcoutsrc_Read4Byte(void * pBtcContext,u32 RegAddr)1297 u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
1298 {
1299 	PBTC_COEXIST pBtCoexist;
1300 	PADAPTER padapter;
1301 
1302 
1303 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1304 	padapter = pBtCoexist->Adapter;
1305 
1306 	return	rtw_read32(padapter, RegAddr);
1307 }
1308 
halbtcoutsrc_Write1Byte(void * pBtcContext,u32 RegAddr,u8 Data)1309 void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1310 {
1311 	PBTC_COEXIST pBtCoexist;
1312 	PADAPTER padapter;
1313 
1314 
1315 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1316 	padapter = pBtCoexist->Adapter;
1317 
1318 	rtw_write8(padapter, RegAddr, Data);
1319 }
1320 
halbtcoutsrc_BitMaskWrite1Byte(void * pBtcContext,u32 regAddr,u8 bitMask,u8 data1b)1321 void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
1322 {
1323 	PBTC_COEXIST pBtCoexist;
1324 	PADAPTER padapter;
1325 	u8 originalValue, bitShift;
1326 	u8 i;
1327 
1328 
1329 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1330 	padapter = pBtCoexist->Adapter;
1331 	originalValue = 0;
1332 	bitShift = 0;
1333 
1334 	if(bitMask != 0xff)
1335 	{
1336 		originalValue = rtw_read8(padapter, regAddr);
1337 
1338 		for (i=0; i<=7; i++)
1339 		{
1340 			if ((bitMask>>i)&0x1)
1341 				break;
1342 		}
1343 		bitShift = i;
1344 
1345 		data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
1346 	}
1347 
1348 	rtw_write8(padapter, regAddr, data1b);
1349 }
1350 
halbtcoutsrc_Write2Byte(void * pBtcContext,u32 RegAddr,u16 Data)1351 void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
1352 {
1353 	PBTC_COEXIST pBtCoexist;
1354 	PADAPTER padapter;
1355 
1356 
1357 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1358 	padapter = pBtCoexist->Adapter;
1359 
1360 	rtw_write16(padapter, RegAddr, Data);
1361 }
1362 
halbtcoutsrc_Write4Byte(void * pBtcContext,u32 RegAddr,u32 Data)1363 void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
1364 {
1365 	PBTC_COEXIST pBtCoexist;
1366 	PADAPTER padapter;
1367 
1368 
1369 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1370 	padapter = pBtCoexist->Adapter;
1371 
1372 	rtw_write32(padapter, RegAddr, Data);
1373 }
1374 
halbtcoutsrc_WriteLocalReg1Byte(void * pBtcContext,u32 RegAddr,u8 Data)1375 void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1376 {
1377 	PBTC_COEXIST		pBtCoexist=(PBTC_COEXIST)pBtcContext;
1378 	PADAPTER			Adapter=pBtCoexist->Adapter;
1379 
1380 	if(BTC_INTF_SDIO == pBtCoexist->chipInterface)
1381 	{
1382 		rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
1383 	}
1384 	else
1385 	{
1386 		rtw_write8(Adapter, RegAddr, Data);
1387 	}
1388 }
1389 
halbtcoutsrc_SetBbReg(void * pBtcContext,u32 RegAddr,u32 BitMask,u32 Data)1390 void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
1391 {
1392 	PBTC_COEXIST pBtCoexist;
1393 	PADAPTER padapter;
1394 
1395 
1396 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1397 	padapter = pBtCoexist->Adapter;
1398 
1399 	PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
1400 }
1401 
1402 
halbtcoutsrc_GetBbReg(void * pBtcContext,u32 RegAddr,u32 BitMask)1403 u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
1404 {
1405 	PBTC_COEXIST pBtCoexist;
1406 	PADAPTER padapter;
1407 
1408 
1409 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1410 	padapter = pBtCoexist->Adapter;
1411 
1412 	return PHY_QueryBBReg(padapter, RegAddr, BitMask);
1413 }
1414 
halbtcoutsrc_SetRfReg(void * pBtcContext,u8 eRFPath,u32 RegAddr,u32 BitMask,u32 Data)1415 void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
1416 {
1417 	PBTC_COEXIST pBtCoexist;
1418 	PADAPTER padapter;
1419 
1420 
1421 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1422 	padapter = pBtCoexist->Adapter;
1423 
1424 	PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
1425 }
1426 
halbtcoutsrc_GetRfReg(void * pBtcContext,u8 eRFPath,u32 RegAddr,u32 BitMask)1427 u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
1428 {
1429 	PBTC_COEXIST pBtCoexist;
1430 	PADAPTER padapter;
1431 
1432 
1433 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1434 	padapter = pBtCoexist->Adapter;
1435 
1436 	return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
1437 }
1438 
halbtcoutsrc_SetBtReg(void * pBtcContext,u8 RegType,u32 RegAddr,u32 Data)1439 void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
1440 {
1441 	PBTC_COEXIST pBtCoexist;
1442 	PADAPTER padapter;
1443 	u8 CmdBuffer1[4] = {0};
1444 	u8 CmdBuffer2[4] = {0};
1445 	u8* AddrToSet = (u8*)&RegAddr;
1446 	u8* ValueToSet = (u8*)&Data;
1447 	u8 OperVer = 0;
1448 	u8 ReqNum = 0;
1449 
1450 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1451 	padapter = pBtCoexist->Adapter;
1452 
1453 	if (IS_HARDWARE_TYPE_8723B(padapter))
1454 	{
1455 		CmdBuffer1[0] |= (OperVer & 0x0f);						/* Set OperVer */
1456 		CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0);				/* Set ReqNum */
1457 		CmdBuffer1[1] = 0x0d; 									/* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */
1458 		CmdBuffer1[2] = ValueToSet[0]; 							/* Set WriteRegValue */
1459 		rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0]));
1460 
1461 		rtw_msleep_os(200);
1462 		ReqNum++;
1463 
1464 		CmdBuffer2[0] |= (OperVer & 0x0f);						/* Set OperVer */
1465 		CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0);				/* Set ReqNum */
1466 		CmdBuffer2[1] = 0x0c; 									/* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */
1467 		CmdBuffer2[3] = AddrToSet[0];							/* Set WriteRegAddr */
1468 		rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0]));
1469 	}
1470 }
1471 
halbtcoutsrc_SetBtAntDetection(void * pBtcContext,u8 txTime,u8 btChnl)1472 u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)
1473 {
1474 /* Always return _FALSE since we don't implement this yet */
1475 #if 0
1476 	PBTC_COEXIST		pBtCoexist = (PBTC_COEXIST)pBtcContext;
1477 	PADAPTER			Adapter = pBtCoexist->Adapter;
1478 	u1Byte				btCanTx = 0;
1479 	BOOLEAN			bStatus = FALSE;
1480 
1481 	bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);
1482 	if (bStatus && btCanTx)
1483 		return _TRUE;
1484 	else
1485 		return _FALSE;
1486 #else
1487 	return _FALSE;
1488 #endif
1489 }
1490 
halbtcoutsrc_GetBtReg(void * pBtcContext,u8 RegType,u32 RegAddr)1491 u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
1492 {
1493 	/* To be implemented. Always return 0 temporarily */
1494 	return 0;
1495 }
1496 
halbtcoutsrc_FillH2cCmd(void * pBtcContext,u8 elementId,u32 cmdLen,u8 * pCmdBuffer)1497 void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
1498 {
1499 	PBTC_COEXIST pBtCoexist;
1500 	PADAPTER padapter;
1501 
1502 
1503 	pBtCoexist = (PBTC_COEXIST)pBtcContext;
1504 	padapter = pBtCoexist->Adapter;
1505 
1506 	rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
1507 }
1508 
1509 //====================================
1510 //		Extern functions called by other module
1511 //====================================
EXhalbtcoutsrc_IsTfbgaPackageType(PADAPTER padapter)1512 u8 EXhalbtcoutsrc_IsTfbgaPackageType(PADAPTER padapter)
1513 {
1514 	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(padapter);
1515 
1516 #ifdef CONFIG_RTL8723B
1517 	if ((pHalData->PackageType == PACKAGE_TFBGA79) || (pHalData->PackageType == PACKAGE_TFBGA80)
1518 		|| (pHalData->PackageType == PACKAGE_TFBGA90)) {
1519 		return _TRUE;
1520 	}
1521 #endif
1522 
1523 	return _FALSE;
1524 }
1525 
EXhalbtcoutsrc_BindBtCoexWithAdapter(void * padapter)1526 u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
1527 {
1528 	PBTC_COEXIST		pBtCoexist=&GLBtCoexist;
1529 	u1Byte	antNum=2, chipType;
1530 
1531 	if(pBtCoexist->bBinded)
1532 		return _FALSE;
1533 	else
1534 		pBtCoexist->bBinded = _TRUE;
1535 
1536 	pBtCoexist->statistics.cntBind++;
1537 
1538 	pBtCoexist->Adapter = padapter;
1539 
1540 	pBtCoexist->stackInfo.bProfileNotified = _FALSE;
1541 
1542 	pBtCoexist->btInfo.bBtCtrlAggBufSize = _FALSE;
1543 	pBtCoexist->btInfo.aggBufSize = 5;
1544 
1545 	pBtCoexist->btInfo.bIncreaseScanDevNum = _FALSE;
1546 	pBtCoexist->btInfo.bMiracastPlusBt = _FALSE;
1547 
1548 #if 0
1549 	chipType = HALBT_GetBtChipType(Adapter);
1550 	EXhalbtcoutsrc_SetChipType(chipType);
1551 	antNum = HALBT_GetPgAntNum(Adapter);
1552 	EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1553 #endif
1554 	// set default antenna position to main  port
1555 	pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
1556 
1557 	pBtCoexist->boardInfo.btdmAntDetFinish = _FALSE;
1558 	pBtCoexist->boardInfo.btdmAntNumByAntDet = 1;
1559 
1560 	pBtCoexist->boardInfo.bTfbgaPackage = EXhalbtcoutsrc_IsTfbgaPackageType((PADAPTER)padapter);
1561 
1562 	if (pBtCoexist->boardInfo.bTfbgaPackage)
1563 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Package Type = TFBGA\n"));
1564 	else
1565 		RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Package Type = Non-TFBGA\n"));
1566 
1567 	return _TRUE;
1568 }
1569 
EXhalbtcoutsrc_InitlizeVariables(void * padapter)1570 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
1571 {
1572 	PBTC_COEXIST pBtCoexist = &GLBtCoexist;
1573 
1574 	//pBtCoexist->statistics.cntBind++;
1575 
1576 	halbtcoutsrc_DbgInit();
1577 
1578 #ifdef CONFIG_PCI_HCI
1579 	pBtCoexist->chipInterface = BTC_INTF_PCI;
1580 #elif defined(CONFIG_USB_HCI)
1581 	pBtCoexist->chipInterface = BTC_INTF_USB;
1582 #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
1583 	pBtCoexist->chipInterface = BTC_INTF_SDIO;
1584 #else
1585 	pBtCoexist->chipInterface = BTC_INTF_UNKNOWN;
1586 #endif
1587 
1588 	EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
1589 
1590 	pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
1591 	pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
1592 	pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
1593 	pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
1594 	pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
1595 	pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
1596 	pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
1597 	pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
1598 
1599 	pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
1600 	pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
1601 
1602 	pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
1603 	pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
1604 
1605 	pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
1606 	pBtCoexist->fBtcDispDbgMsg = halbtcoutsrc_DisplayDbgMsg;
1607 
1608 	pBtCoexist->fBtcGet = halbtcoutsrc_Get;
1609 	pBtCoexist->fBtcSet = halbtcoutsrc_Set;
1610 	pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
1611 	pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
1612 	pBtCoexist->fBtcSetBtAntDetection = halbtcoutsrc_SetBtAntDetection;
1613 
1614 	pBtCoexist->cliBuf = &GLBtcDbgBuf[0];
1615 
1616 	pBtCoexist->boardInfo.singleAntPath = 0;
1617 
1618 	GLBtcWiFiInScanState = _FALSE;
1619 
1620 	GLBtcWiFiInIQKState = _FALSE;
1621 
1622 	GLBtcWiFiInIPS = _FALSE;
1623 
1624 	GLBtcWiFiInLPS = _FALSE;
1625 
1626 	GLBtcBtCoexAliveRegistered = _FALSE;
1627 
1628 	return _TRUE;
1629 }
1630 
EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)1631 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
1632 {
1633 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1634 		return;
1635 
1636 	/* Power on setting function is only added in 8723B currently */
1637 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1638 	{
1639 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1640 			EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
1641 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1642 			EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
1643 	}
1644 }
1645 
EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)1646 void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)
1647 {
1648 	if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1649 		return;
1650 
1651 	pBtCoexist->statistics.cntPreLoadFirmware++;
1652 
1653 	if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1654 	{
1655 		if(pBtCoexist->boardInfo.btdmAntNum == 2)
1656 			EXhalbtc8723b2ant_PreLoadFirmware(pBtCoexist);
1657 		else if(pBtCoexist->boardInfo.btdmAntNum == 1)
1658 			EXhalbtc8723b1ant_PreLoadFirmware(pBtCoexist);
1659 	}
1660 }
1661 
EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist,u8 bWifiOnly)1662 void EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
1663 {
1664 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1665 		return;
1666 
1667 	pBtCoexist->statistics.cntInitHwConfig++;
1668 
1669 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1670 	{
1671 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1672 			EXhalbtc8821aCsr2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1673 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1674 			EXhalbtc8821a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1675 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1676 			EXhalbtc8821a1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1677 	}
1678 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1679 	{
1680 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1681 			EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1682 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1683 			EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1684 	}
1685 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1686 	{
1687 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1688 			EXhalbtc8703b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1689 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1690 			EXhalbtc8703b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1691 	}
1692 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1693 	{
1694 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1695 			EXhalbtc8192e2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1696 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1697 			EXhalbtc8192e1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1698 	}
1699 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1700 	{
1701 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1702 			EXhalbtc8812a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1703 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1704 			EXhalbtc8812a1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1705 	}
1706 }
1707 
EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist)1708 void EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist)
1709 {
1710 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1711 		return;
1712 
1713 	pBtCoexist->statistics.cntInitCoexDm++;
1714 
1715 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1716 	{
1717 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1718 			EXhalbtc8821aCsr2ant_InitCoexDm(pBtCoexist);
1719 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1720 			EXhalbtc8821a2ant_InitCoexDm(pBtCoexist);
1721 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1722 			EXhalbtc8821a1ant_InitCoexDm(pBtCoexist);
1723 	}
1724 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1725 	{
1726 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1727 			EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
1728 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1729 			EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
1730 	}
1731 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1732 	{
1733 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1734 			EXhalbtc8703b2ant_InitCoexDm(pBtCoexist);
1735 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1736 			EXhalbtc8703b1ant_InitCoexDm(pBtCoexist);
1737 	}
1738 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1739 	{
1740 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1741 			EXhalbtc8192e2ant_InitCoexDm(pBtCoexist);
1742 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1743 			EXhalbtc8192e1ant_InitCoexDm(pBtCoexist);
1744 	}
1745 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1746 	{
1747 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1748 			EXhalbtc8812a2ant_InitCoexDm(pBtCoexist);
1749 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1750 			EXhalbtc8812a1ant_InitCoexDm(pBtCoexist);
1751 	}
1752 
1753 	pBtCoexist->bInitilized = _TRUE;
1754 }
1755 
EXhalbtcoutsrc_IpsNotify(PBTC_COEXIST pBtCoexist,u8 type)1756 void EXhalbtcoutsrc_IpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1757 {
1758 	u8	ipsType;
1759 
1760 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1761 		return;
1762 
1763 	pBtCoexist->statistics.cntIpsNotify++;
1764 	if (pBtCoexist->bManualControl)
1765 		return;
1766 
1767 	if (IPS_NONE == type)
1768 	{
1769 		ipsType = BTC_IPS_LEAVE;
1770 		GLBtcWiFiInIPS = _FALSE;
1771 	}
1772 	else
1773 	{
1774 		ipsType = BTC_IPS_ENTER;
1775 		GLBtcWiFiInIPS = _TRUE;
1776 	}
1777 
1778 	// All notify is called in cmd thread, don't need to leave low power again
1779 //	halbtcoutsrc_LeaveLowPower(pBtCoexist);
1780 
1781 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1782 	{
1783 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1784 			EXhalbtc8821aCsr2ant_IpsNotify(pBtCoexist, ipsType);
1785 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1786 			EXhalbtc8821a2ant_IpsNotify(pBtCoexist, ipsType);
1787 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1788 			EXhalbtc8821a1ant_IpsNotify(pBtCoexist, ipsType);
1789 	}
1790 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1791 	{
1792 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1793 			EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
1794 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1795 			EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
1796 	}
1797 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1798 	{
1799 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1800 			EXhalbtc8703b2ant_IpsNotify(pBtCoexist, ipsType);
1801 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1802 			EXhalbtc8703b1ant_IpsNotify(pBtCoexist, ipsType);
1803 	}
1804 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1805 	{
1806 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1807 			EXhalbtc8192e2ant_IpsNotify(pBtCoexist, ipsType);
1808 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1809 			EXhalbtc8192e1ant_IpsNotify(pBtCoexist, ipsType);
1810 	}
1811 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1812 	{
1813 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1814 			EXhalbtc8812a2ant_IpsNotify(pBtCoexist, ipsType);
1815 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1816 			EXhalbtc8812a1ant_IpsNotify(pBtCoexist, ipsType);
1817 	}
1818 
1819 //	halbtcoutsrc_NormalLowPower(pBtCoexist);
1820 }
1821 
EXhalbtcoutsrc_LpsNotify(PBTC_COEXIST pBtCoexist,u8 type)1822 void EXhalbtcoutsrc_LpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1823 {
1824 	u8 lpsType;
1825 
1826 
1827 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1828 		return;
1829 
1830 	pBtCoexist->statistics.cntLpsNotify++;
1831 	if (pBtCoexist->bManualControl)
1832 		return;
1833 
1834 	if (PS_MODE_ACTIVE == type)
1835 	{
1836 		lpsType = BTC_LPS_DISABLE;
1837 		GLBtcWiFiInLPS = _FALSE;
1838 	}
1839 	else
1840 	{
1841 		lpsType = BTC_LPS_ENABLE;
1842 		GLBtcWiFiInLPS = _TRUE;
1843 	}
1844 
1845 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1846 	{
1847 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1848 			EXhalbtc8821aCsr2ant_LpsNotify(pBtCoexist, lpsType);
1849 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1850 			EXhalbtc8821a2ant_LpsNotify(pBtCoexist, lpsType);
1851 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1852 			EXhalbtc8821a1ant_LpsNotify(pBtCoexist, lpsType);
1853 	}
1854 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1855 	{
1856 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1857 			EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
1858 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1859 			EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
1860 	}
1861 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1862 	{
1863 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1864 			EXhalbtc8703b2ant_LpsNotify(pBtCoexist, lpsType);
1865 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1866 			EXhalbtc8703b1ant_LpsNotify(pBtCoexist, lpsType);
1867 	}
1868 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1869 	{
1870 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1871 			EXhalbtc8192e2ant_LpsNotify(pBtCoexist, lpsType);
1872 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1873 			EXhalbtc8192e1ant_LpsNotify(pBtCoexist, lpsType);
1874 	}
1875 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1876 	{
1877 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1878 			EXhalbtc8812a2ant_LpsNotify(pBtCoexist, lpsType);
1879 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1880 			EXhalbtc8812a1ant_LpsNotify(pBtCoexist, lpsType);
1881 	}
1882 }
1883 
EXhalbtcoutsrc_ScanNotify(PBTC_COEXIST pBtCoexist,u8 type)1884 void EXhalbtcoutsrc_ScanNotify(PBTC_COEXIST pBtCoexist, u8 type)
1885 {
1886 	u8	scanType;
1887 
1888 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1889 		return;
1890 	pBtCoexist->statistics.cntScanNotify++;
1891 	if (pBtCoexist->bManualControl)
1892 		return;
1893 
1894 	if (type)
1895 	{
1896 		scanType = BTC_SCAN_START;
1897 		GLBtcWiFiInScanState = _TRUE;
1898 	}
1899 	else
1900 	{
1901 		scanType = BTC_SCAN_FINISH;
1902 		GLBtcWiFiInScanState = _FALSE;
1903 	}
1904 
1905 	// All notify is called in cmd thread, don't need to leave low power again
1906 //	halbtcoutsrc_LeaveLowPower(pBtCoexist);
1907 
1908 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1909 	{
1910 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1911 			EXhalbtc8821aCsr2ant_ScanNotify(pBtCoexist, scanType);
1912 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1913 			EXhalbtc8821a2ant_ScanNotify(pBtCoexist, scanType);
1914 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1915 			EXhalbtc8821a1ant_ScanNotify(pBtCoexist, scanType);
1916 	}
1917 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1918 	{
1919 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1920 			EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
1921 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1922 			EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
1923 	}
1924 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1925 	{
1926 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1927 			EXhalbtc8703b2ant_ScanNotify(pBtCoexist, scanType);
1928 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1929 			EXhalbtc8703b1ant_ScanNotify(pBtCoexist, scanType);
1930 	}
1931 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1932 	{
1933 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1934 			EXhalbtc8192e2ant_ScanNotify(pBtCoexist, scanType);
1935 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1936 			EXhalbtc8192e1ant_ScanNotify(pBtCoexist, scanType);
1937 	}
1938 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1939 	{
1940 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1941 			EXhalbtc8812a2ant_ScanNotify(pBtCoexist, scanType);
1942 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1943 			EXhalbtc8812a1ant_ScanNotify(pBtCoexist, scanType);
1944 	}
1945 
1946 //	halbtcoutsrc_NormalLowPower(pBtCoexist);
1947 }
1948 
EXhalbtcoutsrc_ConnectNotify(PBTC_COEXIST pBtCoexist,u8 action)1949 void EXhalbtcoutsrc_ConnectNotify(PBTC_COEXIST pBtCoexist, u8 action)
1950 {
1951 	u8	assoType;
1952 
1953 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1954 		return;
1955 	pBtCoexist->statistics.cntConnectNotify++;
1956 	if (pBtCoexist->bManualControl)
1957 		return;
1958 
1959 	if (action)
1960 		assoType = BTC_ASSOCIATE_START;
1961 	else
1962 		assoType = BTC_ASSOCIATE_FINISH;
1963 
1964 	// All notify is called in cmd thread, don't need to leave low power again
1965 //	halbtcoutsrc_LeaveLowPower(pBtCoexist);
1966 
1967 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1968 	{
1969 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1970 			EXhalbtc8821aCsr2ant_ConnectNotify(pBtCoexist, assoType);
1971 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1972 			EXhalbtc8821a2ant_ConnectNotify(pBtCoexist, assoType);
1973 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1974 			EXhalbtc8821a1ant_ConnectNotify(pBtCoexist, assoType);
1975 	}
1976 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1977 	{
1978 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1979 			EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
1980 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1981 			EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
1982 	}
1983 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1984 	{
1985 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1986 			EXhalbtc8703b2ant_ConnectNotify(pBtCoexist, assoType);
1987 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1988 			EXhalbtc8703b1ant_ConnectNotify(pBtCoexist, assoType);
1989 	}
1990 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1991 	{
1992 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
1993 			EXhalbtc8192e2ant_ConnectNotify(pBtCoexist, assoType);
1994 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1995 			EXhalbtc8192e1ant_ConnectNotify(pBtCoexist, assoType);
1996 	}
1997 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1998 	{
1999 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2000 			EXhalbtc8812a2ant_ConnectNotify(pBtCoexist, assoType);
2001 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2002 			EXhalbtc8812a1ant_ConnectNotify(pBtCoexist, assoType);
2003 	}
2004 
2005 //	halbtcoutsrc_NormalLowPower(pBtCoexist);
2006 }
2007 
EXhalbtcoutsrc_MediaStatusNotify(PBTC_COEXIST pBtCoexist,RT_MEDIA_STATUS mediaStatus)2008 void EXhalbtcoutsrc_MediaStatusNotify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
2009 {
2010 	u8 mStatus;
2011 
2012 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2013 		return;
2014 
2015 	pBtCoexist->statistics.cntMediaStatusNotify++;
2016 	if (pBtCoexist->bManualControl)
2017 		return;
2018 
2019 	if (RT_MEDIA_CONNECT == mediaStatus)
2020 		mStatus = BTC_MEDIA_CONNECT;
2021 	else
2022 		mStatus = BTC_MEDIA_DISCONNECT;
2023 
2024 	// All notify is called in cmd thread, don't need to leave low power again
2025 //	halbtcoutsrc_LeaveLowPower(pBtCoexist);
2026 
2027 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2028 	{
2029 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2030 			EXhalbtc8821aCsr2ant_MediaStatusNotify(pBtCoexist, mStatus);
2031 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2032 			EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, mStatus);
2033 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2034 			EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, mStatus);
2035 	}
2036 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2037 	{
2038 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2039 			EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
2040 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2041 			EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
2042 	}
2043 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2044 	{
2045 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2046 			EXhalbtc8703b2ant_MediaStatusNotify(pBtCoexist, mStatus);
2047 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2048 			EXhalbtc8703b1ant_MediaStatusNotify(pBtCoexist, mStatus);
2049 	}
2050 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2051 	{
2052 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2053 			EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, mStatus);
2054 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2055 			EXhalbtc8192e1ant_MediaStatusNotify(pBtCoexist, mStatus);
2056 	}
2057 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2058 	{
2059 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2060 			EXhalbtc8812a2ant_MediaStatusNotify(pBtCoexist, mStatus);
2061 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2062 			EXhalbtc8812a1ant_MediaStatusNotify(pBtCoexist, mStatus);
2063 	}
2064 
2065 //	halbtcoutsrc_NormalLowPower(pBtCoexist);
2066 }
2067 
EXhalbtcoutsrc_SpecialPacketNotify(PBTC_COEXIST pBtCoexist,u8 pktType)2068 void EXhalbtcoutsrc_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 pktType)
2069 {
2070 	u8	packetType;
2071 
2072 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2073 		return;
2074 	pBtCoexist->statistics.cntSpecialPacketNotify++;
2075 	if (pBtCoexist->bManualControl)
2076 		return;
2077 
2078 	if (PACKET_DHCP == pktType)
2079 		packetType = BTC_PACKET_DHCP;
2080 	else if (PACKET_EAPOL == pktType)
2081 		packetType = BTC_PACKET_EAPOL;
2082 	else if (PACKET_ARP == pktType)
2083 		packetType = BTC_PACKET_ARP;
2084 	else
2085 	{
2086 		packetType = BTC_PACKET_UNKNOWN;
2087 		return;
2088 	}
2089 
2090 	// All notify is called in cmd thread, don't need to leave low power again
2091 //	halbtcoutsrc_LeaveLowPower(pBtCoexist);
2092 
2093 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2094 	{
2095 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2096 			EXhalbtc8821aCsr2ant_SpecialPacketNotify(pBtCoexist, packetType);
2097 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2098 			EXhalbtc8821a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2099 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2100 			EXhalbtc8821a1ant_SpecialPacketNotify(pBtCoexist, packetType);
2101 	}
2102 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2103 	{
2104 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2105 			EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
2106 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2107 			EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
2108 	}
2109 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2110 	{
2111 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2112 			EXhalbtc8703b2ant_SpecialPacketNotify(pBtCoexist, packetType);
2113 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2114 			EXhalbtc8703b1ant_SpecialPacketNotify(pBtCoexist, packetType);
2115 	}
2116 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2117 	{
2118 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2119 			EXhalbtc8192e2ant_SpecialPacketNotify(pBtCoexist, packetType);
2120 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2121 			EXhalbtc8192e1ant_SpecialPacketNotify(pBtCoexist, packetType);
2122 	}
2123 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2124 	{
2125 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2126 			EXhalbtc8812a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2127 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2128 			EXhalbtc8812a1ant_SpecialPacketNotify(pBtCoexist, packetType);
2129 	}
2130 
2131 //	halbtcoutsrc_NormalLowPower(pBtCoexist);
2132 }
2133 
EXhalbtcoutsrc_BtInfoNotify(PBTC_COEXIST pBtCoexist,u8 * tmpBuf,u8 length)2134 void EXhalbtcoutsrc_BtInfoNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
2135 {
2136 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2137 		return;
2138 
2139 	pBtCoexist->statistics.cntBtInfoNotify++;
2140 
2141 	// All notify is called in cmd thread, don't need to leave low power again
2142 //	halbtcoutsrc_LeaveLowPower(pBtCoexist);
2143 
2144 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2145 	{
2146 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2147 			EXhalbtc8821aCsr2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2148 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2149 			EXhalbtc8821a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2150 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2151 			EXhalbtc8821a1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2152 	}
2153 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2154 	{
2155 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2156 			EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2157 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2158 			EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2159 	}
2160 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2161 	{
2162 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2163 			EXhalbtc8703b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2164 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2165 			EXhalbtc8703b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2166 	}
2167 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2168 	{
2169 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2170 			EXhalbtc8192e2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2171 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2172 			EXhalbtc8192e1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2173 	}
2174 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2175 	{
2176 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2177 			EXhalbtc8812a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2178 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2179 			EXhalbtc8812a1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2180 	}
2181 
2182 //	halbtcoutsrc_NormalLowPower(pBtCoexist);
2183 }
2184 
2185 VOID
EXhalbtcoutsrc_RfStatusNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)2186 EXhalbtcoutsrc_RfStatusNotify(
2187 	IN	PBTC_COEXIST		pBtCoexist,
2188 	IN	u1Byte 				type
2189 	)
2190 {
2191 	if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2192 		return;
2193 	pBtCoexist->statistics.cntRfStatusNotify++;
2194 
2195 	if(IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2196 	{
2197 	}
2198 	else if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2199 	{
2200 		if(pBtCoexist->boardInfo.btdmAntNum == 1)
2201 			EXhalbtc8723b1ant_RfStatusNotify(pBtCoexist, type);
2202 	}
2203 	else if(IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2204 	{
2205 		if(pBtCoexist->boardInfo.btdmAntNum == 1)
2206 			EXhalbtc8703b1ant_RfStatusNotify(pBtCoexist, type);
2207 	}
2208 	else if(IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2209 	{
2210 	}
2211 	else if(IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2212 	{
2213 	}
2214 }
2215 
EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist,u8 type)2216 void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)
2217 {
2218 #if 0
2219 	u8	stackOpType;
2220 
2221 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2222 		return;
2223 	pBtCoexist->statistics.cntStackOperationNotify++;
2224 	if (pBtCoexist->bManualControl)
2225 		return;
2226 
2227 	if ((HCI_BT_OP_INQUIRY_START == type) ||
2228 		(HCI_BT_OP_PAGING_START == type) ||
2229 		(HCI_BT_OP_PAIRING_START == type))
2230 	{
2231 		stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START;
2232 	}
2233 	else if ((HCI_BT_OP_INQUIRY_FINISH == type) ||
2234 		(HCI_BT_OP_PAGING_SUCCESS == type) ||
2235 		(HCI_BT_OP_PAGING_UNSUCCESS == type) ||
2236 		(HCI_BT_OP_PAIRING_FINISH == type) )
2237 	{
2238 		stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
2239 	}
2240 	else
2241 	{
2242 		stackOpType = BTC_STACK_OP_NONE;
2243 	}
2244 
2245 #endif
2246 }
2247 
EXhalbtcoutsrc_HaltNotify(PBTC_COEXIST pBtCoexist)2248 void EXhalbtcoutsrc_HaltNotify(PBTC_COEXIST pBtCoexist)
2249 {
2250 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2251 		return;
2252 
2253 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2254 	{
2255 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2256 			EXhalbtc8821aCsr2ant_HaltNotify(pBtCoexist);
2257 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2258 			EXhalbtc8821a2ant_HaltNotify(pBtCoexist);
2259 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2260 			EXhalbtc8821a1ant_HaltNotify(pBtCoexist);
2261 	}
2262 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2263 	{
2264 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2265 			EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
2266 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2267 			EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
2268 	}
2269 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2270 	{
2271 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2272 			EXhalbtc8703b2ant_HaltNotify(pBtCoexist);
2273 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2274 			EXhalbtc8703b1ant_HaltNotify(pBtCoexist);
2275 	}
2276 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2277 	{
2278 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2279 			EXhalbtc8192e2ant_HaltNotify(pBtCoexist);
2280 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2281 			EXhalbtc8192e1ant_HaltNotify(pBtCoexist);
2282 	}
2283 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2284 	{
2285 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2286 			EXhalbtc8812a2ant_HaltNotify(pBtCoexist);
2287 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2288 			EXhalbtc8812a1ant_HaltNotify(pBtCoexist);
2289 	}
2290 
2291 	pBtCoexist->bBinded = FALSE;
2292 }
2293 
EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)2294 void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)
2295 {
2296 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2297 	{
2298 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2299 		{
2300 			halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); //BT goto standby while GNT_BT 1-->0
2301 		}
2302 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2303 		{
2304 			halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); //BT goto standby while GNT_BT 1-->0
2305 		}
2306 	}
2307 }
2308 
EXhalbtcoutsrc_PnpNotify(PBTC_COEXIST pBtCoexist,u8 pnpState)2309 void EXhalbtcoutsrc_PnpNotify(PBTC_COEXIST pBtCoexist, u8 pnpState)
2310 {
2311 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2312 		return;
2313 
2314 	//
2315 	// currently only 1ant we have to do the notification,
2316 	// once pnp is notified to sleep state, we have to leave LPS that we can sleep normally.
2317 	//
2318 
2319 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2320 	{
2321 		if (pBtCoexist->boardInfo.btdmAntNum == 1)
2322 			EXhalbtc8723b1ant_PnpNotify(pBtCoexist,pnpState);
2323 		else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2324 			EXhalbtc8723b2ant_PnpNotify(pBtCoexist,pnpState);
2325 	}
2326 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2327 	{
2328 		if (pBtCoexist->boardInfo.btdmAntNum == 1)
2329 			EXhalbtc8703b1ant_PnpNotify(pBtCoexist,pnpState);
2330 		else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2331 			EXhalbtc8703b2ant_PnpNotify(pBtCoexist,pnpState);
2332 	}
2333 	else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2334 	{
2335 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2336 			EXhalbtc8821aCsr2ant_PnpNotify(pBtCoexist, pnpState);
2337 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2338 			EXhalbtc8821a1ant_PnpNotify(pBtCoexist,pnpState);
2339 		else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2340 			EXhalbtc8821a2ant_PnpNotify(pBtCoexist,pnpState);
2341 	}
2342 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2343 	{
2344 		if (pBtCoexist->boardInfo.btdmAntNum == 1)
2345 			EXhalbtc8192e1ant_PnpNotify(pBtCoexist, pnpState);
2346 	}
2347 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2348 	{
2349 		if (pBtCoexist->boardInfo.btdmAntNum == 1)
2350 			EXhalbtc8812a1ant_PnpNotify(pBtCoexist, pnpState);
2351 	}
2352 }
2353 
EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)2354 void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)
2355 {
2356 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2357 		return;
2358 	pBtCoexist->statistics.cntCoexDmSwitch++;
2359 
2360 	halbtcoutsrc_LeaveLowPower(pBtCoexist);
2361 
2362 	if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2363 	{
2364 		if (pBtCoexist->boardInfo.btdmAntNum == 1)
2365 		{
2366 			pBtCoexist->bStopCoexDm = TRUE;
2367 			EXhalbtc8723b1ant_CoexDmReset(pBtCoexist);
2368 			EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
2369 			EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, FALSE);
2370 			EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
2371 			pBtCoexist->bStopCoexDm = FALSE;
2372 		}
2373 	}
2374 
2375 	halbtcoutsrc_NormalLowPower(pBtCoexist);
2376 }
2377 
EXhalbtcoutsrc_Periodical(PBTC_COEXIST pBtCoexist)2378 void EXhalbtcoutsrc_Periodical(PBTC_COEXIST pBtCoexist)
2379 {
2380 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2381 		return;
2382 	pBtCoexist->statistics.cntPeriodical++;
2383 
2384 	// Periodical should be called in cmd thread,
2385 	// don't need to leave low power again
2386 //	halbtcoutsrc_LeaveLowPower(pBtCoexist);
2387 
2388 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2389 	{
2390 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2391 			EXhalbtc8821aCsr2ant_Periodical(pBtCoexist);
2392 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2393 			EXhalbtc8821a2ant_Periodical(pBtCoexist);
2394 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2395 		{
2396 			if (!halbtcoutsrc_UnderIps(pBtCoexist))
2397 			{
2398 				EXhalbtc8821a1ant_Periodical(pBtCoexist);
2399 			}
2400 		}
2401 	}
2402 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2403 	{
2404 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2405 			EXhalbtc8723b2ant_Periodical(pBtCoexist);
2406 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2407 			EXhalbtc8723b1ant_Periodical(pBtCoexist);
2408 	}
2409 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2410 	{
2411 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2412 			EXhalbtc8703b2ant_Periodical(pBtCoexist);
2413 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2414 			EXhalbtc8703b1ant_Periodical(pBtCoexist);
2415 	}
2416 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2417 	{
2418 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2419 			EXhalbtc8192e2ant_Periodical(pBtCoexist);
2420 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2421 			EXhalbtc8192e1ant_Periodical(pBtCoexist);
2422 	}
2423 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2424 	{
2425 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2426 			EXhalbtc8812a2ant_Periodical(pBtCoexist);
2427 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2428 			EXhalbtc8812a1ant_Periodical(pBtCoexist);
2429 	}
2430 
2431 //	halbtcoutsrc_NormalLowPower(pBtCoexist);
2432 }
2433 
EXhalbtcoutsrc_DbgControl(PBTC_COEXIST pBtCoexist,u8 opCode,u8 opLen,u8 * pData)2434 void EXhalbtcoutsrc_DbgControl(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)
2435 {
2436 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2437 		return;
2438 
2439 	pBtCoexist->statistics.cntDbgCtrl++;
2440 
2441 	// This function doesn't be called yet,
2442 	// default no need to leave low power to avoid deadlock
2443 //	halbtcoutsrc_LeaveLowPower(pBtCoexist);
2444 
2445 	if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2446 	{
2447 		if (pBtCoexist->boardInfo.btdmAntNum == 1)
2448 			EXhalbtc8192e1ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2449 	}
2450 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2451 	{
2452 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2453 			EXhalbtc8812a2ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2454 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2455 			EXhalbtc8812a1ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2456 	}
2457 
2458 //	halbtcoutsrc_NormalLowPower(pBtCoexist);
2459 }
2460 
2461 #if 0
2462 VOID
2463 EXhalbtcoutsrc_AntennaDetection(
2464 	IN	PBTC_COEXIST			pBtCoexist,
2465 	IN	u4Byte					centFreq,
2466 	IN	u4Byte					offset,
2467 	IN	u4Byte					span,
2468 	IN	u4Byte					seconds
2469 	)
2470 {
2471 	if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2472 		return;
2473 
2474 	/* Need to refine the following power save operations to enable this function in the future */
2475 #if 0
2476 	IPSDisable(pBtCoexist->Adapter, FALSE, 0);
2477 	LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);
2478 #endif
2479 
2480 	if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2481 	{
2482 		if(pBtCoexist->boardInfo.btdmAntNum == 1)
2483 			EXhalbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds);
2484 	}
2485 
2486 	//IPSReturn(pBtCoexist->Adapter, 0xff);
2487 }
2488 #endif
2489 
EXhalbtcoutsrc_StackUpdateProfileInfo(void)2490 void EXhalbtcoutsrc_StackUpdateProfileInfo(void)
2491 {
2492 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
2493 	PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2494 	PADAPTER padapter = (PADAPTER)GLBtCoexist.Adapter;
2495 	PBT_MGNT pBtMgnt = &padapter->coex_info.BtMgnt;
2496 	u8 i;
2497 
2498 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2499 		return;
2500 
2501 	pBtCoexist->stackInfo.bProfileNotified = _TRUE;
2502 
2503 	pBtCoexist->stackInfo.numOfLink =
2504 		pBtMgnt->ExtConfig.NumberOfACL+pBtMgnt->ExtConfig.NumberOfSCO;
2505 
2506 	// reset first
2507 	pBtCoexist->stackInfo.bBtLinkExist = _FALSE;
2508 	pBtCoexist->stackInfo.bScoExist = _FALSE;
2509 	pBtCoexist->stackInfo.bAclExist = _FALSE;
2510 	pBtCoexist->stackInfo.bA2dpExist = _FALSE;
2511 	pBtCoexist->stackInfo.bHidExist = _FALSE;
2512 	pBtCoexist->stackInfo.numOfHid = 0;
2513 	pBtCoexist->stackInfo.bPanExist = _FALSE;
2514 
2515 	if (!pBtMgnt->ExtConfig.NumberOfACL)
2516 		pBtCoexist->stackInfo.minBtRssi = 0;
2517 
2518 	if (pBtCoexist->stackInfo.numOfLink)
2519 	{
2520 		pBtCoexist->stackInfo.bBtLinkExist = _TRUE;
2521 		if (pBtMgnt->ExtConfig.NumberOfSCO)
2522 			pBtCoexist->stackInfo.bScoExist = _TRUE;
2523 		if (pBtMgnt->ExtConfig.NumberOfACL)
2524 			pBtCoexist->stackInfo.bAclExist = _TRUE;
2525 	}
2526 
2527 	for (i=0; i<pBtMgnt->ExtConfig.NumberOfACL; i++)
2528 	{
2529 		if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2530 		{
2531 			pBtCoexist->stackInfo.bA2dpExist = _TRUE;
2532 		}
2533 		else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2534 		{
2535 			pBtCoexist->stackInfo.bPanExist = _TRUE;
2536 		}
2537 		else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2538 		{
2539 			pBtCoexist->stackInfo.bHidExist = _TRUE;
2540 			pBtCoexist->stackInfo.numOfHid++;
2541 		}
2542 		else
2543 		{
2544 			pBtCoexist->stackInfo.bUnknownAclExist = _TRUE;
2545 		}
2546 	}
2547 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
2548 }
2549 
EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)2550 void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)
2551 {
2552 	PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2553 
2554 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2555 		return;
2556 
2557 	pBtCoexist->stackInfo.minBtRssi = btRssi;
2558 }
2559 
EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)2560 void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)
2561 {
2562 	PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2563 
2564 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2565 		return;
2566 
2567 	pBtCoexist->stackInfo.hciVersion = hciVersion;
2568 }
2569 
EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion,u16 btPatchVersion)2570 void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)
2571 {
2572 	PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2573 
2574 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2575 		return;
2576 
2577 	pBtCoexist->btInfo.btRealFwVer = btPatchVersion;
2578 	pBtCoexist->btInfo.btHciVer = btHciVersion;
2579 }
2580 
2581 #if 0
2582 void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)
2583 {
2584 	GLBtCoexist.boardInfo.bBtExist = bBtExist;
2585 }
2586 #endif
EXhalbtcoutsrc_SetChipType(u8 chipType)2587 void EXhalbtcoutsrc_SetChipType(u8 chipType)
2588 {
2589 	switch(chipType)
2590 	{
2591 		default:
2592 		case BT_2WIRE:
2593 		case BT_ISSC_3WIRE:
2594 		case BT_ACCEL:
2595 		case BT_RTL8756:
2596 			GLBtCoexist.boardInfo.btChipType = BTC_CHIP_UNDEF;
2597 			break;
2598 		case BT_CSR_BC4:
2599 			GLBtCoexist.boardInfo.btChipType = BTC_CHIP_CSR_BC4;
2600 			break;
2601 		case BT_CSR_BC8:
2602 			GLBtCoexist.boardInfo.btChipType = BTC_CHIP_CSR_BC8;
2603 			break;
2604 		case BT_RTL8723A:
2605 			GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723A;
2606 			break;
2607 		case BT_RTL8821:
2608 			GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8821;
2609 			break;
2610 		case BT_RTL8723B:
2611 			GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
2612 			break;
2613 	}
2614 }
2615 
EXhalbtcoutsrc_SetAntNum(u8 type,u8 antNum)2616 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
2617 {
2618 	if (BT_COEX_ANT_TYPE_PG == type)
2619 	{
2620 		GLBtCoexist.boardInfo.pgAntNum = antNum;
2621 		GLBtCoexist.boardInfo.btdmAntNum = antNum;
2622 #if 0
2623 		//The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1
2624 		//The antenna position should be determined by auto-detect mechanism
2625 		// The following is assumed to main, and those must be modified if y auto-detect mechanism is ready
2626 		if ((GLBtCoexist.boardInfo.pgAntNum == 2) && (GLBtCoexist.boardInfo.btdmAntNum == 1) )
2627 			GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2628 		else
2629 			GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2630 #endif
2631 	}
2632 	else if (BT_COEX_ANT_TYPE_ANTDIV == type)
2633 	{
2634 		GLBtCoexist.boardInfo.btdmAntNum = antNum;
2635 		//GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2636 	}
2637 	else if (BT_COEX_ANT_TYPE_DETECTED == type)
2638 	{
2639 		GLBtCoexist.boardInfo.btdmAntNum = antNum;
2640 		//GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2641 	}
2642 }
2643 
2644 //
2645 // Currently used by 8723b only, S0 or S1
2646 //
EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)2647 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
2648 {
2649 	GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
2650 }
2651 
EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)2652 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
2653 {
2654 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2655 		return;
2656 
2657 	halbtcoutsrc_LeaveLowPower(pBtCoexist);
2658 
2659 	if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2660 	{
2661 		if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2662 			EXhalbtc8821aCsr2ant_DisplayCoexInfo(pBtCoexist);
2663 		else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2664 			EXhalbtc8821a2ant_DisplayCoexInfo(pBtCoexist);
2665 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2666 			EXhalbtc8821a1ant_DisplayCoexInfo(pBtCoexist);
2667 	}
2668 	else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2669 	{
2670 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2671 			EXhalbtc8723b2ant_DisplayCoexInfo(pBtCoexist);
2672 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2673 			EXhalbtc8723b1ant_DisplayCoexInfo(pBtCoexist);
2674 	}
2675 	else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2676 	{
2677 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2678 			EXhalbtc8703b2ant_DisplayCoexInfo(pBtCoexist);
2679 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2680 			EXhalbtc8703b1ant_DisplayCoexInfo(pBtCoexist);
2681 	}
2682 	else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2683 	{
2684 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2685 			EXhalbtc8192e2ant_DisplayCoexInfo(pBtCoexist);
2686 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2687 			EXhalbtc8192e1ant_DisplayCoexInfo(pBtCoexist);
2688 	}
2689 	else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2690 	{
2691 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2692 			EXhalbtc8812a2ant_DisplayCoexInfo(pBtCoexist);
2693 		else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2694 			EXhalbtc8812a1ant_DisplayCoexInfo(pBtCoexist);
2695 	}
2696 
2697 	halbtcoutsrc_NormalLowPower(pBtCoexist);
2698 }
2699 
EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)2700 void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)
2701 {
2702 	if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2703 		return;
2704 
2705 	halbtcoutsrc_LeaveLowPower(pBtCoexist);
2706 
2707 	if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2708 	{
2709 		if(pBtCoexist->boardInfo.btdmAntNum == 1)
2710 			EXhalbtc8723b1ant_DisplayAntDetection(pBtCoexist);
2711 	}
2712 
2713 	halbtcoutsrc_NormalLowPower(pBtCoexist);
2714 }
2715 
EXhalbtcoutsrc_BTOffOnNotify(PBTC_COEXIST pBtCoexist,u8 bBTON)2716 void EXhalbtcoutsrc_BTOffOnNotify(PBTC_COEXIST pBtCoexist, u8 bBTON)
2717 {
2718 
2719 	if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2720 		if (pBtCoexist->boardInfo.btdmAntNum == 2)
2721 			EXhalbtc8812a2ant_BTOffOnNotify(pBtCoexist, (bBTON == _TRUE)?BTC_BT_ON:BTC_BT_OFF);
2722 	}
2723 
2724 }
2725 
halbt_InitHwConfig92C(PADAPTER padapter)2726 static void halbt_InitHwConfig92C(PADAPTER padapter)
2727 {
2728 	PHAL_DATA_TYPE pHalData;
2729 	u8 u1Tmp;
2730 
2731 
2732 	pHalData = GET_HAL_DATA(padapter);
2733 	if( (pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
2734 		(pHalData->bt_coexist.btChipType == BT_CSR_BC8))
2735 	{
2736 		if (pHalData->rf_type == RF_1T1R)
2737 		{
2738 			// Config to 1T1R
2739 			u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
2740 			u1Tmp &= ~BIT(1);
2741 			rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
2742 			RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
2743 
2744 			u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
2745 			u1Tmp &= ~BIT(1);
2746 			rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
2747 			RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
2748 		}
2749 	}
2750 }
2751 
halbt_InitHwConfig92D(PADAPTER padapter)2752 static void halbt_InitHwConfig92D(PADAPTER padapter)
2753 {
2754 	PHAL_DATA_TYPE pHalData;
2755 	u8 u1Tmp;
2756 
2757 	pHalData = GET_HAL_DATA(padapter);
2758 	if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
2759 		(pHalData->bt_coexist.btChipType == BT_CSR_BC8))
2760 	{
2761 		if (pHalData->rf_type == RF_1T1R)
2762 		{
2763 			// Config to 1T1R
2764 			u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
2765 			u1Tmp &= ~BIT(1);
2766 			rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
2767 			RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
2768 
2769 			u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
2770 			u1Tmp &= ~BIT(1);
2771 			rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
2772 			RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
2773 		}
2774 	}
2775 }
2776 
2777 /*
2778  * Description:
2779  *	Run BT-Coexist mechansim or not
2780  *
2781  */
hal_btcoex_SetBTCoexist(PADAPTER padapter,u8 bBtExist)2782 void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)
2783 {
2784 	PHAL_DATA_TYPE	pHalData;
2785 
2786 
2787 	pHalData = GET_HAL_DATA(padapter);
2788 	pHalData->bt_coexist.bBtExist = bBtExist;
2789 
2790 	//EXhalbtcoutsrc_SetBtExist(bBtExist);
2791 }
2792 
2793 /*
2794  * Dewcription:
2795  *	Check is co-exist mechanism enabled or not
2796  *
2797  * Return:
2798  *	_TRUE	Enable BT co-exist mechanism
2799  *	_FALSE	Disable BT co-exist mechanism
2800  */
hal_btcoex_IsBtExist(PADAPTER padapter)2801 u8 hal_btcoex_IsBtExist(PADAPTER padapter)
2802 {
2803 	PHAL_DATA_TYPE	pHalData;
2804 
2805 
2806 	pHalData = GET_HAL_DATA(padapter);
2807 	return pHalData->bt_coexist.bBtExist;
2808 }
2809 
hal_btcoex_IsBtDisabled(PADAPTER padapter)2810 u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)
2811 {
2812 	if (!hal_btcoex_IsBtExist(padapter))
2813 		return _TRUE;
2814 
2815 	if (GLBtCoexist.btInfo.bBtDisabled)
2816 		return _TRUE;
2817 	else
2818 		return _FALSE;
2819 }
2820 
hal_btcoex_SetChipType(PADAPTER padapter,u8 chipType)2821 void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)
2822 {
2823 	PHAL_DATA_TYPE	pHalData;
2824 
2825 
2826 	pHalData = GET_HAL_DATA(padapter);
2827 	pHalData->bt_coexist.btChipType = chipType;
2828 
2829 	EXhalbtcoutsrc_SetChipType(chipType);
2830 }
2831 
hal_btcoex_GetChipType(PADAPTER padapter)2832 u8 hal_btcoex_GetChipType(PADAPTER padapter)
2833 {
2834 	PHAL_DATA_TYPE	pHalData;
2835 
2836 
2837 	pHalData = GET_HAL_DATA(padapter);
2838 	return pHalData->bt_coexist.btChipType;
2839 }
2840 
hal_btcoex_SetPgAntNum(PADAPTER padapter,u8 antNum)2841 void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)
2842 {
2843 	PHAL_DATA_TYPE	pHalData;
2844 
2845 
2846 	pHalData = GET_HAL_DATA(padapter);
2847 
2848 	pHalData->bt_coexist.btTotalAntNum = antNum;
2849 	EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
2850 }
2851 
hal_btcoex_GetPgAntNum(PADAPTER padapter)2852 u8 hal_btcoex_GetPgAntNum(PADAPTER padapter)
2853 {
2854 	PHAL_DATA_TYPE pHalData;
2855 
2856 
2857 	pHalData = GET_HAL_DATA(padapter);
2858 
2859 	return pHalData->bt_coexist.btTotalAntNum;
2860 }
2861 
hal_btcoex_SetSingleAntPath(PADAPTER padapter,u8 singleAntPath)2862 void hal_btcoex_SetSingleAntPath(PADAPTER padapter, u8 singleAntPath)
2863 {
2864 	EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
2865 }
2866 
hal_btcoex_Initialize(PADAPTER padapter)2867 u8 hal_btcoex_Initialize(PADAPTER padapter)
2868 {
2869 	u8 ret1;
2870 	u8 ret2;
2871 
2872 
2873 	_rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
2874 	ret1 = EXhalbtcoutsrc_InitlizeVariables((void*)padapter);
2875 	ret2 = (ret1==_TRUE) ? _TRUE : _FALSE;
2876 
2877 	return ret2;
2878 }
2879 
hal_btcoex_PowerOnSetting(PADAPTER padapter)2880 void hal_btcoex_PowerOnSetting(PADAPTER padapter)
2881 {
2882 	EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
2883 }
2884 
hal_btcoex_PreLoadFirmware(PADAPTER padapter)2885 void hal_btcoex_PreLoadFirmware(PADAPTER padapter)
2886 {
2887 	EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);
2888 }
2889 
hal_btcoex_InitHwConfig(PADAPTER padapter,u8 bWifiOnly)2890 void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)
2891 {
2892 	if (!hal_btcoex_IsBtExist(padapter))
2893 		return;
2894 
2895 	EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
2896 	EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
2897 }
2898 
hal_btcoex_IpsNotify(PADAPTER padapter,u8 type)2899 void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)
2900 {
2901 	EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
2902 }
2903 
hal_btcoex_LpsNotify(PADAPTER padapter,u8 type)2904 void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)
2905 {
2906 	EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
2907 }
2908 
hal_btcoex_ScanNotify(PADAPTER padapter,u8 type)2909 void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)
2910 {
2911 	EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
2912 }
2913 
hal_btcoex_ConnectNotify(PADAPTER padapter,u8 action)2914 void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
2915 {
2916 	EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
2917 }
2918 
hal_btcoex_MediaStatusNotify(PADAPTER padapter,u8 mediaStatus)2919 void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
2920 {
2921 	EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
2922 }
2923 
hal_btcoex_SpecialPacketNotify(PADAPTER padapter,u8 pktType)2924 void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
2925 {
2926 	EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
2927 }
2928 
hal_btcoex_IQKNotify(PADAPTER padapter,u8 state)2929 void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)
2930 {
2931 	GLBtcWiFiInIQKState = state;
2932 }
2933 
hal_btcoex_BtInfoNotify(PADAPTER padapter,u8 length,u8 * tmpBuf)2934 void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
2935 {
2936 	if (GLBtcWiFiInIQKState == _TRUE)
2937 		return;
2938 
2939 	EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
2940 }
2941 
hal_btcoex_SuspendNotify(PADAPTER padapter,u8 state)2942 void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
2943 {
2944 	if (state == 1)
2945 		state = BTC_WIFI_PNP_SLEEP;
2946 	else
2947 		state = BTC_WIFI_PNP_WAKE_UP;
2948 
2949 	EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
2950 }
2951 
hal_btcoex_HaltNotify(PADAPTER padapter)2952 void hal_btcoex_HaltNotify(PADAPTER padapter)
2953 {
2954 	EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
2955 }
2956 
hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)2957 void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)
2958 {
2959 	EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);
2960 }
2961 
hal_btcoex_Hanlder(PADAPTER padapter)2962 void hal_btcoex_Hanlder(PADAPTER padapter)
2963 {
2964 	EXhalbtcoutsrc_Periodical(&GLBtCoexist);
2965 }
2966 
hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)2967 s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)
2968 {
2969 	return (s32)GLBtCoexist.btInfo.bRejectAggPkt;
2970 }
2971 
hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)2972 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
2973 {
2974 	return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
2975 }
2976 
hal_btcoex_GetAMPDUSize(PADAPTER padapter)2977 u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)
2978 {
2979 	return (u32)GLBtCoexist.btInfo.aggBufSize;
2980 }
2981 
hal_btcoex_SetManualControl(PADAPTER padapter,u8 bmanual)2982 void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)
2983 {
2984 	GLBtCoexist.bManualControl = bmanual;
2985 }
2986 
hal_btcoex_1Ant(PADAPTER padapter)2987 u8 hal_btcoex_1Ant(PADAPTER padapter)
2988 {
2989 	if (hal_btcoex_IsBtExist(padapter) == _FALSE)
2990 		return _FALSE;
2991 
2992 	if (GLBtCoexist.boardInfo.btdmAntNum == 1)
2993 		return _TRUE;
2994 
2995 	return _FALSE;
2996 }
2997 
hal_btcoex_IsBtControlLps(PADAPTER padapter)2998 u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)
2999 {
3000 	if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3001 		return _FALSE;
3002 
3003 	if (GLBtCoexist.btInfo.bBtDisabled)
3004 		return _FALSE;
3005 
3006 	if (GLBtCoexist.btInfo.bBtCtrlLps)
3007 		return _TRUE;
3008 
3009 	return _FALSE;
3010 }
3011 
hal_btcoex_IsLpsOn(PADAPTER padapter)3012 u8 hal_btcoex_IsLpsOn(PADAPTER padapter)
3013 {
3014 	if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3015 		return _FALSE;
3016 
3017 	if (GLBtCoexist.btInfo.bBtDisabled)
3018 		return _FALSE;
3019 
3020 	if (GLBtCoexist.btInfo.bBtLpsOn)
3021 		return _TRUE;
3022 
3023 	return _FALSE;
3024 }
3025 
hal_btcoex_RpwmVal(PADAPTER padapter)3026 u8 hal_btcoex_RpwmVal(PADAPTER padapter)
3027 {
3028 	return GLBtCoexist.btInfo.rpwmVal;
3029 }
3030 
hal_btcoex_LpsVal(PADAPTER padapter)3031 u8 hal_btcoex_LpsVal(PADAPTER padapter)
3032 {
3033 	return GLBtCoexist.btInfo.lpsVal;
3034 }
3035 
hal_btcoex_GetRaMask(PADAPTER padapter)3036 u32 hal_btcoex_GetRaMask(PADAPTER padapter)
3037 {
3038 	if (!hal_btcoex_IsBtExist(padapter))
3039 		return 0;
3040 
3041 	if (GLBtCoexist.btInfo.bBtDisabled)
3042 		return 0;
3043 
3044 		/* Modify by YiWei , suggest by Cosa and Jenyu
3045 		 * Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask.
3046 		 */
3047 	/*if (GLBtCoexist.boardInfo.btdmAntNum != 1)
3048 		return 0;*/
3049 
3050 	return GLBtCoexist.btInfo.raMask;
3051 }
3052 
hal_btcoex_RecordPwrMode(PADAPTER padapter,u8 * pCmdBuf,u8 cmdLen)3053 void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
3054 {
3055 	RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW write pwrModeCmd=0x%04x%08x\n",
3056 		pCmdBuf[0]<<8|pCmdBuf[1],
3057 		pCmdBuf[2]<<24|pCmdBuf[3]<<16|pCmdBuf[4]<<8|pCmdBuf[5]));
3058 
3059 	_rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
3060 }
3061 
hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter,u8 * pbuf,u32 bufsize)3062 void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
3063 {
3064 	PBTCDBGINFO pinfo;
3065 
3066 
3067 	pinfo = &GLBtcDbgInfo;
3068 	DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
3069 	EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
3070 	DBG_BT_INFO_INIT(pinfo, NULL, 0);
3071 }
3072 
hal_btcoex_SetDBG(PADAPTER padapter,u32 * pDbgModule)3073 void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
3074 {
3075 	u32 i;
3076 
3077 
3078 	if (NULL == pDbgModule)
3079 		return;
3080 
3081 	for (i = 0; i < COMP_MAX; i++)
3082 		GLBtcDbgType[i] = pDbgModule[i];
3083 }
3084 
hal_btcoex_GetDBG(PADAPTER padapter,u8 * pStrBuf,u32 bufSize)3085 u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
3086 {
3087 	s32 count;
3088 	u8 *pstr;
3089 	u32 leftSize;
3090 
3091 
3092 	if ((NULL == pStrBuf) || (0 == bufSize))
3093 		return 0;
3094 
3095 	count = 0;
3096 	pstr = pStrBuf;
3097 	leftSize = bufSize;
3098 //	DBG_871X(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize);
3099 
3100 	count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
3101 	if ((count < 0) || (count >= leftSize))
3102 		goto exit;
3103 	pstr += count;
3104 	leftSize -= count;
3105 
3106 	count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
3107 	if ((count < 0) || (count >= leftSize))
3108 		goto exit;
3109 	pstr += count;
3110 	leftSize -= count;
3111 
3112 	count = rtw_sprintf(pstr, leftSize,
3113 		"COMP_COEX: 0x%08X\n\n",
3114 		GLBtcDbgType[COMP_COEX]);
3115 	if ((count < 0) || (count >= leftSize))
3116 		goto exit;
3117 	pstr += count;
3118 	leftSize -= count;
3119 
3120 #if 0
3121 	count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
3122 	if ((count < 0) || (count >= leftSize))
3123 		goto exit;
3124 	pstr += count;
3125 	leftSize -= count;
3126 	count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
3127 		GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_INIT?1:0);
3128 	if ((count < 0) || (count >= leftSize))
3129 		goto exit;
3130 	pstr += count;
3131 	leftSize -= count;
3132 	count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
3133 		GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_NOTIFY?1:0);
3134 	if ((count < 0) || (count >= leftSize))
3135 		goto exit;
3136 	pstr += count;
3137 	leftSize -= count;
3138 
3139 	count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
3140 	if ((count < 0) || (count >= leftSize))
3141 		goto exit;
3142 	pstr += count;
3143 	leftSize -= count;
3144 	count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
3145 		GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_RSSI_STATE?1:0);
3146 	if ((count < 0) || (count >= leftSize))
3147 		goto exit;
3148 	pstr += count;
3149 	leftSize -= count;
3150 	count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
3151 		GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_WIFI_RSSI_STATE?1:0);
3152 	if ((count < 0) || (count >= leftSize))
3153 		goto exit;
3154 	pstr += count;
3155 	leftSize -= count;
3156 	count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
3157 		GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_MONITOR?1:0);
3158 	if ((count < 0) || (count >= leftSize))
3159 		goto exit;
3160 	pstr += count;
3161 	leftSize -= count;
3162 	count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
3163 		GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE?1:0);
3164 	if ((count < 0) || (count >= leftSize))
3165 		goto exit;
3166 	pstr += count;
3167 	leftSize -= count;
3168 	count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
3169 		GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW?1:0);
3170 	if ((count < 0) || (count >= leftSize))
3171 		goto exit;
3172 	pstr += count;
3173 	leftSize -= count;
3174 	count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
3175 		GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_DETAIL?1:0);
3176 	if ((count < 0) || (count >= leftSize))
3177 		goto exit;
3178 	pstr += count;
3179 	leftSize -= count;
3180 	count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
3181 		GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_EXEC?1:0);
3182 	if ((count < 0) || (count >= leftSize))
3183 		goto exit;
3184 	pstr += count;
3185 	leftSize -= count;
3186 	count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
3187 		GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW?1:0);
3188 	if ((count < 0) || (count >= leftSize))
3189 		goto exit;
3190 	pstr += count;
3191 	leftSize -= count;
3192 	count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
3193 		GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_DETAIL?1:0);
3194 	if ((count < 0) || (count >= leftSize))
3195 		goto exit;
3196 	pstr += count;
3197 	leftSize -= count;
3198 	count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
3199 		GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_EXEC?1:0);
3200 	if ((count < 0) || (count >= leftSize))
3201 		goto exit;
3202 	pstr += count;
3203 	leftSize -= count;
3204 #endif
3205 
3206 exit:
3207 	count = pstr - pStrBuf;
3208 //	DBG_871X(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count);
3209 
3210 	return count;
3211 }
3212 
hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)3213 u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
3214 {
3215 	if (!hal_btcoex_IsBtExist(padapter))
3216 		return _FALSE;
3217 
3218 	if (GLBtCoexist.btInfo.bIncreaseScanDevNum)
3219 		return _TRUE;
3220 
3221 	return _FALSE;
3222 }
3223 
hal_btcoex_IsBtLinkExist(PADAPTER padapter)3224 u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)
3225 {
3226 	if (GLBtCoexist.btLinkInfo.bBtLinkExist)
3227 		return _TRUE;
3228 
3229 	return _FALSE;
3230 }
3231 
hal_btcoex_SetBtPatchVersion(PADAPTER padapter,u16 btHciVer,u16 btPatchVer)3232 void hal_btcoex_SetBtPatchVersion(PADAPTER padapter,u16 btHciVer,u16 btPatchVer)
3233 {
3234 	EXhalbtcoutsrc_SetBtPatchVersion(btHciVer,btPatchVer);
3235 }
3236 
hal_btcoex_SetHciVersion(PADAPTER padapter,u16 hciVersion)3237 void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)
3238 {
3239 	EXhalbtcoutsrc_SetHciVersion(hciVersion);
3240 }
3241 
hal_btcoex_StackUpdateProfileInfo(void)3242 void hal_btcoex_StackUpdateProfileInfo(void)
3243 {
3244 	EXhalbtcoutsrc_StackUpdateProfileInfo();
3245 }
3246 
hal_btcoex_BTOffOnNotify(PADAPTER padapter,u8 bBTON)3247 void hal_btcoex_BTOffOnNotify(PADAPTER padapter, u8 bBTON)
3248 {
3249 	EXhalbtcoutsrc_BTOffOnNotify(&GLBtCoexist, bBTON);
3250 }
3251 
3252 /*
3253  *	Description:
3254  *	Setting BT coex antenna isolation type .
3255  *	coex mechanisn/ spital stream/ best throughput
3256  *	anttype = 0	,	PSTDMA	/	2SS	/	0.5T	,	bad isolation , WiFi/BT ANT Distance<15cm , (<20dB) for 2,3 antenna
3257  *	anttype = 1	,	PSTDMA	/	1SS	/	0.5T	,	normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 2 antenna
3258  *	anttype = 2	,	TDMA	/	2SS	/	T ,		normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 3 antenna
3259  *	anttype = 3	,	no TDMA	/	1SS	/	0.5T	,	good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 2 antenna
3260  *	anttype = 4	,	no TDMA	/	2SS	/	T ,		good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 3 antenna
3261  *	wifi only throughput ~ T
3262  *	wifi/BT share one antenna with SPDT
3263  */
hal_btcoex_SetAntIsolationType(PADAPTER padapter,u8 anttype)3264 void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)
3265 {
3266 		PHAL_DATA_TYPE pHalData;
3267 		PBTC_COEXIST	pBtCoexist = &GLBtCoexist;
3268 
3269 		/*DBG_871X("####%s , anttype = %d  , %d\n" , __func__ , anttype , __LINE__); */
3270 		pHalData = GET_HAL_DATA(padapter);
3271 
3272 
3273 		pHalData->bt_coexist.btAntisolation = anttype;
3274 
3275 		switch (pHalData->bt_coexist.btAntisolation) {
3276 		case 0:
3277 				pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_0;
3278 				break;
3279 		case 1:
3280 				pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_1;
3281 				break;
3282 		case 2:
3283 				pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_2;
3284 				break;
3285 		case 3:
3286 				pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_3;
3287 				break;
3288 		case 4:
3289 				pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_4;
3290 				break;
3291 		}
3292 
3293 }
3294 
3295 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
3296 int
hal_btcoex_ParseAntIsolationConfigFile(PADAPTER Adapter,char * buffer)3297 hal_btcoex_ParseAntIsolationConfigFile(
3298   PADAPTER		Adapter,
3299   char*			buffer
3300 )
3301 {
3302 	HAL_DATA_TYPE	*pHalData = GET_HAL_DATA(Adapter);
3303 	u32	i = 0 , j = 0;
3304 	char	*szLine , *ptmp;
3305 	int rtStatus = _SUCCESS;
3306 	char param_value_string[10];
3307 	u8 param_value;
3308 	u8 anttype = 4;
3309 
3310 	u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1;
3311 
3312 	typedef struct ant_isolation {
3313 		char *param_name;  /* antenna isolation config parameter name */
3314 		u8 *value; /* antenna isolation config parameter value */
3315 	} ANT_ISOLATION;
3316 
3317 	ANT_ISOLATION ant_isolation_param[] = {
3318 												{"ANT_NUMBER" , &ant_num},
3319 												{"ANT_DISTANCE" , &ant_distance},
3320 												{"RFE_TYPE" , &rfe_type},
3321 												{NULL , 0}
3322 										};
3323 
3324 
3325 
3326 	/* DBG_871X("===>Hal_ParseAntIsolationConfigFile()\n" ); */
3327 
3328 	ptmp = buffer;
3329 	for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
3330 		/* skip comment */
3331 		if (IsCommentString(szLine))
3332 			continue;
3333 
3334 		/* DBG_871X("%s : szLine = %s , strlen(szLine) = %d\n" , __func__ , szLine , strlen(szLine));*/
3335 		for (j = 0 ; ant_isolation_param[j].param_name != NULL ; j++) {
3336 			if (strstr(szLine , ant_isolation_param[j].param_name) != NULL) {
3337 				i = 0;
3338 				while (i < strlen(szLine)) {
3339 					if (szLine[i] != '"')
3340 						++i;
3341 					else {
3342 						/* skip only has one " */
3343 						if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) {
3344 							DBG_871X("Fail to parse parameters , format error!\n");
3345 							break;
3346 						}
3347 						_rtw_memset((PVOID)param_value_string , 0 , 10);
3348 						if (!ParseQualifiedString(szLine , &i , param_value_string , '"' , '"')) {
3349 							DBG_871X("Fail to parse parameters\n");
3350 							return _FAIL;
3351 						} else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value))
3352 							DBG_871X("Fail to GetU1ByteIntegerFromStringInDecimal\n");
3353 
3354 						break;
3355 					}
3356 				}
3357 			}
3358 		}
3359 	}
3360 
3361 	/* YiWei 20140716 , for BT coex antenna isolation control */
3362 	/* rfe_type = 0 was SPDT , rfe_type = 1 was coupler */
3363 	if (ant_num == 3 && ant_distance >= 50)
3364 		anttype = 3;
3365 	else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1)
3366 		anttype = 2;
3367 	else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50)
3368 		anttype = 2;
3369 	else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1)
3370 		anttype = 2;
3371 	else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15))
3372 		anttype = 1;
3373 	else if (ant_num == 2 && rfe_type == 0)
3374 		anttype = 0;
3375 	else
3376 		anttype = 0;
3377 
3378 	hal_btcoex_SetAntIsolationType(Adapter, anttype);
3379 
3380 	DBG_871X("%s : ant_num = %d\n" , __func__ , ant_num);
3381 	DBG_871X("%s : ant_distance = %d\n" , __func__ , ant_distance);
3382 	DBG_871X("%s : rfe_type = %d\n" , __func__ , rfe_type);
3383 	/* DBG_871X("<===Hal_ParseAntIsolationConfigFile()\n"); */
3384 	return rtStatus;
3385 }
3386 
3387 
3388 int
hal_btcoex_AntIsolationConfig_ParaFile(IN PADAPTER Adapter,IN char * pFileName)3389 hal_btcoex_AntIsolationConfig_ParaFile(
3390 	IN	PADAPTER	Adapter,
3391 	IN	char*	 	pFileName
3392 )
3393 {
3394 	HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
3395 	int	rlen = 0 , rtStatus = _FAIL;
3396 
3397 	_rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN);
3398 
3399 
3400 	rtw_merge_string(rtw_phy_para_file_path, PATH_LENGTH_MAX, rtw_phy_file_path, pFileName);
3401 
3402 	if (rtw_is_file_readable(rtw_phy_para_file_path) == _TRUE)
3403 	{
3404 		rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
3405 		if (rlen > 0)
3406 		{
3407 			rtStatus = _SUCCESS;
3408 		}
3409 	}
3410 
3411 
3412 	if (rtStatus == _SUCCESS) {
3413 		/*DBG_871X("%s(): read %s ok\n", __func__ , pFileName);*/
3414 		rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf);
3415 	} else {
3416 		DBG_871X("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName);
3417 	}
3418 
3419 	return rtStatus;
3420 }
3421 #endif // CONFIG_LOAD_PHY_PARA_FROM_FILE
3422 #endif // CONFIG_BT_COEXIST
3423 
3424