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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #define __HAL_BTCOEX_C__
22 #ifdef CONFIG_BT_COEXIST
25 #include <hal_btcoex.h>
26 #include <Mp_Precomp.h>
28 //====================================
30 //====================================
31 const char *const BtProfileString[] =
40 const char *const BtSpecString[] =
51 const char *const BtLinkRoleString[] =
57 const char *const h2cStaString[] =
65 const char *const ioStaString[] =
80 const char *const GLBtcWifiBwString[]={
88 const char *const GLBtcWifiFreqString[]={
93 const char *const GLBtcIotPeerString[] = {
103 "REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
104 "SELF_SOFTAP", /* Self is SoftAP */
110 "REALTEK_JAGUAR_BCUTAP",
111 "REALTEK_JAGUAR_CCUTAP"
114 #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS 8000
116 BTC_COEXIST GLBtCoexist;
117 u8 GLBtcWiFiInScanState;
118 u8 GLBtcWiFiInIQKState;
121 u8 GLBtcBtCoexAliveRegistered;
127 typedef enum _bt_ext_eid {
128 C2H_WIFI_FW_ACTIVE_RSP = 0,
133 typedef enum _bt_c2h_status {
135 BT_STATUS_VERSION_MISMATCH,
136 BT_STATUS_UNKNOWN_OPCODE,
137 BT_STATUS_ERROR_PARAMETER
140 /* C2H BT OP CODES */
141 typedef enum _bt_op_code {
142 BT_OP_GET_BT_VERSION = 0,
143 BT_OP_WRITE_REG_ADDR = 12,
144 BT_OP_WRITE_REG_VALUE,
148 #define BTC_MPOPER_TIMEOUT 50 /* unit: ms */
150 #define C2H_MAX_SIZE 16
152 _mutex GLBtcBtMpOperLock;
153 _timer GLBtcBtMpOperTimer;
154 _sema GLBtcBtMpRptSema;
156 u8 GLBtcBtMpRptStatus;
157 u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE];
158 u8 GLBtcBtMpRptRspSize;
160 u8 GLBtcBtMpRptWiFiOK;
166 u32 GLBtcDbgType[COMP_MAX];
167 u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
169 typedef struct _btcoexdbginfo
172 u32 size; // buffer total size
173 u32 len; // now used length
174 } BTCDBGINFO, *PBTCDBGINFO;
176 BTCDBGINFO GLBtcDbgInfo;
178 #define BT_Operation(Adapter) _FALSE
180 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
182 if (NULL == pinfo) return;
184 _rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
192 void DBG_BT_INFO(u8 *dbgmsg)
199 pinfo = &GLBtcDbgInfo;
201 if (NULL == pinfo->info)
204 msglen = strlen(dbgmsg);
205 if (pinfo->len + msglen > pinfo->size)
208 pbuf = pinfo->info + pinfo->len;
209 _rtw_memcpy(pbuf, dbgmsg, msglen);
210 pinfo->len += msglen;
213 //====================================
214 // Debug related function
215 //====================================
216 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
218 if (!pBtCoexist->bBinded ||
219 NULL == pBtCoexist->Adapter)
226 static void halbtcoutsrc_DbgInit(void)
230 for (i = 0; i < COMP_MAX; i++)
234 static u8 halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)
236 if (pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC4
237 || pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC8
244 static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
246 if (pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC4
247 || pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC8
251 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
259 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
264 padapter = pBtCoexist->Adapter;
266 pBtCoexist->btInfo.bBtCtrlLps = _TRUE;
267 pBtCoexist->btInfo.bBtLpsOn = _FALSE;
269 rtw_btcoex_LPS_Leave(padapter);
272 void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
277 padapter = pBtCoexist->Adapter;
279 pBtCoexist->btInfo.bBtCtrlLps = _TRUE;
280 pBtCoexist->btInfo.bBtLpsOn = _TRUE;
282 rtw_btcoex_LPS_Enter(padapter);
285 void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
290 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Normal LPS behavior!!!\n"));
292 padapter = pBtCoexist->Adapter;
294 if (pBtCoexist->btInfo.bBtCtrlLps)
296 pBtCoexist->btInfo.bBtLpsOn = _FALSE;
297 rtw_btcoex_LPS_Leave(padapter);
298 pBtCoexist->btInfo.bBtCtrlLps = _FALSE;
300 // recover the LPS state to the original
302 padapter->HalFunc.UpdateLPSStatusHandler(
304 pPSC->RegLeisurePsMode,
305 pPSC->RegPowerSaveMode);
312 * 1. this function will request pwrctrl->lock
314 void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
316 #ifdef CONFIG_LPS_LCLK
318 PHAL_DATA_TYPE pHalData;
319 struct pwrctrl_priv *pwrctrl;
323 u32 timeout; // unit: ms
326 padapter = pBtCoexist->Adapter;
327 pHalData = GET_HAL_DATA(padapter);
328 pwrctrl = adapter_to_pwrctl(padapter);
330 #ifdef LPS_RPWM_WAIT_MS
331 timeout = LPS_RPWM_WAIT_MS;
332 #else // !LPS_RPWM_WAIT_MS
334 #endif // !LPS_RPWM_WAIT_MS
336 if (GLBtcBtCoexAliveRegistered == _TRUE)
339 stime = rtw_get_current_time();
341 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
342 if (_SUCCESS == ready)
345 utime = rtw_get_passing_time_ms(stime);
352 GLBtcBtCoexAliveRegistered = _TRUE;
353 #endif // CONFIG_LPS_LCLK
358 * 1. this function will request pwrctrl->lock
360 void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
362 #ifdef CONFIG_LPS_LCLK
365 if (GLBtcBtCoexAliveRegistered == _FALSE)
368 padapter = pBtCoexist->Adapter;
369 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
371 GLBtcBtCoexAliveRegistered = _FALSE;
372 #endif // CONFIG_LPS_LCLK
375 void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
377 pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
379 halbtcoutsrc_LeaveLowPower(pBtCoexist); // leave 32k low power.
381 halbtcoutsrc_NormalLowPower(pBtCoexist); // original 32k low power behavior.
384 void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
387 BOOLEAN bNeedToAct = _FALSE;
388 static u32 preTime = 0;
391 padapter = pBtCoexist->Adapter;
393 //=====================================
394 // To void continuous deleteBA=>addBA=>deleteBA=>addBA
395 // This function is not allowed to continuous called.
396 // It can only be called after 8 seconds.
397 //=====================================
399 curTime = rtw_systime_to_ms(rtw_get_current_time());
400 if((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS) // over 8 seconds you can execute this function again.
409 if (pBtCoexist->btInfo.bRejectAggPkt)
412 pBtCoexist->btInfo.bPreRejectAggPkt = pBtCoexist->btInfo.bRejectAggPkt;
416 if(pBtCoexist->btInfo.bPreRejectAggPkt)
419 pBtCoexist->btInfo.bPreRejectAggPkt = pBtCoexist->btInfo.bRejectAggPkt;
422 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
423 pBtCoexist->btInfo.bBtCtrlAggBufSize)
426 pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
429 if (pBtCoexist->btInfo.bBtCtrlAggBufSize)
431 if (pBtCoexist->btInfo.preAggBufSize !=
432 pBtCoexist->btInfo.aggBufSize)
436 pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
441 rtw_btcoex_rx_ampdu_apply(padapter);
444 u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
446 struct mlme_priv *pmlmepriv;
449 pmlmepriv = &padapter->mlmepriv;
451 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
453 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
455 if (_TRUE == pmlmepriv->LinkDetectInfo.bBusyTraffic)
459 #if defined(CONFIG_CONCURRENT_MODE)
460 pmlmepriv = &padapter->pbuddy_adapter->mlmepriv;
462 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
464 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
466 if (_TRUE == pmlmepriv->LinkDetectInfo.bBusyTraffic)
474 static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
476 struct mlme_priv *pmlmepriv;
478 u32 portConnectedStatus;
481 pmlmepriv = &padapter->mlmepriv;
483 portConnectedStatus = 0;
486 if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
490 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
492 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
495 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
497 portConnectedStatus |= WIFI_AP_CONNECTED;
502 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
504 portConnectedStatus |= WIFI_STA_CONNECTED;
508 return portConnectedStatus;
511 u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
513 //=================================
515 // [31:16]=> connected port number
516 // [15:0]=> port connected bit define
517 //================================
521 u32 portConnectedStatus, numOfConnectedPort;
524 padapter = pBtCoexist->Adapter;
526 portConnectedStatus = 0;
527 numOfConnectedPort = 0;
529 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
532 portConnectedStatus |= retVal;
533 numOfConnectedPort++;
536 #ifdef CONFIG_CONCURRENT_MODE
537 if (padapter->pbuddy_adapter)
539 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter->pbuddy_adapter);
542 portConnectedStatus |= retVal;
543 numOfConnectedPort++;
546 #endif // CONFIG_CONCURRENT_MODE
548 retVal = (numOfConnectedPort << 16) | portConnectedStatus;
553 static u8 _is_btfwver_valid(PBTC_COEXIST pBtCoexist, u16 btfwver)
558 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
559 if (btfwver == 0x8723)
565 static void _btmpoper_timer_hdl(void *p)
567 if (GLBtcBtMpRptWait) {
568 GLBtcBtMpRptWait = 0;
569 _rtw_up_sema(&GLBtcBtMpRptSema);
575 * Before call this function, caller should acquire "GLBtcBtMpOperLock"!
576 * Othrewise there will be racing problem and something may go wrong.
578 static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size)
581 u8 buf[H2C_BTMP_OPER_LEN] = {0};
590 if ((size + 2) > H2C_BTMP_OPER_LEN)
591 return BT_STATUS_H2C_LENGTH_EXCEEDED;
594 seq = GLBtcBtMpOperSeq & 0xF;
597 buf[0] = (opcodever & 0xF) | (seq << 4);
600 _rtw_memcpy(buf+2, cmd, size);
602 GLBtcBtMpRptWait = 1;
603 GLBtcBtMpRptWiFiOK = 0;
604 GLBtcBtMpRptBTOK = 0;
605 GLBtcBtMpRptStatus = 0;
606 padapter = pBtCoexist->Adapter;
607 _set_timer(&GLBtcBtMpOperTimer, BTC_MPOPER_TIMEOUT);
608 if (rtw_hal_fill_h2c_cmd(padapter, H2C_BT_MP_OPER, buflen, buf) == _FAIL) {
609 _cancel_timer(&GLBtcBtMpOperTimer, &timer_cancelled);
610 ret = BT_STATUS_H2C_FAIL;
614 _rtw_down_sema(&GLBtcBtMpRptSema);
615 /* GLBtcBtMpRptWait should be 0 here*/
617 if (!GLBtcBtMpRptWiFiOK) {
618 DBG_871X("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__);
619 ret = BT_STATUS_H2C_TIMTOUT;
622 if (!GLBtcBtMpRptBTOK) {
623 DBG_871X("%s: Didn't get BT response!\n", __FUNCTION__);
624 ret = BT_STATUS_H2C_BT_NO_RSP;
627 if (seq != GLBtcBtMpRptSeq) {
628 DBG_871X("%s: Sequence number not match!(%d!=%d)!\n",
629 __FUNCTION__, seq, GLBtcBtMpRptSeq);
630 ret = BT_STATUS_C2H_REQNUM_MISMATCH;
634 switch (GLBtcBtMpRptStatus) {
635 /* Examine the status reported from C2H */
637 ret = BT_STATUS_BT_OP_SUCCESS;
638 DBG_871X("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__);
640 case BT_STATUS_VERSION_MISMATCH:
641 ret = BT_STATUS_OPCODE_L_VERSION_MISMATCH;
642 DBG_871X("%s: C2H status = BT_STATUS_OPCODE_L_VERSION_MISMATCH\n", __FUNCTION__);
644 case BT_STATUS_UNKNOWN_OPCODE:
645 ret = BT_STATUS_UNKNOWN_OPCODE_L;
646 DBG_871X("%s: C2H status = MP_BT_STATUS_UNKNOWN_OPCODE_L\n", __FUNCTION__);
648 case BT_STATUS_ERROR_PARAMETER:
649 ret = BT_STATUS_PARAMETER_FORMAT_ERROR_L;
650 DBG_871X("%s: C2H status = MP_BT_STATUS_PARAMETER_FORMAT_ERROR_L\n", __FUNCTION__);
653 ret = BT_STATUS_UNKNOWN_STATUS_L;
654 DBG_871X("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__);
662 u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
664 if (_is_btfwver_valid(pBtCoexist, pBtCoexist->btInfo.btRealFwVer) == _TRUE)
667 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
672 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
674 ret = _btmpoper_cmd(pBtCoexist, BT_OP_GET_BT_VERSION, 0, NULL, 0);
675 if (BT_STATUS_BT_OP_SUCCESS == ret) {
676 pBtCoexist->btInfo.btRealFwVer = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
677 pBtCoexist->btInfo.btFwVer = *(GLBtcBtMpRptRsp+2);
679 pBtCoexist->btInfo.getBtFwVerCnt++;
681 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
683 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
687 buf[0] = 0x0; /* OP_Code */
688 buf[1] = 0x0; /* OP_Code_Length */
689 BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
690 #endif /* !CONFIG_BT_COEXIST_SOCKET_TRX */
694 return pBtCoexist->btInfo.btRealFwVer;
697 s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
699 PHAL_DATA_TYPE pHalData;
700 s32 UndecoratedSmoothedPWDB = 0;
702 pHalData = GET_HAL_DATA(padapter);
704 UndecoratedSmoothedPWDB = pHalData->EntryMinUndecoratedSmoothedPWDB;
706 return UndecoratedSmoothedPWDB;
709 static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
711 struct mlme_priv *pmlmepriv;
712 struct mlme_ext_priv *pmlmeext;
713 static u8 scan_AP_num = 0;
716 pmlmepriv = &padapter->mlmepriv;
717 pmlmeext = &padapter->mlmeextpriv;
719 if (GLBtcWiFiInScanState == _FALSE) {
720 if (pmlmepriv->num_of_scanned > 0xFF)
723 scan_AP_num = (u8)pmlmepriv->num_of_scanned;
729 u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
731 PBTC_COEXIST pBtCoexist;
733 PHAL_DATA_TYPE pHalData;
734 struct mlme_ext_priv *mlmeext;
735 u8 bSoftApExist, bVwifiExist;
743 pBtCoexist = (PBTC_COEXIST)pBtcContext;
744 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
747 padapter = pBtCoexist->Adapter;
748 pHalData = GET_HAL_DATA(padapter);
749 mlmeext = &padapter->mlmeextpriv;
750 bSoftApExist = _FALSE;
751 bVwifiExist = _FALSE;
753 pS4Tmp = (s32*)pOutBuf;
754 pU4Tmp = (u32*)pOutBuf;
755 pU1Tmp = (u8*)pOutBuf;
760 case BTC_GET_BL_HS_OPERATION:
765 case BTC_GET_BL_HS_CONNECTING:
770 case BTC_GET_BL_WIFI_CONNECTED:
771 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
772 #ifdef CONFIG_CONCURRENT_MODE
773 if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
775 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_ASOC_STATE);
777 #endif // CONFIG_CONCURRENT_MODE
780 case BTC_GET_BL_WIFI_BUSY:
781 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
784 case BTC_GET_BL_WIFI_SCAN:
786 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_SITE_MONITOR);
787 #ifdef CONFIG_CONCURRENT_MODE
788 if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
790 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_SITE_MONITOR);
792 #endif // CONFIG_CONCURRENT_MODE
794 /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
795 WIFI_SITE_MONITOR in fwstate may not be cleared in time */
796 *pu8 = GLBtcWiFiInScanState;
800 case BTC_GET_BL_WIFI_LINK:
801 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
802 #ifdef CONFIG_CONCURRENT_MODE
803 if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
805 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_UNDER_LINKING);
807 #endif // CONFIG_CONCURRENT_MODE
810 case BTC_GET_BL_WIFI_ROAM:
811 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
812 #ifdef CONFIG_CONCURRENT_MODE
813 if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
815 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_UNDER_LINKING);
817 #endif // CONFIG_CONCURRENT_MODE
820 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
824 case BTC_GET_BL_WIFI_UNDER_5G:
825 *pu8 = (pHalData->CurrentBandType == 1)? _TRUE : _FALSE;
828 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
829 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
830 #ifdef CONFIG_CONCURRENT_MODE
831 if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
833 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_AP_STATE);
835 #endif // CONFIG_CONCURRENT_MODE
838 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
839 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0? _FALSE: _TRUE;
842 case BTC_GET_BL_WIFI_UNDER_B_MODE:
843 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
849 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
850 if (padapter->registrypriv.mp_mode == 0)
860 case BTC_GET_BL_EXT_SWITCH:
863 case BTC_GET_BL_IS_ASUS_8723B:
864 /* Always return FALSE in linux driver since this case is added only for windows driver */
868 case BTC_GET_S4_WIFI_RSSI:
869 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
872 case BTC_GET_S4_HS_RSSI:
877 case BTC_GET_U4_WIFI_BW:
878 if (IsLegacyOnly(mlmeext->cur_wireless_mode))
879 *pU4Tmp = BTC_WIFI_BW_LEGACY;
880 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
881 *pU4Tmp = BTC_WIFI_BW_HT20;
882 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
883 *pU4Tmp = BTC_WIFI_BW_HT40;
885 *pU4Tmp = BTC_WIFI_BW_HT40; /* todo */
888 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
890 PRT_LINK_DETECT_T plinkinfo;
891 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
893 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
894 *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
896 *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
900 case BTC_GET_U4_WIFI_FW_VER:
901 *pU4Tmp = pHalData->FirmwareVersion << 16;
902 *pU4Tmp |= pHalData->FirmwareSubVersion;
905 case BTC_GET_U4_WIFI_LINK_STATUS:
906 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
909 case BTC_GET_U4_BT_PATCH_VER:
910 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
913 case BTC_GET_U1_WIFI_DOT11_CHNL:
914 *pU1Tmp = padapter->mlmeextpriv.cur_channel;
917 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
918 *pU1Tmp = pHalData->CurrentChannel;
921 case BTC_GET_U1_WIFI_HS_CHNL:
926 case BTC_GET_U1_MAC_PHY_MODE:
927 // *pU1Tmp = BTC_SMSP;
928 // *pU1Tmp = BTC_DMSP;
929 // *pU1Tmp = BTC_DMDP;
930 // *pU1Tmp = BTC_MP_UNKNOWN;
933 case BTC_GET_U1_AP_NUM:
934 *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
936 case BTC_GET_U1_ANT_TYPE:
937 switch(pHalData->bt_coexist.btAntisolation)
940 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_0;
941 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_0;
944 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_1;
945 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_1;
948 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_2;
949 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_2;
952 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_3;
953 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_3;
956 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_4;
957 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_4;
961 case BTC_GET_U1_IOT_PEER:
962 *pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;
965 //=======1Ant===========
966 case BTC_GET_U1_LPS_MODE:
967 *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
978 u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
980 PBTC_COEXIST pBtCoexist;
982 PHAL_DATA_TYPE pHalData;
989 pBtCoexist = (PBTC_COEXIST)pBtcContext;
990 padapter = pBtCoexist->Adapter;
991 pHalData = GET_HAL_DATA(padapter);
993 pU1Tmp = (u8*)pInBuf;
994 pU4Tmp = (u32*)pInBuf;
997 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1002 // set some u8 type variables.
1003 case BTC_SET_BL_BT_DISABLE:
1004 pBtCoexist->btInfo.bBtDisabled = *pu8;
1007 case BTC_SET_BL_BT_TRAFFIC_BUSY:
1008 pBtCoexist->btInfo.bBtBusy = *pu8;
1011 case BTC_SET_BL_BT_LIMITED_DIG:
1012 pBtCoexist->btInfo.bLimitedDig = *pu8;
1015 case BTC_SET_BL_FORCE_TO_ROAM:
1016 pBtCoexist->btInfo.bForceToRoam = *pu8;
1019 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
1020 pBtCoexist->btInfo.bRejectAggPkt = *pu8;
1023 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
1024 pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
1027 case BTC_SET_BL_INC_SCAN_DEV_NUM:
1028 pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
1031 case BTC_SET_BL_BT_TX_RX_MASK:
1032 pBtCoexist->btInfo.bBtTxRxMask = *pu8;
1035 case BTC_SET_BL_MIRACAST_PLUS_BT:
1036 pBtCoexist->btInfo.bMiracastPlusBt = *pu8;
1039 // set some u8 type variables.
1040 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
1041 pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pU1Tmp;
1044 case BTC_SET_U1_AGG_BUF_SIZE:
1045 pBtCoexist->btInfo.aggBufSize = *pU1Tmp;
1048 // the following are some action which will be triggered
1049 case BTC_SET_ACT_GET_BT_RSSI:
1051 BT_SendGetBtRssiEvent(padapter);
1057 case BTC_SET_ACT_AGGREGATE_CTRL:
1058 halbtcoutsrc_AggregationCheck(pBtCoexist);
1061 //=======1Ant===========
1062 // set some u8 type variables.
1063 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
1064 pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pU1Tmp;
1067 case BTC_SET_U1_LPS_VAL:
1068 pBtCoexist->btInfo.lpsVal = *pU1Tmp;
1071 case BTC_SET_U1_RPWM_VAL:
1072 pBtCoexist->btInfo.rpwmVal = *pU1Tmp;
1075 // the following are some action which will be triggered
1076 case BTC_SET_ACT_LEAVE_LPS:
1077 halbtcoutsrc_LeaveLps(pBtCoexist);
1080 case BTC_SET_ACT_ENTER_LPS:
1081 halbtcoutsrc_EnterLps(pBtCoexist);
1084 case BTC_SET_ACT_NORMAL_LPS:
1085 halbtcoutsrc_NormalLps(pBtCoexist);
1088 case BTC_SET_ACT_DISABLE_LOW_POWER:
1089 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
1092 case BTC_SET_ACT_UPDATE_RAMASK:
1093 pBtCoexist->btInfo.raMask = *pU4Tmp;
1095 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE)
1097 struct sta_info *psta;
1098 PWLAN_BSSID_EX cur_network;
1100 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
1101 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
1102 rtw_hal_update_ra_mask(psta, 0);
1106 case BTC_SET_ACT_SEND_MIMO_PS:
1108 u8 newMimoPsMode = 3;
1109 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1110 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1112 /* *pU1Tmp = 0 use SM_PS static type */
1113 /* *pU1Tmp = 1 disable SM_PS */
1115 newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
1116 else if (*pU1Tmp == 1)
1117 newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
1119 if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) {
1120 /* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */
1121 issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1);
1126 case BTC_SET_ACT_CTRL_BT_INFO:
1127 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1129 u8 dataLen = *pU1Tmp;
1133 _rtw_memcpy(tmpBuf, pU1Tmp+1, dataLen);
1135 BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
1137 #else //!CONFIG_BT_COEXIST_SOCKET_TRX
1139 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
1142 case BTC_SET_ACT_CTRL_BT_COEX:
1143 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1145 u8 dataLen = *pU1Tmp;
1149 _rtw_memcpy(tmpBuf, pU1Tmp+1, dataLen);
1151 BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
1153 #else //!CONFIG_BT_COEXIST_SOCKET_TRX
1155 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
1157 case BTC_SET_ACT_CTRL_8723B_ANT:
1160 u1Byte dataLen=*pU1Tmp;
1164 PlatformMoveMemory(&tmpBuf[0], pU1Tmp+1, dataLen);
1166 BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
1172 //=====================
1181 u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
1184 struct pwrctrl_priv *pwrpriv;
1187 padapter = pBtCoexist->Adapter;
1188 pwrpriv = &padapter->dvobj->pwrctl_priv;
1189 bMacPwrCtrlOn = _FALSE;
1191 if ((_TRUE == pwrpriv->bips_processing)
1192 && (IPS_NONE != pwrpriv->ips_mode_req)
1198 if (rf_off == pwrpriv->rf_pwrstate)
1203 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
1204 if (_FALSE == bMacPwrCtrlOn)
1212 u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
1214 return GLBtcWiFiInLPS;
1217 u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
1219 /* todo: the method to check whether wifi is under 32K or not */
1223 void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
1226 PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1227 PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1228 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
1229 u8 *cliBuf = pBtCoexist->cliBuf;
1232 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
1235 #if (H2C_USE_IO_THREAD != 1)
1236 for(i=0; i<H2C_STATUS_MAX; i++)
1238 if (pHalData->h2cStatistics[i])
1240 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1241 h2cStaString[i], pHalData->h2cStatistics[i]);
1246 for(i=0; i<IO_STATUS_MAX; i++)
1248 if(Adapter->ioComStr.ioH2cStatistics[i])
1250 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1251 ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);
1257 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
1258 pHalData->LastHMEBoxNum);
1260 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
1261 pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
1264 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \
1265 pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,
1266 DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);
1269 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
1270 DBG_Var.c2hPacketCnt);
1273 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
1274 pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
1276 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \
1277 pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,
1278 pBtCoexist->statistics.cntRfStatusNotify);
1280 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \
1281 pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,
1282 pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,
1283 pBtCoexist->statistics.cntMediaStatusNotify);
1285 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind",
1286 pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify,
1287 pBtCoexist->statistics.cntBind);
1292 void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
1295 PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1296 PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1297 u8 *cliBuf = pBtCoexist->cliBuf;
1301 if (pBtCoexist->stackInfo.bProfileNotified)
1303 for (i=0; i<pBtMgnt->ExtConfig.NumberOfACL; i++)
1305 if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1)
1307 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \
1308 BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1309 BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],
1310 BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);
1311 CL_PRINTF(cliBuf); }
1314 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
1315 BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1316 BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);
1324 void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
1326 PADAPTER padapter = pBtCoexist->Adapter;
1327 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1328 u8* cliBuf=pBtCoexist->cliBuf;
1329 s32 wifiRssi=0, btHsRssi=0;
1330 BOOLEAN bScan=_FALSE, bLink=_FALSE, bRoam=_FALSE, bWifiBusy=_FALSE, bWifiUnderBMode=_FALSE;
1331 u32 wifiBw=BTC_WIFI_BW_HT20, wifiTrafficDir=BTC_WIFI_TRAFFIC_TX, wifiFreq=BTC_FREQ_2_4G;
1332 u32 wifiLinkStatus=0x0;
1333 BOOLEAN bBtHsOn=_FALSE, bLowPower=_FALSE;
1334 u8 wifiChnl=0, wifiHsChnl=0, nScanAPNum = 0, FwPSState;
1336 wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
1337 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc", \
1338 ((wifiLinkStatus&WIFI_STA_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_AP_CONNECTED)? 1:0),
1339 ((wifiLinkStatus&WIFI_HS_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_P2P_GO_CONNECTED)? 1:0),
1340 ((wifiLinkStatus&WIFI_P2P_GC_CONNECTED)? 1:0) );
1343 if (wifiLinkStatus&WIFI_STA_CONNECTED) {
1344 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "IOT Peer", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor]);
1348 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1349 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiChnl);
1350 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl); CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(High Speed)", \
1351 wifiChnl, wifiHsChnl, bBtHsOn);
1354 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
1355 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);
1356 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \
1357 wifiRssi-100, btHsRssi-100);
1361 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1362 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1363 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1364 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \
1365 bLink, bRoam, bScan);
1368 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifiFreq);
1369 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1370 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1371 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1372 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
1373 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);
1374 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ AP=%d ", "Wifi freq/ bw/ traffic", \
1375 GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode)? "11b": GLBtcWifiBwString[wifiBw]),
1376 ((!bWifiBusy)? "idle": ((BTC_WIFI_TRAFFIC_TX==wifiTrafficDir)? "uplink":"downlink")),
1381 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \
1382 ((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE)? "IPS ON":"IPS OFF"),
1383 ((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE)? ", LPS ON":", LPS OFF"),
1384 ((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE)? ", 32k":""));
1387 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)", "Power mode cmd(lps/rpwm)", \
1388 pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
1389 pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
1390 pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],
1391 pBtCoexist->btInfo.lpsVal,
1392 pBtCoexist->btInfo.rpwmVal);
1396 void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
1398 PBTC_COEXIST pBtCoexist;
1401 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1404 case BTC_DBG_DISP_COEX_STATISTICS:
1405 halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
1407 case BTC_DBG_DISP_BT_LINK_INFO:
1408 halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
1410 case BTC_DBG_DISP_WIFI_STATUS:
1411 halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
1418 //====================================
1419 // IO related function
1420 //====================================
1421 u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
1423 PBTC_COEXIST pBtCoexist;
1427 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1428 padapter = pBtCoexist->Adapter;
1430 return rtw_read8(padapter, RegAddr);
1433 u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
1435 PBTC_COEXIST pBtCoexist;
1439 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1440 padapter = pBtCoexist->Adapter;
1442 return rtw_read16(padapter, RegAddr);
1445 u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
1447 PBTC_COEXIST pBtCoexist;
1451 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1452 padapter = pBtCoexist->Adapter;
1454 return rtw_read32(padapter, RegAddr);
1457 void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1459 PBTC_COEXIST pBtCoexist;
1463 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1464 padapter = pBtCoexist->Adapter;
1466 rtw_write8(padapter, RegAddr, Data);
1469 void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
1471 PBTC_COEXIST pBtCoexist;
1473 u8 originalValue, bitShift;
1477 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1478 padapter = pBtCoexist->Adapter;
1484 originalValue = rtw_read8(padapter, regAddr);
1486 for (i=0; i<=7; i++)
1488 if ((bitMask>>i)&0x1)
1493 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
1496 rtw_write8(padapter, regAddr, data1b);
1499 void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
1501 PBTC_COEXIST pBtCoexist;
1505 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1506 padapter = pBtCoexist->Adapter;
1508 rtw_write16(padapter, RegAddr, Data);
1511 void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
1513 PBTC_COEXIST pBtCoexist;
1517 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1518 padapter = pBtCoexist->Adapter;
1520 rtw_write32(padapter, RegAddr, Data);
1523 void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1525 PBTC_COEXIST pBtCoexist=(PBTC_COEXIST)pBtcContext;
1526 PADAPTER Adapter=pBtCoexist->Adapter;
1528 if(BTC_INTF_SDIO == pBtCoexist->chipInterface)
1530 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
1534 rtw_write8(Adapter, RegAddr, Data);
1538 void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
1540 PBTC_COEXIST pBtCoexist;
1544 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1545 padapter = pBtCoexist->Adapter;
1547 PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
1551 u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
1553 PBTC_COEXIST pBtCoexist;
1557 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1558 padapter = pBtCoexist->Adapter;
1560 return PHY_QueryBBReg(padapter, RegAddr, BitMask);
1563 void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
1565 PBTC_COEXIST pBtCoexist;
1569 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1570 padapter = pBtCoexist->Adapter;
1572 PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
1575 u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
1577 PBTC_COEXIST pBtCoexist;
1581 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1582 padapter = pBtCoexist->Adapter;
1584 return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
1587 u16 halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
1589 PBTC_COEXIST pBtCoexist;
1590 u16 ret = BT_STATUS_BT_OP_SUCCESS;
1592 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1594 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1600 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1602 Data = cpu_to_le32(Data);
1603 op_code = BT_OP_WRITE_REG_VALUE;
1604 status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Data, 3);
1605 if (status != BT_STATUS_BT_OP_SUCCESS)
1606 ret = SET_BT_MP_OPER_RET(op_code, status);
1609 *(u16 *)(buf+1) = cpu_to_le16((u16)RegAddr);
1610 op_code = BT_OP_WRITE_REG_ADDR;
1611 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
1612 if (status != BT_STATUS_BT_OP_SUCCESS)
1613 ret = SET_BT_MP_OPER_RET(op_code, status);
1616 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1618 ret = BT_STATUS_NOT_IMPLEMENT;
1623 u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)
1625 /* Always return _FALSE since we don't implement this yet */
1627 PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
1628 PADAPTER Adapter = pBtCoexist->Adapter;
1630 BOOLEAN bStatus = FALSE;
1632 bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);
1633 if (bStatus && btCanTx)
1642 u16 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 *data)
1644 PBTC_COEXIST pBtCoexist;
1645 u16 ret = BT_STATUS_BT_OP_SUCCESS;
1647 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1649 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1656 *(u16 *)(buf+1) = cpu_to_le16((u16)RegAddr);
1658 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1660 op_code = BT_OP_READ_REG;
1661 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
1662 if (status == BT_STATUS_BT_OP_SUCCESS)
1663 *data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
1665 ret = SET_BT_MP_OPER_RET(op_code, status);
1667 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1670 ret = BT_STATUS_NOT_IMPLEMENT;
1675 void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
1677 PBTC_COEXIST pBtCoexist;
1681 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1682 padapter = pBtCoexist->Adapter;
1684 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
1687 //====================================
1688 // Extern functions called by other module
1689 //====================================
1690 u8 EXhalbtcoutsrc_IsTfbgaPackageType(PADAPTER padapter)
1692 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
1694 #ifdef CONFIG_RTL8723B
1695 if ((pHalData->PackageType == PACKAGE_TFBGA79) || (pHalData->PackageType == PACKAGE_TFBGA80)
1696 || (pHalData->PackageType == PACKAGE_TFBGA90)) {
1704 u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
1706 PBTC_COEXIST pBtCoexist=&GLBtCoexist;
1707 u1Byte antNum=2, chipType;
1709 if(pBtCoexist->bBinded)
1712 pBtCoexist->bBinded = _TRUE;
1714 pBtCoexist->statistics.cntBind++;
1716 pBtCoexist->Adapter = padapter;
1718 pBtCoexist->stackInfo.bProfileNotified = _FALSE;
1720 pBtCoexist->btInfo.bBtCtrlAggBufSize = _FALSE;
1721 pBtCoexist->btInfo.aggBufSize = 5;
1723 pBtCoexist->btInfo.bIncreaseScanDevNum = _FALSE;
1724 pBtCoexist->btInfo.bMiracastPlusBt = _FALSE;
1727 chipType = HALBT_GetBtChipType(Adapter);
1728 EXhalbtcoutsrc_SetChipType(chipType);
1729 antNum = HALBT_GetPgAntNum(Adapter);
1730 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1732 // set default antenna position to main port
1733 pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
1735 pBtCoexist->boardInfo.btdmAntDetFinish = _FALSE;
1736 pBtCoexist->boardInfo.btdmAntNumByAntDet = 1;
1738 pBtCoexist->boardInfo.bTfbgaPackage = EXhalbtcoutsrc_IsTfbgaPackageType((PADAPTER)padapter);
1740 if (pBtCoexist->boardInfo.bTfbgaPackage)
1741 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Package Type = TFBGA\n"));
1743 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Package Type = Non-TFBGA\n"));
1748 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
1750 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
1752 //pBtCoexist->statistics.cntBind++;
1754 halbtcoutsrc_DbgInit();
1756 #ifdef CONFIG_PCI_HCI
1757 pBtCoexist->chipInterface = BTC_INTF_PCI;
1758 #elif defined(CONFIG_USB_HCI)
1759 pBtCoexist->chipInterface = BTC_INTF_USB;
1760 #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
1761 pBtCoexist->chipInterface = BTC_INTF_SDIO;
1763 pBtCoexist->chipInterface = BTC_INTF_UNKNOWN;
1766 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
1768 pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
1769 pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
1770 pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
1771 pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
1772 pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
1773 pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
1774 pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
1775 pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
1777 pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
1778 pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
1780 pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
1781 pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
1783 pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
1784 pBtCoexist->fBtcDispDbgMsg = halbtcoutsrc_DisplayDbgMsg;
1786 pBtCoexist->fBtcGet = halbtcoutsrc_Get;
1787 pBtCoexist->fBtcSet = halbtcoutsrc_Set;
1788 pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
1789 pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
1790 pBtCoexist->fBtcSetBtAntDetection = halbtcoutsrc_SetBtAntDetection;
1792 pBtCoexist->cliBuf = &GLBtcDbgBuf[0];
1794 pBtCoexist->boardInfo.singleAntPath = 0;
1796 GLBtcWiFiInScanState = _FALSE;
1798 GLBtcWiFiInIQKState = _FALSE;
1800 GLBtcWiFiInIPS = _FALSE;
1802 GLBtcWiFiInLPS = _FALSE;
1804 GLBtcBtCoexAliveRegistered = _FALSE;
1806 /* BT Control H2C/C2H*/
1807 GLBtcBtMpOperSeq = 0;
1808 _rtw_mutex_init(&GLBtcBtMpOperLock);
1809 _init_timer(&GLBtcBtMpOperTimer, ((PADAPTER)padapter)->pnetdev, _btmpoper_timer_hdl, pBtCoexist);
1810 _rtw_init_sema(&GLBtcBtMpRptSema, 0);
1811 GLBtcBtMpRptSeq = 0;
1812 GLBtcBtMpRptStatus = 0;
1813 _rtw_memset(GLBtcBtMpRptRsp, 0, C2H_MAX_SIZE);
1814 GLBtcBtMpRptRspSize = 0;
1815 GLBtcBtMpRptWait = 0;
1816 GLBtcBtMpRptWiFiOK = 0;
1817 GLBtcBtMpRptBTOK = 0;
1822 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
1824 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1827 /* Power on setting function is only added in 8723B currently */
1828 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1830 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1831 EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
1832 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1833 EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
1837 void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)
1839 if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1842 pBtCoexist->statistics.cntPreLoadFirmware++;
1844 if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1846 if(pBtCoexist->boardInfo.btdmAntNum == 2)
1847 EXhalbtc8723b2ant_PreLoadFirmware(pBtCoexist);
1848 else if(pBtCoexist->boardInfo.btdmAntNum == 1)
1849 EXhalbtc8723b1ant_PreLoadFirmware(pBtCoexist);
1853 void EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
1855 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1858 pBtCoexist->statistics.cntInitHwConfig++;
1860 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1862 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1863 EXhalbtc8821aCsr2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1864 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1865 EXhalbtc8821a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1866 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1867 EXhalbtc8821a1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1869 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1871 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1872 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1873 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1874 EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1876 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1878 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1879 EXhalbtc8703b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1880 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1881 EXhalbtc8703b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1883 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1885 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1886 EXhalbtc8192e2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1887 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1888 EXhalbtc8192e1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1890 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1892 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1893 EXhalbtc8812a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1894 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1895 EXhalbtc8812a1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1899 void EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist)
1901 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1904 pBtCoexist->statistics.cntInitCoexDm++;
1906 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1908 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1909 EXhalbtc8821aCsr2ant_InitCoexDm(pBtCoexist);
1910 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1911 EXhalbtc8821a2ant_InitCoexDm(pBtCoexist);
1912 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1913 EXhalbtc8821a1ant_InitCoexDm(pBtCoexist);
1915 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1917 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1918 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
1919 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1920 EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
1922 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1924 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1925 EXhalbtc8703b2ant_InitCoexDm(pBtCoexist);
1926 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1927 EXhalbtc8703b1ant_InitCoexDm(pBtCoexist);
1929 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1931 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1932 EXhalbtc8192e2ant_InitCoexDm(pBtCoexist);
1933 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1934 EXhalbtc8192e1ant_InitCoexDm(pBtCoexist);
1936 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1938 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1939 EXhalbtc8812a2ant_InitCoexDm(pBtCoexist);
1940 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1941 EXhalbtc8812a1ant_InitCoexDm(pBtCoexist);
1944 pBtCoexist->bInitilized = _TRUE;
1947 void EXhalbtcoutsrc_IpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1951 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1954 pBtCoexist->statistics.cntIpsNotify++;
1955 if (pBtCoexist->bManualControl)
1958 if (IPS_NONE == type)
1960 ipsType = BTC_IPS_LEAVE;
1961 GLBtcWiFiInIPS = _FALSE;
1965 ipsType = BTC_IPS_ENTER;
1966 GLBtcWiFiInIPS = _TRUE;
1969 // All notify is called in cmd thread, don't need to leave low power again
1970 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
1972 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1974 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1975 EXhalbtc8821aCsr2ant_IpsNotify(pBtCoexist, ipsType);
1976 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1977 EXhalbtc8821a2ant_IpsNotify(pBtCoexist, ipsType);
1978 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1979 EXhalbtc8821a1ant_IpsNotify(pBtCoexist, ipsType);
1981 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1983 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1984 EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
1985 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1986 EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
1988 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1990 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1991 EXhalbtc8703b2ant_IpsNotify(pBtCoexist, ipsType);
1992 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1993 EXhalbtc8703b1ant_IpsNotify(pBtCoexist, ipsType);
1995 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1997 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1998 EXhalbtc8192e2ant_IpsNotify(pBtCoexist, ipsType);
1999 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2000 EXhalbtc8192e1ant_IpsNotify(pBtCoexist, ipsType);
2002 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2004 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2005 EXhalbtc8812a2ant_IpsNotify(pBtCoexist, ipsType);
2006 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2007 EXhalbtc8812a1ant_IpsNotify(pBtCoexist, ipsType);
2010 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2013 void EXhalbtcoutsrc_LpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
2018 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2021 pBtCoexist->statistics.cntLpsNotify++;
2022 if (pBtCoexist->bManualControl)
2025 if (PS_MODE_ACTIVE == type)
2027 lpsType = BTC_LPS_DISABLE;
2028 GLBtcWiFiInLPS = _FALSE;
2032 lpsType = BTC_LPS_ENABLE;
2033 GLBtcWiFiInLPS = _TRUE;
2036 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2038 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2039 EXhalbtc8821aCsr2ant_LpsNotify(pBtCoexist, lpsType);
2040 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2041 EXhalbtc8821a2ant_LpsNotify(pBtCoexist, lpsType);
2042 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2043 EXhalbtc8821a1ant_LpsNotify(pBtCoexist, lpsType);
2045 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2047 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2048 EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
2049 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2050 EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
2052 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2054 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2055 EXhalbtc8703b2ant_LpsNotify(pBtCoexist, lpsType);
2056 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2057 EXhalbtc8703b1ant_LpsNotify(pBtCoexist, lpsType);
2059 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2061 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2062 EXhalbtc8192e2ant_LpsNotify(pBtCoexist, lpsType);
2063 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2064 EXhalbtc8192e1ant_LpsNotify(pBtCoexist, lpsType);
2066 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2068 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2069 EXhalbtc8812a2ant_LpsNotify(pBtCoexist, lpsType);
2070 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2071 EXhalbtc8812a1ant_LpsNotify(pBtCoexist, lpsType);
2075 void EXhalbtcoutsrc_ScanNotify(PBTC_COEXIST pBtCoexist, u8 type)
2079 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2081 pBtCoexist->statistics.cntScanNotify++;
2082 if (pBtCoexist->bManualControl)
2087 scanType = BTC_SCAN_START;
2088 GLBtcWiFiInScanState = _TRUE;
2092 scanType = BTC_SCAN_FINISH;
2093 GLBtcWiFiInScanState = _FALSE;
2096 // All notify is called in cmd thread, don't need to leave low power again
2097 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2099 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2101 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2102 EXhalbtc8821aCsr2ant_ScanNotify(pBtCoexist, scanType);
2103 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2104 EXhalbtc8821a2ant_ScanNotify(pBtCoexist, scanType);
2105 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2106 EXhalbtc8821a1ant_ScanNotify(pBtCoexist, scanType);
2108 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2110 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2111 EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
2112 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2113 EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
2115 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2117 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2118 EXhalbtc8703b2ant_ScanNotify(pBtCoexist, scanType);
2119 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2120 EXhalbtc8703b1ant_ScanNotify(pBtCoexist, scanType);
2122 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2124 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2125 EXhalbtc8192e2ant_ScanNotify(pBtCoexist, scanType);
2126 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2127 EXhalbtc8192e1ant_ScanNotify(pBtCoexist, scanType);
2129 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2131 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2132 EXhalbtc8812a2ant_ScanNotify(pBtCoexist, scanType);
2133 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2134 EXhalbtc8812a1ant_ScanNotify(pBtCoexist, scanType);
2137 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2140 void EXhalbtcoutsrc_ConnectNotify(PBTC_COEXIST pBtCoexist, u8 action)
2144 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2146 pBtCoexist->statistics.cntConnectNotify++;
2147 if (pBtCoexist->bManualControl)
2151 assoType = BTC_ASSOCIATE_START;
2153 assoType = BTC_ASSOCIATE_FINISH;
2155 // All notify is called in cmd thread, don't need to leave low power again
2156 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2158 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2160 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2161 EXhalbtc8821aCsr2ant_ConnectNotify(pBtCoexist, assoType);
2162 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2163 EXhalbtc8821a2ant_ConnectNotify(pBtCoexist, assoType);
2164 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2165 EXhalbtc8821a1ant_ConnectNotify(pBtCoexist, assoType);
2167 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2169 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2170 EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
2171 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2172 EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
2174 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2176 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2177 EXhalbtc8703b2ant_ConnectNotify(pBtCoexist, assoType);
2178 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2179 EXhalbtc8703b1ant_ConnectNotify(pBtCoexist, assoType);
2181 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2183 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2184 EXhalbtc8192e2ant_ConnectNotify(pBtCoexist, assoType);
2185 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2186 EXhalbtc8192e1ant_ConnectNotify(pBtCoexist, assoType);
2188 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2190 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2191 EXhalbtc8812a2ant_ConnectNotify(pBtCoexist, assoType);
2192 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2193 EXhalbtc8812a1ant_ConnectNotify(pBtCoexist, assoType);
2196 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2199 void EXhalbtcoutsrc_MediaStatusNotify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
2203 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2206 pBtCoexist->statistics.cntMediaStatusNotify++;
2207 if (pBtCoexist->bManualControl)
2210 if (RT_MEDIA_CONNECT == mediaStatus)
2211 mStatus = BTC_MEDIA_CONNECT;
2213 mStatus = BTC_MEDIA_DISCONNECT;
2215 // All notify is called in cmd thread, don't need to leave low power again
2216 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2218 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2220 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2221 EXhalbtc8821aCsr2ant_MediaStatusNotify(pBtCoexist, mStatus);
2222 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2223 EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, mStatus);
2224 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2225 EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, mStatus);
2227 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2229 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2230 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
2231 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2232 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
2234 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2236 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2237 EXhalbtc8703b2ant_MediaStatusNotify(pBtCoexist, mStatus);
2238 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2239 EXhalbtc8703b1ant_MediaStatusNotify(pBtCoexist, mStatus);
2241 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2243 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2244 EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, mStatus);
2245 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2246 EXhalbtc8192e1ant_MediaStatusNotify(pBtCoexist, mStatus);
2248 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2250 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2251 EXhalbtc8812a2ant_MediaStatusNotify(pBtCoexist, mStatus);
2252 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2253 EXhalbtc8812a1ant_MediaStatusNotify(pBtCoexist, mStatus);
2256 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2259 void EXhalbtcoutsrc_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 pktType)
2263 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2265 pBtCoexist->statistics.cntSpecialPacketNotify++;
2266 if (pBtCoexist->bManualControl)
2269 if (PACKET_DHCP == pktType)
2270 packetType = BTC_PACKET_DHCP;
2271 else if (PACKET_EAPOL == pktType)
2272 packetType = BTC_PACKET_EAPOL;
2273 else if (PACKET_ARP == pktType)
2274 packetType = BTC_PACKET_ARP;
2277 packetType = BTC_PACKET_UNKNOWN;
2281 // All notify is called in cmd thread, don't need to leave low power again
2282 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2284 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2286 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2287 EXhalbtc8821aCsr2ant_SpecialPacketNotify(pBtCoexist, packetType);
2288 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2289 EXhalbtc8821a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2290 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2291 EXhalbtc8821a1ant_SpecialPacketNotify(pBtCoexist, packetType);
2293 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2295 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2296 EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
2297 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2298 EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
2300 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2302 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2303 EXhalbtc8703b2ant_SpecialPacketNotify(pBtCoexist, packetType);
2304 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2305 EXhalbtc8703b1ant_SpecialPacketNotify(pBtCoexist, packetType);
2307 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2309 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2310 EXhalbtc8192e2ant_SpecialPacketNotify(pBtCoexist, packetType);
2311 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2312 EXhalbtc8192e1ant_SpecialPacketNotify(pBtCoexist, packetType);
2314 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2316 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2317 EXhalbtc8812a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2318 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2319 EXhalbtc8812a1ant_SpecialPacketNotify(pBtCoexist, packetType);
2322 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2325 void EXhalbtcoutsrc_BtInfoNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
2327 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2330 pBtCoexist->statistics.cntBtInfoNotify++;
2332 // All notify is called in cmd thread, don't need to leave low power again
2333 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2335 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2337 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2338 EXhalbtc8821aCsr2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2339 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2340 EXhalbtc8821a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2341 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2342 EXhalbtc8821a1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2344 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2346 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2347 EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2348 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2349 EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2351 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2353 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2354 EXhalbtc8703b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2355 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2356 EXhalbtc8703b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2358 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2360 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2361 EXhalbtc8192e2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2362 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2363 EXhalbtc8192e1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2365 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2367 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2368 EXhalbtc8812a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2369 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2370 EXhalbtc8812a1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2373 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2377 EXhalbtcoutsrc_RfStatusNotify(
2378 IN PBTC_COEXIST pBtCoexist,
2382 if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2384 pBtCoexist->statistics.cntRfStatusNotify++;
2386 if(IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2389 else if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2391 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2392 EXhalbtc8723b1ant_RfStatusNotify(pBtCoexist, type);
2394 else if(IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2396 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2397 EXhalbtc8703b1ant_RfStatusNotify(pBtCoexist, type);
2399 else if(IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2402 else if(IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2407 void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)
2412 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2414 pBtCoexist->statistics.cntStackOperationNotify++;
2415 if (pBtCoexist->bManualControl)
2418 if ((HCI_BT_OP_INQUIRY_START == type) ||
2419 (HCI_BT_OP_PAGING_START == type) ||
2420 (HCI_BT_OP_PAIRING_START == type))
2422 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START;
2424 else if ((HCI_BT_OP_INQUIRY_FINISH == type) ||
2425 (HCI_BT_OP_PAGING_SUCCESS == type) ||
2426 (HCI_BT_OP_PAGING_UNSUCCESS == type) ||
2427 (HCI_BT_OP_PAIRING_FINISH == type) )
2429 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
2433 stackOpType = BTC_STACK_OP_NONE;
2439 void EXhalbtcoutsrc_HaltNotify(PBTC_COEXIST pBtCoexist)
2441 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2444 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2446 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2447 EXhalbtc8821aCsr2ant_HaltNotify(pBtCoexist);
2448 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2449 EXhalbtc8821a2ant_HaltNotify(pBtCoexist);
2450 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2451 EXhalbtc8821a1ant_HaltNotify(pBtCoexist);
2453 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2455 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2456 EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
2457 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2458 EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
2460 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2462 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2463 EXhalbtc8703b2ant_HaltNotify(pBtCoexist);
2464 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2465 EXhalbtc8703b1ant_HaltNotify(pBtCoexist);
2467 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2469 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2470 EXhalbtc8192e2ant_HaltNotify(pBtCoexist);
2471 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2472 EXhalbtc8192e1ant_HaltNotify(pBtCoexist);
2474 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2476 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2477 EXhalbtc8812a2ant_HaltNotify(pBtCoexist);
2478 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2479 EXhalbtc8812a1ant_HaltNotify(pBtCoexist);
2482 pBtCoexist->bBinded = FALSE;
2485 void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)
2487 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2489 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2491 halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); //BT goto standby while GNT_BT 1-->0
2493 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2495 halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); //BT goto standby while GNT_BT 1-->0
2500 void EXhalbtcoutsrc_PnpNotify(PBTC_COEXIST pBtCoexist, u8 pnpState)
2502 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2506 // currently only 1ant we have to do the notification,
2507 // once pnp is notified to sleep state, we have to leave LPS that we can sleep normally.
2510 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2512 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2513 EXhalbtc8723b1ant_PnpNotify(pBtCoexist,pnpState);
2514 else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2515 EXhalbtc8723b2ant_PnpNotify(pBtCoexist,pnpState);
2517 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2519 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2520 EXhalbtc8703b1ant_PnpNotify(pBtCoexist,pnpState);
2521 else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2522 EXhalbtc8703b2ant_PnpNotify(pBtCoexist,pnpState);
2524 else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2526 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2527 EXhalbtc8821aCsr2ant_PnpNotify(pBtCoexist, pnpState);
2528 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2529 EXhalbtc8821a1ant_PnpNotify(pBtCoexist,pnpState);
2530 else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2531 EXhalbtc8821a2ant_PnpNotify(pBtCoexist,pnpState);
2533 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2535 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2536 EXhalbtc8192e1ant_PnpNotify(pBtCoexist, pnpState);
2538 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2540 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2541 EXhalbtc8812a1ant_PnpNotify(pBtCoexist, pnpState);
2545 void EXhalbtcoutsrc_ScoreBoardStatusNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
2547 if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2548 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2549 EXhalbtc8703b1ant_ScoreBoardStatusNotify(pBtCoexist, tmpBuf, length);
2553 void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)
2555 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2557 pBtCoexist->statistics.cntCoexDmSwitch++;
2559 halbtcoutsrc_LeaveLowPower(pBtCoexist);
2561 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2563 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2565 pBtCoexist->bStopCoexDm = TRUE;
2566 EXhalbtc8723b1ant_CoexDmReset(pBtCoexist);
2567 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
2568 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, FALSE);
2569 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
2570 pBtCoexist->bStopCoexDm = FALSE;
2574 halbtcoutsrc_NormalLowPower(pBtCoexist);
2577 void EXhalbtcoutsrc_Periodical(PBTC_COEXIST pBtCoexist)
2579 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2581 pBtCoexist->statistics.cntPeriodical++;
2583 // Periodical should be called in cmd thread,
2584 // don't need to leave low power again
2585 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2587 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2589 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2590 EXhalbtc8821aCsr2ant_Periodical(pBtCoexist);
2591 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2592 EXhalbtc8821a2ant_Periodical(pBtCoexist);
2593 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2595 if (!halbtcoutsrc_UnderIps(pBtCoexist))
2597 EXhalbtc8821a1ant_Periodical(pBtCoexist);
2601 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2603 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2604 EXhalbtc8723b2ant_Periodical(pBtCoexist);
2605 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2606 EXhalbtc8723b1ant_Periodical(pBtCoexist);
2608 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2610 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2611 EXhalbtc8703b2ant_Periodical(pBtCoexist);
2612 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2613 EXhalbtc8703b1ant_Periodical(pBtCoexist);
2615 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2617 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2618 EXhalbtc8192e2ant_Periodical(pBtCoexist);
2619 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2620 EXhalbtc8192e1ant_Periodical(pBtCoexist);
2622 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2624 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2625 EXhalbtc8812a2ant_Periodical(pBtCoexist);
2626 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2627 EXhalbtc8812a1ant_Periodical(pBtCoexist);
2630 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2633 void EXhalbtcoutsrc_DbgControl(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)
2635 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2638 pBtCoexist->statistics.cntDbgCtrl++;
2640 // This function doesn't be called yet,
2641 // default no need to leave low power to avoid deadlock
2642 // halbtcoutsrc_LeaveLowPower(pBtCoexist);
2644 if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2646 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2647 EXhalbtc8192e1ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2649 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2651 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2652 EXhalbtc8812a2ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2653 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2654 EXhalbtc8812a1ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2657 // halbtcoutsrc_NormalLowPower(pBtCoexist);
2662 EXhalbtcoutsrc_AntennaDetection(
2663 IN PBTC_COEXIST pBtCoexist,
2670 if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2673 /* Need to refine the following power save operations to enable this function in the future */
2675 IPSDisable(pBtCoexist->Adapter, FALSE, 0);
2676 LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);
2679 if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2681 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2682 EXhalbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds);
2685 //IPSReturn(pBtCoexist->Adapter, 0xff);
2689 void EXhalbtcoutsrc_StackUpdateProfileInfo(void)
2691 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
2692 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2693 PADAPTER padapter = (PADAPTER)GLBtCoexist.Adapter;
2694 PBT_MGNT pBtMgnt = &padapter->coex_info.BtMgnt;
2697 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2700 pBtCoexist->stackInfo.bProfileNotified = _TRUE;
2702 pBtCoexist->stackInfo.numOfLink =
2703 pBtMgnt->ExtConfig.NumberOfACL+pBtMgnt->ExtConfig.NumberOfSCO;
2706 pBtCoexist->stackInfo.bBtLinkExist = _FALSE;
2707 pBtCoexist->stackInfo.bScoExist = _FALSE;
2708 pBtCoexist->stackInfo.bAclExist = _FALSE;
2709 pBtCoexist->stackInfo.bA2dpExist = _FALSE;
2710 pBtCoexist->stackInfo.bHidExist = _FALSE;
2711 pBtCoexist->stackInfo.numOfHid = 0;
2712 pBtCoexist->stackInfo.bPanExist = _FALSE;
2714 if (!pBtMgnt->ExtConfig.NumberOfACL)
2715 pBtCoexist->stackInfo.minBtRssi = 0;
2717 if (pBtCoexist->stackInfo.numOfLink)
2719 pBtCoexist->stackInfo.bBtLinkExist = _TRUE;
2720 if (pBtMgnt->ExtConfig.NumberOfSCO)
2721 pBtCoexist->stackInfo.bScoExist = _TRUE;
2722 if (pBtMgnt->ExtConfig.NumberOfACL)
2723 pBtCoexist->stackInfo.bAclExist = _TRUE;
2726 for (i=0; i<pBtMgnt->ExtConfig.NumberOfACL; i++)
2728 if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2730 pBtCoexist->stackInfo.bA2dpExist = _TRUE;
2732 else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2734 pBtCoexist->stackInfo.bPanExist = _TRUE;
2736 else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2738 pBtCoexist->stackInfo.bHidExist = _TRUE;
2739 pBtCoexist->stackInfo.numOfHid++;
2743 pBtCoexist->stackInfo.bUnknownAclExist = _TRUE;
2746 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
2749 void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)
2751 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2753 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2756 pBtCoexist->stackInfo.minBtRssi = btRssi;
2759 void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)
2761 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2763 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2766 pBtCoexist->stackInfo.hciVersion = hciVersion;
2769 void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)
2771 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2773 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2776 pBtCoexist->btInfo.btRealFwVer = btPatchVersion;
2777 pBtCoexist->btInfo.btHciVer = btHciVersion;
2781 void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)
2783 GLBtCoexist.boardInfo.bBtExist = bBtExist;
2786 void EXhalbtcoutsrc_SetChipType(u8 chipType)
2795 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_UNDEF;
2798 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_CSR_BC4;
2801 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_CSR_BC8;
2804 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723A;
2807 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8821;
2810 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
2815 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
2817 if (BT_COEX_ANT_TYPE_PG == type)
2819 GLBtCoexist.boardInfo.pgAntNum = antNum;
2820 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2822 //The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1
2823 //The antenna position should be determined by auto-detect mechanism
2824 // The following is assumed to main, and those must be modified if y auto-detect mechanism is ready
2825 if ((GLBtCoexist.boardInfo.pgAntNum == 2) && (GLBtCoexist.boardInfo.btdmAntNum == 1) )
2826 GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2828 GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2831 else if (BT_COEX_ANT_TYPE_ANTDIV == type)
2833 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2834 //GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2836 else if (BT_COEX_ANT_TYPE_DETECTED == type)
2838 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2839 //GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2844 // Currently used by 8723b only, S0 or S1
2846 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
2848 GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
2851 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
2853 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2856 halbtcoutsrc_LeaveLowPower(pBtCoexist);
2858 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2860 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2861 EXhalbtc8821aCsr2ant_DisplayCoexInfo(pBtCoexist);
2862 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2863 EXhalbtc8821a2ant_DisplayCoexInfo(pBtCoexist);
2864 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2865 EXhalbtc8821a1ant_DisplayCoexInfo(pBtCoexist);
2867 else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2869 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2870 EXhalbtc8723b2ant_DisplayCoexInfo(pBtCoexist);
2871 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2872 EXhalbtc8723b1ant_DisplayCoexInfo(pBtCoexist);
2874 else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2876 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2877 EXhalbtc8703b2ant_DisplayCoexInfo(pBtCoexist);
2878 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2879 EXhalbtc8703b1ant_DisplayCoexInfo(pBtCoexist);
2881 else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2883 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2884 EXhalbtc8192e2ant_DisplayCoexInfo(pBtCoexist);
2885 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2886 EXhalbtc8192e1ant_DisplayCoexInfo(pBtCoexist);
2888 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2890 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2891 EXhalbtc8812a2ant_DisplayCoexInfo(pBtCoexist);
2892 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2893 EXhalbtc8812a1ant_DisplayCoexInfo(pBtCoexist);
2896 halbtcoutsrc_NormalLowPower(pBtCoexist);
2899 void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)
2901 if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2904 halbtcoutsrc_LeaveLowPower(pBtCoexist);
2906 if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2908 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2909 EXhalbtc8723b1ant_DisplayAntDetection(pBtCoexist);
2912 halbtcoutsrc_NormalLowPower(pBtCoexist);
2915 void EXhalbtcoutsrc_BTOffOnNotify(PBTC_COEXIST pBtCoexist, u8 bBTON)
2918 if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2919 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2920 EXhalbtc8812a2ant_BTOffOnNotify(pBtCoexist, (bBTON == _TRUE)?BTC_BT_ON:BTC_BT_OFF);
2925 static void halbt_InitHwConfig92C(PADAPTER padapter)
2927 PHAL_DATA_TYPE pHalData;
2931 pHalData = GET_HAL_DATA(padapter);
2932 if( (pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
2933 (pHalData->bt_coexist.btChipType == BT_CSR_BC8))
2935 if (pHalData->rf_type == RF_1T1R)
2938 u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
2940 rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
2941 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
2943 u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
2945 rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
2946 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
2951 static void halbt_InitHwConfig92D(PADAPTER padapter)
2953 PHAL_DATA_TYPE pHalData;
2956 pHalData = GET_HAL_DATA(padapter);
2957 if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
2958 (pHalData->bt_coexist.btChipType == BT_CSR_BC8))
2960 if (pHalData->rf_type == RF_1T1R)
2963 u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
2965 rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
2966 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
2968 u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
2970 rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
2971 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
2978 * Run BT-Coexist mechansim or not
2981 void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)
2983 PHAL_DATA_TYPE pHalData;
2986 pHalData = GET_HAL_DATA(padapter);
2987 pHalData->bt_coexist.bBtExist = bBtExist;
2989 //EXhalbtcoutsrc_SetBtExist(bBtExist);
2994 * Check is co-exist mechanism enabled or not
2997 * _TRUE Enable BT co-exist mechanism
2998 * _FALSE Disable BT co-exist mechanism
3000 u8 hal_btcoex_IsBtExist(PADAPTER padapter)
3002 PHAL_DATA_TYPE pHalData;
3005 pHalData = GET_HAL_DATA(padapter);
3006 return pHalData->bt_coexist.bBtExist;
3009 u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)
3011 if (!hal_btcoex_IsBtExist(padapter))
3014 if (GLBtCoexist.btInfo.bBtDisabled)
3020 void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)
3022 PHAL_DATA_TYPE pHalData;
3025 pHalData = GET_HAL_DATA(padapter);
3026 pHalData->bt_coexist.btChipType = chipType;
3028 EXhalbtcoutsrc_SetChipType(chipType);
3031 u8 hal_btcoex_GetChipType(PADAPTER padapter)
3033 PHAL_DATA_TYPE pHalData;
3036 pHalData = GET_HAL_DATA(padapter);
3037 return pHalData->bt_coexist.btChipType;
3040 void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)
3042 PHAL_DATA_TYPE pHalData;
3045 pHalData = GET_HAL_DATA(padapter);
3047 pHalData->bt_coexist.btTotalAntNum = antNum;
3048 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
3051 u8 hal_btcoex_GetPgAntNum(PADAPTER padapter)
3053 PHAL_DATA_TYPE pHalData;
3056 pHalData = GET_HAL_DATA(padapter);
3058 return pHalData->bt_coexist.btTotalAntNum;
3061 void hal_btcoex_SetSingleAntPath(PADAPTER padapter, u8 singleAntPath)
3063 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
3066 u8 hal_btcoex_Initialize(PADAPTER padapter)
3072 _rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
3073 ret1 = EXhalbtcoutsrc_InitlizeVariables((void*)padapter);
3074 ret2 = (ret1==_TRUE) ? _TRUE : _FALSE;
3079 void hal_btcoex_PowerOnSetting(PADAPTER padapter)
3081 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
3084 void hal_btcoex_PreLoadFirmware(PADAPTER padapter)
3086 EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);
3089 void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)
3091 if (!hal_btcoex_IsBtExist(padapter))
3094 EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
3095 EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
3098 void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)
3100 EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
3103 void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)
3105 EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
3108 void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)
3110 EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
3113 void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
3115 EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
3118 void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
3120 EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
3123 void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
3125 EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
3128 void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)
3130 GLBtcWiFiInIQKState = state;
3133 void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3135 if (GLBtcWiFiInIQKState == _TRUE)
3138 EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
3141 void hal_btcoex_BtMpRptNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3143 u8 extid, status, len, seq;
3146 if (!GLBtcBtMpRptWait)
3149 if ((length < 3) || (!tmpBuf))
3153 /* not response from BT FW then exit*/
3155 case C2H_WIFI_FW_ACTIVE_RSP:
3156 GLBtcBtMpRptWiFiOK = 1;
3159 case C2H_TRIG_BY_BT_FW:
3160 _cancel_timer_ex(&GLBtcBtMpOperTimer);
3161 GLBtcBtMpRptWait = 0;
3162 GLBtcBtMpRptBTOK = 1;
3169 status = tmpBuf[1] & 0xF;
3170 len = tmpBuf[1] >> 4;
3171 seq = tmpBuf[2] >> 4;
3173 GLBtcBtMpRptSeq = seq;
3174 GLBtcBtMpRptStatus = status;
3175 _rtw_memcpy(GLBtcBtMpRptRsp, tmpBuf+3, len);
3176 GLBtcBtMpRptRspSize = len;
3177 _rtw_up_sema(&GLBtcBtMpRptSema);
3180 void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
3183 state = BTC_WIFI_PNP_SLEEP;
3185 state = BTC_WIFI_PNP_WAKE_UP;
3187 EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
3190 void hal_btcoex_HaltNotify(PADAPTER padapter)
3192 EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
3195 void hal_btcoex_ScoreBoardStatusNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3197 EXhalbtcoutsrc_ScoreBoardStatusNotify(&GLBtCoexist, tmpBuf, length);
3200 void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)
3202 EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);
3205 void hal_btcoex_Hanlder(PADAPTER padapter)
3207 EXhalbtcoutsrc_Periodical(&GLBtCoexist);
3210 s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)
3212 return (s32)GLBtCoexist.btInfo.bRejectAggPkt;
3215 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
3217 return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
3220 u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)
3222 return (u32)GLBtCoexist.btInfo.aggBufSize;
3225 void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)
3227 GLBtCoexist.bManualControl = bmanual;
3230 u8 hal_btcoex_1Ant(PADAPTER padapter)
3232 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3235 if (GLBtCoexist.boardInfo.btdmAntNum == 1)
3241 u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)
3243 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3246 if (GLBtCoexist.btInfo.bBtDisabled)
3249 if (GLBtCoexist.btInfo.bBtCtrlLps)
3255 u8 hal_btcoex_IsLpsOn(PADAPTER padapter)
3257 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3260 if (GLBtCoexist.btInfo.bBtDisabled)
3263 if (GLBtCoexist.btInfo.bBtLpsOn)
3269 u8 hal_btcoex_RpwmVal(PADAPTER padapter)
3271 return GLBtCoexist.btInfo.rpwmVal;
3274 u8 hal_btcoex_LpsVal(PADAPTER padapter)
3276 return GLBtCoexist.btInfo.lpsVal;
3279 u32 hal_btcoex_GetRaMask(PADAPTER padapter)
3281 if (!hal_btcoex_IsBtExist(padapter))
3284 if (GLBtCoexist.btInfo.bBtDisabled)
3287 /* Modify by YiWei , suggest by Cosa and Jenyu
3288 * Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask.
3290 /*if (GLBtCoexist.boardInfo.btdmAntNum != 1)
3293 return GLBtCoexist.btInfo.raMask;
3296 void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
3298 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW write pwrModeCmd=0x%04x%08x\n",
3299 pCmdBuf[0]<<8|pCmdBuf[1],
3300 pCmdBuf[2]<<24|pCmdBuf[3]<<16|pCmdBuf[4]<<8|pCmdBuf[5]));
3302 _rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
3305 void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
3310 pinfo = &GLBtcDbgInfo;
3311 DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
3312 EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
3313 DBG_BT_INFO_INIT(pinfo, NULL, 0);
3316 void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
3321 if (NULL == pDbgModule)
3324 for (i = 0; i < COMP_MAX; i++)
3325 GLBtcDbgType[i] = pDbgModule[i];
3328 u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
3335 if ((NULL == pStrBuf) || (0 == bufSize))
3341 // DBG_871X(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize);
3343 count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
3344 if ((count < 0) || (count >= leftSize))
3349 count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
3350 if ((count < 0) || (count >= leftSize))
3355 count = rtw_sprintf(pstr, leftSize,
3356 "COMP_COEX: 0x%08X\n\n",
3357 GLBtcDbgType[COMP_COEX]);
3358 if ((count < 0) || (count >= leftSize))
3364 count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
3365 if ((count < 0) || (count >= leftSize))
3369 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
3370 GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_INIT?1:0);
3371 if ((count < 0) || (count >= leftSize))
3375 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
3376 GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_NOTIFY?1:0);
3377 if ((count < 0) || (count >= leftSize))
3382 count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
3383 if ((count < 0) || (count >= leftSize))
3387 count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
3388 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_RSSI_STATE?1:0);
3389 if ((count < 0) || (count >= leftSize))
3393 count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
3394 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_WIFI_RSSI_STATE?1:0);
3395 if ((count < 0) || (count >= leftSize))
3399 count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
3400 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_MONITOR?1:0);
3401 if ((count < 0) || (count >= leftSize))
3405 count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
3406 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE?1:0);
3407 if ((count < 0) || (count >= leftSize))
3411 count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
3412 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW?1:0);
3413 if ((count < 0) || (count >= leftSize))
3417 count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
3418 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_DETAIL?1:0);
3419 if ((count < 0) || (count >= leftSize))
3423 count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
3424 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_EXEC?1:0);
3425 if ((count < 0) || (count >= leftSize))
3429 count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
3430 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW?1:0);
3431 if ((count < 0) || (count >= leftSize))
3435 count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
3436 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_DETAIL?1:0);
3437 if ((count < 0) || (count >= leftSize))
3441 count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
3442 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_EXEC?1:0);
3443 if ((count < 0) || (count >= leftSize))
3450 count = pstr - pStrBuf;
3451 // DBG_871X(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count);
3456 u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
3458 if (!hal_btcoex_IsBtExist(padapter))
3461 if (GLBtCoexist.btInfo.bIncreaseScanDevNum)
3467 u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)
3469 if (GLBtCoexist.btLinkInfo.bBtLinkExist)
3475 void hal_btcoex_SetBtPatchVersion(PADAPTER padapter,u16 btHciVer,u16 btPatchVer)
3477 EXhalbtcoutsrc_SetBtPatchVersion(btHciVer,btPatchVer);
3480 void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)
3482 EXhalbtcoutsrc_SetHciVersion(hciVersion);
3485 void hal_btcoex_StackUpdateProfileInfo(void)
3487 EXhalbtcoutsrc_StackUpdateProfileInfo();
3490 void hal_btcoex_BTOffOnNotify(PADAPTER padapter, u8 bBTON)
3492 EXhalbtcoutsrc_BTOffOnNotify(&GLBtCoexist, bBTON);
3497 * Setting BT coex antenna isolation type .
3498 * coex mechanisn/ spital stream/ best throughput
3499 * anttype = 0 , PSTDMA / 2SS / 0.5T , bad isolation , WiFi/BT ANT Distance<15cm , (<20dB) for 2,3 antenna
3500 * anttype = 1 , PSTDMA / 1SS / 0.5T , normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 2 antenna
3501 * anttype = 2 , TDMA / 2SS / T , normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 3 antenna
3502 * anttype = 3 , no TDMA / 1SS / 0.5T , good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 2 antenna
3503 * anttype = 4 , no TDMA / 2SS / T , good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 3 antenna
3504 * wifi only throughput ~ T
3505 * wifi/BT share one antenna with SPDT
3507 void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)
3509 PHAL_DATA_TYPE pHalData;
3510 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3512 /*DBG_871X("####%s , anttype = %d , %d\n" , __func__ , anttype , __LINE__); */
3513 pHalData = GET_HAL_DATA(padapter);
3516 pHalData->bt_coexist.btAntisolation = anttype;
3518 switch (pHalData->bt_coexist.btAntisolation) {
3520 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_0;
3523 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_1;
3526 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_2;
3529 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_3;
3532 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_4;
3538 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
3540 hal_btcoex_ParseAntIsolationConfigFile(
3545 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
3547 char *szLine , *ptmp;
3548 int rtStatus = _SUCCESS;
3549 char param_value_string[10];
3553 u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1;
3555 typedef struct ant_isolation {
3556 char *param_name; /* antenna isolation config parameter name */
3557 u8 *value; /* antenna isolation config parameter value */
3560 ANT_ISOLATION ant_isolation_param[] = {
3561 {"ANT_NUMBER" , &ant_num},
3562 {"ANT_DISTANCE" , &ant_distance},
3563 {"RFE_TYPE" , &rfe_type},
3569 /* DBG_871X("===>Hal_ParseAntIsolationConfigFile()\n" ); */
3572 for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
3574 if (IsCommentString(szLine))
3577 /* DBG_871X("%s : szLine = %s , strlen(szLine) = %d\n" , __func__ , szLine , strlen(szLine));*/
3578 for (j = 0 ; ant_isolation_param[j].param_name != NULL ; j++) {
3579 if (strstr(szLine , ant_isolation_param[j].param_name) != NULL) {
3581 while (i < strlen(szLine)) {
3582 if (szLine[i] != '"')
3585 /* skip only has one " */
3586 if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) {
3587 DBG_871X("Fail to parse parameters , format error!\n");
3590 _rtw_memset((PVOID)param_value_string , 0 , 10);
3591 if (!ParseQualifiedString(szLine , &i , param_value_string , '"' , '"')) {
3592 DBG_871X("Fail to parse parameters\n");
3594 } else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value))
3595 DBG_871X("Fail to GetU1ByteIntegerFromStringInDecimal\n");
3604 /* YiWei 20140716 , for BT coex antenna isolation control */
3605 /* rfe_type = 0 was SPDT , rfe_type = 1 was coupler */
3606 if (ant_num == 3 && ant_distance >= 50)
3608 else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1)
3610 else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50)
3612 else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1)
3614 else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15))
3616 else if (ant_num == 2 && rfe_type == 0)
3621 hal_btcoex_SetAntIsolationType(Adapter, anttype);
3623 DBG_871X("%s : ant_num = %d\n" , __func__ , ant_num);
3624 DBG_871X("%s : ant_distance = %d\n" , __func__ , ant_distance);
3625 DBG_871X("%s : rfe_type = %d\n" , __func__ , rfe_type);
3626 /* DBG_871X("<===Hal_ParseAntIsolationConfigFile()\n"); */
3632 hal_btcoex_AntIsolationConfig_ParaFile(
3633 IN PADAPTER Adapter,
3637 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
3638 int rlen = 0 , rtStatus = _FAIL;
3640 _rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN);
3643 rtw_merge_string(rtw_phy_para_file_path, PATH_LENGTH_MAX, rtw_phy_file_path, pFileName);
3645 if (rtw_is_file_readable(rtw_phy_para_file_path) == _TRUE)
3647 rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
3650 rtStatus = _SUCCESS;
3655 if (rtStatus == _SUCCESS) {
3656 /*DBG_871X("%s(): read %s ok\n", __func__ , pFileName);*/
3657 rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf);
3659 DBG_871X("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName);
3664 #endif // CONFIG_LOAD_PHY_PARA_FROM_FILE
3666 u16 hal_btcoex_btreg_read(PADAPTER padapter, u8 type, u16 addr, u32 *data)
3670 halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
3672 ret = halbtcoutsrc_GetBtReg(&GLBtCoexist, type, addr, data);
3674 halbtcoutsrc_NormalLowPower(&GLBtCoexist);
3679 u16 hal_btcoex_btreg_write(PADAPTER padapter, u8 type, u16 addr, u16 val)
3683 halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
3685 ret = halbtcoutsrc_SetBtReg(&GLBtCoexist, type, addr, val);
3687 halbtcoutsrc_NormalLowPower(&GLBtCoexist);
3691 #endif // CONFIG_BT_COEXIST