net: wireless: rockchip_wlan: add rtl8188eu support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8188eu / hal / hal_btcoex.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2013 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20 #define __HAL_BTCOEX_C__
21
22 #ifdef CONFIG_BT_COEXIST
23
24 #include <hal_data.h>
25 #include <hal_btcoex.h>
26 #include <Mp_Precomp.h>
27
28 //====================================
29 //              Global variables
30 //====================================
31 const char *const BtProfileString[] =
32 {
33         "NONE",
34         "A2DP",
35         "PAN",
36         "HID",
37         "SCO",
38 };
39
40 const char *const BtSpecString[] =
41 {
42         "1.0b",
43         "1.1",
44         "1.2",
45         "2.0+EDR",
46         "2.1+EDR",
47         "3.0+HS",
48         "4.0",
49 };
50
51 const char *const BtLinkRoleString[] =
52 {
53         "Master",
54         "Slave",
55 };
56
57 const char *const h2cStaString[] =
58 {
59         "successful",
60         "h2c busy",
61         "rf off",
62         "fw not read",
63 };
64
65 const char *const ioStaString[] =
66 {
67         "success",
68         "can not IO",
69         "rf off",
70         "fw not read",
71         "wait io timeout",
72         "invalid len",
73         "idle Q empty",
74         "insert waitQ fail",
75         "unknown fail",
76         "wrong level",
77         "h2c stopped",
78 };
79
80 const char *const GLBtcWifiBwString[]={
81         "11bg",
82         "HT20",
83         "HT40",
84         "HT80",
85         "HT160"
86 };
87
88 const char *const GLBtcWifiFreqString[]={
89         "2.4G",
90         "5G"
91 };
92
93 const char *const GLBtcIotPeerString[] = {
94         "UNKNOWN",
95         "REALTEK",
96         "REALTEK_92SE",
97         "BROADCOM",
98         "RALINK",
99         "ATHEROS",
100         "CISCO",
101         "MERU", 
102         "MARVELL",
103         "REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
104         "SELF_SOFTAP", /* Self is SoftAP */
105         "AIRGO",
106         "INTEL", 
107         "RTK_APCLIENT", 
108         "REALTEK_81XX", 
109         "REALTEK_WOW",
110         "REALTEK_JAGUAR_BCUTAP",
111         "REALTEK_JAGUAR_CCUTAP"
112 };
113
114 #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS       8000
115
116 BTC_COEXIST GLBtCoexist;
117 u8 GLBtcWiFiInScanState;
118 u8 GLBtcWiFiInIQKState;
119 u8 GLBtcWiFiInIPS;
120 u8 GLBtcWiFiInLPS;
121 u8 GLBtcBtCoexAliveRegistered;
122
123 /*
124  * BT control H2C/C2H
125  */
126 /* EXT_EID */
127 typedef enum _bt_ext_eid {
128         C2H_WIFI_FW_ACTIVE_RSP  = 0,
129         C2H_TRIG_BY_BT_FW
130 } BT_EXT_EID;
131
132 /* C2H_STATUS */
133 typedef enum _bt_c2h_status {
134         BT_STATUS_OK = 0,
135         BT_STATUS_VERSION_MISMATCH,
136         BT_STATUS_UNKNOWN_OPCODE,
137         BT_STATUS_ERROR_PARAMETER
138 } BT_C2H_STATUS;
139
140 /* C2H BT OP CODES */
141 typedef enum _bt_op_code {
142         BT_OP_GET_BT_VERSION    = 0,
143         BT_OP_WRITE_REG_ADDR    = 12,
144         BT_OP_WRITE_REG_VALUE,
145         BT_OP_READ_REG          = 17
146 } BT_OP_CODE;
147
148 #define BTC_MPOPER_TIMEOUT      50      /* unit: ms */
149
150 #define C2H_MAX_SIZE            16
151 u8 GLBtcBtMpOperSeq;
152 _mutex GLBtcBtMpOperLock;
153 _timer GLBtcBtMpOperTimer;
154 _sema GLBtcBtMpRptSema;
155 u8 GLBtcBtMpRptSeq;
156 u8 GLBtcBtMpRptStatus;
157 u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE];
158 u8 GLBtcBtMpRptRspSize;
159 u8 GLBtcBtMpRptWait;
160 u8 GLBtcBtMpRptWiFiOK;
161 u8 GLBtcBtMpRptBTOK;
162
163 /*
164  * Debug
165  */
166 u32 GLBtcDbgType[COMP_MAX];
167 u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
168
169 typedef struct _btcoexdbginfo
170 {
171         u8 *info;
172         u32 size; // buffer total size
173         u32 len; // now used length
174 } BTCDBGINFO, *PBTCDBGINFO;
175
176 BTCDBGINFO GLBtcDbgInfo;
177
178 #define BT_Operation(Adapter)                                           _FALSE
179
180 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
181 {
182         if (NULL == pinfo) return;
183
184         _rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
185
186         if (pbuf && size) {
187                 pinfo->info = pbuf;
188                 pinfo->size = size;
189         }
190 }
191
192 void DBG_BT_INFO(u8 *dbgmsg)
193 {
194         PBTCDBGINFO pinfo;
195         u32 msglen, buflen;
196         u8 *pbuf;
197
198
199         pinfo = &GLBtcDbgInfo;
200
201         if (NULL == pinfo->info)
202                 return;
203
204         msglen = strlen(dbgmsg);
205         if (pinfo->len + msglen > pinfo->size)
206                 return;
207
208         pbuf = pinfo->info + pinfo->len;
209         _rtw_memcpy(pbuf, dbgmsg, msglen);
210         pinfo->len += msglen;
211 }
212
213 //====================================
214 //              Debug related function
215 //====================================
216 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
217 {
218         if (!pBtCoexist->bBinded ||
219                 NULL == pBtCoexist->Adapter)
220         {
221                 return _FALSE;
222         }
223         return _TRUE;
224 }
225
226 static void halbtcoutsrc_DbgInit(void)
227 {
228         u8      i;
229
230         for (i = 0; i < COMP_MAX; i++)
231                 GLBtcDbgType[i] = 0;
232 }
233
234 static u8 halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)
235 {
236         if (pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC4
237                 || pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC8
238         ){
239                 return _TRUE;
240         }
241         return _FALSE;
242 }
243
244 static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
245 {
246         if (pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC4
247                 || pBtCoexist->boardInfo.btChipType == BTC_CHIP_CSR_BC8
248         ){
249                 return _FALSE;
250         }
251         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
252         {
253                 return _FALSE;
254         }
255         else
256                 return _TRUE;
257 }
258
259 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
260 {
261         PADAPTER padapter;
262
263
264         padapter = pBtCoexist->Adapter;
265
266         pBtCoexist->btInfo.bBtCtrlLps = _TRUE;
267         pBtCoexist->btInfo.bBtLpsOn = _FALSE;
268
269         rtw_btcoex_LPS_Leave(padapter);
270 }
271
272 void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
273 {
274         PADAPTER padapter;
275
276
277         padapter = pBtCoexist->Adapter;
278
279         pBtCoexist->btInfo.bBtCtrlLps = _TRUE;
280         pBtCoexist->btInfo.bBtLpsOn = _TRUE;
281
282         rtw_btcoex_LPS_Enter(padapter);
283 }
284
285 void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
286 {
287         PADAPTER padapter;
288
289
290         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Normal LPS behavior!!!\n"));
291
292         padapter = pBtCoexist->Adapter;
293
294         if (pBtCoexist->btInfo.bBtCtrlLps)
295         {
296                 pBtCoexist->btInfo.bBtLpsOn = _FALSE;
297                 rtw_btcoex_LPS_Leave(padapter);
298                 pBtCoexist->btInfo.bBtCtrlLps = _FALSE;
299
300                 // recover the LPS state to the original
301 #if 0
302                 padapter->HalFunc.UpdateLPSStatusHandler(
303                         padapter,
304                         pPSC->RegLeisurePsMode,
305                         pPSC->RegPowerSaveMode);
306 #endif
307         }
308 }
309
310 /*
311  *  Constraint:
312  *         1. this function will request pwrctrl->lock
313  */
314 void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
315 {
316 #ifdef CONFIG_LPS_LCLK
317         PADAPTER padapter;
318         PHAL_DATA_TYPE pHalData;
319         struct pwrctrl_priv *pwrctrl;
320         s32 ready;
321         u32 stime;
322         s32 utime;
323         u32 timeout; // unit: ms
324
325
326         padapter = pBtCoexist->Adapter;
327         pHalData = GET_HAL_DATA(padapter);
328         pwrctrl = adapter_to_pwrctl(padapter);
329         ready = _FAIL;
330 #ifdef LPS_RPWM_WAIT_MS
331         timeout = LPS_RPWM_WAIT_MS;
332 #else // !LPS_RPWM_WAIT_MS
333         timeout = 30;
334 #endif // !LPS_RPWM_WAIT_MS
335
336         if (GLBtcBtCoexAliveRegistered == _TRUE)
337                 return;
338
339         stime = rtw_get_current_time();
340         do {
341                 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
342                 if (_SUCCESS == ready)
343                         break;
344
345                 utime = rtw_get_passing_time_ms(stime);
346                 if (utime > timeout)
347                         break;
348
349                 rtw_msleep_os(1);
350         } while (1);
351
352         GLBtcBtCoexAliveRegistered = _TRUE;
353 #endif // CONFIG_LPS_LCLK
354 }
355
356 /*
357  *  Constraint:
358  *         1. this function will request pwrctrl->lock
359  */
360 void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
361 {
362 #ifdef CONFIG_LPS_LCLK
363         PADAPTER padapter;
364
365         if (GLBtcBtCoexAliveRegistered == _FALSE)
366                 return;
367
368         padapter = pBtCoexist->Adapter;
369         rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
370
371         GLBtcBtCoexAliveRegistered = _FALSE;
372 #endif // CONFIG_LPS_LCLK
373 }
374
375 void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
376 {
377         pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable;
378         if (bLowPwrDisable)
379                 halbtcoutsrc_LeaveLowPower(pBtCoexist);         // leave 32k low power.
380         else
381                 halbtcoutsrc_NormalLowPower(pBtCoexist);        // original 32k low power behavior.
382 }
383
384 void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
385 {
386         PADAPTER padapter;
387         BOOLEAN bNeedToAct = _FALSE;
388         static u32 preTime = 0;
389         u32 curTime = 0;
390
391         padapter = pBtCoexist->Adapter;
392
393         //=====================================
394         // To void continuous deleteBA=>addBA=>deleteBA=>addBA
395         // This function is not allowed to continuous called.
396         // It can only be called after 8 seconds.
397         //=====================================
398
399         curTime = rtw_systime_to_ms(rtw_get_current_time());
400         if((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS)     // over 8 seconds you can execute this function again.
401         {
402                 return;
403         }
404         else
405         {
406                 preTime = curTime;
407         }
408
409         if (pBtCoexist->btInfo.bRejectAggPkt)
410         {
411                 bNeedToAct = _TRUE;
412                 pBtCoexist->btInfo.bPreRejectAggPkt = pBtCoexist->btInfo.bRejectAggPkt;
413         }
414         else
415         {
416                 if(pBtCoexist->btInfo.bPreRejectAggPkt)
417                 {
418                         bNeedToAct = _TRUE;
419                         pBtCoexist->btInfo.bPreRejectAggPkt = pBtCoexist->btInfo.bRejectAggPkt;
420                 }
421                 
422                 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize !=
423                         pBtCoexist->btInfo.bBtCtrlAggBufSize)
424                 {
425                         bNeedToAct = _TRUE;
426                         pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize;
427                 }
428
429                 if (pBtCoexist->btInfo.bBtCtrlAggBufSize)
430                 {
431                         if (pBtCoexist->btInfo.preAggBufSize !=
432                                 pBtCoexist->btInfo.aggBufSize)
433                         {
434                                 bNeedToAct = _TRUE;
435                         }
436                         pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize;
437                 }
438         }
439
440         if (bNeedToAct)
441                 rtw_btcoex_rx_ampdu_apply(padapter);
442 }
443
444 u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
445 {
446         struct mlme_priv *pmlmepriv;
447
448
449         pmlmepriv = &padapter->mlmepriv;
450
451         if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
452         {
453                 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
454                         return _TRUE;
455                 if (_TRUE == pmlmepriv->LinkDetectInfo.bBusyTraffic)
456                         return _TRUE;
457         }
458
459 #if defined(CONFIG_CONCURRENT_MODE)
460         pmlmepriv = &padapter->pbuddy_adapter->mlmepriv;
461
462         if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
463         {
464                 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
465                         return _TRUE;
466                 if (_TRUE == pmlmepriv->LinkDetectInfo.bBusyTraffic)
467                         return _TRUE;
468         }
469 #endif
470
471         return _FALSE;
472 }
473
474 static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
475 {
476         struct mlme_priv *pmlmepriv;
477         u8 bp2p;
478         u32 portConnectedStatus;
479
480
481         pmlmepriv = &padapter->mlmepriv;
482         bp2p = _FALSE;
483         portConnectedStatus = 0;
484
485 #ifdef CONFIG_P2P
486         if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
487                 bp2p = _TRUE;
488 #endif // CONFIG_P2P
489
490         if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE)
491         {
492                 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE)
493                 {
494                         if (_TRUE == bp2p)
495                                 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
496                         else
497                                 portConnectedStatus |= WIFI_AP_CONNECTED;
498                 }
499                 else
500                 {
501                         if (_TRUE == bp2p)
502                                 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
503                         else
504                                 portConnectedStatus |= WIFI_STA_CONNECTED;
505                 }
506         }
507
508         return portConnectedStatus;
509 }
510
511 u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
512 {
513         //=================================
514         // return value:
515         // [31:16]=> connected port number
516         // [15:0]=> port connected bit define
517         //================================
518
519         PADAPTER padapter;
520         u32 retVal;
521         u32 portConnectedStatus, numOfConnectedPort;
522
523
524         padapter = pBtCoexist->Adapter;
525         retVal = 0;
526         portConnectedStatus = 0;
527         numOfConnectedPort = 0;
528
529         retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter);
530         if (retVal)
531         {
532                 portConnectedStatus |= retVal;
533                 numOfConnectedPort++;
534         }
535
536 #ifdef CONFIG_CONCURRENT_MODE
537         if (padapter->pbuddy_adapter)
538         {
539                 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter->pbuddy_adapter);
540                 if (retVal)
541                 {
542                         portConnectedStatus |= retVal;
543                         numOfConnectedPort++;
544                 }
545         }
546 #endif // CONFIG_CONCURRENT_MODE
547
548         retVal = (numOfConnectedPort << 16) | portConnectedStatus;
549         
550         return retVal;
551 }
552
553 static u8 _is_btfwver_valid(PBTC_COEXIST pBtCoexist, u16 btfwver)
554 {
555         if (!btfwver)
556                 return _FALSE;
557
558         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
559                 if (btfwver == 0x8723)
560                         return _FALSE;
561
562         return _TRUE;
563 }
564
565 static void _btmpoper_timer_hdl(void *p)
566 {
567         if (GLBtcBtMpRptWait) {
568                 GLBtcBtMpRptWait = 0;
569                 _rtw_up_sema(&GLBtcBtMpRptSema);
570         }
571 }
572
573 /*
574  * !IMPORTANT!
575  *      Before call this function, caller should acquire "GLBtcBtMpOperLock"!
576  *      Othrewise there will be racing problem and something may go wrong.
577  */
578 static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size)
579 {
580         PADAPTER padapter;
581         u8 buf[H2C_BTMP_OPER_LEN] = {0};
582         u8 buflen;
583         u8 seq;
584         u8 timer_cancelled;
585         s32 ret;
586
587
588         if (!cmd && size)
589                 size = 0;
590         if ((size + 2) > H2C_BTMP_OPER_LEN)
591                 return BT_STATUS_H2C_LENGTH_EXCEEDED;
592         buflen = size + 2;
593
594         seq = GLBtcBtMpOperSeq & 0xF;
595         GLBtcBtMpOperSeq++;
596
597         buf[0] = (opcodever & 0xF) | (seq << 4);
598         buf[1] = opcode;
599         if (cmd && size)
600                 _rtw_memcpy(buf+2, cmd, size);
601
602         GLBtcBtMpRptWait = 1;
603         GLBtcBtMpRptWiFiOK = 0;
604         GLBtcBtMpRptBTOK = 0;
605         GLBtcBtMpRptStatus = 0;
606         padapter = pBtCoexist->Adapter;
607         _set_timer(&GLBtcBtMpOperTimer, BTC_MPOPER_TIMEOUT);
608         if (rtw_hal_fill_h2c_cmd(padapter, H2C_BT_MP_OPER, buflen, buf) == _FAIL) {
609                 _cancel_timer(&GLBtcBtMpOperTimer, &timer_cancelled);
610                 ret = BT_STATUS_H2C_FAIL;
611                 goto exit;
612         }
613
614         _rtw_down_sema(&GLBtcBtMpRptSema);
615         /* GLBtcBtMpRptWait should be 0 here*/
616
617         if (!GLBtcBtMpRptWiFiOK) {
618                 DBG_871X("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__);
619                 ret = BT_STATUS_H2C_TIMTOUT;
620                 goto exit;
621         }
622         if (!GLBtcBtMpRptBTOK) {
623                 DBG_871X("%s: Didn't get BT response!\n", __FUNCTION__);
624                 ret = BT_STATUS_H2C_BT_NO_RSP;
625                 goto exit;
626         }
627         if (seq != GLBtcBtMpRptSeq) {
628                 DBG_871X("%s: Sequence number not match!(%d!=%d)!\n",
629                         __FUNCTION__, seq, GLBtcBtMpRptSeq);
630                 ret = BT_STATUS_C2H_REQNUM_MISMATCH;
631                 goto exit;
632         }
633
634         switch (GLBtcBtMpRptStatus) {
635         /* Examine the status reported from C2H */
636         case BT_STATUS_OK:
637                 ret = BT_STATUS_BT_OP_SUCCESS;
638                 DBG_871X("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__);
639                 break;
640         case BT_STATUS_VERSION_MISMATCH:
641                 ret = BT_STATUS_OPCODE_L_VERSION_MISMATCH;
642                 DBG_871X("%s: C2H status = BT_STATUS_OPCODE_L_VERSION_MISMATCH\n", __FUNCTION__);
643                 break;
644         case BT_STATUS_UNKNOWN_OPCODE:
645                 ret = BT_STATUS_UNKNOWN_OPCODE_L;
646                 DBG_871X("%s: C2H status = MP_BT_STATUS_UNKNOWN_OPCODE_L\n", __FUNCTION__);
647                 break;
648         case BT_STATUS_ERROR_PARAMETER:
649                 ret = BT_STATUS_PARAMETER_FORMAT_ERROR_L;
650                 DBG_871X("%s: C2H status = MP_BT_STATUS_PARAMETER_FORMAT_ERROR_L\n", __FUNCTION__);
651                 break;
652         default:
653                 ret = BT_STATUS_UNKNOWN_STATUS_L;
654                 DBG_871X("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__);
655                 break;
656         }
657
658 exit:
659         return ret;
660 }
661
662 u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
663 {
664         if (_is_btfwver_valid(pBtCoexist, pBtCoexist->btInfo.btRealFwVer) == _TRUE)
665                 goto exit;
666
667         if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
668                 _irqL irqL;
669                 u8 ret;
670
671
672                 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
673
674                 ret = _btmpoper_cmd(pBtCoexist, BT_OP_GET_BT_VERSION, 0, NULL, 0);
675                 if (BT_STATUS_BT_OP_SUCCESS == ret) {
676                         pBtCoexist->btInfo.btRealFwVer = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
677                         pBtCoexist->btInfo.btFwVer = *(GLBtcBtMpRptRsp+2);
678                 }
679                 pBtCoexist->btInfo.getBtFwVerCnt++;
680
681                 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
682         } else {
683 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
684                 u1Byte dataLen = 2;
685                 u1Byte buf[4] = {0};
686
687                 buf[0] = 0x0;   /* OP_Code */
688                 buf[1] = 0x0;   /* OP_Code_Length */
689                 BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
690 #endif /* !CONFIG_BT_COEXIST_SOCKET_TRX */
691         }
692
693 exit:
694         return pBtCoexist->btInfo.btRealFwVer;
695 }
696
697 s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
698 {
699         PHAL_DATA_TYPE pHalData;
700         s32 UndecoratedSmoothedPWDB = 0;
701
702         pHalData = GET_HAL_DATA(padapter);
703
704         UndecoratedSmoothedPWDB = pHalData->EntryMinUndecoratedSmoothedPWDB;
705
706         return UndecoratedSmoothedPWDB;
707 }
708
709 static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
710 {
711         struct mlme_priv *pmlmepriv;
712         struct mlme_ext_priv *pmlmeext;
713         static u8 scan_AP_num = 0;
714
715
716         pmlmepriv = &padapter->mlmepriv;
717         pmlmeext = &padapter->mlmeextpriv;
718
719         if (GLBtcWiFiInScanState == _FALSE) {
720                 if (pmlmepriv->num_of_scanned > 0xFF)
721                         scan_AP_num = 0xFF;
722                 else
723                         scan_AP_num = (u8)pmlmepriv->num_of_scanned;
724         }
725
726         return scan_AP_num;
727 }
728
729 u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
730 {
731         PBTC_COEXIST pBtCoexist;
732         PADAPTER padapter;
733         PHAL_DATA_TYPE pHalData;
734         struct mlme_ext_priv *mlmeext;
735         u8 bSoftApExist, bVwifiExist;
736         u8 *pu8;
737         s32 *pS4Tmp;
738         u32 *pU4Tmp;
739         u8 *pU1Tmp;
740         u8 ret;
741
742
743         pBtCoexist = (PBTC_COEXIST)pBtcContext;
744         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
745                 return _FALSE;
746
747         padapter = pBtCoexist->Adapter;
748         pHalData = GET_HAL_DATA(padapter);
749         mlmeext = &padapter->mlmeextpriv;
750         bSoftApExist = _FALSE;
751         bVwifiExist = _FALSE;
752         pu8 = (u8*)pOutBuf;
753         pS4Tmp = (s32*)pOutBuf;
754         pU4Tmp = (u32*)pOutBuf;
755         pU1Tmp = (u8*)pOutBuf;
756         ret = _TRUE;
757
758         switch (getType)
759         {
760                 case BTC_GET_BL_HS_OPERATION:
761                         *pu8 = _FALSE;
762                         ret = _FALSE;
763                         break;
764
765                 case BTC_GET_BL_HS_CONNECTING:
766                         *pu8 = _FALSE;
767                         ret = _FALSE;
768                         break;
769
770                 case BTC_GET_BL_WIFI_CONNECTED:
771                         *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE);
772 #ifdef CONFIG_CONCURRENT_MODE
773                         if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
774                         {
775                                 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_ASOC_STATE);
776                         }
777 #endif // CONFIG_CONCURRENT_MODE
778                         break;
779
780                 case BTC_GET_BL_WIFI_BUSY:
781                         *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
782                         break;
783
784                 case BTC_GET_BL_WIFI_SCAN:
785 #if 0                   
786                         *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_SITE_MONITOR);
787 #ifdef CONFIG_CONCURRENT_MODE
788                         if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
789                         {
790                                 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_SITE_MONITOR);
791                         }
792 #endif // CONFIG_CONCURRENT_MODE
793 #else           
794                         /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag 
795                                 WIFI_SITE_MONITOR in fwstate may not be cleared in time */
796                         *pu8 = GLBtcWiFiInScanState;
797 #endif
798                         break;
799
800                 case BTC_GET_BL_WIFI_LINK:
801                         *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
802 #ifdef CONFIG_CONCURRENT_MODE
803                         if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
804                         {
805                                 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_UNDER_LINKING);
806                         }
807 #endif // CONFIG_CONCURRENT_MODE
808                         break;
809
810                 case BTC_GET_BL_WIFI_ROAM:
811                         *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING);
812 #ifdef CONFIG_CONCURRENT_MODE
813                         if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
814                         {
815                                 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_UNDER_LINKING);
816                         }
817 #endif // CONFIG_CONCURRENT_MODE
818                         break;
819
820                 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
821                         *pu8 = _FALSE;
822                         break;
823
824                 case BTC_GET_BL_WIFI_UNDER_5G:
825                         *pu8 = (pHalData->CurrentBandType == 1)? _TRUE : _FALSE;
826                         break;
827
828                 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
829                         *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE);
830 #ifdef CONFIG_CONCURRENT_MODE
831                         if ((_FALSE == *pu8) && padapter->pbuddy_adapter)
832                         {
833                                 *pu8 = check_fwstate(&padapter->pbuddy_adapter->mlmepriv, WIFI_AP_STATE);
834                         }
835 #endif // CONFIG_CONCURRENT_MODE
836                         break;
837
838                 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
839                         *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0? _FALSE: _TRUE;
840                         break;
841
842                 case BTC_GET_BL_WIFI_UNDER_B_MODE:
843                         if (mlmeext->cur_wireless_mode == WIRELESS_11B)
844                                 *pu8 = _TRUE;
845                         else
846                                 *pu8 = _FALSE;
847                         break;
848
849                 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
850                         if (padapter->registrypriv.mp_mode == 0)
851                         {
852                                 *pu8 = _FALSE;
853                         }
854                         else
855                         {
856                                 *pu8 = _TRUE;
857                         }
858                         break;
859
860                 case BTC_GET_BL_EXT_SWITCH:
861                         *pu8 = _FALSE;
862                         break;
863                 case BTC_GET_BL_IS_ASUS_8723B:
864                         /* Always return FALSE in linux driver since this case is added only for windows driver */
865                         *pu8 = _FALSE;
866                         break;
867
868                 case BTC_GET_S4_WIFI_RSSI:
869                         *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
870                         break;
871
872                 case BTC_GET_S4_HS_RSSI:
873                         *pS4Tmp = 0;
874                         ret = _FALSE;
875                         break;
876
877                 case BTC_GET_U4_WIFI_BW:
878                         if (IsLegacyOnly(mlmeext->cur_wireless_mode))
879                                 *pU4Tmp = BTC_WIFI_BW_LEGACY;
880                         else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20)
881                                 *pU4Tmp = BTC_WIFI_BW_HT20;
882                         else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_40)
883                                 *pU4Tmp = BTC_WIFI_BW_HT40;
884                         else
885                                 *pU4Tmp = BTC_WIFI_BW_HT40; /* todo */
886                         break;
887
888                 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
889                         {
890                                 PRT_LINK_DETECT_T plinkinfo;
891                                 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
892
893                                 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
894                                         *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
895                                 else
896                                         *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
897                         }
898                         break;
899
900                 case BTC_GET_U4_WIFI_FW_VER:
901                         *pU4Tmp = pHalData->FirmwareVersion << 16;
902                         *pU4Tmp |= pHalData->FirmwareSubVersion;
903                         break;
904
905                 case BTC_GET_U4_WIFI_LINK_STATUS:
906                         *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
907                         break;
908
909                 case BTC_GET_U4_BT_PATCH_VER:
910                         *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
911                         break;
912
913                 case BTC_GET_U1_WIFI_DOT11_CHNL:
914                         *pU1Tmp = padapter->mlmeextpriv.cur_channel;
915                         break;
916
917                 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
918                         *pU1Tmp = pHalData->CurrentChannel;
919                         break;
920
921                 case BTC_GET_U1_WIFI_HS_CHNL:
922                         *pU1Tmp = 0;
923                         ret = _FALSE;
924                         break;
925
926                 case BTC_GET_U1_MAC_PHY_MODE:
927 //                      *pU1Tmp = BTC_SMSP;
928 //                      *pU1Tmp = BTC_DMSP;
929 //                      *pU1Tmp = BTC_DMDP;
930 //                      *pU1Tmp = BTC_MP_UNKNOWN;
931                         break;
932
933                 case BTC_GET_U1_AP_NUM:
934                         *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
935                         break;
936                 case BTC_GET_U1_ANT_TYPE:
937                         switch(pHalData->bt_coexist.btAntisolation)
938                         {
939                                 case 0:
940                                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_0;
941                                         pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_0;
942                                         break;
943                                 case 1:
944                                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_1;
945                                         pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_1;
946                                         break;
947                                 case 2:
948                                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_2;
949                                         pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_2;
950                                         break;
951                                 case 3:
952                                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_3;
953                                         pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_3;
954                                         break;
955                                 case 4:
956                                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_4;
957                                         pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_4;
958                                         break;
959                         }
960                         break;
961                 case BTC_GET_U1_IOT_PEER:
962                         *pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;
963                         break;
964
965                 //=======1Ant===========
966                 case BTC_GET_U1_LPS_MODE:
967                         *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
968                         break;
969
970                 default:
971                         ret = _FALSE;
972                         break;
973         }
974
975         return ret;
976 }
977
978 u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
979 {
980         PBTC_COEXIST pBtCoexist;
981         PADAPTER padapter;
982         PHAL_DATA_TYPE pHalData;
983         u8 *pu8;
984         u8 *pU1Tmp;
985         u32     *pU4Tmp;
986         u8 ret;
987
988
989         pBtCoexist = (PBTC_COEXIST)pBtcContext;
990         padapter = pBtCoexist->Adapter;
991         pHalData = GET_HAL_DATA(padapter);
992         pu8 = (u8*)pInBuf;
993         pU1Tmp = (u8*)pInBuf;
994         pU4Tmp = (u32*)pInBuf;
995         ret = _TRUE;
996
997         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
998                 return _FALSE;
999
1000         switch (setType)
1001         {
1002                 // set some u8 type variables.
1003                 case BTC_SET_BL_BT_DISABLE:
1004                         pBtCoexist->btInfo.bBtDisabled = *pu8;
1005                         break;
1006
1007                 case BTC_SET_BL_BT_TRAFFIC_BUSY:
1008                         pBtCoexist->btInfo.bBtBusy = *pu8;
1009                         break;
1010
1011                 case BTC_SET_BL_BT_LIMITED_DIG:
1012                         pBtCoexist->btInfo.bLimitedDig = *pu8;
1013                         break;
1014
1015                 case BTC_SET_BL_FORCE_TO_ROAM:
1016                         pBtCoexist->btInfo.bForceToRoam = *pu8;
1017                         break;
1018
1019                 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
1020                         pBtCoexist->btInfo.bRejectAggPkt = *pu8;
1021                         break;
1022
1023                 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
1024                         pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8;
1025                         break;
1026
1027                 case BTC_SET_BL_INC_SCAN_DEV_NUM:
1028                         pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8;
1029                         break;
1030
1031                 case BTC_SET_BL_BT_TX_RX_MASK:
1032                         pBtCoexist->btInfo.bBtTxRxMask = *pu8;
1033                         break;
1034
1035                 case BTC_SET_BL_MIRACAST_PLUS_BT:
1036                         pBtCoexist->btInfo.bMiracastPlusBt = *pu8;
1037                         break;
1038
1039                 // set some u8 type variables.
1040                 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
1041                         pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pU1Tmp;
1042                         break;
1043
1044                 case BTC_SET_U1_AGG_BUF_SIZE:
1045                         pBtCoexist->btInfo.aggBufSize = *pU1Tmp;
1046                         break;
1047
1048                 // the following are some action which will be triggered
1049                 case BTC_SET_ACT_GET_BT_RSSI:
1050 #if 0
1051                         BT_SendGetBtRssiEvent(padapter);
1052 #else
1053                         ret = _FALSE;
1054 #endif
1055                         break;
1056
1057                 case BTC_SET_ACT_AGGREGATE_CTRL:
1058                         halbtcoutsrc_AggregationCheck(pBtCoexist);
1059                         break;
1060
1061                 //=======1Ant===========
1062                 // set some u8 type variables.
1063                 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
1064                         pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pU1Tmp;
1065                         break;
1066
1067                 case BTC_SET_U1_LPS_VAL:
1068                         pBtCoexist->btInfo.lpsVal = *pU1Tmp;
1069                         break;
1070
1071                 case BTC_SET_U1_RPWM_VAL:
1072                         pBtCoexist->btInfo.rpwmVal = *pU1Tmp;
1073                         break;
1074
1075                 // the following are some action which will be triggered
1076                 case BTC_SET_ACT_LEAVE_LPS:
1077                         halbtcoutsrc_LeaveLps(pBtCoexist);
1078                         break;
1079
1080                 case BTC_SET_ACT_ENTER_LPS:
1081                         halbtcoutsrc_EnterLps(pBtCoexist);
1082                         break;
1083
1084                 case BTC_SET_ACT_NORMAL_LPS:
1085                         halbtcoutsrc_NormalLps(pBtCoexist);
1086                         break;
1087
1088                 case BTC_SET_ACT_DISABLE_LOW_POWER:
1089                         halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
1090                         break;
1091
1092                 case BTC_SET_ACT_UPDATE_RAMASK:
1093                         pBtCoexist->btInfo.raMask = *pU4Tmp;
1094
1095                         if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE)
1096                         {
1097                                 struct sta_info *psta;
1098                                 PWLAN_BSSID_EX cur_network;
1099
1100                                 cur_network = &padapter->mlmeextpriv.mlmext_info.network;
1101                                 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
1102                                 rtw_hal_update_ra_mask(psta, 0);
1103                         }
1104                         break;
1105
1106                 case BTC_SET_ACT_SEND_MIMO_PS:
1107                         {
1108                                 u8 newMimoPsMode = 3;
1109                                 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1110                                 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1111
1112                                 /* *pU1Tmp = 0 use SM_PS static type */
1113                                 /* *pU1Tmp = 1 disable SM_PS */
1114                                 if (*pU1Tmp == 0)
1115                                         newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
1116                                 else if (*pU1Tmp == 1)
1117                                         newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
1118                                                                                                   
1119                                 if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) {
1120                                         /* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */
1121                                         issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1);
1122                                 }
1123                         }
1124                         break;
1125
1126                 case BTC_SET_ACT_CTRL_BT_INFO:
1127 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1128                         {
1129                                 u8 dataLen = *pU1Tmp;
1130                                 u8 tmpBuf[20];
1131                                 if (dataLen)
1132                                 {
1133                                         _rtw_memcpy(tmpBuf, pU1Tmp+1, dataLen);
1134                                 }
1135                                 BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
1136                         }
1137 #else //!CONFIG_BT_COEXIST_SOCKET_TRX
1138                         ret = _FALSE;
1139 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
1140                         break;
1141
1142                 case BTC_SET_ACT_CTRL_BT_COEX:
1143 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1144                         {
1145                                 u8 dataLen = *pU1Tmp;
1146                                 u8 tmpBuf[20];
1147                                 if (dataLen)
1148                                 {
1149                                         _rtw_memcpy(tmpBuf, pU1Tmp+1, dataLen);
1150                                 }
1151                                 BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
1152                         }
1153 #else //!CONFIG_BT_COEXIST_SOCKET_TRX
1154                         ret = _FALSE;
1155 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
1156                         break;
1157                 case BTC_SET_ACT_CTRL_8723B_ANT:
1158 #if 0
1159                         {
1160                                 u1Byte  dataLen=*pU1Tmp;
1161                                 u1Byte  tmpBuf[20];
1162                                 if(dataLen)
1163                                 {
1164                                         PlatformMoveMemory(&tmpBuf[0], pU1Tmp+1, dataLen);
1165                                 }
1166                                 BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
1167                         }
1168 #else
1169                         ret = _FALSE;
1170 #endif
1171                         break;
1172                 //=====================
1173                 default:
1174                         ret = _FALSE;
1175                         break;
1176         }
1177
1178         return ret;
1179 }
1180
1181 u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
1182 {
1183         PADAPTER padapter;
1184         struct pwrctrl_priv *pwrpriv;
1185         u8 bMacPwrCtrlOn;
1186
1187         padapter = pBtCoexist->Adapter;
1188         pwrpriv = &padapter->dvobj->pwrctl_priv;
1189         bMacPwrCtrlOn = _FALSE;
1190
1191         if ((_TRUE == pwrpriv->bips_processing)
1192                 && (IPS_NONE != pwrpriv->ips_mode_req)
1193                 )
1194         {
1195                 return _TRUE;
1196         }
1197
1198         if (rf_off == pwrpriv->rf_pwrstate)
1199         {
1200                 return _TRUE;
1201         }
1202
1203         rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
1204         if (_FALSE == bMacPwrCtrlOn)
1205         {
1206                 return _TRUE;
1207         }
1208
1209         return _FALSE;
1210 }
1211
1212 u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
1213 {
1214         return GLBtcWiFiInLPS;
1215 }
1216
1217 u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
1218 {
1219         /* todo: the method to check whether wifi is under 32K or not */
1220         return _FALSE;
1221 }
1222
1223 void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
1224 {
1225 #if 0
1226         PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1227         PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1228         PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
1229         u8 *cliBuf = pBtCoexist->cliBuf;
1230         u8 i;
1231
1232         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
1233         CL_PRINTF(cliBuf);
1234
1235 #if (H2C_USE_IO_THREAD != 1)
1236         for(i=0; i<H2C_STATUS_MAX; i++)
1237         {
1238                 if (pHalData->h2cStatistics[i])
1239                 {
1240                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1241                                 h2cStaString[i], pHalData->h2cStatistics[i]);
1242                         CL_PRINTF(cliBuf);
1243                 }
1244         }
1245 #else
1246                 for(i=0; i<IO_STATUS_MAX; i++)
1247                 {
1248                         if(Adapter->ioComStr.ioH2cStatistics[i])
1249                         {
1250                                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1251                                         ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);
1252                                 CL_PRINTF(cliBuf);
1253                         }
1254                 }
1255 #endif
1256 #if 0
1257         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
1258                 pHalData->LastHMEBoxNum);
1259         CL_PRINTF(cliBuf);
1260         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
1261                 pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
1262         CL_PRINTF(cliBuf);
1263
1264         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \
1265                 pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,
1266                 DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);
1267         CL_PRINTF(cliBuf);
1268
1269         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
1270                 DBG_Var.c2hPacketCnt);
1271         CL_PRINTF(cliBuf);
1272 #endif
1273         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
1274                 pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
1275         CL_PRINTF(cliBuf);
1276         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \
1277                 pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,
1278                 pBtCoexist->statistics.cntRfStatusNotify);
1279         CL_PRINTF(cliBuf);
1280         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \
1281                 pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,
1282                 pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,
1283                 pBtCoexist->statistics.cntMediaStatusNotify);
1284         CL_PRINTF(cliBuf);
1285         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind", 
1286                 pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify,
1287                 pBtCoexist->statistics.cntBind);
1288         CL_PRINTF(cliBuf);
1289 #endif
1290 }
1291
1292 void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
1293 {
1294 #if 0
1295         PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1296         PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1297         u8 *cliBuf = pBtCoexist->cliBuf;
1298         u8 i;
1299
1300
1301         if (pBtCoexist->stackInfo.bProfileNotified)
1302         {
1303                 for (i=0; i<pBtMgnt->ExtConfig.NumberOfACL; i++)
1304                 {
1305                         if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1)
1306                         {
1307                                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \
1308                                         BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1309                                         BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],
1310                                         BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);
1311                                 CL_PRINTF(cliBuf);                              }
1312                         else
1313                         {
1314                                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
1315                                         BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1316                                         BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);
1317                                 CL_PRINTF(cliBuf);
1318                         }
1319                 }
1320         }
1321 #endif
1322 }
1323
1324 void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
1325 {
1326         PADAPTER        padapter = pBtCoexist->Adapter;
1327         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1328         u8*                     cliBuf=pBtCoexist->cliBuf;
1329         s32                     wifiRssi=0, btHsRssi=0;
1330         BOOLEAN bScan=_FALSE, bLink=_FALSE, bRoam=_FALSE, bWifiBusy=_FALSE, bWifiUnderBMode=_FALSE;
1331         u32                     wifiBw=BTC_WIFI_BW_HT20, wifiTrafficDir=BTC_WIFI_TRAFFIC_TX, wifiFreq=BTC_FREQ_2_4G;
1332         u32                     wifiLinkStatus=0x0;
1333         BOOLEAN bBtHsOn=_FALSE, bLowPower=_FALSE;
1334         u8                      wifiChnl=0, wifiHsChnl=0, nScanAPNum = 0, FwPSState;
1335
1336         wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
1337         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc", \
1338                 ((wifiLinkStatus&WIFI_STA_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_AP_CONNECTED)? 1:0), 
1339                 ((wifiLinkStatus&WIFI_HS_CONNECTED)? 1:0), ((wifiLinkStatus&WIFI_P2P_GO_CONNECTED)? 1:0), 
1340                 ((wifiLinkStatus&WIFI_P2P_GC_CONNECTED)? 1:0) );
1341         CL_PRINTF(cliBuf);
1342
1343         if (wifiLinkStatus&WIFI_STA_CONNECTED) {
1344                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "IOT Peer", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor]);
1345                 CL_PRINTF(cliBuf);
1346         }
1347
1348         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1349         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiChnl);
1350         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl);  CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(High Speed)", \
1351                 wifiChnl, wifiHsChnl, bBtHsOn);
1352         CL_PRINTF(cliBuf);
1353
1354         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
1355         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);
1356         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \
1357                 wifiRssi-100, btHsRssi-100);
1358         CL_PRINTF(cliBuf);
1359
1360
1361         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1362         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1363         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1364         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \
1365                 bLink, bRoam, bScan);
1366         CL_PRINTF(cliBuf);
1367
1368         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifiFreq);
1369         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1370         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1371         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1372         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
1373         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);
1374         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ AP=%d ", "Wifi freq/ bw/ traffic", \
1375                 GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode)? "11b": GLBtcWifiBwString[wifiBw]),
1376                 ((!bWifiBusy)? "idle": ((BTC_WIFI_TRAFFIC_TX==wifiTrafficDir)? "uplink":"downlink")), 
1377                 nScanAPNum);
1378         CL_PRINTF(cliBuf);
1379
1380         // power status
1381         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \
1382                 ((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE)? "IPS ON":"IPS OFF"),
1383                 ((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE)? ", LPS ON":", LPS OFF"), 
1384                 ((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE)? ", 32k":""));
1385         CL_PRINTF(cliBuf);
1386
1387         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)", "Power mode cmd(lps/rpwm)", \
1388                 pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
1389                 pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
1390                 pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],
1391                 pBtCoexist->btInfo.lpsVal, 
1392                 pBtCoexist->btInfo.rpwmVal);
1393         CL_PRINTF(cliBuf);
1394 }
1395
1396 void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
1397 {
1398         PBTC_COEXIST pBtCoexist;
1399
1400
1401         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1402         switch(dispType)
1403         {
1404                 case BTC_DBG_DISP_COEX_STATISTICS:
1405                         halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
1406                         break;
1407                 case BTC_DBG_DISP_BT_LINK_INFO:
1408                         halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
1409                         break;
1410                 case BTC_DBG_DISP_WIFI_STATUS:
1411                         halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
1412                         break;
1413                 default:
1414                         break;
1415         }
1416 }
1417
1418 //====================================
1419 //              IO related function
1420 //====================================
1421 u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
1422 {
1423         PBTC_COEXIST pBtCoexist;
1424         PADAPTER padapter;
1425
1426
1427         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1428         padapter = pBtCoexist->Adapter;
1429
1430         return rtw_read8(padapter, RegAddr);
1431 }
1432
1433 u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
1434 {
1435         PBTC_COEXIST pBtCoexist;
1436         PADAPTER padapter;
1437
1438
1439         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1440         padapter = pBtCoexist->Adapter;
1441
1442         return  rtw_read16(padapter, RegAddr);
1443 }
1444
1445 u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
1446 {
1447         PBTC_COEXIST pBtCoexist;
1448         PADAPTER padapter;
1449
1450
1451         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1452         padapter = pBtCoexist->Adapter;
1453
1454         return  rtw_read32(padapter, RegAddr);
1455 }
1456
1457 void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1458 {
1459         PBTC_COEXIST pBtCoexist;
1460         PADAPTER padapter;
1461
1462
1463         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1464         padapter = pBtCoexist->Adapter;
1465
1466         rtw_write8(padapter, RegAddr, Data);
1467 }
1468
1469 void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
1470 {
1471         PBTC_COEXIST pBtCoexist;
1472         PADAPTER padapter;
1473         u8 originalValue, bitShift;
1474         u8 i;
1475
1476
1477         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1478         padapter = pBtCoexist->Adapter;
1479         originalValue = 0;
1480         bitShift = 0;
1481
1482         if(bitMask != 0xff)
1483         {
1484                 originalValue = rtw_read8(padapter, regAddr);
1485
1486                 for (i=0; i<=7; i++)
1487                 {
1488                         if ((bitMask>>i)&0x1)
1489                                 break;
1490                 }
1491                 bitShift = i;
1492
1493                 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
1494         }
1495
1496         rtw_write8(padapter, regAddr, data1b);
1497 }
1498
1499 void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
1500 {
1501         PBTC_COEXIST pBtCoexist;
1502         PADAPTER padapter;
1503
1504
1505         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1506         padapter = pBtCoexist->Adapter;
1507
1508         rtw_write16(padapter, RegAddr, Data);
1509 }
1510
1511 void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
1512 {
1513         PBTC_COEXIST pBtCoexist;
1514         PADAPTER padapter;
1515
1516
1517         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1518         padapter = pBtCoexist->Adapter;
1519
1520         rtw_write32(padapter, RegAddr, Data);
1521 }
1522
1523 void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1524 {
1525         PBTC_COEXIST            pBtCoexist=(PBTC_COEXIST)pBtcContext;
1526         PADAPTER                        Adapter=pBtCoexist->Adapter;
1527
1528         if(BTC_INTF_SDIO == pBtCoexist->chipInterface)
1529         {
1530                 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
1531         }
1532         else
1533         {
1534                 rtw_write8(Adapter, RegAddr, Data);
1535         }
1536 }
1537
1538 void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
1539 {
1540         PBTC_COEXIST pBtCoexist;
1541         PADAPTER padapter;
1542
1543
1544         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1545         padapter = pBtCoexist->Adapter;
1546
1547         PHY_SetBBReg(padapter, RegAddr, BitMask, Data);
1548 }
1549
1550
1551 u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
1552 {
1553         PBTC_COEXIST pBtCoexist;
1554         PADAPTER padapter;
1555
1556
1557         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1558         padapter = pBtCoexist->Adapter;
1559
1560         return PHY_QueryBBReg(padapter, RegAddr, BitMask);
1561 }
1562
1563 void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
1564 {
1565         PBTC_COEXIST pBtCoexist;
1566         PADAPTER padapter;
1567
1568
1569         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1570         padapter = pBtCoexist->Adapter;
1571
1572         PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data);
1573 }
1574
1575 u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
1576 {
1577         PBTC_COEXIST pBtCoexist;
1578         PADAPTER padapter;
1579
1580
1581         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1582         padapter = pBtCoexist->Adapter;
1583
1584         return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask);
1585 }
1586
1587 u16 halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
1588 {
1589         PBTC_COEXIST pBtCoexist;
1590         u16 ret = BT_STATUS_BT_OP_SUCCESS;
1591
1592         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1593
1594         if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1595                 u8 buf[3] = {0};
1596                 _irqL irqL;
1597                 u8 op_code;
1598                 u8 status;
1599
1600                 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1601
1602                 Data = cpu_to_le32(Data);
1603                 op_code = BT_OP_WRITE_REG_VALUE;
1604                 status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Data, 3);
1605                 if (status != BT_STATUS_BT_OP_SUCCESS)
1606                         ret = SET_BT_MP_OPER_RET(op_code, status);
1607                 else {
1608                         buf[0] = RegType;
1609                         *(u16 *)(buf+1) = cpu_to_le16((u16)RegAddr);
1610                         op_code = BT_OP_WRITE_REG_ADDR;
1611                         status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
1612                         if (status != BT_STATUS_BT_OP_SUCCESS)
1613                                 ret = SET_BT_MP_OPER_RET(op_code, status);
1614                 }
1615
1616                 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1617         } else
1618                 ret = BT_STATUS_NOT_IMPLEMENT;
1619
1620         return ret;
1621 }
1622
1623 u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)
1624 {
1625 /* Always return _FALSE since we don't implement this yet */    
1626 #if 0   
1627         PBTC_COEXIST            pBtCoexist = (PBTC_COEXIST)pBtcContext;
1628         PADAPTER                        Adapter = pBtCoexist->Adapter;
1629         u1Byte                          btCanTx = 0;
1630         BOOLEAN                 bStatus = FALSE;
1631
1632         bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);
1633         if (bStatus && btCanTx)
1634                 return _TRUE;
1635         else
1636                 return _FALSE;
1637 #else
1638         return _FALSE;
1639 #endif
1640 }
1641
1642 u16 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 *data)
1643 {
1644         PBTC_COEXIST pBtCoexist;
1645         u16 ret = BT_STATUS_BT_OP_SUCCESS;
1646
1647         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1648
1649         if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1650                 u8 buf[3] = {0};
1651                 _irqL irqL;
1652                 u8 op_code;
1653                 u8 status;
1654
1655                 buf[0] = RegType;
1656                 *(u16 *)(buf+1) = cpu_to_le16((u16)RegAddr);
1657
1658                 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1659
1660                 op_code = BT_OP_READ_REG;
1661                 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
1662                 if (status == BT_STATUS_BT_OP_SUCCESS)
1663                         *data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
1664                 else
1665                         ret = SET_BT_MP_OPER_RET(op_code, status);
1666
1667                 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1668
1669         } else
1670                 ret = BT_STATUS_NOT_IMPLEMENT;
1671
1672         return ret;
1673 }
1674
1675 void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
1676 {
1677         PBTC_COEXIST pBtCoexist;
1678         PADAPTER padapter;
1679
1680
1681         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1682         padapter = pBtCoexist->Adapter;
1683
1684         rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
1685 }
1686
1687 //====================================
1688 //              Extern functions called by other module
1689 //====================================
1690 u8 EXhalbtcoutsrc_IsTfbgaPackageType(PADAPTER padapter)
1691 {
1692         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(padapter);
1693
1694 #ifdef CONFIG_RTL8723B
1695         if ((pHalData->PackageType == PACKAGE_TFBGA79) || (pHalData->PackageType == PACKAGE_TFBGA80)
1696                 || (pHalData->PackageType == PACKAGE_TFBGA90)) {
1697                 return _TRUE;
1698         }               
1699 #endif
1700
1701         return _FALSE;
1702 }
1703
1704 u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
1705 {
1706         PBTC_COEXIST            pBtCoexist=&GLBtCoexist;
1707         u1Byte  antNum=2, chipType;
1708         
1709         if(pBtCoexist->bBinded)
1710                 return _FALSE;
1711         else
1712                 pBtCoexist->bBinded = _TRUE;
1713
1714         pBtCoexist->statistics.cntBind++;
1715         
1716         pBtCoexist->Adapter = padapter;
1717         
1718         pBtCoexist->stackInfo.bProfileNotified = _FALSE;
1719
1720         pBtCoexist->btInfo.bBtCtrlAggBufSize = _FALSE;
1721         pBtCoexist->btInfo.aggBufSize = 5;
1722
1723         pBtCoexist->btInfo.bIncreaseScanDevNum = _FALSE;
1724         pBtCoexist->btInfo.bMiracastPlusBt = _FALSE;
1725
1726 #if 0
1727         chipType = HALBT_GetBtChipType(Adapter);
1728         EXhalbtcoutsrc_SetChipType(chipType);
1729         antNum = HALBT_GetPgAntNum(Adapter);
1730         EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
1731 #endif
1732         // set default antenna position to main  port
1733         pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;    
1734
1735         pBtCoexist->boardInfo.btdmAntDetFinish = _FALSE;
1736         pBtCoexist->boardInfo.btdmAntNumByAntDet = 1;
1737
1738         pBtCoexist->boardInfo.bTfbgaPackage = EXhalbtcoutsrc_IsTfbgaPackageType((PADAPTER)padapter);
1739
1740         if (pBtCoexist->boardInfo.bTfbgaPackage)
1741                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Package Type = TFBGA\n"));
1742         else
1743                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Package Type = Non-TFBGA\n"));
1744         
1745         return _TRUE;
1746 }
1747
1748 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
1749 {
1750         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
1751
1752         //pBtCoexist->statistics.cntBind++;
1753
1754         halbtcoutsrc_DbgInit();
1755
1756 #ifdef CONFIG_PCI_HCI
1757         pBtCoexist->chipInterface = BTC_INTF_PCI;
1758 #elif defined(CONFIG_USB_HCI)
1759         pBtCoexist->chipInterface = BTC_INTF_USB;
1760 #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
1761         pBtCoexist->chipInterface = BTC_INTF_SDIO;
1762 #else
1763         pBtCoexist->chipInterface = BTC_INTF_UNKNOWN;
1764 #endif
1765
1766         EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
1767
1768         pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte;
1769         pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte;
1770         pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte;
1771         pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte;
1772         pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte;
1773         pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte;
1774         pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte;
1775         pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte;
1776
1777         pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg;
1778         pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg;
1779
1780         pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg;
1781         pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg;
1782
1783         pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd;
1784         pBtCoexist->fBtcDispDbgMsg = halbtcoutsrc_DisplayDbgMsg;
1785
1786         pBtCoexist->fBtcGet = halbtcoutsrc_Get;
1787         pBtCoexist->fBtcSet = halbtcoutsrc_Set;
1788         pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg;
1789         pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg;
1790         pBtCoexist->fBtcSetBtAntDetection = halbtcoutsrc_SetBtAntDetection;
1791
1792         pBtCoexist->cliBuf = &GLBtcDbgBuf[0];
1793
1794         pBtCoexist->boardInfo.singleAntPath = 0;
1795         
1796         GLBtcWiFiInScanState = _FALSE;
1797
1798         GLBtcWiFiInIQKState = _FALSE;
1799
1800         GLBtcWiFiInIPS = _FALSE;
1801
1802         GLBtcWiFiInLPS = _FALSE;
1803
1804         GLBtcBtCoexAliveRegistered = _FALSE;
1805
1806         /* BT Control H2C/C2H*/
1807         GLBtcBtMpOperSeq = 0;
1808         _rtw_mutex_init(&GLBtcBtMpOperLock);
1809         _init_timer(&GLBtcBtMpOperTimer, ((PADAPTER)padapter)->pnetdev, _btmpoper_timer_hdl, pBtCoexist);
1810         _rtw_init_sema(&GLBtcBtMpRptSema, 0);
1811         GLBtcBtMpRptSeq = 0;
1812         GLBtcBtMpRptStatus = 0;
1813         _rtw_memset(GLBtcBtMpRptRsp, 0, C2H_MAX_SIZE);
1814         GLBtcBtMpRptRspSize = 0;
1815         GLBtcBtMpRptWait = 0;
1816         GLBtcBtMpRptWiFiOK = 0;
1817         GLBtcBtMpRptBTOK = 0;
1818
1819         return _TRUE;
1820 }
1821
1822 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
1823 {
1824         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1825                 return;
1826
1827         /* Power on setting function is only added in 8723B currently */
1828         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1829         {
1830                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1831                         EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist);
1832                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1833                         EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist);
1834         }
1835 }
1836
1837 void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)
1838 {
1839         if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1840                 return;
1841         
1842         pBtCoexist->statistics.cntPreLoadFirmware++;
1843
1844         if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1845         {
1846                 if(pBtCoexist->boardInfo.btdmAntNum == 2)
1847                         EXhalbtc8723b2ant_PreLoadFirmware(pBtCoexist);
1848                 else if(pBtCoexist->boardInfo.btdmAntNum == 1)
1849                         EXhalbtc8723b1ant_PreLoadFirmware(pBtCoexist);
1850         }
1851 }
1852
1853 void EXhalbtcoutsrc_InitHwConfig(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
1854 {
1855         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1856                 return;
1857
1858         pBtCoexist->statistics.cntInitHwConfig++;
1859
1860         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1861         {
1862                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1863                         EXhalbtc8821aCsr2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1864                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1865                         EXhalbtc8821a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1866                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1867                         EXhalbtc8821a1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1868         }
1869         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1870         {
1871                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1872                         EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1873                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1874                         EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1875         }
1876         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1877         {
1878                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1879                         EXhalbtc8703b2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1880                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1881                         EXhalbtc8703b1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1882         }
1883         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1884         {
1885                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1886                         EXhalbtc8192e2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1887                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1888                         EXhalbtc8192e1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1889         }
1890         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1891         {
1892                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1893                         EXhalbtc8812a2ant_InitHwConfig(pBtCoexist, bWifiOnly);
1894                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1895                         EXhalbtc8812a1ant_InitHwConfig(pBtCoexist, bWifiOnly);
1896         }
1897 }
1898
1899 void EXhalbtcoutsrc_InitCoexDm(PBTC_COEXIST pBtCoexist)
1900 {
1901         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1902                 return;
1903
1904         pBtCoexist->statistics.cntInitCoexDm++;
1905
1906         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1907         {
1908                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1909                         EXhalbtc8821aCsr2ant_InitCoexDm(pBtCoexist);
1910                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1911                         EXhalbtc8821a2ant_InitCoexDm(pBtCoexist);
1912                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1913                         EXhalbtc8821a1ant_InitCoexDm(pBtCoexist);
1914         }
1915         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1916         {
1917                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1918                         EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
1919                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1920                         EXhalbtc8723b1ant_InitCoexDm(pBtCoexist);
1921         }
1922         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1923         {
1924                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1925                         EXhalbtc8703b2ant_InitCoexDm(pBtCoexist);
1926                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1927                         EXhalbtc8703b1ant_InitCoexDm(pBtCoexist);
1928         }
1929         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1930         {
1931                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1932                         EXhalbtc8192e2ant_InitCoexDm(pBtCoexist);
1933                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1934                         EXhalbtc8192e1ant_InitCoexDm(pBtCoexist);
1935         }
1936         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
1937         {
1938                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1939                         EXhalbtc8812a2ant_InitCoexDm(pBtCoexist);
1940                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1941                         EXhalbtc8812a1ant_InitCoexDm(pBtCoexist);
1942         }
1943
1944         pBtCoexist->bInitilized = _TRUE;
1945 }
1946
1947 void EXhalbtcoutsrc_IpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
1948 {
1949         u8      ipsType;
1950
1951         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1952                 return;
1953
1954         pBtCoexist->statistics.cntIpsNotify++;
1955         if (pBtCoexist->bManualControl)
1956                 return;
1957
1958         if (IPS_NONE == type)
1959         {
1960                 ipsType = BTC_IPS_LEAVE;
1961                 GLBtcWiFiInIPS = _FALSE;
1962         }
1963         else
1964         {
1965                 ipsType = BTC_IPS_ENTER;
1966                 GLBtcWiFiInIPS = _TRUE;
1967         }
1968         
1969         // All notify is called in cmd thread, don't need to leave low power again
1970 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
1971
1972         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
1973         {
1974                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
1975                         EXhalbtc8821aCsr2ant_IpsNotify(pBtCoexist, ipsType);
1976                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
1977                         EXhalbtc8821a2ant_IpsNotify(pBtCoexist, ipsType);
1978                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1979                         EXhalbtc8821a1ant_IpsNotify(pBtCoexist, ipsType);
1980         }
1981         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1982         {
1983                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1984                         EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType);
1985                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1986                         EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType);
1987         }
1988         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
1989         {
1990                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1991                         EXhalbtc8703b2ant_IpsNotify(pBtCoexist, ipsType);
1992                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
1993                         EXhalbtc8703b1ant_IpsNotify(pBtCoexist, ipsType);
1994         }
1995         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
1996         {
1997                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
1998                         EXhalbtc8192e2ant_IpsNotify(pBtCoexist, ipsType);
1999                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2000                         EXhalbtc8192e1ant_IpsNotify(pBtCoexist, ipsType);
2001         }
2002         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2003         {
2004                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2005                         EXhalbtc8812a2ant_IpsNotify(pBtCoexist, ipsType);
2006                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2007                         EXhalbtc8812a1ant_IpsNotify(pBtCoexist, ipsType);
2008         }
2009
2010 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2011 }
2012
2013 void EXhalbtcoutsrc_LpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
2014 {
2015         u8 lpsType;
2016
2017
2018         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2019                 return;
2020
2021         pBtCoexist->statistics.cntLpsNotify++;
2022         if (pBtCoexist->bManualControl)
2023                 return;
2024
2025         if (PS_MODE_ACTIVE == type)
2026         {
2027                 lpsType = BTC_LPS_DISABLE;
2028                 GLBtcWiFiInLPS = _FALSE;
2029         }
2030         else
2031         {
2032                 lpsType = BTC_LPS_ENABLE;
2033                 GLBtcWiFiInLPS = _TRUE;
2034         }
2035         
2036         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2037         {
2038                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2039                         EXhalbtc8821aCsr2ant_LpsNotify(pBtCoexist, lpsType);
2040                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2041                         EXhalbtc8821a2ant_LpsNotify(pBtCoexist, lpsType);
2042                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2043                         EXhalbtc8821a1ant_LpsNotify(pBtCoexist, lpsType);
2044         }
2045         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2046         {
2047                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2048                         EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType);
2049                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2050                         EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType);
2051         }
2052         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2053         {
2054                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2055                         EXhalbtc8703b2ant_LpsNotify(pBtCoexist, lpsType);
2056                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2057                         EXhalbtc8703b1ant_LpsNotify(pBtCoexist, lpsType);
2058         }
2059         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2060         {
2061                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2062                         EXhalbtc8192e2ant_LpsNotify(pBtCoexist, lpsType);
2063                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2064                         EXhalbtc8192e1ant_LpsNotify(pBtCoexist, lpsType);
2065         }
2066         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2067         {
2068                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2069                         EXhalbtc8812a2ant_LpsNotify(pBtCoexist, lpsType);
2070                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2071                         EXhalbtc8812a1ant_LpsNotify(pBtCoexist, lpsType);
2072         }
2073 }
2074
2075 void EXhalbtcoutsrc_ScanNotify(PBTC_COEXIST pBtCoexist, u8 type)
2076 {
2077         u8      scanType;
2078
2079         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2080                 return;
2081         pBtCoexist->statistics.cntScanNotify++;
2082         if (pBtCoexist->bManualControl)
2083                 return;
2084
2085         if (type)
2086         {
2087                 scanType = BTC_SCAN_START;
2088                 GLBtcWiFiInScanState = _TRUE;
2089         }
2090         else
2091         {
2092                 scanType = BTC_SCAN_FINISH;
2093                 GLBtcWiFiInScanState = _FALSE;
2094         }
2095
2096         // All notify is called in cmd thread, don't need to leave low power again
2097 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2098
2099         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2100         {
2101                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2102                         EXhalbtc8821aCsr2ant_ScanNotify(pBtCoexist, scanType);
2103                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2104                         EXhalbtc8821a2ant_ScanNotify(pBtCoexist, scanType);
2105                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2106                         EXhalbtc8821a1ant_ScanNotify(pBtCoexist, scanType);
2107         }
2108         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2109         {
2110                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2111                         EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType);
2112                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2113                         EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType);
2114         }
2115         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2116         {
2117                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2118                         EXhalbtc8703b2ant_ScanNotify(pBtCoexist, scanType);
2119                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2120                         EXhalbtc8703b1ant_ScanNotify(pBtCoexist, scanType);
2121         }
2122         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2123         {
2124                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2125                         EXhalbtc8192e2ant_ScanNotify(pBtCoexist, scanType);
2126                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2127                         EXhalbtc8192e1ant_ScanNotify(pBtCoexist, scanType);
2128         }
2129         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2130         {
2131                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2132                         EXhalbtc8812a2ant_ScanNotify(pBtCoexist, scanType);
2133                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2134                         EXhalbtc8812a1ant_ScanNotify(pBtCoexist, scanType);
2135         }
2136
2137 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2138 }
2139
2140 void EXhalbtcoutsrc_ConnectNotify(PBTC_COEXIST pBtCoexist, u8 action)
2141 {
2142         u8      assoType;
2143
2144         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2145                 return;
2146         pBtCoexist->statistics.cntConnectNotify++;
2147         if (pBtCoexist->bManualControl)
2148                 return;
2149
2150         if (action)
2151                 assoType = BTC_ASSOCIATE_START;
2152         else
2153                 assoType = BTC_ASSOCIATE_FINISH;
2154
2155         // All notify is called in cmd thread, don't need to leave low power again
2156 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2157
2158         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2159         {
2160                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2161                         EXhalbtc8821aCsr2ant_ConnectNotify(pBtCoexist, assoType);
2162                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2163                         EXhalbtc8821a2ant_ConnectNotify(pBtCoexist, assoType);
2164                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2165                         EXhalbtc8821a1ant_ConnectNotify(pBtCoexist, assoType);
2166         }
2167         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2168         {
2169                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2170                         EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType);
2171                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2172                         EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType);
2173         }
2174         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2175         {
2176                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2177                         EXhalbtc8703b2ant_ConnectNotify(pBtCoexist, assoType);
2178                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2179                         EXhalbtc8703b1ant_ConnectNotify(pBtCoexist, assoType);
2180         }
2181         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2182         {
2183                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2184                         EXhalbtc8192e2ant_ConnectNotify(pBtCoexist, assoType);
2185                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2186                         EXhalbtc8192e1ant_ConnectNotify(pBtCoexist, assoType);
2187         }
2188         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2189         {
2190                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2191                         EXhalbtc8812a2ant_ConnectNotify(pBtCoexist, assoType);
2192                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2193                         EXhalbtc8812a1ant_ConnectNotify(pBtCoexist, assoType);
2194         }
2195
2196 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2197 }
2198
2199 void EXhalbtcoutsrc_MediaStatusNotify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
2200 {
2201         u8 mStatus;
2202
2203         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2204                 return;
2205
2206         pBtCoexist->statistics.cntMediaStatusNotify++;
2207         if (pBtCoexist->bManualControl)
2208                 return;
2209
2210         if (RT_MEDIA_CONNECT == mediaStatus)
2211                 mStatus = BTC_MEDIA_CONNECT;
2212         else
2213                 mStatus = BTC_MEDIA_DISCONNECT;
2214
2215         // All notify is called in cmd thread, don't need to leave low power again
2216 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2217
2218         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2219         {
2220                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2221                         EXhalbtc8821aCsr2ant_MediaStatusNotify(pBtCoexist, mStatus);
2222                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2223                         EXhalbtc8821a2ant_MediaStatusNotify(pBtCoexist, mStatus);
2224                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2225                         EXhalbtc8821a1ant_MediaStatusNotify(pBtCoexist, mStatus);
2226         }
2227         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2228         {
2229                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2230                         EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus);
2231                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2232                         EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus);
2233         }
2234         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2235         {
2236                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2237                         EXhalbtc8703b2ant_MediaStatusNotify(pBtCoexist, mStatus);
2238                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2239                         EXhalbtc8703b1ant_MediaStatusNotify(pBtCoexist, mStatus);
2240         }
2241         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2242         {
2243                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2244                         EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, mStatus);
2245                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2246                         EXhalbtc8192e1ant_MediaStatusNotify(pBtCoexist, mStatus);
2247         }
2248         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2249         {
2250                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2251                         EXhalbtc8812a2ant_MediaStatusNotify(pBtCoexist, mStatus);
2252                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2253                         EXhalbtc8812a1ant_MediaStatusNotify(pBtCoexist, mStatus);
2254         }
2255
2256 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2257 }
2258
2259 void EXhalbtcoutsrc_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 pktType)
2260 {
2261         u8      packetType;
2262
2263         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2264                 return;
2265         pBtCoexist->statistics.cntSpecialPacketNotify++;
2266         if (pBtCoexist->bManualControl)
2267                 return;
2268
2269         if (PACKET_DHCP == pktType)
2270                 packetType = BTC_PACKET_DHCP;
2271         else if (PACKET_EAPOL == pktType)
2272                 packetType = BTC_PACKET_EAPOL;
2273         else if (PACKET_ARP == pktType)
2274                 packetType = BTC_PACKET_ARP;
2275         else
2276         {
2277                 packetType = BTC_PACKET_UNKNOWN;
2278                 return;
2279         }
2280
2281         // All notify is called in cmd thread, don't need to leave low power again
2282 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2283
2284         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2285         {
2286                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2287                         EXhalbtc8821aCsr2ant_SpecialPacketNotify(pBtCoexist, packetType);
2288                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2289                         EXhalbtc8821a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2290                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2291                         EXhalbtc8821a1ant_SpecialPacketNotify(pBtCoexist, packetType);
2292         }
2293         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2294         {
2295                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2296                         EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType);
2297                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2298                         EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType);
2299         }
2300         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2301         {
2302                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2303                         EXhalbtc8703b2ant_SpecialPacketNotify(pBtCoexist, packetType);
2304                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2305                         EXhalbtc8703b1ant_SpecialPacketNotify(pBtCoexist, packetType);
2306         }
2307         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2308         {
2309                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2310                         EXhalbtc8192e2ant_SpecialPacketNotify(pBtCoexist, packetType);
2311                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2312                         EXhalbtc8192e1ant_SpecialPacketNotify(pBtCoexist, packetType);
2313         }
2314         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2315         {
2316                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2317                         EXhalbtc8812a2ant_SpecialPacketNotify(pBtCoexist, packetType);
2318                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2319                         EXhalbtc8812a1ant_SpecialPacketNotify(pBtCoexist, packetType);
2320         }
2321
2322 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2323 }
2324
2325 void EXhalbtcoutsrc_BtInfoNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
2326 {
2327         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2328                 return;
2329
2330         pBtCoexist->statistics.cntBtInfoNotify++;
2331
2332         // All notify is called in cmd thread, don't need to leave low power again
2333 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2334
2335         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2336         {
2337                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2338                         EXhalbtc8821aCsr2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2339                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2340                         EXhalbtc8821a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2341                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2342                         EXhalbtc8821a1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2343         }
2344         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2345         {
2346                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2347                         EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2348                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2349                         EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2350         }
2351         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2352         {
2353                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2354                         EXhalbtc8703b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2355                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2356                         EXhalbtc8703b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2357         }
2358         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2359         {
2360                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2361                         EXhalbtc8192e2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2362                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2363                         EXhalbtc8192e1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2364         }
2365         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2366         {
2367                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2368                         EXhalbtc8812a2ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2369                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2370                         EXhalbtc8812a1ant_BtInfoNotify(pBtCoexist, tmpBuf, length);
2371         }
2372
2373 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2374 }
2375
2376 VOID
2377 EXhalbtcoutsrc_RfStatusNotify(
2378         IN      PBTC_COEXIST            pBtCoexist,
2379         IN      u1Byte                          type
2380         )
2381 {
2382         if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2383                 return;
2384         pBtCoexist->statistics.cntRfStatusNotify++;
2385         
2386         if(IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2387         {
2388         }
2389         else if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2390         {
2391                 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2392                         EXhalbtc8723b1ant_RfStatusNotify(pBtCoexist, type);
2393         }       
2394         else if(IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2395         {
2396                 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2397                         EXhalbtc8703b1ant_RfStatusNotify(pBtCoexist, type);
2398         }       
2399         else if(IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2400         {
2401         }
2402         else if(IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2403         {
2404         }
2405 }
2406
2407 void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)
2408 {
2409 #if 0
2410         u8      stackOpType;
2411
2412         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2413                 return;
2414         pBtCoexist->statistics.cntStackOperationNotify++;
2415         if (pBtCoexist->bManualControl)
2416                 return;
2417
2418         if ((HCI_BT_OP_INQUIRY_START == type) ||
2419                 (HCI_BT_OP_PAGING_START == type) ||
2420                 (HCI_BT_OP_PAIRING_START == type))
2421         {
2422                 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START;
2423         }
2424         else if ((HCI_BT_OP_INQUIRY_FINISH == type) ||
2425                 (HCI_BT_OP_PAGING_SUCCESS == type) ||
2426                 (HCI_BT_OP_PAGING_UNSUCCESS == type) ||
2427                 (HCI_BT_OP_PAIRING_FINISH == type) )
2428         {
2429                 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
2430         }
2431         else
2432         {
2433                 stackOpType = BTC_STACK_OP_NONE;
2434         }
2435
2436 #endif
2437 }
2438
2439 void EXhalbtcoutsrc_HaltNotify(PBTC_COEXIST pBtCoexist)
2440 {
2441         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2442                 return;
2443
2444         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2445         {
2446                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2447                         EXhalbtc8821aCsr2ant_HaltNotify(pBtCoexist);
2448                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2449                         EXhalbtc8821a2ant_HaltNotify(pBtCoexist);
2450                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2451                         EXhalbtc8821a1ant_HaltNotify(pBtCoexist);
2452         }
2453         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2454         {
2455                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2456                         EXhalbtc8723b2ant_HaltNotify(pBtCoexist);
2457                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2458                         EXhalbtc8723b1ant_HaltNotify(pBtCoexist);
2459         }
2460         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2461         {
2462                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2463                         EXhalbtc8703b2ant_HaltNotify(pBtCoexist);
2464                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2465                         EXhalbtc8703b1ant_HaltNotify(pBtCoexist);
2466         }
2467         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2468         {
2469                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2470                         EXhalbtc8192e2ant_HaltNotify(pBtCoexist);
2471                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2472                         EXhalbtc8192e1ant_HaltNotify(pBtCoexist);
2473         }
2474         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2475         {
2476                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2477                         EXhalbtc8812a2ant_HaltNotify(pBtCoexist);
2478                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2479                         EXhalbtc8812a1ant_HaltNotify(pBtCoexist);
2480         }
2481
2482         pBtCoexist->bBinded = FALSE;
2483 }
2484
2485 void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)
2486 {
2487         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2488         {
2489                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2490                 {
2491                         halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); //BT goto standby while GNT_BT 1-->0
2492                 }
2493                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2494                 {
2495                         halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); //BT goto standby while GNT_BT 1-->0
2496                 }
2497         }
2498 }
2499
2500 void EXhalbtcoutsrc_PnpNotify(PBTC_COEXIST pBtCoexist, u8 pnpState)
2501 {
2502         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2503                 return;
2504
2505         //
2506         // currently only 1ant we have to do the notification,
2507         // once pnp is notified to sleep state, we have to leave LPS that we can sleep normally.
2508         //
2509
2510         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2511         {
2512                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2513                         EXhalbtc8723b1ant_PnpNotify(pBtCoexist,pnpState);
2514                 else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2515                         EXhalbtc8723b2ant_PnpNotify(pBtCoexist,pnpState);
2516         }
2517         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2518         {
2519                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2520                         EXhalbtc8703b1ant_PnpNotify(pBtCoexist,pnpState);
2521                 else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2522                         EXhalbtc8703b2ant_PnpNotify(pBtCoexist,pnpState);
2523         }
2524         else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2525         {
2526                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2527                         EXhalbtc8821aCsr2ant_PnpNotify(pBtCoexist, pnpState);
2528                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2529                         EXhalbtc8821a1ant_PnpNotify(pBtCoexist,pnpState);
2530                 else if(pBtCoexist->boardInfo.btdmAntNum == 2)
2531                         EXhalbtc8821a2ant_PnpNotify(pBtCoexist,pnpState);
2532         }
2533         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2534         {
2535                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2536                         EXhalbtc8192e1ant_PnpNotify(pBtCoexist, pnpState);
2537         }
2538         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2539         {
2540                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2541                         EXhalbtc8812a1ant_PnpNotify(pBtCoexist, pnpState);
2542         }
2543 }
2544
2545 void EXhalbtcoutsrc_ScoreBoardStatusNotify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
2546 {
2547         if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2548                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2549                         EXhalbtc8703b1ant_ScoreBoardStatusNotify(pBtCoexist, tmpBuf, length);
2550         }
2551 }
2552
2553 void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)
2554 {
2555         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2556                 return;
2557         pBtCoexist->statistics.cntCoexDmSwitch++;
2558
2559         halbtcoutsrc_LeaveLowPower(pBtCoexist);
2560
2561         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2562         {
2563                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2564                 {
2565                         pBtCoexist->bStopCoexDm = TRUE;
2566                         EXhalbtc8723b1ant_CoexDmReset(pBtCoexist);
2567                         EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
2568                         EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, FALSE);
2569                         EXhalbtc8723b2ant_InitCoexDm(pBtCoexist);
2570                         pBtCoexist->bStopCoexDm = FALSE;
2571                 }
2572         }
2573
2574         halbtcoutsrc_NormalLowPower(pBtCoexist);
2575 }
2576
2577 void EXhalbtcoutsrc_Periodical(PBTC_COEXIST pBtCoexist)
2578 {
2579         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2580                 return;
2581         pBtCoexist->statistics.cntPeriodical++;
2582
2583         // Periodical should be called in cmd thread,
2584         // don't need to leave low power again
2585 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2586
2587         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2588         {
2589                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2590                         EXhalbtc8821aCsr2ant_Periodical(pBtCoexist);
2591                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2592                         EXhalbtc8821a2ant_Periodical(pBtCoexist);
2593                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2594                 {
2595                         if (!halbtcoutsrc_UnderIps(pBtCoexist))
2596                         {
2597                                 EXhalbtc8821a1ant_Periodical(pBtCoexist);
2598                         }
2599                 }
2600         }
2601         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2602         {
2603                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2604                         EXhalbtc8723b2ant_Periodical(pBtCoexist);
2605                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2606                         EXhalbtc8723b1ant_Periodical(pBtCoexist);
2607         }
2608         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2609         {
2610                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2611                         EXhalbtc8703b2ant_Periodical(pBtCoexist);
2612                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2613                         EXhalbtc8703b1ant_Periodical(pBtCoexist);
2614         }
2615         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2616         {
2617                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2618                         EXhalbtc8192e2ant_Periodical(pBtCoexist);
2619                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2620                         EXhalbtc8192e1ant_Periodical(pBtCoexist);
2621         }
2622         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2623         {
2624                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2625                         EXhalbtc8812a2ant_Periodical(pBtCoexist);
2626                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2627                         EXhalbtc8812a1ant_Periodical(pBtCoexist);
2628         }
2629
2630 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2631 }
2632
2633 void EXhalbtcoutsrc_DbgControl(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)
2634 {
2635         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2636                 return;
2637
2638         pBtCoexist->statistics.cntDbgCtrl++;
2639
2640         // This function doesn't be called yet,
2641         // default no need to leave low power to avoid deadlock
2642 //      halbtcoutsrc_LeaveLowPower(pBtCoexist);
2643
2644         if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2645         {
2646                 if (pBtCoexist->boardInfo.btdmAntNum == 1)
2647                         EXhalbtc8192e1ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2648         }
2649         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2650         {
2651                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2652                         EXhalbtc8812a2ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2653                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2654                         EXhalbtc8812a1ant_DbgControl(pBtCoexist, opCode, opLen, pData);
2655         }
2656
2657 //      halbtcoutsrc_NormalLowPower(pBtCoexist);
2658 }
2659
2660 #if 0
2661 VOID
2662 EXhalbtcoutsrc_AntennaDetection(
2663         IN      PBTC_COEXIST                    pBtCoexist,
2664         IN      u4Byte                                  centFreq,
2665         IN      u4Byte                                  offset,
2666         IN      u4Byte                                  span,
2667         IN      u4Byte                                  seconds
2668         )
2669 {
2670         if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2671                 return;
2672
2673         /* Need to refine the following power save operations to enable this function in the future */  
2674 #if 0
2675         IPSDisable(pBtCoexist->Adapter, FALSE, 0);
2676         LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);
2677 #endif
2678
2679         if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2680         {
2681                 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2682                         EXhalbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds);
2683         }
2684
2685         //IPSReturn(pBtCoexist->Adapter, 0xff);
2686 }
2687 #endif
2688
2689 void EXhalbtcoutsrc_StackUpdateProfileInfo(void)
2690 {
2691 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
2692         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2693         PADAPTER padapter = (PADAPTER)GLBtCoexist.Adapter;
2694         PBT_MGNT pBtMgnt = &padapter->coex_info.BtMgnt;
2695         u8 i;
2696
2697         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2698                 return;
2699
2700         pBtCoexist->stackInfo.bProfileNotified = _TRUE;
2701
2702         pBtCoexist->stackInfo.numOfLink =
2703                 pBtMgnt->ExtConfig.NumberOfACL+pBtMgnt->ExtConfig.NumberOfSCO;
2704
2705         // reset first
2706         pBtCoexist->stackInfo.bBtLinkExist = _FALSE;
2707         pBtCoexist->stackInfo.bScoExist = _FALSE;
2708         pBtCoexist->stackInfo.bAclExist = _FALSE;
2709         pBtCoexist->stackInfo.bA2dpExist = _FALSE;
2710         pBtCoexist->stackInfo.bHidExist = _FALSE;
2711         pBtCoexist->stackInfo.numOfHid = 0;
2712         pBtCoexist->stackInfo.bPanExist = _FALSE;
2713
2714         if (!pBtMgnt->ExtConfig.NumberOfACL)
2715                 pBtCoexist->stackInfo.minBtRssi = 0;
2716
2717         if (pBtCoexist->stackInfo.numOfLink)
2718         {
2719                 pBtCoexist->stackInfo.bBtLinkExist = _TRUE;
2720                 if (pBtMgnt->ExtConfig.NumberOfSCO)
2721                         pBtCoexist->stackInfo.bScoExist = _TRUE;
2722                 if (pBtMgnt->ExtConfig.NumberOfACL)
2723                         pBtCoexist->stackInfo.bAclExist = _TRUE;
2724         }
2725
2726         for (i=0; i<pBtMgnt->ExtConfig.NumberOfACL; i++)
2727         {
2728                 if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2729                 {
2730                         pBtCoexist->stackInfo.bA2dpExist = _TRUE;
2731                 }
2732                 else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2733                 {
2734                         pBtCoexist->stackInfo.bPanExist = _TRUE;
2735                 }
2736                 else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
2737                 {
2738                         pBtCoexist->stackInfo.bHidExist = _TRUE;
2739                         pBtCoexist->stackInfo.numOfHid++;
2740                 }
2741                 else
2742                 {
2743                         pBtCoexist->stackInfo.bUnknownAclExist = _TRUE;
2744                 }
2745         }
2746 #endif //CONFIG_BT_COEXIST_SOCKET_TRX
2747 }
2748
2749 void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)
2750 {
2751         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2752
2753         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2754                 return;
2755
2756         pBtCoexist->stackInfo.minBtRssi = btRssi;
2757 }
2758
2759 void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)
2760 {
2761         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2762
2763         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2764                 return;
2765
2766         pBtCoexist->stackInfo.hciVersion = hciVersion;
2767 }
2768
2769 void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)
2770 {
2771         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2772
2773         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2774                 return;
2775
2776         pBtCoexist->btInfo.btRealFwVer = btPatchVersion;
2777         pBtCoexist->btInfo.btHciVer = btHciVersion;
2778 }
2779
2780 #if 0
2781 void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)
2782 {
2783         GLBtCoexist.boardInfo.bBtExist = bBtExist;
2784 }
2785 #endif
2786 void EXhalbtcoutsrc_SetChipType(u8 chipType)
2787 {
2788         switch(chipType)
2789         {
2790                 default:
2791                 case BT_2WIRE:
2792                 case BT_ISSC_3WIRE:
2793                 case BT_ACCEL:
2794                 case BT_RTL8756:
2795                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_UNDEF;
2796                         break;
2797                 case BT_CSR_BC4:
2798                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_CSR_BC4;
2799                         break;
2800                 case BT_CSR_BC8:
2801                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_CSR_BC8;
2802                         break;
2803                 case BT_RTL8723A:
2804                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723A;
2805                         break;
2806                 case BT_RTL8821:
2807                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8821;
2808                         break;
2809                 case BT_RTL8723B:
2810                         GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B;
2811                         break;
2812         }
2813 }
2814
2815 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
2816 {
2817         if (BT_COEX_ANT_TYPE_PG == type)
2818         {
2819                 GLBtCoexist.boardInfo.pgAntNum = antNum;
2820                 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2821 #if 0
2822                 //The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1
2823                 //The antenna position should be determined by auto-detect mechanism
2824                 // The following is assumed to main, and those must be modified if y auto-detect mechanism is ready
2825                 if ((GLBtCoexist.boardInfo.pgAntNum == 2) && (GLBtCoexist.boardInfo.btdmAntNum == 1) )
2826                         GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2827                 else
2828                         GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2829 #endif
2830         }
2831         else if (BT_COEX_ANT_TYPE_ANTDIV == type)
2832         {
2833                 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2834                 //GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;  
2835         }
2836         else if (BT_COEX_ANT_TYPE_DETECTED == type)
2837         {
2838                 GLBtCoexist.boardInfo.btdmAntNum = antNum;
2839                 //GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2840         }
2841 }
2842
2843 //
2844 // Currently used by 8723b only, S0 or S1
2845 //
2846 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
2847 {
2848         GLBtCoexist.boardInfo.singleAntPath = singleAntPath;
2849 }
2850
2851 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
2852 {
2853         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2854                 return;
2855
2856         halbtcoutsrc_LeaveLowPower(pBtCoexist);
2857
2858         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter))
2859         {
2860                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2861                         EXhalbtc8821aCsr2ant_DisplayCoexInfo(pBtCoexist);
2862                 else if (pBtCoexist->boardInfo.btdmAntNum == 2)
2863                         EXhalbtc8821a2ant_DisplayCoexInfo(pBtCoexist);
2864                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2865                         EXhalbtc8821a1ant_DisplayCoexInfo(pBtCoexist);
2866         }
2867         else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2868         {
2869                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2870                         EXhalbtc8723b2ant_DisplayCoexInfo(pBtCoexist);
2871                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2872                         EXhalbtc8723b1ant_DisplayCoexInfo(pBtCoexist);
2873         }
2874         else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter))
2875         {
2876                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2877                         EXhalbtc8703b2ant_DisplayCoexInfo(pBtCoexist);
2878                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2879                         EXhalbtc8703b1ant_DisplayCoexInfo(pBtCoexist);
2880         }
2881         else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter))
2882         {
2883                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2884                         EXhalbtc8192e2ant_DisplayCoexInfo(pBtCoexist);
2885                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2886                         EXhalbtc8192e1ant_DisplayCoexInfo(pBtCoexist);
2887         }
2888         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
2889         {
2890                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2891                         EXhalbtc8812a2ant_DisplayCoexInfo(pBtCoexist);
2892                 else if (pBtCoexist->boardInfo.btdmAntNum == 1)
2893                         EXhalbtc8812a1ant_DisplayCoexInfo(pBtCoexist);
2894         }
2895
2896         halbtcoutsrc_NormalLowPower(pBtCoexist);
2897 }
2898
2899 void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)
2900 {
2901         if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2902                 return;
2903
2904         halbtcoutsrc_LeaveLowPower(pBtCoexist);
2905
2906         if(IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
2907         {
2908                 if(pBtCoexist->boardInfo.btdmAntNum == 1)
2909                         EXhalbtc8723b1ant_DisplayAntDetection(pBtCoexist);
2910         }
2911         
2912         halbtcoutsrc_NormalLowPower(pBtCoexist);
2913 }
2914
2915 void EXhalbtcoutsrc_BTOffOnNotify(PBTC_COEXIST pBtCoexist, u8 bBTON)
2916 {
2917
2918         if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2919                 if (pBtCoexist->boardInfo.btdmAntNum == 2)
2920                         EXhalbtc8812a2ant_BTOffOnNotify(pBtCoexist, (bBTON == _TRUE)?BTC_BT_ON:BTC_BT_OFF);
2921         }
2922
2923 }
2924
2925 static void halbt_InitHwConfig92C(PADAPTER padapter)
2926 {
2927         PHAL_DATA_TYPE pHalData;
2928         u8 u1Tmp;
2929
2930
2931         pHalData = GET_HAL_DATA(padapter);
2932         if( (pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
2933                 (pHalData->bt_coexist.btChipType == BT_CSR_BC8))
2934         {
2935                 if (pHalData->rf_type == RF_1T1R)
2936                 {
2937                         // Config to 1T1R
2938                         u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
2939                         u1Tmp &= ~BIT(1);
2940                         rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
2941                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
2942
2943                         u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
2944                         u1Tmp &= ~BIT(1);
2945                         rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
2946                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
2947                 }
2948         }
2949 }
2950
2951 static void halbt_InitHwConfig92D(PADAPTER padapter)
2952 {
2953         PHAL_DATA_TYPE pHalData;
2954         u8 u1Tmp;
2955
2956         pHalData = GET_HAL_DATA(padapter);
2957         if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
2958                 (pHalData->bt_coexist.btChipType == BT_CSR_BC8))
2959         {
2960                 if (pHalData->rf_type == RF_1T1R)
2961                 {
2962                         // Config to 1T1R
2963                         u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
2964                         u1Tmp &= ~BIT(1);
2965                         rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
2966                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
2967
2968                         u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
2969                         u1Tmp &= ~BIT(1);
2970                         rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
2971                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
2972                 }
2973         }
2974 }
2975
2976 /*
2977  * Description:
2978  *      Run BT-Coexist mechansim or not
2979  *
2980  */
2981 void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)
2982 {
2983         PHAL_DATA_TYPE  pHalData;
2984
2985
2986         pHalData = GET_HAL_DATA(padapter);
2987         pHalData->bt_coexist.bBtExist = bBtExist;
2988
2989         //EXhalbtcoutsrc_SetBtExist(bBtExist);
2990 }
2991
2992 /*
2993  * Dewcription:
2994  *      Check is co-exist mechanism enabled or not
2995  *
2996  * Return:
2997  *      _TRUE   Enable BT co-exist mechanism
2998  *      _FALSE  Disable BT co-exist mechanism
2999  */
3000 u8 hal_btcoex_IsBtExist(PADAPTER padapter)
3001 {
3002         PHAL_DATA_TYPE  pHalData;
3003
3004
3005         pHalData = GET_HAL_DATA(padapter);
3006         return pHalData->bt_coexist.bBtExist;
3007 }
3008
3009 u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)
3010 {
3011         if (!hal_btcoex_IsBtExist(padapter))
3012                 return _TRUE;
3013
3014         if (GLBtCoexist.btInfo.bBtDisabled)
3015                 return _TRUE;
3016         else
3017                 return _FALSE;
3018 }
3019
3020 void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)
3021 {
3022         PHAL_DATA_TYPE  pHalData;
3023
3024
3025         pHalData = GET_HAL_DATA(padapter);
3026         pHalData->bt_coexist.btChipType = chipType;
3027
3028         EXhalbtcoutsrc_SetChipType(chipType);
3029 }
3030
3031 u8 hal_btcoex_GetChipType(PADAPTER padapter)
3032 {
3033         PHAL_DATA_TYPE  pHalData;
3034
3035
3036         pHalData = GET_HAL_DATA(padapter);
3037         return pHalData->bt_coexist.btChipType;
3038 }
3039
3040 void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)
3041 {
3042         PHAL_DATA_TYPE  pHalData;
3043
3044
3045         pHalData = GET_HAL_DATA(padapter);
3046
3047         pHalData->bt_coexist.btTotalAntNum = antNum;
3048         EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
3049 }
3050
3051 u8 hal_btcoex_GetPgAntNum(PADAPTER padapter)
3052 {
3053         PHAL_DATA_TYPE pHalData;
3054
3055
3056         pHalData = GET_HAL_DATA(padapter);
3057
3058         return pHalData->bt_coexist.btTotalAntNum;
3059 }
3060
3061 void hal_btcoex_SetSingleAntPath(PADAPTER padapter, u8 singleAntPath)
3062 {
3063         EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
3064 }
3065
3066 u8 hal_btcoex_Initialize(PADAPTER padapter)
3067 {
3068         u8 ret1;
3069         u8 ret2;
3070
3071
3072         _rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
3073         ret1 = EXhalbtcoutsrc_InitlizeVariables((void*)padapter);
3074         ret2 = (ret1==_TRUE) ? _TRUE : _FALSE;
3075
3076         return ret2;
3077 }
3078
3079 void hal_btcoex_PowerOnSetting(PADAPTER padapter)
3080 {
3081         EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
3082 }
3083
3084 void hal_btcoex_PreLoadFirmware(PADAPTER padapter)
3085 {
3086         EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);
3087 }
3088
3089 void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)
3090 {
3091         if (!hal_btcoex_IsBtExist(padapter))
3092                 return;
3093
3094         EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly);
3095         EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist);
3096 }
3097
3098 void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)
3099 {
3100         EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type);
3101 }
3102
3103 void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)
3104 {
3105         EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type);
3106 }
3107
3108 void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)
3109 {
3110         EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type);
3111 }
3112
3113 void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
3114 {
3115         EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action);
3116 }
3117
3118 void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
3119 {
3120         EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus);
3121 }
3122
3123 void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
3124 {
3125         EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType);
3126 }
3127
3128 void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)
3129 {
3130         GLBtcWiFiInIQKState = state;
3131 }
3132
3133 void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3134 {
3135         if (GLBtcWiFiInIQKState == _TRUE)
3136                 return;
3137         
3138         EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length);
3139 }
3140
3141 void hal_btcoex_BtMpRptNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3142 {
3143         u8 extid, status, len, seq;
3144
3145
3146         if (!GLBtcBtMpRptWait)
3147                 return;
3148
3149         if ((length < 3) || (!tmpBuf))
3150                 return;
3151
3152         extid = tmpBuf[0];
3153         /* not response from BT FW then exit*/
3154         switch (extid) {
3155         case C2H_WIFI_FW_ACTIVE_RSP:
3156                 GLBtcBtMpRptWiFiOK = 1;
3157                 return;
3158
3159         case C2H_TRIG_BY_BT_FW:
3160                 _cancel_timer_ex(&GLBtcBtMpOperTimer);
3161                 GLBtcBtMpRptWait = 0;
3162                 GLBtcBtMpRptBTOK = 1;
3163                 break;
3164
3165         default:
3166                 return;
3167         }
3168
3169         status = tmpBuf[1] & 0xF;
3170         len = tmpBuf[1] >> 4;
3171         seq = tmpBuf[2] >> 4;
3172
3173         GLBtcBtMpRptSeq = seq;
3174         GLBtcBtMpRptStatus = status;
3175         _rtw_memcpy(GLBtcBtMpRptRsp, tmpBuf+3, len);
3176         GLBtcBtMpRptRspSize = len;
3177         _rtw_up_sema(&GLBtcBtMpRptSema);
3178 }
3179
3180 void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
3181 {
3182         if (state == 1)
3183                 state = BTC_WIFI_PNP_SLEEP;
3184         else
3185                 state = BTC_WIFI_PNP_WAKE_UP;
3186
3187         EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state);
3188 }
3189
3190 void hal_btcoex_HaltNotify(PADAPTER padapter)
3191 {
3192         EXhalbtcoutsrc_HaltNotify(&GLBtCoexist);
3193 }
3194
3195 void hal_btcoex_ScoreBoardStatusNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3196 {
3197         EXhalbtcoutsrc_ScoreBoardStatusNotify(&GLBtCoexist, tmpBuf, length);
3198 }
3199
3200 void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)
3201 {
3202         EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);
3203 }
3204
3205 void hal_btcoex_Hanlder(PADAPTER padapter)
3206 {
3207         EXhalbtcoutsrc_Periodical(&GLBtCoexist);
3208 }
3209
3210 s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)
3211 {
3212         return (s32)GLBtCoexist.btInfo.bRejectAggPkt;
3213 }
3214
3215 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
3216 {
3217         return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize;
3218 }
3219
3220 u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)
3221 {
3222         return (u32)GLBtCoexist.btInfo.aggBufSize;
3223 }
3224
3225 void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)
3226 {
3227         GLBtCoexist.bManualControl = bmanual;
3228 }
3229
3230 u8 hal_btcoex_1Ant(PADAPTER padapter)
3231 {
3232         if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3233                 return _FALSE;
3234
3235         if (GLBtCoexist.boardInfo.btdmAntNum == 1)
3236                 return _TRUE;
3237
3238         return _FALSE;
3239 }
3240
3241 u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)
3242 {
3243         if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3244                 return _FALSE;
3245
3246         if (GLBtCoexist.btInfo.bBtDisabled)
3247                 return _FALSE;
3248
3249         if (GLBtCoexist.btInfo.bBtCtrlLps)
3250                 return _TRUE;
3251
3252         return _FALSE;
3253 }
3254
3255 u8 hal_btcoex_IsLpsOn(PADAPTER padapter)
3256 {
3257         if (hal_btcoex_IsBtExist(padapter) == _FALSE)
3258                 return _FALSE;
3259
3260         if (GLBtCoexist.btInfo.bBtDisabled)
3261                 return _FALSE;
3262
3263         if (GLBtCoexist.btInfo.bBtLpsOn)
3264                 return _TRUE;
3265
3266         return _FALSE;
3267 }
3268
3269 u8 hal_btcoex_RpwmVal(PADAPTER padapter)
3270 {
3271         return GLBtCoexist.btInfo.rpwmVal;
3272 }
3273
3274 u8 hal_btcoex_LpsVal(PADAPTER padapter)
3275 {
3276         return GLBtCoexist.btInfo.lpsVal;
3277 }
3278
3279 u32 hal_btcoex_GetRaMask(PADAPTER padapter)
3280 {
3281         if (!hal_btcoex_IsBtExist(padapter))
3282                 return 0;
3283
3284         if (GLBtCoexist.btInfo.bBtDisabled)
3285                 return 0;
3286
3287                 /* Modify by YiWei , suggest by Cosa and Jenyu
3288                  * Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask.
3289                  */
3290         /*if (GLBtCoexist.boardInfo.btdmAntNum != 1)
3291                 return 0;*/
3292
3293         return GLBtCoexist.btInfo.raMask;
3294 }
3295
3296 void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
3297 {
3298         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW write pwrModeCmd=0x%04x%08x\n",
3299                 pCmdBuf[0]<<8|pCmdBuf[1],
3300                 pCmdBuf[2]<<24|pCmdBuf[3]<<16|pCmdBuf[4]<<8|pCmdBuf[5]));
3301
3302         _rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
3303 }
3304
3305 void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
3306 {
3307         PBTCDBGINFO pinfo;
3308
3309
3310         pinfo = &GLBtcDbgInfo;
3311         DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
3312         EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
3313         DBG_BT_INFO_INIT(pinfo, NULL, 0);
3314 }
3315
3316 void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
3317 {
3318         u32 i;
3319
3320
3321         if (NULL == pDbgModule)
3322                 return;
3323
3324         for (i = 0; i < COMP_MAX; i++)
3325                 GLBtcDbgType[i] = pDbgModule[i];
3326 }
3327
3328 u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
3329 {
3330         s32 count;
3331         u8 *pstr;
3332         u32 leftSize;
3333
3334
3335         if ((NULL == pStrBuf) || (0 == bufSize))
3336                 return 0;
3337
3338         count = 0;
3339         pstr = pStrBuf;
3340         leftSize = bufSize;
3341 //      DBG_871X(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize);
3342
3343         count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
3344         if ((count < 0) || (count >= leftSize))
3345                 goto exit;
3346         pstr += count;
3347         leftSize -= count;
3348
3349         count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
3350         if ((count < 0) || (count >= leftSize))
3351                 goto exit;
3352         pstr += count;
3353         leftSize -= count;
3354
3355         count = rtw_sprintf(pstr, leftSize,
3356                 "COMP_COEX: 0x%08X\n\n",
3357                 GLBtcDbgType[COMP_COEX]);
3358         if ((count < 0) || (count >= leftSize))
3359                 goto exit;
3360         pstr += count;
3361         leftSize -= count;
3362
3363 #if 0
3364         count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
3365         if ((count < 0) || (count >= leftSize))
3366                 goto exit;
3367         pstr += count;
3368         leftSize -= count;
3369         count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
3370                 GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_INIT?1:0);
3371         if ((count < 0) || (count >= leftSize))
3372                 goto exit;
3373         pstr += count;
3374         leftSize -= count;
3375         count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
3376                 GLBtcDbgType[BTC_MSG_INTERFACE]&INTF_NOTIFY?1:0);
3377         if ((count < 0) || (count >= leftSize))
3378                 goto exit;
3379         pstr += count;
3380         leftSize -= count;
3381         
3382         count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
3383         if ((count < 0) || (count >= leftSize))
3384                 goto exit;
3385         pstr += count;
3386         leftSize -= count;
3387         count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
3388                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_RSSI_STATE?1:0);
3389         if ((count < 0) || (count >= leftSize))
3390                 goto exit;
3391         pstr += count;
3392         leftSize -= count;
3393         count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
3394                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_WIFI_RSSI_STATE?1:0);
3395         if ((count < 0) || (count >= leftSize))
3396                 goto exit;
3397         pstr += count;
3398         leftSize -= count;
3399         count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
3400                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_BT_MONITOR?1:0);
3401         if ((count < 0) || (count >= leftSize))
3402                 goto exit;
3403         pstr += count;
3404         leftSize -= count;
3405         count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
3406                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE?1:0);
3407         if ((count < 0) || (count >= leftSize))
3408                 goto exit;
3409         pstr += count;
3410         leftSize -= count;
3411         count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
3412                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW?1:0);
3413         if ((count < 0) || (count >= leftSize))
3414                 goto exit;
3415         pstr += count;
3416         leftSize -= count;
3417         count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
3418                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_DETAIL?1:0);
3419         if ((count < 0) || (count >= leftSize))
3420                 goto exit;
3421         pstr += count;
3422         leftSize -= count;
3423         count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
3424                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_FW_EXEC?1:0);
3425         if ((count < 0) || (count >= leftSize))
3426                 goto exit;
3427         pstr += count;
3428         leftSize -= count;
3429         count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
3430                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW?1:0);
3431         if ((count < 0) || (count >= leftSize))
3432                 goto exit;
3433         pstr += count;
3434         leftSize -= count;
3435         count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
3436                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_DETAIL?1:0);
3437         if ((count < 0) || (count >= leftSize))
3438                 goto exit;
3439         pstr += count;
3440         leftSize -= count;
3441         count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
3442                 GLBtcDbgType[BTC_MSG_ALGORITHM]&ALGO_TRACE_SW_EXEC?1:0);
3443         if ((count < 0) || (count >= leftSize))
3444                 goto exit;
3445         pstr += count;
3446         leftSize -= count;
3447 #endif
3448
3449 exit:
3450         count = pstr - pStrBuf;
3451 //      DBG_871X(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count);
3452
3453         return count;
3454 }
3455
3456 u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
3457 {
3458         if (!hal_btcoex_IsBtExist(padapter))
3459                 return _FALSE;
3460
3461         if (GLBtCoexist.btInfo.bIncreaseScanDevNum)
3462                 return _TRUE;
3463
3464         return _FALSE;
3465 }
3466
3467 u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)
3468 {
3469         if (GLBtCoexist.btLinkInfo.bBtLinkExist)
3470                 return _TRUE;
3471
3472         return _FALSE;
3473 }
3474
3475 void hal_btcoex_SetBtPatchVersion(PADAPTER padapter,u16 btHciVer,u16 btPatchVer)
3476 {
3477         EXhalbtcoutsrc_SetBtPatchVersion(btHciVer,btPatchVer);
3478 }
3479
3480 void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)
3481 {
3482         EXhalbtcoutsrc_SetHciVersion(hciVersion);
3483 }
3484
3485 void hal_btcoex_StackUpdateProfileInfo(void)
3486 {
3487         EXhalbtcoutsrc_StackUpdateProfileInfo();
3488 }
3489
3490 void hal_btcoex_BTOffOnNotify(PADAPTER padapter, u8 bBTON)
3491 {
3492         EXhalbtcoutsrc_BTOffOnNotify(&GLBtCoexist, bBTON);
3493 }
3494
3495 /*
3496  *      Description:
3497  *      Setting BT coex antenna isolation type .
3498  *      coex mechanisn/ spital stream/ best throughput
3499  *      anttype = 0     ,       PSTDMA  /       2SS     /       0.5T    ,       bad isolation , WiFi/BT ANT Distance<15cm , (<20dB) for 2,3 antenna
3500  *      anttype = 1     ,       PSTDMA  /       1SS     /       0.5T    ,       normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 2 antenna
3501  *      anttype = 2     ,       TDMA    /       2SS     /       T ,             normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 3 antenna
3502  *      anttype = 3     ,       no TDMA /       1SS     /       0.5T    ,       good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 2 antenna
3503  *      anttype = 4     ,       no TDMA /       2SS     /       T ,             good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 3 antenna
3504  *      wifi only throughput ~ T
3505  *      wifi/BT share one antenna with SPDT
3506  */
3507 void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)
3508 {
3509                 PHAL_DATA_TYPE pHalData;
3510                 PBTC_COEXIST    pBtCoexist = &GLBtCoexist;
3511
3512                 /*DBG_871X("####%s , anttype = %d  , %d\n" , __func__ , anttype , __LINE__); */
3513                 pHalData = GET_HAL_DATA(padapter);
3514
3515
3516                 pHalData->bt_coexist.btAntisolation = anttype;
3517
3518                 switch (pHalData->bt_coexist.btAntisolation) {
3519                 case 0:
3520                                 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_0;
3521                                 break;
3522                 case 1:
3523                                 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_1;
3524                                 break;
3525                 case 2:
3526                                 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_2;
3527                                 break;
3528                 case 3:
3529                                 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_3;
3530                                 break;
3531                 case 4:
3532                                 pBtCoexist->boardInfo.antType = (u1Byte)BTC_ANT_TYPE_4;
3533                                 break;
3534                 }
3535
3536 }
3537
3538 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
3539 int
3540 hal_btcoex_ParseAntIsolationConfigFile(
3541   PADAPTER              Adapter,
3542   char*                 buffer
3543 )
3544 {
3545         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(Adapter);
3546         u32     i = 0 , j = 0;
3547         char    *szLine , *ptmp;
3548         int rtStatus = _SUCCESS;
3549         char param_value_string[10];
3550         u8 param_value;
3551         u8 anttype = 4;
3552         
3553         u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1; 
3554         
3555         typedef struct ant_isolation {
3556                 char *param_name;  /* antenna isolation config parameter name */ 
3557                 u8 *value; /* antenna isolation config parameter value */
3558         } ANT_ISOLATION;
3559
3560         ANT_ISOLATION ant_isolation_param[] = {
3561                                                                                                 {"ANT_NUMBER" , &ant_num},
3562                                                                                                 {"ANT_DISTANCE" , &ant_distance},
3563                                                                                                 {"RFE_TYPE" , &rfe_type},                                                                                               
3564                                                                                                 {NULL , 0}
3565                                                                                 };
3566
3567
3568         
3569         /* DBG_871X("===>Hal_ParseAntIsolationConfigFile()\n" ); */
3570                         
3571         ptmp = buffer;
3572         for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
3573                 /* skip comment */ 
3574                 if (IsCommentString(szLine))
3575                         continue;        
3576
3577                 /* DBG_871X("%s : szLine = %s , strlen(szLine) = %d\n" , __func__ , szLine , strlen(szLine));*/
3578                 for (j = 0 ; ant_isolation_param[j].param_name != NULL ; j++) {
3579                         if (strstr(szLine , ant_isolation_param[j].param_name) != NULL) {
3580                                 i = 0;
3581                                 while (i < strlen(szLine)) {
3582                                         if (szLine[i] != '"')
3583                                                 ++i;
3584                                         else {
3585                                                 /* skip only has one " */
3586                                                 if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) {
3587                                                         DBG_871X("Fail to parse parameters , format error!\n");
3588                                                         break;
3589                                                 }
3590                                                 _rtw_memset((PVOID)param_value_string , 0 , 10);
3591                                                 if (!ParseQualifiedString(szLine , &i , param_value_string , '"' , '"')) {
3592                                                         DBG_871X("Fail to parse parameters\n");
3593                                                         return _FAIL;
3594                                                 } else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value)) 
3595                                                         DBG_871X("Fail to GetU1ByteIntegerFromStringInDecimal\n");
3596
3597                                                 break;
3598                                         }
3599                                 }
3600                         }
3601                 }
3602         } 
3603
3604         /* YiWei 20140716 , for BT coex antenna isolation control */
3605         /* rfe_type = 0 was SPDT , rfe_type = 1 was coupler */
3606         if (ant_num == 3 && ant_distance >= 50) 
3607                 anttype = 3;
3608         else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1)
3609                 anttype = 2;
3610         else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50)
3611                 anttype = 2;
3612         else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1)
3613                 anttype = 2;
3614         else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15))
3615                 anttype = 1;
3616         else if (ant_num == 2 && rfe_type == 0)
3617                 anttype = 0;
3618         else 
3619                 anttype = 0;
3620
3621         hal_btcoex_SetAntIsolationType(Adapter, anttype); 
3622                                                 
3623         DBG_871X("%s : ant_num = %d\n" , __func__ , ant_num);
3624         DBG_871X("%s : ant_distance = %d\n" , __func__ , ant_distance);
3625         DBG_871X("%s : rfe_type = %d\n" , __func__ , rfe_type);
3626         /* DBG_871X("<===Hal_ParseAntIsolationConfigFile()\n"); */
3627         return rtStatus;        
3628 }
3629
3630
3631 int
3632 hal_btcoex_AntIsolationConfig_ParaFile(
3633         IN      PADAPTER        Adapter,
3634         IN      char*           pFileName
3635 )
3636 {
3637         HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
3638         int     rlen = 0 , rtStatus = _FAIL;
3639
3640         _rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN);
3641
3642
3643         rtw_merge_string(rtw_phy_para_file_path, PATH_LENGTH_MAX, rtw_phy_file_path, pFileName);
3644
3645         if (rtw_is_file_readable(rtw_phy_para_file_path) == _TRUE)
3646         {
3647                 rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
3648                 if (rlen > 0)
3649                 {
3650                         rtStatus = _SUCCESS;
3651                 }
3652         }
3653
3654
3655         if (rtStatus == _SUCCESS) {
3656                 /*DBG_871X("%s(): read %s ok\n", __func__ , pFileName);*/
3657                 rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf);
3658         } else {
3659                 DBG_871X("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName);
3660         }
3661
3662         return rtStatus;
3663 }
3664 #endif // CONFIG_LOAD_PHY_PARA_FROM_FILE
3665
3666 u16 hal_btcoex_btreg_read(PADAPTER padapter, u8 type, u16 addr, u32 *data)
3667 {
3668         u16 ret = 0;
3669
3670         halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
3671
3672         ret = halbtcoutsrc_GetBtReg(&GLBtCoexist, type, addr, data);
3673
3674         halbtcoutsrc_NormalLowPower(&GLBtCoexist);
3675
3676         return ret;
3677 }
3678
3679 u16 hal_btcoex_btreg_write(PADAPTER padapter, u8 type, u16 addr, u16 val)
3680 {
3681         u16 ret = 0;
3682
3683         halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
3684
3685         ret = halbtcoutsrc_SetBtReg(&GLBtCoexist, type, addr, val);
3686
3687         halbtcoutsrc_NormalLowPower(&GLBtCoexist);
3688
3689         return ret;
3690 }
3691 #endif // CONFIG_BT_COEXIST
3692