1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2013 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
7 #define __HAL_BTCOEX_C__
10 #include <rtw_debug.h>
11 #include <hal_btcoex.h>
12 #include <Mp_Precomp.h>
14 /* Global variables */
16 struct btc_coexist GLBtCoexist;
17 static u8 GLBtcWiFiInScanState;
18 static u8 GLBtcWiFiInIQKState;
20 #define BT_Operation(Adapter) false
23 /* Debug related function */
25 static u8 halbtcoutsrc_IsBtCoexistAvailable(struct btc_coexist *pBtCoexist)
27 if (!pBtCoexist->bBinded || !pBtCoexist->Adapter)
33 static void halbtcoutsrc_LeaveLps(struct btc_coexist *pBtCoexist)
35 struct adapter *padapter;
38 padapter = pBtCoexist->Adapter;
40 pBtCoexist->btInfo.bBtCtrlLps = true;
41 pBtCoexist->btInfo.bBtLpsOn = false;
43 rtw_btcoex_LPS_Leave(padapter);
46 static void halbtcoutsrc_EnterLps(struct btc_coexist *pBtCoexist)
48 struct adapter *padapter;
51 padapter = pBtCoexist->Adapter;
53 pBtCoexist->btInfo.bBtCtrlLps = true;
54 pBtCoexist->btInfo.bBtLpsOn = true;
56 rtw_btcoex_LPS_Enter(padapter);
59 static void halbtcoutsrc_NormalLps(struct btc_coexist *pBtCoexist)
61 struct adapter *padapter;
63 padapter = pBtCoexist->Adapter;
65 if (pBtCoexist->btInfo.bBtCtrlLps) {
66 pBtCoexist->btInfo.bBtLpsOn = false;
67 rtw_btcoex_LPS_Leave(padapter);
68 pBtCoexist->btInfo.bBtCtrlLps = false;
70 /* recover the LPS state to the original */
76 * 1. this function will request pwrctrl->lock
78 static void halbtcoutsrc_LeaveLowPower(struct btc_coexist *pBtCoexist)
80 struct adapter *padapter;
84 u32 timeout; /* unit: ms */
87 padapter = pBtCoexist->Adapter;
89 #ifdef LPS_RPWM_WAIT_MS
90 timeout = LPS_RPWM_WAIT_MS;
91 #else /* !LPS_RPWM_WAIT_MS */
93 #endif /* !LPS_RPWM_WAIT_MS */
97 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
98 if (_SUCCESS == ready)
101 utime = jiffies_to_msecs(jiffies - stime);
111 * 1. this function will request pwrctrl->lock
113 static void halbtcoutsrc_NormalLowPower(struct btc_coexist *pBtCoexist)
115 struct adapter *padapter;
118 padapter = pBtCoexist->Adapter;
119 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
122 static void halbtcoutsrc_DisableLowPower(struct btc_coexist *pBtCoexist, u8 bLowPwrDisable)
124 pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
126 halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */
128 halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */
131 static void halbtcoutsrc_AggregationCheck(struct btc_coexist *pBtCoexist)
133 struct adapter *padapter;
137 padapter = pBtCoexist->Adapter;
140 if (pBtCoexist->btInfo.bRejectAggPkt) {
141 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
143 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
144 pBtCoexist->btInfo.bBtCtrlAggBufSize) {
146 pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
149 if (pBtCoexist->btInfo.bBtCtrlAggBufSize) {
150 if (pBtCoexist->btInfo.preAggBufSize !=
151 pBtCoexist->btInfo.aggBufSize){
154 pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
158 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
159 rtw_btcoex_RejectApAggregatedPacket(padapter, false);
164 static u8 halbtcoutsrc_IsWifiBusy(struct adapter *padapter)
166 struct mlme_priv *pmlmepriv;
169 pmlmepriv = &padapter->mlmepriv;
171 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
172 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
174 if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
181 static u32 _halbtcoutsrc_GetWifiLinkStatus(struct adapter *padapter)
183 struct mlme_priv *pmlmepriv;
185 u32 portConnectedStatus;
188 pmlmepriv = &padapter->mlmepriv;
190 portConnectedStatus = 0;
192 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
193 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
195 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
197 portConnectedStatus |= WIFI_AP_CONNECTED;
200 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
202 portConnectedStatus |= WIFI_STA_CONNECTED;
206 return portConnectedStatus;
209 static u32 halbtcoutsrc_GetWifiLinkStatus(struct btc_coexist *pBtCoexist)
213 /* [31:16]=> connected port number */
214 /* [15:0]=> port connected bit define */
217 struct adapter *padapter;
219 u32 portConnectedStatus, numOfConnectedPort;
222 padapter = pBtCoexist->Adapter;
223 portConnectedStatus = 0;
224 numOfConnectedPort = 0;
226 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
228 portConnectedStatus |= retVal;
229 numOfConnectedPort++;
232 retVal = (numOfConnectedPort << 16) | portConnectedStatus;
237 static u32 halbtcoutsrc_GetBtPatchVer(struct btc_coexist *pBtCoexist)
239 return pBtCoexist->btInfo.btRealFwVer;
242 static s32 halbtcoutsrc_GetWifiRssi(struct adapter *padapter)
244 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
246 return pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
249 static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter)
251 struct mlme_ext_priv *pmlmeext;
252 static u8 scan_AP_num;
254 pmlmeext = &padapter->mlmeextpriv;
256 if (!GLBtcWiFiInScanState) {
257 if (pmlmeext->sitesurvey_res.bss_cnt > 0xFF)
260 scan_AP_num = (u8)pmlmeext->sitesurvey_res.bss_cnt;
266 static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
268 struct btc_coexist *pBtCoexist;
269 struct adapter *padapter;
270 struct hal_com_data *pHalData;
271 struct mlme_ext_priv *mlmeext;
278 pBtCoexist = (struct btc_coexist *)pBtcContext;
279 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
282 padapter = pBtCoexist->Adapter;
283 pHalData = GET_HAL_DATA(padapter);
284 mlmeext = &padapter->mlmeextpriv;
291 case BTC_GET_BL_HS_OPERATION:
296 case BTC_GET_BL_HS_CONNECTING:
301 case BTC_GET_BL_WIFI_CONNECTED:
302 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
305 case BTC_GET_BL_WIFI_BUSY:
306 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
309 case BTC_GET_BL_WIFI_SCAN:
310 /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
311 WIFI_SITE_MONITOR in fwstate may not be cleared in time */
312 *pu8 = GLBtcWiFiInScanState;
315 case BTC_GET_BL_WIFI_LINK:
316 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
319 case BTC_GET_BL_WIFI_ROAM:
320 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
323 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
327 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
328 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
331 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
332 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm != 0;
335 case BTC_GET_BL_WIFI_UNDER_B_MODE:
336 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
342 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
346 case BTC_GET_BL_EXT_SWITCH:
350 case BTC_GET_S4_WIFI_RSSI:
351 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
354 case BTC_GET_S4_HS_RSSI:
359 case BTC_GET_U4_WIFI_BW:
360 if (is_legacy_only(mlmeext->cur_wireless_mode))
361 *pU4Tmp = BTC_WIFI_BW_LEGACY;
362 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
363 *pU4Tmp = BTC_WIFI_BW_HT20;
365 *pU4Tmp = BTC_WIFI_BW_HT40;
368 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
370 struct rt_link_detect_t *plinkinfo;
371 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
373 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
374 *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
376 *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
380 case BTC_GET_U4_WIFI_FW_VER:
381 *pU4Tmp = pHalData->FirmwareVersion << 16;
382 *pU4Tmp |= pHalData->FirmwareSubVersion;
385 case BTC_GET_U4_WIFI_LINK_STATUS:
386 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
389 case BTC_GET_U4_BT_PATCH_VER:
390 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
393 case BTC_GET_U1_WIFI_DOT11_CHNL:
394 *pu8 = padapter->mlmeextpriv.cur_channel;
397 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
398 *pu8 = pHalData->CurrentChannel;
401 case BTC_GET_U1_WIFI_HS_CHNL:
406 case BTC_GET_U1_MAC_PHY_MODE:
408 /* *pU1Tmp = BTC_DMSP; */
409 /* *pU1Tmp = BTC_DMDP; */
410 /* *pU1Tmp = BTC_MP_UNKNOWN; */
413 case BTC_GET_U1_AP_NUM:
414 *pu8 = halbtcoutsrc_GetWifiScanAPNum(padapter);
417 /* 1Ant =========== */
418 case BTC_GET_U1_LPS_MODE:
419 *pu8 = padapter->dvobj->pwrctl_priv.pwr_mode;
430 static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
432 struct btc_coexist *pBtCoexist;
433 struct adapter *padapter;
439 pBtCoexist = (struct btc_coexist *)pBtcContext;
440 padapter = pBtCoexist->Adapter;
445 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
449 /* set some u8 type variables. */
450 case BTC_SET_BL_BT_DISABLE:
451 pBtCoexist->btInfo.bBtDisabled = *pu8;
454 case BTC_SET_BL_BT_TRAFFIC_BUSY:
455 pBtCoexist->btInfo.bBtBusy = *pu8;
458 case BTC_SET_BL_BT_LIMITED_DIG:
459 pBtCoexist->btInfo.bLimitedDig = *pu8;
462 case BTC_SET_BL_FORCE_TO_ROAM:
463 pBtCoexist->btInfo.bForceToRoam = *pu8;
466 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
467 pBtCoexist->btInfo.bRejectAggPkt = *pu8;
470 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
471 pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
474 case BTC_SET_BL_INC_SCAN_DEV_NUM:
475 pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
478 case BTC_SET_BL_BT_TX_RX_MASK:
479 pBtCoexist->btInfo.bBtTxRxMask = *pu8;
482 /* set some u8 type variables. */
483 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
484 pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pu8;
487 case BTC_SET_U1_AGG_BUF_SIZE:
488 pBtCoexist->btInfo.aggBufSize = *pu8;
491 /* the following are some action which will be triggered */
492 case BTC_SET_ACT_GET_BT_RSSI:
496 case BTC_SET_ACT_AGGREGATE_CTRL:
497 halbtcoutsrc_AggregationCheck(pBtCoexist);
500 /* 1Ant =========== */
501 /* set some u8 type variables. */
502 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
503 pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pu8;
506 case BTC_SET_U1_LPS_VAL:
507 pBtCoexist->btInfo.lpsVal = *pu8;
510 case BTC_SET_U1_RPWM_VAL:
511 pBtCoexist->btInfo.rpwmVal = *pu8;
514 /* the following are some action which will be triggered */
515 case BTC_SET_ACT_LEAVE_LPS:
516 halbtcoutsrc_LeaveLps(pBtCoexist);
519 case BTC_SET_ACT_ENTER_LPS:
520 halbtcoutsrc_EnterLps(pBtCoexist);
523 case BTC_SET_ACT_NORMAL_LPS:
524 halbtcoutsrc_NormalLps(pBtCoexist);
527 case BTC_SET_ACT_DISABLE_LOW_POWER:
528 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
531 case BTC_SET_ACT_UPDATE_RAMASK:
532 pBtCoexist->btInfo.raMask = *pU4Tmp;
534 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true) {
535 struct sta_info *psta;
536 struct wlan_bssid_ex *cur_network;
538 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
539 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->mac_address);
540 rtw_hal_update_ra_mask(psta, 0);
544 case BTC_SET_ACT_SEND_MIMO_PS:
548 case BTC_SET_ACT_CTRL_BT_INFO:
552 case BTC_SET_ACT_CTRL_BT_COEX:
555 case BTC_SET_ACT_CTRL_8723B_ANT:
568 /* IO related function */
570 static u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
572 struct btc_coexist *pBtCoexist;
573 struct adapter *padapter;
576 pBtCoexist = (struct btc_coexist *)pBtcContext;
577 padapter = pBtCoexist->Adapter;
579 return rtw_read8(padapter, RegAddr);
582 static u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
584 struct btc_coexist *pBtCoexist;
585 struct adapter *padapter;
588 pBtCoexist = (struct btc_coexist *)pBtcContext;
589 padapter = pBtCoexist->Adapter;
591 return rtw_read16(padapter, RegAddr);
594 static u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
596 struct btc_coexist *pBtCoexist;
597 struct adapter *padapter;
600 pBtCoexist = (struct btc_coexist *)pBtcContext;
601 padapter = pBtCoexist->Adapter;
603 return rtw_read32(padapter, RegAddr);
606 static void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
608 struct btc_coexist *pBtCoexist;
609 struct adapter *padapter;
612 pBtCoexist = (struct btc_coexist *)pBtcContext;
613 padapter = pBtCoexist->Adapter;
615 rtw_write8(padapter, RegAddr, Data);
618 static void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
620 struct btc_coexist *pBtCoexist;
621 struct adapter *padapter;
622 u8 originalValue, bitShift;
626 pBtCoexist = (struct btc_coexist *)pBtcContext;
627 padapter = pBtCoexist->Adapter;
631 if (bitMask != 0xFF) {
632 originalValue = rtw_read8(padapter, regAddr);
634 for (i = 0; i <= 7; i++) {
635 if ((bitMask >> i) & 0x1)
640 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
643 rtw_write8(padapter, regAddr, data1b);
646 static void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
648 struct btc_coexist *pBtCoexist;
649 struct adapter *padapter;
652 pBtCoexist = (struct btc_coexist *)pBtcContext;
653 padapter = pBtCoexist->Adapter;
655 rtw_write16(padapter, RegAddr, Data);
658 static void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
660 struct btc_coexist *pBtCoexist;
661 struct adapter *padapter;
664 pBtCoexist = (struct btc_coexist *)pBtcContext;
665 padapter = pBtCoexist->Adapter;
667 rtw_write32(padapter, RegAddr, Data);
670 static void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
672 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
673 struct adapter *Adapter = pBtCoexist->Adapter;
675 if (BTC_INTF_SDIO == pBtCoexist->chipInterface)
676 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
678 rtw_write8(Adapter, RegAddr, Data);
681 static void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
683 struct btc_coexist *pBtCoexist;
684 struct adapter *padapter;
687 pBtCoexist = (struct btc_coexist *)pBtcContext;
688 padapter = pBtCoexist->Adapter;
690 PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
694 static u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
696 struct btc_coexist *pBtCoexist;
697 struct adapter *padapter;
700 pBtCoexist = (struct btc_coexist *)pBtcContext;
701 padapter = pBtCoexist->Adapter;
703 return PHY_QueryBBReg(padapter, RegAddr, BitMask);
706 static void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
708 struct btc_coexist *pBtCoexist;
709 struct adapter *padapter;
712 pBtCoexist = (struct btc_coexist *)pBtcContext;
713 padapter = pBtCoexist->Adapter;
715 PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
718 static u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
720 struct btc_coexist *pBtCoexist;
721 struct adapter *padapter;
724 pBtCoexist = (struct btc_coexist *)pBtcContext;
725 padapter = pBtCoexist->Adapter;
727 return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
730 static void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
732 struct btc_coexist *pBtCoexist;
733 struct adapter *padapter;
734 u8 CmdBuffer1[4] = {0};
735 u8 CmdBuffer2[4] = {0};
736 u8 *AddrToSet = (u8 *)&RegAddr;
737 u8 *ValueToSet = (u8 *)&Data;
741 pBtCoexist = (struct btc_coexist *)pBtcContext;
742 padapter = pBtCoexist->Adapter;
744 CmdBuffer1[0] |= (OperVer & 0x0f); /* Set OperVer */
745 CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
746 CmdBuffer1[1] = 0x0d; /* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */
747 CmdBuffer1[2] = ValueToSet[0]; /* Set WriteRegValue */
748 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0]));
753 CmdBuffer2[0] |= (OperVer & 0x0f); /* Set OperVer */
754 CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
755 CmdBuffer2[1] = 0x0c; /* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */
756 CmdBuffer2[3] = AddrToSet[0]; /* Set WriteRegAddr */
757 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0]));
760 static u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
762 /* To be implemented. Always return 0 temporarily */
766 static void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
768 struct btc_coexist *pBtCoexist;
769 struct adapter *padapter;
772 pBtCoexist = (struct btc_coexist *)pBtcContext;
773 padapter = pBtCoexist->Adapter;
775 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
779 /* Extern functions called by other module */
781 static u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
783 struct btc_coexist *pBtCoexist = &GLBtCoexist;
785 if (pBtCoexist->bBinded)
788 pBtCoexist->bBinded = true;
790 pBtCoexist->statistics.cntBind++;
792 pBtCoexist->Adapter = padapter;
794 pBtCoexist->stackInfo.bProfileNotified = false;
796 pBtCoexist->btInfo.bBtCtrlAggBufSize = false;
797 pBtCoexist->btInfo.aggBufSize = 5;
799 pBtCoexist->btInfo.bIncreaseScanDevNum = false;
801 /* set default antenna position to main port */
802 pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
807 void hal_btcoex_Initialize(void *padapter)
809 struct btc_coexist *pBtCoexist;
811 memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
813 pBtCoexist = &GLBtCoexist;
815 /* pBtCoexist->statistics.cntBind++; */
817 pBtCoexist->chipInterface = BTC_INTF_SDIO;
819 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
821 pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
822 pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
823 pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
824 pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
825 pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
826 pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
827 pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
828 pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
830 pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
831 pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
833 pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
834 pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
836 pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
838 pBtCoexist->fBtcGet = halbtcoutsrc_Get;
839 pBtCoexist->fBtcSet = halbtcoutsrc_Set;
840 pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
841 pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
843 pBtCoexist->boardInfo.singleAntPath = 0;
845 GLBtcWiFiInScanState = false;
847 GLBtcWiFiInIQKState = false;
850 void EXhalbtcoutsrc_PowerOnSetting(struct btc_coexist *pBtCoexist)
852 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
855 /* Power on setting function is only added in 8723B currently */
856 if (pBtCoexist->boardInfo.btdmAntNum == 2)
857 EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
858 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
859 EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
862 void EXhalbtcoutsrc_InitHwConfig(struct btc_coexist *pBtCoexist, u8 bWifiOnly)
864 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
867 pBtCoexist->statistics.cntInitHwConfig++;
869 if (pBtCoexist->boardInfo.btdmAntNum == 2)
870 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
871 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
872 EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
875 void EXhalbtcoutsrc_InitCoexDm(struct btc_coexist *pBtCoexist)
877 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
880 pBtCoexist->statistics.cntInitCoexDm++;
882 if (pBtCoexist->boardInfo.btdmAntNum == 2)
883 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
884 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
885 EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
887 pBtCoexist->bInitilized = true;
890 void EXhalbtcoutsrc_IpsNotify(struct btc_coexist *pBtCoexist, u8 type)
894 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
897 pBtCoexist->statistics.cntIpsNotify++;
898 if (pBtCoexist->bManualControl)
901 if (IPS_NONE == type)
902 ipsType = BTC_IPS_LEAVE;
904 ipsType = BTC_IPS_ENTER;
906 /* All notify is called in cmd thread, don't need to leave low power again */
907 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
909 if (pBtCoexist->boardInfo.btdmAntNum == 2)
910 EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
911 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
912 EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
914 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
917 void EXhalbtcoutsrc_LpsNotify(struct btc_coexist *pBtCoexist, u8 type)
922 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
925 pBtCoexist->statistics.cntLpsNotify++;
926 if (pBtCoexist->bManualControl)
929 if (PS_MODE_ACTIVE == type)
930 lpsType = BTC_LPS_DISABLE;
932 lpsType = BTC_LPS_ENABLE;
934 if (pBtCoexist->boardInfo.btdmAntNum == 2)
935 EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
936 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
937 EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
940 void EXhalbtcoutsrc_ScanNotify(struct btc_coexist *pBtCoexist, u8 type)
944 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
946 pBtCoexist->statistics.cntScanNotify++;
947 if (pBtCoexist->bManualControl)
951 scanType = BTC_SCAN_START;
952 GLBtcWiFiInScanState = true;
954 scanType = BTC_SCAN_FINISH;
955 GLBtcWiFiInScanState = false;
958 /* All notify is called in cmd thread, don't need to leave low power again */
959 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
961 if (pBtCoexist->boardInfo.btdmAntNum == 2)
962 EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
963 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
964 EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
966 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
969 void EXhalbtcoutsrc_ConnectNotify(struct btc_coexist *pBtCoexist, u8 action)
973 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
975 pBtCoexist->statistics.cntConnectNotify++;
976 if (pBtCoexist->bManualControl)
980 assoType = BTC_ASSOCIATE_START;
982 assoType = BTC_ASSOCIATE_FINISH;
984 /* All notify is called in cmd thread, don't need to leave low power again */
985 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
987 if (pBtCoexist->boardInfo.btdmAntNum == 2)
988 EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
989 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
990 EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
992 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
995 void EXhalbtcoutsrc_MediaStatusNotify(struct btc_coexist *pBtCoexist, enum
996 rt_media_status mediaStatus)
1000 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1003 pBtCoexist->statistics.cntMediaStatusNotify++;
1004 if (pBtCoexist->bManualControl)
1007 if (RT_MEDIA_CONNECT == mediaStatus)
1008 mStatus = BTC_MEDIA_CONNECT;
1010 mStatus = BTC_MEDIA_DISCONNECT;
1012 /* All notify is called in cmd thread, don't need to leave low power again */
1013 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1015 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1016 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
1017 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1018 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
1020 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1023 void EXhalbtcoutsrc_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 pktType)
1027 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1029 pBtCoexist->statistics.cntSpecialPacketNotify++;
1030 if (pBtCoexist->bManualControl)
1033 if (PACKET_DHCP == pktType) {
1034 packetType = BTC_PACKET_DHCP;
1035 } else if (PACKET_EAPOL == pktType) {
1036 packetType = BTC_PACKET_EAPOL;
1037 } else if (PACKET_ARP == pktType) {
1038 packetType = BTC_PACKET_ARP;
1043 /* All notify is called in cmd thread, don't need to leave low power again */
1044 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1046 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1047 EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
1048 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1049 EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
1051 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1054 void EXhalbtcoutsrc_BtInfoNotify(struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length)
1056 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1059 pBtCoexist->statistics.cntBtInfoNotify++;
1061 /* All notify is called in cmd thread, don't need to leave low power again */
1062 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1064 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1065 EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1066 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1067 EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1069 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1072 void EXhalbtcoutsrc_HaltNotify(struct btc_coexist *pBtCoexist)
1074 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1077 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1078 EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
1079 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1080 EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
1082 pBtCoexist->bBinded = false;
1085 void EXhalbtcoutsrc_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState)
1087 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1091 /* currently only 1ant we have to do the notification, */
1092 /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */
1095 if (pBtCoexist->boardInfo.btdmAntNum == 1)
1096 EXhalbtc8723b1ant_PnpNotify(pBtCoexist, pnpState);
1097 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1098 EXhalbtc8723b2ant_PnpNotify(pBtCoexist, pnpState);
1101 void EXhalbtcoutsrc_Periodical(struct btc_coexist *pBtCoexist)
1103 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1105 pBtCoexist->statistics.cntPeriodical++;
1107 /* Periodical should be called in cmd thread, */
1108 /* don't need to leave low power again */
1109 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1111 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1112 EXhalbtc8723b2ant_Periodical(pBtCoexist);
1113 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1114 EXhalbtc8723b1ant_Periodical(pBtCoexist);
1116 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1119 void EXhalbtcoutsrc_SetChipType(u8 chipType)
1121 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
1124 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
1126 if (BT_COEX_ANT_TYPE_PG == type) {
1127 GLBtCoexist.boardInfo.pgAntNum = antNum;
1128 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1129 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1130 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1131 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1132 } else if (BT_COEX_ANT_TYPE_DETECTED == type) {
1133 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1134 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1139 /* Currently used by 8723b only, S0 or S1 */
1141 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
1143 GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
1148 *Run BT-Coexist mechanism or not
1151 void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist)
1153 struct hal_com_data *pHalData;
1156 pHalData = GET_HAL_DATA(padapter);
1157 pHalData->bt_coexist.bBtExist = bBtExist;
1162 *Check is co-exist mechanism enabled or not
1165 *true Enable BT co-exist mechanism
1166 *false Disable BT co-exist mechanism
1168 bool hal_btcoex_IsBtExist(struct adapter *padapter)
1170 struct hal_com_data *pHalData;
1173 pHalData = GET_HAL_DATA(padapter);
1174 return pHalData->bt_coexist.bBtExist;
1177 bool hal_btcoex_IsBtDisabled(struct adapter *padapter)
1179 if (!hal_btcoex_IsBtExist(padapter))
1182 if (GLBtCoexist.btInfo.bBtDisabled)
1188 void hal_btcoex_SetChipType(struct adapter *padapter, u8 chipType)
1190 struct hal_com_data *pHalData;
1193 pHalData = GET_HAL_DATA(padapter);
1194 pHalData->bt_coexist.btChipType = chipType;
1196 EXhalbtcoutsrc_SetChipType(chipType);
1199 void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum)
1201 struct hal_com_data *pHalData;
1204 pHalData = GET_HAL_DATA(padapter);
1206 pHalData->bt_coexist.btTotalAntNum = antNum;
1207 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1210 void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath)
1212 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
1215 void hal_btcoex_PowerOnSetting(struct adapter *padapter)
1217 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
1220 void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly)
1222 if (!hal_btcoex_IsBtExist(padapter))
1225 EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
1226 EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
1229 void hal_btcoex_IpsNotify(struct adapter *padapter, u8 type)
1231 EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
1234 void hal_btcoex_LpsNotify(struct adapter *padapter, u8 type)
1236 EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
1239 void hal_btcoex_ScanNotify(struct adapter *padapter, u8 type)
1241 EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
1244 void hal_btcoex_ConnectNotify(struct adapter *padapter, u8 action)
1246 EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
1249 void hal_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus)
1251 EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
1254 void hal_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType)
1256 EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
1259 void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state)
1261 GLBtcWiFiInIQKState = state;
1264 void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf)
1266 if (GLBtcWiFiInIQKState)
1269 EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
1272 void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state)
1275 state = BTC_WIFI_PNP_SLEEP;
1277 state = BTC_WIFI_PNP_WAKE_UP;
1279 EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
1282 void hal_btcoex_HaltNotify(struct adapter *padapter)
1284 EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
1287 void hal_btcoex_Handler(struct adapter *padapter)
1289 EXhalbtcoutsrc_Periodical(&GLBtCoexist);
1292 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter)
1294 return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
1297 void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual)
1299 GLBtCoexist.bManualControl = bmanual;
1302 bool hal_btcoex_IsBtControlLps(struct adapter *padapter)
1304 if (!hal_btcoex_IsBtExist(padapter))
1307 if (GLBtCoexist.btInfo.bBtDisabled)
1310 if (GLBtCoexist.btInfo.bBtCtrlLps)
1316 bool hal_btcoex_IsLpsOn(struct adapter *padapter)
1318 if (!hal_btcoex_IsBtExist(padapter))
1321 if (GLBtCoexist.btInfo.bBtDisabled)
1324 if (GLBtCoexist.btInfo.bBtLpsOn)
1330 u8 hal_btcoex_RpwmVal(struct adapter *padapter)
1332 return GLBtCoexist.btInfo.rpwmVal;
1335 u8 hal_btcoex_LpsVal(struct adapter *padapter)
1337 return GLBtCoexist.btInfo.lpsVal;
1340 u32 hal_btcoex_GetRaMask(struct adapter *padapter)
1342 if (!hal_btcoex_IsBtExist(padapter))
1345 if (GLBtCoexist.btInfo.bBtDisabled)
1348 if (GLBtCoexist.boardInfo.btdmAntNum != 1)
1351 return GLBtCoexist.btInfo.raMask;
1354 void hal_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen)
1356 memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);