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