1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  *
4  * Copyright(c) 2013 Realtek Corporation. All rights reserved.
5  *
6  ******************************************************************************/
7 
8 #include <hal_data.h>
9 #include <hal_btcoex.h>
10 #include <Mp_Precomp.h>
11 
12 /* 		Global variables */
13 
14 struct btc_coexist GLBtCoexist;
15 static u8 GLBtcWiFiInScanState;
16 static u8 GLBtcWiFiInIQKState;
17 
18 /*  */
19 /* 		Debug related function */
20 /*  */
halbtcoutsrc_IsBtCoexistAvailable(struct btc_coexist * pBtCoexist)21 static u8 halbtcoutsrc_IsBtCoexistAvailable(struct btc_coexist *pBtCoexist)
22 {
23 	if (!pBtCoexist->bBinded || !pBtCoexist->Adapter)
24 		return false;
25 
26 	return true;
27 }
28 
halbtcoutsrc_LeaveLps(struct btc_coexist * pBtCoexist)29 static void halbtcoutsrc_LeaveLps(struct btc_coexist *pBtCoexist)
30 {
31 	struct adapter *padapter;
32 
33 
34 	padapter = pBtCoexist->Adapter;
35 
36 	pBtCoexist->btInfo.bBtCtrlLps = true;
37 	pBtCoexist->btInfo.bBtLpsOn = false;
38 
39 	rtw_btcoex_LPS_Leave(padapter);
40 }
41 
halbtcoutsrc_EnterLps(struct btc_coexist * pBtCoexist)42 static void halbtcoutsrc_EnterLps(struct btc_coexist *pBtCoexist)
43 {
44 	struct adapter *padapter;
45 
46 
47 	padapter = pBtCoexist->Adapter;
48 
49 	pBtCoexist->btInfo.bBtCtrlLps = true;
50 	pBtCoexist->btInfo.bBtLpsOn = true;
51 
52 	rtw_btcoex_LPS_Enter(padapter);
53 }
54 
halbtcoutsrc_NormalLps(struct btc_coexist * pBtCoexist)55 static void halbtcoutsrc_NormalLps(struct btc_coexist *pBtCoexist)
56 {
57 	struct adapter *padapter;
58 
59 	padapter = pBtCoexist->Adapter;
60 
61 	if (pBtCoexist->btInfo.bBtCtrlLps) {
62 		pBtCoexist->btInfo.bBtLpsOn = false;
63 		rtw_btcoex_LPS_Leave(padapter);
64 		pBtCoexist->btInfo.bBtCtrlLps = false;
65 
66 		/*  recover the LPS state to the original */
67 	}
68 }
69 
70 /*
71  *  Constraint:
72  *   1. this function will request pwrctrl->lock
73  */
halbtcoutsrc_LeaveLowPower(struct btc_coexist * pBtCoexist)74 static void halbtcoutsrc_LeaveLowPower(struct btc_coexist *pBtCoexist)
75 {
76 	struct adapter *padapter;
77 	s32 ready;
78 	unsigned long stime;
79 	unsigned long utime;
80 	u32 timeout; /*  unit: ms */
81 
82 
83 	padapter = pBtCoexist->Adapter;
84 	ready = _FAIL;
85 #ifdef LPS_RPWM_WAIT_MS
86 	timeout = LPS_RPWM_WAIT_MS;
87 #else /*  !LPS_RPWM_WAIT_MS */
88 	timeout = 30;
89 #endif /*  !LPS_RPWM_WAIT_MS */
90 
91 	stime = jiffies;
92 	do {
93 		ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
94 		if (_SUCCESS == ready)
95 			break;
96 
97 		utime = jiffies_to_msecs(jiffies - stime);
98 		if (utime > timeout)
99 			break;
100 
101 		msleep(1);
102 	} while (1);
103 }
104 
105 /*
106  *  Constraint:
107  *   1. this function will request pwrctrl->lock
108  */
halbtcoutsrc_NormalLowPower(struct btc_coexist * pBtCoexist)109 static void halbtcoutsrc_NormalLowPower(struct btc_coexist *pBtCoexist)
110 {
111 	struct adapter *padapter;
112 
113 
114 	padapter = pBtCoexist->Adapter;
115 	rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
116 }
117 
halbtcoutsrc_DisableLowPower(struct btc_coexist * pBtCoexist,u8 bLowPwrDisable)118 static void halbtcoutsrc_DisableLowPower(struct btc_coexist *pBtCoexist, u8 bLowPwrDisable)
119 {
120 	pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
121 	if (bLowPwrDisable)
122 		halbtcoutsrc_LeaveLowPower(pBtCoexist);		/*  leave 32k low power. */
123 	else
124 		halbtcoutsrc_NormalLowPower(pBtCoexist);	/*  original 32k low power behavior. */
125 }
126 
halbtcoutsrc_AggregationCheck(struct btc_coexist * pBtCoexist)127 static void halbtcoutsrc_AggregationCheck(struct btc_coexist *pBtCoexist)
128 {
129 	struct adapter *padapter;
130 	bool bNeedToAct;
131 
132 
133 	padapter = pBtCoexist->Adapter;
134 	bNeedToAct = false;
135 
136 	if (pBtCoexist->btInfo.bRejectAggPkt) {
137 		rtw_btcoex_RejectApAggregatedPacket(padapter, true);
138 	} else {
139 		if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
140 			pBtCoexist->btInfo.bBtCtrlAggBufSize) {
141 			bNeedToAct = true;
142 			pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
143 		}
144 
145 		if (pBtCoexist->btInfo.bBtCtrlAggBufSize) {
146 			if (pBtCoexist->btInfo.preAggBufSize !=
147 				pBtCoexist->btInfo.aggBufSize){
148 				bNeedToAct = true;
149 			}
150 			pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
151 		}
152 
153 		if (bNeedToAct) {
154 			rtw_btcoex_RejectApAggregatedPacket(padapter, true);
155 			rtw_btcoex_RejectApAggregatedPacket(padapter, false);
156 		}
157 	}
158 }
159 
halbtcoutsrc_IsWifiBusy(struct adapter * padapter)160 static u8 halbtcoutsrc_IsWifiBusy(struct adapter *padapter)
161 {
162 	struct mlme_priv *pmlmepriv;
163 
164 
165 	pmlmepriv = &padapter->mlmepriv;
166 
167 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
168 		if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
169 			return true;
170 		if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
171 			return true;
172 	}
173 
174 	return false;
175 }
176 
_halbtcoutsrc_GetWifiLinkStatus(struct adapter * padapter)177 static u32 _halbtcoutsrc_GetWifiLinkStatus(struct adapter *padapter)
178 {
179 	struct mlme_priv *pmlmepriv;
180 	u8 bp2p;
181 	u32 portConnectedStatus;
182 
183 
184 	pmlmepriv = &padapter->mlmepriv;
185 	bp2p = false;
186 	portConnectedStatus = 0;
187 
188 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
189 		if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
190 			if (bp2p)
191 				portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
192 			else
193 				portConnectedStatus |= WIFI_AP_CONNECTED;
194 		} else {
195 			if (bp2p)
196 				portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
197 			else
198 				portConnectedStatus |= WIFI_STA_CONNECTED;
199 		}
200 	}
201 
202 	return portConnectedStatus;
203 }
204 
halbtcoutsrc_GetWifiLinkStatus(struct btc_coexist * pBtCoexist)205 static u32 halbtcoutsrc_GetWifiLinkStatus(struct btc_coexist *pBtCoexist)
206 {
207 	/*  */
208 	/*  return value: */
209 	/*  [31:16]=> connected port number */
210 	/*  [15:0]=> port connected bit define */
211 	/*  */
212 
213 	struct adapter *padapter;
214 	u32 retVal;
215 	u32 portConnectedStatus, numOfConnectedPort;
216 
217 
218 	padapter = pBtCoexist->Adapter;
219 	portConnectedStatus = 0;
220 	numOfConnectedPort = 0;
221 
222 	retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
223 	if (retVal) {
224 		portConnectedStatus |= retVal;
225 		numOfConnectedPort++;
226 	}
227 
228 	retVal = (numOfConnectedPort << 16) | portConnectedStatus;
229 
230 	return retVal;
231 }
232 
halbtcoutsrc_GetBtPatchVer(struct btc_coexist * pBtCoexist)233 static u32 halbtcoutsrc_GetBtPatchVer(struct btc_coexist *pBtCoexist)
234 {
235 	return pBtCoexist->btInfo.btRealFwVer;
236 }
237 
halbtcoutsrc_GetWifiRssi(struct adapter * padapter)238 static s32 halbtcoutsrc_GetWifiRssi(struct adapter *padapter)
239 {
240 	struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
241 
242 	return pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
243 }
244 
halbtcoutsrc_GetWifiScanAPNum(struct adapter * padapter)245 static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter)
246 {
247 	struct mlme_ext_priv *pmlmeext;
248 	static u8 scan_AP_num;
249 
250 	pmlmeext = &padapter->mlmeextpriv;
251 
252 	if (!GLBtcWiFiInScanState) {
253 		if (pmlmeext->sitesurvey_res.bss_cnt > 0xFF)
254 			scan_AP_num = 0xFF;
255 		else
256 			scan_AP_num = (u8)pmlmeext->sitesurvey_res.bss_cnt;
257 	}
258 
259 	return scan_AP_num;
260 }
261 
halbtcoutsrc_Get(void * pBtcContext,u8 getType,void * pOutBuf)262 static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
263 {
264 	struct btc_coexist *pBtCoexist;
265 	struct adapter *padapter;
266 	struct hal_com_data *pHalData;
267 	struct mlme_ext_priv *mlmeext;
268 	u8 *pu8;
269 	s32 *pS4Tmp;
270 	u32 *pU4Tmp;
271 	u8 ret;
272 
273 
274 	pBtCoexist = (struct btc_coexist *)pBtcContext;
275 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
276 		return false;
277 
278 	padapter = pBtCoexist->Adapter;
279 	pHalData = GET_HAL_DATA(padapter);
280 	mlmeext = &padapter->mlmeextpriv;
281 	pu8 = pOutBuf;
282 	pS4Tmp = pOutBuf;
283 	pU4Tmp = pOutBuf;
284 	ret = true;
285 
286 	switch (getType) {
287 	case BTC_GET_BL_HS_OPERATION:
288 		*pu8 = false;
289 		ret = false;
290 		break;
291 
292 	case BTC_GET_BL_HS_CONNECTING:
293 		*pu8 = false;
294 		ret = false;
295 		break;
296 
297 	case BTC_GET_BL_WIFI_CONNECTED:
298 		*pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
299 		break;
300 
301 	case BTC_GET_BL_WIFI_BUSY:
302 		*pu8 = halbtcoutsrc_IsWifiBusy(padapter);
303 		break;
304 
305 	case BTC_GET_BL_WIFI_SCAN:
306 		/* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
307 			WIFI_SITE_MONITOR in fwstate may not be cleared in time */
308 		*pu8 = GLBtcWiFiInScanState;
309 		break;
310 
311 	case BTC_GET_BL_WIFI_LINK:
312 		*pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
313 		break;
314 
315 	case BTC_GET_BL_WIFI_ROAM:
316 		*pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
317 		break;
318 
319 	case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
320 		*pu8 = false;
321 		break;
322 
323 	case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
324 		*pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
325 		break;
326 
327 	case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
328 		*pu8 = padapter->securitypriv.dot11PrivacyAlgrthm != 0;
329 		break;
330 
331 	case BTC_GET_BL_WIFI_UNDER_B_MODE:
332 		if (mlmeext->cur_wireless_mode == WIRELESS_11B)
333 			*pu8 = true;
334 		else
335 			*pu8 = false;
336 		break;
337 
338 	case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
339 		*pu8 = false;
340 		break;
341 
342 	case BTC_GET_BL_EXT_SWITCH:
343 		*pu8 = false;
344 		break;
345 
346 	case BTC_GET_S4_WIFI_RSSI:
347 		*pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
348 		break;
349 
350 	case BTC_GET_S4_HS_RSSI:
351 		*pS4Tmp = 0;
352 		ret = false;
353 		break;
354 
355 	case BTC_GET_U4_WIFI_BW:
356 		if (is_legacy_only(mlmeext->cur_wireless_mode))
357 			*pU4Tmp = BTC_WIFI_BW_LEGACY;
358 		else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
359 			*pU4Tmp = BTC_WIFI_BW_HT20;
360 		else
361 			*pU4Tmp = BTC_WIFI_BW_HT40;
362 		break;
363 
364 	case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
365 		{
366 			struct rt_link_detect_t *plinkinfo;
367 			plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
368 
369 			if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
370 				*pU4Tmp = BTC_WIFI_TRAFFIC_TX;
371 			else
372 				*pU4Tmp = BTC_WIFI_TRAFFIC_RX;
373 		}
374 		break;
375 
376 	case BTC_GET_U4_WIFI_FW_VER:
377 		*pU4Tmp = pHalData->FirmwareVersion << 16;
378 		*pU4Tmp |= pHalData->FirmwareSubVersion;
379 		break;
380 
381 	case BTC_GET_U4_WIFI_LINK_STATUS:
382 		*pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
383 		break;
384 
385 	case BTC_GET_U4_BT_PATCH_VER:
386 		*pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
387 		break;
388 
389 	case BTC_GET_U1_WIFI_DOT11_CHNL:
390 		*pu8 = padapter->mlmeextpriv.cur_channel;
391 		break;
392 
393 	case BTC_GET_U1_WIFI_CENTRAL_CHNL:
394 		*pu8 = pHalData->CurrentChannel;
395 		break;
396 
397 	case BTC_GET_U1_WIFI_HS_CHNL:
398 		*pu8 = 0;
399 		ret = false;
400 		break;
401 
402 	case BTC_GET_U1_MAC_PHY_MODE:
403 		*pu8 = BTC_SMSP;
404 /* 			*pU1Tmp = BTC_DMSP; */
405 /* 			*pU1Tmp = BTC_DMDP; */
406 /* 			*pU1Tmp = BTC_MP_UNKNOWN; */
407 		break;
408 
409 	case BTC_GET_U1_AP_NUM:
410 		*pu8 = halbtcoutsrc_GetWifiScanAPNum(padapter);
411 		break;
412 
413 	/* 1Ant =========== */
414 	case BTC_GET_U1_LPS_MODE:
415 		*pu8 = padapter->dvobj->pwrctl_priv.pwr_mode;
416 		break;
417 
418 	default:
419 		ret = false;
420 		break;
421 	}
422 
423 	return ret;
424 }
425 
halbtcoutsrc_Set(void * pBtcContext,u8 setType,void * pInBuf)426 static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
427 {
428 	struct btc_coexist *pBtCoexist;
429 	struct adapter *padapter;
430 	u8 *pu8;
431 	u32 *pU4Tmp;
432 	u8 ret;
433 
434 
435 	pBtCoexist = (struct btc_coexist *)pBtcContext;
436 	padapter = pBtCoexist->Adapter;
437 	pu8 = pInBuf;
438 	pU4Tmp = pInBuf;
439 	ret = true;
440 
441 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
442 		return false;
443 
444 	switch (setType) {
445 	/*  set some u8 type variables. */
446 	case BTC_SET_BL_BT_DISABLE:
447 		pBtCoexist->btInfo.bBtDisabled = *pu8;
448 		break;
449 
450 	case BTC_SET_BL_BT_TRAFFIC_BUSY:
451 		pBtCoexist->btInfo.bBtBusy = *pu8;
452 		break;
453 
454 	case BTC_SET_BL_BT_LIMITED_DIG:
455 		pBtCoexist->btInfo.bLimitedDig = *pu8;
456 		break;
457 
458 	case BTC_SET_BL_FORCE_TO_ROAM:
459 		pBtCoexist->btInfo.bForceToRoam = *pu8;
460 		break;
461 
462 	case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
463 		pBtCoexist->btInfo.bRejectAggPkt = *pu8;
464 		break;
465 
466 	case BTC_SET_BL_BT_CTRL_AGG_SIZE:
467 		pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
468 		break;
469 
470 	case BTC_SET_BL_INC_SCAN_DEV_NUM:
471 		pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
472 		break;
473 
474 	case BTC_SET_BL_BT_TX_RX_MASK:
475 		pBtCoexist->btInfo.bBtTxRxMask = *pu8;
476 		break;
477 
478 	/*  set some u8 type variables. */
479 	case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
480 		pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pu8;
481 		break;
482 
483 	case BTC_SET_U1_AGG_BUF_SIZE:
484 		pBtCoexist->btInfo.aggBufSize = *pu8;
485 		break;
486 
487 	/*  the following are some action which will be triggered */
488 	case BTC_SET_ACT_GET_BT_RSSI:
489 		ret = false;
490 		break;
491 
492 	case BTC_SET_ACT_AGGREGATE_CTRL:
493 		halbtcoutsrc_AggregationCheck(pBtCoexist);
494 		break;
495 
496 	/* 1Ant =========== */
497 	/*  set some u8 type variables. */
498 	case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
499 		pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pu8;
500 		break;
501 
502 	case BTC_SET_U1_LPS_VAL:
503 		pBtCoexist->btInfo.lpsVal = *pu8;
504 		break;
505 
506 	case BTC_SET_U1_RPWM_VAL:
507 		pBtCoexist->btInfo.rpwmVal = *pu8;
508 		break;
509 
510 	/*  the following are some action which will be triggered */
511 	case BTC_SET_ACT_LEAVE_LPS:
512 		halbtcoutsrc_LeaveLps(pBtCoexist);
513 		break;
514 
515 	case BTC_SET_ACT_ENTER_LPS:
516 		halbtcoutsrc_EnterLps(pBtCoexist);
517 		break;
518 
519 	case BTC_SET_ACT_NORMAL_LPS:
520 		halbtcoutsrc_NormalLps(pBtCoexist);
521 		break;
522 
523 	case BTC_SET_ACT_DISABLE_LOW_POWER:
524 		halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
525 		break;
526 
527 	case BTC_SET_ACT_UPDATE_RAMASK:
528 		pBtCoexist->btInfo.raMask = *pU4Tmp;
529 
530 		if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true) {
531 			struct sta_info *psta;
532 			struct wlan_bssid_ex *cur_network;
533 
534 			cur_network = &padapter->mlmeextpriv.mlmext_info.network;
535 			psta = rtw_get_stainfo(&padapter->stapriv, cur_network->mac_address);
536 			rtw_hal_update_ra_mask(psta, 0);
537 		}
538 		break;
539 
540 	case BTC_SET_ACT_SEND_MIMO_PS:
541 		ret = false;
542 		break;
543 
544 	case BTC_SET_ACT_CTRL_BT_INFO:
545 		ret = false;
546 		break;
547 
548 	case BTC_SET_ACT_CTRL_BT_COEX:
549 		ret = false;
550 		break;
551 	case BTC_SET_ACT_CTRL_8723B_ANT:
552 		ret = false;
553 		break;
554 	/*  */
555 	default:
556 		ret = false;
557 		break;
558 	}
559 
560 	return ret;
561 }
562 
563 /*  */
564 /* 		IO related function */
565 /*  */
halbtcoutsrc_Read1Byte(void * pBtcContext,u32 RegAddr)566 static u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
567 {
568 	struct btc_coexist *pBtCoexist;
569 	struct adapter *padapter;
570 
571 
572 	pBtCoexist = (struct btc_coexist *)pBtcContext;
573 	padapter = pBtCoexist->Adapter;
574 
575 	return rtw_read8(padapter, RegAddr);
576 }
577 
halbtcoutsrc_Read2Byte(void * pBtcContext,u32 RegAddr)578 static u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
579 {
580 	struct btc_coexist *pBtCoexist;
581 	struct adapter *padapter;
582 
583 
584 	pBtCoexist = (struct btc_coexist *)pBtcContext;
585 	padapter = pBtCoexist->Adapter;
586 
587 	return	rtw_read16(padapter, RegAddr);
588 }
589 
halbtcoutsrc_Read4Byte(void * pBtcContext,u32 RegAddr)590 static u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
591 {
592 	struct btc_coexist *pBtCoexist;
593 	struct adapter *padapter;
594 
595 
596 	pBtCoexist = (struct btc_coexist *)pBtcContext;
597 	padapter = pBtCoexist->Adapter;
598 
599 	return	rtw_read32(padapter, RegAddr);
600 }
601 
halbtcoutsrc_Write1Byte(void * pBtcContext,u32 RegAddr,u8 Data)602 static void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
603 {
604 	struct btc_coexist *pBtCoexist;
605 	struct adapter *padapter;
606 
607 
608 	pBtCoexist = (struct btc_coexist *)pBtcContext;
609 	padapter = pBtCoexist->Adapter;
610 
611 	rtw_write8(padapter, RegAddr, Data);
612 }
613 
halbtcoutsrc_BitMaskWrite1Byte(void * pBtcContext,u32 regAddr,u8 bitMask,u8 data1b)614 static void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
615 {
616 	struct btc_coexist *pBtCoexist;
617 	struct adapter *padapter;
618 	u8 originalValue, bitShift;
619 	u8 i;
620 
621 
622 	pBtCoexist = (struct btc_coexist *)pBtcContext;
623 	padapter = pBtCoexist->Adapter;
624 	originalValue = 0;
625 	bitShift = 0;
626 
627 	if (bitMask != 0xFF) {
628 		originalValue = rtw_read8(padapter, regAddr);
629 
630 		for (i = 0; i <= 7; i++) {
631 			if ((bitMask >> i) & 0x1)
632 				break;
633 		}
634 		bitShift = i;
635 
636 		data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
637 	}
638 
639 	rtw_write8(padapter, regAddr, data1b);
640 }
641 
halbtcoutsrc_Write2Byte(void * pBtcContext,u32 RegAddr,u16 Data)642 static void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
643 {
644 	struct btc_coexist *pBtCoexist;
645 	struct adapter *padapter;
646 
647 
648 	pBtCoexist = (struct btc_coexist *)pBtcContext;
649 	padapter = pBtCoexist->Adapter;
650 
651 	rtw_write16(padapter, RegAddr, Data);
652 }
653 
halbtcoutsrc_Write4Byte(void * pBtcContext,u32 RegAddr,u32 Data)654 static void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
655 {
656 	struct btc_coexist *pBtCoexist;
657 	struct adapter *padapter;
658 
659 
660 	pBtCoexist = (struct btc_coexist *)pBtcContext;
661 	padapter = pBtCoexist->Adapter;
662 
663 	rtw_write32(padapter, RegAddr, Data);
664 }
665 
halbtcoutsrc_WriteLocalReg1Byte(void * pBtcContext,u32 RegAddr,u8 Data)666 static void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
667 {
668 	struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
669 	struct adapter *Adapter = pBtCoexist->Adapter;
670 
671 	if (BTC_INTF_SDIO == pBtCoexist->chipInterface)
672 		rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
673 	else
674 		rtw_write8(Adapter, RegAddr, Data);
675 }
676 
halbtcoutsrc_SetBbReg(void * pBtcContext,u32 RegAddr,u32 BitMask,u32 Data)677 static void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
678 {
679 	struct btc_coexist *pBtCoexist;
680 	struct adapter *padapter;
681 
682 
683 	pBtCoexist = (struct btc_coexist *)pBtcContext;
684 	padapter = pBtCoexist->Adapter;
685 
686 	PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
687 }
688 
689 
halbtcoutsrc_GetBbReg(void * pBtcContext,u32 RegAddr,u32 BitMask)690 static u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
691 {
692 	struct btc_coexist *pBtCoexist;
693 	struct adapter *padapter;
694 
695 
696 	pBtCoexist = (struct btc_coexist *)pBtcContext;
697 	padapter = pBtCoexist->Adapter;
698 
699 	return PHY_QueryBBReg(padapter, RegAddr, BitMask);
700 }
701 
halbtcoutsrc_SetRfReg(void * pBtcContext,u8 eRFPath,u32 RegAddr,u32 BitMask,u32 Data)702 static void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
703 {
704 	struct btc_coexist *pBtCoexist;
705 	struct adapter *padapter;
706 
707 
708 	pBtCoexist = (struct btc_coexist *)pBtcContext;
709 	padapter = pBtCoexist->Adapter;
710 
711 	PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
712 }
713 
halbtcoutsrc_GetRfReg(void * pBtcContext,u8 eRFPath,u32 RegAddr,u32 BitMask)714 static u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
715 {
716 	struct btc_coexist *pBtCoexist;
717 	struct adapter *padapter;
718 
719 
720 	pBtCoexist = (struct btc_coexist *)pBtcContext;
721 	padapter = pBtCoexist->Adapter;
722 
723 	return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
724 }
725 
halbtcoutsrc_SetBtReg(void * pBtcContext,u8 RegType,u32 RegAddr,u32 Data)726 static void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
727 {
728 	struct btc_coexist *pBtCoexist;
729 	struct adapter *padapter;
730 	u8 CmdBuffer1[4] = {0};
731 	u8 CmdBuffer2[4] = {0};
732 	u8 *AddrToSet = (u8 *)&RegAddr;
733 	u8 *ValueToSet = (u8 *)&Data;
734 	u8 OperVer = 0;
735 	u8 ReqNum = 0;
736 
737 	pBtCoexist = (struct btc_coexist *)pBtcContext;
738 	padapter = pBtCoexist->Adapter;
739 
740 	CmdBuffer1[0] |= (OperVer & 0x0f);						/* Set OperVer */
741 	CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0);				/* Set ReqNum */
742 	CmdBuffer1[1] = 0x0d;									/* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */
743 	CmdBuffer1[2] = ValueToSet[0];							/* Set WriteRegValue */
744 	rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0]));
745 
746 	msleep(200);
747 	ReqNum++;
748 
749 	CmdBuffer2[0] |= (OperVer & 0x0f);						/* Set OperVer */
750 	CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0);				/* Set ReqNum */
751 	CmdBuffer2[1] = 0x0c;									/* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */
752 	CmdBuffer2[3] = AddrToSet[0];							/* Set WriteRegAddr */
753 	rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0]));
754 }
755 
halbtcoutsrc_GetBtReg(void * pBtcContext,u8 RegType,u32 RegAddr)756 static u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
757 {
758 	/* To be implemented. Always return 0 temporarily */
759 	return 0;
760 }
761 
halbtcoutsrc_FillH2cCmd(void * pBtcContext,u8 elementId,u32 cmdLen,u8 * pCmdBuffer)762 static void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
763 {
764 	struct btc_coexist *pBtCoexist;
765 	struct adapter *padapter;
766 
767 
768 	pBtCoexist = (struct btc_coexist *)pBtcContext;
769 	padapter = pBtCoexist->Adapter;
770 
771 	rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
772 }
773 
774 /*  */
775 /* 		Extern functions called by other module */
776 /*  */
EXhalbtcoutsrc_BindBtCoexWithAdapter(void * padapter)777 static u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
778 {
779 	struct btc_coexist *pBtCoexist = &GLBtCoexist;
780 
781 	if (pBtCoexist->bBinded)
782 		return false;
783 	else
784 		pBtCoexist->bBinded = true;
785 
786 	pBtCoexist->statistics.cntBind++;
787 
788 	pBtCoexist->Adapter = padapter;
789 
790 	pBtCoexist->stackInfo.bProfileNotified = false;
791 
792 	pBtCoexist->btInfo.bBtCtrlAggBufSize = false;
793 	pBtCoexist->btInfo.aggBufSize = 5;
794 
795 	pBtCoexist->btInfo.bIncreaseScanDevNum = false;
796 
797 	/*  set default antenna position to main  port */
798 	pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
799 
800 	return true;
801 }
802 
hal_btcoex_Initialize(void * padapter)803 void hal_btcoex_Initialize(void *padapter)
804 {
805 	struct btc_coexist *pBtCoexist;
806 
807 	memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
808 
809 	pBtCoexist = &GLBtCoexist;
810 
811 	/* pBtCoexist->statistics.cntBind++; */
812 
813 	pBtCoexist->chipInterface = BTC_INTF_SDIO;
814 
815 	EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
816 
817 	pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
818 	pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
819 	pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
820 	pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
821 	pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
822 	pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
823 	pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
824 	pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
825 
826 	pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
827 	pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
828 
829 	pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
830 	pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
831 
832 	pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
833 
834 	pBtCoexist->fBtcGet = halbtcoutsrc_Get;
835 	pBtCoexist->fBtcSet = halbtcoutsrc_Set;
836 	pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
837 	pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
838 
839 	pBtCoexist->boardInfo.singleAntPath = 0;
840 
841 	GLBtcWiFiInScanState = false;
842 
843 	GLBtcWiFiInIQKState = false;
844 }
845 
EXhalbtcoutsrc_PowerOnSetting(struct btc_coexist * pBtCoexist)846 void EXhalbtcoutsrc_PowerOnSetting(struct btc_coexist *pBtCoexist)
847 {
848 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
849 		return;
850 
851 	/* Power on setting function is only added in 8723B currently */
852 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
853 		EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
854 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
855 		EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
856 }
857 
EXhalbtcoutsrc_InitHwConfig(struct btc_coexist * pBtCoexist,u8 bWifiOnly)858 void EXhalbtcoutsrc_InitHwConfig(struct btc_coexist *pBtCoexist, u8 bWifiOnly)
859 {
860 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
861 		return;
862 
863 	pBtCoexist->statistics.cntInitHwConfig++;
864 
865 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
866 		EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
867 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
868 		EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
869 }
870 
EXhalbtcoutsrc_InitCoexDm(struct btc_coexist * pBtCoexist)871 void EXhalbtcoutsrc_InitCoexDm(struct btc_coexist *pBtCoexist)
872 {
873 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
874 		return;
875 
876 	pBtCoexist->statistics.cntInitCoexDm++;
877 
878 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
879 		EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
880 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
881 		EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
882 
883 	pBtCoexist->bInitilized = true;
884 }
885 
EXhalbtcoutsrc_IpsNotify(struct btc_coexist * pBtCoexist,u8 type)886 void EXhalbtcoutsrc_IpsNotify(struct btc_coexist *pBtCoexist, u8 type)
887 {
888 	u8 ipsType;
889 
890 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
891 		return;
892 
893 	pBtCoexist->statistics.cntIpsNotify++;
894 	if (pBtCoexist->bManualControl)
895 		return;
896 
897 	if (IPS_NONE == type)
898 		ipsType = BTC_IPS_LEAVE;
899 	else
900 		ipsType = BTC_IPS_ENTER;
901 
902 	/*  All notify is called in cmd thread, don't need to leave low power again */
903 /* 	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
904 
905 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
906 		EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
907 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
908 		EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
909 
910 /* 	halbtcoutsrc_NormalLowPower(pBtCoexist); */
911 }
912 
EXhalbtcoutsrc_LpsNotify(struct btc_coexist * pBtCoexist,u8 type)913 void EXhalbtcoutsrc_LpsNotify(struct btc_coexist *pBtCoexist, u8 type)
914 {
915 	u8 lpsType;
916 
917 
918 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
919 		return;
920 
921 	pBtCoexist->statistics.cntLpsNotify++;
922 	if (pBtCoexist->bManualControl)
923 		return;
924 
925 	if (PS_MODE_ACTIVE == type)
926 		lpsType = BTC_LPS_DISABLE;
927 	else
928 		lpsType = BTC_LPS_ENABLE;
929 
930 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
931 		EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
932 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
933 		EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
934 }
935 
EXhalbtcoutsrc_ScanNotify(struct btc_coexist * pBtCoexist,u8 type)936 void EXhalbtcoutsrc_ScanNotify(struct btc_coexist *pBtCoexist, u8 type)
937 {
938 	u8 scanType;
939 
940 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
941 		return;
942 	pBtCoexist->statistics.cntScanNotify++;
943 	if (pBtCoexist->bManualControl)
944 		return;
945 
946 	if (type) {
947 		scanType = BTC_SCAN_START;
948 		GLBtcWiFiInScanState = true;
949 	} else {
950 		scanType = BTC_SCAN_FINISH;
951 		GLBtcWiFiInScanState = false;
952 	}
953 
954 	/*  All notify is called in cmd thread, don't need to leave low power again */
955 /* 	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
956 
957 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
958 		EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
959 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
960 		EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
961 
962 /* 	halbtcoutsrc_NormalLowPower(pBtCoexist); */
963 }
964 
EXhalbtcoutsrc_ConnectNotify(struct btc_coexist * pBtCoexist,u8 action)965 void EXhalbtcoutsrc_ConnectNotify(struct btc_coexist *pBtCoexist, u8 action)
966 {
967 	u8 assoType;
968 
969 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
970 		return;
971 	pBtCoexist->statistics.cntConnectNotify++;
972 	if (pBtCoexist->bManualControl)
973 		return;
974 
975 	if (action)
976 		assoType = BTC_ASSOCIATE_START;
977 	else
978 		assoType = BTC_ASSOCIATE_FINISH;
979 
980 	/*  All notify is called in cmd thread, don't need to leave low power again */
981 /* 	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
982 
983 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
984 		EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
985 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
986 		EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
987 
988 /* 	halbtcoutsrc_NormalLowPower(pBtCoexist); */
989 }
990 
EXhalbtcoutsrc_MediaStatusNotify(struct btc_coexist * pBtCoexist,enum rt_media_status mediaStatus)991 void EXhalbtcoutsrc_MediaStatusNotify(struct btc_coexist *pBtCoexist, enum
992 	rt_media_status mediaStatus)
993 {
994 	u8 mStatus;
995 
996 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
997 		return;
998 
999 	pBtCoexist->statistics.cntMediaStatusNotify++;
1000 	if (pBtCoexist->bManualControl)
1001 		return;
1002 
1003 	if (RT_MEDIA_CONNECT == mediaStatus)
1004 		mStatus = BTC_MEDIA_CONNECT;
1005 	else
1006 		mStatus = BTC_MEDIA_DISCONNECT;
1007 
1008 	/*  All notify is called in cmd thread, don't need to leave low power again */
1009 /* 	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1010 
1011 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
1012 		EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
1013 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1014 		EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
1015 
1016 /* 	halbtcoutsrc_NormalLowPower(pBtCoexist); */
1017 }
1018 
EXhalbtcoutsrc_SpecialPacketNotify(struct btc_coexist * pBtCoexist,u8 pktType)1019 void EXhalbtcoutsrc_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 pktType)
1020 {
1021 	u8 packetType;
1022 
1023 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1024 		return;
1025 	pBtCoexist->statistics.cntSpecialPacketNotify++;
1026 	if (pBtCoexist->bManualControl)
1027 		return;
1028 
1029 	if (PACKET_DHCP == pktType) {
1030 		packetType = BTC_PACKET_DHCP;
1031 	} else if (PACKET_EAPOL == pktType) {
1032 		packetType = BTC_PACKET_EAPOL;
1033 	} else if (PACKET_ARP == pktType) {
1034 		packetType = BTC_PACKET_ARP;
1035 	} else {
1036 		return;
1037 	}
1038 
1039 	/*  All notify is called in cmd thread, don't need to leave low power again */
1040 /* 	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1041 
1042 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
1043 		EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
1044 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1045 		EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
1046 
1047 /* 	halbtcoutsrc_NormalLowPower(pBtCoexist); */
1048 }
1049 
EXhalbtcoutsrc_BtInfoNotify(struct btc_coexist * pBtCoexist,u8 * tmpBuf,u8 length)1050 void EXhalbtcoutsrc_BtInfoNotify(struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length)
1051 {
1052 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1053 		return;
1054 
1055 	pBtCoexist->statistics.cntBtInfoNotify++;
1056 
1057 	/*  All notify is called in cmd thread, don't need to leave low power again */
1058 /* 	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1059 
1060 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
1061 		EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1062 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1063 		EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1064 
1065 /* 	halbtcoutsrc_NormalLowPower(pBtCoexist); */
1066 }
1067 
EXhalbtcoutsrc_HaltNotify(struct btc_coexist * pBtCoexist)1068 void EXhalbtcoutsrc_HaltNotify(struct btc_coexist *pBtCoexist)
1069 {
1070 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1071 		return;
1072 
1073 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
1074 		EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
1075 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1076 		EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
1077 
1078 	pBtCoexist->bBinded = false;
1079 }
1080 
EXhalbtcoutsrc_PnpNotify(struct btc_coexist * pBtCoexist,u8 pnpState)1081 void EXhalbtcoutsrc_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState)
1082 {
1083 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1084 		return;
1085 
1086 	/*  */
1087 	/*  currently only 1ant we have to do the notification, */
1088 	/*  once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */
1089 	/*  */
1090 
1091 	if (pBtCoexist->boardInfo.btdmAntNum == 1)
1092 		EXhalbtc8723b1ant_PnpNotify(pBtCoexist, pnpState);
1093 	else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1094 		EXhalbtc8723b2ant_PnpNotify(pBtCoexist, pnpState);
1095 }
1096 
EXhalbtcoutsrc_Periodical(struct btc_coexist * pBtCoexist)1097 void EXhalbtcoutsrc_Periodical(struct btc_coexist *pBtCoexist)
1098 {
1099 	if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1100 		return;
1101 	pBtCoexist->statistics.cntPeriodical++;
1102 
1103 	/*  Periodical should be called in cmd thread, */
1104 	/*  don't need to leave low power again */
1105 /* 	halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1106 
1107 	if (pBtCoexist->boardInfo.btdmAntNum == 2)
1108 		EXhalbtc8723b2ant_Periodical(pBtCoexist);
1109 	else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1110 		EXhalbtc8723b1ant_Periodical(pBtCoexist);
1111 
1112 /* 	halbtcoutsrc_NormalLowPower(pBtCoexist); */
1113 }
1114 
EXhalbtcoutsrc_SetAntNum(u8 type,u8 antNum)1115 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
1116 {
1117 	if (BT_COEX_ANT_TYPE_PG == type) {
1118 		GLBtCoexist.boardInfo.pgAntNum = antNum;
1119 		GLBtCoexist.boardInfo.btdmAntNum = antNum;
1120 	} else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1121 		GLBtCoexist.boardInfo.btdmAntNum = antNum;
1122 		/* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1123 	} else if (BT_COEX_ANT_TYPE_DETECTED == type) {
1124 		GLBtCoexist.boardInfo.btdmAntNum = antNum;
1125 		/* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1126 	}
1127 }
1128 
1129 /*  */
1130 /*  Currently used by 8723b only, S0 or S1 */
1131 /*  */
EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)1132 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
1133 {
1134 	GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
1135 }
1136 
1137 /*
1138  * Description:
1139  *Run BT-Coexist mechanism or not
1140  *
1141  */
hal_btcoex_SetBTCoexist(struct adapter * padapter,u8 bBtExist)1142 void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist)
1143 {
1144 	struct hal_com_data *pHalData;
1145 
1146 
1147 	pHalData = GET_HAL_DATA(padapter);
1148 	pHalData->bt_coexist.bBtExist = bBtExist;
1149 }
1150 
1151 /*
1152  * Dewcription:
1153  *Check is co-exist mechanism enabled or not
1154  *
1155  * Return:
1156  *true	Enable BT co-exist mechanism
1157  *false	Disable BT co-exist mechanism
1158  */
hal_btcoex_IsBtExist(struct adapter * padapter)1159 bool hal_btcoex_IsBtExist(struct adapter *padapter)
1160 {
1161 	struct hal_com_data *pHalData;
1162 
1163 
1164 	pHalData = GET_HAL_DATA(padapter);
1165 	return pHalData->bt_coexist.bBtExist;
1166 }
1167 
hal_btcoex_IsBtDisabled(struct adapter * padapter)1168 bool hal_btcoex_IsBtDisabled(struct adapter *padapter)
1169 {
1170 	if (!hal_btcoex_IsBtExist(padapter))
1171 		return true;
1172 
1173 	if (GLBtCoexist.btInfo.bBtDisabled)
1174 		return true;
1175 	else
1176 		return false;
1177 }
1178 
hal_btcoex_SetPgAntNum(struct adapter * padapter,u8 antNum)1179 void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum)
1180 {
1181 	struct hal_com_data *pHalData;
1182 
1183 
1184 	pHalData = GET_HAL_DATA(padapter);
1185 
1186 	pHalData->bt_coexist.btTotalAntNum = antNum;
1187 	EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1188 }
1189 
hal_btcoex_SetSingleAntPath(struct adapter * padapter,u8 singleAntPath)1190 void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath)
1191 {
1192 	EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
1193 }
1194 
hal_btcoex_PowerOnSetting(struct adapter * padapter)1195 void hal_btcoex_PowerOnSetting(struct adapter *padapter)
1196 {
1197 	EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
1198 }
1199 
hal_btcoex_InitHwConfig(struct adapter * padapter,u8 bWifiOnly)1200 void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly)
1201 {
1202 	if (!hal_btcoex_IsBtExist(padapter))
1203 		return;
1204 
1205 	EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
1206 	EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
1207 }
1208 
hal_btcoex_IpsNotify(struct adapter * padapter,u8 type)1209 void hal_btcoex_IpsNotify(struct adapter *padapter, u8 type)
1210 {
1211 	EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
1212 }
1213 
hal_btcoex_LpsNotify(struct adapter * padapter,u8 type)1214 void hal_btcoex_LpsNotify(struct adapter *padapter, u8 type)
1215 {
1216 	EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
1217 }
1218 
hal_btcoex_ScanNotify(struct adapter * padapter,u8 type)1219 void hal_btcoex_ScanNotify(struct adapter *padapter, u8 type)
1220 {
1221 	EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
1222 }
1223 
hal_btcoex_ConnectNotify(struct adapter * padapter,u8 action)1224 void hal_btcoex_ConnectNotify(struct adapter *padapter, u8 action)
1225 {
1226 	EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
1227 }
1228 
hal_btcoex_MediaStatusNotify(struct adapter * padapter,u8 mediaStatus)1229 void hal_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus)
1230 {
1231 	EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
1232 }
1233 
hal_btcoex_SpecialPacketNotify(struct adapter * padapter,u8 pktType)1234 void hal_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType)
1235 {
1236 	EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
1237 }
1238 
hal_btcoex_IQKNotify(struct adapter * padapter,u8 state)1239 void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state)
1240 {
1241 	GLBtcWiFiInIQKState = state;
1242 }
1243 
hal_btcoex_BtInfoNotify(struct adapter * padapter,u8 length,u8 * tmpBuf)1244 void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf)
1245 {
1246 	if (GLBtcWiFiInIQKState)
1247 		return;
1248 
1249 	EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
1250 }
1251 
hal_btcoex_SuspendNotify(struct adapter * padapter,u8 state)1252 void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state)
1253 {
1254 	if (state == 1)
1255 		state = BTC_WIFI_PNP_SLEEP;
1256 	else
1257 		state = BTC_WIFI_PNP_WAKE_UP;
1258 
1259 	EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
1260 }
1261 
hal_btcoex_HaltNotify(struct adapter * padapter)1262 void hal_btcoex_HaltNotify(struct adapter *padapter)
1263 {
1264 	EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
1265 }
1266 
hal_btcoex_Handler(struct adapter * padapter)1267 void hal_btcoex_Handler(struct adapter *padapter)
1268 {
1269 	EXhalbtcoutsrc_Periodical(&GLBtCoexist);
1270 }
1271 
hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter * padapter)1272 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter)
1273 {
1274 	return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
1275 }
1276 
hal_btcoex_IsBtControlLps(struct adapter * padapter)1277 bool hal_btcoex_IsBtControlLps(struct adapter *padapter)
1278 {
1279 	if (!hal_btcoex_IsBtExist(padapter))
1280 		return false;
1281 
1282 	if (GLBtCoexist.btInfo.bBtDisabled)
1283 		return false;
1284 
1285 	if (GLBtCoexist.btInfo.bBtCtrlLps)
1286 		return true;
1287 
1288 	return false;
1289 }
1290 
hal_btcoex_IsLpsOn(struct adapter * padapter)1291 bool hal_btcoex_IsLpsOn(struct adapter *padapter)
1292 {
1293 	if (!hal_btcoex_IsBtExist(padapter))
1294 		return false;
1295 
1296 	if (GLBtCoexist.btInfo.bBtDisabled)
1297 		return false;
1298 
1299 	if (GLBtCoexist.btInfo.bBtLpsOn)
1300 		return true;
1301 
1302 	return false;
1303 }
1304 
hal_btcoex_RpwmVal(struct adapter * padapter)1305 u8 hal_btcoex_RpwmVal(struct adapter *padapter)
1306 {
1307 	return GLBtCoexist.btInfo.rpwmVal;
1308 }
1309 
hal_btcoex_LpsVal(struct adapter * padapter)1310 u8 hal_btcoex_LpsVal(struct adapter *padapter)
1311 {
1312 	return GLBtCoexist.btInfo.lpsVal;
1313 }
1314 
hal_btcoex_GetRaMask(struct adapter * padapter)1315 u32 hal_btcoex_GetRaMask(struct adapter *padapter)
1316 {
1317 	if (!hal_btcoex_IsBtExist(padapter))
1318 		return 0;
1319 
1320 	if (GLBtCoexist.btInfo.bBtDisabled)
1321 		return 0;
1322 
1323 	if (GLBtCoexist.boardInfo.btdmAntNum != 1)
1324 		return 0;
1325 
1326 	return GLBtCoexist.btInfo.raMask;
1327 }
1328 
hal_btcoex_RecordPwrMode(struct adapter * padapter,u8 * pCmdBuf,u8 cmdLen)1329 void hal_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen)
1330 {
1331 	memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
1332 }
1333