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