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