1 
   2 
   3 
   4 
   5 
   6 
   7 #ifndef __RTW_PWRCTRL_H_
   8 #define __RTW_PWRCTRL_H_
   9 
  10 #include <linux/mutex.h>
  11 
  12 #define FW_PWR0 0
  13 #define FW_PWR1         1
  14 #define FW_PWR2         2
  15 #define FW_PWR3         3
  16 
  17 
  18 #define HW_PWR0 7
  19 #define HW_PWR1         6
  20 #define HW_PWR2         2
  21 #define HW_PWR3 0
  22 #define HW_PWR4 8
  23 
  24 #define FW_PWRMSK       0x7
  25 
  26 
  27 #define XMIT_ALIVE      BIT(0)
  28 #define RECV_ALIVE      BIT(1)
  29 #define CMD_ALIVE       BIT(2)
  30 #define EVT_ALIVE       BIT(3)
  31 #define BTCOEX_ALIVE    BIT(4)
  32 
  33 
  34 enum Power_Mgnt {
  35         PS_MODE_ACTIVE  = 0,
  36         PS_MODE_MIN,
  37         PS_MODE_MAX,
  38         PS_MODE_DTIM,   
  39         PS_MODE_VOIP,
  40         PS_MODE_UAPSD_WMM,
  41         PS_MODE_UAPSD,
  42         PS_MODE_IBSS,
  43         PS_MODE_WWLAN,
  44         PM_Radio_Off,
  45         PM_Card_Disable,
  46         PS_MODE_NUM,
  47 };
  48 
  49 #ifdef CONFIG_PNO_SUPPORT
  50 #define MAX_PNO_LIST_COUNT 16
  51 #define MAX_SCAN_LIST_COUNT 14 
  52 #endif
  53 
  54 
  55 
  56 
  57 
  58 
  59 
  60 #define PS_DPS                          BIT(0)
  61 #define PS_LCLK                         (PS_DPS)
  62 #define PS_RF_OFF                       BIT(1)
  63 #define PS_ALL_ON                       BIT(2)
  64 #define PS_ST_ACTIVE            BIT(3)
  65 
  66 #define PS_ISR_ENABLE           BIT(4)
  67 #define PS_IMR_ENABLE           BIT(5)
  68 #define PS_ACK                          BIT(6)
  69 #define PS_TOGGLE                       BIT(7)
  70 
  71 #define PS_STATE_MASK           (0x0F)
  72 #define PS_STATE_HW_MASK        (0x07)
  73 #define PS_SEQ_MASK                     (0xc0)
  74 
  75 #define PS_STATE(x)             (PS_STATE_MASK & (x))
  76 #define PS_STATE_HW(x)  (PS_STATE_HW_MASK & (x))
  77 #define PS_SEQ(x)               (PS_SEQ_MASK & (x))
  78 
  79 #define PS_STATE_S0             (PS_DPS)
  80 #define PS_STATE_S1             (PS_LCLK)
  81 #define PS_STATE_S2             (PS_RF_OFF)
  82 #define PS_STATE_S3             (PS_ALL_ON)
  83 #define PS_STATE_S4             ((PS_ST_ACTIVE) | (PS_ALL_ON))
  84 
  85 
  86 #define PS_IS_RF_ON(x)  ((x) & (PS_ALL_ON))
  87 #define PS_IS_ACTIVE(x) ((x) & (PS_ST_ACTIVE))
  88 #define CLR_PS_STATE(x) ((x) = ((x) & (0xF0)))
  89 
  90 
  91 struct reportpwrstate_parm {
  92         unsigned char mode;
  93         unsigned char state; 
  94         unsigned short rsvd;
  95 };
  96 
  97 #define LPS_DELAY_TIME  1*HZ 
  98 
  99 #define EXE_PWR_NONE    0x01
 100 #define EXE_PWR_IPS             0x02
 101 #define EXE_PWR_LPS             0x04
 102 
 103 
 104 enum rt_rf_power_state {
 105         rf_on,          
 106         rf_sleep,       
 107         rf_off,         
 108         
 109         rf_max
 110 };
 111 
 112 
 113 #define RT_RF_OFF_LEVL_ASPM                     BIT(0)  
 114 #define RT_RF_OFF_LEVL_CLK_REQ          BIT(1)  
 115 #define RT_RF_OFF_LEVL_PCI_D3                   BIT(2)  
 116 #define RT_RF_OFF_LEVL_HALT_NIC         BIT(3)  
 117 #define RT_RF_OFF_LEVL_FREE_FW          BIT(4)  
 118 #define RT_RF_OFF_LEVL_FW_32K           BIT(5)  
 119 #define RT_RF_PS_LEVEL_ALWAYS_ASPM      BIT(6)  
 120 #define RT_RF_LPS_DISALBE_2R                    BIT(30) 
 121 #define RT_RF_LPS_LEVEL_ASPM                    BIT(31) 
 122 
 123 #define RT_IN_PS_LEVEL(ppsc, _PS_FLAG)          ((ppsc->cur_ps_level & _PS_FLAG) ? true : false)
 124 #define RT_CLEAR_PS_LEVEL(ppsc, _PS_FLAG)       (ppsc->cur_ps_level &= (~(_PS_FLAG)))
 125 #define RT_SET_PS_LEVEL(ppsc, _PS_FLAG)         (ppsc->cur_ps_level |= _PS_FLAG)
 126 
 127 
 128 #define RT_PCI_ASPM_OSC_IGNORE          0        
 129 #define RT_PCI_ASPM_OSC_ENABLE          BIT0 
 130 #define RT_PCI_ASPM_OSC_DISABLE         BIT1 
 131 
 132 
 133 enum _PS_BBRegBackup_ {
 134         PSBBREG_RF0 = 0,
 135         PSBBREG_RF1,
 136         PSBBREG_RF2,
 137         PSBBREG_AFE0,
 138         PSBBREG_TOTALCNT
 139 };
 140 
 141 enum { 
 142         IPS_NONE = 0,
 143         IPS_NORMAL,
 144         IPS_LEVEL_2,
 145         IPS_NUM
 146 };
 147 
 148 
 149 enum PS_DENY_REASON {
 150         PS_DENY_DRV_INITIAL = 0,
 151         PS_DENY_SCAN,
 152         PS_DENY_JOIN,
 153         PS_DENY_DISCONNECT,
 154         PS_DENY_SUSPEND,
 155         PS_DENY_IOCTL,
 156         PS_DENY_MGNT_TX,
 157         PS_DENY_DRV_REMOVE = 30,
 158         PS_DENY_OTHERS = 31
 159 };
 160 
 161 #ifdef CONFIG_PNO_SUPPORT
 162 struct pno_nlo_info
 163 {
 164         u32 fast_scan_period;                           
 165         u32 ssid_num;                           
 166         u32 slow_scan_period;                   
 167         u32 fast_scan_iterations;                       
 168         u8 ssid_length[MAX_PNO_LIST_COUNT];     
 169         u8 ssid_cipher_info[MAX_PNO_LIST_COUNT];        
 170         u8 ssid_channel_info[MAX_PNO_LIST_COUNT];       
 171 };
 172 
 173 struct pno_ssid {
 174         u32     SSID_len;
 175         u8 SSID[32];
 176 };
 177 
 178 struct pno_ssid_list {
 179         struct pno_ssid node[MAX_PNO_LIST_COUNT];
 180 };
 181 
 182 struct pno_scan_channel_info
 183 {
 184         u8 channel;
 185         u8 tx_power;
 186         u8 timeout;
 187         u8 active;                              
 188 };
 189 
 190 struct pno_scan_info
 191 {
 192         u8 enableRFE;                   
 193         u8 period_scan_time;            
 194         u8 periodScan;                  
 195         u8 orig_80_offset;                      
 196         u8 orig_40_offset;                      
 197         u8 orig_bw;                     
 198         u8 orig_ch;                     
 199         u8 channel_num;                 
 200         u64     rfe_type;                       
 201         struct pno_scan_channel_info ssid_channel_info[MAX_SCAN_LIST_COUNT];
 202 };
 203 #endif 
 204 
 205 struct pwrctrl_priv
 206 {
 207         struct mutex lock;
 208         volatile u8 rpwm; 
 209         volatile u8 cpwm; 
 210         volatile u8 tog; 
 211         volatile u8 cpwm_tog; 
 212 
 213         u8 pwr_mode;
 214         u8 smart_ps;
 215         u8 bcn_ant_mode;
 216         u8 dtim;
 217 
 218         u32 alives;
 219         _workitem cpwm_event;
 220         u8 brpwmtimeout;
 221         _workitem rpwmtimeoutwi;
 222         _timer pwr_rpwm_timer;
 223         u8 bpower_saving; 
 224 
 225         u8 b_hw_radio_off;
 226         u8 reg_rfoff;
 227         u8 reg_pdnmode; 
 228         u32 rfoff_reason;
 229 
 230         
 231         u32 cur_ps_level;
 232         u32 reg_rfps_level;
 233 
 234         uint    ips_enter_cnts;
 235         uint    ips_leave_cnts;
 236 
 237         u8 ips_mode;
 238         u8 ips_org_mode;
 239         u8 ips_mode_req; 
 240         bool bips_processing;
 241         unsigned long ips_deny_time; 
 242         u8 pre_ips_type;
 243 
 244         
 245         
 246         
 247         
 248         u32 ps_deny;
 249 
 250         u8 ps_processing; 
 251 
 252         u8 fw_psmode_iface_id;
 253         u8 bLeisurePs;
 254         u8 LpsIdleCount;
 255         u8 power_mgnt;
 256         u8 org_power_mgnt;
 257         u8 bFwCurrentInPSMode;
 258         unsigned long   DelayLPSLastTimeStamp;
 259         s32             pnp_current_pwr_state;
 260         u8 pnp_bstop_trx;
 261 
 262 
 263         u8 bInternalAutoSuspend;
 264         u8 bInSuspend;
 265 
 266         u8 bAutoResume;
 267         u8 autopm_cnt;
 268 
 269         u8 bSupportRemoteWakeup;
 270         u8 wowlan_wake_reason;
 271         u8 wowlan_ap_mode;
 272         u8 wowlan_mode;
 273 #ifdef CONFIG_WOWLAN
 274         u8 wowlan_pattern;
 275         u8 wowlan_magic;
 276         u8 wowlan_unicast;
 277         u8 wowlan_pattern_idx;
 278         u8 wowlan_pno_enable;
 279 #ifdef CONFIG_PNO_SUPPORT
 280         u8 pno_in_resume;
 281         u8 pno_inited;
 282         struct pno_nlo_info *pnlo_info;
 283         struct pno_scan_info *pscan_info;
 284         struct pno_ssid_list *pno_ssid_list;
 285 #endif
 286         u32     wowlan_pattern_context[8][5];
 287         u64             wowlan_fw_iv;
 288 #endif 
 289         _timer  pwr_state_check_timer;
 290         struct adapter *adapter;
 291         int             pwr_state_check_interval;
 292         u8 pwr_state_check_cnts;
 293 
 294         int             ps_flag; 
 295 
 296         enum rt_rf_power_state  rf_pwrstate;
 297         
 298         enum rt_rf_power_state  change_rfpwrstate;
 299 
 300         u8 bHWPowerdown; 
 301         u8 bHWPwrPindetect; 
 302         u8 bkeepfwalive;
 303         u8 brfoffbyhw;
 304         unsigned long PS_BBRegBackup[PSBBREG_TOTALCNT];
 305 };
 306 
 307 #define rtw_get_ips_mode_req(pwrctl) \
 308         (pwrctl)->ips_mode_req
 309 
 310 #define rtw_ips_mode_req(pwrctl, ips_mode) \
 311         (pwrctl)->ips_mode_req = (ips_mode)
 312 
 313 #define RTW_PWR_STATE_CHK_INTERVAL 2000
 314 
 315 #define _rtw_set_pwr_state_check_timer(pwrctl, ms) \
 316         do { \
 317                  \
 318                 _set_timer(&(pwrctl)->pwr_state_check_timer, (ms)); \
 319         } while (0)
 320 
 321 #define rtw_set_pwr_state_check_timer(pwrctl) \
 322         _rtw_set_pwr_state_check_timer((pwrctl), (pwrctl)->pwr_state_check_interval)
 323 
 324 extern void rtw_init_pwrctrl_priv(struct adapter *adapter);
 325 extern void rtw_free_pwrctrl_priv(struct adapter * adapter);
 326 
 327 s32 rtw_register_task_alive(struct adapter *, u32 task);
 328 void rtw_unregister_task_alive(struct adapter *, u32 task);
 329 extern s32 rtw_register_tx_alive(struct adapter *padapter);
 330 extern void rtw_unregister_tx_alive(struct adapter *padapter);
 331 extern s32 rtw_register_cmd_alive(struct adapter *padapter);
 332 extern void rtw_unregister_cmd_alive(struct adapter *padapter);
 333 extern void cpwm_int_hdl(struct adapter *padapter, struct reportpwrstate_parm *preportpwrstate);
 334 extern void LPS_Leave_check(struct adapter *padapter);
 335 
 336 extern void LeaveAllPowerSaveMode(struct adapter * Adapter);
 337 extern void LeaveAllPowerSaveModeDirect(struct adapter * Adapter);
 338 void _ips_enter(struct adapter *padapter);
 339 void ips_enter(struct adapter *padapter);
 340 int _ips_leave(struct adapter *padapter);
 341 int ips_leave(struct adapter *padapter);
 342 
 343 void rtw_ps_processor(struct adapter *padapter);
 344 
 345 s32 LPS_RF_ON_check(struct adapter *padapter, u32 delay_ms);
 346 void LPS_Enter(struct adapter *padapter, const char *msg);
 347 void LPS_Leave(struct adapter *padapter, const char *msg);
 348 void traffic_check_for_leave_lps(struct adapter *padapter, u8 tx, u32 tx_packets);
 349 void rtw_set_ps_mode(struct adapter *padapter, u8 ps_mode, u8 smart_ps, u8 bcn_ant_mode, const char *msg);
 350 void rtw_set_rpwm(struct adapter *padapter, u8 val8);
 351 
 352 void rtw_set_ips_deny(struct adapter *padapter, u32 ms);
 353 int _rtw_pwr_wakeup(struct adapter *padapter, u32 ips_deffer_ms, const char *caller);
 354 #define rtw_pwr_wakeup(adapter) _rtw_pwr_wakeup(adapter, RTW_PWR_STATE_CHK_INTERVAL, __func__)
 355 #define rtw_pwr_wakeup_ex(adapter, ips_deffer_ms) _rtw_pwr_wakeup(adapter, ips_deffer_ms, __func__)
 356 int rtw_pm_set_ips(struct adapter *padapter, u8 mode);
 357 int rtw_pm_set_lps(struct adapter *padapter, u8 mode);
 358 
 359 void rtw_ps_deny(struct adapter *padapter, enum PS_DENY_REASON reason);
 360 void rtw_ps_deny_cancel(struct adapter *padapter, enum PS_DENY_REASON reason);
 361 u32 rtw_ps_deny_get(struct adapter *padapter);
 362 
 363 #endif