1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 /* ************************************************************
23 * This file is for 92CE/92CU dynamic mechanism only
26 * ************************************************************ */
27 #define _RTL8703B_DM_C_
29 /* ************************************************************
31 * ************************************************************ */
32 #include <rtl8703b_hal.h>
34 /* ************************************************************
36 * ************************************************************ */
45 PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
46 u1Byte CurRate, RateThreshold;
48 if (pMgntInfo->pHTInfo->bCurBW40MHz)
49 RateThreshold = MGN_MCS1;
51 RateThreshold = MGN_MCS3;
53 if (Adapter->TxStats.CurrentInitTxRate <= RateThreshold) {
54 pMgntInfo->bDmDisableProtect = TRUE;
55 DbgPrint("Forced disable protect: %x\n", Adapter->TxStats.CurrentInitTxRate);
57 pMgntInfo->bDmDisableProtect = FALSE;
58 DbgPrint("Enable protect: %x\n", Adapter->TxStats.CurrentInitTxRate);
69 if (!Adapter->MgntInfo.bMediaConnect)
72 /* 2008.12.10 tynli Add for getting Current_Tx_Rate_Reg flexibly. */
73 rtw_hal_get_hwreg(Adapter, HW_VAR_INIT_TX_RATE, (pu1Byte)(&Adapter->TxStats.CurrentInitTxRate));
75 /* Calculate current Tx Rate(Successful transmited!!) */
77 /* Calculate current Rx Rate(Successful received!!) */
79 /* for tx tx retry count */
80 rtw_hal_get_hwreg(Adapter, HW_VAR_RETRY_COUNT, (pu1Byte)(&Adapter->TxStats.NumTxRetryCount));
83 #ifdef CONFIG_SUPPORT_HW_WPS_PBC
84 static void dm_CheckPbcGPIO(_adapter *padapter)
87 u8 bPbcPressed = _FALSE;
89 if (!padapter->registrypriv.hw_wps_pbc)
93 tmp1byte = rtw_read8(padapter, GPIO_IO_SEL);
94 tmp1byte |= (HAL_8192C_HW_GPIO_WPS_BIT);
95 rtw_write8(padapter, GPIO_IO_SEL, tmp1byte); /* enable GPIO[2] as output mode */
97 tmp1byte &= ~(HAL_8192C_HW_GPIO_WPS_BIT);
98 rtw_write8(padapter, GPIO_IN, tmp1byte); /* reset the floating voltage level */
100 tmp1byte = rtw_read8(padapter, GPIO_IO_SEL);
101 tmp1byte &= ~(HAL_8192C_HW_GPIO_WPS_BIT);
102 rtw_write8(padapter, GPIO_IO_SEL, tmp1byte); /* enable GPIO[2] as input mode */
104 tmp1byte = rtw_read8(padapter, GPIO_IN);
106 if (tmp1byte == 0xff)
109 if (tmp1byte & HAL_8192C_HW_GPIO_WPS_BIT)
112 tmp1byte = rtw_read8(padapter, GPIO_IN);
114 if (tmp1byte == 0xff || padapter->init_adpt_in_progress)
117 if ((tmp1byte & HAL_8192C_HW_GPIO_WPS_BIT) == 0)
121 if (_TRUE == bPbcPressed) {
122 /* Here we only set bPbcPressed to true */
123 /* After trigger PBC, the variable will be set to false */
124 RTW_INFO("CheckPbcGPIO - PBC is pressed\n");
125 rtw_request_wps_pbc_event(padapter);
128 #endif /* #ifdef CONFIG_SUPPORT_HW_WPS_PBC */
131 #ifdef CONFIG_PCI_HCI
134 * Perform interrupt migration dynamically to reduce CPU utilization.
137 * 1. Do not enable migration under WIFI test.
139 * Created by Roger, 2010.03.05.
142 dm_InterruptMigration(
146 HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
147 struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
148 BOOLEAN bCurrentIntMt, bCurrentACIntDisable;
149 BOOLEAN IntMtToSet = _FALSE;
150 BOOLEAN ACIntToSet = _FALSE;
153 /* Retrieve current interrupt migration and Tx four ACs IMR settings first. */
154 bCurrentIntMt = pHalData->bInterruptMigration;
155 bCurrentACIntDisable = pHalData->bDisableTxInt;
158 /* <Roger_Notes> Currently we use busy traffic for reference instead of RxIntOK counts to prevent non-linear Rx statistics */
159 /* when interrupt migration is set before. 2010.03.05. */
161 if (!Adapter->registrypriv.wifi_spec &&
162 (check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) &&
163 pmlmepriv->LinkDetectInfo.bHigherBusyTraffic) {
166 /* To check whether we should disable Tx interrupt or not. */
167 if (pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic)
171 /* Update current settings. */
172 if (bCurrentIntMt != IntMtToSet) {
173 RTW_INFO("%s(): Update interrrupt migration(%d)\n", __FUNCTION__, IntMtToSet);
176 /* <Roger_Notes> Set interrrupt migration timer and corresponging Tx/Rx counter. */
177 /* timer 25ns*0xfa0=100us for 0xf packets. */
180 rtw_write32(Adapter, REG_INT_MIG, 0xff000fa0);/* 0x306:Rx, 0x307:Tx */
181 pHalData->bInterruptMigration = IntMtToSet;
183 /* Reset all interrupt migration settings. */
184 rtw_write32(Adapter, REG_INT_MIG, 0);
185 pHalData->bInterruptMigration = IntMtToSet;
190 if (bCurrentACIntDisable != ACIntToSet) {
191 RTW_INFO("%s(): Update AC interrrupt(%d)\n", __FUNCTION__, ACIntToSet);
192 if (ACIntToSet) { /* Disable four ACs interrupts. */
194 /* <Roger_Notes> Disable VO, VI, BE and BK four AC interrupts to gain more efficient CPU utilization. */
195 /* When extremely highly Rx OK occurs, we will disable Tx interrupts. */
198 UpdateInterruptMask8192CE(Adapter, 0, RT_AC_INT_MASKS);
199 pHalData->bDisableTxInt = ACIntToSet;
200 } else { /* Enable four ACs interrupts. */
201 UpdateInterruptMask8192CE(Adapter, RT_AC_INT_MASKS, 0);
202 pHalData->bDisableTxInt = ACIntToSet;
212 * Initialize GPIO setting registers
219 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
223 tmp1byte = rtw_read8(Adapter, REG_GPIO_MUXCFG);
224 tmp1byte &= (GPIOSEL_GPIO | ~GPIOSEL_ENBT);
226 rtw_write8(Adapter, REG_GPIO_MUXCFG, tmp1byte);
228 /* ************************************************************
230 * ************************************************************ */
231 static void Init_ODM_ComInfo_8703b(PADAPTER Adapter)
233 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
234 struct PHY_DM_STRUCT *pDM_Odm = &(pHalData->odmpriv);
235 u32 SupportAbility = 0;
238 Init_ODM_ComInfo(Adapter);
240 odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_PACKAGE_TYPE, pHalData->PackageType);
243 cut_ver = GET_CVID_CUT_VERSION(pHalData->version_id);
245 RTW_INFO("%s(): fab_ver=%d cut_ver=%d\n", __func__, fab_ver, cut_ver);
246 odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_FAB_VER, fab_ver);
247 odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_CUT_VER, cut_ver);
249 #ifdef CONFIG_DISABLE_ODM
262 odm_cmn_info_update(pDM_Odm, ODM_CMNINFO_ABILITY, SupportAbility);
265 static void Update_ODM_ComInfo_8703b(PADAPTER Adapter)
267 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
268 struct PHY_DM_STRUCT *pDM_Odm = &(pHalData->odmpriv);
269 u32 SupportAbility = 0;
272 | ODM_BB_DIG /* For BB */
275 | ODM_BB_RSSI_MONITOR
277 | ODM_BB_CFO_TRACKING
278 /* | ODM_BB_PWR_TRAIN */
280 | ODM_RF_TX_PWR_TRACK /* For RF */
282 | ODM_MAC_EDCA_TURBO /* For MAC */
285 if (rtw_odm_adaptivity_needed(Adapter) == _TRUE) {
286 rtw_odm_adaptivity_config_msg(RTW_DBGDUMP, Adapter);
287 SupportAbility |= ODM_BB_ADAPTIVITY;
290 #ifdef CONFIG_ANTENNA_DIVERSITY
291 if (pHalData->AntDivCfg)
292 SupportAbility |= ODM_BB_ANT_DIV;
296 if (Adapter->registrypriv.mp_mode == 1) {
299 | ODM_RF_TX_PWR_TRACK
302 #endif/* (MP_DRIVER==1) */
304 #ifdef CONFIG_DISABLE_ODM
306 #endif/* CONFIG_DISABLE_ODM */
308 odm_cmn_info_update(pDM_Odm, ODM_CMNINFO_ABILITY, SupportAbility);
316 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
317 struct PHY_DM_STRUCT *pDM_Odm = &(pHalData->odmpriv);
321 #ifdef CONFIG_USB_HCI
322 dm_InitGPIOSetting(Adapter);
325 pHalData->DM_Type = dm_type_by_driver;
327 Update_ODM_ComInfo_8703b(Adapter);
329 odm_dm_init(pDM_Odm);
334 rtl8703b_HalDmWatchDog(
338 BOOLEAN bFwCurrentInPSMode = _FALSE;
339 BOOLEAN bFwPSAwake = _TRUE;
340 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
342 #ifdef CONFIG_MP_INCLUDED
344 if (Adapter->registrypriv.mp_mode == 1 && Adapter->mppriv.mp_dm == 0) /* for MP power tracking */
349 if (!rtw_is_hw_init_completed(Adapter))
353 bFwCurrentInPSMode = adapter_to_pwrctl(Adapter)->bFwCurrentInPSMode;
354 rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, (u8 *)(&bFwPSAwake));
358 /* Fw is under p2p powersaving mode, driver should stop dynamic mechanism. */
359 /* modifed by thomas. 2011.06.11. */
360 if (Adapter->wdinfo.p2p_ps_mode)
362 #endif /* CONFIG_P2P */
365 if ((rtw_is_hw_init_completed(Adapter))
366 && ((!bFwCurrentInPSMode) && bFwPSAwake)) {
368 /* Calculate Tx/Rx statistics. */
370 dm_CheckStatistics(Adapter);
371 rtw_hal_check_rxfifo_full(Adapter);
373 /* Dynamically switch RTS/CTS protection. */
375 /* dm_CheckProtection(Adapter); */
377 #ifdef CONFIG_PCI_HCI
378 /* 20100630 Joseph: Disable Interrupt Migration mechanism temporarily because it degrades Rx throughput. */
379 /* Tx Migration settings. */
380 /* dm_InterruptMigration(Adapter); */
382 /* if(Adapter->HalFunc.TxCheckStuckHandler(Adapter)) */
383 /* PlatformScheduleWorkItem(&(GET_HAL_DATA(Adapter)->HalResetWorkItem)); */
388 if (rtw_is_hw_init_completed(Adapter)) {
390 u8 bsta_state = _FALSE;
391 u8 bBtDisabled = _TRUE;
393 if (rtw_mi_check_status(Adapter, MI_ASSOC)) {
395 if (rtw_mi_check_status(Adapter, MI_STA_LINKED))
399 odm_cmn_info_update(&pHalData->odmpriv , ODM_CMNINFO_LINK, bLinked);
400 odm_cmn_info_update(&pHalData->odmpriv , ODM_CMNINFO_STATION_STATE, bsta_state);
402 /* odm_cmn_info_update(&pHalData->odmpriv ,ODM_CMNINFO_RSSI_MIN, pdmpriv->MinUndecoratedPWDBForDM); */
404 #ifdef CONFIG_BT_COEXIST
405 bBtDisabled = rtw_btcoex_IsBtDisabled(Adapter);
406 #endif /* CONFIG_BT_COEXIST */
407 odm_cmn_info_update(&pHalData->odmpriv, ODM_CMNINFO_BT_ENABLED, ((bBtDisabled == _TRUE) ? _FALSE : _TRUE));
409 odm_dm_watchdog(&pHalData->odmpriv);
414 /* Check GPIO to determine current RF on/off and Pbc status. */
415 /* Check Hardware Radio ON/OFF or not */
416 /* if(Adapter->MgntInfo.PowerSaveControl.bGpioRfSw) */
418 /* RTPRINT(FPWR, PWRHW, ("dm_CheckRfCtrlGPIO\n")); */
419 /* dm_CheckRfCtrlGPIO(Adapter); */
421 #ifdef CONFIG_SUPPORT_HW_WPS_PBC
422 dm_CheckPbcGPIO(Adapter);
427 void rtl8703b_hal_dm_in_lps(PADAPTER padapter)
430 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
431 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
432 struct PHY_DM_STRUCT *pDM_Odm = &pHalData->odmpriv;
433 struct _dynamic_initial_gain_threshold_ *pDM_DigTable = &pDM_Odm->dm_dig_table;
434 struct sta_priv *pstapriv = &padapter->stapriv;
435 struct sta_info *psta = NULL;
437 RTW_INFO("%s, rssi_min=%d\n", __func__, pDM_Odm->rssi_min);
440 odm_write_dig(pDM_Odm, pDM_Odm->rssi_min);
444 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
445 if (psta && (psta->rssi_stat.undecorated_smoothed_pwdb > 0)) {
446 PWDB_rssi = (psta->mac_id | (psta->rssi_stat.undecorated_smoothed_pwdb << 16));
448 rtl8703b_set_rssi_cmd(padapter, (u8 *)&PWDB_rssi);
453 void rtl8703b_HalDmWatchDog_in_LPS(IN PADAPTER Adapter)
456 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
457 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
458 struct PHY_DM_STRUCT *pDM_Odm = &pHalData->odmpriv;
459 struct _dynamic_initial_gain_threshold_ *pDM_DigTable = &pDM_Odm->dm_dig_table;
460 struct sta_priv *pstapriv = &Adapter->stapriv;
461 struct sta_info *psta = NULL;
463 if (!rtw_is_hw_init_completed(Adapter))
466 if (rtw_mi_check_status(Adapter, MI_ASSOC))
469 odm_cmn_info_update(&pHalData->odmpriv , ODM_CMNINFO_LINK, bLinked);
471 if (bLinked == _FALSE)
474 if (!(pDM_Odm->support_ability & ODM_BB_RSSI_MONITOR))
478 /* odm_dm_watchdog(&pHalData->odmpriv); */
479 /* Do DIG by RSSI In LPS-32K */
481 /* .1 Find MIN-RSSI */
482 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
486 pHalData->entry_min_undecorated_smoothed_pwdb = psta->rssi_stat.undecorated_smoothed_pwdb;
488 RTW_INFO("cur_ig_value=%d, entry_min_undecorated_smoothed_pwdb = %d\n", pDM_DigTable->cur_ig_value, pHalData->entry_min_undecorated_smoothed_pwdb);
490 if (pHalData->entry_min_undecorated_smoothed_pwdb <= 0)
493 pHalData->min_undecorated_pwdb_for_dm = pHalData->entry_min_undecorated_smoothed_pwdb;
495 pDM_Odm->rssi_min = pHalData->min_undecorated_pwdb_for_dm;
497 /* if(pDM_DigTable->cur_ig_value != pDM_Odm->rssi_min) */
498 if ((pDM_DigTable->cur_ig_value > pDM_Odm->rssi_min + 5) ||
499 (pDM_DigTable->cur_ig_value < pDM_Odm->rssi_min - 5)) {
501 rtw_dm_in_lps_wk_cmd(Adapter);
502 #endif /* CONFIG_LPS */
512 void rtl8703b_init_dm_priv(IN PADAPTER Adapter)
514 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
515 struct PHY_DM_STRUCT *podmpriv = &pHalData->odmpriv;
516 Init_ODM_ComInfo_8703b(Adapter);
517 odm_init_all_timers(podmpriv);
521 void rtl8703b_deinit_dm_priv(IN PADAPTER Adapter)
523 PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
524 struct PHY_DM_STRUCT *podmpriv = &pHalData->odmpriv;
526 odm_cancel_all_timers(podmpriv);