Path: blob/master/ALFA-W1F1/RTL8814AU/hal/hal_btcoex.c
1307 views
/******************************************************************************1*2* Copyright(c) 2013 - 2017 Realtek Corporation.3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of version 2 of the GNU General Public License as6* published by the Free Software Foundation.7*8* This program is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for11* more details.12*13*****************************************************************************/14#define __HAL_BTCOEX_C__1516#ifdef CONFIG_BT_COEXIST1718#include <hal_data.h>19#include <hal_btcoex.h>20#include "btc/mp_precomp.h"2122/* ************************************23* Global variables24* ************************************ */25const char *const BtProfileString[] = {26"NONE",27"A2DP",28"PAN",29"HID",30"SCO",31};3233const char *const BtSpecString[] = {34"1.0b",35"1.1",36"1.2",37"2.0+EDR",38"2.1+EDR",39"3.0+HS",40"4.0",41};4243const char *const BtLinkRoleString[] = {44"Master",45"Slave",46};4748const char *const h2cStaString[] = {49"successful",50"h2c busy",51"rf off",52"fw not read",53};5455const char *const ioStaString[] = {56"success",57"can not IO",58"rf off",59"fw not read",60"wait io timeout",61"invalid len",62"idle Q empty",63"insert waitQ fail",64"unknown fail",65"wrong level",66"h2c stopped",67};6869const char *const GLBtcWifiBwString[] = {70"11bg",71"HT20",72"HT40",73"VHT80",74"VHT160"75};7677const char *const GLBtcWifiFreqString[] = {78"2.4G",79"5G",80"2.4G+5G"81};8283const char *const GLBtcIotPeerString[] = {84"UNKNOWN",85"REALTEK",86"REALTEK_92SE",87"BROADCOM",88"RALINK",89"ATHEROS",90"CISCO",91"MERU",92"MARVELL",93"REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */94"SELF_SOFTAP", /* Self is SoftAP */95"AIRGO",96"INTEL",97"RTK_APCLIENT",98"REALTEK_81XX",99"REALTEK_WOW",100"REALTEK_JAGUAR_BCUTAP",101"REALTEK_JAGUAR_CCUTAP"102};103104const char *const coexOpcodeString[] = {105"Wifi status notify",106"Wifi progress",107"Wifi info",108"Power state",109"Set Control",110"Get Control"111};112113const char *const coexIndTypeString[] = {114"bt info",115"pstdma",116"limited tx/rx",117"coex table",118"request"119};120121const char *const coexH2cResultString[] = {122"ok",123"unknown",124"un opcode",125"opVer MM",126"par Err",127"par OoR",128"reqNum MM",129"halMac Fail",130"h2c TimeOut",131"Invalid c2h Len",132"data overflow"133};134135#define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS 8000136137struct btc_coexist GLBtCoexist;138BTC_OFFLOAD gl_coex_offload;139u8 GLBtcWiFiInScanState;140u8 GLBtcWiFiInIQKState;141u8 GLBtcWiFiInIPS;142u8 GLBtcWiFiInLPS;143u8 GLBtcBtCoexAliveRegistered;144145/*146* BT control H2C/C2H147*/148/* EXT_EID */149typedef enum _bt_ext_eid {150C2H_WIFI_FW_ACTIVE_RSP = 0,151C2H_TRIG_BY_BT_FW152} BT_EXT_EID;153154/* C2H_STATUS */155typedef enum _bt_c2h_status {156BT_STATUS_OK = 0,157BT_STATUS_VERSION_MISMATCH,158BT_STATUS_UNKNOWN_OPCODE,159BT_STATUS_ERROR_PARAMETER160} BT_C2H_STATUS;161162/* C2H BT OP CODES */163typedef enum _bt_op_code {164BT_OP_GET_BT_VERSION = 0x00,165BT_OP_WRITE_REG_ADDR = 0x0c,166BT_OP_WRITE_REG_VALUE = 0x0d,167168BT_OP_READ_REG = 0x11,169170BT_LO_OP_GET_AFH_MAP_L = 0x1e,171BT_LO_OP_GET_AFH_MAP_M = 0x1f,172BT_LO_OP_GET_AFH_MAP_H = 0x20,173174BT_OP_GET_BT_COEX_SUPPORTED_FEATURE = 0x2a,175BT_OP_GET_BT_COEX_SUPPORTED_VERSION = 0x2b,176BT_OP_GET_BT_ANT_DET_VAL = 0x2c,177BT_OP_GET_BT_BLE_SCAN_TYPE = 0x2d,178BT_OP_GET_BT_BLE_SCAN_PARA = 0x2e,179BT_OP_GET_BT_DEVICE_INFO = 0x30,180BT_OP_GET_BT_FORBIDDEN_SLOT_VAL = 0x31,181BT_OP_SET_BT_LANCONSTRAIN_LEVEL = 0x32,182BT_OP_SET_BT_TEST_MODE_VAL = 0x33,183BT_OP_MAX184} BT_OP_CODE;185186#define BTC_MPOPER_TIMEOUT 50 /* unit: ms */187188#define C2H_MAX_SIZE 16189u8 GLBtcBtMpOperSeq;190_mutex GLBtcBtMpOperLock;191_timer GLBtcBtMpOperTimer;192_sema GLBtcBtMpRptSema;193u8 GLBtcBtMpRptSeq;194u8 GLBtcBtMpRptStatus;195u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE];196u8 GLBtcBtMpRptRspSize;197u8 GLBtcBtMpRptWait;198u8 GLBtcBtMpRptWiFiOK;199u8 GLBtcBtMpRptBTOK;200201/*202* Debug203*/204u32 GLBtcDbgType[COMP_MAX];205u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];206u8 gl_btc_trace_buf[BT_TMP_BUF_SIZE];207208typedef struct _btcoexdbginfo {209u8 *info;210u32 size; /* buffer total size */211u32 len; /* now used length */212} BTCDBGINFO, *PBTCDBGINFO;213214BTCDBGINFO GLBtcDbgInfo;215216#define BT_Operation(Adapter) _FALSE217218static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)219{220if (NULL == pinfo)221return;222223_rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));224225if (pbuf && size) {226pinfo->info = pbuf;227pinfo->size = size;228}229}230231void DBG_BT_INFO(u8 *dbgmsg)232{233PBTCDBGINFO pinfo;234u32 msglen, buflen;235u8 *pbuf;236237238pinfo = &GLBtcDbgInfo;239240if (NULL == pinfo->info)241return;242243msglen = strlen(dbgmsg);244if (pinfo->len + msglen > pinfo->size)245return;246247pbuf = pinfo->info + pinfo->len;248_rtw_memcpy(pbuf, dbgmsg, msglen);249pinfo->len += msglen;250}251252/* ************************************253* Debug related function254* ************************************ */255static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)256{257if (!pBtCoexist->bBinded ||258NULL == pBtCoexist->Adapter)259return _FALSE;260return _TRUE;261}262263static void halbtcoutsrc_DbgInit(void)264{265u8 i;266267for (i = 0; i < COMP_MAX; i++)268GLBtcDbgType[i] = 0;269}270271static void halbtcoutsrc_EnterPwrLock(PBTC_COEXIST pBtCoexist)272{273struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);274struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);275276_enter_pwrlock(&pwrpriv->lock);277}278279static void halbtcoutsrc_ExitPwrLock(PBTC_COEXIST pBtCoexist)280{281struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);282struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);283284_exit_pwrlock(&pwrpriv->lock);285}286287static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)288{289if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4290|| pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8291)292return _FALSE;293else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))294return _FALSE;295else296return _TRUE;297}298299static u8 halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)300{301PADAPTER padapter;302303304padapter = pBtCoexist->Adapter;305306pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;307pBtCoexist->bt_info.bt_lps_on = _FALSE;308309return rtw_btcoex_LPS_Leave(padapter);310}311312void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)313{314PADAPTER padapter;315316317padapter = pBtCoexist->Adapter;318319if (pBtCoexist->bdontenterLPS == _FALSE) {320pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;321pBtCoexist->bt_info.bt_lps_on = _TRUE;322323rtw_btcoex_LPS_Enter(padapter);324}325}326327void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)328{329PADAPTER padapter;330331332333padapter = pBtCoexist->Adapter;334335if (pBtCoexist->bt_info.bt_ctrl_lps) {336pBtCoexist->bt_info.bt_lps_on = _FALSE;337rtw_btcoex_LPS_Leave(padapter);338pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;339340/* recover the LPS state to the original */341#if 0342padapter->hal_func.UpdateLPSStatusHandler(343padapter,344pPSC->RegLeisurePsMode,345pPSC->RegPowerSaveMode);346#endif347}348}349350void halbtcoutsrc_Pre_NormalLps(PBTC_COEXIST pBtCoexist)351{352PADAPTER padapter;353354padapter = pBtCoexist->Adapter;355356if (pBtCoexist->bt_info.bt_ctrl_lps) {357pBtCoexist->bt_info.bt_lps_on = _FALSE;358rtw_btcoex_LPS_Leave(padapter);359}360}361362void halbtcoutsrc_Post_NormalLps(PBTC_COEXIST pBtCoexist)363{364if (pBtCoexist->bt_info.bt_ctrl_lps)365pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;366}367368/*369* Constraint:370* 1. this function will request pwrctrl->lock371*/372void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)373{374#ifdef CONFIG_LPS_LCLK375PADAPTER padapter;376PHAL_DATA_TYPE pHalData;377struct pwrctrl_priv *pwrctrl;378s32 ready;379systime stime;380s32 utime;381u32 timeout; /* unit: ms */382383384padapter = pBtCoexist->Adapter;385pHalData = GET_HAL_DATA(padapter);386pwrctrl = adapter_to_pwrctl(padapter);387ready = _FAIL;388#ifdef LPS_RPWM_WAIT_MS389timeout = LPS_RPWM_WAIT_MS;390#else /* !LPS_RPWM_WAIT_MS */391timeout = 30;392#endif /* !LPS_RPWM_WAIT_MS */393394if (GLBtcBtCoexAliveRegistered == _TRUE)395return;396397stime = rtw_get_current_time();398do {399ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);400if (_SUCCESS == ready)401break;402403utime = rtw_get_passing_time_ms(stime);404if (utime > timeout)405break;406407rtw_msleep_os(1);408} while (1);409410GLBtcBtCoexAliveRegistered = _TRUE;411#endif /* CONFIG_LPS_LCLK */412}413414/*415* Constraint:416* 1. this function will request pwrctrl->lock417*/418void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)419{420#ifdef CONFIG_LPS_LCLK421PADAPTER padapter;422423if (GLBtcBtCoexAliveRegistered == _FALSE)424return;425426padapter = pBtCoexist->Adapter;427rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);428429GLBtcBtCoexAliveRegistered = _FALSE;430#endif /* CONFIG_LPS_LCLK */431}432433void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)434{435pBtCoexist->bt_info.bt_disable_low_pwr = bLowPwrDisable;436if (bLowPwrDisable)437halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */438else439halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */440}441442void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)443{444PADAPTER padapter;445BOOLEAN bNeedToAct = _FALSE;446static u32 preTime = 0;447u32 curTime = 0;448449padapter = pBtCoexist->Adapter;450451/* ===================================== */452/* To void continuous deleteBA=>addBA=>deleteBA=>addBA */453/* This function is not allowed to continuous called. */454/* It can only be called after 8 seconds. */455/* ===================================== */456457curTime = rtw_systime_to_ms(rtw_get_current_time());458if ((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS) /* over 8 seconds you can execute this function again. */459return;460else461preTime = curTime;462463if (pBtCoexist->bt_info.reject_agg_pkt) {464bNeedToAct = _TRUE;465pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;466} else {467if (pBtCoexist->bt_info.pre_reject_agg_pkt) {468bNeedToAct = _TRUE;469pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;470}471472if (pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size !=473pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {474bNeedToAct = _TRUE;475pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size = pBtCoexist->bt_info.bt_ctrl_agg_buf_size;476}477478if (pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {479if (pBtCoexist->bt_info.pre_agg_buf_size !=480pBtCoexist->bt_info.agg_buf_size)481bNeedToAct = _TRUE;482pBtCoexist->bt_info.pre_agg_buf_size = pBtCoexist->bt_info.agg_buf_size;483}484}485486if (bNeedToAct)487rtw_btcoex_rx_ampdu_apply(padapter);488}489490u8 halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist)491{492PADAPTER padapter;493PHAL_DATA_TYPE pHalData;494495padapter = pBtCoexist->Adapter;496pHalData = GET_HAL_DATA(padapter);497498return pHalData->bautoload_fail_flag;499}500501u8 halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist)502{503PADAPTER padapter;504505padapter = pBtCoexist->Adapter;506507return GET_HAL_DATA(padapter)->bFWReady;508}509510u8 halbtcoutsrc_IsDualBandConnected(PADAPTER padapter)511{512u8 ret = BTC_MULTIPORT_SCC;513514#ifdef CONFIG_MCC_MODE515if (MCC_EN(padapter) && (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))) {516struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);517struct mcc_obj_priv *mccobjpriv = &(dvobj->mcc_objpriv);518u8 band0 = mccobjpriv->iface[0]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;519u8 band1 = mccobjpriv->iface[1]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;520521if (band0 != band1)522ret = BTC_MULTIPORT_MCC_DUAL_BAND;523else524ret = BTC_MULTIPORT_MCC_DUAL_CHANNEL;525}526#endif527528return ret;529}530531u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)532{533if (rtw_mi_check_status(padapter, MI_AP_ASSOC))534return _TRUE;535if (rtw_mi_busy_traffic_check(padapter, _FALSE))536return _TRUE;537538return _FALSE;539}540541static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)542{543struct mlme_priv *pmlmepriv;544u8 bp2p;545u32 portConnectedStatus;546547548pmlmepriv = &padapter->mlmepriv;549bp2p = _FALSE;550portConnectedStatus = 0;551552#ifdef CONFIG_P2P553if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))554bp2p = _TRUE;555#endif /* CONFIG_P2P */556557if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {558if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {559if (_TRUE == bp2p)560portConnectedStatus |= WIFI_P2P_GO_CONNECTED;561else562portConnectedStatus |= WIFI_AP_CONNECTED;563} else {564if (_TRUE == bp2p)565portConnectedStatus |= WIFI_P2P_GC_CONNECTED;566else567portConnectedStatus |= WIFI_STA_CONNECTED;568}569}570571return portConnectedStatus;572}573574u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)575{576/* ================================= */577/* return value: */578/* [31:16]=> connected port number */579/* [15:0]=> port connected bit define */580/* ================================ */581582PADAPTER padapter;583u32 retVal;584u32 portConnectedStatus, numOfConnectedPort;585struct dvobj_priv *dvobj;586_adapter *iface;587int i;588589padapter = pBtCoexist->Adapter;590retVal = 0;591portConnectedStatus = 0;592numOfConnectedPort = 0;593dvobj = adapter_to_dvobj(padapter);594595for (i = 0; i < dvobj->iface_nums; i++) {596iface = dvobj->padapters[i];597if ((iface) && rtw_is_adapter_up(iface)) {598retVal = _halbtcoutsrc_GetWifiLinkStatus(iface);599if (retVal) {600portConnectedStatus |= retVal;601numOfConnectedPort++;602}603}604}605retVal = (numOfConnectedPort << 16) | portConnectedStatus;606607return retVal;608}609610struct btc_wifi_link_info halbtcoutsrc_getwifilinkinfo(PBTC_COEXIST pBtCoexist)611{612u8 n_assoc_iface = 0, i =0, mcc_en = _FALSE;613PADAPTER adapter = NULL;614PADAPTER iface = NULL;615PADAPTER sta_iface = NULL, p2p_iface = NULL, ap_iface = NULL;616BTC_LINK_MODE btc_link_moe = BTC_LINK_MAX;617struct dvobj_priv *dvobj = NULL;618struct mlme_ext_priv *mlmeext = NULL;619struct btc_wifi_link_info wifi_link_info;620621adapter = (PADAPTER)pBtCoexist->Adapter;622dvobj = adapter_to_dvobj(adapter);623n_assoc_iface = rtw_mi_get_assoc_if_num(adapter);624625/* init value */626wifi_link_info.link_mode = BTC_LINK_NONE;627wifi_link_info.sta_center_channel = 0;628wifi_link_info.p2p_center_channel = 0;629wifi_link_info.bany_client_join_go = _FALSE;630wifi_link_info.benable_noa = _FALSE;631wifi_link_info.bhotspot = _FALSE;632633for (i = 0; i < dvobj->iface_nums; i++) {634iface = dvobj->padapters[i];635if (!iface)636continue;637638mlmeext = &iface->mlmeextpriv;639if (MLME_IS_GO(iface)) {640wifi_link_info.link_mode = BTC_LINK_ONLY_GO;641wifi_link_info.p2p_center_channel =642rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);643p2p_iface = iface;644if (rtw_linked_check(iface))645wifi_link_info.bany_client_join_go = _TRUE;646} else if (MLME_IS_GC(iface)) {647wifi_link_info.link_mode = BTC_LINK_ONLY_GC;648wifi_link_info.p2p_center_channel =649rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);650p2p_iface = iface;651} else if (MLME_IS_AP(iface)) {652wifi_link_info.link_mode = BTC_LINK_ONLY_AP;653ap_iface = iface;654wifi_link_info.p2p_center_channel =655rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);656} else if (MLME_IS_STA(iface) && rtw_linked_check(iface)) {657wifi_link_info.link_mode = BTC_LINK_ONLY_STA;658wifi_link_info.sta_center_channel =659rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);660sta_iface = iface;661}662}663664#ifdef CONFIG_MCC_MODE665if (MCC_EN(adapter)) {666if (rtw_hal_check_mcc_status(adapter, MCC_STATUS_DOING_MCC))667mcc_en = _TRUE;668}669#endif/* CONFIG_MCC_MODE */670671if (n_assoc_iface == 0) {672wifi_link_info.link_mode = BTC_LINK_NONE;673} else if (n_assoc_iface == 1) {674/* by pass */675} else if (n_assoc_iface == 2) {676if (sta_iface && p2p_iface) {677u8 band_sta = sta_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;678u8 band_p2p = p2p_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;679if (band_sta == band_p2p) {680switch (band_sta) {681case BAND_ON_2_4G:682if (MLME_IS_GO(p2p_iface)) {683#ifdef CONFIG_MCC_MODE684wifi_link_info.link_mode =685mcc_en == _TRUE ? BTC_LINK_2G_MCC_GO_STA : BTC_LINK_2G_SCC_GO_STA;686#else /* !CONFIG_MCC_MODE */687wifi_link_info.link_mode = BTC_LINK_2G_SCC_GO_STA;688#endif /* CONFIG_MCC_MODE */689} else if (MLME_IS_GC(p2p_iface)) {690#ifdef CONFIG_MCC_MODE691wifi_link_info.link_mode =692mcc_en == _TRUE ? BTC_LINK_2G_MCC_GC_STA : BTC_LINK_2G_SCC_GC_STA;693#else /* !CONFIG_MCC_MODE */694wifi_link_info.link_mode = BTC_LINK_2G_SCC_GC_STA;695#endif /* CONFIG_MCC_MODE */696}697break;698case BAND_ON_5G:699if (MLME_IS_GO(p2p_iface)) {700#ifdef CONFIG_MCC_MODE701wifi_link_info.link_mode =702mcc_en == _TRUE ? BTC_LINK_5G_MCC_GO_STA : BTC_LINK_5G_SCC_GO_STA;703#else /* !CONFIG_MCC_MODE */704wifi_link_info.link_mode = BTC_LINK_5G_SCC_GO_STA;705#endif /* CONFIG_MCC_MODE */706} else if (MLME_IS_GC(p2p_iface)) {707#ifdef CONFIG_MCC_MODE708wifi_link_info.link_mode =709mcc_en == _TRUE ? BTC_LINK_5G_MCC_GC_STA : BTC_LINK_5G_SCC_GC_STA;710#else /* !CONFIG_MCC_MODE */711wifi_link_info.link_mode = BTC_LINK_5G_SCC_GC_STA;712#endif /* CONFIG_MCC_MODE */713}714break;715}716} else {717if (MLME_IS_GO(p2p_iface))718wifi_link_info.link_mode = BTC_LINK_25G_MCC_GO_STA;719else if (MLME_IS_GC(p2p_iface))720wifi_link_info.link_mode = BTC_LINK_25G_MCC_GC_STA;721}722}723} else {724if (pBtCoexist->board_info.btdm_ant_num == 1)725RTW_ERR("%s do not support n_assoc_iface > 2 (ant_num == 1)", __func__);726}727728return wifi_link_info;729}730731732static void _btmpoper_timer_hdl(void *p)733{734if (GLBtcBtMpRptWait == _TRUE) {735GLBtcBtMpRptWait = _FALSE;736_rtw_up_sema(&GLBtcBtMpRptSema);737}738}739740/*741* !IMPORTANT!742* Before call this function, caller should acquire "GLBtcBtMpOperLock"!743* Othrewise there will be racing problem and something may go wrong.744*/745static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size)746{747PADAPTER padapter;748u8 buf[H2C_BTMP_OPER_LEN] = {0};749u8 buflen;750u8 seq;751s32 ret;752753754if (!cmd && size)755size = 0;756if ((size + 2) > H2C_BTMP_OPER_LEN)757return BT_STATUS_H2C_LENGTH_EXCEEDED;758buflen = size + 2;759760seq = GLBtcBtMpOperSeq & 0xF;761GLBtcBtMpOperSeq++;762763buf[0] = (opcodever & 0xF) | (seq << 4);764buf[1] = opcode;765if (cmd && size)766_rtw_memcpy(buf + 2, cmd, size);767768GLBtcBtMpRptWait = _TRUE;769GLBtcBtMpRptWiFiOK = _FALSE;770GLBtcBtMpRptBTOK = _FALSE;771GLBtcBtMpRptStatus = 0;772padapter = pBtCoexist->Adapter;773_set_timer(&GLBtcBtMpOperTimer, BTC_MPOPER_TIMEOUT);774if (rtw_hal_fill_h2c_cmd(padapter, H2C_BT_MP_OPER, buflen, buf) == _FAIL) {775_cancel_timer_ex(&GLBtcBtMpOperTimer);776ret = BT_STATUS_H2C_FAIL;777goto exit;778}779780_rtw_down_sema(&GLBtcBtMpRptSema);781/* GLBtcBtMpRptWait should be _FALSE here*/782783if (GLBtcBtMpRptWiFiOK == _FALSE) {784RTW_ERR("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__);785ret = BT_STATUS_H2C_TIMTOUT;786goto exit;787}788if (GLBtcBtMpRptBTOK == _FALSE) {789RTW_DBG("%s: Didn't get BT response!\n", __FUNCTION__);790ret = BT_STATUS_H2C_BT_NO_RSP;791goto exit;792}793794if (seq != GLBtcBtMpRptSeq) {795RTW_ERR("%s: Sequence number not match!(%d!=%d)!\n",796__FUNCTION__, seq, GLBtcBtMpRptSeq);797ret = BT_STATUS_C2H_REQNUM_MISMATCH;798goto exit;799}800801switch (GLBtcBtMpRptStatus) {802/* Examine the status reported from C2H */803case BT_STATUS_OK:804ret = BT_STATUS_BT_OP_SUCCESS;805RTW_DBG("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__);806break;807case BT_STATUS_VERSION_MISMATCH:808ret = BT_STATUS_OPCODE_L_VERSION_MISMATCH;809RTW_DBG("%s: C2H status = BT_STATUS_OPCODE_L_VERSION_MISMATCH\n", __FUNCTION__);810break;811case BT_STATUS_UNKNOWN_OPCODE:812ret = BT_STATUS_UNKNOWN_OPCODE_L;813RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_OPCODE_L\n", __FUNCTION__);814break;815case BT_STATUS_ERROR_PARAMETER:816ret = BT_STATUS_PARAMETER_FORMAT_ERROR_L;817RTW_DBG("%s: C2H status = MP_BT_STATUS_PARAMETER_FORMAT_ERROR_L\n", __FUNCTION__);818break;819default:820ret = BT_STATUS_UNKNOWN_STATUS_L;821RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__);822break;823}824825exit:826return ret;827}828829u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)830{831if (pBtCoexist->bt_info.get_bt_fw_ver_cnt <= 5) {832if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {833_irqL irqL;834u8 ret;835836_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);837838ret = _btmpoper_cmd(pBtCoexist, BT_OP_GET_BT_VERSION, 0, NULL, 0);839if (BT_STATUS_BT_OP_SUCCESS == ret) {840pBtCoexist->bt_info.bt_real_fw_ver = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);841pBtCoexist->bt_info.get_bt_fw_ver_cnt++;842}843844_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);845} else {846#ifdef CONFIG_BT_COEXIST_SOCKET_TRX847u8 dataLen = 2;848u8 buf[4] = {0};849850buf[0] = 0x0; /* OP_Code */851buf[1] = 0x0; /* OP_Code_Length */852BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);853#endif /* !CONFIG_BT_COEXIST_SOCKET_TRX */854}855}856857return pBtCoexist->bt_info.bt_real_fw_ver;858}859860s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)861{862return rtw_dm_get_min_rssi(padapter);863}864865u32 halbtcoutsrc_GetBtCoexSupportedFeature(void *pBtcContext)866{867PBTC_COEXIST pBtCoexist;868u32 ret = BT_STATUS_BT_OP_SUCCESS;869u32 data = 0;870871pBtCoexist = (PBTC_COEXIST)pBtcContext;872873if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {874u8 buf[3] = {0};875_irqL irqL;876u8 op_code;877u8 status;878879_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);880881op_code = BT_OP_GET_BT_COEX_SUPPORTED_FEATURE;882status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);883if (status == BT_STATUS_BT_OP_SUCCESS)884data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);885else886ret = SET_BT_MP_OPER_RET(op_code, status);887888_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);889890} else891ret = BT_STATUS_NOT_IMPLEMENT;892893return data;894}895896u32 halbtcoutsrc_GetBtCoexSupportedVersion(void *pBtcContext)897{898PBTC_COEXIST pBtCoexist;899u32 ret = BT_STATUS_BT_OP_SUCCESS;900u32 data = 0xFFFF;901902pBtCoexist = (PBTC_COEXIST)pBtcContext;903904if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {905u8 buf[3] = {0};906_irqL irqL;907u8 op_code;908u8 status;909910_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);911912op_code = BT_OP_GET_BT_COEX_SUPPORTED_VERSION;913status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);914if (status == BT_STATUS_BT_OP_SUCCESS)915data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);916else917ret = SET_BT_MP_OPER_RET(op_code, status);918919_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);920921} else922ret = BT_STATUS_NOT_IMPLEMENT;923924return data;925}926927u32 halbtcoutsrc_GetBtDeviceInfo(void *pBtcContext)928{929PBTC_COEXIST pBtCoexist;930u32 ret = BT_STATUS_BT_OP_SUCCESS;931u32 btDeviceInfo = 0;932933pBtCoexist = (PBTC_COEXIST)pBtcContext;934935if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {936u8 buf[3] = {0};937_irqL irqL;938u8 op_code;939u8 status;940941_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);942943op_code = BT_OP_GET_BT_DEVICE_INFO;944status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);945if (status == BT_STATUS_BT_OP_SUCCESS)946btDeviceInfo = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);947else948ret = SET_BT_MP_OPER_RET(op_code, status);949950_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);951952} else953ret = BT_STATUS_NOT_IMPLEMENT;954955return btDeviceInfo;956}957958u32 halbtcoutsrc_GetBtForbiddenSlotVal(void *pBtcContext)959{960PBTC_COEXIST pBtCoexist;961u32 ret = BT_STATUS_BT_OP_SUCCESS;962u32 btForbiddenSlotVal = 0;963964pBtCoexist = (PBTC_COEXIST)pBtcContext;965966if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {967u8 buf[3] = {0};968_irqL irqL;969u8 op_code;970u8 status;971972_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);973974op_code = BT_OP_GET_BT_FORBIDDEN_SLOT_VAL;975status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);976if (status == BT_STATUS_BT_OP_SUCCESS)977btForbiddenSlotVal = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);978else979ret = SET_BT_MP_OPER_RET(op_code, status);980981_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);982983} else984ret = BT_STATUS_NOT_IMPLEMENT;985986return btForbiddenSlotVal;987}988989static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)990{991struct mlme_priv *pmlmepriv;992struct mlme_ext_priv *pmlmeext;993static u8 scan_AP_num = 0;994995996pmlmepriv = &padapter->mlmepriv;997pmlmeext = &padapter->mlmeextpriv;998999if (GLBtcWiFiInScanState == _FALSE) {1000if (pmlmepriv->num_of_scanned > 0xFF)1001scan_AP_num = 0xFF;1002else1003scan_AP_num = (u8)pmlmepriv->num_of_scanned;1004}10051006return scan_AP_num;1007}10081009u32 halbtcoutsrc_GetPhydmVersion(void *pBtcContext)1010{1011struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;1012PADAPTER Adapter = pBtCoexist->Adapter;10131014#ifdef CONFIG_RTL8192E1015return RELEASE_VERSION_8192E;1016#endif10171018#ifdef CONFIG_RTL8821A1019return RELEASE_VERSION_8821A;1020#endif10211022#ifdef CONFIG_RTL8723B1023return RELEASE_VERSION_8723B;1024#endif10251026#ifdef CONFIG_RTL8812A1027return RELEASE_VERSION_8812A;1028#endif10291030#ifdef CONFIG_RTL8703B1031return RELEASE_VERSION_8703B;1032#endif10331034#ifdef CONFIG_RTL8822B1035return RELEASE_VERSION_8822B;1036#endif10371038#ifdef CONFIG_RTL8723D1039return RELEASE_VERSION_8723D;1040#endif10411042#ifdef CONFIG_RTL8821C1043return RELEASE_VERSION_8821C;1044#endif10451046#ifdef CONFIG_RTL8192F1047return RELEASE_VERSION_8192F;1048#endif10491050#ifdef CONFIG_RTL8822C1051return RELEASE_VERSION_8822C;1052#endif10531054#ifdef CONFIG_RTL8814A1055return RELEASE_VERSION_8814A;1056#endif10571058#ifdef CONFIG_RTL8814B1059return RELEASE_VERSION_8814B;1060#endif1061}10621063u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)1064{1065PBTC_COEXIST pBtCoexist;1066PADAPTER padapter;1067PHAL_DATA_TYPE pHalData;1068struct mlme_ext_priv *mlmeext;1069struct btc_wifi_link_info *wifi_link_info;1070u8 bSoftApExist, bVwifiExist;1071u8 *pu8;1072s32 *pS4Tmp;1073u32 *pU4Tmp;1074u8 *pU1Tmp;1075u16 *pU2Tmp;1076u8 ret;107710781079pBtCoexist = (PBTC_COEXIST)pBtcContext;1080if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))1081return _FALSE;10821083padapter = pBtCoexist->Adapter;1084pHalData = GET_HAL_DATA(padapter);1085mlmeext = &padapter->mlmeextpriv;1086bSoftApExist = _FALSE;1087bVwifiExist = _FALSE;1088pu8 = (u8 *)pOutBuf;1089pS4Tmp = (s32 *)pOutBuf;1090pU4Tmp = (u32 *)pOutBuf;1091pU1Tmp = (u8 *)pOutBuf;1092pU2Tmp = (u16*)pOutBuf;1093wifi_link_info = (struct btc_wifi_link_info *)pOutBuf;1094ret = _TRUE;10951096switch (getType) {1097case BTC_GET_BL_HS_OPERATION:1098*pu8 = _FALSE;1099ret = _FALSE;1100break;11011102case BTC_GET_BL_HS_CONNECTING:1103*pu8 = _FALSE;1104ret = _FALSE;1105break;11061107case BTC_GET_BL_WIFI_FW_READY:1108*pu8 = halbtcoutsrc_is_fw_ready(pBtCoexist);1109break;11101111case BTC_GET_BL_WIFI_CONNECTED:1112*pu8 = (rtw_mi_check_status(padapter, MI_LINKED)) ? _TRUE : _FALSE;1113break;11141115case BTC_GET_BL_WIFI_DUAL_BAND_CONNECTED:1116*pu8 = halbtcoutsrc_IsDualBandConnected(padapter);1117break;11181119case BTC_GET_BL_WIFI_BUSY:1120*pu8 = halbtcoutsrc_IsWifiBusy(padapter);1121break;11221123case BTC_GET_BL_WIFI_SCAN:1124#if 01125*pu8 = (rtw_mi_check_fwstate(padapter, WIFI_SITE_MONITOR)) ? _TRUE : _FALSE;1126#else1127/* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag1128WIFI_SITE_MONITOR in fwstate may not be cleared in time */1129*pu8 = GLBtcWiFiInScanState;1130#endif1131break;11321133case BTC_GET_BL_WIFI_LINK:1134*pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;1135break;11361137case BTC_GET_BL_WIFI_ROAM:1138*pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;1139break;11401141case BTC_GET_BL_WIFI_4_WAY_PROGRESS:1142*pu8 = _FALSE;1143break;11441145case BTC_GET_BL_WIFI_UNDER_5G:1146*pu8 = (pHalData->current_band_type == BAND_ON_5G) ? _TRUE : _FALSE;1147break;11481149case BTC_GET_BL_WIFI_AP_MODE_ENABLE:1150*pu8 = (rtw_mi_check_status(padapter, MI_AP_MODE)) ? _TRUE : _FALSE;1151break;11521153case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:1154*pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? _FALSE : _TRUE;1155break;11561157case BTC_GET_BL_WIFI_UNDER_B_MODE:1158if (mlmeext->cur_wireless_mode == WIRELESS_11B)1159*pu8 = _TRUE;1160else1161*pu8 = _FALSE;1162break;11631164case BTC_GET_BL_WIFI_IS_IN_MP_MODE:1165if (padapter->registrypriv.mp_mode == 0)1166*pu8 = _FALSE;1167else1168*pu8 = _TRUE;1169break;11701171case BTC_GET_BL_EXT_SWITCH:1172*pu8 = _FALSE;1173break;1174case BTC_GET_BL_IS_ASUS_8723B:1175/* Always return FALSE in linux driver since this case is added only for windows driver */1176*pu8 = _FALSE;1177break;11781179case BTC_GET_BL_RF4CE_CONNECTED:1180#ifdef CONFIG_RF4CE_COEXIST1181if (hal_btcoex_get_rf4ce_link_state() == 0)1182*pu8 = FALSE;1183else1184*pu8 = TRUE;1185#else1186*pu8 = FALSE;1187#endif1188break;11891190case BTC_GET_BL_WIFI_LW_PWR_STATE:1191/* return false due to coex do not run during 32K */1192*pu8 = FALSE;1193break;11941195case BTC_GET_S4_WIFI_RSSI:1196*pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);1197break;11981199case BTC_GET_S4_HS_RSSI:1200*pS4Tmp = 0;1201ret = _FALSE;1202break;12031204case BTC_GET_U4_WIFI_BW:1205if (IsLegacyOnly(mlmeext->cur_wireless_mode))1206*pU4Tmp = BTC_WIFI_BW_LEGACY;1207else {1208switch (pHalData->current_channel_bw) {1209case CHANNEL_WIDTH_20:1210*pU4Tmp = BTC_WIFI_BW_HT20;1211break;1212case CHANNEL_WIDTH_40:1213*pU4Tmp = BTC_WIFI_BW_HT40;1214break;1215case CHANNEL_WIDTH_80:1216*pU4Tmp = BTC_WIFI_BW_HT80;1217break;1218case CHANNEL_WIDTH_160:1219*pU4Tmp = BTC_WIFI_BW_HT160;1220break;1221default:1222RTW_INFO("[BTCOEX] unknown bandwidth(%d)\n", pHalData->current_channel_bw);1223*pU4Tmp = BTC_WIFI_BW_HT40;1224break;1225}12261227}1228break;12291230case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:1231case BTC_GET_U4_WIFI_TRAFFIC_DIR:1232{1233PRT_LINK_DETECT_T plinkinfo;1234plinkinfo = &padapter->mlmepriv.LinkDetectInfo;12351236if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)1237*pU4Tmp = BTC_WIFI_TRAFFIC_TX;1238else1239*pU4Tmp = BTC_WIFI_TRAFFIC_RX;1240}1241break;12421243case BTC_GET_U4_WIFI_FW_VER:1244*pU4Tmp = pHalData->firmware_version << 16;1245*pU4Tmp |= pHalData->firmware_sub_version;1246break;12471248case BTC_GET_U4_WIFI_PHY_VER:1249*pU4Tmp = halbtcoutsrc_GetPhydmVersion(pBtCoexist);1250break;12511252case BTC_GET_U4_WIFI_LINK_STATUS:1253*pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);1254break;1255case BTC_GET_BL_WIFI_LINK_INFO:1256*wifi_link_info = halbtcoutsrc_getwifilinkinfo(pBtCoexist);1257break;1258case BTC_GET_U4_BT_PATCH_VER:1259*pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);1260break;12611262case BTC_GET_U4_VENDOR:1263*pU4Tmp = BTC_VENDOR_OTHER;1264break;12651266case BTC_GET_U4_SUPPORTED_VERSION:1267*pU4Tmp = halbtcoutsrc_GetBtCoexSupportedVersion(pBtCoexist);1268break;1269case BTC_GET_U4_SUPPORTED_FEATURE:1270*pU4Tmp = halbtcoutsrc_GetBtCoexSupportedFeature(pBtCoexist);1271break;12721273case BTC_GET_U4_BT_DEVICE_INFO:1274*pU4Tmp = halbtcoutsrc_GetBtDeviceInfo(pBtCoexist);1275break;12761277case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL:1278*pU4Tmp = halbtcoutsrc_GetBtForbiddenSlotVal(pBtCoexist);1279break;12801281case BTC_GET_U4_WIFI_IQK_TOTAL:1282*pU4Tmp = pHalData->odmpriv.n_iqk_cnt;1283break;12841285case BTC_GET_U4_WIFI_IQK_OK:1286*pU4Tmp = pHalData->odmpriv.n_iqk_ok_cnt;1287break;12881289case BTC_GET_U4_WIFI_IQK_FAIL:1290*pU4Tmp = pHalData->odmpriv.n_iqk_fail_cnt;1291break;12921293case BTC_GET_U1_WIFI_DOT11_CHNL:1294*pU1Tmp = padapter->mlmeextpriv.cur_channel;1295break;12961297case BTC_GET_U1_WIFI_CENTRAL_CHNL:1298*pU1Tmp = pHalData->current_channel;1299break;13001301case BTC_GET_U1_WIFI_HS_CHNL:1302*pU1Tmp = 0;1303ret = _FALSE;1304break;13051306case BTC_GET_U1_WIFI_P2P_CHNL:1307#ifdef CONFIG_P2P1308{1309struct wifidirect_info *pwdinfo = &(padapter->wdinfo);13101311*pU1Tmp = pwdinfo->operating_channel;1312}1313#else1314*pU1Tmp = 0;1315#endif1316break;13171318case BTC_GET_U1_MAC_PHY_MODE:1319/* *pU1Tmp = BTC_SMSP;1320* *pU1Tmp = BTC_DMSP;1321* *pU1Tmp = BTC_DMDP;1322* *pU1Tmp = BTC_MP_UNKNOWN; */1323break;13241325case BTC_GET_U1_AP_NUM:1326*pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);1327break;1328case BTC_GET_U1_ANT_TYPE:1329switch (pHalData->bt_coexist.btAntisolation) {1330case 0:1331*pU1Tmp = (u8)BTC_ANT_TYPE_0;1332pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_0;1333break;1334case 1:1335*pU1Tmp = (u8)BTC_ANT_TYPE_1;1336pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_1;1337break;1338case 2:1339*pU1Tmp = (u8)BTC_ANT_TYPE_2;1340pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_2;1341break;1342case 3:1343*pU1Tmp = (u8)BTC_ANT_TYPE_3;1344pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_3;1345break;1346case 4:1347*pU1Tmp = (u8)BTC_ANT_TYPE_4;1348pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_4;1349break;1350}1351break;1352case BTC_GET_U1_IOT_PEER:1353*pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;1354break;13551356/* =======1Ant=========== */1357case BTC_GET_U1_LPS_MODE:1358*pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;1359break;13601361case BTC_GET_U2_BEACON_PERIOD:1362*pU2Tmp = mlmeext->mlmext_info.bcn_interval;1363break;13641365default:1366ret = _FALSE;1367break;1368}13691370return ret;1371}13721373u16 halbtcoutsrc_LnaConstrainLvl(void *pBtcContext, u8 *lna_constrain_level)1374{1375PBTC_COEXIST pBtCoexist;1376u16 ret = BT_STATUS_BT_OP_SUCCESS;13771378pBtCoexist = (PBTC_COEXIST)pBtcContext;13791380if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {1381_irqL irqL;1382u8 op_code;13831384_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);13851386ret = _btmpoper_cmd(pBtCoexist, BT_OP_SET_BT_LANCONSTRAIN_LEVEL, 0, lna_constrain_level, 1);13871388_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);1389} else {1390ret = BT_STATUS_NOT_IMPLEMENT;1391RTW_INFO("%s halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == FALSE\n", __func__);1392}13931394return ret;1395}13961397u8 halbtcoutsrc_SetBtGoldenRxRange(void *pBtcContext, u8 profile, u8 range_shift)1398{1399/* wait for implementation if necessary */14001401return 0;1402}14031404u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)1405{1406PBTC_COEXIST pBtCoexist;1407PADAPTER padapter;1408PHAL_DATA_TYPE pHalData;1409u8 *pu8;1410u8 *pU1Tmp;1411u16 *pU2Tmp;1412u32 *pU4Tmp;1413u8 ret;1414u8 result = _TRUE;141514161417pBtCoexist = (PBTC_COEXIST)pBtcContext;1418if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))1419return _FALSE;14201421padapter = pBtCoexist->Adapter;1422pHalData = GET_HAL_DATA(padapter);1423pu8 = (u8 *)pInBuf;1424pU1Tmp = (u8 *)pInBuf;1425pU2Tmp = (u16*)pInBuf;1426pU4Tmp = (u32 *)pInBuf;1427ret = _TRUE;14281429switch (setType) {1430/* set some u8 type variables. */1431case BTC_SET_BL_BT_DISABLE:1432pBtCoexist->bt_info.bt_disabled = *pu8;1433break;14341435case BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE:1436pBtCoexist->bt_info.bt_enable_disable_change = *pu8;1437break;14381439case BTC_SET_BL_BT_TRAFFIC_BUSY:1440pBtCoexist->bt_info.bt_busy = *pu8;1441break;14421443case BTC_SET_BL_BT_LIMITED_DIG:1444pBtCoexist->bt_info.limited_dig = *pu8;1445break;14461447case BTC_SET_BL_FORCE_TO_ROAM:1448pBtCoexist->bt_info.force_to_roam = *pu8;1449break;14501451case BTC_SET_BL_TO_REJ_AP_AGG_PKT:1452pBtCoexist->bt_info.reject_agg_pkt = *pu8;1453break;14541455case BTC_SET_BL_BT_CTRL_AGG_SIZE:1456pBtCoexist->bt_info.bt_ctrl_agg_buf_size = *pu8;1457break;14581459case BTC_SET_BL_INC_SCAN_DEV_NUM:1460pBtCoexist->bt_info.increase_scan_dev_num = *pu8;1461break;14621463case BTC_SET_BL_BT_TX_RX_MASK:1464pBtCoexist->bt_info.bt_tx_rx_mask = *pu8;1465break;14661467case BTC_SET_BL_MIRACAST_PLUS_BT:1468pBtCoexist->bt_info.miracast_plus_bt = *pu8;1469break;14701471/* set some u8 type variables. */1472case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:1473pBtCoexist->bt_info.rssi_adjust_for_agc_table_on = *pU1Tmp;1474break;14751476case BTC_SET_U1_AGG_BUF_SIZE:1477pBtCoexist->bt_info.agg_buf_size = *pU1Tmp;1478break;14791480/* the following are some action which will be triggered */1481case BTC_SET_ACT_GET_BT_RSSI:1482#if 01483BT_SendGetBtRssiEvent(padapter);1484#else1485ret = _FALSE;1486#endif1487break;14881489case BTC_SET_ACT_AGGREGATE_CTRL:1490halbtcoutsrc_AggregationCheck(pBtCoexist);1491break;14921493/* =======1Ant=========== */1494/* set some u8 type variables. */1495case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:1496pBtCoexist->bt_info.rssi_adjust_for_1ant_coex_type = *pU1Tmp;1497break;14981499case BTC_SET_U1_LPS_VAL:1500pBtCoexist->bt_info.lps_val = *pU1Tmp;1501break;15021503case BTC_SET_U1_RPWM_VAL:1504pBtCoexist->bt_info.rpwm_val = *pU1Tmp;1505break;15061507/* the following are some action which will be triggered */1508case BTC_SET_ACT_LEAVE_LPS:1509result = halbtcoutsrc_LeaveLps(pBtCoexist);1510break;15111512case BTC_SET_ACT_ENTER_LPS:1513halbtcoutsrc_EnterLps(pBtCoexist);1514break;15151516case BTC_SET_ACT_NORMAL_LPS:1517halbtcoutsrc_NormalLps(pBtCoexist);1518break;15191520case BTC_SET_ACT_PRE_NORMAL_LPS:1521halbtcoutsrc_Pre_NormalLps(pBtCoexist);1522break;15231524case BTC_SET_ACT_POST_NORMAL_LPS:1525halbtcoutsrc_Post_NormalLps(pBtCoexist);1526break;15271528case BTC_SET_ACT_DISABLE_LOW_POWER:1529halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);1530break;15311532case BTC_SET_ACT_UPDATE_RAMASK:1533/*1534pBtCoexist->bt_info.ra_mask = *pU4Tmp;15351536if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE) {1537struct sta_info *psta;1538PWLAN_BSSID_EX cur_network;15391540cur_network = &padapter->mlmeextpriv.mlmext_info.network;1541psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);1542rtw_hal_update_ra_mask(psta);1543}1544*/1545break;15461547case BTC_SET_ACT_SEND_MIMO_PS: {1548u8 newMimoPsMode = 3;1549struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);1550struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);15511552/* *pU1Tmp = 0 use SM_PS static type */1553/* *pU1Tmp = 1 disable SM_PS */1554if (*pU1Tmp == 0)1555newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;1556else if (*pU1Tmp == 1)1557newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;15581559if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) {1560/* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */1561issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1);1562}1563}1564break;15651566case BTC_SET_ACT_CTRL_BT_INFO:1567#ifdef CONFIG_BT_COEXIST_SOCKET_TRX1568{1569u8 dataLen = *pU1Tmp;1570u8 tmpBuf[BTC_TMP_BUF_SHORT];1571if (dataLen)1572_rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);1573BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);1574}1575#else /* !CONFIG_BT_COEXIST_SOCKET_TRX */1576ret = _FALSE;1577#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */1578break;15791580case BTC_SET_ACT_CTRL_BT_COEX:1581#ifdef CONFIG_BT_COEXIST_SOCKET_TRX1582{1583u8 dataLen = *pU1Tmp;1584u8 tmpBuf[BTC_TMP_BUF_SHORT];1585if (dataLen)1586_rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);1587BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);1588}1589#else /* !CONFIG_BT_COEXIST_SOCKET_TRX */1590ret = _FALSE;1591#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */1592break;1593case BTC_SET_ACT_CTRL_8723B_ANT:1594#if 01595{1596u8 dataLen = *pU1Tmp;1597u8 tmpBuf[BTC_TMP_BUF_SHORT];1598if (dataLen)1599PlatformMoveMemory(&tmpBuf[0], pU1Tmp + 1, dataLen);1600BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);1601}1602#else1603ret = _FALSE;1604#endif1605break;1606case BTC_SET_BL_BT_LNA_CONSTRAIN_LEVEL:1607halbtcoutsrc_LnaConstrainLvl(pBtCoexist, pu8);1608break;1609case BTC_SET_BL_BT_GOLDEN_RX_RANGE:1610halbtcoutsrc_SetBtGoldenRxRange(pBtCoexist, (*pU2Tmp & 0xff00) >> 8, (*pU2Tmp & 0xff));1611break;1612case BTC_SET_RESET_COEX_VAR:1613_rtw_memset(&pBtCoexist->coex_dm, 0x00, sizeof(pBtCoexist->coex_dm));1614_rtw_memset(&pBtCoexist->coex_sta, 0x00, sizeof(pBtCoexist->coex_sta));16151616switch(pBtCoexist->chip_type) {1617#ifdef CONFIG_RTL8822B1618case BTC_CHIP_RTL8822B:1619_rtw_memset(&pBtCoexist->coex_dm_8822b_1ant, 0x00, sizeof(pBtCoexist->coex_dm_8822b_1ant));1620_rtw_memset(&pBtCoexist->coex_dm_8822b_2ant, 0x00, sizeof(pBtCoexist->coex_dm_8822b_2ant));1621break;1622#endif1623#ifdef CONFIG_RTL8821C1624case BTC_CHIP_RTL8821C:1625_rtw_memset(&pBtCoexist->coex_dm_8821c_1ant, 0x00, sizeof(pBtCoexist->coex_dm_8821c_1ant));1626_rtw_memset(&pBtCoexist->coex_dm_8821c_2ant, 0x00, sizeof(pBtCoexist->coex_dm_8821c_2ant));1627break;1628#endif1629#ifdef CONFIG_RTL8723D1630case BTC_CHIP_RTL8723D:1631_rtw_memset(&pBtCoexist->coex_dm_8723d_1ant, 0x00, sizeof(pBtCoexist->coex_dm_8723d_1ant));1632_rtw_memset(&pBtCoexist->coex_dm_8723d_2ant, 0x00, sizeof(pBtCoexist->coex_dm_8723d_2ant));1633break;1634#endif1635}1636break;1637/* ===================== */1638default:1639ret = _FALSE;1640break;1641}16421643return result;1644}16451646u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)1647{1648PADAPTER padapter;1649struct pwrctrl_priv *pwrpriv;1650u8 bMacPwrCtrlOn;16511652padapter = pBtCoexist->Adapter;1653pwrpriv = &padapter->dvobj->pwrctl_priv;1654bMacPwrCtrlOn = _FALSE;16551656if ((_TRUE == pwrpriv->bips_processing)1657&& (IPS_NONE != pwrpriv->ips_mode_req)1658)1659return _TRUE;16601661if (rf_off == pwrpriv->rf_pwrstate)1662return _TRUE;16631664rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);1665if (_FALSE == bMacPwrCtrlOn)1666return _TRUE;16671668return _FALSE;1669}16701671u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)1672{1673return GLBtcWiFiInLPS;1674}16751676u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)1677{1678/* todo: the method to check whether wifi is under 32K or not */1679return _FALSE;1680}16811682void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)1683{1684#if 01685PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;1686PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;1687PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);1688u8 *cliBuf = pBtCoexist->cliBuf;1689u8 i, j;1690u8 tmpbuf[BTC_TMP_BUF_SHORT];169116921693if (gl_coex_offload.cnt_h2c_sent) {1694CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex h2c notify]============");1695CL_PRINTF(cliBuf);16961697CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = H2c(%d)/Ack(%d)", "Coex h2c/c2h overall statistics",1698gl_coex_offload.cnt_h2c_sent, gl_coex_offload.cnt_c2h_ack);1699for (j = 0; j < COL_STATUS_MAX; j++) {1700if (gl_coex_offload.status[j]) {1701CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.status[j]);1702CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);1703}1704}1705CL_PRINTF(cliBuf);1706}1707for (i = 0; i < COL_OP_WIFI_OPCODE_MAX; i++) {1708if (gl_coex_offload.h2c_record[i].count) {1709/*==========================================*/1710/* H2C result statistics*/1711/*==========================================*/1712CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexOpcodeString[i], gl_coex_offload.h2c_record[i].count);1713for (j = 0; j < COL_STATUS_MAX; j++) {1714if (gl_coex_offload.h2c_record[i].status[j]) {1715CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.h2c_record[i].status[j]);1716CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);1717}1718}1719CL_PRINTF(cliBuf);1720/*==========================================*/1721/* H2C/C2H content*/1722/*==========================================*/1723CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "H2C / C2H content");1724for (j = 0; j < gl_coex_offload.h2c_record[i].h2c_len; j++) {1725CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].h2c_buf[j]);1726CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);1727}1728if (gl_coex_offload.h2c_record[i].c2h_ack_len) {1729CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, "/ ", 2);1730for (j = 0; j < gl_coex_offload.h2c_record[i].c2h_ack_len; j++) {1731CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].c2h_ack_buf[j]);1732CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);1733}1734}1735CL_PRINTF(cliBuf);1736/*==========================================*/1737}1738}17391740if (gl_coex_offload.cnt_c2h_ind) {1741CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex c2h indication]============");1742CL_PRINTF(cliBuf);17431744CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = Ind(%d)", "C2H indication statistics",1745gl_coex_offload.cnt_c2h_ind);1746for (j = 0; j < COL_STATUS_MAX; j++) {1747if (gl_coex_offload.c2h_ind_status[j]) {1748CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_status[j]);1749CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);1750}1751}1752CL_PRINTF(cliBuf);1753}1754for (i = 0; i < COL_IND_MAX; i++) {1755if (gl_coex_offload.c2h_ind_record[i].count) {1756/*==========================================*/1757/* H2C result statistics*/1758/*==========================================*/1759CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexIndTypeString[i], gl_coex_offload.c2h_ind_record[i].count);1760for (j = 0; j < COL_STATUS_MAX; j++) {1761if (gl_coex_offload.c2h_ind_record[i].status[j]) {1762CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_record[i].status[j]);1763CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);1764}1765}1766CL_PRINTF(cliBuf);1767/*==========================================*/1768/* content*/1769/*==========================================*/1770CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "C2H indication content");1771for (j = 0; j < gl_coex_offload.c2h_ind_record[i].ind_len; j++) {1772CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.c2h_ind_record[i].ind_buf[j]);1773CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);1774}1775CL_PRINTF(cliBuf);1776/*==========================================*/1777}1778}17791780CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");1781CL_PRINTF(cliBuf);17821783#if (H2C_USE_IO_THREAD != 1)1784for (i = 0; i < H2C_STATUS_MAX; i++) {1785if (pHalData->h2cStatistics[i]) {1786CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \1787h2cStaString[i], pHalData->h2cStatistics[i]);1788CL_PRINTF(cliBuf);1789}1790}1791#else1792for (i = 0; i < IO_STATUS_MAX; i++) {1793if (Adapter->ioComStr.ioH2cStatistics[i]) {1794CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \1795ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);1796CL_PRINTF(cliBuf);1797}1798}1799#endif1800#if 01801CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \1802pHalData->LastHMEBoxNum);1803CL_PRINTF(cliBuf);1804CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \1805pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);1806CL_PRINTF(cliBuf);18071808CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \1809pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,1810DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);1811CL_PRINTF(cliBuf);18121813CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \1814DBG_Var.c2hPacketCnt);1815CL_PRINTF(cliBuf);1816#endif1817CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \1818pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);1819CL_PRINTF(cliBuf);1820CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \1821pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,1822pBtCoexist->statistics.cntRfStatusNotify);1823CL_PRINTF(cliBuf);1824CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \1825pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,1826pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,1827pBtCoexist->statistics.cntMediaStatusNotify);1828CL_PRINTF(cliBuf);1829CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind",1830pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify,1831pBtCoexist->statistics.cntBind);1832CL_PRINTF(cliBuf);1833#endif1834PADAPTER padapter = pBtCoexist->Adapter;1835PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);1836u8 *cliBuf = pBtCoexist->cli_buf;18371838if (pHalData->EEPROMBluetoothCoexist == 1) {1839CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex Status]============");1840CL_PRINTF(cliBuf);1841CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtDisabled", rtw_btcoex_IsBtDisabled(padapter));1842CL_PRINTF(cliBuf);1843CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtControlLps", rtw_btcoex_IsBtControlLps(padapter));1844CL_PRINTF(cliBuf);1845}1846}18471848void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)1849{1850#if 01851PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;1852PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;1853u8 *cliBuf = pBtCoexist->cliBuf;1854u8 i;185518561857if (pBtCoexist->stack_info.profile_notified) {1858for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {1859if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {1860CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \1861BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],1862BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],1863BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);1864CL_PRINTF(cliBuf);1865} else {1866CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \1867BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],1868BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);1869CL_PRINTF(cliBuf);1870}1871}1872}1873#endif1874}18751876void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)1877{1878PADAPTER padapter = pBtCoexist->Adapter;1879struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);1880u8 *cliBuf = pBtCoexist->cli_buf;1881s32 wifiRssi = 0, btHsRssi = 0;1882BOOLEAN bScan = _FALSE, bLink = _FALSE, bRoam = _FALSE, bWifiBusy = _FALSE, bWifiUnderBMode = _FALSE;1883u32 wifiBw = BTC_WIFI_BW_HT20, wifiTrafficDir = BTC_WIFI_TRAFFIC_TX, wifiFreq = BTC_FREQ_2_4G;1884u32 wifiLinkStatus = 0x0;1885BOOLEAN bBtHsOn = _FALSE, bLowPower = _FALSE;1886u8 wifiChnl = 0, wifiP2PChnl = 0, nScanAPNum = 0, FwPSState;1887u32 iqk_cnt_total = 0, iqk_cnt_ok = 0, iqk_cnt_fail = 0;1888u16 wifiBcnInterval = 0;1889PHAL_DATA_TYPE hal = GET_HAL_DATA(padapter);1890struct btc_wifi_link_info wifi_link_info;18911892wifi_link_info = halbtcoutsrc_getwifilinkinfo(pBtCoexist);18931894switch (wifi_link_info.link_mode) {1895case BTC_LINK_NONE:1896CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1897"None", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1898wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;1899break;1900case BTC_LINK_ONLY_GO:1901CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1902"ONLY_GO", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1903wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;1904break;1905case BTC_LINK_ONLY_GC:1906CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1907"ONLY_GC", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1908wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;1909break;1910case BTC_LINK_ONLY_STA:1911CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1912"ONLY_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1913wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;1914break;1915case BTC_LINK_ONLY_AP:1916CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1917"ONLY_AP", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1918wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;1919break;1920case BTC_LINK_2G_MCC_GO_STA:1921CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1922"24G_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1923wifiFreq = BTC_FREQ_2_4G;1924break;1925case BTC_LINK_5G_MCC_GO_STA:1926CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1927"5G_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1928wifiFreq = BTC_FREQ_5G;1929break;1930case BTC_LINK_25G_MCC_GO_STA:1931CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1932"2BANDS_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1933wifiFreq = BTC_FREQ_25G;1934break;1935case BTC_LINK_2G_MCC_GC_STA:1936CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1937"24G_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1938wifiFreq = BTC_FREQ_2_4G;1939break;1940case BTC_LINK_5G_MCC_GC_STA:1941CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1942"5G_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1943wifiFreq = BTC_FREQ_5G;1944break;1945case BTC_LINK_25G_MCC_GC_STA:1946CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1947"2BANDS_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1948wifiFreq = BTC_FREQ_25G;1949break;1950case BTC_LINK_2G_SCC_GO_STA:1951CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1952"24G_SCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1953wifiFreq = BTC_FREQ_2_4G;1954break;1955case BTC_LINK_5G_SCC_GO_STA:1956CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1957"5G_SCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1958wifiFreq = BTC_FREQ_5G;1959break;1960case BTC_LINK_2G_SCC_GC_STA:1961CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1962"24G_SCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1963wifiFreq = BTC_FREQ_2_4G;1964break;1965case BTC_LINK_5G_SCC_GC_STA:1966CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1967"5G_SCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1968wifiFreq = BTC_FREQ_5G;1969break;1970default:1971CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",1972"UNKNOWN", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);1973wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;1974break;1975}19761977CL_PRINTF(cliBuf);19781979wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);1980CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc",1981((wifiLinkStatus & WIFI_STA_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_AP_CONNECTED) ? 1 : 0),1982((wifiLinkStatus & WIFI_HS_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_P2P_GO_CONNECTED) ? 1 : 0),1983((wifiLinkStatus & WIFI_P2P_GC_CONNECTED) ? 1 : 0));1984CL_PRINTF(cliBuf);19851986pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);1987pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);1988pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);1989CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Link/ Roam/ Scan",1990bLink, bRoam, bScan);1991CL_PRINTF(cliBuf);19921993pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_TOTAL, &iqk_cnt_total);1994pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_OK, &iqk_cnt_ok);1995pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_FAIL, &iqk_cnt_fail);1996CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d %s %s",1997"IQK All/ OK/ Fail/AutoLoad/FWDL", iqk_cnt_total, iqk_cnt_ok, iqk_cnt_fail,1998((halbtcoutsrc_is_autoload_fail(pBtCoexist) == _TRUE) ? "fail":"ok"), ((halbtcoutsrc_is_fw_ready(pBtCoexist) == _TRUE) ? "ok":"fail"));1999CL_PRINTF(cliBuf);20002001if (wifiLinkStatus & WIFI_STA_CONNECTED) {2002CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "IOT Peer", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor]);2003CL_PRINTF(cliBuf);2004}20052006pBtCoexist->btc_get(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);2007pBtCoexist->btc_get(pBtCoexist, BTC_GET_U2_BEACON_PERIOD, &wifiBcnInterval);2008wifiChnl = wifi_link_info.sta_center_channel;2009wifiP2PChnl = wifi_link_info.p2p_center_channel;20102011CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dBm/ %d/ %d/ %d", "RSSI/ STA_Chnl/ P2P_Chnl/ BI",2012wifiRssi-100, wifiChnl, wifiP2PChnl, wifiBcnInterval);2013CL_PRINTF(cliBuf);20142015pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);2016pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);2017pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);2018pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);2019pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);2020CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ %d ", "Band/ BW/ Traffic/ APCnt",2021GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode) ? "11b" : GLBtcWifiBwString[wifiBw]),2022((!bWifiBusy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX == wifiTrafficDir) ? "uplink" : "downlink")),2023nScanAPNum);2024CL_PRINTF(cliBuf);20252026/* power status */2027CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \2028((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE) ? "IPS ON" : "IPS OFF"),2029((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE) ? ", LPS ON" : ", LPS OFF"),2030((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE) ? ", 32k" : ""));2031CL_PRINTF(cliBuf);20322033CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)", "Power mode cmd(lps/rpwm)",2034pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],2035pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],2036pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],2037pBtCoexist->bt_info.lps_val,2038pBtCoexist->bt_info.rpwm_val);2039CL_PRINTF(cliBuf);2040}20412042void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)2043{2044PBTC_COEXIST pBtCoexist;204520462047pBtCoexist = (PBTC_COEXIST)pBtcContext;2048switch (dispType) {2049case BTC_DBG_DISP_COEX_STATISTICS:2050halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);2051break;2052case BTC_DBG_DISP_BT_LINK_INFO:2053halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);2054break;2055case BTC_DBG_DISP_WIFI_STATUS:2056halbtcoutsrc_DisplayWifiStatus(pBtCoexist);2057break;2058default:2059break;2060}2061}20622063/* ************************************2064* IO related function2065* ************************************ */2066u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)2067{2068PBTC_COEXIST pBtCoexist;2069PADAPTER padapter;207020712072pBtCoexist = (PBTC_COEXIST)pBtcContext;2073padapter = pBtCoexist->Adapter;20742075return rtw_read8(padapter, RegAddr);2076}20772078u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)2079{2080PBTC_COEXIST pBtCoexist;2081PADAPTER padapter;208220832084pBtCoexist = (PBTC_COEXIST)pBtcContext;2085padapter = pBtCoexist->Adapter;20862087return rtw_read16(padapter, RegAddr);2088}20892090u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)2091{2092PBTC_COEXIST pBtCoexist;2093PADAPTER padapter;209420952096pBtCoexist = (PBTC_COEXIST)pBtcContext;2097padapter = pBtCoexist->Adapter;20982099return rtw_read32(padapter, RegAddr);2100}21012102void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)2103{2104PBTC_COEXIST pBtCoexist;2105PADAPTER padapter;210621072108pBtCoexist = (PBTC_COEXIST)pBtcContext;2109padapter = pBtCoexist->Adapter;21102111rtw_write8(padapter, RegAddr, Data);2112}21132114void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)2115{2116PBTC_COEXIST pBtCoexist;2117PADAPTER padapter;2118u8 originalValue, bitShift;2119u8 i;212021212122pBtCoexist = (PBTC_COEXIST)pBtcContext;2123padapter = pBtCoexist->Adapter;2124originalValue = 0;2125bitShift = 0;21262127if (bitMask != 0xff) {2128originalValue = rtw_read8(padapter, regAddr);21292130for (i = 0; i <= 7; i++) {2131if ((bitMask >> i) & 0x1)2132break;2133}2134bitShift = i;21352136data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);2137}21382139rtw_write8(padapter, regAddr, data1b);2140}21412142void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)2143{2144PBTC_COEXIST pBtCoexist;2145PADAPTER padapter;214621472148pBtCoexist = (PBTC_COEXIST)pBtcContext;2149padapter = pBtCoexist->Adapter;21502151rtw_write16(padapter, RegAddr, Data);2152}21532154void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)2155{2156PBTC_COEXIST pBtCoexist;2157PADAPTER padapter;215821592160pBtCoexist = (PBTC_COEXIST)pBtcContext;2161padapter = pBtCoexist->Adapter;21622163rtw_write32(padapter, RegAddr, Data);2164}21652166void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)2167{2168PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;2169PADAPTER Adapter = pBtCoexist->Adapter;21702171if (BTC_INTF_SDIO == pBtCoexist->chip_interface)2172rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);2173else2174rtw_write8(Adapter, RegAddr, Data);2175}21762177u32 halbtcoutsrc_WaitLIndirectReg_Ready(void *pBtcContext)2178{2179PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;2180u32 delay_count = 0, reg = 0;21812182if (!btc->chip_para->lte_indirect_access)2183return 0;21842185switch (btc->chip_para->indirect_type) {2186case BTC_INDIRECT_1700:2187reg = 0x1703;2188break;2189case BTC_INDIRECT_7C0:2190reg = 0x7C3;2191break;2192default:2193return 0;2194}21952196/* wait for ready bit before access */2197while (1) {2198if ((halbtcoutsrc_Read1Byte(btc, reg) & BIT(5)) == 0) {2199rtw_mdelay_os(10);2200if (++delay_count >= 10)2201break;2202} else {2203break;2204}2205}22062207return delay_count;2208}22092210u32 halbtcoutsrc_ReadLIndirectReg(void *pBtcContext, u16 reg_addr)2211{2212PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;2213u32 val = 0;22142215if (!btc->chip_para->lte_indirect_access)2216return 0;22172218/* wait for ready bit before access */2219halbtcoutsrc_WaitLIndirectReg_Ready(btc);22202221switch (btc->chip_para->indirect_type) {2222case BTC_INDIRECT_1700:2223halbtcoutsrc_Write4Byte(btc, 0x1700, 0x800F0000 | reg_addr);2224val = halbtcoutsrc_Read4Byte(btc, 0x1708); /* get read data */2225break;2226case BTC_INDIRECT_7C0:2227halbtcoutsrc_Write4Byte(btc, 0x7c0, 0x800F0000 | reg_addr);2228val = halbtcoutsrc_Read4Byte(btc, 0x7c8); /* get read data */2229break;2230}22312232return val;2233}22342235void halbtcoutsrc_WriteLIndirectReg(void *pBtcContext, u16 reg_addr, u32 bit_mask, u32 reg_value)2236{2237PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;2238u32 val, i = 0, bitpos = 0, reg0, reg1;22392240if (!btc->chip_para->lte_indirect_access)2241return;22422243if (bit_mask == 0x0)2244return;22452246switch (btc->chip_para->indirect_type) {2247case BTC_INDIRECT_1700:2248reg0 = 0x1700;2249reg1 = 0x1704;2250break;2251case BTC_INDIRECT_7C0:2252reg0 = 0x7C0;2253reg1 = 0x7C4;2254break;2255default:2256return;2257}22582259if (bit_mask == 0xffffffff) {2260/* wait for ready bit before access 0x1700 */2261halbtcoutsrc_WaitLIndirectReg_Ready(btc);22622263/* put write data */2264halbtcoutsrc_Write4Byte(btc, reg1, reg_value);2265halbtcoutsrc_Write4Byte(btc, reg0, 0xc00F0000 | reg_addr);2266} else {2267for (i = 0; i <= 31; i++) {2268if (((bit_mask >> i) & 0x1) == 0x1) {2269bitpos = i;2270break;2271}2272}22732274/* read back register value before write */2275val = halbtcoutsrc_ReadLIndirectReg(btc, reg_addr);2276val = (val & (~bit_mask)) | (reg_value << bitpos);22772278/* wait for ready bit before access 0x1700 */2279halbtcoutsrc_WaitLIndirectReg_Ready(btc);22802281halbtcoutsrc_Write4Byte(btc, reg1, val); /* put write data */2282halbtcoutsrc_Write4Byte(btc, reg0, 0xc00F0000 | reg_addr);2283}2284}22852286void halbtcoutsrc_Read_scbd(void *pBtcContext, u16* score_board_val)2287{2288PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;2289struct btc_coex_sta *coex_sta = &btc->coex_sta;2290const struct btc_chip_para *chip_para = btc->chip_para;22912292if (!chip_para->scbd_support)2293return;22942295*score_board_val = (btc->btc_read_2byte(btc, 0xaa)) & 0x7fff;2296coex_sta->score_board_BW = *score_board_val;2297}22982299void halbtcoutsrc_Write_scbd(void *pBtcContext, u16 bitpos, u8 state)2300{2301PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;2302struct btc_coex_sta *coex_sta = &btc->coex_sta;2303const struct btc_chip_para *chip_para = btc->chip_para;2304u16 val = 0x2;2305u8* btc_dbg_buf = &gl_btc_trace_buf[0];23062307if (!chip_para->scbd_support)2308return;23092310val = val | coex_sta->score_board_WB;23112312/* for 8822b, Scoreboard[10]: 0: CQDDR off, 1: CQDDR on2313* for 8822c, Scoreboard[10]: 0: CQDDR on, 1:CQDDR fix 2M2314*/2315if (!btc->chip_para->new_scbd10_def && (bitpos & BTC_SCBD_FIX2M)) {2316if (state)2317val = val & (~BTC_SCBD_FIX2M);2318else2319val = val | BTC_SCBD_FIX2M;2320} else {2321if (state)2322val = val | bitpos;2323else2324val = val & (~bitpos);2325}23262327if (val != coex_sta->score_board_WB) {2328coex_sta->score_board_WB = val;2329val = val | 0x8000;2330btc->btc_write_2byte(btc, 0xaa, val);23312332BTC_SPRINTF(btc_dbg_buf, BT_TMP_BUF_SIZE,2333"[BTCoex], write scoreboard 0x%x\n", val);2334} else {2335BTC_SPRINTF(btc_dbg_buf, BT_TMP_BUF_SIZE,2336"[BTCoex], %s: return for nochange\n", __func__);2337}23382339BTC_TRACE(btc_dbg_buf);2340}23412342void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)2343{2344PBTC_COEXIST pBtCoexist;2345PADAPTER padapter;234623472348pBtCoexist = (PBTC_COEXIST)pBtcContext;2349padapter = pBtCoexist->Adapter;23502351phy_set_bb_reg(padapter, RegAddr, BitMask, Data);2352}235323542355u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)2356{2357PBTC_COEXIST pBtCoexist;2358PADAPTER padapter;235923602361pBtCoexist = (PBTC_COEXIST)pBtcContext;2362padapter = pBtCoexist->Adapter;23632364return phy_query_bb_reg(padapter, RegAddr, BitMask);2365}23662367void halbtcoutsrc_SetRfReg(void *pBtcContext, enum rf_path eRFPath, u32 RegAddr, u32 BitMask, u32 Data)2368{2369PBTC_COEXIST pBtCoexist;2370PADAPTER padapter;237123722373pBtCoexist = (PBTC_COEXIST)pBtcContext;2374padapter = pBtCoexist->Adapter;23752376phy_set_rf_reg(padapter, eRFPath, RegAddr, BitMask, Data);2377}23782379u32 halbtcoutsrc_GetRfReg(void *pBtcContext, enum rf_path eRFPath, u32 RegAddr, u32 BitMask)2380{2381PBTC_COEXIST pBtCoexist;2382PADAPTER padapter;238323842385pBtCoexist = (PBTC_COEXIST)pBtcContext;2386padapter = pBtCoexist->Adapter;23872388return phy_query_rf_reg(padapter, eRFPath, RegAddr, BitMask);2389}23902391u16 halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)2392{2393PBTC_COEXIST pBtCoexist;2394u16 ret = BT_STATUS_BT_OP_SUCCESS;23952396pBtCoexist = (PBTC_COEXIST)pBtcContext;23972398if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {2399u8 buf[3] = {0};2400_irqL irqL;2401u8 op_code;2402u8 status;24032404_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);24052406Data = cpu_to_le32(Data);2407op_code = BT_OP_WRITE_REG_VALUE;2408status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Data, 3);2409if (status != BT_STATUS_BT_OP_SUCCESS)2410ret = SET_BT_MP_OPER_RET(op_code, status);2411else {2412buf[0] = RegType;2413*(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);2414op_code = BT_OP_WRITE_REG_ADDR;2415status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);2416if (status != BT_STATUS_BT_OP_SUCCESS)2417ret = SET_BT_MP_OPER_RET(op_code, status);2418}24192420_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);2421} else2422ret = BT_STATUS_NOT_IMPLEMENT;24232424return ret;2425}24262427u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)2428{2429/* Always return _FALSE since we don't implement this yet */2430#if 02431PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;2432PADAPTER Adapter = pBtCoexist->Adapter;2433u8 btCanTx = 0;2434BOOLEAN bStatus = FALSE;24352436bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);2437if (bStatus && btCanTx)2438return _TRUE;2439else2440return _FALSE;2441#else2442return _FALSE;2443#endif2444}24452446BOOLEAN2447halbtcoutsrc_SetBtTRXMASK(2448void *pBtcContext,2449u8 bt_trx_mask2450)2451{2452/* Always return _FALSE since we don't implement this yet */2453#if 02454struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;2455PADAPTER Adapter = pBtCoexist->Adapter;2456BOOLEAN bStatus = FALSE;2457u8 btCanTx = 0;24582459if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter) || IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)2460|| IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {24612462if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter))2463bStatus = NDBG_SetBtTRXMASK(Adapter, 1, bt_trx_mask, &btCanTx);2464else2465bStatus = NDBG_SetBtTRXMASK(Adapter, 2, bt_trx_mask, &btCanTx);2466}246724682469if (bStatus)2470return TRUE;2471else2472return FALSE;2473#else2474return _FALSE;2475#endif2476}24772478u16 halbtcoutsrc_GetBtReg_with_status(void *pBtcContext, u8 RegType, u32 RegAddr, u32 *data)2479{2480PBTC_COEXIST pBtCoexist;2481u16 ret = BT_STATUS_BT_OP_SUCCESS;24822483pBtCoexist = (PBTC_COEXIST)pBtcContext;24842485if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {2486u8 buf[3] = {0};2487_irqL irqL;2488u8 op_code;2489u8 status;24902491buf[0] = RegType;2492*(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);24932494_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);24952496op_code = BT_OP_READ_REG;2497status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);2498if (status == BT_STATUS_BT_OP_SUCCESS)2499*data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);2500else2501ret = SET_BT_MP_OPER_RET(op_code, status);25022503_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);25042505} else2506ret = BT_STATUS_NOT_IMPLEMENT;25072508return ret;2509}25102511u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)2512{2513u32 regVal;25142515return (BT_STATUS_BT_OP_SUCCESS == halbtcoutsrc_GetBtReg_with_status(pBtcContext, RegType, RegAddr, ®Val)) ? regVal : 0xffffffff;2516}25172518u16 halbtcoutsrc_setbttestmode(void *pBtcContext, u8 Type)2519{2520PBTC_COEXIST pBtCoexist;2521u16 ret = BT_STATUS_BT_OP_SUCCESS;25222523pBtCoexist = (PBTC_COEXIST)pBtcContext;25242525if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {2526_irqL irqL;2527u8 op_code;2528u8 status;25292530_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);25312532Type = cpu_to_le32(Type);2533op_code = BT_OP_SET_BT_TEST_MODE_VAL;2534status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Type, 3);2535if (status != BT_STATUS_BT_OP_SUCCESS)2536ret = SET_BT_MP_OPER_RET(op_code, status);25372538_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);2539} else2540ret = BT_STATUS_NOT_IMPLEMENT;25412542return ret;25432544}254525462547void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)2548{2549PBTC_COEXIST pBtCoexist;2550PADAPTER padapter;2551s32 ret = 0;255225532554pBtCoexist = (PBTC_COEXIST)pBtcContext;2555padapter = pBtCoexist->Adapter;25562557ret = rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);25582559#ifdef CONFIG_RTL8192F2560if (ret == _SUCCESS) {2561switch (elementId) {2562case H2C_BT_INFO:2563case H2C_BT_IGNORE_WLANACT:2564case H2C_WL_OPMODE:2565case H2C_BT_MP_OPER:2566case H2C_BT_CONTROL:2567rtw_msleep_os(20);2568break;2569}2570}2571#endif2572}25732574static void halbtcoutsrc_coex_offload_init(void)2575{2576u8 i;25772578gl_coex_offload.h2c_req_num = 0;2579gl_coex_offload.cnt_h2c_sent = 0;2580gl_coex_offload.cnt_c2h_ack = 0;2581gl_coex_offload.cnt_c2h_ind = 0;25822583for (i = 0; i < COL_MAX_H2C_REQ_NUM; i++)2584init_completion(&gl_coex_offload.c2h_event[i]);2585}25862587static COL_H2C_STATUS halbtcoutsrc_send_h2c(PADAPTER Adapter, PCOL_H2C pcol_h2c, u16 h2c_cmd_len)2588{2589COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK;2590u8 i;25912592#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))2593reinit_completion(&gl_coex_offload.c2h_event[pcol_h2c->req_num]); /* set event to un signaled state */2594#else2595INIT_COMPLETION(gl_coex_offload.c2h_event[pcol_h2c->req_num]);2596#endif25972598if (TRUE) {2599#if 0 /*(USE_HAL_MAC_API == 1) */2600if (RT_STATUS_SUCCESS == HAL_MAC_Send_BT_COEX(&GET_HAL_MAC_INFO(Adapter), (u8 *)(pcol_h2c), (u32)h2c_cmd_len, 1)) {2601if (!wait_for_completion_timeout(&gl_coex_offload.c2h_event[pcol_h2c->req_num], 20)) {2602h2c_status = COL_STATUS_H2C_TIMTOUT;2603}2604} else {2605h2c_status = COL_STATUS_H2C_HALMAC_FAIL;2606}2607#endif2608}26092610return h2c_status;2611}26122613static COL_H2C_STATUS halbtcoutsrc_check_c2h_ack(PADAPTER Adapter, PCOL_SINGLE_H2C_RECORD pH2cRecord)2614{2615COL_H2C_STATUS c2h_status = COL_STATUS_C2H_OK;2616PCOL_H2C p_h2c_cmd = (PCOL_H2C)&pH2cRecord->h2c_buf[0];2617u8 req_num = p_h2c_cmd->req_num;2618PCOL_C2H_ACK p_c2h_ack = (PCOL_C2H_ACK)&gl_coex_offload.c2h_ack_buf[req_num];261926202621if ((COL_C2H_ACK_HDR_LEN + p_c2h_ack->ret_len) > gl_coex_offload.c2h_ack_len[req_num]) {2622c2h_status = COL_STATUS_COEX_DATA_OVERFLOW;2623return c2h_status;2624}2625/* else */2626{2627_rtw_memmove(&pH2cRecord->c2h_ack_buf[0], &gl_coex_offload.c2h_ack_buf[req_num], gl_coex_offload.c2h_ack_len[req_num]);2628pH2cRecord->c2h_ack_len = gl_coex_offload.c2h_ack_len[req_num];2629}263026312632if (p_c2h_ack->req_num != p_h2c_cmd->req_num) {2633c2h_status = COL_STATUS_C2H_REQ_NUM_MISMATCH;2634} else if (p_c2h_ack->opcode_ver != p_h2c_cmd->opcode_ver) {2635c2h_status = COL_STATUS_C2H_OPCODE_VER_MISMATCH;2636} else {2637c2h_status = p_c2h_ack->status;2638}26392640return c2h_status;2641}26422643COL_H2C_STATUS halbtcoutsrc_CoexH2cProcess(void *pBtCoexist,2644u8 opcode, u8 opcode_ver, u8 *ph2c_par, u8 h2c_par_len)2645{2646PADAPTER Adapter = ((struct btc_coexist *)pBtCoexist)->Adapter;2647u8 H2C_Parameter[BTC_TMP_BUF_SHORT] = {0};2648PCOL_H2C pcol_h2c = (PCOL_H2C)&H2C_Parameter[0];2649u16 paraLen = 0;2650COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK, c2h_status = COL_STATUS_C2H_OK;2651COL_H2C_STATUS ret_status = COL_STATUS_C2H_OK;2652u16 i, col_h2c_len = 0;26532654pcol_h2c->opcode = opcode;2655pcol_h2c->opcode_ver = opcode_ver;2656pcol_h2c->req_num = gl_coex_offload.h2c_req_num;2657gl_coex_offload.h2c_req_num++;2658gl_coex_offload.h2c_req_num %= 16;26592660_rtw_memmove(&pcol_h2c->buf[0], ph2c_par, h2c_par_len);266126622663col_h2c_len = h2c_par_len + 2; /* 2=sizeof(OPCode, OPCode_version and Request number) */2664BT_PrintData(Adapter, "[COL], H2C cmd: ", col_h2c_len, H2C_Parameter);26652666gl_coex_offload.cnt_h2c_sent++;26672668gl_coex_offload.h2c_record[opcode].count++;2669gl_coex_offload.h2c_record[opcode].h2c_len = col_h2c_len;2670_rtw_memmove((void *)&gl_coex_offload.h2c_record[opcode].h2c_buf[0], (void *)pcol_h2c, col_h2c_len);26712672h2c_status = halbtcoutsrc_send_h2c(Adapter, pcol_h2c, col_h2c_len);26732674gl_coex_offload.h2c_record[opcode].c2h_ack_len = 0;26752676if (COL_STATUS_C2H_OK == h2c_status) {2677/* if reach here, it means H2C get the correct c2h response, */2678c2h_status = halbtcoutsrc_check_c2h_ack(Adapter, &gl_coex_offload.h2c_record[opcode]);2679ret_status = c2h_status;2680} else {2681/* check h2c status error, return error status code to upper layer. */2682ret_status = h2c_status;2683}2684gl_coex_offload.h2c_record[opcode].status[ret_status]++;2685gl_coex_offload.status[ret_status]++;26862687return ret_status;2688}26892690u8 halbtcoutsrc_GetAntDetValFromBt(void *pBtcContext)2691{2692/* Always return 0 since we don't implement this yet */2693#if 02694struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;2695PADAPTER Adapter = pBtCoexist->Adapter;2696u8 AntDetVal = 0x0;2697u8 opcodeVer = 1;2698BOOLEAN status = false;26992700status = NDBG_GetAntDetValFromBt(Adapter, opcodeVer, &AntDetVal);27012702RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$ halbtcoutsrc_GetAntDetValFromBt(): status = %d, feature = %x\n", status, AntDetVal));27032704return AntDetVal;2705#else2706return 0;2707#endif2708}27092710u8 halbtcoutsrc_GetBleScanTypeFromBt(void *pBtcContext)2711{2712PBTC_COEXIST pBtCoexist;2713u32 ret = BT_STATUS_BT_OP_SUCCESS;2714u8 data = 0;27152716pBtCoexist = (PBTC_COEXIST)pBtcContext;27172718if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {2719u8 buf[3] = {0};2720_irqL irqL;2721u8 op_code;2722u8 status;272327242725_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);27262727op_code = BT_OP_GET_BT_BLE_SCAN_TYPE;2728status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);2729if (status == BT_STATUS_BT_OP_SUCCESS)2730data = *(u8 *)GLBtcBtMpRptRsp;2731else2732ret = SET_BT_MP_OPER_RET(op_code, status);27332734_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);27352736} else2737ret = BT_STATUS_NOT_IMPLEMENT;27382739return data;2740}27412742u32 halbtcoutsrc_GetBleScanParaFromBt(void *pBtcContext, u8 scanType)2743{2744PBTC_COEXIST pBtCoexist;2745u32 ret = BT_STATUS_BT_OP_SUCCESS;2746u32 data = 0;27472748pBtCoexist = (PBTC_COEXIST)pBtcContext;27492750if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {2751u8 buf[3] = {0};2752_irqL irqL;2753u8 op_code;2754u8 status;27552756buf[0] = scanType;27572758_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);27592760op_code = BT_OP_GET_BT_BLE_SCAN_PARA;2761status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 1);2762if (status == BT_STATUS_BT_OP_SUCCESS)2763data = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);2764else2765ret = SET_BT_MP_OPER_RET(op_code, status);27662767_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);27682769} else2770ret = BT_STATUS_NOT_IMPLEMENT;27712772return data;2773}27742775u8 halbtcoutsrc_GetBtAFHMapFromBt(void *pBtcContext, u8 mapType, u8 *afhMap)2776{2777struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;2778u8 buf[2] = {0};2779_irqL irqL;2780u8 op_code;2781u32 *AfhMapL = (u32 *)&(afhMap[0]);2782u32 *AfhMapM = (u32 *)&(afhMap[4]);2783u16 *AfhMapH = (u16 *)&(afhMap[8]);2784u8 status;2785u32 ret = BT_STATUS_BT_OP_SUCCESS;27862787if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _FALSE)2788return _FALSE;27892790buf[0] = 0;2791buf[1] = mapType;27922793_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);27942795op_code = BT_LO_OP_GET_AFH_MAP_L;2796status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);2797if (status == BT_STATUS_BT_OP_SUCCESS)2798*AfhMapL = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);2799else {2800ret = SET_BT_MP_OPER_RET(op_code, status);2801goto exit;2802}28032804op_code = BT_LO_OP_GET_AFH_MAP_M;2805status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);2806if (status == BT_STATUS_BT_OP_SUCCESS)2807*AfhMapM = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);2808else {2809ret = SET_BT_MP_OPER_RET(op_code, status);2810goto exit;2811}28122813op_code = BT_LO_OP_GET_AFH_MAP_H;2814status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);2815if (status == BT_STATUS_BT_OP_SUCCESS)2816*AfhMapH = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);2817else {2818ret = SET_BT_MP_OPER_RET(op_code, status);2819goto exit;2820}28212822exit:28232824_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);28252826return (ret == BT_STATUS_BT_OP_SUCCESS) ? _TRUE : _FALSE;2827}28282829u8 halbtcoutsrc_SetTimer(void *pBtcContext, u32 type, u32 val)2830{2831struct btc_coexist *pBtCoexist=(struct btc_coexist *)pBtcContext;28322833if (type >= BTC_TIMER_MAX)2834return _FALSE;28352836pBtCoexist->coex_sta.cnt_timer[type] = val;28372838RTW_DBG("[BTC], Set Timer: type = %d, val = %d\n", type, val);28392840return _TRUE;2841}28422843u32 halbtcoutsrc_SetAtomic (void *btc_ctx, u32 *target, u32 val)2844{2845*target = val;2846return _SUCCESS;2847}28482849void halbtcoutsrc_phydm_modify_AntDiv_HwSw(void *pBtcContext, u8 is_hw)2850{2851/* empty function since we don't need it */2852}28532854void halbtcoutsrc_phydm_modify_RA_PCR_threshold(void *pBtcContext, u8 RA_offset_direction, u8 RA_threshold_offset)2855{2856struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;28572858/* switch to #if 0 in case the phydm version does not provide the function */2859#if 12860phydm_modify_RA_PCR_threshold(pBtCoexist->odm_priv, RA_offset_direction, RA_threshold_offset);2861#endif2862}28632864u32 halbtcoutsrc_phydm_query_PHY_counter(void *pBtcContext, u8 info_type)2865{2866struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;28672868/* switch to #if 0 in case the phydm version does not provide the function */2869#if 12870return phydm_cmn_info_query((struct dm_struct *)pBtCoexist->odm_priv, (enum phydm_info_query)info_type);2871#else2872return 0;2873#endif2874}28752876void halbtcoutsrc_reduce_wl_tx_power(void *pBtcContext, s8 tx_power)2877{2878struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;2879HAL_DATA_TYPE *pHalData = GET_HAL_DATA((PADAPTER)pBtCoexist->Adapter);28802881/* The reduction of wl tx pwr should be processed inside the set tx pwr lvl function */2882if (IS_HARDWARE_TYPE_8822C(pBtCoexist->Adapter))2883rtw_hal_set_tx_power_level(pBtCoexist->Adapter, pHalData->current_channel);2884}28852886#if 02887static void BT_CoexOffloadRecordErrC2hAck(PADAPTER Adapter)2888{2889PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);28902891if (pDefaultAdapter != Adapter)2892return;28932894if (!hal_btcoex_IsBtExist(Adapter))2895return;28962897gl_coex_offload.cnt_c2h_ack++;28982899gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;2900}29012902static void BT_CoexOffloadC2hAckCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length)2903{2904PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);2905PCOL_C2H_ACK p_c2h_ack = NULL;2906u8 req_num = 0xff;29072908if (pDefaultAdapter != Adapter)2909return;29102911if (!hal_btcoex_IsBtExist(Adapter))2912return;29132914gl_coex_offload.cnt_c2h_ack++;29152916if (length < COL_C2H_ACK_HDR_LEN) { /* c2h ack length must >= 3 (status, opcode_ver, req_num and ret_len) */2917gl_coex_offload.status[COL_STATUS_INVALID_C2H_LEN]++;2918} else {2919BT_PrintData(Adapter, "[COL], c2h ack:", length, tmpBuf);29202921p_c2h_ack = (PCOL_C2H_ACK)tmpBuf;2922req_num = p_c2h_ack->req_num;29232924_rtw_memmove(&gl_coex_offload.c2h_ack_buf[req_num][0], tmpBuf, length);2925gl_coex_offload.c2h_ack_len[req_num] = length;29262927complete(&gl_coex_offload.c2h_event[req_num]);2928}2929}29302931static void BT_CoexOffloadC2hIndCheck(PADAPTER Adapter, u8 *tmpBuf, u8 length)2932{2933PADAPTER pDefaultAdapter = GetDefaultAdapter(Adapter);2934PCOL_C2H_IND p_c2h_ind = NULL;2935u8 ind_type = 0, ind_version = 0, ind_length = 0;29362937if (pDefaultAdapter != Adapter)2938return;29392940if (!hal_btcoex_IsBtExist(Adapter))2941return;29422943gl_coex_offload.cnt_c2h_ind++;29442945if (length < COL_C2H_IND_HDR_LEN) { /* c2h indication length must >= 3 (type, version and length) */2946gl_coex_offload.c2h_ind_status[COL_STATUS_INVALID_C2H_LEN]++;2947} else {2948BT_PrintData(Adapter, "[COL], c2h indication:", length, tmpBuf);29492950p_c2h_ind = (PCOL_C2H_IND)tmpBuf;2951ind_type = p_c2h_ind->type;2952ind_version = p_c2h_ind->version;2953ind_length = p_c2h_ind->length;29542955_rtw_memmove(&gl_coex_offload.c2h_ind_buf[0], tmpBuf, length);2956gl_coex_offload.c2h_ind_len = length;29572958/* log */2959gl_coex_offload.c2h_ind_record[ind_type].count++;2960gl_coex_offload.c2h_ind_record[ind_type].status[COL_STATUS_C2H_OK]++;2961_rtw_memmove(&gl_coex_offload.c2h_ind_record[ind_type].ind_buf[0], tmpBuf, length);2962gl_coex_offload.c2h_ind_record[ind_type].ind_len = length;29632964gl_coex_offload.c2h_ind_status[COL_STATUS_C2H_OK]++;2965/*TODO: need to check c2h indication length*/2966/* TODO: Notification */2967}2968}29692970void BT_CoexOffloadC2hCheck(PADAPTER Adapter, u8 *Buffer, u8 Length)2971{2972#if 0 /*(USE_HAL_MAC_API == 1)*/2973u8 c2hSubCmdId = 0, c2hAckLen = 0, h2cCmdId = 0, h2cSubCmdId = 0, c2hIndLen = 0;29742975BT_PrintData(Adapter, "[COL], c2h packet:", Length - 2, Buffer + 2);2976c2hSubCmdId = (u8)C2H_HDR_GET_C2H_SUB_CMD_ID(Buffer);29772978if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR ||2979c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) {2980if (c2hSubCmdId == C2H_SUB_CMD_ID_H2C_ACK_HDR) {2981/* coex c2h ack */2982h2cCmdId = (u8)H2C_ACK_HDR_GET_H2C_CMD_ID(Buffer);2983h2cSubCmdId = (u8)H2C_ACK_HDR_GET_H2C_SUB_CMD_ID(Buffer);2984if (h2cCmdId == 0xff && h2cSubCmdId == 0x60) {2985c2hAckLen = (u8)C2H_HDR_GET_LEN(Buffer);2986if (c2hAckLen >= 8)2987BT_CoexOffloadC2hAckCheck(Adapter, &Buffer[12], (u8)(c2hAckLen - 8));2988else2989BT_CoexOffloadRecordErrC2hAck(Adapter);2990}2991} else if (c2hSubCmdId == C2H_SUB_CMD_ID_BT_COEX_INFO) {2992/* coex c2h indication */2993c2hIndLen = (u8)C2H_HDR_GET_LEN(Buffer);2994BT_CoexOffloadC2hIndCheck(Adapter, &Buffer[4], (u8)c2hIndLen);2995}2996}2997#endif2998}2999#endif30003001/* ************************************3002* Extern functions called by other module3003* ************************************ */3004u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter)3005{3006PBTC_COEXIST pBtCoexist = &GLBtCoexist;3007HAL_DATA_TYPE *pHalData = GET_HAL_DATA((PADAPTER)padapter);30083009if (pBtCoexist->bBinded)3010return _FALSE;3011else3012pBtCoexist->bBinded = _TRUE;30133014pBtCoexist->statistics.cnt_bind++;30153016pBtCoexist->Adapter = padapter;3017pBtCoexist->odm_priv = (void *)&(pHalData->odmpriv);30183019pBtCoexist->stack_info.profile_notified = _FALSE;30203021pBtCoexist->bt_info.bt_ctrl_agg_buf_size = _FALSE;3022pBtCoexist->bt_info.agg_buf_size = 5;30233024pBtCoexist->bt_info.increase_scan_dev_num = _FALSE;3025pBtCoexist->bt_info.miracast_plus_bt = _FALSE;30263027/* for btc common architecture, inform chip type to coex. mechanism */3028if(IS_HARDWARE_TYPE_8822C(padapter)) {3029#ifdef CONFIG_RTL8822C3030pBtCoexist->chip_type = BTC_CHIP_RTL8822C;3031pBtCoexist->chip_para = &btc_chip_para_8822c;3032#endif3033}3034#ifdef CONFIG_RTL8192F3035else if (IS_HARDWARE_TYPE_8192F(padapter)) {3036pBtCoexist->chip_type = BTC_CHIP_RTL8725A;3037pBtCoexist->chip_para = &btc_chip_para_8192f;3038}3039#endif3040else {3041pBtCoexist->chip_type = BTC_CHIP_UNDEF;3042pBtCoexist->chip_para = NULL;3043}30443045return _TRUE;3046}30473048void EXhalbtcoutsrc_AntInfoSetting(void *padapter)3049{3050PBTC_COEXIST pBtCoexist = &GLBtCoexist;3051u8 antNum = 1, singleAntPath = 0;30523053antNum = rtw_btcoex_get_pg_ant_num((PADAPTER)padapter);3054EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum);30553056if (antNum == 1) {3057singleAntPath = rtw_btcoex_get_pg_single_ant_path((PADAPTER)padapter);3058EXhalbtcoutsrc_SetSingleAntPath(singleAntPath);3059}30603061pBtCoexist->board_info.customerID = RT_CID_DEFAULT;3062pBtCoexist->board_info.customer_id = RT_CID_DEFAULT;30633064/* set default antenna position to main port */3065pBtCoexist->board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;30663067pBtCoexist->board_info.btdm_ant_det_finish = _FALSE;3068pBtCoexist->board_info.btdm_ant_num_by_ant_det = 1;30693070pBtCoexist->board_info.tfbga_package = rtw_btcoex_is_tfbga_package_type((PADAPTER)padapter);30713072pBtCoexist->board_info.rfe_type = rtw_btcoex_get_pg_rfe_type((PADAPTER)padapter);30733074pBtCoexist->board_info.ant_div_cfg = rtw_btcoex_get_ant_div_cfg((PADAPTER)padapter);30753076pBtCoexist->board_info.ant_distance = 10;3077}30783079u8 EXhalbtcoutsrc_InitlizeVariables(void *padapter)3080{3081PBTC_COEXIST pBtCoexist = &GLBtCoexist;30823083/* pBtCoexist->statistics.cntBind++; */30843085halbtcoutsrc_DbgInit();30863087halbtcoutsrc_coex_offload_init();30883089#ifdef CONFIG_PCI_HCI3090pBtCoexist->chip_interface = BTC_INTF_PCI;3091#elif defined(CONFIG_USB_HCI)3092pBtCoexist->chip_interface = BTC_INTF_USB;3093#elif defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)3094pBtCoexist->chip_interface = BTC_INTF_SDIO;3095#else3096pBtCoexist->chip_interface = BTC_INTF_UNKNOWN;3097#endif30983099EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter);31003101pBtCoexist->btc_read_1byte = halbtcoutsrc_Read1Byte;3102pBtCoexist->btc_write_1byte = halbtcoutsrc_Write1Byte;3103pBtCoexist->btc_write_1byte_bitmask = halbtcoutsrc_BitMaskWrite1Byte;3104pBtCoexist->btc_read_2byte = halbtcoutsrc_Read2Byte;3105pBtCoexist->btc_write_2byte = halbtcoutsrc_Write2Byte;3106pBtCoexist->btc_read_4byte = halbtcoutsrc_Read4Byte;3107pBtCoexist->btc_write_4byte = halbtcoutsrc_Write4Byte;3108pBtCoexist->btc_write_local_reg_1byte = halbtcoutsrc_WriteLocalReg1Byte;31093110pBtCoexist->btc_read_linderct = halbtcoutsrc_ReadLIndirectReg;3111pBtCoexist->btc_write_linderct = halbtcoutsrc_WriteLIndirectReg;31123113pBtCoexist->btc_read_scbd = halbtcoutsrc_Read_scbd;3114pBtCoexist->btc_write_scbd = halbtcoutsrc_Write_scbd;31153116pBtCoexist->btc_set_bb_reg = halbtcoutsrc_SetBbReg;3117pBtCoexist->btc_get_bb_reg = halbtcoutsrc_GetBbReg;31183119pBtCoexist->btc_set_rf_reg = halbtcoutsrc_SetRfReg;3120pBtCoexist->btc_get_rf_reg = halbtcoutsrc_GetRfReg;31213122pBtCoexist->btc_fill_h2c = halbtcoutsrc_FillH2cCmd;3123pBtCoexist->btc_disp_dbg_msg = halbtcoutsrc_DisplayDbgMsg;31243125pBtCoexist->btc_get = halbtcoutsrc_Get;3126pBtCoexist->btc_set = halbtcoutsrc_Set;3127pBtCoexist->btc_get_bt_reg = halbtcoutsrc_GetBtReg;3128pBtCoexist->btc_set_bt_reg = halbtcoutsrc_SetBtReg;3129pBtCoexist->btc_set_bt_ant_detection = halbtcoutsrc_SetBtAntDetection;3130pBtCoexist->btc_set_bt_trx_mask = halbtcoutsrc_SetBtTRXMASK;3131pBtCoexist->btc_coex_h2c_process = halbtcoutsrc_CoexH2cProcess;3132pBtCoexist->btc_get_bt_coex_supported_feature = halbtcoutsrc_GetBtCoexSupportedFeature;3133pBtCoexist->btc_get_bt_coex_supported_version= halbtcoutsrc_GetBtCoexSupportedVersion;3134pBtCoexist->btc_get_ant_det_val_from_bt = halbtcoutsrc_GetAntDetValFromBt;3135pBtCoexist->btc_get_ble_scan_type_from_bt = halbtcoutsrc_GetBleScanTypeFromBt;3136pBtCoexist->btc_get_ble_scan_para_from_bt = halbtcoutsrc_GetBleScanParaFromBt;3137pBtCoexist->btc_get_bt_afh_map_from_bt = halbtcoutsrc_GetBtAFHMapFromBt;3138pBtCoexist->btc_get_bt_phydm_version = halbtcoutsrc_GetPhydmVersion;3139pBtCoexist->btc_set_timer = halbtcoutsrc_SetTimer;3140pBtCoexist->btc_set_atomic= halbtcoutsrc_SetAtomic;3141pBtCoexist->btc_phydm_modify_RA_PCR_threshold = halbtcoutsrc_phydm_modify_RA_PCR_threshold;3142pBtCoexist->btc_phydm_query_PHY_counter = halbtcoutsrc_phydm_query_PHY_counter;3143pBtCoexist->btc_reduce_wl_tx_power = halbtcoutsrc_reduce_wl_tx_power;3144pBtCoexist->btc_phydm_modify_antdiv_hwsw = halbtcoutsrc_phydm_modify_AntDiv_HwSw;31453146pBtCoexist->cli_buf = &GLBtcDbgBuf[0];31473148GLBtcWiFiInScanState = _FALSE;31493150GLBtcWiFiInIQKState = _FALSE;31513152GLBtcWiFiInIPS = _FALSE;31533154GLBtcWiFiInLPS = _FALSE;31553156GLBtcBtCoexAliveRegistered = _FALSE;31573158/* BT Control H2C/C2H*/3159GLBtcBtMpOperSeq = 0;3160_rtw_mutex_init(&GLBtcBtMpOperLock);3161rtw_init_timer(&GLBtcBtMpOperTimer, padapter, _btmpoper_timer_hdl, pBtCoexist);3162_rtw_init_sema(&GLBtcBtMpRptSema, 0);3163GLBtcBtMpRptSeq = 0;3164GLBtcBtMpRptStatus = 0;3165_rtw_memset(GLBtcBtMpRptRsp, 0, C2H_MAX_SIZE);3166GLBtcBtMpRptRspSize = 0;3167GLBtcBtMpRptWait = _FALSE;3168GLBtcBtMpRptWiFiOK = _FALSE;3169GLBtcBtMpRptBTOK = _FALSE;31703171return _TRUE;3172}31733174void EXhalbtcoutsrc_PowerOnSetting(PBTC_COEXIST pBtCoexist)3175{3176HAL_DATA_TYPE *pHalData = NULL;31773178if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))3179return;31803181pHalData = GET_HAL_DATA((PADAPTER)pBtCoexist->Adapter);31823183#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)3184rtw_btc_ex_power_on_setting(pBtCoexist);31853186#else3187if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {3188#ifdef CONFIG_RTL8723B3189if (pBtCoexist->board_info.btdm_ant_num == 2)3190ex_halbtc8723b2ant_power_on_setting(pBtCoexist);3191else if (pBtCoexist->board_info.btdm_ant_num == 1)3192ex_halbtc8723b1ant_power_on_setting(pBtCoexist);3193#endif3194}31953196#ifdef CONFIG_RTL8703B3197else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {3198if (pBtCoexist->board_info.btdm_ant_num == 1)3199ex_halbtc8703b1ant_power_on_setting(pBtCoexist);3200}3201#endif32023203#ifdef CONFIG_RTL8723D3204else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {3205if (pBtCoexist->board_info.btdm_ant_num == 2)3206ex_halbtc8723d2ant_power_on_setting(pBtCoexist);3207else if (pBtCoexist->board_info.btdm_ant_num == 1)3208ex_halbtc8723d1ant_power_on_setting(pBtCoexist);3209}3210#endif32113212#ifdef CONFIG_RTL8821A3213else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {3214if (pBtCoexist->board_info.btdm_ant_num == 1)3215ex_halbtc8821a1ant_power_on_setting(pBtCoexist);3216else if (pBtCoexist->board_info.btdm_ant_num == 2)3217ex_halbtc8821a2ant_power_on_setting(pBtCoexist);3218}3219#endif32203221#ifdef CONFIG_RTL8822B3222else if ((IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) && (pHalData->EEPROMBluetoothCoexist == _TRUE)) {3223if (pBtCoexist->board_info.btdm_ant_num == 1)3224ex_halbtc8822b1ant_power_on_setting(pBtCoexist);3225else if (pBtCoexist->board_info.btdm_ant_num == 2)3226ex_halbtc8822b2ant_power_on_setting(pBtCoexist);3227}3228#endif32293230#ifdef CONFIG_RTL8821C3231else if ((IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) && (pHalData->EEPROMBluetoothCoexist == _TRUE)) {3232if (pBtCoexist->board_info.btdm_ant_num == 2)3233ex_halbtc8821c2ant_power_on_setting(pBtCoexist);3234else if (pBtCoexist->board_info.btdm_ant_num == 1)3235ex_halbtc8821c1ant_power_on_setting(pBtCoexist);3236}3237#endif32383239#ifdef CONFIG_RTL8814A3240if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {3241if (pBtCoexist->board_info.btdm_ant_num == 2)3242ex_halbtc8814a2ant_power_on_setting(pBtCoexist);3243/* else if (pBtCoexist->board_info.btdm_ant_num == 1)3244ex_halbtc8814a1ant_power_on_setting(pBtCoexist); */3245}3246#endif32473248#endif3249}32503251void EXhalbtcoutsrc_PreLoadFirmware(PBTC_COEXIST pBtCoexist)3252{3253if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))3254return;32553256pBtCoexist->statistics.cnt_pre_load_firmware++;32573258if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {3259#ifdef CONFIG_RTL8723B3260if (pBtCoexist->board_info.btdm_ant_num == 2)3261ex_halbtc8723b2ant_pre_load_firmware(pBtCoexist);3262else if (pBtCoexist->board_info.btdm_ant_num == 1)3263ex_halbtc8723b1ant_pre_load_firmware(pBtCoexist);3264#endif3265}32663267#ifdef CONFIG_RTL8723D3268else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {3269if (pBtCoexist->board_info.btdm_ant_num == 2)3270ex_halbtc8723d2ant_pre_load_firmware(pBtCoexist);3271else if (pBtCoexist->board_info.btdm_ant_num == 1)3272ex_halbtc8723d1ant_pre_load_firmware(pBtCoexist);3273}3274#endif32753276#ifdef CONFIG_RTL8821C3277else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {3278if (pBtCoexist->board_info.btdm_ant_num == 2)3279ex_halbtc8821c2ant_pre_load_firmware(pBtCoexist);3280else if (pBtCoexist->board_info.btdm_ant_num == 1)3281ex_halbtc8821c1ant_pre_load_firmware(pBtCoexist);3282}3283#endif3284}32853286void EXhalbtcoutsrc_init_hw_config(PBTC_COEXIST pBtCoexist, u8 bWifiOnly)3287{3288if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))3289return;32903291pBtCoexist->statistics.cnt_init_hw_config++;32923293#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)3294rtw_btc_ex_init_hw_config(pBtCoexist, bWifiOnly);3295#else32963297if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {3298#ifdef CONFIG_RTL8821A3299if (pBtCoexist->board_info.btdm_ant_num == 2)3300ex_halbtc8821a2ant_init_hw_config(pBtCoexist, bWifiOnly);3301else if (pBtCoexist->board_info.btdm_ant_num == 1)3302ex_halbtc8821a1ant_init_hw_config(pBtCoexist, bWifiOnly);3303#endif3304}33053306#ifdef CONFIG_RTL8723B3307else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {3308if (pBtCoexist->board_info.btdm_ant_num == 2)3309ex_halbtc8723b2ant_init_hw_config(pBtCoexist, bWifiOnly);3310else if (pBtCoexist->board_info.btdm_ant_num == 1)3311ex_halbtc8723b1ant_init_hw_config(pBtCoexist, bWifiOnly);3312}3313#endif33143315#ifdef CONFIG_RTL8703B3316else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {3317if (pBtCoexist->board_info.btdm_ant_num == 1)3318ex_halbtc8703b1ant_init_hw_config(pBtCoexist, bWifiOnly);3319}3320#endif33213322#ifdef CONFIG_RTL8723D3323else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {3324if (pBtCoexist->board_info.btdm_ant_num == 2)3325ex_halbtc8723d2ant_init_hw_config(pBtCoexist, bWifiOnly);3326else if (pBtCoexist->board_info.btdm_ant_num == 1)3327ex_halbtc8723d1ant_init_hw_config(pBtCoexist, bWifiOnly);3328}3329#endif33303331#ifdef CONFIG_RTL8192E3332else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {3333if (pBtCoexist->board_info.btdm_ant_num == 2)3334ex_halbtc8192e2ant_init_hw_config(pBtCoexist, bWifiOnly);3335else if (pBtCoexist->board_info.btdm_ant_num == 1)3336ex_halbtc8192e1ant_init_hw_config(pBtCoexist, bWifiOnly);3337}3338#endif33393340#ifdef CONFIG_RTL8812A3341else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {3342if (pBtCoexist->board_info.btdm_ant_num == 2)3343ex_halbtc8812a2ant_init_hw_config(pBtCoexist, bWifiOnly);3344else if (pBtCoexist->board_info.btdm_ant_num == 1)3345ex_halbtc8812a1ant_init_hw_config(pBtCoexist, bWifiOnly);3346}3347#endif33483349#ifdef CONFIG_RTL8822B3350else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {3351if (pBtCoexist->board_info.btdm_ant_num == 1)3352ex_halbtc8822b1ant_init_hw_config(pBtCoexist, bWifiOnly);3353else if (pBtCoexist->board_info.btdm_ant_num == 2)3354ex_halbtc8822b2ant_init_hw_config(pBtCoexist, bWifiOnly);3355}3356#endif33573358#ifdef CONFIG_RTL8821C3359else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {3360if (pBtCoexist->board_info.btdm_ant_num == 2)3361ex_halbtc8821c2ant_init_hw_config(pBtCoexist, bWifiOnly);3362else if (pBtCoexist->board_info.btdm_ant_num == 1)3363ex_halbtc8821c1ant_init_hw_config(pBtCoexist, bWifiOnly);3364}3365#endif33663367#ifdef CONFIG_RTL8814A3368else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {3369if (pBtCoexist->board_info.btdm_ant_num == 2)3370ex_halbtc8814a2ant_init_hw_config(pBtCoexist, bWifiOnly);3371}3372#endif33733374#endif3375}33763377void EXhalbtcoutsrc_init_coex_dm(PBTC_COEXIST pBtCoexist)3378{3379if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))3380return;33813382pBtCoexist->statistics.cnt_init_coex_dm++;33833384#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)3385rtw_btc_ex_init_coex_dm(pBtCoexist);3386#else33873388if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {3389#ifdef CONFIG_RTL8821A3390if (pBtCoexist->board_info.btdm_ant_num == 2)3391ex_halbtc8821a2ant_init_coex_dm(pBtCoexist);3392else if (pBtCoexist->board_info.btdm_ant_num == 1)3393ex_halbtc8821a1ant_init_coex_dm(pBtCoexist);3394#endif3395}33963397#ifdef CONFIG_RTL8723B3398else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {3399if (pBtCoexist->board_info.btdm_ant_num == 2)3400ex_halbtc8723b2ant_init_coex_dm(pBtCoexist);3401else if (pBtCoexist->board_info.btdm_ant_num == 1)3402ex_halbtc8723b1ant_init_coex_dm(pBtCoexist);3403}3404#endif34053406#ifdef CONFIG_RTL8703B3407else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {3408if (pBtCoexist->board_info.btdm_ant_num == 1)3409ex_halbtc8703b1ant_init_coex_dm(pBtCoexist);3410}3411#endif34123413#ifdef CONFIG_RTL8723D3414else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {3415if (pBtCoexist->board_info.btdm_ant_num == 2)3416ex_halbtc8723d2ant_init_coex_dm(pBtCoexist);3417else if (pBtCoexist->board_info.btdm_ant_num == 1)3418ex_halbtc8723d1ant_init_coex_dm(pBtCoexist);3419}3420#endif34213422#ifdef CONFIG_RTL8192E3423else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {3424if (pBtCoexist->board_info.btdm_ant_num == 2)3425ex_halbtc8192e2ant_init_coex_dm(pBtCoexist);3426else if (pBtCoexist->board_info.btdm_ant_num == 1)3427ex_halbtc8192e1ant_init_coex_dm(pBtCoexist);3428}3429#endif34303431#ifdef CONFIG_RTL8812A3432else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {3433if (pBtCoexist->board_info.btdm_ant_num == 2)3434ex_halbtc8812a2ant_init_coex_dm(pBtCoexist);3435else if (pBtCoexist->board_info.btdm_ant_num == 1)3436ex_halbtc8812a1ant_init_coex_dm(pBtCoexist);3437}3438#endif34393440#ifdef CONFIG_RTL8822B3441else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {3442if (pBtCoexist->board_info.btdm_ant_num == 1)3443ex_halbtc8822b1ant_init_coex_dm(pBtCoexist);3444else if (pBtCoexist->board_info.btdm_ant_num == 2)3445ex_halbtc8822b2ant_init_coex_dm(pBtCoexist);3446}3447#endif34483449#ifdef CONFIG_RTL8821C3450else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {3451if (pBtCoexist->board_info.btdm_ant_num == 2)3452ex_halbtc8821c2ant_init_coex_dm(pBtCoexist);3453else if (pBtCoexist->board_info.btdm_ant_num == 1)3454ex_halbtc8821c1ant_init_coex_dm(pBtCoexist);3455}3456#endif34573458#ifdef CONFIG_RTL8814A3459else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {3460if (pBtCoexist->board_info.btdm_ant_num == 2)3461ex_halbtc8814a2ant_init_coex_dm(pBtCoexist);3462}3463#endif34643465#endif34663467pBtCoexist->initilized = _TRUE;3468}34693470void EXhalbtcoutsrc_ips_notify(PBTC_COEXIST pBtCoexist, u8 type)3471{3472u8 ipsType;34733474if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))3475return;34763477pBtCoexist->statistics.cnt_ips_notify++;3478if (pBtCoexist->manual_control)3479return;34803481if (IPS_NONE == type) {3482ipsType = BTC_IPS_LEAVE;3483GLBtcWiFiInIPS = _FALSE;3484} else {3485ipsType = BTC_IPS_ENTER;3486GLBtcWiFiInIPS = _TRUE;3487}34883489/* All notify is called in cmd thread, don't need to leave low power again3490* halbtcoutsrc_LeaveLowPower(pBtCoexist); */34913492#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)3493rtw_btc_ex_ips_notify(pBtCoexist, ipsType);3494#else34953496if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {3497#ifdef CONFIG_RTL8821A3498if (pBtCoexist->board_info.btdm_ant_num == 2)3499ex_halbtc8821a2ant_ips_notify(pBtCoexist, ipsType);3500else if (pBtCoexist->board_info.btdm_ant_num == 1)3501ex_halbtc8821a1ant_ips_notify(pBtCoexist, ipsType);3502#endif3503}35043505#ifdef CONFIG_RTL8723B3506else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {3507if (pBtCoexist->board_info.btdm_ant_num == 2)3508ex_halbtc8723b2ant_ips_notify(pBtCoexist, ipsType);3509else if (pBtCoexist->board_info.btdm_ant_num == 1)3510ex_halbtc8723b1ant_ips_notify(pBtCoexist, ipsType);3511}3512#endif35133514#ifdef CONFIG_RTL8703B3515else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {3516if (pBtCoexist->board_info.btdm_ant_num == 1)3517ex_halbtc8703b1ant_ips_notify(pBtCoexist, ipsType);3518}3519#endif35203521#ifdef CONFIG_RTL8723D3522else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {3523if (pBtCoexist->board_info.btdm_ant_num == 2)3524ex_halbtc8723d2ant_ips_notify(pBtCoexist, ipsType);3525else if (pBtCoexist->board_info.btdm_ant_num == 1)3526ex_halbtc8723d1ant_ips_notify(pBtCoexist, ipsType);3527}3528#endif35293530#ifdef CONFIG_RTL8192E3531else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {3532if (pBtCoexist->board_info.btdm_ant_num == 2)3533ex_halbtc8192e2ant_ips_notify(pBtCoexist, ipsType);3534else if (pBtCoexist->board_info.btdm_ant_num == 1)3535ex_halbtc8192e1ant_ips_notify(pBtCoexist, ipsType);3536}3537#endif35383539#ifdef CONFIG_RTL8812A3540else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {3541if (pBtCoexist->board_info.btdm_ant_num == 2)3542ex_halbtc8812a2ant_ips_notify(pBtCoexist, ipsType);3543else if (pBtCoexist->board_info.btdm_ant_num == 1)3544ex_halbtc8812a1ant_ips_notify(pBtCoexist, ipsType);3545}3546#endif35473548#ifdef CONFIG_RTL8822B3549else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {3550if (pBtCoexist->board_info.btdm_ant_num == 1)3551ex_halbtc8822b1ant_ips_notify(pBtCoexist, ipsType);3552else if (pBtCoexist->board_info.btdm_ant_num == 2)3553ex_halbtc8822b2ant_ips_notify(pBtCoexist, ipsType);3554}3555#endif35563557#ifdef CONFIG_RTL8821C3558else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {3559if (pBtCoexist->board_info.btdm_ant_num == 2)3560ex_halbtc8821c2ant_ips_notify(pBtCoexist, ipsType);3561else if (pBtCoexist->board_info.btdm_ant_num == 1)3562ex_halbtc8821c1ant_ips_notify(pBtCoexist, ipsType);3563}3564#endif35653566#ifdef CONFIG_RTL8814A3567else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {3568if (pBtCoexist->board_info.btdm_ant_num == 2)3569ex_halbtc8814a2ant_ips_notify(pBtCoexist, ipsType);3570}3571#endif35723573#endif3574/* halbtcoutsrc_NormalLowPower(pBtCoexist); */3575}35763577void EXhalbtcoutsrc_lps_notify(PBTC_COEXIST pBtCoexist, u8 type)3578{3579u8 lpsType;358035813582if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))3583return;35843585pBtCoexist->statistics.cnt_lps_notify++;3586if (pBtCoexist->manual_control)3587return;35883589if (PS_MODE_ACTIVE == type) {3590lpsType = BTC_LPS_DISABLE;3591GLBtcWiFiInLPS = _FALSE;3592} else {3593lpsType = BTC_LPS_ENABLE;3594GLBtcWiFiInLPS = _TRUE;3595}35963597#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)3598rtw_btc_ex_lps_notify(pBtCoexist, lpsType);3599#else36003601if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {3602#ifdef CONFIG_RTL8821A3603if (pBtCoexist->board_info.btdm_ant_num == 2)3604ex_halbtc8821a2ant_lps_notify(pBtCoexist, lpsType);3605else if (pBtCoexist->board_info.btdm_ant_num == 1)3606ex_halbtc8821a1ant_lps_notify(pBtCoexist, lpsType);3607#endif3608}36093610#ifdef CONFIG_RTL8723B3611else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {3612if (pBtCoexist->board_info.btdm_ant_num == 2)3613ex_halbtc8723b2ant_lps_notify(pBtCoexist, lpsType);3614else if (pBtCoexist->board_info.btdm_ant_num == 1)3615ex_halbtc8723b1ant_lps_notify(pBtCoexist, lpsType);3616}3617#endif36183619#ifdef CONFIG_RTL8703B3620else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {3621if (pBtCoexist->board_info.btdm_ant_num == 1)3622ex_halbtc8703b1ant_lps_notify(pBtCoexist, lpsType);3623}3624#endif36253626#ifdef CONFIG_RTL8723D3627else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {3628if (pBtCoexist->board_info.btdm_ant_num == 2)3629ex_halbtc8723d2ant_lps_notify(pBtCoexist, lpsType);3630else if (pBtCoexist->board_info.btdm_ant_num == 1)3631ex_halbtc8723d1ant_lps_notify(pBtCoexist, lpsType);3632}3633#endif36343635#ifdef CONFIG_RTL8192E3636else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {3637if (pBtCoexist->board_info.btdm_ant_num == 2)3638ex_halbtc8192e2ant_lps_notify(pBtCoexist, lpsType);3639else if (pBtCoexist->board_info.btdm_ant_num == 1)3640ex_halbtc8192e1ant_lps_notify(pBtCoexist, lpsType);3641}3642#endif36433644#ifdef CONFIG_RTL8812A3645else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {3646if (pBtCoexist->board_info.btdm_ant_num == 2)3647ex_halbtc8812a2ant_lps_notify(pBtCoexist, lpsType);3648else if (pBtCoexist->board_info.btdm_ant_num == 1)3649ex_halbtc8812a1ant_lps_notify(pBtCoexist, lpsType);3650}3651#endif36523653#ifdef CONFIG_RTL8822B3654else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {3655if (pBtCoexist->board_info.btdm_ant_num == 1)3656ex_halbtc8822b1ant_lps_notify(pBtCoexist, lpsType);3657else if (pBtCoexist->board_info.btdm_ant_num == 2)3658ex_halbtc8822b2ant_lps_notify(pBtCoexist, lpsType);3659}3660#endif36613662#ifdef CONFIG_RTL8821C3663else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {3664if (pBtCoexist->board_info.btdm_ant_num == 2)3665ex_halbtc8821c2ant_lps_notify(pBtCoexist, lpsType);3666else if (pBtCoexist->board_info.btdm_ant_num == 1)3667ex_halbtc8821c1ant_lps_notify(pBtCoexist, lpsType);3668}3669#endif36703671#ifdef CONFIG_RTL8814A3672else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {3673if (pBtCoexist->board_info.btdm_ant_num == 2)3674ex_halbtc8814a2ant_lps_notify(pBtCoexist, lpsType);3675}3676#endif36773678#endif3679}36803681void EXhalbtcoutsrc_scan_notify(PBTC_COEXIST pBtCoexist, u8 type)3682{3683u8 scanType;36843685if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))3686return;3687pBtCoexist->statistics.cnt_scan_notify++;3688if (pBtCoexist->manual_control)3689return;36903691if (type) {3692scanType = BTC_SCAN_START;3693GLBtcWiFiInScanState = _TRUE;3694} else {3695scanType = BTC_SCAN_FINISH;3696GLBtcWiFiInScanState = _FALSE;3697}36983699/* All notify is called in cmd thread, don't need to leave low power again3700* halbtcoutsrc_LeaveLowPower(pBtCoexist); */37013702#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)3703rtw_btc_ex_scan_notify(pBtCoexist, scanType);3704#else37053706if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {3707#ifdef CONFIG_RTL8821A3708if (pBtCoexist->board_info.btdm_ant_num == 2)3709ex_halbtc8821a2ant_scan_notify(pBtCoexist, scanType);3710else if (pBtCoexist->board_info.btdm_ant_num == 1)3711ex_halbtc8821a1ant_scan_notify(pBtCoexist, scanType);3712#endif3713}37143715#ifdef CONFIG_RTL8723B3716else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {3717if (pBtCoexist->board_info.btdm_ant_num == 2)3718ex_halbtc8723b2ant_scan_notify(pBtCoexist, scanType);3719else if (pBtCoexist->board_info.btdm_ant_num == 1)3720ex_halbtc8723b1ant_scan_notify(pBtCoexist, scanType);3721}3722#endif37233724#ifdef CONFIG_RTL8703B3725else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {3726if (pBtCoexist->board_info.btdm_ant_num == 1)3727ex_halbtc8703b1ant_scan_notify(pBtCoexist, scanType);3728}3729#endif37303731#ifdef CONFIG_RTL8723D3732else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {3733if (pBtCoexist->board_info.btdm_ant_num == 2)3734ex_halbtc8723d2ant_scan_notify(pBtCoexist, scanType);3735else if (pBtCoexist->board_info.btdm_ant_num == 1)3736ex_halbtc8723d1ant_scan_notify(pBtCoexist, scanType);3737}3738#endif37393740#ifdef CONFIG_RTL8192E3741else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {3742if (pBtCoexist->board_info.btdm_ant_num == 2)3743ex_halbtc8192e2ant_scan_notify(pBtCoexist, scanType);3744else if (pBtCoexist->board_info.btdm_ant_num == 1)3745ex_halbtc8192e1ant_scan_notify(pBtCoexist, scanType);3746}3747#endif37483749#ifdef CONFIG_RTL8812A3750else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {3751if (pBtCoexist->board_info.btdm_ant_num == 2)3752ex_halbtc8812a2ant_scan_notify(pBtCoexist, scanType);3753else if (pBtCoexist->board_info.btdm_ant_num == 1)3754ex_halbtc8812a1ant_scan_notify(pBtCoexist, scanType);3755}3756#endif37573758#ifdef CONFIG_RTL8822B3759else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {3760if (pBtCoexist->board_info.btdm_ant_num == 1)3761ex_halbtc8822b1ant_scan_notify(pBtCoexist, scanType);3762else if (pBtCoexist->board_info.btdm_ant_num == 2)3763ex_halbtc8822b2ant_scan_notify(pBtCoexist, scanType);3764}3765#endif37663767#ifdef CONFIG_RTL8821C3768else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {3769if (pBtCoexist->board_info.btdm_ant_num == 2)3770ex_halbtc8821c2ant_scan_notify(pBtCoexist, scanType);3771else if (pBtCoexist->board_info.btdm_ant_num == 1)3772ex_halbtc8821c1ant_scan_notify(pBtCoexist, scanType);3773}3774#endif37753776#ifdef CONFIG_RTL8814A3777else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {3778if (pBtCoexist->board_info.btdm_ant_num == 2)3779ex_halbtc8814a2ant_scan_notify(pBtCoexist, scanType);3780}3781#endif37823783#endif37843785/* halbtcoutsrc_NormalLowPower(pBtCoexist); */3786}37873788void EXhalbtcoutsrc_SetAntennaPathNotify(PBTC_COEXIST pBtCoexist, u8 type)3789{3790#if 03791u8 switchType;37923793if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))3794return;37953796if (pBtCoexist->manual_control)3797return;37983799halbtcoutsrc_LeaveLowPower(pBtCoexist);38003801switchType = type;38023803if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {3804if (pBtCoexist->board_info.btdm_ant_num == 1)3805ex_halbtc8723b1ant_set_antenna_notify(pBtCoexist, type);3806}3807if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {3808if (pBtCoexist->board_info.btdm_ant_num == 1)3809ex_halbtc8723d1ant_set_antenna_notify(pBtCoexist, type);3810else if (pBtCoexist->board_info.btdm_ant_num == 2)3811ex_halbtc8723d2ant_set_antenna_notify(pBtCoexist, type);3812}38133814halbtcoutsrc_NormalLowPower(pBtCoexist);3815#endif3816}38173818void EXhalbtcoutsrc_connect_notify(PBTC_COEXIST pBtCoexist, u8 assoType)3819{3820if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))3821return;3822pBtCoexist->statistics.cnt_connect_notify++;3823if (pBtCoexist->manual_control)3824return;38253826/* All notify is called in cmd thread, don't need to leave low power again3827* halbtcoutsrc_LeaveLowPower(pBtCoexist); */3828#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)3829rtw_btc_ex_connect_notify(pBtCoexist, assoType);3830#else38313832if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {3833#ifdef CONFIG_RTL8821A3834if (pBtCoexist->board_info.btdm_ant_num == 2)3835ex_halbtc8821a2ant_connect_notify(pBtCoexist, assoType);3836else if (pBtCoexist->board_info.btdm_ant_num == 1)3837ex_halbtc8821a1ant_connect_notify(pBtCoexist, assoType);3838#endif3839}38403841#ifdef CONFIG_RTL8723B3842else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {3843if (pBtCoexist->board_info.btdm_ant_num == 2)3844ex_halbtc8723b2ant_connect_notify(pBtCoexist, assoType);3845else if (pBtCoexist->board_info.btdm_ant_num == 1)3846ex_halbtc8723b1ant_connect_notify(pBtCoexist, assoType);3847}3848#endif38493850#ifdef CONFIG_RTL8703B3851else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {3852if (pBtCoexist->board_info.btdm_ant_num == 1)3853ex_halbtc8703b1ant_connect_notify(pBtCoexist, assoType);3854}3855#endif38563857#ifdef CONFIG_RTL8723D3858else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {3859if (pBtCoexist->board_info.btdm_ant_num == 2)3860ex_halbtc8723d2ant_connect_notify(pBtCoexist, assoType);3861else if (pBtCoexist->board_info.btdm_ant_num == 1)3862ex_halbtc8723d1ant_connect_notify(pBtCoexist, assoType);3863}3864#endif38653866#ifdef CONFIG_RTL8192E3867else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {3868if (pBtCoexist->board_info.btdm_ant_num == 2)3869ex_halbtc8192e2ant_connect_notify(pBtCoexist, assoType);3870else if (pBtCoexist->board_info.btdm_ant_num == 1)3871ex_halbtc8192e1ant_connect_notify(pBtCoexist, assoType);3872}3873#endif38743875#ifdef CONFIG_RTL8812A3876else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {3877if (pBtCoexist->board_info.btdm_ant_num == 2)3878ex_halbtc8812a2ant_connect_notify(pBtCoexist, assoType);3879else if (pBtCoexist->board_info.btdm_ant_num == 1)3880ex_halbtc8812a1ant_connect_notify(pBtCoexist, assoType);3881}3882#endif38833884#ifdef CONFIG_RTL8822B3885else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {3886if (pBtCoexist->board_info.btdm_ant_num == 1)3887ex_halbtc8822b1ant_connect_notify(pBtCoexist, assoType);3888else if (pBtCoexist->board_info.btdm_ant_num == 2)3889ex_halbtc8822b2ant_connect_notify(pBtCoexist, assoType);3890}3891#endif38923893#ifdef CONFIG_RTL8821C3894else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {3895if (pBtCoexist->board_info.btdm_ant_num == 2)3896ex_halbtc8821c2ant_connect_notify(pBtCoexist, assoType);3897else if (pBtCoexist->board_info.btdm_ant_num == 1)3898ex_halbtc8821c1ant_connect_notify(pBtCoexist, assoType);3899}3900#endif39013902#ifdef CONFIG_RTL8814A3903else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {3904if (pBtCoexist->board_info.btdm_ant_num == 2)3905ex_halbtc8814a2ant_connect_notify(pBtCoexist, assoType);3906}3907#endif39083909#endif39103911/* halbtcoutsrc_NormalLowPower(pBtCoexist); */3912}39133914void EXhalbtcoutsrc_media_status_notify(PBTC_COEXIST pBtCoexist, RT_MEDIA_STATUS mediaStatus)3915{3916u8 mStatus = BTC_MEDIA_MAX;3917PADAPTER adapter = NULL;3918HAL_DATA_TYPE *hal = NULL;39193920if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))3921return;39223923if (pBtCoexist->manual_control)3924return;39253926pBtCoexist->statistics.cnt_media_status_notify++;3927adapter = (PADAPTER)pBtCoexist->Adapter;3928hal = GET_HAL_DATA(adapter);39293930if (RT_MEDIA_CONNECT == mediaStatus) {3931if (hal->current_band_type == BAND_ON_2_4G)3932mStatus = BTC_MEDIA_CONNECT;3933else if (hal->current_band_type == BAND_ON_5G)3934mStatus = BTC_MEDIA_CONNECT_5G;3935else {3936mStatus = BTC_MEDIA_CONNECT;3937RTW_ERR("%s unknow band type\n", __func__);3938}3939} else3940mStatus = BTC_MEDIA_DISCONNECT;39413942/* All notify is called in cmd thread, don't need to leave low power again3943* halbtcoutsrc_LeaveLowPower(pBtCoexist); */3944#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)3945rtw_btc_ex_media_status_notify(pBtCoexist, mStatus);3946#else39473948if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {3949#ifdef CONFIG_RTL8821A3950/* compatible for 8821A */3951if (mStatus == BTC_MEDIA_CONNECT_5G)3952mStatus = BTC_MEDIA_CONNECT;3953if (pBtCoexist->board_info.btdm_ant_num == 2)3954ex_halbtc8821a2ant_media_status_notify(pBtCoexist, mStatus);3955else if (pBtCoexist->board_info.btdm_ant_num == 1)3956ex_halbtc8821a1ant_media_status_notify(pBtCoexist, mStatus);3957#endif3958}39593960#ifdef CONFIG_RTL8723B3961else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {3962if (pBtCoexist->board_info.btdm_ant_num == 2)3963ex_halbtc8723b2ant_media_status_notify(pBtCoexist, mStatus);3964else if (pBtCoexist->board_info.btdm_ant_num == 1)3965ex_halbtc8723b1ant_media_status_notify(pBtCoexist, mStatus);3966}3967#endif39683969#ifdef CONFIG_RTL8703B3970else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {3971if (pBtCoexist->board_info.btdm_ant_num == 1)3972ex_halbtc8703b1ant_media_status_notify(pBtCoexist, mStatus);3973}3974#endif39753976#ifdef CONFIG_RTL8723D3977else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {3978if (pBtCoexist->board_info.btdm_ant_num == 2)3979ex_halbtc8723d2ant_media_status_notify(pBtCoexist, mStatus);3980else if (pBtCoexist->board_info.btdm_ant_num == 1)3981ex_halbtc8723d1ant_media_status_notify(pBtCoexist, mStatus);3982}3983#endif39843985#ifdef CONFIG_RTL8192E3986else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {3987if (pBtCoexist->board_info.btdm_ant_num == 2)3988ex_halbtc8192e2ant_media_status_notify(pBtCoexist, mStatus);3989else if (pBtCoexist->board_info.btdm_ant_num == 1)3990ex_halbtc8192e1ant_media_status_notify(pBtCoexist, mStatus);3991}3992#endif39933994#ifdef CONFIG_RTL8812A3995else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {3996/* compatible for 8812A */3997if (mStatus == BTC_MEDIA_CONNECT_5G)3998mStatus = BTC_MEDIA_CONNECT;3999if (pBtCoexist->board_info.btdm_ant_num == 2)4000ex_halbtc8812a2ant_media_status_notify(pBtCoexist, mStatus);4001else if (pBtCoexist->board_info.btdm_ant_num == 1)4002ex_halbtc8812a1ant_media_status_notify(pBtCoexist, mStatus);4003}4004#endif40054006#ifdef CONFIG_RTL8822B4007else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {4008if (pBtCoexist->board_info.btdm_ant_num == 1)4009ex_halbtc8822b1ant_media_status_notify(pBtCoexist, mStatus);4010else if (pBtCoexist->board_info.btdm_ant_num == 2)4011ex_halbtc8822b2ant_media_status_notify(pBtCoexist, mStatus);4012}4013#endif40144015#ifdef CONFIG_RTL8821C4016else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {4017if (pBtCoexist->board_info.btdm_ant_num == 2)4018ex_halbtc8821c2ant_media_status_notify(pBtCoexist, mStatus);4019else if (pBtCoexist->board_info.btdm_ant_num == 1)4020ex_halbtc8821c1ant_media_status_notify(pBtCoexist, mStatus);4021}4022#endif40234024#ifdef CONFIG_RTL8814A4025else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {4026if (pBtCoexist->board_info.btdm_ant_num == 2)4027ex_halbtc8814a2ant_media_status_notify(pBtCoexist, mStatus);4028}4029#endif40304031#endif40324033/* halbtcoutsrc_NormalLowPower(pBtCoexist); */4034}40354036void EXhalbtcoutsrc_specific_packet_notify(PBTC_COEXIST pBtCoexist, u8 pktType)4037{4038u8 packetType;4039PADAPTER adapter = NULL;4040HAL_DATA_TYPE *hal = NULL;40414042if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4043return;40444045if (pBtCoexist->manual_control)4046return;40474048pBtCoexist->statistics.cnt_specific_packet_notify++;4049adapter = (PADAPTER)pBtCoexist->Adapter;4050hal = GET_HAL_DATA(adapter);40514052if (PACKET_DHCP == pktType)4053packetType = BTC_PACKET_DHCP;4054else if (PACKET_EAPOL == pktType)4055packetType = BTC_PACKET_EAPOL;4056else if (PACKET_ARP == pktType)4057packetType = BTC_PACKET_ARP;4058else {4059packetType = BTC_PACKET_UNKNOWN;4060return;4061}40624063if (hal->current_band_type == BAND_ON_5G)4064packetType |= BTC_5G_BAND;40654066/* All notify is called in cmd thread, don't need to leave low power again4067* halbtcoutsrc_LeaveLowPower(pBtCoexist); */4068#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)4069rtw_btc_ex_specific_packet_notify(pBtCoexist, packetType);4070#else40714072if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {4073#ifdef CONFIG_RTL8821A4074/* compatible for 8821A */4075if (hal->current_band_type == BAND_ON_5G)4076packetType &= ~BTC_5G_BAND;40774078if (pBtCoexist->board_info.btdm_ant_num == 2)4079ex_halbtc8821a2ant_specific_packet_notify(pBtCoexist, packetType);4080else if (pBtCoexist->board_info.btdm_ant_num == 1)4081ex_halbtc8821a1ant_specific_packet_notify(pBtCoexist, packetType);4082#endif4083}40844085#ifdef CONFIG_RTL8723B4086else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {4087if (pBtCoexist->board_info.btdm_ant_num == 2)4088ex_halbtc8723b2ant_specific_packet_notify(pBtCoexist, packetType);4089else if (pBtCoexist->board_info.btdm_ant_num == 1)4090ex_halbtc8723b1ant_specific_packet_notify(pBtCoexist, packetType);4091}4092#endif40934094#ifdef CONFIG_RTL8703B4095else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {4096if (pBtCoexist->board_info.btdm_ant_num == 1)4097ex_halbtc8703b1ant_specific_packet_notify(pBtCoexist, packetType);4098}4099#endif41004101#ifdef CONFIG_RTL8723D4102else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {4103if (pBtCoexist->board_info.btdm_ant_num == 2)4104ex_halbtc8723d2ant_specific_packet_notify(pBtCoexist, packetType);4105else if (pBtCoexist->board_info.btdm_ant_num == 1)4106ex_halbtc8723d1ant_specific_packet_notify(pBtCoexist, packetType);4107}4108#endif41094110#ifdef CONFIG_RTL8192E4111else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {4112if (pBtCoexist->board_info.btdm_ant_num == 2)4113ex_halbtc8192e2ant_specific_packet_notify(pBtCoexist, packetType);4114else if (pBtCoexist->board_info.btdm_ant_num == 1)4115ex_halbtc8192e1ant_specific_packet_notify(pBtCoexist, packetType);4116}4117#endif41184119#ifdef CONFIG_RTL8812A4120else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {4121/* compatible for 8812A */4122if (hal->current_band_type == BAND_ON_5G)4123packetType &= ~BTC_5G_BAND;41244125if (pBtCoexist->board_info.btdm_ant_num == 2)4126ex_halbtc8812a2ant_specific_packet_notify(pBtCoexist, packetType);4127else if (pBtCoexist->board_info.btdm_ant_num == 1)4128ex_halbtc8812a1ant_specific_packet_notify(pBtCoexist, packetType);4129}4130#endif41314132#ifdef CONFIG_RTL8822B4133else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {4134if (pBtCoexist->board_info.btdm_ant_num == 1)4135ex_halbtc8822b1ant_specific_packet_notify(pBtCoexist, packetType);4136else if (pBtCoexist->board_info.btdm_ant_num == 2)4137ex_halbtc8822b2ant_specific_packet_notify(pBtCoexist, packetType);4138}4139#endif41404141#ifdef CONFIG_RTL8821C4142else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {4143if (pBtCoexist->board_info.btdm_ant_num == 2)4144ex_halbtc8821c2ant_specific_packet_notify(pBtCoexist, packetType);4145else if (pBtCoexist->board_info.btdm_ant_num == 1)4146ex_halbtc8821c1ant_specific_packet_notify(pBtCoexist, packetType);4147}4148#endif41494150#ifdef CONFIG_RTL8814A4151else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {4152if (pBtCoexist->board_info.btdm_ant_num == 2)4153ex_halbtc8814a2ant_specific_packet_notify(pBtCoexist, packetType);4154}4155#endif41564157#endif41584159/* halbtcoutsrc_NormalLowPower(pBtCoexist); */4160}41614162void EXhalbtcoutsrc_bt_info_notify(PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length)4163{4164if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4165return;41664167pBtCoexist->statistics.cnt_bt_info_notify++;41684169/* All notify is called in cmd thread, don't need to leave low power again4170* halbtcoutsrc_LeaveLowPower(pBtCoexist); */4171#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)4172rtw_btc_ex_bt_info_notify(pBtCoexist, tmpBuf, length);4173#else41744175if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {4176#ifdef CONFIG_RTL8821A4177if (pBtCoexist->board_info.btdm_ant_num == 2)4178ex_halbtc8821a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);4179else if (pBtCoexist->board_info.btdm_ant_num == 1)4180ex_halbtc8821a1ant_bt_info_notify(pBtCoexist, tmpBuf, length);4181#endif4182}41834184#ifdef CONFIG_RTL8723B4185else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {4186if (pBtCoexist->board_info.btdm_ant_num == 2)4187ex_halbtc8723b2ant_bt_info_notify(pBtCoexist, tmpBuf, length);4188else if (pBtCoexist->board_info.btdm_ant_num == 1)4189ex_halbtc8723b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);4190}4191#endif41924193#ifdef CONFIG_RTL8703B4194else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {4195if (pBtCoexist->board_info.btdm_ant_num == 1)4196ex_halbtc8703b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);4197}4198#endif41994200#ifdef CONFIG_RTL8723D4201else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {4202if (pBtCoexist->board_info.btdm_ant_num == 2)4203ex_halbtc8723d2ant_bt_info_notify(pBtCoexist, tmpBuf, length);4204else if (pBtCoexist->board_info.btdm_ant_num == 1)4205ex_halbtc8723d1ant_bt_info_notify(pBtCoexist, tmpBuf, length);4206}4207#endif42084209#ifdef CONFIG_RTL8192E4210else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {4211if (pBtCoexist->board_info.btdm_ant_num == 2)4212ex_halbtc8192e2ant_bt_info_notify(pBtCoexist, tmpBuf, length);4213else if (pBtCoexist->board_info.btdm_ant_num == 1)4214ex_halbtc8192e1ant_bt_info_notify(pBtCoexist, tmpBuf, length);4215}4216#endif42174218#ifdef CONFIG_RTL8812A4219else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {4220if (pBtCoexist->board_info.btdm_ant_num == 2)4221ex_halbtc8812a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);4222else if (pBtCoexist->board_info.btdm_ant_num == 1)4223ex_halbtc8812a1ant_bt_info_notify(pBtCoexist, tmpBuf, length);4224}4225#endif42264227#ifdef CONFIG_RTL8822B4228else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {4229if (pBtCoexist->board_info.btdm_ant_num == 1)4230ex_halbtc8822b1ant_bt_info_notify(pBtCoexist, tmpBuf, length);4231else if (pBtCoexist->board_info.btdm_ant_num == 2)4232ex_halbtc8822b2ant_bt_info_notify(pBtCoexist, tmpBuf, length);4233}4234#endif42354236#ifdef CONFIG_RTL8821C4237else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {4238if (pBtCoexist->board_info.btdm_ant_num == 2)4239ex_halbtc8821c2ant_bt_info_notify(pBtCoexist, tmpBuf, length);4240else if (pBtCoexist->board_info.btdm_ant_num == 1)4241ex_halbtc8821c1ant_bt_info_notify(pBtCoexist, tmpBuf, length);4242}4243#endif42444245#ifdef CONFIG_RTL8814A4246else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {4247if (pBtCoexist->board_info.btdm_ant_num == 2)4248ex_halbtc8814a2ant_bt_info_notify(pBtCoexist, tmpBuf, length);4249}4250#endif42514252#endif42534254/* halbtcoutsrc_NormalLowPower(pBtCoexist); */4255}42564257void EXhalbtcoutsrc_WlFwDbgInfoNotify(PBTC_COEXIST pBtCoexist, u8* tmpBuf, u8 length)4258{4259if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4260return;42614262#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)4263rtw_btc_ex_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);4264#else42654266if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {4267#ifdef CONFIG_RTL8703B4268if (pBtCoexist->board_info.btdm_ant_num == 1)4269ex_halbtc8703b1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);4270#endif4271}42724273#ifdef CONFIG_RTL8723D4274else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {4275if (pBtCoexist->board_info.btdm_ant_num == 1)4276ex_halbtc8723d1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);4277else if (pBtCoexist->board_info.btdm_ant_num == 2)4278ex_halbtc8723d2ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);4279}4280#endif42814282#ifdef CONFIG_RTL8821C4283else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {4284if (pBtCoexist->board_info.btdm_ant_num == 2)4285ex_halbtc8821c2ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);4286else if (pBtCoexist->board_info.btdm_ant_num == 1)4287ex_halbtc8821c1ant_wl_fwdbginfo_notify(pBtCoexist, tmpBuf, length);4288}4289#endif42904291#endif4292}42934294void EXhalbtcoutsrc_rx_rate_change_notify(PBTC_COEXIST pBtCoexist, u8 is_data_frame, u8 btc_rate_id)4295{4296if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4297return;42984299pBtCoexist->statistics.cnt_rate_id_notify++;43004301#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)4302rtw_btc_ex_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);4303#else43044305if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {4306#ifdef CONFIG_RTL8703B4307if (pBtCoexist->board_info.btdm_ant_num == 1)4308ex_halbtc8703b1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);4309#endif4310}43114312#ifdef CONFIG_RTL8723D4313else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {4314if (pBtCoexist->board_info.btdm_ant_num == 1)4315ex_halbtc8723d1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);4316else if (pBtCoexist->board_info.btdm_ant_num == 2)4317ex_halbtc8723d2ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);4318}4319#endif43204321#ifdef CONFIG_RTL8821C4322else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {4323if (pBtCoexist->board_info.btdm_ant_num == 1)4324ex_halbtc8821c1ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);4325else if (pBtCoexist->board_info.btdm_ant_num == 2)4326ex_halbtc8821c2ant_rx_rate_change_notify(pBtCoexist, is_data_frame, btc_rate_id);4327}4328#endif43294330#endif4331}43324333void4334EXhalbtcoutsrc_RfStatusNotify(4335PBTC_COEXIST pBtCoexist,4336u8 type4337)4338{4339if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4340return;4341pBtCoexist->statistics.cnt_rf_status_notify++;43424343#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)4344rtw_btc_ex_rf_status_notify(pBtCoexist, type);4345#else43464347if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {4348#ifdef CONFIG_RTL8723B4349if (pBtCoexist->board_info.btdm_ant_num == 1)4350ex_halbtc8723b1ant_rf_status_notify(pBtCoexist, type);4351#endif4352}43534354#ifdef CONFIG_RTL8703B4355else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {4356if (pBtCoexist->board_info.btdm_ant_num == 1)4357ex_halbtc8703b1ant_rf_status_notify(pBtCoexist, type);4358}4359#endif43604361#ifdef CONFIG_RTL8723D4362else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {4363if (pBtCoexist->board_info.btdm_ant_num == 1)4364ex_halbtc8723d1ant_rf_status_notify(pBtCoexist, type);4365}4366#endif43674368#ifdef CONFIG_RTL8822B4369else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {4370if (pBtCoexist->board_info.btdm_ant_num == 1)4371ex_halbtc8822b1ant_rf_status_notify(pBtCoexist, type);4372else if (pBtCoexist->board_info.btdm_ant_num == 2)4373ex_halbtc8822b2ant_rf_status_notify(pBtCoexist, type);4374}4375#endif43764377#ifdef CONFIG_RTL8821C4378else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {4379if (pBtCoexist->board_info.btdm_ant_num == 2)4380ex_halbtc8821c2ant_rf_status_notify(pBtCoexist, type);4381else if (pBtCoexist->board_info.btdm_ant_num == 1)4382ex_halbtc8821c1ant_rf_status_notify(pBtCoexist, type);4383}4384#endif43854386#ifdef CONFIG_RTL8814A4387else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {4388if (pBtCoexist->board_info.btdm_ant_num == 2)4389ex_halbtc8814a2ant_rf_status_notify(pBtCoexist, type);4390}4391#endif43924393#endif4394}43954396void EXhalbtcoutsrc_StackOperationNotify(PBTC_COEXIST pBtCoexist, u8 type)4397{4398#if 04399u8 stackOpType;44004401if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4402return;4403pBtCoexist->statistics.cntStackOperationNotify++;4404if (pBtCoexist->manual_control)4405return;44064407if ((HCI_BT_OP_INQUIRY_START == type) ||4408(HCI_BT_OP_PAGING_START == type) ||4409(HCI_BT_OP_PAIRING_START == type))4410stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_START;4411else if ((HCI_BT_OP_INQUIRY_FINISH == type) ||4412(HCI_BT_OP_PAGING_SUCCESS == type) ||4413(HCI_BT_OP_PAGING_UNSUCCESS == type) ||4414(HCI_BT_OP_PAIRING_FINISH == type))4415stackOpType = BTC_STACK_OP_INQ_PAGE_PAIR_FINISH;4416else4417stackOpType = BTC_STACK_OP_NONE;44184419#endif4420}44214422void EXhalbtcoutsrc_halt_notify(PBTC_COEXIST pBtCoexist)4423{4424if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4425return;44264427pBtCoexist->statistics.cnt_halt_notify++;44284429#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)4430rtw_btc_ex_halt_notify(pBtCoexist);4431#else44324433if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {4434#ifdef CONFIG_RTL8821A4435if (pBtCoexist->board_info.btdm_ant_num == 2)4436ex_halbtc8821a2ant_halt_notify(pBtCoexist);4437else if (pBtCoexist->board_info.btdm_ant_num == 1)4438ex_halbtc8821a1ant_halt_notify(pBtCoexist);4439#endif4440}44414442#ifdef CONFIG_RTL8723B4443else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {4444if (pBtCoexist->board_info.btdm_ant_num == 2)4445ex_halbtc8723b2ant_halt_notify(pBtCoexist);4446else if (pBtCoexist->board_info.btdm_ant_num == 1)4447ex_halbtc8723b1ant_halt_notify(pBtCoexist);4448}4449#endif44504451#ifdef CONFIG_RTL8703B4452else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {4453if (pBtCoexist->board_info.btdm_ant_num == 1)4454ex_halbtc8703b1ant_halt_notify(pBtCoexist);4455}4456#endif44574458#ifdef CONFIG_RTL8723D4459else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {4460if (pBtCoexist->board_info.btdm_ant_num == 2)4461ex_halbtc8723d2ant_halt_notify(pBtCoexist);4462else if (pBtCoexist->board_info.btdm_ant_num == 1)4463ex_halbtc8723d1ant_halt_notify(pBtCoexist);4464}4465#endif44664467#ifdef CONFIG_RTL8192E4468else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {4469if (pBtCoexist->board_info.btdm_ant_num == 2)4470ex_halbtc8192e2ant_halt_notify(pBtCoexist);4471else if (pBtCoexist->board_info.btdm_ant_num == 1)4472ex_halbtc8192e1ant_halt_notify(pBtCoexist);4473}4474#endif44754476#ifdef CONFIG_RTL8812A4477else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {4478if (pBtCoexist->board_info.btdm_ant_num == 2)4479ex_halbtc8812a2ant_halt_notify(pBtCoexist);4480else if (pBtCoexist->board_info.btdm_ant_num == 1)4481ex_halbtc8812a1ant_halt_notify(pBtCoexist);4482}4483#endif44844485#ifdef CONFIG_RTL8822B4486else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {4487if (pBtCoexist->board_info.btdm_ant_num == 1)4488ex_halbtc8822b1ant_halt_notify(pBtCoexist);4489else if (pBtCoexist->board_info.btdm_ant_num == 2)4490ex_halbtc8822b2ant_halt_notify(pBtCoexist);4491}4492#endif44934494#ifdef CONFIG_RTL8821C4495else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {4496if (pBtCoexist->board_info.btdm_ant_num == 2)4497ex_halbtc8821c2ant_halt_notify(pBtCoexist);4498else if (pBtCoexist->board_info.btdm_ant_num == 1)4499ex_halbtc8821c1ant_halt_notify(pBtCoexist);4500}4501#endif45024503#ifdef CONFIG_RTL8814A4504else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {4505if (pBtCoexist->board_info.btdm_ant_num == 2)4506ex_halbtc8814a2ant_halt_notify(pBtCoexist);4507}4508#endif45094510#endif4511}45124513void EXhalbtcoutsrc_SwitchBtTRxMask(PBTC_COEXIST pBtCoexist)4514{4515if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {4516if (pBtCoexist->board_info.btdm_ant_num == 2) {4517halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x01); /* BT goto standby while GNT_BT 1-->0 */4518} else if (pBtCoexist->board_info.btdm_ant_num == 1) {4519halbtcoutsrc_SetBtReg(pBtCoexist, 0, 0x3c, 0x15); /* BT goto standby while GNT_BT 1-->0 */4520}4521}4522}45234524void EXhalbtcoutsrc_pnp_notify(PBTC_COEXIST pBtCoexist, u8 pnpState)4525{4526if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4527return;45284529pBtCoexist->statistics.cnt_pnp_notify++;45304531/* */4532/* currently only 1ant we have to do the notification, */4533/* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */4534/* */4535#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)4536rtw_btc_ex_pnp_notify(pBtCoexist, pnpState);4537#else45384539if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {4540#ifdef CONFIG_RTL8723B4541if (pBtCoexist->board_info.btdm_ant_num == 1)4542ex_halbtc8723b1ant_pnp_notify(pBtCoexist, pnpState);4543else if (pBtCoexist->board_info.btdm_ant_num == 2)4544ex_halbtc8723b2ant_pnp_notify(pBtCoexist, pnpState);4545#endif4546}45474548#ifdef CONFIG_RTL8703B4549else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {4550if (pBtCoexist->board_info.btdm_ant_num == 1)4551ex_halbtc8703b1ant_pnp_notify(pBtCoexist, pnpState);4552}4553#endif45544555#ifdef CONFIG_RTL8723D4556else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {4557if (pBtCoexist->board_info.btdm_ant_num == 1)4558ex_halbtc8723d1ant_pnp_notify(pBtCoexist, pnpState);4559else if (pBtCoexist->board_info.btdm_ant_num == 2)4560ex_halbtc8723d2ant_pnp_notify(pBtCoexist, pnpState);4561}4562#endif45634564#ifdef CONFIG_RTL8821A4565else if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {4566if (pBtCoexist->board_info.btdm_ant_num == 1)4567ex_halbtc8821a1ant_pnp_notify(pBtCoexist, pnpState);4568else if (pBtCoexist->board_info.btdm_ant_num == 2)4569ex_halbtc8821a2ant_pnp_notify(pBtCoexist, pnpState);4570}4571#endif45724573#ifdef CONFIG_RTL8192E4574else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {4575if (pBtCoexist->board_info.btdm_ant_num == 1)4576ex_halbtc8192e1ant_pnp_notify(pBtCoexist, pnpState);4577}4578#endif45794580#ifdef CONFIG_RTL8812A4581else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {4582if (pBtCoexist->board_info.btdm_ant_num == 1)4583ex_halbtc8812a1ant_pnp_notify(pBtCoexist, pnpState);4584}4585#endif45864587#ifdef CONFIG_RTL8822B4588else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {4589if (pBtCoexist->board_info.btdm_ant_num == 1)4590ex_halbtc8822b1ant_pnp_notify(pBtCoexist, pnpState);4591else if (pBtCoexist->board_info.btdm_ant_num == 2)4592ex_halbtc8822b2ant_pnp_notify(pBtCoexist, pnpState);4593}4594#endif45954596#ifdef CONFIG_RTL8821C4597else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {4598if (pBtCoexist->board_info.btdm_ant_num == 2)4599ex_halbtc8821c2ant_pnp_notify(pBtCoexist, pnpState);4600else if (pBtCoexist->board_info.btdm_ant_num == 1)4601ex_halbtc8821c1ant_pnp_notify(pBtCoexist, pnpState);4602}4603#endif46044605#ifdef CONFIG_RTL8814A4606else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {4607if (pBtCoexist->board_info.btdm_ant_num == 2)4608ex_halbtc8814a2ant_pnp_notify(pBtCoexist, pnpState);4609}4610#endif46114612#endif4613}46144615void EXhalbtcoutsrc_CoexDmSwitch(PBTC_COEXIST pBtCoexist)4616{4617if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4618return;4619pBtCoexist->statistics.cnt_coex_dm_switch++;46204621halbtcoutsrc_LeaveLowPower(pBtCoexist);46224623if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {4624#ifdef CONFIG_RTL8723B4625if (pBtCoexist->board_info.btdm_ant_num == 1) {4626pBtCoexist->stop_coex_dm = TRUE;4627ex_halbtc8723b1ant_coex_dm_reset(pBtCoexist);4628EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);4629ex_halbtc8723b2ant_init_hw_config(pBtCoexist, FALSE);4630ex_halbtc8723b2ant_init_coex_dm(pBtCoexist);4631pBtCoexist->stop_coex_dm = FALSE;4632}4633#endif4634}46354636#ifdef CONFIG_RTL8723D4637else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {4638if (pBtCoexist->board_info.btdm_ant_num == 1) {4639pBtCoexist->stop_coex_dm = TRUE;4640ex_halbtc8723d1ant_coex_dm_reset(pBtCoexist);4641EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_DETECTED, 2);4642ex_halbtc8723d2ant_init_hw_config(pBtCoexist, FALSE);4643ex_halbtc8723d2ant_init_coex_dm(pBtCoexist);4644pBtCoexist->stop_coex_dm = FALSE;4645}4646}4647#endif46484649halbtcoutsrc_NormalLowPower(pBtCoexist);4650}46514652#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)4653void EXhalbtcoutsrc_TimerNotify(PBTC_COEXIST pBtCoexist, u32 timer_type)4654{4655rtw_btc_ex_timerup_notify(pBtCoexist, timer_type);4656}46574658void EXhalbtcoutsrc_WLStatusChangeNotify(PBTC_COEXIST pBtCoexist, u32 change_type)4659{4660rtw_btc_ex_wl_status_change_notify(pBtCoexist, change_type);4661}46624663u32 EXhalbtcoutsrc_CoexTimerCheck(PBTC_COEXIST pBtCoexist)4664{4665u32 i, timer_map = 0;46664667for (i = 0; i < BTC_TIMER_MAX; i++) {4668if (pBtCoexist->coex_sta.cnt_timer[i] > 0) {4669if (pBtCoexist->coex_sta.cnt_timer[i] == 1) {4670timer_map |= BIT(i);4671RTW_DBG("[BTC], %s(): timer_map = 0x%x\n", __func__, timer_map);4672}46734674pBtCoexist->coex_sta.cnt_timer[i]--;4675}4676}46774678return timer_map;4679}46804681u32 EXhalbtcoutsrc_WLStatusCheck(PBTC_COEXIST pBtCoexist)4682{4683struct btc_wifi_link_info link_info;4684const struct btc_chip_para *chip_para = pBtCoexist->chip_para;4685u32 change_map = 0;4686static bool wl_busy_pre;4687bool wl_busy = _FALSE;4688s32 wl_rssi;4689u32 traffic_dir;4690u8 i, tmp;4691static u8 rssi_step_pre = 5, wl_noisy_level_pre = 4;46924693/* WL busy to idle or idle to busy */4694pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &wl_busy);4695if (wl_busy != wl_busy_pre) {4696if (wl_busy)4697change_map |= BIT(BTC_WLSTATUS_CHANGE_TOBUSY);4698else4699change_map |= BIT(BTC_WLSTATUS_CHANGE_TOIDLE);47004701wl_busy_pre = wl_busy;4702}47034704/* WL RSSI */4705pBtCoexist->btc_get(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wl_rssi);4706tmp = (u8)(wl_rssi & 0xff);4707for (i = 0; i < 4; i++) {4708if (tmp >= chip_para->wl_rssi_step[i])4709break;4710}47114712if (rssi_step_pre != i) {4713rssi_step_pre = i;4714change_map |= BIT(BTC_WLSTATUS_CHANGE_RSSI);4715}47164717/* WL Link info */4718pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_LINK_INFO, &link_info);4719if (link_info.link_mode != pBtCoexist->wifi_link_info.link_mode ||4720link_info.sta_center_channel !=4721pBtCoexist->wifi_link_info.sta_center_channel ||4722link_info.p2p_center_channel !=4723pBtCoexist->wifi_link_info.p2p_center_channel ||4724link_info.bany_client_join_go !=4725pBtCoexist->wifi_link_info.bany_client_join_go) {4726change_map |= BIT(BTC_WLSTATUS_CHANGE_LINKINFO);4727pBtCoexist->wifi_link_info = link_info;4728}47294730/* WL Traffic Direction */4731pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIR, &traffic_dir);4732if (wl_busy && traffic_dir != pBtCoexist->wifi_link_info_ext.traffic_dir) {4733change_map |= BIT(BTC_WLSTATUS_CHANGE_DIR);4734pBtCoexist->wifi_link_info_ext.traffic_dir = traffic_dir;4735}47364737/* Noisy Detect */4738if (pBtCoexist->coex_sta.wl_noisy_level != wl_noisy_level_pre) {4739change_map |= BIT(BTC_WLSTATUS_CHANGE_NOISY);4740wl_noisy_level_pre = pBtCoexist->coex_sta.wl_noisy_level;4741}47424743RTW_DBG("[BTC], %s(): change_map = 0x%x\n", __func__, change_map);47444745return change_map;4746}47474748void EXhalbtcoutsrc_status_monitor(PBTC_COEXIST pBtCoexist)4749{4750u32 timer_up_type = 0, wl_status_change_type = 0;47514752timer_up_type = EXhalbtcoutsrc_CoexTimerCheck(pBtCoexist);4753if (timer_up_type != 0)4754EXhalbtcoutsrc_TimerNotify(pBtCoexist, timer_up_type);47554756wl_status_change_type = EXhalbtcoutsrc_WLStatusCheck(pBtCoexist);4757if (wl_status_change_type != 0)4758EXhalbtcoutsrc_WLStatusChangeNotify(pBtCoexist, wl_status_change_type);47594760rtw_btc_ex_periodical(pBtCoexist);4761}4762#endif47634764void EXhalbtcoutsrc_periodical(PBTC_COEXIST pBtCoexist)4765{4766if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4767return;4768pBtCoexist->statistics.cnt_periodical++;47694770/* Periodical should be called in cmd thread, */4771/* don't need to leave low power again4772* halbtcoutsrc_LeaveLowPower(pBtCoexist); */4773#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)4774EXhalbtcoutsrc_status_monitor(pBtCoexist);4775#else47764777if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {4778#ifdef CONFIG_RTL8821A4779if (pBtCoexist->board_info.btdm_ant_num == 2)4780ex_halbtc8821a2ant_periodical(pBtCoexist);4781else if (pBtCoexist->board_info.btdm_ant_num == 1) {4782if (!halbtcoutsrc_UnderIps(pBtCoexist))4783ex_halbtc8821a1ant_periodical(pBtCoexist);4784}4785#endif4786}47874788#ifdef CONFIG_RTL8723B4789else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {4790if (pBtCoexist->board_info.btdm_ant_num == 2)4791ex_halbtc8723b2ant_periodical(pBtCoexist);4792else if (pBtCoexist->board_info.btdm_ant_num == 1)4793ex_halbtc8723b1ant_periodical(pBtCoexist);4794}4795#endif47964797#ifdef CONFIG_RTL8723D4798else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {4799if (pBtCoexist->board_info.btdm_ant_num == 2)4800ex_halbtc8723d2ant_periodical(pBtCoexist);4801else if (pBtCoexist->board_info.btdm_ant_num == 1)4802ex_halbtc8723d1ant_periodical(pBtCoexist);4803}4804#endif48054806#ifdef CONFIG_RTL8703B4807else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {4808if (pBtCoexist->board_info.btdm_ant_num == 1)4809ex_halbtc8703b1ant_periodical(pBtCoexist);4810}4811#endif48124813#ifdef CONFIG_RTL8192E4814else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {4815if (pBtCoexist->board_info.btdm_ant_num == 2)4816ex_halbtc8192e2ant_periodical(pBtCoexist);4817else if (pBtCoexist->board_info.btdm_ant_num == 1)4818ex_halbtc8192e1ant_periodical(pBtCoexist);4819}4820#endif48214822#ifdef CONFIG_RTL8812A4823else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {4824if (pBtCoexist->board_info.btdm_ant_num == 2)4825ex_halbtc8812a2ant_periodical(pBtCoexist);4826else if (pBtCoexist->board_info.btdm_ant_num == 1)4827ex_halbtc8812a1ant_periodical(pBtCoexist);4828}4829#endif48304831#ifdef CONFIG_RTL8822B4832else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {4833if (pBtCoexist->board_info.btdm_ant_num == 1)4834ex_halbtc8822b1ant_periodical(pBtCoexist);4835else if (pBtCoexist->board_info.btdm_ant_num == 2)4836ex_halbtc8822b2ant_periodical(pBtCoexist);4837}4838#endif48394840#ifdef CONFIG_RTL8821C4841else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {4842if (pBtCoexist->board_info.btdm_ant_num == 2)4843ex_halbtc8821c2ant_periodical(pBtCoexist);4844else if (pBtCoexist->board_info.btdm_ant_num == 1)4845ex_halbtc8821c1ant_periodical(pBtCoexist);4846}4847#endif48484849#ifdef CONFIG_RTL8814A4850else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {4851if (pBtCoexist->board_info.btdm_ant_num == 2)4852ex_halbtc8814a2ant_periodical(pBtCoexist);4853}4854#endif48554856#endif48574858/* halbtcoutsrc_NormalLowPower(pBtCoexist); */4859}48604861void EXhalbtcoutsrc_dbg_control(PBTC_COEXIST pBtCoexist, u8 opCode, u8 opLen, u8 *pData)4862{4863if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4864return;48654866pBtCoexist->statistics.cnt_dbg_ctrl++;48674868/* This function doesn't be called yet, */4869/* default no need to leave low power to avoid deadlock4870* halbtcoutsrc_LeaveLowPower(pBtCoexist); */4871#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)4872/* rtw_btc_ex_dbg_control(pBtCoexist, opCode, opLen, pData); */4873#else48744875if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {4876#ifdef CONFIG_RTL8192E4877if (pBtCoexist->board_info.btdm_ant_num == 1)4878ex_halbtc8192e1ant_dbg_control(pBtCoexist, opCode, opLen, pData);4879#endif4880}48814882#ifdef CONFIG_RTL8812A4883else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {4884if (pBtCoexist->board_info.btdm_ant_num == 2)4885ex_halbtc8812a2ant_dbg_control(pBtCoexist, opCode, opLen, pData);4886else if (pBtCoexist->board_info.btdm_ant_num == 1)4887ex_halbtc8812a1ant_dbg_control(pBtCoexist, opCode, opLen, pData);4888}4889#endif48904891#ifdef CONFIG_RTL8822B4892else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter))4893if(pBtCoexist->board_info.btdm_ant_num == 1)4894ex_halbtc8822b1ant_dbg_control(pBtCoexist, opCode, opLen, pData);4895#endif48964897#endif48984899/* halbtcoutsrc_NormalLowPower(pBtCoexist); */4900}49014902#if 04903void4904EXhalbtcoutsrc_AntennaDetection(4905PBTC_COEXIST pBtCoexist,4906u32 centFreq,4907u32 offset,4908u32 span,4909u32 seconds4910)4911{4912if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4913return;49144915/* Need to refine the following power save operations to enable this function in the future */4916#if 04917IPSDisable(pBtCoexist->Adapter, FALSE, 0);4918LeisurePSLeave(pBtCoexist->Adapter, LPS_DISABLE_BT_COEX);4919#endif49204921if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {4922if (pBtCoexist->board_info.btdm_ant_num == 1)4923ex_halbtc8723b1ant_AntennaDetection(pBtCoexist, centFreq, offset, span, seconds);4924}49254926/* IPSReturn(pBtCoexist->Adapter, 0xff); */4927}4928#endif49294930void EXhalbtcoutsrc_StackUpdateProfileInfo(void)4931{4932#ifdef CONFIG_BT_COEXIST_SOCKET_TRX4933PBTC_COEXIST pBtCoexist = &GLBtCoexist;4934PADAPTER padapter = NULL;4935PBT_MGNT pBtMgnt = NULL;4936u8 i;49374938if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4939return;49404941padapter = (PADAPTER)pBtCoexist->Adapter;4942pBtMgnt = &padapter->coex_info.BtMgnt;49434944pBtCoexist->stack_info.profile_notified = _TRUE;49454946pBtCoexist->stack_info.num_of_link =4947pBtMgnt->ExtConfig.NumberOfACL + pBtMgnt->ExtConfig.NumberOfSCO;49484949/* reset first */4950pBtCoexist->stack_info.bt_link_exist = _FALSE;4951pBtCoexist->stack_info.sco_exist = _FALSE;4952pBtCoexist->stack_info.acl_exist = _FALSE;4953pBtCoexist->stack_info.a2dp_exist = _FALSE;4954pBtCoexist->stack_info.hid_exist = _FALSE;4955pBtCoexist->stack_info.num_of_hid = 0;4956pBtCoexist->stack_info.pan_exist = _FALSE;49574958if (!pBtMgnt->ExtConfig.NumberOfACL)4959pBtCoexist->stack_info.min_bt_rssi = 0;49604961if (pBtCoexist->stack_info.num_of_link) {4962pBtCoexist->stack_info.bt_link_exist = _TRUE;4963if (pBtMgnt->ExtConfig.NumberOfSCO)4964pBtCoexist->stack_info.sco_exist = _TRUE;4965if (pBtMgnt->ExtConfig.NumberOfACL)4966pBtCoexist->stack_info.acl_exist = _TRUE;4967}49684969for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {4970if (BT_PROFILE_A2DP == pBtMgnt->ExtConfig.aclLink[i].BTProfile)4971pBtCoexist->stack_info.a2dp_exist = _TRUE;4972else if (BT_PROFILE_PAN == pBtMgnt->ExtConfig.aclLink[i].BTProfile)4973pBtCoexist->stack_info.pan_exist = _TRUE;4974else if (BT_PROFILE_HID == pBtMgnt->ExtConfig.aclLink[i].BTProfile) {4975pBtCoexist->stack_info.hid_exist = _TRUE;4976pBtCoexist->stack_info.num_of_hid++;4977} else4978pBtCoexist->stack_info.unknown_acl_exist = _TRUE;4979}4980#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */4981}49824983void EXhalbtcoutsrc_UpdateMinBtRssi(s8 btRssi)4984{4985PBTC_COEXIST pBtCoexist = &GLBtCoexist;49864987if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4988return;49894990pBtCoexist->stack_info.min_bt_rssi = btRssi;4991}49924993void EXhalbtcoutsrc_SetHciVersion(u16 hciVersion)4994{4995PBTC_COEXIST pBtCoexist = &GLBtCoexist;49964997if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))4998return;49995000pBtCoexist->stack_info.hci_version = hciVersion;5001}50025003void EXhalbtcoutsrc_SetBtPatchVersion(u16 btHciVersion, u16 btPatchVersion)5004{5005PBTC_COEXIST pBtCoexist = &GLBtCoexist;50065007if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))5008return;50095010pBtCoexist->bt_info.bt_real_fw_ver = btPatchVersion;5011pBtCoexist->bt_info.bt_hci_ver = btHciVersion;5012}50135014#if 05015void EXhalbtcoutsrc_SetBtExist(u8 bBtExist)5016{5017GLBtCoexist.boardInfo.bBtExist = bBtExist;5018}5019#endif5020void EXhalbtcoutsrc_SetChipType(u8 chipType)5021{5022switch (chipType) {5023default:5024case BT_2WIRE:5025case BT_ISSC_3WIRE:5026case BT_ACCEL:5027case BT_RTL8756:5028GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;5029break;5030case BT_CSR_BC4:5031GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;5032break;5033case BT_CSR_BC8:5034GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;5035break;5036case BT_RTL8723A:5037GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;5038break;5039case BT_RTL8821:5040GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;5041break;5042case BT_RTL8723B:5043GLBtCoexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;5044break;5045}5046}50475048void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum)5049{5050if (BT_COEX_ANT_TYPE_PG == type) {5051GLBtCoexist.board_info.pg_ant_num = antNum;5052GLBtCoexist.board_info.btdm_ant_num = antNum;5053#if 05054/* The antenna position: Main (default) or Aux for pgAntNum=2 && btdmAntNum =1 */5055/* The antenna position should be determined by auto-detect mechanism */5056/* The following is assumed to main, and those must be modified if y auto-detect mechanism is ready */5057if ((GLBtCoexist.board_info.pg_ant_num == 2) && (GLBtCoexist.board_info.btdm_ant_num == 1))5058GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;5059else5060GLBtCoexist.board_info.btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT;5061#endif5062} else if (BT_COEX_ANT_TYPE_ANTDIV == type) {5063GLBtCoexist.board_info.btdm_ant_num = antNum;5064/* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */5065} else if (BT_COEX_ANT_TYPE_DETECTED == type) {5066GLBtCoexist.board_info.btdm_ant_num = antNum;5067/* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */5068}5069}50705071/*5072* Currently used by 8723b only, S0 or S15073* */5074void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath)5075{5076GLBtCoexist.board_info.single_ant_path = singleAntPath;5077}50785079void EXhalbtcoutsrc_DisplayBtCoexInfo(PBTC_COEXIST pBtCoexist)5080{5081HAL_DATA_TYPE *pHalData = NULL;50825083if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))5084return;50855086halbtcoutsrc_LeaveLowPower(pBtCoexist);50875088/* To prevent the racing with IPS enter */5089halbtcoutsrc_EnterPwrLock(pBtCoexist);50905091#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)5092pHalData = GET_HAL_DATA((PADAPTER)pBtCoexist->Adapter);50935094if (pHalData->EEPROMBluetoothCoexist == _TRUE)5095rtw_btc_ex_display_coex_info(pBtCoexist);5096#else50975098if (IS_HARDWARE_TYPE_8821(pBtCoexist->Adapter)) {5099#ifdef CONFIG_RTL8821A5100if (pBtCoexist->board_info.btdm_ant_num == 2)5101ex_halbtc8821a2ant_display_coex_info(pBtCoexist);5102else if (pBtCoexist->board_info.btdm_ant_num == 1)5103ex_halbtc8821a1ant_display_coex_info(pBtCoexist);5104#endif5105}51065107#ifdef CONFIG_RTL8723B5108else if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {5109if (pBtCoexist->board_info.btdm_ant_num == 2)5110ex_halbtc8723b2ant_display_coex_info(pBtCoexist);5111else if (pBtCoexist->board_info.btdm_ant_num == 1)5112ex_halbtc8723b1ant_display_coex_info(pBtCoexist);5113}5114#endif51155116#ifdef CONFIG_RTL8703B5117else if (IS_HARDWARE_TYPE_8703B(pBtCoexist->Adapter)) {5118if (pBtCoexist->board_info.btdm_ant_num == 1)5119ex_halbtc8703b1ant_display_coex_info(pBtCoexist);5120}5121#endif51225123#ifdef CONFIG_RTL8723D5124else if (IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)) {5125if (pBtCoexist->board_info.btdm_ant_num == 2)5126ex_halbtc8723d2ant_display_coex_info(pBtCoexist);5127else if (pBtCoexist->board_info.btdm_ant_num == 1)5128ex_halbtc8723d1ant_display_coex_info(pBtCoexist);5129}5130#endif51315132#ifdef CONFIG_RTL8192E5133else if (IS_HARDWARE_TYPE_8192E(pBtCoexist->Adapter)) {5134if (pBtCoexist->board_info.btdm_ant_num == 2)5135ex_halbtc8192e2ant_display_coex_info(pBtCoexist);5136else if (pBtCoexist->board_info.btdm_ant_num == 1)5137ex_halbtc8192e1ant_display_coex_info(pBtCoexist);5138}5139#endif51405141#ifdef CONFIG_RTL8812A5142else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {5143if (pBtCoexist->board_info.btdm_ant_num == 2)5144ex_halbtc8812a2ant_display_coex_info(pBtCoexist);5145else if (pBtCoexist->board_info.btdm_ant_num == 1)5146ex_halbtc8812a1ant_display_coex_info(pBtCoexist);5147}5148#endif51495150#ifdef CONFIG_RTL8822B5151else if (IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {5152if (pBtCoexist->board_info.btdm_ant_num == 1)5153ex_halbtc8822b1ant_display_coex_info(pBtCoexist);5154else if (pBtCoexist->board_info.btdm_ant_num == 2)5155ex_halbtc8822b2ant_display_coex_info(pBtCoexist);5156}5157#endif51585159#ifdef CONFIG_RTL8821C5160else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {5161if (pBtCoexist->board_info.btdm_ant_num == 2)5162ex_halbtc8821c2ant_display_coex_info(pBtCoexist);5163else if (pBtCoexist->board_info.btdm_ant_num == 1)5164ex_halbtc8821c1ant_display_coex_info(pBtCoexist);5165}5166#endif51675168#ifdef CONFIG_RTL8814A5169else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {5170if (pBtCoexist->board_info.btdm_ant_num == 2)5171ex_halbtc8814a2ant_display_coex_info(pBtCoexist);5172}5173#endif51745175#endif51765177halbtcoutsrc_ExitPwrLock(pBtCoexist);51785179halbtcoutsrc_NormalLowPower(pBtCoexist);5180}51815182void EXhalbtcoutsrc_DisplayAntDetection(PBTC_COEXIST pBtCoexist)5183{5184if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))5185return;51865187halbtcoutsrc_LeaveLowPower(pBtCoexist);51885189if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {5190#ifdef CONFIG_RTL8723B5191if (pBtCoexist->board_info.btdm_ant_num == 1)5192ex_halbtc8723b1ant_display_ant_detection(pBtCoexist);5193#endif5194}51955196halbtcoutsrc_NormalLowPower(pBtCoexist);5197}51985199void ex_halbtcoutsrc_pta_off_on_notify(PBTC_COEXIST pBtCoexist, u8 bBTON)5200{5201if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter)) {5202#ifdef CONFIG_RTL8812A5203if (pBtCoexist->board_info.btdm_ant_num == 2)5204ex_halbtc8812a2ant_pta_off_on_notify(pBtCoexist, (bBTON == _TRUE) ? BTC_BT_ON : BTC_BT_OFF);5205#endif5206}52075208#ifdef CONFIG_RTL8814A5209else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {5210if (pBtCoexist->board_info.btdm_ant_num == 2)5211ex_halbtc8814a2ant_pta_off_on_notify(pBtCoexist, (bBTON == _TRUE) ? BTC_BT_ON : BTC_BT_OFF);5212}5213#endif5214}52155216void EXhalbtcoutsrc_set_rfe_type(u8 type)5217{5218GLBtCoexist.board_info.rfe_type= type;5219}52205221#ifdef CONFIG_RF4CE_COEXIST5222void EXhalbtcoutsrc_set_rf4ce_link_state(u8 state)5223{5224GLBtCoexist.rf4ce_info.link_state = state;5225}52265227u8 EXhalbtcoutsrc_get_rf4ce_link_state(void)5228{5229return GLBtCoexist.rf4ce_info.link_state;5230}5231#endif52325233void EXhalbtcoutsrc_switchband_notify(struct btc_coexist *pBtCoexist, u8 type)5234{5235if(!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))5236return;52375238if(pBtCoexist->manual_control)5239return;52405241/* Driver should guarantee that the HW status isn't in low power mode */5242/* halbtcoutsrc_LeaveLowPower(pBtCoexist); */5243#if (CONFIG_BTCOEX_SUPPORT_BTC_CMN == 1)5244rtw_btc_ex_switchband_notify(pBtCoexist, type);5245#else52465247if(IS_HARDWARE_TYPE_8822B(pBtCoexist->Adapter)) {5248#ifdef CONFIG_RTL8822B5249if(pBtCoexist->board_info.btdm_ant_num == 1)5250ex_halbtc8822b1ant_switchband_notify(pBtCoexist, type);5251else if(pBtCoexist->board_info.btdm_ant_num == 2)5252ex_halbtc8822b2ant_switchband_notify(pBtCoexist, type);5253#endif5254}52555256#ifdef CONFIG_RTL8821C5257else if (IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {5258if (pBtCoexist->board_info.btdm_ant_num == 2)5259ex_halbtc8821c2ant_switchband_notify(pBtCoexist, type);5260else if (pBtCoexist->board_info.btdm_ant_num == 1)5261ex_halbtc8821c1ant_switchband_notify(pBtCoexist, type);5262}5263#endif52645265#ifdef CONFIG_RTL8814A5266else if (IS_HARDWARE_TYPE_8814A(pBtCoexist->Adapter)) {5267if (pBtCoexist->board_info.btdm_ant_num == 2)5268ex_halbtc8814a2ant_switchband_notify(pBtCoexist, type);5269}5270#endif52715272#endif52735274/* halbtcoutsrc_NormalLowPower(pBtCoexist); */5275}52765277u8 EXhalbtcoutsrc_rate_id_to_btc_rate_id(u8 rate_id)5278{5279u8 btc_rate_id = BTC_UNKNOWN;52805281switch (rate_id) {5282/* CCK rates */5283case DESC_RATE1M:5284btc_rate_id = BTC_CCK_1;5285break;5286case DESC_RATE2M:5287btc_rate_id = BTC_CCK_2;5288break;5289case DESC_RATE5_5M:5290btc_rate_id = BTC_CCK_5_5;5291break;5292case DESC_RATE11M:5293btc_rate_id = BTC_CCK_11;5294break;52955296/* OFDM rates */5297case DESC_RATE6M:5298btc_rate_id = BTC_OFDM_6;5299break;5300case DESC_RATE9M:5301btc_rate_id = BTC_OFDM_9;5302break;5303case DESC_RATE12M:5304btc_rate_id = BTC_OFDM_12;5305break;5306case DESC_RATE18M:5307btc_rate_id = BTC_OFDM_18;5308break;5309case DESC_RATE24M:5310btc_rate_id = BTC_OFDM_24;5311break;5312case DESC_RATE36M:5313btc_rate_id = BTC_OFDM_36;5314break;5315case DESC_RATE48M:5316btc_rate_id = BTC_OFDM_48;5317break;5318case DESC_RATE54M:5319btc_rate_id = BTC_OFDM_54;5320break;53215322/* MCS rates */5323case DESC_RATEMCS0:5324btc_rate_id = BTC_MCS_0;5325break;5326case DESC_RATEMCS1:5327btc_rate_id = BTC_MCS_1;5328break;5329case DESC_RATEMCS2:5330btc_rate_id = BTC_MCS_2;5331break;5332case DESC_RATEMCS3:5333btc_rate_id = BTC_MCS_3;5334break;5335case DESC_RATEMCS4:5336btc_rate_id = BTC_MCS_4;5337break;5338case DESC_RATEMCS5:5339btc_rate_id = BTC_MCS_5;5340break;5341case DESC_RATEMCS6:5342btc_rate_id = BTC_MCS_6;5343break;5344case DESC_RATEMCS7:5345btc_rate_id = BTC_MCS_7;5346break;5347case DESC_RATEMCS8:5348btc_rate_id = BTC_MCS_8;5349break;5350case DESC_RATEMCS9:5351btc_rate_id = BTC_MCS_9;5352break;5353case DESC_RATEMCS10:5354btc_rate_id = BTC_MCS_10;5355break;5356case DESC_RATEMCS11:5357btc_rate_id = BTC_MCS_11;5358break;5359case DESC_RATEMCS12:5360btc_rate_id = BTC_MCS_12;5361break;5362case DESC_RATEMCS13:5363btc_rate_id = BTC_MCS_13;5364break;5365case DESC_RATEMCS14:5366btc_rate_id = BTC_MCS_14;5367break;5368case DESC_RATEMCS15:5369btc_rate_id = BTC_MCS_15;5370break;5371case DESC_RATEMCS16:5372btc_rate_id = BTC_MCS_16;5373break;5374case DESC_RATEMCS17:5375btc_rate_id = BTC_MCS_17;5376break;5377case DESC_RATEMCS18:5378btc_rate_id = BTC_MCS_18;5379break;5380case DESC_RATEMCS19:5381btc_rate_id = BTC_MCS_19;5382break;5383case DESC_RATEMCS20:5384btc_rate_id = BTC_MCS_20;5385break;5386case DESC_RATEMCS21:5387btc_rate_id = BTC_MCS_21;5388break;5389case DESC_RATEMCS22:5390btc_rate_id = BTC_MCS_22;5391break;5392case DESC_RATEMCS23:5393btc_rate_id = BTC_MCS_23;5394break;5395case DESC_RATEMCS24:5396btc_rate_id = BTC_MCS_24;5397break;5398case DESC_RATEMCS25:5399btc_rate_id = BTC_MCS_25;5400break;5401case DESC_RATEMCS26:5402btc_rate_id = BTC_MCS_26;5403break;5404case DESC_RATEMCS27:5405btc_rate_id = BTC_MCS_27;5406break;5407case DESC_RATEMCS28:5408btc_rate_id = BTC_MCS_28;5409break;5410case DESC_RATEMCS29:5411btc_rate_id = BTC_MCS_29;5412break;5413case DESC_RATEMCS30:5414btc_rate_id = BTC_MCS_30;5415break;5416case DESC_RATEMCS31:5417btc_rate_id = BTC_MCS_31;5418break;54195420case DESC_RATEVHTSS1MCS0:5421btc_rate_id = BTC_VHT_1SS_MCS_0;5422break;5423case DESC_RATEVHTSS1MCS1:5424btc_rate_id = BTC_VHT_1SS_MCS_1;5425break;5426case DESC_RATEVHTSS1MCS2:5427btc_rate_id = BTC_VHT_1SS_MCS_2;5428break;5429case DESC_RATEVHTSS1MCS3:5430btc_rate_id = BTC_VHT_1SS_MCS_3;5431break;5432case DESC_RATEVHTSS1MCS4:5433btc_rate_id = BTC_VHT_1SS_MCS_4;5434break;5435case DESC_RATEVHTSS1MCS5:5436btc_rate_id = BTC_VHT_1SS_MCS_5;5437break;5438case DESC_RATEVHTSS1MCS6:5439btc_rate_id = BTC_VHT_1SS_MCS_6;5440break;5441case DESC_RATEVHTSS1MCS7:5442btc_rate_id = BTC_VHT_1SS_MCS_7;5443break;5444case DESC_RATEVHTSS1MCS8:5445btc_rate_id = BTC_VHT_1SS_MCS_8;5446break;5447case DESC_RATEVHTSS1MCS9:5448btc_rate_id = BTC_VHT_1SS_MCS_9;5449break;54505451case DESC_RATEVHTSS2MCS0:5452btc_rate_id = BTC_VHT_2SS_MCS_0;5453break;5454case DESC_RATEVHTSS2MCS1:5455btc_rate_id = BTC_VHT_2SS_MCS_1;5456break;5457case DESC_RATEVHTSS2MCS2:5458btc_rate_id = BTC_VHT_2SS_MCS_2;5459break;5460case DESC_RATEVHTSS2MCS3:5461btc_rate_id = BTC_VHT_2SS_MCS_3;5462break;5463case DESC_RATEVHTSS2MCS4:5464btc_rate_id = BTC_VHT_2SS_MCS_4;5465break;5466case DESC_RATEVHTSS2MCS5:5467btc_rate_id = BTC_VHT_2SS_MCS_5;5468break;5469case DESC_RATEVHTSS2MCS6:5470btc_rate_id = BTC_VHT_2SS_MCS_6;5471break;5472case DESC_RATEVHTSS2MCS7:5473btc_rate_id = BTC_VHT_2SS_MCS_7;5474break;5475case DESC_RATEVHTSS2MCS8:5476btc_rate_id = BTC_VHT_2SS_MCS_8;5477break;5478case DESC_RATEVHTSS2MCS9:5479btc_rate_id = BTC_VHT_2SS_MCS_9;5480break;54815482case DESC_RATEVHTSS3MCS0:5483btc_rate_id = BTC_VHT_3SS_MCS_0;5484break;5485case DESC_RATEVHTSS3MCS1:5486btc_rate_id = BTC_VHT_3SS_MCS_1;5487break;5488case DESC_RATEVHTSS3MCS2:5489btc_rate_id = BTC_VHT_3SS_MCS_2;5490break;5491case DESC_RATEVHTSS3MCS3:5492btc_rate_id = BTC_VHT_3SS_MCS_3;5493break;5494case DESC_RATEVHTSS3MCS4:5495btc_rate_id = BTC_VHT_3SS_MCS_4;5496break;5497case DESC_RATEVHTSS3MCS5:5498btc_rate_id = BTC_VHT_3SS_MCS_5;5499break;5500case DESC_RATEVHTSS3MCS6:5501btc_rate_id = BTC_VHT_3SS_MCS_6;5502break;5503case DESC_RATEVHTSS3MCS7:5504btc_rate_id = BTC_VHT_3SS_MCS_7;5505break;5506case DESC_RATEVHTSS3MCS8:5507btc_rate_id = BTC_VHT_3SS_MCS_8;5508break;5509case DESC_RATEVHTSS3MCS9:5510btc_rate_id = BTC_VHT_3SS_MCS_9;5511break;55125513case DESC_RATEVHTSS4MCS0:5514btc_rate_id = BTC_VHT_4SS_MCS_0;5515break;5516case DESC_RATEVHTSS4MCS1:5517btc_rate_id = BTC_VHT_4SS_MCS_1;5518break;5519case DESC_RATEVHTSS4MCS2:5520btc_rate_id = BTC_VHT_4SS_MCS_2;5521break;5522case DESC_RATEVHTSS4MCS3:5523btc_rate_id = BTC_VHT_4SS_MCS_3;5524break;5525case DESC_RATEVHTSS4MCS4:5526btc_rate_id = BTC_VHT_4SS_MCS_4;5527break;5528case DESC_RATEVHTSS4MCS5:5529btc_rate_id = BTC_VHT_4SS_MCS_5;5530break;5531case DESC_RATEVHTSS4MCS6:5532btc_rate_id = BTC_VHT_4SS_MCS_6;5533break;5534case DESC_RATEVHTSS4MCS7:5535btc_rate_id = BTC_VHT_4SS_MCS_7;5536break;5537case DESC_RATEVHTSS4MCS8:5538btc_rate_id = BTC_VHT_4SS_MCS_8;5539break;5540case DESC_RATEVHTSS4MCS9:5541btc_rate_id = BTC_VHT_4SS_MCS_9;5542break;5543}55445545return btc_rate_id;5546}55475548/*5549* Description:5550* Run BT-Coexist mechansim or not5551*5552*/5553void hal_btcoex_SetBTCoexist(PADAPTER padapter, u8 bBtExist)5554{5555PHAL_DATA_TYPE pHalData;555655575558pHalData = GET_HAL_DATA(padapter);5559pHalData->bt_coexist.bBtExist = bBtExist;5560}55615562/*5563* Dewcription:5564* Check is co-exist mechanism enabled or not5565*5566* Return:5567* _TRUE Enable BT co-exist mechanism5568* _FALSE Disable BT co-exist mechanism5569*/5570u8 hal_btcoex_IsBtExist(PADAPTER padapter)5571{5572PHAL_DATA_TYPE pHalData;557355745575pHalData = GET_HAL_DATA(padapter);5576return pHalData->bt_coexist.bBtExist;5577}55785579u8 hal_btcoex_IsBtDisabled(PADAPTER padapter)5580{5581if (!hal_btcoex_IsBtExist(padapter))5582return _TRUE;55835584if (GLBtCoexist.bt_info.bt_disabled)5585return _TRUE;5586else5587return _FALSE;5588}55895590void hal_btcoex_SetChipType(PADAPTER padapter, u8 chipType)5591{5592PHAL_DATA_TYPE pHalData;55935594pHalData = GET_HAL_DATA(padapter);5595pHalData->bt_coexist.btChipType = chipType;5596}55975598void hal_btcoex_SetPgAntNum(PADAPTER padapter, u8 antNum)5599{5600PHAL_DATA_TYPE pHalData;56015602pHalData = GET_HAL_DATA(padapter);56035604pHalData->bt_coexist.btTotalAntNum = antNum;5605}56065607u8 hal_btcoex_Initialize(PADAPTER padapter)5608{5609HAL_DATA_TYPE *pHalData = GET_HAL_DATA(padapter);5610u8 ret;56115612_rtw_memset(&GLBtCoexist, 0, sizeof(GLBtCoexist));56135614ret = EXhalbtcoutsrc_InitlizeVariables((void *)padapter);56155616return ret;5617}56185619void hal_btcoex_PowerOnSetting(PADAPTER padapter)5620{5621EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist);5622}56235624void hal_btcoex_AntInfoSetting(PADAPTER padapter)5625{5626hal_btcoex_SetBTCoexist(padapter, rtw_btcoex_get_bt_coexist(padapter));5627hal_btcoex_SetChipType(padapter, rtw_btcoex_get_chip_type(padapter));5628hal_btcoex_SetPgAntNum(padapter, rtw_btcoex_get_pg_ant_num(padapter));56295630EXhalbtcoutsrc_AntInfoSetting(padapter);5631}56325633void hal_btcoex_PowerOffSetting(PADAPTER padapter)5634{5635/* Clear the WiFi on/off bit in scoreboard reg. if necessary */5636if (IS_HARDWARE_TYPE_8703B(padapter) || IS_HARDWARE_TYPE_8723D(padapter)5637|| IS_HARDWARE_TYPE_8821C(padapter) || IS_HARDWARE_TYPE_8822B(padapter)5638|| IS_HARDWARE_TYPE_8822C(padapter))5639rtw_write16(padapter, 0xaa, 0x8000);5640}56415642void hal_btcoex_PreLoadFirmware(PADAPTER padapter)5643{5644EXhalbtcoutsrc_PreLoadFirmware(&GLBtCoexist);5645}56465647void hal_btcoex_InitHwConfig(PADAPTER padapter, u8 bWifiOnly)5648{5649if (!hal_btcoex_IsBtExist(padapter))5650return;56515652EXhalbtcoutsrc_init_hw_config(&GLBtCoexist, bWifiOnly);5653EXhalbtcoutsrc_init_coex_dm(&GLBtCoexist);5654}56555656void hal_btcoex_IpsNotify(PADAPTER padapter, u8 type)5657{5658EXhalbtcoutsrc_ips_notify(&GLBtCoexist, type);5659}56605661void hal_btcoex_LpsNotify(PADAPTER padapter, u8 type)5662{5663EXhalbtcoutsrc_lps_notify(&GLBtCoexist, type);5664}56655666void hal_btcoex_ScanNotify(PADAPTER padapter, u8 type)5667{5668EXhalbtcoutsrc_scan_notify(&GLBtCoexist, type);5669}56705671void hal_btcoex_ConnectNotify(PADAPTER padapter, u8 action)5672{5673u8 assoType = 0;5674u8 is_5g_band = _FALSE;56755676is_5g_band = (padapter->mlmeextpriv.cur_channel > 14) ? _TRUE : _FALSE;56775678if (action == _TRUE) {5679if (is_5g_band == _TRUE)5680assoType = BTC_ASSOCIATE_5G_START;5681else5682assoType = BTC_ASSOCIATE_START;5683}5684else {5685if (is_5g_band == _TRUE)5686assoType = BTC_ASSOCIATE_5G_FINISH;5687else5688assoType = BTC_ASSOCIATE_FINISH;5689}56905691EXhalbtcoutsrc_connect_notify(&GLBtCoexist, assoType);5692}56935694void hal_btcoex_MediaStatusNotify(PADAPTER padapter, u8 mediaStatus)5695{5696EXhalbtcoutsrc_media_status_notify(&GLBtCoexist, mediaStatus);5697}56985699void hal_btcoex_SpecialPacketNotify(PADAPTER padapter, u8 pktType)5700{5701EXhalbtcoutsrc_specific_packet_notify(&GLBtCoexist, pktType);5702}57035704void hal_btcoex_IQKNotify(PADAPTER padapter, u8 state)5705{5706GLBtcWiFiInIQKState = state;5707}57085709void hal_btcoex_BtInfoNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)5710{5711if (GLBtcWiFiInIQKState == _TRUE)5712return;57135714EXhalbtcoutsrc_bt_info_notify(&GLBtCoexist, tmpBuf, length);5715}57165717void hal_btcoex_BtMpRptNotify(PADAPTER padapter, u8 length, u8 *tmpBuf)5718{5719u8 extid, status, len, seq;572057215722if (GLBtcBtMpRptWait == _FALSE)5723return;57245725if ((length < 3) || (!tmpBuf))5726return;57275728extid = tmpBuf[0];5729/* not response from BT FW then exit*/5730switch (extid) {5731case C2H_WIFI_FW_ACTIVE_RSP:5732GLBtcBtMpRptWiFiOK = _TRUE;5733break;57345735case C2H_TRIG_BY_BT_FW:5736GLBtcBtMpRptBTOK = _TRUE;57375738status = tmpBuf[1] & 0xF;5739len = length - 3;5740seq = tmpBuf[2] >> 4;57415742GLBtcBtMpRptSeq = seq;5743GLBtcBtMpRptStatus = status;5744_rtw_memcpy(GLBtcBtMpRptRsp, tmpBuf + 3, len);5745GLBtcBtMpRptRspSize = len;57465747break;57485749default:5750return;5751}57525753if ((GLBtcBtMpRptWiFiOK == _TRUE) && (GLBtcBtMpRptBTOK == _TRUE)) {5754GLBtcBtMpRptWait = _FALSE;5755_cancel_timer_ex(&GLBtcBtMpOperTimer);5756_rtw_up_sema(&GLBtcBtMpRptSema);5757}5758}57595760void hal_btcoex_SuspendNotify(PADAPTER padapter, u8 state)5761{5762switch (state) {5763case BTCOEX_SUSPEND_STATE_SUSPEND:5764EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);5765break;5766case BTCOEX_SUSPEND_STATE_SUSPEND_KEEP_ANT:5767/* should switch to "#if 1" once all ICs' coex. revision are upgraded to support the KEEP_ANT case */5768#if 05769EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);5770#else5771EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP);5772EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_SLEEP_KEEP_ANT);5773#endif5774break;5775case BTCOEX_SUSPEND_STATE_RESUME:5776#ifdef CONFIG_FW_MULTI_PORT_SUPPORT5777/* re-download FW after resume, inform WL FW port number */5778rtw_hal_set_wifi_btc_port_id_cmd(GLBtCoexist.Adapter);5779#endif5780EXhalbtcoutsrc_pnp_notify(&GLBtCoexist, BTC_WIFI_PNP_WAKE_UP);5781break;5782}5783}57845785void hal_btcoex_HaltNotify(PADAPTER padapter, u8 do_halt)5786{5787if (do_halt == 1)5788EXhalbtcoutsrc_halt_notify(&GLBtCoexist);57895790GLBtCoexist.bBinded = _FALSE;5791GLBtCoexist.Adapter = NULL;5792}57935794void hal_btcoex_SwitchBtTRxMask(PADAPTER padapter)5795{5796EXhalbtcoutsrc_SwitchBtTRxMask(&GLBtCoexist);5797}57985799void hal_btcoex_Hanlder(PADAPTER padapter)5800{5801u32 bt_patch_ver;58025803EXhalbtcoutsrc_periodical(&GLBtCoexist);58045805if (GLBtCoexist.bt_info.bt_get_fw_ver == 0) {5806GLBtCoexist.btc_get(&GLBtCoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver);5807GLBtCoexist.bt_info.bt_get_fw_ver = bt_patch_ver;5808}5809}58105811s32 hal_btcoex_IsBTCoexRejectAMPDU(PADAPTER padapter)5812{5813return (s32)GLBtCoexist.bt_info.reject_agg_pkt;5814}58155816s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(PADAPTER padapter)5817{5818return (s32)GLBtCoexist.bt_info.bt_ctrl_agg_buf_size;5819}58205821u32 hal_btcoex_GetAMPDUSize(PADAPTER padapter)5822{5823return (u32)GLBtCoexist.bt_info.agg_buf_size;5824}58255826void hal_btcoex_SetManualControl(PADAPTER padapter, u8 bmanual)5827{5828GLBtCoexist.manual_control = bmanual;5829}58305831u8 hal_btcoex_1Ant(PADAPTER padapter)5832{5833if (hal_btcoex_IsBtExist(padapter) == _FALSE)5834return _FALSE;58355836if (GLBtCoexist.board_info.btdm_ant_num == 1)5837return _TRUE;58385839return _FALSE;5840}58415842u8 hal_btcoex_IsBtControlLps(PADAPTER padapter)5843{5844if (GLBtCoexist.bdontenterLPS == _TRUE)5845return _TRUE;58465847if (hal_btcoex_IsBtExist(padapter) == _FALSE)5848return _FALSE;58495850if (GLBtCoexist.bt_info.bt_disabled)5851return _FALSE;58525853if (GLBtCoexist.bt_info.bt_ctrl_lps)5854return _TRUE;58555856return _FALSE;5857}58585859u8 hal_btcoex_IsLpsOn(PADAPTER padapter)5860{5861if (GLBtCoexist.bdontenterLPS == _TRUE)5862return _FALSE;58635864if (hal_btcoex_IsBtExist(padapter) == _FALSE)5865return _FALSE;58665867if (GLBtCoexist.bt_info.bt_disabled)5868return _FALSE;58695870if (GLBtCoexist.bt_info.bt_lps_on)5871return _TRUE;58725873return _FALSE;5874}58755876u8 hal_btcoex_RpwmVal(PADAPTER padapter)5877{5878return GLBtCoexist.bt_info.rpwm_val;5879}58805881u8 hal_btcoex_LpsVal(PADAPTER padapter)5882{5883return GLBtCoexist.bt_info.lps_val;5884}58855886u32 hal_btcoex_GetRaMask(PADAPTER padapter)5887{5888if (!hal_btcoex_IsBtExist(padapter))5889return 0;58905891if (GLBtCoexist.bt_info.bt_disabled)5892return 0;58935894/* Modify by YiWei , suggest by Cosa and Jenyu5895* Remove the limit antenna number , because 2 antenna case (ex: 8192eu)also want to get BT coex report rate mask.5896*/5897/*if (GLBtCoexist.board_info.btdm_ant_num != 1)5898return 0;*/58995900return GLBtCoexist.bt_info.ra_mask;5901}59025903u8 hal_btcoex_query_reduced_wl_pwr_lvl(PADAPTER padapter)5904{5905return GLBtCoexist.coex_dm.cur_wl_pwr_lvl;5906}59075908void hal_btcoex_set_reduced_wl_pwr_lvl(PADAPTER padapter, u8 val)5909{5910GLBtCoexist.coex_dm.cur_wl_pwr_lvl = val;5911}59125913void hal_btcoex_do_reduce_wl_pwr_lvl(PADAPTER padapter)5914{5915halbtcoutsrc_reduce_wl_tx_power(&GLBtCoexist, 0);5916}59175918void hal_btcoex_RecordPwrMode(PADAPTER padapter, u8 *pCmdBuf, u8 cmdLen)5919{59205921_rtw_memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen);5922}59235924void hal_btcoex_DisplayBtCoexInfo(PADAPTER padapter, u8 *pbuf, u32 bufsize)5925{5926PBTCDBGINFO pinfo;592759285929pinfo = &GLBtcDbgInfo;5930DBG_BT_INFO_INIT(pinfo, pbuf, bufsize);5931EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist);5932DBG_BT_INFO_INIT(pinfo, NULL, 0);5933}59345935void hal_btcoex_SetDBG(PADAPTER padapter, u32 *pDbgModule)5936{5937u32 i;593859395940if (NULL == pDbgModule)5941return;59425943for (i = 0; i < COMP_MAX; i++)5944GLBtcDbgType[i] = pDbgModule[i];5945}59465947u32 hal_btcoex_GetDBG(PADAPTER padapter, u8 *pStrBuf, u32 bufSize)5948{5949s32 count;5950u8 *pstr;5951u32 leftSize;595259535954if ((NULL == pStrBuf) || (0 == bufSize))5955return 0;59565957count = 0;5958pstr = pStrBuf;5959leftSize = bufSize;5960/* RTW_INFO(FUNC_ADPT_FMT ": bufsize=%d\n", FUNC_ADPT_ARG(padapter), bufSize); */59615962count = rtw_sprintf(pstr, leftSize, "#define DBG\t%d\n", DBG);5963if ((count < 0) || (count >= leftSize))5964goto exit;5965pstr += count;5966leftSize -= count;59675968count = rtw_sprintf(pstr, leftSize, "BTCOEX Debug Setting:\n");5969if ((count < 0) || (count >= leftSize))5970goto exit;5971pstr += count;5972leftSize -= count;59735974count = rtw_sprintf(pstr, leftSize,5975"COMP_COEX: 0x%08X\n\n",5976GLBtcDbgType[COMP_COEX]);5977if ((count < 0) || (count >= leftSize))5978goto exit;5979pstr += count;5980leftSize -= count;59815982#if 05983count = rtw_sprintf(pstr, leftSize, "INTERFACE Debug Setting Definition:\n");5984if ((count < 0) || (count >= leftSize))5985goto exit;5986pstr += count;5987leftSize -= count;5988count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for INTF_INIT\n",5989GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_INIT ? 1 : 0);5990if ((count < 0) || (count >= leftSize))5991goto exit;5992pstr += count;5993leftSize -= count;5994count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for INTF_NOTIFY\n\n",5995GLBtcDbgType[BTC_MSG_INTERFACE] & INTF_NOTIFY ? 1 : 0);5996if ((count < 0) || (count >= leftSize))5997goto exit;5998pstr += count;5999leftSize -= count;60006001count = rtw_sprintf(pstr, leftSize, "ALGORITHM Debug Setting Definition:\n");6002if ((count < 0) || (count >= leftSize))6003goto exit;6004pstr += count;6005leftSize -= count;6006count = rtw_sprintf(pstr, leftSize, "\tbit[0]=%d for BT_RSSI_STATE\n",6007GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_RSSI_STATE ? 1 : 0);6008if ((count < 0) || (count >= leftSize))6009goto exit;6010pstr += count;6011leftSize -= count;6012count = rtw_sprintf(pstr, leftSize, "\tbit[1]=%d for WIFI_RSSI_STATE\n",6013GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_WIFI_RSSI_STATE ? 1 : 0);6014if ((count < 0) || (count >= leftSize))6015goto exit;6016pstr += count;6017leftSize -= count;6018count = rtw_sprintf(pstr, leftSize, "\tbit[2]=%d for BT_MONITOR\n",6019GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_BT_MONITOR ? 1 : 0);6020if ((count < 0) || (count >= leftSize))6021goto exit;6022pstr += count;6023leftSize -= count;6024count = rtw_sprintf(pstr, leftSize, "\tbit[3]=%d for TRACE\n",6025GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE ? 1 : 0);6026if ((count < 0) || (count >= leftSize))6027goto exit;6028pstr += count;6029leftSize -= count;6030count = rtw_sprintf(pstr, leftSize, "\tbit[4]=%d for TRACE_FW\n",6031GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW ? 1 : 0);6032if ((count < 0) || (count >= leftSize))6033goto exit;6034pstr += count;6035leftSize -= count;6036count = rtw_sprintf(pstr, leftSize, "\tbit[5]=%d for TRACE_FW_DETAIL\n",6037GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_DETAIL ? 1 : 0);6038if ((count < 0) || (count >= leftSize))6039goto exit;6040pstr += count;6041leftSize -= count;6042count = rtw_sprintf(pstr, leftSize, "\tbit[6]=%d for TRACE_FW_EXEC\n",6043GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_FW_EXEC ? 1 : 0);6044if ((count < 0) || (count >= leftSize))6045goto exit;6046pstr += count;6047leftSize -= count;6048count = rtw_sprintf(pstr, leftSize, "\tbit[7]=%d for TRACE_SW\n",6049GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW ? 1 : 0);6050if ((count < 0) || (count >= leftSize))6051goto exit;6052pstr += count;6053leftSize -= count;6054count = rtw_sprintf(pstr, leftSize, "\tbit[8]=%d for TRACE_SW_DETAIL\n",6055GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_DETAIL ? 1 : 0);6056if ((count < 0) || (count >= leftSize))6057goto exit;6058pstr += count;6059leftSize -= count;6060count = rtw_sprintf(pstr, leftSize, "\tbit[9]=%d for TRACE_SW_EXEC\n",6061GLBtcDbgType[BTC_MSG_ALGORITHM] & ALGO_TRACE_SW_EXEC ? 1 : 0);6062if ((count < 0) || (count >= leftSize))6063goto exit;6064pstr += count;6065leftSize -= count;6066#endif60676068exit:6069count = pstr - pStrBuf;6070/* RTW_INFO(FUNC_ADPT_FMT ": usedsize=%d\n", FUNC_ADPT_ARG(padapter), count); */60716072return count;6073}60746075u8 hal_btcoex_IncreaseScanDeviceNum(PADAPTER padapter)6076{6077if (!hal_btcoex_IsBtExist(padapter))6078return _FALSE;60796080if (GLBtCoexist.bt_info.increase_scan_dev_num)6081return _TRUE;60826083return _FALSE;6084}60856086u8 hal_btcoex_IsBtLinkExist(PADAPTER padapter)6087{6088if (GLBtCoexist.bt_link_info.bt_link_exist)6089return _TRUE;60906091return _FALSE;6092}60936094void hal_btcoex_SetBtPatchVersion(PADAPTER padapter, u16 btHciVer, u16 btPatchVer)6095{6096EXhalbtcoutsrc_SetBtPatchVersion(btHciVer, btPatchVer);6097}60986099void hal_btcoex_SetHciVersion(PADAPTER padapter, u16 hciVersion)6100{6101EXhalbtcoutsrc_SetHciVersion(hciVersion);6102}61036104void hal_btcoex_StackUpdateProfileInfo(void)6105{6106EXhalbtcoutsrc_StackUpdateProfileInfo();6107}61086109void hal_btcoex_pta_off_on_notify(PADAPTER padapter, u8 bBTON)6110{6111ex_halbtcoutsrc_pta_off_on_notify(&GLBtCoexist, bBTON);6112}61136114/*6115* Description:6116* Setting BT coex antenna isolation type .6117* coex mechanisn/ spital stream/ best throughput6118* anttype = 0 , PSTDMA / 2SS / 0.5T , bad isolation , WiFi/BT ANT Distance<15cm , (<20dB) for 2,3 antenna6119* anttype = 1 , PSTDMA / 1SS / 0.5T , normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 2 antenna6120* anttype = 2 , TDMA / 2SS / T , normal isolaiton , 50cm>WiFi/BT ANT Distance>15cm , (>20dB) for 3 antenna6121* anttype = 3 , no TDMA / 1SS / 0.5T , good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 2 antenna6122* anttype = 4 , no TDMA / 2SS / T , good isolation , WiFi/BT ANT Distance >50cm , (>40dB) for 3 antenna6123* wifi only throughput ~ T6124* wifi/BT share one antenna with SPDT6125*/6126void hal_btcoex_SetAntIsolationType(PADAPTER padapter, u8 anttype)6127{6128PHAL_DATA_TYPE pHalData;6129PBTC_COEXIST pBtCoexist = &GLBtCoexist;61306131/*RTW_INFO("####%s , anttype = %d , %d\n" , __func__ , anttype , __LINE__); */6132pHalData = GET_HAL_DATA(padapter);613361346135pHalData->bt_coexist.btAntisolation = anttype;61366137switch (pHalData->bt_coexist.btAntisolation) {6138case 0:6139pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_0;6140break;6141case 1:6142pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_1;6143break;6144case 2:6145pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_2;6146break;6147case 3:6148pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_3;6149break;6150case 4:6151pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_4;6152break;6153}61546155}61566157#ifdef CONFIG_LOAD_PHY_PARA_FROM_FILE6158int6159hal_btcoex_ParseAntIsolationConfigFile(6160PADAPTER Adapter,6161char *buffer6162)6163{6164HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);6165u32 i = 0 , j = 0;6166char *szLine , *ptmp;6167int rtStatus = _SUCCESS;6168char param_value_string[10];6169u8 param_value;6170u8 anttype = 4;61716172u8 ant_num = 3 , ant_distance = 50 , rfe_type = 1;61736174typedef struct ant_isolation {6175char *param_name; /* antenna isolation config parameter name */6176u8 *value; /* antenna isolation config parameter value */6177} ANT_ISOLATION;61786179ANT_ISOLATION ant_isolation_param[] = {6180{"ANT_NUMBER" , &ant_num},6181{"ANT_DISTANCE" , &ant_distance},6182{"RFE_TYPE" , &rfe_type},6183{NULL , 0}6184};6185618661876188/* RTW_INFO("===>Hal_ParseAntIsolationConfigFile()\n" ); */61896190ptmp = buffer;6191for (szLine = GetLineFromBuffer(ptmp) ; szLine != NULL; szLine = GetLineFromBuffer(ptmp)) {6192/* skip comment */6193if (IsCommentString(szLine))6194continue;61956196/* RTW_INFO("%s : szLine = %s , strlen(szLine) = %d\n" , __func__ , szLine , strlen(szLine));*/6197for (j = 0 ; ant_isolation_param[j].param_name != NULL ; j++) {6198if (strstr(szLine , ant_isolation_param[j].param_name) != NULL) {6199i = 0;6200while (i < strlen(szLine)) {6201if (szLine[i] != '"')6202++i;6203else {6204/* skip only has one " */6205if (strpbrk(szLine , "\"") == strrchr(szLine , '"')) {6206RTW_INFO("Fail to parse parameters , format error!\n");6207break;6208}6209_rtw_memset((void *)param_value_string , 0 , 10);6210if (!ParseQualifiedString(szLine , &i , param_value_string , '"' , '"')) {6211RTW_INFO("Fail to parse parameters\n");6212return _FAIL;6213} else if (!GetU1ByteIntegerFromStringInDecimal(param_value_string , ant_isolation_param[j].value))6214RTW_INFO("Fail to GetU1ByteIntegerFromStringInDecimal\n");62156216break;6217}6218}6219}6220}6221}62226223/* YiWei 20140716 , for BT coex antenna isolation control */6224/* rfe_type = 0 was SPDT , rfe_type = 1 was coupler */6225if (ant_num == 3 && ant_distance >= 50)6226anttype = 3;6227else if (ant_num == 2 && ant_distance >= 50 && rfe_type == 1)6228anttype = 2;6229else if (ant_num == 3 && ant_distance >= 15 && ant_distance < 50)6230anttype = 2;6231else if (ant_num == 2 && ant_distance >= 15 && ant_distance < 50 && rfe_type == 1)6232anttype = 2;6233else if ((ant_num == 2 && ant_distance < 15 && rfe_type == 1) || (ant_num == 3 && ant_distance < 15))6234anttype = 1;6235else if (ant_num == 2 && rfe_type == 0)6236anttype = 0;6237else6238anttype = 0;62396240hal_btcoex_SetAntIsolationType(Adapter, anttype);62416242RTW_INFO("%s : ant_num = %d\n" , __func__ , ant_num);6243RTW_INFO("%s : ant_distance = %d\n" , __func__ , ant_distance);6244RTW_INFO("%s : rfe_type = %d\n" , __func__ , rfe_type);6245/* RTW_INFO("<===Hal_ParseAntIsolationConfigFile()\n"); */6246return rtStatus;6247}624862496250int6251hal_btcoex_AntIsolationConfig_ParaFile(6252PADAPTER Adapter,6253char *pFileName6254)6255{6256HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);6257int rlen = 0 , rtStatus = _FAIL;62586259_rtw_memset(pHalData->para_file_buf , 0 , MAX_PARA_FILE_BUF_LEN);62606261rtw_get_phy_file_path(Adapter, pFileName);6262if (rtw_is_file_readable(rtw_phy_para_file_path) == _TRUE) {6263rlen = rtw_retrieve_from_file(rtw_phy_para_file_path, pHalData->para_file_buf, MAX_PARA_FILE_BUF_LEN);6264if (rlen > 0)6265rtStatus = _SUCCESS;6266}626762686269if (rtStatus == _SUCCESS) {6270/*RTW_INFO("%s(): read %s ok\n", __func__ , pFileName);*/6271rtStatus = hal_btcoex_ParseAntIsolationConfigFile(Adapter , pHalData->para_file_buf);6272} else6273RTW_INFO("%s(): No File %s, Load from *** Array!\n" , __func__ , pFileName);62746275return rtStatus;6276}6277#endif /* CONFIG_LOAD_PHY_PARA_FROM_FILE */62786279u16 hal_btcoex_btreg_read(PADAPTER padapter, u8 type, u16 addr, u32 *data)6280{6281u16 ret = 0;62826283halbtcoutsrc_LeaveLowPower(&GLBtCoexist);62846285ret = halbtcoutsrc_GetBtReg_with_status(&GLBtCoexist, type, addr, data);62866287halbtcoutsrc_NormalLowPower(&GLBtCoexist);62886289return ret;6290}62916292u16 hal_btcoex_btreg_write(PADAPTER padapter, u8 type, u16 addr, u16 val)6293{6294u16 ret = 0;62956296halbtcoutsrc_LeaveLowPower(&GLBtCoexist);62976298ret = halbtcoutsrc_SetBtReg(&GLBtCoexist, type, addr, val);62996300halbtcoutsrc_NormalLowPower(&GLBtCoexist);63016302return ret;6303}63046305void hal_btcoex_set_rfe_type(u8 type)6306{6307EXhalbtcoutsrc_set_rfe_type(type);6308}63096310#ifdef CONFIG_RF4CE_COEXIST6311void hal_btcoex_set_rf4ce_link_state(u8 state)6312{6313EXhalbtcoutsrc_set_rf4ce_link_state(state);6314}63156316u8 hal_btcoex_get_rf4ce_link_state(void)6317{6318return EXhalbtcoutsrc_get_rf4ce_link_state();6319}6320#endif /* CONFIG_RF4CE_COEXIST */63216322void hal_btcoex_switchband_notify(u8 under_scan, u8 band_type)6323{6324switch (band_type) {6325case BAND_ON_2_4G:6326if (under_scan)6327EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G);6328else6329EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_24G_NOFORSCAN);6330break;6331case BAND_ON_5G:6332EXhalbtcoutsrc_switchband_notify(&GLBtCoexist, BTC_SWITCH_TO_5G);6333break;6334default:6335RTW_INFO("[BTCOEX] unkown switch band type\n");6336break;6337}6338}63396340void hal_btcoex_WlFwDbgInfoNotify(PADAPTER padapter, u8* tmpBuf, u8 length)6341{6342EXhalbtcoutsrc_WlFwDbgInfoNotify(&GLBtCoexist, tmpBuf, length);6343}63446345void hal_btcoex_rx_rate_change_notify(PADAPTER padapter, u8 is_data_frame, u8 rate_id)6346{6347EXhalbtcoutsrc_rx_rate_change_notify(&GLBtCoexist, is_data_frame, EXhalbtcoutsrc_rate_id_to_btc_rate_id(rate_id));6348}63496350u16 hal_btcoex_btset_testode(PADAPTER padapter, u8 type)6351{6352u16 ret = 0;63536354halbtcoutsrc_LeaveLowPower(&GLBtCoexist);63556356ret = halbtcoutsrc_setbttestmode(&GLBtCoexist, type);63576358halbtcoutsrc_NormalLowPower(&GLBtCoexist);63596360return ret;6361}63626363#endif /* CONFIG_BT_COEXIST */636463656366