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