1
0
mirror of https://github.com/morrownr/8821cu-20210916.git synced 2024-12-05 03:22:26 +00:00
8821cu-20210916/hal/hal_btcoex.c
2022-11-17 08:26:57 -06:00

6652 lines
182 KiB
C

/******************************************************************************
*
* Copyright(c) 2013 - 2019 Realtek Corporation.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
*****************************************************************************/
#define __HAL_BTCOEX_C__
#ifdef CONFIG_BT_COEXIST
#include <hal_data.h>
#include <hal_btcoex.h>
#include "btc/mp_precomp.h"
/* ************************************
* Global variables
* ************************************ */
const char *const BtProfileString[] = {
"NONE",
"A2DP",
"PAN",
"HID",
"SCO",
};
const char *const BtSpecString[] = {
"1.0b",
"1.1",
"1.2",
"2.0+EDR",
"2.1+EDR",
"3.0+HS",
"4.0",
};
const char *const BtLinkRoleString[] = {
"Master",
"Slave",
};
const char *const h2cStaString[] = {
"successful",
"h2c busy",
"rf off",
"fw not read",
};
const char *const ioStaString[] = {
"success",
"can not IO",
"rf off",
"fw not read",
"wait io timeout",
"invalid len",
"idle Q empty",
"insert waitQ fail",
"unknown fail",
"wrong level",
"h2c stopped",
};
const char *const GLBtcWifiBwString[] = {
"11bg",
"HT20",
"HT40",
"VHT80",
"VHT160"
};
const char *const GLBtcWifiFreqString[] = {
"2.4G",
"5G",
"2.4G+5G"
};
const char *const GLBtcIotPeerString[] = {
"UNKNOWN",
"REALTEK",
"REALTEK_92SE",
"BROADCOM",
"RALINK",
"ATHEROS",
"CISCO",
"MERU",
"MARVELL",
"REALTEK_SOFTAP", /* peer is RealTek SOFT_AP, by Bohn, 2009.12.17 */
"SELF_SOFTAP", /* Self is SoftAP */
"AIRGO",
"INTEL",
"RTK_APCLIENT",
"REALTEK_81XX",
"REALTEK_WOW",
"REALTEK_JAGUAR_BCUTAP",
"REALTEK_JAGUAR_CCUTAP"
};
const char *const coexOpcodeString[] = {
"Wifi status notify",
"Wifi progress",
"Wifi info",
"Power state",
"Set Control",
"Get Control"
};
const char *const coexIndTypeString[] = {
"bt info",
"pstdma",
"limited tx/rx",
"coex table",
"request"
};
const char *const coexH2cResultString[] = {
"ok",
"unknown",
"un opcode",
"opVer MM",
"par Err",
"par OoR",
"reqNum MM",
"halMac Fail",
"h2c TimeOut",
"Invalid c2h Len",
"data overflow"
};
#define HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS 8000
struct btc_coexist GLBtCoexist;
BTC_OFFLOAD gl_coex_offload;
u8 GLBtcWiFiInScanState;
u8 GLBtcWiFiInIQKState;
u8 GLBtcWiFiInIPS;
u8 GLBtcWiFiInLPS;
u8 GLBtcBtCoexAliveRegistered;
/*
* BT control H2C/C2H
*/
/* EXT_EID */
typedef enum _bt_ext_eid {
C2H_WIFI_FW_ACTIVE_RSP = 0,
C2H_TRIG_BY_BT_FW
} BT_EXT_EID;
/* C2H_STATUS */
typedef enum _bt_c2h_status {
BT_STATUS_OK = 0,
BT_STATUS_VERSION_MISMATCH,
BT_STATUS_UNKNOWN_OPCODE,
BT_STATUS_ERROR_PARAMETER
} BT_C2H_STATUS;
/* C2H BT OP CODES */
typedef enum _bt_op_code {
BT_OP_GET_BT_VERSION = 0x00,
BT_OP_WRITE_REG_ADDR = 0x0c,
BT_OP_WRITE_REG_VALUE = 0x0d,
BT_OP_READ_REG = 0x11,
BT_LO_OP_GET_AFH_MAP_L = 0x1e,
BT_LO_OP_GET_AFH_MAP_M = 0x1f,
BT_LO_OP_GET_AFH_MAP_H = 0x20,
BT_OP_SET_BT_TRX_MASK = 0x29,
BT_OP_GET_BT_COEX_SUPPORTED_FEATURE = 0x2a,
BT_OP_GET_BT_COEX_SUPPORTED_VERSION = 0x2b,
BT_OP_GET_BT_ANT_DET_VAL = 0x2c,
BT_OP_GET_BT_BLE_SCAN_TYPE = 0x2d,
BT_OP_GET_BT_BLE_SCAN_PARA = 0x2e,
BT_OP_GET_BT_DEVICE_INFO = 0x30,
BT_OP_GET_BT_FORBIDDEN_SLOT_VAL = 0x31,
BT_OP_SET_BT_LANCONSTRAIN_LEVEL = 0x32,
BT_OP_SET_BT_TEST_MODE_VAL = 0x33,
BT_OP_MAX
} BT_OP_CODE;
#define BTC_MPOPER_TIMEOUT 50 /* unit: ms */
#define C2H_MAX_SIZE 16
u8 GLBtcBtMpOperSeq;
_mutex GLBtcBtMpOperLock;
_timer GLBtcBtMpOperTimer;
_sema GLBtcBtMpRptSema;
u8 GLBtcBtMpRptSeq;
u8 GLBtcBtMpRptStatus;
u8 GLBtcBtMpRptRsp[C2H_MAX_SIZE];
u8 GLBtcBtMpRptRspSize;
u8 GLBtcBtMpRptWait;
u8 GLBtcBtMpRptWiFiOK;
u8 GLBtcBtMpRptBTOK;
/*
* Debug
*/
u32 GLBtcDbgType[COMP_MAX];
u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE];
u8 gl_btc_trace_buf[BT_TMP_BUF_SIZE];
typedef struct _btcoexdbginfo {
u8 *info;
u32 size; /* buffer total size */
u32 len; /* now used length */
} BTCDBGINFO, *PBTCDBGINFO;
BTCDBGINFO GLBtcDbgInfo;
#define BT_Operation(Adapter) _FALSE
static void DBG_BT_INFO_INIT(PBTCDBGINFO pinfo, u8 *pbuf, u32 size)
{
if (NULL == pinfo)
return;
_rtw_memset(pinfo, 0, sizeof(BTCDBGINFO));
if (pbuf && size) {
pinfo->info = pbuf;
pinfo->size = size;
}
}
void DBG_BT_INFO(u8 *dbgmsg)
{
PBTCDBGINFO pinfo;
u32 msglen, buflen;
u8 *pbuf;
pinfo = &GLBtcDbgInfo;
if (NULL == pinfo->info)
return;
msglen = strlen(dbgmsg);
if (pinfo->len + msglen > pinfo->size)
return;
pbuf = pinfo->info + pinfo->len;
_rtw_memcpy(pbuf, dbgmsg, msglen);
pinfo->len += msglen;
}
/* ************************************
* Debug related function
* ************************************ */
static u8 halbtcoutsrc_IsBtCoexistAvailable(PBTC_COEXIST pBtCoexist)
{
if (!pBtCoexist->bBinded ||
NULL == pBtCoexist->Adapter)
return _FALSE;
return _TRUE;
}
static void halbtcoutsrc_DbgInit(void)
{
u8 i;
for (i = 0; i < COMP_MAX; i++)
GLBtcDbgType[i] = 0;
}
static void halbtcoutsrc_EnterPwrLock(PBTC_COEXIST pBtCoexist)
{
struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
_enter_pwrlock(&pwrpriv->lock);
}
static void halbtcoutsrc_ExitPwrLock(PBTC_COEXIST pBtCoexist)
{
struct dvobj_priv *dvobj = adapter_to_dvobj((PADAPTER)pBtCoexist->Adapter);
struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
_exit_pwrlock(&pwrpriv->lock);
}
static u8 halbtcoutsrc_IsHwMailboxExist(PBTC_COEXIST pBtCoexist)
{
if (pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC4
|| pBtCoexist->board_info.bt_chip_type == BTC_CHIP_CSR_BC8
)
return _FALSE;
else if (IS_HARDWARE_TYPE_8812(pBtCoexist->Adapter))
return _FALSE;
else
return _TRUE;
}
static u8 halbtcoutsrc_LeaveLps(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
padapter = pBtCoexist->Adapter;
pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
pBtCoexist->bt_info.bt_lps_on = _FALSE;
return rtw_btcoex_LPS_Leave(padapter);
}
void halbtcoutsrc_EnterLps(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
padapter = pBtCoexist->Adapter;
if (pBtCoexist->bdontenterLPS == _FALSE) {
pBtCoexist->bt_info.bt_ctrl_lps = _TRUE;
pBtCoexist->bt_info.bt_lps_on = _TRUE;
rtw_btcoex_LPS_Enter(padapter);
}
}
void halbtcoutsrc_NormalLps(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
padapter = pBtCoexist->Adapter;
if (pBtCoexist->bt_info.bt_ctrl_lps) {
pBtCoexist->bt_info.bt_lps_on = _FALSE;
rtw_btcoex_LPS_Leave(padapter);
pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;
/* recover the LPS state to the original */
#if 0
padapter->hal_func.UpdateLPSStatusHandler(
padapter,
pPSC->RegLeisurePsMode,
pPSC->RegPowerSaveMode);
#endif
}
}
void halbtcoutsrc_Pre_NormalLps(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
padapter = pBtCoexist->Adapter;
if (pBtCoexist->bt_info.bt_ctrl_lps) {
pBtCoexist->bt_info.bt_lps_on = _FALSE;
rtw_btcoex_LPS_Leave(padapter);
}
}
void halbtcoutsrc_Post_NormalLps(PBTC_COEXIST pBtCoexist)
{
if (pBtCoexist->bt_info.bt_ctrl_lps)
pBtCoexist->bt_info.bt_ctrl_lps = _FALSE;
}
/*
* Constraint:
* 1. this function will request pwrctrl->lock
*/
void halbtcoutsrc_LeaveLowPower(PBTC_COEXIST pBtCoexist)
{
#ifdef CONFIG_LPS_LCLK
PADAPTER padapter;
PHAL_DATA_TYPE pHalData;
struct pwrctrl_priv *pwrctrl;
s32 ready;
systime stime;
s32 utime;
u32 timeout; /* unit: ms */
padapter = pBtCoexist->Adapter;
pHalData = GET_HAL_DATA(padapter);
pwrctrl = adapter_to_pwrctl(padapter);
ready = _FAIL;
#ifdef LPS_RPWM_WAIT_MS
timeout = LPS_RPWM_WAIT_MS;
#else /* !LPS_RPWM_WAIT_MS */
timeout = 30;
#endif /* !LPS_RPWM_WAIT_MS */
if (GLBtcBtCoexAliveRegistered == _TRUE)
return;
stime = rtw_get_current_time();
do {
ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE);
if (_SUCCESS == ready)
break;
utime = rtw_get_passing_time_ms(stime);
if (utime > timeout)
break;
rtw_msleep_os(1);
} while (1);
GLBtcBtCoexAliveRegistered = _TRUE;
#endif /* CONFIG_LPS_LCLK */
}
/*
* Constraint:
* 1. this function will request pwrctrl->lock
*/
void halbtcoutsrc_NormalLowPower(PBTC_COEXIST pBtCoexist)
{
#ifdef CONFIG_LPS_LCLK
PADAPTER padapter;
if (GLBtcBtCoexAliveRegistered == _FALSE)
return;
padapter = pBtCoexist->Adapter;
rtw_unregister_task_alive(padapter, BTCOEX_ALIVE);
GLBtcBtCoexAliveRegistered = _FALSE;
#endif /* CONFIG_LPS_LCLK */
}
void halbtcoutsrc_DisableLowPower(PBTC_COEXIST pBtCoexist, u8 bLowPwrDisable)
{
pBtCoexist->bt_info.bt_disable_low_pwr = bLowPwrDisable;
if (bLowPwrDisable)
halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */
else
halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */
}
void halbtcoutsrc_AggregationCheck(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
BOOLEAN bNeedToAct = _FALSE;
static u32 preTime = 0;
u32 curTime = 0;
padapter = pBtCoexist->Adapter;
/* ===================================== */
/* To void continuous deleteBA=>addBA=>deleteBA=>addBA */
/* This function is not allowed to continuous called. */
/* It can only be called after 8 seconds. */
/* ===================================== */
curTime = rtw_systime_to_ms(rtw_get_current_time());
if ((curTime - preTime) < HALBTCOUTSRC_AGG_CHK_WINDOW_IN_MS) /* over 8 seconds you can execute this function again. */
return;
else
preTime = curTime;
if (pBtCoexist->bt_info.reject_agg_pkt) {
bNeedToAct = _TRUE;
pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
} else {
if (pBtCoexist->bt_info.pre_reject_agg_pkt) {
bNeedToAct = _TRUE;
pBtCoexist->bt_info.pre_reject_agg_pkt = pBtCoexist->bt_info.reject_agg_pkt;
}
if (pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size !=
pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
bNeedToAct = _TRUE;
pBtCoexist->bt_info.pre_bt_ctrl_agg_buf_size = pBtCoexist->bt_info.bt_ctrl_agg_buf_size;
}
if (pBtCoexist->bt_info.bt_ctrl_agg_buf_size) {
if (pBtCoexist->bt_info.pre_agg_buf_size !=
pBtCoexist->bt_info.agg_buf_size)
bNeedToAct = _TRUE;
pBtCoexist->bt_info.pre_agg_buf_size = pBtCoexist->bt_info.agg_buf_size;
}
}
if (bNeedToAct)
rtw_btcoex_rx_ampdu_apply(padapter);
}
u8 halbtcoutsrc_is_autoload_fail(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
PHAL_DATA_TYPE pHalData;
padapter = pBtCoexist->Adapter;
pHalData = GET_HAL_DATA(padapter);
return pHalData->bautoload_fail_flag;
}
u8 halbtcoutsrc_is_fw_ready(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
padapter = pBtCoexist->Adapter;
return GET_HAL_DATA(padapter)->bFWReady;
}
u8 halbtcoutsrc_IsDualBandConnected(PADAPTER padapter)
{
u8 ret = BTC_MULTIPORT_SCC;
#ifdef CONFIG_MCC_MODE
if (MCC_EN(padapter) && (rtw_hal_check_mcc_status(padapter, MCC_STATUS_DOING_MCC))) {
struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
struct mcc_obj_priv *mccobjpriv = &(dvobj->mcc_objpriv);
u8 band0 = mccobjpriv->iface[0]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
u8 band1 = mccobjpriv->iface[1]->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
if (band0 != band1)
ret = BTC_MULTIPORT_MCC_DUAL_BAND;
else
ret = BTC_MULTIPORT_MCC_DUAL_CHANNEL;
}
#endif
return ret;
}
u8 halbtcoutsrc_IsWifiBusy(PADAPTER padapter)
{
if (rtw_mi_check_status(padapter, MI_AP_ASSOC))
return _TRUE;
if (rtw_mi_busy_traffic_check(padapter))
return _TRUE;
return _FALSE;
}
static u32 _halbtcoutsrc_GetWifiLinkStatus(PADAPTER padapter)
{
struct mlme_priv *pmlmepriv;
u8 bp2p;
u32 portConnectedStatus;
pmlmepriv = &padapter->mlmepriv;
bp2p = _FALSE;
portConnectedStatus = 0;
#ifdef CONFIG_P2P
if (!rtw_p2p_chk_state(&padapter->wdinfo, P2P_STATE_NONE))
bp2p = _TRUE;
#endif /* CONFIG_P2P */
if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {
if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == _TRUE) {
if (_TRUE == bp2p)
portConnectedStatus |= WIFI_P2P_GO_CONNECTED;
else
portConnectedStatus |= WIFI_AP_CONNECTED;
} else {
if (_TRUE == bp2p)
portConnectedStatus |= WIFI_P2P_GC_CONNECTED;
else
portConnectedStatus |= WIFI_STA_CONNECTED;
}
}
return portConnectedStatus;
}
u32 halbtcoutsrc_GetWifiLinkStatus(PBTC_COEXIST pBtCoexist)
{
/* ================================= */
/* return value: */
/* [31:16]=> connected port number */
/* [15:0]=> port connected bit define */
/* ================================ */
PADAPTER padapter;
u32 retVal;
u32 portConnectedStatus, numOfConnectedPort;
struct dvobj_priv *dvobj;
_adapter *iface;
int i;
padapter = pBtCoexist->Adapter;
retVal = 0;
portConnectedStatus = 0;
numOfConnectedPort = 0;
dvobj = adapter_to_dvobj(padapter);
for (i = 0; i < dvobj->iface_nums; i++) {
iface = dvobj->padapters[i];
if ((iface) && rtw_is_adapter_up(iface)) {
retVal = _halbtcoutsrc_GetWifiLinkStatus(iface);
if (retVal) {
portConnectedStatus |= retVal;
numOfConnectedPort++;
}
}
}
retVal = (numOfConnectedPort << 16) | portConnectedStatus;
return retVal;
}
struct btc_wifi_link_info halbtcoutsrc_getwifilinkinfo(PBTC_COEXIST pBtCoexist)
{
u8 n_assoc_iface = 0, i =0, mcc_en = _FALSE;
PADAPTER adapter = NULL;
PADAPTER iface = NULL;
PADAPTER sta_iface = NULL, p2p_iface = NULL, ap_iface = NULL;
BTC_LINK_MODE btc_link_moe = BTC_LINK_MAX;
struct dvobj_priv *dvobj = NULL;
struct mlme_ext_priv *mlmeext = NULL;
struct btc_wifi_link_info wifi_link_info;
adapter = (PADAPTER)pBtCoexist->Adapter;
dvobj = adapter_to_dvobj(adapter);
n_assoc_iface = rtw_mi_get_assoc_if_num(adapter);
/* init value */
wifi_link_info.link_mode = BTC_LINK_NONE;
wifi_link_info.sta_center_channel = 0;
wifi_link_info.p2p_center_channel = 0;
wifi_link_info.bany_client_join_go = _FALSE;
wifi_link_info.benable_noa = _FALSE;
wifi_link_info.bhotspot = _FALSE;
for (i = 0; i < dvobj->iface_nums; i++) {
iface = dvobj->padapters[i];
if (!iface)
continue;
mlmeext = &iface->mlmeextpriv;
if (MLME_IS_GO(iface)) {
wifi_link_info.link_mode = BTC_LINK_ONLY_GO;
wifi_link_info.p2p_center_channel =
rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
p2p_iface = iface;
if (rtw_linked_check(iface))
wifi_link_info.bany_client_join_go = _TRUE;
} else if (MLME_IS_GC(iface)) {
wifi_link_info.link_mode = BTC_LINK_ONLY_GC;
wifi_link_info.p2p_center_channel =
rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
p2p_iface = iface;
} else if (MLME_IS_AP(iface)) {
wifi_link_info.link_mode = BTC_LINK_ONLY_AP;
ap_iface = iface;
wifi_link_info.p2p_center_channel =
rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
} else if (MLME_IS_STA(iface) && rtw_linked_check(iface)) {
wifi_link_info.link_mode = BTC_LINK_ONLY_STA;
wifi_link_info.sta_center_channel =
rtw_get_center_ch(mlmeext->cur_channel, mlmeext->cur_bwmode, mlmeext->cur_ch_offset);
sta_iface = iface;
}
}
#ifdef CONFIG_MCC_MODE
if (MCC_EN(adapter)) {
if (rtw_hal_check_mcc_status(adapter, MCC_STATUS_DOING_MCC))
mcc_en = _TRUE;
}
#endif/* CONFIG_MCC_MODE */
if (n_assoc_iface == 0) {
wifi_link_info.link_mode = BTC_LINK_NONE;
} else if (n_assoc_iface == 1) {
/* by pass */
} else if (n_assoc_iface == 2) {
if (sta_iface && p2p_iface) {
u8 band_sta = sta_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
u8 band_p2p = p2p_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
if (band_sta == band_p2p) {
switch (band_sta) {
case BAND_ON_2_4G:
if (MLME_IS_GO(p2p_iface)) {
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_2G_MCC_GO_STA : BTC_LINK_2G_SCC_GO_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_2G_SCC_GO_STA;
#endif /* CONFIG_MCC_MODE */
} else if (MLME_IS_GC(p2p_iface)) {
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_2G_MCC_GC_STA : BTC_LINK_2G_SCC_GC_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_2G_SCC_GC_STA;
#endif /* CONFIG_MCC_MODE */
}
break;
case BAND_ON_5G:
if (MLME_IS_GO(p2p_iface)) {
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_5G_MCC_GO_STA : BTC_LINK_5G_SCC_GO_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_5G_SCC_GO_STA;
#endif /* CONFIG_MCC_MODE */
} else if (MLME_IS_GC(p2p_iface)) {
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_5G_MCC_GC_STA : BTC_LINK_5G_SCC_GC_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_5G_SCC_GC_STA;
#endif /* CONFIG_MCC_MODE */
}
break;
}
} else {
if (MLME_IS_GO(p2p_iface))
wifi_link_info.link_mode = BTC_LINK_25G_MCC_GO_STA;
else if (MLME_IS_GC(p2p_iface))
wifi_link_info.link_mode = BTC_LINK_25G_MCC_GC_STA;
}
}
if (sta_iface && ap_iface) {
u8 band_sta = sta_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
u8 band_ap = ap_iface->mlmeextpriv.cur_channel > 14 ? BAND_ON_5G : BAND_ON_2_4G;
if (band_sta == band_ap) {
switch (band_sta) {
case BAND_ON_2_4G:
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_2G_MCC_GO_STA : BTC_LINK_2G_SCC_GO_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_2G_SCC_GO_STA;
#endif /* CONFIG_MCC_MODE */
break;
case BAND_ON_5G:
#ifdef CONFIG_MCC_MODE
wifi_link_info.link_mode =
mcc_en == _TRUE ? BTC_LINK_5G_MCC_GO_STA : BTC_LINK_5G_SCC_GO_STA;
#else /* !CONFIG_MCC_MODE */
wifi_link_info.link_mode = BTC_LINK_5G_SCC_GO_STA;
#endif /* CONFIG_MCC_MODE */
break;
}
} else {
wifi_link_info.link_mode = BTC_LINK_25G_MCC_GO_STA;
}
}
} else {
if (pBtCoexist->board_info.btdm_ant_num == 1)
RTW_ERR("%s do not support n_assoc_iface > 2 (ant_num == 1)", __func__);
}
return wifi_link_info;
}
static void _btmpoper_timer_hdl(void *p)
{
if (GLBtcBtMpRptWait == _TRUE) {
GLBtcBtMpRptWait = _FALSE;
_rtw_up_sema(&GLBtcBtMpRptSema);
}
}
/*
* !IMPORTANT!
* Before call this function, caller should acquire "GLBtcBtMpOperLock"!
* Othrewise there will be racing problem and something may go wrong.
*/
static u8 _btmpoper_cmd(PBTC_COEXIST pBtCoexist, u8 opcode, u8 opcodever, u8 *cmd, u8 size)
{
PADAPTER padapter;
u8 buf[H2C_BTMP_OPER_LEN] = {0};
u8 buflen;
u8 seq;
s32 ret;
if (!cmd && size)
size = 0;
if ((size + 2) > H2C_BTMP_OPER_LEN)
return BT_STATUS_H2C_LENGTH_EXCEEDED;
buflen = size + 2;
seq = GLBtcBtMpOperSeq & 0xF;
GLBtcBtMpOperSeq++;
buf[0] = (opcodever & 0xF) | (seq << 4);
buf[1] = opcode;
if (cmd && size)
_rtw_memcpy(buf + 2, cmd, size);
GLBtcBtMpRptWait = _TRUE;
GLBtcBtMpRptWiFiOK = _FALSE;
GLBtcBtMpRptBTOK = _FALSE;
GLBtcBtMpRptStatus = 0;
padapter = pBtCoexist->Adapter;
_set_timer(&GLBtcBtMpOperTimer, BTC_MPOPER_TIMEOUT);
if (rtw_hal_fill_h2c_cmd(padapter, H2C_BT_MP_OPER, buflen, buf) == _FAIL) {
_cancel_timer_ex(&GLBtcBtMpOperTimer);
ret = BT_STATUS_H2C_FAIL;
goto exit;
}
_rtw_down_sema(&GLBtcBtMpRptSema);
/* GLBtcBtMpRptWait should be _FALSE here*/
if (GLBtcBtMpRptWiFiOK == _FALSE) {
RTW_DBG("%s: Didn't get H2C Rsp Event!\n", __FUNCTION__);
ret = BT_STATUS_H2C_TIMTOUT;
goto exit;
}
if (GLBtcBtMpRptBTOK == _FALSE) {
RTW_DBG("%s: Didn't get BT response!\n", __FUNCTION__);
ret = BT_STATUS_H2C_BT_NO_RSP;
goto exit;
}
if (seq != GLBtcBtMpRptSeq) {
RTW_ERR("%s: Sequence number not match!(%d!=%d)!\n",
__FUNCTION__, seq, GLBtcBtMpRptSeq);
ret = BT_STATUS_C2H_REQNUM_MISMATCH;
goto exit;
}
switch (GLBtcBtMpRptStatus) {
/* Examine the status reported from C2H */
case BT_STATUS_OK:
ret = BT_STATUS_BT_OP_SUCCESS;
RTW_DBG("%s: C2H status = BT_STATUS_BT_OP_SUCCESS\n", __FUNCTION__);
break;
case BT_STATUS_VERSION_MISMATCH:
ret = BT_STATUS_OPCODE_L_VERSION_MISMATCH;
RTW_DBG("%s: C2H status = BT_STATUS_OPCODE_L_VERSION_MISMATCH\n", __FUNCTION__);
break;
case BT_STATUS_UNKNOWN_OPCODE:
ret = BT_STATUS_UNKNOWN_OPCODE_L;
RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_OPCODE_L\n", __FUNCTION__);
break;
case BT_STATUS_ERROR_PARAMETER:
ret = BT_STATUS_PARAMETER_FORMAT_ERROR_L;
RTW_DBG("%s: C2H status = MP_BT_STATUS_PARAMETER_FORMAT_ERROR_L\n", __FUNCTION__);
break;
default:
ret = BT_STATUS_UNKNOWN_STATUS_L;
RTW_DBG("%s: C2H status = MP_BT_STATUS_UNKNOWN_STATUS_L\n", __FUNCTION__);
break;
}
exit:
return ret;
}
u32 halbtcoutsrc_GetBtPatchVer(PBTC_COEXIST pBtCoexist)
{
if (pBtCoexist->bt_info.get_bt_fw_ver_cnt <= 5) {
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
_irqL irqL;
u8 ret;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
ret = _btmpoper_cmd(pBtCoexist, BT_OP_GET_BT_VERSION, 0, NULL, 0);
if (BT_STATUS_BT_OP_SUCCESS == ret) {
pBtCoexist->bt_info.bt_real_fw_ver = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
pBtCoexist->bt_info.get_bt_fw_ver_cnt++;
}
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else {
#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
u8 dataLen = 2;
u8 buf[4] = {0};
buf[0] = 0x0; /* OP_Code */
buf[1] = 0x0; /* OP_Code_Length */
BT_SendEventExtBtCoexControl(pBtCoexist->Adapter, _FALSE, dataLen, &buf[0]);
#endif /* !CONFIG_BT_COEXIST_SOCKET_TRX */
}
}
return pBtCoexist->bt_info.bt_real_fw_ver;
}
s32 halbtcoutsrc_GetWifiRssi(PADAPTER padapter)
{
return rtw_dm_get_min_rssi(padapter);
}
u32 halbtcoutsrc_GetBtCoexSupportedFeature(void *pBtcContext)
{
PBTC_COEXIST pBtCoexist;
u32 ret = BT_STATUS_BT_OP_SUCCESS;
u32 data = 0;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
op_code = BT_OP_GET_BT_COEX_SUPPORTED_FEATURE;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
if (status == BT_STATUS_BT_OP_SUCCESS)
data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
else
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return data;
}
u32 halbtcoutsrc_GetBtCoexSupportedVersion(void *pBtcContext)
{
PBTC_COEXIST pBtCoexist;
u32 ret = BT_STATUS_BT_OP_SUCCESS;
u32 data = 0xFFFF;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
op_code = BT_OP_GET_BT_COEX_SUPPORTED_VERSION;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
if (status == BT_STATUS_BT_OP_SUCCESS)
data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
else
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return data;
}
u32 halbtcoutsrc_GetBtDeviceInfo(void *pBtcContext)
{
PBTC_COEXIST pBtCoexist;
u32 ret = BT_STATUS_BT_OP_SUCCESS;
u32 btDeviceInfo = 0;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
op_code = BT_OP_GET_BT_DEVICE_INFO;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
if (status == BT_STATUS_BT_OP_SUCCESS)
btDeviceInfo = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
else
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return btDeviceInfo;
}
u32 halbtcoutsrc_GetBtForbiddenSlotVal(void *pBtcContext)
{
PBTC_COEXIST pBtCoexist;
u32 ret = BT_STATUS_BT_OP_SUCCESS;
u32 btForbiddenSlotVal = 0;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
op_code = BT_OP_GET_BT_FORBIDDEN_SLOT_VAL;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
if (status == BT_STATUS_BT_OP_SUCCESS)
btForbiddenSlotVal = le32_to_cpu(*(u32 *)GLBtcBtMpRptRsp);
else
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return btForbiddenSlotVal;
}
static u8 halbtcoutsrc_GetWifiScanAPNum(PADAPTER padapter)
{
struct mlme_priv *pmlmepriv;
struct mlme_ext_priv *pmlmeext;
static u8 scan_AP_num = 0;
pmlmepriv = &padapter->mlmepriv;
pmlmeext = &padapter->mlmeextpriv;
if (GLBtcWiFiInScanState == _FALSE) {
if (pmlmepriv->num_of_scanned > 0xFF)
scan_AP_num = 0xFF;
else
scan_AP_num = (u8)pmlmepriv->num_of_scanned;
}
return scan_AP_num;
}
u32 halbtcoutsrc_GetPhydmVersion(void *pBtcContext)
{
struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
PADAPTER Adapter = pBtCoexist->Adapter;
#ifdef CONFIG_RTL8192E
return RELEASE_VERSION_8192E;
#endif
#ifdef CONFIG_RTL8821A
return RELEASE_VERSION_8821A;
#endif
#ifdef CONFIG_RTL8723B
return RELEASE_VERSION_8723B;
#endif
#ifdef CONFIG_RTL8812A
return RELEASE_VERSION_8812A;
#endif
#ifdef CONFIG_RTL8703B
return RELEASE_VERSION_8703B;
#endif
#ifdef CONFIG_RTL8822B
return RELEASE_VERSION_8822B;
#endif
#ifdef CONFIG_RTL8723D
return RELEASE_VERSION_8723D;
#endif
#ifdef CONFIG_RTL8821C
return RELEASE_VERSION_8821C;
#endif
#ifdef CONFIG_RTL8192F
return RELEASE_VERSION_8192F;
#endif
#ifdef CONFIG_RTL8822C
return RELEASE_VERSION_8822C;
#endif
#ifdef CONFIG_RTL8814A
return RELEASE_VERSION_8814A;
#endif
#ifdef CONFIG_RTL8814B
return RELEASE_VERSION_8814B;
#endif
#ifdef CONFIG_RTL8723F
return RELEASE_VERSION_8723F;
#endif
}
u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
PHAL_DATA_TYPE pHalData;
struct mlme_ext_priv *mlmeext;
struct btc_wifi_link_info *wifi_link_info;
u8 bSoftApExist, bVwifiExist;
u8 *pu8;
s32 *pS4Tmp;
u32 *pU4Tmp;
u8 *pU1Tmp;
u16 *pU2Tmp;
u8 ret;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
return _FALSE;
padapter = pBtCoexist->Adapter;
pHalData = GET_HAL_DATA(padapter);
mlmeext = &padapter->mlmeextpriv;
bSoftApExist = _FALSE;
bVwifiExist = _FALSE;
pu8 = (u8 *)pOutBuf;
pS4Tmp = (s32 *)pOutBuf;
pU4Tmp = (u32 *)pOutBuf;
pU1Tmp = (u8 *)pOutBuf;
pU2Tmp = (u16*)pOutBuf;
wifi_link_info = (struct btc_wifi_link_info *)pOutBuf;
ret = _TRUE;
switch (getType) {
case BTC_GET_BL_HS_OPERATION:
*pu8 = _FALSE;
ret = _FALSE;
break;
case BTC_GET_BL_HS_CONNECTING:
*pu8 = _FALSE;
ret = _FALSE;
break;
case BTC_GET_BL_WIFI_FW_READY:
*pu8 = halbtcoutsrc_is_fw_ready(pBtCoexist);
break;
case BTC_GET_BL_WIFI_CONNECTED:
*pu8 = (rtw_mi_check_status(padapter, MI_LINKED)) ? _TRUE : _FALSE;
break;
case BTC_GET_BL_WIFI_DUAL_BAND_CONNECTED:
*pu8 = halbtcoutsrc_IsDualBandConnected(padapter);
break;
case BTC_GET_BL_WIFI_BUSY:
*pu8 = halbtcoutsrc_IsWifiBusy(padapter);
break;
case BTC_GET_BL_WIFI_SCAN:
#if 0
*pu8 = (rtw_mi_check_fwstate(padapter, WIFI_UNDER_SURVEY)) ? _TRUE : _FALSE;
#else
/* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag
WIFI_UNDER_SURVEY in fwstate may not be cleared in time */
*pu8 = GLBtcWiFiInScanState;
#endif
break;
case BTC_GET_BL_WIFI_LINK:
*pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
break;
case BTC_GET_BL_WIFI_ROAM:
*pu8 = (rtw_mi_check_status(padapter, MI_STA_LINKING)) ? _TRUE : _FALSE;
break;
case BTC_GET_BL_WIFI_4_WAY_PROGRESS:
*pu8 = _FALSE;
break;
case BTC_GET_BL_WIFI_BSSID:
_rtw_memcpy(pu8, get_bssid(&padapter->mlmepriv), ETH_ALEN);
break;
case BTC_GET_BL_WIFI_UNDER_5G:
*pu8 = (pHalData->current_band_type == BAND_ON_5G) ? _TRUE : _FALSE;
break;
case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
*pu8 = (rtw_mi_check_status(padapter, MI_AP_MODE)) ? _TRUE : _FALSE;
break;
case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
*pu8 = padapter->securitypriv.dot11PrivacyAlgrthm == 0 ? _FALSE : _TRUE;
break;
case BTC_GET_BL_WIFI_UNDER_B_MODE:
if (mlmeext->cur_wireless_mode == WIRELESS_11B)
*pu8 = _TRUE;
else
*pu8 = _FALSE;
break;
case BTC_GET_BL_WIFI_IS_IN_MP_MODE:
if (padapter->registrypriv.mp_mode == 0)
*pu8 = _FALSE;
else
*pu8 = _TRUE;
break;
case BTC_GET_BL_EXT_SWITCH:
*pu8 = _FALSE;
break;
case BTC_GET_BL_IS_ASUS_8723B:
/* Always return FALSE in linux driver since this case is added only for windows driver */
*pu8 = _FALSE;
break;
case BTC_GET_BL_RF4CE_CONNECTED:
#ifdef CONFIG_RF4CE_COEXIST
if (hal_btcoex_get_rf4ce_link_state() == 0)
*pu8 = FALSE;
else
*pu8 = TRUE;
#else
*pu8 = FALSE;
#endif
break;
case BTC_GET_BL_WIFI_LW_PWR_STATE:
/* return false due to coex do not run during 32K */
*pu8 = FALSE;
break;
case BTC_GET_S4_WIFI_RSSI:
*pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter);
break;
case BTC_GET_S4_HS_RSSI:
*pS4Tmp = 0;
ret = _FALSE;
break;
case BTC_GET_U4_WIFI_BW:
if (IsLegacyOnly(mlmeext->cur_wireless_mode))
*pU4Tmp = BTC_WIFI_BW_LEGACY;
else {
switch (pHalData->current_channel_bw) {
case CHANNEL_WIDTH_20:
*pU4Tmp = BTC_WIFI_BW_HT20;
break;
case CHANNEL_WIDTH_40:
*pU4Tmp = BTC_WIFI_BW_HT40;
break;
case CHANNEL_WIDTH_80:
*pU4Tmp = BTC_WIFI_BW_HT80;
break;
case CHANNEL_WIDTH_160:
*pU4Tmp = BTC_WIFI_BW_HT160;
break;
default:
RTW_INFO("[BTCOEX] unknown bandwidth(%d)\n", pHalData->current_channel_bw);
*pU4Tmp = BTC_WIFI_BW_HT40;
break;
}
}
break;
case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
case BTC_GET_U4_WIFI_TRAFFIC_DIR:
{
PRT_LINK_DETECT_T plinkinfo;
plinkinfo = &padapter->mlmepriv.LinkDetectInfo;
if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod)
*pU4Tmp = BTC_WIFI_TRAFFIC_TX;
else
*pU4Tmp = BTC_WIFI_TRAFFIC_RX;
}
break;
case BTC_GET_U4_WIFI_FW_VER:
*pU4Tmp = pHalData->firmware_version << 16;
*pU4Tmp |= pHalData->firmware_sub_version;
break;
case BTC_GET_U4_WIFI_PHY_VER:
*pU4Tmp = halbtcoutsrc_GetPhydmVersion(pBtCoexist);
break;
case BTC_GET_U4_WIFI_LINK_STATUS:
*pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
break;
case BTC_GET_BL_WIFI_LINK_INFO:
*wifi_link_info = halbtcoutsrc_getwifilinkinfo(pBtCoexist);
break;
case BTC_GET_U4_BT_PATCH_VER:
*pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist);
break;
case BTC_GET_U4_VENDOR:
*pU4Tmp = BTC_VENDOR_OTHER;
break;
case BTC_GET_U4_SUPPORTED_VERSION:
*pU4Tmp = halbtcoutsrc_GetBtCoexSupportedVersion(pBtCoexist);
break;
case BTC_GET_U4_SUPPORTED_FEATURE:
*pU4Tmp = halbtcoutsrc_GetBtCoexSupportedFeature(pBtCoexist);
break;
case BTC_GET_U4_BT_DEVICE_INFO:
*pU4Tmp = halbtcoutsrc_GetBtDeviceInfo(pBtCoexist);
break;
case BTC_GET_U4_BT_FORBIDDEN_SLOT_VAL:
case BTC_GET_U4_BT_A2DP_FLUSH_VAL:
*pU4Tmp = halbtcoutsrc_GetBtForbiddenSlotVal(pBtCoexist);
break;
case BTC_GET_U4_WIFI_IQK_TOTAL:
*pU4Tmp = pHalData->odmpriv.n_iqk_cnt;
break;
case BTC_GET_U4_WIFI_IQK_OK:
*pU4Tmp = pHalData->odmpriv.n_iqk_ok_cnt;
break;
case BTC_GET_U4_WIFI_IQK_FAIL:
*pU4Tmp = pHalData->odmpriv.n_iqk_fail_cnt;
break;
case BTC_GET_U1_WIFI_DOT11_CHNL:
*pU1Tmp = padapter->mlmeextpriv.cur_channel;
break;
case BTC_GET_U1_WIFI_CENTRAL_CHNL:
*pU1Tmp = pHalData->current_channel;
break;
case BTC_GET_U1_WIFI_HS_CHNL:
*pU1Tmp = 0;
ret = _FALSE;
break;
case BTC_GET_U1_WIFI_P2P_CHNL:
#ifdef CONFIG_P2P
{
struct wifidirect_info *pwdinfo = &(padapter->wdinfo);
*pU1Tmp = pwdinfo->operating_channel;
}
#else
*pU1Tmp = 0;
#endif
break;
case BTC_GET_U1_MAC_PHY_MODE:
/* *pU1Tmp = BTC_SMSP;
* *pU1Tmp = BTC_DMSP;
* *pU1Tmp = BTC_DMDP;
* *pU1Tmp = BTC_MP_UNKNOWN; */
break;
case BTC_GET_U1_AP_NUM:
*pU1Tmp = halbtcoutsrc_GetWifiScanAPNum(padapter);
break;
case BTC_GET_U1_ANT_TYPE:
switch (pHalData->bt_coexist.btAntisolation) {
case 0:
*pU1Tmp = (u8)BTC_ANT_TYPE_0;
pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_0;
break;
case 1:
*pU1Tmp = (u8)BTC_ANT_TYPE_1;
pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_1;
break;
case 2:
*pU1Tmp = (u8)BTC_ANT_TYPE_2;
pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_2;
break;
case 3:
*pU1Tmp = (u8)BTC_ANT_TYPE_3;
pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_3;
break;
case 4:
*pU1Tmp = (u8)BTC_ANT_TYPE_4;
pBtCoexist->board_info.ant_type = (u8)BTC_ANT_TYPE_4;
break;
}
break;
case BTC_GET_U1_IOT_PEER:
*pU1Tmp = mlmeext->mlmext_info.assoc_AP_vendor;
break;
/* =======1Ant=========== */
case BTC_GET_U1_LPS_MODE:
*pU1Tmp = padapter->dvobj->pwrctl_priv.pwr_mode;
break;
case BTC_GET_U2_BEACON_PERIOD:
*pU2Tmp = mlmeext->mlmext_info.bcn_interval;
break;
default:
ret = _FALSE;
break;
}
return ret;
}
u16 halbtcoutsrc_LnaConstrainLvl(void *pBtcContext, u8 *lna_constrain_level)
{
PBTC_COEXIST pBtCoexist;
u16 ret = BT_STATUS_BT_OP_SUCCESS;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
_irqL irqL;
u8 op_code;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
ret = _btmpoper_cmd(pBtCoexist, BT_OP_SET_BT_LANCONSTRAIN_LEVEL, 0, lna_constrain_level, 1);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else {
ret = BT_STATUS_NOT_IMPLEMENT;
RTW_INFO("%s halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == FALSE\n", __func__);
}
return ret;
}
u8 halbtcoutsrc_SetBtGoldenRxRange(void *pBtcContext, u8 profile, u8 range_shift)
{
/* wait for implementation if necessary */
return 0;
}
u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
PHAL_DATA_TYPE pHalData;
u8 *pu8;
u8 *pU1Tmp;
u16 *pU2Tmp;
u32 *pU4Tmp;
u8 ret;
u8 result = _TRUE;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist))
return _FALSE;
padapter = pBtCoexist->Adapter;
pHalData = GET_HAL_DATA(padapter);
pu8 = (u8 *)pInBuf;
pU1Tmp = (u8 *)pInBuf;
pU2Tmp = (u16*)pInBuf;
pU4Tmp = (u32 *)pInBuf;
ret = _TRUE;
switch (setType) {
/* set some u8 type variables. */
case BTC_SET_BL_BT_DISABLE:
pBtCoexist->bt_info.bt_disabled = *pu8;
break;
case BTC_SET_BL_BT_ENABLE_DISABLE_CHANGE:
pBtCoexist->bt_info.bt_enable_disable_change = *pu8;
break;
case BTC_SET_BL_BT_TRAFFIC_BUSY:
pBtCoexist->bt_info.bt_busy = *pu8;
break;
case BTC_SET_BL_BT_LIMITED_DIG:
pBtCoexist->bt_info.limited_dig = *pu8;
break;
case BTC_SET_BL_FORCE_TO_ROAM:
pBtCoexist->bt_info.force_to_roam = *pu8;
break;
case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
pBtCoexist->bt_info.reject_agg_pkt = *pu8;
break;
case BTC_SET_BL_BT_CTRL_AGG_SIZE:
pBtCoexist->bt_info.bt_ctrl_agg_buf_size = *pu8;
break;
case BTC_SET_BL_INC_SCAN_DEV_NUM:
pBtCoexist->bt_info.increase_scan_dev_num = *pu8;
break;
case BTC_SET_BL_BT_TX_RX_MASK:
pBtCoexist->bt_info.bt_tx_rx_mask = *pu8;
break;
case BTC_SET_BL_MIRACAST_PLUS_BT:
pBtCoexist->bt_info.miracast_plus_bt = *pu8;
break;
/* set some u8 type variables. */
case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
pBtCoexist->bt_info.rssi_adjust_for_agc_table_on = *pU1Tmp;
break;
case BTC_SET_U1_AGG_BUF_SIZE:
pBtCoexist->bt_info.agg_buf_size = *pU1Tmp;
break;
/* the following are some action which will be triggered */
case BTC_SET_ACT_GET_BT_RSSI:
#if 0
BT_SendGetBtRssiEvent(padapter);
#else
ret = _FALSE;
#endif
break;
case BTC_SET_ACT_AGGREGATE_CTRL:
halbtcoutsrc_AggregationCheck(pBtCoexist);
break;
/* =======1Ant=========== */
/* set some u8 type variables. */
case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
pBtCoexist->bt_info.rssi_adjust_for_1ant_coex_type = *pU1Tmp;
break;
case BTC_SET_U1_LPS_VAL:
pBtCoexist->bt_info.lps_val = *pU1Tmp;
break;
case BTC_SET_U1_RPWM_VAL:
pBtCoexist->bt_info.rpwm_val = *pU1Tmp;
break;
/* the following are some action which will be triggered */
case BTC_SET_ACT_LEAVE_LPS:
result = halbtcoutsrc_LeaveLps(pBtCoexist);
break;
case BTC_SET_ACT_ENTER_LPS:
halbtcoutsrc_EnterLps(pBtCoexist);
break;
case BTC_SET_ACT_NORMAL_LPS:
halbtcoutsrc_NormalLps(pBtCoexist);
break;
case BTC_SET_ACT_PRE_NORMAL_LPS:
halbtcoutsrc_Pre_NormalLps(pBtCoexist);
break;
case BTC_SET_ACT_POST_NORMAL_LPS:
halbtcoutsrc_Post_NormalLps(pBtCoexist);
break;
case BTC_SET_ACT_DISABLE_LOW_POWER:
halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8);
break;
case BTC_SET_ACT_UPDATE_RAMASK:
/*
pBtCoexist->bt_info.ra_mask = *pU4Tmp;
if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == _TRUE) {
struct sta_info *psta;
PWLAN_BSSID_EX cur_network;
cur_network = &padapter->mlmeextpriv.mlmext_info.network;
psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress);
rtw_hal_update_ra_mask(psta);
}
*/
break;
case BTC_SET_ACT_SEND_MIMO_PS: {
u8 newMimoPsMode = 3;
struct mlme_ext_priv *pmlmeext = &(padapter->mlmeextpriv);
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
/* *pU1Tmp = 0 use SM_PS static type */
/* *pU1Tmp = 1 disable SM_PS */
if (*pU1Tmp == 0)
newMimoPsMode = WLAN_HT_CAP_SM_PS_STATIC;
else if (*pU1Tmp == 1)
newMimoPsMode = WLAN_HT_CAP_SM_PS_DISABLED;
if (check_fwstate(&padapter->mlmepriv , WIFI_ASOC_STATE) == _TRUE) {
/* issue_action_SM_PS(padapter, get_my_bssid(&(pmlmeinfo->network)), newMimoPsMode); */
issue_action_SM_PS_wait_ack(padapter , get_my_bssid(&(pmlmeinfo->network)) , newMimoPsMode, 3 , 1);
}
}
break;
case BTC_SET_ACT_CTRL_BT_INFO:
#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
{
u8 dataLen = *pU1Tmp;
u8 tmpBuf[BTC_TMP_BUF_SHORT];
if (dataLen)
_rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
BT_SendEventExtBtInfoControl(padapter, dataLen, &tmpBuf[0]);
}
#else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
ret = _FALSE;
#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
break;
case BTC_SET_ACT_CTRL_BT_COEX:
#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
{
u8 dataLen = *pU1Tmp;
u8 tmpBuf[BTC_TMP_BUF_SHORT];
if (dataLen)
_rtw_memcpy(tmpBuf, pU1Tmp + 1, dataLen);
BT_SendEventExtBtCoexControl(padapter, _FALSE, dataLen, &tmpBuf[0]);
}
#else /* !CONFIG_BT_COEXIST_SOCKET_TRX */
ret = _FALSE;
#endif /* CONFIG_BT_COEXIST_SOCKET_TRX */
break;
case BTC_SET_ACT_CTRL_8723B_ANT:
#if 0
{
u8 dataLen = *pU1Tmp;
u8 tmpBuf[BTC_TMP_BUF_SHORT];
if (dataLen)
PlatformMoveMemory(&tmpBuf[0], pU1Tmp + 1, dataLen);
BT_Set8723bAnt(Adapter, dataLen, &tmpBuf[0]);
}
#else
ret = _FALSE;
#endif
break;
case BTC_SET_BL_BT_LNA_CONSTRAIN_LEVEL:
halbtcoutsrc_LnaConstrainLvl(pBtCoexist, pu8);
break;
case BTC_SET_BL_BT_GOLDEN_RX_RANGE:
halbtcoutsrc_SetBtGoldenRxRange(pBtCoexist, (*pU2Tmp & 0xff00) >> 8, (*pU2Tmp & 0xff));
break;
case BTC_SET_RESET_COEX_VAR:
_rtw_memset(&pBtCoexist->coex_dm, 0x00, sizeof(pBtCoexist->coex_dm));
_rtw_memset(&pBtCoexist->coex_sta, 0x00, sizeof(pBtCoexist->coex_sta));
switch(pBtCoexist->chip_type) {
#ifdef CONFIG_RTL8822B
case BTC_CHIP_RTL8822B:
_rtw_memset(&pBtCoexist->coex_dm_8822b_1ant, 0x00, sizeof(pBtCoexist->coex_dm_8822b_1ant));
_rtw_memset(&pBtCoexist->coex_dm_8822b_2ant, 0x00, sizeof(pBtCoexist->coex_dm_8822b_2ant));
_rtw_memset(&pBtCoexist->coex_sta_8822b_1ant, 0x00, sizeof(pBtCoexist->coex_sta_8822b_1ant));
_rtw_memset(&pBtCoexist->coex_sta_8822b_2ant, 0x00, sizeof(pBtCoexist->coex_sta_8822b_2ant));
break;
#endif
#ifdef CONFIG_RTL8821C
case BTC_CHIP_RTL8821C:
_rtw_memset(&pBtCoexist->coex_dm_8821c_1ant, 0x00, sizeof(pBtCoexist->coex_dm_8821c_1ant));
_rtw_memset(&pBtCoexist->coex_dm_8821c_2ant, 0x00, sizeof(pBtCoexist->coex_dm_8821c_2ant));
_rtw_memset(&pBtCoexist->coex_sta_8821c_1ant, 0x00, sizeof(pBtCoexist->coex_sta_8821c_1ant));
_rtw_memset(&pBtCoexist->coex_sta_8821c_2ant, 0x00, sizeof(pBtCoexist->coex_sta_8821c_2ant));
break;
#endif
#ifdef CONFIG_RTL8723D
case BTC_CHIP_RTL8723D:
_rtw_memset(&pBtCoexist->coex_dm_8723d_1ant, 0x00, sizeof(pBtCoexist->coex_dm_8723d_1ant));
_rtw_memset(&pBtCoexist->coex_dm_8723d_2ant, 0x00, sizeof(pBtCoexist->coex_dm_8723d_2ant));
_rtw_memset(&pBtCoexist->coex_sta_8723d_1ant, 0x00, sizeof(pBtCoexist->coex_sta_8723d_1ant));
_rtw_memset(&pBtCoexist->coex_sta_8723d_2ant, 0x00, sizeof(pBtCoexist->coex_sta_8723d_2ant));
break;
#endif
}
break;
/* ===================== */
default:
ret = _FALSE;
break;
}
return result;
}
u8 halbtcoutsrc_UnderIps(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter;
struct pwrctrl_priv *pwrpriv;
u8 bMacPwrCtrlOn;
padapter = pBtCoexist->Adapter;
pwrpriv = &padapter->dvobj->pwrctl_priv;
bMacPwrCtrlOn = _FALSE;
if ((_TRUE == pwrpriv->bips_processing)
&& (IPS_NONE != pwrpriv->ips_mode_req)
)
return _TRUE;
if (rf_off == pwrpriv->rf_pwrstate)
return _TRUE;
rtw_hal_get_hwreg(padapter, HW_VAR_APFM_ON_MAC, &bMacPwrCtrlOn);
if (_FALSE == bMacPwrCtrlOn)
return _TRUE;
return _FALSE;
}
u8 halbtcoutsrc_UnderLps(PBTC_COEXIST pBtCoexist)
{
return GLBtcWiFiInLPS;
}
u8 halbtcoutsrc_Under32K(PBTC_COEXIST pBtCoexist)
{
/* todo: the method to check whether wifi is under 32K or not */
return _FALSE;
}
void halbtcoutsrc_DisplayCoexStatistics(PBTC_COEXIST pBtCoexist)
{
#if 0
PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
u8 *cliBuf = pBtCoexist->cliBuf;
u8 i, j;
u8 tmpbuf[BTC_TMP_BUF_SHORT];
if (gl_coex_offload.cnt_h2c_sent) {
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex h2c notify]============");
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = H2c(%d)/Ack(%d)", "Coex h2c/c2h overall statistics",
gl_coex_offload.cnt_h2c_sent, gl_coex_offload.cnt_c2h_ack);
for (j = 0; j < COL_STATUS_MAX; j++) {
if (gl_coex_offload.status[j]) {
CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.status[j]);
CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
}
}
CL_PRINTF(cliBuf);
}
for (i = 0; i < COL_OP_WIFI_OPCODE_MAX; i++) {
if (gl_coex_offload.h2c_record[i].count) {
/*==========================================*/
/* H2C result statistics*/
/*==========================================*/
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexOpcodeString[i], gl_coex_offload.h2c_record[i].count);
for (j = 0; j < COL_STATUS_MAX; j++) {
if (gl_coex_offload.h2c_record[i].status[j]) {
CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.h2c_record[i].status[j]);
CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
}
}
CL_PRINTF(cliBuf);
/*==========================================*/
/* H2C/C2H content*/
/*==========================================*/
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "H2C / C2H content");
for (j = 0; j < gl_coex_offload.h2c_record[i].h2c_len; j++) {
CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].h2c_buf[j]);
CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
}
if (gl_coex_offload.h2c_record[i].c2h_ack_len) {
CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, "/ ", 2);
for (j = 0; j < gl_coex_offload.h2c_record[i].c2h_ack_len; j++) {
CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.h2c_record[i].c2h_ack_buf[j]);
CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
}
}
CL_PRINTF(cliBuf);
/*==========================================*/
}
}
if (gl_coex_offload.cnt_c2h_ind) {
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex c2h indication]============");
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = Ind(%d)", "C2H indication statistics",
gl_coex_offload.cnt_c2h_ind);
for (j = 0; j < COL_STATUS_MAX; j++) {
if (gl_coex_offload.c2h_ind_status[j]) {
CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_status[j]);
CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
}
}
CL_PRINTF(cliBuf);
}
for (i = 0; i < COL_IND_MAX; i++) {
if (gl_coex_offload.c2h_ind_record[i].count) {
/*==========================================*/
/* H2C result statistics*/
/*==========================================*/
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = total:%d", coexIndTypeString[i], gl_coex_offload.c2h_ind_record[i].count);
for (j = 0; j < COL_STATUS_MAX; j++) {
if (gl_coex_offload.c2h_ind_record[i].status[j]) {
CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, ", %s:%d", coexH2cResultString[j], gl_coex_offload.c2h_ind_record[i].status[j]);
CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, BTC_TMP_BUF_SHORT);
}
}
CL_PRINTF(cliBuf);
/*==========================================*/
/* content*/
/*==========================================*/
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = ", "C2H indication content");
for (j = 0; j < gl_coex_offload.c2h_ind_record[i].ind_len; j++) {
CL_SPRINTF(tmpbuf, BTC_TMP_BUF_SHORT, "%02x ", gl_coex_offload.c2h_ind_record[i].ind_buf[j]);
CL_STRNCAT(cliBuf, BT_TMP_BUF_SIZE, tmpbuf, 3);
}
CL_PRINTF(cliBuf);
/*==========================================*/
}
}
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Statistics]============");
CL_PRINTF(cliBuf);
#if (H2C_USE_IO_THREAD != 1)
for (i = 0; i < H2C_STATUS_MAX; i++) {
if (pHalData->h2cStatistics[i]) {
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
h2cStaString[i], pHalData->h2cStatistics[i]);
CL_PRINTF(cliBuf);
}
}
#else
for (i = 0; i < IO_STATUS_MAX; i++) {
if (Adapter->ioComStr.ioH2cStatistics[i]) {
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s] = %d", "H2C statistics", \
ioStaString[i], Adapter->ioComStr.ioH2cStatistics[i]);
CL_PRINTF(cliBuf);
}
}
#endif
#if 0
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "lastHMEBoxNum", \
pHalData->LastHMEBoxNum);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x / 0x%x", "LastOkH2c/FirstFailH2c(fwNotRead)", \
pHalData->lastSuccessH2cEid, pHalData->firstFailedH2cEid);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "c2hIsr/c2hIntr/clr1AF/noRdy/noBuf", \
pHalData->InterruptLog.nIMR_C2HCMD, DBG_Var.c2hInterruptCnt, DBG_Var.c2hClrReadC2hCnt,
DBG_Var.c2hNotReadyCnt, DBG_Var.c2hBufAlloFailCnt);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "c2hPacket", \
DBG_Var.c2hPacketCnt);
CL_PRINTF(cliBuf);
#endif
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "Periodical/ DbgCtrl", \
pBtCoexist->statistics.cntPeriodical, pBtCoexist->statistics.cntDbgCtrl);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "PowerOn/InitHw/InitCoexDm/RfStatus", \
pBtCoexist->statistics.cntPowerOn, pBtCoexist->statistics.cntInitHwConfig, pBtCoexist->statistics.cntInitCoexDm,
pBtCoexist->statistics.cntRfStatusNotify);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "Ips/Lps/Scan/Connect/Mstatus", \
pBtCoexist->statistics.cntIpsNotify, pBtCoexist->statistics.cntLpsNotify,
pBtCoexist->statistics.cntScanNotify, pBtCoexist->statistics.cntConnectNotify,
pBtCoexist->statistics.cntMediaStatusNotify);
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Special pkt/Bt info/ bind",
pBtCoexist->statistics.cntSpecialPacketNotify, pBtCoexist->statistics.cntBtInfoNotify,
pBtCoexist->statistics.cntBind);
CL_PRINTF(cliBuf);
#endif
PADAPTER padapter = pBtCoexist->Adapter;
PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
u8 *cliBuf = pBtCoexist->cli_buf;
if (pHalData->EEPROMBluetoothCoexist == 1) {
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Coex Status]============");
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtDisabled", rtw_btcoex_IsBtDisabled(padapter));
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IsBtControlLps", rtw_btcoex_IsBtControlLps(padapter));
CL_PRINTF(cliBuf);
}
}
void halbtcoutsrc_DisplayBtLinkInfo(PBTC_COEXIST pBtCoexist)
{
#if 0
PADAPTER padapter = (PADAPTER)pBtCoexist->Adapter;
PBT_MGNT pBtMgnt = &padapter->MgntInfo.BtInfo.BtMgnt;
u8 *cliBuf = pBtCoexist->cliBuf;
u8 i;
if (pBtCoexist->stack_info.profile_notified) {
for (i = 0; i < pBtMgnt->ExtConfig.NumberOfACL; i++) {
if (pBtMgnt->ExtConfig.HCIExtensionVer >= 1) {
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "Bt link type/spec/role", \
BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec],
BtLinkRoleString[pBtMgnt->ExtConfig.aclLink[i].linkRole]);
CL_PRINTF(cliBuf);
} else {
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "Bt link type/spec", \
BtProfileString[pBtMgnt->ExtConfig.aclLink[i].BTProfile],
BtSpecString[pBtMgnt->ExtConfig.aclLink[i].BTCoreSpec]);
CL_PRINTF(cliBuf);
}
}
}
#endif
}
void halbtcoutsrc_DisplayWifiStatus(PBTC_COEXIST pBtCoexist)
{
PADAPTER padapter = pBtCoexist->Adapter;
struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
u8 *cliBuf = pBtCoexist->cli_buf;
s32 wifiRssi = 0, btHsRssi = 0;
BOOLEAN bScan = _FALSE, bLink = _FALSE, bRoam = _FALSE, bWifiBusy = _FALSE, bWifiUnderBMode = _FALSE;
u32 wifiBw = BTC_WIFI_BW_HT20, wifiTrafficDir = BTC_WIFI_TRAFFIC_TX, wifiFreq = BTC_FREQ_2_4G;
u32 wifiLinkStatus = 0x0;
BOOLEAN bBtHsOn = _FALSE, bLowPower = _FALSE;
u8 wifiChnl = 0, wifiP2PChnl = 0, nScanAPNum = 0, FwPSState;
u32 iqk_cnt_total = 0, iqk_cnt_ok = 0, iqk_cnt_fail = 0;
u16 wifiBcnInterval = 0;
PHAL_DATA_TYPE hal = GET_HAL_DATA(padapter);
struct btc_wifi_link_info wifi_link_info;
wifi_link_info = halbtcoutsrc_getwifilinkinfo(pBtCoexist);
switch (wifi_link_info.link_mode) {
case BTC_LINK_NONE:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"None", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
break;
case BTC_LINK_ONLY_GO:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"ONLY_GO", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
break;
case BTC_LINK_ONLY_GC:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"ONLY_GC", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
break;
case BTC_LINK_ONLY_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"ONLY_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
break;
case BTC_LINK_ONLY_AP:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"ONLY_AP", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
break;
case BTC_LINK_2G_MCC_GO_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"24G_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = BTC_FREQ_2_4G;
break;
case BTC_LINK_5G_MCC_GO_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"5G_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = BTC_FREQ_5G;
break;
case BTC_LINK_25G_MCC_GO_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"2BANDS_MCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = BTC_FREQ_25G;
break;
case BTC_LINK_2G_MCC_GC_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"24G_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = BTC_FREQ_2_4G;
break;
case BTC_LINK_5G_MCC_GC_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"5G_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = BTC_FREQ_5G;
break;
case BTC_LINK_25G_MCC_GC_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"2BANDS_MCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = BTC_FREQ_25G;
break;
case BTC_LINK_2G_SCC_GO_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"24G_SCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = BTC_FREQ_2_4G;
break;
case BTC_LINK_5G_SCC_GO_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"5G_SCC_GO_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = BTC_FREQ_5G;
break;
case BTC_LINK_2G_SCC_GC_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"24G_SCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = BTC_FREQ_2_4G;
break;
case BTC_LINK_5G_SCC_GC_STA:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"5G_SCC_GC_STA", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = BTC_FREQ_5G;
break;
default:
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d/ %d/ %d", "WifiLinkMode/HotSpa/Noa/ClientJoin",
"UNKNOWN", wifi_link_info.bhotspot, wifi_link_info.benable_noa, wifi_link_info.bany_client_join_go);
wifiFreq = hal->current_channel > 14 ? BTC_FREQ_5G : BTC_FREQ_2_4G;
break;
}
CL_PRINTF(cliBuf);
wifiLinkStatus = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "STA/vWifi/HS/p2pGo/p2pGc",
((wifiLinkStatus & WIFI_STA_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_AP_CONNECTED) ? 1 : 0),
((wifiLinkStatus & WIFI_HS_CONNECTED) ? 1 : 0), ((wifiLinkStatus & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
((wifiLinkStatus & WIFI_P2P_GC_CONNECTED) ? 1 : 0));
CL_PRINTF(cliBuf);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "Link/ Roam/ Scan",
bLink, bRoam, bScan);
CL_PRINTF(cliBuf);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_TOTAL, &iqk_cnt_total);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_OK, &iqk_cnt_ok);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_IQK_FAIL, &iqk_cnt_fail);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d %s %s",
"IQK All/ OK/ Fail/AutoLoad/FWDL", iqk_cnt_total, iqk_cnt_ok, iqk_cnt_fail,
((halbtcoutsrc_is_autoload_fail(pBtCoexist) == _TRUE) ? "fail":"ok"), ((halbtcoutsrc_is_fw_ready(pBtCoexist) == _TRUE) ? "ok":"fail"));
CL_PRINTF(cliBuf);
if (wifiLinkStatus & WIFI_STA_CONNECTED) {
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ "MAC_FMT"", "IOT Peer/BSSID", GLBtcIotPeerString[padapter->mlmeextpriv.mlmext_info.assoc_AP_vendor], MAC_ARG(get_bssid(&padapter->mlmepriv)));
CL_PRINTF(cliBuf);
}
pBtCoexist->btc_get(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_U2_BEACON_PERIOD, &wifiBcnInterval);
wifiChnl = wifi_link_info.sta_center_channel;
wifiP2PChnl = wifi_link_info.p2p_center_channel;
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dBm/ %d/ %d/ %d", "RSSI/ STA_Chnl/ P2P_Chnl/ BI",
wifiRssi-100, wifiChnl, wifiP2PChnl, wifiBcnInterval);
CL_PRINTF(cliBuf);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
pBtCoexist->btc_get(pBtCoexist, BTC_GET_U1_AP_NUM, &nScanAPNum);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %s/ %s/ %d ", "Band/ BW/ Traffic/ APCnt",
GLBtcWifiFreqString[wifiFreq], ((bWifiUnderBMode) ? "11b" : GLBtcWifiBwString[wifiBw]),
((!bWifiBusy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX == wifiTrafficDir) ? "uplink" : "downlink")),
nScanAPNum);
CL_PRINTF(cliBuf);
/* power status */
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s%s%s", "Power Status", \
((halbtcoutsrc_UnderIps(pBtCoexist) == _TRUE) ? "IPS ON" : "IPS OFF"),
((halbtcoutsrc_UnderLps(pBtCoexist) == _TRUE) ? ", LPS ON" : ", LPS OFF"),
((halbtcoutsrc_Under32K(pBtCoexist) == _TRUE) ? ", 32k" : ""));
CL_PRINTF(cliBuf);
CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x (0x%x/0x%x)", "Power mode cmd(lps/rpwm)",
pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1],
pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3],
pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5],
pBtCoexist->bt_info.lps_val,
pBtCoexist->bt_info.rpwm_val);
CL_PRINTF(cliBuf);
}
void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType)
{
PBTC_COEXIST pBtCoexist;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
switch (dispType) {
case BTC_DBG_DISP_COEX_STATISTICS:
halbtcoutsrc_DisplayCoexStatistics(pBtCoexist);
break;
case BTC_DBG_DISP_BT_LINK_INFO:
halbtcoutsrc_DisplayBtLinkInfo(pBtCoexist);
break;
case BTC_DBG_DISP_WIFI_STATUS:
halbtcoutsrc_DisplayWifiStatus(pBtCoexist);
break;
default:
break;
}
}
/* ************************************
* IO related function
* ************************************ */
u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
return rtw_read8(padapter, RegAddr);
}
u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
return rtw_read16(padapter, RegAddr);
}
u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
return rtw_read32(padapter, RegAddr);
}
void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
rtw_write8(padapter, RegAddr, Data);
}
void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
u8 originalValue, bitShift;
u8 i;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
originalValue = 0;
bitShift = 0;
if (bitMask != 0xff) {
originalValue = rtw_read8(padapter, regAddr);
for (i = 0; i <= 7; i++) {
if ((bitMask >> i) & 0x1)
break;
}
bitShift = i;
data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask);
}
rtw_write8(padapter, regAddr, data1b);
}
void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
rtw_write16(padapter, RegAddr, Data);
}
void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
rtw_write32(padapter, RegAddr, Data);
}
void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data)
{
PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
PADAPTER Adapter = pBtCoexist->Adapter;
if (BTC_INTF_SDIO == pBtCoexist->chip_interface)
rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data);
else
rtw_write8(Adapter, RegAddr, Data);
}
u32 halbtcoutsrc_WaitLIndirectReg_Ready(void *pBtcContext)
{
PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;
u32 delay_count = 0, reg = 0;
if (!btc->chip_para->lte_indirect_access)
return 0;
switch (btc->chip_para->indirect_type) {
case BTC_INDIRECT_1700:
reg = 0x1703;
break;
case BTC_INDIRECT_7C0:
reg = 0x7C3;
break;
default:
return 0;
}
/* wait for ready bit before access */
while (1) {
if ((halbtcoutsrc_Read1Byte(btc, reg) & BIT(5)) == 0) {
rtw_mdelay_os(10);
if (++delay_count >= 10)
break;
} else {
break;
}
}
return delay_count;
}
u32 halbtcoutsrc_ReadLIndirectReg(void *pBtcContext, u16 reg_addr)
{
PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;
u32 val = 0;
if (!btc->chip_para->lte_indirect_access)
return 0;
/* wait for ready bit before access */
halbtcoutsrc_WaitLIndirectReg_Ready(btc);
switch (btc->chip_para->indirect_type) {
case BTC_INDIRECT_1700:
halbtcoutsrc_Write4Byte(btc, 0x1700, 0x800F0000 | reg_addr);
val = halbtcoutsrc_Read4Byte(btc, 0x1708); /* get read data */
break;
case BTC_INDIRECT_7C0:
halbtcoutsrc_Write4Byte(btc, 0x7c0, 0x800F0000 | reg_addr);
val = halbtcoutsrc_Read4Byte(btc, 0x7c8); /* get read data */
break;
}
return val;
}
void halbtcoutsrc_WriteLIndirectReg(void *pBtcContext, u16 reg_addr, u32 bit_mask, u32 reg_value)
{
PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;
u32 val, i = 0, bitpos = 0, reg0, reg1;
if (!btc->chip_para->lte_indirect_access)
return;
if (bit_mask == 0x0)
return;
switch (btc->chip_para->indirect_type) {
case BTC_INDIRECT_1700:
reg0 = 0x1700;
reg1 = 0x1704;
break;
case BTC_INDIRECT_7C0:
reg0 = 0x7C0;
reg1 = 0x7C4;
break;
default:
return;
}
if (bit_mask == 0xffffffff) {
/* wait for ready bit before access 0x1700 */
halbtcoutsrc_WaitLIndirectReg_Ready(btc);
/* put write data */
halbtcoutsrc_Write4Byte(btc, reg1, reg_value);
halbtcoutsrc_Write4Byte(btc, reg0, 0xc00F0000 | reg_addr);
} else {
for (i = 0; i <= 31; i++) {
if (((bit_mask >> i) & 0x1) == 0x1) {
bitpos = i;
break;
}
}
/* read back register value before write */
val = halbtcoutsrc_ReadLIndirectReg(btc, reg_addr);
val = (val & (~bit_mask)) | (reg_value << bitpos);
/* wait for ready bit before access 0x1700 */
halbtcoutsrc_WaitLIndirectReg_Ready(btc);
halbtcoutsrc_Write4Byte(btc, reg1, val); /* put write data */
halbtcoutsrc_Write4Byte(btc, reg0, 0xc00F0000 | reg_addr);
}
}
u16 halbtcoutsrc_Read_scbd(void *pBtcContext, u16* score_board_val)
{
PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;
struct btc_coex_sta *coex_sta = &btc->coex_sta;
const struct btc_chip_para *chip_para = btc->chip_para;
if (!chip_para->scbd_support)
return 0;
*score_board_val = (btc->btc_read_2byte(btc, chip_para->scbd_reg))
& 0x7fff;
coex_sta->score_board_BW = *score_board_val;
return coex_sta->score_board_BW;
}
u32 halbtcoutsrc_Read_scbd_32bit(void *pBtcContext, u32* score_board_val)
{
PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;
struct btc_coex_sta *coex_sta = &btc->coex_sta;
const struct btc_chip_para *chip_para = btc->chip_para;
if (!chip_para->scbd_support)
return 0;
*score_board_val = (btc->btc_read_4byte(btc, chip_para->scbd_reg))
& 0x7fffffff;
coex_sta->score_board_BW_32bit = *score_board_val;
return coex_sta->score_board_BW_32bit;
}
void halbtcoutsrc_Write_scbd(void *pBtcContext, u16 bitpos, u8 state)
{
PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;
struct btc_coex_sta *coex_sta = &btc->coex_sta;
const struct btc_chip_para *chip_para = btc->chip_para;
u16 val = 0x2;
if (!chip_para->scbd_support)
return;
val = val | coex_sta->score_board_WB;
/* for 8822b, Scoreboard[10]: 0: CQDDR off, 1: CQDDR on
* for 8822c, Scoreboard[10]: 0: CQDDR on, 1:CQDDR fix 2M
*/
if (!btc->chip_para->new_scbd10_def && (bitpos & BTC_SCBD_FIX2M)) {
if (state)
val = val & (~BTC_SCBD_FIX2M);
else
val = val | BTC_SCBD_FIX2M;
} else {
if (state)
val = val | bitpos;
else
val = val & (~bitpos);
}
if (val != coex_sta->score_board_WB) {
coex_sta->score_board_WB = val;
val = val | 0x8000;
btc->btc_write_2byte(btc, chip_para->scbd_reg, val);
RTW_DBG("[BTC], write scoreboard 0x%x\n", val);
} else {
RTW_DBG("[BTC], return for nochange\n");
}
}
void halbtcoutsrc_Write_scbd_32bit(void *pBtcContext, u32 bitpos, u8 state)
{
PBTC_COEXIST btc = (PBTC_COEXIST)pBtcContext;
struct btc_coex_sta *coex_sta = &btc->coex_sta;
const struct btc_chip_para *chip_para = btc->chip_para;
u32 val = 0x2;
if (!chip_para->scbd_support)
return;
val = val | coex_sta->score_board_WB;
/* for 8822b, Scoreboard[10]: 0: CQDDR off, 1: CQDDR on
* for 8822c, Scoreboard[10]: 0: CQDDR on, 1:CQDDR fix 2M
*/
if (!btc->chip_para->new_scbd10_def && (bitpos & BTC_SCBD_FIX2M)) {
if (state)
val = val & (~BTC_SCBD_FIX2M);
else
val = val | BTC_SCBD_FIX2M;
} else {
if (state)
val = val | bitpos;
else
val = val & (~bitpos);
}
if (val != coex_sta->score_board_WB_32bit) {
coex_sta->score_board_WB_32bit = val;
val = val | 0x80000000;
btc->btc_write_4byte(btc, chip_para->scbd_reg, val);
RTW_DBG("[BTC], write scoreboard 0x%x\n", val);
} else {
RTW_DBG("[BTC], return for nochange\n");
}
}
void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
phy_set_bb_reg(padapter, RegAddr, BitMask, Data);
}
u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
return phy_query_bb_reg(padapter, RegAddr, BitMask);
}
void halbtcoutsrc_SetRfReg(void *pBtcContext, enum rf_path eRFPath, u32 RegAddr, u32 BitMask, u32 Data)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
phy_set_rf_reg(padapter, eRFPath, RegAddr, BitMask, Data);
}
u32 halbtcoutsrc_GetRfReg(void *pBtcContext, enum rf_path eRFPath, u32 RegAddr, u32 BitMask)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
return phy_query_rf_reg(padapter, eRFPath, RegAddr, BitMask);
}
u16 halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data)
{
PBTC_COEXIST pBtCoexist;
u16 ret = BT_STATUS_BT_OP_SUCCESS;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
Data = cpu_to_le32(Data);
op_code = BT_OP_WRITE_REG_VALUE;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Data, 3);
if (status != BT_STATUS_BT_OP_SUCCESS)
ret = SET_BT_MP_OPER_RET(op_code, status);
else {
buf[0] = RegType;
*(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
op_code = BT_OP_WRITE_REG_ADDR;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
if (status != BT_STATUS_BT_OP_SUCCESS)
ret = SET_BT_MP_OPER_RET(op_code, status);
}
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return ret;
}
u8 halbtcoutsrc_SetBtAntDetection(void *pBtcContext, u8 txTime, u8 btChnl)
{
/* Always return _FALSE since we don't implement this yet */
#if 0
PBTC_COEXIST pBtCoexist = (PBTC_COEXIST)pBtcContext;
PADAPTER Adapter = pBtCoexist->Adapter;
u8 btCanTx = 0;
BOOLEAN bStatus = FALSE;
bStatus = NDBG_SetBtAntDetection(Adapter, txTime, btChnl, &btCanTx);
if (bStatus && btCanTx)
return _TRUE;
else
return _FALSE;
#else
return _FALSE;
#endif
}
u8 halbtcoutsrc_SetBtTRXMASK(void *pBtcContext, u8 bt_trx_mask)
{
PBTC_COEXIST pBtCoexist;
u8 bStatus = _FALSE;
u8 btCanTx = 0;
u16 ret = BT_STATUS_BT_OP_SUCCESS;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter) || IS_HARDWARE_TYPE_8723D(pBtCoexist->Adapter)
|| IS_HARDWARE_TYPE_8821C(pBtCoexist->Adapter)) {
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
u8 len = 0;
_irqL irqL;
u8 op_code;
u8 status;
if (IS_HARDWARE_TYPE_8723B(pBtCoexist->Adapter)) {
buf[0] = bt_trx_mask;
len = 1;
} else {
buf[0] = (bt_trx_mask & 0x80) >> 7;
buf[1] = bt_trx_mask & 0x7f;
len = 2;
}
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
op_code = BT_OP_SET_BT_TRX_MASK;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, len);
if (status != BT_STATUS_BT_OP_SUCCESS)
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
}
if (ret == BT_STATUS_BT_OP_SUCCESS)
return _TRUE;
else
return _FALSE;
}
u16 halbtcoutsrc_GetBtReg_with_status(void *pBtcContext, u8 RegType, u32 RegAddr, u32 *data)
{
PBTC_COEXIST pBtCoexist;
u16 ret = BT_STATUS_BT_OP_SUCCESS;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
buf[0] = RegType;
*(u16 *)(buf + 1) = cpu_to_le16((u16)RegAddr);
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
op_code = BT_OP_READ_REG;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 3);
if (status == BT_STATUS_BT_OP_SUCCESS)
*data = le16_to_cpu(*(u16 *)GLBtcBtMpRptRsp);
else
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return ret;
}
u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr)
{
u32 regVal;
return (BT_STATUS_BT_OP_SUCCESS == halbtcoutsrc_GetBtReg_with_status(pBtcContext, RegType, RegAddr, &regVal)) ? regVal : 0xffffffff;
}
u16 halbtcoutsrc_setbttestmode(void *pBtcContext, u8 Type)
{
PBTC_COEXIST pBtCoexist;
u16 ret = BT_STATUS_BT_OP_SUCCESS;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
_irqL irqL;
u8 op_code;
u8 status;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
Type = cpu_to_le32(Type);
op_code = BT_OP_SET_BT_TEST_MODE_VAL;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, (u8 *)&Type, 3);
if (status != BT_STATUS_BT_OP_SUCCESS)
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return ret;
}
void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer)
{
PBTC_COEXIST pBtCoexist;
PADAPTER padapter;
s32 ret = 0;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
padapter = pBtCoexist->Adapter;
ret = rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer);
#ifdef CONFIG_RTL8192F
if (ret == _SUCCESS) {
switch (elementId) {
case H2C_BT_INFO:
case H2C_BT_IGNORE_WLANACT:
case H2C_WL_OPMODE:
case H2C_BT_MP_OPER:
case H2C_BT_CONTROL:
rtw_msleep_os(20);
break;
}
}
#endif
}
static void halbtcoutsrc_coex_offload_init(void)
{
u8 i;
gl_coex_offload.h2c_req_num = 0;
gl_coex_offload.cnt_h2c_sent = 0;
gl_coex_offload.cnt_c2h_ack = 0;
gl_coex_offload.cnt_c2h_ind = 0;
for (i = 0; i < COL_MAX_H2C_REQ_NUM; i++)
init_completion(&gl_coex_offload.c2h_event[i]);
}
static COL_H2C_STATUS halbtcoutsrc_send_h2c(PADAPTER Adapter, PCOL_H2C pcol_h2c, u16 h2c_cmd_len)
{
COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK;
u8 i;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
reinit_completion(&gl_coex_offload.c2h_event[pcol_h2c->req_num]); /* set event to un signaled state */
#else
INIT_COMPLETION(gl_coex_offload.c2h_event[pcol_h2c->req_num]);
#endif
if (TRUE) {
#if 0 /*(USE_HAL_MAC_API == 1) */
if (RT_STATUS_SUCCESS == HAL_MAC_Send_BT_COEX(&GET_HAL_MAC_INFO(Adapter), (u8 *)(pcol_h2c), (u32)h2c_cmd_len, 1)) {
if (!wait_for_completion_timeout(&gl_coex_offload.c2h_event[pcol_h2c->req_num], 20)) {
h2c_status = COL_STATUS_H2C_TIMTOUT;
}
} else {
h2c_status = COL_STATUS_H2C_HALMAC_FAIL;
}
#endif
}
return h2c_status;
}
static COL_H2C_STATUS halbtcoutsrc_check_c2h_ack(PADAPTER Adapter, PCOL_SINGLE_H2C_RECORD pH2cRecord)
{
COL_H2C_STATUS c2h_status = COL_STATUS_C2H_OK;
PCOL_H2C p_h2c_cmd = (PCOL_H2C)&pH2cRecord->h2c_buf[0];
u8 req_num = p_h2c_cmd->req_num;
PCOL_C2H_ACK p_c2h_ack = (PCOL_C2H_ACK)&gl_coex_offload.c2h_ack_buf[req_num];
if ((COL_C2H_ACK_HDR_LEN + p_c2h_ack->ret_len) > gl_coex_offload.c2h_ack_len[req_num]) {
c2h_status = COL_STATUS_COEX_DATA_OVERFLOW;
return c2h_status;
}
/* else */
{
_rtw_memmove(&pH2cRecord->c2h_ack_buf[0], &gl_coex_offload.c2h_ack_buf[req_num], gl_coex_offload.c2h_ack_len[req_num]);
pH2cRecord->c2h_ack_len = gl_coex_offload.c2h_ack_len[req_num];
}
if (p_c2h_ack->req_num != p_h2c_cmd->req_num) {
c2h_status = COL_STATUS_C2H_REQ_NUM_MISMATCH;
} else if (p_c2h_ack->opcode_ver != p_h2c_cmd->opcode_ver) {
c2h_status = COL_STATUS_C2H_OPCODE_VER_MISMATCH;
} else {
c2h_status = p_c2h_ack->status;
}
return c2h_status;
}
COL_H2C_STATUS halbtcoutsrc_CoexH2cProcess(void *pBtCoexist,
u8 opcode, u8 opcode_ver, u8 *ph2c_par, u8 h2c_par_len)
{
PADAPTER Adapter = ((struct btc_coexist *)pBtCoexist)->Adapter;
u8 H2C_Parameter[BTC_TMP_BUF_SHORT] = {0};
PCOL_H2C pcol_h2c = (PCOL_H2C)&H2C_Parameter[0];
u16 paraLen = 0;
COL_H2C_STATUS h2c_status = COL_STATUS_C2H_OK, c2h_status = COL_STATUS_C2H_OK;
COL_H2C_STATUS ret_status = COL_STATUS_C2H_OK;
u16 i, col_h2c_len = 0;
pcol_h2c->opcode = opcode;
pcol_h2c->opcode_ver = opcode_ver;
pcol_h2c->req_num = gl_coex_offload.h2c_req_num;
gl_coex_offload.h2c_req_num++;
gl_coex_offload.h2c_req_num %= 16;
_rtw_memmove(&pcol_h2c->buf[0], ph2c_par, h2c_par_len);
col_h2c_len = h2c_par_len + 2; /* 2=sizeof(OPCode, OPCode_version and Request number) */
BT_PrintData(Adapter, "[COL], H2C cmd: ", col_h2c_len, H2C_Parameter);
gl_coex_offload.cnt_h2c_sent++;
gl_coex_offload.h2c_record[opcode].count++;
gl_coex_offload.h2c_record[opcode].h2c_len = col_h2c_len;
_rtw_memmove((void *)&gl_coex_offload.h2c_record[opcode].h2c_buf[0], (void *)pcol_h2c, col_h2c_len);
h2c_status = halbtcoutsrc_send_h2c(Adapter, pcol_h2c, col_h2c_len);
gl_coex_offload.h2c_record[opcode].c2h_ack_len = 0;
if (COL_STATUS_C2H_OK == h2c_status) {
/* if reach here, it means H2C get the correct c2h response, */
c2h_status = halbtcoutsrc_check_c2h_ack(Adapter, &gl_coex_offload.h2c_record[opcode]);
ret_status = c2h_status;
} else {
/* check h2c status error, return error status code to upper layer. */
ret_status = h2c_status;
}
gl_coex_offload.h2c_record[opcode].status[ret_status]++;
gl_coex_offload.status[ret_status]++;
return ret_status;
}
u8 halbtcoutsrc_GetAntDetValFromBt(void *pBtcContext)
{
/* Always return 0 since we don't implement this yet */
#if 0
struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext;
PADAPTER Adapter = pBtCoexist->Adapter;
u8 AntDetVal = 0x0;
u8 opcodeVer = 1;
BOOLEAN status = false;
status = NDBG_GetAntDetValFromBt(Adapter, opcodeVer, &AntDetVal);
RT_TRACE(COMP_DBG, DBG_LOUD, ("$$$ halbtcoutsrc_GetAntDetValFromBt(): status = %d, feature = %x\n", status, AntDetVal));
return AntDetVal;
#else
return 0;
#endif
}
u8 halbtcoutsrc_GetBleScanTypeFromBt(void *pBtcContext)
{
PBTC_COEXIST pBtCoexist;
u32 ret = BT_STATUS_BT_OP_SUCCESS;
u8 data = 0;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL);
op_code = BT_OP_GET_BT_BLE_SCAN_TYPE;
status = _btmpoper_cmd(pBtCoexist, op_code, 0, buf, 0);
if (status == BT_STATUS_BT_OP_SUCCESS)
data = *(u8 *)GLBtcBtMpRptRsp;
else
ret = SET_BT_MP_OPER_RET(op_code, status);
_exit_critical_mutex(&GLBtcBtMpOperLock, &irqL);
} else
ret = BT_STATUS_NOT_IMPLEMENT;
return data;
}
u32 halbtcoutsrc_GetBleScanParaFromBt(void *pBtcContext, u8 scanType)
{
PBTC_COEXIST pBtCoexist;
u32 ret = BT_STATUS_BT_OP_SUCCESS;
u32 data = 0;
pBtCoexist = (PBTC_COEXIST)pBtcContext;
if (halbtcoutsrc_IsHwMailboxExist(pBtCoexist) == _TRUE) {
u8 buf[3] = {0};
_irqL irqL;
u8 op_code;
u8 status;
buf[0] = scanType;
_enter_critical_mutex(&GLBtcBtMpOperLock, &irqL)