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