wifi: renew patch drivers/net/wireless
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rtl8188eu / hal / OUTSRC-BTCoexist / HalBtc8192e2Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for RTL8192E 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_8192E_2ANT               GLCoexDm8192e2Ant;\r
20 static PCOEX_DM_8192E_2ANT      pCoexDm=&GLCoexDm8192e2Ant;\r
21 static COEX_STA_8192E_2ANT              GLCoexSta8192e2Ant;\r
22 static PCOEX_STA_8192E_2ANT     pCoexSta=&GLCoexSta8192e2Ant;\r
23 \r
24 const char *const GLBtInfoSrc8192e2Ant[]={\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  GLCoexVerDate8192e2Ant=20130912;\r
31 u4Byte  GLCoexVer8192e2Ant=0x35;\r
32 \r
33 //============================================================\r
34 // local function proto type if needed\r
35 //============================================================\r
36 //============================================================\r
37 // local function start with halbtc8192e2ant_\r
38 //============================================================\r
39 u1Byte\r
40 halbtc8192e2ant_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                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi pre state=LOW\n"));\r
57                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
58                         {\r
59                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
60                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
61                         }\r
62                         else\r
63                         {\r
64                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
65                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
66                         }\r
67                 }\r
68                 else\r
69                 {\r
70                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi pre state=HIGH\n"));\r
71                         if(btRssi < rssiThresh)\r
72                         {\r
73                                 btRssiState = BTC_RSSI_STATE_LOW;\r
74                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
75                         }\r
76                         else\r
77                         {\r
78                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
79                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
80                         }\r
81                 }\r
82         }\r
83         else if(levelNum == 3)\r
84         {\r
85                 if(rssiThresh > rssiThresh1)\r
86                 {\r
87                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi thresh error!!\n"));\r
88                         return pCoexSta->preBtRssiState;\r
89                 }\r
90                 \r
91                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
92                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
93                 {\r
94                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi pre state=LOW\n"));\r
95                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
96                         {\r
97                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
98                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
99                         }\r
100                         else\r
101                         {\r
102                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
103                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
104                         }\r
105                 }\r
106                 else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
107                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))\r
108                 {\r
109                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi pre state=MEDIUM\n"));\r
110                         if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
111                         {\r
112                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
113                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
114                         }\r
115                         else if(btRssi < rssiThresh)\r
116                         {\r
117                                 btRssiState = BTC_RSSI_STATE_LOW;\r
118                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
119                         }\r
120                         else\r
121                         {\r
122                                 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
123                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Medium\n"));\r
124                         }\r
125                 }\r
126                 else\r
127                 {\r
128                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi pre state=HIGH\n"));\r
129                         if(btRssi < rssiThresh1)\r
130                         {\r
131                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
132                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
133                         }\r
134                         else\r
135                         {\r
136                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
137                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
138                         }\r
139                 }\r
140         }\r
141                 \r
142         pCoexSta->preBtRssiState = btRssiState;\r
143 \r
144         return btRssiState;\r
145 }\r
146 \r
147 u1Byte\r
148 halbtc8192e2ant_WifiRssiState(\r
149         IN      PBTC_COEXIST            pBtCoexist,\r
150         IN      u1Byte                  index,\r
151         IN      u1Byte                  levelNum,\r
152         IN      u1Byte                  rssiThresh,\r
153         IN      u1Byte                  rssiThresh1\r
154         )\r
155 {\r
156         s4Byte                  wifiRssi=0;\r
157         u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];\r
158 \r
159         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
160         \r
161         if(levelNum == 2)\r
162         {\r
163                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
164                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
165                 {\r
166                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
167                         {\r
168                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
169                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
170                         }\r
171                         else\r
172                         {\r
173                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
174                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
175                         }\r
176                 }\r
177                 else\r
178                 {\r
179                         if(wifiRssi < rssiThresh)\r
180                         {\r
181                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
182                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
183                         }\r
184                         else\r
185                         {\r
186                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
187                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
188                         }\r
189                 }\r
190         }\r
191         else if(levelNum == 3)\r
192         {\r
193                 if(rssiThresh > rssiThresh1)\r
194                 {\r
195                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI thresh error!!\n"));\r
196                         return pCoexSta->preWifiRssiState[index];\r
197                 }\r
198                 \r
199                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
200                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
201                 {\r
202                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
203                         {\r
204                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
205                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
206                         }\r
207                         else\r
208                         {\r
209                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
210                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
211                         }\r
212                 }\r
213                 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||\r
214                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))\r
215                 {\r
216                         if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
217                         {\r
218                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
219                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
220                         }\r
221                         else if(wifiRssi < rssiThresh)\r
222                         {\r
223                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
224                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
225                         }\r
226                         else\r
227                         {\r
228                                 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
229                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Medium\n"));\r
230                         }\r
231                 }\r
232                 else\r
233                 {\r
234                         if(wifiRssi < rssiThresh1)\r
235                         {\r
236                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
237                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
238                         }\r
239                         else\r
240                         {\r
241                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
242                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
243                         }\r
244                 }\r
245         }\r
246                 \r
247         pCoexSta->preWifiRssiState[index] = wifiRssiState;\r
248 \r
249         return wifiRssiState;\r
250 }\r
251 \r
252 VOID\r
253 halbtc8192e2ant_MonitorBtEnableDisable(\r
254         IN      PBTC_COEXIST            pBtCoexist\r
255         )\r
256 {\r
257         static BOOLEAN  bPreBtDisabled=FALSE;\r
258         static u4Byte   btDisableCnt=0;\r
259         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
260 \r
261         // This function check if bt is disabled\r
262 \r
263         if(     pCoexSta->highPriorityTx == 0 &&\r
264                 pCoexSta->highPriorityRx == 0 &&\r
265                 pCoexSta->lowPriorityTx == 0 &&\r
266                 pCoexSta->lowPriorityRx == 0)\r
267         {\r
268                 bBtActive = FALSE;\r
269         }\r
270         if(     pCoexSta->highPriorityTx == 0xffff &&\r
271                 pCoexSta->highPriorityRx == 0xffff &&\r
272                 pCoexSta->lowPriorityTx == 0xffff &&\r
273                 pCoexSta->lowPriorityRx == 0xffff)\r
274         {\r
275                 bBtActive = FALSE;\r
276         }\r
277         if(bBtActive)\r
278         {\r
279                 btDisableCnt = 0;\r
280                 bBtDisabled = FALSE;\r
281                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
282                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is enabled !!\n"));\r
283         }\r
284         else\r
285         {\r
286                 btDisableCnt++;\r
287                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], bt all counters=0, %d times!!\n", \r
288                                 btDisableCnt));\r
289                 if(btDisableCnt >= 2)\r
290                 {\r
291                         bBtDisabled = TRUE;\r
292                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
293                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is disabled !!\n"));\r
294                 }\r
295         }\r
296         if(bPreBtDisabled != bBtDisabled)\r
297         {\r
298                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is from %s to %s!!\n", \r
299                         (bPreBtDisabled ? "disabled":"enabled"), \r
300                         (bBtDisabled ? "disabled":"enabled")));\r
301                 bPreBtDisabled = bBtDisabled;\r
302                 if(!bBtDisabled)\r
303                 {\r
304                 }\r
305                 else\r
306                 {\r
307                 }\r
308         }\r
309 }\r
310 \r
311 u4Byte\r
312 halbtc8192e2ant_DecideRaMask(\r
313         IN      PBTC_COEXIST            pBtCoexist,\r
314         IN      u1Byte                          ssType,\r
315         IN      u4Byte                          raMaskType\r
316         )\r
317 {\r
318         u4Byte  disRaMask=0x0;\r
319         \r
320         switch(raMaskType)\r
321         {\r
322                 case 0: // normal mode\r
323                         if(ssType == 2)\r
324                                 disRaMask = 0x0;                        // enable 2ss\r
325                         else\r
326                                 disRaMask = 0xfff00000;         // disable 2ss\r
327                         break;\r
328                 case 1: // disable cck 1/2\r
329                         if(ssType == 2)\r
330                                 disRaMask = 0x00000003;         // enable 2ss\r
331                         else\r
332                                 disRaMask = 0xfff00003;         // disable 2ss\r
333                         break;\r
334                 case 2: // disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4\r
335                         if(ssType == 2)\r
336                                 disRaMask = 0x0001f1f7;         // enable 2ss\r
337                         else\r
338                                 disRaMask = 0xfff1f1f7;         // disable 2ss\r
339                         break;\r
340                 default:\r
341                         break;\r
342         }\r
343 \r
344         return disRaMask;\r
345 }\r
346 \r
347 VOID\r
348 halbtc8192e2ant_UpdateRaMask(\r
349         IN      PBTC_COEXIST            pBtCoexist,\r
350         IN      BOOLEAN                         bForceExec,\r
351         IN      u4Byte                          disRateMask\r
352         )\r
353 {\r
354         pCoexDm->curRaMask = disRateMask;\r
355         \r
356         if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))\r
357         {\r
358                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);\r
359         }\r
360         pCoexDm->preRaMask = pCoexDm->curRaMask;\r
361 }\r
362 \r
363 VOID\r
364 halbtc8192e2ant_AutoRateFallbackRetry(\r
365         IN      PBTC_COEXIST            pBtCoexist,\r
366         IN      BOOLEAN                         bForceExec,\r
367         IN      u1Byte                          type\r
368         )\r
369 {\r
370         BOOLEAN bWifiUnderBMode=FALSE;\r
371         \r
372         pCoexDm->curArfrType = type;\r
373 \r
374         if( bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType))\r
375         {\r
376                 switch(pCoexDm->curArfrType)\r
377                 {\r
378                         case 0: // normal mode\r
379                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, pCoexDm->backupArfrCnt1);\r
380                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, pCoexDm->backupArfrCnt2);\r
381                                 break;\r
382                         case 1: \r
383                                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);\r
384                                 if(bWifiUnderBMode)\r
385                                 {\r
386                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);\r
387                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);\r
388                                 }\r
389                                 else\r
390                                 {\r
391                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);\r
392                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);\r
393                                 }\r
394                                 break;\r
395                         default:\r
396                                 break;\r
397                 }\r
398         }\r
399 \r
400         pCoexDm->preArfrType = pCoexDm->curArfrType;\r
401 }\r
402 \r
403 VOID\r
404 halbtc8192e2ant_RetryLimit(\r
405         IN      PBTC_COEXIST            pBtCoexist,\r
406         IN      BOOLEAN                         bForceExec,\r
407         IN      u1Byte                          type\r
408         )\r
409 {\r
410         pCoexDm->curRetryLimitType = type;\r
411 \r
412         if( bForceExec || (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType))\r
413         {\r
414                 switch(pCoexDm->curRetryLimitType)\r
415                 {\r
416                         case 0: // normal mode\r
417                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, pCoexDm->backupRetryLimit);\r
418                                 break;\r
419                         case 1: // retry limit=8\r
420                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);\r
421                                 break;\r
422                         default:\r
423                                 break;\r
424                 }\r
425         }\r
426 \r
427         pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;\r
428 }\r
429 \r
430 VOID\r
431 halbtc8192e2ant_AmpduMaxTime(\r
432         IN      PBTC_COEXIST            pBtCoexist,\r
433         IN      BOOLEAN                         bForceExec,\r
434         IN      u1Byte                          type\r
435         )\r
436 {\r
437         pCoexDm->curAmpduTimeType = type;\r
438 \r
439         if( bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType))\r
440         {\r
441                 switch(pCoexDm->curAmpduTimeType)\r
442                 {\r
443                         case 0: // normal mode\r
444                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime);\r
445                                 break;\r
446                         case 1: // AMPDU timw = 0x38 * 32us\r
447                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);\r
448                                 break;\r
449                         default:\r
450                                 break;\r
451                 }\r
452         }\r
453 \r
454         pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;\r
455 }\r
456 \r
457 VOID\r
458 halbtc8192e2ant_LimitedTx(\r
459         IN      PBTC_COEXIST            pBtCoexist,\r
460         IN      BOOLEAN                         bForceExec,\r
461         IN      u1Byte                          raMaskType,\r
462         IN      u1Byte                          arfrType,\r
463         IN      u1Byte                          retryLimitType,\r
464         IN      u1Byte                          ampduTimeType\r
465         )\r
466 {\r
467         u4Byte  disRaMask=0x0;\r
468 \r
469         pCoexDm->curRaMaskType = raMaskType;\r
470         disRaMask = halbtc8192e2ant_DecideRaMask(pBtCoexist, pCoexDm->curSsType, raMaskType);\r
471         halbtc8192e2ant_UpdateRaMask(pBtCoexist, bForceExec, disRaMask);\r
472 \r
473         halbtc8192e2ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);\r
474         halbtc8192e2ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);\r
475         halbtc8192e2ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);\r
476 }\r
477 \r
478 VOID\r
479 halbtc8192e2ant_LimitedRx(\r
480         IN      PBTC_COEXIST            pBtCoexist,\r
481         IN      BOOLEAN                         bForceExec,\r
482         IN      BOOLEAN                         bRejApAggPkt,\r
483         IN      BOOLEAN                         bBtCtrlAggBufSize,\r
484         IN      u1Byte                          aggBufSize\r
485         )\r
486 {\r
487         BOOLEAN bRejectRxAgg=bRejApAggPkt;\r
488         BOOLEAN bBtCtrlRxAggSize=bBtCtrlAggBufSize;\r
489         u1Byte  rxAggSize=aggBufSize;\r
490 \r
491         //============================================\r
492         //      Rx Aggregation related setting\r
493         //============================================\r
494         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);\r
495         // decide BT control aggregation buf size or not\r
496         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);\r
497         // aggregation buf size, only work when BT control Rx aggregation size.\r
498         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);\r
499         // real update aggregation setting\r
500         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);\r
501 \r
502 \r
503 }\r
504 \r
505 VOID\r
506 halbtc8192e2ant_MonitorBtCtr(\r
507         IN      PBTC_COEXIST            pBtCoexist\r
508         )\r
509 {\r
510         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp;\r
511         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
512         u1Byte                  u1Tmp;\r
513         \r
514         regHPTxRx = 0x770;\r
515         regLPTxRx = 0x774;\r
516 \r
517         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
518         regHPTx = u4Tmp & bMaskLWord;\r
519         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
520 \r
521         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
522         regLPTx = u4Tmp & bMaskLWord;\r
523         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
524                 \r
525         pCoexSta->highPriorityTx = regHPTx;\r
526         pCoexSta->highPriorityRx = regHPRx;\r
527         pCoexSta->lowPriorityTx = regLPTx;\r
528         pCoexSta->lowPriorityRx = regLPRx;\r
529 \r
530         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
531                 regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));\r
532         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
533                 regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));\r
534 \r
535         // reset counter\r
536         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
537 }\r
538 \r
539 VOID\r
540 halbtc8192e2ant_QueryBtInfo(\r
541         IN      PBTC_COEXIST            pBtCoexist\r
542         )\r
543 {\r
544         u1Byte                  H2C_Parameter[1] ={0};\r
545 \r
546         pCoexSta->bC2hBtInfoReqSent = TRUE;\r
547 \r
548         H2C_Parameter[0] |= BIT0;       // trigger\r
549 \r
550         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n", \r
551                 H2C_Parameter[0]));\r
552 \r
553         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);\r
554 }\r
555 \r
556 BOOLEAN\r
557 halbtc8192e2ant_IsWifiStatusChanged(\r
558         IN      PBTC_COEXIST            pBtCoexist\r
559         )\r
560 {\r
561         static BOOLEAN  bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;\r
562         BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;\r
563         BOOLEAN bWifiConnected=FALSE;\r
564 \r
565         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
566         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
567         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
568         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
569 \r
570         if(bWifiConnected)\r
571         {\r
572                 if(bWifiBusy != bPreWifiBusy)\r
573                 {\r
574                         bPreWifiBusy = bWifiBusy;\r
575                         return TRUE;\r
576                 }\r
577                 if(bUnder4way != bPreUnder4way)\r
578                 {\r
579                         bPreUnder4way = bUnder4way;\r
580                         return TRUE;\r
581                 }\r
582                 if(bBtHsOn != bPreBtHsOn)\r
583                 {\r
584                         bPreBtHsOn = bBtHsOn;\r
585                         return TRUE;\r
586                 }\r
587         }\r
588 \r
589         return FALSE;\r
590 }\r
591 \r
592 VOID\r
593 halbtc8192e2ant_UpdateBtLinkInfo(\r
594         IN      PBTC_COEXIST            pBtCoexist\r
595         )\r
596 {\r
597         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
598         BOOLEAN                         bBtHsOn=FALSE;\r
599 \r
600         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
601 \r
602         pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;\r
603         pBtLinkInfo->bScoExist = pCoexSta->bScoExist;\r
604         pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;\r
605         pBtLinkInfo->bPanExist = pCoexSta->bPanExist;\r
606         pBtLinkInfo->bHidExist = pCoexSta->bHidExist;\r
607 \r
608         // work around for HS mode.\r
609         if(bBtHsOn)\r
610         {\r
611                 pBtLinkInfo->bPanExist = TRUE;\r
612                 pBtLinkInfo->bBtLinkExist = TRUE;\r
613         }\r
614 \r
615         // check if Sco only\r
616         if( pBtLinkInfo->bScoExist &&\r
617                 !pBtLinkInfo->bA2dpExist &&\r
618                 !pBtLinkInfo->bPanExist &&\r
619                 !pBtLinkInfo->bHidExist )\r
620                 pBtLinkInfo->bScoOnly = TRUE;\r
621         else\r
622                 pBtLinkInfo->bScoOnly = FALSE;\r
623 \r
624         // check if A2dp only\r
625         if( !pBtLinkInfo->bScoExist &&\r
626                 pBtLinkInfo->bA2dpExist &&\r
627                 !pBtLinkInfo->bPanExist &&\r
628                 !pBtLinkInfo->bHidExist )\r
629                 pBtLinkInfo->bA2dpOnly = TRUE;\r
630         else\r
631                 pBtLinkInfo->bA2dpOnly = FALSE;\r
632 \r
633         // check if Pan only\r
634         if( !pBtLinkInfo->bScoExist &&\r
635                 !pBtLinkInfo->bA2dpExist &&\r
636                 pBtLinkInfo->bPanExist &&\r
637                 !pBtLinkInfo->bHidExist )\r
638                 pBtLinkInfo->bPanOnly = TRUE;\r
639         else\r
640                 pBtLinkInfo->bPanOnly = FALSE;\r
641         \r
642         // check if Hid only\r
643         if( !pBtLinkInfo->bScoExist &&\r
644                 !pBtLinkInfo->bA2dpExist &&\r
645                 !pBtLinkInfo->bPanExist &&\r
646                 pBtLinkInfo->bHidExist )\r
647                 pBtLinkInfo->bHidOnly = TRUE;\r
648         else\r
649                 pBtLinkInfo->bHidOnly = FALSE;\r
650 }\r
651 \r
652 u1Byte\r
653 halbtc8192e2ant_ActionAlgorithm(\r
654         IN      PBTC_COEXIST            pBtCoexist\r
655         )\r
656 {\r
657         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
658         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
659         BOOLEAN                         bBtHsOn=FALSE;\r
660         u1Byte                          algorithm=BT_8192E_2ANT_COEX_ALGO_UNDEFINED;\r
661         u1Byte                          numOfDiffProfile=0;\r
662 \r
663         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
664                 \r
665         if(!pBtLinkInfo->bBtLinkExist)\r
666         {\r
667                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No BT link exists!!!\n"));\r
668                 return algorithm;\r
669         }\r
670 \r
671         if(pBtLinkInfo->bScoExist)\r
672                 numOfDiffProfile++;\r
673         if(pBtLinkInfo->bHidExist)\r
674                 numOfDiffProfile++;\r
675         if(pBtLinkInfo->bPanExist)\r
676                 numOfDiffProfile++;\r
677         if(pBtLinkInfo->bA2dpExist)\r
678                 numOfDiffProfile++;\r
679         \r
680         if(numOfDiffProfile == 1)\r
681         {\r
682                 if(pBtLinkInfo->bScoExist)\r
683                 {\r
684                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO only\n"));\r
685                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;\r
686                 }\r
687                 else\r
688                 {\r
689                         if(pBtLinkInfo->bHidExist)\r
690                         {\r
691                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID only\n"));\r
692                                 algorithm = BT_8192E_2ANT_COEX_ALGO_HID;\r
693                         }\r
694                         else if(pBtLinkInfo->bA2dpExist)\r
695                         {\r
696                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP only\n"));\r
697                                 algorithm = BT_8192E_2ANT_COEX_ALGO_A2DP;\r
698                         }\r
699                         else if(pBtLinkInfo->bPanExist)\r
700                         {\r
701                                 if(bBtHsOn)\r
702                                 {\r
703                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(HS) only\n"));\r
704                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANHS;\r
705                                 }\r
706                                 else\r
707                                 {\r
708                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(EDR) only\n"));\r
709                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR;\r
710                                 }\r
711                         }\r
712                 }\r
713         }\r
714         else if(numOfDiffProfile == 2)\r
715         {\r
716                 if(pBtLinkInfo->bScoExist)\r
717                 {\r
718                         if(pBtLinkInfo->bHidExist)\r
719                         {\r
720                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID\n"));\r
721                                 algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;\r
722                         }\r
723                         else if(pBtLinkInfo->bA2dpExist)\r
724                         {\r
725                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP ==> SCO\n"));\r
726                                 algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;\r
727                         }\r
728                         else if(pBtLinkInfo->bPanExist)\r
729                         {\r
730                                 if(bBtHsOn)\r
731                                 {\r
732                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));\r
733                                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;\r
734                                 }\r
735                                 else\r
736                                 {\r
737                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));\r
738                                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO_PAN;\r
739                                 }\r
740                         }\r
741                 }\r
742                 else\r
743                 {\r
744                         if( pBtLinkInfo->bHidExist &&\r
745                                 pBtLinkInfo->bA2dpExist )\r
746                         {\r
747                                 if(pStackInfo->numOfHid >= 2)\r
748                                 {\r
749                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID*2 + A2DP\n"));\r
750                                         algorithm = BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
751                                 }\r
752                                 else\r
753                                 {                       \r
754                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP\n"));\r
755                                         algorithm = BT_8192E_2ANT_COEX_ALGO_HID_A2DP;\r
756                                 }\r
757                         }\r
758                         else if( pBtLinkInfo->bHidExist &&\r
759                                 pBtLinkInfo->bPanExist )\r
760                         {\r
761                                 if(bBtHsOn)\r
762                                 {\r
763                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(HS)\n"));\r
764                                         algorithm = BT_8192E_2ANT_COEX_ALGO_HID;\r
765                                 }\r
766                                 else\r
767                                 {\r
768                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));\r
769                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;\r
770                                 }\r
771                         }\r
772                         else if( pBtLinkInfo->bPanExist &&\r
773                                 pBtLinkInfo->bA2dpExist )\r
774                         {\r
775                                 if(bBtHsOn)\r
776                                 {\r
777                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));\r
778                                         algorithm = BT_8192E_2ANT_COEX_ALGO_A2DP_PANHS;\r
779                                 }\r
780                                 else\r
781                                 {\r
782                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));\r
783                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_A2DP;\r
784                                 }\r
785                         }\r
786                 }\r
787         }\r
788         else if(numOfDiffProfile == 3)\r
789         {\r
790                 if(pBtLinkInfo->bScoExist)\r
791                 {\r
792                         if( pBtLinkInfo->bHidExist &&\r
793                                 pBtLinkInfo->bA2dpExist )\r
794                         {\r
795                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP ==> HID\n"));\r
796                                 algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;\r
797                         }\r
798                         else if( pBtLinkInfo->bHidExist &&\r
799                                 pBtLinkInfo->bPanExist )\r
800                         {\r
801                                 if(bBtHsOn)\r
802                                 {\r
803                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));\r
804                                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;\r
805                                 }\r
806                                 else\r
807                                 {\r
808                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));\r
809                                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO_PAN;\r
810                                 }\r
811                         }\r
812                         else if( pBtLinkInfo->bPanExist &&\r
813                                 pBtLinkInfo->bA2dpExist )\r
814                         {\r
815                                 if(bBtHsOn)\r
816                                 {\r
817                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));\r
818                                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;\r
819                                 }\r
820                                 else\r
821                                 {\r
822                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));\r
823                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;\r
824                                 }\r
825                         }\r
826                 }\r
827                 else\r
828                 {\r
829                         if( pBtLinkInfo->bHidExist &&\r
830                                 pBtLinkInfo->bPanExist &&\r
831                                 pBtLinkInfo->bA2dpExist )\r
832                         {\r
833                                 if(bBtHsOn)\r
834                                 {\r
835                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));\r
836                                         algorithm = BT_8192E_2ANT_COEX_ALGO_HID_A2DP;\r
837                                 }\r
838                                 else\r
839                                 {\r
840                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));\r
841                                         algorithm = BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
842                                 }\r
843                         }\r
844                 }\r
845         }\r
846         else if(numOfDiffProfile >= 3)\r
847         {\r
848                 if(pBtLinkInfo->bScoExist)\r
849                 {\r
850                         if( pBtLinkInfo->bHidExist &&\r
851                                 pBtLinkInfo->bPanExist &&\r
852                                 pBtLinkInfo->bA2dpExist )\r
853                         {\r
854                                 if(bBtHsOn)\r
855                                 {\r
856                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));\r
857 \r
858                                 }\r
859                                 else\r
860                                 {\r
861                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
862                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;\r
863                                 }\r
864                         }\r
865                 }\r
866         }\r
867 \r
868         return algorithm;\r
869 }\r
870 \r
871 VOID\r
872 halbtc8192e2ant_SetFwDacSwingLevel(\r
873         IN      PBTC_COEXIST            pBtCoexist,\r
874         IN      u1Byte                  dacSwingLvl\r
875         )\r
876 {\r
877         u1Byte                  H2C_Parameter[1] ={0};\r
878 \r
879         // There are several type of dacswing\r
880         // 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6\r
881         H2C_Parameter[0] = dacSwingLvl;\r
882 \r
883         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Set Dac Swing Level=0x%x\n", dacSwingLvl));\r
884         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x64=0x%x\n", H2C_Parameter[0]));\r
885 \r
886         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x64, 1, H2C_Parameter);\r
887 }\r
888 \r
889 VOID\r
890 halbtc8192e2ant_SetFwDecBtPwr(\r
891         IN      PBTC_COEXIST            pBtCoexist,\r
892         IN      u1Byte                          decBtPwrLvl\r
893         )\r
894 {\r
895         u1Byte                  H2C_Parameter[1] ={0};\r
896         \r
897         H2C_Parameter[0] = decBtPwrLvl;\r
898 \r
899         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], decrease Bt Power level = %d, FW write 0x62=0x%x\n", \r
900                 decBtPwrLvl, H2C_Parameter[0]));\r
901 \r
902         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x62, 1, H2C_Parameter);    \r
903 }\r
904 \r
905 VOID\r
906 halbtc8192e2ant_DecBtPwr(\r
907         IN      PBTC_COEXIST            pBtCoexist,\r
908         IN      BOOLEAN                         bForceExec,\r
909         IN      u1Byte                          decBtPwrLvl\r
910         )\r
911 {\r
912         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s Dec BT power level = %d\n",  \r
913                 (bForceExec? "force to":""), decBtPwrLvl));\r
914         pCoexDm->curBtDecPwrLvl = decBtPwrLvl;\r
915 \r
916         if(!bForceExec)\r
917         {\r
918                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], preBtDecPwrLvl=%d, curBtDecPwrLvl=%d\n", \r
919                         pCoexDm->preBtDecPwrLvl, pCoexDm->curBtDecPwrLvl));\r
920 #if 0   // work around, avoid h2c command fail.\r
921                 if(pCoexDm->preBtDecPwrLvl == pCoexDm->curBtDecPwrLvl) \r
922                         return;\r
923 #endif\r
924         }\r
925         halbtc8192e2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl);\r
926 \r
927         pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl;\r
928 }\r
929 \r
930 VOID\r
931 halbtc8192e2ant_SetBtAutoReport(\r
932         IN      PBTC_COEXIST            pBtCoexist,\r
933         IN      BOOLEAN                 bEnableAutoReport\r
934         )\r
935 {\r
936         u1Byte                  H2C_Parameter[1] ={0};\r
937         \r
938         H2C_Parameter[0] = 0;\r
939 \r
940         if(bEnableAutoReport)\r
941         {\r
942                 H2C_Parameter[0] |= BIT0;\r
943         }\r
944 \r
945         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n", \r
946                 (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));\r
947 \r
948         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);    \r
949 }\r
950 \r
951 VOID\r
952 halbtc8192e2ant_BtAutoReport(\r
953         IN      PBTC_COEXIST            pBtCoexist,\r
954         IN      BOOLEAN                 bForceExec,\r
955         IN      BOOLEAN                 bEnableAutoReport\r
956         )\r
957 {\r
958         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s BT Auto report = %s\n",  \r
959                 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));\r
960         pCoexDm->bCurBtAutoReport = bEnableAutoReport;\r
961 \r
962         if(!bForceExec)\r
963         {\r
964                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreBtAutoReport=%d, bCurBtAutoReport=%d\n", \r
965                         pCoexDm->bPreBtAutoReport, pCoexDm->bCurBtAutoReport));\r
966 \r
967                 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport) \r
968                         return;\r
969         }\r
970         halbtc8192e2ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);\r
971 \r
972         pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;\r
973 }\r
974 \r
975 VOID\r
976 halbtc8192e2ant_FwDacSwingLvl(\r
977         IN      PBTC_COEXIST            pBtCoexist,\r
978         IN      BOOLEAN                 bForceExec,\r
979         IN      u1Byte                  fwDacSwingLvl\r
980         )\r
981 {\r
982         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s set FW Dac Swing level = %d\n",  \r
983                 (bForceExec? "force to":""), fwDacSwingLvl));\r
984         pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;\r
985 \r
986         if(!bForceExec)\r
987         {\r
988                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], preFwDacSwingLvl=%d, curFwDacSwingLvl=%d\n", \r
989                         pCoexDm->preFwDacSwingLvl, pCoexDm->curFwDacSwingLvl));\r
990 \r
991                 if(pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl) \r
992                         return;\r
993         }\r
994 \r
995         halbtc8192e2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);\r
996 \r
997         pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;\r
998 }\r
999 \r
1000 VOID\r
1001 halbtc8192e2ant_SetSwRfRxLpfCorner(\r
1002         IN      PBTC_COEXIST            pBtCoexist,\r
1003         IN      BOOLEAN                 bRxRfShrinkOn\r
1004         )\r
1005 {\r
1006         if(bRxRfShrinkOn)\r
1007         {\r
1008                 //Shrink RF Rx LPF corner\r
1009                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));\r
1010                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xffffc);\r
1011         }\r
1012         else\r
1013         {\r
1014                 //Resume RF Rx LPF corner\r
1015                 // After initialized, we can use pCoexDm->btRf0x1eBackup\r
1016                 if(pBtCoexist->bInitilized)\r
1017                 {\r
1018                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Resume RF Rx LPF corner!!\n"));\r
1019                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);\r
1020                 }\r
1021         }\r
1022 }\r
1023 \r
1024 VOID\r
1025 halbtc8192e2ant_RfShrink(\r
1026         IN      PBTC_COEXIST            pBtCoexist,\r
1027         IN      BOOLEAN                 bForceExec,\r
1028         IN      BOOLEAN                 bRxRfShrinkOn\r
1029         )\r
1030 {\r
1031         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn Rx RF Shrink = %s\n",  \r
1032                 (bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));\r
1033         pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;\r
1034 \r
1035         if(!bForceExec)\r
1036         {\r
1037                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreRfRxLpfShrink=%d, bCurRfRxLpfShrink=%d\n", \r
1038                         pCoexDm->bPreRfRxLpfShrink, pCoexDm->bCurRfRxLpfShrink));\r
1039 \r
1040                 if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink) \r
1041                         return;\r
1042         }\r
1043         halbtc8192e2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);\r
1044 \r
1045         pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;\r
1046 }\r
1047 \r
1048 VOID\r
1049 halbtc8192e2ant_SetSwPenaltyTxRateAdaptive(\r
1050         IN      PBTC_COEXIST            pBtCoexist,\r
1051         IN      BOOLEAN                 bLowPenaltyRa\r
1052         )\r
1053 {\r
1054         u1Byte                  H2C_Parameter[6] ={0};\r
1055         \r
1056         H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty\r
1057 \r
1058         if(bLowPenaltyRa)\r
1059         {\r
1060                 H2C_Parameter[1] |= BIT0;\r
1061                 H2C_Parameter[2] = 0x00;  //normal rate except MCS7/6/5, OFDM54/48/36\r
1062                 H2C_Parameter[3] = 0xf7;  //MCS7 or OFDM54\r
1063                 H2C_Parameter[4] = 0xf8;  //MCS6 or OFDM48\r
1064                 H2C_Parameter[5] = 0xf9;        //MCS5 or OFDM36        \r
1065         }\r
1066 \r
1067         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set WiFi Low-Penalty Retry: %s", \r
1068                 (bLowPenaltyRa? "ON!!":"OFF!!")) );\r
1069 \r
1070         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);\r
1071 }\r
1072 \r
1073 VOID\r
1074 halbtc8192e2ant_LowPenaltyRa(\r
1075         IN      PBTC_COEXIST            pBtCoexist,\r
1076         IN      BOOLEAN                 bForceExec,\r
1077         IN      BOOLEAN                 bLowPenaltyRa\r
1078         )\r
1079 {\r
1080         //return;\r
1081         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn LowPenaltyRA = %s\n",  \r
1082                 (bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));\r
1083         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
1084 \r
1085         if(!bForceExec)\r
1086         {\r
1087                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreLowPenaltyRa=%d, bCurLowPenaltyRa=%d\n", \r
1088                         pCoexDm->bPreLowPenaltyRa, pCoexDm->bCurLowPenaltyRa));\r
1089 \r
1090                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
1091                         return;\r
1092         }\r
1093         halbtc8192e2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
1094 \r
1095         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
1096 }\r
1097 \r
1098 VOID\r
1099 halbtc8192e2ant_SetDacSwingReg(\r
1100         IN      PBTC_COEXIST            pBtCoexist,\r
1101         IN      u4Byte                  level\r
1102         )\r
1103 {\r
1104         u1Byte  val=(u1Byte)level;\r
1105 \r
1106         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Write SwDacSwing = 0x%x\n", level));\r
1107         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x883, 0x3e, val);\r
1108 }\r
1109 \r
1110 VOID\r
1111 halbtc8192e2ant_SetSwFullTimeDacSwing(\r
1112         IN      PBTC_COEXIST            pBtCoexist,\r
1113         IN      BOOLEAN                 bSwDacSwingOn,\r
1114         IN      u4Byte                  swDacSwingLvl\r
1115         )\r
1116 {\r
1117         if(bSwDacSwingOn)\r
1118         {\r
1119                 halbtc8192e2ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl);\r
1120         }\r
1121         else\r
1122         {\r
1123                 halbtc8192e2ant_SetDacSwingReg(pBtCoexist, 0x18);\r
1124         }\r
1125 }\r
1126 \r
1127 \r
1128 VOID\r
1129 halbtc8192e2ant_DacSwing(\r
1130         IN      PBTC_COEXIST            pBtCoexist,\r
1131         IN      BOOLEAN                 bForceExec,\r
1132         IN      BOOLEAN                 bDacSwingOn,\r
1133         IN      u4Byte                  dacSwingLvl\r
1134         )\r
1135 {\r
1136         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn DacSwing=%s, dacSwingLvl=0x%x\n",  \r
1137                 (bForceExec? "force to":""), ((bDacSwingOn)? "ON":"OFF"), dacSwingLvl));\r
1138         pCoexDm->bCurDacSwingOn = bDacSwingOn;\r
1139         pCoexDm->curDacSwingLvl = dacSwingLvl;\r
1140 \r
1141         if(!bForceExec)\r
1142         {\r
1143                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreDacSwingOn=%d, preDacSwingLvl=0x%x, bCurDacSwingOn=%d, curDacSwingLvl=0x%x\n", \r
1144                         pCoexDm->bPreDacSwingOn, pCoexDm->preDacSwingLvl,\r
1145                         pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl));\r
1146 \r
1147                 if( (pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&\r
1148                         (pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl) )\r
1149                         return;\r
1150         }\r
1151         delay_ms(30);\r
1152         halbtc8192e2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);\r
1153 \r
1154         pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;\r
1155         pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;\r
1156 }\r
1157 \r
1158 VOID\r
1159 halbtc8192e2ant_SetAdcBackOff(\r
1160         IN      PBTC_COEXIST            pBtCoexist,\r
1161         IN      BOOLEAN                 bAdcBackOff\r
1162         )\r
1163 {\r
1164         if(bAdcBackOff)\r
1165         {\r
1166                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB BackOff Level On!\n"));\r
1167                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xc05, 0x30, 0x3);\r
1168         }\r
1169         else\r
1170         {\r
1171                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB BackOff Level Off!\n"));\r
1172                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xc05, 0x30, 0x1);\r
1173         }\r
1174 }\r
1175 \r
1176 VOID\r
1177 halbtc8192e2ant_AdcBackOff(\r
1178         IN      PBTC_COEXIST            pBtCoexist,\r
1179         IN      BOOLEAN                 bForceExec,\r
1180         IN      BOOLEAN                 bAdcBackOff\r
1181         )\r
1182 {\r
1183         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn AdcBackOff = %s\n",  \r
1184                 (bForceExec? "force to":""), ((bAdcBackOff)? "ON":"OFF")));\r
1185         pCoexDm->bCurAdcBackOff = bAdcBackOff;\r
1186 \r
1187         if(!bForceExec)\r
1188         {\r
1189                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreAdcBackOff=%d, bCurAdcBackOff=%d\n", \r
1190                         pCoexDm->bPreAdcBackOff, pCoexDm->bCurAdcBackOff));\r
1191 \r
1192                 if(pCoexDm->bPreAdcBackOff == pCoexDm->bCurAdcBackOff) \r
1193                         return;\r
1194         }\r
1195         halbtc8192e2ant_SetAdcBackOff(pBtCoexist, pCoexDm->bCurAdcBackOff);\r
1196 \r
1197         pCoexDm->bPreAdcBackOff = pCoexDm->bCurAdcBackOff;\r
1198 }\r
1199 \r
1200 VOID\r
1201 halbtc8192e2ant_SetAgcTable(\r
1202         IN      PBTC_COEXIST            pBtCoexist,\r
1203         IN      BOOLEAN                 bAgcTableEn\r
1204         )\r
1205 {\r
1206         u1Byte          rssiAdjustVal=0;\r
1207 \r
1208         //=================BB AGC Gain Table\r
1209         if(bAgcTableEn)\r
1210         {\r
1211                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB Agc Table On!\n"));\r
1212                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x0a1A0001);\r
1213                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x091B0001);\r
1214                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x081C0001);\r
1215                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x071D0001);\r
1216                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x061E0001);\r
1217                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x051F0001);\r
1218         }\r
1219         else\r
1220         {\r
1221                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB Agc Table Off!\n"));\r
1222                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xaa1A0001);\r
1223                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa91B0001);\r
1224                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa81C0001);\r
1225                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa71D0001);\r
1226                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa61E0001);\r
1227                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa51F0001);\r
1228         }\r
1229         \r
1230 #if 0   \r
1231         //=================RF Gain\r
1232         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);\r
1233         if(bAgcTableEn)\r
1234         {\r
1235                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));\r
1236                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38fff);\r
1237                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38ffe);\r
1238         }\r
1239         else\r
1240         {\r
1241                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));\r
1242                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x380c3);\r
1243                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x28ce6);\r
1244         }\r
1245         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);\r
1246 \r
1247         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x1);\r
1248         if(bAgcTableEn)\r
1249         {\r
1250                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));\r
1251                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38fff);\r
1252                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38ffe);\r
1253         }\r
1254         else\r
1255         {\r
1256                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));\r
1257                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x380c3);\r
1258                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x28ce6);\r
1259         }\r
1260         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x0);\r
1261 \r
1262         // set rssiAdjustVal for wifi module.\r
1263         if(bAgcTableEn)\r
1264         {\r
1265                 rssiAdjustVal = 8;\r
1266         }\r
1267         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);\r
1268 #endif\r
1269 \r
1270 }\r
1271 \r
1272 VOID\r
1273 halbtc8192e2ant_AgcTable(\r
1274         IN      PBTC_COEXIST            pBtCoexist,\r
1275         IN      BOOLEAN                 bForceExec,\r
1276         IN      BOOLEAN                 bAgcTableEn\r
1277         )\r
1278 {\r
1279         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s %s Agc Table\n",  \r
1280                 (bForceExec? "force to":""), ((bAgcTableEn)? "Enable":"Disable")));\r
1281         pCoexDm->bCurAgcTableEn = bAgcTableEn;\r
1282 \r
1283         if(!bForceExec)\r
1284         {\r
1285                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreAgcTableEn=%d, bCurAgcTableEn=%d\n", \r
1286                         pCoexDm->bPreAgcTableEn, pCoexDm->bCurAgcTableEn));\r
1287 \r
1288                 if(pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn) \r
1289                         return;\r
1290         }\r
1291         halbtc8192e2ant_SetAgcTable(pBtCoexist, bAgcTableEn);\r
1292 \r
1293         pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;\r
1294 }\r
1295 \r
1296 VOID\r
1297 halbtc8192e2ant_SetCoexTable(\r
1298         IN      PBTC_COEXIST    pBtCoexist,\r
1299         IN      u4Byte          val0x6c0,\r
1300         IN      u4Byte          val0x6c4,\r
1301         IN      u4Byte          val0x6c8,\r
1302         IN      u1Byte          val0x6cc\r
1303         )\r
1304 {\r
1305         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
1306         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
1307 \r
1308         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));\r
1309         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);\r
1310 \r
1311         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
1312         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
1313 \r
1314         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
1315         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
1316 }\r
1317 \r
1318 VOID\r
1319 halbtc8192e2ant_CoexTable(\r
1320         IN      PBTC_COEXIST            pBtCoexist,\r
1321         IN      BOOLEAN                 bForceExec,\r
1322         IN      u4Byte                  val0x6c0,\r
1323         IN      u4Byte                  val0x6c4,\r
1324         IN      u4Byte                  val0x6c8,\r
1325         IN      u1Byte                  val0x6cc\r
1326         )\r
1327 {\r
1328         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
1329                 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6c8, val0x6cc));\r
1330         pCoexDm->curVal0x6c0 = val0x6c0;\r
1331         pCoexDm->curVal0x6c4 = val0x6c4;\r
1332         pCoexDm->curVal0x6c8 = val0x6c8;\r
1333         pCoexDm->curVal0x6cc = val0x6cc;\r
1334 \r
1335         if(!bForceExec)\r
1336         {\r
1337                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], preVal0x6c0=0x%x, preVal0x6c4=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n", \r
1338                         pCoexDm->preVal0x6c0, pCoexDm->preVal0x6c4, pCoexDm->preVal0x6c8, pCoexDm->preVal0x6cc));\r
1339                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], curVal0x6c0=0x%x, curVal0x6c4=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n", \r
1340                         pCoexDm->curVal0x6c0, pCoexDm->curVal0x6c4, pCoexDm->curVal0x6c8, pCoexDm->curVal0x6cc));\r
1341         \r
1342                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
1343                         (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&\r
1344                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
1345                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
1346                         return;\r
1347         }\r
1348         halbtc8192e2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);\r
1349 \r
1350         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
1351         pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;\r
1352         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
1353         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
1354 }\r
1355 \r
1356 VOID\r
1357 halbtc8192e2ant_CoexTableWithType(\r
1358         IN      PBTC_COEXIST            pBtCoexist,\r
1359         IN      BOOLEAN                         bForceExec,\r
1360         IN      u1Byte                          type\r
1361         )\r
1362 {\r
1363         switch(type)\r
1364         {\r
1365                 case 0:\r
1366                         halbtc8192e2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);\r
1367                         break;\r
1368                 case 1:\r
1369                         halbtc8192e2ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);\r
1370                         break;\r
1371                 case 2:\r
1372                         halbtc8192e2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5ffb5ffb, 0xffffff, 0x3);\r
1373                         break;\r
1374                 case 3:\r
1375                         halbtc8192e2ant_CoexTable(pBtCoexist, bForceExec, 0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3);\r
1376                         break;\r
1377                 case 4:\r
1378                         halbtc8192e2ant_CoexTable(pBtCoexist, bForceExec, 0xdfffdfff, 0x5ffb5ffb, 0xffffff, 0x3);\r
1379                         break;\r
1380 \r
1381                 default:\r
1382                         break;\r
1383         }\r
1384 }\r
1385 \r
1386 VOID\r
1387 halbtc8192e2ant_SetFwIgnoreWlanAct(\r
1388         IN      PBTC_COEXIST            pBtCoexist,\r
1389         IN      BOOLEAN                 bEnable\r
1390         )\r
1391 {\r
1392         u1Byte                  H2C_Parameter[1] ={0};\r
1393                 \r
1394         if(bEnable)\r
1395         {\r
1396                 H2C_Parameter[0] |= BIT0;               // function enable\r
1397         }\r
1398         \r
1399         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", \r
1400                 H2C_Parameter[0]));\r
1401 \r
1402         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);\r
1403 }\r
1404 \r
1405 VOID\r
1406 halbtc8192e2ant_IgnoreWlanAct(\r
1407         IN      PBTC_COEXIST            pBtCoexist,\r
1408         IN      BOOLEAN                 bForceExec,\r
1409         IN      BOOLEAN                 bEnable\r
1410         )\r
1411 {\r
1412         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
1413                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
1414         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
1415 \r
1416         if(!bForceExec)\r
1417         {\r
1418                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", \r
1419                         pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));\r
1420 \r
1421                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
1422                         return;\r
1423         }\r
1424         halbtc8192e2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
1425 \r
1426         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
1427 }\r
1428 \r
1429 VOID\r
1430 halbtc8192e2ant_SetFwPstdma(\r
1431         IN      PBTC_COEXIST            pBtCoexist,\r
1432         IN      u1Byte                  byte1,\r
1433         IN      u1Byte                  byte2,\r
1434         IN      u1Byte                  byte3,\r
1435         IN      u1Byte                  byte4,\r
1436         IN      u1Byte                  byte5\r
1437         )\r
1438 {\r
1439         u1Byte                  H2C_Parameter[5] ={0};\r
1440 \r
1441         H2C_Parameter[0] = byte1;       \r
1442         H2C_Parameter[1] = byte2;       \r
1443         H2C_Parameter[2] = byte3;\r
1444         H2C_Parameter[3] = byte4;\r
1445         H2C_Parameter[4] = byte5;\r
1446 \r
1447         pCoexDm->psTdmaPara[0] = byte1;\r
1448         pCoexDm->psTdmaPara[1] = byte2;\r
1449         pCoexDm->psTdmaPara[2] = byte3;\r
1450         pCoexDm->psTdmaPara[3] = byte4;\r
1451         pCoexDm->psTdmaPara[4] = byte5;\r
1452         \r
1453         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x60(5bytes)=0x%x%08x\n", \r
1454                 H2C_Parameter[0], \r
1455                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
1456 \r
1457         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);\r
1458 }\r
1459 \r
1460 VOID\r
1461 halbtc8192e2ant_SwMechanism1(\r
1462         IN      PBTC_COEXIST    pBtCoexist,     \r
1463         IN      BOOLEAN         bShrinkRxLPF,\r
1464         IN      BOOLEAN         bLowPenaltyRA,\r
1465         IN      BOOLEAN         bLimitedDIG, \r
1466         IN      BOOLEAN         bBTLNAConstrain\r
1467         ) \r
1468 {\r
1469         /*\r
1470         u4Byte  wifiBw;\r
1471         \r
1472         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
1473         \r
1474         if(BTC_WIFI_BW_HT40 != wifiBw)  //only shrink RF Rx LPF for HT40\r
1475         {\r
1476                 if (bShrinkRxLPF)\r
1477                         bShrinkRxLPF = FALSE;\r
1478         }\r
1479         */\r
1480         \r
1481         halbtc8192e2ant_RfShrink(pBtCoexist, NORMAL_EXEC, bShrinkRxLPF);\r
1482         //halbtc8192e2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);\r
1483 }\r
1484 \r
1485 VOID\r
1486 halbtc8192e2ant_SwMechanism2(\r
1487         IN      PBTC_COEXIST    pBtCoexist,     \r
1488         IN      BOOLEAN         bAGCTableShift,\r
1489         IN      BOOLEAN         bADCBackOff,\r
1490         IN      BOOLEAN         bSWDACSwing,\r
1491         IN      u4Byte          dacSwingLvl\r
1492         ) \r
1493 {\r
1494         halbtc8192e2ant_AgcTable(pBtCoexist, NORMAL_EXEC, bAGCTableShift);\r
1495         //halbtc8192e2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, bADCBackOff);\r
1496         halbtc8192e2ant_DacSwing(pBtCoexist, NORMAL_EXEC, bSWDACSwing, dacSwingLvl);\r
1497 }\r
1498 \r
1499 VOID\r
1500 halbtc8192e2ant_SetAntPath(\r
1501         IN      PBTC_COEXIST            pBtCoexist,\r
1502         IN      u1Byte                          antPosType,\r
1503         IN      BOOLEAN                         bInitHwCfg,\r
1504         IN      BOOLEAN                         bWifiOff\r
1505         )\r
1506 {\r
1507         u4Byte                  u4Tmp=0;\r
1508         \r
1509         if(bInitHwCfg)\r
1510         {\r
1511                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x944, 0x24);\r
1512                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x930, 0x700700);                \r
1513                 if(pBtCoexist->chipInterface == BTC_INTF_USB)\r
1514                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30430004);\r
1515                 else\r
1516                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30030004);\r
1517 \r
1518                 // 0x4c[27][24]='00', Set Antenna to BB\r
1519                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1520                 u4Tmp &= ~BIT24;\r
1521                 u4Tmp &= ~BIT27;\r
1522                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1523         }\r
1524         else if(bWifiOff)\r
1525         {\r
1526                 if(pBtCoexist->chipInterface == BTC_INTF_USB)\r
1527                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30430004);\r
1528                 else\r
1529                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30030004);\r
1530 \r
1531                 // 0x4c[27][24]='11', Set Antenna to BT, 0x64[8:7]=0, 0x64[2]=1\r
1532                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1533                 u4Tmp |= BIT24;\r
1534                 u4Tmp |= BIT27;\r
1535                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1536         }\r
1537         \r
1538         // ext switch setting\r
1539         switch(antPosType)\r
1540         {\r
1541                 case BTC_ANT_PATH_WIFI:\r
1542                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x92c, 0x4);\r
1543                         break;\r
1544                 case BTC_ANT_PATH_BT:\r
1545                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x92c, 0x20);\r
1546                         break;\r
1547                 default:\r
1548                 case BTC_ANT_PATH_PTA:\r
1549                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x92c, 0x4);\r
1550                         break;\r
1551         }\r
1552 }\r
1553 \r
1554 VOID\r
1555 halbtc8192e2ant_PsTdma(\r
1556         IN      PBTC_COEXIST            pBtCoexist,\r
1557         IN      BOOLEAN                 bForceExec,\r
1558         IN      BOOLEAN                 bTurnOn,\r
1559         IN      u1Byte                  type\r
1560         )\r
1561 {\r
1562         BOOLEAN                 bTurnOnByCnt=FALSE;\r
1563         u1Byte                  psTdmaTypeByCnt=0;\r
1564 \r
1565         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
1566                 (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));\r
1567         pCoexDm->bCurPsTdmaOn = bTurnOn;\r
1568         pCoexDm->curPsTdma = type;\r
1569 \r
1570         if(!bForceExec)\r
1571         {\r
1572                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n", \r
1573                         pCoexDm->bPrePsTdmaOn, pCoexDm->bCurPsTdmaOn));\r
1574                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n", \r
1575                         pCoexDm->prePsTdma, pCoexDm->curPsTdma));\r
1576 \r
1577                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
1578                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
1579                         return;\r
1580         }       \r
1581         if(bTurnOn)\r
1582         {\r
1583                 switch(type)\r
1584                 {\r
1585                         case 1:\r
1586                         default:\r
1587                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);\r
1588                                 break;\r
1589                         case 2:\r
1590                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);\r
1591                                 break;\r
1592                         case 3:\r
1593                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);\r
1594                                 break;\r
1595                         case 4:\r
1596                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x3, 0xf1, 0x90);\r
1597                                 break;\r
1598                         case 5:\r
1599                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);\r
1600                                 break;\r
1601                         case 6:\r
1602                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);\r
1603                                 break;\r
1604                         case 7:\r
1605                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);\r
1606                                 break;\r
1607                         case 8: \r
1608                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x10, 0x3, 0x70, 0x90);\r
1609                                 break;\r
1610                         case 9: \r
1611                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x10);\r
1612                                 break;\r
1613                         case 10:        \r
1614                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x10);\r
1615                                 break;\r
1616                         case 11:        \r
1617                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x10);\r
1618                                 break;\r
1619                         case 12:\r
1620                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x3, 0xf1, 0x10);\r
1621                                 break;\r
1622                         case 13:\r
1623                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe0, 0x10);\r
1624                                 break;\r
1625                         case 14:\r
1626                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe0, 0x10);\r
1627                                 break;\r
1628                         case 15:\r
1629                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf0, 0x10);\r
1630                                 break;\r
1631                         case 16:\r
1632                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x3, 0xf0, 0x10);\r
1633                                 break;\r
1634                         case 17:\r
1635                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0x61, 0x20, 0x03, 0x10, 0x10);\r
1636                                 break;\r
1637                         case 18:\r
1638                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);\r
1639                                 break;                  \r
1640                         case 19:\r
1641                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x90);\r
1642                                 break;\r
1643                         case 20:\r
1644                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x90);\r
1645                                 break;\r
1646                         case 21:\r
1647                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);\r
1648                                 break;  \r
1649                         case 71:\r
1650                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);\r
1651                                 break;\r
1652                 }\r
1653         }\r
1654         else\r
1655         {\r
1656                 // disable PS tdma\r
1657                 switch(type)\r
1658                 {\r
1659                         default:\r
1660                         case 0:  //ANT2PTA, 0x778=1\r
1661                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);\r
1662                                 halbtc8192e2ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FALSE, FALSE);\r
1663                                 break;\r
1664                         case 1:  //ANT2BT, 0x778=3\r
1665                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);\r
1666                                 delay_ms(5);\r
1667                                 halbtc8192e2ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
1668                                 break;\r
1669 \r
1670                 }\r
1671         }\r
1672 \r
1673         // update pre state\r
1674         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1675         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1676 }\r
1677 \r
1678 VOID\r
1679 halbtc8192e2ant_SetSwitchSsType(\r
1680         IN      PBTC_COEXIST            pBtCoexist,\r
1681         IN      u1Byte                          ssType\r
1682         )\r
1683 {\r
1684         u1Byte  mimoPs=BTC_MIMO_PS_DYNAMIC;\r
1685         u4Byte  disRaMask=0x0;\r
1686 \r
1687         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], REAL set SS Type = %d\n", ssType));\r
1688         \r
1689         disRaMask = halbtc8192e2ant_DecideRaMask(pBtCoexist, ssType, pCoexDm->curRaMaskType);\r
1690         halbtc8192e2ant_UpdateRaMask(pBtCoexist, FORCE_EXEC, disRaMask);\r
1691         \r
1692         if(ssType == 1)\r
1693         {               \r
1694                 halbtc8192e2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);\r
1695                 // switch ofdm path\r
1696                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xc04, 0x11);\r
1697                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xd04, 0x1);\r
1698                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x90c, 0x81111111);\r
1699                 // switch cck patch\r
1700                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xe77, 0x4, 0x1);\r
1701                 //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xa07, 0x81);\r
1702                 mimoPs=BTC_MIMO_PS_STATIC;\r
1703         }\r
1704         else if(ssType == 2)\r
1705         {\r
1706                 halbtc8192e2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
1707                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xc04, 0x33);\r
1708                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xd04, 0x3);\r
1709                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x90c, 0x81121313);\r
1710                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xe77, 0x4, 0x0);\r
1711                 //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xa07, 0x41);\r
1712                 mimoPs=BTC_MIMO_PS_DYNAMIC;\r
1713         }\r
1714         \r
1715         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_SEND_MIMO_PS, &mimoPs);     // set rx 1ss or 2ss\r
1716 }\r
1717 \r
1718 VOID\r
1719 halbtc8192e2ant_SwitchSsType(\r
1720         IN      PBTC_COEXIST            pBtCoexist,\r
1721         IN      BOOLEAN                         bForceExec,\r
1722         IN      u1Byte                          newSsType\r
1723         )\r
1724 {\r
1725         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], %s Switch SS Type = %d\n",  \r
1726                 (bForceExec? "force to":""), newSsType));\r
1727         pCoexDm->curSsType = newSsType;\r
1728 \r
1729         if(!bForceExec)\r
1730         {\r
1731                 if(pCoexDm->preSsType == pCoexDm->curSsType) \r
1732                         return;\r
1733         }\r
1734         halbtc8192e2ant_SetSwitchSsType(pBtCoexist, pCoexDm->curSsType);\r
1735 \r
1736         pCoexDm->preSsType = pCoexDm->curSsType;\r
1737 }\r
1738 \r
1739 VOID\r
1740 halbtc8192e2ant_CoexAllOff(\r
1741         IN      PBTC_COEXIST            pBtCoexist\r
1742         )\r
1743 {\r
1744         // fw all off\r
1745         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1746         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1747         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1748 \r
1749         // sw all off\r
1750         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1751         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1752 \r
1753         // hw all off\r
1754         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1755 }\r
1756 \r
1757 VOID\r
1758 halbtc8192e2ant_InitCoexDm(\r
1759         IN      PBTC_COEXIST            pBtCoexist\r
1760         )\r
1761 {       \r
1762         // force to reset coex mechanism\r
1763         \r
1764         halbtc8192e2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);\r
1765         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);\r
1766         halbtc8192e2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0);\r
1767 \r
1768         halbtc8192e2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
1769         halbtc8192e2ant_SwitchSsType(pBtCoexist, FORCE_EXEC, 2);\r
1770         \r
1771         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1772         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1773 }\r
1774 \r
1775 VOID\r
1776 halbtc8192e2ant_ActionBtInquiry(\r
1777         IN      PBTC_COEXIST            pBtCoexist\r
1778         )\r
1779 {\r
1780         BOOLEAN bLowPwrDisable=TRUE;\r
1781         \r
1782         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1783 \r
1784         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
1785 \r
1786         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1787         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1788         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1789         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1790 \r
1791         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1792         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1793 }\r
1794 \r
1795 BOOLEAN\r
1796 halbtc8192e2ant_IsCommonAction(\r
1797         IN      PBTC_COEXIST            pBtCoexist\r
1798         )\r
1799 {\r
1800         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
1801         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;\r
1802         BOOLEAN                 bBtHsOn=FALSE, bLowPwrDisable=FALSE;\r
1803 \r
1804         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
1805         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1806         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1807 \r
1808         if(pBtLinkInfo->bScoExist || pBtLinkInfo->bHidExist)\r
1809         {\r
1810                 halbtc8192e2ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 0, 0, 0);\r
1811         }\r
1812         else\r
1813         {\r
1814                 halbtc8192e2ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
1815         }\r
1816 \r
1817         if(!bWifiConnected)\r
1818         {\r
1819                 bLowPwrDisable = FALSE;\r
1820                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1821                 \r
1822                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non-connected idle!!\n"));\r
1823 \r
1824                 if( (BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) ||\r
1825                         (BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1826                 {\r
1827                         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 2);\r
1828                         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
1829                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1830                 }\r
1831                 else\r
1832                 {                       \r
1833                         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
1834                         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1835                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1836                 }\r
1837                 \r
1838                 halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1839                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1840                 \r
1841                 halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1842                 halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1843 \r
1844                 bCommon = TRUE;\r
1845         }\r
1846         else\r
1847         {\r
1848                 if(BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
1849                 {\r
1850                         bLowPwrDisable = FALSE;\r
1851                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1852 \r
1853                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));\r
1854 \r
1855                         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 2);\r
1856                         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
1857                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);              \r
1858                         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1859                         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1860 \r
1861                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1862                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1863 \r
1864                         bCommon = TRUE;\r
1865                 }\r
1866                 else if(BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)\r
1867                 {\r
1868                         bLowPwrDisable = TRUE;\r
1869                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1870 \r
1871                         if(bBtHsOn)\r
1872                                 return FALSE;\r
1873                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));\r
1874 \r
1875                         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 2);\r
1876                         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
1877                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1878                         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1879                         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1880 \r
1881                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
1882                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1883 \r
1884                         bCommon = TRUE;\r
1885                 }\r
1886                 else\r
1887                 {\r
1888                         bLowPwrDisable = TRUE;\r
1889                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1890 \r
1891                         if(bWifiBusy)\r
1892                         {\r
1893                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));\r
1894                                 bCommon = FALSE;\r
1895                         }\r
1896                         else\r
1897                         {\r
1898                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));\r
1899 \r
1900                                 halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
1901                                 halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1902                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 21);\r
1903                                 halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);      \r
1904                                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1905                                 halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1906                                 halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1907                                 bCommon = TRUE;\r
1908                         }\r
1909                 }       \r
1910         }\r
1911 \r
1912         return bCommon;\r
1913 }\r
1914 VOID\r
1915 halbtc8192e2ant_TdmaDurationAdjust(\r
1916         IN      PBTC_COEXIST            pBtCoexist,\r
1917         IN      BOOLEAN                 bScoHid,\r
1918         IN      BOOLEAN                 bTxPause,\r
1919         IN      u1Byte                  maxInterval\r
1920         )\r
1921 {\r
1922         static s4Byte           up,dn,m,n,WaitCount;\r
1923         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
1924         u1Byte                  retryCount=0;\r
1925 \r
1926         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjust()\n"));\r
1927 \r
1928         if(!pCoexDm->bAutoTdmaAdjust)\r
1929         {\r
1930                 pCoexDm->bAutoTdmaAdjust = TRUE;\r
1931                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
1932                 {\r
1933                         if(bScoHid)\r
1934                         {\r
1935                                 if(bTxPause)\r
1936                                 {\r
1937                                         if(maxInterval == 1)\r
1938                                         {\r
1939                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
1940                                                 pCoexDm->psTdmaDuAdjType = 13;  \r
1941                                         }\r
1942                                         else if(maxInterval == 2)\r
1943                                         {\r
1944                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
1945                                                 pCoexDm->psTdmaDuAdjType = 14;  \r
1946                                         }\r
1947                                         else if(maxInterval == 3)\r
1948                                         {\r
1949                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1950                                                 pCoexDm->psTdmaDuAdjType = 15;  \r
1951                                         }\r
1952                                         else\r
1953                                         {\r
1954                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1955                                                 pCoexDm->psTdmaDuAdjType = 15;\r
1956                                         }\r
1957                                 }\r
1958                                 else\r
1959                                 {\r
1960                                         if(maxInterval == 1)\r
1961                                         {\r
1962                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1963                                                 pCoexDm->psTdmaDuAdjType = 9;   \r
1964                                         }\r
1965                                         else if(maxInterval == 2)\r
1966                                         {\r
1967                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
1968                                                 pCoexDm->psTdmaDuAdjType = 10;  \r
1969                                         }\r
1970                                         else if(maxInterval == 3)\r
1971                                         {\r
1972                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1973                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1974                                         }\r
1975                                         else\r
1976                                         {\r
1977                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1978                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1979                                         }\r
1980                                 }\r
1981                         }\r
1982                         else\r
1983                         {\r
1984                                 if(bTxPause)\r
1985                                 {\r
1986                                         if(maxInterval == 1)\r
1987                                         {\r
1988                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1989                                                 pCoexDm->psTdmaDuAdjType = 5;   \r
1990                                         }\r
1991                                         else if(maxInterval == 2)\r
1992                                         {\r
1993                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1994                                                 pCoexDm->psTdmaDuAdjType = 6;   \r
1995                                         }\r
1996                                         else if(maxInterval == 3)\r
1997                                         {\r
1998                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1999                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2000                                         }\r
2001                                         else\r
2002                                         {\r
2003                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2004                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2005                                         }\r
2006                                 }\r
2007                                 else\r
2008                                 {\r
2009                                         if(maxInterval == 1)\r
2010                                         {\r
2011                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2012                                                 pCoexDm->psTdmaDuAdjType = 1;   \r
2013                                         }\r
2014                                         else if(maxInterval == 2)\r
2015                                         {\r
2016                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2017                                                 pCoexDm->psTdmaDuAdjType = 2;   \r
2018                                         }\r
2019                                         else if(maxInterval == 3)\r
2020                                         {\r
2021                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2022                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2023                                         }\r
2024                                         else\r
2025                                         {\r
2026                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2027                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2028                                         }\r
2029                                 }\r
2030                         }\r
2031                 }\r
2032                 //============\r
2033                 up = 0;\r
2034                 dn = 0;\r
2035                 m = 1;\r
2036                 n= 3;\r
2037                 result = 0;\r
2038                 WaitCount = 0;\r
2039         }\r
2040         else\r
2041         {\r
2042                 //accquire the BT TRx retry count from BT_Info byte2\r
2043                 retryCount = pCoexSta->btRetryCnt;\r
2044                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));\r
2045                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
2046                         up, dn, m, n, WaitCount));\r
2047                 result = 0;\r
2048                 WaitCount++; \r
2049                   \r
2050                 if(retryCount == 0)  // no retry in the last 2-second duration\r
2051                 {\r
2052                         up++;\r
2053                         dn--;\r
2054 \r
2055                         if (dn <= 0)\r
2056                                 dn = 0;                          \r
2057 \r
2058                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
2059                         {\r
2060                                 WaitCount = 0; \r
2061                                 n = 3;\r
2062                                 up = 0;\r
2063                                 dn = 0;\r
2064                                 result = 1; \r
2065                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));\r
2066                         }\r
2067                 }\r
2068                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
2069                 {\r
2070                         up--; \r
2071                         dn++;\r
2072 \r
2073                         if (up <= 0)\r
2074                                 up = 0;\r
2075 \r
2076                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
2077                         {\r
2078                                 if (WaitCount <= 2)\r
2079                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
2080                                 else\r
2081                                         m = 1;\r
2082 \r
2083                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
2084                                         m = 20;\r
2085 \r
2086                                 n = 3*m;\r
2087                                 up = 0;\r
2088                                 dn = 0;\r
2089                                 WaitCount = 0;\r
2090                                 result = -1; \r
2091                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
2092                         }\r
2093                 }\r
2094                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
2095                 {\r
2096                         if (WaitCount == 1)\r
2097                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
2098                         else\r
2099                                 m = 1;\r
2100 \r
2101                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
2102                                 m = 20;\r
2103 \r
2104                         n = 3*m;\r
2105                         up = 0;\r
2106                         dn = 0;\r
2107                         WaitCount = 0; \r
2108                         result = -1;\r
2109                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
2110                 }\r
2111 \r
2112                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], max Interval = %d\n", maxInterval));\r
2113                 if(maxInterval == 1)\r
2114                 {\r
2115                         if(bTxPause)\r
2116                         {\r
2117                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));\r
2118 \r
2119                                 if(pCoexDm->curPsTdma == 71)\r
2120                                 {\r
2121                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2122                                         pCoexDm->psTdmaDuAdjType = 5;\r
2123                                 }\r
2124                                 else if(pCoexDm->curPsTdma == 1)\r
2125                                 {\r
2126                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2127                                         pCoexDm->psTdmaDuAdjType = 5;\r
2128                                 }\r
2129                                 else if(pCoexDm->curPsTdma == 2)\r
2130                                 {\r
2131                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2132                                         pCoexDm->psTdmaDuAdjType = 6;\r
2133                                 }\r
2134                                 else if(pCoexDm->curPsTdma == 3)\r
2135                                 {\r
2136                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2137                                         pCoexDm->psTdmaDuAdjType = 7;\r
2138                                 }\r
2139                                 else if(pCoexDm->curPsTdma == 4)\r
2140                                 {\r
2141                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2142                                         pCoexDm->psTdmaDuAdjType = 8;\r
2143                                 }\r
2144                                 if(pCoexDm->curPsTdma == 9)\r
2145                                 {\r
2146                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2147                                         pCoexDm->psTdmaDuAdjType = 13;\r
2148                                 }\r
2149                                 else if(pCoexDm->curPsTdma == 10)\r
2150                                 {\r
2151                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2152                                         pCoexDm->psTdmaDuAdjType = 14;\r
2153                                 }\r
2154                                 else if(pCoexDm->curPsTdma == 11)\r
2155                                 {\r
2156                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2157                                         pCoexDm->psTdmaDuAdjType = 15;\r
2158                                 }\r
2159                                 else if(pCoexDm->curPsTdma == 12)\r
2160                                 {\r
2161                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2162                                         pCoexDm->psTdmaDuAdjType = 16;\r
2163                                 }\r
2164                                 \r
2165                                 if(result == -1)\r
2166                                 {                                       \r
2167                                         if(pCoexDm->curPsTdma == 5)\r
2168                                         {\r
2169                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2170                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2171                                         }\r
2172                                         else if(pCoexDm->curPsTdma == 6)\r
2173                                         {\r
2174                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2175                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2176                                         }\r
2177                                         else if(pCoexDm->curPsTdma == 7)\r
2178                                         {\r
2179                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2180                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2181                                         }\r
2182                                         else if(pCoexDm->curPsTdma == 13)\r
2183                                         {\r
2184                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2185                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2186                                         }\r
2187                                         else if(pCoexDm->curPsTdma == 14)\r
2188                                         {\r
2189                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2190                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2191                                         }\r
2192                                         else if(pCoexDm->curPsTdma == 15)\r
2193                                         {\r
2194                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2195                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2196                                         }\r
2197                                 } \r
2198                                 else if (result == 1)\r
2199                                 {\r
2200                                         if(pCoexDm->curPsTdma == 8)\r
2201                                         {\r
2202                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2203                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2204                                         }\r
2205                                         else if(pCoexDm->curPsTdma == 7)\r
2206                                         {\r
2207                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2208                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2209                                         }\r
2210                                         else if(pCoexDm->curPsTdma == 6)\r
2211                                         {\r
2212                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2213                                                 pCoexDm->psTdmaDuAdjType = 5;\r
2214                                         }\r
2215                                         else if(pCoexDm->curPsTdma == 16)\r
2216                                         {\r
2217                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2218                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2219                                         }\r
2220                                         else if(pCoexDm->curPsTdma == 15)\r
2221                                         {\r
2222                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2223                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2224                                         }\r
2225                                         else if(pCoexDm->curPsTdma == 14)\r
2226                                         {\r
2227                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2228                                                 pCoexDm->psTdmaDuAdjType = 13;\r
2229                                         }\r
2230                                 }\r
2231                         }\r
2232                         else\r
2233                         {\r
2234                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));\r
2235                                 if(pCoexDm->curPsTdma == 5)\r
2236                                 {\r
2237                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 71);\r
2238                                         pCoexDm->psTdmaDuAdjType = 71;\r
2239                                 }\r
2240                                 else if(pCoexDm->curPsTdma == 6)\r
2241                                 {\r
2242                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2243                                         pCoexDm->psTdmaDuAdjType = 2;\r
2244                                 }\r
2245                                 else if(pCoexDm->curPsTdma == 7)\r
2246                                 {\r
2247                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2248                                         pCoexDm->psTdmaDuAdjType = 3;\r
2249                                 }\r
2250                                 else if(pCoexDm->curPsTdma == 8)\r
2251                                 {\r
2252                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2253                                         pCoexDm->psTdmaDuAdjType = 4;\r
2254                                 }\r
2255                                 if(pCoexDm->curPsTdma == 13)\r
2256                                 {\r
2257                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2258                                         pCoexDm->psTdmaDuAdjType = 9;\r
2259                                 }\r
2260                                 else if(pCoexDm->curPsTdma == 14)\r
2261                                 {\r
2262                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2263                                         pCoexDm->psTdmaDuAdjType = 10;\r
2264                                 }\r
2265                                 else if(pCoexDm->curPsTdma == 15)\r
2266                                 {\r
2267                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2268                                         pCoexDm->psTdmaDuAdjType = 11;\r
2269                                 }\r
2270                                 else if(pCoexDm->curPsTdma == 16)\r
2271                                 {\r
2272                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2273                                         pCoexDm->psTdmaDuAdjType = 12;\r
2274                                 }\r
2275                                 \r
2276                                 if(result == -1)\r
2277                                 {\r
2278                                         if(pCoexDm->curPsTdma == 71)\r
2279                                         {\r
2280                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2281                                                 pCoexDm->psTdmaDuAdjType = 1;\r
2282                                         }\r
2283                                         else if(pCoexDm->curPsTdma == 1)\r
2284                                         {\r
2285                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2286                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2287                                         }\r
2288                                         else if(pCoexDm->curPsTdma == 2)\r
2289                                         {\r
2290                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2291                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2292                                         }\r
2293                                         else if(pCoexDm->curPsTdma == 3)\r
2294                                         {\r
2295                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2296                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2297                                         }\r
2298                                         else if(pCoexDm->curPsTdma == 9)\r
2299                                         {\r
2300                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2301                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2302                                         }\r
2303                                         else if(pCoexDm->curPsTdma == 10)\r
2304                                         {\r
2305                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2306                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2307                                         }\r
2308                                         else if(pCoexDm->curPsTdma == 11)\r
2309                                         {\r
2310                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2311                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2312                                         }\r
2313                                 } \r
2314                                 else if (result == 1)\r
2315                                 {\r
2316                                         if(pCoexDm->curPsTdma == 4)\r
2317                                         {\r
2318                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2319                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2320                                         }\r
2321                                         else if(pCoexDm->curPsTdma == 3)\r
2322                                         {\r
2323                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2324                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2325                                         }\r
2326                                         else if(pCoexDm->curPsTdma == 2)\r
2327                                         {\r
2328                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2329                                                 pCoexDm->psTdmaDuAdjType = 1;\r
2330                                         }\r
2331                                         else if(pCoexDm->curPsTdma == 1)\r
2332                                         {\r
2333                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 71);\r
2334                                                 pCoexDm->psTdmaDuAdjType = 71;\r
2335                                         }\r
2336                                         else if(pCoexDm->curPsTdma == 12)\r
2337                                         {\r
2338                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2339                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2340                                         }\r
2341                                         else if(pCoexDm->curPsTdma == 11)\r
2342                                         {\r
2343                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2344                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2345                                         }\r
2346                                         else if(pCoexDm->curPsTdma == 10)\r
2347                                         {\r
2348                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2349                                                 pCoexDm->psTdmaDuAdjType = 9;\r
2350                                         }\r
2351                                 }\r
2352                         }\r
2353                 }\r
2354                 else if(maxInterval == 2)\r
2355                 {\r
2356                         if(bTxPause)\r
2357                         {\r
2358                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));\r
2359                                 if(pCoexDm->curPsTdma == 1)\r
2360                                 {\r
2361                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2362                                         pCoexDm->psTdmaDuAdjType = 6;\r
2363                                 }\r
2364                                 else if(pCoexDm->curPsTdma == 2)\r
2365                                 {\r
2366                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2367                                         pCoexDm->psTdmaDuAdjType = 6;\r
2368                                 }\r
2369                                 else if(pCoexDm->curPsTdma == 3)\r
2370                                 {\r
2371                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2372                                         pCoexDm->psTdmaDuAdjType = 7;\r
2373                                 }\r
2374                                 else if(pCoexDm->curPsTdma == 4)\r
2375                                 {\r
2376                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2377                                         pCoexDm->psTdmaDuAdjType = 8;\r
2378                                 }\r
2379                                 if(pCoexDm->curPsTdma == 9)\r
2380                                 {\r
2381                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2382                                         pCoexDm->psTdmaDuAdjType = 14;\r
2383                                 }\r
2384                                 else if(pCoexDm->curPsTdma == 10)\r
2385                                 {\r
2386                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2387                                         pCoexDm->psTdmaDuAdjType = 14;\r
2388                                 }\r
2389                                 else if(pCoexDm->curPsTdma == 11)\r
2390                                 {\r
2391                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2392                                         pCoexDm->psTdmaDuAdjType = 15;\r
2393                                 }\r
2394                                 else if(pCoexDm->curPsTdma == 12)\r
2395                                 {\r
2396                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2397                                         pCoexDm->psTdmaDuAdjType = 16;\r
2398                                 }\r
2399                                 if(result == -1)\r
2400                                 {\r
2401                                         if(pCoexDm->curPsTdma == 5) \r
2402                                         {\r
2403                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2404                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2405                                         }\r
2406                                         else if(pCoexDm->curPsTdma == 6)\r
2407                                         {\r
2408                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2409                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2410                                         }\r
2411                                         else if(pCoexDm->curPsTdma == 7)\r
2412                                         {\r
2413                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2414                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2415                                         }\r
2416                                         else if(pCoexDm->curPsTdma == 13)\r
2417                                         {\r
2418                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2419                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2420                                         }\r
2421                                         else if(pCoexDm->curPsTdma == 14)\r
2422                                         {\r
2423                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2424                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2425                                         }\r
2426                                         else if(pCoexDm->curPsTdma == 15)\r
2427                                         {\r
2428                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2429                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2430                                         }\r
2431                                 } \r
2432                                 else if (result == 1)\r
2433                                 {\r
2434                                         if(pCoexDm->curPsTdma == 8)\r
2435                                         {\r
2436                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2437                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2438                                         }\r
2439                                         else if(pCoexDm->curPsTdma == 7)\r
2440                                         {\r
2441                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2442                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2443                                         }\r
2444                                         else if(pCoexDm->curPsTdma == 6)\r
2445                                         {\r
2446                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2447                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2448                                         }                                       \r
2449                                         else if(pCoexDm->curPsTdma == 16)\r
2450                                         {\r
2451                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2452                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2453                                         }\r
2454                                         else if(pCoexDm->curPsTdma == 15)\r
2455                                         {\r
2456                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2457                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2458                                         }\r
2459                                         else if(pCoexDm->curPsTdma == 14)\r
2460                                         {\r
2461                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2462                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2463                                         }\r
2464                                 }\r
2465                         }\r
2466                         else\r
2467                         {\r
2468                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));\r
2469                                 if(pCoexDm->curPsTdma == 5)\r
2470                                 {\r
2471                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2472                                         pCoexDm->psTdmaDuAdjType = 2;\r
2473                                 }\r
2474                                 else if(pCoexDm->curPsTdma == 6)\r
2475                                 {\r
2476                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2477                                         pCoexDm->psTdmaDuAdjType = 2;\r
2478                                 }\r
2479                                 else if(pCoexDm->curPsTdma == 7)\r
2480                                 {\r
2481                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2482                                         pCoexDm->psTdmaDuAdjType = 3;\r
2483                                 }\r
2484                                 else if(pCoexDm->curPsTdma == 8)\r
2485                                 {\r
2486                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2487                                         pCoexDm->psTdmaDuAdjType = 4;\r
2488                                 }\r
2489                                 if(pCoexDm->curPsTdma == 13)\r
2490                                 {\r
2491                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2492                                         pCoexDm->psTdmaDuAdjType = 10;\r
2493                                 }\r
2494                                 else if(pCoexDm->curPsTdma == 14)\r
2495                                 {\r
2496                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2497                                         pCoexDm->psTdmaDuAdjType = 10;\r
2498                                 }\r
2499                                 else if(pCoexDm->curPsTdma == 15)\r
2500                                 {\r
2501                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2502                                         pCoexDm->psTdmaDuAdjType = 11;\r
2503                                 }\r
2504                                 else if(pCoexDm->curPsTdma == 16)\r
2505                                 {\r
2506                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2507                                         pCoexDm->psTdmaDuAdjType = 12;\r
2508                                 }\r
2509                                 if(result == -1)\r
2510                                 {\r
2511                                         if(pCoexDm->curPsTdma == 1)\r
2512                                         {\r
2513                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2514                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2515                                         }\r
2516                                         else if(pCoexDm->curPsTdma == 2)\r
2517                                         {\r
2518                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2519                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2520                                         }\r
2521                                         else if(pCoexDm->curPsTdma == 3)\r
2522                                         {\r
2523                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2524                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2525                                         }\r
2526                                         else if(pCoexDm->curPsTdma == 9)\r
2527                                         {\r
2528                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2529                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2530                                         }\r
2531                                         else if(pCoexDm->curPsTdma == 10)\r
2532                                         {\r
2533                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2534                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2535                                         }\r
2536                                         else if(pCoexDm->curPsTdma == 11)\r
2537                                         {\r
2538                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2539                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2540                                         }\r
2541                                 } \r
2542                                 else if (result == 1)\r
2543                                 {\r
2544                                         if(pCoexDm->curPsTdma == 4)\r
2545                                         {\r
2546                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2547                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2548                                         }\r
2549                                         else if(pCoexDm->curPsTdma == 3)\r
2550                                         {\r
2551                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2552                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2553                                         }\r
2554                                         else if(pCoexDm->curPsTdma == 2)\r
2555                                         {\r
2556                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2557                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2558                                         }\r
2559                                         else if(pCoexDm->curPsTdma == 12)\r
2560                                         {\r
2561                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2562                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2563                                         }\r
2564                                         else if(pCoexDm->curPsTdma == 11)\r
2565                                         {\r
2566                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2567                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2568                                         }\r
2569                                         else if(pCoexDm->curPsTdma == 10)\r
2570                                         {\r
2571                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2572                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2573                                         }\r
2574                                 }\r
2575                         }\r
2576                 }\r
2577                 else if(maxInterval == 3)\r
2578                 {\r
2579                         if(bTxPause)\r
2580                         {\r
2581                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));\r
2582                                 if(pCoexDm->curPsTdma == 1)\r
2583                                 {\r
2584                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2585                                         pCoexDm->psTdmaDuAdjType = 7;\r
2586                                 }\r
2587                                 else if(pCoexDm->curPsTdma == 2)\r
2588                                 {\r
2589                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2590                                         pCoexDm->psTdmaDuAdjType = 7;\r
2591                                 }\r
2592                                 else if(pCoexDm->curPsTdma == 3)\r
2593                                 {\r
2594                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2595                                         pCoexDm->psTdmaDuAdjType = 7;\r
2596                                 }\r
2597                                 else if(pCoexDm->curPsTdma == 4)\r
2598                                 {\r
2599                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2600                                         pCoexDm->psTdmaDuAdjType = 8;\r
2601                                 }\r
2602                                 if(pCoexDm->curPsTdma == 9)\r
2603                                 {\r
2604                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2605                                         pCoexDm->psTdmaDuAdjType = 15;\r
2606                                 }\r
2607                                 else if(pCoexDm->curPsTdma == 10)\r
2608                                 {\r
2609                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2610                                         pCoexDm->psTdmaDuAdjType = 15;\r
2611                                 }\r
2612                                 else if(pCoexDm->curPsTdma == 11)\r
2613                                 {\r
2614                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2615                                         pCoexDm->psTdmaDuAdjType = 15;\r
2616                                 }\r
2617                                 else if(pCoexDm->curPsTdma == 12)\r
2618                                 {\r
2619                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2620                                         pCoexDm->psTdmaDuAdjType = 16;\r
2621                                 }\r
2622                                 if(result == -1)\r
2623                                 {\r
2624                                         if(pCoexDm->curPsTdma == 5) \r
2625                                         {\r
2626                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2627                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2628                                         }\r
2629                                         else if(pCoexDm->curPsTdma == 6)\r
2630                                         {\r
2631                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2632                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2633                                         }\r
2634                                         else if(pCoexDm->curPsTdma == 7)\r
2635                                         {\r
2636                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2637                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2638                                         }\r
2639                                         else if(pCoexDm->curPsTdma == 13)\r
2640                                         {\r
2641                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2642                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2643                                         }\r
2644                                         else if(pCoexDm->curPsTdma == 14)\r
2645                                         {\r
2646                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2647                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2648                                         }\r
2649                                         else if(pCoexDm->curPsTdma == 15)\r
2650                                         {\r
2651                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2652                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2653                                         }\r
2654                                 } \r
2655                                 else if (result == 1)\r
2656                                 {\r
2657                                         if(pCoexDm->curPsTdma == 8)\r
2658                                         {\r
2659                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2660                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2661                                         }\r
2662                                         else if(pCoexDm->curPsTdma == 7)\r
2663                                         {\r
2664                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2665                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2666                                         }\r
2667                                         else if(pCoexDm->curPsTdma == 6)\r
2668                                         {\r
2669                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2670                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2671                                         }                                       \r
2672                                         else if(pCoexDm->curPsTdma == 16)\r
2673                                         {\r
2674                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2675                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2676                                         }\r
2677                                         else if(pCoexDm->curPsTdma == 15)\r
2678                                         {\r
2679                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2680                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2681                                         }\r
2682                                         else if(pCoexDm->curPsTdma == 14)\r
2683                                         {\r
2684                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2685                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2686                                         }\r
2687                                 }\r
2688                         }\r
2689                         else\r
2690                         {\r
2691                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));\r
2692                                 if(pCoexDm->curPsTdma == 5)\r
2693                                 {\r
2694                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2695                                         pCoexDm->psTdmaDuAdjType = 3;\r
2696                                 }\r
2697                                 else if(pCoexDm->curPsTdma == 6)\r
2698                                 {\r
2699                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2700                                         pCoexDm->psTdmaDuAdjType = 3;\r
2701                                 }\r
2702                                 else if(pCoexDm->curPsTdma == 7)\r
2703                                 {\r
2704                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2705                                         pCoexDm->psTdmaDuAdjType = 3;\r
2706                                 }\r
2707                                 else if(pCoexDm->curPsTdma == 8)\r
2708                                 {\r
2709                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2710                                         pCoexDm->psTdmaDuAdjType = 4;\r
2711                                 }\r
2712                                 if(pCoexDm->curPsTdma == 13)\r
2713                                 {\r
2714                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2715                                         pCoexDm->psTdmaDuAdjType = 11;\r
2716                                 }\r
2717                                 else if(pCoexDm->curPsTdma == 14)\r
2718                                 {\r
2719                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2720                                         pCoexDm->psTdmaDuAdjType = 11;\r
2721                                 }\r
2722                                 else if(pCoexDm->curPsTdma == 15)\r
2723                                 {\r
2724                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2725                                         pCoexDm->psTdmaDuAdjType = 11;\r
2726                                 }\r
2727                                 else if(pCoexDm->curPsTdma == 16)\r
2728                                 {\r
2729                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2730                                         pCoexDm->psTdmaDuAdjType = 12;\r
2731                                 }\r
2732                                 if(result == -1)\r
2733                                 {\r
2734                                         if(pCoexDm->curPsTdma == 1)\r
2735                                         {\r
2736                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2737                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2738                                         }\r
2739                                         else if(pCoexDm->curPsTdma == 2)\r
2740                                         {\r
2741                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2742                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2743                                         }\r
2744                                         else if(pCoexDm->curPsTdma == 3)\r
2745                                         {\r
2746                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2747                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2748                                         }\r
2749                                         else if(pCoexDm->curPsTdma == 9)\r
2750                                         {\r
2751                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2752                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2753                                         }\r
2754                                         else if(pCoexDm->curPsTdma == 10)\r
2755                                         {\r
2756                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2757                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2758                                         }\r
2759                                         else if(pCoexDm->curPsTdma == 11)\r
2760                                         {\r
2761                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2762                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2763                                         }\r
2764                                 } \r
2765                                 else if (result == 1)\r
2766                                 {\r
2767                                         if(pCoexDm->curPsTdma == 4)\r
2768                                         {\r
2769                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2770                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2771                                         }\r
2772                                         else if(pCoexDm->curPsTdma == 3)\r
2773                                         {\r
2774                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2775                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2776                                         }\r
2777                                         else if(pCoexDm->curPsTdma == 2)\r
2778                                         {\r
2779                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2780                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2781                                         }\r
2782                                         else if(pCoexDm->curPsTdma == 12)\r
2783                                         {\r
2784                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2785                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2786                                         }\r
2787                                         else if(pCoexDm->curPsTdma == 11)\r
2788                                         {\r
2789                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2790                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2791                                         }\r
2792                                         else if(pCoexDm->curPsTdma == 10)\r
2793                                         {\r
2794                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2795                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2796                                         }\r
2797                                 }\r
2798                         }\r
2799                 }\r
2800         }\r
2801 \r
2802         // if current PsTdma not match with the recorded one (when scan, dhcp...), \r
2803         // then we have to adjust it back to the previous record one.\r
2804         if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)\r
2805         {\r
2806                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2807                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n", \r
2808                         pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));\r
2809 \r
2810                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2811                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2812                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2813                 \r
2814                 if( !bScan && !bLink && !bRoam)\r
2815                 {\r
2816                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
2817                 }\r
2818                 else\r
2819                 {\r
2820                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));\r
2821                 }\r
2822         }\r
2823 }\r
2824 \r
2825 // SCO only or SCO+PAN(HS)\r
2826 VOID\r
2827 halbtc8192e2ant_ActionSco(\r
2828         IN      PBTC_COEXIST            pBtCoexist\r
2829         )\r
2830 {\r
2831         u1Byte  wifiRssiState, btRssiState=BTC_RSSI_STATE_STAY_LOW;\r
2832         u4Byte  wifiBw;\r
2833 \r
2834         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
2835 \r
2836         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
2837         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
2838 \r
2839         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
2840 \r
2841         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2842 \r
2843         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
2844 \r
2845         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
2846                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
2847         {\r
2848                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2849                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2850         }\r
2851         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
2852                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
2853         {\r
2854                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
2855                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2856         }\r
2857         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
2858                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2859         {\r
2860                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
2861                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2862         }\r
2863         \r
2864         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2865 \r
2866         // sw mechanism\r
2867         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2868         {\r
2869                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2870                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2871                 {\r
2872                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
2873                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x6);                  \r
2874                 }\r
2875                 else\r
2876                 {\r
2877                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
2878                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x6); \r
2879                 }               \r
2880         }\r
2881         else\r
2882         {\r
2883                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2884                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2885                 {\r
2886                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
2887                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x6);\r
2888                 }\r
2889                 else\r
2890                 {\r
2891                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
2892                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x6);\r
2893                 }               \r
2894         }\r
2895 }\r
2896 \r
2897 VOID\r
2898 halbtc8192e2ant_ActionScoPan(\r
2899         IN      PBTC_COEXIST            pBtCoexist\r
2900         )\r
2901 {\r
2902         u1Byte  wifiRssiState, btRssiState=BTC_RSSI_STATE_STAY_LOW;\r
2903         u4Byte  wifiBw;\r
2904 \r
2905         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
2906 \r
2907         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
2908         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
2909 \r
2910         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
2911 \r
2912         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2913 \r
2914         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
2915 \r
2916         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
2917                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
2918         {\r
2919                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2920                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2921         }\r
2922         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
2923                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
2924         {\r
2925                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
2926                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2927         }\r
2928         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
2929                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2930         {\r
2931                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
2932                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2933         }\r
2934         \r
2935         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2936 \r
2937         // sw mechanism\r
2938         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2939         {\r
2940                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2941                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2942                 {\r
2943                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
2944                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x6);                  \r
2945                 }\r
2946                 else\r
2947                 {\r
2948                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
2949                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x6); \r
2950                 }               \r
2951         }\r
2952         else\r
2953         {\r
2954                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2955                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2956                 {\r
2957                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
2958                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x6);\r
2959                 }\r
2960                 else\r
2961                 {\r
2962                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
2963                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x6);\r
2964                 }               \r
2965         }\r
2966 }\r
2967 \r
2968 VOID\r
2969 halbtc8192e2ant_ActionHid(\r
2970         IN      PBTC_COEXIST            pBtCoexist\r
2971         )\r
2972 {\r
2973         u1Byte  wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH; \r
2974         u4Byte  wifiBw;\r
2975 \r
2976         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
2977         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
2978 \r
2979         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
2980         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
2981 \r
2982         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
2983 \r
2984         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2985 \r
2986         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);\r
2987 \r
2988         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
2989                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
2990         {\r
2991                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2992                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2993         }\r
2994         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
2995                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
2996         {\r
2997                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
2998                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2999         }\r
3000         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3001                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3002         {\r
3003                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3004                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
3005         }\r
3006 \r
3007         // sw mechanism\r
3008         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3009         {\r
3010                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3011                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3012                 {\r
3013                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3014                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3015                 }\r
3016                 else\r
3017                 {\r
3018                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3019                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3020                 }       \r
3021         }\r
3022         else\r
3023         {\r
3024                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3025                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3026                 {\r
3027                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3028                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3029                 }\r
3030                 else\r
3031                 {\r
3032                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3033                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3034                 }               \r
3035         }\r
3036 }\r
3037 \r
3038 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
3039 VOID\r
3040 halbtc8192e2ant_ActionA2dp(\r
3041         IN      PBTC_COEXIST            pBtCoexist\r
3042         )\r
3043 {\r
3044         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3045         u4Byte          wifiBw;\r
3046         BOOLEAN         bLongDist=FALSE;\r
3047 \r
3048         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3049         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3050 \r
3051         if( (btRssiState == BTC_RSSI_STATE_LOW||btRssiState == BTC_RSSI_STATE_STAY_LOW) &&\r
3052                 (wifiRssiState == BTC_RSSI_STATE_LOW||wifiRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3053         {\r
3054                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2dp, wifi/bt rssi both LOW!!\n"));\r
3055                 bLongDist = TRUE;\r
3056         }\r
3057         if(bLongDist)\r
3058         {\r
3059                 halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 2);\r
3060                 halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x4);\r
3061         }\r
3062         else\r
3063         {\r
3064                 halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3065                 halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3066         }\r
3067 \r
3068         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3069 \r
3070         if(bLongDist)\r
3071                 halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
3072         else\r
3073                 halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3074 \r
3075 \r
3076         if(bLongDist)\r
3077         {\r
3078                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 17);\r
3079                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
3080                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3081         }\r
3082         else\r
3083         {\r
3084                 if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3085                         (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3086                 {\r
3087                         halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 1);\r
3088                         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3089                 }\r
3090                 else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3091                                 (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3092                 {\r
3093                         halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);\r
3094                         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3095                 }\r
3096                 else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3097                                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3098                 {\r
3099                         halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);\r
3100                         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3101                 }\r
3102         }\r
3103         \r
3104         // sw mechanism\r
3105         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3106         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3107         {\r
3108                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3109                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3110                 {\r
3111                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3112                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3113                 }\r
3114                 else\r
3115                 {\r
3116                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3117                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3118                 }\r
3119         }\r
3120         else\r
3121         {\r
3122                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3123                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3124                 {\r
3125                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3126                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3127                 }\r
3128                 else\r
3129                 {\r
3130                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3131                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3132                 }               \r
3133         }\r
3134 }\r
3135 \r
3136 VOID\r
3137 halbtc8192e2ant_ActionA2dpPanHs(\r
3138         IN      PBTC_COEXIST            pBtCoexist\r
3139         )\r
3140 {\r
3141         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3142         u4Byte          wifiBw;\r
3143 \r
3144         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3145         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3146 \r
3147         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3148         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3149 \r
3150         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3151         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3152 \r
3153         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3154                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3155         {\r
3156                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 2);\r
3157                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3158         }\r
3159         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3160                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3161         {\r
3162                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 2);\r
3163                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3164         }\r
3165         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3166                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3167         {\r
3168                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 2);\r
3169                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3170         }\r
3171 \r
3172         // sw mechanism\r
3173         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3174         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3175         {\r
3176                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3177                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3178                 {\r
3179                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3180                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);\r
3181                 }\r
3182                 else\r
3183                 {\r
3184                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3185                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x6);\r
3186                 }\r
3187         }\r
3188         else\r
3189         {\r
3190                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3191                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3192                 {\r
3193                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3194                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);\r
3195                 }\r
3196                 else\r
3197                 {\r
3198                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3199                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x6);\r
3200                 }               \r
3201         }\r
3202 }\r
3203 \r
3204 VOID\r
3205 halbtc8192e2ant_ActionPanEdr(\r
3206         IN      PBTC_COEXIST            pBtCoexist\r
3207         )\r
3208 {\r
3209         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3210         u4Byte          wifiBw;\r
3211 \r
3212         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3213         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3214 \r
3215         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3216         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3217 \r
3218         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3219 \r
3220         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3221 \r
3222         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3223                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3224         {\r
3225                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3226                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
3227         }\r
3228         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3229                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3230         {\r
3231                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3232                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
3233         }\r
3234         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3235                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3236         {\r
3237                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3238                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
3239         }\r
3240         \r
3241         // sw mechanism\r
3242         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3243         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3244         {\r
3245                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3246                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3247                 {\r
3248                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3249                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3250                 }\r
3251                 else\r
3252                 {\r
3253                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3254                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3255                 }\r
3256         }\r
3257         else\r
3258         {\r
3259                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3260                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3261                 {\r
3262                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3263                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3264                 }\r
3265                 else\r
3266                 {\r
3267                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3268                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3269                 }\r
3270         }\r
3271 }\r
3272 \r
3273 //PAN(HS) only\r
3274 VOID\r
3275 halbtc8192e2ant_ActionPanHs(\r
3276         IN      PBTC_COEXIST            pBtCoexist\r
3277         )\r
3278 {\r
3279         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3280         u4Byte          wifiBw;\r
3281 \r
3282         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3283         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3284 \r
3285         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3286         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3287 \r
3288         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3289 \r
3290         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3291 \r
3292         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3293                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3294         {\r
3295                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3296         }\r
3297         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3298                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3299         {\r
3300                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3301         }\r
3302         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3303                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3304         {\r
3305                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3306         }\r
3307         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
3308 \r
3309         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3310         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3311         {\r
3312                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3313                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3314                 {\r
3315                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3316                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3317                 }\r
3318                 else\r
3319                 {\r
3320                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3321                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3322                 }\r
3323         }\r
3324         else\r
3325         {\r
3326                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3327                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3328                 {\r
3329                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3330                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3331                 }\r
3332                 else\r
3333                 {\r
3334                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3335                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3336                 }\r
3337         }\r
3338 }\r
3339 \r
3340 //PAN(EDR)+A2DP\r
3341 VOID\r
3342 halbtc8192e2ant_ActionPanEdrA2dp(\r
3343         IN      PBTC_COEXIST            pBtCoexist\r
3344         )\r
3345 {\r
3346         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3347         u4Byte          wifiBw;\r
3348 \r
3349         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3350         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3351 \r
3352         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3353         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3354 \r
3355         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3356 \r
3357         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3358 \r
3359         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3360 \r
3361         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3362                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3363         {\r
3364                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3365                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);\r
3366         }\r
3367         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3368                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3369         {\r
3370                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3371                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);\r
3372         }\r
3373         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3374                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3375         {\r
3376                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3377                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);\r
3378         }\r
3379         \r
3380         // sw mechanism \r
3381         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3382         {\r
3383                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3384                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3385                 {\r
3386                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3387                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3388                 }\r
3389                 else\r
3390                 {\r
3391                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3392                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3393                 }\r
3394         }\r
3395         else\r
3396         {\r
3397                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3398                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3399                 {\r
3400                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3401                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3402                 }\r
3403                 else\r
3404                 {\r
3405                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3406                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3407                 }\r
3408         }\r
3409 }\r
3410 \r
3411 VOID\r
3412 halbtc8192e2ant_ActionPanEdrHid(\r
3413         IN      PBTC_COEXIST            pBtCoexist\r
3414         )\r
3415 {\r
3416         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3417         u4Byte          wifiBw;\r
3418 \r
3419         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3420         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3421 \r
3422         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3423 \r
3424         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3425         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3426 \r
3427         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3428 \r
3429         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);\r
3430 \r
3431         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3432                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3433         {\r
3434                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3435                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
3436         }\r
3437         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3438                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3439         {\r
3440                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3441                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
3442         }\r
3443         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3444                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3445         {\r
3446                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3447                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
3448         }\r
3449         \r
3450         // sw mechanism\r
3451         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3452         {\r
3453                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3454                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3455                 {\r
3456                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3457                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3458                 }\r
3459                 else\r
3460                 {\r
3461                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3462                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3463                 }\r
3464         }\r
3465         else\r
3466         {\r
3467                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3468                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3469                 {\r
3470                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3471                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3472                 }\r
3473                 else\r
3474                 {\r
3475                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3476                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3477                 }\r
3478         }\r
3479 }\r
3480 \r
3481 // HID+A2DP+PAN(EDR)\r
3482 VOID\r
3483 halbtc8192e2ant_ActionHidA2dpPanEdr(\r
3484         IN      PBTC_COEXIST            pBtCoexist\r
3485         )\r
3486 {\r
3487         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3488         u4Byte          wifiBw;\r
3489 \r
3490         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3491         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3492 \r
3493         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3494         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3495 \r
3496         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3497 \r
3498         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3499 \r
3500         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);\r
3501 \r
3502         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3503                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3504         {\r
3505                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3506                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3507         }\r
3508         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3509                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3510         {\r
3511                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3512                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3513         }\r
3514         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3515                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3516         {\r
3517                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3518                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3519         }\r
3520 \r
3521         // sw mechanism\r
3522         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3523         {\r
3524                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3525                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3526                 {\r
3527                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3528                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3529                 }\r
3530                 else\r
3531                 {\r
3532                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3533                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3534                 }\r
3535         }\r
3536         else\r
3537         {\r
3538                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3539                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3540                 {\r
3541                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3542                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3543                 }\r
3544                 else\r
3545                 {\r
3546                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3547                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3548                 }\r
3549         }\r
3550 }\r
3551 \r
3552 VOID\r
3553 halbtc8192e2ant_ActionHidA2dp(\r
3554         IN      PBTC_COEXIST            pBtCoexist\r
3555         )\r
3556 {\r
3557         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3558         u4Byte          wifiBw;\r
3559 \r
3560         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3561         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3562 \r
3563         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3564         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3565 \r
3566         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3567 \r
3568         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);\r
3569         \r
3570         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3571                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3572         {\r
3573                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3574                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 2);\r
3575         }\r
3576         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3577                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3578         {\r
3579                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3580                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 2);\r
3581         }\r
3582         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3583                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3584         {\r
3585                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3586                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 2);\r
3587         }       \r
3588         \r
3589         // sw mechanism\r
3590         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3591         {\r
3592                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3593                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3594                 {\r
3595                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3596                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3597                 }\r
3598                 else\r
3599                 {\r
3600                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3601                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3602                 }\r
3603         }\r
3604         else\r
3605         {\r
3606                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3607                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3608                 {\r
3609                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3610                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3611                 }\r
3612                 else\r
3613                 {\r
3614                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3615                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3616                 }\r
3617         }\r
3618 }\r
3619 \r
3620 VOID\r
3621 halbtc8192e2ant_RunCoexistMechanism(\r
3622         IN      PBTC_COEXIST            pBtCoexist\r
3623         )\r
3624 {\r
3625         BOOLEAN                         bWifiUnder5G=FALSE;\r
3626         u1Byte                          btInfoOriginal=0, btRetryCnt=0;\r
3627         u1Byte                          algorithm=0;\r
3628 \r
3629         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism()===>\n"));\r
3630 \r
3631         if(pBtCoexist->bManualControl)\r
3632         {\r
3633                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));\r
3634                 return;\r
3635         }\r
3636 \r
3637         if(pCoexSta->bUnderIps)\r
3638         {\r
3639                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is under IPS !!!\n"));\r
3640                 return;\r
3641         }\r
3642 \r
3643         algorithm = halbtc8192e2ant_ActionAlgorithm(pBtCoexist);\r
3644         if(pCoexSta->bC2hBtInquiryPage && (BT_8192E_2ANT_COEX_ALGO_PANHS!=algorithm))\r
3645         {\r
3646                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT is under inquiry/page scan !!\n"));\r
3647                 halbtc8192e2ant_ActionBtInquiry(pBtCoexist);\r
3648                 return;\r
3649         }\r
3650 \r
3651         pCoexDm->curAlgorithm = algorithm;\r
3652         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Algorithm = %d \n", pCoexDm->curAlgorithm));\r
3653 \r
3654         if(halbtc8192e2ant_IsCommonAction(pBtCoexist))\r
3655         {\r
3656                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant common.\n"));\r
3657                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
3658         }\r
3659         else\r
3660         {\r
3661                 if(pCoexDm->curAlgorithm != pCoexDm->preAlgorithm)\r
3662                 {\r
3663                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n", \r
3664                                 pCoexDm->preAlgorithm, pCoexDm->curAlgorithm));\r
3665                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
3666                 }\r
3667                 switch(pCoexDm->curAlgorithm)\r
3668                 {\r
3669                         case BT_8192E_2ANT_COEX_ALGO_SCO:\r
3670                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = SCO.\n"));\r
3671                                 halbtc8192e2ant_ActionSco(pBtCoexist);\r
3672                                 break;\r
3673                         case BT_8192E_2ANT_COEX_ALGO_SCO_PAN:\r
3674                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = SCO+PAN(EDR).\n"));\r
3675                                 halbtc8192e2ant_ActionScoPan(pBtCoexist);\r
3676                                 break;\r
3677                         case BT_8192E_2ANT_COEX_ALGO_HID:\r
3678                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID.\n"));\r
3679                                 halbtc8192e2ant_ActionHid(pBtCoexist);\r
3680                                 break;\r
3681                         case BT_8192E_2ANT_COEX_ALGO_A2DP:\r
3682                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = A2DP.\n"));\r
3683                                 halbtc8192e2ant_ActionA2dp(pBtCoexist);\r
3684                                 break;\r
3685                         case BT_8192E_2ANT_COEX_ALGO_A2DP_PANHS:\r
3686                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"));\r
3687                                 halbtc8192e2ant_ActionA2dpPanHs(pBtCoexist);\r
3688                                 break;\r
3689                         case BT_8192E_2ANT_COEX_ALGO_PANEDR:\r
3690                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"));\r
3691                                 halbtc8192e2ant_ActionPanEdr(pBtCoexist);\r
3692                                 break;\r
3693                         case BT_8192E_2ANT_COEX_ALGO_PANHS:\r
3694                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HS mode.\n"));\r
3695                                 halbtc8192e2ant_ActionPanHs(pBtCoexist);\r
3696                                 break;\r
3697                         case BT_8192E_2ANT_COEX_ALGO_PANEDR_A2DP:\r
3698                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"));\r
3699                                 halbtc8192e2ant_ActionPanEdrA2dp(pBtCoexist);\r
3700                                 break;\r
3701                         case BT_8192E_2ANT_COEX_ALGO_PANEDR_HID:\r
3702                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));\r
3703                                 halbtc8192e2ant_ActionPanEdrHid(pBtCoexist);\r
3704                                 break;\r
3705                         case BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
3706                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));\r
3707                                 halbtc8192e2ant_ActionHidA2dpPanEdr(pBtCoexist);\r
3708                                 break;\r
3709                         case BT_8192E_2ANT_COEX_ALGO_HID_A2DP:\r
3710                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"));\r
3711                                 halbtc8192e2ant_ActionHidA2dp(pBtCoexist);\r
3712                                 break;\r
3713                         default:\r
3714                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = unknown!!\n"));\r
3715                                 //halbtc8192e2ant_CoexAllOff(pBtCoexist);\r
3716                                 break;\r
3717                 }\r
3718                 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
3719         }\r
3720 }\r
3721 \r
3722 VOID\r
3723 halbtc8192e2ant_InitHwConfig(\r
3724         IN      PBTC_COEXIST            pBtCoexist,\r
3725         IN      BOOLEAN                         bBackUp\r
3726         )\r
3727 {\r
3728         u4Byte  u4Tmp=0;\r
3729         u2Byte  u2Tmp=0;\r
3730         u1Byte  u1Tmp=0;\r
3731 \r
3732         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 2Ant Init HW Config!!\n"));\r
3733 \r
3734         if(bBackUp)\r
3735         {\r
3736                 // backup rf 0x1e value\r
3737                 pCoexDm->btRf0x1eBackup = \r
3738                         pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);\r
3739 \r
3740                 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
3741                 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
3742                 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
3743                 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
3744         }\r
3745 \r
3746         // antenna sw ctrl to bt\r
3747         halbtc8192e2ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, TRUE, FALSE);\r
3748 \r
3749         halbtc8192e2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
3750 \r
3751         // antenna switch control parameter\r
3752         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x858, 0x55555555);\r
3753 \r
3754         // coex parameters\r
3755         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);\r
3756         // 0x790[5:0]=0x5\r
3757         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);\r
3758         u1Tmp &= 0xc0;\r
3759         u1Tmp |= 0x5;\r
3760         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);\r
3761 \r
3762         // enable counter statistics\r
3763         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
3764 \r
3765         // enable PTA\r
3766         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x20);\r
3767         // enable mailbox interface\r
3768         u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x40);\r
3769         u2Tmp |= BIT9;\r
3770         pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x40, u2Tmp);\r
3771 \r
3772         // enable PTA I2C mailbox \r
3773         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x101);\r
3774         u1Tmp |= BIT4;\r
3775         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x101, u1Tmp);\r
3776 \r
3777         // enable bt clock when wifi is disabled.\r
3778         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x93);\r
3779         u1Tmp |= BIT0;\r
3780         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x93, u1Tmp);\r
3781         // enable bt clock when suspend.\r
3782         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7);\r
3783         u1Tmp |= BIT0;\r
3784         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x7, u1Tmp);\r
3785 }\r
3786 \r
3787 //============================================================\r
3788 // work around function start with wa_halbtc8192e2ant_\r
3789 //============================================================\r
3790 //============================================================\r
3791 // extern function start with EXhalbtc8192e2ant_\r
3792 //============================================================\r
3793 VOID\r
3794 EXhalbtc8192e2ant_InitHwConfig(\r
3795         IN      PBTC_COEXIST            pBtCoexist\r
3796         )\r
3797 {\r
3798         halbtc8192e2ant_InitHwConfig(pBtCoexist, TRUE);\r
3799 }\r
3800 \r
3801 VOID\r
3802 EXhalbtc8192e2ant_InitCoexDm(\r
3803         IN      PBTC_COEXIST            pBtCoexist\r
3804         )\r
3805 {\r
3806         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));\r
3807         \r
3808         halbtc8192e2ant_InitCoexDm(pBtCoexist);\r
3809 }\r
3810 \r
3811 VOID\r
3812 EXhalbtc8192e2ant_DisplayCoexInfo(\r
3813         IN      PBTC_COEXIST            pBtCoexist\r
3814         )\r
3815 {\r
3816         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3817         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
3818         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
3819         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
3820         u2Byte                          u2Tmp[4];\r
3821         u4Byte                          u4Tmp[4];\r
3822         BOOLEAN                         bRoam=FALSE, bScan=FALSE, bLink=FALSE, bWifiUnder5G=FALSE;\r
3823         BOOLEAN                         bBtHsOn=FALSE, bWifiBusy=FALSE;\r
3824         s4Byte                          wifiRssi=0, btHsRssi=0;\r
3825         u4Byte                          wifiBw, wifiTrafficDir, faOfdm, faCck;\r
3826         u1Byte                          wifiDot11Chnl, wifiHsChnl;\r
3827         u4Byte                          fwVer=0, btPatchVer=0;\r
3828 \r
3829         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
3830         CL_PRINTF(cliBuf);\r
3831 \r
3832         if(pBtCoexist->bManualControl)\r
3833         {\r
3834                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");\r
3835                 CL_PRINTF(cliBuf);\r
3836                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
3837                 CL_PRINTF(cliBuf);\r
3838         }\r
3839 \r
3840         if(!pBoardInfo->bBtExist)\r
3841         {\r
3842                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n BT not exists !!!");\r
3843                 CL_PRINTF(cliBuf);\r
3844                 return;\r
3845         }\r
3846 \r
3847         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
3848                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
3849         CL_PRINTF(cliBuf);\r
3850         \r
3851         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
3852                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
3853         CL_PRINTF(cliBuf);\r
3854 \r
3855         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
3856         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
3857         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \\r
3858                 GLCoexVerDate8192e2Ant, GLCoexVer8192e2Ant, fwVer, btPatchVer, btPatchVer);\r
3859         CL_PRINTF(cliBuf);\r
3860 \r
3861         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
3862         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiDot11Chnl);\r
3863         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl);\r
3864         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsMode(HsChnl)", \\r
3865                 wifiDot11Chnl, bBtHsOn, wifiHsChnl);\r
3866         CL_PRINTF(cliBuf);\r
3867 \r
3868         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "H2C Wifi inform bt chnl Info", \\r
3869                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
3870                 pCoexDm->wifiChnlInfo[2]);\r
3871         CL_PRINTF(cliBuf);\r
3872 \r
3873         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
3874         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);\r
3875         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \\r
3876                 wifiRssi, btHsRssi);\r
3877         CL_PRINTF(cliBuf);\r
3878 \r
3879         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
3880         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
3881         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
3882         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \\r
3883                 bLink, bRoam, bScan);\r
3884         CL_PRINTF(cliBuf);\r
3885 \r
3886         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);\r
3887         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3888         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
3889         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
3890         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s ", "Wifi status", \\r
3891                 (bWifiUnder5G? "5G":"2.4G"),\r
3892                 ((BTC_WIFI_BW_LEGACY==wifiBw)? "Legacy": (((BTC_WIFI_BW_HT40==wifiBw)? "HT40":"HT20"))),\r
3893                 ((!bWifiBusy)? "idle": ((BTC_WIFI_TRAFFIC_TX==wifiTrafficDir)? "uplink":"downlink")));\r
3894         CL_PRINTF(cliBuf);\r
3895 \r
3896         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
3897                 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":\r
3898                 (  (BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),\r
3899                 pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
3900         CL_PRINTF(cliBuf);\r
3901 \r
3902         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
3903                 pStackInfo->bScoExist, pStackInfo->bHidExist, pStackInfo->bPanExist, pStackInfo->bA2dpExist);\r
3904         CL_PRINTF(cliBuf);\r
3905         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
3906 \r
3907         btInfoExt = pCoexSta->btInfoExt;\r
3908         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
3909                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
3910         CL_PRINTF(cliBuf);      \r
3911 \r
3912         for(i=0; i<BT_INFO_SRC_8192E_2ANT_MAX; i++)\r
3913         {\r
3914                 if(pCoexSta->btInfoC2hCnt[i])\r
3915                 {                               \r
3916                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8192e2Ant[i], \\r
3917                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
3918                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
3919                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
3920                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
3921                         CL_PRINTF(cliBuf);\r
3922                 }\r
3923         }\r
3924 \r
3925         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/%s", "PS state, IPS/LPS", \\r
3926                 ((pCoexSta->bUnderIps? "IPS ON":"IPS OFF")),\r
3927                 ((pCoexSta->bUnderLps? "LPS ON":"LPS OFF")));\r
3928         CL_PRINTF(cliBuf);\r
3929         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);\r
3930 \r
3931         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "SS Type", \\r
3932                 pCoexDm->curSsType);\r
3933         CL_PRINTF(cliBuf);\r
3934 \r
3935         // Sw mechanism \r
3936         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
3937         CL_PRINTF(cliBuf);\r
3938         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "SM1[ShRf/ LpRA/ LimDig]", \\r
3939                 pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);\r
3940         CL_PRINTF(cliBuf);\r
3941         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \\r
3942                 pCoexDm->bCurAgcTableEn, pCoexDm->bCurAdcBackOff, pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl);\r
3943         CL_PRINTF(cliBuf);\r
3944 \r
3945         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \\r
3946                         pBtCoexist->btInfo.raMask);\r
3947         CL_PRINTF(cliBuf);\r
3948 \r
3949         // Fw mechanism         \r
3950         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
3951         CL_PRINTF(cliBuf);      \r
3952 \r
3953         psTdmaCase = pCoexDm->curPsTdma;\r
3954         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \\r
3955                 pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
3956                 pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
3957                 pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);\r
3958         CL_PRINTF(cliBuf);\r
3959 \r
3960         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct", \\r
3961                 pCoexDm->curBtDecPwrLvl, pCoexDm->bCurIgnoreWlanAct);\r
3962         CL_PRINTF(cliBuf);\r
3963 \r
3964         // Hw setting           \r
3965         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
3966         CL_PRINTF(cliBuf);      \r
3967 \r
3968         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \\r
3969                 pCoexDm->btRf0x1eBackup);\r
3970         CL_PRINTF(cliBuf);\r
3971 \r
3972         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "backup ARFR1/ARFR2/RL/AMaxTime", \\r
3973                 pCoexDm->backupArfrCnt1, pCoexDm->backupArfrCnt2, pCoexDm->backupRetryLimit, pCoexDm->backupAmpduMaxTime);\r
3974         CL_PRINTF(cliBuf);\r
3975 \r
3976         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
3977         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
3978         u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
3979         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
3980         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \\r
3981                 u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);\r
3982         CL_PRINTF(cliBuf);\r
3983 \r
3984         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc04);\r
3985         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xd04);\r
3986         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x90c);\r
3987         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0xc04/ 0xd04/ 0x90c", \\r
3988                 u4Tmp[0], u4Tmp[1], u4Tmp[2]);\r
3989         CL_PRINTF(cliBuf);\r
3990 \r
3991         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
3992         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778", \\r
3993                 u1Tmp[0]);\r
3994         CL_PRINTF(cliBuf);\r
3995         \r
3996         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x92c);\r
3997         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);\r
3998         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x92c/ 0x930", \\r
3999                 (u1Tmp[0]), u4Tmp[0]);\r
4000         CL_PRINTF(cliBuf);\r
4001 \r
4002         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
4003         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4f);\r
4004         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x40/ 0x4f", \\r
4005                 u1Tmp[0], u1Tmp[1]);\r
4006         CL_PRINTF(cliBuf);\r
4007 \r
4008         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
4009         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
4010         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
4011                 u4Tmp[0], u1Tmp[0]);\r
4012         CL_PRINTF(cliBuf);\r
4013 \r
4014         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
4015         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
4016                 u4Tmp[0]);\r
4017         CL_PRINTF(cliBuf);\r
4018         \r
4019         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
4020         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
4021         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
4022         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);\r
4023         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \\r
4024                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);\r
4025         CL_PRINTF(cliBuf);\r
4026 \r
4027         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(hp rx[31:16]/tx[15:0])", \\r
4028                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
4029         CL_PRINTF(cliBuf);\r
4030         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(lp rx[31:16]/tx[15:0])", \\r
4031                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
4032         CL_PRINTF(cliBuf);\r
4033 #if(BT_AUTO_REPORT_ONLY_8192E_2ANT == 1)\r
4034         halbtc8192e2ant_MonitorBtCtr(pBtCoexist);\r
4035 #endif\r
4036         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
4037 }\r
4038 \r
4039 \r
4040 VOID\r
4041 EXhalbtc8192e2ant_IpsNotify(\r
4042         IN      PBTC_COEXIST            pBtCoexist,\r
4043         IN      u1Byte                  type\r
4044         )\r
4045 {\r
4046         if(BTC_IPS_ENTER == type)\r
4047         {\r
4048                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));\r
4049                 pCoexSta->bUnderIps = TRUE;\r
4050                 halbtc8192e2ant_CoexAllOff(pBtCoexist);\r
4051                 halbtc8192e2ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
4052         }\r
4053         else if(BTC_IPS_LEAVE == type)\r
4054         {\r
4055                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));\r
4056                 pCoexSta->bUnderIps = FALSE;\r
4057         }\r
4058 }\r
4059 \r
4060 VOID\r
4061 EXhalbtc8192e2ant_LpsNotify(\r
4062         IN      PBTC_COEXIST            pBtCoexist,\r
4063         IN      u1Byte                  type\r
4064         )\r
4065 {\r
4066         if(BTC_LPS_ENABLE == type)\r
4067         {\r
4068                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));\r
4069                 pCoexSta->bUnderLps = TRUE;\r
4070         }\r
4071         else if(BTC_LPS_DISABLE == type)\r
4072         {\r
4073                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));\r
4074                 pCoexSta->bUnderLps = FALSE;\r
4075         }\r
4076 }\r
4077 \r
4078 VOID\r
4079 EXhalbtc8192e2ant_ScanNotify(\r
4080         IN      PBTC_COEXIST            pBtCoexist,\r
4081         IN      u1Byte                  type\r
4082         )\r
4083 {\r
4084         if(BTC_SCAN_START == type)\r
4085         {\r
4086                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
4087         }\r
4088         else if(BTC_SCAN_FINISH == type)\r
4089         {\r
4090                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
4091         }\r
4092 }\r
4093 \r
4094 VOID\r
4095 EXhalbtc8192e2ant_ConnectNotify(\r
4096         IN      PBTC_COEXIST            pBtCoexist,\r
4097         IN      u1Byte                  type\r
4098         )\r
4099 {\r
4100         if(BTC_ASSOCIATE_START == type)\r
4101         {\r
4102                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));\r
4103         }\r
4104         else if(BTC_ASSOCIATE_FINISH == type)\r
4105         {\r
4106                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));\r
4107         }\r
4108 }\r
4109 \r
4110 VOID\r
4111 EXhalbtc8192e2ant_MediaStatusNotify(\r
4112         IN      PBTC_COEXIST            pBtCoexist,\r
4113         IN      u1Byte                          type\r
4114         )\r
4115 {\r
4116         u1Byte                  H2C_Parameter[3] ={0};\r
4117         u4Byte                  wifiBw;\r
4118         u1Byte                  wifiCentralChnl;\r
4119 \r
4120         if(pBtCoexist->bManualControl ||\r
4121                 pBtCoexist->bStopCoexDm ||\r
4122                 pBtCoexist->btInfo.bBtDisabled )\r
4123                 return;\r
4124 \r
4125         if(BTC_MEDIA_CONNECT == type)\r
4126         {\r
4127                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));\r
4128         }\r
4129         else\r
4130         {\r
4131                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));\r
4132         }\r
4133 \r
4134         // only 2.4G we need to inform bt the chnl mask\r
4135         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
4136         if( (BTC_MEDIA_CONNECT == type) &&\r
4137                 (wifiCentralChnl <= 14) )\r
4138         {\r
4139                 H2C_Parameter[0] = 0x1;\r
4140                 H2C_Parameter[1] = wifiCentralChnl;\r
4141                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
4142                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
4143                         H2C_Parameter[2] = 0x30;\r
4144                 else\r
4145                         H2C_Parameter[2] = 0x20;\r
4146         }\r
4147         \r
4148         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
4149         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
4150         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
4151         \r
4152         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x66=0x%x\n", \r
4153                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
4154 \r
4155         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);    \r
4156 }\r
4157 \r
4158 VOID\r
4159 EXhalbtc8192e2ant_SpecialPacketNotify(\r
4160         IN      PBTC_COEXIST                    pBtCoexist,\r
4161         IN      u1Byte                          type\r
4162         )\r
4163 {\r
4164         if(type == BTC_PACKET_DHCP)\r
4165         {\r
4166                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], DHCP Packet notify\n"));\r
4167         }\r
4168 }\r
4169 \r
4170 VOID\r
4171 EXhalbtc8192e2ant_BtInfoNotify(\r
4172         IN      PBTC_COEXIST            pBtCoexist,\r
4173         IN      pu1Byte                 tmpBuf,\r
4174         IN      u1Byte                  length\r
4175         )\r
4176 {\r
4177         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
4178         u1Byte                  btInfo=0;\r
4179         u1Byte                  i, rspSource=0;\r
4180         BOOLEAN                 bBtBusy=FALSE, bLimitedDig=FALSE;\r
4181         BOOLEAN                 bWifiConnected=FALSE;\r
4182 \r
4183         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
4184 \r
4185         rspSource = tmpBuf[0]&0xf;\r
4186         if(rspSource >= BT_INFO_SRC_8192E_2ANT_MAX)\r
4187                 rspSource = BT_INFO_SRC_8192E_2ANT_WIFI_FW;\r
4188         pCoexSta->btInfoC2hCnt[rspSource]++;\r
4189 \r
4190         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
4191         for(i=0; i<length; i++)\r
4192         {\r
4193                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
4194                 if(i == 1)\r
4195                         btInfo = tmpBuf[i];\r
4196                 if(i == length-1)\r
4197                 {\r
4198                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));\r
4199                 }\r
4200                 else\r
4201                 {\r
4202                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));\r
4203                 }\r
4204         }\r
4205 \r
4206         if(BT_INFO_SRC_8192E_2ANT_WIFI_FW != rspSource)\r
4207         {\r
4208                 pCoexSta->btRetryCnt =  // [3:0]\r
4209                         pCoexSta->btInfoC2h[rspSource][2]&0xf;\r
4210 \r
4211                 pCoexSta->btRssi =\r
4212                         pCoexSta->btInfoC2h[rspSource][3]*2+10;\r
4213                 \r
4214                 pCoexSta->btInfoExt = \r
4215                         pCoexSta->btInfoC2h[rspSource][4];\r
4216 \r
4217                 // Here we need to resend some wifi info to BT\r
4218                 // because bt is reset and loss of the info.\r
4219                 if( (pCoexSta->btInfoExt & BIT1) )\r
4220                 {\r
4221                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));\r
4222                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
4223                         if(bWifiConnected)\r
4224                         {\r
4225                                 EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);\r
4226                         }\r
4227                         else\r
4228                         {\r
4229                                 EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
4230                         }\r
4231                 }\r
4232                 \r
4233                 if( (pCoexSta->btInfoExt & BIT3) )\r
4234                 {\r
4235                         if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)\r
4236                         {\r
4237                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));\r
4238                                 halbtc8192e2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
4239                         }\r
4240                 }\r
4241                 else\r
4242                 {\r
4243                         // BT already NOT ignore Wlan active, do nothing here.\r
4244                 }\r
4245 \r
4246 #if(BT_AUTO_REPORT_ONLY_8192E_2ANT == 0)\r
4247                 if( (pCoexSta->btInfoExt & BIT4) )\r
4248                 {\r
4249                         // BT auto report already enabled, do nothing\r
4250                 }\r
4251                 else\r
4252                 {\r
4253                         halbtc8192e2ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);\r
4254                 }\r
4255 #endif\r
4256         }\r
4257 \r
4258         // check BIT2 first ==> check if bt is under inquiry or page scan\r
4259         if(btInfo & BT_INFO_8192E_2ANT_B_INQ_PAGE)\r
4260                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
4261         else\r
4262                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
4263 \r
4264         // set link exist status\r
4265         if(!(btInfo&BT_INFO_8192E_2ANT_B_CONNECTION))\r
4266         {\r
4267                 pCoexSta->bBtLinkExist = FALSE;\r
4268                 pCoexSta->bPanExist = FALSE;\r
4269                 pCoexSta->bA2dpExist = FALSE;\r
4270                 pCoexSta->bHidExist = FALSE;\r
4271                 pCoexSta->bScoExist = FALSE;\r
4272         }\r
4273         else    // connection exists\r
4274         {\r
4275                 pCoexSta->bBtLinkExist = TRUE;\r
4276                 if(btInfo & BT_INFO_8192E_2ANT_B_FTP)\r
4277                         pCoexSta->bPanExist = TRUE;\r
4278                 else\r
4279                         pCoexSta->bPanExist = FALSE;\r
4280                 if(btInfo & BT_INFO_8192E_2ANT_B_A2DP)\r
4281                         pCoexSta->bA2dpExist = TRUE;\r
4282                 else\r
4283                         pCoexSta->bA2dpExist = FALSE;\r
4284                 if(btInfo & BT_INFO_8192E_2ANT_B_HID)\r
4285                         pCoexSta->bHidExist = TRUE;\r
4286                 else\r
4287                         pCoexSta->bHidExist = FALSE;\r
4288                 if(btInfo & BT_INFO_8192E_2ANT_B_SCO_ESCO)\r
4289                         pCoexSta->bScoExist = TRUE;\r
4290                 else\r
4291                         pCoexSta->bScoExist = FALSE;\r
4292         }\r
4293 \r
4294         halbtc8192e2ant_UpdateBtLinkInfo(pBtCoexist);\r
4295         \r
4296         if(!(btInfo&BT_INFO_8192E_2ANT_B_CONNECTION))\r
4297         {\r
4298                 pCoexDm->btStatus = BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE;\r
4299                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));\r
4300         }\r
4301         else if(btInfo == BT_INFO_8192E_2ANT_B_CONNECTION)      // connection exists but no busy\r
4302         {\r
4303                 pCoexDm->btStatus = BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE;\r
4304                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));\r
4305         }\r
4306         else if((btInfo&BT_INFO_8192E_2ANT_B_SCO_ESCO) ||\r
4307                 (btInfo&BT_INFO_8192E_2ANT_B_SCO_BUSY))\r
4308         {\r
4309                 pCoexDm->btStatus = BT_8192E_2ANT_BT_STATUS_SCO_BUSY;\r
4310                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));\r
4311         }\r
4312         else if(btInfo&BT_INFO_8192E_2ANT_B_ACL_BUSY)\r
4313         {\r
4314                 pCoexDm->btStatus = BT_8192E_2ANT_BT_STATUS_ACL_BUSY;\r
4315                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));\r
4316         }\r
4317         else\r
4318         {\r
4319                 pCoexDm->btStatus = BT_8192E_2ANT_BT_STATUS_MAX;\r
4320                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));\r
4321         }\r
4322         \r
4323         if( (BT_8192E_2ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
4324                 (BT_8192E_2ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
4325                 (BT_8192E_2ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
4326         {\r
4327                 bBtBusy = TRUE;\r
4328                 bLimitedDig = TRUE;\r
4329         }\r
4330         else\r
4331         {\r
4332                 bBtBusy = FALSE;\r
4333                 bLimitedDig = FALSE;\r
4334         }\r
4335 \r
4336         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
4337 \r
4338         pCoexDm->bLimitedDig = bLimitedDig;\r
4339         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig);\r
4340 \r
4341         halbtc8192e2ant_RunCoexistMechanism(pBtCoexist);\r
4342 }\r
4343 \r
4344 VOID\r
4345 EXhalbtc8192e2ant_HaltNotify(\r
4346         IN      PBTC_COEXIST                    pBtCoexist\r
4347         )\r
4348 {\r
4349         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));\r
4350 \r
4351         halbtc8192e2ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
4352         halbtc8192e2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
4353         EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
4354 }\r
4355 \r
4356 VOID\r
4357 EXhalbtc8192e2ant_Periodical(\r
4358         IN      PBTC_COEXIST                    pBtCoexist\r
4359         )\r
4360 {\r
4361         static u1Byte           disVerInfoCnt=0;\r
4362         u4Byte                          fwVer=0, btPatchVer=0;\r
4363         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4364         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
4365 \r
4366         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ==========================Periodical===========================\n"));\r
4367 \r
4368         if(disVerInfoCnt <= 5)\r
4369         {\r
4370                 disVerInfoCnt += 1;\r
4371                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
4372                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n", \\r
4373                         pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));\r
4374                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n", \\r
4375                         ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));\r
4376                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
4377                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
4378                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", \\r
4379                         GLCoexVerDate8192e2Ant, GLCoexVer8192e2Ant, fwVer, btPatchVer, btPatchVer));\r
4380                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
4381         }\r
4382 \r
4383 #if(BT_AUTO_REPORT_ONLY_8192E_2ANT == 0)\r
4384         halbtc8192e2ant_QueryBtInfo(pBtCoexist);\r
4385         halbtc8192e2ant_MonitorBtCtr(pBtCoexist);\r
4386         halbtc8192e2ant_MonitorBtEnableDisable(pBtCoexist);\r
4387 #else\r
4388         if( halbtc8192e2ant_IsWifiStatusChanged(pBtCoexist) ||\r
4389                 pCoexDm->bAutoTdmaAdjust)\r
4390         {\r
4391                 halbtc8192e2ant_RunCoexistMechanism(pBtCoexist);\r
4392         }\r
4393 #endif\r
4394 }\r
4395 \r
4396 \r
4397 #endif\r
4398 \r