1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
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.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
20 #ifndef __RTW_PWRCTRL_H_
21 #define __RTW_PWRCTRL_H_
39 #define XMIT_ALIVE BIT(0)
40 #define RECV_ALIVE BIT(1)
41 #define CMD_ALIVE BIT(2)
42 #define EVT_ALIVE BIT(3)
43 #ifdef CONFIG_BT_COEXIST
44 #define BTCOEX_ALIVE BIT(4)
45 #endif /* CONFIG_BT_COEXIST */
48 #ifdef CONFIG_DEFAULT_PATTERNS_EN
49 #ifdef CONFIG_PLATFORM_ANDROID_INTEL_X86
50 /* TCP/ICMP/UDP multicast with specific IP addr */
51 #define DEFAULT_PATTERN_NUM 3
54 #define DEFAULT_PATTERN_NUM 2
57 #define DEFAULT_PATTERN_NUM 0
58 #endif /*CONFIG_DEFAULT_PATTERNS_EN*/
60 #define MAX_WKFM_NUM 16 /* Frame Mask Cam number for pattern match */
61 #define MAX_WKFM_SIZE 16 /* (16 bytes for WKFM bit mask, 16*8 = 128 bits) */
62 #define MAX_WKFM_PATTERN_SIZE 128
63 #define WKFMCAM_ADDR_NUM 6
64 #define WKFMCAM_SIZE 24 /* each entry need 6*4 bytes */
66 PATTERN_BROADCAST = 0,
73 typedef struct rtl_priv_pattern {
75 char content[MAX_WKFM_PATTERN_SIZE];
76 char mask[MAX_WKFM_SIZE];
79 struct rtl_wow_pattern {
87 u8 replay_counter_eapol_key[8];
92 #endif /* CONFIG_WOWLAN */
98 PS_MODE_DTIM , /* PS_MODE_SELF_DEFINED */
109 #ifdef CONFIG_PNO_SUPPORT
110 #define MAX_PNO_LIST_COUNT 16
111 #define MAX_SCAN_LIST_COUNT 14 /* 2.4G only */
112 #define MAX_HIDDEN_AP 8 /* 8 hidden AP */
117 BIT[3] = Protocol PS state, 0: register active state , 1: register sleep state
121 #define PS_DPS BIT(0)
122 #define PS_LCLK (PS_DPS)
123 #define PS_RF_OFF BIT(1)
124 #define PS_ALL_ON BIT(2)
125 #define PS_ST_ACTIVE BIT(3)
127 #define PS_ISR_ENABLE BIT(4)
128 #define PS_IMR_ENABLE BIT(5)
129 #define PS_ACK BIT(6)
130 #define PS_TOGGLE BIT(7)
132 #define PS_STATE_MASK (0x0F)
133 #define PS_STATE_HW_MASK (0x07)
134 #define PS_SEQ_MASK (0xc0)
136 #define PS_STATE(x) (PS_STATE_MASK & (x))
137 #define PS_STATE_HW(x) (PS_STATE_HW_MASK & (x))
138 #define PS_SEQ(x) (PS_SEQ_MASK & (x))
140 #define PS_STATE_S0 (PS_DPS)
141 #define PS_STATE_S1 (PS_LCLK)
142 #define PS_STATE_S2 (PS_RF_OFF)
143 #define PS_STATE_S3 (PS_ALL_ON)
144 #define PS_STATE_S4 ((PS_ST_ACTIVE) | (PS_ALL_ON))
147 #define PS_IS_RF_ON(x) ((x) & (PS_ALL_ON))
148 #define PS_IS_ACTIVE(x) ((x) & (PS_ST_ACTIVE))
149 #define CLR_PS_STATE(x) ((x) = ((x) & (0xF0)))
152 struct reportpwrstate_parm {
154 unsigned char state; /* the CPWM value */
159 typedef _sema _pwrlock;
162 __inline static void _init_pwrlock(_pwrlock *plock)
164 _rtw_init_sema(plock, 1);
167 __inline static void _free_pwrlock(_pwrlock *plock)
169 _rtw_free_sema(plock);
173 __inline static void _enter_pwrlock(_pwrlock *plock)
175 _rtw_down_sema(plock);
179 __inline static void _exit_pwrlock(_pwrlock *plock)
184 #define LPS_DELAY_TIME 1*HZ /* 1 sec */
186 #define EXE_PWR_NONE 0x01
187 #define EXE_PWR_IPS 0x02
188 #define EXE_PWR_LPS 0x04
191 typedef enum _rt_rf_power_state {
192 rf_on, /* RF is on after RFSleep or RFOff */
193 rf_sleep, /* 802.11 Power Save mode */
194 rf_off, /* HW/SW Radio OFF or Inactive Power Save */
195 /* =====Add the new RF state above this line===== */
199 /* RF Off Level for IPS or HW/SW radio off */
200 #define RT_RF_OFF_LEVL_ASPM BIT(0) /* PCI ASPM */
201 #define RT_RF_OFF_LEVL_CLK_REQ BIT(1) /* PCI clock request */
202 #define RT_RF_OFF_LEVL_PCI_D3 BIT(2) /* PCI D3 mode */
203 #define RT_RF_OFF_LEVL_HALT_NIC BIT(3) /* NIC halt, re-initialize hw parameters */
204 #define RT_RF_OFF_LEVL_FREE_FW BIT(4) /* FW free, re-download the FW */
205 #define RT_RF_OFF_LEVL_FW_32K BIT(5) /* FW in 32k */
206 #define RT_RF_PS_LEVEL_ALWAYS_ASPM BIT(6) /* Always enable ASPM and Clock Req in initialization. */
207 #define RT_RF_LPS_DISALBE_2R BIT(30) /* When LPS is on, disable 2R if no packet is received or transmittd. */
208 #define RT_RF_LPS_LEVEL_ASPM BIT(31) /* LPS with ASPM */
210 #define RT_IN_PS_LEVEL(ppsc, _PS_FLAG) ((ppsc->cur_ps_level & _PS_FLAG) ? _TRUE : _FALSE)
211 #define RT_CLEAR_PS_LEVEL(ppsc, _PS_FLAG) (ppsc->cur_ps_level &= (~(_PS_FLAG)))
212 #define RT_SET_PS_LEVEL(ppsc, _PS_FLAG) (ppsc->cur_ps_level |= _PS_FLAG)
214 /* ASPM OSC Control bit, added by Roger, 2013.03.29. */
215 #define RT_PCI_ASPM_OSC_IGNORE 0 /* PCI ASPM ignore OSC control in default */
216 #define RT_PCI_ASPM_OSC_ENABLE BIT0 /* PCI ASPM controlled by OS according to ACPI Spec 5.0 */
217 #define RT_PCI_ASPM_OSC_DISABLE BIT1 /* PCI ASPM controlled by driver or BIOS, i.e., force enable ASPM */
220 enum _PS_BBRegBackup_ {
228 enum { /* for ips_mode */
235 /* Design for pwrctrl_priv.ips_deny, 32 bits for 32 reasons at most */
236 typedef enum _PS_DENY_REASON {
237 PS_DENY_DRV_INITIAL = 0,
244 PS_DENY_DRV_REMOVE = 30,
248 #ifdef CONFIG_PNO_SUPPORT
249 typedef struct pno_nlo_info {
250 u32 fast_scan_period; /* Fast scan period */
251 u8 ssid_num; /* number of entry */
253 u32 slow_scan_period; /* slow scan period */
254 u32 fast_scan_iterations; /* Fast scan iterations */
255 u8 ssid_length[MAX_PNO_LIST_COUNT]; /* SSID Length Array */
256 u8 ssid_cipher_info[MAX_PNO_LIST_COUNT]; /* Cipher information for security */
257 u8 ssid_channel_info[MAX_PNO_LIST_COUNT]; /* channel information */
258 u8 loc_probe_req[MAX_HIDDEN_AP]; /* loc_probeReq */
261 typedef struct pno_ssid {
266 typedef struct pno_ssid_list {
267 pno_ssid_t node[MAX_PNO_LIST_COUNT];
270 typedef struct pno_scan_channel_info {
274 u8 active; /* set 1 means active scan, or pasivite scan. */
275 } pno_scan_channel_info_t;
277 typedef struct pno_scan_info {
278 u8 enableRFE; /* Enable RFE */
279 u8 period_scan_time; /* exclusive with fast_scan_period and slow_scan_period */
280 u8 periodScan; /* exclusive with fast_scan_period and slow_scan_period */
281 u8 orig_80_offset; /* original channel 80 offset */
282 u8 orig_40_offset; /* original channel 40 offset */
283 u8 orig_bw; /* original bandwidth */
284 u8 orig_ch; /* original channel */
285 u8 channel_num; /* number of channel */
286 u64 rfe_type; /* rfe_type && 0x00000000000000ff */
287 pno_scan_channel_info_t ssid_channel_info[MAX_SCAN_LIST_COUNT];
289 #endif /* CONFIG_PNO_SUPPORT */
291 #ifdef CONFIG_LPS_POFF
292 /* Driver context for LPS 32K Close IO Power */
293 typedef struct lps_poff_info {
303 ATOMIC_T bTxBoundInProgress;
304 ATOMIC_T bSetPOFFParm;
306 #endif /*CONFIG_LPS_POFF*/
308 struct pwrctrl_priv {
310 _pwrlock check_32k_lock;
311 volatile u8 rpwm; /* requested power state for fw */
312 volatile u8 cpwm; /* fw current power state. updated when 1. read from HCPWM 2. driver lowers power level */
313 volatile u8 tog; /* toggling */
314 volatile u8 cpwm_tog; /* toggling */
322 _workitem cpwm_event;
323 #ifdef CONFIG_LPS_RPWM_TIMER
325 _workitem rpwmtimeoutwi;
326 _timer pwr_rpwm_timer;
327 #endif /* CONFIG_LPS_RPWM_TIMER */
328 u8 bpower_saving; /* for LPS/IPS */
332 u8 reg_pdnmode; /* powerdown mode */
346 u8 ips_mode_req; /* used to accept the mode setting request, will update to ipsmode later */
347 uint bips_processing;
348 u32 ips_deny_time; /* will deny IPS when system time is smaller than this */
349 u8 pre_ips_type;/* 0: default flow, 1: carddisbale flow */
351 /* ps_deny: if 0, power save is free to go; otherwise deny all kinds of power save. */
352 /* Use PS_DENY_REASON to decide reason. */
353 /* Don't access this variable directly without control function, */
354 /* and this variable should be protected by lock. */
357 u8 ps_processing; /* temporarily used to mark whether in rtw_ps_processor */
359 u8 fw_psmode_iface_id;
364 u8 bFwCurrentInPSMode;
365 u32 DelayLPSLastTimeStamp;
366 s32 pnp_current_pwr_state;
370 u8 bInternalAutoSuspend;
372 #ifdef CONFIG_BT_COEXIST
376 u8 bSupportRemoteWakeup;
377 u8 wowlan_wake_reason;
378 u8 wowlan_last_wake_reason;
382 u8 wowlan_pno_enable;
383 #ifdef CONFIG_GPIO_WAKEUP
385 #endif /* CONFIG_GPIO_WAKEUP */
387 u8 wowlan_txpause_status;
388 u8 wowlan_pattern_idx;
391 struct rtl_priv_pattern patterns[MAX_WKFM_NUM];
392 struct aoac_report wowlan_aoac_rpt;
393 u8 wowlan_aoac_rpt_loc;
394 #ifdef CONFIG_PNO_SUPPORT
396 pno_nlo_info_t *pnlo_info;
397 pno_scan_info_t *pscan_info;
398 pno_ssid_list_t *pno_ssid_list;
399 #endif /* CONFIG_PNO_SUPPORT */
400 #endif /* CONFIG_WOWLAN */
401 _timer pwr_state_check_timer;
402 int pwr_state_check_interval;
403 u8 pwr_state_check_cnts;
405 int ps_flag; /* used by autosuspend */
407 rt_rf_power_state rf_pwrstate;/* cur power state, only for IPS */
408 /* rt_rf_power_state current_rfpwrstate; */
409 rt_rf_power_state change_rfpwrstate;
411 u8 bHWPowerdown; /* power down mode selection. 0:radio off, 1:power down */
412 u8 bHWPwrPindetect; /* come from registrypriv.hwpwrp_detect. enable power down function. 0:disable, 1:enable */
415 unsigned long PS_BBRegBackup[PSBBREG_TOTALCNT];
417 #ifdef CONFIG_RESUME_IN_WORKQUEUE
418 struct workqueue_struct *rtw_workqueue;
419 _workitem resume_work;
422 #ifdef CONFIG_HAS_EARLYSUSPEND
423 struct early_suspend early_suspend;
425 #endif /* CONFIG_HAS_EARLYSUSPEND */
427 #ifdef CONFIG_ANDROID_POWER
428 android_early_suspend_t early_suspend;
432 #ifdef CONFIG_INTEL_PROXIM
433 u8 stored_power_mgnt;
436 #ifdef CONFIG_LPS_POFF
437 lps_poff_info_t *plps_poff_info;
441 u8 lpspg_rsvd_page_locate;
446 #define rtw_get_ips_mode_req(pwrctl) \
447 (pwrctl)->ips_mode_req
449 #define rtw_ips_mode_req(pwrctl, ips_mode) \
450 (pwrctl)->ips_mode_req = (ips_mode)
452 #define RTW_PWR_STATE_CHK_INTERVAL 2000
454 #define _rtw_set_pwr_state_check_timer(pwrctl, ms) \
456 /*RTW_INFO("%s _rtw_set_pwr_state_check_timer(%p, %d)\n", __FUNCTION__, (pwrctl), (ms));*/ \
457 _set_timer(&(pwrctl)->pwr_state_check_timer, (ms)); \
460 #define rtw_set_pwr_state_check_timer(pwrctl) \
461 _rtw_set_pwr_state_check_timer((pwrctl), (pwrctl)->pwr_state_check_interval)
463 extern void rtw_init_pwrctrl_priv(_adapter *adapter);
464 extern void rtw_free_pwrctrl_priv(_adapter *adapter);
466 #ifdef CONFIG_LPS_LCLK
467 s32 rtw_register_task_alive(PADAPTER, u32 task);
468 void rtw_unregister_task_alive(PADAPTER, u32 task);
469 extern s32 rtw_register_tx_alive(PADAPTER padapter);
470 extern void rtw_unregister_tx_alive(PADAPTER padapter);
471 extern s32 rtw_register_rx_alive(PADAPTER padapter);
472 extern void rtw_unregister_rx_alive(PADAPTER padapter);
473 extern s32 rtw_register_cmd_alive(PADAPTER padapter);
474 extern void rtw_unregister_cmd_alive(PADAPTER padapter);
475 extern s32 rtw_register_evt_alive(PADAPTER padapter);
476 extern void rtw_unregister_evt_alive(PADAPTER padapter);
477 extern void cpwm_int_hdl(PADAPTER padapter, struct reportpwrstate_parm *preportpwrstate);
478 extern void LPS_Leave_check(PADAPTER padapter);
481 extern void LeaveAllPowerSaveMode(PADAPTER Adapter);
482 extern void LeaveAllPowerSaveModeDirect(PADAPTER Adapter);
484 void _ips_enter(_adapter *padapter);
485 void ips_enter(_adapter *padapter);
486 int _ips_leave(_adapter *padapter);
487 int ips_leave(_adapter *padapter);
490 void rtw_ps_processor(_adapter *padapter);
492 #ifdef CONFIG_AUTOSUSPEND
493 int autoresume_enter(_adapter *padapter);
495 #ifdef SUPPORT_HW_RFOFF_DETECTED
496 rt_rf_power_state RfOnOffDetect(IN PADAPTER pAdapter);
500 int rtw_fw_ps_state(PADAPTER padapter);
503 s32 LPS_RF_ON_check(PADAPTER padapter, u32 delay_ms);
504 void LPS_Enter(PADAPTER padapter, const char *msg);
505 void LPS_Leave(PADAPTER padapter, const char *msg);
506 void traffic_check_for_leave_lps(PADAPTER padapter, u8 tx, u32 tx_packets);
507 void rtw_set_ps_mode(PADAPTER padapter, u8 ps_mode, u8 smart_ps, u8 bcn_ant_mode, const char *msg);
508 void rtw_set_fw_in_ips_mode(PADAPTER padapter, u8 enable);
509 void rtw_set_rpwm(_adapter *padapter, u8 val8);
512 #ifdef CONFIG_RESUME_IN_WORKQUEUE
513 void rtw_resume_in_workqueue(struct pwrctrl_priv *pwrpriv);
514 #endif /* CONFIG_RESUME_IN_WORKQUEUE */
516 #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
517 bool rtw_is_earlysuspend_registered(struct pwrctrl_priv *pwrpriv);
518 bool rtw_is_do_late_resume(struct pwrctrl_priv *pwrpriv);
519 void rtw_set_do_late_resume(struct pwrctrl_priv *pwrpriv, bool enable);
520 void rtw_register_early_suspend(struct pwrctrl_priv *pwrpriv);
521 void rtw_unregister_early_suspend(struct pwrctrl_priv *pwrpriv);
523 #define rtw_is_earlysuspend_registered(pwrpriv) _FALSE
524 #define rtw_is_do_late_resume(pwrpriv) _FALSE
525 #define rtw_set_do_late_resume(pwrpriv, enable) do {} while (0)
526 #define rtw_register_early_suspend(pwrpriv) do {} while (0)
527 #define rtw_unregister_early_suspend(pwrpriv) do {} while (0)
528 #endif /* CONFIG_HAS_EARLYSUSPEND || CONFIG_ANDROID_POWER */
530 u8 rtw_interface_ps_func(_adapter *padapter, HAL_INTF_PS_FUNC efunc_id, u8 *val);
531 void rtw_set_ips_deny(_adapter *padapter, u32 ms);
532 int _rtw_pwr_wakeup(_adapter *padapter, u32 ips_deffer_ms, const char *caller);
533 #define rtw_pwr_wakeup(adapter) _rtw_pwr_wakeup(adapter, RTW_PWR_STATE_CHK_INTERVAL, __FUNCTION__)
534 #define rtw_pwr_wakeup_ex(adapter, ips_deffer_ms) _rtw_pwr_wakeup(adapter, ips_deffer_ms, __FUNCTION__)
535 int rtw_pm_set_ips(_adapter *padapter, u8 mode);
536 int rtw_pm_set_lps(_adapter *padapter, u8 mode);
538 void rtw_ps_deny(PADAPTER padapter, PS_DENY_REASON reason);
539 void rtw_ps_deny_cancel(PADAPTER padapter, PS_DENY_REASON reason);
540 u32 rtw_ps_deny_get(PADAPTER padapter);
542 #if defined(CONFIG_WOWLAN)
543 void rtw_get_current_ip_address(PADAPTER padapter, u8 *pcurrentip);
544 void rtw_get_sec_iv(PADAPTER padapter, u8 *pcur_dot11txpn, u8 *StaAddr);
545 bool rtw_check_pattern_valid(u8 *input, u8 len);
546 bool rtw_write_to_frame_mask(_adapter *adapter, u8 idx,
547 struct rtl_wow_pattern *content);
549 bool rtw_read_from_frame_mask(_adapter *adapter, u8 idx);
550 bool rtw_wowlan_parser_pattern_cmd(u8 *input, char *pattern,
551 int *pattern_len, char *bit_mask);
552 u8 rtw_set_default_pattern(_adapter *adapter);
553 void rtw_dump_priv_pattern(_adapter *adapter, u8 idx);
554 void rtw_clean_pattern(_adapter *adapter);
555 #endif /* CONFIG_WOWLAN */
556 #endif /* __RTL871X_PWRCTRL_H_ */