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