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;
98 if (NULL == pinfo->info)
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 ||
116 NULL == pBtCoexist->Adapter){
122 static void halbtcoutsrc_DbgInit(void)
126 for (i = 0; i < BTC_MSG_MAX; i++)
129 GLBtcDbgType[BTC_MSG_INTERFACE] = \
134 GLBtcDbgType[BTC_MSG_ALGORITHM] = \
135 /* ALGO_BT_RSSI_STATE | */
136 /* ALGO_WIFI_RSSI_STATE | */
137 /* ALGO_BT_MONITOR | */
139 /* ALGO_TRACE_FW | */
140 /* ALGO_TRACE_FW_DETAIL | */
141 /* ALGO_TRACE_FW_EXEC | */
142 /* ALGO_TRACE_SW | */
143 /* ALGO_TRACE_SW_DETAIL | */
144 /* ALGO_TRACE_SW_EXEC | */
148 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
150 struct adapter *padapter;
153 padapter = pBtCoexist->Adapter;
155 pBtCoexist->btInfo.bBtCtrlLps = true;
156 pBtCoexist->btInfo.bBtLpsOn = false;
158 rtw_btcoex_LPS_Leave(padapter);
161 static void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
163 struct adapter *padapter;
166 padapter = pBtCoexist->Adapter;
168 pBtCoexist->btInfo.bBtCtrlLps = true;
169 pBtCoexist->btInfo.bBtLpsOn = true;
171 rtw_btcoex_LPS_Enter(padapter);
174 static void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
176 struct adapter *padapter;
179 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Normal LPS behavior!!!\n"));
181 padapter = pBtCoexist->Adapter;
183 if (pBtCoexist->btInfo.bBtCtrlLps) {
184 pBtCoexist->btInfo.bBtLpsOn = false;
185 rtw_btcoex_LPS_Leave(padapter);
186 pBtCoexist->btInfo.bBtCtrlLps = false;
188 /* recover the LPS state to the original */
194 * 1. this function will request pwrctrl->lock
196 static void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
198 struct adapter *padapter;
199 struct hal_com_data *pHalData;
203 u32 timeout; /* unit: ms */
206 padapter = pBtCoexist->Adapter;
207 pHalData = GET_HAL_DATA(padapter);
209 #ifdef LPS_RPWM_WAIT_MS
210 timeout = LPS_RPWM_WAIT_MS;
211 #else /* !LPS_RPWM_WAIT_MS */
213 #endif /* !LPS_RPWM_WAIT_MS */
217 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
218 if (_SUCCESS == ready)
221 utime = jiffies_to_msecs(jiffies - stime);
231 * 1. this function will request pwrctrl->lock
233 static void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
235 struct adapter *padapter;
238 padapter = pBtCoexist->Adapter;
239 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
242 static void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
244 pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
246 halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */
248 halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */
251 static void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
253 struct adapter *padapter;
257 padapter = pBtCoexist->Adapter;
260 if (pBtCoexist->btInfo.bRejectAggPkt)
261 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
264 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
265 pBtCoexist->btInfo.bBtCtrlAggBufSize){
268 pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
271 if (pBtCoexist->btInfo.bBtCtrlAggBufSize) {
272 if (pBtCoexist->btInfo.preAggBufSize !=
273 pBtCoexist->btInfo.aggBufSize){
276 pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
280 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
281 rtw_btcoex_RejectApAggregatedPacket(padapter, false);
286 static u8 halbtcoutsrc_IsWifiBusy(struct adapter *padapter)
288 struct mlme_priv *pmlmepriv;
291 pmlmepriv = &padapter->mlmepriv;
293 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
294 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
296 if (true == pmlmepriv->LinkDetectInfo.bBusyTraffic)
303 static u32 _halbtcoutsrc_GetWifiLinkStatus(struct adapter *padapter)
305 struct mlme_priv *pmlmepriv;
307 u32 portConnectedStatus;
310 pmlmepriv = &padapter->mlmepriv;
312 portConnectedStatus = 0;
314 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
315 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
317 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
319 portConnectedStatus |= WIFI_AP_CONNECTED;
322 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
324 portConnectedStatus |= WIFI_STA_CONNECTED;
328 return portConnectedStatus;
331 static u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
335 /* [31:16]=> connected port number */
336 /* [15:0]=> port connected bit define */
339 struct adapter *padapter;
341 u32 portConnectedStatus, numOfConnectedPort;
344 padapter = pBtCoexist->Adapter;
345 portConnectedStatus = 0;
346 numOfConnectedPort = 0;
348 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
350 portConnectedStatus |= retVal;
351 numOfConnectedPort++;
354 retVal = (numOfConnectedPort << 16) | portConnectedStatus;
359 static u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
361 return pBtCoexist->btInfo.btRealFwVer;
364 static s32 halbtcoutsrc_GetWifiRssi(struct adapter *padapter)
366 struct hal_com_data *pHalData;
367 s32 UndecoratedSmoothedPWDB = 0;
370 pHalData = GET_HAL_DATA(padapter);
372 UndecoratedSmoothedPWDB = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
374 return UndecoratedSmoothedPWDB;
377 static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter)
379 struct mlme_ext_priv *pmlmeext;
380 static u8 scan_AP_num;
382 pmlmeext = &padapter->mlmeextpriv;
384 if (GLBtcWiFiInScanState == false) {
385 if (pmlmeext->sitesurvey_res.bss_cnt > 0xFF)
388 scan_AP_num = (u8)pmlmeext->sitesurvey_res.bss_cnt;
394 static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
396 PBTC_COEXIST pBtCoexist;
397 struct adapter *padapter;
398 struct hal_com_data *pHalData;
399 struct mlme_ext_priv *mlmeext;
407 pBtCoexist = (PBTC_COEXIST)pBtcContext;
408 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
411 padapter = pBtCoexist->Adapter;
412 pHalData = GET_HAL_DATA(padapter);
413 mlmeext = &padapter->mlmeextpriv;
421 case BTC_GET_BL_HS_OPERATION:
426 case BTC_GET_BL_HS_CONNECTING:
431 case BTC_GET_BL_WIFI_CONNECTED:
432 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
435 case BTC_GET_BL_WIFI_BUSY:
436 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
439 case BTC_GET_BL_WIFI_SCAN:
440 /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
441 WIFI_SITE_MONITOR in fwstate may not be cleared in time */
442 *pu8 = GLBtcWiFiInScanState;
445 case BTC_GET_BL_WIFI_LINK:
446 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
449 case BTC_GET_BL_WIFI_ROAM:
450 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
453 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
457 case BTC_GET_BL_WIFI_UNDER_5G:
458 *pu8 = pHalData->CurrentBandType == 1;
461 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
462 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
465 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
466 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? false : true;
469 case BTC_GET_BL_WIFI_UNDER_B_MODE:
470 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
476 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
480 case BTC_GET_BL_EXT_SWITCH:
484 case BTC_GET_S4_WIFI_RSSI:
485 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
488 case BTC_GET_S4_HS_RSSI:
493 case BTC_GET_U4_WIFI_BW:
494 if (IsLegacyOnly(mlmeext->cur_wireless_mode))
495 *pU4Tmp = BTC_WIFI_BW_LEGACY;
496 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
497 *pU4Tmp = BTC_WIFI_BW_HT20;
498 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
499 *pU4Tmp = BTC_WIFI_BW_HT40;
501 *pU4Tmp = BTC_WIFI_BW_HT40; /* todo */
504 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
506 PRT_LINK_DETECT_T plinkinfo;
507 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
509 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
510 *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
512 *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
516 case BTC_GET_U4_WIFI_FW_VER:
517 *pU4Tmp = pHalData->FirmwareVersion << 16;
518 *pU4Tmp |= pHalData->FirmwareSubVersion;
521 case BTC_GET_U4_WIFI_LINK_STATUS:
522 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
525 case BTC_GET_U4_BT_PATCH_VER:
526 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
529 case BTC_GET_U1_WIFI_DOT11_CHNL:
530 *pU1Tmp = padapter->mlmeextpriv.cur_channel;
533 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
534 *pU1Tmp = pHalData->CurrentChannel;
537 case BTC_GET_U1_WIFI_HS_CHNL:
542 case BTC_GET_U1_MAC_PHY_MODE:
544 /* *pU1Tmp = BTC_DMSP; */
545 /* *pU1Tmp = BTC_DMDP; */
546 /* *pU1Tmp = BTC_MP_UNKNOWN; */
549 case BTC_GET_U1_AP_NUM:
550 *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
553 /* 1Ant =========== */
554 case BTC_GET_U1_LPS_MODE:
555 *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
566 static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
568 PBTC_COEXIST pBtCoexist;
569 struct adapter *padapter;
570 struct hal_com_data *pHalData;
577 pBtCoexist = (PBTC_COEXIST)pBtcContext;
578 padapter = pBtCoexist->Adapter;
579 pHalData = GET_HAL_DATA(padapter);
585 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
589 /* set some u8 type variables. */
590 case BTC_SET_BL_BT_DISABLE:
591 pBtCoexist->btInfo.bBtDisabled = *pu8;
594 case BTC_SET_BL_BT_TRAFFIC_BUSY:
595 pBtCoexist->btInfo.bBtBusy = *pu8;
598 case BTC_SET_BL_BT_LIMITED_DIG:
599 pBtCoexist->btInfo.bLimitedDig = *pu8;
602 case BTC_SET_BL_FORCE_TO_ROAM:
603 pBtCoexist->btInfo.bForceToRoam = *pu8;
606 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
607 pBtCoexist->btInfo.bRejectAggPkt = *pu8;
610 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
611 pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
614 case BTC_SET_BL_INC_SCAN_DEV_NUM:
615 pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
618 case BTC_SET_BL_BT_TX_RX_MASK:
619 pBtCoexist->btInfo.bBtTxRxMask = *pu8;
622 /* set some u8 type variables. */
623 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
624 pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pU1Tmp;
627 case BTC_SET_U1_AGG_BUF_SIZE:
628 pBtCoexist->btInfo.aggBufSize = *pU1Tmp;
631 /* the following are some action which will be triggered */
632 case BTC_SET_ACT_GET_BT_RSSI:
636 case BTC_SET_ACT_AGGREGATE_CTRL:
637 halbtcoutsrc_AggregationCheck(pBtCoexist);
640 /* 1Ant =========== */
641 /* set some u8 type variables. */
642 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
643 pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pU1Tmp;
646 case BTC_SET_U1_LPS_VAL:
647 pBtCoexist->btInfo.lpsVal = *pU1Tmp;
650 case BTC_SET_U1_RPWM_VAL:
651 pBtCoexist->btInfo.rpwmVal = *pU1Tmp;
654 /* the following are some action which will be triggered */
655 case BTC_SET_ACT_LEAVE_LPS:
656 halbtcoutsrc_LeaveLps(pBtCoexist);
659 case BTC_SET_ACT_ENTER_LPS:
660 halbtcoutsrc_EnterLps(pBtCoexist);
663 case BTC_SET_ACT_NORMAL_LPS:
664 halbtcoutsrc_NormalLps(pBtCoexist);
667 case BTC_SET_ACT_DISABLE_LOW_POWER:
668 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
671 case BTC_SET_ACT_UPDATE_RAMASK:
672 pBtCoexist->btInfo.raMask = *pU4Tmp;
674 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true) {
675 struct sta_info *psta;
676 struct wlan_bssid_ex *cur_network;
678 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
679 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
680 rtw_hal_update_ra_mask(psta, 0);
684 case BTC_SET_ACT_SEND_MIMO_PS:
688 case BTC_SET_ACT_CTRL_BT_INFO:
692 case BTC_SET_ACT_CTRL_BT_COEX:
695 case BTC_SET_ACT_CTRL_8723B_ANT:
707 static void halbtcoutsrc_DisplayFwPwrModeCmd(PBTC_COEXIST pBtCoexist)
709 u8 *cliBuf = pBtCoexist->cliBuf;
711 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x ", "Power mode cmd ", \
712 pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
713 pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
714 pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5]);
719 /* IO related function */
721 static u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
723 PBTC_COEXIST pBtCoexist;
724 struct adapter *padapter;
727 pBtCoexist = (PBTC_COEXIST)pBtcContext;
728 padapter = pBtCoexist->Adapter;
730 return rtw_read8(padapter, RegAddr);
733 static u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
735 PBTC_COEXIST pBtCoexist;
736 struct adapter *padapter;
739 pBtCoexist = (PBTC_COEXIST)pBtcContext;
740 padapter = pBtCoexist->Adapter;
742 return rtw_read16(padapter, RegAddr);
745 static u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
747 PBTC_COEXIST pBtCoexist;
748 struct adapter *padapter;
751 pBtCoexist = (PBTC_COEXIST)pBtcContext;
752 padapter = pBtCoexist->Adapter;
754 return rtw_read32(padapter, RegAddr);
757 static void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
759 PBTC_COEXIST pBtCoexist;
760 struct adapter *padapter;
763 pBtCoexist = (PBTC_COEXIST)pBtcContext;
764 padapter = pBtCoexist->Adapter;
766 rtw_write8(padapter, RegAddr, Data);
769 static void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
771 PBTC_COEXIST pBtCoexist;
772 struct adapter *padapter;
773 u8 originalValue, bitShift;
777 pBtCoexist = (PBTC_COEXIST)pBtcContext;
778 padapter = pBtCoexist->Adapter;
782 if (bitMask != 0xFF) {
783 originalValue = rtw_read8(padapter, regAddr);
785 for (i = 0; i <= 7; i++) {
786 if ((bitMask>>i)&0x1)
791 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
794 rtw_write8(padapter, regAddr, data1b);
797 static void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
799 PBTC_COEXIST pBtCoexist;
800 struct adapter *padapter;
803 pBtCoexist = (PBTC_COEXIST)pBtcContext;
804 padapter = pBtCoexist->Adapter;
806 rtw_write16(padapter, RegAddr, Data);
809 static void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
811 PBTC_COEXIST pBtCoexist;
812 struct adapter *padapter;
815 pBtCoexist = (PBTC_COEXIST)pBtcContext;
816 padapter = pBtCoexist->Adapter;
818 rtw_write32(padapter, RegAddr, Data);
821 static void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
823 PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
824 struct adapter *Adapter = pBtCoexist->Adapter;
826 if (BTC_INTF_SDIO == pBtCoexist->chipInterface) {
827 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
829 rtw_write8(Adapter, RegAddr, Data);
833 static void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
835 PBTC_COEXIST pBtCoexist;
836 struct adapter *padapter;
839 pBtCoexist = (PBTC_COEXIST)pBtcContext;
840 padapter = pBtCoexist->Adapter;
842 PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
846 static u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
848 PBTC_COEXIST pBtCoexist;
849 struct adapter *padapter;
852 pBtCoexist = (PBTC_COEXIST)pBtcContext;
853 padapter = pBtCoexist->Adapter;
855 return PHY_QueryBBReg(padapter, RegAddr, BitMask);
858 static void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
860 PBTC_COEXIST pBtCoexist;
861 struct adapter *padapter;
864 pBtCoexist = (PBTC_COEXIST)pBtcContext;
865 padapter = pBtCoexist->Adapter;
867 PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
870 static u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
872 PBTC_COEXIST pBtCoexist;
873 struct adapter *padapter;
876 pBtCoexist = (PBTC_COEXIST)pBtcContext;
877 padapter = pBtCoexist->Adapter;
879 return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
882 static void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
884 PBTC_COEXIST pBtCoexist;
885 struct adapter *padapter;
886 u8 CmdBuffer1[4] = {0};
887 u8 CmdBuffer2[4] = {0};
888 u8 *AddrToSet = (u8 *)&RegAddr;
889 u8 *ValueToSet = (u8 *)&Data;
893 pBtCoexist = (PBTC_COEXIST)pBtcContext;
894 padapter = pBtCoexist->Adapter;
896 CmdBuffer1[0] |= (OperVer & 0x0f); /* Set OperVer */
897 CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
898 CmdBuffer1[1] = 0x0d; /* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */
899 CmdBuffer1[2] = ValueToSet[0]; /* Set WriteRegValue */
900 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0]));
905 CmdBuffer2[0] |= (OperVer & 0x0f); /* Set OperVer */
906 CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
907 CmdBuffer2[1] = 0x0c; /* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */
908 CmdBuffer2[3] = AddrToSet[0]; /* Set WriteRegAddr */
909 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0]));
912 static u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
914 /* To be implemented. Always return 0 temporarily */
918 static void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
920 PBTC_COEXIST pBtCoexist;
921 struct adapter *padapter;
924 pBtCoexist = (PBTC_COEXIST)pBtcContext;
925 padapter = pBtCoexist->Adapter;
927 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
930 static void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
932 PBTC_COEXIST pBtCoexist;
935 pBtCoexist = (PBTC_COEXIST)pBtcContext;
937 case BTC_DBG_DISP_COEX_STATISTICS:
939 case BTC_DBG_DISP_BT_LINK_INFO:
941 case BTC_DBG_DISP_FW_PWR_MODE_CMD:
942 halbtcoutsrc_DisplayFwPwrModeCmd(pBtCoexist);
950 /* Extern functions called by other module */
952 static u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
954 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
956 if (pBtCoexist->bBinded)
959 pBtCoexist->bBinded = true;
961 pBtCoexist->statistics.cntBind++;
963 pBtCoexist->Adapter = padapter;
965 pBtCoexist->stackInfo.bProfileNotified = false;
967 pBtCoexist->btInfo.bBtCtrlAggBufSize = false;
968 pBtCoexist->btInfo.aggBufSize = 5;
970 pBtCoexist->btInfo.bIncreaseScanDevNum = false;
972 /* set default antenna position to main port */
973 pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
978 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
980 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
982 /* pBtCoexist->statistics.cntBind++; */
984 halbtcoutsrc_DbgInit();
986 pBtCoexist->chipInterface = BTC_INTF_SDIO;
988 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
990 pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
991 pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
992 pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
993 pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
994 pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
995 pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
996 pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
997 pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
999 pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
1000 pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
1002 pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
1003 pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
1005 pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
1006 pBtCoexist->fBtcDispDbgMsg = halbtcoutsrc_DisplayDbgMsg;
1008 pBtCoexist->fBtcGet = halbtcoutsrc_Get;
1009 pBtCoexist->fBtcSet = halbtcoutsrc_Set;
1010 pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
1011 pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
1013 pBtCoexist->cliBuf = &GLBtcDbgBuf[0];
1015 pBtCoexist->boardInfo.singleAntPath = 0;
1017 GLBtcWiFiInScanState = false;
1019 GLBtcWiFiInIQKState = false;
1024 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
1026 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1029 /* Power on setting function is only added in 8723B currently */
1030 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1031 EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
1032 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1033 EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
1036 void EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
1038 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1041 pBtCoexist->statistics.cntInitHwConfig++;
1043 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1044 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1045 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1046 EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1049 void EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist)
1051 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1054 pBtCoexist->statistics.cntInitCoexDm++;
1056 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1057 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
1058 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1059 EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
1061 pBtCoexist->bInitilized = true;
1064 void EXhalbtcoutsrc_IpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1068 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1071 pBtCoexist->statistics.cntIpsNotify++;
1072 if (pBtCoexist->bManualControl)
1075 if (IPS_NONE == type)
1076 ipsType = BTC_IPS_LEAVE;
1078 ipsType = BTC_IPS_ENTER;
1080 /* All notify is called in cmd thread, don't need to leave low power again */
1081 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1083 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1084 EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
1085 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1086 EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
1088 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1091 void EXhalbtcoutsrc_LpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1096 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1099 pBtCoexist->statistics.cntLpsNotify++;
1100 if (pBtCoexist->bManualControl)
1103 if (PS_MODE_ACTIVE == type)
1104 lpsType = BTC_LPS_DISABLE;
1106 lpsType = BTC_LPS_ENABLE;
1108 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1109 EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
1110 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1111 EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
1114 void EXhalbtcoutsrc_ScanNotify(PBTC_COEXIST pBtCoexist, u8 type)
1118 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1120 pBtCoexist->statistics.cntScanNotify++;
1121 if (pBtCoexist->bManualControl)
1125 scanType = BTC_SCAN_START;
1126 GLBtcWiFiInScanState = true;
1128 scanType = BTC_SCAN_FINISH;
1129 GLBtcWiFiInScanState = false;
1132 /* All notify is called in cmd thread, don't need to leave low power again */
1133 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1135 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1136 EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
1137 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1138 EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
1140 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1143 void EXhalbtcoutsrc_ConnectNotify(PBTC_COEXIST pBtCoexist, u8 action)
1147 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1149 pBtCoexist->statistics.cntConnectNotify++;
1150 if (pBtCoexist->bManualControl)
1154 assoType = BTC_ASSOCIATE_START;
1156 assoType = BTC_ASSOCIATE_FINISH;
1158 /* All notify is called in cmd thread, don't need to leave low power again */
1159 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1161 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1162 EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
1163 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1164 EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
1166 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1169 void EXhalbtcoutsrc_MediaStatusNotify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
1173 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1176 pBtCoexist->statistics.cntMediaStatusNotify++;
1177 if (pBtCoexist->bManualControl)
1180 if (RT_MEDIA_CONNECT == mediaStatus)
1181 mStatus = BTC_MEDIA_CONNECT;
1183 mStatus = BTC_MEDIA_DISCONNECT;
1185 /* All notify is called in cmd thread, don't need to leave low power again */
1186 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1188 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1189 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
1190 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1191 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
1193 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1196 void EXhalbtcoutsrc_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 pktType)
1200 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1202 pBtCoexist->statistics.cntSpecialPacketNotify++;
1203 if (pBtCoexist->bManualControl)
1206 if (PACKET_DHCP == pktType)
1207 packetType = BTC_PACKET_DHCP;
1208 else if (PACKET_EAPOL == pktType)
1209 packetType = BTC_PACKET_EAPOL;
1210 else if (PACKET_ARP == pktType)
1211 packetType = BTC_PACKET_ARP;
1213 packetType = BTC_PACKET_UNKNOWN;
1217 /* All notify is called in cmd thread, don't need to leave low power again */
1218 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1220 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1221 EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
1222 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1223 EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
1225 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1228 void EXhalbtcoutsrc_BtInfoNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
1230 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1233 pBtCoexist->statistics.cntBtInfoNotify++;
1235 /* All notify is called in cmd thread, don't need to leave low power again */
1236 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1238 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1239 EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1240 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1241 EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1243 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1246 void EXhalbtcoutsrc_HaltNotify(PBTC_COEXIST pBtCoexist)
1248 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1251 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1252 EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
1253 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1254 EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
1256 pBtCoexist->bBinded = false;
1259 void EXhalbtcoutsrc_PnpNotify(PBTC_COEXIST pBtCoexist, u8 pnpState)
1261 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1265 /* currently only 1ant we have to do the notification, */
1266 /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */
1269 if (pBtCoexist->boardInfo.btdmAntNum == 1)
1270 EXhalbtc8723b1ant_PnpNotify(pBtCoexist, pnpState);
1271 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1272 EXhalbtc8723b2ant_PnpNotify(pBtCoexist, pnpState);
1275 void EXhalbtcoutsrc_Periodical(PBTC_COEXIST pBtCoexist)
1277 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1279 pBtCoexist->statistics.cntPeriodical++;
1281 /* Periodical should be called in cmd thread, */
1282 /* don't need to leave low power again */
1283 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1285 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1286 EXhalbtc8723b2ant_Periodical(pBtCoexist);
1287 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1288 EXhalbtc8723b1ant_Periodical(pBtCoexist);
1290 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1293 void EXhalbtcoutsrc_SetChipType(u8 chipType)
1295 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
1298 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
1300 if (BT_COEX_ANT_TYPE_PG == type) {
1301 GLBtCoexist.boardInfo.pgAntNum = antNum;
1302 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1303 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1304 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1305 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1306 } else if (BT_COEX_ANT_TYPE_DETECTED == type) {
1307 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1308 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1313 /* Currently used by 8723b only, S0 or S1 */
1315 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
1317 GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
1320 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
1322 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1325 halbtcoutsrc_LeaveLowPower(pBtCoexist);
1327 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1328 EXhalbtc8723b2ant_DisplayCoexInfo(pBtCoexist);
1329 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1330 EXhalbtc8723b1ant_DisplayCoexInfo(pBtCoexist);
1332 halbtcoutsrc_NormalLowPower(pBtCoexist);
1337 *Run BT-Coexist mechansim or not
1340 void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist)
1342 struct hal_com_data *pHalData;
1345 pHalData = GET_HAL_DATA(padapter);
1346 pHalData->bt_coexist.bBtExist = bBtExist;
1351 *Check is co-exist mechanism enabled or not
1354 *true Enable BT co-exist mechanism
1355 *false Disable BT co-exist mechanism
1357 u8 hal_btcoex_IsBtExist(struct adapter *padapter)
1359 struct hal_com_data *pHalData;
1362 pHalData = GET_HAL_DATA(padapter);
1363 return pHalData->bt_coexist.bBtExist;
1366 u8 hal_btcoex_IsBtDisabled(struct adapter *padapter)
1368 if (!hal_btcoex_IsBtExist(padapter))
1371 if (GLBtCoexist.btInfo.bBtDisabled)
1377 void hal_btcoex_SetChipType(struct adapter *padapter, u8 chipType)
1379 struct hal_com_data *pHalData;
1382 pHalData = GET_HAL_DATA(padapter);
1383 pHalData->bt_coexist.btChipType = chipType;
1385 EXhalbtcoutsrc_SetChipType(chipType);
1388 void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum)
1390 struct hal_com_data *pHalData;
1393 pHalData = GET_HAL_DATA(padapter);
1395 pHalData->bt_coexist.btTotalAntNum = antNum;
1396 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1399 void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath)
1401 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
1404 u8 hal_btcoex_Initialize(struct adapter *padapter)
1406 memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
1407 return EXhalbtcoutsrc_InitlizeVariables((void *)padapter);
1410 void hal_btcoex_PowerOnSetting(struct adapter *padapter)
1412 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
1415 void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly)
1417 if (!hal_btcoex_IsBtExist(padapter))
1420 EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
1421 EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
1424 void hal_btcoex_IpsNotify(struct adapter *padapter, u8 type)
1426 EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
1429 void hal_btcoex_LpsNotify(struct adapter *padapter, u8 type)
1431 EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
1434 void hal_btcoex_ScanNotify(struct adapter *padapter, u8 type)
1436 EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
1439 void hal_btcoex_ConnectNotify(struct adapter *padapter, u8 action)
1441 EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
1444 void hal_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus)
1446 EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
1449 void hal_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType)
1451 EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
1454 void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state)
1456 GLBtcWiFiInIQKState = state;
1459 void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf)
1461 if (GLBtcWiFiInIQKState == true)
1464 EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
1467 void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state)
1470 state = BTC_WIFI_PNP_SLEEP;
1472 state = BTC_WIFI_PNP_WAKE_UP;
1474 EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
1477 void hal_btcoex_HaltNotify(struct adapter *padapter)
1479 EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
1482 void hal_btcoex_Hanlder(struct adapter *padapter)
1484 EXhalbtcoutsrc_Periodical(&GLBtCoexist);
1487 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter)
1489 return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
1492 void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual)
1494 GLBtCoexist.bManualControl = bmanual;
1497 u8 hal_btcoex_IsBtControlLps(struct adapter *padapter)
1499 if (hal_btcoex_IsBtExist(padapter) == false)
1502 if (GLBtCoexist.btInfo.bBtDisabled)
1505 if (GLBtCoexist.btInfo.bBtCtrlLps)
1511 u8 hal_btcoex_IsLpsOn(struct adapter *padapter)
1513 if (hal_btcoex_IsBtExist(padapter) == false)
1516 if (GLBtCoexist.btInfo.bBtDisabled)
1519 if (GLBtCoexist.btInfo.bBtLpsOn)
1525 u8 hal_btcoex_RpwmVal(struct adapter *padapter)
1527 return GLBtCoexist.btInfo.rpwmVal;
1530 u8 hal_btcoex_LpsVal(struct adapter *padapter)
1532 return GLBtCoexist.btInfo.lpsVal;
1535 u32 hal_btcoex_GetRaMask(struct adapter *padapter)
1537 if (!hal_btcoex_IsBtExist(padapter))
1540 if (GLBtCoexist.btInfo.bBtDisabled)
1543 if (GLBtCoexist.boardInfo.btdmAntNum != 1)
1546 return GLBtCoexist.btInfo.raMask;
1549 void hal_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen)
1551 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write pwrModeCmd = 0x%04x%08x\n",
1552 pCmdBuf[0]<<8|pCmdBuf[1],
1553 pCmdBuf[2]<<24|pCmdBuf[3]<<16|pCmdBuf[4]<<8|pCmdBuf[5]));
1555 memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
1558 void hal_btcoex_DisplayBtCoexInfo(struct adapter *padapter, u8 *pbuf, u32 bufsize)
1563 pinfo = &GLBtcDbgInfo;
1564 DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
1565 EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
1566 DBG_BT_INFO_INIT(pinfo, NULL, 0);
1569 void hal_btcoex_SetDBG(struct adapter *padapter, u32 *pDbgModule)
1574 if (NULL == pDbgModule)
1577 for (i = 0; i < BTC_MSG_MAX; i++)
1578 GLBtcDbgType[i] = pDbgModule[i];
1581 u32 hal_btcoex_GetDBG(struct adapter *padapter, u8 *pStrBuf, u32 bufSize)
1588 if ((NULL == pStrBuf) || (0 == bufSize))
1593 /* DBG_871X(FUNC_ADPT_FMT ": bufsize =%d\n", FUNC_ADPT_ARG(padapter), bufSize); */
1595 count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
1596 if ((count < 0) || (count >= leftSize))
1601 count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
1602 if ((count < 0) || (count >= leftSize))
1607 count = rtw_sprintf(pstr, leftSize,
1608 "INTERFACE / ALGORITHM: 0x%08X / 0x%08X\n\n",
1609 GLBtcDbgType[BTC_MSG_INTERFACE],
1610 GLBtcDbgType[BTC_MSG_ALGORITHM]);
1611 if ((count < 0) || (count >= leftSize))
1616 count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
1617 if ((count < 0) || (count >= leftSize))
1621 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
1622 (GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_INIT)?1:0);
1623 if ((count < 0) || (count >= leftSize))
1627 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
1628 (GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_NOTIFY)?1:0);
1629 if ((count < 0) || (count >= leftSize))
1634 count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
1635 if ((count < 0) || (count >= leftSize))
1639 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
1640 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_RSSI_STATE)?1:0);
1641 if ((count < 0) || (count >= leftSize))
1645 count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
1646 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_WIFI_RSSI_STATE)?1:0);
1647 if ((count < 0) || (count >= leftSize))
1651 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
1652 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_MONITOR)?1:0);
1653 if ((count < 0) || (count >= leftSize))
1657 count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
1658 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE)?1:0);
1659 if ((count < 0) || (count >= leftSize))
1663 count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
1664 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW)?1:0);
1665 if ((count < 0) || (count >= leftSize))
1669 count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
1670 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_DETAIL)?1:0);
1671 if ((count < 0) || (count >= leftSize))
1675 count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
1676 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_EXEC)?1:0);
1677 if ((count < 0) || (count >= leftSize))
1681 count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
1682 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW)?1:0);
1683 if ((count < 0) || (count >= leftSize))
1687 count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
1688 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_DETAIL)?1:0);
1689 if ((count < 0) || (count >= leftSize))
1693 count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
1694 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_EXEC)?1:0);
1695 if ((count < 0) || (count >= leftSize))
1701 count = pstr - pStrBuf;
1702 /* DBG_871X(FUNC_ADPT_FMT ": usedsize =%d\n", FUNC_ADPT_ARG(padapter), count); */