1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2013 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
10 #include <hal_btcoex.h>
11 #include <Mp_Precomp.h>
13 /* Global variables */
15 struct btc_coexist GLBtCoexist;
16 static u8 GLBtcWiFiInScanState;
17 static u8 GLBtcWiFiInIQKState;
20 /* Debug related function */
22 static u8 halbtcoutsrc_IsBtCoexistAvailable(struct btc_coexist *pBtCoexist)
24 if (!pBtCoexist->bBinded || !pBtCoexist->Adapter)
30 static void halbtcoutsrc_LeaveLps(struct btc_coexist *pBtCoexist)
32 struct adapter *padapter;
35 padapter = pBtCoexist->Adapter;
37 pBtCoexist->btInfo.bBtCtrlLps = true;
38 pBtCoexist->btInfo.bBtLpsOn = false;
40 rtw_btcoex_LPS_Leave(padapter);
43 static void halbtcoutsrc_EnterLps(struct btc_coexist *pBtCoexist)
45 struct adapter *padapter;
48 padapter = pBtCoexist->Adapter;
50 pBtCoexist->btInfo.bBtCtrlLps = true;
51 pBtCoexist->btInfo.bBtLpsOn = true;
53 rtw_btcoex_LPS_Enter(padapter);
56 static void halbtcoutsrc_NormalLps(struct btc_coexist *pBtCoexist)
58 struct adapter *padapter;
60 padapter = pBtCoexist->Adapter;
62 if (pBtCoexist->btInfo.bBtCtrlLps) {
63 pBtCoexist->btInfo.bBtLpsOn = false;
64 rtw_btcoex_LPS_Leave(padapter);
65 pBtCoexist->btInfo.bBtCtrlLps = false;
67 /* recover the LPS state to the original */
73 * 1. this function will request pwrctrl->lock
75 static void halbtcoutsrc_LeaveLowPower(struct btc_coexist *pBtCoexist)
77 struct adapter *padapter;
81 u32 timeout; /* unit: ms */
84 padapter = pBtCoexist->Adapter;
86 #ifdef LPS_RPWM_WAIT_MS
87 timeout = LPS_RPWM_WAIT_MS;
88 #else /* !LPS_RPWM_WAIT_MS */
90 #endif /* !LPS_RPWM_WAIT_MS */
94 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
95 if (_SUCCESS == ready)
98 utime = jiffies_to_msecs(jiffies - stime);
108 * 1. this function will request pwrctrl->lock
110 static void halbtcoutsrc_NormalLowPower(struct btc_coexist *pBtCoexist)
112 struct adapter *padapter;
115 padapter = pBtCoexist->Adapter;
116 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
119 static void halbtcoutsrc_DisableLowPower(struct btc_coexist *pBtCoexist, u8 bLowPwrDisable)
121 pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
123 halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */
125 halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */
128 static void halbtcoutsrc_AggregationCheck(struct btc_coexist *pBtCoexist)
130 struct adapter *padapter;
134 padapter = pBtCoexist->Adapter;
137 if (pBtCoexist->btInfo.bRejectAggPkt) {
138 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
140 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
141 pBtCoexist->btInfo.bBtCtrlAggBufSize) {
143 pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
146 if (pBtCoexist->btInfo.bBtCtrlAggBufSize) {
147 if (pBtCoexist->btInfo.preAggBufSize !=
148 pBtCoexist->btInfo.aggBufSize){
151 pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
155 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
156 rtw_btcoex_RejectApAggregatedPacket(padapter, false);
161 static u8 halbtcoutsrc_IsWifiBusy(struct adapter *padapter)
163 struct mlme_priv *pmlmepriv;
166 pmlmepriv = &padapter->mlmepriv;
168 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
169 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
171 if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
178 static u32 _halbtcoutsrc_GetWifiLinkStatus(struct adapter *padapter)
180 struct mlme_priv *pmlmepriv;
182 u32 portConnectedStatus;
185 pmlmepriv = &padapter->mlmepriv;
187 portConnectedStatus = 0;
189 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
190 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
192 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
194 portConnectedStatus |= WIFI_AP_CONNECTED;
197 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
199 portConnectedStatus |= WIFI_STA_CONNECTED;
203 return portConnectedStatus;
206 static u32 halbtcoutsrc_GetWifiLinkStatus(struct btc_coexist *pBtCoexist)
210 /* [31:16]=> connected port number */
211 /* [15:0]=> port connected bit define */
214 struct adapter *padapter;
216 u32 portConnectedStatus, numOfConnectedPort;
219 padapter = pBtCoexist->Adapter;
220 portConnectedStatus = 0;
221 numOfConnectedPort = 0;
223 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
225 portConnectedStatus |= retVal;
226 numOfConnectedPort++;
229 retVal = (numOfConnectedPort << 16) | portConnectedStatus;
234 static u32 halbtcoutsrc_GetBtPatchVer(struct btc_coexist *pBtCoexist)
236 return pBtCoexist->btInfo.btRealFwVer;
239 static s32 halbtcoutsrc_GetWifiRssi(struct adapter *padapter)
241 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
243 return pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
246 static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter)
248 struct mlme_ext_priv *pmlmeext;
249 static u8 scan_AP_num;
251 pmlmeext = &padapter->mlmeextpriv;
253 if (!GLBtcWiFiInScanState) {
254 if (pmlmeext->sitesurvey_res.bss_cnt > 0xFF)
257 scan_AP_num = (u8)pmlmeext->sitesurvey_res.bss_cnt;
263 static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
265 struct btc_coexist *pBtCoexist;
266 struct adapter *padapter;
267 struct hal_com_data *pHalData;
268 struct mlme_ext_priv *mlmeext;
275 pBtCoexist = (struct btc_coexist *)pBtcContext;
276 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
279 padapter = pBtCoexist->Adapter;
280 pHalData = GET_HAL_DATA(padapter);
281 mlmeext = &padapter->mlmeextpriv;
288 case BTC_GET_BL_HS_OPERATION:
293 case BTC_GET_BL_HS_CONNECTING:
298 case BTC_GET_BL_WIFI_CONNECTED:
299 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
302 case BTC_GET_BL_WIFI_BUSY:
303 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
306 case BTC_GET_BL_WIFI_SCAN:
307 /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
308 WIFI_SITE_MONITOR in fwstate may not be cleared in time */
309 *pu8 = GLBtcWiFiInScanState;
312 case BTC_GET_BL_WIFI_LINK:
313 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
316 case BTC_GET_BL_WIFI_ROAM:
317 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
320 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
324 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
325 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
328 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
329 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm != 0;
332 case BTC_GET_BL_WIFI_UNDER_B_MODE:
333 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
339 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
343 case BTC_GET_BL_EXT_SWITCH:
347 case BTC_GET_S4_WIFI_RSSI:
348 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
351 case BTC_GET_S4_HS_RSSI:
356 case BTC_GET_U4_WIFI_BW:
357 if (is_legacy_only(mlmeext->cur_wireless_mode))
358 *pU4Tmp = BTC_WIFI_BW_LEGACY;
359 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
360 *pU4Tmp = BTC_WIFI_BW_HT20;
362 *pU4Tmp = BTC_WIFI_BW_HT40;
365 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
367 struct rt_link_detect_t *plinkinfo;
368 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
370 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
371 *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
373 *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
377 case BTC_GET_U4_WIFI_FW_VER:
378 *pU4Tmp = pHalData->FirmwareVersion << 16;
379 *pU4Tmp |= pHalData->FirmwareSubVersion;
382 case BTC_GET_U4_WIFI_LINK_STATUS:
383 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
386 case BTC_GET_U4_BT_PATCH_VER:
387 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
390 case BTC_GET_U1_WIFI_DOT11_CHNL:
391 *pu8 = padapter->mlmeextpriv.cur_channel;
394 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
395 *pu8 = pHalData->CurrentChannel;
398 case BTC_GET_U1_WIFI_HS_CHNL:
403 case BTC_GET_U1_MAC_PHY_MODE:
405 /* *pU1Tmp = BTC_DMSP; */
406 /* *pU1Tmp = BTC_DMDP; */
407 /* *pU1Tmp = BTC_MP_UNKNOWN; */
410 case BTC_GET_U1_AP_NUM:
411 *pu8 = halbtcoutsrc_GetWifiScanAPNum(padapter);
414 /* 1Ant =========== */
415 case BTC_GET_U1_LPS_MODE:
416 *pu8 = padapter->dvobj->pwrctl_priv.pwr_mode;
427 static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
429 struct btc_coexist *pBtCoexist;
430 struct adapter *padapter;
436 pBtCoexist = (struct btc_coexist *)pBtcContext;
437 padapter = pBtCoexist->Adapter;
442 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
446 /* set some u8 type variables. */
447 case BTC_SET_BL_BT_DISABLE:
448 pBtCoexist->btInfo.bBtDisabled = *pu8;
451 case BTC_SET_BL_BT_TRAFFIC_BUSY:
452 pBtCoexist->btInfo.bBtBusy = *pu8;
455 case BTC_SET_BL_BT_LIMITED_DIG:
456 pBtCoexist->btInfo.bLimitedDig = *pu8;
459 case BTC_SET_BL_FORCE_TO_ROAM:
460 pBtCoexist->btInfo.bForceToRoam = *pu8;
463 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
464 pBtCoexist->btInfo.bRejectAggPkt = *pu8;
467 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
468 pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
471 case BTC_SET_BL_INC_SCAN_DEV_NUM:
472 pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
475 case BTC_SET_BL_BT_TX_RX_MASK:
476 pBtCoexist->btInfo.bBtTxRxMask = *pu8;
479 /* set some u8 type variables. */
480 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
481 pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pu8;
484 case BTC_SET_U1_AGG_BUF_SIZE:
485 pBtCoexist->btInfo.aggBufSize = *pu8;
488 /* the following are some action which will be triggered */
489 case BTC_SET_ACT_GET_BT_RSSI:
493 case BTC_SET_ACT_AGGREGATE_CTRL:
494 halbtcoutsrc_AggregationCheck(pBtCoexist);
497 /* 1Ant =========== */
498 /* set some u8 type variables. */
499 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
500 pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pu8;
503 case BTC_SET_U1_LPS_VAL:
504 pBtCoexist->btInfo.lpsVal = *pu8;
507 case BTC_SET_U1_RPWM_VAL:
508 pBtCoexist->btInfo.rpwmVal = *pu8;
511 /* the following are some action which will be triggered */
512 case BTC_SET_ACT_LEAVE_LPS:
513 halbtcoutsrc_LeaveLps(pBtCoexist);
516 case BTC_SET_ACT_ENTER_LPS:
517 halbtcoutsrc_EnterLps(pBtCoexist);
520 case BTC_SET_ACT_NORMAL_LPS:
521 halbtcoutsrc_NormalLps(pBtCoexist);
524 case BTC_SET_ACT_DISABLE_LOW_POWER:
525 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
528 case BTC_SET_ACT_UPDATE_RAMASK:
529 pBtCoexist->btInfo.raMask = *pU4Tmp;
531 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true) {
532 struct sta_info *psta;
533 struct wlan_bssid_ex *cur_network;
535 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
536 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->mac_address);
537 rtw_hal_update_ra_mask(psta, 0);
541 case BTC_SET_ACT_SEND_MIMO_PS:
545 case BTC_SET_ACT_CTRL_BT_INFO:
549 case BTC_SET_ACT_CTRL_BT_COEX:
552 case BTC_SET_ACT_CTRL_8723B_ANT:
565 /* IO related function */
567 static u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
569 struct btc_coexist *pBtCoexist;
570 struct adapter *padapter;
573 pBtCoexist = (struct btc_coexist *)pBtcContext;
574 padapter = pBtCoexist->Adapter;
576 return rtw_read8(padapter, RegAddr);
579 static u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
581 struct btc_coexist *pBtCoexist;
582 struct adapter *padapter;
585 pBtCoexist = (struct btc_coexist *)pBtcContext;
586 padapter = pBtCoexist->Adapter;
588 return rtw_read16(padapter, RegAddr);
591 static u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
593 struct btc_coexist *pBtCoexist;
594 struct adapter *padapter;
597 pBtCoexist = (struct btc_coexist *)pBtcContext;
598 padapter = pBtCoexist->Adapter;
600 return rtw_read32(padapter, RegAddr);
603 static void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
605 struct btc_coexist *pBtCoexist;
606 struct adapter *padapter;
609 pBtCoexist = (struct btc_coexist *)pBtcContext;
610 padapter = pBtCoexist->Adapter;
612 rtw_write8(padapter, RegAddr, Data);
615 static void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
617 struct btc_coexist *pBtCoexist;
618 struct adapter *padapter;
619 u8 originalValue, bitShift;
623 pBtCoexist = (struct btc_coexist *)pBtcContext;
624 padapter = pBtCoexist->Adapter;
628 if (bitMask != 0xFF) {
629 originalValue = rtw_read8(padapter, regAddr);
631 for (i = 0; i <= 7; i++) {
632 if ((bitMask >> i) & 0x1)
637 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
640 rtw_write8(padapter, regAddr, data1b);
643 static void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
645 struct btc_coexist *pBtCoexist;
646 struct adapter *padapter;
649 pBtCoexist = (struct btc_coexist *)pBtcContext;
650 padapter = pBtCoexist->Adapter;
652 rtw_write16(padapter, RegAddr, Data);
655 static void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
657 struct btc_coexist *pBtCoexist;
658 struct adapter *padapter;
661 pBtCoexist = (struct btc_coexist *)pBtcContext;
662 padapter = pBtCoexist->Adapter;
664 rtw_write32(padapter, RegAddr, Data);
667 static void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
669 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
670 struct adapter *Adapter = pBtCoexist->Adapter;
672 if (BTC_INTF_SDIO == pBtCoexist->chipInterface)
673 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
675 rtw_write8(Adapter, RegAddr, Data);
678 static void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
680 struct btc_coexist *pBtCoexist;
681 struct adapter *padapter;
684 pBtCoexist = (struct btc_coexist *)pBtcContext;
685 padapter = pBtCoexist->Adapter;
687 PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
691 static u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
693 struct btc_coexist *pBtCoexist;
694 struct adapter *padapter;
697 pBtCoexist = (struct btc_coexist *)pBtcContext;
698 padapter = pBtCoexist->Adapter;
700 return PHY_QueryBBReg(padapter, RegAddr, BitMask);
703 static void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
705 struct btc_coexist *pBtCoexist;
706 struct adapter *padapter;
709 pBtCoexist = (struct btc_coexist *)pBtcContext;
710 padapter = pBtCoexist->Adapter;
712 PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
715 static u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
717 struct btc_coexist *pBtCoexist;
718 struct adapter *padapter;
721 pBtCoexist = (struct btc_coexist *)pBtcContext;
722 padapter = pBtCoexist->Adapter;
724 return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
727 static void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
729 struct btc_coexist *pBtCoexist;
730 struct adapter *padapter;
731 u8 CmdBuffer1[4] = {0};
732 u8 CmdBuffer2[4] = {0};
733 u8 *AddrToSet = (u8 *)&RegAddr;
734 u8 *ValueToSet = (u8 *)&Data;
738 pBtCoexist = (struct btc_coexist *)pBtcContext;
739 padapter = pBtCoexist->Adapter;
741 CmdBuffer1[0] |= (OperVer & 0x0f); /* Set OperVer */
742 CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
743 CmdBuffer1[1] = 0x0d; /* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */
744 CmdBuffer1[2] = ValueToSet[0]; /* Set WriteRegValue */
745 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0]));
750 CmdBuffer2[0] |= (OperVer & 0x0f); /* Set OperVer */
751 CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
752 CmdBuffer2[1] = 0x0c; /* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */
753 CmdBuffer2[3] = AddrToSet[0]; /* Set WriteRegAddr */
754 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0]));
757 static u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
759 /* To be implemented. Always return 0 temporarily */
763 static void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
765 struct btc_coexist *pBtCoexist;
766 struct adapter *padapter;
769 pBtCoexist = (struct btc_coexist *)pBtcContext;
770 padapter = pBtCoexist->Adapter;
772 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
776 /* Extern functions called by other module */
778 static u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
780 struct btc_coexist *pBtCoexist = &GLBtCoexist;
782 if (pBtCoexist->bBinded)
785 pBtCoexist->bBinded = true;
787 pBtCoexist->statistics.cntBind++;
789 pBtCoexist->Adapter = padapter;
791 pBtCoexist->stackInfo.bProfileNotified = false;
793 pBtCoexist->btInfo.bBtCtrlAggBufSize = false;
794 pBtCoexist->btInfo.aggBufSize = 5;
796 pBtCoexist->btInfo.bIncreaseScanDevNum = false;
798 /* set default antenna position to main port */
799 pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
804 void hal_btcoex_Initialize(void *padapter)
806 struct btc_coexist *pBtCoexist;
808 memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
810 pBtCoexist = &GLBtCoexist;
812 /* pBtCoexist->statistics.cntBind++; */
814 pBtCoexist->chipInterface = BTC_INTF_SDIO;
816 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
818 pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
819 pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
820 pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
821 pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
822 pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
823 pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
824 pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
825 pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
827 pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
828 pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
830 pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
831 pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
833 pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
835 pBtCoexist->fBtcGet = halbtcoutsrc_Get;
836 pBtCoexist->fBtcSet = halbtcoutsrc_Set;
837 pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
838 pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
840 pBtCoexist->boardInfo.singleAntPath = 0;
842 GLBtcWiFiInScanState = false;
844 GLBtcWiFiInIQKState = false;
847 void EXhalbtcoutsrc_PowerOnSetting(struct btc_coexist *pBtCoexist)
849 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
852 /* Power on setting function is only added in 8723B currently */
853 if (pBtCoexist->boardInfo.btdmAntNum == 2)
854 EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
855 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
856 EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
859 void EXhalbtcoutsrc_InitHwConfig(struct btc_coexist *pBtCoexist, u8 bWifiOnly)
861 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
864 pBtCoexist->statistics.cntInitHwConfig++;
866 if (pBtCoexist->boardInfo.btdmAntNum == 2)
867 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
868 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
869 EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
872 void EXhalbtcoutsrc_InitCoexDm(struct btc_coexist *pBtCoexist)
874 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
877 pBtCoexist->statistics.cntInitCoexDm++;
879 if (pBtCoexist->boardInfo.btdmAntNum == 2)
880 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
881 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
882 EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
884 pBtCoexist->bInitilized = true;
887 void EXhalbtcoutsrc_IpsNotify(struct btc_coexist *pBtCoexist, u8 type)
891 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
894 pBtCoexist->statistics.cntIpsNotify++;
895 if (pBtCoexist->bManualControl)
898 if (IPS_NONE == type)
899 ipsType = BTC_IPS_LEAVE;
901 ipsType = BTC_IPS_ENTER;
903 /* All notify is called in cmd thread, don't need to leave low power again */
904 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
906 if (pBtCoexist->boardInfo.btdmAntNum == 2)
907 EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
908 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
909 EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
911 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
914 void EXhalbtcoutsrc_LpsNotify(struct btc_coexist *pBtCoexist, u8 type)
919 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
922 pBtCoexist->statistics.cntLpsNotify++;
923 if (pBtCoexist->bManualControl)
926 if (PS_MODE_ACTIVE == type)
927 lpsType = BTC_LPS_DISABLE;
929 lpsType = BTC_LPS_ENABLE;
931 if (pBtCoexist->boardInfo.btdmAntNum == 2)
932 EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
933 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
934 EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
937 void EXhalbtcoutsrc_ScanNotify(struct btc_coexist *pBtCoexist, u8 type)
941 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
943 pBtCoexist->statistics.cntScanNotify++;
944 if (pBtCoexist->bManualControl)
948 scanType = BTC_SCAN_START;
949 GLBtcWiFiInScanState = true;
951 scanType = BTC_SCAN_FINISH;
952 GLBtcWiFiInScanState = false;
955 /* All notify is called in cmd thread, don't need to leave low power again */
956 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
958 if (pBtCoexist->boardInfo.btdmAntNum == 2)
959 EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
960 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
961 EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
963 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
966 void EXhalbtcoutsrc_ConnectNotify(struct btc_coexist *pBtCoexist, u8 action)
970 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
972 pBtCoexist->statistics.cntConnectNotify++;
973 if (pBtCoexist->bManualControl)
977 assoType = BTC_ASSOCIATE_START;
979 assoType = BTC_ASSOCIATE_FINISH;
981 /* All notify is called in cmd thread, don't need to leave low power again */
982 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
984 if (pBtCoexist->boardInfo.btdmAntNum == 2)
985 EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
986 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
987 EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
989 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
992 void EXhalbtcoutsrc_MediaStatusNotify(struct btc_coexist *pBtCoexist, enum
993 rt_media_status mediaStatus)
997 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1000 pBtCoexist->statistics.cntMediaStatusNotify++;
1001 if (pBtCoexist->bManualControl)
1004 if (RT_MEDIA_CONNECT == mediaStatus)
1005 mStatus = BTC_MEDIA_CONNECT;
1007 mStatus = BTC_MEDIA_DISCONNECT;
1009 /* All notify is called in cmd thread, don't need to leave low power again */
1010 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1012 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1013 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
1014 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1015 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
1017 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1020 void EXhalbtcoutsrc_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 pktType)
1024 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1026 pBtCoexist->statistics.cntSpecialPacketNotify++;
1027 if (pBtCoexist->bManualControl)
1030 if (PACKET_DHCP == pktType) {
1031 packetType = BTC_PACKET_DHCP;
1032 } else if (PACKET_EAPOL == pktType) {
1033 packetType = BTC_PACKET_EAPOL;
1034 } else if (PACKET_ARP == pktType) {
1035 packetType = BTC_PACKET_ARP;
1040 /* All notify is called in cmd thread, don't need to leave low power again */
1041 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1043 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1044 EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
1045 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1046 EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
1048 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1051 void EXhalbtcoutsrc_BtInfoNotify(struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length)
1053 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1056 pBtCoexist->statistics.cntBtInfoNotify++;
1058 /* All notify is called in cmd thread, don't need to leave low power again */
1059 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1061 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1062 EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1063 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1064 EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1066 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1069 void EXhalbtcoutsrc_HaltNotify(struct btc_coexist *pBtCoexist)
1071 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1074 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1075 EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
1076 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1077 EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
1079 pBtCoexist->bBinded = false;
1082 void EXhalbtcoutsrc_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState)
1084 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1088 /* currently only 1ant we have to do the notification, */
1089 /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */
1092 if (pBtCoexist->boardInfo.btdmAntNum == 1)
1093 EXhalbtc8723b1ant_PnpNotify(pBtCoexist, pnpState);
1094 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1095 EXhalbtc8723b2ant_PnpNotify(pBtCoexist, pnpState);
1098 void EXhalbtcoutsrc_Periodical(struct btc_coexist *pBtCoexist)
1100 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1102 pBtCoexist->statistics.cntPeriodical++;
1104 /* Periodical should be called in cmd thread, */
1105 /* don't need to leave low power again */
1106 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1108 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1109 EXhalbtc8723b2ant_Periodical(pBtCoexist);
1110 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1111 EXhalbtc8723b1ant_Periodical(pBtCoexist);
1113 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1116 void EXhalbtcoutsrc_SetChipType(u8 chipType)
1118 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
1121 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
1123 if (BT_COEX_ANT_TYPE_PG == type) {
1124 GLBtCoexist.boardInfo.pgAntNum = antNum;
1125 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1126 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1127 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1128 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1129 } else if (BT_COEX_ANT_TYPE_DETECTED == type) {
1130 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1131 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1136 /* Currently used by 8723b only, S0 or S1 */
1138 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
1140 GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
1145 *Run BT-Coexist mechanism or not
1148 void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist)
1150 struct hal_com_data *pHalData;
1153 pHalData = GET_HAL_DATA(padapter);
1154 pHalData->bt_coexist.bBtExist = bBtExist;
1159 *Check is co-exist mechanism enabled or not
1162 *true Enable BT co-exist mechanism
1163 *false Disable BT co-exist mechanism
1165 bool hal_btcoex_IsBtExist(struct adapter *padapter)
1167 struct hal_com_data *pHalData;
1170 pHalData = GET_HAL_DATA(padapter);
1171 return pHalData->bt_coexist.bBtExist;
1174 bool hal_btcoex_IsBtDisabled(struct adapter *padapter)
1176 if (!hal_btcoex_IsBtExist(padapter))
1179 if (GLBtCoexist.btInfo.bBtDisabled)
1185 void hal_btcoex_SetChipType(struct adapter *padapter, u8 chipType)
1187 struct hal_com_data *pHalData;
1190 pHalData = GET_HAL_DATA(padapter);
1191 pHalData->bt_coexist.btChipType = chipType;
1193 EXhalbtcoutsrc_SetChipType(chipType);
1196 void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum)
1198 struct hal_com_data *pHalData;
1201 pHalData = GET_HAL_DATA(padapter);
1203 pHalData->bt_coexist.btTotalAntNum = antNum;
1204 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1207 void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath)
1209 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
1212 void hal_btcoex_PowerOnSetting(struct adapter *padapter)
1214 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
1217 void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly)
1219 if (!hal_btcoex_IsBtExist(padapter))
1222 EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
1223 EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
1226 void hal_btcoex_IpsNotify(struct adapter *padapter, u8 type)
1228 EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
1231 void hal_btcoex_LpsNotify(struct adapter *padapter, u8 type)
1233 EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
1236 void hal_btcoex_ScanNotify(struct adapter *padapter, u8 type)
1238 EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
1241 void hal_btcoex_ConnectNotify(struct adapter *padapter, u8 action)
1243 EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
1246 void hal_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus)
1248 EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
1251 void hal_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType)
1253 EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
1256 void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state)
1258 GLBtcWiFiInIQKState = state;
1261 void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf)
1263 if (GLBtcWiFiInIQKState)
1266 EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
1269 void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state)
1272 state = BTC_WIFI_PNP_SLEEP;
1274 state = BTC_WIFI_PNP_WAKE_UP;
1276 EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
1279 void hal_btcoex_HaltNotify(struct adapter *padapter)
1281 EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
1284 void hal_btcoex_Handler(struct adapter *padapter)
1286 EXhalbtcoutsrc_Periodical(&GLBtCoexist);
1289 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter)
1291 return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
1294 void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual)
1296 GLBtCoexist.bManualControl = bmanual;
1299 bool hal_btcoex_IsBtControlLps(struct adapter *padapter)
1301 if (!hal_btcoex_IsBtExist(padapter))
1304 if (GLBtCoexist.btInfo.bBtDisabled)
1307 if (GLBtCoexist.btInfo.bBtCtrlLps)
1313 bool hal_btcoex_IsLpsOn(struct adapter *padapter)
1315 if (!hal_btcoex_IsBtExist(padapter))
1318 if (GLBtCoexist.btInfo.bBtDisabled)
1321 if (GLBtCoexist.btInfo.bBtLpsOn)
1327 u8 hal_btcoex_RpwmVal(struct adapter *padapter)
1329 return GLBtCoexist.btInfo.rpwmVal;
1332 u8 hal_btcoex_LpsVal(struct adapter *padapter)
1334 return GLBtCoexist.btInfo.lpsVal;
1337 u32 hal_btcoex_GetRaMask(struct adapter *padapter)
1339 if (!hal_btcoex_IsBtExist(padapter))
1342 if (GLBtCoexist.btInfo.bBtDisabled)
1345 if (GLBtCoexist.boardInfo.btdmAntNum != 1)
1348 return GLBtCoexist.btInfo.raMask;
1351 void hal_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen)
1353 memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);