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