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