1
2
3
4
5
6
7
8
9
10#define _RTL8723B_DM_C_
11
12#include <drv_types.h>
13#include <rtw_debug.h>
14#include <rtl8723b_hal.h>
15
16
17
18static void dm_CheckStatistics(struct adapter *Adapter)
19{
20}
21
22
23
24static 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
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
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
70static 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
101
102
103
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
128void 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
146void 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
167
168 dm_CheckStatistics(Adapter);
169 rtw_hal_check_rxfifo_full(Adapter);
170 }
171
172
173 if (hw_init_completed == true) {
174 u8 bLinked = false;
175 u8 bsta_state = false;
176 u8 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
188
189 bBtDisabled = rtw_btcoex_IsBtDisabled(Adapter);
190
191 ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_BT_ENABLED, ((bBtDisabled == true)?false:true));
192
193 ODM_DMWatchdog(&pHalData->odmpriv);
194 }
195
196skip_dm:
197 return;
198}
199
200void rtl8723b_hal_dm_in_lps(struct adapter *padapter)
201{
202 u32 PWDB_rssi = 0;
203 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
204 struct hal_com_data *pHalData = GET_HAL_DATA(padapter);
205 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
206 struct sta_priv *pstapriv = &padapter->stapriv;
207 struct sta_info *psta = NULL;
208
209 DBG_871X("%s, RSSI_Min =%d\n", __func__, pDM_Odm->RSSI_Min);
210
211
212 ODM_Write_DIG(pDM_Odm, pDM_Odm->RSSI_Min);
213
214
215
216 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
217 if (psta && (psta->rssi_stat.UndecoratedSmoothedPWDB > 0)) {
218 PWDB_rssi = (psta->mac_id | (psta->rssi_stat.UndecoratedSmoothedPWDB<<16));
219
220 rtl8723b_set_rssi_cmd(padapter, (u8 *)&PWDB_rssi);
221 }
222
223}
224
225void rtl8723b_HalDmWatchDog_in_LPS(struct adapter *Adapter)
226{
227 u8 bLinked = false;
228 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
229 struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
230 struct dm_priv *pdmpriv = &pHalData->dmpriv;
231 PDM_ODM_T pDM_Odm = &pHalData->odmpriv;
232 pDIG_T pDM_DigTable = &pDM_Odm->DM_DigTable;
233 struct sta_priv *pstapriv = &Adapter->stapriv;
234 struct sta_info *psta = NULL;
235
236 if (Adapter->hw_init_completed == false)
237 goto skip_lps_dm;
238
239
240 if (rtw_linked_check(Adapter))
241 bLinked = true;
242
243 ODM_CmnInfoUpdate(&pHalData->odmpriv, ODM_CMNINFO_LINK, bLinked);
244
245 if (bLinked == false)
246 goto skip_lps_dm;
247
248 if (!(pDM_Odm->SupportAbility & ODM_BB_RSSI_MONITOR))
249 goto skip_lps_dm;
250
251
252
253
254
255
256 psta = rtw_get_stainfo(pstapriv, get_bssid(pmlmepriv));
257 if (psta == NULL)
258 goto skip_lps_dm;
259
260 pdmpriv->EntryMinUndecoratedSmoothedPWDB = psta->rssi_stat.UndecoratedSmoothedPWDB;
261
262 DBG_871X("CurIGValue =%d, EntryMinUndecoratedSmoothedPWDB = %d\n", pDM_DigTable->CurIGValue, pdmpriv->EntryMinUndecoratedSmoothedPWDB);
263
264 if (pdmpriv->EntryMinUndecoratedSmoothedPWDB <= 0)
265 goto skip_lps_dm;
266
267 pdmpriv->MinUndecoratedPWDBForDM = pdmpriv->EntryMinUndecoratedSmoothedPWDB;
268
269 pDM_Odm->RSSI_Min = pdmpriv->MinUndecoratedPWDBForDM;
270
271
272 if (
273 (pDM_DigTable->CurIGValue > pDM_Odm->RSSI_Min + 5) ||
274 (pDM_DigTable->CurIGValue < pDM_Odm->RSSI_Min - 5)
275 )
276 rtw_dm_in_lps_wk_cmd(Adapter);
277
278
279skip_lps_dm:
280
281 return;
282
283}
284
285void rtl8723b_init_dm_priv(struct adapter *Adapter)
286{
287 struct hal_com_data *pHalData = GET_HAL_DATA(Adapter);
288 struct dm_priv *pdmpriv = &pHalData->dmpriv;
289
290 memset(pdmpriv, 0, sizeof(struct dm_priv));
291 Init_ODM_ComInfo_8723b(Adapter);
292}
293