1*4882a593Smuzhiyun /******************************************************************************
2*4882a593Smuzhiyun *
3*4882a593Smuzhiyun * Copyright(c) 2007 - 2017 Realtek Corporation.
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify it
6*4882a593Smuzhiyun * under the terms of version 2 of the GNU General Public License as
7*4882a593Smuzhiyun * published by the Free Software Foundation.
8*4882a593Smuzhiyun *
9*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful, but WITHOUT
10*4882a593Smuzhiyun * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11*4882a593Smuzhiyun * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12*4882a593Smuzhiyun * more details.
13*4882a593Smuzhiyun *
14*4882a593Smuzhiyun *****************************************************************************/
15*4882a593Smuzhiyun /* ************************************************************
16*4882a593Smuzhiyun * Description:
17*4882a593Smuzhiyun *
18*4882a593Smuzhiyun * This file is for 92CE/92CU dynamic mechanism only
19*4882a593Smuzhiyun *
20*4882a593Smuzhiyun *
21*4882a593Smuzhiyun * ************************************************************ */
22*4882a593Smuzhiyun #define _RTL8723D_DM_C_
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun /* ************************************************************
25*4882a593Smuzhiyun * include files
26*4882a593Smuzhiyun * ************************************************************ */
27*4882a593Smuzhiyun #include <rtl8723d_hal.h>
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun /* ************************************************************
30*4882a593Smuzhiyun * Global var
31*4882a593Smuzhiyun * ************************************************************ */
32*4882a593Smuzhiyun #ifdef CONFIG_SUPPORT_HW_WPS_PBC
dm_CheckPbcGPIO(_adapter * padapter)33*4882a593Smuzhiyun static void dm_CheckPbcGPIO(_adapter *padapter)
34*4882a593Smuzhiyun {
35*4882a593Smuzhiyun u8 tmp1byte;
36*4882a593Smuzhiyun u8 bPbcPressed = _FALSE;
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun if (!padapter->registrypriv.hw_wps_pbc)
39*4882a593Smuzhiyun return;
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun #ifdef CONFIG_USB_HCI
42*4882a593Smuzhiyun tmp1byte = rtw_read8(padapter, GPIO_IO_SEL);
43*4882a593Smuzhiyun tmp1byte |= (HAL_8192C_HW_GPIO_WPS_BIT);
44*4882a593Smuzhiyun rtw_write8(padapter, GPIO_IO_SEL, tmp1byte); /* enable GPIO[2] as output mode */
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun tmp1byte &= ~(HAL_8192C_HW_GPIO_WPS_BIT);
47*4882a593Smuzhiyun rtw_write8(padapter, GPIO_IN, tmp1byte); /* reset the floating voltage level */
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun tmp1byte = rtw_read8(padapter, GPIO_IO_SEL);
50*4882a593Smuzhiyun tmp1byte &= ~(HAL_8192C_HW_GPIO_WPS_BIT);
51*4882a593Smuzhiyun rtw_write8(padapter, GPIO_IO_SEL, tmp1byte); /* enable GPIO[2] as input mode */
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun tmp1byte = rtw_read8(padapter, GPIO_IN);
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun if (tmp1byte == 0xff)
56*4882a593Smuzhiyun return;
57*4882a593Smuzhiyun
58*4882a593Smuzhiyun if (tmp1byte & HAL_8192C_HW_GPIO_WPS_BIT)
59*4882a593Smuzhiyun bPbcPressed = _TRUE;
60*4882a593Smuzhiyun #else
61*4882a593Smuzhiyun tmp1byte = rtw_read8(padapter, GPIO_IN);
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun if (tmp1byte == 0xff || padapter->init_adpt_in_progress)
64*4882a593Smuzhiyun return;
65*4882a593Smuzhiyun
66*4882a593Smuzhiyun if ((tmp1byte & HAL_8192C_HW_GPIO_WPS_BIT) == 0)
67*4882a593Smuzhiyun bPbcPressed = _TRUE;
68*4882a593Smuzhiyun #endif
69*4882a593Smuzhiyun
70*4882a593Smuzhiyun if (_TRUE == bPbcPressed) {
71*4882a593Smuzhiyun /* Here we only set bPbcPressed to true */
72*4882a593Smuzhiyun /* After trigger PBC, the variable will be set to false */
73*4882a593Smuzhiyun RTW_INFO("CheckPbcGPIO - PBC is pressed\n");
74*4882a593Smuzhiyun rtw_request_wps_pbc_event(padapter);
75*4882a593Smuzhiyun }
76*4882a593Smuzhiyun }
77*4882a593Smuzhiyun #endif /* #ifdef CONFIG_SUPPORT_HW_WPS_PBC */
78*4882a593Smuzhiyun
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun #ifdef CONFIG_PCI_HCI
81*4882a593Smuzhiyun /*
82*4882a593Smuzhiyun * Description:
83*4882a593Smuzhiyun * Perform interrupt migration dynamically to reduce CPU utilization.
84*4882a593Smuzhiyun *
85*4882a593Smuzhiyun * Assumption:
86*4882a593Smuzhiyun * 1. Do not enable migration under WIFI test.
87*4882a593Smuzhiyun *
88*4882a593Smuzhiyun * Created by Roger, 2010.03.05.
89*4882a593Smuzhiyun * */
90*4882a593Smuzhiyun void
dm_InterruptMigration(PADAPTER Adapter)91*4882a593Smuzhiyun dm_InterruptMigration(
92*4882a593Smuzhiyun PADAPTER Adapter
93*4882a593Smuzhiyun )
94*4882a593Smuzhiyun {
95*4882a593Smuzhiyun HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
96*4882a593Smuzhiyun struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
97*4882a593Smuzhiyun BOOLEAN bCurrentIntMt, bCurrentACIntDisable;
98*4882a593Smuzhiyun BOOLEAN IntMtToSet = _FALSE;
99*4882a593Smuzhiyun BOOLEAN ACIntToSet = _FALSE;
100*4882a593Smuzhiyun
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /* Retrieve current interrupt migration and Tx four ACs IMR settings first. */
103*4882a593Smuzhiyun bCurrentIntMt = pHalData->bInterruptMigration;
104*4882a593Smuzhiyun bCurrentACIntDisable = pHalData->bDisableTxInt;
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun /* */
107*4882a593Smuzhiyun /* <Roger_Notes> Currently we use busy traffic for reference instead of RxIntOK counts to prevent non-linear Rx statistics */
108*4882a593Smuzhiyun /* when interrupt migration is set before. 2010.03.05. */
109*4882a593Smuzhiyun /* */
110*4882a593Smuzhiyun if (!Adapter->registrypriv.wifi_spec &&
111*4882a593Smuzhiyun (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) &&
112*4882a593Smuzhiyun pmlmepriv->LinkDetectInfo.bHigherBusyTraffic) {
113*4882a593Smuzhiyun IntMtToSet = _TRUE;
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun /* To check whether we should disable Tx interrupt or not. */
116*4882a593Smuzhiyun if (pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic)
117*4882a593Smuzhiyun ACIntToSet = _TRUE;
118*4882a593Smuzhiyun }
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun /* Update current settings. */
121*4882a593Smuzhiyun if (bCurrentIntMt != IntMtToSet) {
122*4882a593Smuzhiyun RTW_INFO("%s(): Update interrupt migration(%d)\n", __FUNCTION__, IntMtToSet);
123*4882a593Smuzhiyun if (IntMtToSet) {
124*4882a593Smuzhiyun /* */
125*4882a593Smuzhiyun /* <Roger_Notes> Set interrupt migration timer and corresponging Tx/Rx counter. */
126*4882a593Smuzhiyun /* timer 25ns*0xfa0=100us for 0xf packets. */
127*4882a593Smuzhiyun /* 2010.03.05. */
128*4882a593Smuzhiyun /* */
129*4882a593Smuzhiyun rtw_write32(Adapter, REG_INT_MIG_8723D, 0xff000fa0);/* 0x306:Rx, 0x307:Tx */
130*4882a593Smuzhiyun pHalData->bInterruptMigration = IntMtToSet;
131*4882a593Smuzhiyun } else {
132*4882a593Smuzhiyun /* Reset all interrupt migration settings. */
133*4882a593Smuzhiyun rtw_write32(Adapter, REG_INT_MIG_8723D, 0);
134*4882a593Smuzhiyun pHalData->bInterruptMigration = IntMtToSet;
135*4882a593Smuzhiyun }
136*4882a593Smuzhiyun }
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun /*if( bCurrentACIntDisable != ACIntToSet ){
139*4882a593Smuzhiyun RTW_INFO("%s(): Update AC interrupt(%d)\n",__FUNCTION__,ACIntToSet);
140*4882a593Smuzhiyun if(ACIntToSet)
141*4882a593Smuzhiyun {
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun UpdateInterruptMask8192CE( Adapter, 0, RT_AC_INT_MASKS );
148*4882a593Smuzhiyun pHalData->bDisableTxInt = ACIntToSet;
149*4882a593Smuzhiyun }
150*4882a593Smuzhiyun else
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun UpdateInterruptMask8192CE( Adapter, RT_AC_INT_MASKS, 0 );
153*4882a593Smuzhiyun pHalData->bDisableTxInt = ACIntToSet;
154*4882a593Smuzhiyun }
155*4882a593Smuzhiyun }*/
156*4882a593Smuzhiyun
157*4882a593Smuzhiyun }
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun #endif
160*4882a593Smuzhiyun
161*4882a593Smuzhiyun /*
162*4882a593Smuzhiyun * Initialize GPIO setting registers
163*4882a593Smuzhiyun * */
164*4882a593Smuzhiyun #ifdef CONFIG_USB_HCI
165*4882a593Smuzhiyun static void
dm_InitGPIOSetting(PADAPTER Adapter)166*4882a593Smuzhiyun dm_InitGPIOSetting(
167*4882a593Smuzhiyun PADAPTER Adapter
168*4882a593Smuzhiyun )
169*4882a593Smuzhiyun {
170*4882a593Smuzhiyun PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun u8 tmp1byte;
173*4882a593Smuzhiyun
174*4882a593Smuzhiyun tmp1byte = rtw_read8(Adapter, REG_GPIO_MUXCFG);
175*4882a593Smuzhiyun tmp1byte &= (GPIOSEL_GPIO | ~GPIOSEL_ENBT);
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun rtw_write8(Adapter, REG_GPIO_MUXCFG, tmp1byte);
178*4882a593Smuzhiyun }
179*4882a593Smuzhiyun #endif
180*4882a593Smuzhiyun /* ************************************************************
181*4882a593Smuzhiyun * functions
182*4882a593Smuzhiyun * ************************************************************ */
Init_ODM_ComInfo_8723d(PADAPTER Adapter)183*4882a593Smuzhiyun static void Init_ODM_ComInfo_8723d(PADAPTER Adapter)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
186*4882a593Smuzhiyun struct dm_struct *pDM_Odm = &(pHalData->odmpriv);
187*4882a593Smuzhiyun u8 cut_ver, fab_ver;
188*4882a593Smuzhiyun
189*4882a593Smuzhiyun Init_ODM_ComInfo(Adapter);
190*4882a593Smuzhiyun
191*4882a593Smuzhiyun odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_PACKAGE_TYPE, pHalData->PackageType);
192*4882a593Smuzhiyun
193*4882a593Smuzhiyun fab_ver = ODM_TSMC;
194*4882a593Smuzhiyun cut_ver = GET_CVID_CUT_VERSION(pHalData->version_id);
195*4882a593Smuzhiyun
196*4882a593Smuzhiyun RTW_INFO("%s(): Fv=%d Cv=%d\n", __func__, fab_ver, cut_ver);
197*4882a593Smuzhiyun odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_FAB_VER, fab_ver);
198*4882a593Smuzhiyun odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_CUT_VER, cut_ver);
199*4882a593Smuzhiyun }
200*4882a593Smuzhiyun
201*4882a593Smuzhiyun void
rtl8723d_InitHalDm(PADAPTER Adapter)202*4882a593Smuzhiyun rtl8723d_InitHalDm(
203*4882a593Smuzhiyun PADAPTER Adapter
204*4882a593Smuzhiyun )
205*4882a593Smuzhiyun {
206*4882a593Smuzhiyun PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
207*4882a593Smuzhiyun struct dm_struct *pDM_Odm = &(pHalData->odmpriv);
208*4882a593Smuzhiyun
209*4882a593Smuzhiyun #ifdef CONFIG_USB_HCI
210*4882a593Smuzhiyun dm_InitGPIOSetting(Adapter);
211*4882a593Smuzhiyun #endif
212*4882a593Smuzhiyun rtw_phydm_init(Adapter);
213*4882a593Smuzhiyun }
214*4882a593Smuzhiyun
215*4882a593Smuzhiyun void
rtl8723d_HalDmWatchDog(PADAPTER Adapter)216*4882a593Smuzhiyun rtl8723d_HalDmWatchDog(
217*4882a593Smuzhiyun PADAPTER Adapter
218*4882a593Smuzhiyun )
219*4882a593Smuzhiyun {
220*4882a593Smuzhiyun BOOLEAN bFwCurrentInPSMode = _FALSE;
221*4882a593Smuzhiyun u8 bFwPSAwake = _TRUE;
222*4882a593Smuzhiyun PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
223*4882a593Smuzhiyun struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(Adapter);
224*4882a593Smuzhiyun u8 in_lps = _FALSE;
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun #ifdef CONFIG_MP_INCLUDED
227*4882a593Smuzhiyun /* #if MP_DRIVER */
228*4882a593Smuzhiyun if (Adapter->registrypriv.mp_mode == 1 && Adapter->mppriv.mp_dm == 0) /* for MP power tracking */
229*4882a593Smuzhiyun return;
230*4882a593Smuzhiyun /* #endif */
231*4882a593Smuzhiyun #endif
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun if (!rtw_is_hw_init_completed(Adapter))
234*4882a593Smuzhiyun goto skip_dm;
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun #ifdef CONFIG_LPS
237*4882a593Smuzhiyun bFwCurrentInPSMode = pwrpriv->bFwCurrentInPSMode;
238*4882a593Smuzhiyun rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, &bFwPSAwake);
239*4882a593Smuzhiyun #endif
240*4882a593Smuzhiyun
241*4882a593Smuzhiyun #ifdef CONFIG_P2P
242*4882a593Smuzhiyun /* Fw is under p2p powersaving mode, driver should stop dynamic mechanism. */
243*4882a593Smuzhiyun /* modifed by thomas. 2011.06.11. */
244*4882a593Smuzhiyun if (Adapter->wdinfo.p2p_ps_mode)
245*4882a593Smuzhiyun bFwPSAwake = _FALSE;
246*4882a593Smuzhiyun #endif /* CONFIG_P2P */
247*4882a593Smuzhiyun
248*4882a593Smuzhiyun
249*4882a593Smuzhiyun if ((rtw_is_hw_init_completed(Adapter))
250*4882a593Smuzhiyun && ((!bFwCurrentInPSMode) && bFwPSAwake)) {
251*4882a593Smuzhiyun
252*4882a593Smuzhiyun rtw_hal_check_rxfifo_full(Adapter);
253*4882a593Smuzhiyun /* */
254*4882a593Smuzhiyun /* Dynamically switch RTS/CTS protection. */
255*4882a593Smuzhiyun /* */
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun #ifdef CONFIG_PCI_HCI
258*4882a593Smuzhiyun /* 20100630 Joseph: Disable Interrupt Migration mechanism temporarily because it degrades Rx throughput. */
259*4882a593Smuzhiyun /* Tx Migration settings. */
260*4882a593Smuzhiyun /* dm_InterruptMigration(Adapter); */
261*4882a593Smuzhiyun
262*4882a593Smuzhiyun /* if(Adapter->HalFunc.TxCheckStuckHandler(Adapter)) */
263*4882a593Smuzhiyun /* PlatformScheduleWorkItem(&(GET_HAL_DATA(Adapter)->HalResetWorkItem)); */
264*4882a593Smuzhiyun #endif
265*4882a593Smuzhiyun }
266*4882a593Smuzhiyun
267*4882a593Smuzhiyun #ifdef CONFIG_DISABLE_ODM
268*4882a593Smuzhiyun goto skip_dm;
269*4882a593Smuzhiyun #endif
270*4882a593Smuzhiyun
271*4882a593Smuzhiyun #ifdef CONFIG_LPS
272*4882a593Smuzhiyun if (pwrpriv->bLeisurePs && bFwCurrentInPSMode && pwrpriv->pwr_mode != PS_MODE_ACTIVE)
273*4882a593Smuzhiyun in_lps = _TRUE;
274*4882a593Smuzhiyun #endif
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun rtw_phydm_watchdog(Adapter, in_lps);
277*4882a593Smuzhiyun
278*4882a593Smuzhiyun skip_dm:
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun /* Check GPIO to determine current RF on/off and Pbc status. */
281*4882a593Smuzhiyun /* Check Hardware Radio ON/OFF or not */
282*4882a593Smuzhiyun /* if(Adapter->MgntInfo.PowerSaveControl.bGpioRfSw) */
283*4882a593Smuzhiyun /* { */
284*4882a593Smuzhiyun /* RTPRINT(FPWR, PWRHW, ("dm_CheckRfCtrlGPIO\n")); */
285*4882a593Smuzhiyun /* dm_CheckRfCtrlGPIO(Adapter); */
286*4882a593Smuzhiyun /* } */
287*4882a593Smuzhiyun #ifdef CONFIG_SUPPORT_HW_WPS_PBC
288*4882a593Smuzhiyun dm_CheckPbcGPIO(Adapter);
289*4882a593Smuzhiyun #endif
290*4882a593Smuzhiyun return;
291*4882a593Smuzhiyun }
292*4882a593Smuzhiyun
rtl8723d_init_dm_priv(PADAPTER Adapter)293*4882a593Smuzhiyun void rtl8723d_init_dm_priv(PADAPTER Adapter)
294*4882a593Smuzhiyun {
295*4882a593Smuzhiyun PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
296*4882a593Smuzhiyun struct dm_struct *podmpriv = &pHalData->odmpriv;
297*4882a593Smuzhiyun
298*4882a593Smuzhiyun Init_ODM_ComInfo_8723d(Adapter);
299*4882a593Smuzhiyun odm_init_all_timers(podmpriv);
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun
rtl8723d_deinit_dm_priv(PADAPTER Adapter)303*4882a593Smuzhiyun void rtl8723d_deinit_dm_priv(PADAPTER Adapter)
304*4882a593Smuzhiyun {
305*4882a593Smuzhiyun PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
306*4882a593Smuzhiyun struct dm_struct *podmpriv = &pHalData->odmpriv;
307*4882a593Smuzhiyun
308*4882a593Smuzhiyun odm_cancel_all_timers(podmpriv);
309*4882a593Smuzhiyun
310*4882a593Smuzhiyun }
311