1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7 /* Description: */
8 /* This file is for 92CE/92CU dynamic mechanism only */
9
10 #define _RTL8723B_DM_C_
11
12 #include <drv_types.h>
13 #include <rtw_debug.h>
14 #include <rtl8723b_hal.h>
15
16 /* Global var */
17
dm_CheckStatistics(struct adapter * Adapter)18 static void dm_CheckStatistics(struct adapter *Adapter)
19 {
20 }
21 /* */
22 /* functions */
23 /* */
Init_ODM_ComInfo_8723b(struct adapter * Adapter)24 static void Init_ODM_ComInfo_8723b(struct adapter *Adapter)
25 {
26
27 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
28 PDM_ODM_T pDM_Odm = &(pHalData->odmpriv);
29 struct dm_priv *pdmpriv = &pHalData->dmpriv;
30 u8 cut_ver, fab_ver;
31
32 /* */
33 /* Init Value */
34 /* */
35 memset(pDM_Odm, 0, sizeof(*pDM_Odm));
36
37 pDM_Odm->Adapter = Adapter;
38 #define ODM_CE 0x04
39 ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_PLATFORM, ODM_CE);
40 ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_INTERFACE, RTW_SDIO);
41 ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_PACKAGE_TYPE, pHalData->PackageType);
42 ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_IC_TYPE, ODM_RTL8723B);
43
44 fab_ver = ODM_TSMC;
45 cut_ver = ODM_CUT_A;
46
47 DBG_871X("%s(): fab_ver =%d cut_ver =%d\n", __func__, fab_ver, cut_ver);
48 ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_FAB_VER, fab_ver);
49 ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_CUT_VER, cut_ver);
50 ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_MP_TEST_CHIP, IS_NORMAL_CHIP(pHalData->VersionID));
51
52 ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_PATCH_ID, pHalData->CustomerID);
53 /* ODM_CMNINFO_BINHCT_TEST only for MP Team */
54 ODM_CmnInfoInit(pDM_Odm, ODM_CMNINFO_BWIFI_TEST, Adapter->registrypriv.wifi_spec);
55
56
57 if (pHalData->rf_type == RF_1T1R) {
58 ODM_CmnInfoUpdate(pDM_Odm, ODM_CMNINFO_RF_TYPE, ODM_1T1R);
59 } else if (pHalData->rf_type == RF_2T2R) {
60 ODM_CmnInfoUpdate(pDM_Odm, ODM_CMNINFO_RF_TYPE, ODM_2T2R);
61 } else if (pHalData->rf_type == RF_1T2R) {
62 ODM_CmnInfoUpdate(pDM_Odm, ODM_CMNINFO_RF_TYPE, ODM_1T2R);
63 }
64
65 pdmpriv->InitODMFlag = ODM_RF_CALIBRATION|ODM_RF_TX_PWR_TRACK;
66
67 ODM_CmnInfoUpdate(pDM_Odm, ODM_CMNINFO_ABILITY, pdmpriv->InitODMFlag);
68 }
69
Update_ODM_ComInfo_8723b(struct adapter * Adapter)70 static void Update_ODM_ComInfo_8723b(struct adapter *Adapter)
71 {
72 struct mlme_ext_priv *pmlmeext = &Adapter->mlmeextpriv;
73 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
74 struct dvobj_priv *dvobj = adapter_to_dvobj(Adapter);
75 struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(Adapter);
76 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
77 PDM_ODM_T pDM_Odm = &(pHalData->odmpriv);
78 struct dm_priv *pdmpriv = &pHalData->dmpriv;
79 int i;
80 u8 zero = 0;
81
82 pdmpriv->InitODMFlag = 0
83 | ODM_BB_DIG
84 | ODM_BB_RA_MASK
85 | ODM_BB_DYNAMIC_TXPWR
86 | ODM_BB_FA_CNT
87 | ODM_BB_RSSI_MONITOR
88 | ODM_BB_CCK_PD
89 | ODM_BB_PWR_SAVE
90 | ODM_BB_CFO_TRACKING
91 | ODM_MAC_EDCA_TURBO
92 | ODM_RF_TX_PWR_TRACK
93 | ODM_RF_CALIBRATION
94 #ifdef CONFIG_ODM_ADAPTIVITY
95 | ODM_BB_ADAPTIVITY
96 #endif
97 ;
98
99 /* */
100 /* Pointer reference */
101 /* */
102 /* ODM_CMNINFO_MAC_PHY_MODE pHalData->MacPhyMode92D */
103 /* ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_MAC_PHY_MODE,&(pDM_Odm->u8_temp)); */
104
105 ODM_CmnInfoUpdate(pDM_Odm, ODM_CMNINFO_ABILITY, pdmpriv->InitODMFlag);
106
107 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_TX_UNI, &(dvobj->traffic_stat.tx_bytes));
108 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_RX_UNI, &(dvobj->traffic_stat.rx_bytes));
109 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_WM_MODE, &(pmlmeext->cur_wireless_mode));
110 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_SEC_CHNL_OFFSET, &(pHalData->nCur40MhzPrimeSC));
111 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_SEC_MODE, &(Adapter->securitypriv.dot11PrivacyAlgrthm));
112 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_BW, &(pHalData->CurrentChannelBW));
113 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_CHNL, &(pHalData->CurrentChannel));
114 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_NET_CLOSED, &(Adapter->net_closed));
115 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_MP_MODE, &zero);
116 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_BAND, &(pHalData->CurrentBandType));
117 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_FORCED_IGI_LB, &(pHalData->u1ForcedIgiLb));
118 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_FORCED_RATE, &(pHalData->ForcedDataRate));
119
120 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_SCAN, &(pmlmepriv->bScanInProcess));
121 ODM_CmnInfoHook(pDM_Odm, ODM_CMNINFO_POWER_SAVING, &(pwrctrlpriv->bpower_saving));
122
123
124 for (i = 0; i < NUM_STA; i++)
125 ODM_CmnInfoPtrArrayHook(pDM_Odm, ODM_CMNINFO_STA_STATUS, i, NULL);
126 }
127
rtl8723b_InitHalDm(struct adapter * Adapter)128 void rtl8723b_InitHalDm(struct adapter *Adapter)
129 {
130 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
131 struct dm_priv *pdmpriv = &pHalData->dmpriv;
132 PDM_ODM_T pDM_Odm = &(pHalData->odmpriv);
133
134 pdmpriv->DM_Type = DM_Type_ByDriver;
135 pdmpriv->DMFlag = DYNAMIC_FUNC_DISABLE;
136
137 pdmpriv->DMFlag |= DYNAMIC_FUNC_BT;
138
139 pdmpriv->InitDMFlag = pdmpriv->DMFlag;
140
141 Update_ODM_ComInfo_8723b(Adapter);
142
143 ODM_DMInit(pDM_Odm);
144 }
145
rtl8723b_HalDmWatchDog(struct adapter * Adapter)146 void rtl8723b_HalDmWatchDog(struct adapter *Adapter)
147 {
148 bool bFwCurrentInPSMode = false;
149 bool bFwPSAwake = true;
150 u8 hw_init_completed = false;
151 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
152
153 hw_init_completed = Adapter->hw_init_completed;
154
155 if (hw_init_completed == false)
156 goto skip_dm;
157
158 bFwCurrentInPSMode = adapter_to_pwrctl(Adapter)->bFwCurrentInPSMode;
159 rtw_hal_get_hwreg(Adapter, HW_VAR_FWLPS_RF_ON, (u8 *)(&bFwPSAwake));
160
161 if (
162 (hw_init_completed == true) &&
163 ((!bFwCurrentInPSMode) && bFwPSAwake)
164 ) {
165 /* */
166 /* Calculate Tx/Rx statistics. */
167 /* */
168 dm_CheckStatistics(Adapter);
169 rtw_hal_check_rxfifo_full(Adapter);
170 }
171
172 /* ODM */
173 if (hw_init_completed == true) {
174 u8 bLinked = false;
175 u8 bsta_state = false;
176 bool bBtDisabled = true;
177
178 if (rtw_linked_check(Adapter)) {
179 bLinked = true;
180 if (check_fwstate(&Adapter->mlmepriv, WIFI_STATION_STATE))
181 bsta_state = true;
182 }
183
184 ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_LINK, bLinked);
185 ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_STATION_STATE, bsta_state);
186
187 /* ODM_CmnInfoUpdate(&pHalData->odmpriv , ODM_CMNINFO_RSSI_MIN, pdmpriv->MinUndecoratedPWDBForDM); */
188
189 bBtDisabled = hal_btcoex_IsBtDisabled(Adapter);
190
191 ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_BT_ENABLED,
192 !bBtDisabled);
193
194 ODM_DMWatchdog(&pHalData->odmpriv);
195 }
196
197 skip_dm:
198 return;
199 }
200
rtl8723b_hal_dm_in_lps(struct adapter * padapter)201 void rtl8723b_hal_dm_in_lps(struct adapter *padapter)
202 {
203 u32 PWDB_rssi = 0;
204 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
205 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
206 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
207 struct sta_priv *pstapriv = &padapter->stapriv;
208 struct sta_info *psta = NULL;
209
210 DBG_871X("%s, RSSI_Min =%d\n", __func__, pDM_Odm->RSSI_Min);
211
212 /* update IGI */
213 ODM_Write_DIG(pDM_Odm, pDM_Odm->RSSI_Min);
214
215
216 /* set rssi to fw */
217 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
218 if (psta && (psta->rssi_stat.UndecoratedSmoothedPWDB > 0)) {
219 PWDB_rssi = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16));
220
221 rtl8723b_set_rssi_cmd(padapter, (u8 *)&PWDB_rssi);
222 }
223
224 }
225
rtl8723b_HalDmWatchDog_in_LPS(struct adapter * Adapter)226 void rtl8723b_HalDmWatchDog_in_LPS(struct adapter *Adapter)
227 {
228 u8 bLinked = false;
229 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
230 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
231 struct dm_priv *pdmpriv = &pHalData->dmpriv;
232 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
233 pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
234 struct sta_priv *pstapriv = &Adapter->stapriv;
235 struct sta_info *psta = NULL;
236
237 if (Adapter->hw_init_completed == false)
238 goto skip_lps_dm;
239
240
241 if (rtw_linked_check(Adapter))
242 bLinked = true;
243
244 ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_LINK, bLinked);
245
246 if (bLinked == false)
247 goto skip_lps_dm;
248
249 if (!(pDM_Odm->SupportAbility & ODM_BB_RSSI_MONITOR))
250 goto skip_lps_dm;
251
252
253 /* ODM_DMWatchdog(&pHalData->odmpriv); */
254 /* Do DIG by RSSI In LPS-32K */
255
256 /* 1 Find MIN-RSSI */
257 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
258 if (!psta)
259 goto skip_lps_dm;
260
261 pdmpriv->EntryMinUndecoratedSmoothedPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
262
263 DBG_871X("CurIGValue =%d, EntryMinUndecoratedSmoothedPWDB = %d\n", pDM_DigTable->CurIGValue, pdmpriv->EntryMinUndecoratedSmoothedPWDB);
264
265 if (pdmpriv->EntryMinUndecoratedSmoothedPWDB <= 0)
266 goto skip_lps_dm;
267
268 pdmpriv->MinUndecoratedPWDBForDM = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
269
270 pDM_Odm->RSSI_Min = pdmpriv->MinUndecoratedPWDBForDM;
271
272 /* if (pDM_DigTable->CurIGValue != pDM_Odm->RSSI_Min) */
273 if (
274 (pDM_DigTable->CurIGValue > pDM_Odm->RSSI_Min + 5) ||
275 (pDM_DigTable->CurIGValue < pDM_Odm->RSSI_Min - 5)
276 )
277 rtw_dm_in_lps_wk_cmd(Adapter);
278
279
280 skip_lps_dm:
281
282 return;
283
284 }
285
rtl8723b_init_dm_priv(struct adapter * Adapter)286 void rtl8723b_init_dm_priv(struct adapter *Adapter)
287 {
288 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
289 struct dm_priv *pdmpriv = &pHalData->dmpriv;
290
291 memset(pdmpriv, 0, sizeof(struct dm_priv));
292 Init_ODM_ComInfo_8723b(Adapter);
293 }
294