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