1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 ******************************************************************************/
16 #include "Mp_Precomp.h"
18 /* Global variables, these are static variables */
19 static COEX_DM_8723B_1ANT GLCoexDm8723b1Ant;
20 static PCOEX_DM_8723B_1ANT pCoexDm =&GLCoexDm8723b1Ant;
21 static COEX_STA_8723B_1ANT GLCoexSta8723b1Ant;
22 static PCOEX_STA_8723B_1ANT pCoexSta =&GLCoexSta8723b1Ant;
24 static const char *const GLBtInfoSrc8723b1Ant[]={
27 "BT Info[bt auto report]",
30 static u32 GLCoexVerDate8723b1Ant =20140507;
31 static u32 GLCoexVer8723b1Ant = 0x4e;
33 /* local function proto type if needed */
34 /* local function start with halbtc8723b1ant_ */
36 halbtc8723b1ant_BtRssiState(
43 u8 btRssiState =pCoexSta->preBtRssiState;
45 btRssi = pCoexSta->btRssi;
49 if ((pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
50 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
52 if (btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))
54 btRssiState = BTC_RSSI_STATE_HIGH;
55 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));
59 btRssiState = BTC_RSSI_STATE_STAY_LOW;
60 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));
65 if (btRssi < rssiThresh)
67 btRssiState = BTC_RSSI_STATE_LOW;
68 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));
72 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
73 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));
77 else if (levelNum == 3)
79 if (rssiThresh > rssiThresh1)
81 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi thresh error!!\n"));
82 return pCoexSta->preBtRssiState;
85 if ((pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
86 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
88 if (btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))
90 btRssiState = BTC_RSSI_STATE_MEDIUM;
91 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));
95 btRssiState = BTC_RSSI_STATE_STAY_LOW;
96 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));
99 else if ((pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
100 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))
102 if (btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))
104 btRssiState = BTC_RSSI_STATE_HIGH;
105 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));
107 else if (btRssi < rssiThresh)
109 btRssiState = BTC_RSSI_STATE_LOW;
110 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));
114 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
115 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Medium\n"));
120 if (btRssi < rssiThresh1)
122 btRssiState = BTC_RSSI_STATE_MEDIUM;
123 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));
127 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
128 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));
133 pCoexSta->preBtRssiState = btRssiState;
139 halbtc8723b1ant_UpdateRaMask(
140 PBTC_COEXIST pBtCoexist,
145 pCoexDm->curRaMask = disRateMask;
147 if (bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))
149 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);
151 pCoexDm->preRaMask = pCoexDm->curRaMask;
155 halbtc8723b1ant_AutoRateFallbackRetry(
156 PBTC_COEXIST pBtCoexist,
161 bool bWifiUnderBMode =false;
163 pCoexDm->curArfrType = type;
165 if (bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType))
167 switch (pCoexDm->curArfrType)
169 case 0: /* normal mode */
170 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, pCoexDm->backupArfrCnt1);
171 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, pCoexDm->backupArfrCnt2);
174 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
177 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
178 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);
182 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
183 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);
191 pCoexDm->preArfrType = pCoexDm->curArfrType;
195 halbtc8723b1ant_RetryLimit(
196 PBTC_COEXIST pBtCoexist,
201 pCoexDm->curRetryLimitType = type;
203 if (bForceExec || (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType))
205 switch (pCoexDm->curRetryLimitType)
207 case 0: /* normal mode */
208 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, pCoexDm->backupRetryLimit);
210 case 1: /* retry limit =8 */
211 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);
218 pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;
222 halbtc8723b1ant_AmpduMaxTime(
223 PBTC_COEXIST pBtCoexist,
228 pCoexDm->curAmpduTimeType = type;
230 if (bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType))
232 switch (pCoexDm->curAmpduTimeType)
234 case 0: /* normal mode */
235 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime);
237 case 1: /* AMPDU timw = 0x38 * 32us */
238 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);
245 pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;
249 halbtc8723b1ant_LimitedTx(
250 PBTC_COEXIST pBtCoexist,
260 case 0: /* normal mode */
261 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);
263 case 1: /* disable cck 1/2 */
264 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x00000003);
266 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
267 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);
273 halbtc8723b1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);
274 halbtc8723b1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);
275 halbtc8723b1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);
279 halbtc8723b1ant_LimitedRx(
280 PBTC_COEXIST pBtCoexist,
283 bool bBtCtrlAggBufSize,
287 bool bRejectRxAgg =bRejApAggPkt;
288 bool bBtCtrlRxAggSize =bBtCtrlAggBufSize;
289 u8 rxAggSize =aggBufSize;
292 /* Rx Aggregation related setting */
294 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);
295 /* decide BT control aggregation buf size or not */
296 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);
297 /* aggregation buf size, only work when BT control Rx aggregation size. */
298 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
299 /* real update aggregation setting */
300 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
306 halbtc8723b1ant_QueryBtInfo(
307 PBTC_COEXIST pBtCoexist
310 u8 H2C_Parameter[1] ={0};
312 pCoexSta->bC2hBtInfoReqSent = true;
314 H2C_Parameter[0] |= BIT0; /* trigger */
316 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n",
319 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);
323 halbtc8723b1ant_MonitorBtCtr(
324 PBTC_COEXIST pBtCoexist
327 u32 regHPTxRx, regLPTxRx, u4Tmp;
328 u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
329 static u8 NumOfBtCounterChk;
331 /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
332 /* if (! (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) & 0x8)) */
334 if (pCoexSta->bUnderIps)
336 pCoexSta->highPriorityTx = 65535;
337 pCoexSta->highPriorityRx = 65535;
338 pCoexSta->lowPriorityTx = 65535;
339 pCoexSta->lowPriorityRx = 65535;
346 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
347 regHPTx = u4Tmp & bMaskLWord;
348 regHPRx = (u4Tmp & bMaskHWord)>>16;
350 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
351 regLPTx = u4Tmp & bMaskLWord;
352 regLPRx = (u4Tmp & bMaskHWord)>>16;
354 pCoexSta->highPriorityTx = regHPTx;
355 pCoexSta->highPriorityRx = regHPRx;
356 pCoexSta->lowPriorityTx = regLPTx;
357 pCoexSta->lowPriorityRx = regLPRx;
359 if ((pCoexSta->lowPriorityTx >= 1050) && (!pCoexSta->bC2hBtInquiryPage))
360 pCoexSta->popEventCnt++;
362 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
363 regHPRx, regHPTx, regLPRx, regLPTx));
366 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
368 if ((regHPTx == 0) && (regHPRx == 0) && (regLPTx == 0) && (regLPRx == 0))
371 if (NumOfBtCounterChk >= 3)
373 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
374 NumOfBtCounterChk = 0;
381 halbtc8723b1ant_MonitorWiFiCtr(
382 PBTC_COEXIST pBtCoexist
386 bool bWifiBusy = false, bWifiUnderBMode = false;
387 static u8 nCCKLockCounter = 0;
389 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
390 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
391 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
393 if (pCoexSta->bUnderIps)
395 pCoexSta->nCRCOK_CCK = 0;
396 pCoexSta->nCRCOK_11g = 0;
397 pCoexSta->nCRCOK_11n = 0;
398 pCoexSta->nCRCOK_11nAgg = 0;
400 pCoexSta->nCRCErr_CCK = 0;
401 pCoexSta->nCRCErr_11g = 0;
402 pCoexSta->nCRCErr_11n = 0;
403 pCoexSta->nCRCErr_11nAgg = 0;
407 pCoexSta->nCRCOK_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88);
408 pCoexSta->nCRCOK_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94);
409 pCoexSta->nCRCOK_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90);
410 pCoexSta->nCRCOK_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8);
412 pCoexSta->nCRCErr_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84);
413 pCoexSta->nCRCErr_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96);
414 pCoexSta->nCRCErr_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92);
415 pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba);
420 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1);
421 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0);
423 if ((bWifiBusy) && (wifiRssi >= 30) && (!bWifiUnderBMode))
425 if ((pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) ||
426 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
427 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY))
429 if (pCoexSta->nCRCOK_CCK >(pCoexSta->nCRCOK_11g + pCoexSta->nCRCOK_11n +
430 pCoexSta->nCRCOK_11nAgg))
432 if (nCCKLockCounter < 5)
437 if (nCCKLockCounter > 0)
444 if (nCCKLockCounter > 0)
450 if (nCCKLockCounter > 0)
454 if (!pCoexSta->bPreCCKLock)
457 if (nCCKLockCounter >= 5)
458 pCoexSta->bCCKLock = true;
460 pCoexSta->bCCKLock = false;
464 if (nCCKLockCounter == 0)
465 pCoexSta->bCCKLock = false;
467 pCoexSta->bCCKLock = true;
470 pCoexSta->bPreCCKLock = pCoexSta->bCCKLock;
476 halbtc8723b1ant_IsWifiStatusChanged(
477 PBTC_COEXIST pBtCoexist
480 static bool bPreWifiBusy =false, bPreUnder4way =false, bPreBtHsOn =false;
481 bool bWifiBusy =false, bUnder4way =false, bBtHsOn =false;
482 bool bWifiConnected =false;
484 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
485 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
486 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
487 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
491 if (bWifiBusy != bPreWifiBusy)
493 bPreWifiBusy = bWifiBusy;
496 if (bUnder4way != bPreUnder4way)
498 bPreUnder4way = bUnder4way;
501 if (bBtHsOn != bPreBtHsOn)
503 bPreBtHsOn = bBtHsOn;
512 halbtc8723b1ant_UpdateBtLinkInfo(
513 PBTC_COEXIST pBtCoexist
516 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
519 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
521 pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
522 pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
523 pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
524 pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
525 pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
527 /* work around for HS mode. */
530 pBtLinkInfo->bPanExist = true;
531 pBtLinkInfo->bBtLinkExist = true;
534 /* check if Sco only */
535 if (pBtLinkInfo->bScoExist &&
536 !pBtLinkInfo->bA2dpExist &&
537 !pBtLinkInfo->bPanExist &&
538 !pBtLinkInfo->bHidExist)
539 pBtLinkInfo->bScoOnly = true;
541 pBtLinkInfo->bScoOnly = false;
543 /* check if A2dp only */
544 if (!pBtLinkInfo->bScoExist &&
545 pBtLinkInfo->bA2dpExist &&
546 !pBtLinkInfo->bPanExist &&
547 !pBtLinkInfo->bHidExist)
548 pBtLinkInfo->bA2dpOnly = true;
550 pBtLinkInfo->bA2dpOnly = false;
552 /* check if Pan only */
553 if (!pBtLinkInfo->bScoExist &&
554 !pBtLinkInfo->bA2dpExist &&
555 pBtLinkInfo->bPanExist &&
556 !pBtLinkInfo->bHidExist)
557 pBtLinkInfo->bPanOnly = true;
559 pBtLinkInfo->bPanOnly = false;
561 /* check if Hid only */
562 if (!pBtLinkInfo->bScoExist &&
563 !pBtLinkInfo->bA2dpExist &&
564 !pBtLinkInfo->bPanExist &&
565 pBtLinkInfo->bHidExist)
566 pBtLinkInfo->bHidOnly = true;
568 pBtLinkInfo->bHidOnly = false;
572 halbtc8723b1ant_ActionAlgorithm(
573 PBTC_COEXIST pBtCoexist
576 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
578 u8 algorithm =BT_8723B_1ANT_COEX_ALGO_UNDEFINED;
579 u8 numOfDiffProfile = 0;
581 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
583 if (!pBtLinkInfo->bBtLinkExist)
585 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No BT link exists!!!\n"));
589 if (pBtLinkInfo->bScoExist)
591 if (pBtLinkInfo->bHidExist)
593 if (pBtLinkInfo->bPanExist)
595 if (pBtLinkInfo->bA2dpExist)
598 if (numOfDiffProfile == 1)
600 if (pBtLinkInfo->bScoExist)
602 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO only\n"));
603 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
607 if (pBtLinkInfo->bHidExist)
609 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID only\n"));
610 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
612 else if (pBtLinkInfo->bA2dpExist)
614 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP only\n"));
615 algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP;
617 else if (pBtLinkInfo->bPanExist)
621 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = PAN(HS) only\n"));
622 algorithm = BT_8723B_1ANT_COEX_ALGO_PANHS;
626 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = PAN(EDR) only\n"));
627 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR;
632 else if (numOfDiffProfile == 2)
634 if (pBtLinkInfo->bScoExist)
636 if (pBtLinkInfo->bHidExist)
638 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID\n"));
639 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
641 else if (pBtLinkInfo->bA2dpExist)
643 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"));
644 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
646 else if (pBtLinkInfo->bPanExist)
650 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + PAN(HS)\n"));
651 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
655 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + PAN(EDR)\n"));
656 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
662 if (pBtLinkInfo->bHidExist &&
663 pBtLinkInfo->bA2dpExist)
665 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP\n"));
666 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
668 else if (pBtLinkInfo->bHidExist &&
669 pBtLinkInfo->bPanExist)
673 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + PAN(HS)\n"));
674 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
678 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + PAN(EDR)\n"));
679 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
682 else if (pBtLinkInfo->bPanExist &&
683 pBtLinkInfo->bA2dpExist)
687 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP + PAN(HS)\n"));
688 algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS;
692 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP + PAN(EDR)\n"));
693 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP;
698 else if (numOfDiffProfile == 3)
700 if (pBtLinkInfo->bScoExist)
702 if (pBtLinkInfo->bHidExist &&
703 pBtLinkInfo->bA2dpExist)
705 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"));
706 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
708 else if (pBtLinkInfo->bHidExist &&
709 pBtLinkInfo->bPanExist)
713 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"));
714 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
718 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"));
719 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
722 else if (pBtLinkInfo->bPanExist &&
723 pBtLinkInfo->bA2dpExist)
727 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"));
728 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
732 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"));
733 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
739 if (pBtLinkInfo->bHidExist &&
740 pBtLinkInfo->bPanExist &&
741 pBtLinkInfo->bA2dpExist)
745 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"));
746 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
750 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"));
751 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
756 else if (numOfDiffProfile >= 3)
758 if (pBtLinkInfo->bScoExist)
760 if (pBtLinkInfo->bHidExist &&
761 pBtLinkInfo->bPanExist &&
762 pBtLinkInfo->bA2dpExist)
766 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"));
771 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR) ==>PAN(EDR)+HID\n"));
772 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
782 halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(
783 PBTC_COEXIST pBtCoexist,
787 u8 H2C_Parameter[6] ={0};
789 H2C_Parameter[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
793 H2C_Parameter[1] |= BIT0;
794 H2C_Parameter[2] = 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
795 H2C_Parameter[3] = 0xf7; /* MCS7 or OFDM54 */
796 H2C_Parameter[4] = 0xf8; /* MCS6 or OFDM48 */
797 H2C_Parameter[5] = 0xf9; /* MCS5 or OFDM36 */
800 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set WiFi Low-Penalty Retry: %s",
801 (bLowPenaltyRa? "ON!!":"OFF!!")));
803 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
807 halbtc8723b1ant_LowPenaltyRa(
808 PBTC_COEXIST pBtCoexist,
813 pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
817 if (pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
820 halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
822 pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
826 halbtc8723b1ant_SetCoexTable(
827 PBTC_COEXIST pBtCoexist,
834 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0));
835 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
837 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4));
838 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
840 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8));
841 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
843 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc));
844 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
848 halbtc8723b1ant_CoexTable(
849 PBTC_COEXIST pBtCoexist,
857 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6cc = 0x%x\n",
858 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6cc));
859 pCoexDm->curVal0x6c0 = val0x6c0;
860 pCoexDm->curVal0x6c4 = val0x6c4;
861 pCoexDm->curVal0x6c8 = val0x6c8;
862 pCoexDm->curVal0x6cc = val0x6cc;
865 if ((pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
866 (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
867 (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
868 (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc))
871 halbtc8723b1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);
873 pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
874 pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
875 pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
876 pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
880 halbtc8723b1ant_CoexTableWithType(
881 PBTC_COEXIST pBtCoexist,
886 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ********** CoexTable(%d) **********\n", type));
888 pCoexSta->nCoexTableType = type;
893 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3);
896 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
899 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
902 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaa5555, 0xaaaa5a5a, 0xffffff, 0x3);
905 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
908 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3);
911 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);
914 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
922 halbtc8723b1ant_SetFwIgnoreWlanAct(
923 PBTC_COEXIST pBtCoexist,
927 u8 H2C_Parameter[1] ={0};
931 H2C_Parameter[0] |= BIT0; /* function enable */
934 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
937 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
941 halbtc8723b1ant_IgnoreWlanAct(
942 PBTC_COEXIST pBtCoexist,
947 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn Ignore WlanAct %s\n",
948 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));
949 pCoexDm->bCurIgnoreWlanAct = bEnable;
953 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
954 pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));
956 if (pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
959 halbtc8723b1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
961 pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
965 halbtc8723b1ant_SetLpsRpwm(
966 PBTC_COEXIST pBtCoexist,
974 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);
975 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
979 halbtc8723b1ant_LpsRpwm(
980 PBTC_COEXIST pBtCoexist,
986 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s set lps/rpwm = 0x%x/0x%x\n",
987 (bForceExec? "force to":""), lpsVal, rpwmVal));
988 pCoexDm->curLps = lpsVal;
989 pCoexDm->curRpwm = rpwmVal;
993 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], LPS-RxBeaconMode = 0x%x , LPS-RPWM = 0x%x!!\n",
994 pCoexDm->curLps, pCoexDm->curRpwm));
996 if ((pCoexDm->preLps == pCoexDm->curLps) &&
997 (pCoexDm->preRpwm == pCoexDm->curRpwm))
999 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], LPS-RPWM_Last = 0x%x , LPS-RPWM_Now = 0x%x!!\n",
1000 pCoexDm->preRpwm, pCoexDm->curRpwm));
1005 halbtc8723b1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);
1007 pCoexDm->preLps = pCoexDm->curLps;
1008 pCoexDm->preRpwm = pCoexDm->curRpwm;
1012 halbtc8723b1ant_SwMechanism(
1013 PBTC_COEXIST pBtCoexist,
1017 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], SM[LpRA] = %d\n",
1020 halbtc8723b1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
1024 halbtc8723b1ant_SetAntPath(
1025 PBTC_COEXIST pBtCoexist,
1031 PBTC_BOARD_INFO pBoardInfo =&pBtCoexist->boardInfo;
1032 u32 fwVer = 0, u4Tmp = 0, cntBtCalChk = 0;
1033 bool bPgExtSwitch =false;
1034 bool bUseExtSwitch =false;
1035 bool bIsInMpMode = false;
1036 u8 H2C_Parameter[2] ={0}, u1Tmp = 0;
1038 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch);
1039 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); /* [31:16]=fw ver, [15:0]=fw sub ver */
1041 if ((fwVer>0 && fwVer<0xc0000) || bPgExtSwitch)
1042 bUseExtSwitch = true;
1046 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); /* WiFi TRx Mask on */
1047 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); /* BT TRx Mask on */
1049 if (fwVer >= 0x180000)
1051 /* Use H2C to set GNT_BT to HIGH */
1052 H2C_Parameter[0] = 1;
1053 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
1057 /* set grant_bt to high */
1058 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
1060 /* set wlan_act control by PTA */
1061 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
1063 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */
1065 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1);
1066 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff);
1067 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3);
1068 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77);
1072 if (fwVer >= 0x180000)
1074 /* Use H2C to set GNT_BT to HIGH */
1075 H2C_Parameter[0] = 1;
1076 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
1080 /* set grant_bt to high */
1081 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
1083 /* set wlan_act to always low */
1084 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
1086 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);
1088 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); /* BT select s0/s1 is controlled by BT */
1090 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */
1092 /* 0x4c[24:23]= 00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac = 0xf002 */
1093 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1096 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1100 /* Use H2C to set GNT_BT to LOW */
1101 if (fwVer >= 0x180000)
1103 if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765) != 0)
1105 H2C_Parameter[0] = 0;
1106 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
1111 /* BT calibration check */
1112 while (cntBtCalChk <= 20)
1114 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49d);
1118 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ########### BT is calibrating (wait cnt =%d) ###########\n", cntBtCalChk));
1123 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ********** BT is NOT calibrating (wait cnt =%d)**********\n", cntBtCalChk));
1128 /* set grant_bt to PTA */
1129 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0);
1132 if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) != 0xc)
1134 /* set wlan_act control by PTA */
1135 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
1143 /* 0x4c[23]= 0, 0x4c[24]= 1 Antenna control by WL/BT */
1144 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1147 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1149 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /* fixed internal switch S1->WiFi, S0->BT */
1151 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1153 /* tell firmware "no antenna inverse" */
1154 H2C_Parameter[0] = 0;
1155 H2C_Parameter[1] = 1; /* ext switch type */
1156 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1160 /* tell firmware "antenna inverse" */
1161 H2C_Parameter[0] = 1;
1162 H2C_Parameter[1] = 1; /* ext switch type */
1163 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1168 /* ext switch setting */
1171 case BTC_ANT_PATH_WIFI:
1172 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1173 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
1175 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
1177 case BTC_ANT_PATH_BT:
1178 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1179 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
1181 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
1184 case BTC_ANT_PATH_PTA:
1185 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1186 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
1188 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
1197 /* 0x4c[23]= 1, 0x4c[24]= 0 Antenna control by 0x64 */
1198 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1201 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1203 /* Fix Ext switch Main->S1, Aux->S0 */
1204 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0);
1206 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1209 /* tell firmware "no antenna inverse" */
1210 H2C_Parameter[0] = 0;
1211 H2C_Parameter[1] = 0; /* internal switch type */
1212 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1217 /* tell firmware "antenna inverse" */
1218 H2C_Parameter[0] = 1;
1219 H2C_Parameter[1] = 0; /* internal switch type */
1220 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1225 /* internal switch setting */
1228 case BTC_ANT_PATH_WIFI:
1229 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1230 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
1232 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
1234 case BTC_ANT_PATH_BT:
1235 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1236 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
1238 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
1241 case BTC_ANT_PATH_PTA:
1242 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1243 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x200);
1245 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x80);
1252 halbtc8723b1ant_SetFwPstdma(
1253 PBTC_COEXIST pBtCoexist,
1261 u8 H2C_Parameter[5] ={0};
1262 u8 realByte1 =byte1, realByte5 =byte5;
1263 bool bApEnable =false;
1265 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1269 if (byte1&BIT4 && !(byte1&BIT5))
1271 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], FW for 1Ant AP mode\n"));
1280 H2C_Parameter[0] = realByte1;
1281 H2C_Parameter[1] = byte2;
1282 H2C_Parameter[2] = byte3;
1283 H2C_Parameter[3] = byte4;
1284 H2C_Parameter[4] = realByte5;
1286 pCoexDm->psTdmaPara[0] = realByte1;
1287 pCoexDm->psTdmaPara[1] = byte2;
1288 pCoexDm->psTdmaPara[2] = byte3;
1289 pCoexDm->psTdmaPara[3] = byte4;
1290 pCoexDm->psTdmaPara[4] = realByte5;
1292 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], PS-TDMA H2C cmd = 0x%x%08x\n",
1294 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
1296 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
1301 halbtc8723b1ant_PsTdma(
1302 PBTC_COEXIST pBtCoexist,
1308 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
1309 bool bWifiBusy =false;
1310 u8 rssiAdjustVal = 0;
1311 u8 psTdmaByte4Val = 0x50, psTdmaByte0Val = 0x51, psTdmaByte3Val = 0x10;
1312 s8 nWiFiDurationAdjust = 0x0;
1313 /* u32 fwVer = 0; */
1315 /* BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn %s PS TDMA, type =%d\n", */
1316 /* (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type)); */
1317 pCoexDm->bCurPsTdmaOn = bTurnOn;
1318 pCoexDm->curPsTdma = type;
1320 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1322 if (pCoexDm->bCurPsTdmaOn)
1324 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ********** TDMA(on, %d) **********\n",
1325 pCoexDm->curPsTdma));
1329 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ********** TDMA(off, %d) **********\n",
1330 pCoexDm->curPsTdma));
1335 if ((pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
1336 (pCoexDm->prePsTdma == pCoexDm->curPsTdma))
1340 if (pCoexSta->nScanAPNum <= 5)
1341 nWiFiDurationAdjust = 5;
1342 else if (pCoexSta->nScanAPNum >= 40)
1343 nWiFiDurationAdjust = -15;
1344 else if (pCoexSta->nScanAPNum >= 20)
1345 nWiFiDurationAdjust = -10;
1347 if (!pCoexSta->bForceLpsOn) /* only for A2DP-only case 1/2/9/11 */
1349 psTdmaByte0Val = 0x61; /* no null-pkt */
1350 psTdmaByte3Val = 0x11; /* no tx-pause at BT-slot */
1351 psTdmaByte4Val = 0x10; /* 0x778 = d/1 toggle */
1357 if (pBtLinkInfo->bSlaveRole == true)
1359 psTdmaByte4Val = psTdmaByte4Val | 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1366 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, psTdmaByte4Val);
1369 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1372 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x2d+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1375 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, 0x10);
1378 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);
1381 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x15, 0x3, 0x11, 0x10);
1384 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x20, 0x3, 0x11, 0x11);
1387 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);
1390 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);
1393 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1396 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);
1399 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1402 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50);
1405 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x12, 0x12, 0x0, 0x10);
1408 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x21, 0x3, 0x10, psTdmaByte4Val);
1411 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);
1414 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);
1417 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);
1420 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x3f, 0x03, 0x11, 0x10);
1423 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11);
1426 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x10);
1429 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);
1432 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);
1435 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);
1438 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);
1441 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);
1444 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);
1447 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);
1450 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10);
1453 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);
1456 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x35, 0x3, 0x11, 0x11);
1459 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90);
1462 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10);
1465 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10);
1468 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);
1470 case 40: /* SoftAP only with no sta associated, BT disable , TDMA mode for power saving */
1471 /* here softap mode screen off will cost 70-80mA for phone */
1472 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24);
1479 /* disable PS tdma */
1482 case 8: /* PTA Control */
1483 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);
1484 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, false, false);
1487 default: /* Software control, Antenna at BT side */
1488 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
1489 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, false);
1491 case 9: /* Software control, Antenna at WiFi side */
1492 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
1493 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, false, false);
1498 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);
1500 /* update pre state */
1501 pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
1502 pCoexDm->prePsTdma = pCoexDm->curPsTdma;
1506 halbtc8723b1ant_IsCommonAction(
1507 PBTC_COEXIST pBtCoexist
1510 bool bCommon =false, bWifiConnected =false, bWifiBusy =false;
1512 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1513 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1515 if (!bWifiConnected &&
1516 BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)
1518 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));
1520 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1524 else if (bWifiConnected &&
1525 (BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus))
1527 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));
1529 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1533 else if (!bWifiConnected &&
1534 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus))
1536 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));
1538 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1542 else if (bWifiConnected &&
1543 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus))
1545 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));
1547 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1551 else if (!bWifiConnected &&
1552 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus))
1554 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));
1556 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1564 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));
1568 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));
1579 halbtc8723b1ant_TdmaDurationAdjustForAcl(
1580 PBTC_COEXIST pBtCoexist,
1584 static s32 up, dn, m, n, WaitCount;
1585 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1586 u8 retryCount = 0, btInfoExt;
1587 bool bWifiBusy = false;
1589 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));
1591 if (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifiStatus)
1596 if ((BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||
1597 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||
1598 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus))
1600 if (pCoexDm->curPsTdma != 1 &&
1601 pCoexDm->curPsTdma != 2 &&
1602 pCoexDm->curPsTdma != 3 &&
1603 pCoexDm->curPsTdma != 9)
1605 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1606 pCoexDm->psTdmaDuAdjType = 9;
1618 if (!pCoexDm->bAutoTdmaAdjust)
1620 pCoexDm->bAutoTdmaAdjust = true;
1621 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
1623 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1624 pCoexDm->psTdmaDuAdjType = 2;
1635 /* accquire the BT TRx retry count from BT_Info byte2 */
1636 retryCount = pCoexSta->btRetryCnt;
1637 btInfoExt = pCoexSta->btInfoExt;
1638 /* BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount)); */
1639 /* BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], up =%d, dn =%d, m =%d, n =%d, WaitCount =%d\n", */
1640 /* up, dn, m, n, WaitCount)); */
1642 if ((pCoexSta->lowPriorityTx) > 1050 || (pCoexSta->lowPriorityRx) > 1250)
1648 if (retryCount == 0) /* no retry in the last 2-second duration */
1656 if (up >= n) /* if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */
1663 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));
1666 else if (retryCount <= 3) /* <=3 retry in the last 2-second duration */
1674 if (dn == 2) /* if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */
1677 m++; /* 避免一直在兩個level中來回 */
1681 if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
1689 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
1692 else /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */
1695 m++; /* 避免一直在兩個level中來回 */
1699 if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
1707 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
1712 if ((BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&
1713 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)))
1715 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1716 pCoexDm->psTdmaDuAdjType = 9;
1718 else if (pCoexDm->curPsTdma == 1)
1720 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1721 pCoexDm->psTdmaDuAdjType = 2;
1723 else if (pCoexDm->curPsTdma == 2)
1725 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1726 pCoexDm->psTdmaDuAdjType = 9;
1728 else if (pCoexDm->curPsTdma == 9)
1730 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
1731 pCoexDm->psTdmaDuAdjType = 11;
1734 else if (result == 1)
1736 if ((BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&
1737 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)))
1739 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1740 pCoexDm->psTdmaDuAdjType = 9;
1742 else if (pCoexDm->curPsTdma == 11)
1744 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1745 pCoexDm->psTdmaDuAdjType = 9;
1747 else if (pCoexDm->curPsTdma == 9)
1749 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1750 pCoexDm->psTdmaDuAdjType = 2;
1752 else if (pCoexDm->curPsTdma == 2)
1754 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
1755 pCoexDm->psTdmaDuAdjType = 1;
1758 else /* no change */
1760 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], ********** TDMA(on, %d) **********\n",
1761 pCoexDm->curPsTdma));
1764 if (pCoexDm->curPsTdma != 1 &&
1765 pCoexDm->curPsTdma != 2 &&
1766 pCoexDm->curPsTdma != 9 &&
1767 pCoexDm->curPsTdma != 11)
1769 /* recover to previous adjust type */
1770 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, pCoexDm->psTdmaDuAdjType);
1776 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(
1777 PBTC_COEXIST pBtCoexist,
1783 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);
1785 if (lpsMode) /* already under LPS state */
1789 /* keep state under LPS, do nothing. */
1793 /* will leave LPS state, turn off psTdma first */
1794 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
1797 else /* NO PS state */
1801 /* will enter LPS state, turn off psTdma first */
1802 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
1806 /* keep state under NO PS state, do nothing. */
1812 halbtc8723b1ant_PowerSaveState(
1813 PBTC_COEXIST pBtCoexist,
1819 bool bLowPwrDisable =false;
1823 case BTC_PS_WIFI_NATIVE:
1824 /* recover to original 32k low power setting */
1825 bLowPwrDisable = false;
1826 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1827 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1828 pCoexSta->bForceLpsOn = false;
1831 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, true);
1832 halbtc8723b1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);
1833 /* when coex force to enter LPS, do not enter 32k low power. */
1834 bLowPwrDisable = true;
1835 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1836 /* power save must executed before psTdma. */
1837 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1838 pCoexSta->bForceLpsOn = true;
1840 case BTC_PS_LPS_OFF:
1841 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, false);
1842 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
1843 pCoexSta->bForceLpsOn = false;
1852 /* Software Coex Mechanism start */
1858 /* Non-Software Coex Mechanism start */
1862 halbtc8723b1ant_ActionWifiMultiPort(
1863 PBTC_COEXIST pBtCoexist
1866 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1868 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1869 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1873 halbtc8723b1ant_ActionHs(
1874 PBTC_COEXIST pBtCoexist
1877 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
1878 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1882 halbtc8723b1ant_ActionBtInquiry(
1883 PBTC_COEXIST pBtCoexist
1886 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
1887 bool bWifiConnected =false, bApEnable =false, bWifiBusy =false, bBtBusy =false;
1889 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1890 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1891 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1892 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
1894 if ((!bWifiConnected) && (!pCoexSta->bWiFiIsHighPriTask))
1896 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1897 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1899 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1901 else if ((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist) )
1903 /* SCO/HID/A2DP busy */
1904 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1905 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1907 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1909 else if ((pBtLinkInfo->bPanExist) || (bWifiBusy))
1911 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1912 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1914 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1918 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1919 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1921 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1926 halbtc8723b1ant_ActionBtScoHidOnlyBusy(
1927 PBTC_COEXIST pBtCoexist,
1931 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
1932 bool bWifiConnected =false;
1934 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1936 /* tdma and coex table */
1938 if (pBtLinkInfo->bScoExist)
1940 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
1941 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
1945 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1946 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
1951 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(
1952 PBTC_COEXIST pBtCoexist,
1958 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
1959 btRssiState = halbtc8723b1ant_BtRssiState(2, 28, 0);
1961 if ((pCoexSta->lowPriorityRx >= 1000) && (pCoexSta->lowPriorityRx != 65535))
1963 pBtLinkInfo->bSlaveRole = true;
1967 pBtLinkInfo->bSlaveRole = false;
1970 if (pBtLinkInfo->bHidOnly) /* HID */
1972 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);
1973 pCoexDm->bAutoTdmaAdjust = false;
1976 else if (pBtLinkInfo->bA2dpOnly) /* A2DP */
1978 if (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)
1980 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1981 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1982 pCoexDm->bAutoTdmaAdjust = false;
1986 halbtc8723b1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);
1987 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1988 pCoexDm->bAutoTdmaAdjust = true;
1991 else if (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist) /* HID+A2DP */
1993 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1994 pCoexDm->bAutoTdmaAdjust = false;
1996 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1998 else if ((pBtLinkInfo->bPanOnly) || (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist)) /* PAN(OPP, FTP), HID+PAN(OPP, FTP) */
2000 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
2001 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2002 pCoexDm->bAutoTdmaAdjust = false;
2004 else if (((pBtLinkInfo->bA2dpExist) && (pBtLinkInfo->bPanExist)) ||
2005 (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist&&pBtLinkInfo->bPanExist)) /* A2DP+PAN(OPP, FTP), HID+A2DP+PAN(OPP, FTP) */
2007 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
2008 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2009 pCoexDm->bAutoTdmaAdjust = false;
2013 /* BT no-profile busy (0x9) */
2014 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
2015 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2016 pCoexDm->bAutoTdmaAdjust = false;
2021 halbtc8723b1ant_ActionWifiNotConnected(
2022 PBTC_COEXIST pBtCoexist
2025 /* power save state */
2026 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2028 /* tdma and coex table */
2029 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8);
2030 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2034 halbtc8723b1ant_ActionWifiNotConnectedScan(
2035 PBTC_COEXIST pBtCoexist
2038 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
2040 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2042 /* tdma and coex table */
2043 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2045 if (pBtLinkInfo->bA2dpExist)
2047 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
2048 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2050 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
2052 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 22);
2053 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2057 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
2058 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2061 else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2062 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus))
2064 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2065 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2070 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
2071 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2076 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(
2077 PBTC_COEXIST pBtCoexist
2080 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
2082 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2084 /* tdma and coex table */
2085 if ((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist))
2087 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
2088 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2090 else if (pBtLinkInfo->bPanExist)
2092 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
2093 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2097 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
2098 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2103 halbtc8723b1ant_ActionWifiConnectedScan(
2104 PBTC_COEXIST pBtCoexist
2107 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
2109 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2111 /* tdma and coex table */
2112 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2114 if (pBtLinkInfo->bA2dpExist)
2116 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
2117 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2119 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
2121 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 22);
2122 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2126 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
2127 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2130 else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2131 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus))
2133 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2134 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2139 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
2140 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2145 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(
2146 PBTC_COEXIST pBtCoexist
2149 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
2151 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2153 /* tdma and coex table */
2154 if ((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist))
2156 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
2157 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2159 else if (pBtLinkInfo->bPanExist)
2161 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
2162 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2166 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
2167 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2172 halbtc8723b1ant_ActionWifiConnected(
2173 PBTC_COEXIST pBtCoexist
2176 bool bWifiBusy =false;
2177 bool bScan =false, bLink =false, bRoam =false;
2178 bool bUnder4way =false, bApEnable =false;
2180 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect() ===>\n"));
2182 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
2185 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
2186 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));
2190 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2191 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2192 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2193 if (bScan || bLink || bRoam)
2196 halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);
2198 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
2199 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));
2203 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
2204 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2206 /* power save state */
2207 if (!bApEnable && BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)
2209 if (pBtCoexist->btLinkInfo.bA2dpOnly) /* A2DP */
2212 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2215 if (pCoexSta->nScanAPNum >= BT_8723B_1ANT_WIFI_NOISY_THRESH) /* no force LPS, no PS-TDMA, use pure TDMA */
2217 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2221 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
2225 else if ((pCoexSta->bPanExist == false) && (pCoexSta->bA2dpExist == false) && (pCoexSta->bHidExist == false))
2226 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2228 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
2231 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2233 /* tdma and coex table */
2236 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2238 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,
2239 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2241 else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2242 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus))
2244 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2245 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2249 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
2251 if ((pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60)
2252 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2254 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2259 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2261 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,
2262 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2264 else if ((BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2265 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus))
2267 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2268 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2272 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
2274 if ((pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60)
2275 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2277 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2283 halbtc8723b1ant_RunSwCoexistMechanism(
2284 PBTC_COEXIST pBtCoexist
2289 algorithm = halbtc8723b1ant_ActionAlgorithm(pBtCoexist);
2290 pCoexDm->curAlgorithm = algorithm;
2292 if (halbtc8723b1ant_IsCommonAction(pBtCoexist))
2298 switch (pCoexDm->curAlgorithm)
2300 case BT_8723B_1ANT_COEX_ALGO_SCO:
2301 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = SCO.\n"));
2302 /* halbtc8723b1ant_ActionSco(pBtCoexist); */
2304 case BT_8723B_1ANT_COEX_ALGO_HID:
2305 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID.\n"));
2306 /* halbtc8723b1ant_ActionHid(pBtCoexist); */
2308 case BT_8723B_1ANT_COEX_ALGO_A2DP:
2309 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP.\n"));
2310 /* halbtc8723b1ant_ActionA2dp(pBtCoexist); */
2312 case BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS:
2313 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));
2314 /* halbtc8723b1ant_ActionA2dpPanHs(pBtCoexist); */
2316 case BT_8723B_1ANT_COEX_ALGO_PANEDR:
2317 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR).\n"));
2318 /* halbtc8723b1ant_ActionPanEdr(pBtCoexist); */
2320 case BT_8723B_1ANT_COEX_ALGO_PANHS:
2321 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HS mode.\n"));
2322 /* halbtc8723b1ant_ActionPanHs(pBtCoexist); */
2324 case BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP:
2325 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));
2326 /* halbtc8723b1ant_ActionPanEdrA2dp(pBtCoexist); */
2328 case BT_8723B_1ANT_COEX_ALGO_PANEDR_HID:
2329 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));
2330 /* halbtc8723b1ant_ActionPanEdrHid(pBtCoexist); */
2332 case BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
2333 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));
2334 /* halbtc8723b1ant_ActionHidA2dpPanEdr(pBtCoexist); */
2336 case BT_8723B_1ANT_COEX_ALGO_HID_A2DP:
2337 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP.\n"));
2338 /* halbtc8723b1ant_ActionHidA2dp(pBtCoexist); */
2341 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = coexist All Off!!\n"));
2344 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
2349 halbtc8723b1ant_RunCoexistMechanism(
2350 PBTC_COEXIST pBtCoexist
2353 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
2354 bool bWifiConnected =false, bBtHsOn =false;
2355 bool bIncreaseScanDevNum =false;
2356 bool bBtCtrlAggBufSize =false;
2358 u32 wifiLinkStatus = 0;
2359 u32 numOfWifiLink = 0;
2361 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism() ===>\n"));
2363 if (pBtCoexist->bManualControl)
2365 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));
2369 if (pBtCoexist->bStopCoexDm)
2371 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));
2375 if (pCoexSta->bUnderIps)
2377 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is under IPS !!!\n"));
2381 if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
2382 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2383 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus))
2385 bIncreaseScanDevNum = true;
2388 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, &bIncreaseScanDevNum);
2389 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2391 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
2392 numOfWifiLink = wifiLinkStatus>>16;
2394 if ((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))
2396 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("############# [BTCoex], Multi-Port numOfWifiLink = %d, wifiLinkStatus = 0x%x\n", numOfWifiLink, wifiLinkStatus));
2397 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2398 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize);
2400 if ((pBtLinkInfo->bA2dpExist) && (pCoexSta->bC2hBtInquiryPage))
2402 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("############# [BTCoex], BT Is Inquirying\n"));
2403 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2406 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
2411 if ((pBtLinkInfo->bBtLinkExist) && (bWifiConnected))
2413 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);
2415 if (pBtLinkInfo->bScoExist)
2416 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x5);
2418 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x8);
2420 halbtc8723b1ant_SwMechanism(pBtCoexist, true);
2421 halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); /* just print debug message */
2425 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2427 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x5);
2429 halbtc8723b1ant_SwMechanism(pBtCoexist, false);
2430 halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); /* just print debug message */
2433 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2434 if (pCoexSta->bC2hBtInquiryPage)
2436 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("############# [BTCoex], BT Is Inquirying\n"));
2437 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2442 halbtc8723b1ant_ActionHs(pBtCoexist);
2447 if (!bWifiConnected)
2449 bool bScan =false, bLink =false, bRoam =false;
2451 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is non connected-idle !!!\n"));
2453 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2454 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2455 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2457 if (bScan || bLink || bRoam)
2460 halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist);
2462 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
2465 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
2467 else /* wifi LPS/Busy */
2469 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
2474 halbtc8723b1ant_InitCoexDm(
2475 PBTC_COEXIST pBtCoexist
2478 /* force to reset coex mechanism */
2481 halbtc8723b1ant_SwMechanism(pBtCoexist, false);
2483 /* halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8); */
2484 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2486 pCoexSta->popEventCnt = 0;
2490 halbtc8723b1ant_InitHwConfig(
2491 PBTC_COEXIST pBtCoexist,
2496 u32 u4Tmp = 0;/* fwVer; */
2497 u8 u1Tmpa = 0, u1Tmpb = 0;
2499 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 1Ant Init HW Config!!\n"));
2501 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x550, 0x8, 0x1); /* enable TBTT nterrupt */
2503 /* 0x790[5:0]= 0x5 */
2504 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, 0x5);
2506 /* Enable counter statistics */
2507 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);
2508 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);
2510 /* Antenna config */
2513 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, true, false);
2514 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 9);
2517 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, true, false);
2520 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2522 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
2523 u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
2524 u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
2526 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("############# [BTCoex], 0x948 = 0x%x, 0x765 = 0x%x, 0x67 = 0x%x\n",
2527 u4Tmp, u1Tmpa, u1Tmpb));
2531 /* work around function start with wa_halbtc8723b1ant_ */
2534 /* extern function start with EXhalbtc8723b1ant_ */
2537 EXhalbtc8723b1ant_PowerOnSetting(
2538 PBTC_COEXIST pBtCoexist
2541 PBTC_BOARD_INFO pBoardInfo =&pBtCoexist->boardInfo;
2545 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x67, 0x20);
2547 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
2548 u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);
2549 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp|BIT0|BIT1);
2551 /* set GRAN_BT = 1 */
2552 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
2553 /* set WLAN_ACT = 0 */
2554 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
2557 /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
2558 /* Local setting bit define */
2559 /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
2560 /* BIT1: "0" for internal switch; "1" for external switch */
2561 /* BIT2: "0" for one antenna; "1" for two antenna */
2562 /* NOTE: here default all internal switch and 1-antenna ==> BIT1 = 0 and BIT2 = 0 */
2563 if (pBtCoexist->chipInterface == BTC_INTF_USB)
2565 /* fixed at S0 for USB interface */
2566 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
2568 u1Tmp |= 0x1; /* antenna inverse */
2569 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
2571 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
2575 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
2576 if (pBoardInfo->singleAntPath == 0)
2579 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
2580 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2582 else if (pBoardInfo->singleAntPath == 1)
2585 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
2586 u1Tmp |= 0x1; /* antenna inverse */
2587 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
2590 if (pBtCoexist->chipInterface == BTC_INTF_PCI)
2592 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);
2594 else if (pBtCoexist->chipInterface == BTC_INTF_SDIO)
2596 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
2602 EXhalbtc8723b1ant_InitHwConfig(
2603 PBTC_COEXIST pBtCoexist,
2607 halbtc8723b1ant_InitHwConfig(pBtCoexist, true, bWifiOnly);
2611 EXhalbtc8723b1ant_InitCoexDm(
2612 PBTC_COEXIST pBtCoexist
2615 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));
2617 pBtCoexist->bStopCoexDm = false;
2619 halbtc8723b1ant_InitCoexDm(pBtCoexist);
2621 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
2625 EXhalbtc8723b1ant_DisplayCoexInfo(
2626 PBTC_COEXIST pBtCoexist
2629 PBTC_BOARD_INFO pBoardInfo =&pBtCoexist->boardInfo;
2630 PBTC_STACK_INFO pStackInfo =&pBtCoexist->stackInfo;
2631 PBTC_BT_LINK_INFO pBtLinkInfo =&pBtCoexist->btLinkInfo;
2632 u8 * cliBuf =pBtCoexist->cliBuf;
2633 u8 u1Tmp[4], i, btInfoExt, psTdmaCase = 0;
2636 bool bRoam =false, bScan =false, bLink =false, bWifiUnder5G =false, bWifiUnderBMode = false;
2637 bool bBtHsOn =false, bWifiBusy =false;
2638 s32 wifiRssi = 0, btHsRssi = 0;
2639 u32 wifiBw, wifiTrafficDir, faOfdm, faCck, wifiLinkStatus;
2640 u8 wifiDot11Chnl, wifiHsChnl;
2641 u32 fwVer = 0, btPatchVer = 0;
2642 static u8 PopReportIn10s = 0;
2644 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
2647 if (pBtCoexist->bManualControl)
2649 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");
2651 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
2654 if (pBtCoexist->bStopCoexDm)
2656 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");
2658 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
2662 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Ant PG Num/ Ant Mech/ Ant Pos:", \
2663 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos);
2666 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
2667 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);
2670 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
2671 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
2672 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \
2673 GLCoexVerDate8723b1Ant, GLCoexVer8723b1Ant, fwVer, btPatchVer, btPatchVer);
2676 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2677 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiDot11Chnl);
2678 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl);
2679 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(HsMode)", \
2680 wifiDot11Chnl, wifiHsChnl, bBtHsOn);
2683 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "H2C Wifi inform bt chnl Info", \
2684 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],
2685 pCoexDm->wifiChnlInfo[2]);
2688 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
2689 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);
2690 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \
2691 wifiRssi-100, btHsRssi-100);
2694 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2695 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2696 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2697 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %s", "Wifi bLink/ bRoam/ bScan/ bHi-Pri", \
2698 bLink, bRoam, bScan, ((pCoexSta->bWiFiIsHighPriTask)? "1":"0"));
2701 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);
2702 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2703 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2704 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
2705 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
2707 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ AP =%d/ %s ", "Wifi status", \
2708 (bWifiUnder5G? "5G":"2.4G"),
2709 ((bWifiUnderBMode)? "11b": ((BTC_WIFI_BW_LEGACY ==wifiBw)? "11bg": (((BTC_WIFI_BW_HT40 ==wifiBw)? "HT40":"HT20")))),
2710 ((!bWifiBusy)? "idle": ((BTC_WIFI_TRAFFIC_TX ==wifiTrafficDir)? "uplink":"downlink")), pCoexSta->nScanAPNum, (pCoexSta->bCCKLock)? "Lock":"noLock");
2713 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
2714 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "sta/vwifi/hs/p2pGo/p2pGc", \
2715 ((wifiLinkStatus&WIFI_STA_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_AP_CONNECTED)? 1:0),
2716 ((wifiLinkStatus&WIFI_HS_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_P2P_GO_CONNECTED)? 1:0),
2717 ((wifiLinkStatus&WIFI_P2P_GC_CONNECTED)? 1:0));
2722 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", "BT [status/ rssi/ retryCnt/ popCnt]", \
2723 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"): ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":
2724 ((BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),
2725 pCoexSta->btRssi, pCoexSta->btRetryCnt, pCoexSta->popEventCnt);
2728 if (PopReportIn10s >= 5)
2730 pCoexSta->popEventCnt = 0;
2735 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \
2736 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist);
2739 if (pStackInfo->bProfileNotified)
2741 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
2745 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Role", \
2746 (pBtLinkInfo->bSlaveRole)? "Slave":"Master");
2751 btInfoExt = pCoexSta->btInfoExt;
2752 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \
2753 (btInfoExt&BIT0)? "Basic rate":"EDR rate");
2756 for (i = 0; i<BT_INFO_SRC_8723B_1ANT_MAX; i++)
2758 if (pCoexSta->btInfoC2hCnt[i])
2760 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723b1Ant[i], \
2761 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],
2762 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],
2763 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],
2764 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);
2768 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/%s, (0x%x/0x%x)", "PS state, IPS/LPS, (lps/rpwm)", \
2769 ((pCoexSta->bUnderIps? "IPS ON":"IPS OFF")),
2770 ((pCoexSta->bUnderLps? "LPS ON":"LPS OFF")),
2771 pBtCoexist->btInfo.lpsVal,
2772 pBtCoexist->btInfo.rpwmVal);
2774 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
2776 if (!pBtCoexist->bManualControl)
2779 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");
2782 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "SM[LowPenaltyRA]", \
2783 pCoexDm->bCurLowPenaltyRa);
2786 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "DelBA/ BtCtrlAgg/ AggSize", \
2787 (pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),
2788 pBtCoexist->btInfo.aggBufSize);
2790 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \
2791 pBtCoexist->btInfo.raMask);
2795 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
2798 psTdmaCase = pCoexDm->curPsTdma;
2799 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \
2800 pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],
2801 pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],
2802 pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);
2805 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Coex Table Type", \
2806 pCoexSta->nCoexTableType);
2809 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "IgnWlanAct", \
2810 pCoexDm->bCurIgnoreWlanAct);
2814 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Latest error condition(should be 0)", \
2815 pCoexDm->errorCondition);
2821 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
2824 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "backup ARFR1/ARFR2/RL/AMaxTime", \
2825 pCoexDm->backupArfrCnt1, pCoexDm->backupArfrCnt2, pCoexDm->backupRetryLimit, pCoexDm->backupAmpduMaxTime);
2828 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
2829 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
2830 u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
2831 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
2832 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \
2833 u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);
2836 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
2837 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6cc);
2838 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);
2839 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/0x6cc/0x880[29:25]", \
2840 u1Tmp[0], u4Tmp[0], (u4Tmp[1]&0x3e000000) >> 25);
2843 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
2844 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
2845 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x764);
2846 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);
2847 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x948/ 0x67[5] / 0x764 / 0x76e", \
2848 u4Tmp[0], ((u1Tmp[0]&0x20)>> 5), (u4Tmp[1] & 0xffff), u1Tmp[1]);
2851 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x92c);
2852 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);
2853 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x944);
2854 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]", \
2855 u4Tmp[0]&0x3, u4Tmp[1]&0xff, u4Tmp[2]&0x3);
2858 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x39);
2859 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
2860 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
2861 u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x64);
2862 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x38[11]/0x40/0x4c[24:23]/0x64[0]", \
2863 ((u1Tmp[0] & 0x8)>>3), u1Tmp[1], ((u4Tmp[0]&0x01800000)>>23), u1Tmp[2]&0x1);
2866 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
2867 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
2868 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \
2869 u4Tmp[0], u1Tmp[0]);
2872 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
2873 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49c);
2874 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xc50(dig)/0x49c(null-drop)", \
2875 u4Tmp[0]&0xff, u1Tmp[0]);
2878 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);
2879 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);
2880 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);
2881 u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);
2883 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);
2884 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);
2886 faOfdm = ((u4Tmp[0]&0xffff0000) >> 16) + ((u4Tmp[1]&0xffff0000) >> 16) + (u4Tmp[1] & 0xffff) + (u4Tmp[2] & 0xffff) + \
2887 ((u4Tmp[3]&0xffff0000) >> 16) + (u4Tmp[3] & 0xffff) ;
2888 faCck = (u1Tmp[0] << 8) + u1Tmp[1];
2890 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "OFDM-CCA/OFDM-FA/CCK-FA", \
2891 u4Tmp[0]&0xffff, faOfdm, faCck);
2895 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11n-Agg", \
2896 pCoexSta->nCRCOK_CCK, pCoexSta->nCRCOK_11g, pCoexSta->nCRCOK_11n, pCoexSta->nCRCOK_11nAgg);
2899 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11n-Agg", \
2900 pCoexSta->nCRCErr_CCK, pCoexSta->nCRCErr_11g, pCoexSta->nCRCErr_11n, pCoexSta->nCRCErr_11nAgg);
2903 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
2904 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
2905 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
2906 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8(coexTable)", \
2907 u4Tmp[0], u4Tmp[1], u4Tmp[2]);
2910 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \
2911 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);
2913 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \
2914 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);
2917 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
2922 EXhalbtc8723b1ant_IpsNotify(
2923 PBTC_COEXIST pBtCoexist,
2927 if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
2930 if (BTC_IPS_ENTER == type)
2932 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));
2933 pCoexSta->bUnderIps = true;
2935 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
2936 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2937 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true);
2939 else if (BTC_IPS_LEAVE == type)
2941 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));
2942 pCoexSta->bUnderIps = false;
2944 halbtc8723b1ant_InitHwConfig(pBtCoexist, false, false);
2945 halbtc8723b1ant_InitCoexDm(pBtCoexist);
2946 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
2951 EXhalbtc8723b1ant_LpsNotify(
2952 PBTC_COEXIST pBtCoexist,
2956 if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
2959 if (BTC_LPS_ENABLE == type)
2961 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));
2962 pCoexSta->bUnderLps = true;
2964 else if (BTC_LPS_DISABLE == type)
2966 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));
2967 pCoexSta->bUnderLps = false;
2972 EXhalbtc8723b1ant_ScanNotify(
2973 PBTC_COEXIST pBtCoexist,
2977 bool bWifiConnected =false, bBtHsOn =false;
2978 u32 wifiLinkStatus = 0;
2979 u32 numOfWifiLink = 0;
2980 bool bBtCtrlAggBufSize =false;
2986 if (pBtCoexist->bManualControl ||
2987 pBtCoexist->bStopCoexDm)
2990 if (BTC_SCAN_START == type)
2992 pCoexSta->bWiFiIsHighPriTask = true;
2993 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));
2995 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8); /* Force antenna setup for no scan result issue */
2996 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
2997 u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
2998 u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
3001 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], 0x948 = 0x%x, 0x765 = 0x%x, 0x67 = 0x%x\n",
3002 u4Tmp, u1Tmpa, u1Tmpb));
3006 pCoexSta->bWiFiIsHighPriTask = false;
3007 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));
3009 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &pCoexSta->nScanAPNum);
3012 if (pBtCoexist->btInfo.bBtDisabled)
3015 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
3016 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
3018 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
3020 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
3021 numOfWifiLink = wifiLinkStatus>>16;
3022 if (numOfWifiLink >= 2)
3024 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
3025 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize);
3026 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
3030 if (pCoexSta->bC2hBtInquiryPage)
3032 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
3037 halbtc8723b1ant_ActionHs(pBtCoexist);
3041 if (BTC_SCAN_START == type)
3043 /* BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n")); */
3044 if (!bWifiConnected) /* non-connected scan */
3046 halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist);
3048 else /* wifi is connected */
3050 halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);
3053 else if (BTC_SCAN_FINISH == type)
3055 /* BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n")); */
3056 if (!bWifiConnected) /* non-connected scan */
3058 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
3062 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
3068 EXhalbtc8723b1ant_ConnectNotify(
3069 PBTC_COEXIST pBtCoexist,
3073 bool bWifiConnected =false, bBtHsOn =false;
3074 u32 wifiLinkStatus = 0;
3075 u32 numOfWifiLink = 0;
3076 bool bBtCtrlAggBufSize =false;
3079 if (pBtCoexist->bManualControl ||
3080 pBtCoexist->bStopCoexDm ||
3081 pBtCoexist->btInfo.bBtDisabled)
3084 if (BTC_ASSOCIATE_START == type)
3086 pCoexSta->bWiFiIsHighPriTask = true;
3087 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));
3088 pCoexDm->nArpCnt = 0;
3092 pCoexSta->bWiFiIsHighPriTask = false;
3093 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));
3094 /* pCoexDm->nArpCnt = 0; */
3097 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
3098 numOfWifiLink = wifiLinkStatus>>16;
3099 if (numOfWifiLink >= 2)
3101 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
3102 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize);
3103 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
3107 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
3108 if (pCoexSta->bC2hBtInquiryPage)
3110 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
3115 halbtc8723b1ant_ActionHs(pBtCoexist);
3119 if (BTC_ASSOCIATE_START == type)
3121 /* BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n")); */
3122 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
3124 else if (BTC_ASSOCIATE_FINISH == type)
3126 /* BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n")); */
3128 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
3129 if (!bWifiConnected) /* non-connected scan */
3131 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
3135 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
3141 EXhalbtc8723b1ant_MediaStatusNotify(
3142 PBTC_COEXIST pBtCoexist,
3146 u8 H2C_Parameter[3] ={0};
3149 bool bWifiUnderBMode = false;
3151 if (pBtCoexist->bManualControl ||
3152 pBtCoexist->bStopCoexDm ||
3153 pBtCoexist->btInfo.bBtDisabled)
3156 if (BTC_MEDIA_CONNECT == type)
3158 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));
3160 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
3162 /* Set CCK Tx/Rx high Pri except 11b mode */
3163 if (bWifiUnderBMode)
3165 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); /* CCK Tx */
3166 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x00); /* CCK Rx */
3170 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x10); /* CCK Tx */
3171 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); /* CCK Rx */
3174 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
3175 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
3176 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
3177 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
3181 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));
3182 pCoexDm->nArpCnt = 0;
3184 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x0); /* CCK Tx */
3185 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x0); /* CCK Rx */
3188 /* only 2.4G we need to inform bt the chnl mask */
3189 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
3190 if ((BTC_MEDIA_CONNECT == type) &&
3191 (wifiCentralChnl <= 14))
3193 /* H2C_Parameter[0] = 0x1; */
3194 H2C_Parameter[0] = 0x0;
3195 H2C_Parameter[1] = wifiCentralChnl;
3196 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3197 if (BTC_WIFI_BW_HT40 == wifiBw)
3198 H2C_Parameter[2] = 0x30;
3200 H2C_Parameter[2] = 0x20;
3203 pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
3204 pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
3205 pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
3207 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x66 = 0x%x\n",
3208 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
3210 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
3214 EXhalbtc8723b1ant_SpecialPacketNotify(
3215 PBTC_COEXIST pBtCoexist,
3219 bool bBtHsOn =false;
3220 u32 wifiLinkStatus = 0;
3221 u32 numOfWifiLink = 0;
3222 bool bBtCtrlAggBufSize =false;
3225 if (pBtCoexist->bManualControl ||
3226 pBtCoexist->bStopCoexDm ||
3227 pBtCoexist->btInfo.bBtDisabled)
3230 if (BTC_PACKET_DHCP == type ||
3231 BTC_PACKET_EAPOL == type ||
3232 BTC_PACKET_ARP == type)
3234 if (BTC_PACKET_ARP == type)
3236 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet ARP notify\n"));
3239 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], ARP Packet Count = %d\n", pCoexDm->nArpCnt));
3241 if (pCoexDm->nArpCnt >= 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist) */
3243 pCoexSta->bWiFiIsHighPriTask = false;
3247 pCoexSta->bWiFiIsHighPriTask = true;
3252 pCoexSta->bWiFiIsHighPriTask = true;
3253 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet DHCP or EAPOL notify\n"));
3258 pCoexSta->bWiFiIsHighPriTask = false;
3259 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet [Type = %d] notify\n", type));
3262 pCoexSta->specialPktPeriodCnt = 0;
3264 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
3265 numOfWifiLink = wifiLinkStatus>>16;
3266 if (numOfWifiLink >= 2)
3268 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
3269 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize);
3270 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
3274 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
3275 if (pCoexSta->bC2hBtInquiryPage)
3277 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
3282 halbtc8723b1ant_ActionHs(pBtCoexist);
3286 if (BTC_PACKET_DHCP == type ||
3287 BTC_PACKET_EAPOL == type ||
3288 ((BTC_PACKET_ARP == type) && (pCoexSta->bWiFiIsHighPriTask)))
3290 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
3295 EXhalbtc8723b1ant_BtInfoNotify(
3296 PBTC_COEXIST pBtCoexist,
3302 u8 i, rspSource = 0;
3303 bool bWifiConnected =false;
3304 bool bBtBusy =false;
3306 pCoexSta->bC2hBtInfoReqSent = false;
3308 rspSource = tmpBuf[0]&0xf;
3309 if (rspSource >= BT_INFO_SRC_8723B_1ANT_MAX)
3310 rspSource = BT_INFO_SRC_8723B_1ANT_WIFI_FW;
3311 pCoexSta->btInfoC2hCnt[rspSource]++;
3313 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length =%d, hex data =[", rspSource, length));
3314 for (i = 0; i<length; i++)
3316 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
3321 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));
3325 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));
3329 if (BT_INFO_SRC_8723B_1ANT_WIFI_FW != rspSource)
3331 pCoexSta->btRetryCnt = /* [3:0] */
3332 pCoexSta->btInfoC2h[rspSource][2]&0xf;
3334 if (pCoexSta->btRetryCnt >= 1)
3335 pCoexSta->popEventCnt++;
3337 if (pCoexSta->btInfoC2h[rspSource][2]&0x20)
3338 pCoexSta->bC2hBtPage = true;
3340 pCoexSta->bC2hBtPage = false;
3343 pCoexSta->btInfoC2h[rspSource][3]*2-90;
3344 /* pCoexSta->btInfoC2h[rspSource][3]*2+10; */
3346 pCoexSta->btInfoExt =
3347 pCoexSta->btInfoC2h[rspSource][4];
3349 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);
3350 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);
3351 if (!pCoexSta->bBtTxRxMask)
3353 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
3354 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n"));
3355 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15);
3358 /* Here we need to resend some wifi info to BT */
3359 /* because bt is reset and loss of the info. */
3360 if (pCoexSta->btInfoExt & BIT1)
3362 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));
3363 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
3366 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);
3370 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
3374 if (pCoexSta->btInfoExt & BIT3)
3376 if (!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)
3378 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));
3379 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, false);
3384 /* BT already NOT ignore Wlan active, do nothing here. */
3388 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3389 if (btInfo & BT_INFO_8723B_1ANT_B_INQ_PAGE)
3390 pCoexSta->bC2hBtInquiryPage = true;
3392 pCoexSta->bC2hBtInquiryPage = false;
3394 /* set link exist status */
3395 if (!(btInfo&BT_INFO_8723B_1ANT_B_CONNECTION))
3397 pCoexSta->bBtLinkExist = false;
3398 pCoexSta->bPanExist = false;
3399 pCoexSta->bA2dpExist = false;
3400 pCoexSta->bHidExist = false;
3401 pCoexSta->bScoExist = false;
3403 else /* connection exists */
3405 pCoexSta->bBtLinkExist = true;
3406 if (btInfo & BT_INFO_8723B_1ANT_B_FTP)
3407 pCoexSta->bPanExist = true;
3409 pCoexSta->bPanExist = false;
3410 if (btInfo & BT_INFO_8723B_1ANT_B_A2DP)
3411 pCoexSta->bA2dpExist = true;
3413 pCoexSta->bA2dpExist = false;
3414 if (btInfo & BT_INFO_8723B_1ANT_B_HID)
3415 pCoexSta->bHidExist = true;
3417 pCoexSta->bHidExist = false;
3418 if (btInfo & BT_INFO_8723B_1ANT_B_SCO_ESCO)
3419 pCoexSta->bScoExist = true;
3421 pCoexSta->bScoExist = false;
3424 halbtc8723b1ant_UpdateBtLinkInfo(pBtCoexist);
3426 btInfo = btInfo & 0x1f; /* mask profile bit for connect-ilde identification (for CSR case: A2DP idle --> 0x41) */
3428 if (!(btInfo&BT_INFO_8723B_1ANT_B_CONNECTION))
3430 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
3431 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));
3433 else if (btInfo == BT_INFO_8723B_1ANT_B_CONNECTION) /* connection exists but no busy */
3435 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE;
3436 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));
3438 else if ((btInfo&BT_INFO_8723B_1ANT_B_SCO_ESCO) ||
3439 (btInfo&BT_INFO_8723B_1ANT_B_SCO_BUSY))
3441 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_SCO_BUSY;
3442 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));
3444 else if (btInfo&BT_INFO_8723B_1ANT_B_ACL_BUSY)
3446 if (BT_8723B_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)
3447 pCoexDm->bAutoTdmaAdjust = false;
3448 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_ACL_BUSY;
3449 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));
3453 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_MAX;
3454 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));
3457 if ((BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
3458 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
3459 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus))
3463 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
3465 halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);
3469 EXhalbtc8723b1ant_HaltNotify(
3470 PBTC_COEXIST pBtCoexist
3473 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));
3475 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3476 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 0);
3477 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true);
3479 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, true);
3481 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
3483 pBtCoexist->bStopCoexDm = true;
3487 EXhalbtc8723b1ant_PnpNotify(
3488 PBTC_COEXIST pBtCoexist,
3492 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify\n"));
3494 if (BTC_WIFI_PNP_SLEEP == pnpState)
3496 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to SLEEP\n"));
3498 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3499 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
3500 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
3501 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true);
3503 pBtCoexist->bStopCoexDm = true;
3505 else if (BTC_WIFI_PNP_WAKE_UP == pnpState)
3507 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to WAKE UP\n"));
3508 pBtCoexist->bStopCoexDm = false;
3509 halbtc8723b1ant_InitHwConfig(pBtCoexist, false, false);
3510 halbtc8723b1ant_InitCoexDm(pBtCoexist);
3511 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
3516 EXhalbtc8723b1ant_Periodical(
3517 PBTC_COEXIST pBtCoexist
3520 static u8 disVerInfoCnt = 0;
3521 u32 fwVer = 0, btPatchVer = 0;
3523 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ==========================Periodical ===========================\n"));
3525 if (disVerInfoCnt <= 5)
3528 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));
3529 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
3530 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
3531 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", \
3532 GLCoexVerDate8723b1Ant, GLCoexVer8723b1Ant, fwVer, btPatchVer, btPatchVer));
3533 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));
3536 halbtc8723b1ant_MonitorBtCtr(pBtCoexist);
3537 halbtc8723b1ant_MonitorWiFiCtr(pBtCoexist);
3539 if (halbtc8723b1ant_IsWifiStatusChanged(pBtCoexist) ||
3540 pCoexDm->bAutoTdmaAdjust)
3543 halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);
3546 pCoexSta->specialPktPeriodCnt++;