net: wireless: rockchip_wlan: add rtl8188fu support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8188fu / hal / btc / HalBtc8821a1Ant.c
diff --git a/drivers/net/wireless/rockchip_wlan/rtl8188fu/hal/btc/HalBtc8821a1Ant.c b/drivers/net/wireless/rockchip_wlan/rtl8188fu/hal/btc/HalBtc8821a1Ant.c
new file mode 100644 (file)
index 0000000..c840c77
--- /dev/null
@@ -0,0 +1,3433 @@
+//============================================================\r
+// Description:\r
+//\r
+// This file is for 8821A_1ANT Co-exist mechanism\r
+//\r
+// History\r
+// 2012/11/15 Cosa first check in.\r
+//\r
+//============================================================\r
+\r
+//============================================================\r
+// include files\r
+//============================================================\r
+#include "Mp_Precomp.h"\r
+\r
+#if WPP_SOFTWARE_TRACE\r
+#include "HalBtc8821a1Ant.tmh"\r
+#endif\r
+\r
+#if(BT_30_SUPPORT == 1)\r
+//============================================================\r
+// Global variables, these are static variables\r
+//============================================================\r
+static COEX_DM_8821A_1ANT              GLCoexDm8821a1Ant;\r
+static PCOEX_DM_8821A_1ANT     pCoexDm=&GLCoexDm8821a1Ant;\r
+static COEX_STA_8821A_1ANT             GLCoexSta8821a1Ant;\r
+static PCOEX_STA_8821A_1ANT    pCoexSta=&GLCoexSta8821a1Ant;\r
+\r
+const char *const GLBtInfoSrc8821a1Ant[]={\r
+       "BT Info[wifi fw]",\r
+       "BT Info[bt rsp]",\r
+       "BT Info[bt auto report]",\r
+};\r
+\r
+u4Byte GLCoexVerDate8821a1Ant=20140306;\r
+u4Byte GLCoexVer8821a1Ant=0x4b;\r
+\r
+//============================================================\r
+// local function proto type if needed\r
+//============================================================\r
+//============================================================\r
+// local function start with halbtc8821a1ant_\r
+//============================================================\r
+u1Byte\r
+halbtc8821a1ant_BtRssiState(\r
+       u1Byte                  levelNum,\r
+       u1Byte                  rssiThresh,\r
+       u1Byte                  rssiThresh1\r
+       )\r
+{\r
+       s4Byte                  btRssi=0;\r
+       u1Byte                  btRssiState=pCoexSta->preBtRssiState;\r
+\r
+       btRssi = pCoexSta->btRssi;\r
+\r
+       if(levelNum == 2)\r
+       {                       \r
+               if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
+                       (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
+               {\r
+                       if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_HIGH;\r
+                       }\r
+                       else\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if(btRssi < rssiThresh)\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_LOW;\r
+                       }\r
+                       else\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
+                       }\r
+               }\r
+       }\r
+       else if(levelNum == 3)\r
+       {\r
+               if(rssiThresh > rssiThresh1)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Rssi thresh error!!\n"));\r
+                       return pCoexSta->preBtRssiState;\r
+               }\r
+               \r
+               if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
+                       (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
+               {\r
+                       if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_MEDIUM;\r
+                       }\r
+                       else\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
+                       }\r
+               }\r
+               else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
+                       (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))\r
+               {\r
+                       if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_HIGH;\r
+                       }\r
+                       else if(btRssi < rssiThresh)\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_LOW;\r
+                       }\r
+                       else\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if(btRssi < rssiThresh1)\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_MEDIUM;\r
+                       }\r
+                       else\r
+                       {\r
+                               btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
+                       }\r
+               }\r
+       }\r
+               \r
+       pCoexSta->preBtRssiState = btRssiState;\r
+\r
+       return btRssiState;\r
+}\r
+\r
+u1Byte\r
+halbtc8821a1ant_WifiRssiState(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  index,\r
+       IN      u1Byte                  levelNum,\r
+       IN      u1Byte                  rssiThresh,\r
+       IN      u1Byte                  rssiThresh1\r
+       )\r
+{\r
+       s4Byte                  wifiRssi=0;\r
+       u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
+       \r
+       if(levelNum == 2)\r
+       {\r
+               if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
+                       (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
+               {\r
+                       if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_HIGH;\r
+                       }\r
+                       else\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if(wifiRssi < rssiThresh)\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_LOW;\r
+                       }\r
+                       else\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
+                       }\r
+               }\r
+       }\r
+       else if(levelNum == 3)\r
+       {\r
+               if(rssiThresh > rssiThresh1)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi RSSI thresh error!!\n"));\r
+                       return pCoexSta->preWifiRssiState[index];\r
+               }\r
+               \r
+               if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
+                       (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
+               {\r
+                       if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
+                       }\r
+                       else\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
+                       }\r
+               }\r
+               else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||\r
+                       (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))\r
+               {\r
+                       if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8821A_1ANT))\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_HIGH;\r
+                       }\r
+                       else if(wifiRssi < rssiThresh)\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_LOW;\r
+                       }\r
+                       else\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if(wifiRssi < rssiThresh1)\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
+                       }\r
+                       else\r
+                       {\r
+                               wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
+                       }\r
+               }\r
+       }\r
+               \r
+       pCoexSta->preWifiRssiState[index] = wifiRssiState;\r
+\r
+       return wifiRssiState;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_UpdateRaMask(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                         bForceExec,\r
+       IN      u4Byte                          disRateMask\r
+       )\r
+{\r
+       pCoexDm->curRaMask = disRateMask;\r
+       \r
+       if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))\r
+       {\r
+               pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);\r
+       }\r
+       pCoexDm->preRaMask = pCoexDm->curRaMask;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_AutoRateFallbackRetry(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                         bForceExec,\r
+       IN      u1Byte                          type\r
+       )\r
+{\r
+       BOOLEAN bWifiUnderBMode=FALSE;\r
+       \r
+       pCoexDm->curArfrType = type;\r
+\r
+       if( bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType))\r
+       {\r
+               switch(pCoexDm->curArfrType)\r
+               {\r
+                       case 0: // normal mode\r
+                               pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, pCoexDm->backupArfrCnt1);\r
+                               pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, pCoexDm->backupArfrCnt2);\r
+                               break;\r
+                       case 1: \r
+                               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);\r
+                               if(bWifiUnderBMode)\r
+                               {\r
+                                       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);\r
+                                       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);\r
+                               }\r
+                               else\r
+                               {\r
+                                       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);\r
+                                       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);\r
+                               }\r
+                               break;\r
+                       default:\r
+                               break;\r
+               }\r
+       }\r
+\r
+       pCoexDm->preArfrType = pCoexDm->curArfrType;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_RetryLimit(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                         bForceExec,\r
+       IN      u1Byte                          type\r
+       )\r
+{\r
+       pCoexDm->curRetryLimitType = type;\r
+\r
+       if( bForceExec || (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType))\r
+       {\r
+               switch(pCoexDm->curRetryLimitType)\r
+               {\r
+                       case 0: // normal mode\r
+                               pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, pCoexDm->backupRetryLimit);\r
+                               break;\r
+                       case 1: // retry limit=8\r
+                               pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);\r
+                               break;\r
+                       default:\r
+                               break;\r
+               }\r
+       }\r
+\r
+       pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_AmpduMaxTime(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                         bForceExec,\r
+       IN      u1Byte                          type\r
+       )\r
+{\r
+       pCoexDm->curAmpduTimeType = type;\r
+\r
+       if( bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType))\r
+       {\r
+               switch(pCoexDm->curAmpduTimeType)\r
+               {\r
+                       case 0: // normal mode\r
+                               pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime);\r
+                               break;\r
+                       case 1: // AMPDU timw = 0x38 * 32us\r
+                               pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);\r
+                               break;\r
+                       default:\r
+                               break;\r
+               }\r
+       }\r
+\r
+       pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_LimitedTx(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                         bForceExec,\r
+       IN      u1Byte                          raMaskType,\r
+       IN      u1Byte                          arfrType,\r
+       IN      u1Byte                          retryLimitType,\r
+       IN      u1Byte                          ampduTimeType\r
+       )\r
+{\r
+       switch(raMaskType)\r
+       {\r
+               case 0: // normal mode\r
+                       halbtc8821a1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);\r
+                       break;\r
+               case 1: // disable cck 1/2\r
+                       halbtc8821a1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x00000003);\r
+                       break;\r
+               case 2: // disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4\r
+                       halbtc8821a1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);\r
+                       break;\r
+               default:\r
+                       break;\r
+       }\r
+\r
+       halbtc8821a1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);\r
+       halbtc8821a1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);\r
+       halbtc8821a1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_LimitedRx(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                         bForceExec,\r
+       IN      BOOLEAN                         bRejApAggPkt,\r
+       IN      BOOLEAN                         bBtCtrlAggBufSize,\r
+       IN      u1Byte                          aggBufSize\r
+       )\r
+{\r
+       BOOLEAN bRejectRxAgg=bRejApAggPkt;\r
+       BOOLEAN bBtCtrlRxAggSize=bBtCtrlAggBufSize;\r
+       u1Byte  rxAggSize=aggBufSize;\r
+\r
+       //============================================\r
+       //      Rx Aggregation related setting\r
+       //============================================\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);\r
+       // decide BT control aggregation buf size or not\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);\r
+       // aggregation buf size, only work when BT control Rx aggregation size.\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);\r
+       // real update aggregation setting\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);\r
+\r
+\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_MonitorBtCtr(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       u4Byte                  regHPTxRx, regLPTxRx, u4Tmp, u4Tmp1;\r
+       u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
+       u1Byte                  u1Tmp, u1Tmp1;\r
+       s4Byte                  wifiRssi;\r
+#if 0\r
+       //to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS\r
+       if (! (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) & 0x8) ) \r
+       {\r
+               pCoexSta->highPriorityTx = 65535;\r
+               pCoexSta->highPriorityRx = 65535;\r
+               pCoexSta->lowPriorityTx = 65535;\r
+               pCoexSta->lowPriorityRx = 65535;\r
+               return;\r
+       }\r
+#endif \r
+       regHPTxRx = 0x770;\r
+       regLPTxRx = 0x774;\r
+\r
+       u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
+       regHPTx = u4Tmp & bMaskLWord;\r
+       regHPRx = (u4Tmp & bMaskHWord)>>16;\r
+\r
+       u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
+       regLPTx = u4Tmp & bMaskLWord;\r
+       regLPRx = (u4Tmp & bMaskHWord)>>16;\r
+               \r
+       pCoexSta->highPriorityTx = regHPTx;\r
+       pCoexSta->highPriorityRx = regHPRx;\r
+       pCoexSta->lowPriorityTx = regLPTx;\r
+       pCoexSta->lowPriorityRx = regLPRx;\r
+\r
+       // reset counter\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_QueryBtInfo(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       u1Byte                  H2C_Parameter[1] ={0};\r
+\r
+       pCoexSta->bC2hBtInfoReqSent = TRUE;\r
+\r
+       H2C_Parameter[0] |= BIT0;       // trigger\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n", \r
+               H2C_Parameter[0]));\r
+\r
+       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);\r
+}\r
+\r
+BOOLEAN\r
+halbtc8821a1ant_IsWifiStatusChanged(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       static BOOLEAN  bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;\r
+       BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;\r
+       BOOLEAN bWifiConnected=FALSE;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
+\r
+       if(bWifiConnected)\r
+       {\r
+               if(bWifiBusy != bPreWifiBusy)\r
+               {\r
+                       bPreWifiBusy = bWifiBusy;\r
+                       return TRUE;\r
+               }\r
+               if(bUnder4way != bPreUnder4way)\r
+               {\r
+                       bPreUnder4way = bUnder4way;\r
+                       return TRUE;\r
+               }\r
+               if(bBtHsOn != bPreBtHsOn)\r
+               {\r
+                       bPreBtHsOn = bBtHsOn;\r
+                       return TRUE;\r
+               }\r
+       }\r
+\r
+       return FALSE;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_UpdateBtLinkInfo(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       BOOLEAN                         bBtHsOn=FALSE;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
+\r
+       pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;\r
+       pBtLinkInfo->bScoExist = pCoexSta->bScoExist;\r
+       pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;\r
+       pBtLinkInfo->bPanExist = pCoexSta->bPanExist;\r
+       pBtLinkInfo->bHidExist = pCoexSta->bHidExist;\r
+\r
+       // work around for HS mode.\r
+       if(bBtHsOn)\r
+       {\r
+               pBtLinkInfo->bPanExist = TRUE;\r
+               pBtLinkInfo->bBtLinkExist = TRUE;\r
+       }\r
+\r
+       // check if Sco only\r
+       if( pBtLinkInfo->bScoExist &&\r
+               !pBtLinkInfo->bA2dpExist &&\r
+               !pBtLinkInfo->bPanExist &&\r
+               !pBtLinkInfo->bHidExist )\r
+               pBtLinkInfo->bScoOnly = TRUE;\r
+       else\r
+               pBtLinkInfo->bScoOnly = FALSE;\r
+\r
+       // check if A2dp only\r
+       if( !pBtLinkInfo->bScoExist &&\r
+               pBtLinkInfo->bA2dpExist &&\r
+               !pBtLinkInfo->bPanExist &&\r
+               !pBtLinkInfo->bHidExist )\r
+               pBtLinkInfo->bA2dpOnly = TRUE;\r
+       else\r
+               pBtLinkInfo->bA2dpOnly = FALSE;\r
+\r
+       // check if Pan only\r
+       if( !pBtLinkInfo->bScoExist &&\r
+               !pBtLinkInfo->bA2dpExist &&\r
+               pBtLinkInfo->bPanExist &&\r
+               !pBtLinkInfo->bHidExist )\r
+               pBtLinkInfo->bPanOnly = TRUE;\r
+       else\r
+               pBtLinkInfo->bPanOnly = FALSE;\r
+       \r
+       // check if Hid only\r
+       if( !pBtLinkInfo->bScoExist &&\r
+               !pBtLinkInfo->bA2dpExist &&\r
+               !pBtLinkInfo->bPanExist &&\r
+               pBtLinkInfo->bHidExist )\r
+               pBtLinkInfo->bHidOnly = TRUE;\r
+       else\r
+               pBtLinkInfo->bHidOnly = FALSE;\r
+}\r
+\r
+u1Byte\r
+halbtc8821a1ant_ActionAlgorithm(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       BOOLEAN                         bBtHsOn=FALSE;\r
+       u1Byte                          algorithm=BT_8821A_1ANT_COEX_ALGO_UNDEFINED;\r
+       u1Byte                          numOfDiffProfile=0;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
+\r
+       if(!pBtLinkInfo->bBtLinkExist)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No BT link exists!!!\n"));\r
+               return algorithm;\r
+       }\r
+\r
+       if(pBtLinkInfo->bScoExist)\r
+               numOfDiffProfile++;\r
+       if(pBtLinkInfo->bHidExist)\r
+               numOfDiffProfile++;\r
+       if(pBtLinkInfo->bPanExist)\r
+               numOfDiffProfile++;\r
+       if(pBtLinkInfo->bA2dpExist)\r
+               numOfDiffProfile++;\r
+       \r
+       if(numOfDiffProfile == 1)\r
+       {\r
+               if(pBtLinkInfo->bScoExist)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO only\n"));\r
+                       algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;\r
+               }\r
+               else\r
+               {\r
+                       if(pBtLinkInfo->bHidExist)\r
+                       {\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID only\n"));\r
+                               algorithm = BT_8821A_1ANT_COEX_ALGO_HID;\r
+                       }\r
+                       else if(pBtLinkInfo->bA2dpExist)\r
+                       {\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP only\n"));\r
+                               algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP;\r
+                       }\r
+                       else if(pBtLinkInfo->bPanExist)\r
+                       {\r
+                               if(bBtHsOn)\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = PAN(HS) only\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_PANHS;\r
+                               }\r
+                               else\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = PAN(EDR) only\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       else if(numOfDiffProfile == 2)\r
+       {\r
+               if(pBtLinkInfo->bScoExist)\r
+               {\r
+                       if(pBtLinkInfo->bHidExist)\r
+                       {\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID\n"));\r
+                               algorithm = BT_8821A_1ANT_COEX_ALGO_HID;\r
+                       }\r
+                       else if(pBtLinkInfo->bA2dpExist)\r
+                       {\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"));\r
+                               algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;\r
+                       }\r
+                       else if(pBtLinkInfo->bPanExist)\r
+                       {\r
+                               if(bBtHsOn)\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + PAN(HS)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;\r
+                               }\r
+                               else\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + PAN(EDR)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if( pBtLinkInfo->bHidExist &&\r
+                               pBtLinkInfo->bA2dpExist )\r
+                       {\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP\n"));\r
+                               algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;\r
+                       }\r
+                       else if( pBtLinkInfo->bHidExist &&\r
+                               pBtLinkInfo->bPanExist )\r
+                       {\r
+                               if(bBtHsOn)\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + PAN(HS)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;\r
+                               }\r
+                               else\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + PAN(EDR)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;\r
+                               }\r
+                       }\r
+                       else if( pBtLinkInfo->bPanExist &&\r
+                               pBtLinkInfo->bA2dpExist )\r
+                       {\r
+                               if(bBtHsOn)\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP + PAN(HS)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS;\r
+                               }\r
+                               else\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP + PAN(EDR)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       else if(numOfDiffProfile == 3)\r
+       {\r
+               if(pBtLinkInfo->bScoExist)\r
+               {\r
+                       if( pBtLinkInfo->bHidExist &&\r
+                               pBtLinkInfo->bA2dpExist )\r
+                       {\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"));\r
+                               algorithm = BT_8821A_1ANT_COEX_ALGO_HID;\r
+                       }\r
+                       else if( pBtLinkInfo->bHidExist &&\r
+                               pBtLinkInfo->bPanExist )\r
+                       {\r
+                               if(bBtHsOn)\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;\r
+                               }\r
+                               else\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;\r
+                               }\r
+                       }\r
+                       else if( pBtLinkInfo->bPanExist &&\r
+                               pBtLinkInfo->bA2dpExist )\r
+                       {\r
+                               if(bBtHsOn)\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;\r
+                               }\r
+                               else\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       if( pBtLinkInfo->bHidExist &&\r
+                               pBtLinkInfo->bPanExist &&\r
+                               pBtLinkInfo->bA2dpExist )\r
+                       {\r
+                               if(bBtHsOn)\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;\r
+                               }\r
+                               else\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       else if(numOfDiffProfile >= 3)\r
+       {\r
+               if(pBtLinkInfo->bScoExist)\r
+               {\r
+                       if( pBtLinkInfo->bHidExist &&\r
+                               pBtLinkInfo->bPanExist &&\r
+                               pBtLinkInfo->bA2dpExist )\r
+                       {\r
+                               if(bBtHsOn)\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"));\r
+\r
+                               }\r
+                               else\r
+                               {\r
+                                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
+                                       algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       return algorithm;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_SetBtAutoReport(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bEnableAutoReport\r
+       )\r
+{\r
+       u1Byte                  H2C_Parameter[1] ={0};\r
+       \r
+       H2C_Parameter[0] = 0;\r
+\r
+       if(bEnableAutoReport)\r
+       {\r
+               H2C_Parameter[0] |= BIT0;\r
+       }\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n", \r
+               (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));\r
+\r
+       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);    \r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_BtAutoReport(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      BOOLEAN                 bEnableAutoReport\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s BT Auto report = %s\n",  \r
+               (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));\r
+       pCoexDm->bCurBtAutoReport = bEnableAutoReport;\r
+\r
+       if(!bForceExec)\r
+       {\r
+               if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport) \r
+                       return;\r
+       }\r
+       halbtc8821a1ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);\r
+\r
+       pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_SetSwPenaltyTxRateAdaptive(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bLowPenaltyRa\r
+       )\r
+{\r
+       u1Byte                  H2C_Parameter[6] ={0};\r
+       \r
+       H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty\r
+\r
+       if(bLowPenaltyRa)\r
+       {\r
+               H2C_Parameter[1] |= BIT0;\r
+               H2C_Parameter[2] = 0x00;  //normal rate except MCS7/6/5, OFDM54/48/36\r
+               H2C_Parameter[3] = 0xf7;  //MCS7 or OFDM54\r
+               H2C_Parameter[4] = 0xf8;  //MCS6 or OFDM48\r
+               H2C_Parameter[5] = 0xf9;        //MCS5 or OFDM36        \r
+       }\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set WiFi Low-Penalty Retry: %s", \r
+               (bLowPenaltyRa? "ON!!":"OFF!!") ));\r
+\r
+       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_LowPenaltyRa(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      BOOLEAN                 bLowPenaltyRa\r
+       )\r
+{\r
+       pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
+\r
+       if(!bForceExec)\r
+       {\r
+               if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
+                       return;\r
+       }\r
+       halbtc8821a1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
+\r
+       pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_SetCoexTable(\r
+       IN      PBTC_COEXIST    pBtCoexist,\r
+       IN      u4Byte          val0x6c0,\r
+       IN      u4Byte          val0x6c4,\r
+       IN      u4Byte          val0x6c8,\r
+       IN      u1Byte          val0x6cc\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
+       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));\r
+       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
+       pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_CoexTable(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      u4Byte                  val0x6c0,\r
+       IN      u4Byte                  val0x6c4,\r
+       IN      u4Byte                  val0x6c8,\r
+       IN      u1Byte                  val0x6cc\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", \r
+               (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6c8, val0x6cc));\r
+       pCoexDm->curVal0x6c0 = val0x6c0;\r
+       pCoexDm->curVal0x6c4 = val0x6c4;\r
+       pCoexDm->curVal0x6c8 = val0x6c8;\r
+       pCoexDm->curVal0x6cc = val0x6cc;\r
+\r
+       if(!bForceExec)\r
+       {\r
+               if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
+                       (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&\r
+                       (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
+                       (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
+                       return;\r
+       }\r
+       halbtc8821a1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);\r
+\r
+       pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
+       pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;\r
+       pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
+       pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_CoexTableWithType(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                         bForceExec,\r
+       IN      u1Byte                          type\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** CoexTable(%d) **********\n", type));\r
+       \r
+       switch(type)\r
+       {\r
+               case 0:\r
+                       halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3);\r
+                       break;\r
+               case 1:\r
+                       halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);\r
+                       break;\r
+               case 2:\r
+                       halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);\r
+                       break;\r
+               case 3:\r
+                       halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaaaaaa, 0xffffff, 0x3);\r
+                       break;\r
+               case 4:\r
+                       halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);\r
+                       break;\r
+               case 5:\r
+                       halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3);\r
+                       break;\r
+               case 6:\r
+                       halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);\r
+                       break;\r
+               case 7:\r
+                       halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);\r
+                       break;\r
+               default:\r
+                       break;\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_SetFwIgnoreWlanAct(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bEnable\r
+       )\r
+{\r
+       u1Byte                  H2C_Parameter[1] ={0};\r
+               \r
+       if(bEnable)\r
+       {\r
+               H2C_Parameter[0] |= BIT0;               // function enable\r
+       }\r
+       \r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", \r
+               H2C_Parameter[0]));\r
+\r
+       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_IgnoreWlanAct(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      BOOLEAN                 bEnable\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
+               (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
+       pCoexDm->bCurIgnoreWlanAct = bEnable;\r
+\r
+       if(!bForceExec)\r
+       {\r
+               if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
+                       return;\r
+       }\r
+       halbtc8821a1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
+\r
+       pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_SetFwPstdma(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  byte1,\r
+       IN      u1Byte                  byte2,\r
+       IN      u1Byte                  byte3,\r
+       IN      u1Byte                  byte4,\r
+       IN      u1Byte                  byte5\r
+       )\r
+{\r
+       u1Byte                  H2C_Parameter[5] ={0};\r
+       u1Byte                  realByte1=byte1, realByte5=byte5;\r
+       BOOLEAN                 bApEnable=FALSE;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
+\r
+       if(bApEnable)\r
+       {\r
+               if(byte1&BIT4 && !(byte1&BIT5))\r
+               {                       \r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW for 1Ant AP mode\n"));\r
+                       realByte1 &= ~BIT4;\r
+                       realByte1 |= BIT5;\r
+\r
+                       realByte5 |= BIT5;\r
+                       realByte5 &= ~BIT6;\r
+               }\r
+       }\r
+\r
+       H2C_Parameter[0] = realByte1;   \r
+       H2C_Parameter[1] = byte2;       \r
+       H2C_Parameter[2] = byte3;\r
+       H2C_Parameter[3] = byte4;\r
+       H2C_Parameter[4] = realByte5;\r
+\r
+       pCoexDm->psTdmaPara[0] = realByte1;\r
+       pCoexDm->psTdmaPara[1] = byte2;\r
+       pCoexDm->psTdmaPara[2] = byte3;\r
+       pCoexDm->psTdmaPara[3] = byte4;\r
+       pCoexDm->psTdmaPara[4] = realByte5;\r
+       \r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n", \r
+               H2C_Parameter[0], \r
+               H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
+\r
+       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_SetLpsRpwm(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  lpsVal,\r
+       IN      u1Byte                  rpwmVal\r
+       )\r
+{\r
+       u1Byte  lps=lpsVal;\r
+       u1Byte  rpwm=rpwmVal;\r
+       \r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_LpsRpwm(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      u1Byte                  lpsVal,\r
+       IN      u1Byte                  rpwmVal\r
+       )\r
+{\r
+       BOOLEAN bForceExecPwrCmd=FALSE;\r
+       \r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n", \r
+               (bForceExec? "force to":""), lpsVal, rpwmVal));\r
+       pCoexDm->curLps = lpsVal;\r
+       pCoexDm->curRpwm = rpwmVal;\r
+\r
+       if(!bForceExec)\r
+       {\r
+               if( (pCoexDm->preLps == pCoexDm->curLps) &&\r
+                       (pCoexDm->preRpwm == pCoexDm->curRpwm) )\r
+               {\r
+                       return;\r
+               }\r
+       }\r
+       halbtc8821a1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);\r
+\r
+       pCoexDm->preLps = pCoexDm->curLps;\r
+       pCoexDm->preRpwm = pCoexDm->curRpwm;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_SwMechanism(\r
+       IN      PBTC_COEXIST    pBtCoexist,     \r
+       IN      BOOLEAN         bLowPenaltyRA\r
+       ) \r
+{\r
+       halbtc8821a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_SetAntPath(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                          antPosType,\r
+       IN      BOOLEAN                         bInitHwCfg,\r
+       IN      BOOLEAN                         bWifiOff\r
+       )\r
+{\r
+       PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;\r
+       u4Byte                  fwVer=0, u4Tmp=0;\r
+       u1Byte                  H2C_Parameter[2] ={0};\r
+       \r
+       if(bInitHwCfg)\r
+       {\r
+               // 0x4c[23]=0, 0x4c[24]=1  Antenna control by WL/BT\r
+               u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
+               u4Tmp &=~BIT23;\r
+               u4Tmp |= BIT24;\r
+               pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
+\r
+               //0x765 = 0x18\r
+               pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x765, 0x18, 0x3);        \r
+\r
+               if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) \r
+               {\r
+                       //tell firmware "antenna inverse"  ==> WRONG firmware antenna control code.==>need fw to fix\r
+                       H2C_Parameter[0] = 1;\r
+                       H2C_Parameter[1] = 1;\r
+                       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);\r
+\r
+                       //pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x1); //Main Ant to  BT for IPS case 0x4c[23]=1\r
+               }\r
+               else\r
+               {\r
+                       //tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix\r
+                       H2C_Parameter[0] = 0;\r
+                       H2C_Parameter[1] = 1;\r
+                       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);\r
+\r
+                       //pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); //Aux Ant to  BT for IPS case 0x4c[23]=1\r
+               }\r
+       }\r
+       else if(bWifiOff)\r
+       {\r
+               // 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL   BT Vendor 0xac=0xf002\r
+               u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
+               u4Tmp &= ~BIT23;\r
+               u4Tmp &= ~BIT24;\r
+               pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
+\r
+               //0x765 = 0x18\r
+               pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x765, 0x18, 0x3); \r
+       }\r
+       else\r
+       {\r
+               //0x765 = 0x0\r
+               pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x765, 0x18, 0x0); \r
+       }\r
+       \r
+       // ext switch setting\r
+       switch(antPosType)\r
+       {\r
+               case BTC_ANT_PATH_WIFI:\r
+                       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb4, 0x77);\r
+                       if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
+                               pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x1);\r
+                       else\r
+                               pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x2);\r
+                       break;\r
+               case BTC_ANT_PATH_BT:\r
+                       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb4, 0x77);\r
+                       if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
+                               pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x2);\r
+                       else\r
+                               pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x1);\r
+                       break;\r
+               default:\r
+               case BTC_ANT_PATH_PTA:\r
+                       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb4, 0x66);\r
+                       if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
+                               pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x1);\r
+                       else\r
+                               pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x2);\r
+                       break;\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_PsTdma(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bForceExec,\r
+       IN      BOOLEAN                 bTurnOn,\r
+       IN      u1Byte                  type\r
+       )\r
+{\r
+       PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;\r
+       BOOLEAN                 bTurnOnByCnt=FALSE;\r
+       u1Byte                  psTdmaTypeByCnt=0, rssiAdjustVal=0;\r
+       //u4Byte                        fwVer=0;\r
+\r
+       pCoexDm->bCurPsTdmaOn = bTurnOn;\r
+       pCoexDm->curPsTdma = type;\r
+\r
+       if (pCoexDm->bCurPsTdmaOn)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(on, %d) **********\n", \r
+                       pCoexDm->curPsTdma));\r
+       }\r
+       else\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(off, %d) **********\n", \r
+                       pCoexDm->curPsTdma));\r
+       }\r
+\r
+       if(!bForceExec)\r
+       {\r
+               if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
+                       (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
+                       return;\r
+       }\r
+       if(bTurnOn)\r
+       {\r
+               switch(type)\r
+               {\r
+                       default:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, 0x50);\r
+                               break;\r
+                       case 1:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x3a, 0x03, 0x10, 0x50);\r
+                               rssiAdjustVal = 11;\r
+                               break;\r
+                       case 2:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x2b, 0x03, 0x10, 0x50);\r
+                               rssiAdjustVal = 14;\r
+                               break;\r
+                       case 3:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, 0x52);\r
+                               break;\r
+                       case 4:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);\r
+                               rssiAdjustVal = 17;\r
+                               break;\r
+                       case 5:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x15, 0x3, 0x11, 0x10);\r
+                               break;\r
+                       case 6:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x20, 0x3, 0x11, 0x13);\r
+                               break;\r
+                       case 7:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);\r
+                               break;\r
+                       case 8: \r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
+                               break;\r
+                       case 9: \r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x21, 0x3, 0x10, 0x50);\r
+                               rssiAdjustVal = 18;\r
+                               break;\r
+                       case 10:        \r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);\r
+                               break;\r
+                       case 11:        \r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x15, 0x03, 0x10, 0x50);\r
+                               rssiAdjustVal = 20;\r
+                               break;\r
+                       case 12:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50);\r
+                               break;\r
+                       case 13:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x12, 0x12, 0x0, 0x50);\r
+                               break;\r
+                       case 14:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x21, 0x3, 0x10, 0x52);\r
+                               break;\r
+                       case 15:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);\r
+                               break;\r
+                       case 16:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);\r
+                               rssiAdjustVal = 18;\r
+                               break;\r
+                       case 18:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
+                               rssiAdjustVal = 14;\r
+                               break;                  \r
+                       case 20:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x35, 0x03, 0x11, 0x10);\r
+                               break;\r
+                       case 21:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11);\r
+                               break;\r
+                       case 22:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x10);\r
+                               break;\r
+                       case 23:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);\r
+                               rssiAdjustVal = 22;\r
+                               break;\r
+                       case 24:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);\r
+                               rssiAdjustVal = 22;\r
+                               break;\r
+                       case 25:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
+                               rssiAdjustVal = 22;\r
+                               break;\r
+                       case 26:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
+                               rssiAdjustVal = 22;\r
+                               break;\r
+                       case 27:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);\r
+                               rssiAdjustVal = 22;\r
+                               break;\r
+                       case 28:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);\r
+                               break;\r
+                       case 29:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);\r
+                               break;\r
+                       case 30:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10);\r
+                               break;\r
+                       case 31:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);\r
+                               break;\r
+                       case 32:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x35, 0x3, 0x11, 0x11);\r
+                               break;\r
+                       case 33:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90);\r
+                               break;\r
+                       case 34:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10);\r
+                               break;\r
+                       case 35:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10);\r
+                               break;\r
+                       case 36:\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);\r
+                               break;\r
+                       case 40: // SoftAP only with no sta associated,BT disable ,TDMA mode for power saving\r
+                               /* here softap mode screen off will cost 70-80mA for phone */\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24);\r
+                               break;  \r
+               }\r
+       }\r
+       else\r
+       {\r
+               // disable PS tdma\r
+               switch(type)\r
+               {\r
+                       case 8: //PTA Control\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);\r
+                               halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FALSE, FALSE);\r
+                               break;\r
+                       case 0:\r
+                       default:  //Software control, Antenna at BT side\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
+                               halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
+                               break;\r
+                       case 9:   //Software control, Antenna at WiFi side\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
+                               halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FALSE, FALSE);\r
+                               break;\r
+                       case 10:        // under 5G\r
+                               halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);\r
+                               halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
+                               break;\r
+               }\r
+       }\r
+       rssiAdjustVal =0;\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);\r
+\r
+       // update pre state\r
+       pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
+       pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_CoexAllOff(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       // sw all off\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+\r
+       // hw all off\r
+       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
+}\r
+\r
+BOOLEAN\r
+halbtc8821a1ant_IsCommonAction(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
+\r
+       if(!bWifiConnected && \r
+               BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));\r
+               halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+\r
+               bCommon = TRUE;\r
+       }\r
+       else if(bWifiConnected && \r
+                       (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) )\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));\r
+               halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+\r
+               bCommon = TRUE;\r
+       }\r
+       else if(!bWifiConnected && \r
+               (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));\r
+               halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+\r
+               bCommon = TRUE;\r
+       }\r
+       else if(bWifiConnected && \r
+               (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));\r
+               halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+\r
+               bCommon = TRUE;\r
+       }\r
+       else if(!bWifiConnected && \r
+               (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus) )\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));\r
+               halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+               \r
+               bCommon = TRUE;\r
+       }\r
+       else\r
+       {\r
+               if (bWifiBusy)                  \r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));\r
+               }\r
+               else\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));\r
+               }\r
+               \r
+               bCommon = FALSE;\r
+       }\r
+       \r
+       return bCommon;\r
+}\r
+\r
+\r
+VOID\r
+halbtc8821a1ant_TdmaDurationAdjustForAcl(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                          wifiStatus\r
+       )\r
+{\r
+       static s4Byte           up,dn,m,n,WaitCount;\r
+       s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
+       u1Byte                  retryCount=0, btInfoExt;\r
+\r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));\r
+\r
+       if( (BT_8821A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||\r
+               (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||\r
+               (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )\r
+       {\r
+               if( pCoexDm->curPsTdma != 1 &&\r
+                       pCoexDm->curPsTdma != 2 &&\r
+                       pCoexDm->curPsTdma != 3 &&\r
+                       pCoexDm->curPsTdma != 9 )\r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
+                       pCoexDm->psTdmaDuAdjType = 9;\r
+\r
+                       up = 0;\r
+                       dn = 0;\r
+                       m = 1;\r
+                       n= 3;\r
+                       result = 0;\r
+                       WaitCount = 0;\r
+               }               \r
+               return;\r
+       }\r
+       \r
+       if(!pCoexDm->bAutoTdmaAdjust)\r
+       {\r
+               pCoexDm->bAutoTdmaAdjust = TRUE;\r
+               RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
+\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
+               pCoexDm->psTdmaDuAdjType = 2;\r
+               //============\r
+               up = 0;\r
+               dn = 0;\r
+               m = 1;\r
+               n= 3;\r
+               result = 0;\r
+               WaitCount = 0;\r
+       }\r
+       else\r
+       {\r
+               //accquire the BT TRx retry count from BT_Info byte2\r
+               retryCount = pCoexSta->btRetryCnt;\r
+               btInfoExt = pCoexSta->btInfoExt;\r
+               result = 0;\r
+               WaitCount++; \r
+                 \r
+               if(retryCount == 0)  // no retry in the last 2-second duration\r
+               {\r
+                       up++;\r
+                       dn--;\r
+\r
+                       if (dn <= 0)\r
+                               dn = 0;                          \r
+\r
+                       if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
+                       {\r
+                               WaitCount = 0; \r
+                               n = 3;\r
+                               up = 0;\r
+                               dn = 0;\r
+                               result = 1; \r
+                               RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));\r
+                       }\r
+               }\r
+               else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
+               {\r
+                       up--; \r
+                       dn++;\r
+\r
+                       if (up <= 0)\r
+                               up = 0;\r
+\r
+                       if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
+                       {\r
+                               if (WaitCount <= 2)\r
+                                       m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
+                               else\r
+                                       m = 1;\r
+\r
+                               if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
+                                       m = 20;\r
+\r
+                               n = 3*m;\r
+                               up = 0;\r
+                               dn = 0;\r
+                               WaitCount = 0;\r
+                               result = -1; \r
+                               RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
+                       }\r
+               }\r
+               else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
+               {\r
+                       if (WaitCount == 1)\r
+                               m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
+                       else\r
+                               m = 1;\r
+\r
+                       if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
+                               m = 20;\r
+\r
+                       n = 3*m;\r
+                       up = 0;\r
+                       dn = 0;\r
+                       WaitCount = 0; \r
+                       result = -1;\r
+                       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
+               }\r
+\r
+               if(result == -1)\r
+               {\r
+                       if( (BT_INFO_8821A_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
+                               ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
+                       {\r
+                               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
+                               pCoexDm->psTdmaDuAdjType = 9;\r
+                       }\r
+                       else if(pCoexDm->curPsTdma == 1)\r
+                       {\r
+                               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
+                               pCoexDm->psTdmaDuAdjType = 2;\r
+                       }\r
+                       else if(pCoexDm->curPsTdma == 2)\r
+                       {\r
+                               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
+                               pCoexDm->psTdmaDuAdjType = 9;\r
+                       }\r
+                       else if(pCoexDm->curPsTdma == 9)\r
+                       {\r
+                               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
+                               pCoexDm->psTdmaDuAdjType = 11;\r
+                       }\r
+               }\r
+               else if(result == 1)\r
+               {\r
+                       if( (BT_INFO_8821A_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
+                               ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
+                       {\r
+                               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
+                               pCoexDm->psTdmaDuAdjType = 9;\r
+                       }\r
+                       else if(pCoexDm->curPsTdma == 11)\r
+                       {\r
+                               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
+                               pCoexDm->psTdmaDuAdjType = 9;\r
+                       }\r
+                       else if(pCoexDm->curPsTdma == 9)\r
+                       {\r
+                               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
+                               pCoexDm->psTdmaDuAdjType = 2;\r
+                       }\r
+                       else if(pCoexDm->curPsTdma == 2)\r
+                       {\r
+                               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
+                               pCoexDm->psTdmaDuAdjType = 1;\r
+                       }\r
+               }\r
+               else      //no change\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(on, %d) **********\n", \r
+                               pCoexDm->curPsTdma));\r
+               }\r
+\r
+               if( pCoexDm->curPsTdma != 1 &&\r
+                       pCoexDm->curPsTdma != 2 &&\r
+                       pCoexDm->curPsTdma != 9 &&\r
+                       pCoexDm->curPsTdma != 11 )\r
+               {\r
+                       // recover to previous adjust type\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
+               }\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_PsTdmaCheckForPowerSaveState(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                 bNewPsState\r
+       )\r
+{\r
+       u1Byte  lpsMode=0x0;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);\r
+       \r
+       if(lpsMode)     // already under LPS state\r
+       {\r
+               if(bNewPsState)         \r
+               {\r
+                       // keep state under LPS, do nothing.\r
+               }\r
+               else\r
+               {\r
+                       // will leave LPS state, turn off psTdma first\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
+               }\r
+       }\r
+       else                                            // NO PS state\r
+       {\r
+               if(bNewPsState)\r
+               {\r
+                       // will enter LPS state, turn off psTdma first\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
+               }\r
+               else\r
+               {\r
+                       // keep state under NO PS state, do nothing.\r
+               }\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_PowerSaveState(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                          psType,\r
+       IN      u1Byte                          lpsVal,\r
+       IN      u1Byte                          rpwmVal\r
+       )\r
+{\r
+       BOOLEAN         bLowPwrDisable=FALSE;\r
+\r
+       switch(psType)\r
+       {\r
+               case BTC_PS_WIFI_NATIVE:\r
+                       // recover to original 32k low power setting\r
+                       bLowPwrDisable = FALSE;\r
+                       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
+                       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
+                       break;\r
+               case BTC_PS_LPS_ON:\r
+                       halbtc8821a1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);\r
+                       halbtc8821a1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);\r
+                       // when coex force to enter LPS, do not enter 32k low power.\r
+                       bLowPwrDisable = TRUE;\r
+                       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
+                       // power save must executed before psTdma.\r
+                       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);\r
+                       break;\r
+               case BTC_PS_LPS_OFF:\r
+                       halbtc8821a1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);\r
+                       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
+                       break;\r
+               default:\r
+                       break;\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_CoexUnder5G(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+\r
+       halbtc8821a1ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, TRUE);\r
+\r
+       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 10);\r
+\r
+       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
+\r
+       halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
+\r
+       halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 5);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionWifiOnly(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
+       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_MonitorBtEnableDisable(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       static BOOLEAN  bPreBtDisabled=FALSE;\r
+       static u4Byte           btDisableCnt=0;\r
+       BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
+\r
+       // This function check if bt is disabled\r
+\r
+       if(     pCoexSta->highPriorityTx == 0 &&\r
+               pCoexSta->highPriorityRx == 0 &&\r
+               pCoexSta->lowPriorityTx == 0 &&\r
+               pCoexSta->lowPriorityRx == 0)\r
+       {\r
+               bBtActive = FALSE;\r
+       }\r
+       if(     pCoexSta->highPriorityTx == 0xffff &&\r
+               pCoexSta->highPriorityRx == 0xffff &&\r
+               pCoexSta->lowPriorityTx == 0xffff &&\r
+               pCoexSta->lowPriorityRx == 0xffff)\r
+       {\r
+               bBtActive = FALSE;\r
+       }\r
+       if(bBtActive)\r
+       {\r
+               btDisableCnt = 0;\r
+               bBtDisabled = FALSE;\r
+               pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is enabled !!\n"));\r
+       }\r
+       else\r
+       {\r
+               btDisableCnt++;\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt all counters=0, %d times!!\n", \r
+                               btDisableCnt));\r
+               if(btDisableCnt >= 2)\r
+               {\r
+                       bBtDisabled = TRUE;\r
+                       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is disabled !!\n"));\r
+                       halbtc8821a1ant_ActionWifiOnly(pBtCoexist);\r
+               }\r
+       }\r
+       if(bPreBtDisabled != bBtDisabled)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n", \r
+                       (bPreBtDisabled ? "disabled":"enabled"), \r
+                       (bBtDisabled ? "disabled":"enabled")));\r
+               bPreBtDisabled = bBtDisabled;\r
+               if(!bBtDisabled)\r
+               {\r
+               }\r
+               else\r
+               {\r
+                       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
+                       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
+               }\r
+       }\r
+}\r
+\r
+//=============================================\r
+//\r
+//     Software Coex Mechanism start\r
+//\r
+//=============================================\r
+\r
+// SCO only or SCO+PAN(HS)\r
+VOID\r
+halbtc8821a1ant_ActionSco(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, TRUE);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionHid(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, TRUE);\r
+}\r
+\r
+//A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
+VOID\r
+halbtc8821a1ant_ActionA2dp(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionA2dpPanHs(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionPanEdr(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+}\r
+\r
+//PAN(HS) only\r
+VOID\r
+halbtc8821a1ant_ActionPanHs(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+}\r
+\r
+//PAN(EDR)+A2DP\r
+VOID\r
+halbtc8821a1ant_ActionPanEdrA2dp(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionPanEdrHid(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, TRUE);\r
+}\r
+\r
+// HID+A2DP+PAN(EDR)\r
+VOID\r
+halbtc8821a1ant_ActionHidA2dpPanEdr(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, TRUE);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionHidA2dp(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, TRUE);\r
+}\r
+\r
+//=============================================\r
+//\r
+//     Non-Software Coex Mechanism start\r
+//\r
+//=============================================\r
+VOID\r
+halbtc8821a1ant_ActionWifiMultiPort(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+       \r
+       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionHs(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
+       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionBtInquiry(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{      \r
+       PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       BOOLEAN                 bWifiConnected=FALSE, bApEnable=FALSE, bWifiBusy=FALSE, bBtBusy=FALSE;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
+\r
+       if((!bWifiConnected) && (!pCoexSta->bWiFiIsHighPriTask))\r
+       {\r
+               halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);          \r
+       }\r
+       else if((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist))\r
+       {\r
+               // SCO/HID/A2DP  busy\r
+               halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
+\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
+       }\r
+       else if ((pBtLinkInfo->bPanExist) || (bWifiBusy))\r
+       {\r
+               halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);              \r
+               \r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
+       }\r
+       else\r
+       {\r
+               halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionBtScoHidOnlyBusy(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                          wifiStatus\r
+       )\r
+{\r
+       PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       BOOLEAN bWifiConnected=FALSE;\r
+       u1Byte  wifiRssiState=BTC_RSSI_STATE_HIGH;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+\r
+       // tdma and coex table\r
+\r
+       if(pBtLinkInfo->bScoExist)\r
+       {\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+       }\r
+       else //HID\r
+       {\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionWifiConnectedBtAclBusy(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                          wifiStatus\r
+       )\r
+{\r
+       u1Byte          btRssiState;\r
+       \r
+       PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       btRssiState = halbtc8821a1ant_BtRssiState(2, 28, 0);    \r
+\r
+       if(pBtLinkInfo->bHidOnly)  //HID\r
+       {\r
+               halbtc8821a1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);\r
+               pCoexDm->bAutoTdmaAdjust = FALSE;\r
+               return;\r
+       }\r
+       else if(pBtLinkInfo->bA2dpOnly)  //A2DP         \r
+       {\r
+               if(BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)\r
+               {\r
+                       //halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+                       //halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
+                       pCoexDm->bAutoTdmaAdjust = FALSE;\r
+               }\r
+               else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
+                       (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )     \r
+               {\r
+                       halbtc8821a1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
+               }\r
+               else //for low BT RSSI\r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
+                       pCoexDm->bAutoTdmaAdjust = FALSE;\r
+               }\r
+       }\r
+       else if(pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist)  //HID+A2DP\r
+       {\r
+               if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
+                       (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )     \r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
+                       pCoexDm->bAutoTdmaAdjust = FALSE;\r
+               }\r
+               else //for low BT RSSI\r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
+                       pCoexDm->bAutoTdmaAdjust = FALSE;\r
+               }                       \r
+\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 6);\r
+       }\r
+       else if( (pBtLinkInfo->bPanOnly) || (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist) ) //PAN(OPP,FTP), HID+PAN(OPP,FTP)                 \r
+       {\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 6);\r
+               pCoexDm->bAutoTdmaAdjust = FALSE;\r
+       }\r
+       else if ( ((pBtLinkInfo->bA2dpExist) && (pBtLinkInfo->bPanExist)) ||\r
+                      (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist&&pBtLinkInfo->bPanExist) ) //A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP)\r
+       {\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
+               pCoexDm->bAutoTdmaAdjust = FALSE;\r
+       }\r
+       else\r
+       {               \r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
+               pCoexDm->bAutoTdmaAdjust = FALSE;\r
+       }       \r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionWifiNotConnected(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       // power save state\r
+       halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+\r
+       // tdma and coex table  \r
+       halbtc8821a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
+       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionWifiNotConnectedScan(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       \r
+       halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+       \r
+       // tdma and coex table\r
+       if(BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
+       {\r
+               if (pBtLinkInfo->bA2dpExist)\r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
+               }\r
+               else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)\r
+        {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
+               }\r
+               else\r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
+               }\r
+       }\r
+       else if( (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
+                       (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
+       {\r
+               halbtc8821a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
+                       BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
+       }\r
+       else\r
+       {\r
+               //halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
+               //halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
+\r
+               //Bryant Add\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionWifiNotConnectedAssoAuth(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       \r
+       halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+\r
+       // tdma and coex table\r
+       if( (pBtLinkInfo->bScoExist)  || (pBtLinkInfo->bHidExist) )\r
+       {\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
+       }\r
+       else if( (pBtLinkInfo->bA2dpExist)  || (pBtLinkInfo->bPanExist) )                       \r
+       {\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
+       }\r
+       else    \r
+       {               \r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionWifiConnectedScan(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       \r
+       halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+\r
+       // tdma and coex table\r
+       if(BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
+       {\r
+               if (pBtLinkInfo->bA2dpExist)\r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
+               }\r
+               else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)\r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
+               }\r
+               else\r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
+               }\r
+       }\r
+       else if( (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
+                       (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
+       {\r
+               halbtc8821a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
+                       BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
+       }\r
+       else\r
+       {\r
+               //halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
+               //halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
+\r
+               //Bryant Add\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionWifiConnectedSpecialPacket(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+\r
+       halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+\r
+       // tdma and coex table\r
+       if((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist))\r
+       {\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
+       }\r
+       else if(pBtLinkInfo->bPanExist) \r
+       {\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
+       }\r
+       else    \r
+       {               \r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_ActionWifiConnected(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       BOOLEAN         bWifiBusy=FALSE;\r
+       BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
+       BOOLEAN         bUnder4way=FALSE, bApEnable=FALSE;\r
+       u4Byte          wifiBw;\r
+\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect()===>\n"));\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
+       if(bUnder4way)\r
+       {\r
+               halbtc8821a1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));\r
+               return;\r
+       }\r
+       \r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
+       if(bScan || bLink || bRoam)\r
+       {\r
+               if(bScan)       \r
+                       halbtc8821a1ant_ActionWifiConnectedScan(pBtCoexist);\r
+               else\r
+                       halbtc8821a1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));\r
+               return;\r
+       }\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
+       // power save state\r
+       if(!bApEnable && BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)\r
+       {\r
+               if(!bWifiBusy && pBtCoexist->btLinkInfo.bA2dpOnly)      //A2DP\r
+                       halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+               else\r
+                       halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);\r
+       }\r
+       else\r
+               halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+\r
+       // tdma and coex table\r
+       if(!bWifiBusy)\r
+       {\r
+               if(BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
+               {\r
+                       halbtc8821a1ant_ActionWifiConnectedBtAclBusy(pBtCoexist, \r
+                               BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
+               }\r
+               else if( (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
+                       (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
+               {\r
+                       halbtc8821a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
+                               BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
+               }\r
+               else\r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+               }\r
+       }\r
+       else\r
+       {\r
+               if(BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
+               {\r
+                       halbtc8821a1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,\r
+                               BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
+               }\r
+               else if( (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
+                       (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
+               {\r
+                       halbtc8821a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
+                               BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
+               }\r
+               else \r
+               {\r
+                       halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
+                       halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+               }\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_RunSwCoexistMechanism(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       u1Byte  algorithm=0;\r
+\r
+       algorithm = halbtc8821a1ant_ActionAlgorithm(pBtCoexist);\r
+       pCoexDm->curAlgorithm = algorithm;\r
+\r
+       if(halbtc8821a1ant_IsCommonAction(pBtCoexist))\r
+       {\r
+\r
+       }\r
+       else\r
+       {\r
+               switch(pCoexDm->curAlgorithm)\r
+               {\r
+                       case BT_8821A_1ANT_COEX_ALGO_SCO:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = SCO.\n"));\r
+                               halbtc8821a1ant_ActionSco(pBtCoexist);\r
+                               break;\r
+                       case BT_8821A_1ANT_COEX_ALGO_HID:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID.\n"));\r
+                               halbtc8821a1ant_ActionHid(pBtCoexist);\r
+                               break;\r
+                       case BT_8821A_1ANT_COEX_ALGO_A2DP:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = A2DP.\n"));\r
+                               halbtc8821a1ant_ActionA2dp(pBtCoexist);\r
+                               break;\r
+                       case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));\r
+                               halbtc8821a1ant_ActionA2dpPanHs(pBtCoexist);\r
+                               break;\r
+                       case BT_8821A_1ANT_COEX_ALGO_PANEDR:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN(EDR).\n"));\r
+                               halbtc8821a1ant_ActionPanEdr(pBtCoexist);\r
+                               break;\r
+                       case BT_8821A_1ANT_COEX_ALGO_PANHS:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HS mode.\n"));\r
+                               halbtc8821a1ant_ActionPanHs(pBtCoexist);\r
+                               break;\r
+                       case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));\r
+                               halbtc8821a1ant_ActionPanEdrA2dp(pBtCoexist);\r
+                               break;\r
+                       case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));\r
+                               halbtc8821a1ant_ActionPanEdrHid(pBtCoexist);\r
+                               break;\r
+                       case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));\r
+                               halbtc8821a1ant_ActionHidA2dpPanEdr(pBtCoexist);\r
+                               break;\r
+                       case BT_8821A_1ANT_COEX_ALGO_HID_A2DP:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID+A2DP.\n"));\r
+                               halbtc8821a1ant_ActionHidA2dp(pBtCoexist);\r
+                               break;\r
+                       default:\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = coexist All Off!!\n"));\r
+                               //halbtc8821a1ant_CoexAllOff(pBtCoexist);\r
+                               break;\r
+               }\r
+               pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_RunCoexistMechanism(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;\r
+       BOOLEAN bIncreaseScanDevNum=FALSE;\r
+       BOOLEAN bBtCtrlAggBufSize=FALSE;\r
+       u1Byte  aggBufSize=5;\r
+       u1Byte  wifiRssiState=BTC_RSSI_STATE_HIGH;\r
+       u4Byte  wifiLinkStatus=0;\r
+       u4Byte  numOfWifiLink=0;\r
+       BOOLEAN bWifiUnder5G=FALSE;\r
+\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism()===>\n"));\r
+\r
+       if(pBtCoexist->bManualControl)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));\r
+               return;\r
+       }\r
+\r
+       if(pBtCoexist->bStopCoexDm)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));\r
+               return;\r
+       }\r
+\r
+       if(pCoexSta->bUnderIps)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is under IPS !!!\n"));\r
+               return;\r
+       }\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
+       if(bWifiUnder5G)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for 5G <===\n"));\r
+               halbtc8821a1ant_CoexUnder5G(pBtCoexist);\r
+               return;\r
+       }\r
+\r
+       if( (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
+               (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
+               (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
+       {\r
+               bIncreaseScanDevNum = TRUE;\r
+       }\r
+\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, &bIncreaseScanDevNum);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
+       numOfWifiLink = wifiLinkStatus>>16;\r
+       if((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))\r
+       {\r
+               halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
+               halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
+               halbtc8821a1ant_ActionWifiMultiPort(pBtCoexist);\r
+               return;\r
+       }\r
+\r
+       if(!pBtLinkInfo->bScoExist && !pBtLinkInfo->bHidExist)\r
+       {\r
+               halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
+       }\r
+       else\r
+       {\r
+               if(bWifiConnected)\r
+               {\r
+                       wifiRssiState = halbtc8821a1ant_WifiRssiState(pBtCoexist, 1, 2, 30, 0);\r
+                       if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
+                               (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
+                       {\r
+                               halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 1, 1);\r
+                       }\r
+                       else\r
+                       {\r
+                               halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 1, 1);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
+               }\r
+\r
+       }\r
+\r
+       if(pBtLinkInfo->bScoExist)\r
+       {\r
+               bBtCtrlAggBufSize = TRUE;\r
+               aggBufSize = 0x3;\r
+       }\r
+       else if(pBtLinkInfo->bHidExist)\r
+       {\r
+               bBtCtrlAggBufSize = TRUE;\r
+               aggBufSize = 0x5;\r
+       }\r
+       else if(pBtLinkInfo->bA2dpExist || pBtLinkInfo->bPanExist)\r
+       {\r
+               bBtCtrlAggBufSize = TRUE;\r
+               aggBufSize = 0x8;\r
+       }\r
+       halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
+\r
+       halbtc8821a1ant_RunSwCoexistMechanism(pBtCoexist);\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
+       if(pCoexSta->bC2hBtInquiryPage)\r
+       {\r
+               halbtc8821a1ant_ActionBtInquiry(pBtCoexist);\r
+               return;\r
+       }\r
+       else if(bBtHsOn)\r
+       {\r
+               halbtc8821a1ant_ActionHs(pBtCoexist);\r
+               return;\r
+       }\r
+\r
+       \r
+       if(!bWifiConnected)\r
+       {\r
+               BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
+               \r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is non connected-idle !!!\n"));\r
+\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
+\r
+               if(bScan || bLink || bRoam)\r
+               {\r
+                        if (bScan)     \r
+                               halbtc8821a1ant_ActionWifiNotConnectedScan(pBtCoexist); \r
+                        else\r
+                               halbtc8821a1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);     \r
+               }\r
+               else\r
+                       halbtc8821a1ant_ActionWifiNotConnected(pBtCoexist);\r
+       }\r
+       else    // wifi LPS/Busy\r
+       {       \r
+               halbtc8821a1ant_ActionWifiConnected(pBtCoexist);\r
+       }\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_InitCoexDm(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       // force to reset coex mechanism\r
+       // sw all off\r
+       halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
+\r
+       //halbtc8821a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
+       halbtc8821a1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
+}\r
+\r
+VOID\r
+halbtc8821a1ant_InitHwConfig(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                         bBackUp,\r
+       IN      BOOLEAN                         bWifiOnly\r
+       )\r
+{\r
+       PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
+       u4Byte  u4Tmp=0;\r
+       u2Byte                          u2Tmp=0;\r
+       u1Byte  u1Tmp=0;\r
+       u1Byte                          H2C_Parameter[2] ={0};\r
+       BOOLEAN                 bWifiUnder5G=FALSE;\r
+               \r
+       \r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 1Ant Init HW Config!!\n"));\r
+\r
+       if(bWifiOnly)\r
+               return;\r
+       \r
+       if(bBackUp)\r
+       {\r
+               pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
+               pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
+               pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
+               pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
+       }\r
+\r
+       // 0x790[5:0]=0x5\r
+       u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);\r
+       u1Tmp &= 0xc0;\r
+       u1Tmp |= 0x5;\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
+\r
+       //Antenna config\r
+       if(bWifiUnder5G)\r
+               halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, TRUE, FALSE);\r
+       else\r
+               halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, TRUE, FALSE);\r
+\r
+       // PTA parameter\r
+       halbtc8821a1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
+\r
+       // Enable counter statistics\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); //0x76e[3] =1, WLAN_Act control by PTA\r
+       pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);\r
+       pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);\r
+}\r
+\r
+//============================================================\r
+// work around function start with wa_halbtc8821a1ant_\r
+//============================================================\r
+//============================================================\r
+// extern function start with EXhalbtc8821a1ant_\r
+//============================================================\r
+VOID\r
+EXhalbtc8821a1ant_PowerOnSetting(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_InitHwConfig(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      BOOLEAN                         bWifiOnly\r
+       )\r
+{\r
+       halbtc8821a1ant_InitHwConfig(pBtCoexist, TRUE, bWifiOnly);\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_InitCoexDm(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));\r
+\r
+       pBtCoexist->bStopCoexDm = FALSE;\r
+       \r
+       halbtc8821a1ant_InitCoexDm(pBtCoexist);\r
+\r
+       halbtc8821a1ant_QueryBtInfo(pBtCoexist);\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_DisplayCoexInfo(\r
+       IN      PBTC_COEXIST            pBtCoexist\r
+       )\r
+{\r
+       PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
+       PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
+       PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
+       u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
+       u2Byte                          u2Tmp[4];\r
+       u4Byte                          u4Tmp[4];\r
+       u4Byte                          faOfdm, faCck;\r
+       u4Byte                          fwVer=0, btPatchVer=0;\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
+       CL_PRINTF(cliBuf);\r
+\r
+       if(pBtCoexist->bManualControl)\r
+       {\r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");\r
+               CL_PRINTF(cliBuf);\r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
+               CL_PRINTF(cliBuf);\r
+       }\r
+       if(pBtCoexist->bStopCoexDm)\r
+       {\r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");\r
+               CL_PRINTF(cliBuf);\r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
+               CL_PRINTF(cliBuf);\r
+       }\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Ant PG Num/ Ant Mech/ Ant Pos:", \\r
+               pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos);\r
+       CL_PRINTF(cliBuf);      \r
+       \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
+               ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \\r
+               GLCoexVerDate8821a1Ant, GLCoexVer8821a1Ant, fwVer, btPatchVer, btPatchVer);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \\r
+               pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
+               pCoexDm->wifiChnlInfo[2]);\r
+       CL_PRINTF(cliBuf);\r
+       \r
+       // wifi status\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
+       CL_PRINTF(cliBuf);\r
+       pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
+       CL_PRINTF(cliBuf);\r
+       \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
+               ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":\r
+               (  (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),\r
+               pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
+       CL_PRINTF(cliBuf);\r
+       \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
+               pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist);\r
+       CL_PRINTF(cliBuf);      \r
+       pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
+\r
+       btInfoExt = pCoexSta->btInfoExt;\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
+               (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
+       CL_PRINTF(cliBuf);      \r
+\r
+       for(i=0; i<BT_INFO_SRC_8821A_1ANT_MAX; i++)\r
+       {\r
+               if(pCoexSta->btInfoC2hCnt[i])\r
+               {                               \r
+                       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8821a1Ant[i], \\r
+                               pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
+                               pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
+                               pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
+                               pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
+                       CL_PRINTF(cliBuf);\r
+               }\r
+       }\r
+\r
+       if(!pBtCoexist->bManualControl)\r
+       {\r
+       // Sw mechanism \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
+       CL_PRINTF(cliBuf);\r
+       \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "SM[LowPenaltyRA]", \\r
+               pCoexDm->bCurLowPenaltyRa);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "DelBA/ BtCtrlAgg/ AggSize", \\r
+               (pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),\r
+                       pBtCoexist->btInfo.aggBufSize);\r
+       CL_PRINTF(cliBuf);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \\r
+                       pBtCoexist->btInfo.raMask);\r
+       CL_PRINTF(cliBuf);      \r
+\r
+       // Fw mechanism         \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
+       CL_PRINTF(cliBuf);      \r
+       \r
+               psTdmaCase = pCoexDm->curPsTdma;\r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \\r
+                       pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
+                       pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
+                       pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);\r
+               CL_PRINTF(cliBuf);\r
+       \r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IgnWlanAct", \\r
+                       pCoexDm->bCurIgnoreWlanAct);\r
+               CL_PRINTF(cliBuf);\r
+       \r
+               CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Latest error condition(should be 0)", \\r
+                       pCoexDm->errorCondition);\r
+               CL_PRINTF(cliBuf);\r
+       }\r
+\r
+       // Hw setting           \r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
+       CL_PRINTF(cliBuf);      \r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "backup ARFR1/ARFR2/RL/AMaxTime", \\r
+               pCoexDm->backupArfrCnt1, pCoexDm->backupArfrCnt2, pCoexDm->backupRetryLimit, pCoexDm->backupAmpduMaxTime);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
+       u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
+       u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \\r
+               u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc58);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x778/ 0xc58[29:25]", \\r
+               u1Tmp[0], (u4Tmp[0]&0x3e000000) >> 25);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x8db);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x8db[6:5]", \\r
+               ((u1Tmp[0]&0x60)>>5));\r
+       CL_PRINTF(cliBuf); \r
+       \r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x975);\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcb4);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]", \\r
+               (u4Tmp[0]&0x30000000)>>28, u4Tmp[0]&0xff, u1Tmp[0]& 0x3);\r
+       CL_PRINTF(cliBuf);\r
+\r
+\r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
+       u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x64);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x40/0x4c[24:23]/0x64[0]", \\r
+               u1Tmp[0], ((u4Tmp[0]&0x01800000)>>23), u1Tmp[1]&0x1);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
+               u4Tmp[0], u1Tmp[0]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
+               u4Tmp[0]&0xff);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf48);\r
+       u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5d);\r
+       u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "OFDM-FA/ CCK-FA", \\r
+               u4Tmp[0], (u1Tmp[0]<<8) + u1Tmp[1]  );\r
+       CL_PRINTF(cliBuf);\r
+\r
+       u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
+       u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
+       u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8(coexTable)", \\r
+               u4Tmp[0], u4Tmp[1], u4Tmp[2]);\r
+       CL_PRINTF(cliBuf);\r
+\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \\r
+               pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
+       CL_PRINTF(cliBuf);\r
+       CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \\r
+               pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
+       CL_PRINTF(cliBuf);\r
+#if(BT_AUTO_REPORT_ONLY_8821A_1ANT == 1)\r
+       halbtc8821a1ant_MonitorBtCtr(pBtCoexist);\r
+#endif\r
+       pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
+}\r
+\r
+\r
+VOID\r
+EXhalbtc8821a1ant_IpsNotify(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  type\r
+       )\r
+{\r
+       u4Byte  u4Tmp=0;\r
+\r
+       if(pBtCoexist->bManualControl ||        pBtCoexist->bStopCoexDm)\r
+               return;\r
+\r
+       if(BTC_IPS_ENTER == type)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));\r
+               pCoexSta->bUnderIps = TRUE;\r
+               \r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
+               halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);   \r
+               //halbtc8821a1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);\r
+       }\r
+       else if(BTC_IPS_LEAVE == type)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));\r
+               pCoexSta->bUnderIps = FALSE;\r
+\r
+               halbtc8821a1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);\r
+               halbtc8821a1ant_InitCoexDm(pBtCoexist);\r
+               halbtc8821a1ant_QueryBtInfo(pBtCoexist);\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_LpsNotify(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  type\r
+       )\r
+{\r
+       if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)\r
+               return;\r
+\r
+       if(BTC_LPS_ENABLE == type)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));\r
+               pCoexSta->bUnderLps = TRUE;\r
+       }\r
+       else if(BTC_LPS_DISABLE == type)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));\r
+               pCoexSta->bUnderLps = FALSE;\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_ScanNotify(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  type\r
+       )\r
+{\r
+       BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
+       u4Byte  wifiLinkStatus=0;\r
+       u4Byte  numOfWifiLink=0;\r
+       BOOLEAN bBtCtrlAggBufSize=FALSE;\r
+       u1Byte  aggBufSize=5;\r
+\r
+       if(pBtCoexist->bManualControl ||\r
+               pBtCoexist->bStopCoexDm )\r
+               return;\r
+\r
+       if(BTC_SCAN_START == type)\r
+       {\r
+               pCoexSta->bWiFiIsHighPriTask = TRUE;\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));\r
+\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);  //Force antenna setup for no scan result issue\r
+       }\r
+       else\r
+       {\r
+               pCoexSta->bWiFiIsHighPriTask = FALSE;   \r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));\r
+       }       \r
+\r
+       if(pBtCoexist->btInfo.bBtDisabled)\r
+               return;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+\r
+       halbtc8821a1ant_QueryBtInfo(pBtCoexist);\r
+       \r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
+       numOfWifiLink = wifiLinkStatus>>16;\r
+       if(numOfWifiLink >= 2)\r
+       {\r
+               halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
+               halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
+               halbtc8821a1ant_ActionWifiMultiPort(pBtCoexist);\r
+               return;\r
+       }\r
+       \r
+       if(pCoexSta->bC2hBtInquiryPage)\r
+       {\r
+               halbtc8821a1ant_ActionBtInquiry(pBtCoexist);\r
+               return;\r
+       }\r
+       else if(bBtHsOn)\r
+       {\r
+               halbtc8821a1ant_ActionHs(pBtCoexist);\r
+               return;\r
+       }\r
+\r
+       if(BTC_SCAN_START == type)\r
+       {\r
+               //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));\r
+               if(!bWifiConnected)     // non-connected scan\r
+               {\r
+                       halbtc8821a1ant_ActionWifiNotConnectedScan(pBtCoexist);\r
+               }\r
+               else    // wifi is connected\r
+               {\r
+                       halbtc8821a1ant_ActionWifiConnectedScan(pBtCoexist);\r
+               }\r
+       }\r
+       else if(BTC_SCAN_FINISH == type)\r
+       {\r
+               //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));\r
+               if(!bWifiConnected)     // non-connected scan\r
+               {\r
+                       halbtc8821a1ant_ActionWifiNotConnected(pBtCoexist);\r
+               }\r
+               else\r
+               {\r
+                       halbtc8821a1ant_ActionWifiConnected(pBtCoexist);\r
+               }\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_ConnectNotify(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      u1Byte                  type\r
+       )\r
+{\r
+       BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
+       u4Byte  wifiLinkStatus=0;\r
+       u4Byte  numOfWifiLink=0;\r
+       BOOLEAN bBtCtrlAggBufSize=FALSE;\r
+       u1Byte  aggBufSize=5;\r
+\r
+       if(pBtCoexist->bManualControl ||\r
+               pBtCoexist->bStopCoexDm ||\r
+               pBtCoexist->btInfo.bBtDisabled )\r
+               return;\r
+\r
+       if(BTC_ASSOCIATE_START == type)\r
+       {\r
+        pCoexSta->bWiFiIsHighPriTask = TRUE;\r
+                RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));   \r
+                pCoexDm->nArpCnt = 0;\r
+       }\r
+       else\r
+       {\r
+        pCoexSta->bWiFiIsHighPriTask = FALSE;  \r
+                RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));  \r
+               pCoexDm->nArpCnt = 0;\r
+       }\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
+       numOfWifiLink = wifiLinkStatus>>16;\r
+       if(numOfWifiLink >= 2)\r
+       {\r
+               halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
+               halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
+               halbtc8821a1ant_ActionWifiMultiPort(pBtCoexist);\r
+               return;\r
+       }\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
+       if(pCoexSta->bC2hBtInquiryPage)\r
+       {\r
+               halbtc8821a1ant_ActionBtInquiry(pBtCoexist);\r
+               return;\r
+       }\r
+       else if(bBtHsOn)\r
+       {\r
+               halbtc8821a1ant_ActionHs(pBtCoexist);\r
+               return;\r
+       }\r
+\r
+       if(BTC_ASSOCIATE_START == type)\r
+       {\r
+               //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));          \r
+               halbtc8821a1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);\r
+       }\r
+       else if(BTC_ASSOCIATE_FINISH == type)\r
+       {\r
+               //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));\r
+               \r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+               if(!bWifiConnected) // non-connected scan\r
+               {\r
+                       halbtc8821a1ant_ActionWifiNotConnected(pBtCoexist);\r
+               }\r
+               else\r
+               {\r
+                       halbtc8821a1ant_ActionWifiConnected(pBtCoexist);\r
+               }\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_MediaStatusNotify(\r
+       IN      PBTC_COEXIST                    pBtCoexist,\r
+       IN      u1Byte                          type\r
+       )\r
+{\r
+       u1Byte                  H2C_Parameter[3] ={0};\r
+       u4Byte                  wifiBw;\r
+       u1Byte                  wifiCentralChnl;\r
+\r
+       if(pBtCoexist->bManualControl ||\r
+               pBtCoexist->bStopCoexDm ||\r
+               pBtCoexist->btInfo.bBtDisabled )\r
+               return;\r
+\r
+       if(BTC_MEDIA_CONNECT == type)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));\r
+       }\r
+       else\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));\r
+               pCoexDm->nArpCnt = 0;\r
+       }\r
+\r
+       // only 2.4G we need to inform bt the chnl mask\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
+       if( (BTC_MEDIA_CONNECT == type) &&\r
+               (wifiCentralChnl <= 14) )\r
+       {\r
+               //H2C_Parameter[0] = 0x1;\r
+               H2C_Parameter[0] = 0x0;\r
+               H2C_Parameter[1] = wifiCentralChnl;\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
+               if(BTC_WIFI_BW_HT40 == wifiBw)\r
+                       H2C_Parameter[2] = 0x30;\r
+               else\r
+                       H2C_Parameter[2] = 0x20;\r
+       }\r
+               \r
+       pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
+       pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
+       pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
+       \r
+       RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x66=0x%x\n", \r
+               H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
+\r
+       pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_SpecialPacketNotify(\r
+       IN      PBTC_COEXIST                    pBtCoexist,\r
+       IN      u1Byte                          type\r
+       )\r
+{\r
+       BOOLEAN bBtHsOn=FALSE;\r
+       u4Byte  wifiLinkStatus=0;\r
+       u4Byte  numOfWifiLink=0;\r
+       BOOLEAN bBtCtrlAggBufSize=FALSE;\r
+       u1Byte  aggBufSize=5;\r
+       \r
+       if(pBtCoexist->bManualControl ||\r
+               pBtCoexist->bStopCoexDm ||\r
+               pBtCoexist->btInfo.bBtDisabled )\r
+               return;\r
+\r
+       if( BTC_PACKET_DHCP == type || \r
+               BTC_PACKET_EAPOL == type ||\r
+               BTC_PACKET_ARP == type )\r
+       {\r
+               pCoexSta->bWiFiIsHighPriTask = TRUE;\r
+\r
+               if(BTC_PACKET_ARP == type)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet ARP notify\n"));                \r
+               }\r
+               else\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet DHCP or EAPOL notify\n"));              \r
+               }\r
+       }\r
+       else\r
+       {\r
+               pCoexSta->bWiFiIsHighPriTask = FALSE;   \r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet [Type = %d] notify\n", type));\r
+       }\r
+\r
+       pCoexSta->specialPktPeriodCnt = 0;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
+       numOfWifiLink = wifiLinkStatus>>16;\r
+       if(numOfWifiLink >= 2)\r
+       {\r
+               halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
+               halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
+               halbtc8821a1ant_ActionWifiMultiPort(pBtCoexist);\r
+               return;\r
+       }\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
+       if(pCoexSta->bC2hBtInquiryPage)\r
+       {\r
+               halbtc8821a1ant_ActionBtInquiry(pBtCoexist);\r
+               return;\r
+       }\r
+       else if(bBtHsOn)\r
+       {\r
+               halbtc8821a1ant_ActionHs(pBtCoexist);\r
+               return;\r
+       }\r
+\r
+       if( BTC_PACKET_DHCP == type ||\r
+               BTC_PACKET_EAPOL == type || \r
+               BTC_PACKET_ARP == type )\r
+       {\r
+               //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet(%d) notify\n", type));\r
+               if(BTC_PACKET_ARP == type)\r
+               {\r
+                       pCoexDm->nArpCnt++;\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ARP Packet Count = %d\n", pCoexDm->nArpCnt));\r
+                       if(pCoexDm->nArpCnt >= 10) // if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist) \r
+                               return; \r
+               }\r
+               \r
+               halbtc8821a1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_BtInfoNotify(\r
+       IN      PBTC_COEXIST            pBtCoexist,\r
+       IN      pu1Byte                 tmpBuf,\r
+       IN      u1Byte                  length\r
+       )\r
+{\r
+       PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
+       u1Byte                          btInfo=0;\r
+       u1Byte                          i, rspSource=0;\r
+       BOOLEAN                         bWifiConnected=FALSE;\r
+       BOOLEAN                         bBtBusy=FALSE;\r
+       BOOLEAN                         bWifiUnder5G=FALSE;\r
+\r
+       pCoexSta->bC2hBtInfoReqSent = FALSE;\r
+\r
+       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
+\r
+       rspSource = tmpBuf[0]&0xf;\r
+       if(rspSource >= BT_INFO_SRC_8821A_1ANT_MAX)\r
+               rspSource = BT_INFO_SRC_8821A_1ANT_WIFI_FW;\r
+       pCoexSta->btInfoC2hCnt[rspSource]++;\r
+\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
+       for(i=0; i<length; i++)\r
+       {\r
+               pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
+               if(i == 1)\r
+                       btInfo = tmpBuf[i];\r
+               if(i == length-1)\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));\r
+               }\r
+               else\r
+               {\r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));\r
+               }\r
+       }\r
+\r
+       if(BT_INFO_SRC_8821A_1ANT_WIFI_FW != rspSource)\r
+       {\r
+               pCoexSta->btRetryCnt =  // [3:0]\r
+                       pCoexSta->btInfoC2h[rspSource][2]&0xf;\r
+\r
+               if (pCoexSta->btInfoC2h[rspSource][2]&0x20)\r
+                       pCoexSta->bC2hBtPage = TRUE;\r
+               else\r
+                       pCoexSta->bC2hBtPage = FALSE;                   \r
+\r
+               pCoexSta->btRssi =\r
+                       pCoexSta->btInfoC2h[rspSource][3]*2+10;\r
+\r
+               pCoexSta->btInfoExt = \r
+                       pCoexSta->btInfoC2h[rspSource][4];\r
+\r
+               pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);\r
+               pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);\r
+               if(!pCoexSta->bBtTxRxMask)\r
+               {\r
+                       /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */                            \r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n"));\r
+                       pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15);\r
+               }\r
+               \r
+               // Here we need to resend some wifi info to BT\r
+               // because bt is reset and loss of the info.\r
+               if(pCoexSta->btInfoExt & BIT1)\r
+               {                       \r
+                       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));\r
+                       pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
+                       if(bWifiConnected)\r
+                       {\r
+                               EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);\r
+                       }\r
+                       else\r
+                       {\r
+                               EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
+                       }\r
+               }\r
+\r
+               if( (pCoexSta->btInfoExt & BIT3) && !bWifiUnder5G)\r
+               {\r
+                       if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)\r
+                       {\r
+                               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));\r
+                               halbtc8821a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       // BT already NOT ignore Wlan active, do nothing here.\r
+               }\r
+#if(BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)\r
+               if( (pCoexSta->btInfoExt & BIT4) )\r
+               {\r
+                       // BT auto report already enabled, do nothing\r
+               }\r
+               else\r
+               {\r
+                       halbtc8821a1ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);\r
+               }\r
+#endif\r
+       }\r
+               \r
+       // check BIT2 first ==> check if bt is under inquiry or page scan\r
+       if(btInfo & BT_INFO_8821A_1ANT_B_INQ_PAGE)\r
+               pCoexSta->bC2hBtInquiryPage = TRUE;\r
+       else\r
+               pCoexSta->bC2hBtInquiryPage = FALSE;\r
+\r
+       // set link exist status\r
+       if(!(btInfo&BT_INFO_8821A_1ANT_B_CONNECTION))\r
+       {\r
+               pCoexSta->bBtLinkExist = FALSE;\r
+               pCoexSta->bPanExist = FALSE;\r
+               pCoexSta->bA2dpExist = FALSE;\r
+               pCoexSta->bHidExist = FALSE;\r
+               pCoexSta->bScoExist = FALSE;\r
+       }\r
+       else    // connection exists\r
+       {\r
+               pCoexSta->bBtLinkExist = TRUE;\r
+               if(btInfo & BT_INFO_8821A_1ANT_B_FTP)\r
+                       pCoexSta->bPanExist = TRUE;\r
+               else\r
+                       pCoexSta->bPanExist = FALSE;\r
+               if(btInfo & BT_INFO_8821A_1ANT_B_A2DP)\r
+                       pCoexSta->bA2dpExist = TRUE;\r
+               else\r
+                       pCoexSta->bA2dpExist = FALSE;\r
+               if(btInfo & BT_INFO_8821A_1ANT_B_HID)\r
+                       pCoexSta->bHidExist = TRUE;\r
+               else\r
+                       pCoexSta->bHidExist = FALSE;\r
+               if(btInfo & BT_INFO_8821A_1ANT_B_SCO_ESCO)\r
+                       pCoexSta->bScoExist = TRUE;\r
+               else\r
+                       pCoexSta->bScoExist = FALSE;\r
+       }\r
+\r
+       halbtc8821a1ant_UpdateBtLinkInfo(pBtCoexist);\r
+               \r
+       btInfo = btInfo & 0x1f;  //mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41)\r
+       \r
+       if(!(btInfo&BT_INFO_8821A_1ANT_B_CONNECTION))\r
+       {\r
+               pCoexDm->btStatus = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));\r
+       }\r
+       else if(btInfo == BT_INFO_8821A_1ANT_B_CONNECTION)      // connection exists but no busy\r
+       {\r
+               pCoexDm->btStatus = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE;\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));\r
+       }\r
+       else if((btInfo&BT_INFO_8821A_1ANT_B_SCO_ESCO) ||\r
+               (btInfo&BT_INFO_8821A_1ANT_B_SCO_BUSY))\r
+       {\r
+               pCoexDm->btStatus = BT_8821A_1ANT_BT_STATUS_SCO_BUSY;\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));\r
+       }\r
+       else if(btInfo&BT_INFO_8821A_1ANT_B_ACL_BUSY)\r
+       {\r
+               if(BT_8821A_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)\r
+                       pCoexDm->bAutoTdmaAdjust = FALSE;\r
+               pCoexDm->btStatus = BT_8821A_1ANT_BT_STATUS_ACL_BUSY;\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));\r
+       }\r
+       else\r
+       {\r
+               pCoexDm->btStatus = BT_8821A_1ANT_BT_STATUS_MAX;\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));\r
+       }\r
+\r
+       if( (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
+               (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
+               (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
+               bBtBusy = TRUE;\r
+       else\r
+               bBtBusy = FALSE;\r
+       pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
+\r
+       halbtc8821a1ant_RunCoexistMechanism(pBtCoexist);\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_HaltNotify(\r
+       IN      PBTC_COEXIST                    pBtCoexist\r
+       )\r
+{\r
+       u4Byte  u4Tmp;\r
+       \r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));\r
+\r
+       halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+       halbtc8821a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
+       halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
+       //halbtc8821a1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);\r
+\r
+       halbtc8821a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
+\r
+       EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
+\r
+       pBtCoexist->bStopCoexDm = TRUE; \r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_PnpNotify(\r
+       IN      PBTC_COEXIST                    pBtCoexist,\r
+       IN      u1Byte                          pnpState\r
+       )\r
+{\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify\n"));\r
+\r
+       if(BTC_WIFI_PNP_SLEEP == pnpState)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to SLEEP\n"));\r
+\r
+               halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
+               halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
+               halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
+               halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
+              //halbtc8821a1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);\r
+\r
+               pBtCoexist->bStopCoexDm = TRUE;\r
+       }\r
+       else if(BTC_WIFI_PNP_WAKE_UP == pnpState)\r
+       {\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to WAKE UP\n"));\r
+               pBtCoexist->bStopCoexDm = FALSE;\r
+               halbtc8821a1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);\r
+               halbtc8821a1ant_InitCoexDm(pBtCoexist);\r
+               halbtc8821a1ant_QueryBtInfo(pBtCoexist);\r
+       }\r
+}\r
+\r
+VOID\r
+EXhalbtc8821a1ant_Periodical(\r
+       IN      PBTC_COEXIST                    pBtCoexist\r
+       )\r
+{\r
+       static u1Byte           disVerInfoCnt=0;\r
+       u4Byte                          fwVer=0, btPatchVer=0;\r
+       PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
+       PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
+\r
+       RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ==========================Periodical===========================\n"));\r
+\r
+       if(disVerInfoCnt <= 5)\r
+       {\r
+               disVerInfoCnt += 1;\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",\r
+                       pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n",\r
+                       ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
+               pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",\r
+                       GLCoexVerDate8821a1Ant, GLCoexVer8821a1Ant, fwVer, btPatchVer, btPatchVer));\r
+               RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));\r
+       }\r
+\r
+#if(BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)\r
+       halbtc8821a1ant_QueryBtInfo(pBtCoexist);\r
+       halbtc8821a1ant_MonitorBtCtr(pBtCoexist);\r
+       halbtc8821a1ant_MonitorBtEnableDisable(pBtCoexist);\r
+#else\r
+       if( halbtc8821a1ant_IsWifiStatusChanged(pBtCoexist) ||\r
+               pCoexDm->bAutoTdmaAdjust )\r
+       {\r
+               //if(pCoexSta->specialPktPeriodCnt > 2)\r
+               //{\r
+                       halbtc8821a1ant_RunCoexistMechanism(pBtCoexist);        \r
+               //}\r
+       }\r
+\r
+       pCoexSta->specialPktPeriodCnt++;\r
+#endif\r
+}\r
+\r
+\r
+#endif\r
+\r