1 /******************************************************************************
3 * Copyright(c) 2013 Realtek Corporation. All rights reserved.
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.
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
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
19 ******************************************************************************/
20 #define __HAL_BTCOEX_C__
22 #ifdef CONFIG_BT_COEXIST
25 #include <hal_btcoex.h>
26 #include "btc/mp_precomp.h"
28 /* ************************************
30 * ************************************ */
31 const char *const BtProfileString[] = {
39 const char *const BtSpecString[] = {
49 const char *const BtLinkRoleString[] = {
54 const char *const h2cStaString[] = {
61 const char *const ioStaString[] = {
75 const char *const GLBtcWifiBwString[] = {
83 const char *const GLBtcWifiFreqString[] = {
88 const char *const GLBtcIotPeerString[] = {
98 "REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
99 "SELF_SOFTAP", /* Self is SoftAP */
105 "REALTEK_JAGUAR_BCUTAP",
106 "REALTEK_JAGUAR_CCUTAP"
109 const char *const coexOpcodeString[] = {
110 "Wifi status notify",
118 const char *const coexIndTypeString[] = {
126 const char *const coexH2cResultString[] = {
140 #define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS 8000
142 struct btc_coexist GLBtCoexist;
143 BTC_OFFLOAD gl_coex_offload;
144 u8 GLBtcWiFiInScanState;
145 u8 GLBtcWiFiInIQKState;
148 u8 GLBtcBtCoexAliveRegistered;
154 typedef enum _bt_ext_eid {
155 C2H_WIFI_FW_ACTIVE_RSP = 0,
160 typedef enum _bt_c2h_status {
162 BT_STATUS_VERSION_MISMATCH,
163 BT_STATUS_UNKNOWN_OPCODE,
164 BT_STATUS_ERROR_PARAMETER
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,
173 BT_OP_READ_REG = 0x11,
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,
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,
187 #define BTC_MPOPER_TIMEOUT 50 /* unit: ms */
189 #define C2H_MAX_SIZE 16
191 _mutex GLBtcBtMpOperLock;
192 _timer GLBtcBtMpOperTimer;
193 _sema GLBtcBtMpRptSema;
195 u8 GLBtcBtMpRptStatus;
196 u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE];
197 u8 GLBtcBtMpRptRspSize;
199 u8 GLBtcBtMpRptWiFiOK;
205 u32 GLBtcDbgType[COMP_MAX];
206 u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
207 u1Byte gl_btc_trace_buf[BT_TMP_BUF_SIZE];
209 typedef struct _btcoexdbginfo {
211 u32 size; /* buffer total size */
212 u32 len; /* now used length */
213 } BTCDBGINFO, *PBTCDBGINFO;
215 BTCDBGINFO GLBtcDbgInfo;
217 #define BT_Operation(Adapter) _FALSE
219 static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
224 _rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
232 void DBG_BT_INFO(u8 *dbgmsg)
239 pinfo = &GLBtcDbgInfo;
241 if (NULL == pinfo->info)
244 msglen = strlen(dbgmsg);
245 if (pinfo->len + msglen > pinfo->size)
248 pbuf = pinfo->info + pinfo->len;
249 _rtw_memcpy(pbuf, dbgmsg, msglen);
250 pinfo->len += msglen;
253 /* ************************************
254 * Debug related function
255 * ************************************ */
256 static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
258 if (!pBtCoexist->bBinded ||
259 NULL == pBtCoexist->Adapter)
264 static void halbtcoutsrc_DbgInit(void)
268 for (i = 0; i < COMP_MAX; i++)
272 static u8 halbtcoutsrc_IsCsrBtCoex(PBTC_COEXIST pBtCoexist)
274 if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
275 || pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
281 static void halbtcoutsrc_EnterPwrLock(PBTC_COEXIST pBtCoexist)
283 struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
284 struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
286 _enter_pwrlock(&pwrpriv->lock);
289 static void halbtcoutsrc_ExitPwrLock(PBTC_COEXIST pBtCoexist)
291 struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
292 struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
294 _exit_pwrlock(&pwrpriv->lock);
297 static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
299 if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
300 || pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
303 else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
309 static void halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
314 padapter = pBtCoexist->Adapter;
316 pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
317 pBtCoexist->bt_info.bt_lps_on = _FALSE;
319 rtw_btcoex_LPS_Leave(padapter);
322 void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
327 padapter = pBtCoexist->Adapter;
329 if (pBtCoexist->bdontenterLPS == _FALSE) {
330 pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
331 pBtCoexist->bt_info.bt_lps_on = _TRUE;
333 rtw_btcoex_LPS_Enter(padapter);
337 void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
343 padapter = pBtCoexist->Adapter;
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;
350 /* recover the LPS state to the original */
352 padapter->hal_func.UpdateLPSStatusHandler(
354 pPSC->RegLeisurePsMode,
355 pPSC->RegPowerSaveMode);
362 * 1. this function will request pwrctrl->lock
364 void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
366 #ifdef CONFIG_LPS_LCLK
368 PHAL_DATA_TYPE pHalData;
369 struct pwrctrl_priv *pwrctrl;
373 u32 timeout; /* unit: ms */
376 padapter = pBtCoexist->Adapter;
377 pHalData = GET_HAL_DATA(padapter);
378 pwrctrl = adapter_to_pwrctl(padapter);
380 #ifdef LPS_RPWM_WAIT_MS
381 timeout = LPS_RPWM_WAIT_MS;
382 #else /* !LPS_RPWM_WAIT_MS */
384 #endif /* !LPS_RPWM_WAIT_MS */
386 if (GLBtcBtCoexAliveRegistered == _TRUE)
389 stime = rtw_get_current_time();
391 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
392 if (_SUCCESS == ready)
395 utime = rtw_get_passing_time_ms(stime);
402 GLBtcBtCoexAliveRegistered = _TRUE;
403 #endif /* CONFIG_LPS_LCLK */
408 * 1. this function will request pwrctrl->lock
410 void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
412 #ifdef CONFIG_LPS_LCLK
415 if (GLBtcBtCoexAliveRegistered == _FALSE)
418 padapter = pBtCoexist->Adapter;
419 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
421 GLBtcBtCoexAliveRegistered = _FALSE;
422 #endif /* CONFIG_LPS_LCLK */
425 void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
427 pBtCoexist->bt_info.bt_disable_low_pwr = bLowPwrDisable;
429 halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */
431 halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */
434 void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
437 BOOLEAN bNeedToAct = _FALSE;
438 static u32 preTime = 0;
441 padapter = pBtCoexist->Adapter;
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 /* ===================================== */
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. */
455 if (pBtCoexist->bt_info.reject_agg_pkt) {
457 pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
459 if (pBtCoexist->bt_info.pre_reject_agg_pkt) {
461 pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
464 if (pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
465 pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
467 pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size = pBtCoexist->bt_info.bt_ctrl_agg_buf_size;
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)
474 pBtCoexist->bt_info.pre_agg_buf_size = pBtCoexist->bt_info.agg_buf_size;
479 rtw_btcoex_rx_ampdu_apply(padapter);
482 u8 halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist)
485 PHAL_DATA_TYPE pHalData;
487 padapter = pBtCoexist->Adapter;
488 pHalData = GET_HAL_DATA(padapter);
490 return pHalData->bautoload_fail_flag;
493 u8 halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist)
497 padapter = pBtCoexist->Adapter;
499 return padapter->bFWReady;
502 u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
504 if (rtw_mi_check_status(padapter, MI_AP_MODE))
506 if (rtw_mi_busy_traffic_check(padapter, _FALSE))
512 static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
514 struct mlme_priv *pmlmepriv;
516 u32 portConnectedStatus;
519 pmlmepriv = &padapter->mlmepriv;
521 portConnectedStatus = 0;
524 if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
526 #endif /* CONFIG_P2P */
528 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {
529 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
531 portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
533 portConnectedStatus |= WIFI_AP_CONNECTED;
536 portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
538 portConnectedStatus |= WIFI_STA_CONNECTED;
542 return portConnectedStatus;
545 u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
547 /* ================================= */
549 /* [31:16]=> connected port number */
550 /* [15:0]=> port connected bit define */
551 /* ================================ */
555 u32 portConnectedStatus, numOfConnectedPort;
556 struct dvobj_priv *dvobj;
560 padapter = pBtCoexist->Adapter;
562 portConnectedStatus = 0;
563 numOfConnectedPort = 0;
564 dvobj = adapter_to_dvobj(padapter);
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);
571 portConnectedStatus |= retVal;
572 numOfConnectedPort++;
576 retVal = (numOfConnectedPort << 16) | portConnectedStatus;
581 static void _btmpoper_timer_hdl(void *p)
583 if (GLBtcBtMpRptWait) {
584 GLBtcBtMpRptWait = 0;
585 _rtw_up_sema(&GLBtcBtMpRptSema);
591 * Before call this function, caller should acquire "GLBtcBtMpOperLock"!
592 * Othrewise there will be racing problem and something may go wrong.
594 static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size)
597 u8 buf[H2C_BTMP_OPER_LEN] = {0};
606 if ((size + 2) > H2C_BTMP_OPER_LEN)
607 return BT_STATUS_H2C_LENGTH_EXCEEDED;
610 seq = GLBtcBtMpOperSeq & 0xF;
613 buf[0] = (opcodever & 0xF) | (seq << 4);
616 _rtw_memcpy(buf + 2, cmd, size);
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;
630 _rtw_down_sema(&GLBtcBtMpRptSema);
631 /* GLBtcBtMpRptWait should be 0 here*/
633 if (!GLBtcBtMpRptWiFiOK) {
634 RTW_ERR("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__);
635 ret = BT_STATUS_H2C_TIMTOUT;
638 if (!GLBtcBtMpRptBTOK) {
639 RTW_DBG("%s: Didn't get BT response!\n", __FUNCTION__);
640 ret = BT_STATUS_H2C_BT_NO_RSP;
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;
650 switch (GLBtcBtMpRptStatus) {
651 /* Examine the status reported from C2H */
653 ret = BT_STATUS_BT_OP_SUCCESS;
654 RTW_DBG("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__);
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__);
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__);
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__);
669 ret = BT_STATUS_UNKNOWN_STATUS_L;
670 RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__);
678 u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
680 if (pBtCoexist->bt_info.get_bt_fw_ver_cnt <= 5) {
681 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
685 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
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++;
694 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
696 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
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 */
708 return pBtCoexist->bt_info.bt_real_fw_ver;
711 s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
713 PHAL_DATA_TYPE pHalData;
714 s32 undecorated_smoothed_pwdb = 0;
716 pHalData = GET_HAL_DATA(padapter);
718 undecorated_smoothed_pwdb = pHalData->entry_min_undecorated_smoothed_pwdb;
720 return undecorated_smoothed_pwdb;
723 u32 halbtcoutsrc_GetBtCoexSupportedFeature(void *pBtcContext)
725 PBTC_COEXIST pBtCoexist;
726 u32 ret = BT_STATUS_BT_OP_SUCCESS;
729 pBtCoexist = (PBTC_COEXIST)pBtcContext;
731 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
737 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
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);
744 ret = SET_BT_MP_OPER_RET(op_code, status);
746 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
749 ret = BT_STATUS_NOT_IMPLEMENT;
754 u32 halbtcoutsrc_GetBtCoexSupportedVersion(void *pBtcContext)
756 PBTC_COEXIST pBtCoexist;
757 u32 ret = BT_STATUS_BT_OP_SUCCESS;
760 pBtCoexist = (PBTC_COEXIST)pBtcContext;
762 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
768 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
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);
775 ret = SET_BT_MP_OPER_RET(op_code, status);
777 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
780 ret = BT_STATUS_NOT_IMPLEMENT;
785 static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
787 struct mlme_priv *pmlmepriv;
788 struct mlme_ext_priv *pmlmeext;
789 static u8 scan_AP_num = 0;
792 pmlmepriv = &padapter->mlmepriv;
793 pmlmeext = &padapter->mlmeextpriv;
795 if (GLBtcWiFiInScanState == _FALSE) {
796 if (pmlmepriv->num_of_scanned > 0xFF)
799 scan_AP_num = (u8)pmlmepriv->num_of_scanned;
805 u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
807 PBTC_COEXIST pBtCoexist;
809 PHAL_DATA_TYPE pHalData;
810 struct mlme_ext_priv *mlmeext;
811 u8 bSoftApExist, bVwifiExist;
819 pBtCoexist = (PBTC_COEXIST)pBtcContext;
820 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
823 padapter = pBtCoexist->Adapter;
824 pHalData = GET_HAL_DATA(padapter);
825 mlmeext = &padapter->mlmeextpriv;
826 bSoftApExist = _FALSE;
827 bVwifiExist = _FALSE;
829 pS4Tmp = (s32 *)pOutBuf;
830 pU4Tmp = (u32 *)pOutBuf;
831 pU1Tmp = (u8 *)pOutBuf;
835 case BTC_GET_BL_HS_OPERATION:
840 case BTC_GET_BL_HS_CONNECTING:
845 case BTC_GET_BL_WIFI_FW_READY:
846 *pu8 = halbtcoutsrc_is_fw_ready(pBtCoexist);
849 case BTC_GET_BL_WIFI_CONNECTED:
850 *pu8 = (rtw_mi_check_status(padapter, MI_LINKED)) ? _TRUE : _FALSE;
853 case BTC_GET_BL_WIFI_BUSY:
854 *pu8 = halbtcoutsrc_IsWifiBusy(padapter);
857 case BTC_GET_BL_WIFI_SCAN:
859 *pu8 = (rtw_mi_check_fwstate(padapter, WIFI_SITE_MONITOR)) ? _TRUE : _FALSE;
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;
867 case BTC_GET_BL_WIFI_LINK:
868 *pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
871 case BTC_GET_BL_WIFI_ROAM:
872 *pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
875 case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
879 case BTC_GET_BL_WIFI_UNDER_5G:
880 *pu8 = (pHalData->current_band_type == 1) ? _TRUE : _FALSE;
883 case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
884 *pu8 = (rtw_mi_check_status(padapter, MI_AP_MODE)) ? _TRUE : _FALSE;
887 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
888 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? _FALSE : _TRUE;
891 case BTC_GET_BL_WIFI_UNDER_B_MODE:
892 if (mlmeext->cur_wireless_mode == WIRELESS_11B)
898 case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
899 if (padapter->registrypriv.mp_mode == 0)
905 case BTC_GET_BL_EXT_SWITCH:
908 case BTC_GET_BL_IS_ASUS_8723B:
909 /* Always return FALSE in linux driver since this case is added only for windows driver */
913 case BTC_GET_S4_WIFI_RSSI:
914 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
917 case BTC_GET_S4_HS_RSSI:
922 case BTC_GET_U4_WIFI_BW:
923 if (IsLegacyOnly(mlmeext->cur_wireless_mode))
924 *pU4Tmp = BTC_WIFI_BW_LEGACY;
926 switch (pHalData->current_channel_bw) {
927 case CHANNEL_WIDTH_20:
928 *pU4Tmp = BTC_WIFI_BW_HT20;
930 case CHANNEL_WIDTH_40:
931 *pU4Tmp = BTC_WIFI_BW_HT40;
933 case CHANNEL_WIDTH_80:
934 *pU4Tmp = BTC_WIFI_BW_HT80;
936 case CHANNEL_WIDTH_160:
937 *pU4Tmp = BTC_WIFI_BW_HT160;
940 RTW_INFO("[BTCOEX] unknown bandwidth(%d)\n", pHalData->current_channel_bw);
941 *pU4Tmp = BTC_WIFI_BW_HT40;
948 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: {
949 PRT_LINK_DETECT_T plinkinfo;
950 plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
952 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
953 *pU4Tmp = BTC_WIFI_TRAFFIC_TX;
955 *pU4Tmp = BTC_WIFI_TRAFFIC_RX;
959 case BTC_GET_U4_WIFI_FW_VER:
960 *pU4Tmp = pHalData->firmware_version << 16;
961 *pU4Tmp |= pHalData->firmware_sub_version;
964 case BTC_GET_U4_WIFI_LINK_STATUS:
965 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
968 case BTC_GET_U4_BT_PATCH_VER:
969 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
972 case BTC_GET_U4_VENDOR:
973 *pU4Tmp = BTC_VENDOR_OTHER;
976 case BTC_GET_U4_SUPPORTED_VERSION:
977 *pU4Tmp = halbtcoutsrc_GetBtCoexSupportedVersion(pBtCoexist);
979 case BTC_GET_U4_SUPPORTED_FEATURE:
980 *pU4Tmp = halbtcoutsrc_GetBtCoexSupportedFeature(pBtCoexist);
983 case BTC_GET_U4_WIFI_IQK_TOTAL:
984 *pU4Tmp = pHalData->odmpriv.n_iqk_cnt;
987 case BTC_GET_U4_WIFI_IQK_OK:
988 *pU4Tmp = pHalData->odmpriv.n_iqk_ok_cnt;
991 case BTC_GET_U4_WIFI_IQK_FAIL:
992 *pU4Tmp = pHalData->odmpriv.n_iqk_fail_cnt;
995 case BTC_GET_U1_WIFI_DOT11_CHNL:
996 *pU1Tmp = padapter->mlmeextpriv.cur_channel;
999 case BTC_GET_U1_WIFI_CENTRAL_CHNL:
1000 *pU1Tmp = pHalData->current_channel;
1003 case BTC_GET_U1_WIFI_HS_CHNL:
1008 case BTC_GET_U1_WIFI_P2P_CHNL:
1011 struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
1013 *pU1Tmp = pwdinfo->operating_channel;
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; */
1027 case BTC_GET_U1_AP_NUM:
1028 *pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
1030 case BTC_GET_U1_ANT_TYPE:
1031 switch (pHalData->bt_coexist.btAntisolation) {
1033 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_0;
1034 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_0;
1037 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_1;
1038 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_1;
1041 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_2;
1042 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_2;
1045 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_3;
1046 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_3;
1049 *pU1Tmp = (u1Byte)BTC_ANT_TYPE_4;
1050 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_4;
1054 case BTC_GET_U1_IOT_PEER:
1055 *pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;
1058 /* =======1Ant=========== */
1059 case BTC_GET_U1_LPS_MODE:
1060 *pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
1071 u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
1073 PBTC_COEXIST pBtCoexist;
1075 PHAL_DATA_TYPE pHalData;
1082 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1083 padapter = pBtCoexist->Adapter;
1084 pHalData = GET_HAL_DATA(padapter);
1086 pU1Tmp = (u8 *)pInBuf;
1087 pU4Tmp = (u32 *)pInBuf;
1090 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
1094 /* set some u8 type variables. */
1095 case BTC_SET_BL_BT_DISABLE:
1096 pBtCoexist->bt_info.bt_disabled = *pu8;
1099 case BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE:
1100 pBtCoexist->bt_info.bt_enable_disable_change = *pu8;
1103 case BTC_SET_BL_BT_TRAFFIC_BUSY:
1104 pBtCoexist->bt_info.bt_busy = *pu8;
1107 case BTC_SET_BL_BT_LIMITED_DIG:
1108 pBtCoexist->bt_info.limited_dig = *pu8;
1111 case BTC_SET_BL_FORCE_TO_ROAM:
1112 pBtCoexist->bt_info.force_to_roam = *pu8;
1115 case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
1116 pBtCoexist->bt_info.reject_agg_pkt = *pu8;
1119 case BTC_SET_BL_BT_CTRL_AGG_SIZE:
1120 pBtCoexist->bt_info.bt_ctrl_agg_buf_size = *pu8;
1123 case BTC_SET_BL_INC_SCAN_DEV_NUM:
1124 pBtCoexist->bt_info.increase_scan_dev_num = *pu8;
1127 case BTC_SET_BL_BT_TX_RX_MASK:
1128 pBtCoexist->bt_info.bt_tx_rx_mask = *pu8;
1131 case BTC_SET_BL_MIRACAST_PLUS_BT:
1132 pBtCoexist->bt_info.miracast_plus_bt = *pu8;
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;
1140 case BTC_SET_U1_AGG_BUF_SIZE:
1141 pBtCoexist->bt_info.agg_buf_size = *pU1Tmp;
1144 /* the following are some action which will be triggered */
1145 case BTC_SET_ACT_GET_BT_RSSI:
1147 BT_SendGetBtRssiEvent(padapter);
1153 case BTC_SET_ACT_AGGREGATE_CTRL:
1154 halbtcoutsrc_AggregationCheck(pBtCoexist);
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;
1163 case BTC_SET_U1_LPS_VAL:
1164 pBtCoexist->bt_info.lps_val = *pU1Tmp;
1167 case BTC_SET_U1_RPWM_VAL:
1168 pBtCoexist->bt_info.rpwm_val = *pU1Tmp;
1171 /* the following are some action which will be triggered */
1172 case BTC_SET_ACT_LEAVE_LPS:
1173 halbtcoutsrc_LeaveLps(pBtCoexist);
1176 case BTC_SET_ACT_ENTER_LPS:
1177 halbtcoutsrc_EnterLps(pBtCoexist);
1180 case BTC_SET_ACT_NORMAL_LPS:
1181 halbtcoutsrc_NormalLps(pBtCoexist);
1184 case BTC_SET_ACT_DISABLE_LOW_POWER:
1185 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
1188 case BTC_SET_ACT_UPDATE_RAMASK:
1189 pBtCoexist->bt_info.ra_mask = *pU4Tmp;
1191 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE) {
1192 struct sta_info *psta;
1193 PWLAN_BSSID_EX cur_network;
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);
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);
1206 /* *pU1Tmp = 0 use SM_PS static type */
1207 /* *pU1Tmp = 1 disable SM_PS */
1209 newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
1210 else if (*pU1Tmp == 1)
1211 newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
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);
1220 case BTC_SET_ACT_CTRL_BT_INFO:
1221 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1223 u8 dataLen = *pU1Tmp;
1224 u8 tmpBuf[BTC_TMP_BUF_SHORT];
1226 _rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
1227 BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
1229 #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
1231 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
1234 case BTC_SET_ACT_CTRL_BT_COEX:
1235 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1237 u8 dataLen = *pU1Tmp;
1238 u8 tmpBuf[BTC_TMP_BUF_SHORT];
1240 _rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
1241 BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
1243 #else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
1245 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
1247 case BTC_SET_ACT_CTRL_8723B_ANT:
1250 u1Byte dataLen = *pU1Tmp;
1251 u1Byte tmpBuf[BTC_TMP_BUF_SHORT];
1253 PlatformMoveMemory(&tmpBuf[0], pU1Tmp + 1, dataLen);
1254 BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
1260 /* ===================== */
1269 u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
1272 struct pwrctrl_priv *pwrpriv;
1275 padapter = pBtCoexist->Adapter;
1276 pwrpriv = &padapter->dvobj->pwrctl_priv;
1277 bMacPwrCtrlOn = _FALSE;
1279 if ((_TRUE == pwrpriv->bips_processing)
1280 && (IPS_NONE != pwrpriv->ips_mode_req)
1284 if (rf_off == pwrpriv->rf_pwrstate)
1287 rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
1288 if (_FALSE == bMacPwrCtrlOn)
1294 u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
1296 return GLBtcWiFiInLPS;
1299 u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
1301 /* todo: the method to check whether wifi is under 32K or not */
1305 void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
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;
1313 u1Byte tmpbuf[BTC_TMP_BUF_SHORT];
1316 if (gl_coex_offload.cnt_h2c_sent) {
1317 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex h2c notify]============");
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);
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);
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);
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);
1359 /*==========================================*/
1363 if (gl_coex_offload.cnt_c2h_ind) {
1364 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex c2h indication]============");
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);
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);
1390 /*==========================================*/
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);
1399 /*==========================================*/
1403 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
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]);
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]);
1424 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
1425 pHalData->LastHMEBoxNum);
1427 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
1428 pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
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);
1436 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
1437 DBG_Var.c2hPacketCnt);
1440 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
1441 pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
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);
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);
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);
1457 PADAPTER padapter = pBtCoexist->Adapter;
1458 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
1459 u8 *cliBuf = pBtCoexist->cli_buf;
1461 if (pHalData->EEPROMBluetoothCoexist == 1) {
1462 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex Status]============");
1464 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtDisabled", rtw_btcoex_IsBtDisabled(padapter));
1466 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtControlLps", rtw_btcoex_IsBtControlLps(padapter));
1471 void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
1474 PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
1475 PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
1476 u8 *cliBuf = pBtCoexist->cliBuf;
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]);
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]);
1499 void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
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;
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));
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);
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"));
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]);
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);
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")),
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" : ""));
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);
1575 void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
1577 PBTC_COEXIST pBtCoexist;
1580 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1582 case BTC_DBG_DISP_COEX_STATISTICS:
1583 halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
1585 case BTC_DBG_DISP_BT_LINK_INFO:
1586 halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
1588 case BTC_DBG_DISP_WIFI_STATUS:
1589 halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
1596 /* ************************************
1597 * IO related function
1598 * ************************************ */
1599 u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
1601 PBTC_COEXIST pBtCoexist;
1605 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1606 padapter = pBtCoexist->Adapter;
1608 return rtw_read8(padapter, RegAddr);
1611 u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
1613 PBTC_COEXIST pBtCoexist;
1617 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1618 padapter = pBtCoexist->Adapter;
1620 return rtw_read16(padapter, RegAddr);
1623 u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
1625 PBTC_COEXIST pBtCoexist;
1629 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1630 padapter = pBtCoexist->Adapter;
1632 return rtw_read32(padapter, RegAddr);
1635 void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1637 PBTC_COEXIST pBtCoexist;
1641 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1642 padapter = pBtCoexist->Adapter;
1644 rtw_write8(padapter, RegAddr, Data);
1647 void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
1649 PBTC_COEXIST pBtCoexist;
1651 u8 originalValue, bitShift;
1655 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1656 padapter = pBtCoexist->Adapter;
1660 if (bitMask != 0xff) {
1661 originalValue = rtw_read8(padapter, regAddr);
1663 for (i = 0; i <= 7; i++) {
1664 if ((bitMask >> i) & 0x1)
1669 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
1672 rtw_write8(padapter, regAddr, data1b);
1675 void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
1677 PBTC_COEXIST pBtCoexist;
1681 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1682 padapter = pBtCoexist->Adapter;
1684 rtw_write16(padapter, RegAddr, Data);
1687 void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
1689 PBTC_COEXIST pBtCoexist;
1693 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1694 padapter = pBtCoexist->Adapter;
1696 rtw_write32(padapter, RegAddr, Data);
1699 void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
1701 PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
1702 PADAPTER Adapter = pBtCoexist->Adapter;
1704 if (BTC_INTF_SDIO == pBtCoexist->chip_interface)
1705 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
1707 rtw_write8(Adapter, RegAddr, Data);
1710 void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
1712 PBTC_COEXIST pBtCoexist;
1716 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1717 padapter = pBtCoexist->Adapter;
1719 phy_set_bb_reg(padapter, RegAddr, BitMask, Data);
1723 u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
1725 PBTC_COEXIST pBtCoexist;
1729 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1730 padapter = pBtCoexist->Adapter;
1732 return phy_query_bb_reg(padapter, RegAddr, BitMask);
1735 void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
1737 PBTC_COEXIST pBtCoexist;
1741 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1742 padapter = pBtCoexist->Adapter;
1744 phy_set_rf_reg(padapter, eRFPath, RegAddr, BitMask, Data);
1747 u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask)
1749 PBTC_COEXIST pBtCoexist;
1753 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1754 padapter = pBtCoexist->Adapter;
1756 return phy_query_rf_reg(padapter, eRFPath, RegAddr, BitMask);
1759 u16 halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
1761 PBTC_COEXIST pBtCoexist;
1762 u16 ret = BT_STATUS_BT_OP_SUCCESS;
1764 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1766 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1772 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
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);
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);
1788 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1790 ret = BT_STATUS_NOT_IMPLEMENT;
1795 u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)
1797 /* Always return _FALSE since we don't implement this yet */
1799 PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
1800 PADAPTER Adapter = pBtCoexist->Adapter;
1802 BOOLEAN bStatus = FALSE;
1804 bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);
1805 if (bStatus && btCanTx)
1815 halbtcoutsrc_SetBtTRXMASK(
1816 IN PVOID pBtcContext,
1817 IN u1Byte bt_trx_mask
1820 /* Always return _FALSE since we don't implement this yet */
1822 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
1823 PADAPTER Adapter = pBtCoexist->Adapter;
1824 BOOLEAN bStatus = FALSE;
1827 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter) || IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)
1828 || IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
1830 if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))
1831 bStatus = NDBG_SetBtTRXMASK(Adapter, 1, bt_trx_mask, &btCanTx);
1833 bStatus = NDBG_SetBtTRXMASK(Adapter, 2, bt_trx_mask, &btCanTx);
1846 u16 halbtcoutsrc_GetBtReg_with_status(void *pBtcContext, u8 RegType, u32 RegAddr, u32 *data)
1848 PBTC_COEXIST pBtCoexist;
1849 u16 ret = BT_STATUS_BT_OP_SUCCESS;
1851 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1853 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
1860 *(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
1862 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
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);
1869 ret = SET_BT_MP_OPER_RET(op_code, status);
1871 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
1874 ret = BT_STATUS_NOT_IMPLEMENT;
1879 u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
1883 return (BT_STATUS_BT_OP_SUCCESS == halbtcoutsrc_GetBtReg_with_status(pBtcContext, RegType, RegAddr, ®Val)) ? regVal : 0xffffffff;
1886 void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
1888 PBTC_COEXIST pBtCoexist;
1892 pBtCoexist = (PBTC_COEXIST)pBtcContext;
1893 padapter = pBtCoexist->Adapter;
1895 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
1898 static void halbtcoutsrc_coex_offload_init(void)
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;
1907 for (i = 0; i < COL_MAX_H2C_REQ_NUM; i++)
1908 init_completion(&gl_coex_offload.c2h_event[i]);
1911 static COL_H2C_STATUS halbtcoutsrc_send_h2c(PADAPTER Adapter, PCOL_H2C pcol_h2c, u16 h2c_cmd_len)
1913 COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK;
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 */
1919 INIT_COMPLETION(gl_coex_offload.c2h_event[pcol_h2c->req_num]);
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;
1929 h2c_status = COL_STATUS_H2C_HALMAC_FAIL;
1937 static COL_H2C_STATUS halbtcoutsrc_check_c2h_ack(PADAPTER Adapter, PCOL_SINGLE_H2C_RECORD pH2cRecord)
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];
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;
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];
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;
1961 c2h_status = p_c2h_ack->status;
1967 COL_H2C_STATUS halbtcoutsrc_CoexH2cProcess(void *pBtCoexist,
1968 u8 opcode, u8 opcode_ver, u8 *ph2c_par, u8 h2c_par_len)
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];
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;
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;
1984 _rtw_memmove(&pcol_h2c->buf[0], ph2c_par, h2c_par_len);
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);
1990 gl_coex_offload.cnt_h2c_sent++;
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);
1996 h2c_status = halbtcoutsrc_send_h2c(Adapter, pcol_h2c, col_h2c_len);
1998 gl_coex_offload.h2c_record[opcode].c2h_ack_len = 0;
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;
2005 /* check h2c status error, return error status code to upper layer. */
2006 ret_status = h2c_status;
2008 gl_coex_offload.h2c_record[opcode].status[ret_status]++;
2009 gl_coex_offload.status[ret_status]++;
2014 u8 halbtcoutsrc_GetAntDetValFromBt(void *pBtcContext)
2016 /* Always return 0 since we don't implement this yet */
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;
2024 status = NDBG_GetAntDetValFromBt(Adapter, opcodeVer, &AntDetVal);
2026 RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$ halbtcoutsrc_GetAntDetValFromBt(): status = %d, feature = %x\n", status, AntDetVal));
2034 u8 halbtcoutsrc_GetBleScanTypeFromBt(void *pBtcContext)
2036 PBTC_COEXIST pBtCoexist;
2037 u32 ret = BT_STATUS_BT_OP_SUCCESS;
2040 pBtCoexist = (PBTC_COEXIST)pBtcContext;
2042 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2049 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
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;
2056 ret = SET_BT_MP_OPER_RET(op_code, status);
2058 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2061 ret = BT_STATUS_NOT_IMPLEMENT;
2066 u32 halbtcoutsrc_GetBleScanParaFromBt(void *pBtcContext, u8 scanType)
2068 PBTC_COEXIST pBtCoexist;
2069 u32 ret = BT_STATUS_BT_OP_SUCCESS;
2072 pBtCoexist = (PBTC_COEXIST)pBtcContext;
2074 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
2081 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
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);
2088 ret = SET_BT_MP_OPER_RET(op_code, status);
2090 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2093 ret = BT_STATUS_NOT_IMPLEMENT;
2098 u8 halbtcoutsrc_GetBtAFHMapFromBt(void *pBtcContext, u8 mapType, u8 *afhMap)
2100 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2104 u32 *AfhMapL = (u32 *)&(afhMap[0]);
2105 u32 *AfhMapM = (u32 *)&(afhMap[4]);
2106 u16 *AfhMapH = (u16 *)&(afhMap[8]);
2108 u32 ret = BT_STATUS_BT_OP_SUCCESS;
2110 if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _FALSE)
2116 _enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
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);
2123 ret = SET_BT_MP_OPER_RET(op_code, status);
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);
2132 ret = SET_BT_MP_OPER_RET(op_code, status);
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);
2141 ret = SET_BT_MP_OPER_RET(op_code, status);
2147 _exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
2149 return (ret == BT_STATUS_BT_OP_SUCCESS) ? _TRUE : _FALSE;
2152 u32 halbtcoutsrc_GetPhydmVersion(void *pBtcContext)
2154 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2155 PADAPTER Adapter = pBtCoexist->Adapter;
2157 #ifdef CONFIG_RTL8192E
2158 return RELEASE_VERSION_8192E;
2161 #ifdef CONFIG_RTL8821A
2162 return RELEASE_VERSION_8821A;
2165 #ifdef CONFIG_RTL8723B
2166 return RELEASE_VERSION_8723B;
2169 #ifdef CONFIG_RTL8812A
2170 return RELEASE_VERSION_8812A;
2173 #ifdef CONFIG_RTL8703B
2174 return RELEASE_VERSION_8703B;
2177 #ifdef CONFIG_RTL8822B
2178 return RELEASE_VERSION_8822B;
2181 #ifdef CONFIG_RTL8723D
2182 return RELEASE_VERSION_8723D;
2185 #ifdef CONFIG_RTL8821C
2186 return RELEASE_VERSION_8821C;
2190 void halbtcoutsrc_phydm_modify_RA_PCR_threshold(void *pBtcContext, u8 RA_offset_direction, u8 RA_threshold_offset)
2192 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2194 /* switch to #if 0 in case the phydm version does not provide the function */
2196 phydm_modify_RA_PCR_threshold(pBtCoexist->odm_priv, RA_offset_direction, RA_threshold_offset);
2200 u32 halbtcoutsrc_phydm_query_PHY_counter(void *pBtcContext, u8 info_type)
2202 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
2204 /* switch to #if 0 in case the phydm version does not provide the function */
2206 return phydm_cmn_info_query((struct PHY_DM_STRUCT *)pBtCoexist->odm_priv, (enum phydm_info_query_e)info_type);
2213 static void BT_CoexOffloadRecordErrC2hAck(PADAPTER Adapter)
2215 PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);
2217 if (pDefaultAdapter != Adapter)
2220 if (!hal_btcoex_IsBtExist(Adapter))
2223 gl_coex_offload.cnt_c2h_ack++;
2225 gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;
2228 static void BT_CoexOffloadC2hAckCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length)
2230 PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);
2231 PCOL_C2H_ACK p_c2h_ack = NULL;
2234 if (pDefaultAdapter != Adapter)
2237 if (!hal_btcoex_IsBtExist(Adapter))
2240 gl_coex_offload.cnt_c2h_ack++;
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]++;
2245 BT_PrintData(Adapter, "[COL], c2h ack:", length, tmpBuf);
2247 p_c2h_ack = (PCOL_C2H_ACK)tmpBuf;
2248 req_num = p_c2h_ack->req_num;
2250 _rtw_memmove(&gl_coex_offload.c2h_ack_buf[req_num][0], tmpBuf, length);
2251 gl_coex_offload.c2h_ack_len[req_num] = length;
2253 complete(&gl_coex_offload.c2h_event[req_num]);
2257 static void BT_CoexOffloadC2hIndCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length)
2259 PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);
2260 PCOL_C2H_IND p_c2h_ind = NULL;
2261 u8 ind_type = 0, ind_version = 0, ind_length = 0;
2263 if (pDefaultAdapter != Adapter)
2266 if (!hal_btcoex_IsBtExist(Adapter))
2269 gl_coex_offload.cnt_c2h_ind++;
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]++;
2274 BT_PrintData(Adapter, "[COL], c2h indication:", length, tmpBuf);
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;
2281 _rtw_memmove(&gl_coex_offload.c2h_ind_buf[0], tmpBuf, length);
2282 gl_coex_offload.c2h_ind_len = length;
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;
2290 gl_coex_offload.c2h_ind_status[COL_STATUS_C2H_OK]++;
2291 /*TODO: need to check c2h indication length*/
2292 /* TODO: Notification */
2296 void BT_CoexOffloadC2hCheck(PADAPTER Adapter, u8 *Buffer, u8 Length)
2298 #if 0 /*(USE_HAL_MAC_API == 1)*/
2299 u8 c2hSubCmdId = 0, c2hAckLen = 0, h2cCmdId = 0, h2cSubCmdId = 0, c2hIndLen = 0;
2301 BT_PrintData(Adapter, "[COL], c2h packet:", Length - 2, Buffer + 2);
2302 c2hSubCmdId = (u1Byte)C2H_HDR_GET_C2H_SUB_CMD_ID(Buffer);
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) {
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);
2313 BT_CoexOffloadC2hAckCheck(Adapter, &Buffer[12], (u1Byte)(c2hAckLen - 8));
2315 BT_CoexOffloadRecordErrC2hAck(Adapter);
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);
2327 /* ************************************
2328 * Extern functions called by other module
2329 * ************************************ */
2330 u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)
2332 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2333 u8 antNum = 1, chipType = 0, singleAntPath = 0;
2334 HAL_DATA_TYPE *pHalData = GET_HAL_DATA((PADAPTER)padapter);
2336 if (pBtCoexist->bBinded)
2339 pBtCoexist->bBinded = _TRUE;
2341 pBtCoexist->statistics.cnt_bind++;
2343 pBtCoexist->Adapter = padapter;
2344 pBtCoexist->odm_priv = (PVOID)&(pHalData->odmpriv);
2346 pBtCoexist->stack_info.profile_notified = _FALSE;
2348 pBtCoexist->bt_info.bt_ctrl_agg_buf_size = _FALSE;
2349 pBtCoexist->bt_info.agg_buf_size = 5;
2351 pBtCoexist->bt_info.increase_scan_dev_num = _FALSE;
2352 pBtCoexist->bt_info.miracast_plus_bt = _FALSE;
2354 antNum = rtw_btcoex_get_pg_ant_num((PADAPTER)padapter);
2355 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);
2358 singleAntPath = rtw_btcoex_get_pg_single_ant_path((PADAPTER)padapter);
2359 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);
2362 /* set default antenna position to main port */
2363 pBtCoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
2365 pBtCoexist->board_info.btdm_ant_det_finish = _FALSE;
2366 pBtCoexist->board_info.btdm_ant_num_by_ant_det = 1;
2368 pBtCoexist->board_info.tfbga_package = rtw_btcoex_is_tfbga_package_type((PADAPTER)padapter);
2370 pBtCoexist->board_info.rfe_type = rtw_btcoex_get_pg_rfe_type((PADAPTER)padapter);
2372 pBtCoexist->board_info.ant_div_cfg = rtw_btcoex_get_ant_div_cfg((PADAPTER)padapter);
2377 u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)
2379 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
2381 /* pBtCoexist->statistics.cntBind++; */
2383 halbtcoutsrc_DbgInit();
2385 halbtcoutsrc_coex_offload_init();
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;
2394 pBtCoexist->chip_interface = BTC_INTF_UNKNOWN;
2397 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);
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;
2408 pBtCoexist->btc_set_bb_reg = halbtcoutsrc_SetBbReg;
2409 pBtCoexist->btc_get_bb_reg = halbtcoutsrc_GetBbReg;
2411 pBtCoexist->btc_set_rf_reg = halbtcoutsrc_SetRfReg;
2412 pBtCoexist->btc_get_rf_reg = halbtcoutsrc_GetRfReg;
2414 pBtCoexist->btc_fill_h2c = halbtcoutsrc_FillH2cCmd;
2415 pBtCoexist->btc_disp_dbg_msg = halbtcoutsrc_DisplayDbgMsg;
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;
2434 pBtCoexist->cli_buf = &GLBtcDbgBuf[0];
2436 GLBtcWiFiInScanState = _FALSE;
2438 GLBtcWiFiInIQKState = _FALSE;
2440 GLBtcWiFiInIPS = _FALSE;
2442 GLBtcWiFiInLPS = _FALSE;
2444 GLBtcBtCoexAliveRegistered = _FALSE;
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;
2462 void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)
2464 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
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);
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);
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);
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);
2497 void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)
2499 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2502 pBtCoexist->statistics.cnt_pre_load_firmware++;
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);
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);
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);
2526 void EXhalbtcoutsrc_init_hw_config(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)
2528 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2531 pBtCoexist->statistics.cnt_init_hw_config++;
2533 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2535 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2536 ex_halbtc8821aCsr2ant_init_hw_config(pBtCoexist, bWifiOnly);
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);
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);
2587 void EXhalbtcoutsrc_init_coex_dm(PBTC_COEXIST pBtCoexist)
2589 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2592 pBtCoexist->statistics.cnt_init_coex_dm++;
2594 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2596 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2597 ex_halbtc8821aCsr2ant_init_coex_dm(pBtCoexist);
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);
2639 pBtCoexist->initilized = _TRUE;
2642 void EXhalbtcoutsrc_ips_notify(PBTC_COEXIST pBtCoexist, u8 type)
2646 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2649 pBtCoexist->statistics.cnt_ips_notify++;
2650 if (pBtCoexist->manual_control)
2653 if (IPS_NONE == type) {
2654 ipsType = BTC_IPS_LEAVE;
2655 GLBtcWiFiInIPS = _FALSE;
2657 ipsType = BTC_IPS_ENTER;
2658 GLBtcWiFiInIPS = _TRUE;
2661 /* All notify is called in cmd thread, don't need to leave low power again
2662 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2664 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2666 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2667 ex_halbtc8821aCsr2ant_ips_notify(pBtCoexist, ipsType);
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);
2709 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
2712 void EXhalbtcoutsrc_lps_notify(PBTC_COEXIST pBtCoexist, u8 type)
2717 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2720 pBtCoexist->statistics.cnt_lps_notify++;
2721 if (pBtCoexist->manual_control)
2724 if (PS_MODE_ACTIVE == type) {
2725 lpsType = BTC_LPS_DISABLE;
2726 GLBtcWiFiInLPS = _FALSE;
2728 lpsType = BTC_LPS_ENABLE;
2729 GLBtcWiFiInLPS = _TRUE;
2732 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2734 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2735 ex_halbtc8821aCsr2ant_lps_notify(pBtCoexist, lpsType);
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);
2778 void EXhalbtcoutsrc_scan_notify(PBTC_COEXIST pBtCoexist, u8 type)
2782 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2784 pBtCoexist->statistics.cnt_scan_notify++;
2785 if (pBtCoexist->manual_control)
2789 scanType = BTC_SCAN_START;
2790 GLBtcWiFiInScanState = _TRUE;
2792 scanType = BTC_SCAN_FINISH;
2793 GLBtcWiFiInScanState = _FALSE;
2796 /* All notify is called in cmd thread, don't need to leave low power again
2797 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2799 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2801 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2802 ex_halbtc8821aCsr2ant_scan_notify(pBtCoexist, scanType);
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);
2844 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
2847 void EXhalbtcoutsrc_SetAntennaPathNotify(PBTC_COEXIST pBtCoexist, u8 type)
2852 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2855 if (pBtCoexist->manual_control)
2858 halbtcoutsrc_LeaveLowPower(pBtCoexist);
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);
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);
2873 halbtcoutsrc_NormalLowPower(pBtCoexist);
2877 void EXhalbtcoutsrc_connect_notify(PBTC_COEXIST pBtCoexist, u8 action)
2881 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2883 pBtCoexist->statistics.cnt_connect_notify++;
2884 if (pBtCoexist->manual_control)
2888 assoType = BTC_ASSOCIATE_START;
2890 assoType = BTC_ASSOCIATE_FINISH;
2892 /* All notify is called in cmd thread, don't need to leave low power again
2893 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2895 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2897 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2898 ex_halbtc8821aCsr2ant_connect_notify(pBtCoexist, assoType);
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);
2940 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
2943 void EXhalbtcoutsrc_media_status_notify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)
2947 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
2950 pBtCoexist->statistics.cnt_media_status_notify++;
2951 if (pBtCoexist->manual_control)
2954 if (RT_MEDIA_CONNECT == mediaStatus)
2955 mStatus = BTC_MEDIA_CONNECT;
2957 mStatus = BTC_MEDIA_DISCONNECT;
2959 /* All notify is called in cmd thread, don't need to leave low power again
2960 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
2962 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
2964 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
2965 ex_halbtc8821aCsr2ant_media_status_notify(pBtCoexist, mStatus);
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);
3007 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
3010 void EXhalbtcoutsrc_specific_packet_notify(PBTC_COEXIST pBtCoexist, u8 pktType)
3014 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3016 pBtCoexist->statistics.cnt_specific_packet_notify++;
3017 if (pBtCoexist->manual_control)
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;
3027 packetType = BTC_PACKET_UNKNOWN;
3031 /* All notify is called in cmd thread, don't need to leave low power again
3032 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3034 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3036 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3037 ex_halbtc8821aCsr2ant_specific_packet_notify(pBtCoexist, packetType);
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);
3079 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
3082 void EXhalbtcoutsrc_bt_info_notify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)
3084 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3087 pBtCoexist->statistics.cnt_bt_info_notify++;
3089 /* All notify is called in cmd thread, don't need to leave low power again
3090 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3092 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3094 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3095 ex_halbtc8821aCsr2ant_bt_info_notify(pBtCoexist, tmpBuf, length);
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);
3137 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
3141 EXhalbtcoutsrc_RfStatusNotify(
3142 IN PBTC_COEXIST pBtCoexist,
3146 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3148 pBtCoexist->statistics.cnt_rf_status_notify++;
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);
3175 void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)
3180 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3182 pBtCoexist->statistics.cntStackOperationNotify++;
3183 if (pBtCoexist->manual_control)
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;
3196 stackOpType = BTC_STACK_OP_NONE;
3201 void EXhalbtcoutsrc_halt_notify(PBTC_COEXIST pBtCoexist)
3203 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3206 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3208 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3209 ex_halbtc8821aCsr2ant_halt_notify(pBtCoexist);
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);
3252 void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)
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 */
3263 void EXhalbtcoutsrc_pnp_notify(PBTC_COEXIST pBtCoexist, u8 pnpState)
3265 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
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. */
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)) {
3288 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3289 ex_halbtc8821aCsr2ant_pnp_notify(pBtCoexist, pnpState);
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);
3315 void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)
3317 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3319 pBtCoexist->statistics.cnt_coex_dm_switch++;
3321 halbtcoutsrc_LeaveLowPower(pBtCoexist);
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;
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;
3343 halbtcoutsrc_NormalLowPower(pBtCoexist);
3346 void EXhalbtcoutsrc_periodical(PBTC_COEXIST pBtCoexist)
3348 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3350 pBtCoexist->statistics.cnt_periodical++;
3352 /* Periodical should be called in cmd thread, */
3353 /* don't need to leave low power again
3354 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
3356 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3358 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3359 ex_halbtc8821aCsr2ant_periodical(pBtCoexist);
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);
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);
3403 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
3406 void EXhalbtcoutsrc_dbg_control(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)
3408 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3411 pBtCoexist->statistics.cnt_dbg_ctrl++;
3413 /* This function doesn't be called yet, */
3414 /* default no need to leave low power to avoid deadlock
3415 * halbtcoutsrc_LeaveLowPower(pBtCoexist); */
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);
3429 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
3434 EXhalbtcoutsrc_AntennaDetection(
3435 IN PBTC_COEXIST pBtCoexist,
3442 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3445 /* Need to refine the following power save operations to enable this function in the future */
3447 IPSDisable(pBtCoexist->Adapter, FALSE, 0);
3448 LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);
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);
3456 /* IPSReturn(pBtCoexist->Adapter, 0xff); */
3460 void EXhalbtcoutsrc_StackUpdateProfileInfo(void)
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;
3468 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3471 pBtCoexist->stack_info.profile_notified = _TRUE;
3473 pBtCoexist->stack_info.num_of_link =
3474 pBtMgnt->ExtConfig.NumberOfACL + pBtMgnt->ExtConfig.NumberOfSCO;
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;
3485 if (!pBtMgnt->ExtConfig.NumberOfACL)
3486 pBtCoexist->stack_info.min_bt_rssi = 0;
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;
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++;
3505 pBtCoexist->stack_info.unknown_acl_exist = _TRUE;
3507 #endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
3510 void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)
3512 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3514 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3517 pBtCoexist->stack_info.min_bt_rssi = btRssi;
3520 void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)
3522 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3524 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3527 pBtCoexist->stack_info.hci_version = hciVersion;
3530 void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)
3532 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
3534 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3537 pBtCoexist->bt_info.bt_real_fw_ver = btPatchVersion;
3538 pBtCoexist->bt_info.bt_hci_ver = btHciVersion;
3542 void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)
3544 GLBtCoexist.boardInfo.bBtExist = bBtExist;
3547 void EXhalbtcoutsrc_SetChipType(u8 chipType)
3555 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
3558 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
3561 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
3564 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
3567 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
3570 GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
3575 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)
3577 if (BT_COEX_ANT_TYPE_PG == type) {
3578 GLBtCoexist.board_info.pg_ant_num = antNum;
3579 GLBtCoexist.board_info.btdm_ant_num = antNum;
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;
3587 GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;
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; */
3599 * Currently used by 8723b only, S0 or S1
3601 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)
3603 GLBtCoexist.board_info.single_ant_path = singleAntPath;
3606 void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)
3608 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3611 halbtcoutsrc_LeaveLowPower(pBtCoexist);
3613 /* To prevent the racing with IPS enter */
3614 halbtcoutsrc_EnterPwrLock(pBtCoexist);
3616 if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {
3618 if (halbtcoutsrc_IsCsrBtCoex(pBtCoexist) == _TRUE)
3619 ex_halbtc8821aCsr2ant_display_coex_info(pBtCoexist);
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);
3661 halbtcoutsrc_ExitPwrLock(pBtCoexist);
3663 halbtcoutsrc_NormalLowPower(pBtCoexist);
3666 void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)
3668 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3671 halbtcoutsrc_LeaveLowPower(pBtCoexist);
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);
3683 halbtcoutsrc_NormalLowPower(pBtCoexist);
3686 void ex_halbtcoutsrc_pta_off_on_notify(PBTC_COEXIST pBtCoexist, u8 bBTON)
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);
3694 void EXhalbtcoutsrc_set_rfe_type(u8 type)
3696 GLBtCoexist.board_info.rfe_type= type;
3699 void EXhalbtcoutsrc_switchband_notify(struct btc_coexist *pBtCoexist, u8 type)
3701 if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
3704 if(pBtCoexist->manual_control)
3707 /* Driver should guarantee that the HW status isn't in low power mode */
3708 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */
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);
3722 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */
3725 static void halbt_init_hw_config92C(PADAPTER padapter)
3727 PHAL_DATA_TYPE pHalData;
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);
3738 rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
3739 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
3741 u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
3743 rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
3744 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
3749 static void halbt_init_hw_config92D(PADAPTER padapter)
3751 PHAL_DATA_TYPE pHalData;
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);
3761 rtw_write8(padapter, rOFDM0_TRxPathEnable, u1Tmp);
3762 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xC04 = 0x%x\n", u1Tmp));
3764 u1Tmp = rtw_read8(padapter, rOFDM1_TRxPathEnable);
3766 rtw_write8(padapter, rOFDM1_TRxPathEnable, u1Tmp);
3767 RT_DISP(FBT, BT_TRACE, ("[BTCoex], BT write 0xD04 = 0x%x\n", u1Tmp));
3774 * Run BT-Coexist mechansim or not
3777 void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)
3779 PHAL_DATA_TYPE pHalData;
3782 pHalData = GET_HAL_DATA(padapter);
3783 pHalData->bt_coexist.bBtExist = bBtExist;
3788 * Check is co-exist mechanism enabled or not
3791 * _TRUE Enable BT co-exist mechanism
3792 * _FALSE Disable BT co-exist mechanism
3794 u8 hal_btcoex_IsBtExist(PADAPTER padapter)
3796 PHAL_DATA_TYPE pHalData;
3799 pHalData = GET_HAL_DATA(padapter);
3800 return pHalData->bt_coexist.bBtExist;
3803 u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)
3805 if (!hal_btcoex_IsBtExist(padapter))
3808 if (GLBtCoexist.bt_info.bt_disabled)
3814 void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)
3816 PHAL_DATA_TYPE pHalData;
3818 pHalData = GET_HAL_DATA(padapter);
3819 pHalData->bt_coexist.btChipType = chipType;
3822 void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)
3824 PHAL_DATA_TYPE pHalData;
3826 pHalData = GET_HAL_DATA(padapter);
3828 pHalData->bt_coexist.btTotalAntNum = antNum;
3831 u8 hal_btcoex_Initialize(PADAPTER padapter)
3833 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);
3836 _rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));
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));
3842 ret = EXhalbtcoutsrc_InitlizeVariables((void *)padapter);
3847 void hal_btcoex_PowerOnSetting(PADAPTER padapter)
3849 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);
3852 void hal_btcoex_PowerOffSetting(PADAPTER padapter)
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);
3860 void hal_btcoex_PreLoadFirmware(PADAPTER padapter)
3862 EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);
3865 void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)
3867 if (!hal_btcoex_IsBtExist(padapter))
3870 EXhalbtcoutsrc_init_hw_config(&GLBtCoexist, bWifiOnly);
3871 EXhalbtcoutsrc_init_coex_dm(&GLBtCoexist);
3874 void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)
3876 EXhalbtcoutsrc_ips_notify(&GLBtCoexist, type);
3879 void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)
3881 EXhalbtcoutsrc_lps_notify(&GLBtCoexist, type);
3884 void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)
3886 EXhalbtcoutsrc_scan_notify(&GLBtCoexist, type);
3889 void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)
3891 EXhalbtcoutsrc_connect_notify(&GLBtCoexist, action);
3894 void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)
3896 EXhalbtcoutsrc_media_status_notify(&GLBtCoexist, mediaStatus);
3899 void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)
3901 EXhalbtcoutsrc_specific_packet_notify(&GLBtCoexist, pktType);
3904 void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)
3906 GLBtcWiFiInIQKState = state;
3909 void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3911 if (GLBtcWiFiInIQKState == _TRUE)
3914 EXhalbtcoutsrc_bt_info_notify(&GLBtCoexist, tmpBuf, length);
3917 void hal_btcoex_BtMpRptNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)
3919 u8 extid, status, len, seq;
3922 if (!GLBtcBtMpRptWait)
3925 if ((length < 3) || (!tmpBuf))
3929 /* not response from BT FW then exit*/
3931 case C2H_WIFI_FW_ACTIVE_RSP:
3932 GLBtcBtMpRptWiFiOK = 1;
3935 case C2H_TRIG_BY_BT_FW:
3936 _cancel_timer_ex(&GLBtcBtMpOperTimer);
3937 GLBtcBtMpRptWait = 0;
3938 GLBtcBtMpRptBTOK = 1;
3945 status = tmpBuf[1] & 0xF;
3947 seq = tmpBuf[2] >> 4;
3949 GLBtcBtMpRptSeq = seq;
3950 GLBtcBtMpRptStatus = status;
3951 _rtw_memcpy(GLBtcBtMpRptRsp, tmpBuf + 3, len);
3952 GLBtcBtMpRptRspSize = len;
3953 _rtw_up_sema(&GLBtcBtMpRptSema);
3956 void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)
3959 case BTCOEX_SUSPEND_STATE_SUSPEND:
3960 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);
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 */
3965 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);
3967 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);
3968 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);
3971 case BTCOEX_SUSPEND_STATE_RESUME:
3972 EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_WAKE_UP);
3977 void hal_btcoex_HaltNotify(PADAPTER padapter, u8 do_halt)
3980 EXhalbtcoutsrc_halt_notify(&GLBtCoexist);
3982 GLBtCoexist.bBinded = _FALSE;
3983 GLBtCoexist.Adapter = NULL;
3986 void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)
3988 EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);
3991 void hal_btcoex_Hanlder(PADAPTER padapter)
3995 EXhalbtcoutsrc_periodical(&GLBtCoexist);
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;
4003 s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)
4005 return (s32)GLBtCoexist.bt_info.reject_agg_pkt;
4008 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)
4010 return (s32)GLBtCoexist.bt_info.bt_ctrl_agg_buf_size;
4013 u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)
4015 return (u32)GLBtCoexist.bt_info.agg_buf_size;
4018 void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)
4020 GLBtCoexist.manual_control = bmanual;
4023 u8 hal_btcoex_1Ant(PADAPTER padapter)
4025 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
4028 if (GLBtCoexist.board_info.btdm_ant_num == 1)
4034 u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)
4036 if (GLBtCoexist.bdontenterLPS == _TRUE)
4039 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
4042 if (GLBtCoexist.bt_info.bt_disabled)
4045 if (GLBtCoexist.bt_info.bt_ctrl_lps)
4051 u8 hal_btcoex_IsLpsOn(PADAPTER padapter)
4053 if (GLBtCoexist.bdontenterLPS == _TRUE)
4056 if (hal_btcoex_IsBtExist(padapter) == _FALSE)
4059 if (GLBtCoexist.bt_info.bt_disabled)
4062 if (GLBtCoexist.bt_info.bt_lps_on)
4068 u8 hal_btcoex_RpwmVal(PADAPTER padapter)
4070 return GLBtCoexist.bt_info.rpwm_val;
4073 u8 hal_btcoex_LpsVal(PADAPTER padapter)
4075 return GLBtCoexist.bt_info.lps_val;
4078 u32 hal_btcoex_GetRaMask(PADAPTER padapter)
4080 if (!hal_btcoex_IsBtExist(padapter))
4083 if (GLBtCoexist.bt_info.bt_disabled)
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.
4089 /*if (GLBtCoexist.board_info.btdm_ant_num != 1)
4092 return GLBtCoexist.bt_info.ra_mask;
4095 void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)
4098 _rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);
4101 void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)
4106 pinfo = &GLBtcDbgInfo;
4107 DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);
4108 EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);
4109 DBG_BT_INFO_INIT(pinfo, NULL, 0);
4112 void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)
4117 if (NULL == pDbgModule)
4120 for (i = 0; i < COMP_MAX; i++)
4121 GLBtcDbgType[i] = pDbgModule[i];
4124 u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)
4131 if ((NULL == pStrBuf) || (0 == bufSize))
4137 /* RTW_INFO(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize); */
4139 count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);
4140 if ((count < 0) || (count >= leftSize))
4145 count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");
4146 if ((count < 0) || (count >= leftSize))
4151 count = rtw_sprintf(pstr, leftSize,
4152 "COMP_COEX: 0x%08X\n\n",
4153 GLBtcDbgType[COMP_COEX]);
4154 if ((count < 0) || (count >= leftSize))
4160 count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");
4161 if ((count < 0) || (count >= leftSize))
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))
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))
4178 count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");
4179 if ((count < 0) || (count >= leftSize))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
4246 count = pstr - pStrBuf;
4247 /* RTW_INFO(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count); */
4252 u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)
4254 if (!hal_btcoex_IsBtExist(padapter))
4257 if (GLBtCoexist.bt_info.increase_scan_dev_num)
4263 u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)
4265 if (GLBtCoexist.bt_link_info.bt_link_exist)
4271 void hal_btcoex_SetBtPatchVersion(PADAPTER padapter, u16 btHciVer, u16 btPatchVer)
4273 EXhalbtcoutsrc_SetBtPatchVersion(btHciVer, btPatchVer);
4276 void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)
4278 EXhalbtcoutsrc_SetHciVersion(hciVersion);
4281 void hal_btcoex_StackUpdateProfileInfo(void)
4283 EXhalbtcoutsrc_StackUpdateProfileInfo();
4286 void hal_btcoex_pta_off_on_notify(PADAPTER padapter, u8 bBTON)
4288 ex_halbtcoutsrc_pta_off_on_notify(&GLBtCoexist, bBTON);
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
4303 void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)
4305 PHAL_DATA_TYPE pHalData;
4306 PBTC_COEXIST pBtCoexist = &GLBtCoexist;
4308 /*RTW_INFO("####%s , anttype = %d , %d\n" , __func__ , anttype , __LINE__); */
4309 pHalData = GET_HAL_DATA(padapter);
4312 pHalData->bt_coexist.btAntisolation = anttype;
4314 switch (pHalData->bt_coexist.btAntisolation) {
4316 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_0;
4319 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_1;
4322 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_2;
4325 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_3;
4328 pBtCoexist->board_info.ant_type = (u1Byte)BTC_ANT_TYPE_4;
4334 #ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE
4336 hal_btcoex_ParseAntIsolationConfigFile(
4341 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
4343 char *szLine , *ptmp;
4344 int rtStatus = _SUCCESS;
4345 char param_value_string[10];
4349 u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1;
4351 typedef struct ant_isolation {
4352 char *param_name; /* antenna isolation config parameter name */
4353 u8 *value; /* antenna isolation config parameter value */
4356 ANT_ISOLATION ant_isolation_param[] = {
4357 {"ANT_NUMBER" , &ant_num},
4358 {"ANT_DISTANCE" , &ant_distance},
4359 {"RFE_TYPE" , &rfe_type},
4365 /* RTW_INFO("===>Hal_ParseAntIsolationConfigFile()\n" ); */
4368 for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {
4370 if (IsCommentString(szLine))
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) {
4377 while (i < strlen(szLine)) {
4378 if (szLine[i] != '"')
4381 /* skip only has one " */
4382 if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) {
4383 RTW_INFO("Fail to parse parameters , format error!\n");
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");
4390 } else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value))
4391 RTW_INFO("Fail to GetU1ByteIntegerFromStringInDecimal\n");
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)
4404 else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1)
4406 else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50)
4408 else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1)
4410 else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15))
4412 else if (ant_num == 2 && rfe_type == 0)
4417 hal_btcoex_SetAntIsolationType(Adapter, anttype);
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"); */
4428 hal_btcoex_AntIsolationConfig_ParaFile(
4429 IN PADAPTER Adapter,
4433 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
4434 int rlen = 0 , rtStatus = _FAIL;
4436 _rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN);
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);
4442 rtStatus = _SUCCESS;
4446 if (rtStatus == _SUCCESS) {
4447 /*RTW_INFO("%s(): read %s ok\n", __func__ , pFileName);*/
4448 rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf);
4450 RTW_INFO("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName);
4454 #endif /* CONFIG_LOAD_PHY_PARA_FROM_FILE */
4456 u16 hal_btcoex_btreg_read(PADAPTER padapter, u8 type, u16 addr, u32 *data)
4460 halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
4462 ret = halbtcoutsrc_GetBtReg_with_status(&GLBtCoexist, type, addr, data);
4464 halbtcoutsrc_NormalLowPower(&GLBtCoexist);
4469 u16 hal_btcoex_btreg_write(PADAPTER padapter, u8 type, u16 addr, u16 val)
4473 halbtcoutsrc_LeaveLowPower(&GLBtCoexist);
4475 ret = halbtcoutsrc_SetBtReg(&GLBtCoexist, type, addr, val);
4477 halbtcoutsrc_NormalLowPower(&GLBtCoexist);
4482 void hal_btcoex_set_rfe_type(u8 type)
4484 EXhalbtcoutsrc_set_rfe_type(type);
4486 void hal_btcoex_switchband_notify(u8 under_scan, u8 band_type)
4488 switch (band_type) {
4491 EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G);
4493 EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G_NOFORSCAN);
4496 EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_5G);
4499 RTW_INFO("[BTCOEX] unkown switch band type\n");
4503 #endif /* CONFIG_BT_COEXIST */