Path: blob/master/ALFA-W1F1/RTL8814AU/hal/rtl8814a/rtl8814a_dm.c
1307 views
/******************************************************************************1*2* Copyright(c) 2007 - 2017 Realtek Corporation.3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of version 2 of the GNU General Public License as6* published by the Free Software Foundation.7*8* This program is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for11* more details.12*13*****************************************************************************/14/* ************************************************************15* Description:16*17* This file is for 92CE/92CU dynamic mechanism only18*19*20* ************************************************************ */21#define _RTL8814A_DM_C_2223/* ************************************************************24* include files25* ************************************************************26* #include <drv_types.h> */27#include <rtl8814a_hal.h>2829/* ************************************************************30* Global var31* ************************************************************ */32#ifdef CONFIG_SUPPORT_HW_WPS_PBC33static void dm_CheckPbcGPIO(_adapter *padapter)34{35u8 tmp1byte;36u8 bPbcPressed = _FALSE;3738if (!padapter->registrypriv.hw_wps_pbc)39return;40#ifdef CONFIG_BT_COEXIST41if (hal_btcoex_IsBtExist(padapter))42return;43#endif /* CONFIG_BT_COEXIST */4445#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI)4647tmp1byte = rtw_read8(padapter, REG_GPIO_EXT_CTRL_8814A);48/* RTW_INFO("CheckPbcGPIO - %x\n", tmp1byte); */4950if (tmp1byte == 0xff)51return ;52else if (tmp1byte & BIT3) {53/* Here we only set bPbcPressed to TRUE. After trigger PBC, the variable will be set to FALSE */54RTW_INFO("CheckPbcGPIO - PBC is pressed\n");55bPbcPressed = _TRUE;56}5758#endif5960if (_TRUE == bPbcPressed) {61/* Here we only set bPbcPressed to true */62/* After trigger PBC, the variable will be set to false */63RTW_INFO("CheckPbcGPIO - PBC is pressed\n");6465rtw_request_wps_pbc_event(padapter);66}67}68#endif /* #ifdef CONFIG_SUPPORT_HW_WPS_PBC */6970#ifdef CONFIG_PCI_HCI71/*72* Description:73* Perform interrupt migration dynamically to reduce CPU utilization.74*75* Assumption:76* 1. Do not enable migration under WIFI test.77*78* Created by Roger, 2010.03.05.79* */80void81dm_InterruptMigration(82PADAPTER Adapter83)84{85HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);86struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);87BOOLEAN bCurrentIntMt, bCurrentACIntDisable;88BOOLEAN IntMtToSet = _FALSE;89BOOLEAN ACIntToSet = _FALSE;909192/* Retrieve current interrupt migration and Tx four ACs IMR settings first. */93bCurrentIntMt = pHalData->bInterruptMigration;94bCurrentACIntDisable = pHalData->bDisableTxInt;9596/* */97/* <Roger_Notes> Currently we use busy traffic for reference instead of RxIntOK counts to prevent non-linear Rx statistics */98/* when interrupt migration is set before. 2010.03.05. */99/* */100if (!Adapter->registrypriv.wifi_spec &&101(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) &&102pmlmepriv->LinkDetectInfo.bHigherBusyTraffic) {103IntMtToSet = _TRUE;104105/* To check whether we should disable Tx interrupt or not. */106if (pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic)107ACIntToSet = _TRUE;108}109110/* Update current settings. */111if (bCurrentIntMt != IntMtToSet) {112RTW_INFO("%s(): Update interrrupt migration(%d)\n", __FUNCTION__, IntMtToSet);113if (IntMtToSet) {114/* */115/* <Roger_Notes> Set interrrupt migration timer and corresponging Tx/Rx counter. */116/* timer 25ns*0xfa0=100us for 0xf packets. */117/* 2010.03.05. */118/* */119rtw_write32(Adapter, REG_INT_MIG_8814A, 0xff000fa0);/* 0x306:Rx, 0x307:Tx */120pHalData->bInterruptMigration = IntMtToSet;121} else {122/* Reset all interrupt migration settings. */123rtw_write32(Adapter, REG_INT_MIG_8814A, 0);124pHalData->bInterruptMigration = IntMtToSet;125}126}127128#if 0129if (bCurrentACIntDisable != ACIntToSet) {130RTW_INFO("%s(): Update AC interrrupt(%d)\n", __FUNCTION__, ACIntToSet);131if (ACIntToSet) { /* Disable four ACs interrupts. */132/* */133/* <Roger_Notes> Disable VO, VI, BE and BK four AC interrupts to gain more efficient CPU utilization. */134/* When extremely highly Rx OK occurs, we will disable Tx interrupts. */135/* 2010.03.05. */136/* */137UpdateInterruptMask8192CE(Adapter, 0, RT_AC_INT_MASKS);138pHalData->bDisableTxInt = ACIntToSet;139} else { /* Enable four ACs interrupts. */140UpdateInterruptMask8192CE(Adapter, RT_AC_INT_MASKS, 0);141pHalData->bDisableTxInt = ACIntToSet;142}143}144#endif145146}147148#endif /* CONFIG_PCI_HCI */149150/*151* Initialize GPIO setting registers152* */153#ifdef CONFIG_USB_HCI154static void155dm_InitGPIOSetting(156PADAPTER Adapter157)158{159PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);160161u8 tmp1byte;162163tmp1byte = rtw_read8(Adapter, REG_GPIO_MUXCFG);164tmp1byte &= (GPIOSEL_GPIO | ~GPIOSEL_ENBT);165166rtw_write8(Adapter, REG_GPIO_MUXCFG, tmp1byte);167}168#endif169/* ************************************************************170* functions171* ************************************************************ */172static void Init_ODM_ComInfo_8814(PADAPTER Adapter)173{174PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);175struct dm_struct *pDM_Odm = &(pHalData->odmpriv);176u32 SupportAbility = 0;177178u8 cut_ver, fab_ver;179180Init_ODM_ComInfo(Adapter);181182fab_ver = ODM_TSMC;183if (IS_A_CUT(pHalData->version_id))184cut_ver = ODM_CUT_A;185else if (IS_B_CUT(pHalData->version_id))186cut_ver = ODM_CUT_B;187else if (IS_C_CUT(pHalData->version_id))188cut_ver = ODM_CUT_C;189else if (IS_D_CUT(pHalData->version_id))190cut_ver = ODM_CUT_D;191else if (IS_E_CUT(pHalData->version_id))192cut_ver = ODM_CUT_E;193else194cut_ver = ODM_CUT_A;195196odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_FAB_VER, fab_ver);197odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_CUT_VER, cut_ver);198199}200201void202rtl8814_InitHalDm(203PADAPTER Adapter204)205{206PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);207struct dm_struct *pDM_Odm = &(pHalData->odmpriv);208209#ifdef CONFIG_USB_HCI210dm_InitGPIOSetting(Adapter);211#endif /* CONFIG_USB_HCI */212rtw_phydm_init(Adapter);213/* Adapter->fix_rate = 0xFF; */214}215216217void218rtl8814_HalDmWatchDog(219PADAPTER Adapter220)221{222BOOLEAN bFwCurrentInPSMode = _FALSE;223u8 bFwPSAwake = _TRUE;224PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);225struct dm_struct *pDM_Odm = &(pHalData->odmpriv);226struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(Adapter);227u8 in_lps = _FALSE;228229if (!rtw_is_hw_init_completed(Adapter))230goto skip_dm;231232#ifdef CONFIG_LPS233bFwCurrentInPSMode = pwrpriv->bFwCurrentInPSMode;234rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, &bFwPSAwake);235#endif236237#ifdef CONFIG_P2P_PS238/* Fw is under p2p powersaving mode, driver should stop dynamic mechanism. */239/* modifed by thomas. 2011.06.11. */240if (Adapter->wdinfo.p2p_ps_mode)241bFwPSAwake = _FALSE;242#endif /* CONFIG_P2P_PS */243244if ((rtw_is_hw_init_completed(Adapter))245&& ((!bFwCurrentInPSMode) && bFwPSAwake)) {246247rtw_hal_check_rxfifo_full(Adapter);248/* */249/* Dynamically switch RTS/CTS protection. */250/* */251252#ifdef CONFIG_PCI_HCI253/* 20100630 Joseph: Disable Interrupt Migration mechanism temporarily because it degrades Rx throughput. */254/* Tx Migration settings. */255/* dm_InterruptMigration(Adapter); */256257/* if(Adapter->HalFunc.TxCheckStuckHandler(Adapter)) */258/* PlatformScheduleWorkItem(&(GET_HAL_DATA(Adapter)->HalResetWorkItem)); */259#endif260261}262263#ifdef CONFIG_DISABLE_ODM264goto skip_dm;265#endif266#ifdef CONFIG_LPS267if (pwrpriv->bLeisurePs && bFwCurrentInPSMode && pwrpriv->pwr_mode != PS_MODE_ACTIVE)268in_lps = _TRUE;269#endif270271rtw_phydm_watchdog(Adapter, in_lps);272273skip_dm:274275#ifdef CONFIG_SUPPORT_HW_WPS_PBC276/* Check GPIO to determine current Pbc status. */277dm_CheckPbcGPIO(Adapter);278#endif279280return;281}282283void rtl8814_init_dm_priv(PADAPTER Adapter)284{285PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);286struct dm_struct *podmpriv = &pHalData->odmpriv;287288Init_ODM_ComInfo_8814(Adapter);289odm_init_all_timers(podmpriv);290pHalData->CurrentTxPwrIdx = 20;291}292293void rtl8814_deinit_dm_priv(PADAPTER Adapter)294{295PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);296struct dm_struct *podmpriv = &pHalData->odmpriv;297/* _rtw_spinlock_free(&pHalData->odm_stainfo_lock); */298odm_cancel_all_timers(podmpriv);299}300301302