Merge tag 'lsk-v3.10-android-14.12'
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bs / hal / OUTSRC-BTCoexist / HalBtc8812a1Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for 8812a1ant 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_8812A_1ANT               GLCoexDm8812a1Ant;\r
20 static PCOEX_DM_8812A_1ANT      pCoexDm=&GLCoexDm8812a1Ant;\r
21 static COEX_STA_8812A_1ANT              GLCoexSta8812a1Ant;\r
22 static PCOEX_STA_8812A_1ANT     pCoexSta=&GLCoexSta8812a1Ant;\r
23 \r
24 const char *const GLBtInfoSrc8812a1Ant[]={\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  GLCoexVerDate8812a1Ant=20130729;\r
31 u4Byte  GLCoexVer8812a1Ant=0x10;\r
32 \r
33 //============================================================\r
34 // local function proto type if needed\r
35 //============================================================\r
36 //============================================================\r
37 // local function start with halbtc8812a1ant_\r
38 //============================================================\r
39 u1Byte\r
40 halbtc8812a1ant_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_8812A_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_8812A_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_8812A_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 halbtc8812a1ant_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_8812A_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_8812A_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_8812A_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 halbtc8812a1ant_UpdateRaMask(\r
249         IN      PBTC_COEXIST            pBtCoexist,\r
250         IN      BOOLEAN                         bForceExec,\r
251         IN      u1Byte                          type,\r
252         IN      u4Byte                          rateMask\r
253         )\r
254 {\r
255         if(BTC_RATE_DISABLE == type)\r
256         {\r
257                 pCoexDm->curRaMask |= rateMask;         // disable rate\r
258         }\r
259         else if(BTC_RATE_ENABLE == type)\r
260         {\r
261                 pCoexDm->curRaMask &= ~rateMask;        // enable rate\r
262         }\r
263         \r
264         if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))\r
265         {\r
266                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);\r
267         }\r
268         pCoexDm->preRaMask = pCoexDm->curRaMask;\r
269 }\r
270 \r
271 VOID\r
272 halbtc8812a1ant_MonitorBtCtr(\r
273         IN      PBTC_COEXIST            pBtCoexist\r
274         )\r
275 {\r
276         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp;\r
277         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
278         u1Byte                  u1Tmp;\r
279         \r
280         regHPTxRx = 0x770;\r
281         regLPTxRx = 0x774;\r
282 \r
283         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
284         regHPTx = u4Tmp & bMaskLWord;\r
285         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
286 \r
287         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
288         regLPTx = u4Tmp & bMaskLWord;\r
289         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
290                 \r
291         pCoexSta->highPriorityTx = regHPTx;\r
292         pCoexSta->highPriorityRx = regHPRx;\r
293         pCoexSta->lowPriorityTx = regLPTx;\r
294         pCoexSta->lowPriorityRx = regLPRx;\r
295 \r
296         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
297                 regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));\r
298         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
299                 regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));\r
300 \r
301         // reset counter\r
302         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
303 }\r
304 \r
305 VOID\r
306 halbtc8812a1ant_QueryBtInfo(\r
307         IN      PBTC_COEXIST            pBtCoexist\r
308         )\r
309 {       \r
310         u1Byte  dataLen=3;\r
311         u1Byte  buf[5] = {0};\r
312 \r
313         if(!pBtCoexist->btInfo.bBtDisabled)\r
314         {\r
315                 if(!pCoexSta->btInfoQueryCnt ||\r
316                         (pCoexSta->btInfoC2hCnt[BT_INFO_SRC_8812A_1ANT_BT_RSP]-pCoexSta->btInfoQueryCnt)>2)\r
317                 {\r
318                         buf[0] = dataLen;\r
319                         buf[1] = 0x1;   // polling enable, 1=enable, 0=disable\r
320                         buf[2] = 0x2;   // polling time in seconds\r
321                         buf[3] = 0x1;   // auto report enable, 1=enable, 0=disable\r
322                                 \r
323                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_INFO, (PVOID)&buf[0]);\r
324                 }\r
325         }\r
326         pCoexSta->btInfoQueryCnt++;\r
327 }\r
328 \r
329 VOID\r
330 halbtc8812a1ant_UpdateBtLinkInfo(\r
331         IN      PBTC_COEXIST            pBtCoexist\r
332         )\r
333 {\r
334         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
335 \r
336         pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;\r
337         pBtLinkInfo->bScoExist = pCoexSta->bScoExist;\r
338         pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;\r
339         pBtLinkInfo->bPanExist = pCoexSta->bPanExist;\r
340         pBtLinkInfo->bHidExist = pCoexSta->bHidExist;\r
341 \r
342         // check if Sco only\r
343         if( pBtLinkInfo->bScoExist &&\r
344                 !pBtLinkInfo->bA2dpExist &&\r
345                 !pBtLinkInfo->bPanExist &&\r
346                 !pBtLinkInfo->bHidExist )\r
347                 pBtLinkInfo->bScoOnly = TRUE;\r
348         else\r
349                 pBtLinkInfo->bScoOnly = FALSE;\r
350 \r
351         // check if A2dp only\r
352         if( !pBtLinkInfo->bScoExist &&\r
353                 pBtLinkInfo->bA2dpExist &&\r
354                 !pBtLinkInfo->bPanExist &&\r
355                 !pBtLinkInfo->bHidExist )\r
356                 pBtLinkInfo->bA2dpOnly = TRUE;\r
357         else\r
358                 pBtLinkInfo->bA2dpOnly = FALSE;\r
359 \r
360         // check if Pan only\r
361         if( !pBtLinkInfo->bScoExist &&\r
362                 !pBtLinkInfo->bA2dpExist &&\r
363                 pBtLinkInfo->bPanExist &&\r
364                 !pBtLinkInfo->bHidExist )\r
365                 pBtLinkInfo->bPanOnly = TRUE;\r
366         else\r
367                 pBtLinkInfo->bPanOnly = FALSE;\r
368         \r
369         // check if Hid only\r
370         if( !pBtLinkInfo->bScoExist &&\r
371                 !pBtLinkInfo->bA2dpExist &&\r
372                 !pBtLinkInfo->bPanExist &&\r
373                 pBtLinkInfo->bHidExist )\r
374                 pBtLinkInfo->bHidOnly = TRUE;\r
375         else\r
376                 pBtLinkInfo->bHidOnly = FALSE;\r
377 }\r
378 \r
379 u1Byte\r
380 halbtc8812a1ant_ActionAlgorithm(\r
381         IN      PBTC_COEXIST            pBtCoexist\r
382         )\r
383 {\r
384         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
385         BOOLEAN                         bBtHsOn=FALSE;\r
386         u1Byte                          algorithm=BT_8812A_1ANT_COEX_ALGO_UNDEFINED;\r
387         u1Byte                          numOfDiffProfile=0;\r
388 \r
389         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
390         \r
391         if(!pBtLinkInfo->bBtLinkExist)\r
392         {\r
393                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No profile exists!!!\n"));\r
394                 return algorithm;\r
395         }\r
396 \r
397         if(pBtLinkInfo->bScoExist)\r
398                 numOfDiffProfile++;\r
399         if(pBtLinkInfo->bHidExist)\r
400                 numOfDiffProfile++;\r
401         if(pBtLinkInfo->bPanExist)\r
402                 numOfDiffProfile++;\r
403         if(pBtLinkInfo->bA2dpExist)\r
404                 numOfDiffProfile++;\r
405         \r
406         if(numOfDiffProfile == 1)\r
407         {\r
408                 if(pBtLinkInfo->bScoExist)\r
409                 {\r
410                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO only\n"));\r
411                         algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;\r
412                 }\r
413                 else\r
414                 {\r
415                         if(pBtLinkInfo->bHidExist)\r
416                         {\r
417                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID only\n"));\r
418                                 algorithm = BT_8812A_1ANT_COEX_ALGO_HID;\r
419                         }\r
420                         else if(pBtLinkInfo->bA2dpExist)\r
421                         {\r
422                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP only\n"));\r
423                                 algorithm = BT_8812A_1ANT_COEX_ALGO_A2DP;\r
424                         }\r
425                         else if(pBtLinkInfo->bPanExist)\r
426                         {\r
427                                 if(bBtHsOn)\r
428                                 {\r
429                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(HS) only\n"));\r
430                                         algorithm = BT_8812A_1ANT_COEX_ALGO_PANHS;\r
431                                 }\r
432                                 else\r
433                                 {\r
434                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(EDR) only\n"));\r
435                                         algorithm = BT_8812A_1ANT_COEX_ALGO_PANEDR;\r
436                                 }\r
437                         }\r
438                 }\r
439         }\r
440         else if(numOfDiffProfile == 2)\r
441         {\r
442                 if(pBtLinkInfo->bScoExist)\r
443                 {\r
444                         if(pBtLinkInfo->bHidExist)\r
445                         {\r
446                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID\n"));\r
447                                 algorithm = BT_8812A_1ANT_COEX_ALGO_HID;\r
448                         }\r
449                         else if(pBtLinkInfo->bA2dpExist)\r
450                         {\r
451                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP ==> SCO\n"));\r
452                                 algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;\r
453                         }\r
454                         else if(pBtLinkInfo->bPanExist)\r
455                         {\r
456                                 if(bBtHsOn)\r
457                                 {\r
458                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));\r
459                                         algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;\r
460                                 }\r
461                                 else\r
462                                 {\r
463                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));\r
464                                         algorithm = BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;\r
465                                 }\r
466                         }\r
467                 }\r
468                 else\r
469                 {\r
470                         if( pBtLinkInfo->bHidExist &&\r
471                                 pBtLinkInfo->bA2dpExist )\r
472                         {\r
473                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP\n"));\r
474                                 algorithm = BT_8812A_1ANT_COEX_ALGO_HID_A2DP;\r
475                         }\r
476                         else if( pBtLinkInfo->bHidExist &&\r
477                                 pBtLinkInfo->bPanExist )\r
478                         {\r
479                                 if(bBtHsOn)\r
480                                 {\r
481                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(HS)\n"));\r
482                                         algorithm = BT_8812A_1ANT_COEX_ALGO_HID_A2DP;\r
483                                 }\r
484                                 else\r
485                                 {\r
486                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));\r
487                                         algorithm = BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;\r
488                                 }\r
489                         }\r
490                         else if( pBtLinkInfo->bPanExist &&\r
491                                 pBtLinkInfo->bA2dpExist )\r
492                         {\r
493                                 if(bBtHsOn)\r
494                                 {\r
495                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));\r
496                                         algorithm = BT_8812A_1ANT_COEX_ALGO_A2DP_PANHS;\r
497                                 }\r
498                                 else\r
499                                 {\r
500                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));\r
501                                         algorithm = BT_8812A_1ANT_COEX_ALGO_PANEDR_A2DP;\r
502                                 }\r
503                         }\r
504                 }\r
505         }\r
506         else if(numOfDiffProfile == 3)\r
507         {\r
508                 if(pBtLinkInfo->bScoExist)\r
509                 {\r
510                         if( pBtLinkInfo->bHidExist &&\r
511                                 pBtLinkInfo->bA2dpExist )\r
512                         {\r
513                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP ==> HID\n"));\r
514                                 algorithm = BT_8812A_1ANT_COEX_ALGO_HID;\r
515                         }\r
516                         else if( pBtLinkInfo->bHidExist &&\r
517                                 pBtLinkInfo->bPanExist )\r
518                         {\r
519                                 if(bBtHsOn)\r
520                                 {\r
521                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));\r
522                                         algorithm = BT_8812A_1ANT_COEX_ALGO_HID_A2DP;\r
523                                 }\r
524                                 else\r
525                                 {\r
526                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));\r
527                                         algorithm = BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;\r
528                                 }\r
529                         }\r
530                         else if( pBtLinkInfo->bPanExist &&\r
531                                 pBtLinkInfo->bA2dpExist )\r
532                         {\r
533                                 if(bBtHsOn)\r
534                                 {\r
535                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));\r
536                                         algorithm = BT_8812A_1ANT_COEX_ALGO_SCO;\r
537                                 }\r
538                                 else\r
539                                 {\r
540                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));\r
541                                         algorithm = BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;\r
542                                 }\r
543                         }\r
544                 }\r
545                 else\r
546                 {\r
547                         if( pBtLinkInfo->bHidExist &&\r
548                                 pBtLinkInfo->bPanExist &&\r
549                                 pBtLinkInfo->bA2dpExist )\r
550                         {\r
551                                 if(bBtHsOn)\r
552                                 {\r
553                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));\r
554                                         algorithm = BT_8812A_1ANT_COEX_ALGO_HID_A2DP;\r
555                                 }\r
556                                 else\r
557                                 {\r
558                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));\r
559                                         algorithm = BT_8812A_1ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
560                                 }\r
561                         }\r
562                 }\r
563         }\r
564         else if(numOfDiffProfile >= 3)\r
565         {\r
566                 if(pBtLinkInfo->bScoExist)\r
567                 {\r
568                         if( pBtLinkInfo->bHidExist &&\r
569                                 pBtLinkInfo->bPanExist &&\r
570                                 pBtLinkInfo->bA2dpExist )\r
571                         {\r
572                                 if(bBtHsOn)\r
573                                 {\r
574                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));\r
575 \r
576                                 }\r
577                                 else\r
578                                 {\r
579                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
580                                         algorithm = BT_8812A_1ANT_COEX_ALGO_PANEDR_HID;\r
581                                 }\r
582                         }\r
583                 }\r
584         }\r
585 \r
586         return algorithm;\r
587 }\r
588 \r
589 VOID\r
590 halbtc8812a1ant_SetBtAutoReport(\r
591         IN      PBTC_COEXIST            pBtCoexist,\r
592         IN      BOOLEAN                 bEnableAutoReport\r
593         )\r
594 {\r
595 }\r
596 \r
597 VOID\r
598 halbtc8812a1ant_BtAutoReport(\r
599         IN      PBTC_COEXIST            pBtCoexist,\r
600         IN      BOOLEAN                 bForceExec,\r
601         IN      BOOLEAN                 bEnableAutoReport\r
602         )\r
603 {\r
604         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s BT Auto report = %s\n",  \r
605                 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));\r
606         pCoexDm->bCurBtAutoReport = bEnableAutoReport;\r
607 \r
608         if(!bForceExec)\r
609         {\r
610                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreBtAutoReport=%d, bCurBtAutoReport=%d\n", \r
611                         pCoexDm->bPreBtAutoReport, pCoexDm->bCurBtAutoReport));\r
612 \r
613                 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport) \r
614                         return;\r
615         }\r
616         halbtc8812a1ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);\r
617 \r
618         pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;\r
619 }\r
620 \r
621 VOID\r
622 halbtc8812a1ant_SetSwPenaltyTxRateAdaptive(\r
623         IN      PBTC_COEXIST            pBtCoexist,\r
624         IN      BOOLEAN                 bLowPenaltyRa\r
625         )\r
626 {\r
627         u1Byte  tmpU1;\r
628 \r
629         tmpU1 = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd);\r
630         tmpU1 |= BIT0;\r
631         if(bLowPenaltyRa)\r
632         {\r
633                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));\r
634                 tmpU1 &= ~BIT2;\r
635         }\r
636         else\r
637         {\r
638                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Tx rate adaptive, set normal!!\n"));\r
639                 tmpU1 |= BIT2;\r
640         }\r
641 \r
642         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, tmpU1);\r
643 }\r
644 \r
645 VOID\r
646 halbtc8812a1ant_LowPenaltyRa(\r
647         IN      PBTC_COEXIST            pBtCoexist,\r
648         IN      BOOLEAN                 bForceExec,\r
649         IN      BOOLEAN                 bLowPenaltyRa\r
650         )\r
651 {\r
652         return;\r
653         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn LowPenaltyRA = %s\n",  \r
654                 (bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));\r
655         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
656 \r
657         if(!bForceExec)\r
658         {\r
659                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreLowPenaltyRa=%d, bCurLowPenaltyRa=%d\n", \r
660                         pCoexDm->bPreLowPenaltyRa, pCoexDm->bCurLowPenaltyRa));\r
661 \r
662                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
663                         return;\r
664         }\r
665         halbtc8812a1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
666 \r
667         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
668 }\r
669 \r
670 VOID\r
671 halbtc8812a1ant_SetCoexTable(\r
672         IN      PBTC_COEXIST    pBtCoexist,\r
673         IN      u4Byte          val0x6c0,\r
674         IN      u4Byte          val0x6c4,\r
675         IN      u4Byte          val0x6c8,\r
676         IN      u1Byte          val0x6cc\r
677         )\r
678 {\r
679         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
680         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
681 \r
682         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));\r
683         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);\r
684 \r
685         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
686         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
687 \r
688         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
689         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
690 }\r
691 \r
692 VOID\r
693 halbtc8812a1ant_CoexTable(\r
694         IN      PBTC_COEXIST            pBtCoexist,\r
695         IN      BOOLEAN                 bForceExec,\r
696         IN      u4Byte                  val0x6c0,\r
697         IN      u4Byte                  val0x6c4,\r
698         IN      u4Byte                  val0x6c8,\r
699         IN      u1Byte                  val0x6cc\r
700         )\r
701 {\r
702         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
703                 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6c8, val0x6cc));\r
704         pCoexDm->curVal0x6c0 = val0x6c0;\r
705         pCoexDm->curVal0x6c4 = val0x6c4;\r
706         pCoexDm->curVal0x6c8 = val0x6c8;\r
707         pCoexDm->curVal0x6cc = val0x6cc;\r
708 \r
709         if(!bForceExec)\r
710         {\r
711                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], preVal0x6c0=0x%x, preVal0x6c4=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n", \r
712                         pCoexDm->preVal0x6c0, pCoexDm->preVal0x6c4, pCoexDm->preVal0x6c8, pCoexDm->preVal0x6cc));\r
713                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], curVal0x6c0=0x%x, curVal0x6c4=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n", \r
714                         pCoexDm->curVal0x6c0, pCoexDm->curVal0x6c4, pCoexDm->curVal0x6c8, pCoexDm->curVal0x6cc));\r
715         \r
716                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
717                         (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&\r
718                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
719                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
720                         return;\r
721         }\r
722         halbtc8812a1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);\r
723 \r
724         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
725         pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;\r
726         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
727         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
728 }\r
729 \r
730 VOID\r
731 halbtc8812a1ant_CoexTableWithType(\r
732         IN      PBTC_COEXIST            pBtCoexist,\r
733         IN      BOOLEAN                         bForceExec,\r
734         IN      u1Byte                          type\r
735         )\r
736 {\r
737         switch(type)\r
738         {\r
739                 case 0:\r
740                         halbtc8812a1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffff, 0x3);\r
741                         break;\r
742                 case 1:\r
743                         halbtc8812a1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffff, 0x3);\r
744                         break;\r
745                 case 2:\r
746                         halbtc8812a1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffff, 0x3);\r
747                         break;\r
748                 case 3:\r
749                         halbtc8812a1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffff, 0x3);\r
750                         break;\r
751                 case 4:\r
752                         halbtc8812a1ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0xffffffff, 0xffff, 0x3);\r
753                         break;\r
754                 case 5:\r
755                         halbtc8812a1ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5fff5fff, 0xffff, 0x3);\r
756                         break;\r
757                 case 6:\r
758                         halbtc8812a1ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5a5a5a, 0xffff, 0x3);\r
759                         break;\r
760                 case 7:\r
761                         halbtc8812a1ant_CoexTable(pBtCoexist, bForceExec, 0x5afa5afa, 0x5afa5afa, 0xffff, 0x3);\r
762                         break;\r
763                 default:\r
764                         break;\r
765         }\r
766 }\r
767 \r
768 VOID\r
769 halbtc8812a1ant_SetFwIgnoreWlanAct(\r
770         IN      PBTC_COEXIST            pBtCoexist,\r
771         IN      BOOLEAN                 bEnable\r
772         )\r
773 {\r
774         u1Byte  dataLen=3;\r
775         u1Byte  buf[5] = {0};\r
776 \r
777         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], %s BT Ignore Wlan_Act\n",\r
778                 (bEnable? "Enable":"Disable")));\r
779 \r
780         buf[0] = dataLen;\r
781         buf[1] = 0x1;                   // OP_Code\r
782         buf[2] = 0x1;                   // OP_Code_Length\r
783         if(bEnable)\r
784                 buf[3] = 0x1;           // OP_Code_Content\r
785         else\r
786                 buf[3] = 0x0;\r
787                 \r
788         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);      \r
789 }\r
790 \r
791 VOID\r
792 halbtc8812a1ant_IgnoreWlanAct(\r
793         IN      PBTC_COEXIST            pBtCoexist,\r
794         IN      BOOLEAN                 bForceExec,\r
795         IN      BOOLEAN                 bEnable\r
796         )\r
797 {\r
798         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
799                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
800         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
801 \r
802         if(!bForceExec)\r
803         {\r
804                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", \r
805                         pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));\r
806 \r
807                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
808                         return;\r
809         }\r
810         halbtc8812a1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
811 \r
812         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
813 }\r
814 \r
815 VOID\r
816 halbtc8812a1ant_SetFwPstdma(\r
817         IN      PBTC_COEXIST            pBtCoexist,\r
818         IN      u1Byte                  byte1,\r
819         IN      u1Byte                  byte2,\r
820         IN      u1Byte                  byte3,\r
821         IN      u1Byte                  byte4,\r
822         IN      u1Byte                  byte5\r
823         )\r
824 {\r
825         u1Byte                  H2C_Parameter[5] ={0};\r
826 \r
827         H2C_Parameter[0] = byte1;       \r
828         H2C_Parameter[1] = byte2;       \r
829         H2C_Parameter[2] = byte3;\r
830         H2C_Parameter[3] = byte4;\r
831         H2C_Parameter[4] = byte5;\r
832 \r
833         pCoexDm->psTdmaPara[0] = byte1;\r
834         pCoexDm->psTdmaPara[1] = byte2;\r
835         pCoexDm->psTdmaPara[2] = byte3;\r
836         pCoexDm->psTdmaPara[3] = byte4;\r
837         pCoexDm->psTdmaPara[4] = byte5;\r
838         \r
839         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x60(5bytes)=0x%x%08x\n", \r
840                 H2C_Parameter[0], \r
841                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
842 \r
843         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);\r
844 }\r
845 \r
846 VOID\r
847 halbtc8812a1ant_SetLpsRpwm(\r
848         IN      PBTC_COEXIST            pBtCoexist,\r
849         IN      u1Byte                  lpsVal,\r
850         IN      u1Byte                  rpwmVal\r
851         )\r
852 {\r
853         u1Byte  lps=lpsVal;\r
854         u1Byte  rpwm=rpwmVal;\r
855         \r
856         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);\r
857         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);\r
858 }\r
859 \r
860 VOID\r
861 halbtc8812a1ant_LpsRpwm(\r
862         IN      PBTC_COEXIST            pBtCoexist,\r
863         IN      BOOLEAN                 bForceExec,\r
864         IN      u1Byte                  lpsVal,\r
865         IN      u1Byte                  rpwmVal\r
866         )\r
867 {\r
868         BOOLEAN bForceExecPwrCmd=FALSE;\r
869         \r
870         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n", \r
871                 (bForceExec? "force to":""), lpsVal, rpwmVal));\r
872         pCoexDm->curLps = lpsVal;\r
873         pCoexDm->curRpwm = rpwmVal;\r
874 \r
875         if(!bForceExec)\r
876         {\r
877                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], preLps/curLps=0x%x/0x%x, preRpwm/curRpwm=0x%x/0x%x!!\n", \r
878                         pCoexDm->preLps, pCoexDm->curLps, pCoexDm->preRpwm, pCoexDm->curRpwm));\r
879 \r
880                 if( (pCoexDm->preLps == pCoexDm->curLps) &&\r
881                         (pCoexDm->preRpwm == pCoexDm->curRpwm) )\r
882                 {\r
883                         return;\r
884                 }\r
885         }\r
886         halbtc8812a1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);\r
887 \r
888         pCoexDm->preLps = pCoexDm->curLps;\r
889         pCoexDm->preRpwm = pCoexDm->curRpwm;\r
890 }\r
891 \r
892 VOID\r
893 halbtc8812a1ant_SetAntPath(\r
894         IN      PBTC_COEXIST            pBtCoexist,\r
895         IN      u1Byte                          antPosType,\r
896         IN      BOOLEAN                         bInitHwCfg,\r
897         IN      BOOLEAN                         bWifiOff\r
898         )\r
899 {\r
900         u1Byte                  u1Tmp=0;\r
901         \r
902         if(bInitHwCfg)\r
903         {\r
904                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb3, 0x77);\r
905                 \r
906                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x900, 0x00000400);\r
907                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76d, 0x1);\r
908         }\r
909         else if(bWifiOff)\r
910         {\r
911 \r
912         }\r
913         \r
914         // ext switch setting\r
915         switch(antPosType)\r
916         {\r
917                 case BTC_ANT_PATH_WIFI:\r
918                         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xcb7);\r
919                         u1Tmp |= BIT3;\r
920                         u1Tmp &= ~BIT2;                 \r
921                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb7, u1Tmp);\r
922                         break;\r
923                 case BTC_ANT_PATH_BT:\r
924                         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xcb7);\r
925                         u1Tmp &= ~BIT3;\r
926                         u1Tmp |= BIT2;\r
927                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb7, u1Tmp);\r
928                         break;\r
929                 default:\r
930                 case BTC_ANT_PATH_PTA:\r
931                         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xcb7);\r
932                         u1Tmp |= BIT3;\r
933                         u1Tmp &= ~BIT2;                 \r
934                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xcb7, u1Tmp);\r
935                         break;\r
936         }\r
937 }\r
938 \r
939 VOID\r
940 halbtc8812a1ant_PsTdma(\r
941         IN      PBTC_COEXIST            pBtCoexist,\r
942         IN      BOOLEAN                 bForceExec,\r
943         IN      BOOLEAN                 bTurnOn,\r
944         IN      u1Byte                  type\r
945         )\r
946 {\r
947         BOOLEAN                 bTurnOnByCnt=FALSE;\r
948         u1Byte                  psTdmaTypeByCnt=0, rssiAdjustVal=0;\r
949 \r
950         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
951                 (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));\r
952         pCoexDm->bCurPsTdmaOn = bTurnOn;\r
953         pCoexDm->curPsTdma = type;\r
954 \r
955         if(!bForceExec)\r
956         {\r
957                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n", \r
958                         pCoexDm->bPrePsTdmaOn, pCoexDm->bCurPsTdmaOn));\r
959                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n", \r
960                         pCoexDm->prePsTdma, pCoexDm->curPsTdma));\r
961 \r
962                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
963                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
964                         return;\r
965         }\r
966         if(bTurnOn)\r
967         {\r
968                 switch(type)\r
969                 {\r
970                         default:\r
971                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0x0, 0x50);\r
972                                 break;\r
973                         case 1:\r
974                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0x0, 0x50);\r
975                                 rssiAdjustVal = 11;\r
976                                 break;\r
977                         case 2:\r
978                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x12, 0x0, 0x50);\r
979                                 rssiAdjustVal = 14;\r
980                                 break;\r
981                         case 3:\r
982                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x40);\r
983                                 break;\r
984                         case 4:\r
985                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);\r
986                                 rssiAdjustVal = 17;\r
987                                 break;\r
988                         case 5:\r
989                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x61, 0x15, 0x3, 0x31, 0x0);\r
990                                 break;\r
991                         case 6:\r
992                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x0, 0x0);\r
993                                 break;\r
994                         case 7:\r
995                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);\r
996                                 break;\r
997                         case 8: \r
998                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
999                                 break;\r
1000                         case 9: \r
1001                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0xa, 0xa, 0x0, 0x50);\r
1002                                 rssiAdjustVal = 18;\r
1003                                 break;\r
1004                         case 10:        \r
1005                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);\r
1006                                 break;\r
1007                         case 11:        \r
1008                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x5, 0x5, 0x0, 0x50);\r
1009                                 rssiAdjustVal = 20;\r
1010                                 break;\r
1011                         case 12:\r
1012                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xeb, 0xa, 0x3, 0x31, 0x18);\r
1013                                 break;\r
1014 \r
1015                         case 15:\r
1016                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);\r
1017                                 break;\r
1018                         case 16:\r
1019                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);\r
1020                                 rssiAdjustVal = 18;\r
1021                                 break;\r
1022 \r
1023                         case 18:\r
1024                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);\r
1025                                 rssiAdjustVal = 14;\r
1026                                 break;                  \r
1027                                 \r
1028                         case 20:\r
1029                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x13, 0x25, 0x25, 0x0, 0x0);\r
1030                                 break;\r
1031                         case 21:\r
1032                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x20, 0x3, 0x10, 0x40);\r
1033                                 break;\r
1034                         case 22:\r
1035                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x13, 0x8, 0x8, 0x0, 0x40);\r
1036                                 break;\r
1037                         case 23:\r
1038                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);\r
1039                                 rssiAdjustVal = 22;\r
1040                                 break;\r
1041                         case 24:\r
1042                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);\r
1043                                 rssiAdjustVal = 22;\r
1044                                 break;\r
1045                         case 25:\r
1046                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
1047                                 rssiAdjustVal = 22;\r
1048                                 break;\r
1049                         case 26:\r
1050                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);\r
1051                                 rssiAdjustVal = 22;\r
1052                                 break;\r
1053                         case 27:\r
1054                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);\r
1055                                 rssiAdjustVal = 22;\r
1056                                 break;\r
1057                         case 28:\r
1058                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);\r
1059                                 break;\r
1060                         case 29:\r
1061                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);\r
1062                                 break;\r
1063                         case 30:\r
1064                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);\r
1065                                 break;\r
1066                         case 31:\r
1067                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);\r
1068                                 break;\r
1069                         case 32:\r
1070                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xab, 0xa, 0x3, 0x31, 0x90);\r
1071                                 break;\r
1072                         case 33:\r
1073                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90);\r
1074                                 break;\r
1075                         case 34:\r
1076                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0x0, 0x10);\r
1077                                 break;\r
1078                         case 35:\r
1079                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x0, 0x10);\r
1080                                 break;\r
1081                         case 36:\r
1082                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);\r
1083                                 break;\r
1084                         case 37:\r
1085                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x53, 0x25, 0x3, 0x10, 0x50);\r
1086                                 break;\r
1087                 }\r
1088         }\r
1089         else\r
1090         {\r
1091                 // disable PS tdma\r
1092                 switch(type)\r
1093                 {\r
1094                         case 8:\r
1095                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);\r
1096                                 halbtc8812a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FALSE, FALSE);\r
1097                                 break;\r
1098                         case 0:\r
1099                         default:\r
1100                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1101                                 halbtc8812a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
1102                                 break;\r
1103                         case 9:\r
1104                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1105                                 halbtc8812a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FALSE, FALSE);\r
1106                                 break;\r
1107                         case 10:\r
1108                                 halbtc8812a1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);\r
1109                                 halbtc8812a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
1110                                 break;\r
1111                 }\r
1112         }\r
1113         rssiAdjustVal =0;\r
1114         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);\r
1115 \r
1116         // update pre state\r
1117         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1118         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1119 }\r
1120 \r
1121 VOID\r
1122 halbtc8812a1ant_CoexAllOff(\r
1123         IN      PBTC_COEXIST            pBtCoexist\r
1124         )\r
1125 {\r
1126         // hw all off\r
1127         halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1128 }\r
1129 \r
1130 BOOLEAN\r
1131 halbtc8812a1ant_IsCommonAction(\r
1132         IN      PBTC_COEXIST            pBtCoexist\r
1133         )\r
1134 {\r
1135         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;\r
1136 \r
1137         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1138         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1139 \r
1140         if(!bWifiConnected && \r
1141                 BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
1142         {\r
1143                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));\r
1144 \r
1145                 bCommon = TRUE;\r
1146         }\r
1147         else if(bWifiConnected && \r
1148                 (BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1149         {\r
1150                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));\r
1151 \r
1152                 bCommon = TRUE;\r
1153         }\r
1154         else if(!bWifiConnected && \r
1155                 (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1156         {\r
1157                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));\r
1158 \r
1159                 bCommon = TRUE;\r
1160         }\r
1161         else if(bWifiConnected && \r
1162                 (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1163         {\r
1164                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));\r
1165 \r
1166                 bCommon = TRUE;\r
1167         }\r
1168         else if(!bWifiConnected && \r
1169                 (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus) )\r
1170         {\r
1171                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));\r
1172                 \r
1173                 bCommon = TRUE;\r
1174         }\r
1175         else\r
1176         {       \r
1177                 bCommon = FALSE;\r
1178         }\r
1179         \r
1180         return bCommon;\r
1181 }\r
1182 \r
1183 \r
1184 VOID\r
1185 halbtc8812a1ant_TdmaDurationAdjustForAcl(\r
1186         IN      PBTC_COEXIST            pBtCoexist,\r
1187         IN      u1Byte                          wifiStatus\r
1188         )\r
1189 {\r
1190         static s4Byte           up,dn,m,n,WaitCount;\r
1191         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
1192         u1Byte                  retryCount=0, btInfoExt;\r
1193 \r
1194         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));\r
1195 \r
1196         if( (BT_8812A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||\r
1197                 (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||\r
1198                 (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )\r
1199         {\r
1200                 if( pCoexDm->curPsTdma != 1 &&\r
1201                         pCoexDm->curPsTdma != 2 &&\r
1202                         pCoexDm->curPsTdma != 3 &&\r
1203                         pCoexDm->curPsTdma != 9 )\r
1204                 {\r
1205                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1206                         pCoexDm->psTdmaDuAdjType = 9;\r
1207 \r
1208                         up = 0;\r
1209                         dn = 0;\r
1210                         m = 1;\r
1211                         n= 3;\r
1212                         result = 0;\r
1213                         WaitCount = 0;\r
1214                 }               \r
1215                 return;\r
1216         }\r
1217         \r
1218         if(pCoexDm->bResetTdmaAdjust)\r
1219         {\r
1220                 pCoexDm->bResetTdmaAdjust = FALSE;\r
1221                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
1222 \r
1223                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1224                 pCoexDm->psTdmaDuAdjType = 2;\r
1225                 //============\r
1226                 up = 0;\r
1227                 dn = 0;\r
1228                 m = 1;\r
1229                 n= 3;\r
1230                 result = 0;\r
1231                 WaitCount = 0;\r
1232         }\r
1233         else\r
1234         {\r
1235                 //accquire the BT TRx retry count from BT_Info byte2\r
1236                 retryCount = pCoexSta->btRetryCnt;\r
1237                 btInfoExt = pCoexSta->btInfoExt;\r
1238                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));\r
1239                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
1240                         up, dn, m, n, WaitCount));\r
1241                 result = 0;\r
1242                 WaitCount++; \r
1243                   \r
1244                 if(retryCount == 0)  // no retry in the last 2-second duration\r
1245                 {\r
1246                         up++;\r
1247                         dn--;\r
1248 \r
1249                         if (dn <= 0)\r
1250                                 dn = 0;                          \r
1251 \r
1252                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
1253                         {\r
1254                                 WaitCount = 0; \r
1255                                 n = 3;\r
1256                                 up = 0;\r
1257                                 dn = 0;\r
1258                                 result = 1; \r
1259                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));\r
1260                         }\r
1261                 }\r
1262                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
1263                 {\r
1264                         up--; \r
1265                         dn++;\r
1266 \r
1267                         if (up <= 0)\r
1268                                 up = 0;\r
1269 \r
1270                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
1271                         {\r
1272                                 if (WaitCount <= 2)\r
1273                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1274                                 else\r
1275                                         m = 1;\r
1276 \r
1277                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1278                                         m = 20;\r
1279 \r
1280                                 n = 3*m;\r
1281                                 up = 0;\r
1282                                 dn = 0;\r
1283                                 WaitCount = 0;\r
1284                                 result = -1; \r
1285                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
1286                         }\r
1287                 }\r
1288                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
1289                 {\r
1290                         if (WaitCount == 1)\r
1291                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1292                         else\r
1293                                 m = 1;\r
1294 \r
1295                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1296                                 m = 20;\r
1297 \r
1298                         n = 3*m;\r
1299                         up = 0;\r
1300                         dn = 0;\r
1301                         WaitCount = 0; \r
1302                         result = -1;\r
1303                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
1304                 }\r
1305 \r
1306                 if(result == -1)\r
1307                 {\r
1308                         if( (BT_INFO_8812A_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
1309                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
1310                         {\r
1311                                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1312                                 pCoexDm->psTdmaDuAdjType = 9;\r
1313                         }\r
1314                         else if(pCoexDm->curPsTdma == 1)\r
1315                         {\r
1316                                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1317                                 pCoexDm->psTdmaDuAdjType = 2;\r
1318                         }\r
1319                         else if(pCoexDm->curPsTdma == 2)\r
1320                         {\r
1321                                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1322                                 pCoexDm->psTdmaDuAdjType = 9;\r
1323                         }\r
1324                         else if(pCoexDm->curPsTdma == 9)\r
1325                         {\r
1326                                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1327                                 pCoexDm->psTdmaDuAdjType = 11;\r
1328                         }\r
1329                 }\r
1330                 else if(result == 1)\r
1331                 {\r
1332                         if( (BT_INFO_8812A_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&\r
1333                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )\r
1334                         {\r
1335                                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1336                                 pCoexDm->psTdmaDuAdjType = 9;\r
1337                         }\r
1338                         else if(pCoexDm->curPsTdma == 11)\r
1339                         {\r
1340                                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1341                                 pCoexDm->psTdmaDuAdjType = 9;\r
1342                         }\r
1343                         else if(pCoexDm->curPsTdma == 9)\r
1344                         {\r
1345                                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1346                                 pCoexDm->psTdmaDuAdjType = 2;\r
1347                         }\r
1348                         else if(pCoexDm->curPsTdma == 2)\r
1349                         {\r
1350                                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1351                                 pCoexDm->psTdmaDuAdjType = 1;\r
1352                         }\r
1353                 }\r
1354 \r
1355                 if( pCoexDm->curPsTdma != 1 &&\r
1356                         pCoexDm->curPsTdma != 2 &&\r
1357                         pCoexDm->curPsTdma != 9 &&\r
1358                         pCoexDm->curPsTdma != 11 )\r
1359                 {\r
1360                         // recover to previous adjust type\r
1361                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
1362                 }\r
1363         }\r
1364 }\r
1365 \r
1366 u1Byte\r
1367 halbtc8812a1ant_PsTdmaTypeByWifiRssi(\r
1368         IN      s4Byte  wifiRssi,\r
1369         IN      s4Byte  preWifiRssi,\r
1370         IN      u1Byte  wifiRssiThresh\r
1371         )\r
1372 {\r
1373         u1Byte  psTdmaType=0;\r
1374         \r
1375         if(wifiRssi > preWifiRssi)\r
1376         {\r
1377                 if(wifiRssi > (wifiRssiThresh+5))\r
1378                 {\r
1379                         psTdmaType = 26;\r
1380                 }\r
1381                 else\r
1382                 {\r
1383                         psTdmaType = 25;\r
1384                 }\r
1385         }\r
1386         else\r
1387         {\r
1388                 if(wifiRssi > wifiRssiThresh)\r
1389                 {\r
1390                         psTdmaType = 26;\r
1391                 }\r
1392                 else\r
1393                 {\r
1394                         psTdmaType = 25;\r
1395                 }\r
1396         }\r
1397 \r
1398         return psTdmaType;\r
1399 }\r
1400 \r
1401 VOID\r
1402 halbtc8812a1ant_PsTdmaCheckForPowerSaveState(\r
1403         IN      PBTC_COEXIST            pBtCoexist,\r
1404         IN      BOOLEAN                 bNewPsState\r
1405         )\r
1406 {\r
1407         u1Byte  lpsMode=0x0;\r
1408 \r
1409         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);\r
1410         \r
1411         if(lpsMode)     // already under LPS state\r
1412         {\r
1413                 if(bNewPsState)         \r
1414                 {\r
1415                         // keep state under LPS, do nothing.\r
1416                 }\r
1417                 else\r
1418                 {\r
1419                         // will leave LPS state, turn off psTdma first\r
1420                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1421                 }\r
1422         }\r
1423         else                                            // NO PS state\r
1424         {\r
1425                 if(bNewPsState)\r
1426                 {\r
1427                         // will enter LPS state, turn off psTdma first\r
1428                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1429                 }\r
1430                 else\r
1431                 {\r
1432                         // keep state under NO PS state, do nothing.\r
1433                 }\r
1434         }\r
1435 }\r
1436 \r
1437 VOID\r
1438 halbtc8812a1ant_PowerSaveState(\r
1439         IN      PBTC_COEXIST            pBtCoexist,\r
1440         IN      u1Byte                          psType,\r
1441         IN      u1Byte                          lpsVal,\r
1442         IN      u1Byte                          rpwmVal\r
1443         )\r
1444 {\r
1445         BOOLEAN         bLowPwrDisable=FALSE;\r
1446 \r
1447         switch(psType)\r
1448         {\r
1449                 case BTC_PS_WIFI_NATIVE:\r
1450                         // recover to original 32k low power setting\r
1451                         bLowPwrDisable = FALSE;\r
1452                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1453                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1454                         break;\r
1455                 case BTC_PS_LPS_ON:\r
1456                         halbtc8812a1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);\r
1457                         halbtc8812a1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);\r
1458                         // when coex force to enter LPS, do not enter 32k low power.\r
1459                         bLowPwrDisable = TRUE;\r
1460                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1461                         // power save must executed before psTdma.\r
1462                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);\r
1463                         break;\r
1464                 case BTC_PS_LPS_OFF:\r
1465                         halbtc8812a1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);\r
1466                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
1467                         break;\r
1468                 default:\r
1469                         break;\r
1470         }\r
1471 }\r
1472 \r
1473 \r
1474 VOID\r
1475 halbtc8812a1ant_CoexUnder5G(\r
1476         IN      PBTC_COEXIST            pBtCoexist\r
1477         )\r
1478 {\r
1479         halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1480         \r
1481         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 10);\r
1482 \r
1483         halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1484 }\r
1485 \r
1486 VOID\r
1487 halbtc8812a1ant_ActionWifiOnly(\r
1488         IN      PBTC_COEXIST            pBtCoexist\r
1489         )\r
1490 {\r
1491         halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1492         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
1493 }\r
1494 \r
1495 VOID\r
1496 halbtc8812a1ant_MonitorBtEnableDisable(\r
1497         IN      PBTC_COEXIST            pBtCoexist\r
1498         )\r
1499 {\r
1500         PBTC_STACK_INFO pStackInfo=&pBtCoexist->stackInfo;\r
1501         static BOOLEAN  bPreBtDisabled=FALSE;\r
1502         static u4Byte   btDisableCnt=0;\r
1503         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
1504 \r
1505         // only 8812a need to consider if core stack is installed.\r
1506         if(!pStackInfo->hciVersion)\r
1507         {\r
1508                 bBtActive = FALSE;\r
1509         }\r
1510 \r
1511         // This function check if bt is disabled\r
1512 \r
1513         if(     pCoexSta->highPriorityTx == 0 &&\r
1514                 pCoexSta->highPriorityRx == 0 &&\r
1515                 pCoexSta->lowPriorityTx == 0 &&\r
1516                 pCoexSta->lowPriorityRx == 0)\r
1517         {\r
1518                 bBtActive = FALSE;\r
1519         }\r
1520         if(     pCoexSta->highPriorityTx == 0xffff &&\r
1521                 pCoexSta->highPriorityRx == 0xffff &&\r
1522                 pCoexSta->lowPriorityTx == 0xffff &&\r
1523                 pCoexSta->lowPriorityRx == 0xffff)\r
1524         {\r
1525                 bBtActive = FALSE;\r
1526         }\r
1527         if(bBtActive)\r
1528         {\r
1529                 btDisableCnt = 0;\r
1530                 bBtDisabled = FALSE;\r
1531                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1532                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is enabled !!\n"));\r
1533         }\r
1534         else\r
1535         {\r
1536                 btDisableCnt++;\r
1537                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], bt all counters=0, %d times!!\n", \r
1538                                 btDisableCnt));\r
1539                 if(btDisableCnt >= 2)\r
1540                 {\r
1541                         bBtDisabled = TRUE;\r
1542                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1543                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is disabled !!\n"));\r
1544                         halbtc8812a1ant_ActionWifiOnly(pBtCoexist);\r
1545                 }\r
1546         }\r
1547         if(bPreBtDisabled != bBtDisabled)\r
1548         {\r
1549                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is from %s to %s!!\n", \r
1550                         (bPreBtDisabled ? "disabled":"enabled"), \r
1551                         (bBtDisabled ? "disabled":"enabled")));\r
1552                 bPreBtDisabled = bBtDisabled;\r
1553                 if(!bBtDisabled)\r
1554                 {\r
1555                 }\r
1556                 else\r
1557                 {\r
1558                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
1559                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1560                 }\r
1561         }\r
1562 }\r
1563 \r
1564 //=============================================\r
1565 //\r
1566 //      Software Coex Mechanism start\r
1567 //\r
1568 //=============================================\r
1569 \r
1570 // SCO only or SCO+PAN(HS)\r
1571 VOID\r
1572 halbtc8812a1ant_ActionSco(\r
1573         IN      PBTC_COEXIST            pBtCoexist\r
1574         )\r
1575 {\r
1576 }\r
1577 \r
1578 VOID\r
1579 halbtc8812a1ant_ActionHid(\r
1580         IN      PBTC_COEXIST            pBtCoexist\r
1581         )\r
1582 {\r
1583 }\r
1584 \r
1585 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
1586 VOID\r
1587 halbtc8812a1ant_ActionA2dp(\r
1588         IN      PBTC_COEXIST            pBtCoexist\r
1589         )\r
1590 {\r
1591 }\r
1592 \r
1593 VOID\r
1594 halbtc8812a1ant_ActionA2dpPanHs(\r
1595         IN      PBTC_COEXIST            pBtCoexist\r
1596         )\r
1597 {\r
1598 }\r
1599 \r
1600 VOID\r
1601 halbtc8812a1ant_ActionPanEdr(\r
1602         IN      PBTC_COEXIST            pBtCoexist\r
1603         )\r
1604 {\r
1605 }\r
1606 \r
1607 //PAN(HS) only\r
1608 VOID\r
1609 halbtc8812a1ant_ActionPanHs(\r
1610         IN      PBTC_COEXIST            pBtCoexist\r
1611         )\r
1612 {\r
1613 }\r
1614 \r
1615 //PAN(EDR)+A2DP\r
1616 VOID\r
1617 halbtc8812a1ant_ActionPanEdrA2dp(\r
1618         IN      PBTC_COEXIST            pBtCoexist\r
1619         )\r
1620 {\r
1621 }\r
1622 \r
1623 VOID\r
1624 halbtc8812a1ant_ActionPanEdrHid(\r
1625         IN      PBTC_COEXIST            pBtCoexist\r
1626         )\r
1627 {\r
1628 }\r
1629 \r
1630 // HID+A2DP+PAN(EDR)\r
1631 VOID\r
1632 halbtc8812a1ant_ActionHidA2dpPanEdr(\r
1633         IN      PBTC_COEXIST            pBtCoexist\r
1634         )\r
1635 {\r
1636 }\r
1637 \r
1638 VOID\r
1639 halbtc8812a1ant_ActionHidA2dp(\r
1640         IN      PBTC_COEXIST            pBtCoexist\r
1641         )\r
1642 {\r
1643 }\r
1644 \r
1645 //=============================================\r
1646 //\r
1647 //      Non-Software Coex Mechanism start\r
1648 //\r
1649 //=============================================\r
1650 \r
1651 VOID\r
1652 halbtc8812a1ant_ActionHs(\r
1653         IN      PBTC_COEXIST            pBtCoexist\r
1654         )\r
1655 {\r
1656         BOOLEAN                 bHsConnecting=FALSE;\r
1657 \r
1658         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_CONNECTING, &bHsConnecting);\r
1659 \r
1660         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action for HS, bHsConnecting=%d!!!\n", bHsConnecting));\r
1661         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1662 \r
1663         if(bHsConnecting)\r
1664         {\r
1665                 halbtc8812a1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 3);\r
1666         }\r
1667         else\r
1668         {\r
1669                 if((pCoexSta->highPriorityTx+pCoexSta->highPriorityRx+\r
1670                         pCoexSta->lowPriorityTx+pCoexSta->lowPriorityRx)<=1200)\r
1671                         halbtc8812a1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 3);\r
1672                 else\r
1673                         halbtc8812a1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);   \r
1674         }\r
1675 }\r
1676 \r
1677 VOID\r
1678 halbtc8812a1ant_ActionBtInquiry(\r
1679         IN      PBTC_COEXIST            pBtCoexist\r
1680         )\r
1681 {\r
1682         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
1683         BOOLEAN                 bWifiConnected=FALSE;\r
1684         \r
1685         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1686 \r
1687         if(!bWifiConnected)\r
1688         {\r
1689                 halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1690                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1691                 halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1692         }\r
1693         else if( (pBtLinkInfo->bScoExist) ||\r
1694                         (pBtLinkInfo->bHidOnly) )\r
1695         {\r
1696                 // SCO/HID-only busy\r
1697                 halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1698                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);\r
1699                 halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
1700         }\r
1701         else\r
1702         {\r
1703                 halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x0);\r
1704                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 30);\r
1705                 halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1706         }\r
1707 }\r
1708 \r
1709 VOID\r
1710 halbtc8812a1ant_ActionBtScoHidOnlyBusy(\r
1711         IN      PBTC_COEXIST            pBtCoexist,\r
1712         IN      u1Byte                          wifiStatus\r
1713         )\r
1714 {\r
1715         // tdma and coex table\r
1716         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1717 \r
1718         if(BT_8812A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus)\r
1719                 halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);          \r
1720         else\r
1721                 halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1722 }\r
1723 \r
1724 VOID\r
1725 halbtc8812a1ant_ActionWifiConnectedBtAclBusy(\r
1726         IN      PBTC_COEXIST            pBtCoexist,\r
1727         IN      u1Byte                          wifiStatus\r
1728         )\r
1729 {\r
1730         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
1731 \r
1732         if(pBtLinkInfo->bHidOnly)\r
1733         {\r
1734                 halbtc8812a1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);\r
1735                 pCoexDm->bResetTdmaAdjust = TRUE;\r
1736                 return;\r
1737         }\r
1738         else if( (pBtLinkInfo->bA2dpOnly) ||\r
1739                          (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist) )\r
1740         {\r
1741                 halbtc8812a1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);\r
1742         }\r
1743         else if( (pBtLinkInfo->bPanOnly) ||\r
1744                         (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist) )\r
1745         {\r
1746                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1747                 pCoexDm->bResetTdmaAdjust = TRUE;\r
1748         }\r
1749         else\r
1750         {\r
1751                 if( (BT_8812A_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||\r
1752                         (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||\r
1753                         (BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )\r
1754                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1755                 else\r
1756                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1757                 pCoexDm->bResetTdmaAdjust = TRUE;\r
1758         }\r
1759                 \r
1760         halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
1761 }\r
1762 \r
1763 VOID\r
1764 halbtc8812a1ant_ActionWifiNotConnected(\r
1765         IN      PBTC_COEXIST            pBtCoexist\r
1766         )\r
1767 {\r
1768         // power save state\r
1769         halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1770 \r
1771         // tdma and coex table  \r
1772         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1773         halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1774 }\r
1775 \r
1776 VOID\r
1777 halbtc8812a1ant_ActionWifiNotConnectedAssoAuthScan(\r
1778         IN      PBTC_COEXIST            pBtCoexist\r
1779         )\r
1780 {\r
1781         halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1782 \r
1783         // tdma and coex table\r
1784         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1785         halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1786 }\r
1787 \r
1788 VOID\r
1789 halbtc8812a1ant_ActionWifiConnectedScan(\r
1790         IN      PBTC_COEXIST            pBtCoexist\r
1791         )\r
1792 {\r
1793         // power save state\r
1794         if(BT_8812A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)\r
1795                 halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x0);\r
1796         else\r
1797                 halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1798 \r
1799         // tdma and coex table\r
1800         if(BT_8812A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
1801         {\r
1802                 halbtc8812a1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,\r
1803                         BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
1804         }\r
1805         else if( (BT_8812A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
1806                         (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
1807         {\r
1808                 halbtc8812a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
1809                         BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SCAN);\r
1810         }\r
1811         else\r
1812         {\r
1813                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1814                 halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1815         }\r
1816 }\r
1817 \r
1818 VOID\r
1819 halbtc8812a1ant_ActionWifiConnectedSpecialPacket(\r
1820         IN      PBTC_COEXIST            pBtCoexist\r
1821         )\r
1822 {\r
1823         // power save state\r
1824         if(BT_8812A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)\r
1825                 halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x0);\r
1826         else\r
1827                 halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1828 \r
1829         // tdma and coex table\r
1830         if(BT_8812A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
1831         {\r
1832                 halbtc8812a1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,\r
1833                         BT_8812A_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT);\r
1834         }\r
1835         else\r
1836         {\r
1837                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1838                 halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1839         }\r
1840 }\r
1841 \r
1842 VOID\r
1843 halbtc8812a1ant_ActionWifiConnected(\r
1844         IN      PBTC_COEXIST            pBtCoexist\r
1845         )\r
1846 {\r
1847         BOOLEAN         bWifiConnected=FALSE, bWifiBusy=FALSE;\r
1848         BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
1849         BOOLEAN         bUnder4way=FALSE;\r
1850         u4Byte          wifiBw;\r
1851 \r
1852         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect()===>\n"));\r
1853 \r
1854         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1855         if(!bWifiConnected)\r
1856         {\r
1857                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi not connected<===\n"));\r
1858                 return;\r
1859         }\r
1860 \r
1861         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
1862         if(bUnder4way)\r
1863         {\r
1864                 halbtc8812a1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
1865                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));\r
1866                 return;\r
1867         }\r
1868         \r
1869         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
1870         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
1871         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
1872         if(bScan || bLink || bRoam)\r
1873         {\r
1874                 halbtc8812a1ant_ActionWifiConnectedScan(pBtCoexist);\r
1875                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));\r
1876                 return;\r
1877         }\r
1878 \r
1879         // power save state\r
1880         if(BT_8812A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)\r
1881                 halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x0);\r
1882         else\r
1883                 halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
1884 \r
1885         // tdma and coex table\r
1886         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);      \r
1887         if(!bWifiBusy)\r
1888         {\r
1889                 if(BT_8812A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
1890                 {\r
1891                         halbtc8812a1ant_ActionWifiConnectedBtAclBusy(pBtCoexist, \r
1892                                 BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
1893                 }\r
1894                 else if( (BT_8812A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
1895                         (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
1896                 {\r
1897                         halbtc8812a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
1898                                 BT_8812A_1ANT_WIFI_STATUS_CONNECTED_IDLE);\r
1899                 }\r
1900                 else\r
1901                 {\r
1902                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1903                         halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1904                 }\r
1905         }\r
1906         else\r
1907         {\r
1908                 if(BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
1909                 {\r
1910                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1911                         halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1912                 }\r
1913                 else if(BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)\r
1914                 {                       \r
1915                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1916                         halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1917                 }\r
1918                 else if(BT_8812A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)\r
1919                 {\r
1920                         halbtc8812a1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,\r
1921                                 BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
1922                 }\r
1923                 else if( (BT_8812A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
1924                         (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
1925                 {\r
1926                         halbtc8812a1ant_ActionBtScoHidOnlyBusy(pBtCoexist,\r
1927                                 BT_8812A_1ANT_WIFI_STATUS_CONNECTED_BUSY);\r
1928                 }\r
1929                 else \r
1930                 {\r
1931                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1932                         halbtc8812a1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1933                 }\r
1934         }\r
1935 }\r
1936 \r
1937 VOID\r
1938 halbtc8812a1ant_RunSwCoexistMechanism(\r
1939         IN      PBTC_COEXIST            pBtCoexist\r
1940         )\r
1941 {\r
1942         BOOLEAN                         bWifiUnder5G=FALSE, bWifiBusy=FALSE, bWifiConnected=FALSE;\r
1943         u1Byte                          btInfoOriginal=0, btRetryCnt=0;\r
1944         u1Byte                          algorithm=0;\r
1945 \r
1946         return;\r
1947 \r
1948         algorithm = halbtc8812a1ant_ActionAlgorithm(pBtCoexist);\r
1949         pCoexDm->curAlgorithm = algorithm;              \r
1950 \r
1951         if(halbtc8812a1ant_IsCommonAction(pBtCoexist))\r
1952         {\r
1953         }\r
1954         else\r
1955         {\r
1956                 switch(pCoexDm->curAlgorithm)\r
1957                 {\r
1958                         case BT_8812A_1ANT_COEX_ALGO_SCO:\r
1959                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = SCO.\n"));\r
1960                                 halbtc8812a1ant_ActionSco(pBtCoexist);\r
1961                                 break;\r
1962                         case BT_8812A_1ANT_COEX_ALGO_HID:\r
1963                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID.\n"));\r
1964                                 halbtc8812a1ant_ActionHid(pBtCoexist);\r
1965                                 break;\r
1966                         case BT_8812A_1ANT_COEX_ALGO_A2DP:\r
1967                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP.\n"));\r
1968                                 halbtc8812a1ant_ActionA2dp(pBtCoexist);\r
1969                                 break;\r
1970                         case BT_8812A_1ANT_COEX_ALGO_A2DP_PANHS:\r
1971                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));\r
1972                                 halbtc8812a1ant_ActionA2dpPanHs(pBtCoexist);\r
1973                                 break;\r
1974                         case BT_8812A_1ANT_COEX_ALGO_PANEDR:\r
1975                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR).\n"));\r
1976                                 halbtc8812a1ant_ActionPanEdr(pBtCoexist);\r
1977                                 break;\r
1978                         case BT_8812A_1ANT_COEX_ALGO_PANHS:\r
1979                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HS mode.\n"));\r
1980                                 halbtc8812a1ant_ActionPanHs(pBtCoexist);\r
1981                                 break;\r
1982                         case BT_8812A_1ANT_COEX_ALGO_PANEDR_A2DP:\r
1983                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));\r
1984                                 halbtc8812a1ant_ActionPanEdrA2dp(pBtCoexist);\r
1985                                 break;\r
1986                         case BT_8812A_1ANT_COEX_ALGO_PANEDR_HID:\r
1987                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));\r
1988                                 halbtc8812a1ant_ActionPanEdrHid(pBtCoexist);\r
1989                                 break;\r
1990                         case BT_8812A_1ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
1991                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));\r
1992                                 halbtc8812a1ant_ActionHidA2dpPanEdr(pBtCoexist);\r
1993                                 break;\r
1994                         case BT_8812A_1ANT_COEX_ALGO_HID_A2DP:\r
1995                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = HID+A2DP.\n"));\r
1996                                 halbtc8812a1ant_ActionHidA2dp(pBtCoexist);\r
1997                                 break;\r
1998                         default:\r
1999                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action algorithm = coexist All Off!!\n"));\r
2000                                 halbtc8812a1ant_CoexAllOff(pBtCoexist);\r
2001                                 break;\r
2002                 }\r
2003                 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
2004         }\r
2005 }\r
2006 \r
2007 VOID\r
2008 halbtc8812a1ant_RunCoexistMechanism(\r
2009         IN      PBTC_COEXIST            pBtCoexist\r
2010         )\r
2011 {\r
2012         BOOLEAN bWifiUnder5G=FALSE, bWifiBusy=FALSE, bWifiConnected=FALSE, bBtHsOn=FALSE;\r
2013 \r
2014         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism()===>\n"));\r
2015 \r
2016         if(pBtCoexist->bManualControl)\r
2017         {\r
2018                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));\r
2019                 return;\r
2020         }\r
2021         \r
2022         if(pBtCoexist->bStopCoexDm)\r
2023         {\r
2024                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));\r
2025                 return;\r
2026         }\r
2027 \r
2028         if(pCoexSta->bUnderIps)\r
2029         {\r
2030                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is under IPS !!!\n"));\r
2031                 return;\r
2032         }\r
2033 \r
2034         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
2035         if(bWifiUnder5G)\r
2036         {\r
2037                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), run 5G coex setting!!<===\n"));\r
2038                 halbtc8812a1ant_CoexUnder5G(pBtCoexist);\r
2039                 return;\r
2040         }\r
2041 \r
2042         halbtc8812a1ant_RunSwCoexistMechanism(pBtCoexist);\r
2043 \r
2044         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2045         if(pCoexSta->bC2hBtInquiryPage)\r
2046         {\r
2047                 halbtc8812a1ant_ActionBtInquiry(pBtCoexist);\r
2048                 return;\r
2049         }\r
2050         else if(bBtHsOn)\r
2051         {\r
2052                 halbtc8812a1ant_ActionHs(pBtCoexist);\r
2053                 return;\r
2054         }\r
2055 \r
2056         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2057         if(!bWifiConnected)\r
2058         {\r
2059                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2060                 \r
2061                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is non connected-idle !!!\n"));\r
2062 \r
2063                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2064                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2065                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2066 \r
2067                 if(bScan || bLink || bRoam)\r
2068                         halbtc8812a1ant_ActionWifiNotConnectedAssoAuthScan(pBtCoexist);\r
2069                 else\r
2070                         halbtc8812a1ant_ActionWifiNotConnected(pBtCoexist);\r
2071         }\r
2072         else    // wifi LPS/Busy\r
2073         {\r
2074                 halbtc8812a1ant_ActionWifiConnected(pBtCoexist);\r
2075         }\r
2076 }\r
2077 \r
2078 VOID\r
2079 halbtc8812a1ant_InitCoexDm(\r
2080         IN      PBTC_COEXIST            pBtCoexist\r
2081         )\r
2082 {       \r
2083         // force to reset coex mechanism\r
2084         halbtc8812a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);\r
2085         halbtc8812a1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
2086 }\r
2087 \r
2088 //============================================================\r
2089 // work around function start with wa_halbtc8812a1ant_\r
2090 //============================================================\r
2091 //============================================================\r
2092 // extern function start with EXhalbtc8812a1ant_\r
2093 //============================================================\r
2094 VOID\r
2095 EXhalbtc8812a1ant_PowerOnSetting(\r
2096         IN      PBTC_COEXIST            pBtCoexist\r
2097         )\r
2098 {\r
2099 }\r
2100 \r
2101 VOID\r
2102 EXhalbtc8812a1ant_InitHwConfig(\r
2103         IN      PBTC_COEXIST            pBtCoexist,\r
2104         IN      BOOLEAN                         bWifiOnly\r
2105         )\r
2106 {\r
2107         u4Byte  u4Tmp=0;\r
2108         u2Byte  u2Tmp=0;\r
2109         u1Byte  u1Tmp=0;\r
2110 \r
2111         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 1Ant Init HW Config!!\n"));\r
2112         \r
2113         //ant sw control to BT\r
2114         halbtc8812a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, TRUE, FALSE);\r
2115 \r
2116         // 0x790[5:0]=0x5\r
2117         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);\r
2118         u1Tmp &= 0xc0;\r
2119         u1Tmp |= 0x5;\r
2120         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);\r
2121 \r
2122         // PTA parameter\r
2123         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, 0x0);\r
2124         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, 0xffff);\r
2125         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, 0x55555555);\r
2126         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, 0x55555555);\r
2127 \r
2128         // coex parameters\r
2129         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);\r
2130 \r
2131         // enable counter statistics\r
2132         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
2133 \r
2134         // enable PTA\r
2135         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x20);\r
2136 \r
2137         // bt clock related\r
2138         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4);\r
2139         u1Tmp |= BIT7;\r
2140         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4, u1Tmp);\r
2141 \r
2142         // bt clock related\r
2143         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7);\r
2144         u1Tmp |= BIT1;\r
2145         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x7, u1Tmp);\r
2146 }\r
2147 \r
2148 VOID\r
2149 EXhalbtc8812a1ant_InitCoexDm(\r
2150         IN      PBTC_COEXIST            pBtCoexist\r
2151         )\r
2152 {\r
2153         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));\r
2154 \r
2155         pBtCoexist->bStopCoexDm = FALSE;\r
2156 \r
2157         halbtc8812a1ant_InitCoexDm(pBtCoexist);\r
2158 }\r
2159 \r
2160 VOID\r
2161 EXhalbtc8812a1ant_DisplayCoexInfo(\r
2162         IN      PBTC_COEXIST            pBtCoexist\r
2163         )\r
2164 {\r
2165         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
2166         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
2167         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2168         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
2169         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
2170         u4Byte                          u4Tmp[4];\r
2171         BOOLEAN                         bRoam=FALSE, bScan=FALSE, bLink=FALSE, bWifiUnder5G=FALSE;\r
2172         BOOLEAN                         bBtHsOn=FALSE, bWifiBusy=FALSE;\r
2173         s4Byte                          wifiRssi=0, btHsRssi=0;\r
2174         u4Byte                          wifiBw, wifiTrafficDir;\r
2175         u1Byte                          wifiDot11Chnl, wifiHsChnl;\r
2176         u4Byte                          fwVer=0, btPatchVer=0;\r
2177 \r
2178         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
2179         CL_PRINTF(cliBuf);\r
2180 \r
2181         if(pBtCoexist->bManualControl)\r
2182         {\r
2183                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");\r
2184                 CL_PRINTF(cliBuf);\r
2185                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
2186                 CL_PRINTF(cliBuf);\r
2187         }\r
2188         if(pBtCoexist->bStopCoexDm)\r
2189         {\r
2190                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");\r
2191                 CL_PRINTF(cliBuf);\r
2192                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
2193                 CL_PRINTF(cliBuf);\r
2194         }\r
2195 \r
2196         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
2197                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
2198         CL_PRINTF(cliBuf);      \r
2199         \r
2200         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
2201                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
2202         CL_PRINTF(cliBuf);\r
2203 \r
2204         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
2205         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
2206         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \\r
2207                 GLCoexVerDate8812a1Ant, GLCoexVer8812a1Ant, fwVer, btPatchVer, btPatchVer);\r
2208         CL_PRINTF(cliBuf);\r
2209 \r
2210         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2211         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiDot11Chnl);\r
2212         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl);\r
2213         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(HsMode)", \\r
2214                 wifiDot11Chnl, wifiHsChnl, bBtHsOn);\r
2215         CL_PRINTF(cliBuf);\r
2216 \r
2217         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "H2C Wifi inform bt chnl Info", \\r
2218                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
2219                 pCoexDm->wifiChnlInfo[2]);\r
2220         CL_PRINTF(cliBuf);\r
2221 \r
2222         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
2223         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);\r
2224         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \\r
2225                 wifiRssi, btHsRssi);\r
2226         CL_PRINTF(cliBuf);\r
2227 \r
2228         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2229         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2230         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2231         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \\r
2232                 bLink, bRoam, bScan);\r
2233         CL_PRINTF(cliBuf);\r
2234 \r
2235         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
2236         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2237         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
2238         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
2239         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s ", "Wifi status", \\r
2240                 (bWifiUnder5G? "5G":"2.4G"),\r
2241                 ((BTC_WIFI_BW_LEGACY==wifiBw)? "Legacy": (((BTC_WIFI_BW_HT40==wifiBw)? "HT40":"HT20"))),\r
2242                 ((!bWifiBusy)? "idle": ((BTC_WIFI_TRAFFIC_TX==wifiTrafficDir)? "uplink":"downlink")));\r
2243         CL_PRINTF(cliBuf);\r
2244         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
2245                 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":\r
2246                 (  (BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),\r
2247                 pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
2248         CL_PRINTF(cliBuf);\r
2249                                         \r
2250         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
2251                 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist);\r
2252         CL_PRINTF(cliBuf);      \r
2253         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
2254 \r
2255         btInfoExt = pCoexSta->btInfoExt;\r
2256         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
2257                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
2258         CL_PRINTF(cliBuf);      \r
2259 \r
2260         for(i=0; i<BT_INFO_SRC_8812A_1ANT_MAX; i++)\r
2261         {\r
2262                 if(pCoexSta->btInfoC2hCnt[i])\r
2263                 {                               \r
2264                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8812a1Ant[i], \\r
2265                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
2266                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
2267                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
2268                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
2269                         CL_PRINTF(cliBuf);\r
2270                 }\r
2271         }\r
2272         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/%s, (0x%x/0x%x)", "PS state, IPS/LPS, (lps/rpwm)", \\r
2273                 ((pCoexSta->bUnderIps? "IPS ON":"IPS OFF")),\r
2274                 ((pCoexSta->bUnderLps? "LPS ON":"LPS OFF")), \r
2275                 pBtCoexist->btInfo.lpsVal, \r
2276                 pBtCoexist->btInfo.rpwmVal);\r
2277         CL_PRINTF(cliBuf);\r
2278         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);\r
2279 \r
2280         if(!pBtCoexist->bManualControl)\r
2281         {\r
2282                 // Sw mechanism \r
2283                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
2284                 CL_PRINTF(cliBuf);\r
2285         \r
2286                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "DelBA/ BtCtrlAgg/ AggSize", \\r
2287                         (pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),\r
2288                                 pBtCoexist->btInfo.aggBufSize);\r
2289                 CL_PRINTF(cliBuf);\r
2290                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \\r
2291                                 pBtCoexist->btInfo.raMask);\r
2292                 CL_PRINTF(cliBuf);\r
2293 \r
2294                 // Fw mechanism         \r
2295                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
2296                 CL_PRINTF(cliBuf);      \r
2297 \r
2298                 psTdmaCase = pCoexDm->curPsTdma;\r
2299                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA", \\r
2300                         pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
2301                         pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
2302                         pCoexDm->psTdmaPara[4], psTdmaCase);\r
2303                 CL_PRINTF(cliBuf);\r
2304 \r
2305                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Latest error condition(should be 0)", \\r
2306                         pCoexDm->errorCondition);\r
2307                 CL_PRINTF(cliBuf);\r
2308                 \r
2309                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IgnWlanAct", \\r
2310                         pCoexDm->bCurIgnoreWlanAct);\r
2311                 CL_PRINTF(cliBuf);\r
2312         }\r
2313 \r
2314         // Hw setting           \r
2315         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
2316         CL_PRINTF(cliBuf);      \r
2317 \r
2318         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
2319         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778", \\r
2320                 u1Tmp[0]);\r
2321         CL_PRINTF(cliBuf);\r
2322         \r
2323         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xcb3);\r
2324         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xcb7);\r
2325         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x900);\r
2326         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0xcb3/0xcb7/0x900", \\r
2327                 u1Tmp[0], u1Tmp[1], u4Tmp[0]);\r
2328         CL_PRINTF(cliBuf);\r
2329 \r
2330         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
2331         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \\r
2332                 u1Tmp[0]);\r
2333         CL_PRINTF(cliBuf);\r
2334 \r
2335         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
2336         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
2337         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
2338                 u4Tmp[0], u1Tmp[0]);\r
2339         CL_PRINTF(cliBuf);\r
2340 \r
2341         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
2342         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
2343                 u4Tmp[0]);\r
2344         CL_PRINTF(cliBuf);\r
2345 \r
2346         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
2347         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
2348         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
2349         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);\r
2350         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \\r
2351                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);\r
2352         CL_PRINTF(cliBuf);\r
2353 \r
2354         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(hp rx[31:16]/tx[15:0])", \\r
2355                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
2356         CL_PRINTF(cliBuf);\r
2357         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(lp rx[31:16]/tx[15:0])", \\r
2358                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
2359         CL_PRINTF(cliBuf);\r
2360         \r
2361         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
2362 }\r
2363 \r
2364 \r
2365 VOID\r
2366 EXhalbtc8812a1ant_IpsNotify(\r
2367         IN      PBTC_COEXIST            pBtCoexist,\r
2368         IN      u1Byte                  type\r
2369         )\r
2370 {\r
2371         u4Byte  u4Tmp=0;\r
2372 \r
2373         if(pBtCoexist->bManualControl ||        pBtCoexist->bStopCoexDm)\r
2374                 return;\r
2375 \r
2376         if(BTC_IPS_ENTER == type)\r
2377         {\r
2378                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));\r
2379                 pCoexSta->bUnderIps = TRUE;             \r
2380                 halbtc8812a1ant_CoexAllOff(pBtCoexist);\r
2381                 halbtc8812a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
2382         }\r
2383         else if(BTC_IPS_LEAVE == type)\r
2384         {\r
2385                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));\r
2386                 pCoexSta->bUnderIps = FALSE;\r
2387         }\r
2388 }\r
2389 \r
2390 VOID\r
2391 EXhalbtc8812a1ant_LpsNotify(\r
2392         IN      PBTC_COEXIST            pBtCoexist,\r
2393         IN      u1Byte                  type\r
2394         )\r
2395 {\r
2396         if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)\r
2397                 return;\r
2398 \r
2399         if(BTC_LPS_ENABLE == type)\r
2400         {\r
2401                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));\r
2402                 pCoexSta->bUnderLps = TRUE;\r
2403         }\r
2404         else if(BTC_LPS_DISABLE == type)\r
2405         {\r
2406                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));\r
2407                 pCoexSta->bUnderLps = FALSE;\r
2408         }\r
2409 }\r
2410 \r
2411 VOID\r
2412 EXhalbtc8812a1ant_ScanNotify(\r
2413         IN      PBTC_COEXIST            pBtCoexist,\r
2414         IN      u1Byte                  type\r
2415         )\r
2416 {\r
2417         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
2418 \r
2419         if(pBtCoexist->bManualControl ||\r
2420                 pBtCoexist->bStopCoexDm ||\r
2421                 pBtCoexist->btInfo.bBtDisabled )\r
2422                 return;\r
2423 \r
2424         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2425         if(pCoexSta->bC2hBtInquiryPage)\r
2426         {\r
2427                 halbtc8812a1ant_ActionBtInquiry(pBtCoexist);\r
2428                 return;\r
2429         }\r
2430         else if(bBtHsOn)\r
2431         {\r
2432                 halbtc8812a1ant_ActionHs(pBtCoexist);\r
2433                 return;\r
2434         }\r
2435 \r
2436         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2437         if(BTC_SCAN_START == type)\r
2438         {       \r
2439                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
2440                 if(!bWifiConnected)     // non-connected scan\r
2441                 {\r
2442                         halbtc8812a1ant_ActionWifiNotConnectedAssoAuthScan(pBtCoexist);\r
2443                 }\r
2444                 else    // wifi is connected\r
2445                 {\r
2446                         halbtc8812a1ant_ActionWifiConnectedScan(pBtCoexist);\r
2447                 }\r
2448         }\r
2449         else if(BTC_SCAN_FINISH == type)\r
2450         {\r
2451                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
2452                 if(!bWifiConnected)     // non-connected scan\r
2453                 {\r
2454                         halbtc8812a1ant_ActionWifiNotConnected(pBtCoexist);\r
2455                 }\r
2456                 else\r
2457                 {\r
2458                         halbtc8812a1ant_ActionWifiConnected(pBtCoexist);\r
2459                 }\r
2460         }\r
2461 }\r
2462 \r
2463 VOID\r
2464 EXhalbtc8812a1ant_ConnectNotify(\r
2465         IN      PBTC_COEXIST            pBtCoexist,\r
2466         IN      u1Byte                  type\r
2467         )\r
2468 {\r
2469         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    \r
2470 \r
2471         if(pBtCoexist->bManualControl ||\r
2472                 pBtCoexist->bStopCoexDm ||\r
2473                 pBtCoexist->btInfo.bBtDisabled )\r
2474                 return;\r
2475 \r
2476         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2477         if(pCoexSta->bC2hBtInquiryPage)\r
2478         {\r
2479                 halbtc8812a1ant_ActionBtInquiry(pBtCoexist);\r
2480                 return;\r
2481         }\r
2482         else if(bBtHsOn)\r
2483         {\r
2484                 halbtc8812a1ant_ActionHs(pBtCoexist);\r
2485                 return;\r
2486         }\r
2487 \r
2488         if(BTC_ASSOCIATE_START == type)\r
2489         {\r
2490                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));\r
2491                 halbtc8812a1ant_ActionWifiNotConnectedAssoAuthScan(pBtCoexist);\r
2492         }\r
2493         else if(BTC_ASSOCIATE_FINISH == type)\r
2494         {\r
2495                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));\r
2496                 \r
2497                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2498                 if(!bWifiConnected) // non-connected scan\r
2499                 {\r
2500                         halbtc8812a1ant_ActionWifiNotConnected(pBtCoexist);\r
2501                 }\r
2502                 else\r
2503                 {\r
2504                         halbtc8812a1ant_ActionWifiConnected(pBtCoexist);\r
2505                 }\r
2506         }\r
2507 }\r
2508 \r
2509 VOID\r
2510 EXhalbtc8812a1ant_MediaStatusNotify(\r
2511         IN      PBTC_COEXIST                    pBtCoexist,\r
2512         IN      u1Byte                          type\r
2513         )\r
2514 {\r
2515         u1Byte                  dataLen=5;\r
2516         u1Byte                  buf[6] = {0};\r
2517         u1Byte                  H2C_Parameter[3] ={0};\r
2518         u4Byte                  wifiBw;\r
2519         u1Byte                  wifiCentralChnl;\r
2520 \r
2521         if(pBtCoexist->bManualControl ||\r
2522                 pBtCoexist->bStopCoexDm ||\r
2523                 pBtCoexist->btInfo.bBtDisabled )\r
2524                 return;\r
2525 \r
2526         if(BTC_MEDIA_CONNECT == type)\r
2527         {\r
2528                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));\r
2529         }\r
2530         else\r
2531         {\r
2532                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));\r
2533         }\r
2534 \r
2535         // only 2.4G we need to inform bt the chnl mask\r
2536         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
2537         if( (BTC_MEDIA_CONNECT == type) &&\r
2538                 (wifiCentralChnl <= 14) )\r
2539         {\r
2540                 H2C_Parameter[0] = 0x1;\r
2541                 H2C_Parameter[1] = wifiCentralChnl;\r
2542                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2543                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
2544                         H2C_Parameter[2] = 0x30;\r
2545                 else\r
2546                         H2C_Parameter[2] = 0x20;\r
2547         }\r
2548                 \r
2549         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
2550         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
2551         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
2552         \r
2553         buf[0] = dataLen;\r
2554         buf[1] = 0x5;                           // OP_Code\r
2555         buf[2] = 0x3;                           // OP_Code_Length\r
2556         buf[3] = H2C_Parameter[0];      // OP_Code_Content\r
2557         buf[4] = H2C_Parameter[1];\r
2558         buf[5] = H2C_Parameter[2];\r
2559                 \r
2560         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);              \r
2561 }\r
2562 \r
2563 VOID\r
2564 EXhalbtc8812a1ant_SpecialPacketNotify(\r
2565         IN      PBTC_COEXIST                    pBtCoexist,\r
2566         IN      u1Byte                          type\r
2567         )\r
2568 {\r
2569         BOOLEAN bBtHsOn=FALSE;\r
2570 \r
2571         if(pBtCoexist->bManualControl ||\r
2572                 pBtCoexist->bStopCoexDm ||\r
2573                 pBtCoexist->btInfo.bBtDisabled )\r
2574                 return;\r
2575 \r
2576         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2577         if(pCoexSta->bC2hBtInquiryPage)\r
2578         {\r
2579                 halbtc8812a1ant_ActionBtInquiry(pBtCoexist);\r
2580                 return;\r
2581         }\r
2582         else if(bBtHsOn)\r
2583         {\r
2584                 halbtc8812a1ant_ActionHs(pBtCoexist);\r
2585                 return;\r
2586         }\r
2587 \r
2588         if( BTC_PACKET_DHCP == type ||\r
2589                 BTC_PACKET_EAPOL == type )\r
2590         {\r
2591                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], special Packet(%d) notify\n", type));\r
2592                 halbtc8812a1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);\r
2593         }\r
2594 }\r
2595 \r
2596 VOID\r
2597 EXhalbtc8812a1ant_BtInfoNotify(\r
2598         IN      PBTC_COEXIST            pBtCoexist,\r
2599         IN      pu1Byte                 tmpBuf,\r
2600         IN      u1Byte                  length\r
2601         )\r
2602 {\r
2603         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
2604         u1Byte                          btInfo=0;\r
2605         u1Byte                          i, rspSource=0;\r
2606         static u4Byte           setBtPsdMode=0;\r
2607         BOOLEAN                         bBtBusy=FALSE;\r
2608         BOOLEAN                         bWifiConnected=FALSE;\r
2609         BOOLEAN                         bBtCtrlAggBufSize=FALSE, bRejApAggPkt=FALSE;\r
2610 \r
2611         rspSource = tmpBuf[0]&0xf;\r
2612         if(rspSource >= BT_INFO_SRC_8812A_1ANT_MAX)\r
2613                 rspSource = BT_INFO_SRC_8812A_1ANT_WIFI_FW;\r
2614         pCoexSta->btInfoC2hCnt[rspSource]++;\r
2615 \r
2616         if(BT_INFO_SRC_8812A_1ANT_BT_RSP == rspSource)\r
2617                 pCoexSta->btInfoQueryCnt = pCoexSta->btInfoC2hCnt[BT_INFO_SRC_8812A_1ANT_BT_RSP];\r
2618 \r
2619         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
2620         for(i=0; i<length; i++)\r
2621         {\r
2622                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
2623                 if(i == 1)\r
2624                         btInfo = tmpBuf[i];\r
2625                 if(i == length-1)\r
2626                 {\r
2627                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));\r
2628                 }\r
2629                 else\r
2630                 {\r
2631                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));\r
2632                 }\r
2633         }\r
2634 \r
2635         if(pBtCoexist->btInfo.bBtDisabled)\r
2636         {\r
2637                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), return for BT is disabled <===\n"));\r
2638                 return;\r
2639         }       \r
2640 \r
2641         if(pBtCoexist->bManualControl)\r
2642         {\r
2643                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n"));\r
2644                 return;\r
2645         }\r
2646         if(pBtCoexist->bStopCoexDm)\r
2647         {\r
2648                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), return for Coex STOPPED!!<===\n"));\r
2649                 return;\r
2650         }\r
2651 \r
2652         if(BT_INFO_SRC_8812A_1ANT_WIFI_FW != rspSource)\r
2653         {\r
2654                 pCoexSta->btRetryCnt =  // [3:0]\r
2655                         pCoexSta->btInfoC2h[rspSource][2]&0xf;\r
2656 \r
2657                 pCoexSta->btRssi =\r
2658                         pCoexSta->btInfoC2h[rspSource][3]*2+10;\r
2659 \r
2660                 pCoexSta->btInfoExt = \r
2661                         pCoexSta->btInfoC2h[rspSource][4];\r
2662 \r
2663                 // Here we need to resend some wifi info to BT\r
2664                 // because bt is reset and loss of the info.\r
2665                 if( (pCoexSta->btInfoExt & BIT1) )\r
2666                 {\r
2667                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));\r
2668                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2669                         if(bWifiConnected)\r
2670                         {\r
2671                                 EXhalbtc8812a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);\r
2672                         }\r
2673                         else\r
2674                         {\r
2675                                 EXhalbtc8812a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
2676                         }\r
2677 \r
2678                         setBtPsdMode = 0;\r
2679                 }\r
2680 \r
2681                 // test-chip bt patch only rsp the status for BT_RSP, \r
2682                 // so temporary we consider the following only under BT_RSP\r
2683                 if(BT_INFO_SRC_8812A_1ANT_BT_RSP == rspSource)\r
2684                 {\r
2685                         if( (pCoexSta->btInfoExt & BIT3) )\r
2686                         {\r
2687                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));\r
2688                                 halbtc8812a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
2689                         }\r
2690                         else\r
2691                         {\r
2692                                 // BT already NOT ignore Wlan active, do nothing here.\r
2693                         }\r
2694 \r
2695                         if( (pCoexSta->btInfoExt & BIT4) )\r
2696                         {\r
2697                                 // BT auto report already enabled, do nothing\r
2698                         }\r
2699                         else\r
2700                         {\r
2701                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit4 check, set BT to enable Auto Report!!\n"));\r
2702                                 halbtc8812a1ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);\r
2703                         }\r
2704                 }\r
2705         }\r
2706                 \r
2707         // check BIT2 first ==> check if bt is under inquiry or page scan\r
2708         if(btInfo & BT_INFO_8812A_1ANT_B_INQ_PAGE)\r
2709                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
2710         else\r
2711                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
2712 \r
2713         // set link exist status\r
2714         if(!(btInfo&BT_INFO_8812A_1ANT_B_CONNECTION))\r
2715         {\r
2716                 pCoexSta->bBtLinkExist = FALSE;\r
2717                 pCoexSta->bPanExist = FALSE;\r
2718                 pCoexSta->bA2dpExist = FALSE;\r
2719                 pCoexSta->bHidExist = FALSE;\r
2720                 pCoexSta->bScoExist = FALSE;\r
2721         }\r
2722         else    // connection exists\r
2723         {\r
2724                 pCoexSta->bBtLinkExist = TRUE;\r
2725                 if(btInfo & BT_INFO_8812A_1ANT_B_FTP)\r
2726                         pCoexSta->bPanExist = TRUE;\r
2727                 else\r
2728                         pCoexSta->bPanExist = FALSE;\r
2729                 if(btInfo & BT_INFO_8812A_1ANT_B_A2DP)\r
2730                         pCoexSta->bA2dpExist = TRUE;\r
2731                 else\r
2732                         pCoexSta->bA2dpExist = FALSE;\r
2733                 if(btInfo & BT_INFO_8812A_1ANT_B_HID)\r
2734                         pCoexSta->bHidExist = TRUE;\r
2735                 else\r
2736                         pCoexSta->bHidExist = FALSE;\r
2737                 if(btInfo & BT_INFO_8812A_1ANT_B_SCO_ESCO)\r
2738                         pCoexSta->bScoExist = TRUE;\r
2739                 else\r
2740                         pCoexSta->bScoExist = FALSE;\r
2741         }\r
2742 \r
2743         halbtc8812a1ant_UpdateBtLinkInfo(pBtCoexist);\r
2744         \r
2745         if(!(btInfo&BT_INFO_8812A_1ANT_B_CONNECTION))\r
2746         {\r
2747                 pCoexDm->btStatus = BT_8812A_1ANT_BT_STATUS_NON_CONNECTED_IDLE;\r
2748                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), bt non-connected idle!!!\n"));\r
2749         }\r
2750         else if(btInfo == BT_INFO_8812A_1ANT_B_CONNECTION)      // connection exists but no busy\r
2751         {\r
2752                 pCoexDm->btStatus = BT_8812A_1ANT_BT_STATUS_CONNECTED_IDLE;\r
2753                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), bt connected-idle!!!\n"));\r
2754         }               \r
2755         else if((btInfo&BT_INFO_8812A_1ANT_B_SCO_ESCO) ||\r
2756                 (btInfo&BT_INFO_8812A_1ANT_B_SCO_BUSY))\r
2757         {\r
2758                 pCoexDm->btStatus = BT_8812A_1ANT_BT_STATUS_SCO_BUSY;\r
2759                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), bt sco busy!!!\n"));\r
2760         }\r
2761         else if(btInfo&BT_INFO_8812A_1ANT_B_ACL_BUSY)\r
2762         {\r
2763                 if(BT_8812A_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)\r
2764                         pCoexDm->bResetTdmaAdjust = TRUE;\r
2765                 pCoexDm->btStatus = BT_8812A_1ANT_BT_STATUS_ACL_BUSY;\r
2766                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), bt acl busy!!!\n"));\r
2767         }\r
2768         else\r
2769         {\r
2770                 pCoexDm->btStatus = BT_8812A_1ANT_BT_STATUS_MAX;\r
2771                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), bt non-defined state!!!\n"));\r
2772         }\r
2773 \r
2774         if(pBtLinkInfo->bScoExist)\r
2775         {\r
2776                 bRejApAggPkt = TRUE;\r
2777                 halbtc8812a1ant_UpdateRaMask(pBtCoexist, NORMAL_EXEC, BTC_RATE_DISABLE, 0x00000003);    // disable cck 1M2M.\r
2778         }\r
2779         else\r
2780         {\r
2781                 halbtc8812a1ant_UpdateRaMask(pBtCoexist, NORMAL_EXEC, BTC_RATE_ENABLE, 0x00000003);     // enable cck 1M2M.\r
2782         }\r
2783 \r
2784         if( (BT_8812A_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
2785                 (BT_8812A_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
2786                 (BT_8812A_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
2787         {\r
2788                 bBtBusy = TRUE;\r
2789                 if(pBtLinkInfo->bHidExist)\r
2790                         bBtCtrlAggBufSize = TRUE;\r
2791         }\r
2792         else\r
2793         {\r
2794                 bBtBusy = FALSE;\r
2795         }\r
2796         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
2797 \r
2798         //============================================\r
2799         //      Aggregation related setting\r
2800         //============================================  \r
2801         // if sco, reject AddBA\r
2802         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejApAggPkt);\r
2803         // decide BT control aggregation buf size or not\r
2804         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlAggBufSize);\r
2805         // real update aggregation setting\r
2806         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);\r
2807         //============================================\r
2808 \r
2809         halbtc8812a1ant_RunCoexistMechanism(pBtCoexist);\r
2810 }\r
2811 \r
2812 VOID\r
2813 EXhalbtc8812a1ant_HaltNotify(\r
2814         IN      PBTC_COEXIST                    pBtCoexist\r
2815         )\r
2816 {\r
2817         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));\r
2818 \r
2819         halbtc8812a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
2820         halbtc8812a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
2821         halbtc8812a1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
2822         EXhalbtc8812a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
2823 }\r
2824 \r
2825 VOID\r
2826 EXhalbtc8812a1ant_PnpNotify(\r
2827         IN      PBTC_COEXIST                    pBtCoexist,\r
2828         IN      u1Byte                          pnpState\r
2829         )\r
2830 {\r
2831         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify\n"));\r
2832 \r
2833         if(BTC_WIFI_PNP_SLEEP == pnpState)\r
2834         {\r
2835                 pBtCoexist->bStopCoexDm = TRUE;\r
2836                 halbtc8812a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
2837                 halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2838                 halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
2839         }\r
2840         else if(BTC_WIFI_PNP_WAKE_UP == pnpState)\r
2841         {\r
2842                 \r
2843         }\r
2844 }\r
2845 \r
2846 VOID\r
2847 EXhalbtc8812a1ant_Periodical(\r
2848         IN      PBTC_COEXIST                    pBtCoexist\r
2849         )\r
2850 {\r
2851         static u1Byte           disVerInfoCnt=0;\r
2852         u4Byte                          fwVer=0, btPatchVer=0;\r
2853         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
2854         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
2855 \r
2856         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ==========================Periodical===========================\n"));\r
2857 \r
2858         if(disVerInfoCnt <= 5)\r
2859         {\r
2860                 disVerInfoCnt += 1;\r
2861                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
2862                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n", \\r
2863                         pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));\r
2864                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n", \\r
2865                         ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));\r
2866                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
2867                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
2868                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", \\r
2869                         GLCoexVerDate8812a1Ant, GLCoexVer8812a1Ant, fwVer, btPatchVer, btPatchVer));\r
2870                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
2871         }\r
2872 \r
2873         halbtc8812a1ant_QueryBtInfo(pBtCoexist);\r
2874         halbtc8812a1ant_MonitorBtCtr(pBtCoexist);\r
2875         halbtc8812a1ant_MonitorBtEnableDisable(pBtCoexist);\r
2876 }\r
2877 \r
2878 VOID\r
2879 EXhalbtc8812a1ant_DbgControl(\r
2880         IN      PBTC_COEXIST                    pBtCoexist,\r
2881         IN      u1Byte                          opCode,\r
2882         IN      u1Byte                          opLen,\r
2883         IN      pu1Byte                         pData\r
2884         )\r
2885 {\r
2886         switch(opCode)\r
2887         {\r
2888                 case BTC_DBG_SET_COEX_NORMAL:\r
2889                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Set CoexMode to Normal\n"));\r
2890                         pBtCoexist->bManualControl = FALSE;\r
2891                         halbtc8812a1ant_InitCoexDm(pBtCoexist);\r
2892                         break;\r
2893                 case BTC_DBG_SET_COEX_WIFI_ONLY:\r
2894                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Set CoexMode to Wifi Only\n"));\r
2895                         pBtCoexist->bManualControl = TRUE;\r
2896                         halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2897                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
2898                         break;\r
2899                 case BTC_DBG_SET_COEX_BT_ONLY:\r
2900                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Set CoexMode to BT only\n"));\r
2901                         pBtCoexist->bManualControl = TRUE;\r
2902                         halbtc8812a1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
2903                         halbtc8812a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);      \r
2904                         break;\r
2905                 case BTC_DBG_SET_COEX_DEC_BT_PWR:\r
2906                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Set Dec BT power\n"));\r
2907                         {\r
2908                                 u1Byte  dataLen=4;\r
2909                                 u1Byte  buf[6] = {0};\r
2910                                 u1Byte  decBtPwr=0, pwrLevel=0;\r
2911                                 if(opLen == 2)\r
2912                                 {\r
2913                                         decBtPwr = pData[0];\r
2914                                         pwrLevel = pData[1];\r
2915                                 \r
2916                                         buf[0] = dataLen;\r
2917                                         buf[1] = 0x3;           // OP_Code\r
2918                                         buf[2] = 0x2;           // OP_Code_Length\r
2919                                         \r
2920                                         buf[3] = decBtPwr;      // OP_Code_Content\r
2921                                         buf[4] = pwrLevel;\r
2922                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Set Dec BT power=%d, pwrLevel=%d\n", decBtPwr, pwrLevel));\r
2923                                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);      \r
2924                                 }\r
2925                         }\r
2926                         break;\r
2927 \r
2928                 case BTC_DBG_SET_COEX_BT_AFH_MAP:\r
2929                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Set BT AFH Map\n"));\r
2930                         {\r
2931                                 u1Byte  dataLen=5;\r
2932                                 u1Byte  buf[6] = {0};\r
2933                                 if(opLen == 3)\r
2934                                 {\r
2935                                         buf[0] = dataLen;\r
2936                                         buf[1] = 0x5;                           // OP_Code\r
2937                                         buf[2] = 0x3;                           // OP_Code_Length\r
2938 \r
2939                                         buf[3] = pData[0];                      // OP_Code_Content\r
2940                                         buf[4] = pData[1];\r
2941                                         buf[5] = pData[2];\r
2942 \r
2943                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Set BT AFH Map = %02x %02x %02x\n", \r
2944                                                 pData[0], pData[1], pData[2]));\r
2945                                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);\r
2946                                 }\r
2947                         }\r
2948                         break;\r
2949                 \r
2950                 case BTC_DBG_SET_COEX_BT_IGNORE_WLAN_ACT:\r
2951                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Set BT Ignore Wlan Active\n"));\r
2952                         {\r
2953                                 u1Byte  dataLen=3;\r
2954                                 u1Byte  buf[6] = {0};\r
2955                                 if(opLen == 1)\r
2956                                 {\r
2957                                         buf[0] = dataLen;\r
2958                                         buf[1] = 0x1;                   // OP_Code\r
2959                                         buf[2] = 0x1;                   // OP_Code_Length\r
2960 \r
2961                                         buf[3] = pData[0];              // OP_Code_Content\r
2962                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Set BT Ignore Wlan Active = 0x%x\n", \r
2963                                                 pData[0]));\r
2964                                                 \r
2965                                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_BT_COEX, (PVOID)&buf[0]);\r
2966                                 }\r
2967                         }\r
2968                         break;\r
2969                 default:\r
2970                         break;\r
2971         }\r
2972 }\r
2973 #endif\r
2974 \r