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