support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8189es / hal / OUTSRC-BTCoexist / HalBtc8821a1Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for 8821A_1ANT 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_8821A_1ANT               GLCoexDm8821a1Ant;\r
20 static PCOEX_DM_8821A_1ANT      pCoexDm=&GLCoexDm8821a1Ant;\r
21 static COEX_STA_8821A_1ANT              GLCoexSta8821a1Ant;\r
22 static PCOEX_STA_8821A_1ANT     pCoexSta=&GLCoexSta8821a1Ant;\r
23 \r
24 const char *const GLBtInfoSrc8821a1Ant[]={\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  GLCoexVerDate8821a1Ant=20140306;\r
31 u4Byte  GLCoexVer8821a1Ant=0x4b;\r
32 \r
33 //============================================================\r
34 // local function proto type if needed\r
35 //============================================================\r
36 //============================================================\r
37 // local function start with halbtc8821a1ant_\r
38 //============================================================\r
39 u1Byte\r
40 halbtc8821a1ant_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_8821A_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_8821A_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_8821A_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 halbtc8821a1ant_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_8821A_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_8821A_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_8821A_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 halbtc8821a1ant_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 halbtc8821a1ant_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 halbtc8821a1ant_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 halbtc8821a1ant_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 halbtc8821a1ant_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                         halbtc8821a1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);\r
371                         break;\r
372                 case 1: // disable cck 1/2\r
373                         halbtc8821a1ant_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                         halbtc8821a1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);\r
377                         break;\r
378                 default:\r
379                         break;\r
380         }\r
381 \r
382         halbtc8821a1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);\r
383         halbtc8821a1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);\r
384         halbtc8821a1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);\r
385 }\r
386 \r
387 VOID\r
388 halbtc8821a1ant_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 halbtc8821a1ant_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 #if 0\r
424         //to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS\r
425         if (! (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) & 0x8) ) \r
426         {\r
427                 pCoexSta->highPriorityTx = 65535;\r
428                 pCoexSta->highPriorityRx = 65535;\r
429                 pCoexSta->lowPriorityTx = 65535;\r
430                 pCoexSta->lowPriorityRx = 65535;\r
431                 return;\r
432         }\r
433 #endif  \r
434         regHPTxRx = 0x770;\r
435         regLPTxRx = 0x774;\r
436 \r
437         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
438         regHPTx = u4Tmp & bMaskLWord;\r
439         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
440 \r
441         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
442         regLPTx = u4Tmp & bMaskLWord;\r
443         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
444                 \r
445         pCoexSta->highPriorityTx = regHPTx;\r
446         pCoexSta->highPriorityRx = regHPRx;\r
447         pCoexSta->lowPriorityTx = regLPTx;\r
448         pCoexSta->lowPriorityRx = regLPRx;\r
449 \r
450         // reset counter\r
451         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
452 }\r
453 \r
454 VOID\r
455 halbtc8821a1ant_QueryBtInfo(\r
456         IN      PBTC_COEXIST            pBtCoexist\r
457         )\r
458 {\r
459         u1Byte                  H2C_Parameter[1] ={0};\r
460 \r
461         pCoexSta->bC2hBtInfoReqSent = TRUE;\r
462 \r
463         H2C_Parameter[0] |= BIT0;       // trigger\r
464 \r
465         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n", \r
466                 H2C_Parameter[0]));\r
467 \r
468         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);\r
469 }\r
470 \r
471 BOOLEAN\r
472 halbtc8821a1ant_IsWifiStatusChanged(\r
473         IN      PBTC_COEXIST            pBtCoexist\r
474         )\r
475 {\r
476         static BOOLEAN  bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;\r
477         BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;\r
478         BOOLEAN bWifiConnected=FALSE;\r
479 \r
480         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
481         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
482         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
483         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
484 \r
485         if(bWifiConnected)\r
486         {\r
487                 if(bWifiBusy != bPreWifiBusy)\r
488                 {\r
489                         bPreWifiBusy = bWifiBusy;\r
490                         return TRUE;\r
491                 }\r
492                 if(bUnder4way != bPreUnder4way)\r
493                 {\r
494                         bPreUnder4way = bUnder4way;\r
495                         return TRUE;\r
496                 }\r
497                 if(bBtHsOn != bPreBtHsOn)\r
498                 {\r
499                         bPreBtHsOn = bBtHsOn;\r
500                         return TRUE;\r
501                 }\r
502         }\r
503 \r
504         return FALSE;\r
505 }\r
506 \r
507 VOID\r
508 halbtc8821a1ant_UpdateBtLinkInfo(\r
509         IN      PBTC_COEXIST            pBtCoexist\r
510         )\r
511 {\r
512         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
513         BOOLEAN                         bBtHsOn=FALSE;\r
514 \r
515         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
516 \r
517         pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;\r
518         pBtLinkInfo->bScoExist = pCoexSta->bScoExist;\r
519         pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;\r
520         pBtLinkInfo->bPanExist = pCoexSta->bPanExist;\r
521         pBtLinkInfo->bHidExist = pCoexSta->bHidExist;\r
522 \r
523         // work around for HS mode.\r
524         if(bBtHsOn)\r
525         {\r
526                 pBtLinkInfo->bPanExist = TRUE;\r
527                 pBtLinkInfo->bBtLinkExist = TRUE;\r
528         }\r
529 \r
530         // check if Sco only\r
531         if( pBtLinkInfo->bScoExist &&\r
532                 !pBtLinkInfo->bA2dpExist &&\r
533                 !pBtLinkInfo->bPanExist &&\r
534                 !pBtLinkInfo->bHidExist )\r
535                 pBtLinkInfo->bScoOnly = TRUE;\r
536         else\r
537                 pBtLinkInfo->bScoOnly = FALSE;\r
538 \r
539         // check if A2dp only\r
540         if( !pBtLinkInfo->bScoExist &&\r
541                 pBtLinkInfo->bA2dpExist &&\r
542                 !pBtLinkInfo->bPanExist &&\r
543                 !pBtLinkInfo->bHidExist )\r
544                 pBtLinkInfo->bA2dpOnly = TRUE;\r
545         else\r
546                 pBtLinkInfo->bA2dpOnly = FALSE;\r
547 \r
548         // check if Pan only\r
549         if( !pBtLinkInfo->bScoExist &&\r
550                 !pBtLinkInfo->bA2dpExist &&\r
551                 pBtLinkInfo->bPanExist &&\r
552                 !pBtLinkInfo->bHidExist )\r
553                 pBtLinkInfo->bPanOnly = TRUE;\r
554         else\r
555                 pBtLinkInfo->bPanOnly = FALSE;\r
556         \r
557         // check if Hid only\r
558         if( !pBtLinkInfo->bScoExist &&\r
559                 !pBtLinkInfo->bA2dpExist &&\r
560                 !pBtLinkInfo->bPanExist &&\r
561                 pBtLinkInfo->bHidExist )\r
562                 pBtLinkInfo->bHidOnly = TRUE;\r
563         else\r
564                 pBtLinkInfo->bHidOnly = FALSE;\r
565 }\r
566 \r
567 u1Byte\r
568 halbtc8821a1ant_ActionAlgorithm(\r
569         IN      PBTC_COEXIST            pBtCoexist\r
570         )\r
571 {\r
572         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
573         BOOLEAN                         bBtHsOn=FALSE;\r
574         u1Byte                          algorithm=BT_8821A_1ANT_COEX_ALGO_UNDEFINED;\r
575         u1Byte                          numOfDiffProfile=0;\r
576 \r
577         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
578 \r
579         if(!pBtLinkInfo->bBtLinkExist)\r
580         {\r
581                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No BT link exists!!!\n"));\r
582                 return algorithm;\r
583         }\r
584 \r
585         if(pBtLinkInfo->bScoExist)\r
586                 numOfDiffProfile++;\r
587         if(pBtLinkInfo->bHidExist)\r
588                 numOfDiffProfile++;\r
589         if(pBtLinkInfo->bPanExist)\r
590                 numOfDiffProfile++;\r
591         if(pBtLinkInfo->bA2dpExist)\r
592                 numOfDiffProfile++;\r
593         \r
594         if(numOfDiffProfile == 1)\r
595         {\r
596                 if(pBtLinkInfo->bScoExist)\r
597                 {\r
598                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO only\n"));\r
599                         algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;\r
600                 }\r
601                 else\r
602                 {\r
603                         if(pBtLinkInfo->bHidExist)\r
604                         {\r
605                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID only\n"));\r
606                                 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;\r
607                         }\r
608                         else if(pBtLinkInfo->bA2dpExist)\r
609                         {\r
610                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP only\n"));\r
611                                 algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP;\r
612                         }\r
613                         else if(pBtLinkInfo->bPanExist)\r
614                         {\r
615                                 if(bBtHsOn)\r
616                                 {\r
617                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = PAN(HS) only\n"));\r
618                                         algorithm = BT_8821A_1ANT_COEX_ALGO_PANHS;\r
619                                 }\r
620                                 else\r
621                                 {\r
622                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = PAN(EDR) only\n"));\r
623                                         algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR;\r
624                                 }\r
625                         }\r
626                 }\r
627         }\r
628         else if(numOfDiffProfile == 2)\r
629         {\r
630                 if(pBtLinkInfo->bScoExist)\r
631                 {\r
632                         if(pBtLinkInfo->bHidExist)\r
633                         {\r
634                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID\n"));\r
635                                 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;\r
636                         }\r
637                         else if(pBtLinkInfo->bA2dpExist)\r
638                         {\r
639                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"));\r
640                                 algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;\r
641                         }\r
642                         else if(pBtLinkInfo->bPanExist)\r
643                         {\r
644                                 if(bBtHsOn)\r
645                                 {\r
646                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + PAN(HS)\n"));\r
647                                         algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;\r
648                                 }\r
649                                 else\r
650                                 {\r
651                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + PAN(EDR)\n"));\r
652                                         algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;\r
653                                 }\r
654                         }\r
655                 }\r
656                 else\r
657                 {\r
658                         if( pBtLinkInfo->bHidExist &&\r
659                                 pBtLinkInfo->bA2dpExist )\r
660                         {\r
661                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP\n"));\r
662                                 algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;\r
663                         }\r
664                         else if( pBtLinkInfo->bHidExist &&\r
665                                 pBtLinkInfo->bPanExist )\r
666                         {\r
667                                 if(bBtHsOn)\r
668                                 {\r
669                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + PAN(HS)\n"));\r
670                                         algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;\r
671                                 }\r
672                                 else\r
673                                 {\r
674                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + PAN(EDR)\n"));\r
675                                         algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;\r
676                                 }\r
677                         }\r
678                         else if( pBtLinkInfo->bPanExist &&\r
679                                 pBtLinkInfo->bA2dpExist )\r
680                         {\r
681                                 if(bBtHsOn)\r
682                                 {\r
683                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP + PAN(HS)\n"));\r
684                                         algorithm = BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS;\r
685                                 }\r
686                                 else\r
687                                 {\r
688                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = A2DP + PAN(EDR)\n"));\r
689                                         algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP;\r
690                                 }\r
691                         }\r
692                 }\r
693         }\r
694         else if(numOfDiffProfile == 3)\r
695         {\r
696                 if(pBtLinkInfo->bScoExist)\r
697                 {\r
698                         if( pBtLinkInfo->bHidExist &&\r
699                                 pBtLinkInfo->bA2dpExist )\r
700                         {\r
701                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"));\r
702                                 algorithm = BT_8821A_1ANT_COEX_ALGO_HID;\r
703                         }\r
704                         else if( pBtLinkInfo->bHidExist &&\r
705                                 pBtLinkInfo->bPanExist )\r
706                         {\r
707                                 if(bBtHsOn)\r
708                                 {\r
709                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"));\r
710                                         algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;\r
711                                 }\r
712                                 else\r
713                                 {\r
714                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"));\r
715                                         algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;\r
716                                 }\r
717                         }\r
718                         else if( pBtLinkInfo->bPanExist &&\r
719                                 pBtLinkInfo->bA2dpExist )\r
720                         {\r
721                                 if(bBtHsOn)\r
722                                 {\r
723                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"));\r
724                                         algorithm = BT_8821A_1ANT_COEX_ALGO_SCO;\r
725                                 }\r
726                                 else\r
727                                 {\r
728                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"));\r
729                                         algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;\r
730                                 }\r
731                         }\r
732                 }\r
733                 else\r
734                 {\r
735                         if( pBtLinkInfo->bHidExist &&\r
736                                 pBtLinkInfo->bPanExist &&\r
737                                 pBtLinkInfo->bA2dpExist )\r
738                         {\r
739                                 if(bBtHsOn)\r
740                                 {\r
741                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"));\r
742                                         algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP;\r
743                                 }\r
744                                 else\r
745                                 {\r
746                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"));\r
747                                         algorithm = BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
748                                 }\r
749                         }\r
750                 }\r
751         }\r
752         else if(numOfDiffProfile >= 3)\r
753         {\r
754                 if(pBtLinkInfo->bScoExist)\r
755                 {\r
756                         if( pBtLinkInfo->bHidExist &&\r
757                                 pBtLinkInfo->bPanExist &&\r
758                                 pBtLinkInfo->bA2dpExist )\r
759                         {\r
760                                 if(bBtHsOn)\r
761                                 {\r
762                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"));\r
763 \r
764                                 }\r
765                                 else\r
766                                 {\r
767                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
768                                         algorithm = BT_8821A_1ANT_COEX_ALGO_PANEDR_HID;\r
769                                 }\r
770                         }\r
771                 }\r
772         }\r
773 \r
774         return algorithm;\r
775 }\r
776 \r
777 VOID\r
778 halbtc8821a1ant_SetBtAutoReport(\r
779         IN      PBTC_COEXIST            pBtCoexist,\r
780         IN      BOOLEAN                 bEnableAutoReport\r
781         )\r
782 {\r
783         u1Byte                  H2C_Parameter[1] ={0};\r
784         \r
785         H2C_Parameter[0] = 0;\r
786 \r
787         if(bEnableAutoReport)\r
788         {\r
789                 H2C_Parameter[0] |= BIT0;\r
790         }\r
791 \r
792         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n", \r
793                 (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));\r
794 \r
795         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);    \r
796 }\r
797 \r
798 VOID\r
799 halbtc8821a1ant_BtAutoReport(\r
800         IN      PBTC_COEXIST            pBtCoexist,\r
801         IN      BOOLEAN                 bForceExec,\r
802         IN      BOOLEAN                 bEnableAutoReport\r
803         )\r
804 {\r
805         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s BT Auto report = %s\n",  \r
806                 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));\r
807         pCoexDm->bCurBtAutoReport = bEnableAutoReport;\r
808 \r
809         if(!bForceExec)\r
810         {\r
811                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreBtAutoReport=%d, bCurBtAutoReport=%d\n", \r
812                         pCoexDm->bPreBtAutoReport, pCoexDm->bCurBtAutoReport));\r
813 \r
814                 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport) \r
815                         return;\r
816         }\r
817         halbtc8821a1ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);\r
818 \r
819         pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;\r
820 }\r
821 \r
822 VOID\r
823 halbtc8821a1ant_SetSwPenaltyTxRateAdaptive(\r
824         IN      PBTC_COEXIST            pBtCoexist,\r
825         IN      BOOLEAN                 bLowPenaltyRa\r
826         )\r
827 {\r
828         u1Byte                  H2C_Parameter[6] ={0};\r
829         \r
830         H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty\r
831 \r
832         if(bLowPenaltyRa)\r
833         {\r
834                 H2C_Parameter[1] |= BIT0;\r
835                 H2C_Parameter[2] = 0x00;  //normal rate except MCS7/6/5, OFDM54/48/36\r
836                 H2C_Parameter[3] = 0xf7;  //MCS7 or OFDM54\r
837                 H2C_Parameter[4] = 0xf8;  //MCS6 or OFDM48\r
838                 H2C_Parameter[5] = 0xf9;        //MCS5 or OFDM36        \r
839         }\r
840 \r
841         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set WiFi Low-Penalty Retry: %s", \r
842                 (bLowPenaltyRa? "ON!!":"OFF!!") ));\r
843 \r
844         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);\r
845 }\r
846 \r
847 VOID\r
848 halbtc8821a1ant_LowPenaltyRa(\r
849         IN      PBTC_COEXIST            pBtCoexist,\r
850         IN      BOOLEAN                 bForceExec,\r
851         IN      BOOLEAN                 bLowPenaltyRa\r
852         )\r
853 {\r
854         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
855 \r
856         if(!bForceExec)\r
857         {\r
858                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
859                         return;\r
860         }\r
861         halbtc8821a1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
862 \r
863         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
864 }\r
865 \r
866 VOID\r
867 halbtc8821a1ant_SetCoexTable(\r
868         IN      PBTC_COEXIST    pBtCoexist,\r
869         IN      u4Byte          val0x6c0,\r
870         IN      u4Byte          val0x6c4,\r
871         IN      u4Byte          val0x6c8,\r
872         IN      u1Byte          val0x6cc\r
873         )\r
874 {\r
875         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
876         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
877 \r
878         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));\r
879         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);\r
880 \r
881         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
882         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
883 \r
884         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
885         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
886 }\r
887 \r
888 VOID\r
889 halbtc8821a1ant_CoexTable(\r
890         IN      PBTC_COEXIST            pBtCoexist,\r
891         IN      BOOLEAN                 bForceExec,\r
892         IN      u4Byte                  val0x6c0,\r
893         IN      u4Byte                  val0x6c4,\r
894         IN      u4Byte                  val0x6c8,\r
895         IN      u1Byte                  val0x6cc\r
896         )\r
897 {\r
898         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", \r
899                 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6c8, val0x6cc));\r
900         pCoexDm->curVal0x6c0 = val0x6c0;\r
901         pCoexDm->curVal0x6c4 = val0x6c4;\r
902         pCoexDm->curVal0x6c8 = val0x6c8;\r
903         pCoexDm->curVal0x6cc = val0x6cc;\r
904 \r
905         if(!bForceExec)\r
906         {\r
907                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
908                         (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&\r
909                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
910                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
911                         return;\r
912         }\r
913         halbtc8821a1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);\r
914 \r
915         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
916         pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;\r
917         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
918         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
919 }\r
920 \r
921 VOID\r
922 halbtc8821a1ant_CoexTableWithType(\r
923         IN      PBTC_COEXIST            pBtCoexist,\r
924         IN      BOOLEAN                         bForceExec,\r
925         IN      u1Byte                          type\r
926         )\r
927 {\r
928         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ********** CoexTable(%d) **********\n", type));\r
929         \r
930         switch(type)\r
931         {\r
932                 case 0:\r
933                         halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3);\r
934                         break;\r
935                 case 1:\r
936                         halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);\r
937                         break;\r
938                 case 2:\r
939                         halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);\r
940                         break;\r
941                 case 3:\r
942                         halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaaaaaa, 0xffffff, 0x3);\r
943                         break;\r
944                 case 4:\r
945                         halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);\r
946                         break;\r
947                 case 5:\r
948                         halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3);\r
949                         break;\r
950                 case 6:\r
951                         halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);\r
952                         break;\r
953                 case 7:\r
954                         halbtc8821a1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);\r
955                         break;\r
956                 default:\r
957                         break;\r
958         }\r
959 }\r
960 \r
961 VOID\r
962 halbtc8821a1ant_SetFwIgnoreWlanAct(\r
963         IN      PBTC_COEXIST            pBtCoexist,\r
964         IN      BOOLEAN                 bEnable\r
965         )\r
966 {\r
967         u1Byte                  H2C_Parameter[1] ={0};\r
968                 \r
969         if(bEnable)\r
970         {\r
971                 H2C_Parameter[0] |= BIT0;               // function enable\r
972         }\r
973         \r
974         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", \r
975                 H2C_Parameter[0]));\r
976 \r
977         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);\r
978 }\r
979 \r
980 VOID\r
981 halbtc8821a1ant_IgnoreWlanAct(\r
982         IN      PBTC_COEXIST            pBtCoexist,\r
983         IN      BOOLEAN                 bForceExec,\r
984         IN      BOOLEAN                 bEnable\r
985         )\r
986 {\r
987         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
988                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
989         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
990 \r
991         if(!bForceExec)\r
992         {\r
993                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", \r
994                         pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));\r
995 \r
996                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
997                         return;\r
998         }\r
999         halbtc8821a1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
1000 \r
1001         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
1002 }\r
1003 \r
1004 VOID\r
1005 halbtc8821a1ant_SetFwPstdma(\r
1006         IN      PBTC_COEXIST            pBtCoexist,\r
1007         IN      u1Byte                  byte1,\r
1008         IN      u1Byte                  byte2,\r
1009         IN      u1Byte                  byte3,\r
1010         IN      u1Byte                  byte4,\r
1011         IN      u1Byte                  byte5\r
1012         )\r
1013 {\r
1014         u1Byte                  H2C_Parameter[5] ={0};\r
1015         u1Byte                  realByte1=byte1, realByte5=byte5;\r
1016         BOOLEAN                 bApEnable=FALSE;\r
1017 \r
1018         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
1019 \r
1020         if(bApEnable)\r
1021         {\r
1022                 if(byte1&BIT4 && !(byte1&BIT5))\r
1023                 {                       \r
1024                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], FW for 1Ant AP mode\n"));\r
1025                         realByte1 &= ~BIT4;\r
1026                         realByte1 |= BIT5;\r
1027 \r
1028                         realByte5 |= BIT5;\r
1029                         realByte5 &= ~BIT6;\r
1030                 }\r
1031         }\r
1032 \r
1033         H2C_Parameter[0] = realByte1;   \r
1034         H2C_Parameter[1] = byte2;       \r
1035         H2C_Parameter[2] = byte3;\r
1036         H2C_Parameter[3] = byte4;\r
1037         H2C_Parameter[4] = realByte5;\r
1038 \r
1039         pCoexDm->psTdmaPara[0] = realByte1;\r
1040         pCoexDm->psTdmaPara[1] = byte2;\r
1041         pCoexDm->psTdmaPara[2] = byte3;\r
1042         pCoexDm->psTdmaPara[3] = byte4;\r
1043         pCoexDm->psTdmaPara[4] = realByte5;\r
1044         \r
1045         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n", \r
1046                 H2C_Parameter[0], \r
1047                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
1048 \r
1049         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);\r
1050 }\r
1051 \r
1052 VOID\r
1053 halbtc8821a1ant_SetLpsRpwm(\r
1054         IN      PBTC_COEXIST            pBtCoexist,\r
1055         IN      u1Byte                  lpsVal,\r
1056         IN      u1Byte                  rpwmVal\r
1057         )\r
1058 {\r
1059         u1Byte  lps=lpsVal;\r
1060         u1Byte  rpwm=rpwmVal;\r
1061         \r
1062         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);\r
1063         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);\r
1064 }\r
1065 \r
1066 VOID\r
1067 halbtc8821a1ant_LpsRpwm(\r
1068         IN      PBTC_COEXIST            pBtCoexist,\r
1069         IN      BOOLEAN                 bForceExec,\r
1070         IN      u1Byte                  lpsVal,\r
1071         IN      u1Byte                  rpwmVal\r
1072         )\r
1073 {\r
1074         BOOLEAN bForceExecPwrCmd=FALSE;\r
1075         \r
1076         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n", \r
1077                 (bForceExec? "force to":""), lpsVal, rpwmVal));\r
1078         pCoexDm->curLps = lpsVal;\r
1079         pCoexDm->curRpwm = rpwmVal;\r
1080 \r
1081         if(!bForceExec)\r
1082         {\r
1083                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], LPS-RxBeaconMode=0x%x , LPS-RPWM=0x%x!!\n", \r
1084                          pCoexDm->curLps, pCoexDm->curRpwm));\r
1085 \r
1086                 if( (pCoexDm->preLps == pCoexDm->curLps) &&\r
1087                         (pCoexDm->preRpwm == pCoexDm->curRpwm) )\r
1088                 {\r
1089                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], LPS-RPWM_Last=0x%x , LPS-RPWM_Now=0x%x!!\n", \r
1090                                  pCoexDm->preRpwm, pCoexDm->curRpwm));\r
1091 \r
1092                         return;\r
1093                 }\r
1094         }\r
1095         halbtc8821a1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);\r
1096 \r
1097         pCoexDm->preLps = pCoexDm->curLps;\r
1098         pCoexDm->preRpwm = pCoexDm->curRpwm;\r
1099 }\r
1100 \r
1101 VOID\r
1102 halbtc8821a1ant_SwMechanism(\r
1103         IN      PBTC_COEXIST    pBtCoexist,     \r
1104         IN      BOOLEAN         bLowPenaltyRA\r
1105         ) \r
1106 {\r
1107         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], SM[LpRA] = %d\n", \r
1108                 bLowPenaltyRA));\r
1109         \r
1110         halbtc8821a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);\r
1111 }\r
1112 \r
1113 VOID\r
1114 halbtc8821a1ant_SetAntPath(\r
1115         IN      PBTC_COEXIST            pBtCoexist,\r
1116         IN      u1Byte                          antPosType,\r
1117         IN      BOOLEAN                         bInitHwCfg,\r
1118         IN      BOOLEAN                         bWifiOff\r
1119         )\r
1120 {\r
1121         PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;\r
1122         u4Byte                  fwVer=0, u4Tmp=0;\r
1123         u1Byte                  H2C_Parameter[2] ={0};\r
1124         \r
1125         if(bInitHwCfg)\r
1126         {\r
1127                 // 0x4c[23]=0, 0x4c[24]=1  Antenna control by WL/BT\r
1128                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1129                 u4Tmp &=~BIT23;\r
1130                 u4Tmp |= BIT24;\r
1131                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1132 \r
1133                 //0x765 = 0x18\r
1134                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x765, 0x18, 0x3);        \r
1135 \r
1136                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) \r
1137                 {\r
1138                         //tell firmware "antenna inverse"  ==> WRONG firmware antenna control code.==>need fw to fix\r
1139                         H2C_Parameter[0] = 1;\r
1140                         H2C_Parameter[1] = 1;\r
1141                         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);\r
1142 \r
1143                         //pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x1); //Main Ant to  BT for IPS case 0x4c[23]=1\r
1144                 }\r
1145                 else\r
1146                 {\r
1147                         //tell firmware "no antenna inverse" ==> WRONG firmware antenna control code.==>need fw to fix\r
1148                         H2C_Parameter[0] = 0;\r
1149                         H2C_Parameter[1] = 1;\r
1150                         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);\r
1151 \r
1152                         //pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); //Aux Ant to  BT for IPS case 0x4c[23]=1\r
1153                 }\r
1154         }\r
1155         else if(bWifiOff)\r
1156         {\r
1157                 // 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL   BT Vendor 0xac=0xf002\r
1158                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1159                 u4Tmp &= ~BIT23;\r
1160                 u4Tmp &= ~BIT24;\r
1161                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1162 \r
1163                 //0x765 = 0x18\r
1164                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x765, 0x18, 0x3); \r
1165         }\r
1166         else\r
1167         {\r
1168                 //0x765 = 0x0\r
1169                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x765, 0x18, 0x0); \r
1170         }\r
1171         \r
1172         // ext switch setting\r
1173         switch(antPosType)\r
1174         {\r
1175                 case BTC_ANT_PATH_WIFI:\r
1176                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb4, 0x77);\r
1177                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1178                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x1);\r
1179                         else\r
1180                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x2);\r
1181                         break;\r
1182                 case BTC_ANT_PATH_BT:\r
1183                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb4, 0x77);\r
1184                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1185                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x2);\r
1186                         else\r
1187                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x1);\r
1188                         break;\r
1189                 default:\r
1190                 case BTC_ANT_PATH_PTA:\r
1191                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb4, 0x66);\r
1192                         if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1193                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x1);\r
1194                         else\r
1195                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xcb7, 0x30, 0x2);\r
1196                         break;\r
1197         }\r
1198 }\r
1199 \r
1200 VOID\r
1201 halbtc8821a1ant_PsTdma(\r
1202         IN      PBTC_COEXIST            pBtCoexist,\r
1203         IN      BOOLEAN                 bForceExec,\r
1204         IN      BOOLEAN                 bTurnOn,\r
1205         IN      u1Byte                  type\r
1206         )\r
1207 {\r
1208         PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;\r
1209         BOOLEAN                 bTurnOnByCnt=FALSE;\r
1210         u1Byte                  psTdmaTypeByCnt=0, rssiAdjustVal=0;\r
1211         //u4Byte                        fwVer=0;\r
1212 \r
1213         pCoexDm->bCurPsTdmaOn = bTurnOn;\r
1214         pCoexDm->curPsTdma = type;\r
1215 \r
1216         if (pCoexDm->bCurPsTdmaOn)\r
1217         {\r
1218                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ********** TDMA(on, %d) **********\n", \r
1219                         pCoexDm->curPsTdma));\r
1220         }\r
1221         else\r
1222         {\r
1223                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ********** TDMA(off, %d) **********\n", \r
1224                         pCoexDm->curPsTdma));\r
1225         }\r
1226 \r
1227         if(!bForceExec)\r
1228         {\r
1229                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
1230                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
1231                         return;\r
1232         }\r
1233         if(bTurnOn)\r
1234         {\r
1235                 switch(type)\r
1236                 {\r
1237                         default:\r
1238                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, 0x50);\r
1239                                 break;\r
1240                         case 1:\r
1241                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x3a, 0x03, 0x10, 0x50);\r
1242                                 rssiAdjustVal = 11;\r
1243                                 break;\r
1244                         case 2:\r
1245                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x2b, 0x03, 0x10, 0x50);\r
1246                                 rssiAdjustVal = 14;\r
1247                                 break;\r
1248                         case 3:\r
1249                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, 0x52);\r
1250                                 break;\r
1251                         case 4:\r
1252                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);\r
1253                                 rssiAdjustVal = 17;\r
1254                                 break;\r
1255                         case 5:\r
1256                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x15, 0x3, 0x11, 0x10);\r
1257                                 break;\r
1258                         case 6:\r
1259                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x20, 0x3, 0x11, 0x13);\r
1260                                 break;\r
1261                         case 7:\r
1262                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);\r
1263                                 break;\r
1264                         case 8: \r
1265                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
1266                                 break;\r
1267                         case 9: \r
1268                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x21, 0x3, 0x10, 0x50);\r
1269                                 rssiAdjustVal = 18;\r
1270                                 break;\r
1271                         case 10:        \r
1272                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);\r
1273                                 break;\r
1274                         case 11:        \r
1275                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x15, 0x03, 0x10, 0x50);\r
1276                                 rssiAdjustVal = 20;\r
1277                                 break;\r
1278                         case 12:\r
1279                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50);\r
1280                                 break;\r
1281                         case 13:\r
1282                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x12, 0x12, 0x0, 0x50);\r
1283                                 break;\r
1284                         case 14:\r
1285                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x21, 0x3, 0x10, 0x52);\r
1286                                 break;\r
1287                         case 15:\r
1288                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);\r
1289                                 break;\r
1290                         case 16:\r
1291                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);\r
1292                                 rssiAdjustVal = 18;\r
1293                                 break;\r
1294                         case 18:\r
1295                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
1296                                 rssiAdjustVal = 14;\r
1297                                 break;                  \r
1298                         case 20:\r
1299                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x35, 0x03, 0x11, 0x10);\r
1300                                 break;\r
1301                         case 21:\r
1302                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11);\r
1303                                 break;\r
1304                         case 22:\r
1305                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x10);\r
1306                                 break;\r
1307                         case 23:\r
1308                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);\r
1309                                 rssiAdjustVal = 22;\r
1310                                 break;\r
1311                         case 24:\r
1312                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);\r
1313                                 rssiAdjustVal = 22;\r
1314                                 break;\r
1315                         case 25:\r
1316                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
1317                                 rssiAdjustVal = 22;\r
1318                                 break;\r
1319                         case 26:\r
1320                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
1321                                 rssiAdjustVal = 22;\r
1322                                 break;\r
1323                         case 27:\r
1324                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);\r
1325                                 rssiAdjustVal = 22;\r
1326                                 break;\r
1327                         case 28:\r
1328                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);\r
1329                                 break;\r
1330                         case 29:\r
1331                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);\r
1332                                 break;\r
1333                         case 30:\r
1334                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10);\r
1335                                 break;\r
1336                         case 31:\r
1337                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);\r
1338                                 break;\r
1339                         case 32:\r
1340                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x35, 0x3, 0x11, 0x11);\r
1341                                 break;\r
1342                         case 33:\r
1343                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90);\r
1344                                 break;\r
1345                         case 34:\r
1346                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10);\r
1347                                 break;\r
1348                         case 35:\r
1349                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10);\r
1350                                 break;\r
1351                         case 36:\r
1352                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);\r
1353                                 break;\r
1354                         case 40: // SoftAP only with no sta associated,BT disable ,TDMA mode for power saving\r
1355                                 /* here softap mode screen off will cost 70-80mA for phone */\r
1356                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24);\r
1357                                 break;  \r
1358                 }\r
1359         }\r
1360         else\r
1361         {\r
1362                 // disable PS tdma\r
1363                 switch(type)\r
1364                 {\r
1365                         case 8: //PTA Control\r
1366                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);\r
1367                                 halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FALSE, FALSE);\r
1368                                 break;\r
1369                         case 0:\r
1370                         default:  //Software control, Antenna at BT side\r
1371                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1372                                 halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
1373                                 break;\r
1374                         case 9:   //Software control, Antenna at WiFi side\r
1375                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1376                                 halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FALSE, FALSE);\r
1377                                 break;\r
1378                         case 10:        // under 5G\r
1379                                 halbtc8821a1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);\r
1380                                 halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
1381                                 break;\r
1382                 }\r
1383         }\r
1384         rssiAdjustVal =0;\r
1385         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);\r
1386 \r
1387         // update pre state\r
1388         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1389         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1390 }\r
1391 \r
1392 VOID\r
1393 halbtc8821a1ant_CoexAllOff(\r
1394         IN      PBTC_COEXIST            pBtCoexist\r
1395         )\r
1396 {\r
1397         // sw all off\r
1398         halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1399 \r
1400         // hw all off\r
1401         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1402 }\r
1403 \r
1404 BOOLEAN\r
1405 halbtc8821a1ant_IsCommonAction(\r
1406         IN      PBTC_COEXIST            pBtCoexist\r
1407         )\r
1408 {\r
1409         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;\r
1410 \r
1411         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1412         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1413 \r
1414         if(!bWifiConnected && \r
1415                 BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
1416         {\r
1417                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));\r
1418                 halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1419 \r
1420                 bCommon = TRUE;\r
1421         }\r
1422         else if(bWifiConnected && \r
1423                         (BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1424         {\r
1425                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));\r
1426                 halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1427 \r
1428                 bCommon = TRUE;\r
1429         }\r
1430         else if(!bWifiConnected && \r
1431                 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1432         {\r
1433                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));\r
1434                 halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1435 \r
1436                 bCommon = TRUE;\r
1437         }\r
1438         else if(bWifiConnected && \r
1439                 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1440         {\r
1441                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));\r
1442                 halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1443 \r
1444                 bCommon = TRUE;\r
1445         }\r
1446         else if(!bWifiConnected && \r
1447                 (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus) )\r
1448         {\r
1449                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));\r
1450                 halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1451                 \r
1452                 bCommon = TRUE;\r
1453         }\r
1454         else\r
1455         {\r
1456                 if (bWifiBusy)                  \r
1457                 {\r
1458                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));\r
1459                 }\r
1460                 else\r
1461                 {\r
1462                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));\r
1463                 }\r
1464                 \r
1465                 bCommon = FALSE;\r
1466         }\r
1467         \r
1468         return bCommon;\r
1469 }\r
1470 \r
1471 \r
1472 VOID\r
1473 halbtc8821a1ant_TdmaDurationAdjustForAcl(\r
1474         IN      PBTC_COEXIST            pBtCoexist,\r
1475         IN      u1Byte                          wifiStatus\r
1476         )\r
1477 {\r
1478         static s4Byte           up,dn,m,n,WaitCount;\r
1479         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
1480         u1Byte                  retryCount=0, btInfoExt;\r
1481 \r
1482         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));\r
1483 \r
1484         if( (BT_8821A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||\r
1485                 (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||\r
1486                 (BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )\r
1487         {\r
1488                 if( pCoexDm->curPsTdma != 1 &&\r
1489                         pCoexDm->curPsTdma != 2 &&\r
1490                         pCoexDm->curPsTdma != 3 &&\r
1491                         pCoexDm->curPsTdma != 9 )\r
1492                 {\r
1493                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1494                         pCoexDm->psTdmaDuAdjType = 9;\r
1495 \r
1496                         up = 0;\r
1497                         dn = 0;\r
1498                         m = 1;\r
1499                         n= 3;\r
1500                         result = 0;\r
1501                         WaitCount = 0;\r
1502                 }               \r
1503                 return;\r
1504         }\r
1505         \r
1506         if(!pCoexDm->bAutoTdmaAdjust)\r
1507         {\r
1508                 pCoexDm->bAutoTdmaAdjust = TRUE;\r
1509                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
1510 \r
1511                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1512                 pCoexDm->psTdmaDuAdjType = 2;\r
1513                 //============\r
1514                 up = 0;\r
1515                 dn = 0;\r
1516                 m = 1;\r
1517                 n= 3;\r
1518                 result = 0;\r
1519                 WaitCount = 0;\r
1520         }\r
1521         else\r
1522         {\r
1523                 //accquire the BT TRx retry count from BT_Info byte2\r
1524                 retryCount = pCoexSta->btRetryCnt;\r
1525                 btInfoExt = pCoexSta->btInfoExt;\r
1526                 //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));\r
1527                 //BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
1528                 //      up, dn, m, n, WaitCount));\r
1529                 result = 0;\r
1530                 WaitCount++; \r
1531                   \r
1532                 if(retryCount == 0)  // no retry in the last 2-second duration\r
1533                 {\r
1534                         up++;\r
1535                         dn--;\r
1536 \r
1537                         if (dn <= 0)\r
1538                                 dn = 0;                          \r
1539 \r
1540                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
1541                         {\r
1542                                 WaitCount = 0; \r
1543                                 n = 3;\r
1544                                 up = 0;\r
1545                                 dn = 0;\r
1546                                 result = 1; \r
1547                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));\r
1548                         }\r
1549                 }\r
1550                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
1551                 {\r
1552                         up--; \r
1553                         dn++;\r
1554 \r
1555                         if (up <= 0)\r
1556                                 up = 0;\r
1557 \r
1558                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
1559                         {\r
1560                                 if (WaitCount <= 2)\r
1561                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1562                                 else\r
1563                                         m = 1;\r
1564 \r
1565                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1566                                         m = 20;\r
1567 \r
1568                                 n = 3*m;\r
1569                                 up = 0;\r
1570                                 dn = 0;\r
1571                                 WaitCount = 0;\r
1572                                 result = -1; \r
1573                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
1574                         }\r
1575                 }\r
1576                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
1577                 {\r
1578                         if (WaitCount == 1)\r
1579                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1580                         else\r
1581                                 m = 1;\r
1582 \r
1583                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1584                                 m = 20;\r
1585 \r
1586                         n = 3*m;\r
1587                         up = 0;\r
1588                         dn = 0;\r
1589                         WaitCount = 0; \r
1590                         result = -1;\r
1591                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
1592                 }\r
1593 \r
1594                 if(result == -1)\r
1595                 {\r
1596                         if( (BT_INFO_8821A_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
1597                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
1598                         {\r
1599                                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1600                                 pCoexDm->psTdmaDuAdjType = 9;\r
1601                         }\r
1602                         else if(pCoexDm->curPsTdma == 1)\r
1603                         {\r
1604                                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1605                                 pCoexDm->psTdmaDuAdjType = 2;\r
1606                         }\r
1607                         else if(pCoexDm->curPsTdma == 2)\r
1608                         {\r
1609                                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1610                                 pCoexDm->psTdmaDuAdjType = 9;\r
1611                         }\r
1612                         else if(pCoexDm->curPsTdma == 9)\r
1613                         {\r
1614                                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1615                                 pCoexDm->psTdmaDuAdjType = 11;\r
1616                         }\r
1617                 }\r
1618                 else if(result == 1)\r
1619                 {\r
1620                         if( (BT_INFO_8821A_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
1621                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
1622                         {\r
1623                                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1624                                 pCoexDm->psTdmaDuAdjType = 9;\r
1625                         }\r
1626                         else if(pCoexDm->curPsTdma == 11)\r
1627                         {\r
1628                                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1629                                 pCoexDm->psTdmaDuAdjType = 9;\r
1630                         }\r
1631                         else if(pCoexDm->curPsTdma == 9)\r
1632                         {\r
1633                                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1634                                 pCoexDm->psTdmaDuAdjType = 2;\r
1635                         }\r
1636                         else if(pCoexDm->curPsTdma == 2)\r
1637                         {\r
1638                                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1639                                 pCoexDm->psTdmaDuAdjType = 1;\r
1640                         }\r
1641                 }\r
1642                 else      //no change\r
1643                 {\r
1644                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], ********** TDMA(on, %d) **********\n", \r
1645                                 pCoexDm->curPsTdma));\r
1646                 }\r
1647 \r
1648                 if( pCoexDm->curPsTdma != 1 &&\r
1649                         pCoexDm->curPsTdma != 2 &&\r
1650                         pCoexDm->curPsTdma != 9 &&\r
1651                         pCoexDm->curPsTdma != 11 )\r
1652                 {\r
1653                         // recover to previous adjust type\r
1654                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
1655                 }\r
1656         }\r
1657 }\r
1658 \r
1659 VOID\r
1660 halbtc8821a1ant_PsTdmaCheckForPowerSaveState(\r
1661         IN      PBTC_COEXIST            pBtCoexist,\r
1662         IN      BOOLEAN                 bNewPsState\r
1663         )\r
1664 {\r
1665         u1Byte  lpsMode=0x0;\r
1666 \r
1667         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);\r
1668         \r
1669         if(lpsMode)     // already under LPS state\r
1670         {\r
1671                 if(bNewPsState)         \r
1672                 {\r
1673                         // keep state under LPS, do nothing.\r
1674                 }\r
1675                 else\r
1676                 {\r
1677                         // will leave LPS state, turn off psTdma first\r
1678                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1679                 }\r
1680         }\r
1681         else                                            // NO PS state\r
1682         {\r
1683                 if(bNewPsState)\r
1684                 {\r
1685                         // will enter LPS state, turn off psTdma first\r
1686                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1687                 }\r
1688                 else\r
1689                 {\r
1690                         // keep state under NO PS state, do nothing.\r
1691                 }\r
1692         }\r
1693 }\r
1694 \r
1695 VOID\r
1696 halbtc8821a1ant_PowerSaveState(\r
1697         IN      PBTC_COEXIST            pBtCoexist,\r
1698         IN      u1Byte                          psType,\r
1699         IN      u1Byte                          lpsVal,\r
1700         IN      u1Byte                          rpwmVal\r
1701         )\r
1702 {\r
1703         BOOLEAN         bLowPwrDisable=FALSE;\r
1704 \r
1705         switch(psType)\r
1706         {\r
1707                 case BTC_PS_WIFI_NATIVE:\r
1708                         // recover to original 32k low power setting\r
1709                         bLowPwrDisable = FALSE;\r
1710                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1711                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1712                         break;\r
1713                 case BTC_PS_LPS_ON:\r
1714                         halbtc8821a1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);\r
1715                         halbtc8821a1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);\r
1716                         // when coex force to enter LPS, do not enter 32k low power.\r
1717                         bLowPwrDisable = TRUE;\r
1718                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1719                         // power save must executed before psTdma.\r
1720                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);\r
1721                         break;\r
1722                 case BTC_PS_LPS_OFF:\r
1723                         halbtc8821a1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);\r
1724                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
1725                         break;\r
1726                 default:\r
1727                         break;\r
1728         }\r
1729 }\r
1730 \r
1731 VOID\r
1732 halbtc8821a1ant_CoexUnder5G(\r
1733         IN      PBTC_COEXIST            pBtCoexist\r
1734         )\r
1735 {\r
1736         halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1737 \r
1738         halbtc8821a1ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, TRUE);\r
1739 \r
1740         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 10);\r
1741 \r
1742         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1743 \r
1744         halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
1745 \r
1746         halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 5);\r
1747 }\r
1748 \r
1749 VOID\r
1750 halbtc8821a1ant_ActionWifiOnly(\r
1751         IN      PBTC_COEXIST            pBtCoexist\r
1752         )\r
1753 {\r
1754         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1755         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
1756 }\r
1757 \r
1758 VOID\r
1759 halbtc8821a1ant_MonitorBtEnableDisable(\r
1760         IN      PBTC_COEXIST            pBtCoexist\r
1761         )\r
1762 {\r
1763         static BOOLEAN  bPreBtDisabled=FALSE;\r
1764         static u4Byte           btDisableCnt=0;\r
1765         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
1766 \r
1767         // This function check if bt is disabled\r
1768 \r
1769         if(     pCoexSta->highPriorityTx == 0 &&\r
1770                 pCoexSta->highPriorityRx == 0 &&\r
1771                 pCoexSta->lowPriorityTx == 0 &&\r
1772                 pCoexSta->lowPriorityRx == 0)\r
1773         {\r
1774                 bBtActive = FALSE;\r
1775         }\r
1776         if(     pCoexSta->highPriorityTx == 0xffff &&\r
1777                 pCoexSta->highPriorityRx == 0xffff &&\r
1778                 pCoexSta->lowPriorityTx == 0xffff &&\r
1779                 pCoexSta->lowPriorityRx == 0xffff)\r
1780         {\r
1781                 bBtActive = FALSE;\r
1782         }\r
1783         if(bBtActive)\r
1784         {\r
1785                 btDisableCnt = 0;\r
1786                 bBtDisabled = FALSE;\r
1787                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1788                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is enabled !!\n"));\r
1789         }\r
1790         else\r
1791         {\r
1792                 btDisableCnt++;\r
1793                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], bt all counters=0, %d times!!\n", \r
1794                                 btDisableCnt));\r
1795                 if(btDisableCnt >= 2)\r
1796                 {\r
1797                         bBtDisabled = TRUE;\r
1798                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1799                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is disabled !!\n"));\r
1800                         halbtc8821a1ant_ActionWifiOnly(pBtCoexist);\r
1801                 }\r
1802         }\r
1803         if(bPreBtDisabled != bBtDisabled)\r
1804         {\r
1805                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is from %s to %s!!\n", \r
1806                         (bPreBtDisabled ? "disabled":"enabled"), \r
1807                         (bBtDisabled ? "disabled":"enabled")));\r
1808                 bPreBtDisabled = bBtDisabled;\r
1809                 if(!bBtDisabled)\r
1810                 {\r
1811                 }\r
1812                 else\r
1813                 {\r
1814                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
1815                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1816                 }\r
1817         }\r
1818 }\r
1819 \r
1820 //=============================================\r
1821 //\r
1822 //      Software Coex Mechanism start\r
1823 //\r
1824 //=============================================\r
1825 \r
1826 // SCO only or SCO+PAN(HS)\r
1827 VOID\r
1828 halbtc8821a1ant_ActionSco(\r
1829         IN      PBTC_COEXIST            pBtCoexist\r
1830         )\r
1831 {\r
1832         halbtc8821a1ant_SwMechanism(pBtCoexist, TRUE);\r
1833 }\r
1834 \r
1835 VOID\r
1836 halbtc8821a1ant_ActionHid(\r
1837         IN      PBTC_COEXIST            pBtCoexist\r
1838         )\r
1839 {\r
1840         halbtc8821a1ant_SwMechanism(pBtCoexist, TRUE);\r
1841 }\r
1842 \r
1843 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
1844 VOID\r
1845 halbtc8821a1ant_ActionA2dp(\r
1846         IN      PBTC_COEXIST            pBtCoexist\r
1847         )\r
1848 {\r
1849         halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1850 }\r
1851 \r
1852 VOID\r
1853 halbtc8821a1ant_ActionA2dpPanHs(\r
1854         IN      PBTC_COEXIST            pBtCoexist\r
1855         )\r
1856 {\r
1857         halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1858 }\r
1859 \r
1860 VOID\r
1861 halbtc8821a1ant_ActionPanEdr(\r
1862         IN      PBTC_COEXIST            pBtCoexist\r
1863         )\r
1864 {\r
1865         halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1866 }\r
1867 \r
1868 //PAN(HS) only\r
1869 VOID\r
1870 halbtc8821a1ant_ActionPanHs(\r
1871         IN      PBTC_COEXIST            pBtCoexist\r
1872         )\r
1873 {\r
1874         halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1875 }\r
1876 \r
1877 //PAN(EDR)+A2DP\r
1878 VOID\r
1879 halbtc8821a1ant_ActionPanEdrA2dp(\r
1880         IN      PBTC_COEXIST            pBtCoexist\r
1881         )\r
1882 {\r
1883         halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
1884 }\r
1885 \r
1886 VOID\r
1887 halbtc8821a1ant_ActionPanEdrHid(\r
1888         IN      PBTC_COEXIST            pBtCoexist\r
1889         )\r
1890 {\r
1891         halbtc8821a1ant_SwMechanism(pBtCoexist, TRUE);\r
1892 }\r
1893 \r
1894 // HID+A2DP+PAN(EDR)\r
1895 VOID\r
1896 halbtc8821a1ant_ActionHidA2dpPanEdr(\r
1897         IN      PBTC_COEXIST            pBtCoexist\r
1898         )\r
1899 {\r
1900         halbtc8821a1ant_SwMechanism(pBtCoexist, TRUE);\r
1901 }\r
1902 \r
1903 VOID\r
1904 halbtc8821a1ant_ActionHidA2dp(\r
1905         IN      PBTC_COEXIST            pBtCoexist\r
1906         )\r
1907 {\r
1908         halbtc8821a1ant_SwMechanism(pBtCoexist, TRUE);\r
1909 }\r
1910 \r
1911 //=============================================\r
1912 //\r
1913 //      Non-Software Coex Mechanism start\r
1914 //\r
1915 //=============================================\r
1916 VOID\r
1917 halbtc8821a1ant_ActionWifiMultiPort(\r
1918         IN      PBTC_COEXIST            pBtCoexist\r
1919         )\r
1920 {\r
1921         halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1922         \r
1923         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1924         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1925 }\r
1926 \r
1927 VOID\r
1928 halbtc8821a1ant_ActionHs(\r
1929         IN      PBTC_COEXIST            pBtCoexist\r
1930         )\r
1931 {\r
1932         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1933         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1934 }\r
1935 \r
1936 VOID\r
1937 halbtc8821a1ant_ActionBtInquiry(\r
1938         IN      PBTC_COEXIST            pBtCoexist\r
1939         )\r
1940 {       \r
1941         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
1942         BOOLEAN                 bWifiConnected=FALSE, bApEnable=FALSE, bWifiBusy=FALSE, bBtBusy=FALSE;\r
1943 \r
1944         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
1945         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1946         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1947         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
1948 \r
1949         if((!bWifiConnected) && (!pCoexSta->bWiFiIsHighPriTask))\r
1950         {\r
1951                 halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1952                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1953 \r
1954                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);          \r
1955         }\r
1956         else if((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist))\r
1957         {\r
1958                 // SCO/HID/A2DP  busy\r
1959                 halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1960                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
1961 \r
1962                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
1963         }\r
1964         else if ((pBtLinkInfo->bPanExist) || (bWifiBusy))\r
1965         {\r
1966                 halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1967                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);              \r
1968                 \r
1969                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
1970         }\r
1971         else\r
1972         {\r
1973                 halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1974                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1975 \r
1976                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
1977         }\r
1978 }\r
1979 \r
1980 VOID\r
1981 halbtc8821a1ant_ActionBtScoHidOnlyBusy(\r
1982         IN      PBTC_COEXIST            pBtCoexist,\r
1983         IN      u1Byte                          wifiStatus\r
1984         )\r
1985 {\r
1986         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
1987         BOOLEAN bWifiConnected=FALSE;\r
1988         u1Byte  wifiRssiState=BTC_RSSI_STATE_HIGH;\r
1989 \r
1990         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1991 \r
1992         // tdma and coex table\r
1993 \r
1994         if(pBtLinkInfo->bScoExist)\r
1995         {\r
1996                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1997                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1998         }\r
1999         else //HID\r
2000         {\r
2001                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2002                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);\r
2003         }\r
2004 }\r
2005 \r
2006 VOID\r
2007 halbtc8821a1ant_ActionWifiConnectedBtAclBusy(\r
2008         IN      PBTC_COEXIST            pBtCoexist,\r
2009         IN      u1Byte                          wifiStatus\r
2010         )\r
2011 {\r
2012         u1Byte          btRssiState;\r
2013         \r
2014         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2015         btRssiState = halbtc8821a1ant_BtRssiState(2, 28, 0);    \r
2016 \r
2017         if(pBtLinkInfo->bHidOnly)  //HID\r
2018         {\r
2019                 halbtc8821a1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);\r
2020                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2021                 return;\r
2022         }\r
2023         else if(pBtLinkInfo->bA2dpOnly)  //A2DP         \r
2024         {\r
2025                 if(BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)\r
2026                 {\r
2027                         //halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2028                         //halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2029                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2030                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2031                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
2032                 }\r
2033                 else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
2034                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )     \r
2035                 {\r
2036                         halbtc8821a1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);\r
2037                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2038                 }\r
2039                 else //for low BT RSSI\r
2040                 {\r
2041                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2042                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2043                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
2044                 }\r
2045         }\r
2046         else if(pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist)  //HID+A2DP\r
2047         {\r
2048                 if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
2049                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )     \r
2050                 {\r
2051                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2052                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
2053                 }\r
2054                 else //for low BT RSSI\r
2055                 {\r
2056                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2057                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
2058                 }                       \r
2059 \r
2060                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 6);\r
2061         }\r
2062         else if( (pBtLinkInfo->bPanOnly) || (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist) ) //PAN(OPP,FTP), HID+PAN(OPP,FTP)                 \r
2063         {\r
2064                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2065                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 6);\r
2066                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2067         }\r
2068         else if ( ((pBtLinkInfo->bA2dpExist) && (pBtLinkInfo->bPanExist)) ||\r
2069                        (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist&&pBtLinkInfo->bPanExist) ) //A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP)\r
2070         {\r
2071                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2072                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2073                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2074         }\r
2075         else\r
2076         {               \r
2077                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2078                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2079                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
2080         }       \r
2081 }\r
2082 \r
2083 VOID\r
2084 halbtc8821a1ant_ActionWifiNotConnected(\r
2085         IN      PBTC_COEXIST            pBtCoexist\r
2086         )\r
2087 {\r
2088         // power save state\r
2089         halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2090 \r
2091         // tdma and coex table  \r
2092         halbtc8821a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
2093         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2094 }\r
2095 \r
2096 VOID\r
2097 halbtc8821a1ant_ActionWifiNotConnectedScan(\r
2098         IN      PBTC_COEXIST            pBtCoexist\r
2099         )\r
2100 {\r
2101         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2102         \r
2103         halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2104         \r
2105         // tdma and coex table\r
2106         if(BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2107         {\r
2108                 if (pBtLinkInfo->bA2dpExist)\r
2109                 {\r
2110                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2111                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2112                 }\r
2113                 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)\r
2114          {\r
2115                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
2116                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2117                 }\r
2118                 else\r
2119                 {\r
2120                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2121                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2122                 }\r
2123         }\r
2124         else if( (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2125                         (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2126         {\r
2127                 halbtc8821a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2128                         BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
2129         }\r
2130         else\r
2131         {\r
2132                 //halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2133                 //halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2134 \r
2135                 //Bryant Add\r
2136                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2137                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2138         }\r
2139 }\r
2140 \r
2141 VOID\r
2142 halbtc8821a1ant_ActionWifiNotConnectedAssoAuth(\r
2143         IN      PBTC_COEXIST            pBtCoexist\r
2144         )\r
2145 {\r
2146         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2147         \r
2148         halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2149 \r
2150         // tdma and coex table\r
2151         if( (pBtLinkInfo->bScoExist)  || (pBtLinkInfo->bHidExist) )\r
2152         {\r
2153                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2154                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
2155         }\r
2156         else if( (pBtLinkInfo->bA2dpExist)  || (pBtLinkInfo->bPanExist) )                       \r
2157         {\r
2158                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2159                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
2160         }\r
2161         else    \r
2162         {               \r
2163                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2164                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2165         }\r
2166 }\r
2167 \r
2168 VOID\r
2169 halbtc8821a1ant_ActionWifiConnectedScan(\r
2170         IN      PBTC_COEXIST            pBtCoexist\r
2171         )\r
2172 {\r
2173         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2174         \r
2175         halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2176 \r
2177         // tdma and coex table\r
2178         if(BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2179         {\r
2180                 if (pBtLinkInfo->bA2dpExist)\r
2181                 {\r
2182                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2183                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2184                 }\r
2185                 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)\r
2186                 {\r
2187                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
2188                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2189                 }\r
2190                 else\r
2191                 {\r
2192                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2193                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2194                 }\r
2195         }\r
2196         else if( (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2197                         (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2198         {\r
2199                 halbtc8821a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2200                         BT_8821A_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
2201         }\r
2202         else\r
2203         {\r
2204                 //halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2205                 //halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
2206 \r
2207                 //Bryant Add\r
2208                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2209                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2210         }\r
2211 }\r
2212 \r
2213 VOID\r
2214 halbtc8821a1ant_ActionWifiConnectedSpecialPacket(\r
2215         IN      PBTC_COEXIST            pBtCoexist\r
2216         )\r
2217 {\r
2218         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2219 \r
2220         halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2221 \r
2222         // tdma and coex table\r
2223         if((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist))\r
2224         {\r
2225                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
2226                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
2227         }\r
2228         else if(pBtLinkInfo->bPanExist) \r
2229         {\r
2230                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);\r
2231                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          \r
2232         }\r
2233         else    \r
2234         {               \r
2235                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2236                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2237         }\r
2238 }\r
2239 \r
2240 VOID\r
2241 halbtc8821a1ant_ActionWifiConnected(\r
2242         IN      PBTC_COEXIST            pBtCoexist\r
2243         )\r
2244 {\r
2245         BOOLEAN         bWifiBusy=FALSE;\r
2246         BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2247         BOOLEAN         bUnder4way=FALSE, bApEnable=FALSE;\r
2248         u4Byte          wifiBw;\r
2249 \r
2250         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect()===>\n"));\r
2251 \r
2252         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
2253         if(bUnder4way)\r
2254         {\r
2255                 halbtc8821a1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
2256                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));\r
2257                 return;\r
2258         }\r
2259         \r
2260         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2261         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2262         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2263         if(bScan || bLink || bRoam)\r
2264         {\r
2265                 if(bScan)       \r
2266                         halbtc8821a1ant_ActionWifiConnectedScan(pBtCoexist);\r
2267                 else\r
2268                         halbtc8821a1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
2269                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));\r
2270                 return;\r
2271         }\r
2272 \r
2273         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
2274         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
2275         // power save state\r
2276         if(!bApEnable && BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)\r
2277         {\r
2278                 if(!bWifiBusy && pBtCoexist->btLinkInfo.bA2dpOnly)      //A2DP\r
2279                         halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2280                 else\r
2281                         halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);\r
2282         }\r
2283         else\r
2284                 halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2285 \r
2286         // tdma and coex table\r
2287         if(!bWifiBusy)\r
2288         {\r
2289                 if(BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2290                 {\r
2291                         halbtc8821a1ant_ActionWifiConnectedBtAclBusy(pBtCoexist, \r
2292                                 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
2293                 }\r
2294                 else if( (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2295                         (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2296                 {\r
2297                         halbtc8821a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2298                                 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
2299                 }\r
2300                 else\r
2301                 {\r
2302                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2303                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2304                 }\r
2305         }\r
2306         else\r
2307         {\r
2308                 if(BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
2309                 {\r
2310                         halbtc8821a1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,\r
2311                                 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
2312                 }\r
2313                 else if( (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2314                         (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2315                 {\r
2316                         halbtc8821a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
2317                                 BT_8821A_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
2318                 }\r
2319                 else \r
2320                 {\r
2321                         halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
2322                         halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
2323                 }\r
2324         }\r
2325 }\r
2326 \r
2327 VOID\r
2328 halbtc8821a1ant_RunSwCoexistMechanism(\r
2329         IN      PBTC_COEXIST            pBtCoexist\r
2330         )\r
2331 {\r
2332         u1Byte  algorithm=0;\r
2333 \r
2334         algorithm = halbtc8821a1ant_ActionAlgorithm(pBtCoexist);\r
2335         pCoexDm->curAlgorithm = algorithm;\r
2336 \r
2337         if(halbtc8821a1ant_IsCommonAction(pBtCoexist))\r
2338         {\r
2339 \r
2340         }\r
2341         else\r
2342         {\r
2343                 switch(pCoexDm->curAlgorithm)\r
2344                 {\r
2345                         case BT_8821A_1ANT_COEX_ALGO_SCO:\r
2346                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = SCO.\n"));\r
2347                                 halbtc8821a1ant_ActionSco(pBtCoexist);\r
2348                                 break;\r
2349                         case BT_8821A_1ANT_COEX_ALGO_HID:\r
2350                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID.\n"));\r
2351                                 halbtc8821a1ant_ActionHid(pBtCoexist);\r
2352                                 break;\r
2353                         case BT_8821A_1ANT_COEX_ALGO_A2DP:\r
2354                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP.\n"));\r
2355                                 halbtc8821a1ant_ActionA2dp(pBtCoexist);\r
2356                                 break;\r
2357                         case BT_8821A_1ANT_COEX_ALGO_A2DP_PANHS:\r
2358                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));\r
2359                                 halbtc8821a1ant_ActionA2dpPanHs(pBtCoexist);\r
2360                                 break;\r
2361                         case BT_8821A_1ANT_COEX_ALGO_PANEDR:\r
2362                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR).\n"));\r
2363                                 halbtc8821a1ant_ActionPanEdr(pBtCoexist);\r
2364                                 break;\r
2365                         case BT_8821A_1ANT_COEX_ALGO_PANHS:\r
2366                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HS mode.\n"));\r
2367                                 halbtc8821a1ant_ActionPanHs(pBtCoexist);\r
2368                                 break;\r
2369                         case BT_8821A_1ANT_COEX_ALGO_PANEDR_A2DP:\r
2370                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));\r
2371                                 halbtc8821a1ant_ActionPanEdrA2dp(pBtCoexist);\r
2372                                 break;\r
2373                         case BT_8821A_1ANT_COEX_ALGO_PANEDR_HID:\r
2374                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));\r
2375                                 halbtc8821a1ant_ActionPanEdrHid(pBtCoexist);\r
2376                                 break;\r
2377                         case BT_8821A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
2378                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));\r
2379                                 halbtc8821a1ant_ActionHidA2dpPanEdr(pBtCoexist);\r
2380                                 break;\r
2381                         case BT_8821A_1ANT_COEX_ALGO_HID_A2DP:\r
2382                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP.\n"));\r
2383                                 halbtc8821a1ant_ActionHidA2dp(pBtCoexist);\r
2384                                 break;\r
2385                         default:\r
2386                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = coexist All Off!!\n"));\r
2387                                 //halbtc8821a1ant_CoexAllOff(pBtCoexist);\r
2388                                 break;\r
2389                 }\r
2390                 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
2391         }\r
2392 }\r
2393 \r
2394 VOID\r
2395 halbtc8821a1ant_RunCoexistMechanism(\r
2396         IN      PBTC_COEXIST            pBtCoexist\r
2397         )\r
2398 {\r
2399         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2400         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;\r
2401         BOOLEAN bIncreaseScanDevNum=FALSE;\r
2402         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
2403         u1Byte  aggBufSize=5;\r
2404         u1Byte  wifiRssiState=BTC_RSSI_STATE_HIGH;\r
2405         u4Byte  wifiLinkStatus=0;\r
2406         u4Byte  numOfWifiLink=0;\r
2407         BOOLEAN bWifiUnder5G=FALSE;\r
2408 \r
2409         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism()===>\n"));\r
2410 \r
2411         if(pBtCoexist->bManualControl)\r
2412         {\r
2413                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));\r
2414                 return;\r
2415         }\r
2416 \r
2417         if(pBtCoexist->bStopCoexDm)\r
2418         {\r
2419                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));\r
2420                 return;\r
2421         }\r
2422 \r
2423         if(pCoexSta->bUnderIps)\r
2424         {\r
2425                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is under IPS !!!\n"));\r
2426                 return;\r
2427         }\r
2428 \r
2429         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
2430         if(bWifiUnder5G)\r
2431         {\r
2432                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for 5G <===\n"));\r
2433                 halbtc8821a1ant_CoexUnder5G(pBtCoexist);\r
2434                 return;\r
2435         }\r
2436 \r
2437         if( (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
2438                 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2439                 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2440         {\r
2441                 bIncreaseScanDevNum = TRUE;\r
2442         }\r
2443 \r
2444         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, &bIncreaseScanDevNum);\r
2445         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2446 \r
2447         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
2448         numOfWifiLink = wifiLinkStatus>>16;\r
2449         if((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))\r
2450         {\r
2451                 halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
2452                 halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
2453                 halbtc8821a1ant_ActionWifiMultiPort(pBtCoexist);\r
2454                 return;\r
2455         }\r
2456 \r
2457         if(!pBtLinkInfo->bScoExist && !pBtLinkInfo->bHidExist)\r
2458         {\r
2459                 halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
2460         }\r
2461         else\r
2462         {\r
2463                 if(bWifiConnected)\r
2464                 {\r
2465                         wifiRssiState = halbtc8821a1ant_WifiRssiState(pBtCoexist, 1, 2, 30, 0);\r
2466                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2467                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2468                         {\r
2469                                 halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 1, 1);\r
2470                         }\r
2471                         else\r
2472                         {\r
2473                                 halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 1, 1);\r
2474                         }\r
2475                 }\r
2476                 else\r
2477                 {\r
2478                         halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
2479                 }\r
2480 \r
2481         }\r
2482 \r
2483         if(pBtLinkInfo->bScoExist)\r
2484         {\r
2485                 bBtCtrlAggBufSize = TRUE;\r
2486                 aggBufSize = 0x3;\r
2487         }\r
2488         else if(pBtLinkInfo->bHidExist)\r
2489         {\r
2490                 bBtCtrlAggBufSize = TRUE;\r
2491                 aggBufSize = 0x5;\r
2492         }\r
2493         else if(pBtLinkInfo->bA2dpExist || pBtLinkInfo->bPanExist)\r
2494         {\r
2495                 bBtCtrlAggBufSize = TRUE;\r
2496                 aggBufSize = 0x8;\r
2497         }\r
2498         halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
2499 \r
2500         halbtc8821a1ant_RunSwCoexistMechanism(pBtCoexist);\r
2501 \r
2502         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2503         if(pCoexSta->bC2hBtInquiryPage)\r
2504         {\r
2505                 halbtc8821a1ant_ActionBtInquiry(pBtCoexist);\r
2506                 return;\r
2507         }\r
2508         else if(bBtHsOn)\r
2509         {\r
2510                 halbtc8821a1ant_ActionHs(pBtCoexist);\r
2511                 return;\r
2512         }\r
2513 \r
2514         \r
2515         if(!bWifiConnected)\r
2516         {\r
2517                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2518                 \r
2519                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is non connected-idle !!!\n"));\r
2520 \r
2521                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2522                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2523                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2524 \r
2525                 if(bScan || bLink || bRoam)\r
2526                 {\r
2527                          if (bScan)     \r
2528                                 halbtc8821a1ant_ActionWifiNotConnectedScan(pBtCoexist); \r
2529                          else\r
2530                                 halbtc8821a1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);     \r
2531                 }\r
2532                 else\r
2533                         halbtc8821a1ant_ActionWifiNotConnected(pBtCoexist);\r
2534         }\r
2535         else    // wifi LPS/Busy\r
2536         {       \r
2537                 halbtc8821a1ant_ActionWifiConnected(pBtCoexist);\r
2538         }\r
2539 }\r
2540 \r
2541 VOID\r
2542 halbtc8821a1ant_InitCoexDm(\r
2543         IN      PBTC_COEXIST            pBtCoexist\r
2544         )\r
2545 {\r
2546         // force to reset coex mechanism\r
2547         // sw all off\r
2548         halbtc8821a1ant_SwMechanism(pBtCoexist, FALSE);\r
2549 \r
2550         //halbtc8821a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
2551         halbtc8821a1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
2552 }\r
2553 \r
2554 VOID\r
2555 halbtc8821a1ant_InitHwConfig(\r
2556         IN      PBTC_COEXIST            pBtCoexist,\r
2557         IN      BOOLEAN                         bBackUp,\r
2558         IN      BOOLEAN                         bWifiOnly\r
2559         )\r
2560 {\r
2561         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
2562         u4Byte  u4Tmp=0;\r
2563         u2Byte                          u2Tmp=0;\r
2564         u1Byte  u1Tmp=0;\r
2565         u1Byte                          H2C_Parameter[2] ={0};\r
2566         BOOLEAN                 bWifiUnder5G=FALSE;\r
2567                 \r
2568         \r
2569         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 1Ant Init HW Config!!\n"));\r
2570 \r
2571         if(bWifiOnly)\r
2572                 return;\r
2573         \r
2574         if(bBackUp)\r
2575         {\r
2576                 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
2577                 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
2578                 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
2579                 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
2580         }\r
2581 \r
2582         // 0x790[5:0]=0x5\r
2583         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);\r
2584         u1Tmp &= 0xc0;\r
2585         u1Tmp |= 0x5;\r
2586         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);\r
2587 \r
2588         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
2589 \r
2590         //Antenna config\r
2591         if(bWifiUnder5G)\r
2592                 halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, TRUE, FALSE);\r
2593         else\r
2594                 halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, TRUE, FALSE);\r
2595 \r
2596         // PTA parameter\r
2597         halbtc8821a1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
2598 \r
2599         // Enable counter statistics\r
2600         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); //0x76e[3] =1, WLAN_Act control by PTA\r
2601         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);\r
2602         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);\r
2603 }\r
2604 \r
2605 //============================================================\r
2606 // work around function start with wa_halbtc8821a1ant_\r
2607 //============================================================\r
2608 //============================================================\r
2609 // extern function start with EXhalbtc8821a1ant_\r
2610 //============================================================\r
2611 VOID\r
2612 EXhalbtc8821a1ant_PowerOnSetting(\r
2613         IN      PBTC_COEXIST            pBtCoexist\r
2614         )\r
2615 {\r
2616 }\r
2617 \r
2618 VOID\r
2619 EXhalbtc8821a1ant_InitHwConfig(\r
2620         IN      PBTC_COEXIST            pBtCoexist,\r
2621         IN      BOOLEAN                         bWifiOnly\r
2622         )\r
2623 {\r
2624         halbtc8821a1ant_InitHwConfig(pBtCoexist, TRUE, bWifiOnly);\r
2625 }\r
2626 \r
2627 VOID\r
2628 EXhalbtc8821a1ant_InitCoexDm(\r
2629         IN      PBTC_COEXIST            pBtCoexist\r
2630         )\r
2631 {\r
2632         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));\r
2633 \r
2634         pBtCoexist->bStopCoexDm = FALSE;\r
2635         \r
2636         halbtc8821a1ant_InitCoexDm(pBtCoexist);\r
2637 \r
2638         halbtc8821a1ant_QueryBtInfo(pBtCoexist);\r
2639 }\r
2640 \r
2641 VOID\r
2642 EXhalbtc8821a1ant_DisplayCoexInfo(\r
2643         IN      PBTC_COEXIST            pBtCoexist\r
2644         )\r
2645 {\r
2646         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
2647         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
2648         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2649         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
2650         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
2651         u2Byte                          u2Tmp[4];\r
2652         u4Byte                          u4Tmp[4];\r
2653         u4Byte                          faOfdm, faCck;\r
2654         u4Byte                          fwVer=0, btPatchVer=0;\r
2655 \r
2656         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
2657         CL_PRINTF(cliBuf);\r
2658 \r
2659         if(pBtCoexist->bManualControl)\r
2660         {\r
2661                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");\r
2662                 CL_PRINTF(cliBuf);\r
2663                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
2664                 CL_PRINTF(cliBuf);\r
2665         }\r
2666         if(pBtCoexist->bStopCoexDm)\r
2667         {\r
2668                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");\r
2669                 CL_PRINTF(cliBuf);\r
2670                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
2671                 CL_PRINTF(cliBuf);\r
2672         }\r
2673 \r
2674         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Ant PG Num/ Ant Mech/ Ant Pos:", \\r
2675                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos);\r
2676         CL_PRINTF(cliBuf);      \r
2677         \r
2678         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
2679                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
2680         CL_PRINTF(cliBuf);\r
2681 \r
2682         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
2683         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
2684         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \\r
2685                 GLCoexVerDate8821a1Ant, GLCoexVer8821a1Ant, fwVer, btPatchVer, btPatchVer);\r
2686         CL_PRINTF(cliBuf);\r
2687 \r
2688         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \\r
2689                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
2690                 pCoexDm->wifiChnlInfo[2]);\r
2691         CL_PRINTF(cliBuf);\r
2692 \r
2693         // wifi status\r
2694         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
2695         CL_PRINTF(cliBuf);\r
2696         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
2697 \r
2698         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
2699         CL_PRINTF(cliBuf);\r
2700         \r
2701         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
2702                 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":\r
2703                 (  (BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),\r
2704                 pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
2705         CL_PRINTF(cliBuf);\r
2706         \r
2707         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
2708                 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist);\r
2709         CL_PRINTF(cliBuf);      \r
2710         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
2711 \r
2712         btInfoExt = pCoexSta->btInfoExt;\r
2713         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
2714                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
2715         CL_PRINTF(cliBuf);      \r
2716 \r
2717         for(i=0; i<BT_INFO_SRC_8821A_1ANT_MAX; i++)\r
2718         {\r
2719                 if(pCoexSta->btInfoC2hCnt[i])\r
2720                 {                               \r
2721                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8821a1Ant[i], \\r
2722                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
2723                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
2724                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
2725                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
2726                         CL_PRINTF(cliBuf);\r
2727                 }\r
2728         }\r
2729 \r
2730         if(!pBtCoexist->bManualControl)\r
2731         {\r
2732         // Sw mechanism \r
2733         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
2734         CL_PRINTF(cliBuf);\r
2735         \r
2736         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "SM[LowPenaltyRA]", \\r
2737                 pCoexDm->bCurLowPenaltyRa);\r
2738         CL_PRINTF(cliBuf);\r
2739 \r
2740         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "DelBA/ BtCtrlAgg/ AggSize", \\r
2741                 (pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),\r
2742                         pBtCoexist->btInfo.aggBufSize);\r
2743         CL_PRINTF(cliBuf);\r
2744         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \\r
2745                         pBtCoexist->btInfo.raMask);\r
2746         CL_PRINTF(cliBuf);      \r
2747 \r
2748         // Fw mechanism         \r
2749         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
2750         CL_PRINTF(cliBuf);      \r
2751         \r
2752                 psTdmaCase = pCoexDm->curPsTdma;\r
2753                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \\r
2754                         pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
2755                         pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
2756                         pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);\r
2757                 CL_PRINTF(cliBuf);\r
2758         \r
2759                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IgnWlanAct", \\r
2760                         pCoexDm->bCurIgnoreWlanAct);\r
2761                 CL_PRINTF(cliBuf);\r
2762         \r
2763                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Latest error condition(should be 0)", \\r
2764                         pCoexDm->errorCondition);\r
2765                 CL_PRINTF(cliBuf);\r
2766         }\r
2767 \r
2768         // Hw setting           \r
2769         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
2770         CL_PRINTF(cliBuf);      \r
2771 \r
2772         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "backup ARFR1/ARFR2/RL/AMaxTime", \\r
2773                 pCoexDm->backupArfrCnt1, pCoexDm->backupArfrCnt2, pCoexDm->backupRetryLimit, pCoexDm->backupAmpduMaxTime);\r
2774         CL_PRINTF(cliBuf);\r
2775 \r
2776         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
2777         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
2778         u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
2779         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
2780         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \\r
2781                 u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);\r
2782         CL_PRINTF(cliBuf);\r
2783 \r
2784         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
2785         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc58);\r
2786         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x778/ 0xc58[29:25]", \\r
2787                 u1Tmp[0], (u4Tmp[0]&0x3e000000) >> 25);\r
2788         CL_PRINTF(cliBuf);\r
2789 \r
2790         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x8db);\r
2791         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x8db[6:5]", \\r
2792                 ((u1Tmp[0]&0x60)>>5));\r
2793         CL_PRINTF(cliBuf); \r
2794         \r
2795         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x975);\r
2796         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcb4);\r
2797         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0xcb4[29:28]/0xcb4[7:0]/0x974[9:8]", \\r
2798                 (u4Tmp[0]&0x30000000)>>28, u4Tmp[0]&0xff, u1Tmp[0]& 0x3);\r
2799         CL_PRINTF(cliBuf);\r
2800 \r
2801 \r
2802         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
2803         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
2804         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x64);\r
2805         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x40/0x4c[24:23]/0x64[0]", \\r
2806                 u1Tmp[0], ((u4Tmp[0]&0x01800000)>>23), u1Tmp[1]&0x1);\r
2807         CL_PRINTF(cliBuf);\r
2808 \r
2809         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
2810         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
2811         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
2812                 u4Tmp[0], u1Tmp[0]);\r
2813         CL_PRINTF(cliBuf);\r
2814 \r
2815         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
2816         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
2817                 u4Tmp[0]&0xff);\r
2818         CL_PRINTF(cliBuf);\r
2819 \r
2820         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf48);\r
2821         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5d);\r
2822         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);\r
2823         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "OFDM-FA/ CCK-FA", \\r
2824                 u4Tmp[0], (u1Tmp[0]<<8) + u1Tmp[1]  );\r
2825         CL_PRINTF(cliBuf);\r
2826 \r
2827         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
2828         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
2829         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
2830         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8(coexTable)", \\r
2831                 u4Tmp[0], u4Tmp[1], u4Tmp[2]);\r
2832         CL_PRINTF(cliBuf);\r
2833 \r
2834         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \\r
2835                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
2836         CL_PRINTF(cliBuf);\r
2837         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \\r
2838                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
2839         CL_PRINTF(cliBuf);\r
2840 #if(BT_AUTO_REPORT_ONLY_8821A_1ANT == 1)\r
2841         halbtc8821a1ant_MonitorBtCtr(pBtCoexist);\r
2842 #endif\r
2843         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
2844 }\r
2845 \r
2846 \r
2847 VOID\r
2848 EXhalbtc8821a1ant_IpsNotify(\r
2849         IN      PBTC_COEXIST            pBtCoexist,\r
2850         IN      u1Byte                  type\r
2851         )\r
2852 {\r
2853         u4Byte  u4Tmp=0;\r
2854 \r
2855         if(pBtCoexist->bManualControl ||        pBtCoexist->bStopCoexDm)\r
2856                 return;\r
2857 \r
2858         if(BTC_IPS_ENTER == type)\r
2859         {\r
2860                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));\r
2861                 pCoexSta->bUnderIps = TRUE;\r
2862                 \r
2863                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2864                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2865                 halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);   \r
2866                 //halbtc8821a1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);\r
2867         }\r
2868         else if(BTC_IPS_LEAVE == type)\r
2869         {\r
2870                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));\r
2871                 pCoexSta->bUnderIps = FALSE;\r
2872 \r
2873                 halbtc8821a1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);\r
2874                 halbtc8821a1ant_InitCoexDm(pBtCoexist);\r
2875                 halbtc8821a1ant_QueryBtInfo(pBtCoexist);\r
2876         }\r
2877 }\r
2878 \r
2879 VOID\r
2880 EXhalbtc8821a1ant_LpsNotify(\r
2881         IN      PBTC_COEXIST            pBtCoexist,\r
2882         IN      u1Byte                  type\r
2883         )\r
2884 {\r
2885         if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)\r
2886                 return;\r
2887 \r
2888         if(BTC_LPS_ENABLE == type)\r
2889         {\r
2890                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));\r
2891                 pCoexSta->bUnderLps = TRUE;\r
2892         }\r
2893         else if(BTC_LPS_DISABLE == type)\r
2894         {\r
2895                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));\r
2896                 pCoexSta->bUnderLps = FALSE;\r
2897         }\r
2898 }\r
2899 \r
2900 VOID\r
2901 EXhalbtc8821a1ant_ScanNotify(\r
2902         IN      PBTC_COEXIST            pBtCoexist,\r
2903         IN      u1Byte                  type\r
2904         )\r
2905 {\r
2906         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
2907         u4Byte  wifiLinkStatus=0;\r
2908         u4Byte  numOfWifiLink=0;\r
2909         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
2910         u1Byte  aggBufSize=5;\r
2911 \r
2912         if(pBtCoexist->bManualControl ||\r
2913                 pBtCoexist->bStopCoexDm )\r
2914                 return;\r
2915 \r
2916         if(BTC_SCAN_START == type)\r
2917         {\r
2918                 pCoexSta->bWiFiIsHighPriTask = TRUE;\r
2919                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
2920 \r
2921                 halbtc8821a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);  //Force antenna setup for no scan result issue\r
2922         }\r
2923         else\r
2924         {\r
2925                 pCoexSta->bWiFiIsHighPriTask = FALSE;   \r
2926                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
2927         }       \r
2928 \r
2929         if(pBtCoexist->btInfo.bBtDisabled)\r
2930                 return;\r
2931 \r
2932         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2933         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2934 \r
2935         halbtc8821a1ant_QueryBtInfo(pBtCoexist);\r
2936         \r
2937         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
2938         numOfWifiLink = wifiLinkStatus>>16;\r
2939         if(numOfWifiLink >= 2)\r
2940         {\r
2941                 halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
2942                 halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
2943                 halbtc8821a1ant_ActionWifiMultiPort(pBtCoexist);\r
2944                 return;\r
2945         }\r
2946         \r
2947         if(pCoexSta->bC2hBtInquiryPage)\r
2948         {\r
2949                 halbtc8821a1ant_ActionBtInquiry(pBtCoexist);\r
2950                 return;\r
2951         }\r
2952         else if(bBtHsOn)\r
2953         {\r
2954                 halbtc8821a1ant_ActionHs(pBtCoexist);\r
2955                 return;\r
2956         }\r
2957 \r
2958         if(BTC_SCAN_START == type)\r
2959         {\r
2960                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
2961                 if(!bWifiConnected)     // non-connected scan\r
2962                 {\r
2963                         halbtc8821a1ant_ActionWifiNotConnectedScan(pBtCoexist);\r
2964                 }\r
2965                 else    // wifi is connected\r
2966                 {\r
2967                         halbtc8821a1ant_ActionWifiConnectedScan(pBtCoexist);\r
2968                 }\r
2969         }\r
2970         else if(BTC_SCAN_FINISH == type)\r
2971         {\r
2972                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
2973                 if(!bWifiConnected)     // non-connected scan\r
2974                 {\r
2975                         halbtc8821a1ant_ActionWifiNotConnected(pBtCoexist);\r
2976                 }\r
2977                 else\r
2978                 {\r
2979                         halbtc8821a1ant_ActionWifiConnected(pBtCoexist);\r
2980                 }\r
2981         }\r
2982 }\r
2983 \r
2984 VOID\r
2985 EXhalbtc8821a1ant_ConnectNotify(\r
2986         IN      PBTC_COEXIST            pBtCoexist,\r
2987         IN      u1Byte                  type\r
2988         )\r
2989 {\r
2990         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
2991         u4Byte  wifiLinkStatus=0;\r
2992         u4Byte  numOfWifiLink=0;\r
2993         BOOLEAN bBtCtrlAggBufSize=FALSE;\r
2994         u1Byte  aggBufSize=5;\r
2995 \r
2996         if(pBtCoexist->bManualControl ||\r
2997                 pBtCoexist->bStopCoexDm ||\r
2998                 pBtCoexist->btInfo.bBtDisabled )\r
2999                 return;\r
3000 \r
3001         if(BTC_ASSOCIATE_START == type)\r
3002         {\r
3003          pCoexSta->bWiFiIsHighPriTask = TRUE;\r
3004                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));        \r
3005                 pCoexDm->nArpCnt = 0;\r
3006         }\r
3007         else\r
3008         {\r
3009                 pCoexSta->bWiFiIsHighPriTask = FALSE;   \r
3010                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));       \r
3011                 pCoexDm->nArpCnt = 0;\r
3012         }\r
3013 \r
3014         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
3015         numOfWifiLink = wifiLinkStatus>>16;\r
3016         if(numOfWifiLink >= 2)\r
3017         {\r
3018                 halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
3019                 halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
3020                 halbtc8821a1ant_ActionWifiMultiPort(pBtCoexist);\r
3021                 return;\r
3022         }\r
3023 \r
3024         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
3025         if(pCoexSta->bC2hBtInquiryPage)\r
3026         {\r
3027                 halbtc8821a1ant_ActionBtInquiry(pBtCoexist);\r
3028                 return;\r
3029         }\r
3030         else if(bBtHsOn)\r
3031         {\r
3032                 halbtc8821a1ant_ActionHs(pBtCoexist);\r
3033                 return;\r
3034         }\r
3035 \r
3036         if(BTC_ASSOCIATE_START == type)\r
3037         {\r
3038                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));              \r
3039                 halbtc8821a1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);\r
3040         }\r
3041         else if(BTC_ASSOCIATE_FINISH == type)\r
3042         {\r
3043                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));\r
3044                 \r
3045                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
3046                 if(!bWifiConnected) // non-connected scan\r
3047                 {\r
3048                         halbtc8821a1ant_ActionWifiNotConnected(pBtCoexist);\r
3049                 }\r
3050                 else\r
3051                 {\r
3052                         halbtc8821a1ant_ActionWifiConnected(pBtCoexist);\r
3053                 }\r
3054         }\r
3055 }\r
3056 \r
3057 VOID\r
3058 EXhalbtc8821a1ant_MediaStatusNotify(\r
3059         IN      PBTC_COEXIST                    pBtCoexist,\r
3060         IN      u1Byte                          type\r
3061         )\r
3062 {\r
3063         u1Byte                  H2C_Parameter[3] ={0};\r
3064         u4Byte                  wifiBw;\r
3065         u1Byte                  wifiCentralChnl;\r
3066 \r
3067         if(pBtCoexist->bManualControl ||\r
3068                 pBtCoexist->bStopCoexDm ||\r
3069                 pBtCoexist->btInfo.bBtDisabled )\r
3070                 return;\r
3071 \r
3072         if(BTC_MEDIA_CONNECT == type)\r
3073         {\r
3074                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));\r
3075         }\r
3076         else\r
3077         {\r
3078                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));\r
3079                 pCoexDm->nArpCnt = 0;\r
3080         }\r
3081 \r
3082         // only 2.4G we need to inform bt the chnl mask\r
3083         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
3084         if( (BTC_MEDIA_CONNECT == type) &&\r
3085                 (wifiCentralChnl <= 14) )\r
3086         {\r
3087                 //H2C_Parameter[0] = 0x1;\r
3088                 H2C_Parameter[0] = 0x0;\r
3089                 H2C_Parameter[1] = wifiCentralChnl;\r
3090                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3091                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
3092                         H2C_Parameter[2] = 0x30;\r
3093                 else\r
3094                         H2C_Parameter[2] = 0x20;\r
3095         }\r
3096                 \r
3097         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
3098         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
3099         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
3100         \r
3101         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x66=0x%x\n", \r
3102                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
3103 \r
3104         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);\r
3105 }\r
3106 \r
3107 VOID\r
3108 EXhalbtc8821a1ant_SpecialPacketNotify(\r
3109         IN      PBTC_COEXIST                    pBtCoexist,\r
3110         IN      u1Byte                          type\r
3111         )\r
3112 {\r
3113         BOOLEAN 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         if( BTC_PACKET_DHCP == type || \r
3125                 BTC_PACKET_EAPOL == type ||\r
3126                 BTC_PACKET_ARP == type )\r
3127         {\r
3128                 pCoexSta->bWiFiIsHighPriTask = TRUE;\r
3129 \r
3130                 if(BTC_PACKET_ARP == type)\r
3131                 {\r
3132                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet ARP notify\n"));            \r
3133                 }\r
3134                 else\r
3135                 {\r
3136                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet DHCP or EAPOL notify\n"));          \r
3137                 }\r
3138         }\r
3139         else\r
3140         {\r
3141                 pCoexSta->bWiFiIsHighPriTask = FALSE;   \r
3142                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet [Type = %d] notify\n", type));\r
3143         }\r
3144 \r
3145         pCoexSta->specialPktPeriodCnt = 0;\r
3146 \r
3147         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
3148         numOfWifiLink = wifiLinkStatus>>16;\r
3149         if(numOfWifiLink >= 2)\r
3150         {\r
3151                 halbtc8821a1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
3152                 halbtc8821a1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);\r
3153                 halbtc8821a1ant_ActionWifiMultiPort(pBtCoexist);\r
3154                 return;\r
3155         }\r
3156 \r
3157         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
3158         if(pCoexSta->bC2hBtInquiryPage)\r
3159         {\r
3160                 halbtc8821a1ant_ActionBtInquiry(pBtCoexist);\r
3161                 return;\r
3162         }\r
3163         else if(bBtHsOn)\r
3164         {\r
3165                 halbtc8821a1ant_ActionHs(pBtCoexist);\r
3166                 return;\r
3167         }\r
3168 \r
3169         if( BTC_PACKET_DHCP == type ||\r
3170                 BTC_PACKET_EAPOL == type || \r
3171                 BTC_PACKET_ARP == type )\r
3172         {\r
3173                 //BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet(%d) notify\n", type));\r
3174                 if(BTC_PACKET_ARP == type)\r
3175                 {\r
3176                         pCoexDm->nArpCnt++;\r
3177                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], ARP Packet Count = %d\n", pCoexDm->nArpCnt));\r
3178                         if(pCoexDm->nArpCnt >= 10) // if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist) \r
3179                                 return; \r
3180                 }\r
3181                 \r
3182                 halbtc8821a1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
3183         }\r
3184 }\r
3185 \r
3186 VOID\r
3187 EXhalbtc8821a1ant_BtInfoNotify(\r
3188         IN      PBTC_COEXIST            pBtCoexist,\r
3189         IN      pu1Byte                 tmpBuf,\r
3190         IN      u1Byte                  length\r
3191         )\r
3192 {\r
3193         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
3194         u1Byte                          btInfo=0;\r
3195         u1Byte                          i, rspSource=0;\r
3196         BOOLEAN                         bWifiConnected=FALSE;\r
3197         BOOLEAN                         bBtBusy=FALSE;\r
3198         BOOLEAN                         bWifiUnder5G=FALSE;\r
3199 \r
3200         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
3201 \r
3202         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
3203 \r
3204         rspSource = tmpBuf[0]&0xf;\r
3205         if(rspSource >= BT_INFO_SRC_8821A_1ANT_MAX)\r
3206                 rspSource = BT_INFO_SRC_8821A_1ANT_WIFI_FW;\r
3207         pCoexSta->btInfoC2hCnt[rspSource]++;\r
3208 \r
3209         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
3210         for(i=0; i<length; i++)\r
3211         {\r
3212                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
3213                 if(i == 1)\r
3214                         btInfo = tmpBuf[i];\r
3215                 if(i == length-1)\r
3216                 {\r
3217                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));\r
3218                 }\r
3219                 else\r
3220                 {\r
3221                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));\r
3222                 }\r
3223         }\r
3224 \r
3225         if(BT_INFO_SRC_8821A_1ANT_WIFI_FW != rspSource)\r
3226         {\r
3227                 pCoexSta->btRetryCnt =  // [3:0]\r
3228                         pCoexSta->btInfoC2h[rspSource][2]&0xf;\r
3229 \r
3230                 if (pCoexSta->btInfoC2h[rspSource][2]&0x20)\r
3231                         pCoexSta->bC2hBtPage = TRUE;\r
3232                 else\r
3233                         pCoexSta->bC2hBtPage = FALSE;                   \r
3234 \r
3235                 pCoexSta->btRssi =\r
3236                         pCoexSta->btInfoC2h[rspSource][3]*2+10;\r
3237 \r
3238                 pCoexSta->btInfoExt = \r
3239                         pCoexSta->btInfoC2h[rspSource][4];\r
3240 \r
3241                 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);\r
3242                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);\r
3243                 if(!pCoexSta->bBtTxRxMask)\r
3244                 {\r
3245                         /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */                            \r
3246                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n"));\r
3247                         pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15);\r
3248                 }\r
3249                 \r
3250                 // Here we need to resend some wifi info to BT\r
3251                 // because bt is reset and loss of the info.\r
3252                 if(pCoexSta->btInfoExt & BIT1)\r
3253                 {                       \r
3254                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));\r
3255                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
3256                         if(bWifiConnected)\r
3257                         {\r
3258                                 EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);\r
3259                         }\r
3260                         else\r
3261                         {\r
3262                                 EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
3263                         }\r
3264                 }\r
3265 \r
3266                 if( (pCoexSta->btInfoExt & BIT3) && !bWifiUnder5G)\r
3267                 {\r
3268                         if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)\r
3269                         {\r
3270                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));\r
3271                                 halbtc8821a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
3272                         }\r
3273                 }\r
3274                 else\r
3275                 {\r
3276                         // BT already NOT ignore Wlan active, do nothing here.\r
3277                 }\r
3278 #if(BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)\r
3279                 if( (pCoexSta->btInfoExt & BIT4) )\r
3280                 {\r
3281                         // BT auto report already enabled, do nothing\r
3282                 }\r
3283                 else\r
3284                 {\r
3285                         halbtc8821a1ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);\r
3286                 }\r
3287 #endif\r
3288         }\r
3289                 \r
3290         // check BIT2 first ==> check if bt is under inquiry or page scan\r
3291         if(btInfo & BT_INFO_8821A_1ANT_B_INQ_PAGE)\r
3292                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
3293         else\r
3294                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
3295 \r
3296         // set link exist status\r
3297         if(!(btInfo&BT_INFO_8821A_1ANT_B_CONNECTION))\r
3298         {\r
3299                 pCoexSta->bBtLinkExist = FALSE;\r
3300                 pCoexSta->bPanExist = FALSE;\r
3301                 pCoexSta->bA2dpExist = FALSE;\r
3302                 pCoexSta->bHidExist = FALSE;\r
3303                 pCoexSta->bScoExist = FALSE;\r
3304         }\r
3305         else    // connection exists\r
3306         {\r
3307                 pCoexSta->bBtLinkExist = TRUE;\r
3308                 if(btInfo & BT_INFO_8821A_1ANT_B_FTP)\r
3309                         pCoexSta->bPanExist = TRUE;\r
3310                 else\r
3311                         pCoexSta->bPanExist = FALSE;\r
3312                 if(btInfo & BT_INFO_8821A_1ANT_B_A2DP)\r
3313                         pCoexSta->bA2dpExist = TRUE;\r
3314                 else\r
3315                         pCoexSta->bA2dpExist = FALSE;\r
3316                 if(btInfo & BT_INFO_8821A_1ANT_B_HID)\r
3317                         pCoexSta->bHidExist = TRUE;\r
3318                 else\r
3319                         pCoexSta->bHidExist = FALSE;\r
3320                 if(btInfo & BT_INFO_8821A_1ANT_B_SCO_ESCO)\r
3321                         pCoexSta->bScoExist = TRUE;\r
3322                 else\r
3323                         pCoexSta->bScoExist = FALSE;\r
3324         }\r
3325 \r
3326         halbtc8821a1ant_UpdateBtLinkInfo(pBtCoexist);\r
3327                 \r
3328         btInfo = btInfo & 0x1f;  //mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41)\r
3329         \r
3330         if(!(btInfo&BT_INFO_8821A_1ANT_B_CONNECTION))\r
3331         {\r
3332                 pCoexDm->btStatus = BT_8821A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;\r
3333                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));\r
3334         }\r
3335         else if(btInfo == BT_INFO_8821A_1ANT_B_CONNECTION)      // connection exists but no busy\r
3336         {\r
3337                 pCoexDm->btStatus = BT_8821A_1ANT_BT_STATUS_CONNECTED_IDLE;\r
3338                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));\r
3339         }\r
3340         else if((btInfo&BT_INFO_8821A_1ANT_B_SCO_ESCO) ||\r
3341                 (btInfo&BT_INFO_8821A_1ANT_B_SCO_BUSY))\r
3342         {\r
3343                 pCoexDm->btStatus = BT_8821A_1ANT_BT_STATUS_SCO_BUSY;\r
3344                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));\r
3345         }\r
3346         else if(btInfo&BT_INFO_8821A_1ANT_B_ACL_BUSY)\r
3347         {\r
3348                 if(BT_8821A_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)\r
3349                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
3350                 pCoexDm->btStatus = BT_8821A_1ANT_BT_STATUS_ACL_BUSY;\r
3351                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));\r
3352         }\r
3353         else\r
3354         {\r
3355                 pCoexDm->btStatus = BT_8821A_1ANT_BT_STATUS_MAX;\r
3356                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));\r
3357         }\r
3358 \r
3359         if( (BT_8821A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
3360                 (BT_8821A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
3361                 (BT_8821A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
3362                 bBtBusy = TRUE;\r
3363         else\r
3364                 bBtBusy = FALSE;\r
3365         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
3366 \r
3367         halbtc8821a1ant_RunCoexistMechanism(pBtCoexist);\r
3368 }\r
3369 \r
3370 VOID\r
3371 EXhalbtc8821a1ant_HaltNotify(\r
3372         IN      PBTC_COEXIST                    pBtCoexist\r
3373         )\r
3374 {\r
3375         u4Byte  u4Tmp;\r
3376         \r
3377         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));\r
3378 \r
3379         halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
3380         halbtc8821a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
3381         halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
3382         //halbtc8821a1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);\r
3383 \r
3384         halbtc8821a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
3385 \r
3386         EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
3387 \r
3388         pBtCoexist->bStopCoexDm = TRUE; \r
3389 }\r
3390 \r
3391 VOID\r
3392 EXhalbtc8821a1ant_PnpNotify(\r
3393         IN      PBTC_COEXIST                    pBtCoexist,\r
3394         IN      u1Byte                          pnpState\r
3395         )\r
3396 {\r
3397         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify\n"));\r
3398 \r
3399         if(BTC_WIFI_PNP_SLEEP == pnpState)\r
3400         {\r
3401                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to SLEEP\n"));\r
3402 \r
3403                 halbtc8821a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
3404                 halbtc8821a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
3405                 halbtc8821a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3406                 halbtc8821a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
3407                 //halbtc8821a1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);\r
3408 \r
3409                 pBtCoexist->bStopCoexDm = TRUE;\r
3410         }\r
3411         else if(BTC_WIFI_PNP_WAKE_UP == pnpState)\r
3412         {\r
3413                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to WAKE UP\n"));\r
3414                 pBtCoexist->bStopCoexDm = FALSE;\r
3415                 halbtc8821a1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);\r
3416                 halbtc8821a1ant_InitCoexDm(pBtCoexist);\r
3417                 halbtc8821a1ant_QueryBtInfo(pBtCoexist);\r
3418         }\r
3419 }\r
3420 \r
3421 VOID\r
3422 EXhalbtc8821a1ant_Periodical(\r
3423         IN      PBTC_COEXIST                    pBtCoexist\r
3424         )\r
3425 {\r
3426         static u1Byte           disVerInfoCnt=0;\r
3427         u4Byte                          fwVer=0, btPatchVer=0;\r
3428         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3429         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
3430 \r
3431         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ==========================Periodical===========================\n"));\r
3432 \r
3433         if(disVerInfoCnt <= 5)\r
3434         {\r
3435                 disVerInfoCnt += 1;\r
3436                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
3437                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n", \\r
3438                         pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));\r
3439                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n", \\r
3440                         ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));\r
3441                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
3442                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
3443                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", \\r
3444                         GLCoexVerDate8821a1Ant, GLCoexVer8821a1Ant, fwVer, btPatchVer, btPatchVer));\r
3445                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
3446         }\r
3447 \r
3448 #if(BT_AUTO_REPORT_ONLY_8821A_1ANT == 0)\r
3449         halbtc8821a1ant_QueryBtInfo(pBtCoexist);\r
3450         halbtc8821a1ant_MonitorBtCtr(pBtCoexist);\r
3451         halbtc8821a1ant_MonitorBtEnableDisable(pBtCoexist);\r
3452 #else\r
3453         if( halbtc8821a1ant_IsWifiStatusChanged(pBtCoexist) ||\r
3454                 pCoexDm->bAutoTdmaAdjust )\r
3455         {\r
3456                 //if(pCoexSta->specialPktPeriodCnt > 2)\r
3457                 //{\r
3458                         halbtc8821a1ant_RunCoexistMechanism(pBtCoexist);        \r
3459                 //}\r
3460         }\r
3461 \r
3462         pCoexSta->specialPktPeriodCnt++;\r
3463 #endif\r
3464 }\r
3465 \r
3466 \r
3467 #endif\r
3468 \r