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