1 /******************************************************************************
3 * Copyright(c) 2013 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
15 #define __HAL_BTCOEX_C__
18 #include <rtw_debug.h>
19 #include <hal_btcoex.h>
20 #include <Mp_Precomp.h>
22 /* Global variables */
23 static const char *const BtProfileString[] = {
31 static const char *const BtSpecString[] = {
41 static const char *const BtLinkRoleString[] = {
46 static const char *const h2cStaString[] = {
53 static const char *const ioStaString[] = {
67 BTC_COEXIST GLBtCoexist;
68 static u8 GLBtcWiFiInScanState;
69 static u8 GLBtcWiFiInIQKState;
71 u32 GLBtcDbgType[BTC_MSG_MAX];
72 static u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
74 typedef struct _btcoexdbginfo {
76 u32 size; /* buffer total size */
77 u32 len; /* now used length */
78 } BTCDBGINFO, *PBTCDBGINFO;
80 static BTCDBGINFO GLBtcDbgInfo;
82 #define BT_Operation(Adapter) false
84 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
89 memset(pinfo, 0, sizeof(BTCDBGINFO));
97 void DBG_BT_INFO(u8 *dbgmsg)
104 pinfo = &GLBtcDbgInfo;
106 if (NULL == pinfo->info)
109 msglen = strlen(dbgmsg);
110 if (pinfo->len + msglen > pinfo->size)
113 pbuf = pinfo->info + pinfo->len;
114 memcpy(pbuf, dbgmsg, msglen);
115 pinfo->len += msglen;
119 /* Debug related function */
121 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
123 if (!pBtCoexist->bBinded ||
124 NULL == pBtCoexist->Adapter){
130 static void halbtcoutsrc_DbgInit(void)
134 for (i = 0; i < BTC_MSG_MAX; i++)
137 GLBtcDbgType[BTC_MSG_INTERFACE] = \
142 GLBtcDbgType[BTC_MSG_ALGORITHM] = \
143 /* ALGO_BT_RSSI_STATE | */
144 /* ALGO_WIFI_RSSI_STATE | */
145 /* ALGO_BT_MONITOR | */
147 /* ALGO_TRACE_FW | */
148 /* ALGO_TRACE_FW_DETAIL | */
149 /* ALGO_TRACE_FW_EXEC | */
150 /* ALGO_TRACE_SW | */
151 /* ALGO_TRACE_SW_DETAIL | */
152 /* ALGO_TRACE_SW_EXEC | */
156 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
158 struct adapter *padapter;
161 padapter = pBtCoexist->Adapter;
163 pBtCoexist->btInfo.bBtCtrlLps = true;
164 pBtCoexist->btInfo.bBtLpsOn = false;
166 rtw_btcoex_LPS_Leave(padapter);
169 static void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
171 struct adapter *padapter;
174 padapter = pBtCoexist->Adapter;
176 pBtCoexist->btInfo.bBtCtrlLps = true;
177 pBtCoexist->btInfo.bBtLpsOn = true;
179 rtw_btcoex_LPS_Enter(padapter);
182 static void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
184 struct adapter *padapter;
187 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Normal LPS behavior!!!\n"));
189 padapter = pBtCoexist->Adapter;
191 if (pBtCoexist->btInfo.bBtCtrlLps) {
192 pBtCoexist->btInfo.bBtLpsOn = false;
193 rtw_btcoex_LPS_Leave(padapter);
194 pBtCoexist->btInfo.bBtCtrlLps = false;
196 /* recover the LPS state to the original */
202 * 1. this function will request pwrctrl->lock
204 static void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
206 struct adapter *padapter;
207 struct hal_com_data *pHalData;
211 u32 timeout; /* unit: ms */
214 padapter = pBtCoexist->Adapter;
215 pHalData = GET_HAL_DATA(padapter);
217 #ifdef LPS_RPWM_WAIT_MS
218 timeout = LPS_RPWM_WAIT_MS;
219 #else /* !LPS_RPWM_WAIT_MS */
221 #endif /* !LPS_RPWM_WAIT_MS */
225 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
226 if (_SUCCESS == ready)
229 utime = jiffies_to_msecs(jiffies - stime);
239 * 1. this function will request pwrctrl->lock
241 static void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
243 struct adapter *padapter;
246 padapter = pBtCoexist->Adapter;
247 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
250 static void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
252 pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
254 halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */
256 halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */
259 static void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
261 struct adapter *padapter;
265 padapter = pBtCoexist->Adapter;
268 if (pBtCoexist->btInfo.bRejectAggPkt)
269 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
272 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
273 pBtCoexist->btInfo.bBtCtrlAggBufSize){
276 pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
279 if (pBtCoexist->btInfo.bBtCtrlAggBufSize) {
280 if (pBtCoexist->btInfo.preAggBufSize !=
281 pBtCoexist->btInfo.aggBufSize){
284 pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
288 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
289 rtw_btcoex_RejectApAggregatedPacket(padapter, false);
294 static u8 halbtcoutsrc_IsWifiBusy(struct adapter *padapter)
296 struct mlme_priv *pmlmepriv;
299 pmlmepriv = &padapter->mlmepriv;
301 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
302 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
304 if (true == pmlmepriv->LinkDetectInfo.bBusyTraffic)
311 static u32 _halbtcoutsrc_GetWifiLinkStatus(struct adapter *padapter)
313 struct mlme_priv *pmlmepriv;
315 u32 portConnectedStatus;
318 pmlmepriv = &padapter->mlmepriv;
320 portConnectedStatus = 0;
322 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
323 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
325 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
327 portConnectedStatus |= WIFI_AP_CONNECTED;
330 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
332 portConnectedStatus |= WIFI_STA_CONNECTED;
336 return portConnectedStatus;
339 static u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
343 /* [31:16]=> connected port number */
344 /* [15:0]=> port connected bit define */
347 struct adapter *padapter;
349 u32 portConnectedStatus, numOfConnectedPort;
352 padapter = pBtCoexist->Adapter;
353 portConnectedStatus = 0;
354 numOfConnectedPort = 0;
356 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
358 portConnectedStatus |= retVal;
359 numOfConnectedPort++;
362 retVal = (numOfConnectedPort << 16) | portConnectedStatus;
367 static u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
369 return pBtCoexist->btInfo.btRealFwVer;
372 static s32 halbtcoutsrc_GetWifiRssi(struct adapter *padapter)
374 struct hal_com_data *pHalData;
375 s32 UndecoratedSmoothedPWDB = 0;
378 pHalData = GET_HAL_DATA(padapter);
380 UndecoratedSmoothedPWDB = pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
382 return UndecoratedSmoothedPWDB;
385 static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter)
387 struct mlme_ext_priv *pmlmeext;
388 static u8 scan_AP_num;
390 pmlmeext = &padapter->mlmeextpriv;
392 if (GLBtcWiFiInScanState == false) {
393 if (pmlmeext->sitesurvey_res.bss_cnt > 0xFF)
396 scan_AP_num = (u8)pmlmeext->sitesurvey_res.bss_cnt;
402 static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
404 PBTC_COEXIST pBtCoexist;
405 struct adapter *padapter;
406 struct hal_com_data *pHalData;
407 struct mlme_ext_priv *mlmeext;
415 pBtCoexist = (PBTC_COEXIST)pBtcContext;
416 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
419 padapter = pBtCoexist->Adapter;
420 pHalData = GET_HAL_DATA(padapter);
421 mlmeext = &padapter->mlmeextpriv;
429 case BTC_GET_BL_HS_OPERATION:
434 case BTC_GET_BL_HS_CONNECTING:
439 case BTC_GET_BL_WIFI_CONNECTED:
440 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
443 case BTC_GET_BL_WIFI_BUSY:
444 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
447 case BTC_GET_BL_WIFI_SCAN:
448 /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
449 WIFI_SITE_MONITOR in fwstate may not be cleared in time */
450 *pu8 = GLBtcWiFiInScanState;
453 case BTC_GET_BL_WIFI_LINK:
454 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
457 case BTC_GET_BL_WIFI_ROAM:
458 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
461 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
465 case BTC_GET_BL_WIFI_UNDER_5G:
466 *pu8 = (pHalData->CurrentBandType == 1) ? true : false;
469 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
470 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
473 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
474 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? false : true;
477 case BTC_GET_BL_WIFI_UNDER_B_MODE:
478 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
484 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
488 case BTC_GET_BL_EXT_SWITCH:
492 case BTC_GET_S4_WIFI_RSSI:
493 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
496 case BTC_GET_S4_HS_RSSI:
501 case BTC_GET_U4_WIFI_BW:
502 if (IsLegacyOnly(mlmeext->cur_wireless_mode))
503 *pU4Tmp = BTC_WIFI_BW_LEGACY;
504 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
505 *pU4Tmp = BTC_WIFI_BW_HT20;
506 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
507 *pU4Tmp = BTC_WIFI_BW_HT40;
509 *pU4Tmp = BTC_WIFI_BW_HT40; /* todo */
512 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
514 PRT_LINK_DETECT_T plinkinfo;
515 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
517 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
518 *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
520 *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
524 case BTC_GET_U4_WIFI_FW_VER:
525 *pU4Tmp = pHalData->FirmwareVersion << 16;
526 *pU4Tmp |= pHalData->FirmwareSubVersion;
529 case BTC_GET_U4_WIFI_LINK_STATUS:
530 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
533 case BTC_GET_U4_BT_PATCH_VER:
534 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
537 case BTC_GET_U1_WIFI_DOT11_CHNL:
538 *pU1Tmp = padapter->mlmeextpriv.cur_channel;
541 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
542 *pU1Tmp = pHalData->CurrentChannel;
545 case BTC_GET_U1_WIFI_HS_CHNL:
550 case BTC_GET_U1_MAC_PHY_MODE:
552 /* *pU1Tmp = BTC_DMSP; */
553 /* *pU1Tmp = BTC_DMDP; */
554 /* *pU1Tmp = BTC_MP_UNKNOWN; */
557 case BTC_GET_U1_AP_NUM:
558 *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
561 /* 1Ant =========== */
562 case BTC_GET_U1_LPS_MODE:
563 *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
574 static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
576 PBTC_COEXIST pBtCoexist;
577 struct adapter *padapter;
578 struct hal_com_data *pHalData;
585 pBtCoexist = (PBTC_COEXIST)pBtcContext;
586 padapter = pBtCoexist->Adapter;
587 pHalData = GET_HAL_DATA(padapter);
593 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
597 /* set some u8 type variables. */
598 case BTC_SET_BL_BT_DISABLE:
599 pBtCoexist->btInfo.bBtDisabled = *pu8;
602 case BTC_SET_BL_BT_TRAFFIC_BUSY:
603 pBtCoexist->btInfo.bBtBusy = *pu8;
606 case BTC_SET_BL_BT_LIMITED_DIG:
607 pBtCoexist->btInfo.bLimitedDig = *pu8;
610 case BTC_SET_BL_FORCE_TO_ROAM:
611 pBtCoexist->btInfo.bForceToRoam = *pu8;
614 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
615 pBtCoexist->btInfo.bRejectAggPkt = *pu8;
618 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
619 pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
622 case BTC_SET_BL_INC_SCAN_DEV_NUM:
623 pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
626 case BTC_SET_BL_BT_TX_RX_MASK:
627 pBtCoexist->btInfo.bBtTxRxMask = *pu8;
630 /* set some u8 type variables. */
631 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
632 pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pU1Tmp;
635 case BTC_SET_U1_AGG_BUF_SIZE:
636 pBtCoexist->btInfo.aggBufSize = *pU1Tmp;
639 /* the following are some action which will be triggered */
640 case BTC_SET_ACT_GET_BT_RSSI:
644 case BTC_SET_ACT_AGGREGATE_CTRL:
645 halbtcoutsrc_AggregationCheck(pBtCoexist);
648 /* 1Ant =========== */
649 /* set some u8 type variables. */
650 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
651 pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pU1Tmp;
654 case BTC_SET_U1_LPS_VAL:
655 pBtCoexist->btInfo.lpsVal = *pU1Tmp;
658 case BTC_SET_U1_RPWM_VAL:
659 pBtCoexist->btInfo.rpwmVal = *pU1Tmp;
662 /* the following are some action which will be triggered */
663 case BTC_SET_ACT_LEAVE_LPS:
664 halbtcoutsrc_LeaveLps(pBtCoexist);
667 case BTC_SET_ACT_ENTER_LPS:
668 halbtcoutsrc_EnterLps(pBtCoexist);
671 case BTC_SET_ACT_NORMAL_LPS:
672 halbtcoutsrc_NormalLps(pBtCoexist);
675 case BTC_SET_ACT_DISABLE_LOW_POWER:
676 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
679 case BTC_SET_ACT_UPDATE_RAMASK:
680 pBtCoexist->btInfo.raMask = *pU4Tmp;
682 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true) {
683 struct sta_info *psta;
684 struct wlan_bssid_ex *cur_network;
686 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
687 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
688 rtw_hal_update_ra_mask(psta, 0);
692 case BTC_SET_ACT_SEND_MIMO_PS:
696 case BTC_SET_ACT_CTRL_BT_INFO:
700 case BTC_SET_ACT_CTRL_BT_COEX:
703 case BTC_SET_ACT_CTRL_8723B_ANT:
715 static void halbtcoutsrc_DisplayFwPwrModeCmd(PBTC_COEXIST pBtCoexist)
717 u8 *cliBuf = pBtCoexist->cliBuf;
719 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x ", "Power mode cmd ", \
720 pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
721 pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
722 pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5]);
727 /* IO related function */
729 static u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
731 PBTC_COEXIST pBtCoexist;
732 struct adapter *padapter;
735 pBtCoexist = (PBTC_COEXIST)pBtcContext;
736 padapter = pBtCoexist->Adapter;
738 return rtw_read8(padapter, RegAddr);
741 static u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
743 PBTC_COEXIST pBtCoexist;
744 struct adapter *padapter;
747 pBtCoexist = (PBTC_COEXIST)pBtcContext;
748 padapter = pBtCoexist->Adapter;
750 return rtw_read16(padapter, RegAddr);
753 static u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
755 PBTC_COEXIST pBtCoexist;
756 struct adapter *padapter;
759 pBtCoexist = (PBTC_COEXIST)pBtcContext;
760 padapter = pBtCoexist->Adapter;
762 return rtw_read32(padapter, RegAddr);
765 static void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
767 PBTC_COEXIST pBtCoexist;
768 struct adapter *padapter;
771 pBtCoexist = (PBTC_COEXIST)pBtcContext;
772 padapter = pBtCoexist->Adapter;
774 rtw_write8(padapter, RegAddr, Data);
777 static void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
779 PBTC_COEXIST pBtCoexist;
780 struct adapter *padapter;
781 u8 originalValue, bitShift;
785 pBtCoexist = (PBTC_COEXIST)pBtcContext;
786 padapter = pBtCoexist->Adapter;
790 if (bitMask != 0xFF) {
791 originalValue = rtw_read8(padapter, regAddr);
793 for (i = 0; i <= 7; i++) {
794 if ((bitMask>>i)&0x1)
799 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
802 rtw_write8(padapter, regAddr, data1b);
805 static void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
807 PBTC_COEXIST pBtCoexist;
808 struct adapter *padapter;
811 pBtCoexist = (PBTC_COEXIST)pBtcContext;
812 padapter = pBtCoexist->Adapter;
814 rtw_write16(padapter, RegAddr, Data);
817 static void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
819 PBTC_COEXIST pBtCoexist;
820 struct adapter *padapter;
823 pBtCoexist = (PBTC_COEXIST)pBtcContext;
824 padapter = pBtCoexist->Adapter;
826 rtw_write32(padapter, RegAddr, Data);
829 static void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
831 PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
832 struct adapter *Adapter = pBtCoexist->Adapter;
834 if (BTC_INTF_SDIO == pBtCoexist->chipInterface) {
835 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
837 rtw_write8(Adapter, RegAddr, Data);
841 static void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
843 PBTC_COEXIST pBtCoexist;
844 struct adapter *padapter;
847 pBtCoexist = (PBTC_COEXIST)pBtcContext;
848 padapter = pBtCoexist->Adapter;
850 PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
854 static u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
856 PBTC_COEXIST pBtCoexist;
857 struct adapter *padapter;
860 pBtCoexist = (PBTC_COEXIST)pBtcContext;
861 padapter = pBtCoexist->Adapter;
863 return PHY_QueryBBReg(padapter, RegAddr, BitMask);
866 static void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
868 PBTC_COEXIST pBtCoexist;
869 struct adapter *padapter;
872 pBtCoexist = (PBTC_COEXIST)pBtcContext;
873 padapter = pBtCoexist->Adapter;
875 PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
878 static u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
880 PBTC_COEXIST pBtCoexist;
881 struct adapter *padapter;
884 pBtCoexist = (PBTC_COEXIST)pBtcContext;
885 padapter = pBtCoexist->Adapter;
887 return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
890 static void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
892 PBTC_COEXIST pBtCoexist;
893 struct adapter *padapter;
894 u8 CmdBuffer1[4] = {0};
895 u8 CmdBuffer2[4] = {0};
896 u8 *AddrToSet = (u8 *)&RegAddr;
897 u8 *ValueToSet = (u8 *)&Data;
901 pBtCoexist = (PBTC_COEXIST)pBtcContext;
902 padapter = pBtCoexist->Adapter;
904 CmdBuffer1[0] |= (OperVer & 0x0f); /* Set OperVer */
905 CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
906 CmdBuffer1[1] = 0x0d; /* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */
907 CmdBuffer1[2] = ValueToSet[0]; /* Set WriteRegValue */
908 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0]));
913 CmdBuffer2[0] |= (OperVer & 0x0f); /* Set OperVer */
914 CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */
915 CmdBuffer2[1] = 0x0c; /* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */
916 CmdBuffer2[3] = AddrToSet[0]; /* Set WriteRegAddr */
917 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0]));
920 static u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
922 /* To be implemented. Always return 0 temporarily */
926 static void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
928 PBTC_COEXIST pBtCoexist;
929 struct adapter *padapter;
932 pBtCoexist = (PBTC_COEXIST)pBtcContext;
933 padapter = pBtCoexist->Adapter;
935 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
938 static void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
940 PBTC_COEXIST pBtCoexist;
943 pBtCoexist = (PBTC_COEXIST)pBtcContext;
945 case BTC_DBG_DISP_COEX_STATISTICS:
947 case BTC_DBG_DISP_BT_LINK_INFO:
949 case BTC_DBG_DISP_FW_PWR_MODE_CMD:
950 halbtcoutsrc_DisplayFwPwrModeCmd(pBtCoexist);
958 /* Extern functions called by other module */
960 static u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
962 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
964 if (pBtCoexist->bBinded)
967 pBtCoexist->bBinded = true;
969 pBtCoexist->statistics.cntBind++;
971 pBtCoexist->Adapter = padapter;
973 pBtCoexist->stackInfo.bProfileNotified = false;
975 pBtCoexist->btInfo.bBtCtrlAggBufSize = false;
976 pBtCoexist->btInfo.aggBufSize = 5;
978 pBtCoexist->btInfo.bIncreaseScanDevNum = false;
980 /* set default antenna position to main port */
981 pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
986 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
988 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
990 /* pBtCoexist->statistics.cntBind++; */
992 halbtcoutsrc_DbgInit();
994 pBtCoexist->chipInterface = BTC_INTF_SDIO;
996 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
998 pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
999 pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
1000 pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
1001 pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
1002 pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
1003 pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
1004 pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
1005 pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
1007 pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
1008 pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
1010 pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
1011 pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
1013 pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
1014 pBtCoexist->fBtcDispDbgMsg = halbtcoutsrc_DisplayDbgMsg;
1016 pBtCoexist->fBtcGet = halbtcoutsrc_Get;
1017 pBtCoexist->fBtcSet = halbtcoutsrc_Set;
1018 pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
1019 pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
1021 pBtCoexist->cliBuf = &GLBtcDbgBuf[0];
1023 pBtCoexist->boardInfo.singleAntPath = 0;
1025 GLBtcWiFiInScanState = false;
1027 GLBtcWiFiInIQKState = false;
1032 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
1034 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1037 /* Power on setting function is only added in 8723B currently */
1038 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1039 EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
1040 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1041 EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
1044 void EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
1046 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1049 pBtCoexist->statistics.cntInitHwConfig++;
1051 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1052 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1053 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1054 EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1057 void EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist)
1059 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1062 pBtCoexist->statistics.cntInitCoexDm++;
1064 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1065 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
1066 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1067 EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
1069 pBtCoexist->bInitilized = true;
1072 void EXhalbtcoutsrc_IpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1076 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1079 pBtCoexist->statistics.cntIpsNotify++;
1080 if (pBtCoexist->bManualControl)
1083 if (IPS_NONE == type)
1084 ipsType = BTC_IPS_LEAVE;
1086 ipsType = BTC_IPS_ENTER;
1088 /* All notify is called in cmd thread, don't need to leave low power again */
1089 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1091 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1092 EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
1093 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1094 EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
1096 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1099 void EXhalbtcoutsrc_LpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1104 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1107 pBtCoexist->statistics.cntLpsNotify++;
1108 if (pBtCoexist->bManualControl)
1111 if (PS_MODE_ACTIVE == type)
1112 lpsType = BTC_LPS_DISABLE;
1114 lpsType = BTC_LPS_ENABLE;
1116 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1117 EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
1118 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1119 EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
1122 void EXhalbtcoutsrc_ScanNotify(PBTC_COEXIST pBtCoexist, u8 type)
1126 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1128 pBtCoexist->statistics.cntScanNotify++;
1129 if (pBtCoexist->bManualControl)
1133 scanType = BTC_SCAN_START;
1134 GLBtcWiFiInScanState = true;
1136 scanType = BTC_SCAN_FINISH;
1137 GLBtcWiFiInScanState = false;
1140 /* All notify is called in cmd thread, don't need to leave low power again */
1141 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1143 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1144 EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
1145 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1146 EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
1148 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1151 void EXhalbtcoutsrc_ConnectNotify(PBTC_COEXIST pBtCoexist, u8 action)
1155 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1157 pBtCoexist->statistics.cntConnectNotify++;
1158 if (pBtCoexist->bManualControl)
1162 assoType = BTC_ASSOCIATE_START;
1164 assoType = BTC_ASSOCIATE_FINISH;
1166 /* All notify is called in cmd thread, don't need to leave low power again */
1167 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1169 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1170 EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
1171 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1172 EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
1174 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1177 void EXhalbtcoutsrc_MediaStatusNotify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
1181 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1184 pBtCoexist->statistics.cntMediaStatusNotify++;
1185 if (pBtCoexist->bManualControl)
1188 if (RT_MEDIA_CONNECT == mediaStatus)
1189 mStatus = BTC_MEDIA_CONNECT;
1191 mStatus = BTC_MEDIA_DISCONNECT;
1193 /* All notify is called in cmd thread, don't need to leave low power again */
1194 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1196 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1197 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
1198 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1199 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
1201 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1204 void EXhalbtcoutsrc_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 pktType)
1208 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1210 pBtCoexist->statistics.cntSpecialPacketNotify++;
1211 if (pBtCoexist->bManualControl)
1214 if (PACKET_DHCP == pktType)
1215 packetType = BTC_PACKET_DHCP;
1216 else if (PACKET_EAPOL == pktType)
1217 packetType = BTC_PACKET_EAPOL;
1218 else if (PACKET_ARP == pktType)
1219 packetType = BTC_PACKET_ARP;
1221 packetType = BTC_PACKET_UNKNOWN;
1225 /* All notify is called in cmd thread, don't need to leave low power again */
1226 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1228 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1229 EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
1230 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1231 EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
1233 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1236 void EXhalbtcoutsrc_BtInfoNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
1238 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1241 pBtCoexist->statistics.cntBtInfoNotify++;
1243 /* All notify is called in cmd thread, don't need to leave low power again */
1244 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1246 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1247 EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1248 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1249 EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1251 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1254 void EXhalbtcoutsrc_HaltNotify(PBTC_COEXIST pBtCoexist)
1256 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1259 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1260 EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
1261 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1262 EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
1264 pBtCoexist->bBinded = false;
1267 void EXhalbtcoutsrc_PnpNotify(PBTC_COEXIST pBtCoexist, u8 pnpState)
1269 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1273 /* currently only 1ant we have to do the notification, */
1274 /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */
1277 if (pBtCoexist->boardInfo.btdmAntNum == 1)
1278 EXhalbtc8723b1ant_PnpNotify(pBtCoexist, pnpState);
1279 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1280 EXhalbtc8723b2ant_PnpNotify(pBtCoexist, pnpState);
1283 void EXhalbtcoutsrc_Periodical(PBTC_COEXIST pBtCoexist)
1285 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1287 pBtCoexist->statistics.cntPeriodical++;
1289 /* Periodical should be called in cmd thread, */
1290 /* don't need to leave low power again */
1291 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
1293 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1294 EXhalbtc8723b2ant_Periodical(pBtCoexist);
1295 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1296 EXhalbtc8723b1ant_Periodical(pBtCoexist);
1298 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
1301 void EXhalbtcoutsrc_SetChipType(u8 chipType)
1303 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
1306 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
1308 if (BT_COEX_ANT_TYPE_PG == type) {
1309 GLBtCoexist.boardInfo.pgAntNum = antNum;
1310 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1311 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1312 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1313 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1314 } else if (BT_COEX_ANT_TYPE_DETECTED == type) {
1315 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1316 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
1321 /* Currently used by 8723b only, S0 or S1 */
1323 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
1325 GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
1328 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
1330 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1333 halbtcoutsrc_LeaveLowPower(pBtCoexist);
1335 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1336 EXhalbtc8723b2ant_DisplayCoexInfo(pBtCoexist);
1337 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1338 EXhalbtc8723b1ant_DisplayCoexInfo(pBtCoexist);
1340 halbtcoutsrc_NormalLowPower(pBtCoexist);
1345 *Run BT-Coexist mechansim or not
1348 void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist)
1350 struct hal_com_data *pHalData;
1353 pHalData = GET_HAL_DATA(padapter);
1354 pHalData->bt_coexist.bBtExist = bBtExist;
1359 *Check is co-exist mechanism enabled or not
1362 *true Enable BT co-exist mechanism
1363 *false Disable BT co-exist mechanism
1365 u8 hal_btcoex_IsBtExist(struct adapter *padapter)
1367 struct hal_com_data *pHalData;
1370 pHalData = GET_HAL_DATA(padapter);
1371 return pHalData->bt_coexist.bBtExist;
1374 u8 hal_btcoex_IsBtDisabled(struct adapter *padapter)
1376 if (!hal_btcoex_IsBtExist(padapter))
1379 if (GLBtCoexist.btInfo.bBtDisabled)
1385 void hal_btcoex_SetChipType(struct adapter *padapter, u8 chipType)
1387 struct hal_com_data *pHalData;
1390 pHalData = GET_HAL_DATA(padapter);
1391 pHalData->bt_coexist.btChipType = chipType;
1393 EXhalbtcoutsrc_SetChipType(chipType);
1396 void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum)
1398 struct hal_com_data *pHalData;
1401 pHalData = GET_HAL_DATA(padapter);
1403 pHalData->bt_coexist.btTotalAntNum = antNum;
1404 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1407 void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath)
1409 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
1412 u8 hal_btcoex_Initialize(struct adapter *padapter)
1418 memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
1419 ret1 = EXhalbtcoutsrc_InitlizeVariables((void *)padapter);
1420 ret2 = (ret1 == true) ? true : false;
1425 void hal_btcoex_PowerOnSetting(struct adapter *padapter)
1427 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
1430 void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly)
1432 if (!hal_btcoex_IsBtExist(padapter))
1435 EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
1436 EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
1439 void hal_btcoex_IpsNotify(struct adapter *padapter, u8 type)
1441 EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
1444 void hal_btcoex_LpsNotify(struct adapter *padapter, u8 type)
1446 EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
1449 void hal_btcoex_ScanNotify(struct adapter *padapter, u8 type)
1451 EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
1454 void hal_btcoex_ConnectNotify(struct adapter *padapter, u8 action)
1456 EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
1459 void hal_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus)
1461 EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
1464 void hal_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType)
1466 EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
1469 void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state)
1471 GLBtcWiFiInIQKState = state;
1474 void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf)
1476 if (GLBtcWiFiInIQKState == true)
1479 EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
1482 void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state)
1485 state = BTC_WIFI_PNP_SLEEP;
1487 state = BTC_WIFI_PNP_WAKE_UP;
1489 EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
1492 void hal_btcoex_HaltNotify(struct adapter *padapter)
1494 EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
1497 void hal_btcoex_Hanlder(struct adapter *padapter)
1499 EXhalbtcoutsrc_Periodical(&GLBtCoexist);
1502 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter)
1504 return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
1507 void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual)
1509 GLBtCoexist.bManualControl = bmanual;
1512 u8 hal_btcoex_IsBtControlLps(struct adapter *padapter)
1514 if (hal_btcoex_IsBtExist(padapter) == false)
1517 if (GLBtCoexist.btInfo.bBtDisabled)
1520 if (GLBtCoexist.btInfo.bBtCtrlLps)
1526 u8 hal_btcoex_IsLpsOn(struct adapter *padapter)
1528 if (hal_btcoex_IsBtExist(padapter) == false)
1531 if (GLBtCoexist.btInfo.bBtDisabled)
1534 if (GLBtCoexist.btInfo.bBtLpsOn)
1540 u8 hal_btcoex_RpwmVal(struct adapter *padapter)
1542 return GLBtCoexist.btInfo.rpwmVal;
1545 u8 hal_btcoex_LpsVal(struct adapter *padapter)
1547 return GLBtCoexist.btInfo.lpsVal;
1550 u32 hal_btcoex_GetRaMask(struct adapter *padapter)
1552 if (!hal_btcoex_IsBtExist(padapter))
1555 if (GLBtCoexist.btInfo.bBtDisabled)
1558 if (GLBtCoexist.boardInfo.btdmAntNum != 1)
1561 return GLBtCoexist.btInfo.raMask;
1564 void hal_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen)
1566 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write pwrModeCmd = 0x%04x%08x\n",
1567 pCmdBuf[0]<<8|pCmdBuf[1],
1568 pCmdBuf[2]<<24|pCmdBuf[3]<<16|pCmdBuf[4]<<8|pCmdBuf[5]));
1570 memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
1573 void hal_btcoex_DisplayBtCoexInfo(struct adapter *padapter, u8 *pbuf, u32 bufsize)
1578 pinfo = &GLBtcDbgInfo;
1579 DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
1580 EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
1581 DBG_BT_INFO_INIT(pinfo, NULL, 0);
1584 void hal_btcoex_SetDBG(struct adapter *padapter, u32 *pDbgModule)
1589 if (NULL == pDbgModule)
1592 for (i = 0; i < BTC_MSG_MAX; i++)
1593 GLBtcDbgType[i] = pDbgModule[i];
1596 u32 hal_btcoex_GetDBG(struct adapter *padapter, u8 *pStrBuf, u32 bufSize)
1603 if ((NULL == pStrBuf) || (0 == bufSize))
1608 /* DBG_871X(FUNC_ADPT_FMT ": bufsize =%d\n", FUNC_ADPT_ARG(padapter), bufSize); */
1610 count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
1611 if ((count < 0) || (count >= leftSize))
1616 count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
1617 if ((count < 0) || (count >= leftSize))
1622 count = rtw_sprintf(pstr, leftSize,
1623 "INTERFACE / ALGORITHM: 0x%08X / 0x%08X\n\n",
1624 GLBtcDbgType[BTC_MSG_INTERFACE],
1625 GLBtcDbgType[BTC_MSG_ALGORITHM]);
1626 if ((count < 0) || (count >= leftSize))
1631 count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
1632 if ((count < 0) || (count >= leftSize))
1636 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
1637 (GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_INIT)?1:0);
1638 if ((count < 0) || (count >= leftSize))
1642 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
1643 (GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_NOTIFY)?1:0);
1644 if ((count < 0) || (count >= leftSize))
1649 count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
1650 if ((count < 0) || (count >= leftSize))
1654 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
1655 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_RSSI_STATE)?1:0);
1656 if ((count < 0) || (count >= leftSize))
1660 count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
1661 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_WIFI_RSSI_STATE)?1:0);
1662 if ((count < 0) || (count >= leftSize))
1666 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
1667 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_MONITOR)?1:0);
1668 if ((count < 0) || (count >= leftSize))
1672 count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
1673 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE)?1:0);
1674 if ((count < 0) || (count >= leftSize))
1678 count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
1679 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW)?1:0);
1680 if ((count < 0) || (count >= leftSize))
1684 count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
1685 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_DETAIL)?1:0);
1686 if ((count < 0) || (count >= leftSize))
1690 count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
1691 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_EXEC)?1:0);
1692 if ((count < 0) || (count >= leftSize))
1696 count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
1697 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW)?1:0);
1698 if ((count < 0) || (count >= leftSize))
1702 count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
1703 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_DETAIL)?1:0);
1704 if ((count < 0) || (count >= leftSize))
1708 count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
1709 (GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_EXEC)?1:0);
1710 if ((count < 0) || (count >= leftSize))
1716 count = pstr - pStrBuf;
1717 /* DBG_871X(FUNC_ADPT_FMT ": usedsize =%d\n", FUNC_ADPT_ARG(padapter), count); */