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