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