Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/hal/rtl8814a/rtl8814a_dm.c
1307 views
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 _RTL8814A_DM_C_
23
24
/* ************************************************************
25
* include files
26
* ************************************************************
27
* #include <drv_types.h> */
28
#include <rtl8814a_hal.h>
29
30
/* ************************************************************
31
* Global var
32
* ************************************************************ */
33
#ifdef CONFIG_SUPPORT_HW_WPS_PBC
34
static void dm_CheckPbcGPIO(_adapter *padapter)
35
{
36
u8 tmp1byte;
37
u8 bPbcPressed = _FALSE;
38
39
if (!padapter->registrypriv.hw_wps_pbc)
40
return;
41
#ifdef CONFIG_BT_COEXIST
42
if (hal_btcoex_IsBtExist(padapter))
43
return;
44
#endif /* CONFIG_BT_COEXIST */
45
46
#if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI)
47
48
tmp1byte = rtw_read8(padapter, REG_GPIO_EXT_CTRL_8814A);
49
/* RTW_INFO("CheckPbcGPIO - %x\n", tmp1byte); */
50
51
if (tmp1byte == 0xff)
52
return ;
53
else if (tmp1byte & BIT3) {
54
/* Here we only set bPbcPressed to TRUE. After trigger PBC, the variable will be set to FALSE */
55
RTW_INFO("CheckPbcGPIO - PBC is pressed\n");
56
bPbcPressed = _TRUE;
57
}
58
59
#endif
60
61
if (_TRUE == bPbcPressed) {
62
/* Here we only set bPbcPressed to true */
63
/* After trigger PBC, the variable will be set to false */
64
RTW_INFO("CheckPbcGPIO - PBC is pressed\n");
65
66
rtw_request_wps_pbc_event(padapter);
67
}
68
}
69
#endif /* #ifdef CONFIG_SUPPORT_HW_WPS_PBC */
70
71
#ifdef CONFIG_PCI_HCI
72
/*
73
* Description:
74
* Perform interrupt migration dynamically to reduce CPU utilization.
75
*
76
* Assumption:
77
* 1. Do not enable migration under WIFI test.
78
*
79
* Created by Roger, 2010.03.05.
80
* */
81
void
82
dm_InterruptMigration(
83
PADAPTER Adapter
84
)
85
{
86
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
87
struct mlme_priv *pmlmepriv = &(Adapter->mlmepriv);
88
BOOLEAN bCurrentIntMt, bCurrentACIntDisable;
89
BOOLEAN IntMtToSet = _FALSE;
90
BOOLEAN ACIntToSet = _FALSE;
91
92
93
/* Retrieve current interrupt migration and Tx four ACs IMR settings first. */
94
bCurrentIntMt = pHalData->bInterruptMigration;
95
bCurrentACIntDisable = pHalData->bDisableTxInt;
96
97
/* */
98
/* <Roger_Notes> Currently we use busy traffic for reference instead of RxIntOK counts to prevent non-linear Rx statistics */
99
/* when interrupt migration is set before. 2010.03.05. */
100
/* */
101
if (!Adapter->registrypriv.wifi_spec &&
102
(check_fwstate(pmlmepriv, _FW_LINKED) == _TRUE) &&
103
pmlmepriv->LinkDetectInfo.bHigherBusyTraffic) {
104
IntMtToSet = _TRUE;
105
106
/* To check whether we should disable Tx interrupt or not. */
107
if (pmlmepriv->LinkDetectInfo.bHigherBusyRxTraffic)
108
ACIntToSet = _TRUE;
109
}
110
111
/* Update current settings. */
112
if (bCurrentIntMt != IntMtToSet) {
113
RTW_INFO("%s(): Update interrrupt migration(%d)\n", __FUNCTION__, IntMtToSet);
114
if (IntMtToSet) {
115
/* */
116
/* <Roger_Notes> Set interrrupt migration timer and corresponging Tx/Rx counter. */
117
/* timer 25ns*0xfa0=100us for 0xf packets. */
118
/* 2010.03.05. */
119
/* */
120
rtw_write32(Adapter, REG_INT_MIG_8814A, 0xff000fa0);/* 0x306:Rx, 0x307:Tx */
121
pHalData->bInterruptMigration = IntMtToSet;
122
} else {
123
/* Reset all interrupt migration settings. */
124
rtw_write32(Adapter, REG_INT_MIG_8814A, 0);
125
pHalData->bInterruptMigration = IntMtToSet;
126
}
127
}
128
129
#if 0
130
if (bCurrentACIntDisable != ACIntToSet) {
131
RTW_INFO("%s(): Update AC interrrupt(%d)\n", __FUNCTION__, ACIntToSet);
132
if (ACIntToSet) { /* Disable four ACs interrupts. */
133
/* */
134
/* <Roger_Notes> Disable VO, VI, BE and BK four AC interrupts to gain more efficient CPU utilization. */
135
/* When extremely highly Rx OK occurs, we will disable Tx interrupts. */
136
/* 2010.03.05. */
137
/* */
138
UpdateInterruptMask8192CE(Adapter, 0, RT_AC_INT_MASKS);
139
pHalData->bDisableTxInt = ACIntToSet;
140
} else { /* Enable four ACs interrupts. */
141
UpdateInterruptMask8192CE(Adapter, RT_AC_INT_MASKS, 0);
142
pHalData->bDisableTxInt = ACIntToSet;
143
}
144
}
145
#endif
146
147
}
148
149
#endif /* CONFIG_PCI_HCI */
150
151
/*
152
* Initialize GPIO setting registers
153
* */
154
#ifdef CONFIG_USB_HCI
155
static void
156
dm_InitGPIOSetting(
157
PADAPTER Adapter
158
)
159
{
160
PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
161
162
u8 tmp1byte;
163
164
tmp1byte = rtw_read8(Adapter, REG_GPIO_MUXCFG);
165
tmp1byte &= (GPIOSEL_GPIO | ~GPIOSEL_ENBT);
166
167
rtw_write8(Adapter, REG_GPIO_MUXCFG, tmp1byte);
168
}
169
#endif
170
/* ************************************************************
171
* functions
172
* ************************************************************ */
173
static void Init_ODM_ComInfo_8814(PADAPTER Adapter)
174
{
175
PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
176
struct dm_struct *pDM_Odm = &(pHalData->odmpriv);
177
u32 SupportAbility = 0;
178
179
u8 cut_ver, fab_ver;
180
181
Init_ODM_ComInfo(Adapter);
182
183
fab_ver = ODM_TSMC;
184
if (IS_A_CUT(pHalData->version_id))
185
cut_ver = ODM_CUT_A;
186
else if (IS_B_CUT(pHalData->version_id))
187
cut_ver = ODM_CUT_B;
188
else if (IS_C_CUT(pHalData->version_id))
189
cut_ver = ODM_CUT_C;
190
else if (IS_D_CUT(pHalData->version_id))
191
cut_ver = ODM_CUT_D;
192
else if (IS_E_CUT(pHalData->version_id))
193
cut_ver = ODM_CUT_E;
194
else
195
cut_ver = ODM_CUT_A;
196
197
odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_FAB_VER, fab_ver);
198
odm_cmn_info_init(pDM_Odm, ODM_CMNINFO_CUT_VER, cut_ver);
199
200
}
201
202
void
203
rtl8814_InitHalDm(
204
PADAPTER Adapter
205
)
206
{
207
PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
208
struct dm_struct *pDM_Odm = &(pHalData->odmpriv);
209
210
#ifdef CONFIG_USB_HCI
211
dm_InitGPIOSetting(Adapter);
212
#endif /* CONFIG_USB_HCI */
213
rtw_phydm_init(Adapter);
214
/* Adapter->fix_rate = 0xFF; */
215
}
216
217
218
void
219
rtl8814_HalDmWatchDog(
220
PADAPTER Adapter
221
)
222
{
223
BOOLEAN bFwCurrentInPSMode = _FALSE;
224
u8 bFwPSAwake = _TRUE;
225
PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
226
struct dm_struct *pDM_Odm = &(pHalData->odmpriv);
227
struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(Adapter);
228
u8 in_lps = _FALSE;
229
230
if (!rtw_is_hw_init_completed(Adapter))
231
goto skip_dm;
232
233
#ifdef CONFIG_LPS
234
bFwCurrentInPSMode = pwrpriv->bFwCurrentInPSMode;
235
rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, &bFwPSAwake);
236
#endif
237
238
#ifdef CONFIG_P2P_PS
239
/* Fw is under p2p powersaving mode, driver should stop dynamic mechanism. */
240
/* modifed by thomas. 2011.06.11. */
241
if (Adapter->wdinfo.p2p_ps_mode)
242
bFwPSAwake = _FALSE;
243
#endif /* CONFIG_P2P_PS */
244
245
if ((rtw_is_hw_init_completed(Adapter))
246
&& ((!bFwCurrentInPSMode) && bFwPSAwake)) {
247
248
rtw_hal_check_rxfifo_full(Adapter);
249
/* */
250
/* Dynamically switch RTS/CTS protection. */
251
/* */
252
253
#ifdef CONFIG_PCI_HCI
254
/* 20100630 Joseph: Disable Interrupt Migration mechanism temporarily because it degrades Rx throughput. */
255
/* Tx Migration settings. */
256
/* dm_InterruptMigration(Adapter); */
257
258
/* if(Adapter->HalFunc.TxCheckStuckHandler(Adapter)) */
259
/* PlatformScheduleWorkItem(&(GET_HAL_DATA(Adapter)->HalResetWorkItem)); */
260
#endif
261
262
}
263
264
#ifdef CONFIG_DISABLE_ODM
265
goto skip_dm;
266
#endif
267
#ifdef CONFIG_LPS
268
if (pwrpriv->bLeisurePs && bFwCurrentInPSMode && pwrpriv->pwr_mode != PS_MODE_ACTIVE)
269
in_lps = _TRUE;
270
#endif
271
272
rtw_phydm_watchdog(Adapter, in_lps);
273
274
skip_dm:
275
276
#ifdef CONFIG_SUPPORT_HW_WPS_PBC
277
/* Check GPIO to determine current Pbc status. */
278
dm_CheckPbcGPIO(Adapter);
279
#endif
280
281
return;
282
}
283
284
void rtl8814_init_dm_priv(PADAPTER Adapter)
285
{
286
PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
287
struct dm_struct *podmpriv = &pHalData->odmpriv;
288
289
Init_ODM_ComInfo_8814(Adapter);
290
odm_init_all_timers(podmpriv);
291
pHalData->CurrentTxPwrIdx = 20;
292
}
293
294
void rtl8814_deinit_dm_priv(PADAPTER Adapter)
295
{
296
PHAL_DATA_TYPE pHalData = GET_HAL_DATA(Adapter);
297
struct dm_struct *podmpriv = &pHalData->odmpriv;
298
/* _rtw_spinlock_free(&pHalData->odm_stainfo_lock); */
299
odm_cancel_all_timers(podmpriv);
300
}
301
302