Linux-libre 3.18.13-gnu
[librecmc/linux-libre.git] / drivers / staging / rtl8723au / core / rtw_pwrctrl.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
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 <osdep_service.h>
18 #include <drv_types.h>
19 #include <osdep_intf.h>
20 #include <rtl8723a_cmd.h>
21 #include <rtw_sreset.h>
22
23 #include <rtl8723a_bt_intf.h>
24 #include <usb_ops_linux.h>
25
26 void ips_enter23a(struct rtw_adapter *padapter)
27 {
28         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
29
30         down(&pwrpriv->lock);
31
32         pwrpriv->bips_processing = true;
33
34         /*  syn ips_mode with request */
35         pwrpriv->ips_mode = pwrpriv->ips_mode_req;
36
37         pwrpriv->ips_enter23a_cnts++;
38         DBG_8723A("==>ips_enter23a cnts:%d\n", pwrpriv->ips_enter23a_cnts);
39         rtl8723a_BT_disable_coexist(padapter);
40
41         if (pwrpriv->change_rfpwrstate == rf_off) {
42                 pwrpriv->bpower_saving = true;
43                 DBG_8723A_LEVEL(_drv_always_, "nolinked power save enter\n");
44
45                 if (pwrpriv->ips_mode == IPS_LEVEL_2)
46                         pwrpriv->bkeepfwalive = true;
47
48                 rtw_ips_pwr_down23a(padapter);
49                 pwrpriv->rf_pwrstate = rf_off;
50         }
51         pwrpriv->bips_processing = false;
52
53         up(&pwrpriv->lock);
54 }
55
56 int ips_leave23a(struct rtw_adapter *padapter)
57 {
58         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
59         struct security_priv *psecuritypriv = &padapter->securitypriv;
60         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
61         int result = _SUCCESS;
62         int keyid;
63
64         down(&pwrpriv->lock);
65
66         if (pwrpriv->rf_pwrstate == rf_off && !pwrpriv->bips_processing) {
67                 pwrpriv->bips_processing = true;
68                 pwrpriv->change_rfpwrstate = rf_on;
69                 pwrpriv->ips_leave23a_cnts++;
70                 DBG_8723A("==>ips_leave23a cnts:%d\n",
71                           pwrpriv->ips_leave23a_cnts);
72
73                 result = rtw_ips_pwr_up23a(padapter);
74                 if (result == _SUCCESS)
75                         pwrpriv->rf_pwrstate = rf_on;
76
77                 DBG_8723A_LEVEL(_drv_always_, "nolinked power save leave\n");
78
79                 if (psecuritypriv->dot11PrivacyAlgrthm ==
80                     WLAN_CIPHER_SUITE_WEP40 ||
81                     psecuritypriv->dot11PrivacyAlgrthm ==
82                     WLAN_CIPHER_SUITE_WEP104) {
83                         DBG_8723A("==>%s, channel(%d), processing(%x)\n",
84                                   __func__, padapter->mlmeextpriv.cur_channel,
85                                   pwrpriv->bips_processing);
86                         set_channel_bwmode23a(padapter,
87                                               padapter->mlmeextpriv.cur_channel,
88                                               HAL_PRIME_CHNL_OFFSET_DONT_CARE,
89                                               HT_CHANNEL_WIDTH_20);
90                         for (keyid = 0; keyid < 4; keyid++) {
91                                 if (pmlmepriv->key_mask & BIT(keyid)) {
92                                         if (keyid ==
93                                             psecuritypriv->dot11PrivacyKeyIndex)
94                                                 result = rtw_set_key23a(padapter, psecuritypriv, keyid, 1);
95                                         else
96                                                 result = rtw_set_key23a(padapter, psecuritypriv, keyid, 0);
97                                 }
98                         }
99                 }
100
101                 DBG_8723A("==> ips_leave23a.....LED(0x%08x)...\n",
102                           rtl8723au_read32(padapter, 0x4c));
103                 pwrpriv->bips_processing = false;
104
105                 pwrpriv->bkeepfwalive = false;
106                 pwrpriv->bpower_saving = false;
107         }
108
109         up(&pwrpriv->lock);
110
111         return result;
112 }
113
114
115 static bool rtw_pwr_unassociated_idle(struct rtw_adapter *adapter)
116 {
117         struct mlme_priv *pmlmepriv = &adapter->mlmepriv;
118         struct xmit_priv *pxmit_priv = &adapter->xmitpriv;
119
120         bool ret = false;
121
122         if (time_after_eq(adapter->pwrctrlpriv.ips_deny_time, jiffies))
123                 goto exit;
124
125         if (check_fwstate(pmlmepriv, WIFI_ASOC_STATE|WIFI_SITE_MONITOR) ||
126             check_fwstate(pmlmepriv, WIFI_UNDER_LINKING|WIFI_UNDER_WPS) ||
127             check_fwstate(pmlmepriv, WIFI_AP_STATE) ||
128             check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE|WIFI_ADHOC_STATE)){
129                 goto exit;
130         }
131
132         if (pxmit_priv->free_xmitbuf_cnt != NR_XMITBUFF ||
133                 pxmit_priv->free_xmit_extbuf_cnt != NR_XMIT_EXTBUFF) {
134                 DBG_8723A_LEVEL(_drv_always_,
135                                 "There are some pkts to transmit\n");
136                 DBG_8723A_LEVEL(_drv_info_, "free_xmitbuf_cnt: %d, "
137                                 "free_xmit_extbuf_cnt: %d\n",
138                                 pxmit_priv->free_xmitbuf_cnt,
139                                 pxmit_priv->free_xmit_extbuf_cnt);
140                 goto exit;
141         }
142
143         ret = true;
144
145 exit:
146         return ret;
147 }
148
149 void rtw_ps_processor23a(struct rtw_adapter *padapter)
150 {
151         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
152         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
153
154         pwrpriv->ps_processing = true;
155
156         if (pwrpriv->bips_processing == true)
157                 goto exit;
158
159         if (pwrpriv->ips_mode_req == IPS_NONE)
160                 goto exit;
161
162         if (rtw_pwr_unassociated_idle(padapter) == false)
163                 goto exit;
164
165         if (pwrpriv->rf_pwrstate == rf_on &&
166             (pwrpriv->pwr_state_check_cnts % 4) == 0) {
167                 DBG_8723A("==>%s .fw_state(%x)\n", __func__,
168                           get_fwstate(pmlmepriv));
169                 pwrpriv->change_rfpwrstate = rf_off;
170                 ips_enter23a(padapter);
171         }
172 exit:
173         rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
174         pwrpriv->ps_processing = false;
175         return;
176 }
177
178 static void pwr_state_check_handler(unsigned long data)
179 {
180         struct rtw_adapter *padapter = (struct rtw_adapter *)data;
181         rtw_ps_cmd23a(padapter);
182 }
183
184 /*
185  *
186  * Parameters
187  *   padapter
188  *   pslv       power state level, only could be PS_STATE_S0 ~ PS_STATE_S4
189  *
190  */
191 void rtw_set_rpwm23a(struct rtw_adapter *padapter, u8 pslv)
192 {
193         u8 rpwm;
194         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
195
196         pslv = PS_STATE(pslv);
197
198         if (pwrpriv->btcoex_rfon) {
199                 if (pslv < PS_STATE_S4)
200                         pslv = PS_STATE_S3;
201         }
202
203         if (pwrpriv->rpwm == pslv) {
204                 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
205                         ("%s: Already set rpwm[0x%02X], new = 0x%02X!\n",
206                          __func__, pwrpriv->rpwm, pslv));
207                 return;
208         }
209
210         if (padapter->bSurpriseRemoved == true ||
211             padapter->hw_init_completed == false) {
212                 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
213                          ("%s: SurpriseRemoved(%d) hw_init_completed(%d)\n",
214                           __func__, padapter->bSurpriseRemoved,
215                           padapter->hw_init_completed));
216
217                 pwrpriv->cpwm = PS_STATE_S4;
218
219                 return;
220         }
221
222         if (padapter->bDriverStopped == true) {
223                 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
224                          ("%s: change power state(0x%02X) when DriverStopped\n",
225                           __func__, pslv));
226
227                 if (pslv < PS_STATE_S2) {
228                         RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
229                                  ("%s: Reject to enter PS_STATE(0x%02X) lower "
230                                   "than S2 when DriverStopped!!\n",
231                                   __func__, pslv));
232                         return;
233                 }
234         }
235
236         rpwm = pslv | pwrpriv->tog;
237         RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
238                  ("rtw_set_rpwm23a: rpwm = 0x%02x cpwm = 0x%02x\n",
239                   rpwm, pwrpriv->cpwm));
240
241         pwrpriv->rpwm = pslv;
242
243         rtl8723a_set_rpwm(padapter, rpwm);
244
245         pwrpriv->tog += 0x80;
246         pwrpriv->cpwm = pslv;
247 }
248
249 static bool PS_RDY_CHECK(struct rtw_adapter *padapter)
250 {
251         unsigned long delta_time;
252         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
253         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
254
255         delta_time = jiffies - pwrpriv->DelayLPSLastTimeStamp;
256
257         if (delta_time < LPS_DELAY_TIME)
258                 return false;
259
260         if (!check_fwstate(pmlmepriv, _FW_LINKED) ||
261             check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) ||
262             check_fwstate(pmlmepriv, WIFI_AP_STATE) ||
263             check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
264             check_fwstate(pmlmepriv, WIFI_ADHOC_STATE))
265                 return false;
266         if (pwrpriv->bInSuspend)
267                 return false;
268         if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X &&
269             !padapter->securitypriv.binstallGrpkey) {
270                 DBG_8723A("Group handshake still in progress !!!\n");
271                 return false;
272         }
273         if (!rtw_cfg80211_pwr_mgmt(padapter))
274                 return false;
275
276         return true;
277 }
278
279 void rtw_set_ps_mode23a(struct rtw_adapter *padapter, u8 ps_mode,
280                         u8 smart_ps, u8 bcn_ant_mode)
281 {
282         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
283
284         RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
285                          ("%s: PowerMode =%d Smart_PS =%d\n",
286                           __func__, ps_mode, smart_ps));
287
288         if (ps_mode > PM_Card_Disable) {
289                 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
290                          ("ps_mode:%d error\n", ps_mode));
291                 return;
292         }
293
294         if (pwrpriv->pwr_mode == ps_mode) {
295                 if (PS_MODE_ACTIVE == ps_mode)
296                         return;
297
298                 if (pwrpriv->smart_ps == smart_ps &&
299                     pwrpriv->bcn_ant_mode == bcn_ant_mode)
300                         return;
301         }
302
303         if (ps_mode == PS_MODE_ACTIVE) {
304                 DBG_8723A("rtw_set_ps_mode23a: Leave 802.11 power save\n");
305
306                 pwrpriv->pwr_mode = ps_mode;
307                 rtw_set_rpwm23a(padapter, PS_STATE_S4);
308                 rtl8723a_set_FwPwrMode_cmd(padapter, ps_mode);
309                 pwrpriv->bFwCurrentInPSMode = false;
310         } else {
311                 if (PS_RDY_CHECK(padapter) ||
312                     rtl8723a_BT_using_antenna_1(padapter)) {
313                         DBG_8723A("%s: Enter 802.11 power save\n", __func__);
314
315                         pwrpriv->bFwCurrentInPSMode = true;
316                         pwrpriv->pwr_mode = ps_mode;
317                         pwrpriv->smart_ps = smart_ps;
318                         pwrpriv->bcn_ant_mode = bcn_ant_mode;
319                         rtl8723a_set_FwPwrMode_cmd(padapter, ps_mode);
320
321                         rtw_set_rpwm23a(padapter, PS_STATE_S2);
322                 }
323         }
324 }
325
326 /*
327  * Return:
328  *      0:      Leave OK
329  *      -1:     Timeout
330  *      -2:     Other error
331  */
332 s32 LPS_RF_ON_check23a(struct rtw_adapter *padapter, u32 delay_ms)
333 {
334         unsigned long start_time, end_time;
335         u8 bAwake = false;
336         s32 err = 0;
337
338         start_time = jiffies;
339         end_time = start_time + msecs_to_jiffies(delay_ms);
340
341         while (1)
342         {
343                 bAwake = rtl8723a_get_fwlps_rf_on(padapter);
344                 if (bAwake == true)
345                         break;
346
347                 if (padapter->bSurpriseRemoved == true) {
348                         err = -2;
349                         DBG_8723A("%s: device surprise removed!!\n", __func__);
350                         break;
351                 }
352
353                 if (time_after(jiffies, end_time)) {
354                         err = -1;
355                         DBG_8723A("%s: Wait for FW LPS leave more than %u "
356                                   "ms!\n", __func__, delay_ms);
357                         break;
358                 }
359                 udelay(100);
360         }
361
362         return err;
363 }
364
365 /*      Description: */
366 /*              Enter the leisure power save mode. */
367 void LPS_Enter23a(struct rtw_adapter *padapter)
368 {
369         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
370
371         if (!PS_RDY_CHECK(padapter))
372                 return;
373
374         if (pwrpriv->bLeisurePs) {
375                 /*  Idle for a while if we connect to AP a while ago. */
376                 if (pwrpriv->LpsIdleCount >= 2) { /*   4 Sec */
377                         if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) {
378                                 pwrpriv->bpower_saving = true;
379                                 DBG_8723A("%s smart_ps:%d\n", __func__,
380                                           pwrpriv->smart_ps);
381                                 /* For Tenda W311R IOT issue */
382                                 rtw_set_ps_mode23a(padapter,
383                                                    pwrpriv->power_mgnt,
384                                                    pwrpriv->smart_ps, 0);
385                         }
386                 } else
387                         pwrpriv->LpsIdleCount++;
388         }
389 }
390
391 /*      Description: */
392 /*              Leave the leisure power save mode. */
393 void LPS_Leave23a(struct rtw_adapter *padapter)
394 {
395 #define LPS_LEAVE_TIMEOUT_MS 100
396
397         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
398
399         if (pwrpriv->bLeisurePs) {
400                 if (pwrpriv->pwr_mode != PS_MODE_ACTIVE) {
401                         rtw_set_ps_mode23a(padapter, PS_MODE_ACTIVE, 0, 0);
402
403                         if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
404                                 LPS_RF_ON_check23a(padapter,
405                                                    LPS_LEAVE_TIMEOUT_MS);
406                 }
407         }
408
409         pwrpriv->bpower_saving = false;
410 }
411
412 /*  Description: Leave all power save mode: LPS, FwLPS, IPS if needed. */
413 /*  Move code to function by tynli. 2010.03.26. */
414 void LeaveAllPowerSaveMode23a(struct rtw_adapter *Adapter)
415 {
416         struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
417         u8 enqueue = 0;
418
419         /* DBG_8723A("%s.....\n", __func__); */
420         if (check_fwstate(pmlmepriv, _FW_LINKED))
421                 rtw_lps_ctrl_wk_cmd23a(Adapter, LPS_CTRL_LEAVE, enqueue);
422 }
423
424 void rtw_init_pwrctrl_priv23a(struct rtw_adapter *padapter)
425 {
426         struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
427
428         sema_init(&pwrctrlpriv->lock, 1);
429         pwrctrlpriv->rf_pwrstate = rf_on;
430         pwrctrlpriv->ips_enter23a_cnts = 0;
431         pwrctrlpriv->ips_leave23a_cnts = 0;
432         pwrctrlpriv->bips_processing = false;
433
434         pwrctrlpriv->ips_mode = padapter->registrypriv.ips_mode;
435         pwrctrlpriv->ips_mode_req = padapter->registrypriv.ips_mode;
436
437         pwrctrlpriv->pwr_state_check_interval = RTW_PWR_STATE_CHK_INTERVAL;
438         pwrctrlpriv->pwr_state_check_cnts = 0;
439         pwrctrlpriv->bInSuspend = false;
440         pwrctrlpriv->bkeepfwalive = false;
441
442         pwrctrlpriv->LpsIdleCount = 0;
443
444         /*  PS_MODE_MIN; */
445         pwrctrlpriv->power_mgnt = padapter->registrypriv.power_mgnt;
446         pwrctrlpriv->bLeisurePs =
447                 (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt)?true:false;
448
449         pwrctrlpriv->bFwCurrentInPSMode = false;
450
451         pwrctrlpriv->rpwm = 0;
452         pwrctrlpriv->cpwm = PS_STATE_S4;
453
454         pwrctrlpriv->pwr_mode = PS_MODE_ACTIVE;
455         pwrctrlpriv->smart_ps = padapter->registrypriv.smart_ps;
456         pwrctrlpriv->bcn_ant_mode = 0;
457
458         pwrctrlpriv->tog = 0x80;
459
460         pwrctrlpriv->btcoex_rfon = false;
461
462         setup_timer(&pwrctrlpriv->pwr_state_check_timer,
463                     pwr_state_check_handler, (unsigned long)padapter);
464 }
465
466 void rtw_free_pwrctrl_priv(struct rtw_adapter *adapter)
467 {
468 }
469
470 inline void rtw_set_ips_deny23a(struct rtw_adapter *padapter, u32 ms)
471 {
472         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
473         pwrpriv->ips_deny_time = jiffies + msecs_to_jiffies(ms);
474 }
475
476 /*
477 * rtw_pwr_wakeup - Wake the NIC up from: 1)IPS. 2)USB autosuspend
478 * @adapter: pointer to _adapter structure
479 * @ips_deffer_ms: the ms will prevent from falling into IPS after wakeup
480 * Return _SUCCESS or _FAIL
481 */
482
483 int _rtw_pwr_wakeup23a(struct rtw_adapter *padapter, u32 ips_deffer_ms, const char *caller)
484 {
485         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
486         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
487         int ret = _SUCCESS;
488         unsigned long start = jiffies;
489         unsigned long new_deny_time;
490
491         new_deny_time = jiffies + msecs_to_jiffies(ips_deffer_ms);
492
493         if (time_before(pwrpriv->ips_deny_time, new_deny_time))
494                 pwrpriv->ips_deny_time = new_deny_time;
495
496         if (pwrpriv->ps_processing) {
497                 DBG_8723A("%s wait ps_processing...\n", __func__);
498                 while (pwrpriv->ps_processing &&
499                        jiffies_to_msecs(jiffies - start) <= 3000)
500                         msleep(10);
501                 if (pwrpriv->ps_processing)
502                         DBG_8723A("%s wait ps_processing timeout\n", __func__);
503                 else
504                         DBG_8723A("%s wait ps_processing done\n", __func__);
505         }
506
507         if (rtw_sreset_inprogress(padapter)) {
508                 DBG_8723A("%s wait sreset_inprogress...\n", __func__);
509                 while (rtw_sreset_inprogress(padapter) &&
510                        jiffies_to_msecs(jiffies - start) <= 4000)
511                         msleep(10);
512                 if (rtw_sreset_inprogress(padapter))
513                         DBG_8723A("%s wait sreset_inprogress timeout\n",
514                                   __func__);
515                 else
516                         DBG_8723A("%s wait sreset_inprogress done\n", __func__);
517         }
518
519         if (pwrpriv->bInSuspend) {
520                 DBG_8723A("%s wait bInSuspend...\n", __func__);
521                 while (pwrpriv->bInSuspend &&
522                        (jiffies_to_msecs(jiffies - start) <= 3000)) {
523                         msleep(10);
524                 }
525                 if (pwrpriv->bInSuspend)
526                         DBG_8723A("%s wait bInSuspend timeout\n", __func__);
527                 else
528                         DBG_8723A("%s wait bInSuspend done\n", __func__);
529         }
530
531         /* System suspend is not allowed to wakeup */
532         if (pwrpriv->bInSuspend) {
533                 ret = _FAIL;
534                 goto exit;
535         }
536
537         /* I think this should be check in IPS, LPS, autosuspend functions... */
538         if (check_fwstate(pmlmepriv, _FW_LINKED)) {
539                 ret = _SUCCESS;
540                 goto exit;
541         }
542
543         if (rf_off == pwrpriv->rf_pwrstate) {
544                 DBG_8723A("%s call ips_leave23a....\n", __func__);
545                 if (ips_leave23a(padapter)== _FAIL) {
546                         DBG_8723A("======> ips_leave23a fail.............\n");
547                         ret = _FAIL;
548                         goto exit;
549                 }
550         }
551
552         /* TODO: the following checking need to be merged... */
553         if (padapter->bDriverStopped || !padapter->bup ||
554             !padapter->hw_init_completed) {
555                 DBG_8723A("%s: bDriverStopped =%d, bup =%d, hw_init_completed "
556                           "=%u\n", caller, padapter->bDriverStopped,
557                           padapter->bup, padapter->hw_init_completed);
558                 ret = _FAIL;
559                 goto exit;
560         }
561
562 exit:
563         new_deny_time = jiffies + msecs_to_jiffies(ips_deffer_ms);
564         if (time_before(pwrpriv->ips_deny_time, new_deny_time))
565                 pwrpriv->ips_deny_time = new_deny_time;
566         return ret;
567 }
568
569 int rtw_pm_set_lps23a(struct rtw_adapter *padapter, u8 mode)
570 {
571         int ret = 0;
572         struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
573
574         if (mode < PS_MODE_NUM) {
575                 if (pwrctrlpriv->power_mgnt != mode) {
576                         if (PS_MODE_ACTIVE == mode)
577                                 LeaveAllPowerSaveMode23a(padapter);
578                         else
579                                 pwrctrlpriv->LpsIdleCount = 2;
580                         pwrctrlpriv->power_mgnt = mode;
581                         pwrctrlpriv->bLeisurePs =
582                                 (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt) ?
583                                 true:false;
584                 }
585         } else
586                 ret = -EINVAL;
587
588         return ret;
589 }
590
591 int rtw_pm_set_ips23a(struct rtw_adapter *padapter, u8 mode)
592 {
593         struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
594
595         if (mode != IPS_NORMAL && mode != IPS_LEVEL_2 && mode != IPS_NONE)
596                 return -EINVAL;
597
598         pwrctrlpriv->ips_mode_req = mode;
599         if (mode == IPS_NONE) {
600                 DBG_8723A("%s %s\n", __func__, "IPS_NONE");
601                 if (padapter->bSurpriseRemoved == 0 &&
602                     rtw_pwr_wakeup(padapter) == _FAIL)
603                         return -EFAULT;
604         }
605
606         return 0;
607 }