net: wireless: rockchip_wlan: add rtl8723cs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723cs / 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 "btc/mp_precomp.h"
27
28 /* ************************************
29  *              Global variables
30  * ************************************ */
31 const char *const BtProfileString[] = {
32         "NONE",
33         "A2DP",
34         "PAN",
35         "HID",
36         "SCO",
37 };
38
39 const char *const BtSpecString[] = {
40         "1.0b",
41         "1.1",
42         "1.2",
43         "2.0+EDR",
44         "2.1+EDR",
45         "3.0+HS",
46         "4.0",
47 };
48
49 const char *const BtLinkRoleString[] = {
50         "Master",
51         "Slave",
52 };
53
54 const char *const h2cStaString[] = {
55         "successful",
56         "h2c busy",
57         "rf off",
58         "fw not read",
59 };
60
61 const char *const ioStaString[] = {
62         "success",
63         "can not IO",
64         "rf off",
65         "fw not read",
66         "wait io timeout",
67         "invalid len",
68         "idle Q empty",
69         "insert waitQ fail",
70         "unknown fail",
71         "wrong level",
72         "h2c stopped",
73 };
74
75 const char *const GLBtcWifiBwString[] = {
76         "11bg",
77         "HT20",
78         "HT40",
79         "HT80",
80         "HT160"
81 };
82
83 const char *const GLBtcWifiFreqString[] = {
84         "2.4G",
85         "5G"
86 };
87
88 const char *const GLBtcIotPeerString[] = {
89         "UNKNOWN",
90         "REALTEK",
91         "REALTEK_92SE",
92         "BROADCOM",
93         "RALINK",
94         "ATHEROS",
95         "CISCO",
96         "MERU",
97         "MARVELL",
98         "REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
99         "SELF_SOFTAP", /* Self is SoftAP */
100         "AIRGO",
101         "INTEL",
102         "RTK_APCLIENT",
103         "REALTEK_81XX",
104         "REALTEK_WOW",
105         "REALTEK_JAGUAR_BCUTAP",
106         "REALTEK_JAGUAR_CCUTAP"
107 };
108
109 const char *const coexOpcodeString[] = {
110         "Wifi status notify",
111         "Wifi progress",
112         "Wifi info",
113         "Power state",
114         "Set Control",
115         "Get Control"
116 };
117
118 const char *const coexIndTypeString[] = {
119         "bt info",
120         "pstdma",
121         "limited tx/rx",
122         "coex table",
123         "request"
124 };
125
126 const char *const coexH2cResultString[] = {
127         "ok",
128         "unknown",
129         "un opcode",
130         "opVer MM",
131         "par Err",
132         "par OoR",
133         "reqNum MM",
134         "halMac Fail",
135         "h2c TimeOut",
136         "Invalid c2h Len",
137         "data overflow"
138 };
139
140 #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS       8000
141
142 struct btc_coexist GLBtCoexist;
143 BTC_OFFLOAD gl_coex_offload;
144 u8 GLBtcWiFiInScanState;
145 u8 GLBtcWiFiInIQKState;
146 u8 GLBtcWiFiInIPS;
147 u8 GLBtcWiFiInLPS;
148 u8 GLBtcBtCoexAliveRegistered;
149
150 /*
151  * BT control H2C/C2H
152  */
153 /* EXT_EID */
154 typedef enum _bt_ext_eid {
155         C2H_WIFI_FW_ACTIVE_RSP  = 0,
156         C2H_TRIG_BY_BT_FW
157 } BT_EXT_EID;
158
159 /* C2H_STATUS */
160 typedef enum _bt_c2h_status {
161         BT_STATUS_OK = 0,
162         BT_STATUS_VERSION_MISMATCH,
163         BT_STATUS_UNKNOWN_OPCODE,
164         BT_STATUS_ERROR_PARAMETER
165 } BT_C2H_STATUS;
166
167 /* C2H BT OP CODES */
168 typedef enum _bt_op_code {
169         BT_OP_GET_BT_VERSION                                    = 0x00,
170         BT_OP_WRITE_REG_ADDR                                    = 0x0c,
171         BT_OP_WRITE_REG_VALUE                                   = 0x0d,
172
173         BT_OP_READ_REG                                                  = 0x11,
174
175         BT_LO_OP_GET_AFH_MAP_L                                  = 0x1e,
176         BT_LO_OP_GET_AFH_MAP_M                                  = 0x1f,
177         BT_LO_OP_GET_AFH_MAP_H                                  = 0x20,
178
179         BT_OP_GET_BT_COEX_SUPPORTED_FEATURE             = 0x2a,
180         BT_OP_GET_BT_COEX_SUPPORTED_VERSION             = 0x2b,
181         BT_OP_GET_BT_ANT_DET_VAL                                = 0x2c,
182         BT_OP_GET_BT_BLE_SCAN_PARA                              = 0x2d,
183         BT_OP_GET_BT_BLE_SCAN_TYPE                              = 0x2e,
184         BT_OP_MAX
185 } BT_OP_CODE;
186
187 #define BTC_MPOPER_TIMEOUT      50      /* unit: ms */
188
189 #define C2H_MAX_SIZE            16
190 u8 GLBtcBtMpOperSeq;
191 _mutex GLBtcBtMpOperLock;
192 _timer GLBtcBtMpOperTimer;
193 _sema GLBtcBtMpRptSema;
194 u8 GLBtcBtMpRptSeq;
195 u8 GLBtcBtMpRptStatus;
196 u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE];
197 u8 GLBtcBtMpRptRspSize;
198 u8 GLBtcBtMpRptWait;
199 u8 GLBtcBtMpRptWiFiOK;
200 u8 GLBtcBtMpRptBTOK;
201
202 /*
203  * Debug
204  */
205 u32 GLBtcDbgType[COMP_MAX];
206 u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
207 u1Byte  gl_btc_trace_buf[BT_TMP_BUF_SIZE];
208
209 typedef struct _btcoexdbginfo {
210         u8 *info;
211         u32 size; /* buffer total size */
212         u32 len; /* now used length */
213 } BTCDBGINFO, *PBTCDBGINFO;
214
215 BTCDBGINFO GLBtcDbgInfo;
216
217 #define BT_Operation(Adapter)                                           _FALSE
218
219 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
220 {
221         if (NULL == pinfo)
222                 return;
223
224         _rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
225
226         if (pbuf && size) {
227                 pinfo->info = pbuf;
228                 pinfo->size = size;
229         }
230 }
231
232 void DBG_BT_INFO(u8 *dbgmsg)
233 {
234         PBTCDBGINFO pinfo;
235         u32 msglen, buflen;
236         u8 *pbuf;
237
238
239         pinfo = &GLBtcDbgInfo;
240
241         if (NULL == pinfo->info)
242                 return;
243
244         msglen = strlen(dbgmsg);
245         if (pinfo->len + msglen > pinfo->size)
246                 return;
247
248         pbuf = pinfo->info + pinfo->len;
249         _rtw_memcpy(pbuf, dbgmsg, msglen);
250         pinfo->len += msglen;
251 }
252
253 /* ************************************
254  *              Debug related function
255  * ************************************ */
256 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
257 {
258         if (!pBtCoexist->bBinded ||
259             NULL == pBtCoexist->Adapter)
260                 return _FALSE;
261         return _TRUE;
262 }
263
264 static void halbtcoutsrc_DbgInit(void)
265 {
266         u8      i;
267
268         for (i = 0; i < COMP_MAX; i++)
269                 GLBtcDbgType[i] = 0;
270 }
271
272 static u8 halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)
273 {
274         if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
275             || pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
276            )
277                 return _TRUE;
278         return _FALSE;
279 }
280
281 static void halbtcoutsrc_EnterPwrLock(PBTC_COEXIST pBtCoexist)
282 {
283         struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
284         struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
285
286         _enter_pwrlock(&pwrpriv->lock);
287 }
288
289 static void halbtcoutsrc_ExitPwrLock(PBTC_COEXIST pBtCoexist)
290 {
291         struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
292         struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
293
294         _exit_pwrlock(&pwrpriv->lock);
295 }
296
297 static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
298 {
299         if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
300             || pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
301            )
302                 return _FALSE;
303         else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
304                 return _FALSE;
305         else
306                 return _TRUE;
307 }
308
309 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
310 {
311         PADAPTER padapter;
312
313
314         padapter = pBtCoexist->Adapter;
315
316         pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
317         pBtCoexist->bt_info.bt_lps_on = _FALSE;
318
319         rtw_btcoex_LPS_Leave(padapter);
320 }
321
322 void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
323 {
324         PADAPTER padapter;
325
326
327         padapter = pBtCoexist->Adapter;
328
329         if (pBtCoexist->bdontenterLPS == _FALSE) {
330                 pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
331                 pBtCoexist->bt_info.bt_lps_on = _TRUE;
332
333                 rtw_btcoex_LPS_Enter(padapter);
334         }
335 }
336
337 void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
338 {
339         PADAPTER padapter;
340
341
342
343         padapter = pBtCoexist->Adapter;
344
345         if (pBtCoexist->bt_info.bt_ctrl_lps) {
346                 pBtCoexist->bt_info.bt_lps_on = _FALSE;
347                 rtw_btcoex_LPS_Leave(padapter);
348                 pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;
349
350                 /* recover the LPS state to the original */
351 #if 0
352                 padapter->hal_func.UpdateLPSStatusHandler(
353                         padapter,
354                         pPSC->RegLeisurePsMode,
355                         pPSC->RegPowerSaveMode);
356 #endif
357         }
358 }
359
360 /*
361  *  Constraint:
362  *         1. this function will request pwrctrl->lock
363  */
364 void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
365 {
366 #ifdef CONFIG_LPS_LCLK
367         PADAPTER padapter;
368         PHAL_DATA_TYPE pHalData;
369         struct pwrctrl_priv *pwrctrl;
370         s32 ready;
371         u32 stime;
372         s32 utime;
373         u32 timeout; /* unit: ms */
374
375
376         padapter = pBtCoexist->Adapter;
377         pHalData = GET_HAL_DATA(padapter);
378         pwrctrl = adapter_to_pwrctl(padapter);
379         ready = _FAIL;
380 #ifdef LPS_RPWM_WAIT_MS
381         timeout = LPS_RPWM_WAIT_MS;
382 #else /* !LPS_RPWM_WAIT_MS */
383         timeout = 30;
384 #endif /* !LPS_RPWM_WAIT_MS */
385
386         if (GLBtcBtCoexAliveRegistered == _TRUE)
387                 return;
388
389         stime = rtw_get_current_time();
390         do {
391                 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
392                 if (_SUCCESS == ready)
393                         break;
394
395                 utime = rtw_get_passing_time_ms(stime);
396                 if (utime > timeout)
397                         break;
398
399                 rtw_msleep_os(1);
400         } while (1);
401
402         GLBtcBtCoexAliveRegistered = _TRUE;
403 #endif /* CONFIG_LPS_LCLK */
404 }
405
406 /*
407  *  Constraint:
408  *         1. this function will request pwrctrl->lock
409  */
410 void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
411 {
412 #ifdef CONFIG_LPS_LCLK
413         PADAPTER padapter;
414
415         if (GLBtcBtCoexAliveRegistered == _FALSE)
416                 return;
417
418         padapter = pBtCoexist->Adapter;
419         rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
420
421         GLBtcBtCoexAliveRegistered = _FALSE;
422 #endif /* CONFIG_LPS_LCLK */
423 }
424
425 void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
426 {
427         pBtCoexist->bt_info.bt_disable_low_pwr = bLowPwrDisable;
428         if (bLowPwrDisable)
429                 halbtcoutsrc_LeaveLowPower(pBtCoexist);         /* leave 32k low power. */
430         else
431                 halbtcoutsrc_NormalLowPower(pBtCoexist);        /* original 32k low power behavior. */
432 }
433
434 void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
435 {
436         PADAPTER padapter;
437         BOOLEAN bNeedToAct = _FALSE;
438         static u32 preTime = 0;
439         u32 curTime = 0;
440
441         padapter = pBtCoexist->Adapter;
442
443         /* ===================================== */
444         /* To void continuous deleteBA=>addBA=>deleteBA=>addBA */
445         /* This function is not allowed to continuous called. */
446         /* It can only be called after 8 seconds. */
447         /* ===================================== */
448
449         curTime = rtw_systime_to_ms(rtw_get_current_time());
450         if ((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS)    /* over 8 seconds you can execute this function again. */
451                 return;
452         else
453                 preTime = curTime;
454
455         if (pBtCoexist->bt_info.reject_agg_pkt) {
456                 bNeedToAct = _TRUE;
457                 pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
458         } else {
459                 if (pBtCoexist->bt_info.pre_reject_agg_pkt) {
460                         bNeedToAct = _TRUE;
461                         pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
462                 }
463
464                 if (pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
465                     pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
466                         bNeedToAct = _TRUE;
467                         pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size = pBtCoexist->bt_info.bt_ctrl_agg_buf_size;
468                 }
469
470                 if (pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
471                         if (pBtCoexist->bt_info.pre_agg_buf_size !=
472                             pBtCoexist->bt_info.agg_buf_size)
473                                 bNeedToAct = _TRUE;
474                         pBtCoexist->bt_info.pre_agg_buf_size = pBtCoexist->bt_info.agg_buf_size;
475                 }
476         }
477
478         if (bNeedToAct)
479                 rtw_btcoex_rx_ampdu_apply(padapter);
480 }
481
482 u8 halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist)
483 {
484         PADAPTER padapter;
485         PHAL_DATA_TYPE pHalData;
486
487         padapter = pBtCoexist->Adapter;
488         pHalData = GET_HAL_DATA(padapter);
489
490         return pHalData->bautoload_fail_flag;
491 }
492
493 u8 halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist)
494 {
495         PADAPTER padapter;
496
497         padapter = pBtCoexist->Adapter;
498
499         return padapter->bFWReady;
500 }
501
502 u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
503 {
504         if (rtw_mi_check_status(padapter, MI_AP_MODE))
505                 return _TRUE;
506         if (rtw_mi_busy_traffic_check(padapter, _FALSE))
507                 return _TRUE;
508
509         return _FALSE;
510 }
511
512 static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
513 {
514         struct mlme_priv *pmlmepriv;
515         u8 bp2p;
516         u32 portConnectedStatus;
517
518
519         pmlmepriv = &padapter->mlmepriv;
520         bp2p = _FALSE;
521         portConnectedStatus = 0;
522
523 #ifdef CONFIG_P2P
524         if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
525                 bp2p = _TRUE;
526 #endif /* CONFIG_P2P */
527
528         if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {
529                 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
530                         if (_TRUE == bp2p)
531                                 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
532                         else
533                                 portConnectedStatus |= WIFI_AP_CONNECTED;
534                 } else {
535                         if (_TRUE == bp2p)
536                                 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
537                         else
538                                 portConnectedStatus |= WIFI_STA_CONNECTED;
539                 }
540         }
541
542         return portConnectedStatus;
543 }
544
545 u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
546 {
547         /* ================================= */
548         /* return value: */
549         /* [31:16]=> connected port number */
550         /* [15:0]=> port connected bit define */
551         /* ================================ */
552
553         PADAPTER padapter;
554         u32 retVal;
555         u32 portConnectedStatus, numOfConnectedPort;
556         struct dvobj_priv *dvobj;
557         _adapter *iface;
558         int i;
559
560         padapter = pBtCoexist->Adapter;
561         retVal = 0;
562         portConnectedStatus = 0;
563         numOfConnectedPort = 0;
564         dvobj = adapter_to_dvobj(padapter);
565
566         for (i = 0; i < dvobj->iface_nums; i++) {
567                 iface = dvobj->padapters[i];
568                 if ((iface) && rtw_is_adapter_up(iface)) {
569                         retVal = _halbtcoutsrc_GetWifiLinkStatus(iface);
570                         if (retVal) {
571                                 portConnectedStatus |= retVal;
572                                 numOfConnectedPort++;
573                         }
574                 }
575         }
576         retVal = (numOfConnectedPort << 16) | portConnectedStatus;
577
578         return retVal;
579 }
580
581 static void _btmpoper_timer_hdl(void *p)
582 {
583         if (GLBtcBtMpRptWait) {
584                 GLBtcBtMpRptWait = 0;
585                 _rtw_up_sema(&GLBtcBtMpRptSema);
586         }
587 }
588
589 /*
590  * !IMPORTANT!
591  *      Before call this function, caller should acquire "GLBtcBtMpOperLock"!
592  *      Othrewise there will be racing problem and something may go wrong.
593  */
594 static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size)
595 {
596         PADAPTER padapter;
597         u8 buf[H2C_BTMP_OPER_LEN] = {0};
598         u8 buflen;
599         u8 seq;
600         u8 timer_cancelled;
601         s32 ret;
602
603
604         if (!cmd && size)
605                 size = 0;
606         if ((size + 2) > H2C_BTMP_OPER_LEN)
607                 return BT_STATUS_H2C_LENGTH_EXCEEDED;
608         buflen = size + 2;
609
610         seq = GLBtcBtMpOperSeq & 0xF;
611         GLBtcBtMpOperSeq++;
612
613         buf[0] = (opcodever & 0xF) | (seq << 4);
614         buf[1] = opcode;
615         if (cmd && size)
616                 _rtw_memcpy(buf + 2, cmd, size);
617
618         GLBtcBtMpRptWait = 1;
619         GLBtcBtMpRptWiFiOK = 0;
620         GLBtcBtMpRptBTOK = 0;
621         GLBtcBtMpRptStatus = 0;
622         padapter = pBtCoexist->Adapter;
623         _set_timer(&GLBtcBtMpOperTimer, BTC_MPOPER_TIMEOUT);
624         if (rtw_hal_fill_h2c_cmd(padapter, H2C_BT_MP_OPER, buflen, buf) == _FAIL) {
625                 _cancel_timer(&GLBtcBtMpOperTimer, &timer_cancelled);
626                 ret = BT_STATUS_H2C_FAIL;
627                 goto exit;
628         }
629
630         _rtw_down_sema(&GLBtcBtMpRptSema);
631         /* GLBtcBtMpRptWait should be 0 here*/
632
633         if (!GLBtcBtMpRptWiFiOK) {
634                 RTW_ERR("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__);
635                 ret = BT_STATUS_H2C_TIMTOUT;
636                 goto exit;
637         }
638         if (!GLBtcBtMpRptBTOK) {
639                 RTW_DBG("%s: Didn't get BT response!\n", __FUNCTION__);
640                 ret = BT_STATUS_H2C_BT_NO_RSP;
641                 goto exit;
642         }
643         if (seq != GLBtcBtMpRptSeq) {
644                 RTW_ERR("%s: Sequence number not match!(%d!=%d)!\n",
645                          __FUNCTION__, seq, GLBtcBtMpRptSeq);
646                 ret = BT_STATUS_C2H_REQNUM_MISMATCH;
647                 goto exit;
648         }
649
650         switch (GLBtcBtMpRptStatus) {
651         /* Examine the status reported from C2H */
652         case BT_STATUS_OK:
653                 ret = BT_STATUS_BT_OP_SUCCESS;
654                 RTW_DBG("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__);
655                 break;
656         case BT_STATUS_VERSION_MISMATCH:
657                 ret = BT_STATUS_OPCODE_L_VERSION_MISMATCH;
658                 RTW_DBG("%s: C2H status = BT_STATUS_OPCODE_L_VERSION_MISMATCH\n", __FUNCTION__);
659                 break;
660         case BT_STATUS_UNKNOWN_OPCODE:
661                 ret = BT_STATUS_UNKNOWN_OPCODE_L;
662                 RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_OPCODE_L\n", __FUNCTION__);
663                 break;
664         case BT_STATUS_ERROR_PARAMETER:
665                 ret = BT_STATUS_PARAMETER_FORMAT_ERROR_L;
666                 RTW_DBG("%s: C2H status = MP_BT_STATUS_PARAMETER_FORMAT_ERROR_L\n", __FUNCTION__);
667                 break;
668         default:
669                 ret = BT_STATUS_UNKNOWN_STATUS_L;
670                 RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__);
671                 break;
672         }
673
674 exit:
675         return ret;
676 }
677
678 u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
679 {
680         if (pBtCoexist->bt_info.get_bt_fw_ver_cnt <= 5) {
681                 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
682                         _irqL irqL;
683                         u8 ret;
684
685                         _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
686
687                         ret = _btmpoper_cmd(pBtCoexist, BT_OP_GET_BT_VERSION, 0, NULL, 0);
688                         if (BT_STATUS_BT_OP_SUCCESS == ret) {
689                                 pBtCoexist->bt_info.bt_real_fw_ver = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
690                                 pBtCoexist->bt_info.bt_fw_ver = *(GLBtcBtMpRptRsp + 2);
691                                 pBtCoexist->bt_info.get_bt_fw_ver_cnt++;
692                         }
693
694                         _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
695                 } else {
696 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
697                         u1Byte dataLen = 2;
698                         u1Byte buf[4] = {0};
699
700                         buf[0] = 0x0;   /* OP_Code */
701                         buf[1] = 0x0;   /* OP_Code_Length */
702                         BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
703 #endif /* !CONFIG_BT_COEXIST_SOCKET_TRX */
704                 }
705         }
706
707 exit:
708         return pBtCoexist->bt_info.bt_real_fw_ver;
709 }
710
711 s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
712 {
713         PHAL_DATA_TYPE pHalData;
714         s32 undecorated_smoothed_pwdb = 0;
715
716         pHalData = GET_HAL_DATA(padapter);
717
718         undecorated_smoothed_pwdb = pHalData->entry_min_undecorated_smoothed_pwdb;
719
720         return undecorated_smoothed_pwdb;
721 }
722
723 u32 halbtcoutsrc_GetBtCoexSupportedFeature(void *pBtcContext)
724 {
725         PBTC_COEXIST pBtCoexist;
726         u32 ret = BT_STATUS_BT_OP_SUCCESS;
727         u32 data = 0;
728
729         pBtCoexist = (PBTC_COEXIST)pBtcContext;
730
731         if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
732                 u8 buf[3] = {0};
733                 _irqL irqL;
734                 u8 op_code;
735                 u8 status;
736
737                 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
738
739                 op_code = BT_OP_GET_BT_COEX_SUPPORTED_FEATURE;
740                 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
741                 if (status == BT_STATUS_BT_OP_SUCCESS)
742                         data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
743                 else
744                         ret = SET_BT_MP_OPER_RET(op_code, status);
745
746                 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
747
748         } else
749                 ret = BT_STATUS_NOT_IMPLEMENT;
750
751         return data;
752 }
753
754 u32 halbtcoutsrc_GetBtCoexSupportedVersion(void *pBtcContext)
755 {
756         PBTC_COEXIST pBtCoexist;
757         u32 ret = BT_STATUS_BT_OP_SUCCESS;
758         u32 data = 0xFFFF;
759
760         pBtCoexist = (PBTC_COEXIST)pBtcContext;
761
762         if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
763                 u8 buf[3] = {0};
764                 _irqL irqL;
765                 u8 op_code;
766                 u8 status;
767
768                 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
769
770                 op_code = BT_OP_GET_BT_COEX_SUPPORTED_VERSION;
771                 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
772                 if (status == BT_STATUS_BT_OP_SUCCESS)
773                         data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
774                 else
775                         ret = SET_BT_MP_OPER_RET(op_code, status);
776
777                 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
778
779         } else
780                 ret = BT_STATUS_NOT_IMPLEMENT;
781
782         return data;
783 }
784
785 static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
786 {
787         struct mlme_priv *pmlmepriv;
788         struct mlme_ext_priv *pmlmeext;
789         static u8 scan_AP_num = 0;
790
791
792         pmlmepriv = &padapter->mlmepriv;
793         pmlmeext = &padapter->mlmeextpriv;
794
795         if (GLBtcWiFiInScanState == _FALSE) {
796                 if (pmlmepriv->num_of_scanned > 0xFF)
797                         scan_AP_num = 0xFF;
798                 else
799                         scan_AP_num = (u8)pmlmepriv->num_of_scanned;
800         }
801
802         return scan_AP_num;
803 }
804
805 u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
806 {
807         PBTC_COEXIST pBtCoexist;
808         PADAPTER padapter;
809         PHAL_DATA_TYPE pHalData;
810         struct mlme_ext_priv *mlmeext;
811         u8 bSoftApExist, bVwifiExist;
812         u8 *pu8;
813         s32 *pS4Tmp;
814         u32 *pU4Tmp;
815         u8 *pU1Tmp;
816         u8 ret;
817
818
819         pBtCoexist = (PBTC_COEXIST)pBtcContext;
820         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
821                 return _FALSE;
822
823         padapter = pBtCoexist->Adapter;
824         pHalData = GET_HAL_DATA(padapter);
825         mlmeext = &padapter->mlmeextpriv;
826         bSoftApExist = _FALSE;
827         bVwifiExist = _FALSE;
828         pu8 = (u8 *)pOutBuf;
829         pS4Tmp = (s32 *)pOutBuf;
830         pU4Tmp = (u32 *)pOutBuf;
831         pU1Tmp = (u8 *)pOutBuf;
832         ret = _TRUE;
833
834         switch (getType) {
835         case BTC_GET_BL_HS_OPERATION:
836                 *pu8 = _FALSE;
837                 ret = _FALSE;
838                 break;
839
840         case BTC_GET_BL_HS_CONNECTING:
841                 *pu8 = _FALSE;
842                 ret = _FALSE;
843                 break;
844
845         case BTC_GET_BL_WIFI_FW_READY:
846                 *pu8 = halbtcoutsrc_is_fw_ready(pBtCoexist);
847                 break;
848
849         case BTC_GET_BL_WIFI_CONNECTED:
850                 *pu8 = (rtw_mi_check_status(padapter, MI_LINKED)) ? _TRUE : _FALSE;
851                 break;
852
853         case BTC_GET_BL_WIFI_BUSY:
854                 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
855                 break;
856
857         case BTC_GET_BL_WIFI_SCAN:
858 #if 0
859                 *pu8 = (rtw_mi_check_fwstate(padapter, WIFI_SITE_MONITOR)) ? _TRUE : _FALSE;
860 #else
861                 /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
862                         WIFI_SITE_MONITOR in fwstate may not be cleared in time */
863                 *pu8 = GLBtcWiFiInScanState;
864 #endif
865                 break;
866
867         case BTC_GET_BL_WIFI_LINK:
868                 *pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
869                 break;
870
871         case BTC_GET_BL_WIFI_ROAM:
872                 *pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
873                 break;
874
875         case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
876                 *pu8 = _FALSE;
877                 break;
878
879         case BTC_GET_BL_WIFI_UNDER_5G:
880                 *pu8 = (pHalData->current_band_type == 1) ? _TRUE : _FALSE;
881                 break;
882
883         case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
884                 *pu8 = (rtw_mi_check_status(padapter, MI_AP_MODE)) ? _TRUE : _FALSE;
885                 break;
886
887         case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
888                 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? _FALSE : _TRUE;
889                 break;
890
891         case BTC_GET_BL_WIFI_UNDER_B_MODE:
892                 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
893                         *pu8 = _TRUE;
894                 else
895                         *pu8 = _FALSE;
896                 break;
897
898         case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
899                 if (padapter->registrypriv.mp_mode == 0)
900                         *pu8 = _FALSE;
901                 else
902                         *pu8 = _TRUE;
903                 break;
904
905         case BTC_GET_BL_EXT_SWITCH:
906                 *pu8 = _FALSE;
907                 break;
908         case BTC_GET_BL_IS_ASUS_8723B:
909                 /* Always return FALSE in linux driver since this case is added only for windows driver */
910                 *pu8 = _FALSE;
911                 break;
912
913         case BTC_GET_S4_WIFI_RSSI:
914                 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
915                 break;
916
917         case BTC_GET_S4_HS_RSSI:
918                 *pS4Tmp = 0;
919                 ret = _FALSE;
920                 break;
921
922         case BTC_GET_U4_WIFI_BW:
923                 if (IsLegacyOnly(mlmeext->cur_wireless_mode))
924                         *pU4Tmp = BTC_WIFI_BW_LEGACY;
925                 else {
926                         switch (pHalData->current_channel_bw) {
927                         case CHANNEL_WIDTH_20:
928                                 *pU4Tmp = BTC_WIFI_BW_HT20;
929                                 break;
930                         case CHANNEL_WIDTH_40:
931                                 *pU4Tmp = BTC_WIFI_BW_HT40;
932                                 break;
933                         case CHANNEL_WIDTH_80:
934                                 *pU4Tmp = BTC_WIFI_BW_HT80;
935                                 break;
936                         case CHANNEL_WIDTH_160:
937                                 *pU4Tmp = BTC_WIFI_BW_HT160;
938                                 break;
939                         default:
940                                 RTW_INFO("[BTCOEX] unknown bandwidth(%d)\n", pHalData->current_channel_bw);
941                                 *pU4Tmp = BTC_WIFI_BW_HT40;
942                                 break;
943                         }
944
945                 }
946                 break;
947
948         case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: {
949                 PRT_LINK_DETECT_T plinkinfo;
950                 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
951
952                 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
953                         *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
954                 else
955                         *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
956         }
957                 break;
958
959         case BTC_GET_U4_WIFI_FW_VER:
960                 *pU4Tmp = pHalData->firmware_version << 16;
961                 *pU4Tmp |= pHalData->firmware_sub_version;
962                 break;
963
964         case BTC_GET_U4_WIFI_LINK_STATUS:
965                 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
966                 break;
967
968         case BTC_GET_U4_BT_PATCH_VER:
969                 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
970                 break;
971
972         case BTC_GET_U4_VENDOR:
973                 *pU4Tmp = BTC_VENDOR_OTHER;
974                 break;
975
976         case BTC_GET_U4_SUPPORTED_VERSION:
977                 *pU4Tmp = halbtcoutsrc_GetBtCoexSupportedVersion(pBtCoexist);
978                 break;
979         case BTC_GET_U4_SUPPORTED_FEATURE:
980                 *pU4Tmp = halbtcoutsrc_GetBtCoexSupportedFeature(pBtCoexist);
981                 break;
982
983         case BTC_GET_U4_WIFI_IQK_TOTAL:
984                 *pU4Tmp = pHalData->odmpriv.n_iqk_cnt;
985                 break;
986
987         case BTC_GET_U4_WIFI_IQK_OK:
988                 *pU4Tmp = pHalData->odmpriv.n_iqk_ok_cnt;
989                 break;
990
991         case BTC_GET_U4_WIFI_IQK_FAIL:
992                 *pU4Tmp = pHalData->odmpriv.n_iqk_fail_cnt;
993                 break;
994
995         case BTC_GET_U1_WIFI_DOT11_CHNL:
996                 *pU1Tmp = padapter->mlmeextpriv.cur_channel;
997                 break;
998
999         case BTC_GET_U1_WIFI_CENTRAL_CHNL:
1000                 *pU1Tmp = pHalData->current_channel;
1001                 break;
1002
1003         case BTC_GET_U1_WIFI_HS_CHNL:
1004                 *pU1Tmp = 0;
1005                 ret = _FALSE;
1006                 break;
1007
1008         case BTC_GET_U1_WIFI_P2P_CHNL:
1009 #ifdef CONFIG_P2P
1010                 {
1011                         struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1012                         
1013                         *pU1Tmp = pwdinfo->operating_channel;
1014                 }
1015 #else
1016                 *pU1Tmp = 0;
1017 #endif
1018                 break;
1019
1020         case BTC_GET_U1_MAC_PHY_MODE:
1021                 /*                      *pU1Tmp = BTC_SMSP;
1022                  *                      *pU1Tmp = BTC_DMSP;
1023                  *                      *pU1Tmp = BTC_DMDP;
1024                  *                      *pU1Tmp = BTC_MP_UNKNOWN; */
1025                 break;
1026
1027         case BTC_GET_U1_AP_NUM:
1028                 *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
1029                 break;
1030         case BTC_GET_U1_ANT_TYPE:
1031                 switch (pHalData->bt_coexist.btAntisolation) {
1032                 case 0:
1033                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_0;
1034                         pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_0;
1035                         break;
1036                 case 1:
1037                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_1;
1038                         pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_1;
1039                         break;
1040                 case 2:
1041                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_2;
1042                         pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_2;
1043                         break;
1044                 case 3:
1045                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_3;
1046                         pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_3;
1047                         break;
1048                 case 4:
1049                         *pU1Tmp = (u1Byte)BTC_ANT_TYPE_4;
1050                         pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_4;
1051                         break;
1052                 }
1053                 break;
1054         case BTC_GET_U1_IOT_PEER:
1055                 *pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;
1056                 break;
1057
1058         /* =======1Ant=========== */
1059         case BTC_GET_U1_LPS_MODE:
1060                 *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
1061                 break;
1062
1063         default:
1064                 ret = _FALSE;
1065                 break;
1066         }
1067
1068         return ret;
1069 }
1070
1071 u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
1072 {
1073         PBTC_COEXIST pBtCoexist;
1074         PADAPTER padapter;
1075         PHAL_DATA_TYPE pHalData;
1076         u8 *pu8;
1077         u8 *pU1Tmp;
1078         u32     *pU4Tmp;
1079         u8 ret;
1080
1081
1082         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1083         padapter = pBtCoexist->Adapter;
1084         pHalData = GET_HAL_DATA(padapter);
1085         pu8 = (u8 *)pInBuf;
1086         pU1Tmp = (u8 *)pInBuf;
1087         pU4Tmp = (u32 *)pInBuf;
1088         ret = _TRUE;
1089
1090         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1091                 return _FALSE;
1092
1093         switch (setType) {
1094         /* set some u8 type variables. */
1095         case BTC_SET_BL_BT_DISABLE:
1096                 pBtCoexist->bt_info.bt_disabled = *pu8;
1097                 break;
1098
1099         case BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE:
1100                 pBtCoexist->bt_info.bt_enable_disable_change = *pu8;
1101                 break;
1102
1103         case BTC_SET_BL_BT_TRAFFIC_BUSY:
1104                 pBtCoexist->bt_info.bt_busy = *pu8;
1105                 break;
1106
1107         case BTC_SET_BL_BT_LIMITED_DIG:
1108                 pBtCoexist->bt_info.limited_dig = *pu8;
1109                 break;
1110
1111         case BTC_SET_BL_FORCE_TO_ROAM:
1112                 pBtCoexist->bt_info.force_to_roam = *pu8;
1113                 break;
1114
1115         case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
1116                 pBtCoexist->bt_info.reject_agg_pkt = *pu8;
1117                 break;
1118
1119         case BTC_SET_BL_BT_CTRL_AGG_SIZE:
1120                 pBtCoexist->bt_info.bt_ctrl_agg_buf_size = *pu8;
1121                 break;
1122
1123         case BTC_SET_BL_INC_SCAN_DEV_NUM:
1124                 pBtCoexist->bt_info.increase_scan_dev_num = *pu8;
1125                 break;
1126
1127         case BTC_SET_BL_BT_TX_RX_MASK:
1128                 pBtCoexist->bt_info.bt_tx_rx_mask = *pu8;
1129                 break;
1130
1131         case BTC_SET_BL_MIRACAST_PLUS_BT:
1132                 pBtCoexist->bt_info.miracast_plus_bt = *pu8;
1133                 break;
1134
1135         /* set some u8 type variables. */
1136         case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
1137                 pBtCoexist->bt_info.rssi_adjust_for_agc_table_on = *pU1Tmp;
1138                 break;
1139
1140         case BTC_SET_U1_AGG_BUF_SIZE:
1141                 pBtCoexist->bt_info.agg_buf_size = *pU1Tmp;
1142                 break;
1143
1144         /* the following are some action which will be triggered */
1145         case BTC_SET_ACT_GET_BT_RSSI:
1146 #if 0
1147                 BT_SendGetBtRssiEvent(padapter);
1148 #else
1149                 ret = _FALSE;
1150 #endif
1151                 break;
1152
1153         case BTC_SET_ACT_AGGREGATE_CTRL:
1154                 halbtcoutsrc_AggregationCheck(pBtCoexist);
1155                 break;
1156
1157         /* =======1Ant=========== */
1158         /* set some u8 type variables. */
1159         case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
1160                 pBtCoexist->bt_info.rssi_adjust_for_1ant_coex_type = *pU1Tmp;
1161                 break;
1162
1163         case BTC_SET_U1_LPS_VAL:
1164                 pBtCoexist->bt_info.lps_val = *pU1Tmp;
1165                 break;
1166
1167         case BTC_SET_U1_RPWM_VAL:
1168                 pBtCoexist->bt_info.rpwm_val = *pU1Tmp;
1169                 break;
1170
1171         /* the following are some action which will be triggered */
1172         case BTC_SET_ACT_LEAVE_LPS:
1173                 halbtcoutsrc_LeaveLps(pBtCoexist);
1174                 break;
1175
1176         case BTC_SET_ACT_ENTER_LPS:
1177                 halbtcoutsrc_EnterLps(pBtCoexist);
1178                 break;
1179
1180         case BTC_SET_ACT_NORMAL_LPS:
1181                 halbtcoutsrc_NormalLps(pBtCoexist);
1182                 break;
1183
1184         case BTC_SET_ACT_DISABLE_LOW_POWER:
1185                 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
1186                 break;
1187
1188         case BTC_SET_ACT_UPDATE_RAMASK:
1189                 pBtCoexist->bt_info.ra_mask = *pU4Tmp;
1190
1191                 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE) {
1192                         struct sta_info *psta;
1193                         PWLAN_BSSID_EX cur_network;
1194
1195                         cur_network = &padapter->mlmeextpriv.mlmext_info.network;
1196                         psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
1197                         rtw_hal_update_ra_mask(psta, psta->rssi_level, _FALSE);
1198                 }
1199                 break;
1200
1201         case BTC_SET_ACT_SEND_MIMO_PS: {
1202                 u8 newMimoPsMode = 3;
1203                 struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
1204                 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1205
1206                 /* *pU1Tmp = 0 use SM_PS static type */
1207                 /* *pU1Tmp = 1 disable SM_PS */
1208                 if (*pU1Tmp == 0)
1209                         newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
1210                 else if (*pU1Tmp == 1)
1211                         newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
1212
1213                 if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) {
1214                         /* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */
1215                         issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1);
1216                 }
1217         }
1218         break;
1219
1220         case BTC_SET_ACT_CTRL_BT_INFO:
1221 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1222                 {
1223                         u8 dataLen = *pU1Tmp;
1224                         u8 tmpBuf[BTC_TMP_BUF_SHORT];
1225                         if (dataLen)
1226                                 _rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
1227                         BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
1228                 }
1229 #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
1230                 ret = _FALSE;
1231 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
1232                 break;
1233
1234         case BTC_SET_ACT_CTRL_BT_COEX:
1235 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1236                 {
1237                         u8 dataLen = *pU1Tmp;
1238                         u8 tmpBuf[BTC_TMP_BUF_SHORT];
1239                         if (dataLen)
1240                                 _rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
1241                         BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
1242                 }
1243 #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
1244                 ret = _FALSE;
1245 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
1246                 break;
1247         case BTC_SET_ACT_CTRL_8723B_ANT:
1248 #if 0
1249                 {
1250                         u1Byte  dataLen = *pU1Tmp;
1251                         u1Byte  tmpBuf[BTC_TMP_BUF_SHORT];
1252                         if (dataLen)
1253                                 PlatformMoveMemory(&tmpBuf[0], pU1Tmp + 1, dataLen);
1254                         BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
1255                 }
1256 #else
1257                 ret = _FALSE;
1258 #endif
1259                 break;
1260         /* ===================== */
1261         default:
1262                 ret = _FALSE;
1263                 break;
1264         }
1265
1266         return ret;
1267 }
1268
1269 u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
1270 {
1271         PADAPTER padapter;
1272         struct pwrctrl_priv *pwrpriv;
1273         u8 bMacPwrCtrlOn;
1274
1275         padapter = pBtCoexist->Adapter;
1276         pwrpriv = &padapter->dvobj->pwrctl_priv;
1277         bMacPwrCtrlOn = _FALSE;
1278
1279         if ((_TRUE == pwrpriv->bips_processing)
1280             && (IPS_NONE != pwrpriv->ips_mode_req)
1281            )
1282                 return _TRUE;
1283
1284         if (rf_off == pwrpriv->rf_pwrstate)
1285                 return _TRUE;
1286
1287         rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
1288         if (_FALSE == bMacPwrCtrlOn)
1289                 return _TRUE;
1290
1291         return _FALSE;
1292 }
1293
1294 u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
1295 {
1296         return GLBtcWiFiInLPS;
1297 }
1298
1299 u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
1300 {
1301         /* todo: the method to check whether wifi is under 32K or not */
1302         return _FALSE;
1303 }
1304
1305 void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
1306 {
1307 #if 0
1308         PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1309         PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1310         PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
1311         u8 *cliBuf = pBtCoexist->cliBuf;
1312         u1Byte                  i, j;
1313         u1Byte                  tmpbuf[BTC_TMP_BUF_SHORT];
1314
1315
1316         if (gl_coex_offload.cnt_h2c_sent) {
1317                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex h2c notify]============");
1318                 CL_PRINTF(cliBuf);
1319
1320                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = H2c(%d)/Ack(%d)", "Coex h2c/c2h overall statistics",
1321                         gl_coex_offload.cnt_h2c_sent, gl_coex_offload.cnt_c2h_ack);
1322                 for (j = 0; j < COL_STATUS_MAX; j++) {
1323                         if (gl_coex_offload.status[j]) {
1324                                 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.status[j]);
1325                                 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1326                         }
1327                 }
1328                 CL_PRINTF(cliBuf);
1329         }
1330         for (i = 0; i < COL_OP_WIFI_OPCODE_MAX; i++) {
1331                 if (gl_coex_offload.h2c_record[i].count) {
1332                         /*==========================================*/
1333                         /*      H2C result statistics*/
1334                         /*==========================================*/
1335                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexOpcodeString[i], gl_coex_offload.h2c_record[i].count);
1336                         for (j = 0; j < COL_STATUS_MAX; j++) {
1337                                 if (gl_coex_offload.h2c_record[i].status[j]) {
1338                                         CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.h2c_record[i].status[j]);
1339                                         CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1340                                 }
1341                         }
1342                         CL_PRINTF(cliBuf);
1343                         /*==========================================*/
1344                         /*      H2C/C2H content*/
1345                         /*==========================================*/
1346                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "H2C / C2H content");
1347                         for (j = 0; j < gl_coex_offload.h2c_record[i].h2c_len; j++) {
1348                                 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].h2c_buf[j]);
1349                                 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
1350                         }
1351                         if (gl_coex_offload.h2c_record[i].c2h_ack_len) {
1352                                 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, "/ ", 2);
1353                                 for (j = 0; j < gl_coex_offload.h2c_record[i].c2h_ack_len; j++) {
1354                                         CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].c2h_ack_buf[j]);
1355                                         CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
1356                                 }
1357                         }
1358                         CL_PRINTF(cliBuf);
1359                         /*==========================================*/
1360                 }
1361         }
1362
1363         if (gl_coex_offload.cnt_c2h_ind) {
1364                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex c2h indication]============");
1365                 CL_PRINTF(cliBuf);
1366
1367                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = Ind(%d)", "C2H indication statistics",
1368                            gl_coex_offload.cnt_c2h_ind);
1369                 for (j = 0; j < COL_STATUS_MAX; j++) {
1370                         if (gl_coex_offload.c2h_ind_status[j]) {
1371                                 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_status[j]);
1372                                 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1373                         }
1374                 }
1375                 CL_PRINTF(cliBuf);
1376         }
1377         for (i = 0; i < COL_IND_MAX; i++) {
1378                 if (gl_coex_offload.c2h_ind_record[i].count) {
1379                         /*==========================================*/
1380                         /*      H2C result statistics*/
1381                         /*==========================================*/
1382                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexIndTypeString[i], gl_coex_offload.c2h_ind_record[i].count);
1383                         for (j = 0; j < COL_STATUS_MAX; j++) {
1384                                 if (gl_coex_offload.c2h_ind_record[i].status[j]) {
1385                                         CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_record[i].status[j]);
1386                                         CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
1387                                 }
1388                         }
1389                         CL_PRINTF(cliBuf);
1390                         /*==========================================*/
1391                         /*      content*/
1392                         /*==========================================*/
1393                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "C2H indication content");
1394                         for (j = 0; j < gl_coex_offload.c2h_ind_record[i].ind_len; j++) {
1395                                 CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.c2h_ind_record[i].ind_buf[j]);
1396                                 CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
1397                         }
1398                         CL_PRINTF(cliBuf);
1399                         /*==========================================*/
1400                 }
1401         }
1402
1403         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
1404         CL_PRINTF(cliBuf);
1405
1406 #if (H2C_USE_IO_THREAD != 1)
1407         for (i = 0; i < H2C_STATUS_MAX; i++) {
1408                 if (pHalData->h2cStatistics[i]) {
1409                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1410                                    h2cStaString[i], pHalData->h2cStatistics[i]);
1411                         CL_PRINTF(cliBuf);
1412                 }
1413         }
1414 #else
1415         for (i = 0; i < IO_STATUS_MAX; i++) {
1416                 if (Adapter->ioComStr.ioH2cStatistics[i]) {
1417                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
1418                                 ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);
1419                         CL_PRINTF(cliBuf);
1420                 }
1421         }
1422 #endif
1423 #if 0
1424         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
1425                    pHalData->LastHMEBoxNum);
1426         CL_PRINTF(cliBuf);
1427         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
1428                    pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
1429         CL_PRINTF(cliBuf);
1430
1431         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \
1432                 pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,
1433                    DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);
1434         CL_PRINTF(cliBuf);
1435
1436         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
1437                    DBG_Var.c2hPacketCnt);
1438         CL_PRINTF(cliBuf);
1439 #endif
1440         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
1441                 pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
1442         CL_PRINTF(cliBuf);
1443         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \
1444                 pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,
1445                    pBtCoexist->statistics.cntRfStatusNotify);
1446         CL_PRINTF(cliBuf);
1447         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \
1448                 pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,
1449                 pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,
1450                    pBtCoexist->statistics.cntMediaStatusNotify);
1451         CL_PRINTF(cliBuf);
1452         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind",
1453                 pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify,
1454                    pBtCoexist->statistics.cntBind);
1455         CL_PRINTF(cliBuf);
1456 #endif
1457         PADAPTER                padapter = pBtCoexist->Adapter;
1458         PHAL_DATA_TYPE  pHalData = GET_HAL_DATA(padapter);
1459         u8                              *cliBuf = pBtCoexist->cli_buf;
1460
1461         if (pHalData->EEPROMBluetoothCoexist == 1) {
1462                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex Status]============");
1463                 CL_PRINTF(cliBuf);
1464                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtDisabled", rtw_btcoex_IsBtDisabled(padapter));
1465                 CL_PRINTF(cliBuf);
1466                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtControlLps", rtw_btcoex_IsBtControlLps(padapter));
1467                 CL_PRINTF(cliBuf);
1468         }
1469 }
1470
1471 void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
1472 {
1473 #if 0
1474         PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1475         PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1476         u8 *cliBuf = pBtCoexist->cliBuf;
1477         u8 i;
1478
1479
1480         if (pBtCoexist->stack_info.profile_notified) {
1481                 for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {
1482                         if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
1483                                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \
1484                                         BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1485                                         BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],
1486                                         BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);
1487                                 CL_PRINTF(cliBuf);
1488                         } else {
1489                                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
1490                                         BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
1491                                         BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);
1492                                 CL_PRINTF(cliBuf);
1493                         }
1494                 }
1495         }
1496 #endif
1497 }
1498
1499 void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
1500 {
1501         PADAPTER        padapter = pBtCoexist->Adapter;
1502         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1503         u8                      *cliBuf = pBtCoexist->cli_buf;
1504         s32                     wifiRssi = 0, btHsRssi = 0;
1505         BOOLEAN bScan = _FALSE, bLink = _FALSE, bRoam = _FALSE, bWifiBusy = _FALSE, bWifiUnderBMode = _FALSE;
1506         u32                     wifiBw = BTC_WIFI_BW_HT20, wifiTrafficDir = BTC_WIFI_TRAFFIC_TX, wifiFreq = BTC_FREQ_2_4G;
1507         u32                     wifiLinkStatus = 0x0;
1508         BOOLEAN bBtHsOn = _FALSE, bLowPower = _FALSE;
1509         u8                      wifiChnl = 0, wifiP2PChnl = 0, nScanAPNum = 0, FwPSState;
1510         u32                     iqk_cnt_total = 0, iqk_cnt_ok = 0, iqk_cnt_fail = 0;
1511
1512         wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
1513         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc", \
1514                 ((wifiLinkStatus & WIFI_STA_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_AP_CONNECTED) ? 1 : 0),
1515                 ((wifiLinkStatus & WIFI_HS_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
1516                    ((wifiLinkStatus & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
1517         CL_PRINTF(cliBuf);
1518
1519         pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1520         pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1521         pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1522         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Link/ Roam/ Scan", \
1523                 bLink, bRoam, bScan);
1524         CL_PRINTF(cliBuf);      
1525
1526         pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_TOTAL, &iqk_cnt_total);
1527         pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_OK, &iqk_cnt_ok);
1528         pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_FAIL, &iqk_cnt_fail);
1529         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d %s %s",
1530                 "IQK All/ OK/ Fail/AutoLoad/FWDL", iqk_cnt_total, iqk_cnt_ok, iqk_cnt_fail,
1531                 ((halbtcoutsrc_is_autoload_fail(pBtCoexist) == _TRUE) ? "fail":"ok"), ((halbtcoutsrc_is_fw_ready(pBtCoexist) == _TRUE) ? "ok":"fail"));
1532         CL_PRINTF(cliBuf);
1533         
1534         if (wifiLinkStatus & WIFI_STA_CONNECTED) {
1535                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "IOT Peer", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor]);
1536                 CL_PRINTF(cliBuf);
1537         }
1538
1539         pBtCoexist->btc_get(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
1540         pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiChnl);
1541         if ((wifiLinkStatus & WIFI_P2P_GO_CONNECTED) || (wifiLinkStatus & WIFI_P2P_GC_CONNECTED)) 
1542                 pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_WIFI_P2P_CHNL, &wifiP2PChnl);        
1543         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dBm/ %d/ %d", "RSSI/ STA_Chnl/ P2P_Chnl", \
1544                 wifiRssi -100, wifiChnl, wifiP2PChnl);
1545         CL_PRINTF(cliBuf);
1546
1547         pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifiFreq);
1548         pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
1549         pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1550         pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
1551         pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
1552         pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);
1553         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ %d ", "Band/ BW/ Traffic/ APCnt", \
1554                 GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode) ? "11b" : GLBtcWifiBwString[wifiBw]),
1555                 ((!bWifiBusy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX == wifiTrafficDir) ? "uplink" : "downlink")),
1556                    nScanAPNum);
1557         CL_PRINTF(cliBuf);
1558
1559         /* power status */
1560         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \
1561                 ((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE) ? "IPS ON" : "IPS OFF"),
1562                 ((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE) ? ", LPS ON" : ", LPS OFF"),
1563                 ((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE) ? ", 32k" : ""));
1564         CL_PRINTF(cliBuf);
1565
1566         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)", \
1567                    pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
1568                    pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
1569                    pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],
1570                    pBtCoexist->bt_info.lps_val,
1571                    pBtCoexist->bt_info.rpwm_val);
1572         CL_PRINTF(cliBuf);
1573 }
1574
1575 void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
1576 {
1577         PBTC_COEXIST pBtCoexist;
1578
1579
1580         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1581         switch (dispType) {
1582         case BTC_DBG_DISP_COEX_STATISTICS:
1583                 halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
1584                 break;
1585         case BTC_DBG_DISP_BT_LINK_INFO:
1586                 halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
1587                 break;
1588         case BTC_DBG_DISP_WIFI_STATUS:
1589                 halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
1590                 break;
1591         default:
1592                 break;
1593         }
1594 }
1595
1596 /* ************************************
1597  *              IO related function
1598  * ************************************ */
1599 u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
1600 {
1601         PBTC_COEXIST pBtCoexist;
1602         PADAPTER padapter;
1603
1604
1605         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1606         padapter = pBtCoexist->Adapter;
1607
1608         return rtw_read8(padapter, RegAddr);
1609 }
1610
1611 u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
1612 {
1613         PBTC_COEXIST pBtCoexist;
1614         PADAPTER padapter;
1615
1616
1617         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1618         padapter = pBtCoexist->Adapter;
1619
1620         return  rtw_read16(padapter, RegAddr);
1621 }
1622
1623 u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
1624 {
1625         PBTC_COEXIST pBtCoexist;
1626         PADAPTER padapter;
1627
1628
1629         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1630         padapter = pBtCoexist->Adapter;
1631
1632         return  rtw_read32(padapter, RegAddr);
1633 }
1634
1635 void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1636 {
1637         PBTC_COEXIST pBtCoexist;
1638         PADAPTER padapter;
1639
1640
1641         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1642         padapter = pBtCoexist->Adapter;
1643
1644         rtw_write8(padapter, RegAddr, Data);
1645 }
1646
1647 void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
1648 {
1649         PBTC_COEXIST pBtCoexist;
1650         PADAPTER padapter;
1651         u8 originalValue, bitShift;
1652         u8 i;
1653
1654
1655         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1656         padapter = pBtCoexist->Adapter;
1657         originalValue = 0;
1658         bitShift = 0;
1659
1660         if (bitMask != 0xff) {
1661                 originalValue = rtw_read8(padapter, regAddr);
1662
1663                 for (i = 0; i <= 7; i++) {
1664                         if ((bitMask >> i) & 0x1)
1665                                 break;
1666                 }
1667                 bitShift = i;
1668
1669                 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
1670         }
1671
1672         rtw_write8(padapter, regAddr, data1b);
1673 }
1674
1675 void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
1676 {
1677         PBTC_COEXIST pBtCoexist;
1678         PADAPTER padapter;
1679
1680
1681         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1682         padapter = pBtCoexist->Adapter;
1683
1684         rtw_write16(padapter, RegAddr, Data);
1685 }
1686
1687 void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
1688 {
1689         PBTC_COEXIST pBtCoexist;
1690         PADAPTER padapter;
1691
1692
1693         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1694         padapter = pBtCoexist->Adapter;
1695
1696         rtw_write32(padapter, RegAddr, Data);
1697 }
1698
1699 void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1700 {
1701         PBTC_COEXIST            pBtCoexist = (PBTC_COEXIST)pBtcContext;
1702         PADAPTER                        Adapter = pBtCoexist->Adapter;
1703
1704         if (BTC_INTF_SDIO == pBtCoexist->chip_interface)
1705                 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
1706         else
1707                 rtw_write8(Adapter, RegAddr, Data);
1708 }
1709
1710 void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
1711 {
1712         PBTC_COEXIST pBtCoexist;
1713         PADAPTER padapter;
1714
1715
1716         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1717         padapter = pBtCoexist->Adapter;
1718
1719         phy_set_bb_reg(padapter, RegAddr, BitMask, Data);
1720 }
1721
1722
1723 u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
1724 {
1725         PBTC_COEXIST pBtCoexist;
1726         PADAPTER padapter;
1727
1728
1729         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1730         padapter = pBtCoexist->Adapter;
1731
1732         return phy_query_bb_reg(padapter, RegAddr, BitMask);
1733 }
1734
1735 void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
1736 {
1737         PBTC_COEXIST pBtCoexist;
1738         PADAPTER padapter;
1739
1740
1741         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1742         padapter = pBtCoexist->Adapter;
1743
1744         phy_set_rf_reg(padapter, eRFPath, RegAddr, BitMask, Data);
1745 }
1746
1747 u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
1748 {
1749         PBTC_COEXIST pBtCoexist;
1750         PADAPTER padapter;
1751
1752
1753         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1754         padapter = pBtCoexist->Adapter;
1755
1756         return phy_query_rf_reg(padapter, eRFPath, RegAddr, BitMask);
1757 }
1758
1759 u16 halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
1760 {
1761         PBTC_COEXIST pBtCoexist;
1762         u16 ret = BT_STATUS_BT_OP_SUCCESS;
1763
1764         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1765
1766         if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1767                 u8 buf[3] = {0};
1768                 _irqL irqL;
1769                 u8 op_code;
1770                 u8 status;
1771
1772                 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1773
1774                 Data = cpu_to_le32(Data);
1775                 op_code = BT_OP_WRITE_REG_VALUE;
1776                 status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Data, 3);
1777                 if (status != BT_STATUS_BT_OP_SUCCESS)
1778                         ret = SET_BT_MP_OPER_RET(op_code, status);
1779                 else {
1780                         buf[0] = RegType;
1781                         *(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
1782                         op_code = BT_OP_WRITE_REG_ADDR;
1783                         status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
1784                         if (status != BT_STATUS_BT_OP_SUCCESS)
1785                                 ret = SET_BT_MP_OPER_RET(op_code, status);
1786                 }
1787
1788                 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1789         } else
1790                 ret = BT_STATUS_NOT_IMPLEMENT;
1791
1792         return ret;
1793 }
1794
1795 u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)
1796 {
1797         /* Always return _FALSE since we don't implement this yet */
1798 #if 0
1799         PBTC_COEXIST            pBtCoexist = (PBTC_COEXIST)pBtcContext;
1800         PADAPTER                        Adapter = pBtCoexist->Adapter;
1801         u1Byte                          btCanTx = 0;
1802         BOOLEAN                 bStatus = FALSE;
1803
1804         bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);
1805         if (bStatus && btCanTx)
1806                 return _TRUE;
1807         else
1808                 return _FALSE;
1809 #else
1810         return _FALSE;
1811 #endif
1812 }
1813
1814 BOOLEAN
1815 halbtcoutsrc_SetBtTRXMASK(
1816         IN      PVOID                   pBtcContext,
1817         IN      u1Byte                  bt_trx_mask
1818         )
1819 {
1820         /* Always return _FALSE since we don't implement this yet */
1821 #if 0
1822         struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
1823         PADAPTER                        Adapter = pBtCoexist->Adapter;
1824         BOOLEAN                         bStatus = FALSE;
1825         u1Byte                          btCanTx = 0;
1826
1827         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter) || IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)
1828                         || IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
1829
1830         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1831                 bStatus = NDBG_SetBtTRXMASK(Adapter, 1, bt_trx_mask, &btCanTx);
1832         else
1833                 bStatus = NDBG_SetBtTRXMASK(Adapter, 2, bt_trx_mask, &btCanTx);
1834         }
1835
1836         
1837         if (bStatus)
1838                 return TRUE;
1839         else
1840                 return FALSE;
1841 #else
1842         return _FALSE;
1843 #endif
1844 }
1845
1846 u16 halbtcoutsrc_GetBtReg_with_status(void *pBtcContext, u8 RegType, u32 RegAddr, u32 *data)
1847 {
1848         PBTC_COEXIST pBtCoexist;
1849         u16 ret = BT_STATUS_BT_OP_SUCCESS;
1850
1851         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1852
1853         if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1854                 u8 buf[3] = {0};
1855                 _irqL irqL;
1856                 u8 op_code;
1857                 u8 status;
1858
1859                 buf[0] = RegType;
1860                 *(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
1861
1862                 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1863
1864                 op_code = BT_OP_READ_REG;
1865                 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
1866                 if (status == BT_STATUS_BT_OP_SUCCESS)
1867                         *data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
1868                 else
1869                         ret = SET_BT_MP_OPER_RET(op_code, status);
1870
1871                 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1872
1873         } else
1874                 ret = BT_STATUS_NOT_IMPLEMENT;
1875
1876         return ret;
1877 }
1878
1879 u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
1880 {
1881         u32 regVal;
1882         
1883         return (BT_STATUS_BT_OP_SUCCESS == halbtcoutsrc_GetBtReg_with_status(pBtcContext, RegType, RegAddr, &regVal)) ? regVal : 0xffffffff;
1884 }
1885
1886 void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
1887 {
1888         PBTC_COEXIST pBtCoexist;
1889         PADAPTER padapter;
1890
1891
1892         pBtCoexist = (PBTC_COEXIST)pBtcContext;
1893         padapter = pBtCoexist->Adapter;
1894
1895         rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
1896 }
1897
1898 static void halbtcoutsrc_coex_offload_init(void)
1899 {
1900         u1Byte  i;
1901
1902         gl_coex_offload.h2c_req_num = 0;
1903         gl_coex_offload.cnt_h2c_sent = 0;
1904         gl_coex_offload.cnt_c2h_ack = 0;
1905         gl_coex_offload.cnt_c2h_ind = 0;
1906
1907         for (i = 0; i < COL_MAX_H2C_REQ_NUM; i++)
1908                 init_completion(&gl_coex_offload.c2h_event[i]);
1909 }
1910
1911 static COL_H2C_STATUS halbtcoutsrc_send_h2c(PADAPTER Adapter, PCOL_H2C pcol_h2c, u16 h2c_cmd_len)
1912 {
1913         COL_H2C_STATUS          h2c_status = COL_STATUS_C2H_OK;
1914         u8                              i;
1915
1916 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
1917         reinit_completion(&gl_coex_offload.c2h_event[pcol_h2c->req_num]);               /* set event to un signaled state */
1918 #else
1919         INIT_COMPLETION(gl_coex_offload.c2h_event[pcol_h2c->req_num]);
1920 #endif
1921
1922         if (TRUE) {
1923 #if 0   /*(USE_HAL_MAC_API == 1) */
1924                 if (RT_STATUS_SUCCESS == HAL_MAC_Send_BT_COEX(&GET_HAL_MAC_INFO(Adapter), (pu1Byte)(pcol_h2c), (u4Byte)h2c_cmd_len, 1)) {
1925                         if (!wait_for_completion_timeout(&gl_coex_offload.c2h_event[pcol_h2c->req_num], 20)) {
1926                                 h2c_status = COL_STATUS_H2C_TIMTOUT;
1927                         }
1928                 } else {
1929                         h2c_status = COL_STATUS_H2C_HALMAC_FAIL;
1930                 }
1931 #endif
1932         }
1933
1934         return h2c_status;
1935 }
1936
1937 static COL_H2C_STATUS halbtcoutsrc_check_c2h_ack(PADAPTER Adapter, PCOL_SINGLE_H2C_RECORD pH2cRecord)
1938 {
1939         COL_H2C_STATUS  c2h_status = COL_STATUS_C2H_OK;
1940         PCOL_H2C                p_h2c_cmd = (PCOL_H2C)&pH2cRecord->h2c_buf[0];
1941         u8                      req_num = p_h2c_cmd->req_num;
1942         PCOL_C2H_ACK    p_c2h_ack = (PCOL_C2H_ACK)&gl_coex_offload.c2h_ack_buf[req_num];
1943
1944
1945         if ((COL_C2H_ACK_HDR_LEN + p_c2h_ack->ret_len) > gl_coex_offload.c2h_ack_len[req_num]) {
1946                 c2h_status = COL_STATUS_COEX_DATA_OVERFLOW;
1947                 return c2h_status;
1948         }
1949         /* else */
1950         {
1951                 _rtw_memmove(&pH2cRecord->c2h_ack_buf[0], &gl_coex_offload.c2h_ack_buf[req_num], gl_coex_offload.c2h_ack_len[req_num]);
1952                 pH2cRecord->c2h_ack_len = gl_coex_offload.c2h_ack_len[req_num];
1953         }
1954
1955
1956         if (p_c2h_ack->req_num != p_h2c_cmd->req_num) {
1957                 c2h_status = COL_STATUS_C2H_REQ_NUM_MISMATCH;
1958         } else if (p_c2h_ack->opcode_ver != p_h2c_cmd->opcode_ver) {
1959                 c2h_status = COL_STATUS_C2H_OPCODE_VER_MISMATCH;
1960         } else {
1961                 c2h_status = p_c2h_ack->status;
1962         }
1963
1964         return c2h_status;
1965 }
1966
1967 COL_H2C_STATUS halbtcoutsrc_CoexH2cProcess(void *pBtCoexist,
1968                 u8 opcode, u8 opcode_ver, u8 *ph2c_par, u8 h2c_par_len)
1969 {
1970         PADAPTER                        Adapter = ((struct btc_coexist *)pBtCoexist)->Adapter;
1971         u8                              H2C_Parameter[BTC_TMP_BUF_SHORT] = {0};
1972         PCOL_H2C                        pcol_h2c = (PCOL_H2C)&H2C_Parameter[0];
1973         u16                             paraLen = 0;
1974         COL_H2C_STATUS          h2c_status = COL_STATUS_C2H_OK, c2h_status = COL_STATUS_C2H_OK;
1975         COL_H2C_STATUS          ret_status = COL_STATUS_C2H_OK;
1976         u16                             i, col_h2c_len = 0;
1977
1978         pcol_h2c->opcode = opcode;
1979         pcol_h2c->opcode_ver = opcode_ver;
1980         pcol_h2c->req_num = gl_coex_offload.h2c_req_num;
1981         gl_coex_offload.h2c_req_num++;
1982         gl_coex_offload.h2c_req_num %= 16;
1983
1984         _rtw_memmove(&pcol_h2c->buf[0], ph2c_par, h2c_par_len);
1985
1986
1987         col_h2c_len = h2c_par_len + 2;  /* 2=sizeof(OPCode, OPCode_version and  Request number) */
1988         BT_PrintData(Adapter, "[COL], H2C cmd: ", col_h2c_len, H2C_Parameter);
1989
1990         gl_coex_offload.cnt_h2c_sent++;
1991
1992         gl_coex_offload.h2c_record[opcode].count++;
1993         gl_coex_offload.h2c_record[opcode].h2c_len = col_h2c_len;
1994         _rtw_memmove((PVOID)&gl_coex_offload.h2c_record[opcode].h2c_buf[0], (PVOID)pcol_h2c, col_h2c_len);
1995
1996         h2c_status = halbtcoutsrc_send_h2c(Adapter, pcol_h2c, col_h2c_len);
1997
1998         gl_coex_offload.h2c_record[opcode].c2h_ack_len = 0;
1999
2000         if (COL_STATUS_C2H_OK == h2c_status) {
2001                 /* if reach here, it means H2C get the correct c2h response, */
2002                 c2h_status = halbtcoutsrc_check_c2h_ack(Adapter, &gl_coex_offload.h2c_record[opcode]);
2003                 ret_status = c2h_status;
2004         } else {
2005                 /* check h2c status error, return error status code to upper layer. */
2006                 ret_status = h2c_status;
2007         }
2008         gl_coex_offload.h2c_record[opcode].status[ret_status]++;
2009         gl_coex_offload.status[ret_status]++;
2010
2011         return ret_status;
2012 }
2013
2014 u8 halbtcoutsrc_GetAntDetValFromBt(void *pBtcContext)
2015 {
2016         /* Always return 0 since we don't implement this yet */
2017 #if 0
2018         struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2019         PADAPTER                        Adapter = pBtCoexist->Adapter;
2020         u1Byte                          AntDetVal = 0x0;
2021         u1Byte                          opcodeVer = 1;
2022         BOOLEAN                         status = false;
2023
2024         status = NDBG_GetAntDetValFromBt(Adapter, opcodeVer, &AntDetVal);
2025
2026         RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$ halbtcoutsrc_GetAntDetValFromBt(): status = %d, feature = %x\n", status, AntDetVal));
2027
2028         return AntDetVal;
2029 #else
2030         return 0;
2031 #endif
2032 }
2033
2034 u8 halbtcoutsrc_GetBleScanTypeFromBt(void *pBtcContext)
2035 {
2036         PBTC_COEXIST pBtCoexist;
2037         u32 ret = BT_STATUS_BT_OP_SUCCESS;
2038         u8 data = 0;
2039
2040         pBtCoexist = (PBTC_COEXIST)pBtcContext;
2041
2042         if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2043                 u8 buf[3] = {0};
2044                 _irqL irqL;
2045                 u8 op_code;
2046                 u8 status;
2047
2048
2049                 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2050
2051                 op_code = BT_OP_GET_BT_BLE_SCAN_TYPE;
2052                 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2053                 if (status == BT_STATUS_BT_OP_SUCCESS)
2054                         data = *(u8 *)GLBtcBtMpRptRsp;
2055                 else
2056                         ret = SET_BT_MP_OPER_RET(op_code, status);
2057
2058                 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2059
2060         } else
2061                 ret = BT_STATUS_NOT_IMPLEMENT;
2062
2063         return data;
2064 }
2065
2066 u32 halbtcoutsrc_GetBleScanParaFromBt(void *pBtcContext, u8 scanType)
2067 {
2068         PBTC_COEXIST pBtCoexist;
2069         u32 ret = BT_STATUS_BT_OP_SUCCESS;
2070         u32 data = 0;
2071
2072         pBtCoexist = (PBTC_COEXIST)pBtcContext;
2073
2074         if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2075                 u8 buf[3] = {0};
2076                 _irqL irqL;
2077                 u8 op_code;
2078                 u8 status;
2079                 
2080
2081                 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2082
2083                 op_code = BT_OP_GET_BT_BLE_SCAN_PARA;
2084                 status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2085                 if (status == BT_STATUS_BT_OP_SUCCESS)
2086                         data = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
2087                 else
2088                         ret = SET_BT_MP_OPER_RET(op_code, status);
2089
2090                 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2091
2092         } else
2093                 ret = BT_STATUS_NOT_IMPLEMENT;
2094
2095         return data;
2096 }
2097
2098 u8 halbtcoutsrc_GetBtAFHMapFromBt(void *pBtcContext, u8 mapType, u8 *afhMap)
2099 {
2100         struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2101         u8 buf[2] = {0};
2102         _irqL irqL;
2103         u8 op_code;
2104         u32 *AfhMapL = (u32 *)&(afhMap[0]);
2105         u32 *AfhMapM = (u32 *)&(afhMap[4]);
2106         u16 *AfhMapH = (u16 *)&(afhMap[8]);
2107         u8 status;
2108         u32 ret = BT_STATUS_BT_OP_SUCCESS;
2109
2110         if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _FALSE)
2111                 return _FALSE;
2112
2113         buf[0] = 0;
2114         buf[1] = mapType;
2115
2116         _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2117
2118         op_code = BT_LO_OP_GET_AFH_MAP_L;
2119         status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2120         if (status == BT_STATUS_BT_OP_SUCCESS)
2121                 *AfhMapL = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
2122         else {
2123                 ret = SET_BT_MP_OPER_RET(op_code, status);
2124                 goto exit;
2125         }
2126
2127         op_code = BT_LO_OP_GET_AFH_MAP_M;
2128         status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2129         if (status == BT_STATUS_BT_OP_SUCCESS)
2130                 *AfhMapM = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
2131         else {
2132                 ret = SET_BT_MP_OPER_RET(op_code, status);
2133                 goto exit;
2134         }
2135
2136         op_code = BT_LO_OP_GET_AFH_MAP_H;
2137         status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
2138         if (status == BT_STATUS_BT_OP_SUCCESS)
2139                 *AfhMapH = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
2140         else {
2141                 ret = SET_BT_MP_OPER_RET(op_code, status);
2142                 goto exit;
2143         }
2144
2145 exit:
2146
2147         _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2148
2149         return (ret == BT_STATUS_BT_OP_SUCCESS) ? _TRUE : _FALSE;
2150 }
2151
2152 u32 halbtcoutsrc_GetPhydmVersion(void *pBtcContext)
2153 {
2154         struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2155         PADAPTER                Adapter = pBtCoexist->Adapter;
2156
2157 #ifdef CONFIG_RTL8192E
2158         return RELEASE_VERSION_8192E;
2159 #endif
2160
2161 #ifdef CONFIG_RTL8821A
2162         return RELEASE_VERSION_8821A;
2163 #endif
2164
2165 #ifdef CONFIG_RTL8723B
2166         return RELEASE_VERSION_8723B;
2167 #endif
2168
2169 #ifdef CONFIG_RTL8812A
2170         return RELEASE_VERSION_8812A;
2171 #endif
2172
2173 #ifdef CONFIG_RTL8703B
2174         return RELEASE_VERSION_8703B;
2175 #endif
2176
2177 #ifdef CONFIG_RTL8822B
2178         return RELEASE_VERSION_8822B;
2179 #endif
2180
2181 #ifdef CONFIG_RTL8723D
2182         return RELEASE_VERSION_8723D;
2183 #endif
2184
2185 #ifdef CONFIG_RTL8821C
2186         return RELEASE_VERSION_8821C;
2187 #endif
2188 }
2189
2190 void halbtcoutsrc_phydm_modify_RA_PCR_threshold(void *pBtcContext, u8 RA_offset_direction, u8 RA_threshold_offset)
2191 {
2192         struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2193
2194 /* switch to #if 0 in case the phydm version does not provide the function */
2195 #if 1
2196         phydm_modify_RA_PCR_threshold(pBtCoexist->odm_priv, RA_offset_direction, RA_threshold_offset);
2197 #endif
2198 }
2199
2200 u32 halbtcoutsrc_phydm_query_PHY_counter(void *pBtcContext, u8 info_type)
2201 {
2202         struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2203
2204 /* switch to #if 0 in case the phydm version does not provide the function */
2205 #if 1
2206         return phydm_cmn_info_query((struct PHY_DM_STRUCT *)pBtCoexist->odm_priv, (enum phydm_info_query_e)info_type);
2207 #else
2208         return 0;
2209 #endif
2210 }
2211
2212 #if 0
2213 static void BT_CoexOffloadRecordErrC2hAck(PADAPTER      Adapter)
2214 {
2215         PADAPTER                pDefaultAdapter = GetDefaultAdapter(Adapter);
2216
2217         if (pDefaultAdapter != Adapter)
2218                 return;
2219
2220         if (!hal_btcoex_IsBtExist(Adapter))
2221                 return;
2222
2223         gl_coex_offload.cnt_c2h_ack++;
2224
2225         gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;
2226 }
2227
2228 static void BT_CoexOffloadC2hAckCheck(PADAPTER  Adapter, u8 *tmpBuf, u8 length)
2229 {
2230         PADAPTER                pDefaultAdapter = GetDefaultAdapter(Adapter);
2231         PCOL_C2H_ACK    p_c2h_ack = NULL;
2232         u8                      req_num = 0xff;
2233
2234         if (pDefaultAdapter != Adapter)
2235                 return;
2236
2237         if (!hal_btcoex_IsBtExist(Adapter))
2238                 return;
2239
2240         gl_coex_offload.cnt_c2h_ack++;
2241
2242         if (length < COL_C2H_ACK_HDR_LEN) {             /* c2h ack length must >= 3 (status, opcode_ver, req_num and ret_len) */
2243                 gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;
2244         } else {
2245                 BT_PrintData(Adapter, "[COL], c2h ack:", length, tmpBuf);
2246
2247                 p_c2h_ack = (PCOL_C2H_ACK)tmpBuf;
2248                 req_num = p_c2h_ack->req_num;
2249
2250                 _rtw_memmove(&gl_coex_offload.c2h_ack_buf[req_num][0], tmpBuf, length);
2251                 gl_coex_offload.c2h_ack_len[req_num] = length;
2252
2253                 complete(&gl_coex_offload.c2h_event[req_num]);
2254         }
2255 }
2256
2257 static void BT_CoexOffloadC2hIndCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length)
2258 {
2259         PADAPTER                pDefaultAdapter = GetDefaultAdapter(Adapter);
2260         PCOL_C2H_IND    p_c2h_ind = NULL;
2261         u8                      ind_type = 0, ind_version = 0, ind_length = 0;
2262
2263         if (pDefaultAdapter != Adapter)
2264                 return;
2265
2266         if (!hal_btcoex_IsBtExist(Adapter))
2267                 return;
2268
2269         gl_coex_offload.cnt_c2h_ind++;
2270
2271         if (length < COL_C2H_IND_HDR_LEN) {             /* c2h indication length must >= 3 (type, version and length) */
2272                 gl_coex_offload.c2h_ind_status[COL_STATUS_INVALID_C2H_LEN]++;
2273         } else {
2274                 BT_PrintData(Adapter, "[COL], c2h indication:", length, tmpBuf);
2275
2276                 p_c2h_ind = (PCOL_C2H_IND)tmpBuf;
2277                 ind_type = p_c2h_ind->type;
2278                 ind_version = p_c2h_ind->version;
2279                 ind_length = p_c2h_ind->length;
2280
2281                 _rtw_memmove(&gl_coex_offload.c2h_ind_buf[0], tmpBuf, length);
2282                 gl_coex_offload.c2h_ind_len = length;
2283
2284                 /* log */
2285                 gl_coex_offload.c2h_ind_record[ind_type].count++;
2286                 gl_coex_offload.c2h_ind_record[ind_type].status[COL_STATUS_C2H_OK]++;
2287                 _rtw_memmove(&gl_coex_offload.c2h_ind_record[ind_type].ind_buf[0], tmpBuf, length);
2288                 gl_coex_offload.c2h_ind_record[ind_type].ind_len = length;
2289
2290                 gl_coex_offload.c2h_ind_status[COL_STATUS_C2H_OK]++;
2291                 /*TODO: need to check c2h indication length*/
2292                 /* TODO: Notification */
2293         }
2294 }
2295
2296 void BT_CoexOffloadC2hCheck(PADAPTER Adapter, u8 *Buffer, u8 Length)
2297 {
2298 #if 0 /*(USE_HAL_MAC_API == 1)*/
2299         u8      c2hSubCmdId = 0, c2hAckLen = 0, h2cCmdId = 0, h2cSubCmdId = 0, c2hIndLen = 0;
2300
2301         BT_PrintData(Adapter, "[COL], c2h packet:", Length - 2, Buffer + 2);
2302         c2hSubCmdId = (u1Byte)C2H_HDR_GET_C2H_SUB_CMD_ID(Buffer);
2303
2304         if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR ||
2305             c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) {
2306                 if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR) {
2307                         /* coex c2h ack */
2308                         h2cCmdId = (u1Byte)H2C_ACK_HDR_GET_H2C_CMD_ID(Buffer);
2309                         h2cSubCmdId = (u1Byte)H2C_ACK_HDR_GET_H2C_SUB_CMD_ID(Buffer);
2310                         if (h2cCmdId == 0xff && h2cSubCmdId == 0x60) {
2311                                 c2hAckLen = (u1Byte)C2H_HDR_GET_LEN(Buffer);
2312                                 if (c2hAckLen >= 8)
2313                                         BT_CoexOffloadC2hAckCheck(Adapter, &Buffer[12], (u1Byte)(c2hAckLen - 8));
2314                                 else
2315                                         BT_CoexOffloadRecordErrC2hAck(Adapter);
2316                         }
2317                 } else if (c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) {
2318                         /* coex c2h indication */
2319                         c2hIndLen = (u1Byte)C2H_HDR_GET_LEN(Buffer);
2320                         BT_CoexOffloadC2hIndCheck(Adapter, &Buffer[4], (u1Byte)c2hIndLen);
2321                 }
2322         }
2323 #endif
2324 }
2325 #endif
2326
2327 /* ************************************
2328  *              Extern functions called by other module
2329  * ************************************ */
2330 u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
2331 {
2332         PBTC_COEXIST            pBtCoexist = &GLBtCoexist;
2333         u8      antNum = 1, chipType = 0, singleAntPath = 0;
2334         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA((PADAPTER)padapter);
2335
2336         if (pBtCoexist->bBinded)
2337                 return _FALSE;
2338         else
2339                 pBtCoexist->bBinded = _TRUE;
2340
2341         pBtCoexist->statistics.cnt_bind++;
2342
2343         pBtCoexist->Adapter = padapter;
2344         pBtCoexist->odm_priv = (PVOID)&(pHalData->odmpriv);
2345
2346         pBtCoexist->stack_info.profile_notified = _FALSE;
2347
2348         pBtCoexist->bt_info.bt_ctrl_agg_buf_size = _FALSE;
2349         pBtCoexist->bt_info.agg_buf_size = 5;
2350
2351         pBtCoexist->bt_info.increase_scan_dev_num = _FALSE;
2352         pBtCoexist->bt_info.miracast_plus_bt = _FALSE;
2353
2354         antNum = rtw_btcoex_get_pg_ant_num((PADAPTER)padapter);
2355         EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
2356
2357         if (antNum == 1) {
2358                 singleAntPath = rtw_btcoex_get_pg_single_ant_path((PADAPTER)padapter);
2359                 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
2360         }
2361
2362         /* set default antenna position to main  port */
2363         pBtCoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
2364
2365         pBtCoexist->board_info.btdm_ant_det_finish = _FALSE;
2366         pBtCoexist->board_info.btdm_ant_num_by_ant_det = 1;
2367
2368         pBtCoexist->board_info.tfbga_package = rtw_btcoex_is_tfbga_package_type((PADAPTER)padapter);
2369
2370         pBtCoexist->board_info.rfe_type = rtw_btcoex_get_pg_rfe_type((PADAPTER)padapter);
2371
2372         pBtCoexist->board_info.ant_div_cfg = rtw_btcoex_get_ant_div_cfg((PADAPTER)padapter);
2373
2374         return _TRUE;
2375 }
2376
2377 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
2378 {
2379         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2380
2381         /* pBtCoexist->statistics.cntBind++; */
2382
2383         halbtcoutsrc_DbgInit();
2384
2385         halbtcoutsrc_coex_offload_init();
2386
2387 #ifdef CONFIG_PCI_HCI
2388         pBtCoexist->chip_interface = BTC_INTF_PCI;
2389 #elif defined(CONFIG_USB_HCI)
2390         pBtCoexist->chip_interface = BTC_INTF_USB;
2391 #elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
2392         pBtCoexist->chip_interface = BTC_INTF_SDIO;
2393 #else
2394         pBtCoexist->chip_interface = BTC_INTF_UNKNOWN;
2395 #endif
2396
2397         EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
2398
2399         pBtCoexist->btc_read_1byte = halbtcoutsrc_Read1Byte;
2400         pBtCoexist->btc_write_1byte = halbtcoutsrc_Write1Byte;
2401         pBtCoexist->btc_write_1byte_bitmask = halbtcoutsrc_BitMaskWrite1Byte;
2402         pBtCoexist->btc_read_2byte = halbtcoutsrc_Read2Byte;
2403         pBtCoexist->btc_write_2byte = halbtcoutsrc_Write2Byte;
2404         pBtCoexist->btc_read_4byte = halbtcoutsrc_Read4Byte;
2405         pBtCoexist->btc_write_4byte = halbtcoutsrc_Write4Byte;
2406         pBtCoexist->btc_write_local_reg_1byte = halbtcoutsrc_WriteLocalReg1Byte;
2407
2408         pBtCoexist->btc_set_bb_reg = halbtcoutsrc_SetBbReg;
2409         pBtCoexist->btc_get_bb_reg = halbtcoutsrc_GetBbReg;
2410
2411         pBtCoexist->btc_set_rf_reg = halbtcoutsrc_SetRfReg;
2412         pBtCoexist->btc_get_rf_reg = halbtcoutsrc_GetRfReg;
2413
2414         pBtCoexist->btc_fill_h2c = halbtcoutsrc_FillH2cCmd;
2415         pBtCoexist->btc_disp_dbg_msg = halbtcoutsrc_DisplayDbgMsg;
2416
2417         pBtCoexist->btc_get = halbtcoutsrc_Get;
2418         pBtCoexist->btc_set = halbtcoutsrc_Set;
2419         pBtCoexist->btc_get_bt_reg = halbtcoutsrc_GetBtReg;
2420         pBtCoexist->btc_set_bt_reg = halbtcoutsrc_SetBtReg;
2421         pBtCoexist->btc_set_bt_ant_detection = halbtcoutsrc_SetBtAntDetection;
2422         pBtCoexist->btc_set_bt_trx_mask = halbtcoutsrc_SetBtTRXMASK;
2423         pBtCoexist->btc_coex_h2c_process = halbtcoutsrc_CoexH2cProcess;
2424         pBtCoexist->btc_get_bt_coex_supported_feature = halbtcoutsrc_GetBtCoexSupportedFeature;
2425         pBtCoexist->btc_get_bt_coex_supported_version= halbtcoutsrc_GetBtCoexSupportedVersion;
2426         pBtCoexist->btc_get_ant_det_val_from_bt = halbtcoutsrc_GetAntDetValFromBt;
2427         pBtCoexist->btc_get_ble_scan_type_from_bt = halbtcoutsrc_GetBleScanTypeFromBt;
2428         pBtCoexist->btc_get_ble_scan_para_from_bt = halbtcoutsrc_GetBleScanParaFromBt;
2429         pBtCoexist->btc_get_bt_afh_map_from_bt = halbtcoutsrc_GetBtAFHMapFromBt;
2430         pBtCoexist->btc_get_bt_phydm_version = halbtcoutsrc_GetPhydmVersion;
2431         pBtCoexist->btc_phydm_modify_RA_PCR_threshold = halbtcoutsrc_phydm_modify_RA_PCR_threshold;
2432         pBtCoexist->btc_phydm_query_PHY_counter = halbtcoutsrc_phydm_query_PHY_counter;
2433
2434         pBtCoexist->cli_buf = &GLBtcDbgBuf[0];
2435
2436         GLBtcWiFiInScanState = _FALSE;
2437
2438         GLBtcWiFiInIQKState = _FALSE;
2439
2440         GLBtcWiFiInIPS = _FALSE;
2441
2442         GLBtcWiFiInLPS = _FALSE;
2443
2444         GLBtcBtCoexAliveRegistered = _FALSE;
2445
2446         /* BT Control H2C/C2H*/
2447         GLBtcBtMpOperSeq = 0;
2448         _rtw_mutex_init(&GLBtcBtMpOperLock);
2449         _init_timer(&GLBtcBtMpOperTimer, ((PADAPTER)padapter)->pnetdev, _btmpoper_timer_hdl, pBtCoexist);
2450         _rtw_init_sema(&GLBtcBtMpRptSema, 0);
2451         GLBtcBtMpRptSeq = 0;
2452         GLBtcBtMpRptStatus = 0;
2453         _rtw_memset(GLBtcBtMpRptRsp, 0, C2H_MAX_SIZE);
2454         GLBtcBtMpRptRspSize = 0;
2455         GLBtcBtMpRptWait = 0;
2456         GLBtcBtMpRptWiFiOK = 0;
2457         GLBtcBtMpRptBTOK = 0;
2458
2459         return _TRUE;
2460 }
2461
2462 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
2463 {
2464         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2465                 return;
2466
2467         /* Power on setting function is only added in 8723B currently */
2468         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2469                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2470                         ex_halbtc8723b2ant_power_on_setting(pBtCoexist);
2471                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2472                         ex_halbtc8723b1ant_power_on_setting(pBtCoexist);
2473         }
2474
2475         if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2476                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2477                         ex_halbtc8723d2ant_power_on_setting(pBtCoexist);
2478                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2479                         ex_halbtc8723d1ant_power_on_setting(pBtCoexist);
2480         }
2481
2482         if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2483                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2484                         ex_halbtc8822b1ant_power_on_setting(pBtCoexist);
2485                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2486                         ex_halbtc8822b2ant_power_on_setting(pBtCoexist);
2487         }
2488
2489         if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
2490                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2491                         ex_halbtc8821c2ant_power_on_setting(pBtCoexist);
2492                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2493                         ex_halbtc8821c1ant_power_on_setting(pBtCoexist);
2494         }
2495 }
2496
2497 void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)
2498 {
2499         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2500                 return;
2501
2502         pBtCoexist->statistics.cnt_pre_load_firmware++;
2503
2504         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2505                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2506                         ex_halbtc8723b2ant_pre_load_firmware(pBtCoexist);
2507                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2508                         ex_halbtc8723b1ant_pre_load_firmware(pBtCoexist);
2509         }
2510
2511         if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2512                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2513                         ex_halbtc8723d2ant_pre_load_firmware(pBtCoexist);
2514                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2515                         ex_halbtc8723d1ant_pre_load_firmware(pBtCoexist);
2516         }
2517
2518         if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
2519                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2520                         ex_halbtc8821c2ant_pre_load_firmware(pBtCoexist);
2521                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2522                         ex_halbtc8821c1ant_pre_load_firmware(pBtCoexist);
2523         }
2524 }
2525
2526 void EXhalbtcoutsrc_init_hw_config(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
2527 {
2528         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2529                 return;
2530
2531         pBtCoexist->statistics.cnt_init_hw_config++;
2532
2533         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2534 #if 0
2535                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2536                         ex_halbtc8821aCsr2ant_init_hw_config(pBtCoexist, bWifiOnly);
2537                 else
2538 #endif
2539                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2540                         ex_halbtc8821a2ant_init_hw_config(pBtCoexist, bWifiOnly);
2541                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2542                         ex_halbtc8821a1ant_init_hw_config(pBtCoexist, bWifiOnly);
2543         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2544                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2545                         ex_halbtc8723b2ant_init_hw_config(pBtCoexist, bWifiOnly);
2546                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2547                         ex_halbtc8723b1ant_init_hw_config(pBtCoexist, bWifiOnly);
2548         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2549                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2550                         ex_halbtc8703b1ant_init_hw_config(pBtCoexist, bWifiOnly);
2551         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2552                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2553                         ex_halbtc8723d2ant_init_hw_config(pBtCoexist, bWifiOnly);
2554                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2555                         ex_halbtc8723d1ant_init_hw_config(pBtCoexist, bWifiOnly);
2556         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2557                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2558                         ex_halbtc8192e2ant_init_hw_config(pBtCoexist, bWifiOnly);
2559                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2560                         ex_halbtc8192e1ant_init_hw_config(pBtCoexist, bWifiOnly);
2561         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2562                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2563                         ex_halbtc8812a2ant_init_hw_config(pBtCoexist, bWifiOnly);
2564                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2565                         ex_halbtc8812a1ant_init_hw_config(pBtCoexist, bWifiOnly);
2566         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2567                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2568                         ex_halbtc8822b1ant_init_hw_config(pBtCoexist, bWifiOnly);
2569                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2570                         ex_halbtc8822b2ant_init_hw_config(pBtCoexist, bWifiOnly);
2571                 #ifdef CONFIG_FW_MULTI_PORT_SUPPORT
2572                 rtw_hal_set_default_port_id_cmd(pBtCoexist->Adapter, 0);
2573                 rtw_hal_set_wifi_port_id_cmd(pBtCoexist->Adapter);
2574                 #endif
2575         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
2576                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2577                         ex_halbtc8821c2ant_init_hw_config(pBtCoexist, bWifiOnly);
2578                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2579                         ex_halbtc8821c1ant_init_hw_config(pBtCoexist, bWifiOnly);
2580                 #ifdef CONFIG_FW_MULTI_PORT_SUPPORT
2581                 rtw_hal_set_default_port_id_cmd(pBtCoexist->Adapter, 0);
2582                 rtw_hal_set_wifi_port_id_cmd(pBtCoexist->Adapter);
2583                 #endif
2584         }
2585 }
2586
2587 void EXhalbtcoutsrc_init_coex_dm(PBTC_COEXIST pBtCoexist)
2588 {
2589         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2590                 return;
2591
2592         pBtCoexist->statistics.cnt_init_coex_dm++;
2593
2594         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2595 #if 0
2596                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2597                         ex_halbtc8821aCsr2ant_init_coex_dm(pBtCoexist);
2598                 else
2599 #endif
2600                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2601                         ex_halbtc8821a2ant_init_coex_dm(pBtCoexist);
2602                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2603                         ex_halbtc8821a1ant_init_coex_dm(pBtCoexist);
2604         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2605                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2606                         ex_halbtc8723b2ant_init_coex_dm(pBtCoexist);
2607                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2608                         ex_halbtc8723b1ant_init_coex_dm(pBtCoexist);
2609         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2610                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2611                         ex_halbtc8703b1ant_init_coex_dm(pBtCoexist);
2612         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2613                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2614                         ex_halbtc8723d2ant_init_coex_dm(pBtCoexist);
2615                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2616                         ex_halbtc8723d1ant_init_coex_dm(pBtCoexist);
2617         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2618                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2619                         ex_halbtc8192e2ant_init_coex_dm(pBtCoexist);
2620                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2621                         ex_halbtc8192e1ant_init_coex_dm(pBtCoexist);
2622         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2623                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2624                         ex_halbtc8812a2ant_init_coex_dm(pBtCoexist);
2625                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2626                         ex_halbtc8812a1ant_init_coex_dm(pBtCoexist);
2627         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2628                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2629                         ex_halbtc8822b1ant_init_coex_dm(pBtCoexist);
2630                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2631                         ex_halbtc8822b2ant_init_coex_dm(pBtCoexist);
2632         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
2633                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2634                         ex_halbtc8821c2ant_init_coex_dm(pBtCoexist);
2635                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2636                         ex_halbtc8821c1ant_init_coex_dm(pBtCoexist);
2637         }
2638
2639         pBtCoexist->initilized = _TRUE;
2640 }
2641
2642 void EXhalbtcoutsrc_ips_notify(PBTC_COEXIST pBtCoexist, u8 type)
2643 {
2644         u8      ipsType;
2645
2646         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2647                 return;
2648
2649         pBtCoexist->statistics.cnt_ips_notify++;
2650         if (pBtCoexist->manual_control)
2651                 return;
2652
2653         if (IPS_NONE == type) {
2654                 ipsType = BTC_IPS_LEAVE;
2655                 GLBtcWiFiInIPS = _FALSE;
2656         } else {
2657                 ipsType = BTC_IPS_ENTER;
2658                 GLBtcWiFiInIPS = _TRUE;
2659         }
2660
2661         /* All notify is called in cmd thread, don't need to leave low power again
2662         *       halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2663
2664         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2665 #if 0
2666                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2667                         ex_halbtc8821aCsr2ant_ips_notify(pBtCoexist, ipsType);
2668                 else
2669 #endif
2670                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2671                         ex_halbtc8821a2ant_ips_notify(pBtCoexist, ipsType);
2672                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2673                         ex_halbtc8821a1ant_ips_notify(pBtCoexist, ipsType);
2674         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2675                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2676                         ex_halbtc8723b2ant_ips_notify(pBtCoexist, ipsType);
2677                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2678                         ex_halbtc8723b1ant_ips_notify(pBtCoexist, ipsType);
2679         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2680                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2681                         ex_halbtc8703b1ant_ips_notify(pBtCoexist, ipsType);
2682         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2683                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2684                         ex_halbtc8723d2ant_ips_notify(pBtCoexist, ipsType);
2685                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2686                         ex_halbtc8723d1ant_ips_notify(pBtCoexist, ipsType);
2687         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2688                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2689                         ex_halbtc8192e2ant_ips_notify(pBtCoexist, ipsType);
2690                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2691                         ex_halbtc8192e1ant_ips_notify(pBtCoexist, ipsType);
2692         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2693                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2694                         ex_halbtc8812a2ant_ips_notify(pBtCoexist, ipsType);
2695                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2696                         ex_halbtc8812a1ant_ips_notify(pBtCoexist, ipsType);
2697         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2698                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2699                         ex_halbtc8822b1ant_ips_notify(pBtCoexist, ipsType);
2700                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2701                         ex_halbtc8822b2ant_ips_notify(pBtCoexist, ipsType);
2702         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
2703                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2704                         ex_halbtc8821c2ant_ips_notify(pBtCoexist, ipsType);
2705                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2706                         ex_halbtc8821c1ant_ips_notify(pBtCoexist, ipsType);
2707         }
2708
2709         /*      halbtcoutsrc_NormalLowPower(pBtCoexist); */
2710 }
2711
2712 void EXhalbtcoutsrc_lps_notify(PBTC_COEXIST pBtCoexist, u8 type)
2713 {
2714         u8 lpsType;
2715
2716
2717         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2718                 return;
2719
2720         pBtCoexist->statistics.cnt_lps_notify++;
2721         if (pBtCoexist->manual_control)
2722                 return;
2723
2724         if (PS_MODE_ACTIVE == type) {
2725                 lpsType = BTC_LPS_DISABLE;
2726                 GLBtcWiFiInLPS = _FALSE;
2727         } else {
2728                 lpsType = BTC_LPS_ENABLE;
2729                 GLBtcWiFiInLPS = _TRUE;
2730         }
2731
2732         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2733 #if 0
2734                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2735                         ex_halbtc8821aCsr2ant_lps_notify(pBtCoexist, lpsType);
2736                 else
2737 #endif
2738                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2739                         ex_halbtc8821a2ant_lps_notify(pBtCoexist, lpsType);
2740                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2741                         ex_halbtc8821a1ant_lps_notify(pBtCoexist, lpsType);
2742         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2743                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2744                         ex_halbtc8723b2ant_lps_notify(pBtCoexist, lpsType);
2745                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2746                         ex_halbtc8723b1ant_lps_notify(pBtCoexist, lpsType);
2747         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2748                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2749                         ex_halbtc8703b1ant_lps_notify(pBtCoexist, lpsType);
2750         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2751                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2752                         ex_halbtc8723d2ant_lps_notify(pBtCoexist, lpsType);
2753                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2754                         ex_halbtc8723d1ant_lps_notify(pBtCoexist, lpsType);
2755         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2756                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2757                         ex_halbtc8192e2ant_lps_notify(pBtCoexist, lpsType);
2758                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2759                         ex_halbtc8192e1ant_lps_notify(pBtCoexist, lpsType);
2760         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2761                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2762                         ex_halbtc8812a2ant_lps_notify(pBtCoexist, lpsType);
2763                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2764                         ex_halbtc8812a1ant_lps_notify(pBtCoexist, lpsType);
2765         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2766                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2767                         ex_halbtc8822b1ant_lps_notify(pBtCoexist, lpsType);
2768                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2769                         ex_halbtc8822b2ant_lps_notify(pBtCoexist, lpsType);
2770         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
2771                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2772                         ex_halbtc8821c2ant_lps_notify(pBtCoexist, lpsType);
2773                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2774                         ex_halbtc8821c1ant_lps_notify(pBtCoexist, lpsType);
2775         }
2776 }
2777
2778 void EXhalbtcoutsrc_scan_notify(PBTC_COEXIST pBtCoexist, u8 type)
2779 {
2780         u8      scanType;
2781
2782         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2783                 return;
2784         pBtCoexist->statistics.cnt_scan_notify++;
2785         if (pBtCoexist->manual_control)
2786                 return;
2787
2788         if (type) {
2789                 scanType = BTC_SCAN_START;
2790                 GLBtcWiFiInScanState = _TRUE;
2791         } else {
2792                 scanType = BTC_SCAN_FINISH;
2793                 GLBtcWiFiInScanState = _FALSE;
2794         }
2795
2796         /* All notify is called in cmd thread, don't need to leave low power again
2797         *       halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2798
2799         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2800 #if 0
2801                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2802                         ex_halbtc8821aCsr2ant_scan_notify(pBtCoexist, scanType);
2803                 else
2804 #endif
2805                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2806                         ex_halbtc8821a2ant_scan_notify(pBtCoexist, scanType);
2807                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2808                         ex_halbtc8821a1ant_scan_notify(pBtCoexist, scanType);
2809         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2810                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2811                         ex_halbtc8723b2ant_scan_notify(pBtCoexist, scanType);
2812                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2813                         ex_halbtc8723b1ant_scan_notify(pBtCoexist, scanType);
2814         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2815                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2816                         ex_halbtc8703b1ant_scan_notify(pBtCoexist, scanType);
2817         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2818                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2819                         ex_halbtc8723d2ant_scan_notify(pBtCoexist, scanType);
2820                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2821                         ex_halbtc8723d1ant_scan_notify(pBtCoexist, scanType);
2822         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2823                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2824                         ex_halbtc8192e2ant_scan_notify(pBtCoexist, scanType);
2825                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2826                         ex_halbtc8192e1ant_scan_notify(pBtCoexist, scanType);
2827         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2828                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2829                         ex_halbtc8812a2ant_scan_notify(pBtCoexist, scanType);
2830                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2831                         ex_halbtc8812a1ant_scan_notify(pBtCoexist, scanType);
2832         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2833                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2834                         ex_halbtc8822b1ant_scan_notify(pBtCoexist, scanType);
2835                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2836                         ex_halbtc8822b2ant_scan_notify(pBtCoexist, scanType);
2837         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
2838                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2839                         ex_halbtc8821c2ant_scan_notify(pBtCoexist, scanType);
2840                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2841                         ex_halbtc8821c1ant_scan_notify(pBtCoexist, scanType);
2842         }
2843
2844         /*      halbtcoutsrc_NormalLowPower(pBtCoexist); */
2845 }
2846
2847 void EXhalbtcoutsrc_SetAntennaPathNotify(PBTC_COEXIST pBtCoexist, u8 type)
2848 {
2849 #if 0
2850         u8      switchType;
2851
2852         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2853                 return;
2854
2855         if (pBtCoexist->manual_control)
2856                 return;
2857
2858         halbtcoutsrc_LeaveLowPower(pBtCoexist);
2859
2860         switchType = type;
2861
2862         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2863                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2864                         ex_halbtc8723b1ant_set_antenna_notify(pBtCoexist, type);
2865         }
2866         if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2867                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2868                         ex_halbtc8723d1ant_set_antenna_notify(pBtCoexist, type);
2869                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2870                         ex_halbtc8723d2ant_set_antenna_notify(pBtCoexist, type);
2871         }
2872
2873         halbtcoutsrc_NormalLowPower(pBtCoexist);
2874 #endif
2875 }
2876
2877 void EXhalbtcoutsrc_connect_notify(PBTC_COEXIST pBtCoexist, u8 action)
2878 {
2879         u8      assoType;
2880
2881         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2882                 return;
2883         pBtCoexist->statistics.cnt_connect_notify++;
2884         if (pBtCoexist->manual_control)
2885                 return;
2886
2887         if (action)
2888                 assoType = BTC_ASSOCIATE_START;
2889         else
2890                 assoType = BTC_ASSOCIATE_FINISH;
2891
2892         /* All notify is called in cmd thread, don't need to leave low power again
2893         *       halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2894
2895         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2896 #if 0
2897                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2898                         ex_halbtc8821aCsr2ant_connect_notify(pBtCoexist, assoType);
2899                 else
2900 #endif
2901                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2902                         ex_halbtc8821a2ant_connect_notify(pBtCoexist, assoType);
2903                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2904                         ex_halbtc8821a1ant_connect_notify(pBtCoexist, assoType);
2905         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2906                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2907                         ex_halbtc8723b2ant_connect_notify(pBtCoexist, assoType);
2908                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2909                         ex_halbtc8723b1ant_connect_notify(pBtCoexist, assoType);
2910         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2911                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2912                         ex_halbtc8703b1ant_connect_notify(pBtCoexist, assoType);
2913         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2914                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2915                         ex_halbtc8723d2ant_connect_notify(pBtCoexist, assoType);
2916                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2917                         ex_halbtc8723d1ant_connect_notify(pBtCoexist, assoType);
2918         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2919                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2920                         ex_halbtc8192e2ant_connect_notify(pBtCoexist, assoType);
2921                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2922                         ex_halbtc8192e1ant_connect_notify(pBtCoexist, assoType);
2923         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2924                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2925                         ex_halbtc8812a2ant_connect_notify(pBtCoexist, assoType);
2926                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2927                         ex_halbtc8812a1ant_connect_notify(pBtCoexist, assoType);
2928         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2929                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2930                         ex_halbtc8822b1ant_connect_notify(pBtCoexist, assoType);
2931                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2932                         ex_halbtc8822b2ant_connect_notify(pBtCoexist, assoType);
2933         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
2934                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2935                         ex_halbtc8821c2ant_connect_notify(pBtCoexist, assoType);
2936                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2937                         ex_halbtc8821c1ant_connect_notify(pBtCoexist, assoType);
2938         }
2939
2940         /*      halbtcoutsrc_NormalLowPower(pBtCoexist); */
2941 }
2942
2943 void EXhalbtcoutsrc_media_status_notify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
2944 {
2945         u8 mStatus;
2946
2947         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2948                 return;
2949
2950         pBtCoexist->statistics.cnt_media_status_notify++;
2951         if (pBtCoexist->manual_control)
2952                 return;
2953
2954         if (RT_MEDIA_CONNECT == mediaStatus)
2955                 mStatus = BTC_MEDIA_CONNECT;
2956         else
2957                 mStatus = BTC_MEDIA_DISCONNECT;
2958
2959         /* All notify is called in cmd thread, don't need to leave low power again
2960         *       halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2961
2962         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2963 #if 0
2964                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2965                         ex_halbtc8821aCsr2ant_media_status_notify(pBtCoexist, mStatus);
2966                 else
2967 #endif
2968                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2969                         ex_halbtc8821a2ant_media_status_notify(pBtCoexist, mStatus);
2970                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2971                         ex_halbtc8821a1ant_media_status_notify(pBtCoexist, mStatus);
2972         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
2973                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2974                         ex_halbtc8723b2ant_media_status_notify(pBtCoexist, mStatus);
2975                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2976                         ex_halbtc8723b1ant_media_status_notify(pBtCoexist, mStatus);
2977         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
2978                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2979                         ex_halbtc8703b1ant_media_status_notify(pBtCoexist, mStatus);
2980         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
2981                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2982                         ex_halbtc8723d2ant_media_status_notify(pBtCoexist, mStatus);
2983                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2984                         ex_halbtc8723d1ant_media_status_notify(pBtCoexist, mStatus);
2985         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
2986                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2987                         ex_halbtc8192e2ant_media_status_notify(pBtCoexist, mStatus);
2988                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2989                         ex_halbtc8192e1ant_media_status_notify(pBtCoexist, mStatus);
2990         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
2991                 if (pBtCoexist->board_info.btdm_ant_num == 2)
2992                         ex_halbtc8812a2ant_media_status_notify(pBtCoexist, mStatus);
2993                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
2994                         ex_halbtc8812a1ant_media_status_notify(pBtCoexist, mStatus);
2995         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
2996                 if (pBtCoexist->board_info.btdm_ant_num == 1)
2997                         ex_halbtc8822b1ant_media_status_notify(pBtCoexist, mStatus);
2998                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
2999                         ex_halbtc8822b2ant_media_status_notify(pBtCoexist, mStatus);
3000         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3001                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3002                         ex_halbtc8821c2ant_media_status_notify(pBtCoexist, mStatus);
3003                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3004                         ex_halbtc8821c1ant_media_status_notify(pBtCoexist, mStatus);
3005         }
3006
3007         /*      halbtcoutsrc_NormalLowPower(pBtCoexist); */
3008 }
3009
3010 void EXhalbtcoutsrc_specific_packet_notify(PBTC_COEXIST pBtCoexist, u8 pktType)
3011 {
3012         u8      packetType;
3013
3014         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3015                 return;
3016         pBtCoexist->statistics.cnt_specific_packet_notify++;
3017         if (pBtCoexist->manual_control)
3018                 return;
3019
3020         if (PACKET_DHCP == pktType)
3021                 packetType = BTC_PACKET_DHCP;
3022         else if (PACKET_EAPOL == pktType)
3023                 packetType = BTC_PACKET_EAPOL;
3024         else if (PACKET_ARP == pktType)
3025                 packetType = BTC_PACKET_ARP;
3026         else {
3027                 packetType = BTC_PACKET_UNKNOWN;
3028                 return;
3029         }
3030
3031         /* All notify is called in cmd thread, don't need to leave low power again
3032         *       halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3033
3034         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3035 #if 0
3036                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3037                         ex_halbtc8821aCsr2ant_specific_packet_notify(pBtCoexist, packetType);
3038                 else
3039 #endif
3040                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3041                         ex_halbtc8821a2ant_specific_packet_notify(pBtCoexist, packetType);
3042                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3043                         ex_halbtc8821a1ant_specific_packet_notify(pBtCoexist, packetType);
3044         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3045                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3046                         ex_halbtc8723b2ant_specific_packet_notify(pBtCoexist, packetType);
3047                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3048                         ex_halbtc8723b1ant_specific_packet_notify(pBtCoexist, packetType);
3049         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3050                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3051                         ex_halbtc8703b1ant_specific_packet_notify(pBtCoexist, packetType);
3052         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3053                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3054                         ex_halbtc8723d2ant_specific_packet_notify(pBtCoexist, packetType);
3055                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3056                         ex_halbtc8723d1ant_specific_packet_notify(pBtCoexist, packetType);
3057         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3058                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3059                         ex_halbtc8192e2ant_specific_packet_notify(pBtCoexist, packetType);
3060                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3061                         ex_halbtc8192e1ant_specific_packet_notify(pBtCoexist, packetType);
3062         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3063                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3064                         ex_halbtc8812a2ant_specific_packet_notify(pBtCoexist, packetType);
3065                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3066                         ex_halbtc8812a1ant_specific_packet_notify(pBtCoexist, packetType);
3067         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3068                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3069                         ex_halbtc8822b1ant_specific_packet_notify(pBtCoexist, packetType);
3070                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3071                         ex_halbtc8822b2ant_specific_packet_notify(pBtCoexist, packetType);
3072         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3073                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3074                         ex_halbtc8821c2ant_specific_packet_notify(pBtCoexist, packetType);
3075                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3076                         ex_halbtc8821c1ant_specific_packet_notify(pBtCoexist, packetType);
3077         }
3078
3079         /*      halbtcoutsrc_NormalLowPower(pBtCoexist); */
3080 }
3081
3082 void EXhalbtcoutsrc_bt_info_notify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
3083 {
3084         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3085                 return;
3086
3087         pBtCoexist->statistics.cnt_bt_info_notify++;
3088
3089         /* All notify is called in cmd thread, don't need to leave low power again
3090         *       halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3091
3092         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3093 #if 0
3094                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3095                         ex_halbtc8821aCsr2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3096                 else
3097 #endif
3098                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3099                         ex_halbtc8821a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3100                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3101                         ex_halbtc8821a1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3102         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3103                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3104                         ex_halbtc8723b2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3105                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3106                         ex_halbtc8723b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3107         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3108                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3109                         ex_halbtc8703b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3110         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3111                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3112                         ex_halbtc8723d2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3113                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3114                         ex_halbtc8723d1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3115         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3116                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3117                         ex_halbtc8192e2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3118                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3119                         ex_halbtc8192e1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3120         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3121                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3122                         ex_halbtc8812a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3123                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3124                         ex_halbtc8812a1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3125         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3126                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3127                         ex_halbtc8822b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3128                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3129                         ex_halbtc8822b2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3130         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3131                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3132                         ex_halbtc8821c2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3133                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3134                         ex_halbtc8821c1ant_bt_info_notify(pBtCoexist, tmpBuf, length);
3135         }
3136
3137         /*      halbtcoutsrc_NormalLowPower(pBtCoexist); */
3138 }
3139
3140 VOID
3141 EXhalbtcoutsrc_RfStatusNotify(
3142         IN      PBTC_COEXIST            pBtCoexist,
3143         IN      u1Byte                          type
3144 )
3145 {
3146         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3147                 return;
3148         pBtCoexist->statistics.cnt_rf_status_notify++;
3149
3150         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3151         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3152                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3153                         ex_halbtc8723b1ant_rf_status_notify(pBtCoexist, type);
3154         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3155                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3156                         ex_halbtc8703b1ant_rf_status_notify(pBtCoexist, type);
3157         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3158                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3159                         ex_halbtc8723d1ant_rf_status_notify(pBtCoexist, type);
3160         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3161         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3162         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3163                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3164                         ex_halbtc8822b1ant_rf_status_notify(pBtCoexist, type);
3165                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3166                         ex_halbtc8822b2ant_rf_status_notify(pBtCoexist, type);
3167         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3168                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3169                         ex_halbtc8821c2ant_rf_status_notify(pBtCoexist, type);
3170                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3171                         ex_halbtc8821c1ant_rf_status_notify(pBtCoexist, type);
3172         }
3173 }
3174
3175 void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)
3176 {
3177 #if 0
3178         u8      stackOpType;
3179
3180         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3181                 return;
3182         pBtCoexist->statistics.cntStackOperationNotify++;
3183         if (pBtCoexist->manual_control)
3184                 return;
3185
3186         if ((HCI_BT_OP_INQUIRY_START == type) ||
3187             (HCI_BT_OP_PAGING_START == type) ||
3188             (HCI_BT_OP_PAIRING_START == type))
3189                 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START;
3190         else if ((HCI_BT_OP_INQUIRY_FINISH == type) ||
3191                  (HCI_BT_OP_PAGING_SUCCESS == type) ||
3192                  (HCI_BT_OP_PAGING_UNSUCCESS == type) ||
3193                  (HCI_BT_OP_PAIRING_FINISH == type))
3194                 stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;
3195         else
3196                 stackOpType = BTC_STACK_OP_NONE;
3197
3198 #endif
3199 }
3200
3201 void EXhalbtcoutsrc_halt_notify(PBTC_COEXIST pBtCoexist)
3202 {
3203         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3204                 return;
3205
3206         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3207 #if 0
3208                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3209                         ex_halbtc8821aCsr2ant_halt_notify(pBtCoexist);
3210                 else
3211 #endif
3212                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3213                         ex_halbtc8821a2ant_halt_notify(pBtCoexist);
3214                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3215                         ex_halbtc8821a1ant_halt_notify(pBtCoexist);
3216         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3217                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3218                         ex_halbtc8723b2ant_halt_notify(pBtCoexist);
3219                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3220                         ex_halbtc8723b1ant_halt_notify(pBtCoexist);
3221         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3222                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3223                         ex_halbtc8703b1ant_halt_notify(pBtCoexist);
3224         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3225                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3226                         ex_halbtc8723d2ant_halt_notify(pBtCoexist);
3227                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3228                         ex_halbtc8723d1ant_halt_notify(pBtCoexist);
3229         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3230                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3231                         ex_halbtc8192e2ant_halt_notify(pBtCoexist);
3232                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3233                         ex_halbtc8192e1ant_halt_notify(pBtCoexist);
3234         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3235                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3236                         ex_halbtc8812a2ant_halt_notify(pBtCoexist);
3237                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3238                         ex_halbtc8812a1ant_halt_notify(pBtCoexist);
3239         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3240                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3241                         ex_halbtc8822b1ant_halt_notify(pBtCoexist);
3242                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3243                         ex_halbtc8822b2ant_halt_notify(pBtCoexist);
3244         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3245                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3246                         ex_halbtc8821c2ant_halt_notify(pBtCoexist);
3247                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3248                         ex_halbtc8821c1ant_halt_notify(pBtCoexist);
3249         }
3250 }
3251
3252 void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)
3253 {
3254         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3255                 if (pBtCoexist->board_info.btdm_ant_num == 2) {
3256                         halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); /* BT goto standby while GNT_BT 1-->0 */
3257                 } else if (pBtCoexist->board_info.btdm_ant_num == 1) {
3258                         halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); /* BT goto standby while GNT_BT 1-->0 */
3259                 }
3260         }
3261 }
3262
3263 void EXhalbtcoutsrc_pnp_notify(PBTC_COEXIST pBtCoexist, u8 pnpState)
3264 {
3265         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3266                 return;
3267
3268         /*  */
3269         /* currently only 1ant we have to do the notification, */
3270         /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */
3271         /*  */
3272
3273         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3274                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3275                         ex_halbtc8723b1ant_pnp_notify(pBtCoexist, pnpState);
3276                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3277                         ex_halbtc8723b2ant_pnp_notify(pBtCoexist, pnpState);
3278         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3279                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3280                         ex_halbtc8703b1ant_pnp_notify(pBtCoexist, pnpState);
3281         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3282                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3283                         ex_halbtc8723d1ant_pnp_notify(pBtCoexist, pnpState);
3284                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3285                         ex_halbtc8723d2ant_pnp_notify(pBtCoexist, pnpState);
3286         } else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3287 #if 0
3288                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3289                         ex_halbtc8821aCsr2ant_pnp_notify(pBtCoexist, pnpState);
3290                 else
3291 #endif
3292                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3293                         ex_halbtc8821a1ant_pnp_notify(pBtCoexist, pnpState);
3294                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3295                         ex_halbtc8821a2ant_pnp_notify(pBtCoexist, pnpState);
3296         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3297                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3298                         ex_halbtc8192e1ant_pnp_notify(pBtCoexist, pnpState);
3299         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3300                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3301                         ex_halbtc8812a1ant_pnp_notify(pBtCoexist, pnpState);
3302         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3303                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3304                         ex_halbtc8822b1ant_pnp_notify(pBtCoexist, pnpState);
3305                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3306                         ex_halbtc8822b2ant_pnp_notify(pBtCoexist, pnpState);
3307         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3308                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3309                         ex_halbtc8821c2ant_pnp_notify(pBtCoexist, pnpState);
3310                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3311                         ex_halbtc8821c1ant_pnp_notify(pBtCoexist, pnpState);
3312         }
3313 }
3314
3315 void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)
3316 {
3317         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3318                 return;
3319         pBtCoexist->statistics.cnt_coex_dm_switch++;
3320
3321         halbtcoutsrc_LeaveLowPower(pBtCoexist);
3322
3323         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3324                 if (pBtCoexist->board_info.btdm_ant_num == 1) {
3325                         pBtCoexist->stop_coex_dm = TRUE;
3326                         ex_halbtc8723b1ant_coex_dm_reset(pBtCoexist);
3327                         EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
3328                         ex_halbtc8723b2ant_init_hw_config(pBtCoexist, FALSE);
3329                         ex_halbtc8723b2ant_init_coex_dm(pBtCoexist);
3330                         pBtCoexist->stop_coex_dm = FALSE;
3331                 }
3332         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3333                 if (pBtCoexist->board_info.btdm_ant_num == 1) {
3334                         pBtCoexist->stop_coex_dm = TRUE;
3335                         ex_halbtc8723d1ant_coex_dm_reset(pBtCoexist);
3336                         EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);
3337                         ex_halbtc8723d2ant_init_hw_config(pBtCoexist, FALSE);
3338                         ex_halbtc8723d2ant_init_coex_dm(pBtCoexist);
3339                         pBtCoexist->stop_coex_dm = FALSE;
3340                 }
3341         }
3342
3343         halbtcoutsrc_NormalLowPower(pBtCoexist);
3344 }
3345
3346 void EXhalbtcoutsrc_periodical(PBTC_COEXIST pBtCoexist)
3347 {
3348         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3349                 return;
3350         pBtCoexist->statistics.cnt_periodical++;
3351
3352         /* Periodical should be called in cmd thread, */
3353         /* don't need to leave low power again
3354         *       halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3355
3356         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3357 #if 0
3358                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3359                         ex_halbtc8821aCsr2ant_periodical(pBtCoexist);
3360                 else
3361 #endif
3362                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3363                         ex_halbtc8821a2ant_periodical(pBtCoexist);
3364                 else if (pBtCoexist->board_info.btdm_ant_num == 1) {
3365                         if (!halbtcoutsrc_UnderIps(pBtCoexist))
3366                                 ex_halbtc8821a1ant_periodical(pBtCoexist);
3367                 }
3368         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3369                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3370                         ex_halbtc8723b2ant_periodical(pBtCoexist);
3371                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3372                         ex_halbtc8723b1ant_periodical(pBtCoexist);
3373         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3374                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3375                         ex_halbtc8723d2ant_periodical(pBtCoexist);
3376                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3377                         ex_halbtc8723d1ant_periodical(pBtCoexist);
3378         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3379                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3380                         ex_halbtc8703b1ant_periodical(pBtCoexist);
3381         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3382                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3383                         ex_halbtc8192e2ant_periodical(pBtCoexist);
3384                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3385                         ex_halbtc8192e1ant_periodical(pBtCoexist);
3386         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3387                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3388                         ex_halbtc8812a2ant_periodical(pBtCoexist);
3389                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3390                         ex_halbtc8812a1ant_periodical(pBtCoexist);
3391         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3392                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3393                         ex_halbtc8822b1ant_periodical(pBtCoexist);
3394                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3395                         ex_halbtc8822b2ant_periodical(pBtCoexist);
3396         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3397                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3398                         ex_halbtc8821c2ant_periodical(pBtCoexist);
3399                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3400                         ex_halbtc8821c1ant_periodical(pBtCoexist);
3401         }
3402
3403         /*      halbtcoutsrc_NormalLowPower(pBtCoexist); */
3404 }
3405
3406 void EXhalbtcoutsrc_dbg_control(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)
3407 {
3408         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3409                 return;
3410
3411         pBtCoexist->statistics.cnt_dbg_ctrl++;
3412
3413         /* This function doesn't be called yet, */
3414         /* default no need to leave low power to avoid deadlock
3415         *       halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3416
3417         if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3418                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3419                         ex_halbtc8192e1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
3420         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3421                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3422                         ex_halbtc8812a2ant_dbg_control(pBtCoexist, opCode, opLen, pData);
3423                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3424                         ex_halbtc8812a1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
3425         } else if(IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter))
3426                 if(pBtCoexist->board_info.btdm_ant_num == 1)
3427                         ex_halbtc8822b1ant_dbg_control(pBtCoexist, opCode, opLen, pData);
3428
3429         /*      halbtcoutsrc_NormalLowPower(pBtCoexist); */
3430 }
3431
3432 #if 0
3433 VOID
3434 EXhalbtcoutsrc_AntennaDetection(
3435         IN      PBTC_COEXIST                    pBtCoexist,
3436         IN      u4Byte                                  centFreq,
3437         IN      u4Byte                                  offset,
3438         IN      u4Byte                                  span,
3439         IN      u4Byte                                  seconds
3440 )
3441 {
3442         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3443                 return;
3444
3445         /* Need to refine the following power save operations to enable this function in the future */
3446 #if 0
3447         IPSDisable(pBtCoexist->Adapter, FALSE, 0);
3448         LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);
3449 #endif
3450
3451         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3452                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3453                         ex_halbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds);
3454         }
3455
3456         /* IPSReturn(pBtCoexist->Adapter, 0xff); */
3457 }
3458 #endif
3459
3460 void EXhalbtcoutsrc_StackUpdateProfileInfo(void)
3461 {
3462 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
3463         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3464         PADAPTER padapter = (PADAPTER)GLBtCoexist.Adapter;
3465         PBT_MGNT pBtMgnt = &padapter->coex_info.BtMgnt;
3466         u8 i;
3467
3468         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3469                 return;
3470
3471         pBtCoexist->stack_info.profile_notified = _TRUE;
3472
3473         pBtCoexist->stack_info.num_of_link =
3474                 pBtMgnt->ExtConfig.NumberOfACL + pBtMgnt->ExtConfig.NumberOfSCO;
3475
3476         /* reset first */
3477         pBtCoexist->stack_info.bt_link_exist = _FALSE;
3478         pBtCoexist->stack_info.sco_exist = _FALSE;
3479         pBtCoexist->stack_info.acl_exist = _FALSE;
3480         pBtCoexist->stack_info.a2dp_exist = _FALSE;
3481         pBtCoexist->stack_info.hid_exist = _FALSE;
3482         pBtCoexist->stack_info.num_of_hid = 0;
3483         pBtCoexist->stack_info.pan_exist = _FALSE;
3484
3485         if (!pBtMgnt->ExtConfig.NumberOfACL)
3486                 pBtCoexist->stack_info.min_bt_rssi = 0;
3487
3488         if (pBtCoexist->stack_info.num_of_link) {
3489                 pBtCoexist->stack_info.bt_link_exist = _TRUE;
3490                 if (pBtMgnt->ExtConfig.NumberOfSCO)
3491                         pBtCoexist->stack_info.sco_exist = _TRUE;
3492                 if (pBtMgnt->ExtConfig.NumberOfACL)
3493                         pBtCoexist->stack_info.acl_exist = _TRUE;
3494         }
3495
3496         for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {
3497                 if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
3498                         pBtCoexist->stack_info.a2dp_exist = _TRUE;
3499                 else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile)
3500                         pBtCoexist->stack_info.pan_exist = _TRUE;
3501                 else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile) {
3502                         pBtCoexist->stack_info.hid_exist = _TRUE;
3503                         pBtCoexist->stack_info.num_of_hid++;
3504                 } else
3505                         pBtCoexist->stack_info.unknown_acl_exist = _TRUE;
3506         }
3507 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
3508 }
3509
3510 void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)
3511 {
3512         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3513
3514         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3515                 return;
3516
3517         pBtCoexist->stack_info.min_bt_rssi = btRssi;
3518 }
3519
3520 void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)
3521 {
3522         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3523
3524         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3525                 return;
3526
3527         pBtCoexist->stack_info.hci_version = hciVersion;
3528 }
3529
3530 void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)
3531 {
3532         PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3533
3534         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3535                 return;
3536
3537         pBtCoexist->bt_info.bt_real_fw_ver = btPatchVersion;
3538         pBtCoexist->bt_info.bt_hci_ver = btHciVersion;
3539 }
3540
3541 #if 0
3542 void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)
3543 {
3544         GLBtCoexist.boardInfo.bBtExist = bBtExist;
3545 }
3546 #endif
3547 void EXhalbtcoutsrc_SetChipType(u8 chipType)
3548 {
3549         switch (chipType) {
3550         default:
3551         case BT_2WIRE:
3552         case BT_ISSC_3WIRE:
3553         case BT_ACCEL:
3554         case BT_RTL8756:
3555                 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
3556                 break;
3557         case BT_CSR_BC4:
3558                 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
3559                 break;
3560         case BT_CSR_BC8:
3561                 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
3562                 break;
3563         case BT_RTL8723A:
3564                 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
3565                 break;
3566         case BT_RTL8821:
3567                 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
3568                 break;
3569         case BT_RTL8723B:
3570                 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
3571                 break;
3572         }
3573 }
3574
3575 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
3576 {
3577         if (BT_COEX_ANT_TYPE_PG == type) {
3578                 GLBtCoexist.board_info.pg_ant_num = antNum;
3579                 GLBtCoexist.board_info.btdm_ant_num = antNum;
3580 #if 0
3581                 /* The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1 */
3582                 /* The antenna position should be determined by auto-detect mechanism */
3583                 /* The following is assumed to main, and those must be modified if y auto-detect mechanism is ready */
3584                 if ((GLBtCoexist.board_info.pg_ant_num == 2) && (GLBtCoexist.board_info.btdm_ant_num == 1))
3585                         GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
3586                 else
3587                         GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
3588 #endif
3589         } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
3590                 GLBtCoexist.board_info.btdm_ant_num = antNum;
3591                 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;  */
3592         } else if (BT_COEX_ANT_TYPE_DETECTED == type) {
3593                 GLBtCoexist.board_info.btdm_ant_num = antNum;
3594                 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */
3595         }
3596 }
3597
3598 /*
3599  * Currently used by 8723b only, S0 or S1
3600  *   */
3601 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
3602 {
3603         GLBtCoexist.board_info.single_ant_path = singleAntPath;
3604 }
3605
3606 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
3607 {
3608         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3609                 return;
3610
3611         halbtcoutsrc_LeaveLowPower(pBtCoexist);
3612
3613         /* To prevent the racing with IPS enter */
3614         halbtcoutsrc_EnterPwrLock(pBtCoexist);
3615
3616         if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3617 #if 0
3618                 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3619                         ex_halbtc8821aCsr2ant_display_coex_info(pBtCoexist);
3620                 else
3621 #endif
3622                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3623                         ex_halbtc8821a2ant_display_coex_info(pBtCoexist);
3624                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3625                         ex_halbtc8821a1ant_display_coex_info(pBtCoexist);
3626         } else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3627                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3628                         ex_halbtc8723b2ant_display_coex_info(pBtCoexist);
3629                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3630                         ex_halbtc8723b1ant_display_coex_info(pBtCoexist);
3631         } else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {
3632                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3633                         ex_halbtc8703b1ant_display_coex_info(pBtCoexist);
3634         } else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {
3635                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3636                         ex_halbtc8723d2ant_display_coex_info(pBtCoexist);
3637                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3638                         ex_halbtc8723d1ant_display_coex_info(pBtCoexist);
3639         } else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {
3640                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3641                         ex_halbtc8192e2ant_display_coex_info(pBtCoexist);
3642                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3643                         ex_halbtc8192e1ant_display_coex_info(pBtCoexist);
3644         } else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3645                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3646                         ex_halbtc8812a2ant_display_coex_info(pBtCoexist);
3647                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3648                         ex_halbtc8812a1ant_display_coex_info(pBtCoexist);
3649         } else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3650                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3651                         ex_halbtc8822b1ant_display_coex_info(pBtCoexist);
3652                 else if (pBtCoexist->board_info.btdm_ant_num == 2)
3653                         ex_halbtc8822b2ant_display_coex_info(pBtCoexist);
3654         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3655                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3656                         ex_halbtc8821c2ant_display_coex_info(pBtCoexist);
3657                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3658                         ex_halbtc8821c1ant_display_coex_info(pBtCoexist);
3659         }
3660
3661         halbtcoutsrc_ExitPwrLock(pBtCoexist);
3662
3663         halbtcoutsrc_NormalLowPower(pBtCoexist);
3664 }
3665
3666 void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)
3667 {
3668         if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3669                 return;
3670
3671         halbtcoutsrc_LeaveLowPower(pBtCoexist);
3672
3673         if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
3674                 if (pBtCoexist->board_info.btdm_ant_num == 1)
3675                         ex_halbtc8723b1ant_display_ant_detection(pBtCoexist);
3676         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3677                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3678                         ex_halbtc8821c2ant_display_ant_detection(pBtCoexist);
3679                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3680                         ex_halbtc8821c1ant_display_ant_detection(pBtCoexist);
3681         }
3682
3683         halbtcoutsrc_NormalLowPower(pBtCoexist);
3684 }
3685
3686 void ex_halbtcoutsrc_pta_off_on_notify(PBTC_COEXIST pBtCoexist, u8 bBTON)
3687 {
3688         if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {
3689                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3690                         ex_halbtc8812a2ant_pta_off_on_notify(pBtCoexist, (bBTON == _TRUE) ? BTC_BT_ON : BTC_BT_OFF);
3691         }
3692 }
3693
3694 void EXhalbtcoutsrc_set_rfe_type(u8 type)
3695 {
3696         GLBtCoexist.board_info.rfe_type= type;
3697 }
3698
3699 void EXhalbtcoutsrc_switchband_notify(struct btc_coexist *pBtCoexist, u8 type)
3700 {
3701         if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3702                 return;
3703         
3704         if(pBtCoexist->manual_control)
3705                 return;
3706
3707         /* Driver should guarantee that the HW status isn't in low power mode */
3708         /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3709
3710         if(IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {
3711                 if(pBtCoexist->board_info.btdm_ant_num == 1)
3712                         ex_halbtc8822b1ant_switchband_notify(pBtCoexist, type);
3713                 else if(pBtCoexist->board_info.btdm_ant_num == 2)
3714                         ex_halbtc8822b2ant_switchband_notify(pBtCoexist, type);
3715         } else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
3716                 if (pBtCoexist->board_info.btdm_ant_num == 2)
3717                         ex_halbtc8821c2ant_switchband_notify(pBtCoexist, type);
3718                 else if (pBtCoexist->board_info.btdm_ant_num == 1)
3719                         ex_halbtc8821c1ant_switchband_notify(pBtCoexist, type);
3720         }
3721
3722         /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
3723 }
3724
3725 static void halbt_init_hw_config92C(PADAPTER padapter)
3726 {
3727         PHAL_DATA_TYPE pHalData;
3728         u8 u1Tmp;
3729
3730
3731         pHalData = GET_HAL_DATA(padapter);
3732         if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
3733             (pHalData->bt_coexist.btChipType == BT_CSR_BC8)) {
3734                 if (pHalData->rf_type == RF_1T1R) {
3735                         /* Config to 1T1R */
3736                         u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
3737                         u1Tmp &= ~BIT(1);
3738                         rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
3739                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
3740
3741                         u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
3742                         u1Tmp &= ~BIT(1);
3743                         rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
3744                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
3745                 }
3746         }
3747 }
3748
3749 static void halbt_init_hw_config92D(PADAPTER padapter)
3750 {
3751         PHAL_DATA_TYPE pHalData;
3752         u8 u1Tmp;
3753
3754         pHalData = GET_HAL_DATA(padapter);
3755         if ((pHalData->bt_coexist.btChipType == BT_CSR_BC4) ||
3756             (pHalData->bt_coexist.btChipType == BT_CSR_BC8)) {
3757                 if (pHalData->rf_type == RF_1T1R) {
3758                         /* Config to 1T1R */
3759                         u1Tmp = rtw_read8(padapter, rOFDM0_TRxPathEnable);
3760                         u1Tmp &= ~BIT(1);
3761                         rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
3762                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
3763
3764                         u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
3765                         u1Tmp &= ~BIT(1);
3766                         rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
3767                         RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
3768                 }
3769         }
3770 }
3771
3772 /*
3773  * Description:
3774  *      Run BT-Coexist mechansim or not
3775  *
3776  */
3777 void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)
3778 {
3779         PHAL_DATA_TYPE  pHalData;
3780
3781
3782         pHalData = GET_HAL_DATA(padapter);
3783         pHalData->bt_coexist.bBtExist = bBtExist;
3784 }
3785
3786 /*
3787  * Dewcription:
3788  *      Check is co-exist mechanism enabled or not
3789  *
3790  * Return:
3791  *      _TRUE   Enable BT co-exist mechanism
3792  *      _FALSE  Disable BT co-exist mechanism
3793  */
3794 u8 hal_btcoex_IsBtExist(PADAPTER padapter)
3795 {
3796         PHAL_DATA_TYPE  pHalData;
3797
3798
3799         pHalData = GET_HAL_DATA(padapter);
3800         return pHalData->bt_coexist.bBtExist;
3801 }
3802
3803 u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)
3804 {
3805         if (!hal_btcoex_IsBtExist(padapter))
3806                 return _TRUE;
3807
3808         if (GLBtCoexist.bt_info.bt_disabled)
3809                 return _TRUE;
3810         else
3811                 return _FALSE;
3812 }
3813
3814 void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)
3815 {
3816         PHAL_DATA_TYPE  pHalData;
3817
3818         pHalData = GET_HAL_DATA(padapter);
3819         pHalData->bt_coexist.btChipType = chipType;
3820 }
3821
3822 void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)
3823 {
3824         PHAL_DATA_TYPE  pHalData;
3825
3826         pHalData = GET_HAL_DATA(padapter);
3827
3828         pHalData->bt_coexist.btTotalAntNum = antNum;
3829 }
3830
3831 u8 hal_btcoex_Initialize(PADAPTER padapter)
3832 {
3833         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(padapter);
3834         u8 ret;
3835
3836         _rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
3837
3838         hal_btcoex_SetBTCoexist(padapter, rtw_btcoex_get_bt_coexist(padapter));
3839         hal_btcoex_SetChipType(padapter, rtw_btcoex_get_chip_type(padapter));
3840         hal_btcoex_SetPgAntNum(padapter, rtw_btcoex_get_pg_ant_num(padapter));
3841         
3842         ret = EXhalbtcoutsrc_InitlizeVariables((void *)padapter);
3843
3844         return ret;
3845 }
3846
3847 void hal_btcoex_PowerOnSetting(PADAPTER padapter)
3848 {
3849         EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
3850 }
3851
3852 void hal_btcoex_PowerOffSetting(PADAPTER padapter)
3853 {
3854         /* Clear the WiFi on/off bit in scoreboard reg. if necessary */
3855         if (IS_HARDWARE_TYPE_8703B(padapter) || IS_HARDWARE_TYPE_8723D(padapter)
3856                 || IS_HARDWARE_TYPE_8821C(padapter) || IS_HARDWARE_TYPE_8822B(padapter))
3857                 rtw_write16(padapter, 0xaa, 0x8000);
3858 }
3859
3860 void hal_btcoex_PreLoadFirmware(PADAPTER padapter)
3861 {
3862         EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);
3863 }
3864
3865 void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)
3866 {
3867         if (!hal_btcoex_IsBtExist(padapter))
3868                 return;
3869
3870         EXhalbtcoutsrc_init_hw_config(&GLBtCoexist, bWifiOnly);
3871         EXhalbtcoutsrc_init_coex_dm(&GLBtCoexist);
3872 }
3873
3874 void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)
3875 {
3876         EXhalbtcoutsrc_ips_notify(&GLBtCoexist, type);
3877 }
3878
3879 void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)
3880 {
3881         EXhalbtcoutsrc_lps_notify(&GLBtCoexist, type);
3882 }
3883
3884 void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)
3885 {
3886         EXhalbtcoutsrc_scan_notify(&GLBtCoexist, type);
3887 }
3888
3889 void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
3890 {
3891         EXhalbtcoutsrc_connect_notify(&GLBtCoexist, action);
3892 }
3893
3894 void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
3895 {
3896         EXhalbtcoutsrc_media_status_notify(&GLBtCoexist, mediaStatus);
3897 }
3898
3899 void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
3900 {
3901         EXhalbtcoutsrc_specific_packet_notify(&GLBtCoexist, pktType);
3902 }
3903
3904 void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)
3905 {
3906         GLBtcWiFiInIQKState = state;
3907 }
3908
3909 void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3910 {
3911         if (GLBtcWiFiInIQKState == _TRUE)
3912                 return;
3913
3914         EXhalbtcoutsrc_bt_info_notify(&GLBtCoexist, tmpBuf, length);
3915 }
3916
3917 void hal_btcoex_BtMpRptNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3918 {
3919         u8 extid, status, len, seq;
3920
3921
3922         if (!GLBtcBtMpRptWait)
3923                 return;
3924
3925         if ((length < 3) || (!tmpBuf))
3926                 return;
3927
3928         extid = tmpBuf[0];
3929         /* not response from BT FW then exit*/
3930         switch (extid) {
3931         case C2H_WIFI_FW_ACTIVE_RSP:
3932                 GLBtcBtMpRptWiFiOK = 1;
3933                 return;
3934
3935         case C2H_TRIG_BY_BT_FW:
3936                 _cancel_timer_ex(&GLBtcBtMpOperTimer);
3937                 GLBtcBtMpRptWait = 0;
3938                 GLBtcBtMpRptBTOK = 1;
3939                 break;
3940
3941         default:
3942                 return;
3943         }
3944
3945         status = tmpBuf[1] & 0xF;
3946         len = length - 3;
3947         seq = tmpBuf[2] >> 4;
3948
3949         GLBtcBtMpRptSeq = seq;
3950         GLBtcBtMpRptStatus = status;
3951         _rtw_memcpy(GLBtcBtMpRptRsp, tmpBuf + 3, len);
3952         GLBtcBtMpRptRspSize = len;
3953         _rtw_up_sema(&GLBtcBtMpRptSema);
3954 }
3955
3956 void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
3957 {
3958         switch (state) {
3959         case BTCOEX_SUSPEND_STATE_SUSPEND:
3960                 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);
3961                 break;
3962         case BTCOEX_SUSPEND_STATE_SUSPEND_KEEP_ANT:
3963                 /* should switch to "#if 1" once all ICs' coex. revision are upgraded to support the KEEP_ANT case */
3964 #if 0
3965                 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);
3966 #else
3967                 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);
3968                 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);
3969 #endif
3970                 break;
3971         case BTCOEX_SUSPEND_STATE_RESUME:
3972                 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_WAKE_UP);
3973                 break;
3974         }
3975 }
3976
3977 void hal_btcoex_HaltNotify(PADAPTER padapter, u8 do_halt)
3978 {
3979         if (do_halt == 1)
3980                 EXhalbtcoutsrc_halt_notify(&GLBtCoexist);
3981
3982         GLBtCoexist.bBinded = _FALSE;
3983         GLBtCoexist.Adapter = NULL;
3984 }
3985
3986 void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)
3987 {
3988         EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);
3989 }
3990
3991 void hal_btcoex_Hanlder(PADAPTER padapter)
3992 {
3993         u32     bt_patch_ver;
3994
3995         EXhalbtcoutsrc_periodical(&GLBtCoexist);
3996
3997         if (GLBtCoexist.bt_info.bt_get_fw_ver == 0) {
3998                 GLBtCoexist.btc_get(&GLBtCoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);
3999                 GLBtCoexist.bt_info.bt_get_fw_ver = bt_patch_ver;
4000         }
4001 }
4002
4003 s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)
4004 {
4005         return (s32)GLBtCoexist.bt_info.reject_agg_pkt;
4006 }
4007
4008 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
4009 {
4010         return (s32)GLBtCoexist.bt_info.bt_ctrl_agg_buf_size;
4011 }
4012
4013 u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)
4014 {
4015         return (u32)GLBtCoexist.bt_info.agg_buf_size;
4016 }
4017
4018 void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)
4019 {
4020         GLBtCoexist.manual_control = bmanual;
4021 }
4022
4023 u8 hal_btcoex_1Ant(PADAPTER padapter)
4024 {
4025         if (hal_btcoex_IsBtExist(padapter) == _FALSE)
4026                 return _FALSE;
4027
4028         if (GLBtCoexist.board_info.btdm_ant_num == 1)
4029                 return _TRUE;
4030
4031         return _FALSE;
4032 }
4033
4034 u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)
4035 {
4036         if (GLBtCoexist.bdontenterLPS == _TRUE)
4037                 return _TRUE;
4038         
4039         if (hal_btcoex_IsBtExist(padapter) == _FALSE)
4040                 return _FALSE;
4041
4042         if (GLBtCoexist.bt_info.bt_disabled)
4043                 return _FALSE;
4044
4045         if (GLBtCoexist.bt_info.bt_ctrl_lps)
4046                 return _TRUE;
4047
4048         return _FALSE;
4049 }
4050
4051 u8 hal_btcoex_IsLpsOn(PADAPTER padapter)
4052 {
4053         if (GLBtCoexist.bdontenterLPS == _TRUE)
4054                 return _FALSE;
4055         
4056         if (hal_btcoex_IsBtExist(padapter) == _FALSE)
4057                 return _FALSE;
4058
4059         if (GLBtCoexist.bt_info.bt_disabled)
4060                 return _FALSE;
4061
4062         if (GLBtCoexist.bt_info.bt_lps_on)
4063                 return _TRUE;
4064
4065         return _FALSE;
4066 }
4067
4068 u8 hal_btcoex_RpwmVal(PADAPTER padapter)
4069 {
4070         return GLBtCoexist.bt_info.rpwm_val;
4071 }
4072
4073 u8 hal_btcoex_LpsVal(PADAPTER padapter)
4074 {
4075         return GLBtCoexist.bt_info.lps_val;
4076 }
4077
4078 u32 hal_btcoex_GetRaMask(PADAPTER padapter)
4079 {
4080         if (!hal_btcoex_IsBtExist(padapter))
4081                 return 0;
4082
4083         if (GLBtCoexist.bt_info.bt_disabled)
4084                 return 0;
4085
4086         /* Modify by YiWei , suggest by Cosa and Jenyu
4087          * Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask.
4088          */
4089         /*if (GLBtCoexist.board_info.btdm_ant_num != 1)
4090                 return 0;*/
4091
4092         return GLBtCoexist.bt_info.ra_mask;
4093 }
4094
4095 void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
4096 {
4097
4098         _rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
4099 }
4100
4101 void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
4102 {
4103         PBTCDBGINFO pinfo;
4104
4105
4106         pinfo = &GLBtcDbgInfo;
4107         DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
4108         EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
4109         DBG_BT_INFO_INIT(pinfo, NULL, 0);
4110 }
4111
4112 void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
4113 {
4114         u32 i;
4115
4116
4117         if (NULL == pDbgModule)
4118                 return;
4119
4120         for (i = 0; i < COMP_MAX; i++)
4121                 GLBtcDbgType[i] = pDbgModule[i];
4122 }
4123
4124 u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
4125 {
4126         s32 count;
4127         u8 *pstr;
4128         u32 leftSize;
4129
4130
4131         if ((NULL == pStrBuf) || (0 == bufSize))
4132                 return 0;
4133
4134         count = 0;
4135         pstr = pStrBuf;
4136         leftSize = bufSize;
4137         /*      RTW_INFO(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize); */
4138
4139         count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
4140         if ((count < 0) || (count >= leftSize))
4141                 goto exit;
4142         pstr += count;
4143         leftSize -= count;
4144
4145         count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
4146         if ((count < 0) || (count >= leftSize))
4147                 goto exit;
4148         pstr += count;
4149         leftSize -= count;
4150
4151         count = rtw_sprintf(pstr, leftSize,
4152                             "COMP_COEX: 0x%08X\n\n",
4153                             GLBtcDbgType[COMP_COEX]);
4154         if ((count < 0) || (count >= leftSize))
4155                 goto exit;
4156         pstr += count;
4157         leftSize -= count;
4158
4159 #if 0
4160         count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
4161         if ((count < 0) || (count >= leftSize))
4162                 goto exit;
4163         pstr += count;
4164         leftSize -= count;
4165         count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",
4166                     GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_INIT ? 1 : 0);
4167         if ((count < 0) || (count >= leftSize))
4168                 goto exit;
4169         pstr += count;
4170         leftSize -= count;
4171         count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",
4172                     GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_NOTIFY ? 1 : 0);
4173         if ((count < 0) || (count >= leftSize))
4174                 goto exit;
4175         pstr += count;
4176         leftSize -= count;
4177
4178         count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
4179         if ((count < 0) || (count >= leftSize))
4180                 goto exit;
4181         pstr += count;
4182         leftSize -= count;
4183         count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",
4184                 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_RSSI_STATE ? 1 : 0);
4185         if ((count < 0) || (count >= leftSize))
4186                 goto exit;
4187         pstr += count;
4188         leftSize -= count;
4189         count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",
4190                 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_WIFI_RSSI_STATE ? 1 : 0);
4191         if ((count < 0) || (count >= leftSize))
4192                 goto exit;
4193         pstr += count;
4194         leftSize -= count;
4195         count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",
4196                     GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_MONITOR ? 1 : 0);
4197         if ((count < 0) || (count >= leftSize))
4198                 goto exit;
4199         pstr += count;
4200         leftSize -= count;
4201         count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",
4202                     GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE ? 1 : 0);
4203         if ((count < 0) || (count >= leftSize))
4204                 goto exit;
4205         pstr += count;
4206         leftSize -= count;
4207         count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",
4208                     GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW ? 1 : 0);
4209         if ((count < 0) || (count >= leftSize))
4210                 goto exit;
4211         pstr += count;
4212         leftSize -= count;
4213         count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",
4214                 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_DETAIL ? 1 : 0);
4215         if ((count < 0) || (count >= leftSize))
4216                 goto exit;
4217         pstr += count;
4218         leftSize -= count;
4219         count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",
4220                 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_EXEC ? 1 : 0);
4221         if ((count < 0) || (count >= leftSize))
4222                 goto exit;
4223         pstr += count;
4224         leftSize -= count;
4225         count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",
4226                     GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW ? 1 : 0);
4227         if ((count < 0) || (count >= leftSize))
4228                 goto exit;
4229         pstr += count;
4230         leftSize -= count;
4231         count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",
4232                 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_DETAIL ? 1 : 0);
4233         if ((count < 0) || (count >= leftSize))
4234                 goto exit;
4235         pstr += count;
4236         leftSize -= count;
4237         count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",
4238                 GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_EXEC ? 1 : 0);
4239         if ((count < 0) || (count >= leftSize))
4240                 goto exit;
4241         pstr += count;
4242         leftSize -= count;
4243 #endif
4244
4245 exit:
4246         count = pstr - pStrBuf;
4247         /*      RTW_INFO(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count); */
4248
4249         return count;
4250 }
4251
4252 u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
4253 {
4254         if (!hal_btcoex_IsBtExist(padapter))
4255                 return _FALSE;
4256
4257         if (GLBtCoexist.bt_info.increase_scan_dev_num)
4258                 return _TRUE;
4259
4260         return _FALSE;
4261 }
4262
4263 u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)
4264 {
4265         if (GLBtCoexist.bt_link_info.bt_link_exist)
4266                 return _TRUE;
4267
4268         return _FALSE;
4269 }
4270
4271 void hal_btcoex_SetBtPatchVersion(PADAPTER padapter, u16 btHciVer, u16 btPatchVer)
4272 {
4273         EXhalbtcoutsrc_SetBtPatchVersion(btHciVer, btPatchVer);
4274 }
4275
4276 void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)
4277 {
4278         EXhalbtcoutsrc_SetHciVersion(hciVersion);
4279 }
4280
4281 void hal_btcoex_StackUpdateProfileInfo(void)
4282 {
4283         EXhalbtcoutsrc_StackUpdateProfileInfo();
4284 }
4285
4286 void hal_btcoex_pta_off_on_notify(PADAPTER padapter, u8 bBTON)
4287 {
4288         ex_halbtcoutsrc_pta_off_on_notify(&GLBtCoexist, bBTON);
4289 }
4290
4291 /*
4292  *      Description:
4293  *      Setting BT coex antenna isolation type .
4294  *      coex mechanisn/ spital stream/ best throughput
4295  *      anttype = 0     ,       PSTDMA  /       2SS     /       0.5T    ,       bad isolation , WiFi/BT ANT Distance<15cm , (<20dB) for 2,3 antenna
4296  *      anttype = 1     ,       PSTDMA  /       1SS     /       0.5T    ,       normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 2 antenna
4297  *      anttype = 2     ,       TDMA    /       2SS     /       T ,             normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 3 antenna
4298  *      anttype = 3     ,       no TDMA /       1SS     /       0.5T    ,       good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 2 antenna
4299  *      anttype = 4     ,       no TDMA /       2SS     /       T ,             good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 3 antenna
4300  *      wifi only throughput ~ T
4301  *      wifi/BT share one antenna with SPDT
4302  */
4303 void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)
4304 {
4305         PHAL_DATA_TYPE pHalData;
4306         PBTC_COEXIST    pBtCoexist = &GLBtCoexist;
4307
4308         /*RTW_INFO("####%s , anttype = %d  , %d\n" , __func__ , anttype , __LINE__); */
4309         pHalData = GET_HAL_DATA(padapter);
4310
4311
4312         pHalData->bt_coexist.btAntisolation = anttype;
4313
4314         switch (pHalData->bt_coexist.btAntisolation) {
4315         case 0:
4316                 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_0;
4317                 break;
4318         case 1:
4319                 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_1;
4320                 break;
4321         case 2:
4322                 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_2;
4323                 break;
4324         case 3:
4325                 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_3;
4326                 break;
4327         case 4:
4328                 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_4;
4329                 break;
4330         }
4331
4332 }
4333
4334 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
4335 int
4336 hal_btcoex_ParseAntIsolationConfigFile(
4337         PADAPTER                Adapter,
4338         char                    *buffer
4339 )
4340 {
4341         HAL_DATA_TYPE   *pHalData = GET_HAL_DATA(Adapter);
4342         u32     i = 0 , j = 0;
4343         char    *szLine , *ptmp;
4344         int rtStatus = _SUCCESS;
4345         char param_value_string[10];
4346         u8 param_value;
4347         u8 anttype = 4;
4348
4349         u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1;
4350
4351         typedef struct ant_isolation {
4352                 char *param_name;  /* antenna isolation config parameter name */
4353                 u8 *value; /* antenna isolation config parameter value */
4354         } ANT_ISOLATION;
4355
4356         ANT_ISOLATION ant_isolation_param[] = {
4357                 {"ANT_NUMBER" , &ant_num},
4358                 {"ANT_DISTANCE" , &ant_distance},
4359                 {"RFE_TYPE" , &rfe_type},
4360                 {NULL , 0}
4361         };
4362
4363
4364
4365         /* RTW_INFO("===>Hal_ParseAntIsolationConfigFile()\n" ); */
4366
4367         ptmp = buffer;
4368         for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
4369                 /* skip comment */
4370                 if (IsCommentString(szLine))
4371                         continue;
4372
4373                 /* RTW_INFO("%s : szLine = %s , strlen(szLine) = %d\n" , __func__ , szLine , strlen(szLine));*/
4374                 for (j = 0 ; ant_isolation_param[j].param_name != NULL ; j++) {
4375                         if (strstr(szLine , ant_isolation_param[j].param_name) != NULL) {
4376                                 i = 0;
4377                                 while (i < strlen(szLine)) {
4378                                         if (szLine[i] != '"')
4379                                                 ++i;
4380                                         else {
4381                                                 /* skip only has one " */
4382                                                 if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) {
4383                                                         RTW_INFO("Fail to parse parameters , format error!\n");
4384                                                         break;
4385                                                 }
4386                                                 _rtw_memset((PVOID)param_value_string , 0 , 10);
4387                                                 if (!ParseQualifiedString(szLine , &i , param_value_string , '"' , '"')) {
4388                                                         RTW_INFO("Fail to parse parameters\n");
4389                                                         return _FAIL;
4390                                                 } else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value))
4391                                                         RTW_INFO("Fail to GetU1ByteIntegerFromStringInDecimal\n");
4392
4393                                                 break;
4394                                         }
4395                                 }
4396                         }
4397                 }
4398         }
4399
4400         /* YiWei 20140716 , for BT coex antenna isolation control */
4401         /* rfe_type = 0 was SPDT , rfe_type = 1 was coupler */
4402         if (ant_num == 3 && ant_distance >= 50)
4403                 anttype = 3;
4404         else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1)
4405                 anttype = 2;
4406         else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50)
4407                 anttype = 2;
4408         else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1)
4409                 anttype = 2;
4410         else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15))
4411                 anttype = 1;
4412         else if (ant_num == 2 && rfe_type == 0)
4413                 anttype = 0;
4414         else
4415                 anttype = 0;
4416
4417         hal_btcoex_SetAntIsolationType(Adapter, anttype);
4418
4419         RTW_INFO("%s : ant_num = %d\n" , __func__ , ant_num);
4420         RTW_INFO("%s : ant_distance = %d\n" , __func__ , ant_distance);
4421         RTW_INFO("%s : rfe_type = %d\n" , __func__ , rfe_type);
4422         /* RTW_INFO("<===Hal_ParseAntIsolationConfigFile()\n"); */
4423         return rtStatus;
4424 }
4425
4426
4427 int
4428 hal_btcoex_AntIsolationConfig_ParaFile(
4429         IN      PADAPTER        Adapter,
4430         IN      char            *pFileName
4431 )
4432 {
4433         HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
4434         int     rlen = 0 , rtStatus = _FAIL;
4435
4436         _rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN);
4437
4438         rtw_get_phy_file_path(Adapter, pFileName);
4439         if (rtw_is_file_readable(rtw_phy_para_file_path) == _TRUE) {
4440                 rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);
4441                 if (rlen > 0)
4442                         rtStatus = _SUCCESS;
4443         }
4444
4445
4446         if (rtStatus == _SUCCESS) {
4447                 /*RTW_INFO("%s(): read %s ok\n", __func__ , pFileName);*/
4448                 rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf);
4449         } else
4450                 RTW_INFO("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName);
4451
4452         return rtStatus;
4453 }
4454 #endif /* CONFIG_LOAD_PHY_PARA_FROM_FILE */
4455
4456 u16 hal_btcoex_btreg_read(PADAPTER padapter, u8 type, u16 addr, u32 *data)
4457 {
4458         u16 ret = 0;
4459
4460         halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
4461
4462         ret = halbtcoutsrc_GetBtReg_with_status(&GLBtCoexist, type, addr, data);
4463
4464         halbtcoutsrc_NormalLowPower(&GLBtCoexist);
4465
4466         return ret;
4467 }
4468
4469 u16 hal_btcoex_btreg_write(PADAPTER padapter, u8 type, u16 addr, u16 val)
4470 {
4471         u16 ret = 0;
4472
4473         halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
4474
4475         ret = halbtcoutsrc_SetBtReg(&GLBtCoexist, type, addr, val);
4476
4477         halbtcoutsrc_NormalLowPower(&GLBtCoexist);
4478
4479         return ret;
4480 }
4481
4482 void hal_btcoex_set_rfe_type(u8 type)
4483 {
4484         EXhalbtcoutsrc_set_rfe_type(type);
4485 }
4486 void hal_btcoex_switchband_notify(u8 under_scan, u8 band_type)
4487 {
4488         switch (band_type) {
4489         case BAND_ON_2_4G:
4490                 if (under_scan)
4491                         EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G);
4492                 else
4493                         EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G_NOFORSCAN);
4494                 break;
4495         case BAND_ON_5G:
4496                 EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_5G);
4497                 break;
4498         default:
4499                 RTW_INFO("[BTCOEX] unkown switch band type\n");
4500                 break;
4501         }
4502 }
4503 #endif /* CONFIG_BT_COEXIST */