1
2
3
4
5
6
7
8#include <hal_data.h>
9#include <rtw_debug.h>
10#include <hal_btcoex.h>
11#include <Mp_Precomp.h>
12
13
14
15struct btc_coexist GLBtCoexist;
16static u8 GLBtcWiFiInScanState;
17static u8 GLBtcWiFiInIQKState;
18
19
20
21
22static u8 halbtcoutsrc_IsBtCoexistAvailable(struct btc_coexist *pBtCoexist)
23{
24 if (!pBtCoexist->bBinded || !pBtCoexist->Adapter)
25 return false;
26
27 return true;
28}
29
30static void halbtcoutsrc_LeaveLps(struct btc_coexist *pBtCoexist)
31{
32 struct adapter *padapter;
33
34
35 padapter = pBtCoexist->Adapter;
36
37 pBtCoexist->btInfo.bBtCtrlLps = true;
38 pBtCoexist->btInfo.bBtLpsOn = false;
39
40 rtw_btcoex_LPS_Leave(padapter);
41}
42
43static void halbtcoutsrc_EnterLps(struct btc_coexist *pBtCoexist)
44{
45 struct adapter *padapter;
46
47
48 padapter = pBtCoexist->Adapter;
49
50 pBtCoexist->btInfo.bBtCtrlLps = true;
51 pBtCoexist->btInfo.bBtLpsOn = true;
52
53 rtw_btcoex_LPS_Enter(padapter);
54}
55
56static void halbtcoutsrc_NormalLps(struct btc_coexist *pBtCoexist)
57{
58 struct adapter *padapter;
59
60 padapter = pBtCoexist->Adapter;
61
62 if (pBtCoexist->btInfo.bBtCtrlLps) {
63 pBtCoexist->btInfo.bBtLpsOn = false;
64 rtw_btcoex_LPS_Leave(padapter);
65 pBtCoexist->btInfo.bBtCtrlLps = false;
66
67
68 }
69}
70
71
72
73
74
75static void halbtcoutsrc_LeaveLowPower(struct btc_coexist *pBtCoexist)
76{
77 struct adapter *padapter;
78 s32 ready;
79 unsigned long stime;
80 unsigned long utime;
81 u32 timeout;
82
83
84 padapter = pBtCoexist->Adapter;
85 ready = _FAIL;
86#ifdef LPS_RPWM_WAIT_MS
87 timeout = LPS_RPWM_WAIT_MS;
88#else
89 timeout = 30;
90#endif
91
92 stime = jiffies;
93 do {
94 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
95 if (_SUCCESS == ready)
96 break;
97
98 utime = jiffies_to_msecs(jiffies - stime);
99 if (utime > timeout)
100 break;
101
102 msleep(1);
103 } while (1);
104}
105
106
107
108
109
110static void halbtcoutsrc_NormalLowPower(struct btc_coexist *pBtCoexist)
111{
112 struct adapter *padapter;
113
114
115 padapter = pBtCoexist->Adapter;
116 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
117}
118
119static void halbtcoutsrc_DisableLowPower(struct btc_coexist *pBtCoexist, u8 bLowPwrDisable)
120{
121 pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
122 if (bLowPwrDisable)
123 halbtcoutsrc_LeaveLowPower(pBtCoexist);
124 else
125 halbtcoutsrc_NormalLowPower(pBtCoexist);
126}
127
128static void halbtcoutsrc_AggregationCheck(struct btc_coexist *pBtCoexist)
129{
130 struct adapter *padapter;
131 bool bNeedToAct;
132
133
134 padapter = pBtCoexist->Adapter;
135 bNeedToAct = false;
136
137 if (pBtCoexist->btInfo.bRejectAggPkt) {
138 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
139 } else {
140 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
141 pBtCoexist->btInfo.bBtCtrlAggBufSize) {
142 bNeedToAct = true;
143 pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
144 }
145
146 if (pBtCoexist->btInfo.bBtCtrlAggBufSize) {
147 if (pBtCoexist->btInfo.preAggBufSize !=
148 pBtCoexist->btInfo.aggBufSize){
149 bNeedToAct = true;
150 }
151 pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
152 }
153
154 if (bNeedToAct) {
155 rtw_btcoex_RejectApAggregatedPacket(padapter, true);
156 rtw_btcoex_RejectApAggregatedPacket(padapter, false);
157 }
158 }
159}
160
161static u8 halbtcoutsrc_IsWifiBusy(struct adapter *padapter)
162{
163 struct mlme_priv *pmlmepriv;
164
165
166 pmlmepriv = &padapter->mlmepriv;
167
168 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
169 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true)
170 return true;
171 if (pmlmepriv->LinkDetectInfo.bBusyTraffic)
172 return true;
173 }
174
175 return false;
176}
177
178static u32 _halbtcoutsrc_GetWifiLinkStatus(struct adapter *padapter)
179{
180 struct mlme_priv *pmlmepriv;
181 u8 bp2p;
182 u32 portConnectedStatus;
183
184
185 pmlmepriv = &padapter->mlmepriv;
186 bp2p = false;
187 portConnectedStatus = 0;
188
189 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) {
190 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
191 if (bp2p)
192 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
193 else
194 portConnectedStatus |= WIFI_AP_CONNECTED;
195 } else {
196 if (bp2p)
197 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
198 else
199 portConnectedStatus |= WIFI_STA_CONNECTED;
200 }
201 }
202
203 return portConnectedStatus;
204}
205
206static u32 halbtcoutsrc_GetWifiLinkStatus(struct btc_coexist *pBtCoexist)
207{
208
209
210
211
212
213
214 struct adapter *padapter;
215 u32 retVal;
216 u32 portConnectedStatus, numOfConnectedPort;
217
218
219 padapter = pBtCoexist->Adapter;
220 portConnectedStatus = 0;
221 numOfConnectedPort = 0;
222
223 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
224 if (retVal) {
225 portConnectedStatus |= retVal;
226 numOfConnectedPort++;
227 }
228
229 retVal = (numOfConnectedPort << 16) | portConnectedStatus;
230
231 return retVal;
232}
233
234static u32 halbtcoutsrc_GetBtPatchVer(struct btc_coexist *pBtCoexist)
235{
236 return pBtCoexist->btInfo.btRealFwVer;
237}
238
239static s32 halbtcoutsrc_GetWifiRssi(struct adapter *padapter)
240{
241 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
242
243 return pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB;
244}
245
246static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter)
247{
248 struct mlme_ext_priv *pmlmeext;
249 static u8 scan_AP_num;
250
251 pmlmeext = &padapter->mlmeextpriv;
252
253 if (!GLBtcWiFiInScanState) {
254 if (pmlmeext->sitesurvey_res.bss_cnt > 0xFF)
255 scan_AP_num = 0xFF;
256 else
257 scan_AP_num = (u8)pmlmeext->sitesurvey_res.bss_cnt;
258 }
259
260 return scan_AP_num;
261}
262
263static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
264{
265 struct btc_coexist *pBtCoexist;
266 struct adapter *padapter;
267 struct hal_com_data *pHalData;
268 struct mlme_ext_priv *mlmeext;
269 u8 *pu8;
270 s32 *pS4Tmp;
271 u32 *pU4Tmp;
272 u8 ret;
273
274
275 pBtCoexist = (struct btc_coexist *)pBtcContext;
276 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
277 return false;
278
279 padapter = pBtCoexist->Adapter;
280 pHalData = GET_HAL_DATA(padapter);
281 mlmeext = &padapter->mlmeextpriv;
282 pu8 = pOutBuf;
283 pS4Tmp = pOutBuf;
284 pU4Tmp = pOutBuf;
285 ret = true;
286
287 switch (getType) {
288 case BTC_GET_BL_HS_OPERATION:
289 *pu8 = false;
290 ret = false;
291 break;
292
293 case BTC_GET_BL_HS_CONNECTING:
294 *pu8 = false;
295 ret = false;
296 break;
297
298 case BTC_GET_BL_WIFI_CONNECTED:
299 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
300 break;
301
302 case BTC_GET_BL_WIFI_BUSY:
303 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
304 break;
305
306 case BTC_GET_BL_WIFI_SCAN:
307
308
309 *pu8 = GLBtcWiFiInScanState;
310 break;
311
312 case BTC_GET_BL_WIFI_LINK:
313 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
314 break;
315
316 case BTC_GET_BL_WIFI_ROAM:
317 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
318 break;
319
320 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
321 *pu8 = false;
322 break;
323
324 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
325 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
326 break;
327
328 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
329 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm != 0;
330 break;
331
332 case BTC_GET_BL_WIFI_UNDER_B_MODE:
333 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
334 *pu8 = true;
335 else
336 *pu8 = false;
337 break;
338
339 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
340 *pu8 = false;
341 break;
342
343 case BTC_GET_BL_EXT_SWITCH:
344 *pu8 = false;
345 break;
346
347 case BTC_GET_S4_WIFI_RSSI:
348 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
349 break;
350
351 case BTC_GET_S4_HS_RSSI:
352 *pS4Tmp = 0;
353 ret = false;
354 break;
355
356 case BTC_GET_U4_WIFI_BW:
357 if (is_legacy_only(mlmeext->cur_wireless_mode))
358 *pU4Tmp = BTC_WIFI_BW_LEGACY;
359 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
360 *pU4Tmp = BTC_WIFI_BW_HT20;
361 else
362 *pU4Tmp = BTC_WIFI_BW_HT40;
363 break;
364
365 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
366 {
367 struct rt_link_detect_t *plinkinfo;
368 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
369
370 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
371 *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
372 else
373 *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
374 }
375 break;
376
377 case BTC_GET_U4_WIFI_FW_VER:
378 *pU4Tmp = pHalData->FirmwareVersion << 16;
379 *pU4Tmp |= pHalData->FirmwareSubVersion;
380 break;
381
382 case BTC_GET_U4_WIFI_LINK_STATUS:
383 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
384 break;
385
386 case BTC_GET_U4_BT_PATCH_VER:
387 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
388 break;
389
390 case BTC_GET_U1_WIFI_DOT11_CHNL:
391 *pu8 = padapter->mlmeextpriv.cur_channel;
392 break;
393
394 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
395 *pu8 = pHalData->CurrentChannel;
396 break;
397
398 case BTC_GET_U1_WIFI_HS_CHNL:
399 *pu8 = 0;
400 ret = false;
401 break;
402
403 case BTC_GET_U1_MAC_PHY_MODE:
404 *pu8 = BTC_SMSP;
405
406
407
408 break;
409
410 case BTC_GET_U1_AP_NUM:
411 *pu8 = halbtcoutsrc_GetWifiScanAPNum(padapter);
412 break;
413
414
415 case BTC_GET_U1_LPS_MODE:
416 *pu8 = padapter->dvobj->pwrctl_priv.pwr_mode;
417 break;
418
419 default:
420 ret = false;
421 break;
422 }
423
424 return ret;
425}
426
427static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
428{
429 struct btc_coexist *pBtCoexist;
430 struct adapter *padapter;
431 u8 *pu8;
432 u32 *pU4Tmp;
433 u8 ret;
434
435
436 pBtCoexist = (struct btc_coexist *)pBtcContext;
437 padapter = pBtCoexist->Adapter;
438 pu8 = pInBuf;
439 pU4Tmp = pInBuf;
440 ret = true;
441
442 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
443 return false;
444
445 switch (setType) {
446
447 case BTC_SET_BL_BT_DISABLE:
448 pBtCoexist->btInfo.bBtDisabled = *pu8;
449 break;
450
451 case BTC_SET_BL_BT_TRAFFIC_BUSY:
452 pBtCoexist->btInfo.bBtBusy = *pu8;
453 break;
454
455 case BTC_SET_BL_BT_LIMITED_DIG:
456 pBtCoexist->btInfo.bLimitedDig = *pu8;
457 break;
458
459 case BTC_SET_BL_FORCE_TO_ROAM:
460 pBtCoexist->btInfo.bForceToRoam = *pu8;
461 break;
462
463 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
464 pBtCoexist->btInfo.bRejectAggPkt = *pu8;
465 break;
466
467 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
468 pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
469 break;
470
471 case BTC_SET_BL_INC_SCAN_DEV_NUM:
472 pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
473 break;
474
475 case BTC_SET_BL_BT_TX_RX_MASK:
476 pBtCoexist->btInfo.bBtTxRxMask = *pu8;
477 break;
478
479
480 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
481 pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pu8;
482 break;
483
484 case BTC_SET_U1_AGG_BUF_SIZE:
485 pBtCoexist->btInfo.aggBufSize = *pu8;
486 break;
487
488
489 case BTC_SET_ACT_GET_BT_RSSI:
490 ret = false;
491 break;
492
493 case BTC_SET_ACT_AGGREGATE_CTRL:
494 halbtcoutsrc_AggregationCheck(pBtCoexist);
495 break;
496
497
498
499 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
500 pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pu8;
501 break;
502
503 case BTC_SET_U1_LPS_VAL:
504 pBtCoexist->btInfo.lpsVal = *pu8;
505 break;
506
507 case BTC_SET_U1_RPWM_VAL:
508 pBtCoexist->btInfo.rpwmVal = *pu8;
509 break;
510
511
512 case BTC_SET_ACT_LEAVE_LPS:
513 halbtcoutsrc_LeaveLps(pBtCoexist);
514 break;
515
516 case BTC_SET_ACT_ENTER_LPS:
517 halbtcoutsrc_EnterLps(pBtCoexist);
518 break;
519
520 case BTC_SET_ACT_NORMAL_LPS:
521 halbtcoutsrc_NormalLps(pBtCoexist);
522 break;
523
524 case BTC_SET_ACT_DISABLE_LOW_POWER:
525 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
526 break;
527
528 case BTC_SET_ACT_UPDATE_RAMASK:
529 pBtCoexist->btInfo.raMask = *pU4Tmp;
530
531 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true) {
532 struct sta_info *psta;
533 struct wlan_bssid_ex *cur_network;
534
535 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
536 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->mac_address);
537 rtw_hal_update_ra_mask(psta, 0);
538 }
539 break;
540
541 case BTC_SET_ACT_SEND_MIMO_PS:
542 ret = false;
543 break;
544
545 case BTC_SET_ACT_CTRL_BT_INFO:
546 ret = false;
547 break;
548
549 case BTC_SET_ACT_CTRL_BT_COEX:
550 ret = false;
551 break;
552 case BTC_SET_ACT_CTRL_8723B_ANT:
553 ret = false;
554 break;
555
556 default:
557 ret = false;
558 break;
559 }
560
561 return ret;
562}
563
564
565
566
567static u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
568{
569 struct btc_coexist *pBtCoexist;
570 struct adapter *padapter;
571
572
573 pBtCoexist = (struct btc_coexist *)pBtcContext;
574 padapter = pBtCoexist->Adapter;
575
576 return rtw_read8(padapter, RegAddr);
577}
578
579static u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
580{
581 struct btc_coexist *pBtCoexist;
582 struct adapter *padapter;
583
584
585 pBtCoexist = (struct btc_coexist *)pBtcContext;
586 padapter = pBtCoexist->Adapter;
587
588 return rtw_read16(padapter, RegAddr);
589}
590
591static u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
592{
593 struct btc_coexist *pBtCoexist;
594 struct adapter *padapter;
595
596
597 pBtCoexist = (struct btc_coexist *)pBtcContext;
598 padapter = pBtCoexist->Adapter;
599
600 return rtw_read32(padapter, RegAddr);
601}
602
603static void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
604{
605 struct btc_coexist *pBtCoexist;
606 struct adapter *padapter;
607
608
609 pBtCoexist = (struct btc_coexist *)pBtcContext;
610 padapter = pBtCoexist->Adapter;
611
612 rtw_write8(padapter, RegAddr, Data);
613}
614
615static void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
616{
617 struct btc_coexist *pBtCoexist;
618 struct adapter *padapter;
619 u8 originalValue, bitShift;
620 u8 i;
621
622
623 pBtCoexist = (struct btc_coexist *)pBtcContext;
624 padapter = pBtCoexist->Adapter;
625 originalValue = 0;
626 bitShift = 0;
627
628 if (bitMask != 0xFF) {
629 originalValue = rtw_read8(padapter, regAddr);
630
631 for (i = 0; i <= 7; i++) {
632 if ((bitMask >> i) & 0x1)
633 break;
634 }
635 bitShift = i;
636
637 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
638 }
639
640 rtw_write8(padapter, regAddr, data1b);
641}
642
643static void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
644{
645 struct btc_coexist *pBtCoexist;
646 struct adapter *padapter;
647
648
649 pBtCoexist = (struct btc_coexist *)pBtcContext;
650 padapter = pBtCoexist->Adapter;
651
652 rtw_write16(padapter, RegAddr, Data);
653}
654
655static void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
656{
657 struct btc_coexist *pBtCoexist;
658 struct adapter *padapter;
659
660
661 pBtCoexist = (struct btc_coexist *)pBtcContext;
662 padapter = pBtCoexist->Adapter;
663
664 rtw_write32(padapter, RegAddr, Data);
665}
666
667static void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
668{
669 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
670 struct adapter *Adapter = pBtCoexist->Adapter;
671
672 if (BTC_INTF_SDIO == pBtCoexist->chipInterface)
673 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
674 else
675 rtw_write8(Adapter, RegAddr, Data);
676}
677
678static void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
679{
680 struct btc_coexist *pBtCoexist;
681 struct adapter *padapter;
682
683
684 pBtCoexist = (struct btc_coexist *)pBtcContext;
685 padapter = pBtCoexist->Adapter;
686
687 PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
688}
689
690
691static u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
692{
693 struct btc_coexist *pBtCoexist;
694 struct adapter *padapter;
695
696
697 pBtCoexist = (struct btc_coexist *)pBtcContext;
698 padapter = pBtCoexist->Adapter;
699
700 return PHY_QueryBBReg(padapter, RegAddr, BitMask);
701}
702
703static void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
704{
705 struct btc_coexist *pBtCoexist;
706 struct adapter *padapter;
707
708
709 pBtCoexist = (struct btc_coexist *)pBtcContext;
710 padapter = pBtCoexist->Adapter;
711
712 PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
713}
714
715static u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
716{
717 struct btc_coexist *pBtCoexist;
718 struct adapter *padapter;
719
720
721 pBtCoexist = (struct btc_coexist *)pBtcContext;
722 padapter = pBtCoexist->Adapter;
723
724 return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
725}
726
727static void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
728{
729 struct btc_coexist *pBtCoexist;
730 struct adapter *padapter;
731 u8 CmdBuffer1[4] = {0};
732 u8 CmdBuffer2[4] = {0};
733 u8 *AddrToSet = (u8 *)&RegAddr;
734 u8 *ValueToSet = (u8 *)&Data;
735 u8 OperVer = 0;
736 u8 ReqNum = 0;
737
738 pBtCoexist = (struct btc_coexist *)pBtcContext;
739 padapter = pBtCoexist->Adapter;
740
741 CmdBuffer1[0] |= (OperVer & 0x0f);
742 CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0);
743 CmdBuffer1[1] = 0x0d;
744 CmdBuffer1[2] = ValueToSet[0];
745 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0]));
746
747 msleep(200);
748 ReqNum++;
749
750 CmdBuffer2[0] |= (OperVer & 0x0f);
751 CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0);
752 CmdBuffer2[1] = 0x0c;
753 CmdBuffer2[3] = AddrToSet[0];
754 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0]));
755}
756
757static u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
758{
759
760 return 0;
761}
762
763static void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
764{
765 struct btc_coexist *pBtCoexist;
766 struct adapter *padapter;
767
768
769 pBtCoexist = (struct btc_coexist *)pBtcContext;
770 padapter = pBtCoexist->Adapter;
771
772 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
773}
774
775
776
777
778static u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
779{
780 struct btc_coexist *pBtCoexist = &GLBtCoexist;
781
782 if (pBtCoexist->bBinded)
783 return false;
784 else
785 pBtCoexist->bBinded = true;
786
787 pBtCoexist->statistics.cntBind++;
788
789 pBtCoexist->Adapter = padapter;
790
791 pBtCoexist->stackInfo.bProfileNotified = false;
792
793 pBtCoexist->btInfo.bBtCtrlAggBufSize = false;
794 pBtCoexist->btInfo.aggBufSize = 5;
795
796 pBtCoexist->btInfo.bIncreaseScanDevNum = false;
797
798
799 pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
800
801 return true;
802}
803
804void hal_btcoex_Initialize(void *padapter)
805{
806 struct btc_coexist *pBtCoexist;
807
808 memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
809
810 pBtCoexist = &GLBtCoexist;
811
812
813
814 pBtCoexist->chipInterface = BTC_INTF_SDIO;
815
816 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
817
818 pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
819 pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
820 pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
821 pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
822 pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
823 pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
824 pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
825 pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
826
827 pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
828 pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
829
830 pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
831 pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
832
833 pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
834
835 pBtCoexist->fBtcGet = halbtcoutsrc_Get;
836 pBtCoexist->fBtcSet = halbtcoutsrc_Set;
837 pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
838 pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
839
840 pBtCoexist->boardInfo.singleAntPath = 0;
841
842 GLBtcWiFiInScanState = false;
843
844 GLBtcWiFiInIQKState = false;
845}
846
847void EXhalbtcoutsrc_PowerOnSetting(struct btc_coexist *pBtCoexist)
848{
849 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
850 return;
851
852
853 if (pBtCoexist->boardInfo.btdmAntNum == 2)
854 EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
855 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
856 EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
857}
858
859void EXhalbtcoutsrc_InitHwConfig(struct btc_coexist *pBtCoexist, u8 bWifiOnly)
860{
861 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
862 return;
863
864 pBtCoexist->statistics.cntInitHwConfig++;
865
866 if (pBtCoexist->boardInfo.btdmAntNum == 2)
867 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
868 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
869 EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
870}
871
872void EXhalbtcoutsrc_InitCoexDm(struct btc_coexist *pBtCoexist)
873{
874 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
875 return;
876
877 pBtCoexist->statistics.cntInitCoexDm++;
878
879 if (pBtCoexist->boardInfo.btdmAntNum == 2)
880 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
881 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
882 EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
883
884 pBtCoexist->bInitilized = true;
885}
886
887void EXhalbtcoutsrc_IpsNotify(struct btc_coexist *pBtCoexist, u8 type)
888{
889 u8 ipsType;
890
891 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
892 return;
893
894 pBtCoexist->statistics.cntIpsNotify++;
895 if (pBtCoexist->bManualControl)
896 return;
897
898 if (IPS_NONE == type)
899 ipsType = BTC_IPS_LEAVE;
900 else
901 ipsType = BTC_IPS_ENTER;
902
903
904
905
906 if (pBtCoexist->boardInfo.btdmAntNum == 2)
907 EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
908 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
909 EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
910
911
912}
913
914void EXhalbtcoutsrc_LpsNotify(struct btc_coexist *pBtCoexist, u8 type)
915{
916 u8 lpsType;
917
918
919 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
920 return;
921
922 pBtCoexist->statistics.cntLpsNotify++;
923 if (pBtCoexist->bManualControl)
924 return;
925
926 if (PS_MODE_ACTIVE == type)
927 lpsType = BTC_LPS_DISABLE;
928 else
929 lpsType = BTC_LPS_ENABLE;
930
931 if (pBtCoexist->boardInfo.btdmAntNum == 2)
932 EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
933 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
934 EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
935}
936
937void EXhalbtcoutsrc_ScanNotify(struct btc_coexist *pBtCoexist, u8 type)
938{
939 u8 scanType;
940
941 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
942 return;
943 pBtCoexist->statistics.cntScanNotify++;
944 if (pBtCoexist->bManualControl)
945 return;
946
947 if (type) {
948 scanType = BTC_SCAN_START;
949 GLBtcWiFiInScanState = true;
950 } else {
951 scanType = BTC_SCAN_FINISH;
952 GLBtcWiFiInScanState = false;
953 }
954
955
956
957
958 if (pBtCoexist->boardInfo.btdmAntNum == 2)
959 EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
960 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
961 EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
962
963
964}
965
966void EXhalbtcoutsrc_ConnectNotify(struct btc_coexist *pBtCoexist, u8 action)
967{
968 u8 assoType;
969
970 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
971 return;
972 pBtCoexist->statistics.cntConnectNotify++;
973 if (pBtCoexist->bManualControl)
974 return;
975
976 if (action)
977 assoType = BTC_ASSOCIATE_START;
978 else
979 assoType = BTC_ASSOCIATE_FINISH;
980
981
982
983
984 if (pBtCoexist->boardInfo.btdmAntNum == 2)
985 EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
986 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
987 EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
988
989
990}
991
992void EXhalbtcoutsrc_MediaStatusNotify(struct btc_coexist *pBtCoexist, enum
993 rt_media_status mediaStatus)
994{
995 u8 mStatus;
996
997 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
998 return;
999
1000 pBtCoexist->statistics.cntMediaStatusNotify++;
1001 if (pBtCoexist->bManualControl)
1002 return;
1003
1004 if (RT_MEDIA_CONNECT == mediaStatus)
1005 mStatus = BTC_MEDIA_CONNECT;
1006 else
1007 mStatus = BTC_MEDIA_DISCONNECT;
1008
1009
1010
1011
1012 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1013 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
1014 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1015 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
1016
1017
1018}
1019
1020void EXhalbtcoutsrc_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 pktType)
1021{
1022 u8 packetType;
1023
1024 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1025 return;
1026 pBtCoexist->statistics.cntSpecialPacketNotify++;
1027 if (pBtCoexist->bManualControl)
1028 return;
1029
1030 if (PACKET_DHCP == pktType) {
1031 packetType = BTC_PACKET_DHCP;
1032 } else if (PACKET_EAPOL == pktType) {
1033 packetType = BTC_PACKET_EAPOL;
1034 } else if (PACKET_ARP == pktType) {
1035 packetType = BTC_PACKET_ARP;
1036 } else {
1037 return;
1038 }
1039
1040
1041
1042
1043 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1044 EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
1045 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1046 EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
1047
1048
1049}
1050
1051void EXhalbtcoutsrc_BtInfoNotify(struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length)
1052{
1053 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1054 return;
1055
1056 pBtCoexist->statistics.cntBtInfoNotify++;
1057
1058
1059
1060
1061 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1062 EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1063 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1064 EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
1065
1066
1067}
1068
1069void EXhalbtcoutsrc_HaltNotify(struct btc_coexist *pBtCoexist)
1070{
1071 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1072 return;
1073
1074 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1075 EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
1076 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1077 EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
1078
1079 pBtCoexist->bBinded = false;
1080}
1081
1082void EXhalbtcoutsrc_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState)
1083{
1084 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1085 return;
1086
1087
1088
1089
1090
1091
1092 if (pBtCoexist->boardInfo.btdmAntNum == 1)
1093 EXhalbtc8723b1ant_PnpNotify(pBtCoexist, pnpState);
1094 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1095 EXhalbtc8723b2ant_PnpNotify(pBtCoexist, pnpState);
1096}
1097
1098void EXhalbtcoutsrc_Periodical(struct btc_coexist *pBtCoexist)
1099{
1100 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1101 return;
1102 pBtCoexist->statistics.cntPeriodical++;
1103
1104
1105
1106
1107
1108 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1109 EXhalbtc8723b2ant_Periodical(pBtCoexist);
1110 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1111 EXhalbtc8723b1ant_Periodical(pBtCoexist);
1112
1113
1114}
1115
1116void EXhalbtcoutsrc_SetChipType(u8 chipType)
1117{
1118 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
1119}
1120
1121void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
1122{
1123 if (BT_COEX_ANT_TYPE_PG == type) {
1124 GLBtCoexist.boardInfo.pgAntNum = antNum;
1125 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1126 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1127 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1128
1129 } else if (BT_COEX_ANT_TYPE_DETECTED == type) {
1130 GLBtCoexist.boardInfo.btdmAntNum = antNum;
1131
1132 }
1133}
1134
1135
1136
1137
1138void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
1139{
1140 GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
1141}
1142
1143
1144
1145
1146
1147
1148void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist)
1149{
1150 struct hal_com_data *pHalData;
1151
1152
1153 pHalData = GET_HAL_DATA(padapter);
1154 pHalData->bt_coexist.bBtExist = bBtExist;
1155}
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165bool hal_btcoex_IsBtExist(struct adapter *padapter)
1166{
1167 struct hal_com_data *pHalData;
1168
1169
1170 pHalData = GET_HAL_DATA(padapter);
1171 return pHalData->bt_coexist.bBtExist;
1172}
1173
1174bool hal_btcoex_IsBtDisabled(struct adapter *padapter)
1175{
1176 if (!hal_btcoex_IsBtExist(padapter))
1177 return true;
1178
1179 if (GLBtCoexist.btInfo.bBtDisabled)
1180 return true;
1181 else
1182 return false;
1183}
1184
1185void hal_btcoex_SetChipType(struct adapter *padapter, u8 chipType)
1186{
1187 struct hal_com_data *pHalData;
1188
1189
1190 pHalData = GET_HAL_DATA(padapter);
1191 pHalData->bt_coexist.btChipType = chipType;
1192
1193 EXhalbtcoutsrc_SetChipType(chipType);
1194}
1195
1196void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum)
1197{
1198 struct hal_com_data *pHalData;
1199
1200
1201 pHalData = GET_HAL_DATA(padapter);
1202
1203 pHalData->bt_coexist.btTotalAntNum = antNum;
1204 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1205}
1206
1207void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath)
1208{
1209 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
1210}
1211
1212void hal_btcoex_PowerOnSetting(struct adapter *padapter)
1213{
1214 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
1215}
1216
1217void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly)
1218{
1219 if (!hal_btcoex_IsBtExist(padapter))
1220 return;
1221
1222 EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
1223 EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
1224}
1225
1226void hal_btcoex_IpsNotify(struct adapter *padapter, u8 type)
1227{
1228 EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
1229}
1230
1231void hal_btcoex_LpsNotify(struct adapter *padapter, u8 type)
1232{
1233 EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
1234}
1235
1236void hal_btcoex_ScanNotify(struct adapter *padapter, u8 type)
1237{
1238 EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
1239}
1240
1241void hal_btcoex_ConnectNotify(struct adapter *padapter, u8 action)
1242{
1243 EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
1244}
1245
1246void hal_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus)
1247{
1248 EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
1249}
1250
1251void hal_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType)
1252{
1253 EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
1254}
1255
1256void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state)
1257{
1258 GLBtcWiFiInIQKState = state;
1259}
1260
1261void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf)
1262{
1263 if (GLBtcWiFiInIQKState)
1264 return;
1265
1266 EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
1267}
1268
1269void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state)
1270{
1271 if (state == 1)
1272 state = BTC_WIFI_PNP_SLEEP;
1273 else
1274 state = BTC_WIFI_PNP_WAKE_UP;
1275
1276 EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
1277}
1278
1279void hal_btcoex_HaltNotify(struct adapter *padapter)
1280{
1281 EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
1282}
1283
1284void hal_btcoex_Handler(struct adapter *padapter)
1285{
1286 EXhalbtcoutsrc_Periodical(&GLBtCoexist);
1287}
1288
1289s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter)
1290{
1291 return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
1292}
1293
1294void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual)
1295{
1296 GLBtCoexist.bManualControl = bmanual;
1297}
1298
1299bool hal_btcoex_IsBtControlLps(struct adapter *padapter)
1300{
1301 if (!hal_btcoex_IsBtExist(padapter))
1302 return false;
1303
1304 if (GLBtCoexist.btInfo.bBtDisabled)
1305 return false;
1306
1307 if (GLBtCoexist.btInfo.bBtCtrlLps)
1308 return true;
1309
1310 return false;
1311}
1312
1313bool hal_btcoex_IsLpsOn(struct adapter *padapter)
1314{
1315 if (!hal_btcoex_IsBtExist(padapter))
1316 return false;
1317
1318 if (GLBtCoexist.btInfo.bBtDisabled)
1319 return false;
1320
1321 if (GLBtCoexist.btInfo.bBtLpsOn)
1322 return true;
1323
1324 return false;
1325}
1326
1327u8 hal_btcoex_RpwmVal(struct adapter *padapter)
1328{
1329 return GLBtCoexist.btInfo.rpwmVal;
1330}
1331
1332u8 hal_btcoex_LpsVal(struct adapter *padapter)
1333{
1334 return GLBtCoexist.btInfo.lpsVal;
1335}
1336
1337u32 hal_btcoex_GetRaMask(struct adapter *padapter)
1338{
1339 if (!hal_btcoex_IsBtExist(padapter))
1340 return 0;
1341
1342 if (GLBtCoexist.btInfo.bBtDisabled)
1343 return 0;
1344
1345 if (GLBtCoexist.boardInfo.btdmAntNum != 1)
1346 return 0;
1347
1348 return GLBtCoexist.btInfo.raMask;
1349}
1350
1351void hal_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen)
1352{
1353 memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
1354}
1355