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