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