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