Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8b4139d | 2014-07-24 14:05:26 +0200 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of version 2 of the GNU General Public License as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 23 | * USA |
| 24 | * |
| 25 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 26 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 27 | * |
| 28 | * Contact Information: |
| 29 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 30 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 31 | * |
| 32 | * BSD LICENSE |
| 33 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 34 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Johannes Berg | 8b4139d | 2014-07-24 14:05:26 +0200 | [diff] [blame] | 35 | * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 36 | * All rights reserved. |
| 37 | * |
| 38 | * Redistribution and use in source and binary forms, with or without |
| 39 | * modification, are permitted provided that the following conditions |
| 40 | * are met: |
| 41 | * |
| 42 | * * Redistributions of source code must retain the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer. |
| 44 | * * Redistributions in binary form must reproduce the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer in |
| 46 | * the documentation and/or other materials provided with the |
| 47 | * distribution. |
| 48 | * * Neither the name Intel Corporation nor the names of its |
| 49 | * contributors may be used to endorse or promote products derived |
| 50 | * from this software without specific prior written permission. |
| 51 | * |
| 52 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 53 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 54 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 55 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 56 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 57 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 58 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 59 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 60 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 61 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 62 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 63 | * |
| 64 | *****************************************************************************/ |
| 65 | |
| 66 | #include <linux/kernel.h> |
| 67 | #include <linux/module.h> |
| 68 | #include <linux/slab.h> |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame^] | 69 | #include <linux/etherdevice.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 70 | |
| 71 | #include <net/mac80211.h> |
| 72 | |
| 73 | #include "iwl-debug.h" |
| 74 | #include "mvm.h" |
| 75 | #include "iwl-modparams.h" |
| 76 | #include "fw-api-power.h" |
| 77 | |
| 78 | #define POWER_KEEP_ALIVE_PERIOD_SEC 25 |
| 79 | |
Emmanuel Grumbach | d623d24 | 2014-01-26 12:58:24 +0200 | [diff] [blame] | 80 | static |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 81 | int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm, |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 82 | struct iwl_beacon_filter_cmd *cmd, |
| 83 | u32 flags) |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 84 | { |
Emmanuel Grumbach | d623d24 | 2014-01-26 12:58:24 +0200 | [diff] [blame] | 85 | IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n", |
| 86 | le32_to_cpu(cmd->ba_enable_beacon_abort)); |
| 87 | IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n", |
| 88 | le32_to_cpu(cmd->ba_escape_timer)); |
| 89 | IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n", |
| 90 | le32_to_cpu(cmd->bf_debug_flag)); |
| 91 | IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n", |
| 92 | le32_to_cpu(cmd->bf_enable_beacon_filter)); |
| 93 | IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n", |
| 94 | le32_to_cpu(cmd->bf_energy_delta)); |
| 95 | IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n", |
| 96 | le32_to_cpu(cmd->bf_escape_timer)); |
| 97 | IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n", |
| 98 | le32_to_cpu(cmd->bf_roaming_energy_delta)); |
| 99 | IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n", |
| 100 | le32_to_cpu(cmd->bf_roaming_state)); |
| 101 | IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n", |
| 102 | le32_to_cpu(cmd->bf_temp_threshold)); |
| 103 | IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n", |
| 104 | le32_to_cpu(cmd->bf_temp_fast_filter)); |
| 105 | IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n", |
| 106 | le32_to_cpu(cmd->bf_temp_slow_filter)); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 107 | |
Emmanuel Grumbach | d623d24 | 2014-01-26 12:58:24 +0200 | [diff] [blame] | 108 | return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags, |
| 109 | sizeof(struct iwl_beacon_filter_cmd), cmd); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 110 | } |
| 111 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 112 | static |
| 113 | void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm, |
| 114 | struct ieee80211_vif *vif, |
| 115 | struct iwl_beacon_filter_cmd *cmd) |
| 116 | { |
| 117 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 118 | |
| 119 | if (vif->bss_conf.cqm_rssi_thold) { |
| 120 | cmd->bf_energy_delta = |
| 121 | cpu_to_le32(vif->bss_conf.cqm_rssi_hyst); |
| 122 | /* fw uses an absolute value for this */ |
| 123 | cmd->bf_roaming_state = |
| 124 | cpu_to_le32(-vif->bss_conf.cqm_rssi_thold); |
| 125 | } |
| 126 | cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled); |
| 127 | } |
| 128 | |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 129 | static void iwl_mvm_power_log(struct iwl_mvm *mvm, |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 130 | struct iwl_mac_power_cmd *cmd) |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 131 | { |
| 132 | IWL_DEBUG_POWER(mvm, |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 133 | "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n", |
| 134 | cmd->id_and_color, iwlmvm_mod_params.power_scheme, |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 135 | le16_to_cpu(cmd->flags)); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 136 | IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n", |
| 137 | le16_to_cpu(cmd->keep_alive_seconds)); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 138 | |
Alexander Bondar | e3c588e | 2013-04-07 14:08:59 +0300 | [diff] [blame] | 139 | if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) { |
| 140 | IWL_DEBUG_POWER(mvm, "Disable power management\n"); |
| 141 | return; |
| 142 | } |
| 143 | |
| 144 | IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n", |
| 145 | le32_to_cpu(cmd->rx_data_timeout)); |
| 146 | IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n", |
| 147 | le32_to_cpu(cmd->tx_data_timeout)); |
| 148 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) |
| 149 | IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n", |
| 150 | cmd->skip_dtim_periods); |
| 151 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK)) |
| 152 | IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n", |
| 153 | cmd->lprx_rssi_threshold); |
| 154 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) { |
| 155 | IWL_DEBUG_POWER(mvm, "uAPSD enabled\n"); |
| 156 | IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n", |
| 157 | le32_to_cpu(cmd->rx_data_timeout_uapsd)); |
| 158 | IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n", |
| 159 | le32_to_cpu(cmd->tx_data_timeout_uapsd)); |
| 160 | IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid); |
| 161 | IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags); |
| 162 | IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 163 | } |
| 164 | } |
| 165 | |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 166 | static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm, |
| 167 | struct ieee80211_vif *vif, |
| 168 | struct iwl_mac_power_cmd *cmd) |
| 169 | { |
| 170 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 171 | enum ieee80211_ac_numbers ac; |
| 172 | bool tid_found = false; |
| 173 | |
| 174 | for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) { |
| 175 | if (!mvmvif->queue_params[ac].uapsd) |
| 176 | continue; |
| 177 | |
| 178 | if (mvm->cur_ucode != IWL_UCODE_WOWLAN) |
| 179 | cmd->flags |= |
| 180 | cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK); |
| 181 | |
| 182 | cmd->uapsd_ac_flags |= BIT(ac); |
| 183 | |
| 184 | /* QNDP TID - the highest TID with no admission control */ |
| 185 | if (!tid_found && !mvmvif->queue_params[ac].acm) { |
| 186 | tid_found = true; |
| 187 | switch (ac) { |
| 188 | case IEEE80211_AC_VO: |
| 189 | cmd->qndp_tid = 6; |
| 190 | break; |
| 191 | case IEEE80211_AC_VI: |
| 192 | cmd->qndp_tid = 5; |
| 193 | break; |
| 194 | case IEEE80211_AC_BE: |
| 195 | cmd->qndp_tid = 0; |
| 196 | break; |
| 197 | case IEEE80211_AC_BK: |
| 198 | cmd->qndp_tid = 1; |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
Eliad Peller | 84fd760 | 2014-07-30 15:42:19 +0300 | [diff] [blame] | 204 | if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) { |
| 205 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 206 | /* set advanced pm flag with no uapsd ACs to enable ps-poll */ |
| 207 | if (mvmvif->dbgfs_pm.use_ps_poll) |
| 208 | cmd->flags |= |
| 209 | cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK); |
| 210 | #endif |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 211 | return; |
Eliad Peller | 84fd760 | 2014-07-30 15:42:19 +0300 | [diff] [blame] | 212 | } |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 213 | |
| 214 | cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK); |
| 215 | |
| 216 | if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) | |
| 217 | BIT(IEEE80211_AC_VI) | |
| 218 | BIT(IEEE80211_AC_BE) | |
| 219 | BIT(IEEE80211_AC_BK))) { |
| 220 | cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK); |
| 221 | cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL); |
| 222 | cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ? |
| 223 | cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) : |
| 224 | cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW); |
| 225 | } |
| 226 | |
| 227 | cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP; |
| 228 | |
| 229 | if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags & |
| 230 | cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) { |
| 231 | cmd->rx_data_timeout_uapsd = |
| 232 | cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT); |
| 233 | cmd->tx_data_timeout_uapsd = |
| 234 | cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT); |
| 235 | } else { |
| 236 | cmd->rx_data_timeout_uapsd = |
| 237 | cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT); |
| 238 | cmd->tx_data_timeout_uapsd = |
| 239 | cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT); |
| 240 | } |
| 241 | |
| 242 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) { |
| 243 | cmd->heavy_tx_thld_packets = |
| 244 | IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS; |
| 245 | cmd->heavy_rx_thld_packets = |
| 246 | IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS; |
| 247 | } else { |
| 248 | cmd->heavy_tx_thld_packets = |
| 249 | IWL_MVM_PS_HEAVY_TX_THLD_PACKETS; |
| 250 | cmd->heavy_rx_thld_packets = |
| 251 | IWL_MVM_PS_HEAVY_RX_THLD_PACKETS; |
| 252 | } |
| 253 | cmd->heavy_tx_thld_percentage = |
| 254 | IWL_MVM_PS_HEAVY_TX_THLD_PERCENT; |
| 255 | cmd->heavy_rx_thld_percentage = |
| 256 | IWL_MVM_PS_HEAVY_RX_THLD_PERCENT; |
| 257 | } |
| 258 | |
Avri Altman | c6e37a6 | 2014-04-01 12:08:13 +0300 | [diff] [blame] | 259 | static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm, |
| 260 | struct ieee80211_vif *vif) |
| 261 | { |
| 262 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 263 | |
| 264 | if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid, |
| 265 | ETH_ALEN)) |
| 266 | return false; |
| 267 | |
| 268 | if (vif->p2p && |
| 269 | !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD)) |
| 270 | return false; |
| 271 | /* |
| 272 | * Avoid using uAPSD if P2P client is associated to GO that uses |
| 273 | * opportunistic power save. This is due to current FW limitation. |
| 274 | */ |
| 275 | if (vif->p2p && |
| 276 | (vif->bss_conf.p2p_noa_attr.oppps_ctwindow & |
| 277 | IEEE80211_P2P_OPPPS_ENABLE_BIT)) |
| 278 | return false; |
| 279 | |
Avri Altman | 0534528 | 2014-05-08 10:06:01 +0300 | [diff] [blame] | 280 | /* |
| 281 | * Avoid using uAPSD if client is in DCM - |
| 282 | * low latency issue in Miracast |
| 283 | */ |
Arik Nemtsov | cf7b491 | 2014-05-15 11:44:40 +0300 | [diff] [blame] | 284 | if (iwl_mvm_phy_ctx_count(mvm) >= 2) |
Avri Altman | 0534528 | 2014-05-08 10:06:01 +0300 | [diff] [blame] | 285 | return false; |
| 286 | |
Avri Altman | c6e37a6 | 2014-04-01 12:08:13 +0300 | [diff] [blame] | 287 | return true; |
| 288 | } |
| 289 | |
Avri Altman | 886ca9f | 2014-10-02 19:46:16 +0200 | [diff] [blame] | 290 | static int iwl_mvm_power_get_skip_over_dtim(int dtimper, int bi) |
| 291 | { |
| 292 | int numerator; |
| 293 | int dtim_interval = dtimper * bi; |
| 294 | |
| 295 | if (WARN_ON(!dtim_interval)) |
| 296 | return 0; |
| 297 | |
| 298 | if (dtimper == 1) { |
| 299 | if (bi > 100) |
| 300 | numerator = 408; |
| 301 | else |
| 302 | numerator = 510; |
| 303 | } else if (dtimper < 10) { |
| 304 | numerator = 612; |
| 305 | } else { |
| 306 | return 0; |
| 307 | } |
| 308 | return max(1, (numerator / dtim_interval)); |
| 309 | } |
| 310 | |
Avri Altman | 49c6d80 | 2014-08-27 19:58:56 +0300 | [diff] [blame] | 311 | static bool iwl_mvm_power_is_radar(struct ieee80211_vif *vif) |
| 312 | { |
| 313 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 314 | struct ieee80211_channel *chan; |
| 315 | bool radar_detect = false; |
| 316 | |
| 317 | rcu_read_lock(); |
| 318 | chanctx_conf = rcu_dereference(vif->chanctx_conf); |
| 319 | WARN_ON(!chanctx_conf); |
| 320 | if (chanctx_conf) { |
| 321 | chan = chanctx_conf->def.chan; |
| 322 | radar_detect = chan->flags & IEEE80211_CHAN_RADAR; |
| 323 | } |
| 324 | rcu_read_unlock(); |
| 325 | |
| 326 | return radar_detect; |
| 327 | } |
| 328 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 329 | static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm, |
| 330 | struct ieee80211_vif *vif, |
| 331 | struct iwl_mac_power_cmd *cmd) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 332 | { |
Avri Altman | 5387b34 | 2014-11-11 07:29:59 +0200 | [diff] [blame] | 333 | int dtimper, bi; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 334 | int keep_alive; |
| 335 | bool radar_detect = false; |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 336 | struct iwl_mvm_vif *mvmvif __maybe_unused = |
| 337 | iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 338 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 339 | cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 340 | mvmvif->color)); |
Emmanuel Grumbach | 717e239 | 2014-07-31 14:39:40 +0300 | [diff] [blame] | 341 | dtimper = vif->bss_conf.dtim_period; |
Avri Altman | 886ca9f | 2014-10-02 19:46:16 +0200 | [diff] [blame] | 342 | bi = vif->bss_conf.beacon_int; |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 343 | |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 344 | /* |
| 345 | * Regardless of power management state the driver must set |
| 346 | * keep alive period. FW will use it for sending keep alive NDPs |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 347 | * immediately after association. Check that keep alive period |
| 348 | * is at least 3 * DTIM |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 349 | */ |
Avri Altman | 5387b34 | 2014-11-11 07:29:59 +0200 | [diff] [blame] | 350 | keep_alive = DIV_ROUND_UP(ieee80211_tu_to_usec(3 * dtimper * bi), |
| 351 | USEC_PER_SEC); |
| 352 | keep_alive = max(keep_alive, POWER_KEEP_ALIVE_PERIOD_SEC); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 353 | cmd->keep_alive_seconds = cpu_to_le16(keep_alive); |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 354 | |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 355 | if (mvm->ps_disabled) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 356 | return; |
| 357 | |
Alexander Bondar | 9a61304 | 2013-03-05 12:54:00 +0200 | [diff] [blame] | 358 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 359 | |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 360 | if (!vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif) || |
Arik Nemtsov | 9474d44 | 2014-09-03 12:09:45 +0300 | [diff] [blame] | 361 | !mvmvif->pm_enabled || iwl_mvm_tdls_sta_count(mvm, vif)) |
Alexander Bondar | 9a61304 | 2013-03-05 12:54:00 +0200 | [diff] [blame] | 362 | return; |
| 363 | |
| 364 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 365 | |
Alexander Bondar | bd4ace2 | 2013-03-21 17:14:14 +0200 | [diff] [blame] | 366 | if (vif->bss_conf.beacon_rate && |
| 367 | (vif->bss_conf.beacon_rate->bitrate == 10 || |
| 368 | vif->bss_conf.beacon_rate->bitrate == 60)) { |
| 369 | cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 370 | cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD; |
Alexander Bondar | bd4ace2 | 2013-03-21 17:14:14 +0200 | [diff] [blame] | 371 | } |
| 372 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 373 | /* Check if radar detection is required on current channel */ |
Avri Altman | 49c6d80 | 2014-08-27 19:58:56 +0300 | [diff] [blame] | 374 | radar_detect = iwl_mvm_power_is_radar(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 375 | |
| 376 | /* Check skip over DTIM conditions */ |
Avri Altman | 886ca9f | 2014-10-02 19:46:16 +0200 | [diff] [blame] | 377 | if (!radar_detect && (dtimper < 10) && |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 378 | (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP || |
| 379 | mvm->cur_ucode == IWL_UCODE_WOWLAN)) { |
Avri Altman | 886ca9f | 2014-10-02 19:46:16 +0200 | [diff] [blame] | 380 | cmd->skip_dtim_periods = |
| 381 | iwl_mvm_power_get_skip_over_dtim(dtimper, bi); |
| 382 | if (cmd->skip_dtim_periods) |
| 383 | cmd->flags |= |
| 384 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
Alexander Bondar | 5b1dbfc | 2013-04-23 13:32:35 +0300 | [diff] [blame] | 385 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 386 | |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 387 | if (mvm->cur_ucode != IWL_UCODE_WOWLAN) { |
Johannes Berg | 9954592 | 2013-06-14 13:36:21 +0200 | [diff] [blame] | 388 | cmd->rx_data_timeout = |
| 389 | cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT); |
| 390 | cmd->tx_data_timeout = |
| 391 | cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT); |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 392 | } else { |
Johannes Berg | 9954592 | 2013-06-14 13:36:21 +0200 | [diff] [blame] | 393 | cmd->rx_data_timeout = |
| 394 | cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT); |
| 395 | cmd->tx_data_timeout = |
| 396 | cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT); |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 397 | } |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 398 | |
Avri Altman | c6e37a6 | 2014-04-01 12:08:13 +0300 | [diff] [blame] | 399 | if (iwl_mvm_power_allow_uapsd(mvm, vif)) |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 400 | iwl_mvm_power_configure_uapsd(mvm, vif, cmd); |
Alexander Bondar | e3c588e | 2013-04-07 14:08:59 +0300 | [diff] [blame] | 401 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 402 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 403 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE) |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 404 | cmd->keep_alive_seconds = |
| 405 | cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 406 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) { |
| 407 | if (mvmvif->dbgfs_pm.skip_over_dtim) |
| 408 | cmd->flags |= |
| 409 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
| 410 | else |
| 411 | cmd->flags &= |
| 412 | cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
| 413 | } |
| 414 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT) |
| 415 | cmd->rx_data_timeout = |
| 416 | cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout); |
| 417 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT) |
| 418 | cmd->tx_data_timeout = |
| 419 | cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout); |
| 420 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS) |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 421 | cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods; |
Alexander Bondar | bd4ace2 | 2013-03-21 17:14:14 +0200 | [diff] [blame] | 422 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) { |
| 423 | if (mvmvif->dbgfs_pm.lprx_ena) |
| 424 | cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK); |
| 425 | else |
| 426 | cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK); |
| 427 | } |
| 428 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD) |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 429 | cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold; |
Alexander Bondar | 8971634 | 2013-08-04 17:52:23 +0300 | [diff] [blame] | 430 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) { |
| 431 | if (mvmvif->dbgfs_pm.snooze_ena) |
| 432 | cmd->flags |= |
| 433 | cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK); |
| 434 | else |
| 435 | cmd->flags &= |
| 436 | cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK); |
| 437 | } |
Alexander Bondar | e45a941 | 2013-12-04 10:13:24 +0200 | [diff] [blame] | 438 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) { |
| 439 | u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK; |
| 440 | if (mvmvif->dbgfs_pm.uapsd_misbehaving) |
| 441 | cmd->flags |= cpu_to_le16(flag); |
| 442 | else |
| 443 | cmd->flags &= cpu_to_le16(flag); |
| 444 | } |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 445 | #endif /* CONFIG_IWLWIFI_DEBUGFS */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 446 | } |
| 447 | |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 448 | static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm, |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 449 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 450 | { |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 451 | struct iwl_mac_power_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 452 | |
Alexander Bondar | f4a3e2f | 2013-03-05 13:47:04 +0200 | [diff] [blame] | 453 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 454 | iwl_mvm_power_log(mvm, &cmd); |
Emmanuel Grumbach | 474b50c | 2014-01-28 09:13:04 +0200 | [diff] [blame] | 455 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 456 | memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd)); |
| 457 | #endif |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 458 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 459 | return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0, |
Emmanuel Grumbach | 06280a2 | 2014-01-27 08:09:23 +0200 | [diff] [blame] | 460 | sizeof(cmd), &cmd); |
| 461 | } |
| 462 | |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 463 | int iwl_mvm_power_update_device(struct iwl_mvm *mvm) |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 464 | { |
| 465 | struct iwl_device_power_cmd cmd = { |
| 466 | .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK), |
| 467 | }; |
| 468 | |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 469 | if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) |
| 470 | mvm->ps_disabled = true; |
| 471 | |
| 472 | if (mvm->ps_disabled) |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 473 | cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK); |
| 474 | |
| 475 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 476 | if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 : |
| 477 | mvm->disable_power_off) |
| 478 | cmd.flags &= |
| 479 | cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 480 | #endif |
| 481 | IWL_DEBUG_POWER(mvm, |
| 482 | "Sending device power command with flags = 0x%X\n", |
| 483 | cmd.flags); |
| 484 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 485 | return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd), |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 486 | &cmd); |
| 487 | } |
| 488 | |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 489 | void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 490 | { |
| 491 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 492 | |
| 493 | if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid, |
| 494 | ETH_ALEN)) |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame^] | 495 | eth_zero_addr(mvmvif->uapsd_misbehaving_bssid); |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac, |
| 499 | struct ieee80211_vif *vif) |
| 500 | { |
| 501 | u8 *ap_sta_id = _data; |
| 502 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 503 | |
| 504 | /* The ap_sta_id is not expected to change during current association |
| 505 | * so no explicit protection is needed |
| 506 | */ |
| 507 | if (mvmvif->ap_sta_id == *ap_sta_id) |
| 508 | memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid, |
| 509 | ETH_ALEN); |
| 510 | } |
| 511 | |
| 512 | int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm, |
| 513 | struct iwl_rx_cmd_buffer *rxb, |
| 514 | struct iwl_device_cmd *cmd) |
| 515 | { |
| 516 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 517 | struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data; |
| 518 | u8 ap_sta_id = le32_to_cpu(notif->sta_id); |
| 519 | |
| 520 | ieee80211_iterate_active_interfaces_atomic( |
| 521 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 522 | iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id); |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 527 | struct iwl_power_vifs { |
Arik Nemtsov | fa3d07e | 2014-05-15 18:59:32 +0300 | [diff] [blame] | 528 | struct iwl_mvm *mvm; |
Emmanuel Grumbach | 06280a2 | 2014-01-27 08:09:23 +0200 | [diff] [blame] | 529 | struct ieee80211_vif *bf_vif; |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 530 | struct ieee80211_vif *bss_vif; |
Avri Altman | 8ea0c68 | 2014-02-20 13:28:57 +0200 | [diff] [blame] | 531 | struct ieee80211_vif *p2p_vif; |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 532 | struct ieee80211_vif *ap_vif; |
| 533 | struct ieee80211_vif *monitor_vif; |
| 534 | bool p2p_active; |
| 535 | bool bss_active; |
| 536 | bool ap_active; |
| 537 | bool monitor_active; |
Emmanuel Grumbach | 06280a2 | 2014-01-27 08:09:23 +0200 | [diff] [blame] | 538 | }; |
| 539 | |
Luciano Coelho | 128aa94 | 2014-08-08 18:36:22 +0300 | [diff] [blame] | 540 | static void iwl_mvm_power_disable_pm_iterator(void *_data, u8* mac, |
| 541 | struct ieee80211_vif *vif) |
| 542 | { |
| 543 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 544 | |
| 545 | mvmvif->pm_enabled = false; |
| 546 | } |
| 547 | |
Luciano Coelho | 2533edc | 2014-08-08 19:50:46 +0300 | [diff] [blame] | 548 | static void iwl_mvm_power_ps_disabled_iterator(void *_data, u8* mac, |
| 549 | struct ieee80211_vif *vif) |
| 550 | { |
| 551 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 552 | bool *disable_ps = _data; |
| 553 | |
| 554 | if (mvmvif->phy_ctxt) |
| 555 | if (mvmvif->phy_ctxt->id < MAX_PHYS) |
| 556 | *disable_ps |= mvmvif->ps_disabled; |
| 557 | } |
| 558 | |
Luciano Coelho | 128aa94 | 2014-08-08 18:36:22 +0300 | [diff] [blame] | 559 | static void iwl_mvm_power_get_vifs_iterator(void *_data, u8 *mac, |
| 560 | struct ieee80211_vif *vif) |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 561 | { |
Emmanuel Grumbach | 06280a2 | 2014-01-27 08:09:23 +0200 | [diff] [blame] | 562 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 563 | struct iwl_power_vifs *power_iterator = _data; |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 564 | |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 565 | switch (ieee80211_vif_type_p2p(vif)) { |
| 566 | case NL80211_IFTYPE_P2P_DEVICE: |
| 567 | break; |
Emmanuel Grumbach | 06280a2 | 2014-01-27 08:09:23 +0200 | [diff] [blame] | 568 | |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 569 | case NL80211_IFTYPE_P2P_GO: |
| 570 | case NL80211_IFTYPE_AP: |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 571 | /* only a single MAC of the same type */ |
| 572 | WARN_ON(power_iterator->ap_vif); |
| 573 | power_iterator->ap_vif = vif; |
| 574 | if (mvmvif->phy_ctxt) |
| 575 | if (mvmvif->phy_ctxt->id < MAX_PHYS) |
| 576 | power_iterator->ap_active = true; |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 577 | break; |
Emmanuel Grumbach | 06280a2 | 2014-01-27 08:09:23 +0200 | [diff] [blame] | 578 | |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 579 | case NL80211_IFTYPE_MONITOR: |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 580 | /* only a single MAC of the same type */ |
| 581 | WARN_ON(power_iterator->monitor_vif); |
| 582 | power_iterator->monitor_vif = vif; |
| 583 | if (mvmvif->phy_ctxt) |
| 584 | if (mvmvif->phy_ctxt->id < MAX_PHYS) |
| 585 | power_iterator->monitor_active = true; |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 586 | break; |
| 587 | |
| 588 | case NL80211_IFTYPE_P2P_CLIENT: |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 589 | /* only a single MAC of the same type */ |
Avri Altman | 8ea0c68 | 2014-02-20 13:28:57 +0200 | [diff] [blame] | 590 | WARN_ON(power_iterator->p2p_vif); |
| 591 | power_iterator->p2p_vif = vif; |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 592 | if (mvmvif->phy_ctxt) |
| 593 | if (mvmvif->phy_ctxt->id < MAX_PHYS) |
| 594 | power_iterator->p2p_active = true; |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 595 | break; |
| 596 | |
| 597 | case NL80211_IFTYPE_STATION: |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 598 | /* only a single MAC of the same type */ |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 599 | WARN_ON(power_iterator->bss_vif); |
| 600 | power_iterator->bss_vif = vif; |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 601 | if (mvmvif->phy_ctxt) |
| 602 | if (mvmvif->phy_ctxt->id < MAX_PHYS) |
| 603 | power_iterator->bss_active = true; |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 604 | |
| 605 | if (mvmvif->bf_data.bf_enabled && |
| 606 | !WARN_ON(power_iterator->bf_vif)) |
| 607 | power_iterator->bf_vif = vif; |
Alexander Bondar | 7303dd7f | 2014-02-03 21:57:28 +0200 | [diff] [blame] | 608 | |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 609 | break; |
| 610 | |
| 611 | default: |
| 612 | break; |
| 613 | } |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 614 | } |
| 615 | |
Luciano Coelho | b187330 | 2014-08-08 17:12:07 +0300 | [diff] [blame] | 616 | static void iwl_mvm_power_set_pm(struct iwl_mvm *mvm, |
| 617 | struct iwl_power_vifs *vifs) |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 618 | { |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 619 | struct iwl_mvm_vif *bss_mvmvif = NULL; |
| 620 | struct iwl_mvm_vif *p2p_mvmvif = NULL; |
| 621 | struct iwl_mvm_vif *ap_mvmvif = NULL; |
| 622 | bool client_same_channel = false; |
| 623 | bool ap_same_channel = false; |
| 624 | |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 625 | lockdep_assert_held(&mvm->mutex); |
| 626 | |
Luciano Coelho | 128aa94 | 2014-08-08 18:36:22 +0300 | [diff] [blame] | 627 | /* set pm_enable to false */ |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 628 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, |
Luciano Coelho | 128aa94 | 2014-08-08 18:36:22 +0300 | [diff] [blame] | 629 | IEEE80211_IFACE_ITER_NORMAL, |
| 630 | iwl_mvm_power_disable_pm_iterator, |
| 631 | NULL); |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 632 | |
| 633 | if (vifs->bss_vif) |
| 634 | bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif); |
| 635 | |
| 636 | if (vifs->p2p_vif) |
| 637 | p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif); |
| 638 | |
| 639 | if (vifs->ap_vif) |
| 640 | ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif); |
| 641 | |
| 642 | /* enable PM on bss if bss stand alone */ |
Arik Nemtsov | 9474d44 | 2014-09-03 12:09:45 +0300 | [diff] [blame] | 643 | if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active) { |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 644 | bss_mvmvif->pm_enabled = true; |
| 645 | return; |
| 646 | } |
| 647 | |
| 648 | /* enable PM on p2p if p2p stand alone */ |
Arik Nemtsov | 9474d44 | 2014-09-03 12:09:45 +0300 | [diff] [blame] | 649 | if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active) { |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 650 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM) |
| 651 | p2p_mvmvif->pm_enabled = true; |
| 652 | return; |
| 653 | } |
| 654 | |
| 655 | if (vifs->bss_active && vifs->p2p_active) |
| 656 | client_same_channel = (bss_mvmvif->phy_ctxt->id == |
| 657 | p2p_mvmvif->phy_ctxt->id); |
| 658 | if (vifs->bss_active && vifs->ap_active) |
| 659 | ap_same_channel = (bss_mvmvif->phy_ctxt->id == |
| 660 | ap_mvmvif->phy_ctxt->id); |
| 661 | |
Avri Altman | 63ef81c | 2014-04-02 07:54:07 +0300 | [diff] [blame] | 662 | /* clients are not stand alone: enable PM if DCM */ |
| 663 | if (!(client_same_channel || ap_same_channel) && |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 664 | (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) { |
Avri Altman | 63ef81c | 2014-04-02 07:54:07 +0300 | [diff] [blame] | 665 | if (vifs->bss_active) |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 666 | bss_mvmvif->pm_enabled = true; |
Avri Altman | 63ef81c | 2014-04-02 07:54:07 +0300 | [diff] [blame] | 667 | if (vifs->p2p_active && |
| 668 | (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)) |
| 669 | p2p_mvmvif->pm_enabled = true; |
| 670 | return; |
Avri Altman | 1988902 | 2014-03-19 07:25:06 +0200 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /* |
| 674 | * There is only one channel in the system and there are only |
| 675 | * bss and p2p clients that share it |
| 676 | */ |
| 677 | if (client_same_channel && !vifs->ap_active && |
| 678 | (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM)) { |
| 679 | /* share same channel*/ |
| 680 | bss_mvmvif->pm_enabled = true; |
| 681 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM) |
| 682 | p2p_mvmvif->pm_enabled = true; |
| 683 | } |
Emmanuel Grumbach | e5e7aa8 | 2014-01-27 16:57:33 +0200 | [diff] [blame] | 684 | } |
| 685 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 686 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Emmanuel Grumbach | c1cb92f | 2014-01-28 10:17:18 +0200 | [diff] [blame] | 687 | int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm, |
| 688 | struct ieee80211_vif *vif, char *buf, |
| 689 | int bufsz) |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 690 | { |
Emmanuel Grumbach | 474b50c | 2014-01-28 09:13:04 +0200 | [diff] [blame] | 691 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 692 | struct iwl_mac_power_cmd cmd = {}; |
| 693 | int pos = 0; |
| 694 | |
Emmanuel Grumbach | 474b50c | 2014-01-28 09:13:04 +0200 | [diff] [blame] | 695 | mutex_lock(&mvm->mutex); |
| 696 | memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd)); |
| 697 | mutex_unlock(&mvm->mutex); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 698 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 699 | pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n", |
| 700 | iwlmvm_mod_params.power_scheme); |
| 701 | pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n", |
| 702 | le16_to_cpu(cmd.flags)); |
| 703 | pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n", |
| 704 | le16_to_cpu(cmd.keep_alive_seconds)); |
| 705 | |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 706 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) |
| 707 | return pos; |
| 708 | |
| 709 | pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n", |
| 710 | (cmd.flags & |
| 711 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0); |
| 712 | pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n", |
| 713 | cmd.skip_dtim_periods); |
| 714 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) { |
| 715 | pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n", |
| 716 | le32_to_cpu(cmd.rx_data_timeout)); |
| 717 | pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n", |
| 718 | le32_to_cpu(cmd.tx_data_timeout)); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 719 | } |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 720 | if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK)) |
| 721 | pos += scnprintf(buf+pos, bufsz-pos, |
| 722 | "lprx_rssi_threshold = %d\n", |
| 723 | cmd.lprx_rssi_threshold); |
| 724 | |
| 725 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) |
| 726 | return pos; |
| 727 | |
| 728 | pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n", |
| 729 | le32_to_cpu(cmd.rx_data_timeout_uapsd)); |
| 730 | pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n", |
| 731 | le32_to_cpu(cmd.tx_data_timeout_uapsd)); |
| 732 | pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid); |
| 733 | pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n", |
| 734 | cmd.uapsd_ac_flags); |
| 735 | pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n", |
| 736 | cmd.uapsd_max_sp); |
| 737 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n", |
| 738 | cmd.heavy_tx_thld_packets); |
| 739 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n", |
| 740 | cmd.heavy_rx_thld_packets); |
| 741 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n", |
| 742 | cmd.heavy_tx_thld_percentage); |
| 743 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n", |
| 744 | cmd.heavy_rx_thld_percentage); |
| 745 | pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n", |
| 746 | (cmd.flags & |
| 747 | cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ? |
| 748 | 1 : 0); |
| 749 | |
| 750 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK))) |
| 751 | return pos; |
| 752 | |
| 753 | pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n", |
| 754 | cmd.snooze_interval); |
| 755 | pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n", |
| 756 | cmd.snooze_window); |
| 757 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 758 | return pos; |
| 759 | } |
| 760 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 761 | void |
| 762 | iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif, |
| 763 | struct iwl_beacon_filter_cmd *cmd) |
| 764 | { |
| 765 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 766 | struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf; |
| 767 | |
| 768 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 769 | cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 770 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA) |
| 771 | cmd->bf_roaming_energy_delta = |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 772 | cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 773 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 774 | cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state); |
| 775 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD) |
| 776 | cmd->bf_temp_threshold = |
| 777 | cpu_to_le32(dbgfs_bf->bf_temp_threshold); |
| 778 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER) |
| 779 | cmd->bf_temp_fast_filter = |
| 780 | cpu_to_le32(dbgfs_bf->bf_temp_fast_filter); |
| 781 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER) |
| 782 | cmd->bf_temp_slow_filter = |
| 783 | cpu_to_le32(dbgfs_bf->bf_temp_slow_filter); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 784 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 785 | cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 786 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER) |
| 787 | cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer); |
| 788 | if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER) |
| 789 | cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer); |
| 790 | if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 791 | cmd->ba_enable_beacon_abort = |
| 792 | cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 793 | } |
| 794 | #endif |
| 795 | |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 796 | static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm, |
| 797 | struct ieee80211_vif *vif, |
| 798 | struct iwl_beacon_filter_cmd *cmd, |
| 799 | u32 cmd_flags, |
| 800 | bool d0i3) |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 801 | { |
| 802 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 803 | int ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 804 | |
Avri Altman | fa7b2e7 | 2014-05-20 08:03:24 +0300 | [diff] [blame] | 805 | if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period || |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 806 | vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 807 | return 0; |
| 808 | |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 809 | iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd); |
| 810 | if (!d0i3) |
| 811 | iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd); |
| 812 | ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 813 | |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 814 | /* don't change bf_enabled in case of temporary d0i3 configuration */ |
| 815 | if (!ret && !d0i3) |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 816 | mvmvif->bf_data.bf_enabled = true; |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 817 | |
| 818 | return ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 819 | } |
| 820 | |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 821 | int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm, |
| 822 | struct ieee80211_vif *vif, |
| 823 | u32 flags) |
| 824 | { |
| 825 | struct iwl_beacon_filter_cmd cmd = { |
| 826 | IWL_BF_CMD_CONFIG_DEFAULTS, |
| 827 | .bf_enable_beacon_filter = cpu_to_le32(1), |
| 828 | }; |
| 829 | |
| 830 | return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false); |
| 831 | } |
| 832 | |
Emmanuel Grumbach | 13b7232 | 2014-05-20 11:28:18 +0300 | [diff] [blame] | 833 | static int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm, |
| 834 | struct ieee80211_vif *vif, |
| 835 | bool enable) |
Avri Altman | fa7b2e7 | 2014-05-20 08:03:24 +0300 | [diff] [blame] | 836 | { |
| 837 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 838 | struct iwl_beacon_filter_cmd cmd = { |
| 839 | IWL_BF_CMD_CONFIG_DEFAULTS, |
| 840 | .bf_enable_beacon_filter = cpu_to_le32(1), |
| 841 | }; |
| 842 | |
| 843 | if (!mvmvif->bf_data.bf_enabled) |
| 844 | return 0; |
| 845 | |
| 846 | if (mvm->cur_ucode == IWL_UCODE_WOWLAN) |
| 847 | cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3); |
| 848 | |
| 849 | mvmvif->bf_data.ba_enabled = enable; |
| 850 | return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false); |
| 851 | } |
| 852 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 853 | int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm, |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 854 | struct ieee80211_vif *vif, |
| 855 | u32 flags) |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 856 | { |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 857 | struct iwl_beacon_filter_cmd cmd = {}; |
| 858 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 859 | int ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 860 | |
Emmanuel Grumbach | 73e5f2c | 2014-03-30 08:57:30 +0300 | [diff] [blame] | 861 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 862 | return 0; |
| 863 | |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 864 | ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 865 | |
| 866 | if (!ret) |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 867 | mvmvif->bf_data.bf_enabled = false; |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 868 | |
| 869 | return ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 870 | } |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 871 | |
Luciano Coelho | 2533edc | 2014-08-08 19:50:46 +0300 | [diff] [blame] | 872 | static int iwl_mvm_power_set_ps(struct iwl_mvm *mvm) |
Emmanuel Grumbach | 13b7232 | 2014-05-20 11:28:18 +0300 | [diff] [blame] | 873 | { |
Luciano Coelho | 128aa94 | 2014-08-08 18:36:22 +0300 | [diff] [blame] | 874 | bool disable_ps; |
Emmanuel Grumbach | 13b7232 | 2014-05-20 11:28:18 +0300 | [diff] [blame] | 875 | int ret; |
| 876 | |
Emmanuel Grumbach | 13b7232 | 2014-05-20 11:28:18 +0300 | [diff] [blame] | 877 | /* disable PS if CAM */ |
Luciano Coelho | b187330 | 2014-08-08 17:12:07 +0300 | [diff] [blame] | 878 | disable_ps = (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM); |
Luciano Coelho | 2533edc | 2014-08-08 19:50:46 +0300 | [diff] [blame] | 879 | /* ...or if any of the vifs require PS to be off */ |
| 880 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, |
| 881 | IEEE80211_IFACE_ITER_NORMAL, |
| 882 | iwl_mvm_power_ps_disabled_iterator, |
| 883 | &disable_ps); |
Luciano Coelho | b187330 | 2014-08-08 17:12:07 +0300 | [diff] [blame] | 884 | |
| 885 | /* update device power state if it has changed */ |
| 886 | if (mvm->ps_disabled != disable_ps) { |
| 887 | bool old_ps_disabled = mvm->ps_disabled; |
| 888 | |
| 889 | mvm->ps_disabled = disable_ps; |
| 890 | ret = iwl_mvm_power_update_device(mvm); |
| 891 | if (ret) { |
| 892 | mvm->ps_disabled = old_ps_disabled; |
| 893 | return ret; |
Emmanuel Grumbach | 13b7232 | 2014-05-20 11:28:18 +0300 | [diff] [blame] | 894 | } |
| 895 | } |
| 896 | |
Luciano Coelho | 128aa94 | 2014-08-08 18:36:22 +0300 | [diff] [blame] | 897 | return 0; |
| 898 | } |
| 899 | |
Luciano Coelho | ef9203d | 2014-08-08 19:18:35 +0300 | [diff] [blame] | 900 | static int iwl_mvm_power_set_ba(struct iwl_mvm *mvm, |
| 901 | struct iwl_power_vifs *vifs) |
Luciano Coelho | 128aa94 | 2014-08-08 18:36:22 +0300 | [diff] [blame] | 902 | { |
| 903 | struct iwl_mvm_vif *mvmvif; |
Luciano Coelho | ef9203d | 2014-08-08 19:18:35 +0300 | [diff] [blame] | 904 | bool ba_enable; |
| 905 | |
| 906 | if (!vifs->bf_vif) |
| 907 | return 0; |
| 908 | |
| 909 | mvmvif = iwl_mvm_vif_from_mac80211(vifs->bf_vif); |
| 910 | |
| 911 | ba_enable = !(!mvmvif->pm_enabled || mvm->ps_disabled || |
| 912 | !vifs->bf_vif->bss_conf.ps || |
| 913 | iwl_mvm_vif_low_latency(mvmvif)); |
| 914 | |
| 915 | return iwl_mvm_update_beacon_abort(mvm, vifs->bf_vif, ba_enable); |
| 916 | } |
| 917 | |
| 918 | int iwl_mvm_power_update_ps(struct iwl_mvm *mvm) |
| 919 | { |
Luciano Coelho | 128aa94 | 2014-08-08 18:36:22 +0300 | [diff] [blame] | 920 | struct iwl_power_vifs vifs = { |
| 921 | .mvm = mvm, |
| 922 | }; |
Luciano Coelho | ef9203d | 2014-08-08 19:18:35 +0300 | [diff] [blame] | 923 | int ret; |
| 924 | |
| 925 | lockdep_assert_held(&mvm->mutex); |
| 926 | |
| 927 | /* get vifs info */ |
| 928 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, |
| 929 | IEEE80211_IFACE_ITER_NORMAL, |
| 930 | iwl_mvm_power_get_vifs_iterator, &vifs); |
| 931 | |
Luciano Coelho | 2533edc | 2014-08-08 19:50:46 +0300 | [diff] [blame] | 932 | ret = iwl_mvm_power_set_ps(mvm); |
Luciano Coelho | ef9203d | 2014-08-08 19:18:35 +0300 | [diff] [blame] | 933 | if (ret) |
| 934 | return ret; |
| 935 | |
| 936 | return iwl_mvm_power_set_ba(mvm, &vifs); |
| 937 | } |
| 938 | |
| 939 | int iwl_mvm_power_update_mac(struct iwl_mvm *mvm) |
| 940 | { |
| 941 | struct iwl_power_vifs vifs = { |
| 942 | .mvm = mvm, |
| 943 | }; |
Luciano Coelho | 128aa94 | 2014-08-08 18:36:22 +0300 | [diff] [blame] | 944 | int ret; |
| 945 | |
| 946 | lockdep_assert_held(&mvm->mutex); |
| 947 | |
| 948 | /* get vifs info */ |
| 949 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, |
| 950 | IEEE80211_IFACE_ITER_NORMAL, |
| 951 | iwl_mvm_power_get_vifs_iterator, &vifs); |
| 952 | |
| 953 | iwl_mvm_power_set_pm(mvm, &vifs); |
| 954 | |
Luciano Coelho | 2533edc | 2014-08-08 19:50:46 +0300 | [diff] [blame] | 955 | ret = iwl_mvm_power_set_ps(mvm); |
Luciano Coelho | 128aa94 | 2014-08-08 18:36:22 +0300 | [diff] [blame] | 956 | if (ret) |
| 957 | return ret; |
| 958 | |
Emmanuel Grumbach | 13b7232 | 2014-05-20 11:28:18 +0300 | [diff] [blame] | 959 | if (vifs.bss_vif) { |
| 960 | ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif); |
| 961 | if (ret) |
| 962 | return ret; |
| 963 | } |
| 964 | |
| 965 | if (vifs.p2p_vif) { |
| 966 | ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif); |
| 967 | if (ret) |
| 968 | return ret; |
| 969 | } |
| 970 | |
Luciano Coelho | ef9203d | 2014-08-08 19:18:35 +0300 | [diff] [blame] | 971 | return iwl_mvm_power_set_ba(mvm, &vifs); |
Emmanuel Grumbach | 13b7232 | 2014-05-20 11:28:18 +0300 | [diff] [blame] | 972 | } |
| 973 | |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 974 | int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm, |
| 975 | struct ieee80211_vif *vif, |
| 976 | bool enable, u32 flags) |
| 977 | { |
| 978 | int ret; |
| 979 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 980 | struct iwl_mac_power_cmd cmd = {}; |
| 981 | |
| 982 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 983 | return 0; |
| 984 | |
| 985 | if (!vif->bss_conf.assoc) |
| 986 | return 0; |
| 987 | |
| 988 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); |
| 989 | if (enable) { |
Avri Altman | 49c6d80 | 2014-08-27 19:58:56 +0300 | [diff] [blame] | 990 | /* configure skip over dtim up to 306TU - 314 msec */ |
Emmanuel Grumbach | 717e239 | 2014-07-31 14:39:40 +0300 | [diff] [blame] | 991 | int dtimper = vif->bss_conf.dtim_period ?: 1; |
Avri Altman | 49c6d80 | 2014-08-27 19:58:56 +0300 | [diff] [blame] | 992 | int dtimper_tu = dtimper * vif->bss_conf.beacon_int; |
| 993 | bool radar_detect = iwl_mvm_power_is_radar(vif); |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 994 | |
Avri Altman | 49c6d80 | 2014-08-27 19:58:56 +0300 | [diff] [blame] | 995 | if (WARN_ON(!dtimper_tu)) |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 996 | return 0; |
| 997 | |
Avri Altman | 49c6d80 | 2014-08-27 19:58:56 +0300 | [diff] [blame] | 998 | /* Check skip over DTIM conditions */ |
| 999 | /* TODO: check that multicast wake lock is off */ |
| 1000 | if (!radar_detect && (dtimper < 10)) { |
| 1001 | cmd.skip_dtim_periods = 306 / dtimper_tu; |
| 1002 | if (cmd.skip_dtim_periods) |
| 1003 | cmd.flags |= cpu_to_le16( |
| 1004 | POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
| 1005 | } |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 1006 | } |
| 1007 | iwl_mvm_power_log(mvm, &cmd); |
Emmanuel Grumbach | 474b50c | 2014-01-28 09:13:04 +0200 | [diff] [blame] | 1008 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1009 | memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd)); |
| 1010 | #endif |
Eliad Peller | 3dd37d0 | 2014-01-07 14:00:24 +0200 | [diff] [blame] | 1011 | ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags, |
| 1012 | sizeof(cmd), &cmd); |
| 1013 | if (ret) |
| 1014 | return ret; |
| 1015 | |
| 1016 | /* configure beacon filtering */ |
| 1017 | if (mvmvif != mvm->bf_allowed_vif) |
| 1018 | return 0; |
| 1019 | |
| 1020 | if (enable) { |
| 1021 | struct iwl_beacon_filter_cmd cmd_bf = { |
| 1022 | IWL_BF_CMD_CONFIG_D0I3, |
| 1023 | .bf_enable_beacon_filter = cpu_to_le32(1), |
| 1024 | }; |
| 1025 | ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf, |
| 1026 | flags, true); |
| 1027 | } else { |
| 1028 | if (mvmvif->bf_data.bf_enabled) |
| 1029 | ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags); |
| 1030 | else |
| 1031 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags); |
| 1032 | } |
| 1033 | |
| 1034 | return ret; |
| 1035 | } |