| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 1 | /****************************************************************************** | 
|  | 2 | * | 
| Larry Finger | a8d7606 | 2012-01-07 20:46:42 -0600 | [diff] [blame] | 3 | * Copyright(c) 2009-2012  Realtek Corporation. | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 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 | * 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 | 
|  | 17 | * | 
|  | 18 | * The full GNU General Public License is included in this distribution in the | 
|  | 19 | * file called LICENSE. | 
|  | 20 | * | 
|  | 21 | * Contact Information: | 
|  | 22 | * wlanfae <wlanfae@realtek.com> | 
|  | 23 | * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, | 
|  | 24 | * Hsinchu 300, Taiwan. | 
|  | 25 | * | 
|  | 26 | * Larry Finger <Larry.Finger@lwfinger.net> | 
|  | 27 | * | 
|  | 28 | *****************************************************************************/ | 
|  | 29 |  | 
| Paul Gortmaker | ee40fa0 | 2011-05-27 16:14:23 -0400 | [diff] [blame] | 30 | #include <linux/export.h> | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 31 | #include "wifi.h" | 
|  | 32 | #include "base.h" | 
|  | 33 | #include "ps.h" | 
|  | 34 |  | 
|  | 35 | bool rtl_ps_enable_nic(struct ieee80211_hw *hw) | 
|  | 36 | { | 
|  | 37 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 38 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
|  | 39 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 40 |  | 
|  | 41 | /*<1> reset trx ring */ | 
|  | 42 | if (rtlhal->interface == INTF_PCI) | 
|  | 43 | rtlpriv->intf_ops->reset_trx_ring(hw); | 
|  | 44 |  | 
|  | 45 | if (is_hal_stop(rtlhal)) | 
|  | 46 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 47 | "Driver is already down!\n"); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 48 |  | 
|  | 49 | /*<2> Enable Adapter */ | 
| Larry Finger | b0302ab | 2012-01-30 09:54:49 -0600 | [diff] [blame] | 50 | if (rtlpriv->cfg->ops->hw_init(hw)) | 
|  | 51 | return 1; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 52 | RT_CLEAR_PS_LEVEL(ppsc, RT_RF_OFF_LEVL_HALT_NIC); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 53 |  | 
|  | 54 | /*<3> Enable Interrupt */ | 
|  | 55 | rtlpriv->cfg->ops->enable_interrupt(hw); | 
|  | 56 |  | 
|  | 57 | /*<enable timer> */ | 
|  | 58 | rtl_watch_dog_timer_callback((unsigned long)hw); | 
|  | 59 |  | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 60 | return true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 61 | } | 
|  | 62 | EXPORT_SYMBOL(rtl_ps_enable_nic); | 
|  | 63 |  | 
|  | 64 | bool rtl_ps_disable_nic(struct ieee80211_hw *hw) | 
|  | 65 | { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 66 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 67 |  | 
|  | 68 | /*<1> Stop all timer */ | 
|  | 69 | rtl_deinit_deferred_work(hw); | 
|  | 70 |  | 
|  | 71 | /*<2> Disable Interrupt */ | 
|  | 72 | rtlpriv->cfg->ops->disable_interrupt(hw); | 
| Mike McCormack | 67fc605 | 2011-05-31 08:49:23 +0900 | [diff] [blame] | 73 | tasklet_kill(&rtlpriv->works.irq_tasklet); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 74 |  | 
|  | 75 | /*<3> Disable Adapter */ | 
|  | 76 | rtlpriv->cfg->ops->hw_disable(hw); | 
|  | 77 |  | 
| Larry Finger | 3247328 | 2011-03-27 16:19:57 -0500 | [diff] [blame] | 78 | return true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 79 | } | 
|  | 80 | EXPORT_SYMBOL(rtl_ps_disable_nic); | 
|  | 81 |  | 
|  | 82 | bool rtl_ps_set_rf_state(struct ieee80211_hw *hw, | 
|  | 83 | enum rf_pwrstate state_toset, | 
| Mike McCormack | 4b9d8d6 | 2011-06-20 10:46:05 +0900 | [diff] [blame] | 84 | u32 changesource) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 85 | { | 
|  | 86 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 87 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 88 | bool actionallowed = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 89 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 90 | switch (state_toset) { | 
|  | 91 | case ERFON: | 
|  | 92 | ppsc->rfoff_reason &= (~changesource); | 
|  | 93 |  | 
|  | 94 | if ((changesource == RF_CHANGE_BY_HW) && | 
| Mike McCormack | e10542c | 2011-06-20 10:47:51 +0900 | [diff] [blame] | 95 | (ppsc->hwradiooff)) { | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 96 | ppsc->hwradiooff = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 97 | } | 
|  | 98 |  | 
|  | 99 | if (!ppsc->rfoff_reason) { | 
|  | 100 | ppsc->rfoff_reason = 0; | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 101 | actionallowed = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 102 | } | 
|  | 103 |  | 
|  | 104 | break; | 
|  | 105 |  | 
|  | 106 | case ERFOFF: | 
|  | 107 |  | 
|  | 108 | if ((changesource == RF_CHANGE_BY_HW) | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 109 | && (ppsc->hwradiooff == false)) { | 
|  | 110 | ppsc->hwradiooff = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 111 | } | 
|  | 112 |  | 
|  | 113 | ppsc->rfoff_reason |= changesource; | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 114 | actionallowed = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 115 | break; | 
|  | 116 |  | 
|  | 117 | case ERFSLEEP: | 
|  | 118 | ppsc->rfoff_reason |= changesource; | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 119 | actionallowed = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 120 | break; | 
|  | 121 |  | 
|  | 122 | default: | 
|  | 123 | RT_TRACE(rtlpriv, COMP_ERR, DBG_EMERG, | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 124 | "switch case not processed\n"); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 125 | break; | 
|  | 126 | } | 
|  | 127 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 128 | if (actionallowed) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 129 | rtlpriv->cfg->ops->set_rf_power_state(hw, state_toset); | 
|  | 130 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 131 | return actionallowed; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 132 | } | 
|  | 133 | EXPORT_SYMBOL(rtl_ps_set_rf_state); | 
|  | 134 |  | 
|  | 135 | static void _rtl_ps_inactive_ps(struct ieee80211_hw *hw) | 
|  | 136 | { | 
|  | 137 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 138 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
|  | 139 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
|  | 140 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 141 | ppsc->swrf_processing = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 142 |  | 
| Larry Finger | 099fb8a | 2011-05-14 10:15:17 -0500 | [diff] [blame] | 143 | if (ppsc->inactive_pwrstate == ERFON && | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 144 | rtlhal->interface == INTF_PCI) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 145 | if ((ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM) && | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 146 | RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM) && | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 147 | rtlhal->interface == INTF_PCI) { | 
|  | 148 | rtlpriv->intf_ops->disable_aspm(hw); | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 149 | RT_CLEAR_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 150 | } | 
|  | 151 | } | 
|  | 152 |  | 
| Mike McCormack | 4b9d8d6 | 2011-06-20 10:46:05 +0900 | [diff] [blame] | 153 | rtl_ps_set_rf_state(hw, ppsc->inactive_pwrstate, RF_CHANGE_BY_IPS); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 154 |  | 
|  | 155 | if (ppsc->inactive_pwrstate == ERFOFF && | 
|  | 156 | rtlhal->interface == INTF_PCI) { | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 157 | if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM && | 
|  | 158 | !RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM)) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 159 | rtlpriv->intf_ops->enable_aspm(hw); | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 160 | RT_SET_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 161 | } | 
|  | 162 | } | 
|  | 163 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 164 | ppsc->swrf_processing = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 165 | } | 
|  | 166 |  | 
|  | 167 | void rtl_ips_nic_off_wq_callback(void *data) | 
|  | 168 | { | 
|  | 169 | struct rtl_works *rtlworks = | 
|  | 170 | container_of_dwork_rtl(data, struct rtl_works, ips_nic_off_wq); | 
|  | 171 | struct ieee80211_hw *hw = rtlworks->hw; | 
|  | 172 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 173 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
|  | 174 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 175 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
|  | 176 | enum rf_pwrstate rtstate; | 
|  | 177 |  | 
|  | 178 | if (mac->opmode != NL80211_IFTYPE_STATION) { | 
|  | 179 | RT_TRACE(rtlpriv, COMP_ERR, DBG_WARNING, | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 180 | "not station return\n"); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 181 | return; | 
|  | 182 | } | 
|  | 183 |  | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 184 | if (mac->link_state > MAC80211_NOLINK) | 
|  | 185 | return; | 
|  | 186 |  | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 187 | if (is_hal_stop(rtlhal)) | 
|  | 188 | return; | 
|  | 189 |  | 
|  | 190 | if (rtlpriv->sec.being_setkey) | 
|  | 191 | return; | 
|  | 192 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 193 | if (ppsc->inactiveps) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 194 | rtstate = ppsc->rfpwr_state; | 
|  | 195 |  | 
|  | 196 | /* | 
|  | 197 | *Do not enter IPS in the following conditions: | 
|  | 198 | *(1) RF is already OFF or Sleep | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 199 | *(2) swrf_processing (indicates the IPS is still under going) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 200 | *(3) Connectted (only disconnected can trigger IPS) | 
|  | 201 | *(4) IBSS (send Beacon) | 
|  | 202 | *(5) AP mode (send Beacon) | 
|  | 203 | *(6) monitor mode (rcv packet) | 
|  | 204 | */ | 
|  | 205 |  | 
|  | 206 | if (rtstate == ERFON && | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 207 | !ppsc->swrf_processing && | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 208 | (mac->link_state == MAC80211_NOLINK) && | 
|  | 209 | !mac->act_scanning) { | 
|  | 210 | RT_TRACE(rtlpriv, COMP_RF, DBG_TRACE, | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 211 | "IPSEnter(): Turn off RF\n"); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 212 |  | 
|  | 213 | ppsc->inactive_pwrstate = ERFOFF; | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 214 | ppsc->in_powersavemode = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 215 |  | 
|  | 216 | /*rtl_pci_reset_trx_ring(hw); */ | 
|  | 217 | _rtl_ps_inactive_ps(hw); | 
|  | 218 | } | 
|  | 219 | } | 
|  | 220 | } | 
|  | 221 |  | 
|  | 222 | void rtl_ips_nic_off(struct ieee80211_hw *hw) | 
|  | 223 | { | 
|  | 224 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 225 |  | 
|  | 226 | /* | 
|  | 227 | *because when link with ap, mac80211 will ask us | 
|  | 228 | *to disable nic quickly after scan before linking, | 
|  | 229 | *this will cause link failed, so we delay 100ms here | 
|  | 230 | */ | 
|  | 231 | queue_delayed_work(rtlpriv->works.rtl_wq, | 
|  | 232 | &rtlpriv->works.ips_nic_off_wq, MSECS(100)); | 
|  | 233 | } | 
|  | 234 |  | 
|  | 235 | void rtl_ips_nic_on(struct ieee80211_hw *hw) | 
|  | 236 | { | 
|  | 237 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 238 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 239 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
|  | 240 | enum rf_pwrstate rtstate; | 
| Larry Finger | b9116b9a | 2011-12-16 21:17:16 -0600 | [diff] [blame] | 241 | unsigned long flags; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 242 |  | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 243 | if (mac->opmode != NL80211_IFTYPE_STATION) | 
|  | 244 | return; | 
|  | 245 |  | 
| Larry Finger | b9116b9a | 2011-12-16 21:17:16 -0600 | [diff] [blame] | 246 | spin_lock_irqsave(&rtlpriv->locks.ips_lock, flags); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 247 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 248 | if (ppsc->inactiveps) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 249 | rtstate = ppsc->rfpwr_state; | 
|  | 250 |  | 
|  | 251 | if (rtstate != ERFON && | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 252 | !ppsc->swrf_processing && | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 253 | ppsc->rfoff_reason <= RF_CHANGE_BY_IPS) { | 
|  | 254 |  | 
|  | 255 | ppsc->inactive_pwrstate = ERFON; | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 256 | ppsc->in_powersavemode = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 257 |  | 
|  | 258 | _rtl_ps_inactive_ps(hw); | 
|  | 259 | } | 
|  | 260 | } | 
|  | 261 |  | 
| Larry Finger | b9116b9a | 2011-12-16 21:17:16 -0600 | [diff] [blame] | 262 | spin_unlock_irqrestore(&rtlpriv->locks.ips_lock, flags); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 263 | } | 
|  | 264 |  | 
|  | 265 | /*for FW LPS*/ | 
|  | 266 |  | 
|  | 267 | /* | 
|  | 268 | *Determine if we can set Fw into PS mode | 
|  | 269 | *in current condition.Return TRUE if it | 
|  | 270 | *can enter PS mode. | 
|  | 271 | */ | 
|  | 272 | static bool rtl_get_fwlps_doze(struct ieee80211_hw *hw) | 
|  | 273 | { | 
|  | 274 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 275 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 276 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
|  | 277 | u32 ps_timediff; | 
|  | 278 |  | 
|  | 279 | ps_timediff = jiffies_to_msecs(jiffies - | 
|  | 280 | ppsc->last_delaylps_stamp_jiffies); | 
|  | 281 |  | 
|  | 282 | if (ps_timediff < 2000) { | 
|  | 283 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 284 | "Delay enter Fw LPS for DHCP, ARP, or EAPOL exchanging state\n"); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 285 | return false; | 
|  | 286 | } | 
|  | 287 |  | 
|  | 288 | if (mac->link_state != MAC80211_LINKED) | 
|  | 289 | return false; | 
|  | 290 |  | 
|  | 291 | if (mac->opmode == NL80211_IFTYPE_ADHOC) | 
|  | 292 | return false; | 
|  | 293 |  | 
|  | 294 | return true; | 
|  | 295 | } | 
|  | 296 |  | 
|  | 297 | /* Change current and default preamble mode.*/ | 
|  | 298 | static void rtl_lps_set_psmode(struct ieee80211_hw *hw, u8 rt_psmode) | 
|  | 299 | { | 
|  | 300 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 301 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 302 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
|  | 303 | u8 rpwm_val, fw_pwrmode; | 
|  | 304 |  | 
|  | 305 | if (mac->opmode == NL80211_IFTYPE_ADHOC) | 
|  | 306 | return; | 
|  | 307 |  | 
|  | 308 | if (mac->link_state != MAC80211_LINKED) | 
|  | 309 | return; | 
|  | 310 |  | 
|  | 311 | if (ppsc->dot11_psmode == rt_psmode) | 
|  | 312 | return; | 
|  | 313 |  | 
|  | 314 | /* Update power save mode configured. */ | 
|  | 315 | ppsc->dot11_psmode = rt_psmode; | 
|  | 316 |  | 
|  | 317 | /* | 
|  | 318 | *<FW control LPS> | 
|  | 319 | *1. Enter PS mode | 
|  | 320 | *   Set RPWM to Fw to turn RF off and send H2C fw_pwrmode | 
|  | 321 | *   cmd to set Fw into PS mode. | 
|  | 322 | *2. Leave PS mode | 
|  | 323 | *   Send H2C fw_pwrmode cmd to Fw to set Fw into Active | 
|  | 324 | *   mode and set RPWM to turn RF on. | 
|  | 325 | */ | 
|  | 326 |  | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 327 | if ((ppsc->fwctrl_lps) && ppsc->report_linked) { | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 328 | bool fw_current_inps; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 329 | if (ppsc->dot11_psmode == EACTIVE) { | 
|  | 330 | RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 331 | "FW LPS leave ps_mode:%x\n", | 
|  | 332 | FW_PS_ACTIVE_MODE); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 333 |  | 
|  | 334 | rpwm_val = 0x0C;	/* RF on */ | 
|  | 335 | fw_pwrmode = FW_PS_ACTIVE_MODE; | 
|  | 336 | rtlpriv->cfg->ops->set_hw_reg(hw, HW_VAR_SET_RPWM, | 
|  | 337 | (u8 *) (&rpwm_val)); | 
|  | 338 | rtlpriv->cfg->ops->set_hw_reg(hw, | 
|  | 339 | HW_VAR_H2C_FW_PWRMODE, | 
|  | 340 | (u8 *) (&fw_pwrmode)); | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 341 | fw_current_inps = false; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 342 |  | 
|  | 343 | rtlpriv->cfg->ops->set_hw_reg(hw, | 
|  | 344 | HW_VAR_FW_PSMODE_STATUS, | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 345 | (u8 *) (&fw_current_inps)); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 346 |  | 
|  | 347 | } else { | 
|  | 348 | if (rtl_get_fwlps_doze(hw)) { | 
|  | 349 | RT_TRACE(rtlpriv, COMP_RF, DBG_DMESG, | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 350 | "FW LPS enter ps_mode:%x\n", | 
|  | 351 | ppsc->fwctrl_psmode); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 352 |  | 
|  | 353 | rpwm_val = 0x02;	/* RF off */ | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 354 | fw_current_inps = true; | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 355 | rtlpriv->cfg->ops->set_hw_reg(hw, | 
|  | 356 | HW_VAR_FW_PSMODE_STATUS, | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 357 | (u8 *) (&fw_current_inps)); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 358 | rtlpriv->cfg->ops->set_hw_reg(hw, | 
|  | 359 | HW_VAR_H2C_FW_PWRMODE, | 
|  | 360 | (u8 *) (&ppsc->fwctrl_psmode)); | 
|  | 361 |  | 
|  | 362 | rtlpriv->cfg->ops->set_hw_reg(hw, | 
|  | 363 | HW_VAR_SET_RPWM, | 
|  | 364 | (u8 *) (&rpwm_val)); | 
|  | 365 | } else { | 
|  | 366 | /* Reset the power save related parameters. */ | 
|  | 367 | ppsc->dot11_psmode = EACTIVE; | 
|  | 368 | } | 
|  | 369 | } | 
|  | 370 | } | 
|  | 371 | } | 
|  | 372 |  | 
|  | 373 | /*Enter the leisure power save mode.*/ | 
|  | 374 | void rtl_lps_enter(struct ieee80211_hw *hw) | 
|  | 375 | { | 
|  | 376 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 377 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
|  | 378 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 379 |  | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 380 | if (!ppsc->fwctrl_lps) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 381 | return; | 
|  | 382 |  | 
|  | 383 | if (rtlpriv->sec.being_setkey) | 
|  | 384 | return; | 
|  | 385 |  | 
| Larry Finger | 7ea4724 | 2011-02-19 16:28:57 -0600 | [diff] [blame] | 386 | if (rtlpriv->link_info.busytraffic) | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 387 | return; | 
|  | 388 |  | 
|  | 389 | /*sleep after linked 10s, to let DHCP and 4-way handshake ok enough!! */ | 
|  | 390 | if (mac->cnt_after_linked < 5) | 
|  | 391 | return; | 
|  | 392 |  | 
|  | 393 | if (mac->opmode == NL80211_IFTYPE_ADHOC) | 
|  | 394 | return; | 
|  | 395 |  | 
|  | 396 | if (mac->link_state != MAC80211_LINKED) | 
|  | 397 | return; | 
|  | 398 |  | 
| Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 399 | mutex_lock(&rtlpriv->locks.ps_mutex); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 400 |  | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 401 | /* Idle for a while if we connect to AP a while ago. */ | 
|  | 402 | if (mac->cnt_after_linked >= 2) { | 
|  | 403 | if (ppsc->dot11_psmode == EACTIVE) { | 
|  | 404 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 405 | "Enter 802.11 power save mode...\n"); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 406 |  | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 407 | rtl_lps_set_psmode(hw, EAUTOPS); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 408 | } | 
|  | 409 | } | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 410 |  | 
| Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 411 | mutex_unlock(&rtlpriv->locks.ps_mutex); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 412 | } | 
|  | 413 |  | 
|  | 414 | /*Leave the leisure power save mode.*/ | 
|  | 415 | void rtl_lps_leave(struct ieee80211_hw *hw) | 
|  | 416 | { | 
|  | 417 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 418 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
|  | 419 | struct rtl_hal *rtlhal = rtl_hal(rtl_priv(hw)); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 420 |  | 
| Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 421 | mutex_lock(&rtlpriv->locks.ps_mutex); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 422 |  | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 423 | if (ppsc->fwctrl_lps) { | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 424 | if (ppsc->dot11_psmode != EACTIVE) { | 
|  | 425 |  | 
|  | 426 | /*FIX ME */ | 
|  | 427 | rtlpriv->cfg->ops->enable_interrupt(hw); | 
|  | 428 |  | 
|  | 429 | if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM && | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 430 | RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM) && | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 431 | rtlhal->interface == INTF_PCI) { | 
|  | 432 | rtlpriv->intf_ops->disable_aspm(hw); | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 433 | RT_CLEAR_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 434 | } | 
|  | 435 |  | 
|  | 436 | RT_TRACE(rtlpriv, COMP_POWER, DBG_LOUD, | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 437 | "Busy Traffic,Leave 802.11 power save..\n"); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 438 |  | 
|  | 439 | rtl_lps_set_psmode(hw, EACTIVE); | 
|  | 440 | } | 
|  | 441 | } | 
| Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 442 | mutex_unlock(&rtlpriv->locks.ps_mutex); | 
| Larry Finger | 0c81733 | 2010-12-08 11:12:31 -0600 | [diff] [blame] | 443 | } | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 444 |  | 
|  | 445 | /* For sw LPS*/ | 
|  | 446 | void rtl_swlps_beacon(struct ieee80211_hw *hw, void *data, unsigned int len) | 
|  | 447 | { | 
|  | 448 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 449 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 450 | struct ieee80211_hdr *hdr = (void *) data; | 
|  | 451 | struct ieee80211_tim_ie *tim_ie; | 
|  | 452 | u8 *tim; | 
|  | 453 | u8 tim_len; | 
|  | 454 | bool u_buffed; | 
|  | 455 | bool m_buffed; | 
|  | 456 |  | 
|  | 457 | if (mac->opmode != NL80211_IFTYPE_STATION) | 
|  | 458 | return; | 
|  | 459 |  | 
|  | 460 | if (!rtlpriv->psc.swctrl_lps) | 
|  | 461 | return; | 
|  | 462 |  | 
|  | 463 | if (rtlpriv->mac80211.link_state != MAC80211_LINKED) | 
|  | 464 | return; | 
|  | 465 |  | 
|  | 466 | if (!rtlpriv->psc.sw_ps_enabled) | 
|  | 467 | return; | 
|  | 468 |  | 
|  | 469 | if (rtlpriv->psc.fwctrl_lps) | 
|  | 470 | return; | 
|  | 471 |  | 
|  | 472 | if (likely(!(hw->conf.flags & IEEE80211_CONF_PS))) | 
|  | 473 | return; | 
|  | 474 |  | 
|  | 475 | /* check if this really is a beacon */ | 
|  | 476 | if (!ieee80211_is_beacon(hdr->frame_control)) | 
|  | 477 | return; | 
|  | 478 |  | 
|  | 479 | /* min. beacon length + FCS_LEN */ | 
|  | 480 | if (len <= 40 + FCS_LEN) | 
|  | 481 | return; | 
|  | 482 |  | 
|  | 483 | /* and only beacons from the associated BSSID, please */ | 
|  | 484 | if (compare_ether_addr(hdr->addr3, rtlpriv->mac80211.bssid)) | 
|  | 485 | return; | 
|  | 486 |  | 
|  | 487 | rtlpriv->psc.last_beacon = jiffies; | 
|  | 488 |  | 
|  | 489 | tim = rtl_find_ie(data, len - FCS_LEN, WLAN_EID_TIM); | 
|  | 490 | if (!tim) | 
|  | 491 | return; | 
|  | 492 |  | 
|  | 493 | if (tim[1] < sizeof(*tim_ie)) | 
|  | 494 | return; | 
|  | 495 |  | 
|  | 496 | tim_len = tim[1]; | 
|  | 497 | tim_ie = (struct ieee80211_tim_ie *) &tim[2]; | 
|  | 498 |  | 
|  | 499 | if (!WARN_ON_ONCE(!hw->conf.ps_dtim_period)) | 
|  | 500 | rtlpriv->psc.dtim_counter = tim_ie->dtim_count; | 
|  | 501 |  | 
|  | 502 | /* Check whenever the PHY can be turned off again. */ | 
|  | 503 |  | 
|  | 504 | /* 1. What about buffered unicast traffic for our AID? */ | 
|  | 505 | u_buffed = ieee80211_check_tim(tim_ie, tim_len, | 
|  | 506 | rtlpriv->mac80211.assoc_id); | 
|  | 507 |  | 
|  | 508 | /* 2. Maybe the AP wants to send multicast/broadcast data? */ | 
|  | 509 | m_buffed = tim_ie->bitmap_ctrl & 0x01; | 
|  | 510 | rtlpriv->psc.multi_buffered = m_buffed; | 
|  | 511 |  | 
|  | 512 | /* unicast will process by mac80211 through | 
|  | 513 | * set ~IEEE80211_CONF_PS, So we just check | 
|  | 514 | * multicast frames here */ | 
|  | 515 | if (!m_buffed) { | 
|  | 516 | /* back to low-power land. and delay is | 
|  | 517 | * prevent null power save frame tx fail */ | 
|  | 518 | queue_delayed_work(rtlpriv->works.rtl_wq, | 
|  | 519 | &rtlpriv->works.ps_work, MSECS(5)); | 
|  | 520 | } else { | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 521 | RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, | 
|  | 522 | "u_bufferd: %x, m_buffered: %x\n", u_buffed, m_buffed); | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 523 | } | 
|  | 524 | } | 
|  | 525 |  | 
|  | 526 | void rtl_swlps_rf_awake(struct ieee80211_hw *hw) | 
|  | 527 | { | 
|  | 528 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 529 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
|  | 530 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 531 |  | 
|  | 532 | if (!rtlpriv->psc.swctrl_lps) | 
|  | 533 | return; | 
|  | 534 | if (mac->link_state != MAC80211_LINKED) | 
|  | 535 | return; | 
|  | 536 |  | 
|  | 537 | if (ppsc->reg_rfps_level & RT_RF_LPS_LEVEL_ASPM && | 
|  | 538 | RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM)) { | 
|  | 539 | rtlpriv->intf_ops->disable_aspm(hw); | 
|  | 540 | RT_CLEAR_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM); | 
|  | 541 | } | 
|  | 542 |  | 
| Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 543 | mutex_lock(&rtlpriv->locks.ps_mutex); | 
| Mike McCormack | 4b9d8d6 | 2011-06-20 10:46:05 +0900 | [diff] [blame] | 544 | rtl_ps_set_rf_state(hw, ERFON, RF_CHANGE_BY_PS); | 
| Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 545 | mutex_unlock(&rtlpriv->locks.ps_mutex); | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 546 | } | 
|  | 547 |  | 
|  | 548 | void rtl_swlps_rfon_wq_callback(void *data) | 
|  | 549 | { | 
|  | 550 | struct rtl_works *rtlworks = | 
|  | 551 | container_of_dwork_rtl(data, struct rtl_works, ps_rfon_wq); | 
|  | 552 | struct ieee80211_hw *hw = rtlworks->hw; | 
|  | 553 |  | 
|  | 554 | rtl_swlps_rf_awake(hw); | 
|  | 555 | } | 
|  | 556 |  | 
|  | 557 | void rtl_swlps_rf_sleep(struct ieee80211_hw *hw) | 
|  | 558 | { | 
|  | 559 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 560 | struct rtl_mac *mac = rtl_mac(rtl_priv(hw)); | 
|  | 561 | struct rtl_ps_ctl *ppsc = rtl_psc(rtl_priv(hw)); | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 562 | u8 sleep_intv; | 
|  | 563 |  | 
|  | 564 | if (!rtlpriv->psc.sw_ps_enabled) | 
|  | 565 | return; | 
|  | 566 |  | 
|  | 567 | if ((rtlpriv->sec.being_setkey) || | 
|  | 568 | (mac->opmode == NL80211_IFTYPE_ADHOC)) | 
|  | 569 | return; | 
|  | 570 |  | 
|  | 571 | /*sleep after linked 10s, to let DHCP and 4-way handshake ok enough!! */ | 
|  | 572 | if ((mac->link_state != MAC80211_LINKED) || (mac->cnt_after_linked < 5)) | 
|  | 573 | return; | 
|  | 574 |  | 
|  | 575 | if (rtlpriv->link_info.busytraffic) | 
|  | 576 | return; | 
|  | 577 |  | 
| Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 578 | mutex_lock(&rtlpriv->locks.ps_mutex); | 
| Mike McCormack | 4b9d8d6 | 2011-06-20 10:46:05 +0900 | [diff] [blame] | 579 | rtl_ps_set_rf_state(hw, ERFSLEEP, RF_CHANGE_BY_PS); | 
| Stanislaw Gruszka | 6539306 | 2011-12-12 12:43:24 +0100 | [diff] [blame] | 580 | mutex_unlock(&rtlpriv->locks.ps_mutex); | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 581 |  | 
|  | 582 | if (ppsc->reg_rfps_level & RT_RF_OFF_LEVL_ASPM && | 
|  | 583 | !RT_IN_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM)) { | 
|  | 584 | rtlpriv->intf_ops->enable_aspm(hw); | 
|  | 585 | RT_SET_PS_LEVEL(ppsc, RT_PS_LEVEL_ASPM); | 
|  | 586 | } | 
|  | 587 |  | 
|  | 588 | /* here is power save alg, when this beacon is DTIM | 
|  | 589 | * we will set sleep time to dtim_period * n; | 
|  | 590 | * when this beacon is not DTIM, we will set sleep | 
|  | 591 | * time to sleep_intv = rtlpriv->psc.dtim_counter or | 
|  | 592 | * MAX_SW_LPS_SLEEP_INTV(default set to 5) */ | 
|  | 593 |  | 
|  | 594 | if (rtlpriv->psc.dtim_counter == 0) { | 
|  | 595 | if (hw->conf.ps_dtim_period == 1) | 
|  | 596 | sleep_intv = hw->conf.ps_dtim_period * 2; | 
|  | 597 | else | 
|  | 598 | sleep_intv = hw->conf.ps_dtim_period; | 
|  | 599 | } else { | 
|  | 600 | sleep_intv = rtlpriv->psc.dtim_counter; | 
|  | 601 | } | 
|  | 602 |  | 
|  | 603 | if (sleep_intv > MAX_SW_LPS_SLEEP_INTV) | 
|  | 604 | sleep_intv = MAX_SW_LPS_SLEEP_INTV; | 
|  | 605 |  | 
|  | 606 | /* this print should always be dtim_conter = 0 & | 
|  | 607 | * sleep  = dtim_period, that meaons, we should | 
|  | 608 | * awake before every dtim */ | 
|  | 609 | RT_TRACE(rtlpriv, COMP_POWER, DBG_DMESG, | 
| Joe Perches | f30d750 | 2012-01-04 19:40:41 -0800 | [diff] [blame] | 610 | "dtim_counter:%x will sleep :%d beacon_intv\n", | 
|  | 611 | rtlpriv->psc.dtim_counter, sleep_intv); | 
| Chaoming_Li | cc7dc0c | 2011-04-25 12:53:14 -0500 | [diff] [blame] | 612 |  | 
|  | 613 | /* we tested that 40ms is enough for sw & hw sw delay */ | 
|  | 614 | queue_delayed_work(rtlpriv->works.rtl_wq, &rtlpriv->works.ps_rfon_wq, | 
|  | 615 | MSECS(sleep_intv * mac->vif->bss_conf.beacon_int - 40)); | 
|  | 616 | } | 
|  | 617 |  | 
|  | 618 |  | 
|  | 619 | void rtl_swlps_wq_callback(void *data) | 
|  | 620 | { | 
|  | 621 | struct rtl_works *rtlworks = container_of_dwork_rtl(data, | 
|  | 622 | struct rtl_works, | 
|  | 623 | ps_work); | 
|  | 624 | struct ieee80211_hw *hw = rtlworks->hw; | 
|  | 625 | struct rtl_priv *rtlpriv = rtl_priv(hw); | 
|  | 626 | bool ps = false; | 
|  | 627 |  | 
|  | 628 | ps = (hw->conf.flags & IEEE80211_CONF_PS); | 
|  | 629 |  | 
|  | 630 | /* we can sleep after ps null send ok */ | 
|  | 631 | if (rtlpriv->psc.state_inap) { | 
|  | 632 | rtl_swlps_rf_sleep(hw); | 
|  | 633 |  | 
|  | 634 | if (rtlpriv->psc.state && !ps) { | 
|  | 635 | rtlpriv->psc.sleep_ms = jiffies_to_msecs(jiffies - | 
|  | 636 | rtlpriv->psc.last_action); | 
|  | 637 | } | 
|  | 638 |  | 
|  | 639 | if (ps) | 
|  | 640 | rtlpriv->psc.last_slept = jiffies; | 
|  | 641 |  | 
|  | 642 | rtlpriv->psc.last_action = jiffies; | 
|  | 643 | rtlpriv->psc.state = ps; | 
|  | 644 | } | 
|  | 645 | } |