1 // SPDX-License-Identifier: GPL-2.0 2 /****************************************************************************** 3 * 4 * Copyright(c) 2013 Realtek Corporation. All rights reserved. 5 * 6 ******************************************************************************/ 7 #define __HAL_BTCOEX_C__ 8 9 #include <hal_data.h> 10 #include <rtw_debug.h> 11 #include <hal_btcoex.h> 12 #include <Mp_Precomp.h> 13 14 /* Global variables */ 15 16 struct btc_coexist GLBtCoexist; 17 static u8 GLBtcWiFiInScanState; 18 static u8 GLBtcWiFiInIQKState; 19 20 static u8 GLBtcDbgBuf[BT_TMP_BUF_SIZE]; 21 22 struct btcdbginfo { /* _btcoexdbginfo */ 23 u8 *info; 24 u32 size; /* buffer total size */ 25 u32 len; /* now used length */ 26 }; 27 28 static struct btcdbginfo GLBtcDbgInfo; 29 30 #define BT_Operation(Adapter) false 31 32 static void DBG_BT_INFO_INIT(struct btcdbginfo *pinfo, u8 *pbuf, u32 size) 33 { 34 if (!pinfo) 35 return; 36 37 memset(pinfo, 0, sizeof(struct btcdbginfo)); 38 39 if (pbuf && size) { 40 pinfo->info = pbuf; 41 pinfo->size = size; 42 } 43 } 44 45 void DBG_BT_INFO(u8 *dbgmsg) 46 { 47 struct btcdbginfo *pinfo; 48 u32 msglen; 49 u8 *pbuf; 50 51 52 pinfo = &GLBtcDbgInfo; 53 54 if (!pinfo->info) 55 return; 56 57 msglen = strlen(dbgmsg); 58 if (pinfo->len + msglen > pinfo->size) 59 return; 60 61 pbuf = pinfo->info + pinfo->len; 62 memcpy(pbuf, dbgmsg, msglen); 63 pinfo->len += msglen; 64 } 65 66 /* */ 67 /* Debug related function */ 68 /* */ 69 static u8 halbtcoutsrc_IsBtCoexistAvailable(struct btc_coexist *pBtCoexist) 70 { 71 if (!pBtCoexist->bBinded || !pBtCoexist->Adapter) 72 return false; 73 74 return true; 75 } 76 77 static void halbtcoutsrc_LeaveLps(struct btc_coexist *pBtCoexist) 78 { 79 struct adapter *padapter; 80 81 82 padapter = pBtCoexist->Adapter; 83 84 pBtCoexist->btInfo.bBtCtrlLps = true; 85 pBtCoexist->btInfo.bBtLpsOn = false; 86 87 rtw_btcoex_LPS_Leave(padapter); 88 } 89 90 static void halbtcoutsrc_EnterLps(struct btc_coexist *pBtCoexist) 91 { 92 struct adapter *padapter; 93 94 95 padapter = pBtCoexist->Adapter; 96 97 pBtCoexist->btInfo.bBtCtrlLps = true; 98 pBtCoexist->btInfo.bBtLpsOn = true; 99 100 rtw_btcoex_LPS_Enter(padapter); 101 } 102 103 static void halbtcoutsrc_NormalLps(struct btc_coexist *pBtCoexist) 104 { 105 struct adapter *padapter; 106 107 padapter = pBtCoexist->Adapter; 108 109 if (pBtCoexist->btInfo.bBtCtrlLps) { 110 pBtCoexist->btInfo.bBtLpsOn = false; 111 rtw_btcoex_LPS_Leave(padapter); 112 pBtCoexist->btInfo.bBtCtrlLps = false; 113 114 /* recover the LPS state to the original */ 115 } 116 } 117 118 /* 119 * Constraint: 120 * 1. this function will request pwrctrl->lock 121 */ 122 static void halbtcoutsrc_LeaveLowPower(struct btc_coexist *pBtCoexist) 123 { 124 struct adapter *padapter; 125 s32 ready; 126 unsigned long stime; 127 unsigned long utime; 128 u32 timeout; /* unit: ms */ 129 130 131 padapter = pBtCoexist->Adapter; 132 ready = _FAIL; 133 #ifdef LPS_RPWM_WAIT_MS 134 timeout = LPS_RPWM_WAIT_MS; 135 #else /* !LPS_RPWM_WAIT_MS */ 136 timeout = 30; 137 #endif /* !LPS_RPWM_WAIT_MS */ 138 139 stime = jiffies; 140 do { 141 ready = rtw_register_task_alive(padapter, BTCOEX_ALIVE); 142 if (_SUCCESS == ready) 143 break; 144 145 utime = jiffies_to_msecs(jiffies - stime); 146 if (utime > timeout) 147 break; 148 149 msleep(1); 150 } while (1); 151 } 152 153 /* 154 * Constraint: 155 * 1. this function will request pwrctrl->lock 156 */ 157 static void halbtcoutsrc_NormalLowPower(struct btc_coexist *pBtCoexist) 158 { 159 struct adapter *padapter; 160 161 162 padapter = pBtCoexist->Adapter; 163 rtw_unregister_task_alive(padapter, BTCOEX_ALIVE); 164 } 165 166 static void halbtcoutsrc_DisableLowPower(struct btc_coexist *pBtCoexist, u8 bLowPwrDisable) 167 { 168 pBtCoexist->btInfo.bBtDisableLowPwr = bLowPwrDisable; 169 if (bLowPwrDisable) 170 halbtcoutsrc_LeaveLowPower(pBtCoexist); /* leave 32k low power. */ 171 else 172 halbtcoutsrc_NormalLowPower(pBtCoexist); /* original 32k low power behavior. */ 173 } 174 175 static void halbtcoutsrc_AggregationCheck(struct btc_coexist *pBtCoexist) 176 { 177 struct adapter *padapter; 178 bool bNeedToAct; 179 180 181 padapter = pBtCoexist->Adapter; 182 bNeedToAct = false; 183 184 if (pBtCoexist->btInfo.bRejectAggPkt) { 185 rtw_btcoex_RejectApAggregatedPacket(padapter, true); 186 } else { 187 if (pBtCoexist->btInfo.bPreBtCtrlAggBufSize != 188 pBtCoexist->btInfo.bBtCtrlAggBufSize) { 189 bNeedToAct = true; 190 pBtCoexist->btInfo.bPreBtCtrlAggBufSize = pBtCoexist->btInfo.bBtCtrlAggBufSize; 191 } 192 193 if (pBtCoexist->btInfo.bBtCtrlAggBufSize) { 194 if (pBtCoexist->btInfo.preAggBufSize != 195 pBtCoexist->btInfo.aggBufSize){ 196 bNeedToAct = true; 197 } 198 pBtCoexist->btInfo.preAggBufSize = pBtCoexist->btInfo.aggBufSize; 199 } 200 201 if (bNeedToAct) { 202 rtw_btcoex_RejectApAggregatedPacket(padapter, true); 203 rtw_btcoex_RejectApAggregatedPacket(padapter, false); 204 } 205 } 206 } 207 208 static u8 halbtcoutsrc_IsWifiBusy(struct adapter *padapter) 209 { 210 struct mlme_priv *pmlmepriv; 211 212 213 pmlmepriv = &padapter->mlmepriv; 214 215 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) { 216 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) 217 return true; 218 if (pmlmepriv->LinkDetectInfo.bBusyTraffic) 219 return true; 220 } 221 222 return false; 223 } 224 225 static u32 _halbtcoutsrc_GetWifiLinkStatus(struct adapter *padapter) 226 { 227 struct mlme_priv *pmlmepriv; 228 u8 bp2p; 229 u32 portConnectedStatus; 230 231 232 pmlmepriv = &padapter->mlmepriv; 233 bp2p = false; 234 portConnectedStatus = 0; 235 236 if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == true) { 237 if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) { 238 if (bp2p) 239 portConnectedStatus |= WIFI_P2P_GO_CONNECTED; 240 else 241 portConnectedStatus |= WIFI_AP_CONNECTED; 242 } else { 243 if (bp2p) 244 portConnectedStatus |= WIFI_P2P_GC_CONNECTED; 245 else 246 portConnectedStatus |= WIFI_STA_CONNECTED; 247 } 248 } 249 250 return portConnectedStatus; 251 } 252 253 static u32 halbtcoutsrc_GetWifiLinkStatus(struct btc_coexist *pBtCoexist) 254 { 255 /* */ 256 /* return value: */ 257 /* [31:16]=> connected port number */ 258 /* [15:0]=> port connected bit define */ 259 /* */ 260 261 struct adapter *padapter; 262 u32 retVal; 263 u32 portConnectedStatus, numOfConnectedPort; 264 265 266 padapter = pBtCoexist->Adapter; 267 portConnectedStatus = 0; 268 numOfConnectedPort = 0; 269 270 retVal = _halbtcoutsrc_GetWifiLinkStatus(padapter); 271 if (retVal) { 272 portConnectedStatus |= retVal; 273 numOfConnectedPort++; 274 } 275 276 retVal = (numOfConnectedPort << 16) | portConnectedStatus; 277 278 return retVal; 279 } 280 281 static u32 halbtcoutsrc_GetBtPatchVer(struct btc_coexist *pBtCoexist) 282 { 283 return pBtCoexist->btInfo.btRealFwVer; 284 } 285 286 static s32 halbtcoutsrc_GetWifiRssi(struct adapter *padapter) 287 { 288 struct hal_com_data *pHalData = GET_HAL_DATA(padapter); 289 290 return pHalData->dmpriv.EntryMinUndecoratedSmoothedPWDB; 291 } 292 293 static u8 halbtcoutsrc_GetWifiScanAPNum(struct adapter *padapter) 294 { 295 struct mlme_ext_priv *pmlmeext; 296 static u8 scan_AP_num; 297 298 pmlmeext = &padapter->mlmeextpriv; 299 300 if (!GLBtcWiFiInScanState) { 301 if (pmlmeext->sitesurvey_res.bss_cnt > 0xFF) 302 scan_AP_num = 0xFF; 303 else 304 scan_AP_num = (u8)pmlmeext->sitesurvey_res.bss_cnt; 305 } 306 307 return scan_AP_num; 308 } 309 310 static u8 halbtcoutsrc_Get(void *pBtcContext, u8 getType, void *pOutBuf) 311 { 312 struct btc_coexist *pBtCoexist; 313 struct adapter *padapter; 314 struct hal_com_data *pHalData; 315 struct mlme_ext_priv *mlmeext; 316 u8 *pu8; 317 s32 *pS4Tmp; 318 u32 *pU4Tmp; 319 u8 ret; 320 321 322 pBtCoexist = (struct btc_coexist *)pBtcContext; 323 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 324 return false; 325 326 padapter = pBtCoexist->Adapter; 327 pHalData = GET_HAL_DATA(padapter); 328 mlmeext = &padapter->mlmeextpriv; 329 pu8 = pOutBuf; 330 pS4Tmp = pOutBuf; 331 pU4Tmp = pOutBuf; 332 ret = true; 333 334 switch (getType) { 335 case BTC_GET_BL_HS_OPERATION: 336 *pu8 = false; 337 ret = false; 338 break; 339 340 case BTC_GET_BL_HS_CONNECTING: 341 *pu8 = false; 342 ret = false; 343 break; 344 345 case BTC_GET_BL_WIFI_CONNECTED: 346 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE); 347 break; 348 349 case BTC_GET_BL_WIFI_BUSY: 350 *pu8 = halbtcoutsrc_IsWifiBusy(padapter); 351 break; 352 353 case BTC_GET_BL_WIFI_SCAN: 354 /* Use the value of the new variable GLBtcWiFiInScanState to judge whether WiFi is in scan state or not, since the originally used flag 355 WIFI_SITE_MONITOR in fwstate may not be cleared in time */ 356 *pu8 = GLBtcWiFiInScanState; 357 break; 358 359 case BTC_GET_BL_WIFI_LINK: 360 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING); 361 break; 362 363 case BTC_GET_BL_WIFI_ROAM: 364 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_UNDER_LINKING); 365 break; 366 367 case BTC_GET_BL_WIFI_4_WAY_PROGRESS: 368 *pu8 = false; 369 break; 370 371 case BTC_GET_BL_WIFI_AP_MODE_ENABLE: 372 *pu8 = check_fwstate(&padapter->mlmepriv, WIFI_AP_STATE); 373 break; 374 375 case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION: 376 *pu8 = padapter->securitypriv.dot11PrivacyAlgrthm != 0; 377 break; 378 379 case BTC_GET_BL_WIFI_UNDER_B_MODE: 380 if (mlmeext->cur_wireless_mode == WIRELESS_11B) 381 *pu8 = true; 382 else 383 *pu8 = false; 384 break; 385 386 case BTC_GET_BL_WIFI_IS_IN_MP_MODE: 387 *pu8 = false; 388 break; 389 390 case BTC_GET_BL_EXT_SWITCH: 391 *pu8 = false; 392 break; 393 394 case BTC_GET_S4_WIFI_RSSI: 395 *pS4Tmp = halbtcoutsrc_GetWifiRssi(padapter); 396 break; 397 398 case BTC_GET_S4_HS_RSSI: 399 *pS4Tmp = 0; 400 ret = false; 401 break; 402 403 case BTC_GET_U4_WIFI_BW: 404 if (IsLegacyOnly(mlmeext->cur_wireless_mode)) 405 *pU4Tmp = BTC_WIFI_BW_LEGACY; 406 else if (pHalData->CurrentChannelBW == CHANNEL_WIDTH_20) 407 *pU4Tmp = BTC_WIFI_BW_HT20; 408 else 409 *pU4Tmp = BTC_WIFI_BW_HT40; 410 break; 411 412 case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION: 413 { 414 struct rt_link_detect_t *plinkinfo; 415 plinkinfo = &padapter->mlmepriv.LinkDetectInfo; 416 417 if (plinkinfo->NumTxOkInPeriod > plinkinfo->NumRxOkInPeriod) 418 *pU4Tmp = BTC_WIFI_TRAFFIC_TX; 419 else 420 *pU4Tmp = BTC_WIFI_TRAFFIC_RX; 421 } 422 break; 423 424 case BTC_GET_U4_WIFI_FW_VER: 425 *pU4Tmp = pHalData->FirmwareVersion << 16; 426 *pU4Tmp |= pHalData->FirmwareSubVersion; 427 break; 428 429 case BTC_GET_U4_WIFI_LINK_STATUS: 430 *pU4Tmp = halbtcoutsrc_GetWifiLinkStatus(pBtCoexist); 431 break; 432 433 case BTC_GET_U4_BT_PATCH_VER: 434 *pU4Tmp = halbtcoutsrc_GetBtPatchVer(pBtCoexist); 435 break; 436 437 case BTC_GET_U1_WIFI_DOT11_CHNL: 438 *pu8 = padapter->mlmeextpriv.cur_channel; 439 break; 440 441 case BTC_GET_U1_WIFI_CENTRAL_CHNL: 442 *pu8 = pHalData->CurrentChannel; 443 break; 444 445 case BTC_GET_U1_WIFI_HS_CHNL: 446 *pu8 = 0; 447 ret = false; 448 break; 449 450 case BTC_GET_U1_MAC_PHY_MODE: 451 *pu8 = BTC_SMSP; 452 /* *pU1Tmp = BTC_DMSP; */ 453 /* *pU1Tmp = BTC_DMDP; */ 454 /* *pU1Tmp = BTC_MP_UNKNOWN; */ 455 break; 456 457 case BTC_GET_U1_AP_NUM: 458 *pu8 = halbtcoutsrc_GetWifiScanAPNum(padapter); 459 break; 460 461 /* 1Ant =========== */ 462 case BTC_GET_U1_LPS_MODE: 463 *pu8 = padapter->dvobj->pwrctl_priv.pwr_mode; 464 break; 465 466 default: 467 ret = false; 468 break; 469 } 470 471 return ret; 472 } 473 474 static u8 halbtcoutsrc_Set(void *pBtcContext, u8 setType, void *pInBuf) 475 { 476 struct btc_coexist *pBtCoexist; 477 struct adapter *padapter; 478 u8 *pu8; 479 u32 *pU4Tmp; 480 u8 ret; 481 482 483 pBtCoexist = (struct btc_coexist *)pBtcContext; 484 padapter = pBtCoexist->Adapter; 485 pu8 = pInBuf; 486 pU4Tmp = pInBuf; 487 ret = true; 488 489 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 490 return false; 491 492 switch (setType) { 493 /* set some u8 type variables. */ 494 case BTC_SET_BL_BT_DISABLE: 495 pBtCoexist->btInfo.bBtDisabled = *pu8; 496 break; 497 498 case BTC_SET_BL_BT_TRAFFIC_BUSY: 499 pBtCoexist->btInfo.bBtBusy = *pu8; 500 break; 501 502 case BTC_SET_BL_BT_LIMITED_DIG: 503 pBtCoexist->btInfo.bLimitedDig = *pu8; 504 break; 505 506 case BTC_SET_BL_FORCE_TO_ROAM: 507 pBtCoexist->btInfo.bForceToRoam = *pu8; 508 break; 509 510 case BTC_SET_BL_TO_REJ_AP_AGG_PKT: 511 pBtCoexist->btInfo.bRejectAggPkt = *pu8; 512 break; 513 514 case BTC_SET_BL_BT_CTRL_AGG_SIZE: 515 pBtCoexist->btInfo.bBtCtrlAggBufSize = *pu8; 516 break; 517 518 case BTC_SET_BL_INC_SCAN_DEV_NUM: 519 pBtCoexist->btInfo.bIncreaseScanDevNum = *pu8; 520 break; 521 522 case BTC_SET_BL_BT_TX_RX_MASK: 523 pBtCoexist->btInfo.bBtTxRxMask = *pu8; 524 break; 525 526 /* set some u8 type variables. */ 527 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON: 528 pBtCoexist->btInfo.rssiAdjustForAgcTableOn = *pu8; 529 break; 530 531 case BTC_SET_U1_AGG_BUF_SIZE: 532 pBtCoexist->btInfo.aggBufSize = *pu8; 533 break; 534 535 /* the following are some action which will be triggered */ 536 case BTC_SET_ACT_GET_BT_RSSI: 537 ret = false; 538 break; 539 540 case BTC_SET_ACT_AGGREGATE_CTRL: 541 halbtcoutsrc_AggregationCheck(pBtCoexist); 542 break; 543 544 /* 1Ant =========== */ 545 /* set some u8 type variables. */ 546 case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE: 547 pBtCoexist->btInfo.rssiAdjustFor1AntCoexType = *pu8; 548 break; 549 550 case BTC_SET_U1_LPS_VAL: 551 pBtCoexist->btInfo.lpsVal = *pu8; 552 break; 553 554 case BTC_SET_U1_RPWM_VAL: 555 pBtCoexist->btInfo.rpwmVal = *pu8; 556 break; 557 558 /* the following are some action which will be triggered */ 559 case BTC_SET_ACT_LEAVE_LPS: 560 halbtcoutsrc_LeaveLps(pBtCoexist); 561 break; 562 563 case BTC_SET_ACT_ENTER_LPS: 564 halbtcoutsrc_EnterLps(pBtCoexist); 565 break; 566 567 case BTC_SET_ACT_NORMAL_LPS: 568 halbtcoutsrc_NormalLps(pBtCoexist); 569 break; 570 571 case BTC_SET_ACT_DISABLE_LOW_POWER: 572 halbtcoutsrc_DisableLowPower(pBtCoexist, *pu8); 573 break; 574 575 case BTC_SET_ACT_UPDATE_RAMASK: 576 pBtCoexist->btInfo.raMask = *pU4Tmp; 577 578 if (check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE) == true) { 579 struct sta_info *psta; 580 struct wlan_bssid_ex *cur_network; 581 582 cur_network = &padapter->mlmeextpriv.mlmext_info.network; 583 psta = rtw_get_stainfo(&padapter->stapriv, cur_network->MacAddress); 584 rtw_hal_update_ra_mask(psta, 0); 585 } 586 break; 587 588 case BTC_SET_ACT_SEND_MIMO_PS: 589 ret = false; 590 break; 591 592 case BTC_SET_ACT_CTRL_BT_INFO: 593 ret = false; 594 break; 595 596 case BTC_SET_ACT_CTRL_BT_COEX: 597 ret = false; 598 break; 599 case BTC_SET_ACT_CTRL_8723B_ANT: 600 ret = false; 601 break; 602 /* */ 603 default: 604 ret = false; 605 break; 606 } 607 608 return ret; 609 } 610 611 static void halbtcoutsrc_DisplayFwPwrModeCmd(struct btc_coexist *pBtCoexist) 612 { 613 u8 *cliBuf = pBtCoexist->cliBuf; 614 615 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x ", "Power mode cmd ", \ 616 pBtCoexist->pwrModeVal[0], pBtCoexist->pwrModeVal[1], 617 pBtCoexist->pwrModeVal[2], pBtCoexist->pwrModeVal[3], 618 pBtCoexist->pwrModeVal[4], pBtCoexist->pwrModeVal[5]); 619 CL_PRINTF(cliBuf); 620 } 621 622 /* */ 623 /* IO related function */ 624 /* */ 625 static u8 halbtcoutsrc_Read1Byte(void *pBtcContext, u32 RegAddr) 626 { 627 struct btc_coexist *pBtCoexist; 628 struct adapter *padapter; 629 630 631 pBtCoexist = (struct btc_coexist *)pBtcContext; 632 padapter = pBtCoexist->Adapter; 633 634 return rtw_read8(padapter, RegAddr); 635 } 636 637 static u16 halbtcoutsrc_Read2Byte(void *pBtcContext, u32 RegAddr) 638 { 639 struct btc_coexist *pBtCoexist; 640 struct adapter *padapter; 641 642 643 pBtCoexist = (struct btc_coexist *)pBtcContext; 644 padapter = pBtCoexist->Adapter; 645 646 return rtw_read16(padapter, RegAddr); 647 } 648 649 static u32 halbtcoutsrc_Read4Byte(void *pBtcContext, u32 RegAddr) 650 { 651 struct btc_coexist *pBtCoexist; 652 struct adapter *padapter; 653 654 655 pBtCoexist = (struct btc_coexist *)pBtcContext; 656 padapter = pBtCoexist->Adapter; 657 658 return rtw_read32(padapter, RegAddr); 659 } 660 661 static void halbtcoutsrc_Write1Byte(void *pBtcContext, u32 RegAddr, u8 Data) 662 { 663 struct btc_coexist *pBtCoexist; 664 struct adapter *padapter; 665 666 667 pBtCoexist = (struct btc_coexist *)pBtcContext; 668 padapter = pBtCoexist->Adapter; 669 670 rtw_write8(padapter, RegAddr, Data); 671 } 672 673 static void halbtcoutsrc_BitMaskWrite1Byte(void *pBtcContext, u32 regAddr, u8 bitMask, u8 data1b) 674 { 675 struct btc_coexist *pBtCoexist; 676 struct adapter *padapter; 677 u8 originalValue, bitShift; 678 u8 i; 679 680 681 pBtCoexist = (struct btc_coexist *)pBtcContext; 682 padapter = pBtCoexist->Adapter; 683 originalValue = 0; 684 bitShift = 0; 685 686 if (bitMask != 0xFF) { 687 originalValue = rtw_read8(padapter, regAddr); 688 689 for (i = 0; i <= 7; i++) { 690 if ((bitMask >> i) & 0x1) 691 break; 692 } 693 bitShift = i; 694 695 data1b = (originalValue & ~bitMask) | ((data1b << bitShift) & bitMask); 696 } 697 698 rtw_write8(padapter, regAddr, data1b); 699 } 700 701 static void halbtcoutsrc_Write2Byte(void *pBtcContext, u32 RegAddr, u16 Data) 702 { 703 struct btc_coexist *pBtCoexist; 704 struct adapter *padapter; 705 706 707 pBtCoexist = (struct btc_coexist *)pBtcContext; 708 padapter = pBtCoexist->Adapter; 709 710 rtw_write16(padapter, RegAddr, Data); 711 } 712 713 static void halbtcoutsrc_Write4Byte(void *pBtcContext, u32 RegAddr, u32 Data) 714 { 715 struct btc_coexist *pBtCoexist; 716 struct adapter *padapter; 717 718 719 pBtCoexist = (struct btc_coexist *)pBtcContext; 720 padapter = pBtCoexist->Adapter; 721 722 rtw_write32(padapter, RegAddr, Data); 723 } 724 725 static void halbtcoutsrc_WriteLocalReg1Byte(void *pBtcContext, u32 RegAddr, u8 Data) 726 { 727 struct btc_coexist *pBtCoexist = (struct btc_coexist *)pBtcContext; 728 struct adapter *Adapter = pBtCoexist->Adapter; 729 730 if (BTC_INTF_SDIO == pBtCoexist->chipInterface) 731 rtw_write8(Adapter, SDIO_LOCAL_BASE | RegAddr, Data); 732 else 733 rtw_write8(Adapter, RegAddr, Data); 734 } 735 736 static void halbtcoutsrc_SetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask, u32 Data) 737 { 738 struct btc_coexist *pBtCoexist; 739 struct adapter *padapter; 740 741 742 pBtCoexist = (struct btc_coexist *)pBtcContext; 743 padapter = pBtCoexist->Adapter; 744 745 PHY_SetBBReg(padapter, RegAddr, BitMask, Data); 746 } 747 748 749 static u32 halbtcoutsrc_GetBbReg(void *pBtcContext, u32 RegAddr, u32 BitMask) 750 { 751 struct btc_coexist *pBtCoexist; 752 struct adapter *padapter; 753 754 755 pBtCoexist = (struct btc_coexist *)pBtcContext; 756 padapter = pBtCoexist->Adapter; 757 758 return PHY_QueryBBReg(padapter, RegAddr, BitMask); 759 } 760 761 static void halbtcoutsrc_SetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask, u32 Data) 762 { 763 struct btc_coexist *pBtCoexist; 764 struct adapter *padapter; 765 766 767 pBtCoexist = (struct btc_coexist *)pBtcContext; 768 padapter = pBtCoexist->Adapter; 769 770 PHY_SetRFReg(padapter, eRFPath, RegAddr, BitMask, Data); 771 } 772 773 static u32 halbtcoutsrc_GetRfReg(void *pBtcContext, u8 eRFPath, u32 RegAddr, u32 BitMask) 774 { 775 struct btc_coexist *pBtCoexist; 776 struct adapter *padapter; 777 778 779 pBtCoexist = (struct btc_coexist *)pBtcContext; 780 padapter = pBtCoexist->Adapter; 781 782 return PHY_QueryRFReg(padapter, eRFPath, RegAddr, BitMask); 783 } 784 785 static void halbtcoutsrc_SetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr, u32 Data) 786 { 787 struct btc_coexist *pBtCoexist; 788 struct adapter *padapter; 789 u8 CmdBuffer1[4] = {0}; 790 u8 CmdBuffer2[4] = {0}; 791 u8 *AddrToSet = (u8 *)&RegAddr; 792 u8 *ValueToSet = (u8 *)&Data; 793 u8 OperVer = 0; 794 u8 ReqNum = 0; 795 796 pBtCoexist = (struct btc_coexist *)pBtcContext; 797 padapter = pBtCoexist->Adapter; 798 799 CmdBuffer1[0] |= (OperVer & 0x0f); /* Set OperVer */ 800 CmdBuffer1[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */ 801 CmdBuffer1[1] = 0x0d; /* Set OpCode to BT_LO_OP_WRITE_REG_VALUE */ 802 CmdBuffer1[2] = ValueToSet[0]; /* Set WriteRegValue */ 803 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer1[0])); 804 805 msleep(200); 806 ReqNum++; 807 808 CmdBuffer2[0] |= (OperVer & 0x0f); /* Set OperVer */ 809 CmdBuffer2[0] |= ((ReqNum << 4) & 0xf0); /* Set ReqNum */ 810 CmdBuffer2[1] = 0x0c; /* Set OpCode of BT_LO_OP_WRITE_REG_ADDR */ 811 CmdBuffer2[3] = AddrToSet[0]; /* Set WriteRegAddr */ 812 rtw_hal_fill_h2c_cmd(padapter, 0x67, 4, &(CmdBuffer2[0])); 813 } 814 815 static u32 halbtcoutsrc_GetBtReg(void *pBtcContext, u8 RegType, u32 RegAddr) 816 { 817 /* To be implemented. Always return 0 temporarily */ 818 return 0; 819 } 820 821 static void halbtcoutsrc_FillH2cCmd(void *pBtcContext, u8 elementId, u32 cmdLen, u8 *pCmdBuffer) 822 { 823 struct btc_coexist *pBtCoexist; 824 struct adapter *padapter; 825 826 827 pBtCoexist = (struct btc_coexist *)pBtcContext; 828 padapter = pBtCoexist->Adapter; 829 830 rtw_hal_fill_h2c_cmd(padapter, elementId, cmdLen, pCmdBuffer); 831 } 832 833 static void halbtcoutsrc_DisplayDbgMsg(void *pBtcContext, u8 dispType) 834 { 835 struct btc_coexist *pBtCoexist; 836 837 838 pBtCoexist = (struct btc_coexist *)pBtcContext; 839 switch (dispType) { 840 case BTC_DBG_DISP_COEX_STATISTICS: 841 break; 842 case BTC_DBG_DISP_BT_LINK_INFO: 843 break; 844 case BTC_DBG_DISP_FW_PWR_MODE_CMD: 845 halbtcoutsrc_DisplayFwPwrModeCmd(pBtCoexist); 846 break; 847 default: 848 break; 849 } 850 } 851 852 /* */ 853 /* Extern functions called by other module */ 854 /* */ 855 static u8 EXhalbtcoutsrc_BindBtCoexWithAdapter(void *padapter) 856 { 857 struct btc_coexist *pBtCoexist = &GLBtCoexist; 858 859 if (pBtCoexist->bBinded) 860 return false; 861 else 862 pBtCoexist->bBinded = true; 863 864 pBtCoexist->statistics.cntBind++; 865 866 pBtCoexist->Adapter = padapter; 867 868 pBtCoexist->stackInfo.bProfileNotified = false; 869 870 pBtCoexist->btInfo.bBtCtrlAggBufSize = false; 871 pBtCoexist->btInfo.aggBufSize = 5; 872 873 pBtCoexist->btInfo.bIncreaseScanDevNum = false; 874 875 /* set default antenna position to main port */ 876 pBtCoexist->boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; 877 878 return true; 879 } 880 881 void hal_btcoex_Initialize(void *padapter) 882 { 883 struct btc_coexist *pBtCoexist; 884 885 memset(&GLBtCoexist, 0, sizeof(GLBtCoexist)); 886 887 pBtCoexist = &GLBtCoexist; 888 889 /* pBtCoexist->statistics.cntBind++; */ 890 891 pBtCoexist->chipInterface = BTC_INTF_SDIO; 892 893 EXhalbtcoutsrc_BindBtCoexWithAdapter(padapter); 894 895 pBtCoexist->fBtcRead1Byte = halbtcoutsrc_Read1Byte; 896 pBtCoexist->fBtcWrite1Byte = halbtcoutsrc_Write1Byte; 897 pBtCoexist->fBtcWrite1ByteBitMask = halbtcoutsrc_BitMaskWrite1Byte; 898 pBtCoexist->fBtcRead2Byte = halbtcoutsrc_Read2Byte; 899 pBtCoexist->fBtcWrite2Byte = halbtcoutsrc_Write2Byte; 900 pBtCoexist->fBtcRead4Byte = halbtcoutsrc_Read4Byte; 901 pBtCoexist->fBtcWrite4Byte = halbtcoutsrc_Write4Byte; 902 pBtCoexist->fBtcWriteLocalReg1Byte = halbtcoutsrc_WriteLocalReg1Byte; 903 904 pBtCoexist->fBtcSetBbReg = halbtcoutsrc_SetBbReg; 905 pBtCoexist->fBtcGetBbReg = halbtcoutsrc_GetBbReg; 906 907 pBtCoexist->fBtcSetRfReg = halbtcoutsrc_SetRfReg; 908 pBtCoexist->fBtcGetRfReg = halbtcoutsrc_GetRfReg; 909 910 pBtCoexist->fBtcFillH2c = halbtcoutsrc_FillH2cCmd; 911 pBtCoexist->fBtcDispDbgMsg = halbtcoutsrc_DisplayDbgMsg; 912 913 pBtCoexist->fBtcGet = halbtcoutsrc_Get; 914 pBtCoexist->fBtcSet = halbtcoutsrc_Set; 915 pBtCoexist->fBtcGetBtReg = halbtcoutsrc_GetBtReg; 916 pBtCoexist->fBtcSetBtReg = halbtcoutsrc_SetBtReg; 917 918 pBtCoexist->cliBuf = &GLBtcDbgBuf[0]; 919 920 pBtCoexist->boardInfo.singleAntPath = 0; 921 922 GLBtcWiFiInScanState = false; 923 924 GLBtcWiFiInIQKState = false; 925 } 926 927 void EXhalbtcoutsrc_PowerOnSetting(struct btc_coexist *pBtCoexist) 928 { 929 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 930 return; 931 932 /* Power on setting function is only added in 8723B currently */ 933 if (pBtCoexist->boardInfo.btdmAntNum == 2) 934 EXhalbtc8723b2ant_PowerOnSetting(pBtCoexist); 935 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 936 EXhalbtc8723b1ant_PowerOnSetting(pBtCoexist); 937 } 938 939 void EXhalbtcoutsrc_InitHwConfig(struct btc_coexist *pBtCoexist, u8 bWifiOnly) 940 { 941 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 942 return; 943 944 pBtCoexist->statistics.cntInitHwConfig++; 945 946 if (pBtCoexist->boardInfo.btdmAntNum == 2) 947 EXhalbtc8723b2ant_InitHwConfig(pBtCoexist, bWifiOnly); 948 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 949 EXhalbtc8723b1ant_InitHwConfig(pBtCoexist, bWifiOnly); 950 } 951 952 void EXhalbtcoutsrc_InitCoexDm(struct btc_coexist *pBtCoexist) 953 { 954 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 955 return; 956 957 pBtCoexist->statistics.cntInitCoexDm++; 958 959 if (pBtCoexist->boardInfo.btdmAntNum == 2) 960 EXhalbtc8723b2ant_InitCoexDm(pBtCoexist); 961 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 962 EXhalbtc8723b1ant_InitCoexDm(pBtCoexist); 963 964 pBtCoexist->bInitilized = true; 965 } 966 967 void EXhalbtcoutsrc_IpsNotify(struct btc_coexist *pBtCoexist, u8 type) 968 { 969 u8 ipsType; 970 971 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 972 return; 973 974 pBtCoexist->statistics.cntIpsNotify++; 975 if (pBtCoexist->bManualControl) 976 return; 977 978 if (IPS_NONE == type) 979 ipsType = BTC_IPS_LEAVE; 980 else 981 ipsType = BTC_IPS_ENTER; 982 983 /* All notify is called in cmd thread, don't need to leave low power again */ 984 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ 985 986 if (pBtCoexist->boardInfo.btdmAntNum == 2) 987 EXhalbtc8723b2ant_IpsNotify(pBtCoexist, ipsType); 988 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 989 EXhalbtc8723b1ant_IpsNotify(pBtCoexist, ipsType); 990 991 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ 992 } 993 994 void EXhalbtcoutsrc_LpsNotify(struct btc_coexist *pBtCoexist, u8 type) 995 { 996 u8 lpsType; 997 998 999 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 1000 return; 1001 1002 pBtCoexist->statistics.cntLpsNotify++; 1003 if (pBtCoexist->bManualControl) 1004 return; 1005 1006 if (PS_MODE_ACTIVE == type) 1007 lpsType = BTC_LPS_DISABLE; 1008 else 1009 lpsType = BTC_LPS_ENABLE; 1010 1011 if (pBtCoexist->boardInfo.btdmAntNum == 2) 1012 EXhalbtc8723b2ant_LpsNotify(pBtCoexist, lpsType); 1013 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 1014 EXhalbtc8723b1ant_LpsNotify(pBtCoexist, lpsType); 1015 } 1016 1017 void EXhalbtcoutsrc_ScanNotify(struct btc_coexist *pBtCoexist, u8 type) 1018 { 1019 u8 scanType; 1020 1021 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 1022 return; 1023 pBtCoexist->statistics.cntScanNotify++; 1024 if (pBtCoexist->bManualControl) 1025 return; 1026 1027 if (type) { 1028 scanType = BTC_SCAN_START; 1029 GLBtcWiFiInScanState = true; 1030 } else { 1031 scanType = BTC_SCAN_FINISH; 1032 GLBtcWiFiInScanState = false; 1033 } 1034 1035 /* All notify is called in cmd thread, don't need to leave low power again */ 1036 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ 1037 1038 if (pBtCoexist->boardInfo.btdmAntNum == 2) 1039 EXhalbtc8723b2ant_ScanNotify(pBtCoexist, scanType); 1040 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 1041 EXhalbtc8723b1ant_ScanNotify(pBtCoexist, scanType); 1042 1043 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ 1044 } 1045 1046 void EXhalbtcoutsrc_ConnectNotify(struct btc_coexist *pBtCoexist, u8 action) 1047 { 1048 u8 assoType; 1049 1050 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 1051 return; 1052 pBtCoexist->statistics.cntConnectNotify++; 1053 if (pBtCoexist->bManualControl) 1054 return; 1055 1056 if (action) 1057 assoType = BTC_ASSOCIATE_START; 1058 else 1059 assoType = BTC_ASSOCIATE_FINISH; 1060 1061 /* All notify is called in cmd thread, don't need to leave low power again */ 1062 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ 1063 1064 if (pBtCoexist->boardInfo.btdmAntNum == 2) 1065 EXhalbtc8723b2ant_ConnectNotify(pBtCoexist, assoType); 1066 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 1067 EXhalbtc8723b1ant_ConnectNotify(pBtCoexist, assoType); 1068 1069 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ 1070 } 1071 1072 void EXhalbtcoutsrc_MediaStatusNotify(struct btc_coexist *pBtCoexist, enum 1073 rt_media_status mediaStatus) 1074 { 1075 u8 mStatus; 1076 1077 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 1078 return; 1079 1080 pBtCoexist->statistics.cntMediaStatusNotify++; 1081 if (pBtCoexist->bManualControl) 1082 return; 1083 1084 if (RT_MEDIA_CONNECT == mediaStatus) 1085 mStatus = BTC_MEDIA_CONNECT; 1086 else 1087 mStatus = BTC_MEDIA_DISCONNECT; 1088 1089 /* All notify is called in cmd thread, don't need to leave low power again */ 1090 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ 1091 1092 if (pBtCoexist->boardInfo.btdmAntNum == 2) 1093 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, mStatus); 1094 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 1095 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, mStatus); 1096 1097 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ 1098 } 1099 1100 void EXhalbtcoutsrc_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 pktType) 1101 { 1102 u8 packetType; 1103 1104 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 1105 return; 1106 pBtCoexist->statistics.cntSpecialPacketNotify++; 1107 if (pBtCoexist->bManualControl) 1108 return; 1109 1110 if (PACKET_DHCP == pktType) { 1111 packetType = BTC_PACKET_DHCP; 1112 } else if (PACKET_EAPOL == pktType) { 1113 packetType = BTC_PACKET_EAPOL; 1114 } else if (PACKET_ARP == pktType) { 1115 packetType = BTC_PACKET_ARP; 1116 } else { 1117 return; 1118 } 1119 1120 /* All notify is called in cmd thread, don't need to leave low power again */ 1121 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ 1122 1123 if (pBtCoexist->boardInfo.btdmAntNum == 2) 1124 EXhalbtc8723b2ant_SpecialPacketNotify(pBtCoexist, packetType); 1125 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 1126 EXhalbtc8723b1ant_SpecialPacketNotify(pBtCoexist, packetType); 1127 1128 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ 1129 } 1130 1131 void EXhalbtcoutsrc_BtInfoNotify(struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length) 1132 { 1133 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 1134 return; 1135 1136 pBtCoexist->statistics.cntBtInfoNotify++; 1137 1138 /* All notify is called in cmd thread, don't need to leave low power again */ 1139 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ 1140 1141 if (pBtCoexist->boardInfo.btdmAntNum == 2) 1142 EXhalbtc8723b2ant_BtInfoNotify(pBtCoexist, tmpBuf, length); 1143 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 1144 EXhalbtc8723b1ant_BtInfoNotify(pBtCoexist, tmpBuf, length); 1145 1146 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ 1147 } 1148 1149 void EXhalbtcoutsrc_HaltNotify(struct btc_coexist *pBtCoexist) 1150 { 1151 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 1152 return; 1153 1154 if (pBtCoexist->boardInfo.btdmAntNum == 2) 1155 EXhalbtc8723b2ant_HaltNotify(pBtCoexist); 1156 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 1157 EXhalbtc8723b1ant_HaltNotify(pBtCoexist); 1158 1159 pBtCoexist->bBinded = false; 1160 } 1161 1162 void EXhalbtcoutsrc_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState) 1163 { 1164 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 1165 return; 1166 1167 /* */ 1168 /* currently only 1ant we have to do the notification, */ 1169 /* once pnp is notified to sleep state, we have to leave LPS that we can sleep normally. */ 1170 /* */ 1171 1172 if (pBtCoexist->boardInfo.btdmAntNum == 1) 1173 EXhalbtc8723b1ant_PnpNotify(pBtCoexist, pnpState); 1174 else if (pBtCoexist->boardInfo.btdmAntNum == 2) 1175 EXhalbtc8723b2ant_PnpNotify(pBtCoexist, pnpState); 1176 } 1177 1178 void EXhalbtcoutsrc_Periodical(struct btc_coexist *pBtCoexist) 1179 { 1180 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 1181 return; 1182 pBtCoexist->statistics.cntPeriodical++; 1183 1184 /* Periodical should be called in cmd thread, */ 1185 /* don't need to leave low power again */ 1186 /* halbtcoutsrc_LeaveLowPower(pBtCoexist); */ 1187 1188 if (pBtCoexist->boardInfo.btdmAntNum == 2) 1189 EXhalbtc8723b2ant_Periodical(pBtCoexist); 1190 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 1191 EXhalbtc8723b1ant_Periodical(pBtCoexist); 1192 1193 /* halbtcoutsrc_NormalLowPower(pBtCoexist); */ 1194 } 1195 1196 void EXhalbtcoutsrc_SetChipType(u8 chipType) 1197 { 1198 GLBtCoexist.boardInfo.btChipType = BTC_CHIP_RTL8723B; 1199 } 1200 1201 void EXhalbtcoutsrc_SetAntNum(u8 type, u8 antNum) 1202 { 1203 if (BT_COEX_ANT_TYPE_PG == type) { 1204 GLBtCoexist.boardInfo.pgAntNum = antNum; 1205 GLBtCoexist.boardInfo.btdmAntNum = antNum; 1206 } else if (BT_COEX_ANT_TYPE_ANTDIV == type) { 1207 GLBtCoexist.boardInfo.btdmAntNum = antNum; 1208 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */ 1209 } else if (BT_COEX_ANT_TYPE_DETECTED == type) { 1210 GLBtCoexist.boardInfo.btdmAntNum = antNum; 1211 /* GLBtCoexist.boardInfo.btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT; */ 1212 } 1213 } 1214 1215 /* */ 1216 /* Currently used by 8723b only, S0 or S1 */ 1217 /* */ 1218 void EXhalbtcoutsrc_SetSingleAntPath(u8 singleAntPath) 1219 { 1220 GLBtCoexist.boardInfo.singleAntPath = singleAntPath; 1221 } 1222 1223 void EXhalbtcoutsrc_DisplayBtCoexInfo(struct btc_coexist *pBtCoexist) 1224 { 1225 if (!halbtcoutsrc_IsBtCoexistAvailable(pBtCoexist)) 1226 return; 1227 1228 halbtcoutsrc_LeaveLowPower(pBtCoexist); 1229 1230 if (pBtCoexist->boardInfo.btdmAntNum == 2) 1231 EXhalbtc8723b2ant_DisplayCoexInfo(pBtCoexist); 1232 else if (pBtCoexist->boardInfo.btdmAntNum == 1) 1233 EXhalbtc8723b1ant_DisplayCoexInfo(pBtCoexist); 1234 1235 halbtcoutsrc_NormalLowPower(pBtCoexist); 1236 } 1237 1238 /* 1239 * Description: 1240 *Run BT-Coexist mechanism or not 1241 * 1242 */ 1243 void hal_btcoex_SetBTCoexist(struct adapter *padapter, u8 bBtExist) 1244 { 1245 struct hal_com_data *pHalData; 1246 1247 1248 pHalData = GET_HAL_DATA(padapter); 1249 pHalData->bt_coexist.bBtExist = bBtExist; 1250 } 1251 1252 /* 1253 * Dewcription: 1254 *Check is co-exist mechanism enabled or not 1255 * 1256 * Return: 1257 *true Enable BT co-exist mechanism 1258 *false Disable BT co-exist mechanism 1259 */ 1260 bool hal_btcoex_IsBtExist(struct adapter *padapter) 1261 { 1262 struct hal_com_data *pHalData; 1263 1264 1265 pHalData = GET_HAL_DATA(padapter); 1266 return pHalData->bt_coexist.bBtExist; 1267 } 1268 1269 bool hal_btcoex_IsBtDisabled(struct adapter *padapter) 1270 { 1271 if (!hal_btcoex_IsBtExist(padapter)) 1272 return true; 1273 1274 if (GLBtCoexist.btInfo.bBtDisabled) 1275 return true; 1276 else 1277 return false; 1278 } 1279 1280 void hal_btcoex_SetChipType(struct adapter *padapter, u8 chipType) 1281 { 1282 struct hal_com_data *pHalData; 1283 1284 1285 pHalData = GET_HAL_DATA(padapter); 1286 pHalData->bt_coexist.btChipType = chipType; 1287 1288 EXhalbtcoutsrc_SetChipType(chipType); 1289 } 1290 1291 void hal_btcoex_SetPgAntNum(struct adapter *padapter, u8 antNum) 1292 { 1293 struct hal_com_data *pHalData; 1294 1295 1296 pHalData = GET_HAL_DATA(padapter); 1297 1298 pHalData->bt_coexist.btTotalAntNum = antNum; 1299 EXhalbtcoutsrc_SetAntNum(BT_COEX_ANT_TYPE_PG, antNum); 1300 } 1301 1302 void hal_btcoex_SetSingleAntPath(struct adapter *padapter, u8 singleAntPath) 1303 { 1304 EXhalbtcoutsrc_SetSingleAntPath(singleAntPath); 1305 } 1306 1307 void hal_btcoex_PowerOnSetting(struct adapter *padapter) 1308 { 1309 EXhalbtcoutsrc_PowerOnSetting(&GLBtCoexist); 1310 } 1311 1312 void hal_btcoex_InitHwConfig(struct adapter *padapter, u8 bWifiOnly) 1313 { 1314 if (!hal_btcoex_IsBtExist(padapter)) 1315 return; 1316 1317 EXhalbtcoutsrc_InitHwConfig(&GLBtCoexist, bWifiOnly); 1318 EXhalbtcoutsrc_InitCoexDm(&GLBtCoexist); 1319 } 1320 1321 void hal_btcoex_IpsNotify(struct adapter *padapter, u8 type) 1322 { 1323 EXhalbtcoutsrc_IpsNotify(&GLBtCoexist, type); 1324 } 1325 1326 void hal_btcoex_LpsNotify(struct adapter *padapter, u8 type) 1327 { 1328 EXhalbtcoutsrc_LpsNotify(&GLBtCoexist, type); 1329 } 1330 1331 void hal_btcoex_ScanNotify(struct adapter *padapter, u8 type) 1332 { 1333 EXhalbtcoutsrc_ScanNotify(&GLBtCoexist, type); 1334 } 1335 1336 void hal_btcoex_ConnectNotify(struct adapter *padapter, u8 action) 1337 { 1338 EXhalbtcoutsrc_ConnectNotify(&GLBtCoexist, action); 1339 } 1340 1341 void hal_btcoex_MediaStatusNotify(struct adapter *padapter, u8 mediaStatus) 1342 { 1343 EXhalbtcoutsrc_MediaStatusNotify(&GLBtCoexist, mediaStatus); 1344 } 1345 1346 void hal_btcoex_SpecialPacketNotify(struct adapter *padapter, u8 pktType) 1347 { 1348 EXhalbtcoutsrc_SpecialPacketNotify(&GLBtCoexist, pktType); 1349 } 1350 1351 void hal_btcoex_IQKNotify(struct adapter *padapter, u8 state) 1352 { 1353 GLBtcWiFiInIQKState = state; 1354 } 1355 1356 void hal_btcoex_BtInfoNotify(struct adapter *padapter, u8 length, u8 *tmpBuf) 1357 { 1358 if (GLBtcWiFiInIQKState) 1359 return; 1360 1361 EXhalbtcoutsrc_BtInfoNotify(&GLBtCoexist, tmpBuf, length); 1362 } 1363 1364 void hal_btcoex_SuspendNotify(struct adapter *padapter, u8 state) 1365 { 1366 if (state == 1) 1367 state = BTC_WIFI_PNP_SLEEP; 1368 else 1369 state = BTC_WIFI_PNP_WAKE_UP; 1370 1371 EXhalbtcoutsrc_PnpNotify(&GLBtCoexist, state); 1372 } 1373 1374 void hal_btcoex_HaltNotify(struct adapter *padapter) 1375 { 1376 EXhalbtcoutsrc_HaltNotify(&GLBtCoexist); 1377 } 1378 1379 void hal_btcoex_Handler(struct adapter *padapter) 1380 { 1381 EXhalbtcoutsrc_Periodical(&GLBtCoexist); 1382 } 1383 1384 s32 hal_btcoex_IsBTCoexCtrlAMPDUSize(struct adapter *padapter) 1385 { 1386 return (s32)GLBtCoexist.btInfo.bBtCtrlAggBufSize; 1387 } 1388 1389 void hal_btcoex_SetManualControl(struct adapter *padapter, u8 bmanual) 1390 { 1391 GLBtCoexist.bManualControl = bmanual; 1392 } 1393 1394 bool hal_btcoex_IsBtControlLps(struct adapter *padapter) 1395 { 1396 if (!hal_btcoex_IsBtExist(padapter)) 1397 return false; 1398 1399 if (GLBtCoexist.btInfo.bBtDisabled) 1400 return false; 1401 1402 if (GLBtCoexist.btInfo.bBtCtrlLps) 1403 return true; 1404 1405 return false; 1406 } 1407 1408 bool hal_btcoex_IsLpsOn(struct adapter *padapter) 1409 { 1410 if (!hal_btcoex_IsBtExist(padapter)) 1411 return false; 1412 1413 if (GLBtCoexist.btInfo.bBtDisabled) 1414 return false; 1415 1416 if (GLBtCoexist.btInfo.bBtLpsOn) 1417 return true; 1418 1419 return false; 1420 } 1421 1422 u8 hal_btcoex_RpwmVal(struct adapter *padapter) 1423 { 1424 return GLBtCoexist.btInfo.rpwmVal; 1425 } 1426 1427 u8 hal_btcoex_LpsVal(struct adapter *padapter) 1428 { 1429 return GLBtCoexist.btInfo.lpsVal; 1430 } 1431 1432 u32 hal_btcoex_GetRaMask(struct adapter *padapter) 1433 { 1434 if (!hal_btcoex_IsBtExist(padapter)) 1435 return 0; 1436 1437 if (GLBtCoexist.btInfo.bBtDisabled) 1438 return 0; 1439 1440 if (GLBtCoexist.boardInfo.btdmAntNum != 1) 1441 return 0; 1442 1443 return GLBtCoexist.btInfo.raMask; 1444 } 1445 1446 void hal_btcoex_RecordPwrMode(struct adapter *padapter, u8 *pCmdBuf, u8 cmdLen) 1447 { 1448 memcpy(GLBtCoexist.pwrModeVal, pCmdBuf, cmdLen); 1449 } 1450 1451 void hal_btcoex_DisplayBtCoexInfo(struct adapter *padapter, u8 *pbuf, u32 bufsize) 1452 { 1453 struct btcdbginfo *pinfo; 1454 1455 1456 pinfo = &GLBtcDbgInfo; 1457 DBG_BT_INFO_INIT(pinfo, pbuf, bufsize); 1458 EXhalbtcoutsrc_DisplayBtCoexInfo(&GLBtCoexist); 1459 DBG_BT_INFO_INIT(pinfo, NULL, 0); 1460 } 1461 1462