Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / 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))
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 }
176
177 static void pwr_state_check_handler(unsigned long data)
178 {
179         struct rtw_adapter *padapter = (struct rtw_adapter *)data;
180
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 than S2 when DriverStopped!!\n",
230                                  __func__, pslv);
231                         return;
232                 }
233         }
234
235         rpwm = pslv | pwrpriv->tog;
236         RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
237                  "rtw_set_rpwm23a: rpwm = 0x%02x cpwm = 0x%02x\n",
238                  rpwm, pwrpriv->cpwm);
239
240         pwrpriv->rpwm = pslv;
241
242         rtl8723a_set_rpwm(padapter, rpwm);
243
244         pwrpriv->tog += 0x80;
245         pwrpriv->cpwm = pslv;
246 }
247
248 static bool PS_RDY_CHECK(struct rtw_adapter *padapter)
249 {
250         unsigned long delta_time;
251         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
252         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
253
254         delta_time = jiffies - pwrpriv->DelayLPSLastTimeStamp;
255
256         if (delta_time < LPS_DELAY_TIME)
257                 return false;
258
259         if (!check_fwstate(pmlmepriv, _FW_LINKED) ||
260             check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) ||
261             check_fwstate(pmlmepriv, WIFI_AP_STATE) ||
262             check_fwstate(pmlmepriv, WIFI_ADHOC_MASTER_STATE) ||
263             check_fwstate(pmlmepriv, WIFI_ADHOC_STATE))
264                 return false;
265         if (pwrpriv->bInSuspend)
266                 return false;
267         if (padapter->securitypriv.dot11AuthAlgrthm == dot11AuthAlgrthm_8021X &&
268             !padapter->securitypriv.binstallGrpkey) {
269                 DBG_8723A("Group handshake still in progress !!!\n");
270                 return false;
271         }
272         if (!rtw_cfg80211_pwr_mgmt(padapter))
273                 return false;
274
275         return true;
276 }
277
278 void rtw_set_ps_mode23a(struct rtw_adapter *padapter, u8 ps_mode,
279                         u8 smart_ps, u8 bcn_ant_mode)
280 {
281         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
282
283         RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_notice_,
284                  "%s: PowerMode =%d Smart_PS =%d\n",
285                  __func__, ps_mode, smart_ps);
286
287         if (ps_mode > PM_Card_Disable) {
288                 RT_TRACE(_module_rtl871x_pwrctrl_c_, _drv_err_,
289                          "ps_mode:%d error\n", ps_mode);
290                 return;
291         }
292
293         if (pwrpriv->pwr_mode == ps_mode) {
294                 if (PS_MODE_ACTIVE == ps_mode)
295                         return;
296
297                 if (pwrpriv->smart_ps == smart_ps &&
298                     pwrpriv->bcn_ant_mode == bcn_ant_mode)
299                         return;
300         }
301
302         if (ps_mode == PS_MODE_ACTIVE) {
303                 DBG_8723A("rtw_set_ps_mode23a: Leave 802.11 power save\n");
304
305                 pwrpriv->pwr_mode = ps_mode;
306                 rtw_set_rpwm23a(padapter, PS_STATE_S4);
307                 rtl8723a_set_FwPwrMode_cmd(padapter, ps_mode);
308                 pwrpriv->bFwCurrentInPSMode = false;
309         } else {
310                 if (PS_RDY_CHECK(padapter) ||
311                     rtl8723a_BT_using_antenna_1(padapter)) {
312                         DBG_8723A("%s: Enter 802.11 power save\n", __func__);
313
314                         pwrpriv->bFwCurrentInPSMode = true;
315                         pwrpriv->pwr_mode = ps_mode;
316                         pwrpriv->smart_ps = smart_ps;
317                         pwrpriv->bcn_ant_mode = bcn_ant_mode;
318                         rtl8723a_set_FwPwrMode_cmd(padapter, ps_mode);
319
320                         rtw_set_rpwm23a(padapter, PS_STATE_S2);
321                 }
322         }
323 }
324
325 /*
326  * Return:
327  *      0:      Leave OK
328  *      -1:     Timeout
329  *      -2:     Other error
330  */
331 s32 LPS_RF_ON_check23a(struct rtw_adapter *padapter, u32 delay_ms)
332 {
333         unsigned long start_time, end_time;
334         u8 bAwake = false;
335         s32 err = 0;
336
337         start_time = jiffies;
338         end_time = start_time + msecs_to_jiffies(delay_ms);
339
340         while (1) {
341                 bAwake = rtl8723a_get_fwlps_rf_on(padapter);
342                 if (bAwake == true)
343                         break;
344
345                 if (padapter->bSurpriseRemoved == true) {
346                         err = -2;
347                         DBG_8723A("%s: device surprise removed!!\n", __func__);
348                         break;
349                 }
350
351                 if (time_after(jiffies, end_time)) {
352                         err = -1;
353                         DBG_8723A("%s: Wait for FW LPS leave more than %u "
354                                   "ms!\n", __func__, delay_ms);
355                         break;
356                 }
357                 udelay(100);
358         }
359
360         return err;
361 }
362
363 /*      Description: */
364 /*              Enter the leisure power save mode. */
365 void LPS_Enter23a(struct rtw_adapter *padapter)
366 {
367         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
368
369         if (!PS_RDY_CHECK(padapter))
370                 return;
371
372         if (pwrpriv->bLeisurePs) {
373                 /*  Idle for a while if we connect to AP a while ago. */
374                 if (pwrpriv->LpsIdleCount >= 2) { /*   4 Sec */
375                         if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) {
376                                 pwrpriv->bpower_saving = true;
377                                 DBG_8723A("%s smart_ps:%d\n", __func__,
378                                           pwrpriv->smart_ps);
379                                 /* For Tenda W311R IOT issue */
380                                 rtw_set_ps_mode23a(padapter,
381                                                    pwrpriv->power_mgnt,
382                                                    pwrpriv->smart_ps, 0);
383                         }
384                 } else
385                         pwrpriv->LpsIdleCount++;
386         }
387 }
388
389 /*      Description: */
390 /*              Leave the leisure power save mode. */
391 void LPS_Leave23a(struct rtw_adapter *padapter)
392 {
393 #define LPS_LEAVE_TIMEOUT_MS 100
394
395         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
396
397         if (pwrpriv->bLeisurePs) {
398                 if (pwrpriv->pwr_mode != PS_MODE_ACTIVE) {
399                         rtw_set_ps_mode23a(padapter, PS_MODE_ACTIVE, 0, 0);
400
401                         if (pwrpriv->pwr_mode == PS_MODE_ACTIVE)
402                                 LPS_RF_ON_check23a(padapter,
403                                                    LPS_LEAVE_TIMEOUT_MS);
404                 }
405         }
406
407         pwrpriv->bpower_saving = false;
408 }
409
410 /*  Description: Leave all power save mode: LPS, FwLPS, IPS if needed. */
411 /*  Move code to function by tynli. 2010.03.26. */
412 void LeaveAllPowerSaveMode23a(struct rtw_adapter *Adapter)
413 {
414         struct mlme_priv *pmlmepriv = &Adapter->mlmepriv;
415         u8 enqueue = 0;
416
417         /* DBG_8723A("%s.....\n", __func__); */
418         if (check_fwstate(pmlmepriv, _FW_LINKED))
419                 rtw_lps_ctrl_wk_cmd23a(Adapter, LPS_CTRL_LEAVE, enqueue);
420 }
421
422 void rtw_init_pwrctrl_priv23a(struct rtw_adapter *padapter)
423 {
424         struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
425
426         sema_init(&pwrctrlpriv->lock, 1);
427         pwrctrlpriv->rf_pwrstate = rf_on;
428         pwrctrlpriv->ips_enter23a_cnts = 0;
429         pwrctrlpriv->ips_leave23a_cnts = 0;
430         pwrctrlpriv->bips_processing = false;
431
432         pwrctrlpriv->ips_mode = padapter->registrypriv.ips_mode;
433         pwrctrlpriv->ips_mode_req = padapter->registrypriv.ips_mode;
434
435         pwrctrlpriv->pwr_state_check_interval = RTW_PWR_STATE_CHK_INTERVAL;
436         pwrctrlpriv->pwr_state_check_cnts = 0;
437         pwrctrlpriv->bInSuspend = false;
438         pwrctrlpriv->bkeepfwalive = false;
439
440         pwrctrlpriv->LpsIdleCount = 0;
441
442         /*  PS_MODE_MIN; */
443         pwrctrlpriv->power_mgnt = padapter->registrypriv.power_mgnt;
444         pwrctrlpriv->bLeisurePs =
445                 (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt)?true:false;
446
447         pwrctrlpriv->bFwCurrentInPSMode = false;
448
449         pwrctrlpriv->rpwm = 0;
450         pwrctrlpriv->cpwm = PS_STATE_S4;
451
452         pwrctrlpriv->pwr_mode = PS_MODE_ACTIVE;
453         pwrctrlpriv->smart_ps = padapter->registrypriv.smart_ps;
454         pwrctrlpriv->bcn_ant_mode = 0;
455
456         pwrctrlpriv->tog = 0x80;
457
458         pwrctrlpriv->btcoex_rfon = false;
459
460         setup_timer(&pwrctrlpriv->pwr_state_check_timer,
461                     pwr_state_check_handler, (unsigned long)padapter);
462 }
463
464 void rtw_free_pwrctrl_priv(struct rtw_adapter *adapter)
465 {
466 }
467
468 inline void rtw_set_ips_deny23a(struct rtw_adapter *padapter, u32 ms)
469 {
470         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
471
472         pwrpriv->ips_deny_time = jiffies + msecs_to_jiffies(ms);
473 }
474
475 /*
476 * rtw_pwr_wakeup - Wake the NIC up from: 1)IPS. 2)USB autosuspend
477 * @adapter: pointer to _adapter structure
478 * @ips_deffer_ms: the ms will prevent from falling into IPS after wakeup
479 * Return _SUCCESS or _FAIL
480 */
481
482 int _rtw_pwr_wakeup23a(struct rtw_adapter *padapter, u32 ips_deffer_ms, const char *caller)
483 {
484         struct pwrctrl_priv *pwrpriv = &padapter->pwrctrlpriv;
485         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
486         int ret = _SUCCESS;
487         unsigned long start = jiffies;
488         unsigned long new_deny_time;
489
490         new_deny_time = jiffies + msecs_to_jiffies(ips_deffer_ms);
491
492         if (time_before(pwrpriv->ips_deny_time, new_deny_time))
493                 pwrpriv->ips_deny_time = new_deny_time;
494
495         if (pwrpriv->ps_processing) {
496                 DBG_8723A("%s wait ps_processing...\n", __func__);
497                 while (pwrpriv->ps_processing &&
498                        jiffies_to_msecs(jiffies - start) <= 3000)
499                         msleep(10);
500                 if (pwrpriv->ps_processing)
501                         DBG_8723A("%s wait ps_processing timeout\n", __func__);
502                 else
503                         DBG_8723A("%s wait ps_processing done\n", __func__);
504         }
505
506         if (rtw_sreset_inprogress(padapter)) {
507                 DBG_8723A("%s wait sreset_inprogress...\n", __func__);
508                 while (rtw_sreset_inprogress(padapter) &&
509                        jiffies_to_msecs(jiffies - start) <= 4000)
510                         msleep(10);
511                 if (rtw_sreset_inprogress(padapter))
512                         DBG_8723A("%s wait sreset_inprogress timeout\n",
513                                   __func__);
514                 else
515                         DBG_8723A("%s wait sreset_inprogress done\n", __func__);
516         }
517
518         if (pwrpriv->bInSuspend) {
519                 DBG_8723A("%s wait bInSuspend...\n", __func__);
520                 while (pwrpriv->bInSuspend &&
521                        (jiffies_to_msecs(jiffies - start) <= 3000)) {
522                         msleep(10);
523                 }
524                 if (pwrpriv->bInSuspend)
525                         DBG_8723A("%s wait bInSuspend timeout\n", __func__);
526                 else
527                         DBG_8723A("%s wait bInSuspend done\n", __func__);
528         }
529
530         /* System suspend is not allowed to wakeup */
531         if (pwrpriv->bInSuspend) {
532                 ret = _FAIL;
533                 goto exit;
534         }
535
536         /* I think this should be check in IPS, LPS, autosuspend functions... */
537         if (check_fwstate(pmlmepriv, _FW_LINKED)) {
538                 ret = _SUCCESS;
539                 goto exit;
540         }
541
542         if (rf_off == pwrpriv->rf_pwrstate) {
543                 DBG_8723A("%s call ips_leave23a....\n", __func__);
544                 if (ips_leave23a(padapter)== _FAIL) {
545                         DBG_8723A("======> ips_leave23a fail.............\n");
546                         ret = _FAIL;
547                         goto exit;
548                 }
549         }
550
551         /* TODO: the following checking need to be merged... */
552         if (padapter->bDriverStopped || !padapter->bup ||
553             !padapter->hw_init_completed) {
554                 DBG_8723A("%s: bDriverStopped =%d, bup =%d, hw_init_completed "
555                           "=%u\n", caller, padapter->bDriverStopped,
556                           padapter->bup, padapter->hw_init_completed);
557                 ret = _FAIL;
558                 goto exit;
559         }
560
561 exit:
562         new_deny_time = jiffies + msecs_to_jiffies(ips_deffer_ms);
563         if (time_before(pwrpriv->ips_deny_time, new_deny_time))
564                 pwrpriv->ips_deny_time = new_deny_time;
565         return ret;
566 }
567
568 int rtw_pm_set_lps23a(struct rtw_adapter *padapter, u8 mode)
569 {
570         int ret = 0;
571         struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
572
573         if (mode < PS_MODE_NUM) {
574                 if (pwrctrlpriv->power_mgnt != mode) {
575                         if (PS_MODE_ACTIVE == mode)
576                                 LeaveAllPowerSaveMode23a(padapter);
577                         else
578                                 pwrctrlpriv->LpsIdleCount = 2;
579                         pwrctrlpriv->power_mgnt = mode;
580                         pwrctrlpriv->bLeisurePs =
581                                 (PS_MODE_ACTIVE != pwrctrlpriv->power_mgnt) ?
582                                 true:false;
583                 }
584         } else
585                 ret = -EINVAL;
586
587         return ret;
588 }
589
590 int rtw_pm_set_ips23a(struct rtw_adapter *padapter, u8 mode)
591 {
592         struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
593
594         if (mode != IPS_NORMAL && mode != IPS_LEVEL_2 && mode != IPS_NONE)
595                 return -EINVAL;
596
597         pwrctrlpriv->ips_mode_req = mode;
598         if (mode == IPS_NONE) {
599                 DBG_8723A("%s %s\n", __func__, "IPS_NONE");
600                 if (padapter->bSurpriseRemoved == 0 &&
601                     rtw_pwr_wakeup(padapter) == _FAIL)
602                         return -EFAULT;
603         }
604
605         return 0;
606 }