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