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 */
15 static const char *const BtProfileString[] = {
23 static const char *const BtSpecString[] = {
33 static const char *const BtLinkRoleString[] = {
38 static const char *const h2cStaString[] = {
45 static const char *const ioStaString[] = {
59 BTC_COEXIST GLBtCoexist;
60 static u8 GLBtcWiFiInScanState;
61 static u8 GLBtcWiFiInIQKState;
63 u32 GLBtcDbgType[BTC_MSG_MAX];
64 static u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
66 typedef struct _btcoexdbginfo {
68 u32 size; /* buffer total size */
69 u32 len; /* now used length */
70 } BTCDBGINFO, *PBTCDBGINFO;
72 static BTCDBGINFO GLBtcDbgInfo;
74 #define BT_Operation(Adapter) false
76 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
81 memset(pinfo, 0, sizeof(BTCDBGINFO));
89 void DBG_BT_INFO(u8 *dbgmsg)
96 pinfo = &GLBtcDbgInfo;
101 msglen = strlen(dbgmsg);
102 if (pinfo->len + msglen > pinfo->size)
105 pbuf = pinfo->info + pinfo->len;
106 memcpy(pbuf, dbgmsg, msglen);
107 pinfo->len += msglen;
111 /* Debug related function */
113 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
115 if (!pBtCoexist->bBinded || !pBtCoexist->Adapter)
121 static void halbtcoutsrc_DbgInit(void)
125 for (i = 0; i < BTC_MSG_MAX; i++)
128 GLBtcDbgType[BTC_MSG_INTERFACE] = \
133 GLBtcDbgType[BTC_MSG_ALGORITHM] = \
134 /* ALGO_BT_RSSI_STATE | */
135 /* ALGO_WIFI_RSSI_STATE | */
136 /* ALGO_BT_MONITOR | */
138 /* ALGO_TRACE_FW | */
139 /* ALGO_TRACE_FW_DETAIL | */
140 /* ALGO_TRACE_FW_EXEC | */
141 /* ALGO_TRACE_SW | */
142 /* ALGO_TRACE_SW_DETAIL | */
143 /* ALGO_TRACE_SW_EXEC | */
147 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
149 struct adapter *padapter;
152 padapter = pBtCoexist->Adapter;
154 pBtCoexist->btInfo.bBtCtrlLps = true;
155 pBtCoexist->btInfo.bBtLpsOn = false;
157 rtw_btcoex_LPS_Leave(padapter);
160 static void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
162 struct adapter *padapter;
165 padapter = pBtCoexist->Adapter;
167 pBtCoexist->btInfo.bBtCtrlLps = true;
168 pBtCoexist->btInfo.bBtLpsOn = true;
170 rtw_btcoex_LPS_Enter(padapter);
173 static void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
175 struct adapter *padapter;
178 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Normal LPS behavior!!!\n"));
180 padapter = pBtCoexist->Adapter;
182 if (pBtCoexist->btInfo.bBtCtrlLps) {
183 pBtCoexist->btInfo.bBtLpsOn = false;
184 rtw_btcoex_LPS_Leave(padapter);
185 pBtCoexist->btInfo.bBtCtrlLps = false;
187 /* recover the LPS state to the original */
193 * 1. this function will request pwrctrl->lock
195 static void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
197 struct adapter *padapter;
198 struct hal_com_data *pHalData;
202 u32 timeout; /* unit: ms */
205 padapter = pBtCoexist->Adapter;
206 pHalData = GET_HAL_DATA(padapter);
208 #ifdef LPS_RPWM_WAIT_MS
209 timeout = LPS_RPWM_WAIT_MS;
210 #else /* !LPS_RPWM_WAIT_MS */
212 #endif /* !LPS_RPWM_WAIT_MS */
216 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
217 if (_SUCCESS == ready)
220 utime = jiffies_to_msecs(jiffies - stime);
230 * 1. this function will request pwrctrl->lock
232 static void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
234 struct adapter *padapter;
237 padapter = pBtCoexist->Adapter;
238 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
241 static void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
243 pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
245 halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */
247 halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */
250 static void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
252 struct adapter *padapter;
256 padapter = pBtCoexist->Adapter;
259 if (pBtCoexist->btInfo.bRejectAggPkt) {
260 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
262 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
263 pBtCoexist->btInfo.bBtCtrlAggBufSize) {
265 pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
268 if (pBtCoexist->btInfo.bBtCtrlAggBufSize) {
269 if (pBtCoexist->btInfo.preAggBufSize !=
270 pBtCoexist->btInfo.aggBufSize){
273 pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
277 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
278 rtw_btcoex_RejectApAggregatedPacket(padapter, false);
283 static u8 halbtcoutsrc_IsWifiBusy(struct adapter *padapter)
285 struct mlme_priv *pmlmepriv;
288 pmlmepriv = &padapter->mlmepriv;
290 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
291 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
293 if (true == pmlmepriv->LinkDetectInfo.bBusyTraffic)
300 static u32 _halbtcoutsrc_GetWifiLinkStatus(struct adapter *padapter)
302 struct mlme_priv *pmlmepriv;
304 u32 portConnectedStatus;
307 pmlmepriv = &padapter->mlmepriv;
309 portConnectedStatus = 0;
311 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
312 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
314 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
316 portConnectedStatus |= WIFI_AP_CONNECTED;
319 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
321 portConnectedStatus |= WIFI_STA_CONNECTED;
325 return portConnectedStatus;
328 static u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
332 /* [31:16]=> connected port number */
333 /* [15:0]=> port connected bit define */
336 struct adapter *padapter;
338 u32 portConnectedStatus, numOfConnectedPort;
341 padapter = pBtCoexist->Adapter;
342 portConnectedStatus = 0;
343 numOfConnectedPort = 0;
345 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
347 portConnectedStatus |= retVal;
348 numOfConnectedPort++;
351 retVal = (numOfConnectedPort << 16) | portConnectedStatus;
356 static u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
358 return pBtCoexist->btInfo.btRealFwVer;
361 static s32 halbtcoutsrc_GetWifiRssi(struct adapter *padapter)
363 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
365 return pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
368 static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter)
370 struct mlme_ext_priv *pmlmeext;
371 static u8 scan_AP_num;
373 pmlmeext = &padapter->mlmeextpriv;
375 if (GLBtcWiFiInScanState == false) {
376 if (pmlmeext->sitesurvey_res.bss_cnt > 0xFF)
379 scan_AP_num = (u8)pmlmeext->sitesurvey_res.bss_cnt;
385 static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
387 PBTC_COEXIST pBtCoexist;
388 struct adapter *padapter;
389 struct hal_com_data *pHalData;
390 struct mlme_ext_priv *mlmeext;
398 pBtCoexist = (PBTC_COEXIST)pBtcContext;
399 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
402 padapter = pBtCoexist->Adapter;
403 pHalData = GET_HAL_DATA(padapter);
404 mlmeext = &padapter->mlmeextpriv;
412 case BTC_GET_BL_HS_OPERATION:
417 case BTC_GET_BL_HS_CONNECTING:
422 case BTC_GET_BL_WIFI_CONNECTED:
423 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
426 case BTC_GET_BL_WIFI_BUSY:
427 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
430 case BTC_GET_BL_WIFI_SCAN:
431 /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
432 WIFI_SITE_MONITOR in fwstate may not be cleared in time */
433 *pu8 = GLBtcWiFiInScanState;
436 case BTC_GET_BL_WIFI_LINK:
437 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
440 case BTC_GET_BL_WIFI_ROAM:
441 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
444 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
448 case BTC_GET_BL_WIFI_UNDER_5G:
449 *pu8 = pHalData->CurrentBandType == 1;
452 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
453 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
456 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
457 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? false : true;
460 case BTC_GET_BL_WIFI_UNDER_B_MODE:
461 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
467 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
471 case BTC_GET_BL_EXT_SWITCH:
475 case BTC_GET_S4_WIFI_RSSI:
476 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
479 case BTC_GET_S4_HS_RSSI:
484 case BTC_GET_U4_WIFI_BW:
485 if (IsLegacyOnly(mlmeext->cur_wireless_mode))
486 *pU4Tmp = BTC_WIFI_BW_LEGACY;
487 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
488 *pU4Tmp = BTC_WIFI_BW_HT20;
489 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
490 *pU4Tmp = BTC_WIFI_BW_HT40;
492 *pU4Tmp = BTC_WIFI_BW_HT40; /* todo */
495 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
497 PRT_LINK_DETECT_T plinkinfo;
498 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
500 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
501 *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
503 *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
507 case BTC_GET_U4_WIFI_FW_VER:
508 *pU4Tmp = pHalData->FirmwareVersion << 16;
509 *pU4Tmp |= pHalData->FirmwareSubVersion;
512 case BTC_GET_U4_WIFI_LINK_STATUS:
513 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
516 case BTC_GET_U4_BT_PATCH_VER:
517 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
520 case BTC_GET_U1_WIFI_DOT11_CHNL:
521 *pU1Tmp = padapter->mlmeextpriv.cur_channel;
524 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
525 *pU1Tmp = pHalData->CurrentChannel;
528 case BTC_GET_U1_WIFI_HS_CHNL:
533 case BTC_GET_U1_MAC_PHY_MODE:
535 /* *pU1Tmp = BTC_DMSP; */
536 /* *pU1Tmp = BTC_DMDP; */
537 /* *pU1Tmp = BTC_MP_UNKNOWN; */
540 case BTC_GET_U1_AP_NUM:
541 *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
544 /* 1Ant =========== */
545 case BTC_GET_U1_LPS_MODE:
546 *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
557 static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
559 PBTC_COEXIST pBtCoexist;
560 struct adapter *padapter;
566 pBtCoexist = (PBTC_COEXIST)pBtcContext;
567 padapter = pBtCoexist->Adapter;
572 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
576 /* set some u8 type variables. */
577 case BTC_SET_BL_BT_DISABLE:
578 pBtCoexist->btInfo.bBtDisabled = *pu8;
581 case BTC_SET_BL_BT_TRAFFIC_BUSY:
582 pBtCoexist->btInfo.bBtBusy = *pu8;
585 case BTC_SET_BL_BT_LIMITED_DIG:
586 pBtCoexist->btInfo.bLimitedDig = *pu8;
589 case BTC_SET_BL_FORCE_TO_ROAM:
590 pBtCoexist->btInfo.bForceToRoam = *pu8;
593 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
594 pBtCoexist->btInfo.bRejectAggPkt = *pu8;
597 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
598 pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
601 case BTC_SET_BL_INC_SCAN_DEV_NUM:
602 pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
605 case BTC_SET_BL_BT_TX_RX_MASK:
606 pBtCoexist->btInfo.bBtTxRxMask = *pu8;
609 /* set some u8 type variables. */
610 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
611 pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pu8;
614 case BTC_SET_U1_AGG_BUF_SIZE:
615 pBtCoexist->btInfo.aggBufSize = *pu8;
618 /* the following are some action which will be triggered */
619 case BTC_SET_ACT_GET_BT_RSSI:
623 case BTC_SET_ACT_AGGREGATE_CTRL:
624 halbtcoutsrc_AggregationCheck(pBtCoexist);
627 /* 1Ant =========== */
628 /* set some u8 type variables. */
629 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
630 pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pu8;
633 case BTC_SET_U1_LPS_VAL:
634 pBtCoexist->btInfo.lpsVal = *pu8;
637 case BTC_SET_U1_RPWM_VAL:
638 pBtCoexist->btInfo.rpwmVal = *pu8;
641 /* the following are some action which will be triggered */
642 case BTC_SET_ACT_LEAVE_LPS:
643 halbtcoutsrc_LeaveLps(pBtCoexist);
646 case BTC_SET_ACT_ENTER_LPS:
647 halbtcoutsrc_EnterLps(pBtCoexist);
650 case BTC_SET_ACT_NORMAL_LPS:
651 halbtcoutsrc_NormalLps(pBtCoexist);
654 case BTC_SET_ACT_DISABLE_LOW_POWER:
655 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
658 case BTC_SET_ACT_UPDATE_RAMASK:
659 pBtCoexist->btInfo.raMask = *pU4Tmp;
661 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true) {
662 struct sta_info *psta;
663 struct wlan_bssid_ex *cur_network;
665 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
666 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
667 rtw_hal_update_ra_mask(psta, 0);
671 case BTC_SET_ACT_SEND_MIMO_PS:
675 case BTC_SET_ACT_CTRL_BT_INFO:
679 case BTC_SET_ACT_CTRL_BT_COEX:
682 case BTC_SET_ACT_CTRL_8723B_ANT:
694 static void halbtcoutsrc_DisplayFwPwrModeCmd(PBTC_COEXIST pBtCoexist)
696 u8 *cliBuf = pBtCoexist->cliBuf;
698 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x ", "Power mode cmd ", \
699 pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
700 pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
701 pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5]);
706 /* IO related function */
708 static u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
710 PBTC_COEXIST pBtCoexist;
711 struct adapter *padapter;
714 pBtCoexist = (PBTC_COEXIST)pBtcContext;
715 padapter = pBtCoexist->Adapter;
717 return rtw_read8(padapter, RegAddr);
720 static u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
722 PBTC_COEXIST pBtCoexist;
723 struct adapter *padapter;
726 pBtCoexist = (PBTC_COEXIST)pBtcContext;
727 padapter = pBtCoexist->Adapter;
729 return rtw_read16(padapter, RegAddr);
732 static u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
734 PBTC_COEXIST pBtCoexist;
735 struct adapter *padapter;
738 pBtCoexist = (PBTC_COEXIST)pBtcContext;
739 padapter = pBtCoexist->Adapter;
741 return rtw_read32(padapter, RegAddr);
744 static void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
746 PBTC_COEXIST pBtCoexist;
747 struct adapter *padapter;
750 pBtCoexist = (PBTC_COEXIST)pBtcContext;
751 padapter = pBtCoexist->Adapter;
753 rtw_write8(padapter, RegAddr, Data);
756 static void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
758 PBTC_COEXIST pBtCoexist;
759 struct adapter *padapter;
760 u8 originalValue, bitShift;
764 pBtCoexist = (PBTC_COEXIST)pBtcContext;
765 padapter = pBtCoexist->Adapter;
769 if (bitMask != 0xFF) {
770 originalValue = rtw_read8(padapter, regAddr);
772 for (i = 0; i <= 7; i++) {
773 if ((bitMask>>i)&0x1)
778 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
781 rtw_write8(padapter, regAddr, data1b);
784 static void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
786 PBTC_COEXIST pBtCoexist;
787 struct adapter *padapter;
790 pBtCoexist = (PBTC_COEXIST)pBtcContext;
791 padapter = pBtCoexist->Adapter;
793 rtw_write16(padapter, RegAddr, Data);
796 static void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
798 PBTC_COEXIST pBtCoexist;
799 struct adapter *padapter;
802 pBtCoexist = (PBTC_COEXIST)pBtcContext;
803 padapter = pBtCoexist->Adapter;
805 rtw_write32(padapter, RegAddr, Data);
808 static void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
810 PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
811 struct adapter *Adapter = pBtCoexist->Adapter;
813 if (BTC_INTF_SDIO == pBtCoexist->chipInterface)
814 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
816 rtw_write8(Adapter, RegAddr, Data);
819 static void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
821 PBTC_COEXIST pBtCoexist;
822 struct adapter *padapter;
825 pBtCoexist = (PBTC_COEXIST)pBtcContext;
826 padapter = pBtCoexist->Adapter;
828 PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
832 static u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
834 PBTC_COEXIST pBtCoexist;
835 struct adapter *padapter;
838 pBtCoexist = (PBTC_COEXIST)pBtcContext;
839 padapter = pBtCoexist->Adapter;
841 return PHY_QueryBBReg(padapter, RegAddr, BitMask);
844 static void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
846 PBTC_COEXIST pBtCoexist;
847 struct adapter *padapter;
850 pBtCoexist = (PBTC_COEXIST)pBtcContext;
851 padapter = pBtCoexist->Adapter;
853 PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
856 static u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
858 PBTC_COEXIST pBtCoexist;
859 struct adapter *padapter;
862 pBtCoexist = (PBTC_COEXIST)pBtcContext;
863 padapter = pBtCoexist->Adapter;
865 return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
868 static void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
870 PBTC_COEXIST pBtCoexist;
871 struct adapter *padapter;
872 u8 CmdBuffer1[4] = {0};
873 u8 CmdBuffer2[4] = {0};
874 u8 *AddrToSet = (u8 *)&RegAddr;
875 u8 *ValueToSet = (u8 *)&Data;
879 pBtCoexist = (PBTC_COEXIST)pBtcContext;
880 padapter = pBtCoexist->Adapter;
882 CmdBuffer1[0] |= (OperVer & 0x0f); /* Set OperVer */
883 CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
884 CmdBuffer1[1] = 0x0d; /* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */
885 CmdBuffer1[2] = ValueToSet[0]; /* Set WriteRegValue */
886 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0]));
891 CmdBuffer2[0] |= (OperVer & 0x0f); /* Set OperVer */
892 CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
893 CmdBuffer2[1] = 0x0c; /* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */
894 CmdBuffer2[3] = AddrToSet[0]; /* Set WriteRegAddr */
895 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0]));
898 static u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
900 /* To be implemented. Always return 0 temporarily */
904 static void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
906 PBTC_COEXIST pBtCoexist;
907 struct adapter *padapter;
910 pBtCoexist = (PBTC_COEXIST)pBtcContext;
911 padapter = pBtCoexist->Adapter;
913 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
916 static void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
918 PBTC_COEXIST pBtCoexist;
921 pBtCoexist = (PBTC_COEXIST)pBtcContext;
923 case BTC_DBG_DISP_COEX_STATISTICS:
925 case BTC_DBG_DISP_BT_LINK_INFO:
927 case BTC_DBG_DISP_FW_PWR_MODE_CMD:
928 halbtcoutsrc_DisplayFwPwrModeCmd(pBtCoexist);
936 /* Extern functions called by other module */
938 static u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
940 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
942 if (pBtCoexist->bBinded)
945 pBtCoexist->bBinded = true;
947 pBtCoexist->statistics.cntBind++;
949 pBtCoexist->Adapter = padapter;
951 pBtCoexist->stackInfo.bProfileNotified = false;
953 pBtCoexist->btInfo.bBtCtrlAggBufSize = false;
954 pBtCoexist->btInfo.aggBufSize = 5;
956 pBtCoexist->btInfo.bIncreaseScanDevNum = false;
958 /* set default antenna position to main port */
959 pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
964 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
966 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
968 /* pBtCoexist->statistics.cntBind++; */
970 halbtcoutsrc_DbgInit();
972 pBtCoexist->chipInterface = BTC_INTF_SDIO;
974 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
976 pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
977 pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
978 pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
979 pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
980 pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
981 pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
982 pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
983 pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
985 pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
986 pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
988 pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
989 pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
991 pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
992 pBtCoexist->fBtcDispDbgMsg = halbtcoutsrc_DisplayDbgMsg;
994 pBtCoexist->fBtcGet = halbtcoutsrc_Get;
995 pBtCoexist->fBtcSet = halbtcoutsrc_Set;
996 pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
997 pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
999 pBtCoexist->cliBuf = &GLBtcDbgBuf[0];
1001 pBtCoexist->boardInfo.singleAntPath = 0;
1003 GLBtcWiFiInScanState = false;
1005 GLBtcWiFiInIQKState = false;
1010 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
1012 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1015 /* Power on setting function is only added in 8723B currently */
1016 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1017 EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
1018 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1019 EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
1022 void EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
1024 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1027 pBtCoexist->statistics.cntInitHwConfig++;
1029 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1030 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1031 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1032 EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1035 void EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist)
1037 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1040 pBtCoexist->statistics.cntInitCoexDm++;
1042 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1043 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
1044 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1045 EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
1047 pBtCoexist->bInitilized = true;
1050 void EXhalbtcoutsrc_IpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1054 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1057 pBtCoexist->statistics.cntIpsNotify++;
1058 if (pBtCoexist->bManualControl)
1061 if (IPS_NONE == type)
1062 ipsType = BTC_IPS_LEAVE;
1064 ipsType = BTC_IPS_ENTER;
1066 /* All notify is called in cmd thread, don't need to leave low power again */
1067 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1069 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1070 EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
1071 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1072 EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
1074 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1077 void EXhalbtcoutsrc_LpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1082 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1085 pBtCoexist->statistics.cntLpsNotify++;
1086 if (pBtCoexist->bManualControl)
1089 if (PS_MODE_ACTIVE == type)
1090 lpsType = BTC_LPS_DISABLE;
1092 lpsType = BTC_LPS_ENABLE;
1094 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1095 EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
1096 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1097 EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
1100 void EXhalbtcoutsrc_ScanNotify(PBTC_COEXIST pBtCoexist, u8 type)
1104 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1106 pBtCoexist->statistics.cntScanNotify++;
1107 if (pBtCoexist->bManualControl)
1111 scanType = BTC_SCAN_START;
1112 GLBtcWiFiInScanState = true;
1114 scanType = BTC_SCAN_FINISH;
1115 GLBtcWiFiInScanState = false;
1118 /* All notify is called in cmd thread, don't need to leave low power again */
1119 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1121 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1122 EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
1123 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1124 EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
1126 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1129 void EXhalbtcoutsrc_ConnectNotify(PBTC_COEXIST pBtCoexist, u8 action)
1133 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1135 pBtCoexist->statistics.cntConnectNotify++;
1136 if (pBtCoexist->bManualControl)
1140 assoType = BTC_ASSOCIATE_START;
1142 assoType = BTC_ASSOCIATE_FINISH;
1144 /* All notify is called in cmd thread, don't need to leave low power again */
1145 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1147 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1148 EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
1149 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1150 EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
1152 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1155 void EXhalbtcoutsrc_MediaStatusNotify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
1159 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1162 pBtCoexist->statistics.cntMediaStatusNotify++;
1163 if (pBtCoexist->bManualControl)
1166 if (RT_MEDIA_CONNECT == mediaStatus)
1167 mStatus = BTC_MEDIA_CONNECT;
1169 mStatus = BTC_MEDIA_DISCONNECT;
1171 /* All notify is called in cmd thread, don't need to leave low power again */
1172 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1174 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1175 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
1176 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1177 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
1179 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1182 void EXhalbtcoutsrc_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 pktType)
1186 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1188 pBtCoexist->statistics.cntSpecialPacketNotify++;
1189 if (pBtCoexist->bManualControl)
1192 if (PACKET_DHCP == pktType) {
1193 packetType = BTC_PACKET_DHCP;
1194 } else if (PACKET_EAPOL == pktType) {
1195 packetType = BTC_PACKET_EAPOL;
1196 } else if (PACKET_ARP == pktType) {
1197 packetType = BTC_PACKET_ARP;
1199 packetType = BTC_PACKET_UNKNOWN;
1203 /* All notify is called in cmd thread, don't need to leave low power again */
1204 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1206 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1207 EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
1208 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1209 EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
1211 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1214 void EXhalbtcoutsrc_BtInfoNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
1216 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1219 pBtCoexist->statistics.cntBtInfoNotify++;
1221 /* All notify is called in cmd thread, don't need to leave low power again */
1222 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1224 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1225 EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1226 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1227 EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1229 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1232 void EXhalbtcoutsrc_HaltNotify(PBTC_COEXIST pBtCoexist)
1234 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1237 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1238 EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
1239 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1240 EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
1242 pBtCoexist->bBinded = false;
1245 void EXhalbtcoutsrc_PnpNotify(PBTC_COEXIST pBtCoexist, u8 pnpState)
1247 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1251 /* currently only 1ant we have to do the notification, */
1252 /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */
1255 if (pBtCoexist->boardInfo.btdmAntNum == 1)
1256 EXhalbtc8723b1ant_PnpNotify(pBtCoexist, pnpState);
1257 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1258 EXhalbtc8723b2ant_PnpNotify(pBtCoexist, pnpState);
1261 void EXhalbtcoutsrc_Periodical(PBTC_COEXIST pBtCoexist)
1263 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1265 pBtCoexist->statistics.cntPeriodical++;
1267 /* Periodical should be called in cmd thread, */
1268 /* don't need to leave low power again */
1269 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1271 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1272 EXhalbtc8723b2ant_Periodical(pBtCoexist);
1273 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1274 EXhalbtc8723b1ant_Periodical(pBtCoexist);
1276 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1279 void EXhalbtcoutsrc_SetChipType(u8 chipType)
1281 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
1284 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
1286 if (BT_COEX_ANT_TYPE_PG == type) {
1287 GLBtCoexist.boardInfo.pgAntNum = antNum;
1288 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1289 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1290 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1291 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1292 } else if (BT_COEX_ANT_TYPE_DETECTED == type) {
1293 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1294 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1299 /* Currently used by 8723b only, S0 or S1 */
1301 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
1303 GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
1306 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
1308 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1311 halbtcoutsrc_LeaveLowPower(pBtCoexist);
1313 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1314 EXhalbtc8723b2ant_DisplayCoexInfo(pBtCoexist);
1315 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1316 EXhalbtc8723b1ant_DisplayCoexInfo(pBtCoexist);
1318 halbtcoutsrc_NormalLowPower(pBtCoexist);
1323 *Run BT-Coexist mechansim or not
1326 void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist)
1328 struct hal_com_data *pHalData;
1331 pHalData = GET_HAL_DATA(padapter);
1332 pHalData->bt_coexist.bBtExist = bBtExist;
1337 *Check is co-exist mechanism enabled or not
1340 *true Enable BT co-exist mechanism
1341 *false Disable BT co-exist mechanism
1343 u8 hal_btcoex_IsBtExist(struct adapter *padapter)
1345 struct hal_com_data *pHalData;
1348 pHalData = GET_HAL_DATA(padapter);
1349 return pHalData->bt_coexist.bBtExist;
1352 u8 hal_btcoex_IsBtDisabled(struct adapter *padapter)
1354 if (!hal_btcoex_IsBtExist(padapter))
1357 if (GLBtCoexist.btInfo.bBtDisabled)
1363 void hal_btcoex_SetChipType(struct adapter *padapter, u8 chipType)
1365 struct hal_com_data *pHalData;
1368 pHalData = GET_HAL_DATA(padapter);
1369 pHalData->bt_coexist.btChipType = chipType;
1371 EXhalbtcoutsrc_SetChipType(chipType);
1374 void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum)
1376 struct hal_com_data *pHalData;
1379 pHalData = GET_HAL_DATA(padapter);
1381 pHalData->bt_coexist.btTotalAntNum = antNum;
1382 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1385 void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath)
1387 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
1390 u8 hal_btcoex_Initialize(struct adapter *padapter)
1392 memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
1393 return EXhalbtcoutsrc_InitlizeVariables((void *)padapter);
1396 void hal_btcoex_PowerOnSetting(struct adapter *padapter)
1398 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
1401 void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly)
1403 if (!hal_btcoex_IsBtExist(padapter))
1406 EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
1407 EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
1410 void hal_btcoex_IpsNotify(struct adapter *padapter, u8 type)
1412 EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
1415 void hal_btcoex_LpsNotify(struct adapter *padapter, u8 type)
1417 EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
1420 void hal_btcoex_ScanNotify(struct adapter *padapter, u8 type)
1422 EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
1425 void hal_btcoex_ConnectNotify(struct adapter *padapter, u8 action)
1427 EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
1430 void hal_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus)
1432 EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
1435 void hal_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType)
1437 EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
1440 void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state)
1442 GLBtcWiFiInIQKState = state;
1445 void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf)
1447 if (GLBtcWiFiInIQKState == true)
1450 EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
1453 void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state)
1456 state = BTC_WIFI_PNP_SLEEP;
1458 state = BTC_WIFI_PNP_WAKE_UP;
1460 EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
1463 void hal_btcoex_HaltNotify(struct adapter *padapter)
1465 EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
1468 void hal_btcoex_Handler(struct adapter *padapter)
1470 EXhalbtcoutsrc_Periodical(&GLBtCoexist);
1473 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter)
1475 return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
1478 void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual)
1480 GLBtCoexist.bManualControl = bmanual;
1483 u8 hal_btcoex_IsBtControlLps(struct adapter *padapter)
1485 if (hal_btcoex_IsBtExist(padapter) == false)
1488 if (GLBtCoexist.btInfo.bBtDisabled)
1491 if (GLBtCoexist.btInfo.bBtCtrlLps)
1497 u8 hal_btcoex_IsLpsOn(struct adapter *padapter)
1499 if (hal_btcoex_IsBtExist(padapter) == false)
1502 if (GLBtCoexist.btInfo.bBtDisabled)
1505 if (GLBtCoexist.btInfo.bBtLpsOn)
1511 u8 hal_btcoex_RpwmVal(struct adapter *padapter)
1513 return GLBtCoexist.btInfo.rpwmVal;
1516 u8 hal_btcoex_LpsVal(struct adapter *padapter)
1518 return GLBtCoexist.btInfo.lpsVal;
1521 u32 hal_btcoex_GetRaMask(struct adapter *padapter)
1523 if (!hal_btcoex_IsBtExist(padapter))
1526 if (GLBtCoexist.btInfo.bBtDisabled)
1529 if (GLBtCoexist.boardInfo.btdmAntNum != 1)
1532 return GLBtCoexist.btInfo.raMask;
1535 void hal_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen)
1537 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write pwrModeCmd = 0x%04x%08x\n",
1538 pCmdBuf[0]<<8|pCmdBuf[1],
1539 pCmdBuf[2]<<24|pCmdBuf[3]<<16|pCmdBuf[4]<<8|pCmdBuf[5]));
1541 memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
1544 void hal_btcoex_DisplayBtCoexInfo(struct adapter *padapter, u8 *pbuf, u32 bufsize)
1549 pinfo = &GLBtcDbgInfo;
1550 DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
1551 EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
1552 DBG_BT_INFO_INIT(pinfo, NULL, 0);
1555 void hal_btcoex_SetDBG(struct adapter *padapter, u32 *pDbgModule)
1563 for (i = 0; i < BTC_MSG_MAX; i++)
1564 GLBtcDbgType[i] = pDbgModule[i];
1567 u32 hal_btcoex_GetDBG(struct adapter *padapter, u8 *pStrBuf, u32 bufSize)
1574 if (!pStrBuf || bufSize == 0)
1579 /* DBG_871X(FUNC_ADPT_FMT ": bufsize =%d\n", FUNC_ADPT_ARG(padapter), bufSize); */
1581 count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
1582 if ((count < 0) || (count >= leftSize))
1587 count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
1588 if ((count < 0) || (count >= leftSize))
1593 count = rtw_sprintf(pstr, leftSize,
1594 "INTERFACE / ALGORITHM: 0x%08X / 0x%08X\n\n",
1595 GLBtcDbgType[BTC_MSG_INTERFACE],
1596 GLBtcDbgType[BTC_MSG_ALGORITHM]);
1597 if ((count < 0) || (count >= leftSize))
1602 count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
1603 if ((count < 0) || (count >= leftSize))
1607 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
1608 (GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_INIT)?1:0);
1609 if ((count < 0) || (count >= leftSize))
1613 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
1614 (GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_NOTIFY)?1:0);
1615 if ((count < 0) || (count >= leftSize))
1620 count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
1621 if ((count < 0) || (count >= leftSize))
1625 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
1626 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_RSSI_STATE)?1:0);
1627 if ((count < 0) || (count >= leftSize))
1631 count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
1632 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_WIFI_RSSI_STATE)?1:0);
1633 if ((count < 0) || (count >= leftSize))
1637 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
1638 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_MONITOR)?1:0);
1639 if ((count < 0) || (count >= leftSize))
1643 count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
1644 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE)?1:0);
1645 if ((count < 0) || (count >= leftSize))
1649 count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
1650 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW)?1:0);
1651 if ((count < 0) || (count >= leftSize))
1655 count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
1656 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_DETAIL)?1:0);
1657 if ((count < 0) || (count >= leftSize))
1661 count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
1662 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_EXEC)?1:0);
1663 if ((count < 0) || (count >= leftSize))
1667 count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
1668 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW)?1:0);
1669 if ((count < 0) || (count >= leftSize))
1673 count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
1674 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_DETAIL)?1:0);
1675 if ((count < 0) || (count >= leftSize))
1679 count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
1680 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_EXEC)?1:0);
1681 if ((count < 0) || (count >= leftSize))
1687 count = pstr - pStrBuf;
1688 /* DBG_871X(FUNC_ADPT_FMT ": usedsize =%d\n", FUNC_ADPT_ARG(padapter), count); */