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