• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define _RTW_PWRCTRL_C_
16 
17 #include <drv_types.h>
18 #include <hal_data.h>
19 #include <hal_com_h2c.h>
20 
21 #ifdef DBG_CHECK_FW_PS_STATE
rtw_fw_ps_state(PADAPTER padapter)22 int rtw_fw_ps_state(PADAPTER padapter)
23 {
24 	struct dvobj_priv *psdpriv = padapter->dvobj;
25 	struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
26 	int ret = _FAIL, dont_care = 0;
27 	u16 fw_ps_state = 0;
28 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
29 	struct registry_priv  *registry_par = &padapter->registrypriv;
30 
31 	if (registry_par->check_fw_ps != 1)
32 		return _SUCCESS;
33 
34 	_enter_pwrlock(&pwrpriv->check_32k_lock);
35 
36 	if (RTW_CANNOT_RUN(padapter)) {
37 		RTW_INFO("%s: bSurpriseRemoved=%s , hw_init_completed=%d, bDriverStopped=%s\n", __func__
38 			 , rtw_is_surprise_removed(padapter) ? "True" : "False"
39 			 , rtw_get_hw_init_completed(padapter)
40 			 , rtw_is_drv_stopped(padapter) ? "True" : "False");
41 		goto exit_fw_ps_state;
42 	}
43 	#if defined(CONFIG_RTL8822B) || defined(CONFIG_RTL8821C) || defined(CONFIG_RTL8822C)
44 	rtw_hal_get_hwreg(padapter, HW_VAR_FW_PS_STATE, (u8 *)&fw_ps_state);
45 	if ((fw_ps_state & BIT_LPS_STATUS) == 0)
46 		ret = _SUCCESS;
47 	else {
48 		pdbgpriv->dbg_poll_fail_cnt++;
49 		RTW_INFO("%s: fw_ps_state=%04x\n", __FUNCTION__, fw_ps_state);
50 	}
51 	#else
52 	rtw_hal_set_hwreg(padapter, HW_VAR_SET_REQ_FW_PS, (u8 *)&dont_care);
53 	{
54 		/* 4. if 0x88[7]=1, driver set cmd to leave LPS/IPS. */
55 		/* Else, hw will keep in active mode. */
56 		/* debug info: */
57 		/* 0x88[7] = 32kpermission, */
58 		/* 0x88[6:0] = current_ps_state */
59 		/* 0x89[7:0] = last_rpwm */
60 
61 		rtw_hal_get_hwreg(padapter, HW_VAR_FW_PS_STATE, (u8 *)&fw_ps_state);
62 
63 		if ((fw_ps_state & 0x80) == 0)
64 			ret = _SUCCESS;
65 		else {
66 			pdbgpriv->dbg_poll_fail_cnt++;
67 			RTW_INFO("%s: fw_ps_state=%04x\n", __FUNCTION__, fw_ps_state);
68 		}
69 	}
70 	#endif
71 
72 exit_fw_ps_state:
73 	_exit_pwrlock(&pwrpriv->check_32k_lock);
74 	return ret;
75 }
76 #endif /*DBG_CHECK_FW_PS_STATE*/
77 #ifdef CONFIG_IPS
_ips_enter(_adapter * padapter)78 void _ips_enter(_adapter *padapter)
79 {
80 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
81 
82 	pwrpriv->bips_processing = _TRUE;
83 
84 	/* syn ips_mode with request */
85 	pwrpriv->ips_mode = pwrpriv->ips_mode_req;
86 
87 	pwrpriv->ips_enter_cnts++;
88 	RTW_INFO("==>ips_enter cnts:%d\n", pwrpriv->ips_enter_cnts);
89 
90 	if (rf_off == pwrpriv->change_rfpwrstate) {
91 		pwrpriv->bpower_saving = _TRUE;
92 		RTW_PRINT("nolinked power save enter\n");
93 
94 		if (pwrpriv->ips_mode == IPS_LEVEL_2)
95 			pwrpriv->bkeepfwalive = _TRUE;
96 
97 #ifdef CONFIG_RTW_CFGVENDOR_LLSTATS
98 		pwrpriv->pwr_saving_start_time = rtw_get_current_time();
99 #endif /* CONFIG_RTW_CFGVENDOR_LLSTATS */
100 
101 		rtw_ips_pwr_down(padapter);
102 		pwrpriv->rf_pwrstate = rf_off;
103 	}
104 	pwrpriv->bips_processing = _FALSE;
105 
106 }
107 
ips_enter(_adapter * padapter)108 void ips_enter(_adapter *padapter)
109 {
110 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
111 
112 
113 #ifdef CONFIG_BT_COEXIST
114 	rtw_btcoex_IpsNotify(padapter, pwrpriv->ips_mode_req);
115 #endif /* CONFIG_BT_COEXIST */
116 
117 	_enter_pwrlock(&pwrpriv->lock);
118 	_ips_enter(padapter);
119 	_exit_pwrlock(&pwrpriv->lock);
120 
121 #ifdef CONFIG_PCI_DYNAMIC_ASPM
122 	rtw_pci_dynamic_aspm_set_mode(padapter, ASPM_MODE_PS);
123 #endif
124 }
125 
_ips_leave(_adapter * padapter)126 int _ips_leave(_adapter *padapter)
127 {
128 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
129 	int result = _SUCCESS;
130 
131 	if ((pwrpriv->rf_pwrstate == rf_off) && (!pwrpriv->bips_processing)) {
132 		pwrpriv->bips_processing = _TRUE;
133 		pwrpriv->change_rfpwrstate = rf_on;
134 		pwrpriv->ips_leave_cnts++;
135 		RTW_INFO("==>ips_leave cnts:%d\n", pwrpriv->ips_leave_cnts);
136 
137 		result = rtw_ips_pwr_up(padapter);
138 		if (result == _SUCCESS)
139 			pwrpriv->rf_pwrstate = rf_on;
140 
141 #ifdef CONFIG_RTW_CFGVENDOR_LLSTATS
142 		pwrpriv->pwr_saving_time += rtw_get_passing_time_ms(pwrpriv->pwr_saving_start_time);
143 #endif /* CONFIG_RTW_CFGVENDOR_LLSTATS */
144 
145 		RTW_PRINT("nolinked power save leave\n");
146 
147 		RTW_INFO("==> ips_leave.....LED(0x%08x)...\n", rtw_read32(padapter, 0x4c));
148 		pwrpriv->bips_processing = _FALSE;
149 
150 		pwrpriv->bkeepfwalive = _FALSE;
151 		pwrpriv->bpower_saving = _FALSE;
152 	}
153 
154 	return result;
155 }
156 
ips_leave(_adapter * padapter)157 int ips_leave(_adapter *padapter)
158 {
159 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
160 #ifdef DBG_CHECK_FW_PS_STATE
161 	struct dvobj_priv *psdpriv = padapter->dvobj;
162 	struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
163 #endif
164 	int ret;
165 
166 	if (!is_primary_adapter(padapter))
167 		return _SUCCESS;
168 
169 	_enter_pwrlock(&pwrpriv->lock);
170 	ret = _ips_leave(padapter);
171 #ifdef DBG_CHECK_FW_PS_STATE
172 	if (rtw_fw_ps_state(padapter) == _FAIL) {
173 		RTW_INFO("ips leave doesn't leave 32k\n");
174 		pdbgpriv->dbg_leave_ips_fail_cnt++;
175 	}
176 #endif /* DBG_CHECK_FW_PS_STATE */
177 	_exit_pwrlock(&pwrpriv->lock);
178 
179 #ifdef CONFIG_PCI_DYNAMIC_ASPM
180 	rtw_pci_dynamic_aspm_set_mode(padapter, ASPM_MODE_PERF);
181 #endif
182 
183 	if (_SUCCESS == ret)
184 		odm_dm_reset(&GET_HAL_DATA(padapter)->odmpriv);
185 
186 #ifdef CONFIG_BT_COEXIST
187 	if (_SUCCESS == ret)
188 		rtw_btcoex_IpsNotify(padapter, IPS_NONE);
189 #endif /* CONFIG_BT_COEXIST */
190 
191 	return ret;
192 }
193 #endif /* CONFIG_IPS */
194 
195 #ifdef SUPPORT_HW_RFOFF_DETECTED
196 	int rtw_hw_suspend(_adapter *padapter);
197 	int rtw_hw_resume(_adapter *padapter);
198 #endif
199 
rtw_pwr_unassociated_idle(_adapter * adapter)200 bool rtw_pwr_unassociated_idle(_adapter *adapter)
201 {
202 	u8 i;
203 	_adapter *iface;
204 	struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
205 	struct xmit_priv *pxmit_priv = &adapter->xmitpriv;
206 	struct mlme_priv *pmlmepriv;
207 #ifdef CONFIG_P2P
208 	struct wifidirect_info	*pwdinfo;
209 #endif
210 
211 	bool ret = _FALSE;
212 
213 	if (adapter_to_pwrctl(adapter)->bpower_saving == _TRUE) {
214 		/* RTW_INFO("%s: already in LPS or IPS mode\n", __func__); */
215 		goto exit;
216 	}
217 
218 	if (rtw_time_after(adapter_to_pwrctl(adapter)->ips_deny_time, rtw_get_current_time())) {
219 		/* RTW_INFO("%s ips_deny_time\n", __func__); */
220 		goto exit;
221 	}
222 
223 	for (i = 0; i < dvobj->iface_nums; i++) {
224 		iface = dvobj->padapters[i];
225 		if ((iface) && rtw_is_adapter_up(iface)) {
226 			pmlmepriv = &(iface->mlmepriv);
227 #ifdef CONFIG_P2P
228 			pwdinfo = &(iface->wdinfo);
229 #endif
230 			if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE | WIFI_UNDER_SURVEY)
231 				|| check_fwstate(pmlmepriv, WIFI_UNDER_LINKING | WIFI_UNDER_WPS)
232 				|| MLME_IS_AP(iface)
233 				|| MLME_IS_MESH(iface)
234 				|| check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE)
235 				#if defined(CONFIG_IOCTL_CFG80211)
236 				|| rtw_cfg80211_get_is_roch(iface) == _TRUE
237 				|| (rtw_cfg80211_is_ro_ch_once(adapter)
238 					&& rtw_cfg80211_get_last_ro_ch_passing_ms(adapter) < 3000)
239 				#elif defined(CONFIG_P2P)
240 				|| rtw_p2p_chk_state(pwdinfo, P2P_STATE_IDLE)
241 				|| rtw_p2p_chk_state(pwdinfo, P2P_STATE_LISTEN)
242 				#endif
243 			)
244 				goto exit;
245 
246 		}
247 	}
248 
249 #if (MP_DRIVER == 1)
250 	if (adapter->registrypriv.mp_mode == 1)
251 		goto exit;
252 #endif
253 
254 	if (pxmit_priv->free_xmitbuf_cnt != NR_XMITBUFF ||
255 	    pxmit_priv->free_xmit_extbuf_cnt != NR_XMIT_EXTBUFF) {
256 		RTW_PRINT("There are some pkts to transmit\n");
257 		RTW_PRINT("free_xmitbuf_cnt: %d, free_xmit_extbuf_cnt: %d\n",
258 			pxmit_priv->free_xmitbuf_cnt, pxmit_priv->free_xmit_extbuf_cnt);
259 		goto exit;
260 	}
261 
262 	ret = _TRUE;
263 
264 exit:
265 	return ret;
266 }
267 
268 
269 /*
270  * ATTENTION:
271  *	rtw_ps_processor() doesn't handle LPS.
272  */
rtw_ps_processor(_adapter * padapter)273 void rtw_ps_processor(_adapter *padapter)
274 {
275 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
276 	struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
277 	struct dvobj_priv *psdpriv = padapter->dvobj;
278 	struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
279 #ifdef SUPPORT_HW_RFOFF_DETECTED
280 	rt_rf_power_state rfpwrstate;
281 #endif /* SUPPORT_HW_RFOFF_DETECTED */
282 	u32 ps_deny = 0;
283 
284 	_enter_pwrlock(&adapter_to_pwrctl(padapter)->lock);
285 	ps_deny = rtw_ps_deny_get(padapter);
286 	_exit_pwrlock(&adapter_to_pwrctl(padapter)->lock);
287 	if (ps_deny != 0) {
288 		if (!MLME_IS_MONITOR(padapter)) {
289 			RTW_INFO(FUNC_ADPT_FMT ": ps_deny=0x%08X, skip power save!\n",
290 				 FUNC_ADPT_ARG(padapter), ps_deny);
291 		}
292 		goto exit;
293 	}
294 
295 	if (pwrpriv->bInSuspend == _TRUE) { /* system suspend or autosuspend */
296 		pdbgpriv->dbg_ps_insuspend_cnt++;
297 		RTW_INFO("%s, pwrpriv->bInSuspend == _TRUE ignore this process\n", __FUNCTION__);
298 		return;
299 	}
300 
301 	pwrpriv->ps_processing = _TRUE;
302 
303 #ifdef SUPPORT_HW_RFOFF_DETECTED
304 	if (pwrpriv->bips_processing == _TRUE)
305 		goto exit;
306 
307 	/* RTW_INFO("==> fw report state(0x%x)\n",rtw_read8(padapter,0x1ca));	 */
308 	if (pwrpriv->bHWPwrPindetect) {
309 
310 		rfpwrstate = RfOnOffDetect(padapter);
311 		RTW_INFO("@@@@- #2  %s==> rfstate:%s\n", __FUNCTION__, (rfpwrstate == rf_on) ? "rf_on" : "rf_off");
312 
313 		if (rfpwrstate != pwrpriv->rf_pwrstate) {
314 			if (rfpwrstate == rf_off) {
315 				pwrpriv->change_rfpwrstate = rf_off;
316 				pwrpriv->brfoffbyhw = _TRUE;
317 				rtw_hw_suspend(padapter);
318 			} else {
319 				pwrpriv->change_rfpwrstate = rf_on;
320 				rtw_hw_resume(padapter);
321 			}
322 			RTW_INFO("current rf_pwrstate(%s)\n", (pwrpriv->rf_pwrstate == rf_off) ? "rf_off" : "rf_on");
323 		}
324 
325 		pwrpriv->pwr_state_check_cnts++;
326 	}
327 #endif /* SUPPORT_HW_RFOFF_DETECTED */
328 
329 	if (pwrpriv->ips_mode_req == IPS_NONE)
330 		goto exit;
331 
332 	if (rtw_pwr_unassociated_idle(padapter) == _FALSE)
333 		goto exit;
334 
335 	if ((pwrpriv->rf_pwrstate == rf_on) && ((pwrpriv->pwr_state_check_cnts % 4) == 0)) {
336 		RTW_INFO("==>%s .fw_state(%x)\n", __FUNCTION__, get_fwstate(pmlmepriv));
337 		pwrpriv->change_rfpwrstate = rf_off;
338 
339 #ifdef CONFIG_IPS
340 			ips_enter(padapter);
341 #endif
342 
343 	}
344 exit:
345 #ifndef CONFIG_IPS_CHECK_IN_WD
346 	rtw_set_pwr_state_check_timer(pwrpriv);
347 #endif
348 	pwrpriv->ps_processing = _FALSE;
349 	return;
350 }
351 
pwr_state_check_handler(void * ctx)352 void pwr_state_check_handler(void *ctx)
353 {
354 	_adapter *padapter = (_adapter *)ctx;
355 	rtw_ps_cmd(padapter);
356 }
357 
358 #ifdef CONFIG_LPS
359 #ifdef CONFIG_CHECK_LEAVE_LPS
360 #ifdef CONFIG_LPS_CHK_BY_TP
traffic_check_for_leave_lps_by_tp(PADAPTER padapter,u8 tx,struct sta_info * sta)361 void traffic_check_for_leave_lps_by_tp(PADAPTER padapter, u8 tx, struct sta_info *sta)
362 {
363 	struct stainfo_stats *pstats = &sta->sta_stats;
364 	u64 cur_acc_tx_bytes = 0, cur_acc_rx_bytes = 0;
365 	u32 tx_tp_kbyte = 0, rx_tp_kbyte = 0;
366 	u32 tx_tp_th = 0, rx_tp_th = 0;
367 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
368 	u8	leave_lps = _FALSE;
369 
370 	if (tx) { /* from tx */
371 		cur_acc_tx_bytes = pstats->tx_bytes - pstats->acc_tx_bytes;
372 		tx_tp_kbyte = cur_acc_tx_bytes >> 10;
373 		tx_tp_th = pwrpriv->lps_tx_tp_th * 1024 / 8 * 2; /*KBytes @2s*/
374 
375 		if (tx_tp_kbyte >= tx_tp_th ||
376 			padapter->mlmepriv.LinkDetectInfo.NumTxOkInPeriod >= pwrpriv->lps_tx_pkts){
377 			if (pwrpriv->bLeisurePs
378 				&& (pwrpriv->pwr_mode != PS_MODE_ACTIVE)
379 				#ifdef CONFIG_BT_COEXIST
380 				&& (rtw_btcoex_IsBtControlLps(padapter) == _FALSE)
381 				#endif
382 			) {
383 				leave_lps = _TRUE;
384 			}
385 		}
386 
387 	} else { /* from rx path */
388 		cur_acc_rx_bytes = pstats->rx_bytes - pstats->acc_rx_bytes;
389 		rx_tp_kbyte = cur_acc_rx_bytes >> 10;
390 		rx_tp_th = pwrpriv->lps_rx_tp_th * 1024 / 8 * 2;
391 
392 		if (rx_tp_kbyte>= rx_tp_th ||
393 			padapter->mlmepriv.LinkDetectInfo.NumRxUnicastOkInPeriod >= pwrpriv->lps_rx_pkts) {
394 			if (pwrpriv->bLeisurePs
395 				&& (pwrpriv->pwr_mode != PS_MODE_ACTIVE)
396 				#ifdef CONFIG_BT_COEXIST
397 				&& (rtw_btcoex_IsBtControlLps(padapter) == _FALSE)
398 				#endif
399 			) {
400 				leave_lps = _TRUE;
401 			}
402 		}
403 	}
404 
405 	if (leave_lps) {
406 		#ifdef DBG_LPS_CHK_BY_TP
407 		RTW_INFO("leave lps via %s, ", tx ? "Tx" : "Rx");
408 		if (tx)
409 			RTW_INFO("Tx = %d [%d] (KB)\n", tx_tp_kbyte, tx_tp_th);
410 		else
411 			RTW_INFO("Rx = %d [%d] (KB)\n", rx_tp_kbyte, rx_tp_th);
412 		#endif
413 		pwrpriv->lps_chk_cnt = pwrpriv->lps_chk_cnt_th;
414 		/* rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE, 0); */
415 		rtw_lps_ctrl_wk_cmd(padapter, tx ? LPS_CTRL_TX_TRAFFIC_LEAVE : LPS_CTRL_RX_TRAFFIC_LEAVE, 0);
416 	}
417 }
418 #endif /*CONFIG_LPS_CHK_BY_TP*/
419 
traffic_check_for_leave_lps(PADAPTER padapter,u8 tx,u32 tx_packets)420 void	traffic_check_for_leave_lps(PADAPTER padapter, u8 tx, u32 tx_packets)
421 {
422 	static systime start_time = 0;
423 	static u32 xmit_cnt = 0;
424 	u8	bLeaveLPS = _FALSE;
425 	struct mlme_priv	*pmlmepriv = &padapter->mlmepriv;
426 
427 
428 
429 	if (tx) { /* from tx */
430 		xmit_cnt += tx_packets;
431 
432 		if (start_time == 0)
433 			start_time = rtw_get_current_time();
434 
435 		if (rtw_get_passing_time_ms(start_time) > 2000) { /* 2 sec == watch dog timer */
436 			if (xmit_cnt > 8) {
437 				if ((adapter_to_pwrctl(padapter)->bLeisurePs)
438 				    && (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE)
439 #ifdef CONFIG_BT_COEXIST
440 				    && (rtw_btcoex_IsBtControlLps(padapter) == _FALSE)
441 #endif
442 				   ) {
443 					/* RTW_INFO("leave lps via Tx = %d\n", xmit_cnt);			 */
444 					bLeaveLPS = _TRUE;
445 				}
446 			}
447 
448 			start_time = rtw_get_current_time();
449 			xmit_cnt = 0;
450 		}
451 
452 	} else { /* from rx path */
453 		if (pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod > 4/*2*/) {
454 			if ((adapter_to_pwrctl(padapter)->bLeisurePs)
455 			    && (adapter_to_pwrctl(padapter)->pwr_mode != PS_MODE_ACTIVE)
456 #ifdef CONFIG_BT_COEXIST
457 			    && (rtw_btcoex_IsBtControlLps(padapter) == _FALSE)
458 #endif
459 			   ) {
460 				/* RTW_INFO("leave lps via Rx = %d\n", pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod);	 */
461 				bLeaveLPS = _TRUE;
462 			}
463 		}
464 	}
465 
466 	if (bLeaveLPS) {
467 		/* RTW_INFO("leave lps via %s, Tx = %d, Rx = %d\n", tx?"Tx":"Rx", pmlmepriv->LinkDetectInfo.NumTxOkInPeriod,pmlmepriv->LinkDetectInfo.NumRxUnicastOkInPeriod);	 */
468 		/* rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_LEAVE, 0); */
469 		rtw_lps_ctrl_wk_cmd(padapter, tx ? LPS_CTRL_TX_TRAFFIC_LEAVE : LPS_CTRL_RX_TRAFFIC_LEAVE, tx ? RTW_CMDF_DIRECTLY : 0);
470 	}
471 }
472 #endif /* CONFIG_CHECK_LEAVE_LPS */
473 
474 #ifdef CONFIG_LPS_LCLK
475 #define LPS_CPWM_TIMEOUT_MS	10 /*ms*/
476 #define LPS_RPWM_RETRY_CNT		3
477 
rtw_cpwm_polling(_adapter * adapter,u8 rpwm,u8 cpwm_orig)478 u8 rtw_cpwm_polling(_adapter *adapter, u8 rpwm, u8 cpwm_orig)
479 {
480 	u8 rst = _FAIL;
481 	u8 cpwm_now = 0;
482 	systime start_time;
483 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(adapter);
484 	#ifdef DBG_CHECK_FW_PS_STATE
485 	struct debug_priv *pdbgpriv = &(adapter_to_dvobj(adapter)->drv_dbg);
486 	#endif
487 
488 	pwrpriv->rpwm_retry = 0;
489 
490 	do {
491 		start_time = rtw_get_current_time();
492 		do {
493 			rtw_msleep_os(1);
494 			rtw_hal_get_hwreg(adapter, HW_VAR_CPWM, &cpwm_now);
495 
496 			if ((cpwm_orig ^ cpwm_now) & 0x80) {
497 				pwrpriv->cpwm = PS_STATE_S4;
498 				pwrpriv->cpwm_tog = cpwm_now & PS_TOGGLE;
499 				rst = _SUCCESS;
500 				break;
501 			}
502 		} while (rtw_get_passing_time_ms(start_time) < LPS_CPWM_TIMEOUT_MS && !RTW_CANNOT_RUN(adapter));
503 
504 		if (rst == _SUCCESS)
505 			break;
506 		else {
507 			/* rpwm retry */
508 			cpwm_orig = cpwm_now;
509 			rpwm &= ~PS_TOGGLE;
510 			rpwm |= pwrpriv->tog;
511 			rtw_hal_set_hwreg(adapter, HW_VAR_SET_RPWM, (u8 *)(&rpwm));
512 			pwrpriv->tog += 0x80;
513 		}
514 	} while (pwrpriv->rpwm_retry++ < LPS_RPWM_RETRY_CNT && !RTW_CANNOT_RUN(adapter));
515 
516 	if (rst == _SUCCESS) {
517 		#ifdef DBG_CHECK_FW_PS_STATE
518 		RTW_INFO("%s: polling cpwm OK! rpwm_retry=%d, cpwm_orig=%02x, cpwm_now=%02x , 0x100=0x%x\n"
519 			, __func__, pwrpriv->rpwm_retry, cpwm_orig, cpwm_now, rtw_read8(adapter, REG_CR));
520 		if (rtw_fw_ps_state(adapter) == _FAIL) {
521 			RTW_INFO("leave 32k but fw state in 32k\n");
522 			pdbgpriv->dbg_rpwm_toogle_cnt++;
523 		}
524 		#endif /* DBG_CHECK_FW_PS_STATE */
525 	} else {
526 		RTW_ERR("%s: polling cpwm timeout! rpwm_retry=%d, cpwm_orig=%02x, cpwm_now=%02x\n"
527 				, __func__, pwrpriv->rpwm_retry, cpwm_orig, cpwm_now);
528 		#ifdef DBG_CHECK_FW_PS_STATE
529 		if (rtw_fw_ps_state(adapter) == _FAIL) {
530 			RTW_INFO("rpwm timeout and fw ps state in 32k\n");
531 			pdbgpriv->dbg_rpwm_timeout_fail_cnt++;
532 		}
533 		#endif /* DBG_CHECK_FW_PS_STATE */
534 
535 		#ifdef CONFIG_LPS_RPWM_TIMER
536 		_set_timer(&pwrpriv->pwr_rpwm_timer, 1);
537 		#endif /* CONFIG_LPS_RPWM_TIMER */
538 	}
539 
540 	return rst;
541 }
542 #endif
543 /*
544  * Description:
545  *	This function MUST be called under power lock protect
546  *
547  * Parameters
548  *	padapter
549  *	pslv			power state level, only could be PS_STATE_S0 ~ PS_STATE_S4
550  *
551  */
rtw_set_rpwm(PADAPTER padapter,u8 pslv)552 u8 rtw_set_rpwm(PADAPTER padapter, u8 pslv)
553 {
554 	u8	rpwm = 0xFF;
555 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
556 #ifdef CONFIG_LPS_LCLK
557 	u8 cpwm_orig;
558 #endif
559 
560 	pslv = PS_STATE(pslv);
561 
562 #ifdef CONFIG_LPS_RPWM_TIMER
563 	if (pwrpriv->brpwmtimeout == _TRUE)
564 		RTW_INFO("%s: RPWM timeout, force to set RPWM(0x%02X) again!\n", __FUNCTION__, pslv);
565 	else
566 #endif /* CONFIG_LPS_RPWM_TIMER */
567 	{
568 		if ((pwrpriv->rpwm == pslv)
569 #ifdef CONFIG_LPS_LCLK
570 		    || ((pwrpriv->rpwm >= PS_STATE_S2) && (pslv >= PS_STATE_S2))
571 #endif
572 			|| (pwrpriv->lps_level == LPS_NORMAL)
573 		   ) {
574 			return rpwm;
575 		}
576 	}
577 
578 	if (rtw_is_surprise_removed(padapter) ||
579 	    (!rtw_is_hw_init_completed(padapter))) {
580 
581 		pwrpriv->cpwm = PS_STATE_S4;
582 
583 		return rpwm;
584 	}
585 
586 	if (rtw_is_drv_stopped(padapter))
587 		if (pslv < PS_STATE_S2)
588 			return rpwm;
589 
590 	rpwm = pslv | pwrpriv->tog;
591 #ifdef CONFIG_LPS_LCLK
592 	/* only when from PS_STATE S0/S1 to S2 and higher needs ACK */
593 	if ((pwrpriv->cpwm < PS_STATE_S2) && (pslv >= PS_STATE_S2))
594 		rpwm |= PS_ACK;
595 #endif
596 
597 	pwrpriv->rpwm = pslv;
598 
599 #ifdef CONFIG_LPS_LCLK
600 	cpwm_orig = 0;
601 	if (rpwm & PS_ACK)
602 		rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_orig);
603 #endif
604 
605 #if defined(CONFIG_LPS_RPWM_TIMER) && !defined(CONFIG_DETECT_CPWM_BY_POLLING)
606 	if (rpwm & PS_ACK) {
607 		#if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN) || defined(CONFIG_P2P_WOWLAN)
608 		if (pwrpriv->wowlan_mode != _TRUE &&
609 			pwrpriv->wowlan_ap_mode != _TRUE &&
610 			pwrpriv->wowlan_p2p_mode != _TRUE)
611 		#endif
612 		_set_timer(&pwrpriv->pwr_rpwm_timer, LPS_CPWM_TIMEOUT_MS);
613 	}
614 #endif /* CONFIG_LPS_RPWM_TIMER & !CONFIG_DETECT_CPWM_BY_POLLING */
615 
616 	rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&rpwm));
617 
618 	pwrpriv->tog += 0x80;
619 
620 #ifdef CONFIG_LPS_LCLK
621 	/* No LPS 32K, No Ack */
622 	if (rpwm & PS_ACK) {
623 		#ifdef CONFIG_DETECT_CPWM_BY_POLLING
624 		rtw_cpwm_polling(padapter, rpwm, cpwm_orig);
625 		#else
626 		#if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN) || defined(CONFIG_P2P_WOWLAN)
627 		if (pwrpriv->wowlan_mode == _TRUE ||
628 			pwrpriv->wowlan_ap_mode == _TRUE ||
629 			pwrpriv->wowlan_p2p_mode == _TRUE)
630 				rtw_cpwm_polling(padapter, rpwm, cpwm_orig);
631 		#endif /*#if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN) || defined(CONFIG_P2P_WOWLAN)*/
632 		#endif /*#ifdef CONFIG_DETECT_CPWM_BY_POLLING*/
633 	} else
634 #endif /* CONFIG_LPS_LCLK */
635 	{
636 		pwrpriv->cpwm = pslv;
637 	}
638 
639 	return rpwm;
640 }
641 
PS_RDY_CHECK(_adapter * padapter)642 u8 PS_RDY_CHECK(_adapter *padapter)
643 {
644 	struct pwrctrl_priv	*pwrpriv = adapter_to_pwrctl(padapter);
645 	struct mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
646 
647 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN)
648 	if (_TRUE == pwrpriv->bInSuspend && pwrpriv->wowlan_mode)
649 		return _TRUE;
650 	else if (_TRUE == pwrpriv->bInSuspend && pwrpriv->wowlan_ap_mode)
651 		return _TRUE;
652 	else if (_TRUE == pwrpriv->bInSuspend)
653 		return _FALSE;
654 #else
655 	if (_TRUE == pwrpriv->bInSuspend)
656 		return _FALSE;
657 #endif
658 
659 	if (rtw_time_after(pwrpriv->lps_deny_time, rtw_get_current_time()))
660 		return _FALSE;
661 
662 	if (check_fwstate(pmlmepriv, WIFI_UNDER_SURVEY)
663 		|| check_fwstate(pmlmepriv, WIFI_UNDER_LINKING | WIFI_UNDER_WPS)
664 		|| MLME_IS_AP(padapter)
665 		|| MLME_IS_MESH(padapter)
666 		|| MLME_IS_MONITOR(padapter)
667 		|| check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE | WIFI_ADHOC_STATE)
668 		#if defined(CONFIG_IOCTL_CFG80211)
669 		|| rtw_cfg80211_get_is_roch(padapter) == _TRUE
670 		#endif
671 		|| rtw_is_scan_deny(padapter)
672 		#ifdef CONFIG_TDLS
673 		/* TDLS link is established. */
674 		|| (padapter->tdlsinfo.link_established == _TRUE)
675 		#endif /* CONFIG_TDLS		 */
676 		#ifdef CONFIG_DFS_MASTER
677 		|| adapter_to_rfctl(padapter)->radar_detect_enabled
678 		#endif
679 	)
680 		return _FALSE;
681 
682 	if ((padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X) && (padapter->securitypriv.binstallGrpkey == _FALSE)) {
683 		RTW_INFO("Group handshake still in progress !!!\n");
684 		return _FALSE;
685 	}
686 
687 #ifdef CONFIG_IOCTL_CFG80211
688 	if (!rtw_cfg80211_pwr_mgmt(padapter))
689 		return _FALSE;
690 #endif
691 
692 	return _TRUE;
693 }
694 
695 #ifdef CONFIG_LPS_LCLK
rtw_set_lps_lclk(_adapter * padapter,u8 enable)696 void rtw_set_lps_lclk(_adapter *padapter, u8 enable)
697 {
698 	struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
699 	u8 val8 = 0;
700 	u8 polling_cnt = 0;
701 	u8 cpwm_orig = 0;
702 	u8 cpwm_now = 0;
703 	u8 result = _FAIL;
704 	systime start_time;
705 
706 	if (enable) {
707 		/* set rpwm to enter 32k */
708 		rtw_hal_get_hwreg(padapter, HW_VAR_RPWM_TOG, &val8);
709 		RTW_INFO("%s: read rpwm=%02x\n", __func__, val8);
710 		val8 += PS_TOGGLE;
711 		val8 |= PS_LCLK;
712 		rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&val8));
713 		RTW_INFO("%s: write rpwm=%02x\n", __func__, val8);
714 		pwrctl->tog = (val8 + PS_TOGGLE) & PS_TOGGLE;
715 
716 		/* When using PNO, the FW may scan first, so polling register 100
717 		 * may not see 0xEA at this point.
718 		 */
719 		if (!pwrctl->wowlan_pno_enable) {
720 			do {
721 				val8 = rtw_read8(padapter, REG_CR);
722 				polling_cnt++;
723 				RTW_INFO("%s  polling 0x100=0x%x, cnt=%d\n",
724 					 __func__, val8, polling_cnt);
725 				RTW_INFO("%s 0x08:%02x, 0x03:%02x\n",
726 					 __func__,
727 					 rtw_read8(padapter, 0x08),
728 					 rtw_read8(padapter, 0x03));
729 				rtw_mdelay_os(10);
730 			} while (polling_cnt < 20 && (val8 != 0xEA));
731 		}
732 	} else {
733 		/* for polling cpwm */
734 		rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_orig);
735 
736 		/* set rpwm to leave 32k */
737 		rtw_hal_get_hwreg(padapter, HW_VAR_RPWM_TOG, &val8);
738 		RTW_INFO("%s: read rpwm=%02x\n", __func__, val8);
739 		val8 += PS_TOGGLE;
740 		val8 |= PS_ACK;
741 		rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&val8));
742 		RTW_INFO("%s: write rpwm=%02x\n", __func__, val8);
743 		pwrctl->tog = (val8 + PS_TOGGLE) & PS_TOGGLE;
744 
745 		/* do polling cpwm */
746 		start_time = rtw_get_current_time();
747 		do {
748 			rtw_mdelay_os(1);
749 
750 			rtw_hal_get_hwreg(padapter, HW_VAR_CPWM, &cpwm_now);
751 			if ((cpwm_orig ^ cpwm_now) & PS_TOGGLE)
752 				break;
753 
754 			if (rtw_get_passing_time_ms(start_time) > 100) {
755 				RTW_INFO("%s: polling cpwm timeout\n",
756 					__func__);
757 				break;
758 			}
759 		} while (1);
760 
761 #ifdef CONFIG_PNO_SUPPORT
762 		if (pwrctl->wowlan_pno_enable) {
763 			do {
764 				rtw_mdelay_os(1);
765 
766 				val8 = rtw_read8(padapter, REG_CR);
767 				if (val8 != 0xEA) {
768 					result = _SUCCESS;
769 					break;
770 				}
771 
772 				polling_cnt++;
773 			} while (polling_cnt < 100);
774 
775 			if (result == _FAIL )
776 				RTW_INFO("%s: It is not finished to leave 32K\n",
777 					__func__);
778 		}
779 #endif
780 	}
781 }
782 #endif
783 
784 #if defined(CONFIG_FWLPS_IN_IPS)
rtw_set_fw_in_ips_mode(PADAPTER padapter,u8 enable)785 void rtw_set_fw_in_ips_mode(PADAPTER padapter, u8 enable)
786 {
787 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
788 	int cnt = 0;
789 	u8 val8 = 0;
790 	u8 parm[H2C_INACTIVE_PS_LEN] = {0};
791 
792 	if (padapter->netif_up == _FALSE) {
793 		RTW_INFO("%s: ERROR, netif is down\n", __func__);
794 		return;
795 	}
796 
797 	/* u8 cmd_param; */ /* BIT0:enable, BIT1:NoConnect32k */
798 	if (enable) {
799 #ifdef CONFIG_BT_COEXIST
800 		rtw_btcoex_IpsNotify(padapter, pwrpriv->ips_mode_req);
801 #endif
802 		/* Enter IPS */
803 		RTW_INFO("%s: issue H2C to FW when entering IPS\n", __func__);
804 
805 		parm[0] = 0x1;/* suggest by Isaac.Hsu*/
806 #ifdef CONFIG_PNO_SUPPORT
807 		if (pwrpriv->pno_inited) {
808 			parm[1] = pwrpriv->pnlo_info->fast_scan_iterations;
809 			parm[2] = pwrpriv->pnlo_info->slow_scan_period;
810 		}
811 #endif
812 
813 		rtw_hal_fill_h2c_cmd(padapter, /* H2C_FWLPS_IN_IPS_, */
814 				     H2C_INACTIVE_PS_,
815 				     H2C_INACTIVE_PS_LEN, parm);
816 		/* poll 0x1cc to make sure H2C command already finished by FW; MAC_0x1cc=0 means H2C done by FW. */
817 		do {
818 			val8 = rtw_read8(padapter, REG_HMETFR);
819 			cnt++;
820 			RTW_INFO("%s  polling REG_HMETFR=0x%x, cnt=%d\n",
821 				 __func__, val8, cnt);
822 			rtw_mdelay_os(10);
823 		} while (cnt < 100 && (val8 != 0));
824 
825 #ifdef CONFIG_LPS_LCLK
826 		/* H2C done, enter 32k */
827 		if (val8 == 0)
828 			rtw_set_lps_lclk(padapter, _TRUE);
829 #endif
830 	} else {
831 		/* Leave IPS */
832 		RTW_INFO("%s: Leaving IPS in FWLPS state\n", __func__);
833 
834 #ifdef CONFIG_LPS_LCLK
835 		rtw_set_lps_lclk(padapter, _FALSE);
836 #endif
837 		parm[0] = 0x0;
838 		parm[1] = 0x0;
839 		parm[2] = 0x0;
840 		rtw_hal_fill_h2c_cmd(padapter, H2C_INACTIVE_PS_,
841 				     H2C_INACTIVE_PS_LEN, parm);
842 #ifdef CONFIG_BT_COEXIST
843 		rtw_btcoex_IpsNotify(padapter, IPS_NONE);
844 #endif
845 	}
846 }
847 #endif /* CONFIG_FWLPS_IN_IPS */
848 
rtw_exec_lps(_adapter * padapter,u8 ps_mode)849 void rtw_exec_lps(_adapter *padapter, u8 ps_mode)
850 {
851 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
852 
853 	if (ps_mode == PS_MODE_ACTIVE) {
854 #ifdef CONFIG_LPS_ACK
855 		_enter_critical_mutex(&pwrpriv->lps_ack_mutex, NULL);
856 		rtw_sctx_init(&pwrpriv->lps_ack_sctx, 100);
857 #endif /* CONFIG_LPS_ACK */
858 
859 		rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
860 		rtw_hal_set_hwreg(padapter, HW_VAR_LPS_STATE_CHK, (u8 *)(&ps_mode));
861 
862 #ifdef CONFIG_LPS_ACK
863 		_exit_critical_mutex(&pwrpriv->lps_ack_mutex, NULL);
864 #endif /* CONFIG_LPS_ACK */
865 	} else {
866 		if (MLME_IS_ASOC(padapter))
867 			rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE, (u8 *)(&ps_mode));
868 		else
869 			RTW_INFO(FUNC_ADPT_FMT": It can't execute LPS without Wi-Fi connection!\n",
870 				FUNC_ADPT_ARG(padapter));
871 	}
872 }
873 
rtw_lps_rfon_ctrl(_adapter * padapter,u8 rfon_ctrl)874 void rtw_lps_rfon_ctrl(_adapter *padapter, u8 rfon_ctrl)
875 {
876 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
877 	u8 rpwm = 0;
878 
879 	if (pwrpriv->bFwCurrentInPSMode && pwrpriv->pwr_mode != PS_MODE_ACTIVE) {
880 		if (rfon_ctrl == rf_on) {
881 #ifdef CONFIG_LPS_LCLK
882 			if (pwrpriv->lps_level >= LPS_LCLK) {
883 				s32 ready = _FAIL;
884 				systime stime;
885 				s32 utime;
886 				u32 timeout; /* unit: ms */
887 
888 #ifdef LPS_RPWM_WAIT_MS
889 				timeout = LPS_RPWM_WAIT_MS;
890 #else
891 				timeout = 30;
892 #endif /* !LPS_RPWM_WAIT_MS */
893 
894 				stime = rtw_get_current_time();
895 				do {
896 					ready = rtw_register_task_alive(padapter, LPS_ALIVE);
897 					if (ready == _SUCCESS)
898 						break;
899 
900 					utime = rtw_get_passing_time_ms(stime);
901 					if (utime > timeout)
902 						break;
903 
904 					rtw_msleep_os(1);
905 				} while (1);
906 
907 				if (ready == _FAIL)
908 					RTW_INFO(FUNC_ADPT_FMT": It is not ready to leave 32K !!!\n",
909 						FUNC_ADPT_ARG(padapter));
910 			}
911 #endif /* CONFIG_LPS_LCLK */
912 
913 #ifdef CONFIG_LPS_ACK
914 			_enter_critical_mutex(&pwrpriv->lps_ack_mutex, NULL);
915 			rtw_sctx_init(&pwrpriv->lps_ack_sctx, 100);
916 #endif /* CONFIG_LPS_ACK */
917 
918 			rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE_RFON_CTRL, (u8 *)(&rfon_ctrl));
919 			rtw_hal_set_hwreg(padapter, HW_VAR_LPS_RFON_CHK, (u8 *)(&rfon_ctrl));
920 
921 #ifdef CONFIG_LPS_ACK
922 			_exit_critical_mutex(&pwrpriv->lps_ack_mutex, NULL);
923 #endif /* CONFIG_LPS_ACK */
924 		} else {
925 			if (MLME_IS_ASOC(padapter)) {
926 #ifdef CONFIG_LPS_PG
927 				if (pwrpriv->lps_level == LPS_PG) {
928 						 if (rtw_hal_set_lps_pg_info_cmd(padapter) == _FAIL)
929 						 	RTW_INFO(FUNC_ADPT_FMT": Send PG H2C command Fail! \n",
930 						 			    FUNC_ADPT_ARG(padapter));
931 				}
932 #endif /* CONFIG_LPS_PG */
933 				rtw_hal_set_hwreg(padapter, HW_VAR_H2C_FW_PWRMODE_RFON_CTRL, (u8 *)(&rfon_ctrl));
934 			} else {
935 				RTW_INFO(FUNC_ADPT_FMT": It can't execute RFON without Wi-Fi connection!\n",
936 					FUNC_ADPT_ARG(padapter));
937 			}
938 
939 #ifdef CONFIG_LPS_LCLK
940 			if (pwrpriv->lps_level >= LPS_LCLK) {
941 				rtw_unregister_task_alive(padapter, LPS_ALIVE);
942 
943 				if (pwrpriv->alives == 0) {
944 					u8 polling_cnt = 0;
945 					u8 reg_val8 = 0;
946 					u8 result = _FAIL;
947 
948 					do {
949 						rtw_msleep_os(1);
950 						reg_val8 = rtw_read8(padapter, REG_CR);
951 						if (reg_val8 == 0xEA) {
952 							result= _SUCCESS;
953 							break;
954 						}
955 						polling_cnt++;
956 					} while (polling_cnt < 100);
957 
958 					if (result == _FAIL )
959 						RTW_INFO(FUNC_ADPT_FMT": It is not finished to enter 32K !!!\n",
960 							FUNC_ADPT_ARG(padapter));
961 				}
962 			}
963 #endif /* CONFIG_LPS_LCLK */
964 		}
965 	} else {
966 		RTW_INFO(FUNC_ADPT_FMT": RFON can't work due to ps state is not in LPS !\n",
967 							FUNC_ADPT_ARG(padapter));
968 	}
969 }
970 
rtw_set_ps_mode(PADAPTER padapter,u8 ps_mode,u8 smart_ps,u8 bcn_ant_mode,const char * msg)971 void rtw_set_ps_mode(PADAPTER padapter, u8 ps_mode, u8 smart_ps, u8 bcn_ant_mode, const char *msg)
972 {
973 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
974 	struct mlme_priv	*pmlmepriv = &(padapter->mlmepriv);
975 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN) || defined(CONFIG_P2P_WOWLAN)
976 	struct dvobj_priv *psdpriv = padapter->dvobj;
977 	struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
978 #endif
979 #ifdef CONFIG_WMMPS_STA
980 	struct registry_priv *pregistrypriv = &padapter->registrypriv;
981 #endif
982 #ifdef CONFIG_P2P
983 	struct wifidirect_info	*pwdinfo = &(padapter->wdinfo);
984 #endif /* CONFIG_P2P */
985 #ifdef CONFIG_TDLS
986 	struct sta_priv *pstapriv = &padapter->stapriv;
987 	_irqL irqL;
988 	int i, j;
989 	_list	*plist, *phead;
990 	struct sta_info *ptdls_sta;
991 #endif /* CONFIG_TDLS */
992 #ifdef CONFIG_LPS_PG
993 	u8 lps_pg_hdl_id = 0;
994 #endif
995 
996 
997 
998 	if (ps_mode > PM_Card_Disable) {
999 		return;
1000 	}
1001 
1002 	if (pwrpriv->pwr_mode == ps_mode) {
1003 		if (PS_MODE_ACTIVE == ps_mode)
1004 			return;
1005 
1006 #ifndef CONFIG_BT_COEXIST
1007 #ifdef CONFIG_WMMPS_STA
1008 		if (!rtw_is_wmmps_mode(padapter))
1009 #endif /* CONFIG_WMMPS_STA */
1010 			if ((pwrpriv->smart_ps == smart_ps) &&
1011 			    (pwrpriv->bcn_ant_mode == bcn_ant_mode))
1012 				return;
1013 #endif /* !CONFIG_BT_COEXIST */
1014 	}
1015 
1016 #ifdef CONFIG_FW_MULTI_PORT_SUPPORT
1017 	if (PS_MODE_ACTIVE != ps_mode) {
1018 		rtw_set_ps_rsvd_page(padapter);
1019 		rtw_set_default_port_id(padapter);
1020 	}
1021 #endif
1022 
1023 #ifdef CONFIG_LPS_PG
1024 	if ((PS_MODE_ACTIVE != ps_mode) && (pwrpriv->lps_level == LPS_PG)) {
1025 		if (pwrpriv->wowlan_mode != _TRUE) {
1026 				/*rtw_hal_set_lps_pg_info(padapter);*/
1027 				lps_pg_hdl_id = LPS_PG_INFO_CFG;
1028 				rtw_hal_set_hwreg(padapter, HW_VAR_LPS_PG_HANDLE, (u8 *)(&lps_pg_hdl_id));
1029 		}
1030 	}
1031 #endif
1032 
1033 #ifdef CONFIG_LPS_LCLK
1034 	_enter_pwrlock(&pwrpriv->lock);
1035 #endif
1036 
1037 	/* if(pwrpriv->pwr_mode == PS_MODE_ACTIVE) */
1038 	if (ps_mode == PS_MODE_ACTIVE) {
1039 		if (1
1040 #ifdef CONFIG_BT_COEXIST
1041 		    && (((rtw_btcoex_IsBtControlLps(padapter) == _FALSE)
1042 #ifdef CONFIG_P2P_PS
1043 			 && (pwdinfo->opp_ps == 0)
1044 #endif /* CONFIG_P2P_PS */
1045 			)
1046 			|| ((rtw_btcoex_IsBtControlLps(padapter) == _TRUE)
1047 			    && (rtw_btcoex_IsLpsOn(padapter) == _FALSE))
1048 		       )
1049 #else /* !CONFIG_BT_COEXIST */
1050 #ifdef CONFIG_P2P_PS
1051 		    && (pwdinfo->opp_ps == 0)
1052 #endif /* CONFIG_P2P_PS */
1053 #endif /* !CONFIG_BT_COEXIST */
1054 		   ) {
1055 			RTW_INFO(FUNC_ADPT_FMT" Leave 802.11 power save - %s\n",
1056 				 FUNC_ADPT_ARG(padapter), msg);
1057 
1058 			if (pwrpriv->lps_leave_cnts < UINT_MAX)
1059 				pwrpriv->lps_leave_cnts++;
1060 			else
1061 				pwrpriv->lps_leave_cnts = 0;
1062 #ifdef CONFIG_TDLS
1063 			for (i = 0; i < NUM_STA; i++) {
1064 				phead = &(pstapriv->sta_hash[i]);
1065 				plist = get_next(phead);
1066 
1067 				while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
1068 					ptdls_sta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
1069 
1070 					if (ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE)
1071 						issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->cmn.mac_addr, 0, 0, 0);
1072 					plist = get_next(plist);
1073 				}
1074 			}
1075 #endif /* CONFIG_TDLS */
1076 
1077 			pwrpriv->pwr_mode = ps_mode;
1078 			rtw_set_rpwm(padapter, PS_STATE_S4);
1079 
1080 #if defined(CONFIG_WOWLAN) || defined(CONFIG_AP_WOWLAN) || defined(CONFIG_P2P_WOWLAN)
1081 			if (pwrpriv->wowlan_mode == _TRUE ||
1082 			    pwrpriv->wowlan_ap_mode == _TRUE ||
1083 			    pwrpriv->wowlan_p2p_mode == _TRUE) {
1084 				systime start_time;
1085 				u32 delay_ms;
1086 				u8 val8;
1087 				delay_ms = 20;
1088 				start_time = rtw_get_current_time();
1089 				do {
1090 					rtw_hal_get_hwreg(padapter, HW_VAR_SYS_CLKR, &val8);
1091 					if (!(val8 & BIT(4))) { /* 0x08 bit4 =1 --> in 32k, bit4 = 0 --> leave 32k */
1092 						pwrpriv->cpwm = PS_STATE_S4;
1093 						break;
1094 					}
1095 					if (rtw_get_passing_time_ms(start_time) > delay_ms) {
1096 						RTW_INFO("%s: Wait for FW 32K leave more than %u ms!!!\n",
1097 							__FUNCTION__, delay_ms);
1098 						pdbgpriv->dbg_wow_leave_ps_fail_cnt++;
1099 						break;
1100 					}
1101 					rtw_usleep_os(100);
1102 				} while (1);
1103 			}
1104 #endif
1105 #ifdef CONFIG_LPS_PG
1106 			if (pwrpriv->lps_level == LPS_PG) {
1107 				lps_pg_hdl_id = LPS_PG_REDLEMEM;
1108 				rtw_hal_set_hwreg(padapter, HW_VAR_LPS_PG_HANDLE, (u8 *)(&lps_pg_hdl_id));
1109 			}
1110 #endif
1111 #ifdef CONFIG_WOWLAN
1112 			if (pwrpriv->wowlan_mode == _TRUE)
1113 				rtw_hal_set_hwreg(padapter, HW_VAR_H2C_INACTIVE_IPS, (u8 *)(&ps_mode));
1114 #endif /* CONFIG_WOWLAN */
1115 
1116 			rtw_exec_lps(padapter, ps_mode);
1117 
1118 #ifdef CONFIG_LPS_PG
1119 			if (pwrpriv->lps_level == LPS_PG) {
1120 				lps_pg_hdl_id = LPS_PG_PHYDM_EN;
1121 				rtw_hal_set_hwreg(padapter, HW_VAR_LPS_PG_HANDLE, (u8 *)(&lps_pg_hdl_id));
1122 			}
1123 #endif
1124 
1125 #ifdef CONFIG_LPS_POFF
1126 			rtw_hal_set_hwreg(padapter, HW_VAR_LPS_POFF_SET_MODE,
1127 					  (u8 *)(&ps_mode));
1128 #endif /*CONFIG_LPS_POFF*/
1129 
1130 			pwrpriv->bFwCurrentInPSMode = _FALSE;
1131 
1132 #ifdef CONFIG_BT_COEXIST
1133 			rtw_btcoex_LpsNotify(padapter, ps_mode);
1134 #endif /* CONFIG_BT_COEXIST */
1135 		}
1136 	} else {
1137 		if ((PS_RDY_CHECK(padapter) && check_fwstate(&padapter->mlmepriv, WIFI_ASOC_STATE))
1138 #ifdef CONFIG_BT_COEXIST
1139 		    || ((rtw_btcoex_IsBtControlLps(padapter) == _TRUE)
1140 			&& (rtw_btcoex_IsLpsOn(padapter) == _TRUE))
1141 #endif
1142 #ifdef CONFIG_P2P_WOWLAN
1143 		    || (_TRUE == pwrpriv->wowlan_p2p_mode)
1144 #endif /* CONFIG_P2P_WOWLAN */
1145 #ifdef CONFIG_WOWLAN
1146 			|| WOWLAN_IS_STA_MIX_MODE(padapter)
1147 #endif /* CONFIG_WOWLAN */
1148 		   ) {
1149 			u8 pslv;
1150 
1151 			RTW_INFO(FUNC_ADPT_FMT" Enter 802.11 power save - %s\n",
1152 				 FUNC_ADPT_ARG(padapter), msg);
1153 
1154 			if (pwrpriv->lps_enter_cnts < UINT_MAX)
1155 				pwrpriv->lps_enter_cnts++;
1156 			else
1157 				pwrpriv->lps_enter_cnts = 0;
1158 #ifdef CONFIG_TDLS
1159 			for (i = 0; i < NUM_STA; i++) {
1160 				phead = &(pstapriv->sta_hash[i]);
1161 				plist = get_next(phead);
1162 
1163 				while ((rtw_end_of_queue_search(phead, plist)) == _FALSE) {
1164 					ptdls_sta = LIST_CONTAINOR(plist, struct sta_info, hash_list);
1165 
1166 					if (ptdls_sta->tdls_sta_state & TDLS_LINKED_STATE)
1167 						issue_nulldata_to_TDLS_peer_STA(padapter, ptdls_sta->cmn.mac_addr, 1, 0, 0);
1168 					plist = get_next(plist);
1169 				}
1170 			}
1171 #endif /* CONFIG_TDLS */
1172 
1173 #ifdef CONFIG_BT_COEXIST
1174 			rtw_btcoex_LpsNotify(padapter, ps_mode);
1175 #endif /* CONFIG_BT_COEXIST */
1176 
1177 #ifdef CONFIG_LPS_POFF
1178 			rtw_hal_set_hwreg(padapter, HW_VAR_LPS_POFF_SET_MODE,
1179 					  (u8 *)(&ps_mode));
1180 #endif /*CONFIG_LPS_POFF*/
1181 
1182 			pwrpriv->bFwCurrentInPSMode = _TRUE;
1183 			pwrpriv->pwr_mode = ps_mode;
1184 			pwrpriv->smart_ps = smart_ps;
1185 			pwrpriv->bcn_ant_mode = bcn_ant_mode;
1186 #ifdef CONFIG_LPS_PG
1187 			if (pwrpriv->lps_level == LPS_PG) {
1188 				lps_pg_hdl_id = LPS_PG_PHYDM_DIS;
1189 				rtw_hal_set_hwreg(padapter, HW_VAR_LPS_PG_HANDLE, (u8 *)(&lps_pg_hdl_id));
1190 			}
1191 #endif
1192 
1193 #ifdef CONFIG_WMMPS_STA
1194 			pwrpriv->wmm_smart_ps = pregistrypriv->wmm_smart_ps;
1195 #endif /* CONFIG_WMMPS_STA */
1196 
1197 			rtw_exec_lps(padapter, ps_mode);
1198 
1199 #ifdef CONFIG_WOWLAN
1200 			if (pwrpriv->wowlan_mode == _TRUE)
1201 				rtw_hal_set_hwreg(padapter, HW_VAR_H2C_INACTIVE_IPS, (u8 *)(&ps_mode));
1202 #endif /* CONFIG_WOWLAN */
1203 
1204 #ifdef CONFIG_P2P_PS
1205 			/* Set CTWindow after LPS */
1206 			if (pwdinfo->opp_ps == 1)
1207 				p2p_ps_wk_cmd(padapter, P2P_PS_ENABLE, 0);
1208 #endif /* CONFIG_P2P_PS */
1209 
1210 			pslv = PS_STATE_S2;
1211 #ifdef CONFIG_LPS_LCLK
1212 			if (pwrpriv->alives == 0)
1213 				pslv = PS_STATE_S0;
1214 #endif /* CONFIG_LPS_LCLK */
1215 
1216 #ifdef CONFIG_BT_COEXIST
1217 			if ((rtw_btcoex_IsBtDisabled(padapter) == _FALSE)
1218 			    && (rtw_btcoex_IsBtControlLps(padapter) == _TRUE)) {
1219 				u8 val8;
1220 
1221 				val8 = rtw_btcoex_LpsVal(padapter);
1222 				if (val8 & BIT(4))
1223 					pslv = PS_STATE_S2;
1224 
1225 			}
1226 #endif /* CONFIG_BT_COEXIST */
1227 
1228 			rtw_set_rpwm(padapter, pslv);
1229 		}
1230 	}
1231 
1232 #ifdef CONFIG_LPS_LCLK
1233 	_exit_pwrlock(&pwrpriv->lock);
1234 #endif
1235 
1236 }
1237 
1238 const char * const LPS_CTRL_PHYDM = "LPS_CTRL_PHYDM";
1239 
1240 /*
1241  *	Description:
1242  *		Enter the leisure power save mode.
1243  *   */
LPS_Enter(PADAPTER padapter,const char * msg)1244 void LPS_Enter(PADAPTER padapter, const char *msg)
1245 {
1246 	struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1247 	struct pwrctrl_priv	*pwrpriv = dvobj_to_pwrctl(dvobj);
1248 	int i;
1249 	char buf[32] = {0};
1250 #ifdef DBG_LA_MODE
1251 	struct registry_priv *registry_par = &(padapter->registrypriv);
1252 #endif
1253 
1254 	/*	RTW_INFO("+LeisurePSEnter\n"); */
1255 	if (GET_HAL_DATA(padapter)->bFWReady == _FALSE)
1256 		return;
1257 
1258 #ifdef CONFIG_BT_COEXIST
1259 	if (rtw_btcoex_IsBtControlLps(padapter) == _TRUE)
1260 		return;
1261 #endif
1262 
1263 #ifdef DBG_LA_MODE
1264 	if(registry_par->la_mode_en == 1) {
1265 		RTW_INFO("%s LA debug mode lps_leave \n", __func__);
1266 		return;
1267 	}
1268 #endif
1269 	/* Skip lps enter request if number of assocated adapters is not 1 */
1270 	if (rtw_mi_get_assoc_if_num(padapter) != 1)
1271 		return;
1272 
1273 #ifndef CONFIG_FW_MULTI_PORT_SUPPORT
1274 	/* Skip lps enter request for adapter not port0 */
1275 	if (get_hw_port(padapter) != HW_PORT0)
1276 		return;
1277 #endif
1278 
1279 	for (i = 0; i < dvobj->iface_nums; i++) {
1280 		if (PS_RDY_CHECK(dvobj->padapters[i]) == _FALSE)
1281 			return;
1282 	}
1283 
1284 #ifdef CONFIG_CLIENT_PORT_CFG
1285 	if ((rtw_hal_get_port(padapter) == CLT_PORT_INVALID) ||
1286 		get_clt_num(padapter) > MAX_CLIENT_PORT_NUM){
1287 		RTW_ERR(ADPT_FMT" cannot get client port or clt num(%d) over than 4\n", ADPT_ARG(padapter), get_clt_num(padapter));
1288 		return;
1289 	}
1290 #endif
1291 
1292 #ifdef CONFIG_P2P_PS
1293 	if (padapter->wdinfo.p2p_ps_mode == P2P_PS_NOA) {
1294 		return;/* supporting p2p client ps NOA via H2C_8723B_P2P_PS_OFFLOAD */
1295 	}
1296 #endif /* CONFIG_P2P_PS */
1297 
1298 	if (pwrpriv->bLeisurePs) {
1299 		/* Idle for a while if we connect to AP a while ago. */
1300 		if (pwrpriv->LpsIdleCount >= 2) { /* 4 Sec */
1301 			if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) {
1302 
1303 #ifdef CONFIG_WMMPS_STA
1304 				if (rtw_is_wmmps_mode(padapter))
1305 					msg = "WMMPS_IDLE";
1306 #endif /* CONFIG_WMMPS_STA */
1307 
1308 				sprintf(buf, "WIFI-%s", msg);
1309 				pwrpriv->bpower_saving = _TRUE;
1310 
1311 #ifdef CONFIG_RTW_CFGVENDOR_LLSTATS
1312 				pwrpriv->pwr_saving_start_time = rtw_get_current_time();
1313 #endif /* CONFIG_RTW_CFGVENDOR_LLSTATS */
1314 
1315 				rtw_set_ps_mode(padapter, pwrpriv->power_mgnt, padapter->registrypriv.smart_ps, 0, buf);
1316 
1317 #ifdef CONFIG_PCI_DYNAMIC_ASPM
1318 				if (msg != LPS_CTRL_PHYDM)
1319 					rtw_pci_dynamic_aspm_set_mode(padapter, ASPM_MODE_PS);
1320 #endif
1321 			}
1322 		} else
1323 			pwrpriv->LpsIdleCount++;
1324 	}
1325 
1326 	/*	RTW_INFO("-LeisurePSEnter\n"); */
1327 
1328 }
1329 
1330 /*
1331  *	Description:
1332  *		Leave the leisure power save mode.
1333  *   */
LPS_Leave(PADAPTER padapter,const char * msg)1334 void LPS_Leave(PADAPTER padapter, const char *msg)
1335 {
1336 #define LPS_LEAVE_TIMEOUT_MS 100
1337 
1338 	struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1339 	struct pwrctrl_priv	*pwrpriv = dvobj_to_pwrctl(dvobj);
1340 	char buf[32] = {0};
1341 #ifdef DBG_CHECK_FW_PS_STATE
1342 	struct debug_priv *pdbgpriv = &dvobj->drv_dbg;
1343 #endif
1344 
1345 
1346 	/*	RTW_INFO("+LeisurePSLeave\n"); */
1347 
1348 #ifdef CONFIG_BT_COEXIST
1349 	if (rtw_btcoex_IsBtControlLps(padapter) == _TRUE)
1350 		return;
1351 #endif
1352 
1353 	if (pwrpriv->bLeisurePs) {
1354 		if (pwrpriv->pwr_mode != PS_MODE_ACTIVE) {
1355 #ifdef CONFIG_PCI_DYNAMIC_ASPM
1356 			if (msg != LPS_CTRL_PHYDM)
1357 				rtw_pci_dynamic_aspm_set_mode(padapter, ASPM_MODE_PERF);
1358 #endif
1359 #ifdef CONFIG_WMMPS_STA
1360 			if (rtw_is_wmmps_mode(padapter))
1361 				msg = "WMMPS_BUSY";
1362 #endif /* CONFIG_WMMPS_STA */
1363 
1364 			sprintf(buf, "WIFI-%s", msg);
1365 			rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0, buf);
1366 
1367 #ifdef CONFIG_RTW_CFGVENDOR_LLSTATS
1368 			pwrpriv->pwr_saving_time += rtw_get_passing_time_ms(pwrpriv->pwr_saving_start_time);
1369 #endif /* CONFIG_RTW_CFGVENDOR_LLSTATS */
1370 		}
1371 	}
1372 
1373 	pwrpriv->bpower_saving = _FALSE;
1374 #ifdef DBG_CHECK_FW_PS_STATE
1375 	if (rtw_fw_ps_state(padapter) == _FAIL) {
1376 		RTW_INFO("leave lps, fw in 32k\n");
1377 		pdbgpriv->dbg_leave_lps_fail_cnt++;
1378 	}
1379 #endif /* DBG_CHECK_FW_PS_STATE
1380  * 	RTW_INFO("-LeisurePSLeave\n"); */
1381 
1382 }
1383 
1384 #ifdef CONFIG_WOWLAN
rtw_wow_lps_level_decide(_adapter * adapter,u8 wow_en)1385 void rtw_wow_lps_level_decide(_adapter *adapter, u8 wow_en)
1386 {
1387 	struct dvobj_priv *dvobj = adapter_to_dvobj(adapter);
1388 	struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1389 
1390 	if (wow_en) {
1391 		pwrpriv->lps_level_bk = pwrpriv->lps_level;
1392 		pwrpriv->lps_level = pwrpriv->wowlan_lps_level;
1393 		#ifdef CONFIG_LPS_1T1R
1394 		pwrpriv->lps_1t1r_bk = pwrpriv->lps_1t1r;
1395 		pwrpriv->lps_1t1r = pwrpriv->wowlan_lps_1t1r;
1396 		#endif
1397 	} else {
1398 		pwrpriv->lps_level = pwrpriv->lps_level_bk;
1399 		#ifdef CONFIG_LPS_1T1R
1400 		pwrpriv->lps_1t1r = pwrpriv->lps_1t1r_bk;
1401 		#endif
1402 	}
1403 }
1404 #endif /* CONFIG_WOWLAN */
1405 #endif /* CONFIG_LPS */
1406 
LeaveAllPowerSaveModeDirect(PADAPTER Adapter)1407 void LeaveAllPowerSaveModeDirect(PADAPTER Adapter)
1408 {
1409 	struct dvobj_priv *dvobj = adapter_to_dvobj(Adapter);
1410 	PADAPTER pri_padapter = GET_PRIMARY_ADAPTER(Adapter);
1411 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(Adapter);
1412 #ifdef CONFIG_LPS_LCLK
1413 #ifndef CONFIG_DETECT_CPWM_BY_POLLING
1414 	u8 cpwm_orig;
1415 #endif /* CONFIG_DETECT_CPWM_BY_POLLING */
1416 	u8 rpwm;
1417 #endif
1418 	int i;
1419 
1420 	RTW_INFO("%s.....\n", __FUNCTION__);
1421 
1422 	if (rtw_is_surprise_removed(Adapter)) {
1423 		RTW_INFO(FUNC_ADPT_FMT ": bSurpriseRemoved=_TRUE Skip!\n", FUNC_ADPT_ARG(Adapter));
1424 		return;
1425 	}
1426 
1427 	if (rtw_mi_check_status(Adapter, MI_LINKED)) { /*connect*/
1428 
1429 		if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) {
1430 			RTW_INFO("%s: Driver Already Leave LPS\n", __FUNCTION__);
1431 			return;
1432 		}
1433 
1434 #ifdef CONFIG_LPS_LCLK
1435 		_enter_pwrlock(&pwrpriv->lock);
1436 
1437 #ifndef CONFIG_DETECT_CPWM_BY_POLLING
1438 		cpwm_orig = 0;
1439 		rtw_hal_get_hwreg(Adapter, HW_VAR_CPWM, &cpwm_orig);
1440 #endif /* CONFIG_DETECT_CPWM_BY_POLLING */
1441 		rpwm = rtw_set_rpwm(Adapter, PS_STATE_S4);
1442 
1443 #ifndef CONFIG_DETECT_CPWM_BY_POLLING
1444 		if (rpwm != 0xFF && rpwm & PS_ACK)
1445 			rtw_cpwm_polling(Adapter, rpwm, cpwm_orig);
1446 #endif /* CONFIG_DETECT_CPWM_BY_POLLING */
1447 
1448 		_exit_pwrlock(&pwrpriv->lock);
1449 #endif/*CONFIG_LPS_LCLK*/
1450 
1451 #ifdef CONFIG_P2P_PS
1452 		for (i = 0; i < dvobj->iface_nums; i++) {
1453 			_adapter *iface = dvobj->padapters[i];
1454 			struct wifidirect_info *pwdinfo = &(iface->wdinfo);
1455 
1456 			if (pwdinfo->p2p_ps_mode > P2P_PS_NONE)
1457 				p2p_ps_wk_cmd(iface, P2P_PS_DISABLE, 0);
1458 		}
1459 #endif /* CONFIG_P2P_PS */
1460 
1461 #ifdef CONFIG_LPS
1462 		rtw_lps_ctrl_wk_cmd(pri_padapter, LPS_CTRL_LEAVE, RTW_CMDF_DIRECTLY);
1463 #endif
1464 	} else {
1465 		if (pwrpriv->rf_pwrstate == rf_off) {
1466 
1467 #if defined(CONFIG_FWLPS_IN_IPS) || defined(CONFIG_SWLPS_IN_IPS) || defined(CONFIG_RTL8188E) || defined(CONFIG_PNO_SUPPORT)
1468 #ifdef CONFIG_IPS
1469 			if (_FALSE == ips_leave(pri_padapter))
1470 				RTW_INFO("======> ips_leave fail.............\n");
1471 #endif
1472 #endif /* CONFIG_SWLPS_IN_IPS || (CONFIG_PLATFORM_SPRD && CONFIG_RTL8188E) */
1473 
1474 		}
1475 	}
1476 
1477 }
1478 
1479 /*
1480  * Description: Leave all power save mode: LPS, FwLPS, IPS if needed.
1481  * Move code to function by tynli. 2010.03.26.
1482  *   */
LeaveAllPowerSaveMode(PADAPTER Adapter)1483 void LeaveAllPowerSaveMode(PADAPTER Adapter)
1484 {
1485 	struct dvobj_priv *dvobj = adapter_to_dvobj(Adapter);
1486 	u8	enqueue = 0;
1487 	int i;
1488 
1489 	#ifndef CONFIG_NEW_NETDEV_HDL
1490 	if (_FALSE == Adapter->bup) {
1491 		RTW_INFO(FUNC_ADPT_FMT ": bup=%d Skip!\n",
1492 			 FUNC_ADPT_ARG(Adapter), Adapter->bup);
1493 		return;
1494 	}
1495 	#endif
1496 
1497 /*	RTW_INFO(FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(Adapter));*/
1498 
1499 	if (rtw_is_surprise_removed(Adapter)) {
1500 		RTW_INFO(FUNC_ADPT_FMT ": bSurpriseRemoved=_TRUE Skip!\n", FUNC_ADPT_ARG(Adapter));
1501 		return;
1502 	}
1503 
1504 	if (rtw_mi_get_assoc_if_num(Adapter)) {
1505 		/* connect */
1506 #ifdef CONFIG_LPS_LCLK
1507 		enqueue = 1;
1508 #endif
1509 
1510 #ifdef CONFIG_P2P_PS
1511 		for (i = 0; i < dvobj->iface_nums; i++) {
1512 			_adapter *iface = dvobj->padapters[i];
1513 			struct wifidirect_info *pwdinfo = &(iface->wdinfo);
1514 
1515 			if (pwdinfo->p2p_ps_mode > P2P_PS_NONE)
1516 				p2p_ps_wk_cmd(iface, P2P_PS_DISABLE, enqueue);
1517 		}
1518 #endif /* CONFIG_P2P_PS */
1519 
1520 #ifdef CONFIG_LPS
1521 		rtw_lps_ctrl_wk_cmd(Adapter, LPS_CTRL_LEAVE, enqueue ? 0 : RTW_CMDF_DIRECTLY);
1522 #endif
1523 
1524 #ifdef CONFIG_LPS_LCLK
1525 		LPS_Leave_check(Adapter);
1526 #endif
1527 	} else {
1528 		if (adapter_to_pwrctl(Adapter)->rf_pwrstate == rf_off) {
1529 
1530 #if defined(CONFIG_FWLPS_IN_IPS) || defined(CONFIG_SWLPS_IN_IPS) || (defined(CONFIG_PLATFORM_SPRD) && defined(CONFIG_RTL8188E))
1531 #ifdef CONFIG_IPS
1532 			if (_FALSE == ips_leave(Adapter))
1533 				RTW_INFO("======> ips_leave fail.............\n");
1534 #endif
1535 #endif /* CONFIG_SWLPS_IN_IPS || (CONFIG_PLATFORM_SPRD && CONFIG_RTL8188E) */
1536 
1537 		}
1538 	}
1539 
1540 }
1541 
1542 #ifdef CONFIG_LPS_LCLK
LPS_Leave_check(PADAPTER padapter)1543 void LPS_Leave_check(
1544 	PADAPTER padapter)
1545 {
1546 	struct pwrctrl_priv *pwrpriv;
1547 	systime	start_time;
1548 	u8	bReady;
1549 
1550 
1551 	pwrpriv = adapter_to_pwrctl(padapter);
1552 
1553 	bReady = _FALSE;
1554 	start_time = rtw_get_current_time();
1555 
1556 	rtw_yield_os();
1557 
1558 	while (1) {
1559 		_enter_pwrlock(&pwrpriv->lock);
1560 
1561 		if (rtw_is_surprise_removed(padapter)
1562 		    || (!rtw_is_hw_init_completed(padapter))
1563 #ifdef CONFIG_USB_HCI
1564 		    || rtw_is_drv_stopped(padapter)
1565 #endif
1566 		    || (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
1567 		   )
1568 			bReady = _TRUE;
1569 
1570 		_exit_pwrlock(&pwrpriv->lock);
1571 
1572 		if (_TRUE == bReady)
1573 			break;
1574 
1575 		if (rtw_get_passing_time_ms(start_time) > 100) {
1576 			RTW_ERR("Wait for cpwm event  than 100 ms!!!\n");
1577 			break;
1578 		}
1579 		rtw_msleep_os(1);
1580 	}
1581 
1582 }
1583 
1584 /*
1585  * Caller:ISR handler...
1586  *
1587  * This will be called when CPWM interrupt is up.
1588  *
1589  * using to update cpwn of drv; and drv willl make a decision to up or down pwr level
1590  */
cpwm_int_hdl(PADAPTER padapter,struct reportpwrstate_parm * preportpwrstate)1591 void cpwm_int_hdl(
1592 	PADAPTER padapter,
1593 	struct reportpwrstate_parm *preportpwrstate)
1594 {
1595 	struct pwrctrl_priv *pwrpriv;
1596 
1597 	if (!padapter)
1598 		goto exit;
1599 
1600 	if (RTW_CANNOT_RUN(padapter))
1601 		goto exit;
1602 
1603 	pwrpriv = adapter_to_pwrctl(padapter);
1604 #if 0
1605 	if (pwrpriv->cpwm_tog == (preportpwrstate->state & PS_TOGGLE)) {
1606 		goto exit;
1607 	}
1608 #endif
1609 
1610 	_enter_pwrlock(&pwrpriv->lock);
1611 
1612 #ifdef CONFIG_LPS_RPWM_TIMER
1613 	if (pwrpriv->rpwm < PS_STATE_S2) {
1614 		RTW_INFO("%s: Redundant CPWM Int. RPWM=0x%02X CPWM=0x%02x\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm);
1615 		_exit_pwrlock(&pwrpriv->lock);
1616 		goto exit;
1617 	}
1618 #endif /* CONFIG_LPS_RPWM_TIMER */
1619 
1620 	pwrpriv->cpwm = PS_STATE(preportpwrstate->state);
1621 	pwrpriv->cpwm_tog = preportpwrstate->state & PS_TOGGLE;
1622 
1623 	if (pwrpriv->cpwm >= PS_STATE_S2) {
1624 		if (pwrpriv->alives & CMD_ALIVE)
1625 			_rtw_up_sema(&padapter->cmdpriv.cmd_queue_sema);
1626 
1627 		if (pwrpriv->alives & XMIT_ALIVE)
1628 			_rtw_up_sema(&padapter->xmitpriv.xmit_sema);
1629 	}
1630 
1631 	_exit_pwrlock(&pwrpriv->lock);
1632 
1633 exit:
1634 	return;
1635 }
1636 
cpwm_event_callback(struct work_struct * work)1637 static void cpwm_event_callback(struct work_struct *work)
1638 {
1639 	struct pwrctrl_priv *pwrpriv = container_of(work, struct pwrctrl_priv, cpwm_event);
1640 	struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
1641 	_adapter *adapter = dvobj_get_primary_adapter(dvobj);
1642 	struct reportpwrstate_parm report;
1643 
1644 	/* RTW_INFO("%s\n",__FUNCTION__); */
1645 
1646 	report.state = PS_STATE_S2;
1647 	cpwm_int_hdl(adapter, &report);
1648 }
1649 
dma_event_callback(struct work_struct * work)1650 static void dma_event_callback(struct work_struct *work)
1651 {
1652 	struct pwrctrl_priv *pwrpriv = container_of(work, struct pwrctrl_priv, dma_event);
1653 	struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
1654 	_adapter *adapter = dvobj_get_primary_adapter(dvobj);
1655 
1656 	rtw_unregister_tx_alive(adapter);
1657 }
1658 
1659 #ifdef CONFIG_LPS_RPWM_TIMER
1660 
1661 #define DBG_CPWM_CHK_FAIL
1662 #if defined(DBG_CPWM_CHK_FAIL) && (defined(CONFIG_RTL8822B) || defined(CONFIG_RTL8821C) || defined(CONFIG_RTL8822C) \
1663 				   || defined(CONFIG_RTL8723F))
1664 #define CPU_EXCEPTION_CODE 0xFAFAFAFA
rtw_cpwm_chk_fail_debug(_adapter * padapter)1665 static void rtw_cpwm_chk_fail_debug(_adapter *padapter)
1666 {
1667 	u32 cpu_state;
1668 
1669 	cpu_state = rtw_read32(padapter, 0x10FC);
1670 
1671 	RTW_INFO("[PS-DBG] Reg_10FC =0x%08x\n", cpu_state);
1672 	RTW_INFO("[PS-DBG] Reg_10F8 =0x%08x\n", rtw_read32(padapter, 0x10F8));
1673 	RTW_INFO("[PS-DBG] Reg_11F8 =0x%08x\n", rtw_read32(padapter, 0x11F8));
1674 	RTW_INFO("[PS-DBG] Reg_4A4 =0x%08x\n", rtw_read32(padapter, 0x4A4));
1675 	RTW_INFO("[PS-DBG] Reg_4A8 =0x%08x\n", rtw_read32(padapter, 0x4A8));
1676 
1677 	if (cpu_state == CPU_EXCEPTION_CODE) {
1678 		RTW_INFO("[PS-DBG] Reg_48C =0x%08x\n", rtw_read32(padapter, 0x48C));
1679 		RTW_INFO("[PS-DBG] Reg_490 =0x%08x\n", rtw_read32(padapter, 0x490));
1680 		RTW_INFO("[PS-DBG] Reg_494 =0x%08x\n", rtw_read32(padapter, 0x494));
1681 		RTW_INFO("[PS-DBG] Reg_498 =0x%08x\n", rtw_read32(padapter, 0x498));
1682 		RTW_INFO("[PS-DBG] Reg_49C =0x%08x\n", rtw_read32(padapter, 0x49C));
1683 		RTW_INFO("[PS-DBG] Reg_4A0 =0x%08x\n", rtw_read32(padapter, 0x4A0));
1684 		RTW_INFO("[PS-DBG] Reg_1BC =0x%08x\n", rtw_read32(padapter, 0x1BC));
1685 
1686 		RTW_INFO("[PS-DBG] Reg_008 =0x%08x\n", rtw_read32(padapter, 0x08));
1687 		RTW_INFO("[PS-DBG] Reg_2F0 =0x%08x\n", rtw_read32(padapter, 0x2F0));
1688 		RTW_INFO("[PS-DBG] Reg_2F4 =0x%08x\n", rtw_read32(padapter, 0x2F4));
1689 		RTW_INFO("[PS-DBG] Reg_2F8 =0x%08x\n", rtw_read32(padapter, 0x2F8));
1690 		RTW_INFO("[PS-DBG] Reg_2FC =0x%08x\n", rtw_read32(padapter, 0x2FC));
1691 
1692 		rtw_dump_fifo(RTW_DBGDUMP, padapter, 5, 0, 3072);
1693 	}
1694 }
1695 #endif
rpwmtimeout_workitem_callback(struct work_struct * work)1696 static void rpwmtimeout_workitem_callback(struct work_struct *work)
1697 {
1698 	PADAPTER padapter;
1699 	struct dvobj_priv *dvobj;
1700 	struct pwrctrl_priv *pwrpriv;
1701 
1702 
1703 	pwrpriv = container_of(work, struct pwrctrl_priv, rpwmtimeoutwi);
1704 	dvobj = pwrctl_to_dvobj(pwrpriv);
1705 	padapter = dvobj_get_primary_adapter(dvobj);
1706 
1707 	if (!padapter)
1708 		return;
1709 
1710 	if (RTW_CANNOT_RUN(padapter))
1711 		return;
1712 
1713 	_enter_pwrlock(&pwrpriv->lock);
1714 	if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2)) {
1715 		RTW_INFO("%s: rpwm=0x%02X cpwm=0x%02X CPWM done!\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm);
1716 		goto exit;
1717 	}
1718 
1719 	if (pwrpriv->rpwm_retry++ < LPS_RPWM_RETRY_CNT) {
1720 		u8 rpwm = (pwrpriv->rpwm | pwrpriv->tog | PS_ACK);
1721 
1722 		rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&rpwm));
1723 
1724 		pwrpriv->tog += 0x80;
1725 		_set_timer(&pwrpriv->pwr_rpwm_timer, LPS_CPWM_TIMEOUT_MS);
1726 		goto exit;
1727 	}
1728 
1729 	pwrpriv->rpwm_retry = 0;
1730 	_exit_pwrlock(&pwrpriv->lock);
1731 
1732 #if defined(DBG_CPWM_CHK_FAIL) && (defined(CONFIG_RTL8822B) || defined(CONFIG_RTL8821C) || defined(CONFIG_RTL8822C) \
1733 				   || defined(CONFIG_RTL8723F))
1734 	RTW_INFO("+%s: rpwm=0x%02X cpwm=0x%02X\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm);
1735 	rtw_cpwm_chk_fail_debug(padapter);
1736 #endif
1737 
1738 	if (rtw_read8(padapter, 0x100) != 0xEA) {
1739 #if 1
1740 		struct reportpwrstate_parm report;
1741 
1742 		report.state = PS_STATE_S2;
1743 		RTW_INFO("\n%s: FW already leave 32K!\n\n", __func__);
1744 		cpwm_int_hdl(padapter, &report);
1745 #else
1746 		RTW_INFO("\n%s: FW already leave 32K!\n\n", __func__);
1747 		cpwm_event_callback(&pwrpriv->cpwm_event);
1748 #endif
1749 		return;
1750 	}
1751 
1752 	_enter_pwrlock(&pwrpriv->lock);
1753 
1754 	if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2)) {
1755 		RTW_INFO("%s: cpwm=%d, nothing to do!\n", __func__, pwrpriv->cpwm);
1756 		goto exit;
1757 	}
1758 	pwrpriv->brpwmtimeout = _TRUE;
1759 	rtw_set_rpwm(padapter, pwrpriv->rpwm);
1760 	pwrpriv->brpwmtimeout = _FALSE;
1761 
1762 exit:
1763 	_exit_pwrlock(&pwrpriv->lock);
1764 }
1765 
1766 /*
1767  * This function is a timer handler, can't do any IO in it.
1768  */
pwr_rpwm_timeout_handler(void * FunctionContext)1769 static void pwr_rpwm_timeout_handler(void *FunctionContext)
1770 {
1771 	PADAPTER padapter;
1772 	struct pwrctrl_priv *pwrpriv;
1773 
1774 
1775 	padapter = (PADAPTER)FunctionContext;
1776 	pwrpriv = adapter_to_pwrctl(padapter);
1777 	if (!padapter)
1778 		return;
1779 
1780 	if (RTW_CANNOT_RUN(padapter))
1781 		return;
1782 
1783 	RTW_INFO("+%s: rpwm=0x%02X cpwm=0x%02X\n", __func__, pwrpriv->rpwm, pwrpriv->cpwm);
1784 
1785 	if ((pwrpriv->rpwm == pwrpriv->cpwm) || (pwrpriv->cpwm >= PS_STATE_S2)) {
1786 		RTW_INFO("+%s: cpwm=%d, nothing to do!\n", __func__, pwrpriv->cpwm);
1787 		return;
1788 	}
1789 
1790 	_set_workitem(&pwrpriv->rpwmtimeoutwi);
1791 }
1792 #endif /* CONFIG_LPS_RPWM_TIMER */
1793 
register_task_alive(struct pwrctrl_priv * pwrctrl,u32 tag)1794 __inline static void register_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag)
1795 {
1796 	pwrctrl->alives |= tag;
1797 }
1798 
unregister_task_alive(struct pwrctrl_priv * pwrctrl,u32 tag)1799 __inline static void unregister_task_alive(struct pwrctrl_priv *pwrctrl, u32 tag)
1800 {
1801 	pwrctrl->alives &= ~tag;
1802 }
1803 
1804 
1805 /*
1806  * Description:
1807  *	Check if the fw_pwrstate is okay for I/O.
1808  *	If not (cpwm is less than S2), then the sub-routine
1809  *	will raise the cpwm to be greater than or equal to S2.
1810  *
1811  *	Calling Context: Passive
1812  *
1813  *	Constraint:
1814  *		1. this function will request pwrctrl->lock
1815  *
1816  * Return Value:
1817  *	_SUCCESS	hardware is ready for I/O
1818  *	_FAIL		can't I/O right now
1819  */
rtw_register_task_alive(PADAPTER padapter,u32 task)1820 s32 rtw_register_task_alive(PADAPTER padapter, u32 task)
1821 {
1822 	s32 res;
1823 	struct pwrctrl_priv *pwrctrl;
1824 	u8 pslv;
1825 
1826 
1827 	res = _SUCCESS;
1828 	pwrctrl = adapter_to_pwrctl(padapter);
1829 	pslv = PS_STATE_S2;
1830 
1831 	_enter_pwrlock(&pwrctrl->lock);
1832 
1833 	register_task_alive(pwrctrl, task);
1834 
1835 	if (pwrctrl->bFwCurrentInPSMode == _TRUE) {
1836 
1837 		if (pwrctrl->cpwm < pslv) {
1838 			if (pwrctrl->cpwm < PS_STATE_S2)
1839 				res = _FAIL;
1840 			if (pwrctrl->rpwm < pslv)
1841 				rtw_set_rpwm(padapter, pslv);
1842 		}
1843 	}
1844 
1845 	_exit_pwrlock(&pwrctrl->lock);
1846 
1847 #ifdef CONFIG_DETECT_CPWM_BY_POLLING
1848 	if (_FAIL == res) {
1849 		if (pwrctrl->cpwm >= PS_STATE_S2)
1850 			res = _SUCCESS;
1851 	}
1852 #endif /* CONFIG_DETECT_CPWM_BY_POLLING */
1853 
1854 
1855 	return res;
1856 }
1857 
1858 /*
1859  * Description:
1860  *	If task is done, call this func. to power down firmware again.
1861  *
1862  *	Constraint:
1863  *		1. this function will request pwrctrl->lock
1864  *
1865  * Return Value:
1866  *	none
1867  */
rtw_unregister_task_alive(PADAPTER padapter,u32 task)1868 void rtw_unregister_task_alive(PADAPTER padapter, u32 task)
1869 {
1870 	struct pwrctrl_priv *pwrctrl;
1871 	u8 pslv;
1872 
1873 
1874 	pwrctrl = adapter_to_pwrctl(padapter);
1875 	pslv = PS_STATE_S0;
1876 
1877 #ifdef CONFIG_BT_COEXIST
1878 	if ((rtw_btcoex_IsBtDisabled(padapter) == _FALSE)
1879 	    && (rtw_btcoex_IsBtControlLps(padapter) == _TRUE)) {
1880 		u8 val8;
1881 
1882 		val8 = rtw_btcoex_LpsVal(padapter);
1883 		if (val8 & BIT(4))
1884 			pslv = PS_STATE_S2;
1885 
1886 	}
1887 #endif /* CONFIG_BT_COEXIST */
1888 
1889 	_enter_pwrlock(&pwrctrl->lock);
1890 
1891 	unregister_task_alive(pwrctrl, task);
1892 
1893 	if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE)
1894 	    && (pwrctrl->bFwCurrentInPSMode == _TRUE)) {
1895 
1896 		if (pwrctrl->cpwm > pslv) {
1897 			if ((pslv >= PS_STATE_S2) || (pwrctrl->alives == 0))
1898 				rtw_set_rpwm(padapter, pslv);
1899 		}
1900 	}
1901 
1902 	_exit_pwrlock(&pwrctrl->lock);
1903 
1904 }
1905 
1906 /*
1907  * Caller: rtw_xmit_thread
1908  *
1909  * Check if the fw_pwrstate is okay for xmit.
1910  * If not (cpwm is less than S3), then the sub-routine
1911  * will raise the cpwm to be greater than or equal to S3.
1912  *
1913  * Calling Context: Passive
1914  *
1915  * Return Value:
1916  *	 _SUCCESS	rtw_xmit_thread can write fifo/txcmd afterwards.
1917  *	 _FAIL		rtw_xmit_thread can not do anything.
1918  */
rtw_register_tx_alive(PADAPTER padapter)1919 s32 rtw_register_tx_alive(PADAPTER padapter)
1920 {
1921 	s32 res;
1922 	struct pwrctrl_priv *pwrctrl;
1923 	u8 pslv;
1924 
1925 
1926 	res = _SUCCESS;
1927 	pwrctrl = adapter_to_pwrctl(padapter);
1928 	pslv = PS_STATE_S2;
1929 
1930 	_enter_pwrlock(&pwrctrl->lock);
1931 
1932 	register_task_alive(pwrctrl, XMIT_ALIVE);
1933 
1934 	if (pwrctrl->bFwCurrentInPSMode == _TRUE) {
1935 
1936 		if (pwrctrl->cpwm < pslv) {
1937 			if (pwrctrl->cpwm < PS_STATE_S2)
1938 				res = _FAIL;
1939 			if (pwrctrl->rpwm < pslv)
1940 				rtw_set_rpwm(padapter, pslv);
1941 		}
1942 	}
1943 
1944 	_exit_pwrlock(&pwrctrl->lock);
1945 
1946 #ifdef CONFIG_DETECT_CPWM_BY_POLLING
1947 	if (_FAIL == res) {
1948 		if (pwrctrl->cpwm >= PS_STATE_S2)
1949 			res = _SUCCESS;
1950 	}
1951 #endif /* CONFIG_DETECT_CPWM_BY_POLLING */
1952 
1953 
1954 	return res;
1955 }
1956 
1957 /*
1958  * Caller: rtw_cmd_thread
1959  *
1960  * Check if the fw_pwrstate is okay for issuing cmd.
1961  * If not (cpwm should be is less than S2), then the sub-routine
1962  * will raise the cpwm to be greater than or equal to S2.
1963  *
1964  * Calling Context: Passive
1965  *
1966  * Return Value:
1967  *	_SUCCESS	rtw_cmd_thread can issue cmds to firmware afterwards.
1968  *	_FAIL		rtw_cmd_thread can not do anything.
1969  */
rtw_register_cmd_alive(PADAPTER padapter)1970 s32 rtw_register_cmd_alive(PADAPTER padapter)
1971 {
1972 	s32 res;
1973 	struct pwrctrl_priv *pwrctrl;
1974 	u8 pslv;
1975 
1976 
1977 	res = _SUCCESS;
1978 	pwrctrl = adapter_to_pwrctl(padapter);
1979 	pslv = PS_STATE_S2;
1980 
1981 	_enter_pwrlock(&pwrctrl->lock);
1982 
1983 	register_task_alive(pwrctrl, CMD_ALIVE);
1984 
1985 	if (pwrctrl->bFwCurrentInPSMode == _TRUE) {
1986 
1987 		if (pwrctrl->cpwm < pslv) {
1988 			if (pwrctrl->cpwm < PS_STATE_S2)
1989 				res = _FAIL;
1990 			if (pwrctrl->rpwm < pslv)
1991 				rtw_set_rpwm(padapter, pslv);
1992 		}
1993 	}
1994 
1995 	_exit_pwrlock(&pwrctrl->lock);
1996 
1997 #ifdef CONFIG_DETECT_CPWM_BY_POLLING
1998 	if (_FAIL == res) {
1999 		if (pwrctrl->cpwm >= PS_STATE_S2)
2000 			res = _SUCCESS;
2001 	}
2002 #endif /* CONFIG_DETECT_CPWM_BY_POLLING */
2003 
2004 
2005 	return res;
2006 }
2007 
2008 /*
2009  * Caller: rx_isr
2010  *
2011  * Calling Context: Dispatch/ISR
2012  *
2013  * Return Value:
2014  *	_SUCCESS
2015  *	_FAIL
2016  */
rtw_register_rx_alive(PADAPTER padapter)2017 s32 rtw_register_rx_alive(PADAPTER padapter)
2018 {
2019 	struct pwrctrl_priv *pwrctrl;
2020 
2021 
2022 	pwrctrl = adapter_to_pwrctl(padapter);
2023 
2024 	_enter_pwrlock(&pwrctrl->lock);
2025 
2026 	register_task_alive(pwrctrl, RECV_ALIVE);
2027 
2028 	_exit_pwrlock(&pwrctrl->lock);
2029 
2030 
2031 	return _SUCCESS;
2032 }
2033 
2034 /*
2035  * Caller: evt_isr or evt_thread
2036  *
2037  * Calling Context: Dispatch/ISR or Passive
2038  *
2039  * Return Value:
2040  *	_SUCCESS
2041  *	_FAIL
2042  */
rtw_register_evt_alive(PADAPTER padapter)2043 s32 rtw_register_evt_alive(PADAPTER padapter)
2044 {
2045 	struct pwrctrl_priv *pwrctrl;
2046 
2047 
2048 	pwrctrl = adapter_to_pwrctl(padapter);
2049 
2050 	_enter_pwrlock(&pwrctrl->lock);
2051 
2052 	register_task_alive(pwrctrl, EVT_ALIVE);
2053 
2054 	_exit_pwrlock(&pwrctrl->lock);
2055 
2056 
2057 	return _SUCCESS;
2058 }
2059 
2060 /*
2061  * Caller: ISR
2062  *
2063  * If ISR's txdone,
2064  * No more pkts for TX,
2065  * Then driver shall call this fun. to power down firmware again.
2066  */
rtw_unregister_tx_alive(PADAPTER padapter)2067 void rtw_unregister_tx_alive(PADAPTER padapter)
2068 {
2069 	struct pwrctrl_priv *pwrctrl;
2070 	_adapter *iface;
2071 	struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
2072 	u8 pslv, i;
2073 
2074 
2075 	pwrctrl = adapter_to_pwrctl(padapter);
2076 	pslv = PS_STATE_S0;
2077 
2078 #ifdef CONFIG_BT_COEXIST
2079 	if ((rtw_btcoex_IsBtDisabled(padapter) == _FALSE)
2080 	    && (rtw_btcoex_IsBtControlLps(padapter) == _TRUE)) {
2081 		u8 val8;
2082 
2083 		val8 = rtw_btcoex_LpsVal(padapter);
2084 		if (val8 & BIT(4))
2085 			pslv = PS_STATE_S2;
2086 
2087 	}
2088 #endif /* CONFIG_BT_COEXIST */
2089 
2090 #ifdef CONFIG_P2P_PS
2091 	for (i = 0; i < dvobj->iface_nums; i++) {
2092 		iface = dvobj->padapters[i];
2093 		if ((iface) && rtw_is_adapter_up(iface)) {
2094 			if (iface->wdinfo.p2p_ps_mode > P2P_PS_NONE) {
2095 				pslv = PS_STATE_S2;
2096 				break;
2097 			}
2098 		}
2099 	}
2100 #endif
2101 	_enter_pwrlock(&pwrctrl->lock);
2102 
2103 	unregister_task_alive(pwrctrl, XMIT_ALIVE);
2104 
2105 	if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE)
2106 	    && (pwrctrl->bFwCurrentInPSMode == _TRUE)) {
2107 
2108 		if (pwrctrl->cpwm > pslv) {
2109 			if ((pslv >= PS_STATE_S2) || (pwrctrl->alives == 0))
2110 				rtw_set_rpwm(padapter, pslv);
2111 		}
2112 	}
2113 
2114 	_exit_pwrlock(&pwrctrl->lock);
2115 
2116 }
2117 
2118 /*
2119  * Caller: ISR
2120  *
2121  * If all commands have been done,
2122  * and no more command to do,
2123  * then driver shall call this fun. to power down firmware again.
2124  */
rtw_unregister_cmd_alive(PADAPTER padapter)2125 void rtw_unregister_cmd_alive(PADAPTER padapter)
2126 {
2127 	_adapter *iface;
2128 	struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
2129 	struct pwrctrl_priv *pwrctrl;
2130 	u8 pslv, i;
2131 
2132 
2133 	pwrctrl = adapter_to_pwrctl(padapter);
2134 	pslv = PS_STATE_S0;
2135 
2136 #ifdef CONFIG_BT_COEXIST
2137 	if ((rtw_btcoex_IsBtDisabled(padapter) == _FALSE)
2138 	    && (rtw_btcoex_IsBtControlLps(padapter) == _TRUE)) {
2139 		u8 val8;
2140 
2141 		val8 = rtw_btcoex_LpsVal(padapter);
2142 		if (val8 & BIT(4))
2143 			pslv = PS_STATE_S2;
2144 
2145 	}
2146 #endif /* CONFIG_BT_COEXIST */
2147 
2148 #ifdef CONFIG_P2P_PS
2149 	for (i = 0; i < dvobj->iface_nums; i++) {
2150 		iface = dvobj->padapters[i];
2151 		if ((iface) && rtw_is_adapter_up(iface)) {
2152 			if (iface->wdinfo.p2p_ps_mode > P2P_PS_NONE) {
2153 				pslv = PS_STATE_S2;
2154 				break;
2155 			}
2156 		}
2157 	}
2158 #endif
2159 
2160 	_enter_pwrlock(&pwrctrl->lock);
2161 
2162 	unregister_task_alive(pwrctrl, CMD_ALIVE);
2163 
2164 	if ((pwrctrl->pwr_mode != PS_MODE_ACTIVE)
2165 	    && (pwrctrl->bFwCurrentInPSMode == _TRUE)) {
2166 
2167 		if (pwrctrl->cpwm > pslv) {
2168 			if ((pslv >= PS_STATE_S2) || (pwrctrl->alives == 0))
2169 				rtw_set_rpwm(padapter, pslv);
2170 		}
2171 	}
2172 
2173 	_exit_pwrlock(&pwrctrl->lock);
2174 
2175 }
2176 
2177 /*
2178  * Caller: ISR
2179  */
rtw_unregister_rx_alive(PADAPTER padapter)2180 void rtw_unregister_rx_alive(PADAPTER padapter)
2181 {
2182 	struct pwrctrl_priv *pwrctrl;
2183 
2184 
2185 	pwrctrl = adapter_to_pwrctl(padapter);
2186 
2187 	_enter_pwrlock(&pwrctrl->lock);
2188 
2189 	unregister_task_alive(pwrctrl, RECV_ALIVE);
2190 
2191 
2192 	_exit_pwrlock(&pwrctrl->lock);
2193 
2194 }
2195 
rtw_unregister_evt_alive(PADAPTER padapter)2196 void rtw_unregister_evt_alive(PADAPTER padapter)
2197 {
2198 	struct pwrctrl_priv *pwrctrl;
2199 
2200 
2201 	pwrctrl = adapter_to_pwrctl(padapter);
2202 
2203 	unregister_task_alive(pwrctrl, EVT_ALIVE);
2204 
2205 
2206 	_exit_pwrlock(&pwrctrl->lock);
2207 
2208 }
2209 #endif	/* CONFIG_LPS_LCLK */
2210 
2211 #ifdef CONFIG_RESUME_IN_WORKQUEUE
2212 	static void resume_workitem_callback(struct work_struct *work);
2213 #endif /* CONFIG_RESUME_IN_WORKQUEUE */
2214 
rtw_init_pwrctrl_priv(PADAPTER padapter)2215 void rtw_init_pwrctrl_priv(PADAPTER padapter)
2216 {
2217 #ifdef CONFIG_LPS_1T1R
2218 #define LPS_1T1R_FMT ", LPS_1T1R=%d"
2219 #define LPS_1T1R_ARG , pwrctrlpriv->lps_1t1r
2220 #else
2221 #define LPS_1T1R_FMT ""
2222 #define LPS_1T1R_ARG
2223 #endif
2224 
2225 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
2226 #ifdef CONFIG_WOWLAN
2227 	struct registry_priv  *registry_par = &padapter->registrypriv;
2228 #endif
2229 #ifdef CONFIG_GPIO_WAKEUP
2230 	PHAL_DATA_TYPE pHalData = GET_HAL_DATA(padapter);
2231 #endif
2232 
2233 #if defined(CONFIG_CONCURRENT_MODE)
2234 	if (!is_primary_adapter(padapter))
2235 		return;
2236 #endif
2237 
2238 	_init_pwrlock(&pwrctrlpriv->lock);
2239 	_init_pwrlock(&pwrctrlpriv->check_32k_lock);
2240 	pwrctrlpriv->rf_pwrstate = rf_on;
2241 	pwrctrlpriv->ips_enter_cnts = 0;
2242 	pwrctrlpriv->ips_leave_cnts = 0;
2243 	pwrctrlpriv->lps_enter_cnts = 0;
2244 	pwrctrlpriv->lps_leave_cnts = 0;
2245 	pwrctrlpriv->bips_processing = _FALSE;
2246 #ifdef CONFIG_LPS_CHK_BY_TP
2247 	pwrctrlpriv->lps_chk_by_tp = padapter->registrypriv.lps_chk_by_tp;
2248 	pwrctrlpriv->lps_tx_tp_th = LPS_TX_TP_TH;
2249 	pwrctrlpriv->lps_rx_tp_th = LPS_RX_TP_TH;
2250 	pwrctrlpriv->lps_bi_tp_th = LPS_BI_TP_TH;
2251 	pwrctrlpriv->lps_chk_cnt = pwrctrlpriv->lps_chk_cnt_th = LPS_TP_CHK_CNT;
2252 	pwrctrlpriv->lps_tx_pkts = LPS_CHK_PKTS_TX;
2253 	pwrctrlpriv->lps_rx_pkts = LPS_CHK_PKTS_RX;
2254 #endif
2255 
2256 	pwrctrlpriv->ips_mode = padapter->registrypriv.ips_mode;
2257 	pwrctrlpriv->ips_mode_req = padapter->registrypriv.ips_mode;
2258 	pwrctrlpriv->ips_deny_time = rtw_get_current_time();
2259 	pwrctrlpriv->lps_level = padapter->registrypriv.lps_level;
2260 #ifdef CONFIG_LPS_1T1R
2261 	pwrctrlpriv->lps_1t1r = padapter->registrypriv.lps_1t1r;
2262 #endif
2263 
2264 	pwrctrlpriv->pwr_state_check_interval = RTW_PWR_STATE_CHK_INTERVAL;
2265 	pwrctrlpriv->pwr_state_check_cnts = 0;
2266 	pwrctrlpriv->bInSuspend = _FALSE;
2267 	pwrctrlpriv->bkeepfwalive = _FALSE;
2268 	pwrctrlpriv->LpsIdleCount = 0;
2269 
2270 	/* pwrctrlpriv->FWCtrlPSMode =padapter->registrypriv.power_mgnt; */ /* PS_MODE_MIN; */
2271 	if (padapter->registrypriv.mp_mode == 1)
2272 		pwrctrlpriv->power_mgnt = PS_MODE_ACTIVE ;
2273 	else
2274 		pwrctrlpriv->power_mgnt = padapter->registrypriv.power_mgnt; /* PS_MODE_MIN; */
2275 	pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt) ? _TRUE : _FALSE;
2276 
2277 	pwrctrlpriv->bFwCurrentInPSMode = _FALSE;
2278 	pwrctrlpriv->lps_deny_time = rtw_get_current_time();
2279 
2280 	pwrctrlpriv->rpwm = 0;
2281 	pwrctrlpriv->cpwm = PS_STATE_S4;
2282 
2283 	pwrctrlpriv->pwr_mode = PS_MODE_ACTIVE;
2284 	pwrctrlpriv->smart_ps = padapter->registrypriv.smart_ps;
2285 	pwrctrlpriv->bcn_ant_mode = 0;
2286 	pwrctrlpriv->dtim = 0;
2287 
2288 	pwrctrlpriv->tog = 0x80;
2289 	pwrctrlpriv->rpwm_retry = 0;
2290 
2291 	RTW_INFO("%s: IPS_mode=%d, LPS_mode=%d, LPS_level=%d"LPS_1T1R_FMT"\n",
2292 		__func__, pwrctrlpriv->ips_mode, pwrctrlpriv->power_mgnt, pwrctrlpriv->lps_level
2293 		LPS_1T1R_ARG
2294 	);
2295 
2296 #ifdef CONFIG_LPS_LCLK
2297 	rtw_hal_set_hwreg(padapter, HW_VAR_SET_RPWM, (u8 *)(&pwrctrlpriv->rpwm));
2298 
2299 	_init_workitem(&pwrctrlpriv->cpwm_event, cpwm_event_callback, NULL);
2300 
2301 	_init_workitem(&pwrctrlpriv->dma_event, dma_event_callback, NULL);
2302 
2303 #ifdef CONFIG_LPS_RPWM_TIMER
2304 	pwrctrlpriv->brpwmtimeout = _FALSE;
2305 	_init_workitem(&pwrctrlpriv->rpwmtimeoutwi, rpwmtimeout_workitem_callback, NULL);
2306 	rtw_init_timer(&pwrctrlpriv->pwr_rpwm_timer, padapter, pwr_rpwm_timeout_handler, padapter);
2307 #endif /* CONFIG_LPS_RPWM_TIMER */
2308 #endif /* CONFIG_LPS_LCLK */
2309 
2310 #ifdef CONFIG_LPS_PG
2311 	pwrctrlpriv->lpspg_info.name = "LPSPG_INFO";
2312 	#ifdef CONFIG_RTL8822C
2313 	pwrctrlpriv->lpspg_dpk_info.name = "LPSPG_DPK_INFO";
2314 	pwrctrlpriv->lpspg_iqk_info.name = "LPSPG_IQK_INFO";
2315 	#endif
2316 #endif
2317 
2318 	rtw_init_timer(&pwrctrlpriv->pwr_state_check_timer, padapter, pwr_state_check_handler, padapter);
2319 
2320 	pwrctrlpriv->wowlan_mode = _FALSE;
2321 	pwrctrlpriv->wowlan_ap_mode = _FALSE;
2322 	pwrctrlpriv->wowlan_p2p_mode = _FALSE;
2323 	pwrctrlpriv->wowlan_in_resume = _FALSE;
2324 	pwrctrlpriv->wowlan_last_wake_reason = 0;
2325 
2326 #ifdef CONFIG_RESUME_IN_WORKQUEUE
2327 	_init_workitem(&pwrctrlpriv->resume_work, resume_workitem_callback, NULL);
2328 	pwrctrlpriv->rtw_workqueue = create_singlethread_workqueue("rtw_workqueue");
2329 #endif /* CONFIG_RESUME_IN_WORKQUEUE */
2330 
2331 #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
2332 	pwrctrlpriv->early_suspend.suspend = NULL;
2333 	rtw_register_early_suspend(pwrctrlpriv);
2334 #endif /* CONFIG_HAS_EARLYSUSPEND || CONFIG_ANDROID_POWER */
2335 
2336 #ifdef CONFIG_GPIO_WAKEUP
2337 	pwrctrlpriv->wowlan_gpio_index = WAKEUP_GPIO_IDX;
2338 	/* set output low state in initial */
2339 	pwrctrlpriv->wowlan_gpio_output_state = GPIO_OUTPUT_LOW;
2340 	/*default low active*/
2341 	pwrctrlpriv->is_high_active = HIGH_ACTIVE_DEV2HST;
2342 	pwrctrlpriv->hst2dev_high_active = HIGH_ACTIVE_HST2DEV;
2343 
2344 #if (defined(CONFIG_RTL8192F) && defined(CONFIG_USB_HCI) && defined(CONFIG_BT_COEXIST))
2345 	if (pHalData->EEPROMBluetoothCoexist == _TRUE) {
2346 		/* for 8725AU case */
2347 		pwrctrlpriv->wowlan_gpio_index = WAKEUP_GPIO_IDX_8725AU;
2348 		pwrctrlpriv->is_high_active = HIGH_ACTIVE_DEV2HST_8725AU;
2349 	}
2350 #endif
2351 #ifdef CONFIG_RTW_ONE_PIN_GPIO
2352 	rtw_hal_switch_gpio_wl_ctrl(padapter, pwrctrlpriv->wowlan_gpio_index, _TRUE);
2353 	rtw_hal_set_input_gpio(padapter, pwrctrlpriv->wowlan_gpio_index);
2354 #else
2355 	#ifdef CONFIG_WAKEUP_GPIO_INPUT_MODE
2356 	if (pwrctrlpriv->is_high_active == 0)
2357 		rtw_hal_set_input_gpio(padapter, pwrctrlpriv->wowlan_gpio_index);
2358 	else
2359 		rtw_hal_set_output_gpio(padapter, pwrctrlpriv->wowlan_gpio_index,
2360 			GPIO_OUTPUT_LOW);
2361 	#else
2362 	rtw_hal_set_output_gpio(padapter, pwrctrlpriv->wowlan_gpio_index
2363 		, pwrctrlpriv->wowlan_gpio_output_state);
2364 	rtw_hal_switch_gpio_wl_ctrl(padapter, pwrctrlpriv->wowlan_gpio_index, _TRUE);
2365 	RTW_INFO("%s: set GPIO_%d to OUTPUT %s state in initial and %s_ACTIVE.\n",
2366 		 __func__, pwrctrlpriv->wowlan_gpio_index,
2367 		 pwrctrlpriv->wowlan_gpio_output_state ? "HIGH" : "LOW",
2368 		 pwrctrlpriv->is_high_active ? "HIGI" : "LOW");
2369 	#endif /*CONFIG_WAKEUP_GPIO_INPUT_MODE*/
2370 #endif /* CONFIG_RTW_ONE_PIN_GPIO */
2371 #endif /* CONFIG_GPIO_WAKEUP */
2372 
2373 #ifdef CONFIG_WOWLAN
2374 #ifdef CONFIG_LPS_1T1R
2375 #define WOW_LPS_1T1R_FMT ", WOW_LPS_1T1R=%d"
2376 #define WOW_LPS_1T1R_ARG , pwrctrlpriv->wowlan_lps_1t1r
2377 #else
2378 #define WOW_LPS_1T1R_FMT ""
2379 #define WOW_LPS_1T1R_ARG
2380 #endif
2381 
2382 	pwrctrlpriv->wowlan_power_mgmt = padapter->registrypriv.wow_power_mgnt;
2383 	pwrctrlpriv->wowlan_lps_level = padapter->registrypriv.wow_lps_level;
2384 #ifdef CONFIG_LPS_1T1R
2385 	pwrctrlpriv->wowlan_lps_1t1r = padapter->registrypriv.wow_lps_1t1r;
2386 #endif
2387 
2388 	RTW_INFO("%s: WOW_LPS_mode=%d, WOW_LPS_level=%d"WOW_LPS_1T1R_FMT"\n",
2389 		__func__, pwrctrlpriv->wowlan_power_mgmt, pwrctrlpriv->wowlan_lps_level
2390 		WOW_LPS_1T1R_ARG
2391 	);
2392 
2393 	if (registry_par->wakeup_event & BIT(1))
2394 		pwrctrlpriv->default_patterns_en = _TRUE;
2395 	else
2396 		pwrctrlpriv->default_patterns_en = _FALSE;
2397 
2398 	rtw_wow_pattern_sw_reset(padapter);
2399 #ifdef CONFIG_PNO_SUPPORT
2400 	pwrctrlpriv->pno_inited = _FALSE;
2401 	pwrctrlpriv->pnlo_info = NULL;
2402 	#ifndef RTW_HALMAC
2403 	pwrctrlpriv->pscan_info = NULL;
2404 	#endif
2405 	pwrctrlpriv->pno_ssid_list = NULL;
2406 #endif /* CONFIG_PNO_SUPPORT */
2407 #ifdef CONFIG_WOW_PATTERN_HW_CAM
2408 	_rtw_mutex_init(&pwrctrlpriv->wowlan_pattern_cam_mutex);
2409 #endif
2410 
2411 #ifdef CONFIG_WOW_KEEP_ALIVE_PATTERN
2412 	pwrctrlpriv->wowlan_keep_alive_ack_index = 0xFF;
2413 	pwrctrlpriv->wowlan_wake_pattern_index = 0xFF;
2414 #endif/*CONFIG_WOW_KEEP_ALIVE_PATTERN*/
2415 	pwrctrlpriv->wowlan_aoac_rpt_loc = 0;
2416 #ifdef CONFIG_WAR_OFFLOAD
2417 #if defined(CONFIG_OFFLOAD_MDNS_V4) || defined(CONFIG_OFFLOAD_MDNS_V6)
2418 	rtw_wow_war_mdns_parms_reset(padapter, _TRUE);
2419 #endif /* defined(CONFIG_OFFLOAD_MDNS_V4) || defined(CONFIG_OFFLOAD_MDNS_V6) */
2420 #endif /* CONFIG_WAR_OFFLOAD */
2421 #endif /* CONFIG_WOWLAN */
2422 
2423 #ifdef CONFIG_LPS_POFF
2424 	rtw_hal_set_hwreg(padapter, HW_VAR_LPS_POFF_INIT, 0);
2425 #endif
2426 
2427 #ifdef CONFIG_LPS_ACK
2428 	_rtw_mutex_init(&pwrctrlpriv->lps_ack_mutex);
2429 	pwrctrlpriv->lps_ack_status = -1;
2430 #endif /* CONFIG_LPS_ACK */
2431 }
2432 
2433 
rtw_free_pwrctrl_priv(PADAPTER adapter)2434 void rtw_free_pwrctrl_priv(PADAPTER adapter)
2435 {
2436 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(adapter);
2437 
2438 #if defined(CONFIG_CONCURRENT_MODE)
2439 	if (!is_primary_adapter(adapter))
2440 		return;
2441 #endif
2442 
2443 
2444 	/* _rtw_memset((unsigned char *)pwrctrlpriv, 0, sizeof(struct pwrctrl_priv)); */
2445 
2446 
2447 #ifdef CONFIG_RESUME_IN_WORKQUEUE
2448 	if (pwrctrlpriv->rtw_workqueue) {
2449 		flush_workqueue(pwrctrlpriv->rtw_workqueue);
2450 		destroy_workqueue(pwrctrlpriv->rtw_workqueue);
2451 	}
2452 #endif
2453 
2454 #ifdef CONFIG_LPS_POFF
2455 	rtw_hal_set_hwreg(adapter, HW_VAR_LPS_POFF_DEINIT, 0);
2456 #endif
2457 
2458 #ifdef CONFIG_LPS_LCLK
2459 	_cancel_workitem_sync(&pwrctrlpriv->cpwm_event);
2460 	_cancel_workitem_sync(&pwrctrlpriv->dma_event);
2461 	#ifdef CONFIG_LPS_RPWM_TIMER
2462 	_cancel_workitem_sync(&pwrctrlpriv->rpwmtimeoutwi);
2463 	#endif
2464 #endif /* CONFIG_LPS_LCLK */
2465 
2466 #ifdef CONFIG_LPS_PG
2467 	rsvd_page_cache_free(&pwrctrlpriv->lpspg_info);
2468 	#ifdef CONFIG_RTL8822C
2469 	rsvd_page_cache_free(&pwrctrlpriv->lpspg_dpk_info);
2470 	rsvd_page_cache_free(&pwrctrlpriv->lpspg_iqk_info);
2471 	#endif
2472 #endif
2473 
2474 #ifdef CONFIG_WOWLAN
2475 #ifdef CONFIG_PNO_SUPPORT
2476 	if (pwrctrlpriv->pnlo_info != NULL)
2477 		printk("****** pnlo_info memory leak********\n");
2478 
2479 	#ifndef RTW_HALMAC
2480 	if (pwrctrlpriv->pscan_info != NULL)
2481 		printk("****** pscan_info memory leak********\n");
2482 	#endif
2483 
2484 	if (pwrctrlpriv->pno_ssid_list != NULL)
2485 		printk("****** pno_ssid_list memory leak********\n");
2486 #endif
2487 #ifdef CONFIG_WOW_PATTERN_HW_CAM
2488 	_rtw_mutex_free(&pwrctrlpriv->wowlan_pattern_cam_mutex);
2489 #endif
2490 
2491 #endif /* CONFIG_WOWLAN */
2492 
2493 #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
2494 	rtw_unregister_early_suspend(pwrctrlpriv);
2495 #endif /* CONFIG_HAS_EARLYSUSPEND || CONFIG_ANDROID_POWER */
2496 
2497 	_free_pwrlock(&pwrctrlpriv->lock);
2498 	_free_pwrlock(&pwrctrlpriv->check_32k_lock);
2499 
2500 #ifdef CONFIG_LPS_ACK
2501 	_rtw_mutex_free(&pwrctrlpriv->lps_ack_mutex);
2502 #endif /* CONFIG_LPS_ACK */
2503 }
2504 
2505 #ifdef CONFIG_RESUME_IN_WORKQUEUE
2506 extern int rtw_resume_process(_adapter *padapter);
2507 
resume_workitem_callback(struct work_struct * work)2508 static void resume_workitem_callback(struct work_struct *work)
2509 {
2510 	struct pwrctrl_priv *pwrpriv = container_of(work, struct pwrctrl_priv, resume_work);
2511 	struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
2512 	_adapter *adapter = dvobj_get_primary_adapter(dvobj);
2513 
2514 	RTW_INFO("%s\n", __FUNCTION__);
2515 
2516 	rtw_resume_process(adapter);
2517 
2518 	rtw_resume_unlock_suspend();
2519 }
2520 
rtw_resume_in_workqueue(struct pwrctrl_priv * pwrpriv)2521 void rtw_resume_in_workqueue(struct pwrctrl_priv *pwrpriv)
2522 {
2523 	/* accquire system's suspend lock preventing from falliing asleep while resume in workqueue */
2524 	/* rtw_lock_suspend(); */
2525 
2526 	rtw_resume_lock_suspend();
2527 
2528 #if 1
2529 	queue_work(pwrpriv->rtw_workqueue, &pwrpriv->resume_work);
2530 #else
2531 	_set_workitem(&pwrpriv->resume_work);
2532 #endif
2533 }
2534 #endif /* CONFIG_RESUME_IN_WORKQUEUE */
2535 
2536 #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
rtw_is_earlysuspend_registered(struct pwrctrl_priv * pwrpriv)2537 inline bool rtw_is_earlysuspend_registered(struct pwrctrl_priv *pwrpriv)
2538 {
2539 	return (pwrpriv->early_suspend.suspend) ? _TRUE : _FALSE;
2540 }
2541 
rtw_is_do_late_resume(struct pwrctrl_priv * pwrpriv)2542 inline bool rtw_is_do_late_resume(struct pwrctrl_priv *pwrpriv)
2543 {
2544 	return (pwrpriv->do_late_resume) ? _TRUE : _FALSE;
2545 }
2546 
rtw_set_do_late_resume(struct pwrctrl_priv * pwrpriv,bool enable)2547 inline void rtw_set_do_late_resume(struct pwrctrl_priv *pwrpriv, bool enable)
2548 {
2549 	pwrpriv->do_late_resume = enable;
2550 }
2551 #endif
2552 
2553 #ifdef CONFIG_HAS_EARLYSUSPEND
2554 extern int rtw_resume_process(_adapter *padapter);
rtw_early_suspend(struct early_suspend * h)2555 static void rtw_early_suspend(struct early_suspend *h)
2556 {
2557 	struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
2558 	RTW_INFO("%s\n", __FUNCTION__);
2559 
2560 	rtw_set_do_late_resume(pwrpriv, _FALSE);
2561 }
2562 
rtw_late_resume(struct early_suspend * h)2563 static void rtw_late_resume(struct early_suspend *h)
2564 {
2565 	struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
2566 	struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
2567 	_adapter *adapter = dvobj_get_primary_adapter(dvobj);
2568 
2569 	RTW_INFO("%s\n", __FUNCTION__);
2570 
2571 	if (pwrpriv->do_late_resume) {
2572 		rtw_set_do_late_resume(pwrpriv, _FALSE);
2573 		rtw_resume_process(adapter);
2574 	}
2575 }
2576 
rtw_register_early_suspend(struct pwrctrl_priv * pwrpriv)2577 void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv)
2578 {
2579 	RTW_INFO("%s\n", __FUNCTION__);
2580 
2581 	/* jeff: set the early suspend level before blank screen, so we wll do late resume after scree is lit */
2582 	pwrpriv->early_suspend.level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
2583 	pwrpriv->early_suspend.suspend = rtw_early_suspend;
2584 	pwrpriv->early_suspend.resume = rtw_late_resume;
2585 	register_early_suspend(&pwrpriv->early_suspend);
2586 
2587 
2588 }
2589 
rtw_unregister_early_suspend(struct pwrctrl_priv * pwrpriv)2590 void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv)
2591 {
2592 	RTW_INFO("%s\n", __FUNCTION__);
2593 
2594 	rtw_set_do_late_resume(pwrpriv, _FALSE);
2595 
2596 	if (pwrpriv->early_suspend.suspend)
2597 		unregister_early_suspend(&pwrpriv->early_suspend);
2598 
2599 	pwrpriv->early_suspend.suspend = NULL;
2600 	pwrpriv->early_suspend.resume = NULL;
2601 }
2602 #endif /* CONFIG_HAS_EARLYSUSPEND */
2603 
2604 #ifdef CONFIG_ANDROID_POWER
2605 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
2606 	extern int rtw_resume_process(PADAPTER padapter);
2607 #endif
rtw_early_suspend(android_early_suspend_t * h)2608 static void rtw_early_suspend(android_early_suspend_t *h)
2609 {
2610 	struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
2611 	RTW_INFO("%s\n", __FUNCTION__);
2612 
2613 	rtw_set_do_late_resume(pwrpriv, _FALSE);
2614 }
2615 
rtw_late_resume(android_early_suspend_t * h)2616 static void rtw_late_resume(android_early_suspend_t *h)
2617 {
2618 	struct pwrctrl_priv *pwrpriv = container_of(h, struct pwrctrl_priv, early_suspend);
2619 	struct dvobj_priv *dvobj = pwrctl_to_dvobj(pwrpriv);
2620 	_adapter *adapter = dvobj_get_primary_adapter(dvobj);
2621 
2622 	RTW_INFO("%s\n", __FUNCTION__);
2623 	if (pwrpriv->do_late_resume) {
2624 #if defined(CONFIG_USB_HCI) || defined(CONFIG_SDIO_HCI) || defined(CONFIG_GSPI_HCI)
2625 		rtw_set_do_late_resume(pwrpriv, _FALSE);
2626 		rtw_resume_process(adapter);
2627 #endif
2628 	}
2629 }
2630 
rtw_register_early_suspend(struct pwrctrl_priv * pwrpriv)2631 void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv)
2632 {
2633 	RTW_INFO("%s\n", __FUNCTION__);
2634 
2635 	/* jeff: set the early suspend level before blank screen, so we wll do late resume after scree is lit */
2636 	pwrpriv->early_suspend.level = ANDROID_EARLY_SUSPEND_LEVEL_BLANK_SCREEN - 20;
2637 	pwrpriv->early_suspend.suspend = rtw_early_suspend;
2638 	pwrpriv->early_suspend.resume = rtw_late_resume;
2639 	android_register_early_suspend(&pwrpriv->early_suspend);
2640 }
2641 
rtw_unregister_early_suspend(struct pwrctrl_priv * pwrpriv)2642 void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv)
2643 {
2644 	RTW_INFO("%s\n", __FUNCTION__);
2645 
2646 	rtw_set_do_late_resume(pwrpriv, _FALSE);
2647 
2648 	if (pwrpriv->early_suspend.suspend)
2649 		android_unregister_early_suspend(&pwrpriv->early_suspend);
2650 
2651 	pwrpriv->early_suspend.suspend = NULL;
2652 	pwrpriv->early_suspend.resume = NULL;
2653 }
2654 #endif /* CONFIG_ANDROID_POWER */
2655 
rtw_interface_ps_func(_adapter * padapter,HAL_INTF_PS_FUNC efunc_id,u8 * val)2656 u8 rtw_interface_ps_func(_adapter *padapter, HAL_INTF_PS_FUNC efunc_id, u8 *val)
2657 {
2658 	u8 bResult = _TRUE;
2659 	rtw_hal_intf_ps_func(padapter, efunc_id, val);
2660 
2661 	return bResult;
2662 }
2663 
2664 
rtw_set_ips_deny(_adapter * padapter,u32 ms)2665 inline void rtw_set_ips_deny(_adapter *padapter, u32 ms)
2666 {
2667 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
2668 	pwrpriv->ips_deny_time = rtw_get_current_time() + rtw_ms_to_systime(ms);
2669 }
2670 
2671 /*
2672 * rtw_pwr_wakeup - Wake the NIC up from: 1)IPS. 2)USB autosuspend
2673 * @adapter: pointer to _adapter structure
2674 * @ips_deffer_ms: the ms wiil prevent from falling into IPS after wakeup
2675 * Return _SUCCESS or _FAIL
2676 */
2677 
_rtw_pwr_wakeup(_adapter * padapter,u32 ips_deffer_ms,const char * caller)2678 int _rtw_pwr_wakeup(_adapter *padapter, u32 ips_deffer_ms, const char *caller)
2679 {
2680 	struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
2681 	struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
2682 	struct mlme_priv *pmlmepriv;
2683 	int ret = _SUCCESS;
2684 	systime start = rtw_get_current_time();
2685 
2686 	/*RTW_INFO(FUNC_ADPT_FMT "===>\n", FUNC_ADPT_ARG(padapter));*/
2687 	/* for LPS */
2688 	LeaveAllPowerSaveMode(padapter);
2689 
2690 	/* IPS still bound with primary adapter */
2691 	padapter = GET_PRIMARY_ADAPTER(padapter);
2692 	pmlmepriv = &padapter->mlmepriv;
2693 
2694 	if (rtw_time_after(rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms), pwrpriv->ips_deny_time))
2695 		pwrpriv->ips_deny_time = rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms);
2696 
2697 
2698 	if (pwrpriv->ps_processing) {
2699 		RTW_INFO("%s wait ps_processing...\n", __func__);
2700 		while (pwrpriv->ps_processing && rtw_get_passing_time_ms(start) <= 3000)
2701 			rtw_msleep_os(10);
2702 		if (pwrpriv->ps_processing)
2703 			RTW_INFO("%s wait ps_processing timeout\n", __func__);
2704 		else
2705 			RTW_INFO("%s wait ps_processing done\n", __func__);
2706 	}
2707 
2708 #ifdef DBG_CONFIG_ERROR_DETECT
2709 	if (rtw_hal_sreset_inprogress(padapter)) {
2710 		RTW_INFO("%s wait sreset_inprogress...\n", __func__);
2711 		while (rtw_hal_sreset_inprogress(padapter) && rtw_get_passing_time_ms(start) <= 4000)
2712 			rtw_msleep_os(10);
2713 		if (rtw_hal_sreset_inprogress(padapter))
2714 			RTW_INFO("%s wait sreset_inprogress timeout\n", __func__);
2715 		else
2716 			RTW_INFO("%s wait sreset_inprogress done\n", __func__);
2717 	}
2718 #endif
2719 
2720 	if (pwrpriv->bInSuspend) {
2721 		RTW_INFO("%s wait bInSuspend...\n", __func__);
2722 		while (pwrpriv->bInSuspend
2723 		       && ((rtw_get_passing_time_ms(start) <= 3000 && !rtw_is_do_late_resume(pwrpriv))
2724 			|| (rtw_get_passing_time_ms(start) <= 500 && rtw_is_do_late_resume(pwrpriv)))
2725 		      )
2726 			rtw_msleep_os(10);
2727 		if (pwrpriv->bInSuspend)
2728 			RTW_INFO("%s wait bInSuspend timeout\n", __func__);
2729 		else
2730 			RTW_INFO("%s wait bInSuspend done\n", __func__);
2731 	}
2732 
2733 	/* System suspend is not allowed to wakeup */
2734 	if (_TRUE == pwrpriv->bInSuspend) {
2735 		ret = _FAIL;
2736 		goto exit;
2737 	}
2738 	/* I think this should be check in IPS, LPS, autosuspend functions... */
2739 	if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE) == _TRUE) {
2740 		ret = _SUCCESS;
2741 		goto exit;
2742 	}
2743 
2744 	if (rf_off == pwrpriv->rf_pwrstate) {
2745 
2746 #ifdef CONFIG_IPS
2747 		RTW_INFO("%s call ips_leave....\n", __FUNCTION__);
2748 		if (_FAIL ==  ips_leave(padapter)) {
2749 			RTW_INFO("======> ips_leave fail.............\n");
2750 			ret = _FAIL;
2751 			goto exit;
2752 		}
2753 #endif
2754 
2755 	}
2756 
2757 	/* TODO: the following checking need to be merged... */
2758 	if (rtw_is_drv_stopped(padapter)
2759 	    || !padapter->bup
2760 	    || !rtw_is_hw_init_completed(padapter)
2761 	   ) {
2762 		RTW_INFO("%s: bDriverStopped=%s, bup=%d, hw_init_completed=%u\n"
2763 			 , caller
2764 			 , rtw_is_drv_stopped(padapter) ? "True" : "False"
2765 			 , padapter->bup
2766 			 , rtw_get_hw_init_completed(padapter));
2767 		ret = _FALSE;
2768 		goto exit;
2769 	}
2770 
2771 exit:
2772 	if (rtw_time_after(rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms), pwrpriv->ips_deny_time))
2773 		pwrpriv->ips_deny_time = rtw_get_current_time() + rtw_ms_to_systime(ips_deffer_ms);
2774 	/*RTW_INFO(FUNC_ADPT_FMT "<===\n", FUNC_ADPT_ARG(padapter));*/
2775 	return ret;
2776 
2777 }
2778 
rtw_pm_set_lps(_adapter * padapter,u8 mode)2779 int rtw_pm_set_lps(_adapter *padapter, u8 mode)
2780 {
2781 	int	ret = 0;
2782 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
2783 
2784 	if (mode < PS_MODE_NUM) {
2785 		if (pwrctrlpriv->power_mgnt != mode) {
2786 			if (PS_MODE_ACTIVE == mode)
2787 				LeaveAllPowerSaveMode(padapter);
2788 			else
2789 				pwrctrlpriv->LpsIdleCount = 2;
2790 			pwrctrlpriv->power_mgnt = mode;
2791 			pwrctrlpriv->bLeisurePs = (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt) ? _TRUE : _FALSE;
2792 		}
2793 	} else
2794 		ret = -EINVAL;
2795 
2796 	return ret;
2797 }
2798 
rtw_pm_set_lps_level(_adapter * padapter,u8 level)2799 int rtw_pm_set_lps_level(_adapter *padapter, u8 level)
2800 {
2801 	int	ret = 0;
2802 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
2803 
2804 	if (level < LPS_LEVEL_MAX) {
2805 		if (pwrctrlpriv->lps_level != level) {
2806 			#ifdef CONFIG_LPS
2807 			if (rtw_lps_ctrl_leave_set_level_cmd(padapter, level, RTW_CMDF_WAIT_ACK) != _SUCCESS)
2808 			#endif
2809 				pwrctrlpriv->lps_level = level;
2810 		}
2811 	} else
2812 		ret = -EINVAL;
2813 
2814 	return ret;
2815 }
2816 
2817 #ifdef CONFIG_LPS_1T1R
rtw_pm_set_lps_1t1r(_adapter * padapter,u8 en)2818 int rtw_pm_set_lps_1t1r(_adapter *padapter, u8 en)
2819 {
2820 	int	ret = 0;
2821 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
2822 
2823 	en = en ? 1 : 0;
2824 	if (pwrctrlpriv->lps_1t1r != en) {
2825 		if (rtw_lps_ctrl_leave_set_1t1r_cmd(padapter, en, RTW_CMDF_WAIT_ACK) != _SUCCESS)
2826 			pwrctrlpriv->lps_1t1r = en;
2827 	}
2828 
2829 	return ret;
2830 }
2831 #endif
2832 
rtw_set_lps_deny(_adapter * adapter,u32 ms)2833 inline void rtw_set_lps_deny(_adapter *adapter, u32 ms)
2834 {
2835 	struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(adapter);
2836 	pwrpriv->lps_deny_time = rtw_get_current_time() + rtw_ms_to_systime(ms);
2837 }
2838 
2839 #ifdef CONFIG_WOWLAN
rtw_pm_set_wow_lps(_adapter * padapter,u8 mode)2840 int rtw_pm_set_wow_lps(_adapter *padapter, u8 mode)
2841 {
2842 	int	ret = 0;
2843 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
2844 
2845 	if (mode < PS_MODE_NUM) {
2846 		if (pwrctrlpriv->wowlan_power_mgmt != mode)
2847 			pwrctrlpriv->wowlan_power_mgmt = mode;
2848 	} else
2849 		ret = -EINVAL;
2850 
2851 	return ret;
2852 }
rtw_pm_set_wow_lps_level(_adapter * padapter,u8 level)2853 int rtw_pm_set_wow_lps_level(_adapter *padapter, u8 level)
2854 {
2855 	int	ret = 0;
2856 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
2857 
2858 	if (level < LPS_LEVEL_MAX)
2859 		pwrctrlpriv->wowlan_lps_level = level;
2860 	else
2861 		ret = -EINVAL;
2862 
2863 	return ret;
2864 }
2865 
2866 #ifdef CONFIG_LPS_1T1R
rtw_pm_set_wow_lps_1t1r(_adapter * padapter,u8 en)2867 int rtw_pm_set_wow_lps_1t1r(_adapter *padapter, u8 en)
2868 {
2869 	int	ret = 0;
2870 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
2871 
2872 	en = en ? 1 : 0;
2873 	pwrctrlpriv->wowlan_lps_1t1r = en;
2874 
2875 	return ret;
2876 }
2877 #endif /* CONFIG_LPS_1T1R */
2878 #endif /* CONFIG_WOWLAN */
2879 
rtw_pm_set_ips(_adapter * padapter,u8 mode)2880 int rtw_pm_set_ips(_adapter *padapter, u8 mode)
2881 {
2882 	struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
2883 
2884 	if (mode == IPS_NORMAL || mode == IPS_LEVEL_2) {
2885 		rtw_ips_mode_req(pwrctrlpriv, mode);
2886 		RTW_INFO("%s %s\n", __FUNCTION__, mode == IPS_NORMAL ? "IPS_NORMAL" : "IPS_LEVEL_2");
2887 		return 0;
2888 	} else if (mode == IPS_NONE) {
2889 		rtw_ips_mode_req(pwrctrlpriv, mode);
2890 		RTW_INFO("%s %s\n", __FUNCTION__, "IPS_NONE");
2891 		if (!rtw_is_surprise_removed(padapter) && (_FAIL == rtw_pwr_wakeup(padapter)))
2892 			return -EFAULT;
2893 	} else
2894 		return -EINVAL;
2895 	return 0;
2896 }
2897 
2898 /*
2899  * ATTENTION:
2900  *	This function will request pwrctrl LOCK!
2901  */
rtw_ps_deny(PADAPTER padapter,PS_DENY_REASON reason)2902 void rtw_ps_deny(PADAPTER padapter, PS_DENY_REASON reason)
2903 {
2904 	struct pwrctrl_priv *pwrpriv;
2905 
2906 	/* 	RTW_INFO("+" FUNC_ADPT_FMT ": Request PS deny for %d (0x%08X)\n",
2907 	 *		FUNC_ADPT_ARG(padapter), reason, BIT(reason)); */
2908 
2909 	pwrpriv = adapter_to_pwrctl(padapter);
2910 
2911 	_enter_pwrlock(&pwrpriv->lock);
2912 	if (pwrpriv->ps_deny & BIT(reason)) {
2913 		RTW_INFO(FUNC_ADPT_FMT ": [WARNING] Reason %d had been set before!!\n",
2914 			 FUNC_ADPT_ARG(padapter), reason);
2915 	}
2916 	pwrpriv->ps_deny |= BIT(reason);
2917 	_exit_pwrlock(&pwrpriv->lock);
2918 
2919 	/* 	RTW_INFO("-" FUNC_ADPT_FMT ": Now PS deny for 0x%08X\n",
2920 	 *		FUNC_ADPT_ARG(padapter), pwrpriv->ps_deny); */
2921 }
2922 
2923 /*
2924  * ATTENTION:
2925  *	This function will request pwrctrl LOCK!
2926  */
rtw_ps_deny_cancel(PADAPTER padapter,PS_DENY_REASON reason)2927 void rtw_ps_deny_cancel(PADAPTER padapter, PS_DENY_REASON reason)
2928 {
2929 	struct pwrctrl_priv *pwrpriv;
2930 
2931 
2932 	/* 	RTW_INFO("+" FUNC_ADPT_FMT ": Cancel PS deny for %d(0x%08X)\n",
2933 	 *		FUNC_ADPT_ARG(padapter), reason, BIT(reason)); */
2934 
2935 	pwrpriv = adapter_to_pwrctl(padapter);
2936 
2937 	_enter_pwrlock(&pwrpriv->lock);
2938 	if ((pwrpriv->ps_deny & BIT(reason)) == 0) {
2939 		RTW_INFO(FUNC_ADPT_FMT ": [ERROR] Reason %d had been canceled before!!\n",
2940 			 FUNC_ADPT_ARG(padapter), reason);
2941 	}
2942 	pwrpriv->ps_deny &= ~BIT(reason);
2943 	_exit_pwrlock(&pwrpriv->lock);
2944 
2945 	/* 	RTW_INFO("-" FUNC_ADPT_FMT ": Now PS deny for 0x%08X\n",
2946 	 *		FUNC_ADPT_ARG(padapter), pwrpriv->ps_deny); */
2947 }
2948 
2949 /*
2950  * ATTENTION:
2951  *	Before calling this function pwrctrl lock should be occupied already,
2952  *	otherwise it may return incorrect value.
2953  */
rtw_ps_deny_get(PADAPTER padapter)2954 u32 rtw_ps_deny_get(PADAPTER padapter)
2955 {
2956 	u32 deny;
2957 
2958 
2959 	deny = adapter_to_pwrctl(padapter)->ps_deny;
2960 
2961 	return deny;
2962 }
2963 
_rtw_ssmps(_adapter * adapter,struct sta_info * sta)2964 static void _rtw_ssmps(_adapter *adapter, struct sta_info *sta)
2965 {
2966 	struct mlme_ext_priv *pmlmeext = &(adapter->mlmeextpriv);
2967 	struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
2968 
2969 	if (MLME_IS_STA(adapter)) {
2970 		issue_action_SM_PS_wait_ack(adapter , get_my_bssid(&(pmlmeinfo->network)),
2971 			sta->cmn.sm_ps, 3 , 1);
2972 	}
2973 	else if (MLME_IS_AP(adapter)) {
2974 
2975 	}
2976 	rtw_phydm_ra_registed(adapter, sta);
2977 }
rtw_ssmps_enter(_adapter * adapter,struct sta_info * sta)2978 void rtw_ssmps_enter(_adapter *adapter, struct sta_info *sta)
2979 {
2980 	if (sta->cmn.sm_ps == SM_PS_STATIC)
2981 		return;
2982 
2983 	RTW_INFO(ADPT_FMT" STA [" MAC_FMT "]\n", ADPT_ARG(adapter), MAC_ARG(sta->cmn.mac_addr));
2984 
2985 	sta->cmn.sm_ps = SM_PS_STATIC;
2986 	_rtw_ssmps(adapter, sta);
2987 }
rtw_ssmps_leave(_adapter * adapter,struct sta_info * sta)2988 void rtw_ssmps_leave(_adapter *adapter, struct sta_info *sta)
2989 {
2990 	if (sta->cmn.sm_ps == SM_PS_DISABLE)
2991 		return;
2992 
2993 	RTW_INFO(ADPT_FMT" STA [" MAC_FMT "] \n", ADPT_ARG(adapter), MAC_ARG(sta->cmn.mac_addr));
2994 	sta->cmn.sm_ps = SM_PS_DISABLE;
2995 	_rtw_ssmps(adapter, sta);
2996 }
2997 
2998