phy: rockchip-inno-usb2: add SDP detect retry
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8188eu / hal / OUTSRC-BTCoexist / HalBtc8723b1Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for RTL8723B Co-exist mechanism\r
5 //\r
6 // History\r
7 // 2012/11/15 Cosa first check in.\r
8 //\r
9 //============================================================\r
10 \r
11 //============================================================\r
12 // include files\r
13 //============================================================\r
14 #include "Mp_Precomp.h"\r
15 #if(BT_30_SUPPORT == 1)\r
16 //============================================================\r
17 // Global variables, these are static variables\r
18 //============================================================\r
19 static COEX_DM_8723B_1ANT               GLCoexDm8723b1Ant;\r
20 static PCOEX_DM_8723B_1ANT      pCoexDm=&GLCoexDm8723b1Ant;\r
21 static COEX_STA_8723B_1ANT              GLCoexSta8723b1Ant;\r
22 static PCOEX_STA_8723B_1ANT     pCoexSta=&GLCoexSta8723b1Ant;\r
23 \r
24 const char *const GLBtInfoSrc8723b1Ant[]={\r
25         "BT Info[wifi fw]",\r
26         "BT Info[bt rsp]",\r
27         "BT Info[bt auto report]",\r
28 };\r
29 \r
30 u4Byte  GLCoexVerDate8723b1Ant=20140110;\r
31 u4Byte  GLCoexVer8723b1Ant=0x49;\r
32 \r
33 //============================================================\r
34 // local function proto type if needed\r
35 //============================================================\r
36 //============================================================\r
37 // local function start with halbtc8723b1ant_\r
38 //============================================================\r
39 u1Byte\r
40 halbtc8723b1ant_BtRssiState(\r
41         u1Byte                  levelNum,\r
42         u1Byte                  rssiThresh,\r
43         u1Byte                  rssiThresh1\r
44         )\r
45 {\r
46         s4Byte                  btRssi=0;\r
47         u1Byte                  btRssiState=pCoexSta->preBtRssiState;\r
48 \r
49         btRssi = pCoexSta->btRssi;\r
50 \r
51         if(levelNum == 2)\r
52         {                       \r
53                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
54                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
55                 {\r
56                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
57                         {\r
58                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
59                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
60                         }\r
61                         else\r
62                         {\r
63                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
64                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
65                         }\r
66                 }\r
67                 else\r
68                 {\r
69                         if(btRssi < rssiThresh)\r
70                         {\r
71                                 btRssiState = BTC_RSSI_STATE_LOW;\r
72                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
73                         }\r
74                         else\r
75                         {\r
76                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
77                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
78                         }\r
79                 }\r
80         }\r
81         else if(levelNum == 3)\r
82         {\r
83                 if(rssiThresh > rssiThresh1)\r
84                 {\r
85                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi thresh error!!\n"));\r
86                         return pCoexSta->preBtRssiState;\r
87                 }\r
88                 \r
89                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
90                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
91                 {\r
92                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
93                         {\r
94                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
95                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
96                         }\r
97                         else\r
98                         {\r
99                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
100                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
101                         }\r
102                 }\r
103                 else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
104                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))\r
105                 {\r
106                         if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
107                         {\r
108                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
109                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
110                         }\r
111                         else if(btRssi < rssiThresh)\r
112                         {\r
113                                 btRssiState = BTC_RSSI_STATE_LOW;\r
114                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
115                         }\r
116                         else\r
117                         {\r
118                                 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
119                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Medium\n"));\r
120                         }\r
121                 }\r
122                 else\r
123                 {\r
124                         if(btRssi < rssiThresh1)\r
125                         {\r
126                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
127                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
128                         }\r
129                         else\r
130                         {\r
131                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
132                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
133                         }\r
134                 }\r
135         }\r
136                 \r
137         pCoexSta->preBtRssiState = btRssiState;\r
138 \r
139         return btRssiState;\r
140 }\r
141 \r
142 u1Byte\r
143 halbtc8723b1ant_WifiRssiState(\r
144         IN      PBTC_COEXIST            pBtCoexist,\r
145         IN      u1Byte                  index,\r
146         IN      u1Byte                  levelNum,\r
147         IN      u1Byte                  rssiThresh,\r
148         IN      u1Byte                  rssiThresh1\r
149         )\r
150 {\r
151         s4Byte                  wifiRssi=0;\r
152         u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];\r
153 \r
154         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
155         \r
156         if(levelNum == 2)\r
157         {\r
158                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
159                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
160                 {\r
161                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
162                         {\r
163                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
164                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
165                         }\r
166                         else\r
167                         {\r
168                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
169                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
170                         }\r
171                 }\r
172                 else\r
173                 {\r
174                         if(wifiRssi < rssiThresh)\r
175                         {\r
176                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
177                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
178                         }\r
179                         else\r
180                         {\r
181                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
182                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
183                         }\r
184                 }\r
185         }\r
186         else if(levelNum == 3)\r
187         {\r
188                 if(rssiThresh > rssiThresh1)\r
189                 {\r
190                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI thresh error!!\n"));\r
191                         return pCoexSta->preWifiRssiState[index];\r
192                 }\r
193                 \r
194                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
195                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
196                 {\r
197                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
198                         {\r
199                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
200                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
201                         }\r
202                         else\r
203                         {\r
204                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
205                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
206                         }\r
207                 }\r
208                 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||\r
209                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))\r
210                 {\r
211                         if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))\r
212                         {\r
213                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
214                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
215                         }\r
216                         else if(wifiRssi < rssiThresh)\r
217                         {\r
218                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
219                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
220                         }\r
221                         else\r
222                         {\r
223                                 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
224                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Medium\n"));\r
225                         }\r
226                 }\r
227                 else\r
228                 {\r
229                         if(wifiRssi < rssiThresh1)\r
230                         {\r
231                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
232                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
233                         }\r
234                         else\r
235                         {\r
236                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
237                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
238                         }\r
239                 }\r
240         }\r
241                 \r
242         pCoexSta->preWifiRssiState[index] = wifiRssiState;\r
243 \r
244         return wifiRssiState;\r
245 }\r
246 \r
247 VOID\r
248 halbtc8723b1ant_UpdateRaMask(\r
249         IN      PBTC_COEXIST            pBtCoexist,\r
250         IN      BOOLEAN                         bForceExec,\r
251         IN      u4Byte                          disRateMask\r
252         )\r
253 {\r
254         pCoexDm->curRaMask = disRateMask;\r
255         \r
256         if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))\r
257         {\r
258                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);\r
259         }\r
260         pCoexDm->preRaMask = pCoexDm->curRaMask;\r
261 }\r
262 \r
263 VOID\r
264 halbtc8723b1ant_AutoRateFallbackRetry(\r
265         IN      PBTC_COEXIST            pBtCoexist,\r
266         IN      BOOLEAN                         bForceExec,\r
267         IN      u1Byte                          type\r
268         )\r
269 {\r
270         BOOLEAN bWifiUnderBMode=FALSE;\r
271         \r
272         pCoexDm->curArfrType = type;\r
273 \r
274         if( bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType))\r
275         {\r
276                 switch(pCoexDm->curArfrType)\r
277                 {\r
278                         case 0: // normal mode\r
279                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, pCoexDm->backupArfrCnt1);\r
280                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, pCoexDm->backupArfrCnt2);\r
281                                 break;\r
282                         case 1: \r
283                                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);\r
284                                 if(bWifiUnderBMode)\r
285                                 {\r
286                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);\r
287                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);\r
288                                 }\r
289                                 else\r
290                                 {\r
291                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);\r
292                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);\r
293                                 }\r
294                                 break;\r
295                         default:\r
296                                 break;\r
297                 }\r
298         }\r
299 \r
300         pCoexDm->preArfrType = pCoexDm->curArfrType;\r
301 }\r
302 \r
303 VOID\r
304 halbtc8723b1ant_RetryLimit(\r
305         IN      PBTC_COEXIST            pBtCoexist,\r
306         IN      BOOLEAN                         bForceExec,\r
307         IN      u1Byte                          type\r
308         )\r
309 {\r
310         pCoexDm->curRetryLimitType = type;\r
311 \r
312         if( bForceExec || (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType))\r
313         {\r
314                 switch(pCoexDm->curRetryLimitType)\r
315                 {\r
316                         case 0: // normal mode\r
317                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, pCoexDm->backupRetryLimit);\r
318                                 break;\r
319                         case 1: // retry limit=8\r
320                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);\r
321                                 break;\r
322                         default:\r
323                                 break;\r
324                 }\r
325         }\r
326 \r
327         pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;\r
328 }\r
329 \r
330 VOID\r
331 halbtc8723b1ant_AmpduMaxTime(\r
332         IN      PBTC_COEXIST            pBtCoexist,\r
333         IN      BOOLEAN                         bForceExec,\r
334         IN      u1Byte                          type\r
335         )\r
336 {\r
337         pCoexDm->curAmpduTimeType = type;\r
338 \r
339         if( bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType))\r
340         {\r
341                 switch(pCoexDm->curAmpduTimeType)\r
342                 {\r
343                         case 0: // normal mode\r
344                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime);\r
345                                 break;\r
346                         case 1: // AMPDU timw = 0x38 * 32us\r
347                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);\r
348                                 break;\r
349                         default:\r
350                                 break;\r
351                 }\r
352         }\r
353 \r
354         pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;\r
355 }\r
356 \r
357 VOID\r
358 halbtc8723b1ant_LimitedTx(\r
359         IN      PBTC_COEXIST            pBtCoexist,\r
360         IN      BOOLEAN                         bForceExec,\r
361         IN      u1Byte                          raMaskType,\r
362         IN      u1Byte                          arfrType,\r
363         IN      u1Byte                          retryLimitType,\r
364         IN      u1Byte                          ampduTimeType\r
365         )\r
366 {\r
367         switch(raMaskType)\r
368         {\r
369                 case 0: // normal mode\r
370                         halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);\r
371                         break;\r
372                 case 1: // disable cck 1/2\r
373                         halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x00000003);\r
374                         break;\r
375                 case 2: // disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4\r
376                         halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);\r
377                         break;\r
378                 default:\r
379                         break;\r
380         }\r
381 \r
382         halbtc8723b1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);\r
383         halbtc8723b1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);\r
384         halbtc8723b1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);\r
385 }\r
386 \r
387 VOID\r
388 halbtc8723b1ant_LimitedRx(\r
389         IN      PBTC_COEXIST            pBtCoexist,\r
390         IN      BOOLEAN                         bForceExec,\r
391         IN      BOOLEAN                         bRejApAggPkt,\r
392         IN      BOOLEAN                         bBtCtrlAggBufSize,\r
393         IN      u1Byte                          aggBufSize\r
394         )\r
395 {\r
396         BOOLEAN bRejectRxAgg=bRejApAggPkt;\r
397         BOOLEAN bBtCtrlRxAggSize=bBtCtrlAggBufSize;\r
398         u1Byte  rxAggSize=aggBufSize;\r
399 \r
400         //============================================\r
401         //      Rx Aggregation related setting\r
402         //============================================\r
403         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);\r
404         // decide BT control aggregation buf size or not\r
405         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);\r
406         // aggregation buf size, only work when BT control Rx aggregation size.\r
407         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);\r
408         // real update aggregation setting\r
409         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);\r
410 \r
411 \r
412 }\r
413 \r
414 VOID\r
415 halbtc8723b1ant_MonitorBtCtr(\r
416         IN      PBTC_COEXIST            pBtCoexist\r
417         )\r
418 {\r
419         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp, u4Tmp1;\r
420         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
421         u1Byte                  u1Tmp, u1Tmp1;\r
422         s4Byte                  wifiRssi;\r
423         \r
424         regHPTxRx = 0x770;\r
425         regLPTxRx = 0x774;\r
426 \r
427         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
428         regHPTx = u4Tmp & bMaskLWord;\r
429         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
430 \r
431         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
432         regLPTx = u4Tmp & bMaskLWord;\r
433         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
434                 \r
435         pCoexSta->highPriorityTx = regHPTx;\r
436         pCoexSta->highPriorityRx = regHPRx;\r
437         pCoexSta->lowPriorityTx = regLPTx;\r
438         pCoexSta->lowPriorityRx = regLPRx;\r
439 \r
440         // reset counter\r
441         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
442 }\r
443 \r
444 VOID\r
445 halbtc8723b1ant_QueryBtInfo(\r
446         IN      PBTC_COEXIST            pBtCoexist\r
447         )\r
448 {\r
449         u1Byte                  H2C_Parameter[1] ={0};\r
450 \r
451         pCoexSta->bC2hBtInfoReqSent = TRUE;\r
452 \r
453         H2C_Parameter[0] |= BIT0;       // trigger\r
454 \r
455         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n", \r
456                 H2C_Parameter[0]));\r
457 \r
458         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);\r
459 }\r
460 \r
461 BOOLEAN\r
462 halbtc8723b1ant_IsWifiStatusChanged(\r
463         IN      PBTC_COEXIST            pBtCoexist\r
464         )\r
465 {\r
466         static BOOLEAN  bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;\r
467         BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;\r
468         BOOLEAN bWifiConnected=FALSE;\r
469 \r
470         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
471         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
472         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
473         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
474 \r
475         if(bWifiConnected)\r
476         {\r
477                 if(bWifiBusy != bPreWifiBusy)\r
478                 {\r
479                         bPreWifiBusy = bWifiBusy;\r
480                         return TRUE;\r
481                 }\r
482                 if(bUnder4way != bPreUnder4way)\r
483                 {\r
484                         bPreUnder4way = bUnder4way;\r
485                         return TRUE;\r
486                 }\r
487                 if(bBtHsOn != bPreBtHsOn)\r
488                 {\r
489                         bPreBtHsOn = bBtHsOn;\r
490                         return TRUE;\r
491                 }\r
492         }\r
493 \r
494         return FALSE;\r
495 }\r
496 \r
497 VOID\r
498 halbtc8723b1ant_UpdateBtLinkInfo(\r
499         IN      PBTC_COEXIST            pBtCoexist\r
500         )\r
501 {\r
502         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
503         BOOLEAN                         bBtHsOn=FALSE;\r
504 \r
505         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
506 \r
507         pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;\r
508         pBtLinkInfo->bScoExist = pCoexSta->bScoExist;\r
509         pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;\r
510         pBtLinkInfo->bPanExist = pCoexSta->bPanExist;\r
511         pBtLinkInfo->bHidExist = pCoexSta->bHidExist;\r
512 \r
513         // work around for HS mode.\r
514         if(bBtHsOn)\r
515         {\r
516                 pBtLinkInfo->bPanExist = TRUE;\r
517                 pBtLinkInfo->bBtLinkExist = TRUE;\r
518         }\r
519 \r
520         // check if Sco only\r
521         if( pBtLinkInfo->bScoExist &&\r
522                 !pBtLinkInfo->bA2dpExist &&\r
523                 !pBtLinkInfo->bPanExist &&\r
524                 !pBtLinkInfo->bHidExist )\r
525                 pBtLinkInfo->bScoOnly = TRUE;\r
526         else\r
527                 pBtLinkInfo->bScoOnly = FALSE;\r
528 \r
529         // check if A2dp only\r
530         if( !pBtLinkInfo->bScoExist &&\r
531                 pBtLinkInfo->bA2dpExist &&\r
532                 !pBtLinkInfo->bPanExist &&\r
533                 !pBtLinkInfo->bHidExist )\r
534                 pBtLinkInfo->bA2dpOnly = TRUE;\r
535         else\r
536                 pBtLinkInfo->bA2dpOnly = FALSE;\r
537 \r
538         // check if Pan only\r
539         if( !pBtLinkInfo->bScoExist &&\r
540                 !pBtLinkInfo->bA2dpExist &&\r
541                 pBtLinkInfo->bPanExist &&\r
542                 !pBtLinkInfo->bHidExist )\r
543                 pBtLinkInfo->bPanOnly = TRUE;\r
544         else\r
545                 pBtLinkInfo->bPanOnly = FALSE;\r
546         \r
547         // check if Hid only\r
548         if( !pBtLinkInfo->bScoExist &&\r
549                 !pBtLinkInfo->bA2dpExist &&\r
550                 !pBtLinkInfo->bPanExist &&\r
551                 pBtLinkInfo->bHidExist )\r
552                 pBtLinkInfo->bHidOnly = TRUE;\r
553         else\r
554                 pBtLinkInfo->bHidOnly = FALSE;\r
555 }\r
556 \r
557 u1Byte\r
558 halbtc8723b1ant_ActionAlgorithm(\r
559         IN      PBTC_COEXIST            pBtCoexist\r
560         )\r
561 {\r
562         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
563         BOOLEAN                         bBtHsOn=FALSE;\r
564         u1Byte                          algorithm=BT_8723B_1ANT_COEX_ALGO_UNDEFINED;\r
565         u1Byte                          numOfDiffProfile=0;\r
566 \r
567         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
568 \r
569         if(!pBtLinkInfo->bBtLinkExist)\r
570         {\r
571                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No BT link exists!!!\n"));\r
572                 return algorithm;\r
573         }\r
574 \r
575         if(pBtLinkInfo->bScoExist)\r
576                 numOfDiffProfile++;\r
577         if(pBtLinkInfo->bHidExist)\r
578                 numOfDiffProfile++;\r
579         if(pBtLinkInfo->bPanExist)\r
580                 numOfDiffProfile++;\r
581         if(pBtLinkInfo->bA2dpExist)\r
582                 numOfDiffProfile++;\r
583         \r
584         if(numOfDiffProfile == 1)\r
585         {\r
586                 if(pBtLinkInfo->bScoExist)\r
587                 {\r
588                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO only\n"));\r
589                         algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;\r
590                 }\r
591                 else\r
592                 {\r
593                         if(pBtLinkInfo->bHidExist)\r
594                         {\r
595                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID only\n"));\r
596                                 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;\r
597                         }\r
598                         else if(pBtLinkInfo->bA2dpExist)\r
599                         {\r
600                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP only\n"));\r
601                                 algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP;\r
602                         }\r
603                         else if(pBtLinkInfo->bPanExist)\r
604                         {\r
605                                 if(bBtHsOn)\r
606                                 {\r
607                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = PAN(HS) only\n"));\r
608                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANHS;\r
609                                 }\r
610                                 else\r
611                                 {\r
612                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = PAN(EDR) only\n"));\r
613                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR;\r
614                                 }\r
615                         }\r
616                 }\r
617         }\r
618         else if(numOfDiffProfile == 2)\r
619         {\r
620                 if(pBtLinkInfo->bScoExist)\r
621                 {\r
622                         if(pBtLinkInfo->bHidExist)\r
623                         {\r
624                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID\n"));\r
625                                 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;\r
626                         }\r
627                         else if(pBtLinkInfo->bA2dpExist)\r
628                         {\r
629                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"));\r
630                                 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;\r
631                         }\r
632                         else if(pBtLinkInfo->bPanExist)\r
633                         {\r
634                                 if(bBtHsOn)\r
635                                 {\r
636                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + PAN(HS)\n"));\r
637                                         algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;\r
638                                 }\r
639                                 else\r
640                                 {\r
641                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + PAN(EDR)\n"));\r
642                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;\r
643                                 }\r
644                         }\r
645                 }\r
646                 else\r
647                 {\r
648                         if( pBtLinkInfo->bHidExist &&\r
649                                 pBtLinkInfo->bA2dpExist )\r
650                         {\r
651                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP\n"));\r
652                                 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;\r
653                         }\r
654                         else if( pBtLinkInfo->bHidExist &&\r
655                                 pBtLinkInfo->bPanExist )\r
656                         {\r
657                                 if(bBtHsOn)\r
658                                 {\r
659                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + PAN(HS)\n"));\r
660                                         algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;\r
661                                 }\r
662                                 else\r
663                                 {\r
664                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + PAN(EDR)\n"));\r
665                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;\r
666                                 }\r
667                         }\r
668                         else if( pBtLinkInfo->bPanExist &&\r
669                                 pBtLinkInfo->bA2dpExist )\r
670                         {\r
671                                 if(bBtHsOn)\r
672                                 {\r
673                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP + PAN(HS)\n"));\r
674                                         algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS;\r
675                                 }\r
676                                 else\r
677                                 {\r
678                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP + PAN(EDR)\n"));\r
679                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP;\r
680                                 }\r
681                         }\r
682                 }\r
683         }\r
684         else if(numOfDiffProfile == 3)\r
685         {\r
686                 if(pBtLinkInfo->bScoExist)\r
687                 {\r
688                         if( pBtLinkInfo->bHidExist &&\r
689                                 pBtLinkInfo->bA2dpExist )\r
690                         {\r
691                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"));\r
692                                 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;\r
693                         }\r
694                         else if( pBtLinkInfo->bHidExist &&\r
695                                 pBtLinkInfo->bPanExist )\r
696                         {\r
697                                 if(bBtHsOn)\r
698                                 {\r
699                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"));\r
700                                         algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;\r
701                                 }\r
702                                 else\r
703                                 {\r
704                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"));\r
705                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;\r
706                                 }\r
707                         }\r
708                         else if( pBtLinkInfo->bPanExist &&\r
709                                 pBtLinkInfo->bA2dpExist )\r
710                         {\r
711                                 if(bBtHsOn)\r
712                                 {\r
713                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"));\r
714                                         algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;\r
715                                 }\r
716                                 else\r
717                                 {\r
718                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"));\r
719                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;\r
720                                 }\r
721                         }\r
722                 }\r
723                 else\r
724                 {\r
725                         if( pBtLinkInfo->bHidExist &&\r
726                                 pBtLinkInfo->bPanExist &&\r
727                                 pBtLinkInfo->bA2dpExist )\r
728                         {\r
729                                 if(bBtHsOn)\r
730                                 {\r
731                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"));\r
732                                         algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;\r
733                                 }\r
734                                 else\r
735                                 {\r
736                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"));\r
737                                         algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
738                                 }\r
739                         }\r
740                 }\r
741         }\r
742         else if(numOfDiffProfile >= 3)\r
743         {\r
744                 if(pBtLinkInfo->bScoExist)\r
745                 {\r
746                         if( pBtLinkInfo->bHidExist &&\r
747                                 pBtLinkInfo->bPanExist &&\r
748                                 pBtLinkInfo->bA2dpExist )\r
749                         {\r
750                                 if(bBtHsOn)\r
751                                 {\r
752                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"));\r
753 \r
754                                 }\r
755                                 else\r
756                                 {\r
757                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
758                                         algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;\r
759                                 }\r
760                         }\r
761                 }\r
762         }\r
763 \r
764         return algorithm;\r
765 }\r
766 \r
767 VOID\r
768 halbtc8723b1ant_SetBtAutoReport(\r
769         IN      PBTC_COEXIST            pBtCoexist,\r
770         IN      BOOLEAN                 bEnableAutoReport\r
771         )\r
772 {\r
773         u1Byte                  H2C_Parameter[1] ={0};\r
774         \r
775         H2C_Parameter[0] = 0;\r
776 \r
777         if(bEnableAutoReport)\r
778         {\r
779                 H2C_Parameter[0] |= BIT0;\r
780         }\r
781 \r
782         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n", \r
783                 (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));\r
784 \r
785         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);    \r
786 }\r
787 \r
788 VOID\r
789 halbtc8723b1ant_BtAutoReport(\r
790         IN      PBTC_COEXIST            pBtCoexist,\r
791         IN      BOOLEAN                 bForceExec,\r
792         IN      BOOLEAN                 bEnableAutoReport\r
793         )\r
794 {\r
795         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s BT Auto report = %s\n",  \r
796                 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));\r
797         pCoexDm->bCurBtAutoReport = bEnableAutoReport;\r
798 \r
799         if(!bForceExec)\r
800         {\r
801                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreBtAutoReport=%d, bCurBtAutoReport=%d\n", \r
802                         pCoexDm->bPreBtAutoReport, pCoexDm->bCurBtAutoReport));\r
803 \r
804                 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport) \r
805                         return;\r
806         }\r
807         halbtc8723b1ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);\r
808 \r
809         pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;\r
810 }\r
811 \r
812 VOID\r
813 halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(\r
814         IN      PBTC_COEXIST            pBtCoexist,\r
815         IN      BOOLEAN                 bLowPenaltyRa\r
816         )\r
817 {\r
818         u1Byte                  H2C_Parameter[6] ={0};\r
819         \r
820         H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty\r
821 \r
822         if(bLowPenaltyRa)\r
823         {\r
824                 H2C_Parameter[1] |= BIT0;\r
825                 H2C_Parameter[2] = 0x00;  //normal rate except MCS7/6/5, OFDM54/48/36\r
826                 H2C_Parameter[3] = 0xf7;  //MCS7 or OFDM54\r
827                 H2C_Parameter[4] = 0xf8;  //MCS6 or OFDM48\r
828                 H2C_Parameter[5] = 0xf9;        //MCS5 or OFDM36        \r
829         }\r
830 \r
831         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set WiFi Low-Penalty Retry: %s", \r
832                 (bLowPenaltyRa? "ON!!":"OFF!!") ));\r
833 \r
834         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);\r
835 }\r
836 \r
837 VOID\r
838 halbtc8723b1ant_LowPenaltyRa(\r
839         IN      PBTC_COEXIST            pBtCoexist,\r
840         IN      BOOLEAN                 bForceExec,\r
841         IN      BOOLEAN                 bLowPenaltyRa\r
842         )\r
843 {\r
844         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
845 \r
846         if(!bForceExec)\r
847         {\r
848                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
849                         return;\r
850         }\r
851         halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
852 \r
853         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
854 }\r
855 \r
856 VOID\r
857 halbtc8723b1ant_SetCoexTable(\r
858         IN      PBTC_COEXIST    pBtCoexist,\r
859         IN      u4Byte          val0x6c0,\r
860         IN      u4Byte          val0x6c4,\r
861         IN      u4Byte          val0x6c8,\r
862         IN      u1Byte          val0x6cc\r
863         )\r
864 {\r
865         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
866         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
867 \r
868         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));\r
869         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);\r
870 \r
871         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
872         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
873 \r
874         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
875         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
876 }\r
877 \r
878 VOID\r
879 halbtc8723b1ant_CoexTable(\r
880         IN      PBTC_COEXIST            pBtCoexist,\r
881         IN      BOOLEAN                 bForceExec,\r
882         IN      u4Byte                  val0x6c0,\r
883         IN      u4Byte                  val0x6c4,\r
884         IN      u4Byte                  val0x6c8,\r
885         IN      u1Byte                  val0x6cc\r
886         )\r
887 {\r
888         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6cc=0x%x\n", \r
889                 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6cc));\r
890         pCoexDm->curVal0x6c0 = val0x6c0;\r
891         pCoexDm->curVal0x6c4 = val0x6c4;\r
892         pCoexDm->curVal0x6c8 = val0x6c8;\r
893         pCoexDm->curVal0x6cc = val0x6cc;\r
894 \r
895         if(!bForceExec)\r
896         {\r
897                 //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], preVal0x6c0=0x%x, preVal0x6c4=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n", \r
898                 //      pCoexDm->preVal0x6c0, pCoexDm->preVal0x6c4, pCoexDm->preVal0x6c8, pCoexDm->preVal0x6cc));\r
899                 //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], curVal0x6c0=0x%x, curVal0x6c4=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n", \r
900                 //      pCoexDm->curVal0x6c0, pCoexDm->curVal0x6c4, pCoexDm->curVal0x6c8, pCoexDm->curVal0x6cc));\r
901         \r
902                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
903                         (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&\r
904                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
905                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
906                         return;\r
907         }\r
908         halbtc8723b1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);\r
909 \r
910         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
911         pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;\r
912         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
913         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
914 }\r
915 \r
916 VOID\r
917 halbtc8723b1ant_CoexTableWithType(\r
918         IN      PBTC_COEXIST            pBtCoexist,\r
919         IN      BOOLEAN                         bForceExec,\r
920         IN      u1Byte                          type\r
921         )\r
922 {\r
923 \r
924         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], ********** CoexTable(%d) **********\n", \r
925                                 type));\r
926         \r
927         switch(type)\r
928         {\r
929                 case 0:\r
930                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3);\r
931                         break;\r
932                 case 1:\r
933                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);\r
934                         break;\r
935                 case 2:\r
936                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);\r
937                         break;\r
938                 case 3:\r
939                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaaaaaa, 0xffffff, 0x3);\r
940                         break;\r
941                 case 4:\r
942                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);\r
943                         break;\r
944                 case 5:\r
945                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3);\r
946                         break;\r
947                 case 6:\r
948                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);\r
949                         break;\r
950                 case 7:\r
951                         halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);\r
952                         break;\r
953                 default:\r
954                         break;\r
955         }\r
956 }\r
957 \r
958 VOID\r
959 halbtc8723b1ant_SetFwIgnoreWlanAct(\r
960         IN      PBTC_COEXIST            pBtCoexist,\r
961         IN      BOOLEAN                 bEnable\r
962         )\r
963 {\r
964         u1Byte                  H2C_Parameter[1] ={0};\r
965                 \r
966         if(bEnable)\r
967         {\r
968                 H2C_Parameter[0] |= BIT0;               // function enable\r
969         }\r
970         \r
971         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", \r
972                 H2C_Parameter[0]));\r
973 \r
974         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);\r
975 }\r
976 \r
977 VOID\r
978 halbtc8723b1ant_IgnoreWlanAct(\r
979         IN      PBTC_COEXIST            pBtCoexist,\r
980         IN      BOOLEAN                 bForceExec,\r
981         IN      BOOLEAN                 bEnable\r
982         )\r
983 {\r
984         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
985                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
986         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
987 \r
988         if(!bForceExec)\r
989         {\r
990                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", \r
991                         pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));\r
992 \r
993                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
994                         return;\r
995         }\r
996         halbtc8723b1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
997 \r
998         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
999 }\r
1000 \r
1001 VOID\r
1002 halbtc8723b1ant_SetFwPstdma(\r
1003         IN      PBTC_COEXIST            pBtCoexist,\r
1004         IN      u1Byte                  byte1,\r
1005         IN      u1Byte                  byte2,\r
1006         IN      u1Byte                  byte3,\r
1007         IN      u1Byte                  byte4,\r
1008         IN      u1Byte                  byte5\r
1009         )\r
1010 {\r
1011         u1Byte                  H2C_Parameter[5] ={0};\r
1012         u1Byte                  realByte1=byte1, realByte5=byte5;\r
1013         BOOLEAN                 bApEnable=FALSE;\r
1014 \r
1015         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
1016 \r
1017         if(bApEnable)\r
1018         {\r
1019                 if(byte1&BIT4 && !(byte1&BIT5))\r
1020                 {                       \r
1021                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], FW for 1Ant AP mode\n"));\r
1022                         realByte1 &= ~BIT4;\r
1023                         realByte1 |= BIT5;\r
1024 \r
1025                         realByte5 |= BIT5;\r
1026                         realByte5 &= ~BIT6;\r
1027                 }\r
1028         }\r
1029 \r
1030         H2C_Parameter[0] = realByte1;   \r
1031         H2C_Parameter[1] = byte2;       \r
1032         H2C_Parameter[2] = byte3;\r
1033         H2C_Parameter[3] = byte4;\r
1034         H2C_Parameter[4] = realByte5;\r
1035 \r
1036         pCoexDm->psTdmaPara[0] = realByte1;\r
1037         pCoexDm->psTdmaPara[1] = byte2;\r
1038         pCoexDm->psTdmaPara[2] = byte3;\r
1039         pCoexDm->psTdmaPara[3] = byte4;\r
1040         pCoexDm->psTdmaPara[4] = realByte5;\r
1041         \r
1042         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n", \r
1043                 H2C_Parameter[0], \r
1044                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
1045 \r
1046         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);\r
1047 }\r
1048 \r
1049 VOID\r
1050 halbtc8723b1ant_SetLpsRpwm(\r
1051         IN      PBTC_COEXIST            pBtCoexist,\r
1052         IN      u1Byte                  lpsVal,\r
1053         IN      u1Byte                  rpwmVal\r
1054         )\r
1055 {\r
1056         u1Byte  lps=lpsVal;\r
1057         u1Byte  rpwm=rpwmVal;\r
1058         \r
1059         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);\r
1060         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);\r
1061 }\r
1062 \r
1063 VOID\r
1064 halbtc8723b1ant_LpsRpwm(\r
1065         IN      PBTC_COEXIST            pBtCoexist,\r
1066         IN      BOOLEAN                 bForceExec,\r
1067         IN      u1Byte                  lpsVal,\r
1068         IN      u1Byte                  rpwmVal\r
1069         )\r
1070 {\r
1071         BOOLEAN bForceExecPwrCmd=FALSE;\r
1072         \r
1073         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n", \r
1074                 (bForceExec? "force to":""), lpsVal, rpwmVal));\r
1075         pCoexDm->curLps = lpsVal;\r
1076         pCoexDm->curRpwm = rpwmVal;\r
1077 \r
1078         if(!bForceExec)\r
1079         {\r
1080                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], LPS-RxBeaconMode=0x%x , LPS-RPWM=0x%x!!\n", \r
1081                          pCoexDm->curLps, pCoexDm->curRpwm));\r
1082 \r
1083                 if( (pCoexDm->preLps == pCoexDm->curLps) &&\r
1084                         (pCoexDm->preRpwm == pCoexDm->curRpwm) )\r
1085                 {\r
1086                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], LPS-RPWM_Last=0x%x , LPS-RPWM_Now=0x%x!!\n", \r
1087                                  pCoexDm->preRpwm, pCoexDm->curRpwm));\r
1088 \r
1089                         return;\r
1090                 }\r
1091         }\r
1092         halbtc8723b1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);\r
1093 \r
1094         pCoexDm->preLps = pCoexDm->curLps;\r
1095         pCoexDm->preRpwm = pCoexDm->curRpwm;\r
1096 }\r
1097 \r
1098 VOID\r
1099 halbtc8723b1ant_SwMechanism(\r
1100         IN      PBTC_COEXIST    pBtCoexist,     \r
1101         IN      BOOLEAN                 bLowPenaltyRA\r
1102         ) \r
1103 {\r
1104         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], SM[LpRA] = %d\n", \r
1105                 bLowPenaltyRA));\r
1106 \r
1107         halbtc8723b1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);\r
1108 }\r
1109 \r
1110 VOID\r
1111 halbtc8723b1ant_SetAntPath(\r
1112         IN      PBTC_COEXIST            pBtCoexist,\r
1113         IN      u1Byte                          antPosType,\r
1114         IN      BOOLEAN                         bInitHwCfg,\r
1115         IN      BOOLEAN                         bWifiOff\r
1116         )\r
1117 {\r
1118         PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;\r
1119         u4Byte                  fwVer=0, u4Tmp=0;\r
1120         BOOLEAN                 bPgExtSwitch=FALSE;\r
1121         BOOLEAN                 bUseExtSwitch=FALSE;\r
1122         u1Byte                  H2C_Parameter[2] ={0};\r
1123         PADAPTER padapter=pBtCoexist->Adapter;\r
1124         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch);\r
1125         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);        // [31:16]=fw ver, [15:0]=fw sub ver\r
1126 \r
1127 \r
1128         if((fwVer<0xc0000) || bPgExtSwitch)\r
1129                 bUseExtSwitch = TRUE;\r
1130 \r
1131         if(bInitHwCfg)\r
1132         {\r
1133                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); //BT select s0/s1 is controlled by WiFi\r
1134                 \r
1135                 //Force GNT_BT to Normal\r
1136                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x765, 0x18, 0x0); \r
1137 \r
1138                 //set wlan_act control by PTA\r
1139                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); \r
1140 \r
1141                 //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4); \r
1142         }\r
1143         else if(bWifiOff)\r
1144         {\r
1145         //Force GNT_BT to High\r
1146                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x765, 0x18, 0x3);\r
1147                 \r
1148                 //set wlan_act to always low\r
1149                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
1150                 \r
1151                 if(padapter->registrypriv.mp_mode ==0)  \r
1152                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); //BT select s0/s1 is controlled by BT\r
1153                 else\r
1154                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); //BT select s0/s1 is controlled by WiFi\r
1155         \r
1156                 // 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL   BT Vendor 0xac=0xf002\r
1157                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1158                 u4Tmp &= ~BIT23;\r
1159                 u4Tmp &= ~BIT24;\r
1160                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1161         }\r
1162         \r
1163         if(bUseExtSwitch)\r
1164         {\r
1165                 if(bInitHwCfg)\r
1166                 {\r
1167                         // 0x4c[23]=0, 0x4c[24]=1  Antenna control by WL/BT\r
1168                         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1169                         u4Tmp &=~BIT23;\r
1170                         u4Tmp |= BIT24;\r
1171                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1172 \r
1173                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1174                         {\r
1175                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x1); //Main Ant to  BT for IPS case 0x4c[23]=1\r
1176         \r
1177                                 //tell firmware "no antenna inverse"\r
1178                                 H2C_Parameter[0] = 0;\r
1179                                 H2C_Parameter[1] = 1;  //ext switch type\r
1180                                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);    \r
1181                         }\r
1182                         else\r
1183                         {\r
1184                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); //Aux Ant to  BT for IPS case 0x4c[23]=1\r
1185                 \r
1186                                 //tell firmware "antenna inverse"\r
1187                                 H2C_Parameter[0] = 1;\r
1188                                 H2C_Parameter[1] = 1;  //ext switch type\r
1189                                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);    \r
1190                         }\r
1191                 }\r
1192                 \r
1193                 // fixed internal switch first\r
1194                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1195                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); // fixed internal switch S1->WiFi, S0->BT\r
1196                 else\r
1197                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280); // fixed internal switch S0->WiFi, S1->BT\r
1198 \r
1199                 // ext switch setting\r
1200                 switch(antPosType)\r
1201                 {\r
1202                         case BTC_ANT_PATH_WIFI:\r
1203                                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1204                                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);\r
1205                                 else\r
1206                                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);\r
1207                                 break;\r
1208                         case BTC_ANT_PATH_BT:\r
1209                                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1210                                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);\r
1211                                 else                                    \r
1212                                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);\r
1213                                 break;\r
1214                         default:\r
1215                         case BTC_ANT_PATH_PTA:\r
1216                                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1217                                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);\r
1218                                 else\r
1219                                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);\r
1220                                 break;\r
1221                 }\r
1222         \r
1223         }\r
1224         else\r
1225         {\r
1226                 if(bInitHwCfg)\r
1227                 {\r
1228                         // 0x4c[23]=1, 0x4c[24]=0  Antenna control by 0x64\r
1229                         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1230                         u4Tmp |= BIT23;\r
1231                         u4Tmp &=~BIT24;       \r
1232                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1233 \r
1234                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1235                         {\r
1236                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); //Main Ant to  WiFi for IPS case 0x4c[23]=1\r
1237         \r
1238                                 //tell firmware "no antenna inverse"\r
1239                                 H2C_Parameter[0] = 0;\r
1240                                 H2C_Parameter[1] = 0;  //internal switch type\r
1241                                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);    \r
1242                         }\r
1243                         else\r
1244                         {\r
1245                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x1); //Aux Ant to  BT for IPS case 0x4c[23]=1\r
1246                 \r
1247                                 //tell firmware "antenna inverse"\r
1248                                 H2C_Parameter[0] = 1;\r
1249                                 H2C_Parameter[1] = 0;  //internal switch type\r
1250                                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);    \r
1251                         }\r
1252                 }\r
1253         \r
1254                 // fixed external switch first\r
1255                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1256                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1); //Main->WiFi, Aux->BT\r
1257                 else\r
1258                         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2); //Main->BT, Aux->WiFi\r
1259 \r
1260                 // internal switch setting\r
1261                 switch(antPosType)\r
1262                 {\r
1263                         case BTC_ANT_PATH_WIFI:\r
1264                                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1265                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);\r
1266                                 else\r
1267                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);\r
1268                                 break;\r
1269                         case BTC_ANT_PATH_BT:\r
1270                                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1271                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);\r
1272                                 else\r
1273                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);\r
1274                                 break;\r
1275                         default:\r
1276                         case BTC_ANT_PATH_PTA:\r
1277                                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1278                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x200);                                   \r
1279                                 else\r
1280                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x80);\r
1281                                 break;\r
1282                 }\r
1283         }\r
1284 }\r
1285 \r
1286 VOID\r
1287 halbtc8723b1ant_PsTdma(\r
1288         IN      PBTC_COEXIST            pBtCoexist,\r
1289         IN      BOOLEAN                 bForceExec,\r
1290         IN      BOOLEAN                 bTurnOn,\r
1291         IN      u1Byte                  type\r
1292         )\r
1293 {\r
1294         PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;\r
1295         BOOLEAN                 bTurnOnByCnt=FALSE, bWifiBusy=FALSE;\r
1296         u1Byte                  psTdmaTypeByCnt=0, rssiAdjustVal=0;\r
1297         //u4Byte                        fwVer=0;\r
1298 \r
1299         //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
1300         //      (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));\r
1301         pCoexDm->bCurPsTdmaOn = bTurnOn;\r
1302         pCoexDm->curPsTdma = type;\r
1303 \r
1304         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);      \r
1305 \r
1306         if (pCoexDm->bCurPsTdmaOn)\r
1307         {\r
1308                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], ********** TDMA(on, %d) **********\n", \r
1309                                 pCoexDm->curPsTdma));\r
1310         }\r
1311         else\r
1312         {\r
1313                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], ********** TDMA(off, %d) **********\n", \r
1314                                 pCoexDm->curPsTdma));\r
1315         }\r
1316                         \r
1317         if(!bForceExec)\r
1318         {       \r
1319                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
1320                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
1321                         return;\r
1322         }\r
1323         if(bTurnOn)\r
1324         {\r
1325                 switch(type)\r
1326                 {\r
1327                         default:\r
1328                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, 0x50);\r
1329                                 break;\r
1330                         case 1:\r
1331                                 //if(bWifiBusy)\r
1332                                         halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x3a, 0x03, 0x10, 0x50);\r
1333                                 //else\r
1334                                 //      halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x3a, 0x03, 0x10, 0x51);\r
1335                                 \r
1336                                 rssiAdjustVal = 11;\r
1337                                 break;\r
1338                         case 2:\r
1339                                 //if(bWifiBusy)\r
1340                                         halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x2b, 0x03, 0x10, 0x50);\r
1341                                 //else\r
1342                                 //      halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x2b, 0x03, 0x10, 0x51);\r
1343                                 rssiAdjustVal = 14;\r
1344                                 break;\r
1345                         case 3:\r
1346                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, 0x52);\r
1347                                 break;\r
1348                         case 4:\r
1349                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);\r
1350                                 rssiAdjustVal = 17;\r
1351                                 break;\r
1352                         case 5:\r
1353                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x15, 0x3, 0x11, 0x10);\r
1354                                 break;\r
1355                         case 6:\r
1356                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x20, 0x3, 0x11, 0x13);\r
1357                                 break;\r
1358                         case 7:\r
1359                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);\r
1360                                 break;\r
1361                         case 8: \r
1362                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
1363                                 break;\r
1364                         case 9: \r
1365                                 //if(bWifiBusy)\r
1366                                         halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x21, 0x3, 0x10, 0x50);\r
1367                                 //else\r
1368                                 //      halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x21, 0x3, 0x10, 0x50);\r
1369                                 rssiAdjustVal = 18;\r
1370                                 break;\r
1371                         case 10:        \r
1372                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);\r
1373                                 break;\r
1374                         case 11:        \r
1375                                 //if(bWifiBusy)\r
1376                                         halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x15, 0x03, 0x10, 0x50);\r
1377                                 //else\r
1378                                 //      halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x15, 0x03, 0x10, 0x50);\r
1379                                 rssiAdjustVal = 20;\r
1380                                 break;\r
1381                         case 12:\r
1382                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50);\r
1383                                 break;\r
1384                         case 13:\r
1385                                 //halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x15, 0x15, 0x0, 0x50);\r
1386                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x12, 0x12, 0x0, 0x50);\r
1387                                 break;\r
1388                         case 14:\r
1389                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x21, 0x3, 0x10, 0x52);\r
1390                                 break;\r
1391                         case 15:\r
1392                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);\r
1393                                 break;\r
1394                         case 16:\r
1395                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);\r
1396                                 rssiAdjustVal = 18;\r
1397                                 break;\r
1398                         case 18:\r
1399                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
1400                                 rssiAdjustVal = 14;\r
1401                                 break;                  \r
1402                         case 20:\r
1403                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x35, 0x03, 0x11, 0x10);\r
1404                                 break;\r
1405                         case 21:\r
1406                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11);\r
1407                                 break;\r
1408                         case 22:\r
1409                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x10);\r
1410                                 break;\r
1411                         case 23:\r
1412                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);\r
1413                                 rssiAdjustVal = 22;\r
1414                                 break;\r
1415                         case 24:\r
1416                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);\r
1417                                 rssiAdjustVal = 22;\r
1418                                 break;\r
1419                         case 25:\r
1420                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
1421                                 rssiAdjustVal = 22;\r
1422                                 break;\r
1423                         case 26:\r
1424                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
1425                                 rssiAdjustVal = 22;\r
1426                                 break;\r
1427                         case 27:\r
1428                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);\r
1429                                 rssiAdjustVal = 22;\r
1430                                 break;\r
1431                         case 28:\r
1432                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);\r
1433                                 break;\r
1434                         case 29:\r
1435                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);\r
1436                                 break;\r
1437                         case 30:\r
1438                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10);\r
1439                                 break;\r
1440                         case 31:\r
1441                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);\r
1442                                 break;\r
1443                         case 32:\r
1444                                 //halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0xa, 0x3, 0x10, 0x0);\r
1445                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x35, 0x3, 0x11, 0x11);\r
1446                                 break;\r
1447                         case 33:\r
1448                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90);\r
1449                                 break;\r
1450                         case 34:\r
1451                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10);\r
1452                                 break;\r
1453                         case 35:\r
1454                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10);\r
1455                                 break;\r
1456                         case 36:\r
1457                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);\r
1458                                 break;\r
1459                         case 40: // SoftAP only with no sta associated,BT disable ,TDMA mode for power saving\r
1460                                 /* here softap mode screen off will cost 70-80mA for phone */\r
1461                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24);\r
1462                                 break;  \r
1463                 }\r
1464         }\r
1465         else\r
1466         {               \r
1467                 //pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);      // [31:16]=fw ver, [15:0]=fw sub ver\r
1468 \r
1469                 // disable PS tdma\r
1470                 switch(type)\r
1471                 {\r
1472                         case 8: //PTA Control\r
1473                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);\r
1474                                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FALSE, FALSE);\r
1475                                 break;\r
1476                         case 0:\r
1477                         default:  //Software control, Antenna at BT side\r
1478                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1479                                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
1480                                 break;\r
1481                         case 9:   //Software control, Antenna at WiFi side\r
1482                                 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1483                                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FALSE, FALSE);\r
1484                                 break;                  \r
1485                 }\r
1486         }\r
1487         rssiAdjustVal =0;\r
1488         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);\r
1489 \r
1490         // update pre state\r
1491         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1492         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1493 }\r
1494 \r
1495 VOID\r
1496 halbtc8723b1ant_CoexAllOff(\r
1497         IN      PBTC_COEXIST            pBtCoexist\r
1498         )\r
1499 {\r
1500         // sw all off\r
1501         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1502 \r
1503         // hw all off\r
1504         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1505 }\r
1506 \r
1507 BOOLEAN\r
1508 halbtc8723b1ant_IsCommonAction(\r
1509         IN      PBTC_COEXIST            pBtCoexist\r
1510         )\r
1511 {\r
1512         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;\r
1513 \r
1514         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1515         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1516 \r
1517         if(!bWifiConnected && \r
1518                 BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
1519         {\r
1520                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));\r
1521                 \r
1522                 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1523 \r
1524                 bCommon = TRUE;\r
1525         }\r
1526         else if(bWifiConnected && \r
1527                 (BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1528         {\r
1529                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));\r
1530 \r
1531                 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1532 \r
1533                 bCommon = TRUE;\r
1534         }\r
1535         else if(!bWifiConnected && \r
1536                 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1537         {\r
1538                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));\r
1539 \r
1540                 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1541 \r
1542                 bCommon = TRUE;\r
1543         }\r
1544         else if(bWifiConnected && \r
1545                 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1546         {\r
1547                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));\r
1548 \r
1549                 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1550 \r
1551                 bCommon = TRUE;\r
1552         }\r
1553         else if(!bWifiConnected && \r
1554                 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus) )\r
1555         {\r
1556                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));\r
1557 \r
1558                 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1559                 \r
1560                 bCommon = TRUE;\r
1561         }\r
1562         else\r
1563         {\r
1564                 if (bWifiBusy)                  \r
1565                 {\r
1566                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));\r
1567                 }\r
1568                 else\r
1569                 {\r
1570                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));\r
1571                 }\r
1572                 \r
1573                 bCommon = FALSE;\r
1574         }\r
1575         \r
1576         return bCommon;\r
1577 }\r
1578 \r
1579 \r
1580 VOID\r
1581 halbtc8723b1ant_TdmaDurationAdjustForAcl(\r
1582         IN      PBTC_COEXIST            pBtCoexist,\r
1583         IN      u1Byte                          wifiStatus\r
1584         )\r
1585 {\r
1586         static s4Byte           up,dn,m,n,WaitCount;\r
1587         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
1588         u1Byte                  retryCount=0, btInfoExt;\r
1589         static BOOLEAN  bPreWifiBusy=FALSE;\r
1590         BOOLEAN                 bWifiBusy = FALSE;\r
1591 \r
1592         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));\r
1593 \r
1594         if(BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifiStatus) \r
1595                 bWifiBusy = TRUE;\r
1596         else\r
1597                 bWifiBusy = FALSE;              \r
1598 \r
1599         if( (BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||\r
1600                 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||\r
1601                 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )\r
1602         {\r
1603                 if( pCoexDm->curPsTdma != 1 &&\r
1604                         pCoexDm->curPsTdma != 2 &&\r
1605                         pCoexDm->curPsTdma != 3 &&\r
1606                         pCoexDm->curPsTdma != 9 )\r
1607                 {\r
1608                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1609                         pCoexDm->psTdmaDuAdjType = 9;\r
1610 \r
1611                         up = 0;\r
1612                         dn = 0;\r
1613                         m = 1;\r
1614                         n= 3;\r
1615                         result = 0;\r
1616                         WaitCount = 0;\r
1617                 }               \r
1618                 return;\r
1619         }\r
1620 \r
1621         if(!pCoexDm->bAutoTdmaAdjust)\r
1622         {\r
1623                 pCoexDm->bAutoTdmaAdjust = TRUE;\r
1624                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
1625 \r
1626                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1627                 pCoexDm->psTdmaDuAdjType = 2;\r
1628                 //============\r
1629                 up = 0;\r
1630                 dn = 0;\r
1631                 m = 1;\r
1632                 n= 3;\r
1633                 result = 0;\r
1634                 WaitCount = 0;\r
1635         }\r
1636         else\r
1637         {\r
1638                 //accquire the BT TRx retry count from BT_Info byte2\r
1639                 retryCount = pCoexSta->btRetryCnt;\r
1640                 btInfoExt = pCoexSta->btInfoExt;\r
1641                 //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));\r
1642                 //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
1643                 //      up, dn, m, n, WaitCount));\r
1644                 result = 0;\r
1645                 WaitCount++; \r
1646                   \r
1647                 if(retryCount == 0)  // no retry in the last 2-second duration\r
1648                 {\r
1649                         up++;\r
1650                         dn--;\r
1651 \r
1652                         if (dn <= 0)\r
1653                                 dn = 0;                          \r
1654 \r
1655                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
1656                         {\r
1657                                 WaitCount = 0; \r
1658                                 n = 3;\r
1659                                 up = 0;\r
1660                                 dn = 0;\r
1661                                 result = 1; \r
1662                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));\r
1663                         }\r
1664                 }\r
1665                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
1666                 {\r
1667                         up--; \r
1668                         dn++;\r
1669 \r
1670                         if (up <= 0)\r
1671                                 up = 0;\r
1672 \r
1673                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
1674                         {\r
1675                                 if (WaitCount <= 2)\r
1676                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1677                                 else\r
1678                                         m = 1;\r
1679 \r
1680                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1681                                         m = 20;\r
1682 \r
1683                                 n = 3*m;\r
1684                                 up = 0;\r
1685                                 dn = 0;\r
1686                                 WaitCount = 0;\r
1687                                 result = -1; \r
1688                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
1689                         }\r
1690                 }\r
1691                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
1692                 {\r
1693                         if (WaitCount == 1)\r
1694                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1695                         else\r
1696                                 m = 1;\r
1697 \r
1698                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1699                                 m = 20;\r
1700 \r
1701                         n = 3*m;\r
1702                         up = 0;\r
1703                         dn = 0;\r
1704                         WaitCount = 0; \r
1705                         result = -1;\r
1706                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
1707                 }\r
1708 \r
1709                 if(result == -1)\r
1710                 {\r
1711                         if( (BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
1712                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
1713                         {\r
1714                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1715                                 pCoexDm->psTdmaDuAdjType = 9;\r
1716                         }\r
1717                         else if(pCoexDm->curPsTdma == 1)\r
1718                         {\r
1719                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1720                                 pCoexDm->psTdmaDuAdjType = 2;\r
1721                         }\r
1722                         else if(pCoexDm->curPsTdma == 2)\r
1723                         {\r
1724                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1725                                 pCoexDm->psTdmaDuAdjType = 9;\r
1726                         }\r
1727                         else if(pCoexDm->curPsTdma == 9)\r
1728                         {\r
1729                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1730                                 pCoexDm->psTdmaDuAdjType = 11;\r
1731                         }\r
1732                 }\r
1733                 else if(result == 1)\r
1734                 {\r
1735                         if( (BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
1736                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
1737                         {\r
1738                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1739                                 pCoexDm->psTdmaDuAdjType = 9;\r
1740                         }\r
1741                         else if(pCoexDm->curPsTdma == 11)\r
1742                         {\r
1743                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1744                                 pCoexDm->psTdmaDuAdjType = 9;\r
1745                         }\r
1746                         else if(pCoexDm->curPsTdma == 9)\r
1747                         {\r
1748                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1749                                 pCoexDm->psTdmaDuAdjType = 2;\r
1750                         }\r
1751                         else if(pCoexDm->curPsTdma == 2)\r
1752                         {\r
1753                                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1754                                 pCoexDm->psTdmaDuAdjType = 1;\r
1755                         }\r
1756                 }\r
1757                 else      //no change\r
1758                 {\r
1759                         /* Bryant Modify        \r
1760                         if(bWifiBusy != bPreWifiBusy)  //if busy / idle change\r
1761                         {\r
1762                                 bPreWifiBusy = bWifiBusy;\r
1763                                 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, pCoexDm->curPsTdma);\r
1764                         }\r
1765                         */\r
1766                 \r
1767                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], ********** TDMA(on, %d) **********\n", \r
1768                                 pCoexDm->curPsTdma));\r
1769                 }\r
1770 \r
1771                 if( pCoexDm->curPsTdma != 1 &&\r
1772                         pCoexDm->curPsTdma != 2 &&\r
1773                         pCoexDm->curPsTdma != 9 &&\r
1774                         pCoexDm->curPsTdma != 11 )\r
1775                 {\r
1776                         // recover to previous adjust type\r
1777                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
1778                 }\r
1779         }\r
1780 }\r
1781 \r
1782 VOID\r
1783 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(\r
1784         IN      PBTC_COEXIST            pBtCoexist,\r
1785         IN      BOOLEAN                 bNewPsState\r
1786         )\r
1787 {\r
1788         u1Byte  lpsMode=0x0;\r
1789 \r
1790         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);\r
1791         \r
1792         if(lpsMode)     // already under LPS state\r
1793         {\r
1794                 if(bNewPsState)         \r
1795                 {\r
1796                         // keep state under LPS, do nothing.\r
1797                 }\r
1798                 else\r
1799                 {\r
1800                         // will leave LPS state, turn off psTdma first\r
1801                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1802                 }\r
1803         }\r
1804         else                                            // NO PS state\r
1805         {\r
1806                 if(bNewPsState)\r
1807                 {\r
1808                         // will enter LPS state, turn off psTdma first\r
1809                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1810                 }\r
1811                 else\r
1812                 {\r
1813                         // keep state under NO PS state, do nothing.\r
1814                 }\r
1815         }\r
1816 }\r
1817 \r
1818 VOID\r
1819 halbtc8723b1ant_PowerSaveState(\r
1820         IN      PBTC_COEXIST            pBtCoexist,\r
1821         IN      u1Byte                          psType,\r
1822         IN      u1Byte                          lpsVal,\r
1823         IN      u1Byte                          rpwmVal\r
1824         )\r
1825 {\r
1826         BOOLEAN         bLowPwrDisable=FALSE;\r
1827         \r
1828         switch(psType)\r
1829         {\r
1830                 case BTC_PS_WIFI_NATIVE:\r
1831                         // recover to original 32k low power setting\r
1832                         bLowPwrDisable = FALSE;\r
1833                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1834                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1835                         break;\r
1836                 case BTC_PS_LPS_ON:\r
1837                         halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);\r
1838                         halbtc8723b1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);                      \r
1839                         // when coex force to enter LPS, do not enter 32k low power.\r
1840                         bLowPwrDisable = TRUE;\r
1841                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1842                         // power save must executed before psTdma.                      \r
1843                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);\r
1844                         break;\r
1845                 case BTC_PS_LPS_OFF:\r
1846                         halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);\r
1847                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
1848                         break;\r
1849                 default:\r
1850                         break;\r
1851         }\r
1852 }\r
1853 \r
1854 VOID\r
1855 halbtc8723b1ant_ActionWifiOnly(\r
1856         IN      PBTC_COEXIST            pBtCoexist\r
1857         )\r
1858 {\r
1859         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1860         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
1861 }\r
1862 \r
1863 VOID\r
1864 halbtc8723b1ant_MonitorBtEnableDisable(\r
1865         IN      PBTC_COEXIST            pBtCoexist\r
1866         )\r
1867 {\r
1868         static BOOLEAN  bPreBtDisabled=FALSE;\r
1869         static u4Byte           btDisableCnt=0;\r
1870         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
1871 \r
1872         // This function check if bt is disabled\r
1873 \r
1874         if(     pCoexSta->highPriorityTx == 0 &&\r
1875                 pCoexSta->highPriorityRx == 0 &&\r
1876                 pCoexSta->lowPriorityTx == 0 &&\r
1877                 pCoexSta->lowPriorityRx == 0)\r
1878         {\r
1879                 bBtActive = FALSE;\r
1880         }\r
1881         if(     pCoexSta->highPriorityTx == 0xffff &&\r
1882                 pCoexSta->highPriorityRx == 0xffff &&\r
1883                 pCoexSta->lowPriorityTx == 0xffff &&\r
1884                 pCoexSta->lowPriorityRx == 0xffff)\r
1885         {\r
1886                 bBtActive = FALSE;\r
1887         }\r
1888         if(bBtActive)\r
1889         {\r
1890                 btDisableCnt = 0;\r
1891                 bBtDisabled = FALSE;\r
1892                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1893                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is enabled !!\n"));\r
1894         }\r
1895         else\r
1896         {\r
1897                 btDisableCnt++;\r
1898                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], bt all counters=0, %d times!!\n", \r
1899                                 btDisableCnt));\r
1900                 if(btDisableCnt >= 2)\r
1901                 {\r
1902                         bBtDisabled = TRUE;\r
1903                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1904                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is disabled !!\n"));\r
1905                         halbtc8723b1ant_ActionWifiOnly(pBtCoexist);\r
1906                 }\r
1907         }\r
1908         if(bPreBtDisabled != bBtDisabled)\r
1909         {\r
1910                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is from %s to %s!!\n", \r
1911                         (bPreBtDisabled ? "disabled":"enabled"), \r
1912                         (bBtDisabled ? "disabled":"enabled")));\r
1913                 bPreBtDisabled = bBtDisabled;\r
1914                 if(!bBtDisabled)\r
1915                 {\r
1916                 }\r
1917                 else\r
1918                 {\r
1919                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
1920                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1921                 }\r
1922         }\r
1923 }\r
1924 \r
1925 //=============================================\r
1926 //\r
1927 //      Software Coex Mechanism start\r
1928 //\r
1929 //=============================================\r
1930 \r
1931 // SCO only or SCO+PAN(HS)\r
1932 VOID\r
1933 halbtc8723b1ant_ActionSco(\r
1934         IN      PBTC_COEXIST            pBtCoexist\r
1935         )\r
1936 {\r
1937         halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
1938 }\r
1939 \r
1940 \r
1941 VOID\r
1942 halbtc8723b1ant_ActionHid(\r
1943         IN      PBTC_COEXIST            pBtCoexist\r
1944         )\r
1945 {\r
1946         halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
1947 }\r
1948 \r
1949 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
1950 VOID\r
1951 halbtc8723b1ant_ActionA2dp(\r
1952         IN      PBTC_COEXIST            pBtCoexist\r
1953         )\r
1954 {\r
1955         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1956 }\r
1957 \r
1958 VOID\r
1959 halbtc8723b1ant_ActionA2dpPanHs(\r
1960         IN      PBTC_COEXIST            pBtCoexist\r
1961         )\r
1962 {\r
1963         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1964 }\r
1965 \r
1966 VOID\r
1967 halbtc8723b1ant_ActionPanEdr(\r
1968         IN      PBTC_COEXIST            pBtCoexist\r
1969         )\r
1970 {\r
1971         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1972 }\r
1973 \r
1974 //PAN(HS) only\r
1975 VOID\r
1976 halbtc8723b1ant_ActionPanHs(\r
1977         IN      PBTC_COEXIST            pBtCoexist\r
1978         )\r
1979 {\r
1980         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1981 }\r
1982 \r
1983 //PAN(EDR)+A2DP\r
1984 VOID\r
1985 halbtc8723b1ant_ActionPanEdrA2dp(\r
1986         IN      PBTC_COEXIST            pBtCoexist\r
1987         )\r
1988 {\r
1989         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
1990 }\r
1991 \r
1992 VOID\r
1993 halbtc8723b1ant_ActionPanEdrHid(\r
1994         IN      PBTC_COEXIST            pBtCoexist\r
1995         )\r
1996 {\r
1997         halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
1998 }\r
1999 \r
2000 // HID+A2DP+PAN(EDR)\r
2001 VOID\r
2002 halbtc8723b1ant_ActionHidA2dpPanEdr(\r
2003         IN      PBTC_COEXIST            pBtCoexist\r
2004         )\r
2005 {\r
2006         halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
2007 }\r
2008 \r
2009 VOID\r
2010 halbtc8723b1ant_ActionHidA2dp(\r
2011         IN      PBTC_COEXIST            pBtCoexist\r
2012         )\r
2013 {\r
2014         halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);\r
2015 }\r
2016 \r
2017 //=============================================\r
2018 //\r
2019 //      Non-Software Coex Mechanism start\r
2020 //\r
2021 //=============================================\r
2022 VOID\r
2023 halbtc8723b1ant_ActionWifiMultiPort(\r
2024         IN      PBTC_COEXIST            pBtCoexist\r
2025         )\r
2026 {\r
2027         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2028         \r
2029         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2030         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2031 }\r
2032 \r
2033 VOID\r
2034 halbtc8723b1ant_ActionHs(\r
2035         IN      PBTC_COEXIST            pBtCoexist\r
2036         )\r
2037 {\r
2038         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2039         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2040 }\r
2041 \r
2042 VOID\r
2043 halbtc8723b1ant_ActionBtInquiry(\r
2044         IN      PBTC_COEXIST            pBtCoexist\r
2045         )\r
2046 {       \r
2047         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2048         BOOLEAN                 bWifiConnected=FALSE, bApEnable=FALSE, bWifiBusy=FALSE, bBtBusy=FALSE;\r
2049 \r
2050         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
2051         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2052         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
2053         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
2054 \r
2055 \r
2056         if ( (!bWifiConnected) && (!pCoexSta->bWiFiIsHighPriTask) )\r
2057         {\r
2058                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2059                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2060 \r
2061                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);          \r
2062         }\r
2063         else if( (pBtLinkInfo->bScoExist) ||\r
2064                         (pBtLinkInfo->bHidExist) )\r
2065         {\r
2066                 // SCO/HID-only busy\r
2067                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2068                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2069                 \r
2070                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);          \r
2071         }\r
2072         else if ( (pBtLinkInfo->bA2dpExist) ||  (pBtLinkInfo->bPanExist) ||  (bWifiBusy) )\r
2073         {\r
2074                 \r
2075                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
2076                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);              \r
2077                 \r
2078                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2079         }\r
2080         else\r
2081         {\r
2082                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2083                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2084 \r
2085                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);          \r
2086         }\r
2087         \r
2088 }\r
2089 \r
2090 VOID\r
2091 halbtc8723b1ant_ActionBtScoHidOnlyBusy(\r
2092         IN      PBTC_COEXIST            pBtCoexist,\r
2093         IN      u1Byte                          wifiStatus\r
2094         )\r
2095 {\r
2096         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2097         BOOLEAN bWifiConnected=FALSE;\r
2098         u1Byte  wifiRssiState=BTC_RSSI_STATE_HIGH;\r
2099 \r
2100         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2101 \r
2102         // tdma and coex table\r
2103 \r
2104         if(pBtLinkInfo->bScoExist)\r
2105         {\r
2106                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2107                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2108         }\r
2109         else //HID\r
2110         {\r
2111                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2112                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);\r
2113         }\r
2114 /*\r
2115         if(pBtLinkInfo->bScoExist || pBtLinkInfo->bHidExist)\r
2116         {\r
2117                 if(bWifiConnected)\r
2118                 {\r
2119                         wifiRssiState = halbtc8723b1ant_WifiRssiState(pBtCoexist, 0, 2, 30, 0);\r
2120                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2121                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2122                         {\r
2123                                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 2, 1, 1, 1);\r
2124                         }\r
2125                         else\r
2126                         {\r
2127                                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 1, 1);\r
2128                         }\r
2129                 }\r
2130                 else\r
2131                 {\r
2132                         halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
2133                 }\r
2134         }\r
2135 */\r
2136 }\r
2137 \r
2138 VOID\r
2139 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(\r
2140         IN      PBTC_COEXIST            pBtCoexist,\r
2141         IN      u1Byte                          wifiStatus\r
2142         )\r
2143 {\r
2144         u1Byte          btRssiState;\r
2145         \r
2146         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2147         btRssiState = halbtc8723b1ant_BtRssiState(2, 28, 0);    \r
2148 \r
2149         if(pBtLinkInfo->bHidOnly)  //HID\r
2150         {\r
2151                 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);\r
2152                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2153                 return;\r
2154         }\r
2155         else if(pBtLinkInfo->bA2dpOnly)  //A2DP         \r
2156         {\r
2157                 if(BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)\r
2158                 {\r
2159                         //halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2160                         //halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2161                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2162                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2163                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
2164                 }\r
2165                 else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
2166                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )     \r
2167                 {\r
2168                         halbtc8723b1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);\r
2169                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2170                 }\r
2171                 else //for low BT RSSI\r
2172                 {\r
2173                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2174                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2175                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
2176                 }\r
2177         }\r
2178         else if(pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist)  //HID+A2DP\r
2179         {\r
2180                 if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
2181                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )     \r
2182                 {\r
2183                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2184                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
2185                 }\r
2186                 else //for low BT RSSI\r
2187                 {\r
2188                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2189                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
2190                 }                       \r
2191 \r
2192                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 6);\r
2193         }\r
2194         else if( (pBtLinkInfo->bPanOnly) || (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist) ) //PAN(OPP,FTP), HID+PAN(OPP,FTP)                 \r
2195         {\r
2196                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2197                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 6);\r
2198                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2199         }\r
2200         else if ( ((pBtLinkInfo->bA2dpExist) && (pBtLinkInfo->bPanExist)) ||\r
2201                        (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist&&pBtLinkInfo->bPanExist) ) //A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP)\r
2202         {\r
2203                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2204                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2205                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2206         }\r
2207         else\r
2208         {               \r
2209                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2210                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2211                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2212         }       \r
2213 }\r
2214 \r
2215 VOID\r
2216 halbtc8723b1ant_ActionWifiNotConnected(\r
2217         IN      PBTC_COEXIST            pBtCoexist\r
2218         )\r
2219 {\r
2220         // power save state\r
2221         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2222 \r
2223         // tdma and coex table\r
2224         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2225         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2226 }\r
2227 \r
2228 VOID\r
2229 halbtc8723b1ant_ActionWifiNotConnectedScan(\r
2230         IN      PBTC_COEXIST            pBtCoexist\r
2231         )\r
2232 {\r
2233         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2234         \r
2235         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2236         halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
2237 \r
2238         // tdma and coex table\r
2239         if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2240         {\r
2241                 if(pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)\r
2242                 {\r
2243                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
2244                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2245                 }\r
2246                 else if(pBtLinkInfo->bPanOnly)\r
2247                 {\r
2248                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2249                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2250                 }\r
2251                 else\r
2252                 {\r
2253                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2254                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2255                 }\r
2256         }\r
2257         else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2258                         (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2259         {\r
2260                 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2261                         BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
2262         }\r
2263         else\r
2264         {\r
2265                 //halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2266                 //halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2267 \r
2268                 //Bryant Add\r
2269                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2270                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2271         }\r
2272 }\r
2273 \r
2274 VOID\r
2275 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(\r
2276         IN      PBTC_COEXIST            pBtCoexist\r
2277         )\r
2278 {\r
2279         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2280         \r
2281         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2282 \r
2283         // tdma and coex table\r
2284         if( (pBtLinkInfo->bScoExist)  || (pBtLinkInfo->bHidExist) )\r
2285         {\r
2286                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2287                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);          \r
2288         }\r
2289         else if( (pBtLinkInfo->bA2dpExist)  || (pBtLinkInfo->bPanExist) )                       \r
2290         {\r
2291                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2292                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
2293         }\r
2294         else\r
2295         {\r
2296                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2297                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2298         }\r
2299 \r
2300 }\r
2301 \r
2302 VOID\r
2303 halbtc8723b1ant_ActionWifiConnectedScan(\r
2304         IN      PBTC_COEXIST            pBtCoexist\r
2305         )\r
2306 {\r
2307         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2308         \r
2309         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2310 \r
2311         // tdma and coex table\r
2312         if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2313         {\r
2314                 if(pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)\r
2315                 {\r
2316                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
2317                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2318                 }\r
2319                 else if(pBtLinkInfo->bPanOnly)\r
2320                 {\r
2321                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2322                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2323                 }\r
2324                 else\r
2325                 {\r
2326                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2327                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2328         }\r
2329         }\r
2330         else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2331                         (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2332         {\r
2333                 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2334                         BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
2335         }\r
2336         else\r
2337         {\r
2338                 //halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2339                 //halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2340 \r
2341                 //Bryant Add\r
2342                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2343                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2344         }\r
2345 }\r
2346 \r
2347 VOID\r
2348 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(\r
2349         IN      PBTC_COEXIST            pBtCoexist\r
2350         )\r
2351 {\r
2352         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2353 \r
2354         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2355 \r
2356         // tdma and coex table\r
2357         if( (pBtLinkInfo->bScoExist)  || (pBtLinkInfo->bHidExist) )\r
2358         {\r
2359                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2360                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);          \r
2361         }\r
2362         else if( (pBtLinkInfo->bA2dpExist)  || (pBtLinkInfo->bPanExist) )                       \r
2363         {\r
2364                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2365                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
2366         }\r
2367         else\r
2368         {\r
2369                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2370                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2371         }\r
2372 }\r
2373 \r
2374 VOID\r
2375 halbtc8723b1ant_ActionWifiConnected(\r
2376         IN      PBTC_COEXIST            pBtCoexist\r
2377         )\r
2378 {\r
2379         BOOLEAN         bWifiBusy=FALSE;\r
2380         BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2381         BOOLEAN         bUnder4way=FALSE, bApEnable=FALSE;\r
2382         u4Byte          wifiBw;\r
2383 \r
2384         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect()===>\n"));\r
2385 \r
2386         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
2387         if(bUnder4way)\r
2388         {\r
2389                 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
2390                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));\r
2391                 return;\r
2392         }\r
2393         \r
2394         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2395         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2396         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2397         if(bScan || bLink || bRoam)\r
2398         {\r
2399                 if(bScan)       \r
2400                         halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);\r
2401                 else\r
2402                         halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
2403                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));\r
2404                 return;\r
2405         }\r
2406 \r
2407         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
2408         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
2409         // power save state\r
2410         if(!bApEnable && BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)\r
2411         {\r
2412                 if(!bWifiBusy && pBtCoexist->btLinkInfo.bA2dpOnly)      //A2DP\r
2413                         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2414                 else\r
2415                         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);\r
2416         }\r
2417         else\r
2418                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2419 \r
2420         // tdma and coex table\r
2421         if(!bWifiBusy)\r
2422         {\r
2423                 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2424                 {\r
2425                         halbtc8723b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist, \r
2426                                 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
2427                 }\r
2428                 else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2429                         (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2430                 {\r
2431                         halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2432                                 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
2433                 }\r
2434                 else\r
2435                 {\r
2436                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2437                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2438                 }\r
2439         }\r
2440         else\r
2441         {\r
2442                 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2443                 {\r
2444                         halbtc8723b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,\r
2445                                 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
2446                 }\r
2447                 else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2448                         (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2449                 {\r
2450                         halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2451                                 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
2452                 }\r
2453                 else \r
2454                 {\r
2455                         halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2456                         halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2457                 }\r
2458         }\r
2459 }\r
2460 \r
2461 VOID\r
2462 halbtc8723b1ant_RunSwCoexistMechanism(\r
2463         IN      PBTC_COEXIST            pBtCoexist\r
2464         )\r
2465 {\r
2466         u1Byte                          algorithm=0;\r
2467 \r
2468         algorithm = halbtc8723b1ant_ActionAlgorithm(pBtCoexist);\r
2469         pCoexDm->curAlgorithm = algorithm;\r
2470 \r
2471         if(halbtc8723b1ant_IsCommonAction(pBtCoexist))\r
2472         {\r
2473 \r
2474         }\r
2475         else\r
2476         {\r
2477                 switch(pCoexDm->curAlgorithm)\r
2478                 {\r
2479                         case BT_8723B_1ANT_COEX_ALGO_SCO:\r
2480                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = SCO.\n"));\r
2481                                 halbtc8723b1ant_ActionSco(pBtCoexist);\r
2482                                 break;\r
2483                         case BT_8723B_1ANT_COEX_ALGO_HID:\r
2484                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID.\n"));\r
2485                                 halbtc8723b1ant_ActionHid(pBtCoexist);\r
2486                                 break;\r
2487                         case BT_8723B_1ANT_COEX_ALGO_A2DP:\r
2488                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP.\n"));\r
2489                                 halbtc8723b1ant_ActionA2dp(pBtCoexist);\r
2490                                 break;\r
2491                         case BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS:\r
2492                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));\r
2493                                 halbtc8723b1ant_ActionA2dpPanHs(pBtCoexist);\r
2494                                 break;\r
2495                         case BT_8723B_1ANT_COEX_ALGO_PANEDR:\r
2496                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR).\n"));\r
2497                                 halbtc8723b1ant_ActionPanEdr(pBtCoexist);\r
2498                                 break;\r
2499                         case BT_8723B_1ANT_COEX_ALGO_PANHS:\r
2500                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HS mode.\n"));\r
2501                                 halbtc8723b1ant_ActionPanHs(pBtCoexist);\r
2502                                 break;\r
2503                         case BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP:\r
2504                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));\r
2505                                 halbtc8723b1ant_ActionPanEdrA2dp(pBtCoexist);\r
2506                                 break;\r
2507                         case BT_8723B_1ANT_COEX_ALGO_PANEDR_HID:\r
2508                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));\r
2509                                 halbtc8723b1ant_ActionPanEdrHid(pBtCoexist);\r
2510                                 break;\r
2511                         case BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
2512                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));\r
2513                                 halbtc8723b1ant_ActionHidA2dpPanEdr(pBtCoexist);\r
2514                                 break;\r
2515                         case BT_8723B_1ANT_COEX_ALGO_HID_A2DP:\r
2516                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP.\n"));\r
2517                                 halbtc8723b1ant_ActionHidA2dp(pBtCoexist);\r
2518                                 break;\r
2519                         default:\r
2520                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = coexist All Off!!\n"));\r
2521                                 //halbtc8723b1ant_CoexAllOff(pBtCoexist);\r
2522                                 break;\r
2523                 }\r
2524                 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
2525         }\r
2526 }\r
2527 \r
2528 VOID\r
2529 halbtc8723b1ant_RunCoexistMechanism(\r
2530         IN      PBTC_COEXIST            pBtCoexist\r
2531         )\r
2532 {\r
2533         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2534         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;\r
2535         BOOLEAN bIncreaseScanDevNum=FALSE;\r
2536         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
2537         u1Byte  aggBufSize=5;\r
2538         u1Byte  wifiRssiState=BTC_RSSI_STATE_HIGH;\r
2539         u4Byte  wifiLinkStatus=0;\r
2540         u4Byte  numOfWifiLink=0;\r
2541 \r
2542         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism()===>\n"));\r
2543 \r
2544         if(pBtCoexist->bManualControl)\r
2545         {\r
2546                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));\r
2547                 return;\r
2548         }\r
2549 \r
2550         if(pBtCoexist->bStopCoexDm)\r
2551         {\r
2552                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));\r
2553                 return;\r
2554         }\r
2555 \r
2556         if(pCoexSta->bUnderIps)\r
2557         {\r
2558                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is under IPS !!!\n"));\r
2559                 return;\r
2560         }\r
2561 \r
2562         if( (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
2563                 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2564                 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2565         {\r
2566                 bIncreaseScanDevNum = TRUE;\r
2567         }\r
2568 \r
2569         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, &bIncreaseScanDevNum);\r
2570         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2571 \r
2572         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
2573         numOfWifiLink = wifiLinkStatus>>16;\r
2574         if(numOfWifiLink >= 2)\r
2575         {\r
2576                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
2577                 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
2578                 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);\r
2579                 return;\r
2580         }\r
2581 \r
2582         if(!pBtLinkInfo->bScoExist && !pBtLinkInfo->bHidExist)\r
2583         {\r
2584                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
2585         }\r
2586         else\r
2587         {\r
2588                 if(bWifiConnected)\r
2589                 {\r
2590                         wifiRssiState = halbtc8723b1ant_WifiRssiState(pBtCoexist, 1, 2, 30, 0);\r
2591                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2592                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2593                         {\r
2594                                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 1, 1);\r
2595                         }\r
2596                         else\r
2597                         {\r
2598                                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 1, 1);\r
2599                         }\r
2600                 }\r
2601                 else\r
2602                 {\r
2603                         halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
2604                 }\r
2605 \r
2606         }\r
2607 \r
2608         if(pBtLinkInfo->bScoExist)\r
2609         {\r
2610                 bBtCtrlAggBufSize = TRUE;\r
2611                 aggBufSize = 0x3;\r
2612         }\r
2613         else if(pBtLinkInfo->bHidExist)\r
2614         {\r
2615                 bBtCtrlAggBufSize = TRUE;\r
2616                 aggBufSize = 0x5;\r
2617         }\r
2618         else if(pBtLinkInfo->bA2dpExist || pBtLinkInfo->bPanExist)\r
2619         {\r
2620                 bBtCtrlAggBufSize = TRUE;\r
2621                 aggBufSize = 0x8;\r
2622         }\r
2623         halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
2624 \r
2625         halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist);\r
2626         \r
2627         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2628         if(pCoexSta->bC2hBtInquiryPage)\r
2629         {\r
2630                 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);\r
2631                 return;\r
2632         }\r
2633         else if(bBtHsOn)\r
2634         {\r
2635                 halbtc8723b1ant_ActionHs(pBtCoexist);\r
2636                 return;\r
2637         }\r
2638 \r
2639         \r
2640         if(!bWifiConnected)\r
2641         {\r
2642                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2643                 \r
2644                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is non connected-idle !!!\n"));\r
2645 \r
2646                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2647                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2648                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2649 \r
2650                 if(bScan || bLink || bRoam)\r
2651                 {\r
2652                          if (bScan)     \r
2653                                 halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist); \r
2654                          else\r
2655                                 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);     \r
2656                 }\r
2657                 else\r
2658                         halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);\r
2659         }\r
2660         else    // wifi LPS/Busy\r
2661         {\r
2662                 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);\r
2663         }\r
2664 }\r
2665 \r
2666 VOID\r
2667 halbtc8723b1ant_InitCoexDm(\r
2668         IN      PBTC_COEXIST            pBtCoexist\r
2669         )\r
2670 {       \r
2671         // force to reset coex mechanism\r
2672 \r
2673         // sw all off\r
2674         halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);\r
2675         \r
2676         //halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
2677         halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
2678 }\r
2679 \r
2680 VOID\r
2681 halbtc8723b1ant_InitHwConfig(\r
2682         IN      PBTC_COEXIST            pBtCoexist,\r
2683         IN      BOOLEAN                         bBackUp\r
2684         )\r
2685 {\r
2686         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
2687         u4Byte                          u4Tmp=0;//, fwVer;\r
2688         u2Byte                          u2Tmp=0;\r
2689         u1Byte                          u1Tmp=0;\r
2690         u1Byte                          H2C_Parameter[2] ={0};\r
2691         u4Byte                          cntBtCalChk=0;\r
2692 \r
2693         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 1Ant Init HW Config!!\n"));\r
2694 \r
2695         if(bBackUp)\r
2696         {\r
2697                 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
2698                 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
2699                 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
2700                 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
2701         }\r
2702         \r
2703         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); //WiFi goto standby while GNT_BT 0-->1\r
2704         //pBtCoexist->fBtcSetBtReg(pBtCoexist, 0, 0x3c, 0x15); //BT goto standby while GNT_BT 1-->0\r
2705 \r
2706         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff);\r
2707         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3);\r
2708         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77);\r
2709 \r
2710         //pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); //BT select s0/s1 is controlled by WiFi\r
2711 \r
2712         // BT calibration check\r
2713         while(cntBtCalChk <= 20)\r
2714         {\r
2715                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x49d);\r
2716                 cntBtCalChk++;\r
2717                 if(u4Tmp & BIT0)\r
2718                 {\r
2719                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ########### BT calibration(cnt=%d) ###########\n", cntBtCalChk));\r
2720                         delay_ms(50);\r
2721                 }\r
2722                 else\r
2723                 {\r
2724                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ********** BT NOT calibration (cnt=%d)**********\n", cntBtCalChk));\r
2725                         break;\r
2726                 }\r
2727         }\r
2728 \r
2729         // 0x790[5:0]=0x5\r
2730         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);\r
2731         u1Tmp &= 0xc0;\r
2732         u1Tmp |= 0x5;\r
2733         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);\r
2734         \r
2735         // Enable counter statistics\r
2736         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); //0x76e[3] =1, WLAN_Act control by PTA\r
2737         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);\r
2738         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1); \r
2739 \r
2740         //Antenna config\r
2741         //halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, TRUE, FALSE);\r
2742         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, TRUE, FALSE);\r
2743 \r
2744         // PTA parameter\r
2745         halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
2746 }\r
2747 \r
2748 VOID\r
2749 halbtc8723b1ant_WifiOffHwCfg(\r
2750         IN      PBTC_COEXIST            pBtCoexist\r
2751         )\r
2752 {\r
2753         // set wlan_act to low\r
2754         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
2755 }\r
2756 \r
2757 //============================================================\r
2758 // work around function start with wa_halbtc8723b1ant_\r
2759 //============================================================\r
2760 //============================================================\r
2761 // extern function start with EXhalbtc8723b1ant_\r
2762 //============================================================\r
2763 VOID\r
2764 EXhalbtc8723b1ant_InitHwConfig(\r
2765         IN      PBTC_COEXIST            pBtCoexist\r
2766         )\r
2767 {\r
2768         halbtc8723b1ant_InitHwConfig(pBtCoexist, TRUE);\r
2769 }\r
2770 \r
2771 VOID\r
2772 EXhalbtc8723b1ant_InitCoexDm(\r
2773         IN      PBTC_COEXIST            pBtCoexist\r
2774         )\r
2775 {\r
2776         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));\r
2777 \r
2778         pBtCoexist->bStopCoexDm = FALSE;\r
2779         \r
2780         halbtc8723b1ant_InitCoexDm(pBtCoexist);\r
2781 \r
2782         halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
2783 }\r
2784 \r
2785 VOID\r
2786 EXhalbtc8723b1ant_DisplayCoexInfo(\r
2787         IN      PBTC_COEXIST            pBtCoexist\r
2788         )\r
2789 {\r
2790         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
2791         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
2792         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2793         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
2794         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
2795         u2Byte                          u2Tmp[4];\r
2796         u4Byte                          u4Tmp[4];\r
2797         BOOLEAN                         bRoam=FALSE, bScan=FALSE, bLink=FALSE, bWifiUnder5G=FALSE;\r
2798         BOOLEAN                         bBtHsOn=FALSE, bWifiBusy=FALSE;\r
2799         s4Byte                          wifiRssi=0, btHsRssi=0;\r
2800         u4Byte                          wifiBw, wifiTrafficDir, faOfdm, faCck, wifiLinkStatus;\r
2801         u1Byte                          wifiDot11Chnl, wifiHsChnl;\r
2802         u4Byte                          fwVer=0, btPatchVer=0;\r
2803 \r
2804         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
2805         CL_PRINTF(cliBuf);\r
2806 \r
2807         if(pBtCoexist->bManualControl)\r
2808         {\r
2809                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");\r
2810                 CL_PRINTF(cliBuf);\r
2811                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
2812                 CL_PRINTF(cliBuf);\r
2813         }\r
2814         if(pBtCoexist->bStopCoexDm)\r
2815         {\r
2816                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");\r
2817                 CL_PRINTF(cliBuf);\r
2818                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
2819                 CL_PRINTF(cliBuf);\r
2820         }\r
2821 \r
2822         if(!pBoardInfo->bBtExist)\r
2823         {\r
2824                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");\r
2825                 CL_PRINTF(cliBuf);\r
2826                 return;\r
2827         }\r
2828 \r
2829         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Ant PG Num/ Ant Mech/ Ant Pos:", \\r
2830                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos);\r
2831         CL_PRINTF(cliBuf);      \r
2832         \r
2833         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
2834                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
2835         CL_PRINTF(cliBuf);\r
2836 \r
2837         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
2838         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
2839         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \\r
2840                 GLCoexVerDate8723b1Ant, GLCoexVer8723b1Ant, fwVer, btPatchVer, btPatchVer);\r
2841         CL_PRINTF(cliBuf);\r
2842 \r
2843         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2844         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiDot11Chnl);\r
2845         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl);\r
2846         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(HsMode)", \\r
2847                 wifiDot11Chnl, wifiHsChnl, bBtHsOn);\r
2848         CL_PRINTF(cliBuf);\r
2849 \r
2850         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "H2C Wifi inform bt chnl Info", \\r
2851                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
2852                 pCoexDm->wifiChnlInfo[2]);\r
2853         CL_PRINTF(cliBuf);\r
2854 \r
2855         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
2856         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);\r
2857         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \\r
2858                 wifiRssi, btHsRssi);\r
2859         CL_PRINTF(cliBuf);\r
2860 \r
2861         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2862         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2863         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2864         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \\r
2865                 bLink, bRoam, bScan);\r
2866         CL_PRINTF(cliBuf);\r
2867 \r
2868         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
2869         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2870         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
2871         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
2872         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s ", "Wifi status", \\r
2873                 (bWifiUnder5G? "5G":"2.4G"),\r
2874                 ((BTC_WIFI_BW_LEGACY==wifiBw)? "Legacy": (((BTC_WIFI_BW_HT40==wifiBw)? "HT40":"HT20"))),\r
2875                 ((!bWifiBusy)? "idle": ((BTC_WIFI_TRAFFIC_TX==wifiTrafficDir)? "uplink":"downlink")));\r
2876         CL_PRINTF(cliBuf);\r
2877 \r
2878         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
2879         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "sta/vwifi/hs/p2pGo/p2pGc", \\r
2880                 ((wifiLinkStatus&WIFI_STA_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_AP_CONNECTED)? 1:0), \r
2881                 ((wifiLinkStatus&WIFI_HS_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_P2P_GO_CONNECTED)? 1:0), \r
2882                 ((wifiLinkStatus&WIFI_P2P_GC_CONNECTED)? 1:0) );\r
2883         CL_PRINTF(cliBuf);\r
2884         \r
2885         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
2886                 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":\r
2887                 (  (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),\r
2888                 pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
2889         CL_PRINTF(cliBuf);\r
2890         \r
2891                                 \r
2892         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
2893                 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist);\r
2894         CL_PRINTF(cliBuf);\r
2895         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);      \r
2896 \r
2897         btInfoExt = pCoexSta->btInfoExt;\r
2898         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
2899                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
2900         CL_PRINTF(cliBuf);      \r
2901 \r
2902         for(i=0; i<BT_INFO_SRC_8723B_1ANT_MAX; i++)\r
2903         {\r
2904                 if(pCoexSta->btInfoC2hCnt[i])\r
2905                 {                               \r
2906                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723b1Ant[i], \\r
2907                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
2908                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
2909                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
2910                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
2911                         CL_PRINTF(cliBuf);\r
2912                 }\r
2913         }\r
2914         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/%s, (0x%x/0x%x)", "PS state, IPS/LPS, (lps/rpwm)", \\r
2915                 ((pCoexSta->bUnderIps? "IPS ON":"IPS OFF")),\r
2916                 ((pCoexSta->bUnderLps? "LPS ON":"LPS OFF")), \r
2917                 pBtCoexist->btInfo.lpsVal, \r
2918                 pBtCoexist->btInfo.rpwmVal);\r
2919         CL_PRINTF(cliBuf);\r
2920         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);\r
2921 \r
2922         if(!pBtCoexist->bManualControl)\r
2923         {\r
2924                 // Sw mechanism \r
2925                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
2926                 CL_PRINTF(cliBuf);\r
2927         \r
2928                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "SM[LowPenaltyRA]", \\r
2929                         pCoexDm->bCurLowPenaltyRa);\r
2930                 CL_PRINTF(cliBuf);\r
2931 \r
2932                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "DelBA/ BtCtrlAgg/ AggSize", \\r
2933                         (pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),\r
2934                                 pBtCoexist->btInfo.aggBufSize);\r
2935                 CL_PRINTF(cliBuf);\r
2936                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \\r
2937                                 pBtCoexist->btInfo.raMask);\r
2938                 CL_PRINTF(cliBuf);\r
2939 \r
2940                 // Fw mechanism         \r
2941                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
2942                 CL_PRINTF(cliBuf);      \r
2943 \r
2944                 psTdmaCase = pCoexDm->curPsTdma;\r
2945                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \\r
2946                         pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
2947                         pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
2948                         pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);\r
2949                 CL_PRINTF(cliBuf);\r
2950                 \r
2951                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "IgnWlanAct", \\r
2952                         pCoexDm->bCurIgnoreWlanAct);\r
2953                 CL_PRINTF(cliBuf);\r
2954         \r
2955                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Latest error condition(should be 0)", \\r
2956                         pCoexDm->errorCondition);\r
2957                 CL_PRINTF(cliBuf);\r
2958         }\r
2959 \r
2960         // Hw setting           \r
2961         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
2962         CL_PRINTF(cliBuf);      \r
2963 \r
2964         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "backup ARFR1/ARFR2/RL/AMaxTime", \\r
2965                 pCoexDm->backupArfrCnt1, pCoexDm->backupArfrCnt2, pCoexDm->backupRetryLimit, pCoexDm->backupAmpduMaxTime);\r
2966         CL_PRINTF(cliBuf);\r
2967 \r
2968         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
2969         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
2970         u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
2971         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
2972         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \\r
2973                 u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);\r
2974         CL_PRINTF(cliBuf);\r
2975 \r
2976         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
2977         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6cc);\r
2978         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);\r
2979         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/0x6cc/0x880[29:25]", \\r
2980                 u1Tmp[0], u4Tmp[0],  (u4Tmp[1]&0x3e000000) >> 25);\r
2981         CL_PRINTF(cliBuf);\r
2982 \r
2983         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);\r
2984         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);\r
2985         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);\r
2986         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x948/ 0x67[5] / 0x765", \\r
2987                 u4Tmp[0], ((u1Tmp[0]&0x20)>> 5), u1Tmp[1]);\r
2988         CL_PRINTF(cliBuf);\r
2989 \r
2990         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x92c);\r
2991         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);\r
2992         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x944);        \r
2993         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]", \\r
2994                 u4Tmp[0]&0x3, u4Tmp[1]&0xff, u4Tmp[2]&0x3);\r
2995         CL_PRINTF(cliBuf);\r
2996 \r
2997         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x39);\r
2998         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
2999         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
3000         u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x64);\r
3001         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]", \\r
3002                 ((u1Tmp[0] & 0x8)>>3), u1Tmp[1], ((u4Tmp[0]&0x01800000)>>23), u1Tmp[2]&0x1);\r
3003         CL_PRINTF(cliBuf);\r
3004 \r
3005         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
3006         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
3007         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
3008                 u4Tmp[0], u1Tmp[0]);\r
3009         CL_PRINTF(cliBuf);\r
3010 \r
3011         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
3012         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49c);\r
3013         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xc50(dig)/0x49c(null-drop)", \\r
3014                 u4Tmp[0]&0xff, u1Tmp[0]);\r
3015         CL_PRINTF(cliBuf);\r
3016 \r
3017         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);\r
3018         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);\r
3019         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);\r
3020         u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);\r
3021 \r
3022         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);\r
3023         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);\r
3024 \r
3025         faOfdm = ((u4Tmp[0]&0xffff0000) >> 16) +  ((u4Tmp[1]&0xffff0000) >> 16) + (u4Tmp[1] & 0xffff) +  (u4Tmp[2] & 0xffff) + \\r
3026                              ((u4Tmp[3]&0xffff0000) >> 16) + (u4Tmp[3] & 0xffff) ;\r
3027         faCck = (u1Tmp[0] << 8) + u1Tmp[1];\r
3028         \r
3029         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "OFDM-CCA/OFDM-FA/CCK-FA", \\r
3030                 u4Tmp[0]&0xffff, faOfdm, faCck);\r
3031         CL_PRINTF(cliBuf);\r
3032 \r
3033         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
3034         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
3035         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
3036         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8(coexTable)", \\r
3037                 u4Tmp[0], u4Tmp[1], u4Tmp[2]);\r
3038         CL_PRINTF(cliBuf);\r
3039 \r
3040         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \\r
3041                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
3042         CL_PRINTF(cliBuf);\r
3043         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \\r
3044                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
3045         CL_PRINTF(cliBuf);\r
3046 #if(BT_AUTO_REPORT_ONLY_8723B_1ANT == 1)\r
3047         halbtc8723b1ant_MonitorBtCtr(pBtCoexist);\r
3048 #endif\r
3049         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
3050 }\r
3051 \r
3052 \r
3053 VOID\r
3054 EXhalbtc8723b1ant_IpsNotify(\r
3055         IN      PBTC_COEXIST            pBtCoexist,\r
3056         IN      u1Byte                  type\r
3057         )\r
3058 {\r
3059         u4Byte  u4Tmp=0;\r
3060 \r
3061         if(pBtCoexist->bManualControl ||        pBtCoexist->bStopCoexDm)\r
3062                 return;\r
3063 \r
3064         if(BTC_IPS_ENTER == type)\r
3065         {\r
3066                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));\r
3067                 pCoexSta->bUnderIps = TRUE;\r
3068                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
3069                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
3070                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
3071                 halbtc8723b1ant_WifiOffHwCfg(pBtCoexist);\r
3072         }\r
3073         else if(BTC_IPS_LEAVE == type)\r
3074         {\r
3075                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));\r
3076                 pCoexSta->bUnderIps = FALSE;\r
3077                 //halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, TRUE, FALSE);\r
3078                 //halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);\r
3079 \r
3080                 halbtc8723b1ant_InitHwConfig(pBtCoexist, FALSE);\r
3081                 halbtc8723b1ant_InitCoexDm(pBtCoexist);\r
3082                 halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
3083         }\r
3084 }\r
3085 \r
3086 VOID\r
3087 EXhalbtc8723b1ant_LpsNotify(\r
3088         IN      PBTC_COEXIST            pBtCoexist,\r
3089         IN      u1Byte                  type\r
3090         )\r
3091 {\r
3092         if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)\r
3093                 return;\r
3094 \r
3095         if(BTC_LPS_ENABLE == type)\r
3096         {\r
3097                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));\r
3098                 pCoexSta->bUnderLps = TRUE;\r
3099         }\r
3100         else if(BTC_LPS_DISABLE == type)\r
3101         {\r
3102                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));\r
3103                 pCoexSta->bUnderLps = FALSE;\r
3104         }\r
3105 }\r
3106 \r
3107 VOID\r
3108 EXhalbtc8723b1ant_ScanNotify(\r
3109         IN      PBTC_COEXIST            pBtCoexist,\r
3110         IN      u1Byte                  type\r
3111         )\r
3112 {\r
3113         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
3114         u4Byte  wifiLinkStatus=0;\r
3115         u4Byte  numOfWifiLink=0;\r
3116         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
3117         u1Byte  aggBufSize=5;\r
3118 \r
3119         if(pBtCoexist->bManualControl ||\r
3120                 pBtCoexist->bStopCoexDm ||\r
3121                 pBtCoexist->btInfo.bBtDisabled )\r
3122                 return;\r
3123 \r
3124         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
3125         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
3126 \r
3127         if(BTC_SCAN_START == type)\r
3128         {\r
3129                 pCoexSta->bWiFiIsHighPriTask = TRUE;\r
3130                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
3131         }\r
3132         else\r
3133         {\r
3134                 pCoexSta->bWiFiIsHighPriTask = FALSE;   \r
3135                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
3136         }\r
3137 \r
3138         halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
3139         \r
3140         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
3141         numOfWifiLink = wifiLinkStatus>>16;\r
3142         if(numOfWifiLink >= 2)\r
3143         {\r
3144                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
3145                 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
3146                 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);\r
3147                 return;\r
3148         }\r
3149         \r
3150         if(pCoexSta->bC2hBtInquiryPage)\r
3151         {\r
3152                 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);\r
3153                 return;\r
3154         }\r
3155         else if(bBtHsOn)\r
3156         {\r
3157                 halbtc8723b1ant_ActionHs(pBtCoexist);\r
3158                 return;\r
3159         }\r
3160 \r
3161         if(BTC_SCAN_START == type)\r
3162         {       \r
3163                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
3164                 if(!bWifiConnected)     // non-connected scan\r
3165                 {\r
3166                         halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist);\r
3167                 }\r
3168                 else    // wifi is connected\r
3169                 {\r
3170                         halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);\r
3171                 }\r
3172         }\r
3173         else if(BTC_SCAN_FINISH == type)\r
3174         {\r
3175                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
3176                 if(!bWifiConnected)     // non-connected scan\r
3177                 {\r
3178                         halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);\r
3179                 }\r
3180                 else\r
3181                 {\r
3182                         halbtc8723b1ant_ActionWifiConnected(pBtCoexist);\r
3183                 }\r
3184         }\r
3185 }\r
3186 \r
3187 VOID\r
3188 EXhalbtc8723b1ant_ConnectNotify(\r
3189         IN      PBTC_COEXIST            pBtCoexist,\r
3190         IN      u1Byte                  type\r
3191         )\r
3192 {\r
3193         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
3194         u4Byte  wifiLinkStatus=0;\r
3195         u4Byte  numOfWifiLink=0;\r
3196         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
3197         u1Byte  aggBufSize=5;\r
3198 \r
3199         if(pBtCoexist->bManualControl ||\r
3200                 pBtCoexist->bStopCoexDm ||\r
3201                 pBtCoexist->btInfo.bBtDisabled )\r
3202                 return;\r
3203 \r
3204         if(BTC_ASSOCIATE_START == type)\r
3205         {\r
3206                 pCoexSta->bWiFiIsHighPriTask = TRUE;\r
3207                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));        \r
3208         }\r
3209         else\r
3210         {\r
3211                 pCoexSta->bWiFiIsHighPriTask = FALSE;   \r
3212                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));       \r
3213         }\r
3214 \r
3215         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
3216         numOfWifiLink = wifiLinkStatus>>16;\r
3217         if(numOfWifiLink >= 2)\r
3218         {\r
3219                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
3220                 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
3221                 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);\r
3222                 return;\r
3223         }\r
3224 \r
3225         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
3226         if(pCoexSta->bC2hBtInquiryPage)\r
3227         {\r
3228                 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);\r
3229                 return;\r
3230         }\r
3231         else if(bBtHsOn)\r
3232         {\r
3233                 halbtc8723b1ant_ActionHs(pBtCoexist);\r
3234                 return;\r
3235         }\r
3236 \r
3237         if(BTC_ASSOCIATE_START == type)\r
3238         {\r
3239                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));              \r
3240                 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);\r
3241         }\r
3242         else if(BTC_ASSOCIATE_FINISH == type)\r
3243         {\r
3244                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));\r
3245                 \r
3246                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
3247                 if(!bWifiConnected) // non-connected scan\r
3248                 {\r
3249                         halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);\r
3250                 }\r
3251                 else\r
3252                 {\r
3253                         halbtc8723b1ant_ActionWifiConnected(pBtCoexist);\r
3254                 }\r
3255         }\r
3256 }\r
3257 \r
3258 VOID\r
3259 EXhalbtc8723b1ant_MediaStatusNotify(\r
3260         IN      PBTC_COEXIST                    pBtCoexist,\r
3261         IN      u1Byte                          type\r
3262         )\r
3263 {\r
3264         u1Byte                  H2C_Parameter[3] ={0};\r
3265         u4Byte                  wifiBw;\r
3266         u1Byte                  wifiCentralChnl;\r
3267 \r
3268         if(pBtCoexist->bManualControl ||\r
3269                 pBtCoexist->bStopCoexDm ||\r
3270                 pBtCoexist->btInfo.bBtDisabled )\r
3271                 return;\r
3272 \r
3273         if(BTC_MEDIA_CONNECT == type)\r
3274         {\r
3275                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));\r
3276         }\r
3277         else\r
3278         {\r
3279                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));\r
3280         }\r
3281 \r
3282         // only 2.4G we need to inform bt the chnl mask\r
3283         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
3284         if( (BTC_MEDIA_CONNECT == type) &&\r
3285                 (wifiCentralChnl <= 14) )\r
3286         {\r
3287                 //H2C_Parameter[0] = 0x1;\r
3288                 H2C_Parameter[0] = 0x0;\r
3289                 H2C_Parameter[1] = wifiCentralChnl;\r
3290                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3291                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
3292                         H2C_Parameter[2] = 0x30;\r
3293                 else\r
3294                         H2C_Parameter[2] = 0x20;\r
3295         }\r
3296                 \r
3297         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
3298         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
3299         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
3300         \r
3301         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x66=0x%x\n", \r
3302                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
3303 \r
3304         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);\r
3305 }\r
3306 \r
3307 VOID\r
3308 EXhalbtc8723b1ant_SpecialPacketNotify(\r
3309         IN      PBTC_COEXIST                    pBtCoexist,\r
3310         IN      u1Byte                          type\r
3311         )\r
3312 {\r
3313         BOOLEAN bBtHsOn=FALSE;\r
3314         u4Byte  wifiLinkStatus=0;\r
3315         u4Byte  numOfWifiLink=0;\r
3316         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
3317         u1Byte  aggBufSize=5;\r
3318         \r
3319         if(pBtCoexist->bManualControl ||\r
3320                 pBtCoexist->bStopCoexDm ||\r
3321                 pBtCoexist->btInfo.bBtDisabled )\r
3322                 return;\r
3323 \r
3324         if( BTC_PACKET_DHCP == type ||   BTC_PACKET_EAPOL == type ||BTC_PACKET_ARP == type)\r
3325         {\r
3326                 pCoexSta->bWiFiIsHighPriTask = TRUE;\r
3327 \r
3328                 if (BTC_PACKET_ARP == type)\r
3329                 {\r
3330                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet ARP notify\n"));            \r
3331                 }\r
3332                 else\r
3333                 {\r
3334                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet DHCP or EAPOL notify\n"));          \r
3335                 }\r
3336         } \r
3337         else\r
3338         {\r
3339                 pCoexSta->bWiFiIsHighPriTask = FALSE;\r
3340                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet [Type = %d] notify\n", type));\r
3341         }\r
3342 \r
3343         pCoexSta->specialPktPeriodCnt = 0;\r
3344 \r
3345         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
3346         numOfWifiLink = wifiLinkStatus>>16;\r
3347         if(numOfWifiLink >= 2)\r
3348         {\r
3349                 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
3350                 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
3351                 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);\r
3352                 return;\r
3353         }\r
3354 \r
3355         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
3356         if(pCoexSta->bC2hBtInquiryPage)\r
3357         {\r
3358                 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);\r
3359                 return;\r
3360         }\r
3361         else if(bBtHsOn)\r
3362         {\r
3363                 halbtc8723b1ant_ActionHs(pBtCoexist);\r
3364                 return;\r
3365         }\r
3366 \r
3367         if( BTC_PACKET_DHCP == type ||\r
3368                 BTC_PACKET_EAPOL == type  || BTC_PACKET_ARP == type)\r
3369         {\r
3370                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet(%d) notify\n", type));\r
3371                 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
3372         }\r
3373 }\r
3374 \r
3375 VOID\r
3376 EXhalbtc8723b1ant_BtInfoNotify(\r
3377         IN      PBTC_COEXIST            pBtCoexist,\r
3378         IN      pu1Byte                 tmpBuf,\r
3379         IN      u1Byte                  length\r
3380         )\r
3381 {\r
3382         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
3383         u1Byte                          btInfo=0;\r
3384         u1Byte                          i, rspSource=0;\r
3385         BOOLEAN                         bWifiConnected=FALSE;\r
3386         BOOLEAN                         bBtBusy=FALSE;\r
3387         \r
3388         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
3389 \r
3390         rspSource = tmpBuf[0]&0xf;\r
3391         if(rspSource >= BT_INFO_SRC_8723B_1ANT_MAX)\r
3392                 rspSource = BT_INFO_SRC_8723B_1ANT_WIFI_FW;\r
3393         pCoexSta->btInfoC2hCnt[rspSource]++;\r
3394 \r
3395         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
3396         for(i=0; i<length; i++)\r
3397         {\r
3398                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
3399                 if(i == 1)\r
3400                         btInfo = tmpBuf[i];\r
3401                 \r
3402                 if(i == length-1)\r
3403                 {\r
3404                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));\r
3405                 }\r
3406                 else\r
3407                 {\r
3408                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));\r
3409                 }\r
3410                         \r
3411         }\r
3412 \r
3413         if(BT_INFO_SRC_8723B_1ANT_WIFI_FW != rspSource)\r
3414         {\r
3415                 pCoexSta->btRetryCnt =  // [3:0]\r
3416                         pCoexSta->btInfoC2h[rspSource][2]&0xf;\r
3417 \r
3418                 if (pCoexSta->btInfoC2h[rspSource][2]&0x20)\r
3419                         pCoexSta->bC2hBtPage = TRUE;\r
3420                 else\r
3421                         pCoexSta->bC2hBtPage = FALSE;                   \r
3422 \r
3423                 pCoexSta->btRssi =\r
3424                         pCoexSta->btInfoC2h[rspSource][3]*2+10;\r
3425 \r
3426                 pCoexSta->btInfoExt = \r
3427                         pCoexSta->btInfoC2h[rspSource][4];\r
3428                 \r
3429                 if (!(pCoexSta->btInfoC2h[rspSource][2] & 0x40))\r
3430                 {\r
3431                         /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch GNT_BT */                         \r
3432                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Switch GNT_BT since BT RF REG 0x3C != 0x15\n"));\r
3433                         pBtCoexist->fBtcSetBtReg(pBtCoexist, 0, 0x3c, 0x15);\r
3434                 }\r
3435                 \r
3436                 // Here we need to resend some wifi info to BT\r
3437                 // because bt is reset and loss of the info.\r
3438                 if(pCoexSta->btInfoExt & BIT1)\r
3439                 {                       \r
3440                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));\r
3441                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
3442                         if(bWifiConnected)\r
3443                         {\r
3444                                 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);\r
3445                         }\r
3446                         else\r
3447                         {\r
3448                                 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
3449                         }\r
3450                 }\r
3451                                 \r
3452                 if(pCoexSta->btInfoExt & BIT3)\r
3453                 {\r
3454                         if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)\r
3455                         {\r
3456                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));\r
3457                                 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
3458                         }\r
3459                 }\r
3460                 else\r
3461                 {\r
3462                         // BT already NOT ignore Wlan active, do nothing here.\r
3463                 }\r
3464 #if(BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)\r
3465                 if( (pCoexSta->btInfoExt & BIT4) )\r
3466                 {\r
3467                         // BT auto report already enabled, do nothing\r
3468                 }\r
3469                 else\r
3470                 {\r
3471                         halbtc8723b1ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);\r
3472                 }\r
3473 #endif\r
3474         }\r
3475                 \r
3476         // check BIT2 first ==> check if bt is under inquiry or page scan\r
3477         if(btInfo & BT_INFO_8723B_1ANT_B_INQ_PAGE)\r
3478                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
3479         else\r
3480                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
3481 \r
3482         // set link exist status\r
3483         if(!(btInfo&BT_INFO_8723B_1ANT_B_CONNECTION))\r
3484         {\r
3485                 pCoexSta->bBtLinkExist = FALSE;\r
3486                 pCoexSta->bPanExist = FALSE;\r
3487                 pCoexSta->bA2dpExist = FALSE;\r
3488                 pCoexSta->bHidExist = FALSE;\r
3489                 pCoexSta->bScoExist = FALSE;\r
3490         }\r
3491         else    // connection exists\r
3492         {\r
3493                 pCoexSta->bBtLinkExist = TRUE;\r
3494                 if(btInfo & BT_INFO_8723B_1ANT_B_FTP)\r
3495                         pCoexSta->bPanExist = TRUE;\r
3496                 else\r
3497                         pCoexSta->bPanExist = FALSE;\r
3498                 if(btInfo & BT_INFO_8723B_1ANT_B_A2DP)\r
3499                         pCoexSta->bA2dpExist = TRUE;\r
3500                 else\r
3501                         pCoexSta->bA2dpExist = FALSE;\r
3502                 if(btInfo & BT_INFO_8723B_1ANT_B_HID)\r
3503                         pCoexSta->bHidExist = TRUE;\r
3504                 else\r
3505                         pCoexSta->bHidExist = FALSE;\r
3506                 if(btInfo & BT_INFO_8723B_1ANT_B_SCO_ESCO)\r
3507                         pCoexSta->bScoExist = TRUE;\r
3508                 else\r
3509                         pCoexSta->bScoExist = FALSE;\r
3510         }\r
3511 \r
3512         halbtc8723b1ant_UpdateBtLinkInfo(pBtCoexist);\r
3513         \r
3514         if(!(btInfo&BT_INFO_8723B_1ANT_B_CONNECTION))\r
3515         {\r
3516                 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;\r
3517                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));\r
3518         }\r
3519         else if(btInfo == BT_INFO_8723B_1ANT_B_CONNECTION)      // connection exists but no busy\r
3520         {\r
3521                 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE;\r
3522                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));\r
3523         }\r
3524         else if((btInfo&BT_INFO_8723B_1ANT_B_SCO_ESCO) ||\r
3525                 (btInfo&BT_INFO_8723B_1ANT_B_SCO_BUSY))\r
3526         {\r
3527                 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_SCO_BUSY;\r
3528                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));\r
3529         }\r
3530         else if(btInfo&BT_INFO_8723B_1ANT_B_ACL_BUSY)\r
3531         {\r
3532                 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)\r
3533                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
3534                 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_ACL_BUSY;\r
3535                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));\r
3536         }\r
3537         else\r
3538         {\r
3539                 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_MAX;\r
3540                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));\r
3541         }\r
3542 \r
3543         if( (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
3544                 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
3545                 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
3546                 bBtBusy = TRUE;\r
3547         else\r
3548                 bBtBusy = FALSE;\r
3549         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
3550 \r
3551         halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);\r
3552 }\r
3553 \r
3554 VOID\r
3555 EXhalbtc8723b1ant_HaltNotify(\r
3556         IN      PBTC_COEXIST                    pBtCoexist\r
3557         )\r
3558 {\r
3559         u4Byte  u4Tmp;\r
3560         \r
3561         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));\r
3562 \r
3563         pBtCoexist->bStopCoexDm = TRUE;\r
3564 \r
3565         halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
3566         halbtc8723b1ant_WifiOffHwCfg(pBtCoexist);\r
3567         halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
3568 \r
3569         halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
3570         halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
3571 \r
3572         EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
3573 }\r
3574 \r
3575 VOID\r
3576 EXhalbtc8723b1ant_PnpNotify(\r
3577         IN      PBTC_COEXIST                    pBtCoexist,\r
3578         IN      u1Byte                          pnpState\r
3579         )\r
3580 {\r
3581         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify\n"));\r
3582 \r
3583         if(BTC_WIFI_PNP_SLEEP == pnpState)\r
3584         {\r
3585                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to SLEEP\n"));\r
3586                 pBtCoexist->bStopCoexDm = TRUE;\r
3587                 /*\r
3588                 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
3589                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
3590                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
3591                 */\r
3592 \r
3593                 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
3594                 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
3595                 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
3596                 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3597                 halbtc8723b1ant_WifiOffHwCfg(pBtCoexist);\r
3598         }\r
3599         else if(BTC_WIFI_PNP_WAKE_UP == pnpState)\r
3600         {\r
3601                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to WAKE UP\n"));\r
3602                 pBtCoexist->bStopCoexDm = FALSE;\r
3603                 halbtc8723b1ant_InitHwConfig(pBtCoexist, FALSE);\r
3604                 halbtc8723b1ant_InitCoexDm(pBtCoexist);\r
3605                 halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
3606         }\r
3607 }\r
3608 \r
3609 VOID\r
3610 EXhalbtc8723b1ant_CoexDmReset(\r
3611         IN      PBTC_COEXIST                    pBtCoexist\r
3612         )\r
3613 {\r
3614         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], *****************Coex DM Reset*****************\n"));\r
3615 \r
3616         halbtc8723b1ant_InitHwConfig(pBtCoexist, FALSE);\r
3617         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3618         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x2, 0xfffff, 0x0);\r
3619         halbtc8723b1ant_InitCoexDm(pBtCoexist);\r
3620 }\r
3621 \r
3622 VOID\r
3623 EXhalbtc8723b1ant_Periodical(\r
3624         IN      PBTC_COEXIST                    pBtCoexist\r
3625         )\r
3626 {\r
3627         static u1Byte           disVerInfoCnt=0;\r
3628         u4Byte                          fwVer=0, btPatchVer=0;\r
3629         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3630         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
3631 \r
3632         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ==========================Periodical===========================\n"));\r
3633 \r
3634         if(disVerInfoCnt <= 5)\r
3635         {\r
3636                 disVerInfoCnt += 1;\r
3637                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
3638                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n", \\r
3639                         pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));\r
3640                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n", \\r
3641                         ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));\r
3642                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
3643                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
3644                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", \\r
3645                         GLCoexVerDate8723b1Ant, GLCoexVer8723b1Ant, fwVer, btPatchVer, btPatchVer));\r
3646                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
3647         }\r
3648 \r
3649 #if(BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)\r
3650         halbtc8723b1ant_QueryBtInfo(pBtCoexist);\r
3651         halbtc8723b1ant_MonitorBtCtr(pBtCoexist);\r
3652         halbtc8723b1ant_MonitorBtEnableDisable(pBtCoexist);\r
3653 #else\r
3654         if( halbtc8723b1ant_IsWifiStatusChanged(pBtCoexist) ||\r
3655                 pCoexDm->bAutoTdmaAdjust )\r
3656         {\r
3657                 //if(pCoexSta->specialPktPeriodCnt > 2)\r
3658                 //{\r
3659                         halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);        \r
3660                 //}\r
3661         }\r
3662 \r
3663         pCoexSta->specialPktPeriodCnt++;\r
3664 #endif\r
3665 }\r
3666 \r
3667 \r
3668 #endif\r
3669 \r