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 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 77 | int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm, |
| 78 | struct iwl_beacon_filter_cmd *cmd) |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 79 | { |
| 80 | int ret; |
| 81 | |
| 82 | ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, CMD_SYNC, |
| 83 | sizeof(struct iwl_beacon_filter_cmd), cmd); |
| 84 | |
| 85 | if (!ret) { |
| 86 | IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n", |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 87 | le32_to_cpu(cmd->ba_enable_beacon_abort)); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 88 | IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n", |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 89 | le32_to_cpu(cmd->ba_escape_timer)); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 90 | IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n", |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 91 | le32_to_cpu(cmd->bf_debug_flag)); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 92 | IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n", |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 93 | le32_to_cpu(cmd->bf_enable_beacon_filter)); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 94 | IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n", |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 95 | le32_to_cpu(cmd->bf_energy_delta)); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 96 | IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n", |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 97 | le32_to_cpu(cmd->bf_escape_timer)); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 98 | IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n", |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 99 | le32_to_cpu(cmd->bf_roaming_energy_delta)); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 100 | IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n", |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 101 | le32_to_cpu(cmd->bf_roaming_state)); |
| 102 | IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n", |
| 103 | le32_to_cpu(cmd->bf_temp_threshold)); |
| 104 | IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n", |
| 105 | le32_to_cpu(cmd->bf_temp_fast_filter)); |
| 106 | IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n", |
| 107 | le32_to_cpu(cmd->bf_temp_slow_filter)); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 108 | } |
| 109 | return ret; |
| 110 | } |
| 111 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 112 | static |
| 113 | void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm, |
| 114 | struct ieee80211_vif *vif, |
| 115 | struct iwl_beacon_filter_cmd *cmd) |
| 116 | { |
| 117 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 118 | |
| 119 | if (vif->bss_conf.cqm_rssi_thold) { |
| 120 | cmd->bf_energy_delta = |
| 121 | cpu_to_le32(vif->bss_conf.cqm_rssi_hyst); |
| 122 | /* fw uses an absolute value for this */ |
| 123 | cmd->bf_roaming_state = |
| 124 | cpu_to_le32(-vif->bss_conf.cqm_rssi_thold); |
| 125 | } |
| 126 | cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled); |
| 127 | } |
| 128 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 129 | int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm, |
| 130 | struct ieee80211_vif *vif, bool enable) |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 131 | { |
| 132 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 133 | struct iwl_beacon_filter_cmd cmd = { |
| 134 | IWL_BF_CMD_CONFIG_DEFAULTS, |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 135 | .bf_enable_beacon_filter = cpu_to_le32(1), |
| 136 | .ba_enable_beacon_abort = cpu_to_le32(enable), |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 137 | }; |
| 138 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 139 | if (!mvmvif->bf_data.bf_enabled) |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 140 | return 0; |
| 141 | |
Alexander Bondar | 8434925 | 2013-07-22 15:39:26 +0300 | [diff] [blame] | 142 | if (mvm->cur_ucode == IWL_UCODE_WOWLAN) |
| 143 | cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3); |
| 144 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 145 | mvmvif->bf_data.ba_enabled = enable; |
| 146 | iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 147 | iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 148 | return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); |
| 149 | } |
| 150 | |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 151 | static void iwl_mvm_power_log(struct iwl_mvm *mvm, |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 152 | struct iwl_mac_power_cmd *cmd) |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 153 | { |
| 154 | IWL_DEBUG_POWER(mvm, |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 155 | "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n", |
| 156 | cmd->id_and_color, iwlmvm_mod_params.power_scheme, |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 157 | le16_to_cpu(cmd->flags)); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 158 | IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n", |
| 159 | le16_to_cpu(cmd->keep_alive_seconds)); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 160 | |
Alexander Bondar | e3c588e | 2013-04-07 14:08:59 +0300 | [diff] [blame] | 161 | if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) { |
| 162 | IWL_DEBUG_POWER(mvm, "Disable power management\n"); |
| 163 | return; |
| 164 | } |
| 165 | |
| 166 | IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n", |
| 167 | le32_to_cpu(cmd->rx_data_timeout)); |
| 168 | IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n", |
| 169 | le32_to_cpu(cmd->tx_data_timeout)); |
| 170 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) |
| 171 | IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n", |
| 172 | cmd->skip_dtim_periods); |
| 173 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK)) |
| 174 | IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n", |
| 175 | cmd->lprx_rssi_threshold); |
| 176 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) { |
| 177 | IWL_DEBUG_POWER(mvm, "uAPSD enabled\n"); |
| 178 | IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n", |
| 179 | le32_to_cpu(cmd->rx_data_timeout_uapsd)); |
| 180 | IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n", |
| 181 | le32_to_cpu(cmd->tx_data_timeout_uapsd)); |
| 182 | IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid); |
| 183 | IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags); |
| 184 | IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 185 | } |
| 186 | } |
| 187 | |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 188 | static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm, |
| 189 | struct ieee80211_vif *vif, |
| 190 | struct iwl_mac_power_cmd *cmd) |
| 191 | { |
| 192 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 193 | enum ieee80211_ac_numbers ac; |
| 194 | bool tid_found = false; |
| 195 | |
| 196 | for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) { |
| 197 | if (!mvmvif->queue_params[ac].uapsd) |
| 198 | continue; |
| 199 | |
| 200 | if (mvm->cur_ucode != IWL_UCODE_WOWLAN) |
| 201 | cmd->flags |= |
| 202 | cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK); |
| 203 | |
| 204 | cmd->uapsd_ac_flags |= BIT(ac); |
| 205 | |
| 206 | /* QNDP TID - the highest TID with no admission control */ |
| 207 | if (!tid_found && !mvmvif->queue_params[ac].acm) { |
| 208 | tid_found = true; |
| 209 | switch (ac) { |
| 210 | case IEEE80211_AC_VO: |
| 211 | cmd->qndp_tid = 6; |
| 212 | break; |
| 213 | case IEEE80211_AC_VI: |
| 214 | cmd->qndp_tid = 5; |
| 215 | break; |
| 216 | case IEEE80211_AC_BE: |
| 217 | cmd->qndp_tid = 0; |
| 218 | break; |
| 219 | case IEEE80211_AC_BK: |
| 220 | cmd->qndp_tid = 1; |
| 221 | break; |
| 222 | } |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) |
| 227 | return; |
| 228 | |
| 229 | cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK); |
| 230 | |
| 231 | if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) | |
| 232 | BIT(IEEE80211_AC_VI) | |
| 233 | BIT(IEEE80211_AC_BE) | |
| 234 | BIT(IEEE80211_AC_BK))) { |
| 235 | cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK); |
| 236 | cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL); |
| 237 | cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ? |
| 238 | cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) : |
| 239 | cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW); |
| 240 | } |
| 241 | |
| 242 | cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP; |
| 243 | |
| 244 | if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags & |
| 245 | cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) { |
| 246 | cmd->rx_data_timeout_uapsd = |
| 247 | cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT); |
| 248 | cmd->tx_data_timeout_uapsd = |
| 249 | cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT); |
| 250 | } else { |
| 251 | cmd->rx_data_timeout_uapsd = |
| 252 | cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT); |
| 253 | cmd->tx_data_timeout_uapsd = |
| 254 | cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT); |
| 255 | } |
| 256 | |
| 257 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) { |
| 258 | cmd->heavy_tx_thld_packets = |
| 259 | IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS; |
| 260 | cmd->heavy_rx_thld_packets = |
| 261 | IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS; |
| 262 | } else { |
| 263 | cmd->heavy_tx_thld_packets = |
| 264 | IWL_MVM_PS_HEAVY_TX_THLD_PACKETS; |
| 265 | cmd->heavy_rx_thld_packets = |
| 266 | IWL_MVM_PS_HEAVY_RX_THLD_PACKETS; |
| 267 | } |
| 268 | cmd->heavy_tx_thld_percentage = |
| 269 | IWL_MVM_PS_HEAVY_TX_THLD_PERCENT; |
| 270 | cmd->heavy_rx_thld_percentage = |
| 271 | IWL_MVM_PS_HEAVY_RX_THLD_PERCENT; |
| 272 | } |
| 273 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 274 | static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm, |
| 275 | struct ieee80211_vif *vif, |
| 276 | struct iwl_mac_power_cmd *cmd) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 277 | { |
| 278 | struct ieee80211_hw *hw = mvm->hw; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 279 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 280 | struct ieee80211_channel *chan; |
| 281 | int dtimper, dtimper_msec; |
| 282 | int keep_alive; |
| 283 | bool radar_detect = false; |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 284 | struct iwl_mvm_vif *mvmvif __maybe_unused = |
| 285 | iwl_mvm_vif_from_mac80211(vif); |
Alexander Bondar | 51498cf | 2013-09-02 17:10:14 +0300 | [diff] [blame] | 286 | bool allow_uapsd = true; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 287 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 288 | cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 289 | mvmvif->color)); |
| 290 | dtimper = hw->conf.ps_dtim_period ?: 1; |
| 291 | |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 292 | /* |
| 293 | * Regardless of power management state the driver must set |
| 294 | * keep alive period. FW will use it for sending keep alive NDPs |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 295 | * immediately after association. Check that keep alive period |
| 296 | * is at least 3 * DTIM |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 297 | */ |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 298 | dtimper_msec = dtimper * vif->bss_conf.beacon_int; |
| 299 | keep_alive = max_t(int, 3 * dtimper_msec, |
| 300 | MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC); |
| 301 | keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC); |
| 302 | cmd->keep_alive_seconds = cpu_to_le16(keep_alive); |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 303 | |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 304 | if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM || |
| 305 | mvm->ps_prevented) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 306 | return; |
| 307 | |
Alexander Bondar | 9a61304 | 2013-03-05 12:54:00 +0200 | [diff] [blame] | 308 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 309 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 310 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 311 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF && |
| 312 | mvmvif->dbgfs_pm.disable_power_off) |
| 313 | cmd->flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 314 | #endif |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 315 | if (!vif->bss_conf.ps || mvmvif->pm_prevented) |
Alexander Bondar | 9a61304 | 2013-03-05 12:54:00 +0200 | [diff] [blame] | 316 | return; |
| 317 | |
| 318 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 319 | |
Alexander Bondar | bd4ace2 | 2013-03-21 17:14:14 +0200 | [diff] [blame] | 320 | if (vif->bss_conf.beacon_rate && |
| 321 | (vif->bss_conf.beacon_rate->bitrate == 10 || |
| 322 | vif->bss_conf.beacon_rate->bitrate == 60)) { |
| 323 | cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 324 | cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD; |
Alexander Bondar | bd4ace2 | 2013-03-21 17:14:14 +0200 | [diff] [blame] | 325 | } |
| 326 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 327 | /* Check if radar detection is required on current channel */ |
| 328 | rcu_read_lock(); |
| 329 | chanctx_conf = rcu_dereference(vif->chanctx_conf); |
| 330 | WARN_ON(!chanctx_conf); |
| 331 | if (chanctx_conf) { |
| 332 | chan = chanctx_conf->def.chan; |
| 333 | radar_detect = chan->flags & IEEE80211_CHAN_RADAR; |
| 334 | } |
| 335 | rcu_read_unlock(); |
| 336 | |
| 337 | /* Check skip over DTIM conditions */ |
| 338 | if (!radar_detect && (dtimper <= 10) && |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 339 | (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP || |
| 340 | mvm->cur_ucode == IWL_UCODE_WOWLAN)) { |
Alexander Bondar | f4a3e2f | 2013-03-05 13:47:04 +0200 | [diff] [blame] | 341 | cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 342 | cmd->skip_dtim_periods = 3; |
Alexander Bondar | 5b1dbfc | 2013-04-23 13:32:35 +0300 | [diff] [blame] | 343 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 344 | |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 345 | if (mvm->cur_ucode != IWL_UCODE_WOWLAN) { |
Johannes Berg | 9954592 | 2013-06-14 13:36:21 +0200 | [diff] [blame] | 346 | cmd->rx_data_timeout = |
| 347 | cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT); |
| 348 | cmd->tx_data_timeout = |
| 349 | cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT); |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 350 | } else { |
Johannes Berg | 9954592 | 2013-06-14 13:36:21 +0200 | [diff] [blame] | 351 | cmd->rx_data_timeout = |
| 352 | cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT); |
| 353 | cmd->tx_data_timeout = |
| 354 | cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT); |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 355 | } |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 356 | |
Alexander Bondar | 51498cf | 2013-09-02 17:10:14 +0300 | [diff] [blame] | 357 | if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid, |
| 358 | ETH_ALEN)) |
| 359 | allow_uapsd = false; |
Alexander Bondar | 7520967 | 2013-11-12 14:47:59 +0200 | [diff] [blame] | 360 | |
| 361 | if (vif->p2p && |
| 362 | !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD)) |
| 363 | allow_uapsd = false; |
Alexander Bondar | 51498cf | 2013-09-02 17:10:14 +0300 | [diff] [blame] | 364 | /* |
| 365 | * Avoid using uAPSD if P2P client is associated to GO that uses |
| 366 | * opportunistic power save. This is due to current FW limitation. |
| 367 | */ |
| 368 | if (vif->p2p && |
| 369 | vif->bss_conf.p2p_noa_attr.oppps_ctwindow & |
| 370 | IEEE80211_P2P_OPPPS_ENABLE_BIT) |
| 371 | allow_uapsd = false; |
| 372 | |
| 373 | if (allow_uapsd) |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 374 | iwl_mvm_power_configure_uapsd(mvm, vif, cmd); |
Alexander Bondar | e3c588e | 2013-04-07 14:08:59 +0300 | [diff] [blame] | 375 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 376 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 377 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE) |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 378 | cmd->keep_alive_seconds = |
| 379 | cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 380 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) { |
| 381 | if (mvmvif->dbgfs_pm.skip_over_dtim) |
| 382 | cmd->flags |= |
| 383 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
| 384 | else |
| 385 | cmd->flags &= |
| 386 | cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
| 387 | } |
| 388 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT) |
| 389 | cmd->rx_data_timeout = |
| 390 | cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout); |
| 391 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT) |
| 392 | cmd->tx_data_timeout = |
| 393 | cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout); |
| 394 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS) |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 395 | cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods; |
Alexander Bondar | bd4ace2 | 2013-03-21 17:14:14 +0200 | [diff] [blame] | 396 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) { |
| 397 | if (mvmvif->dbgfs_pm.lprx_ena) |
| 398 | cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK); |
| 399 | else |
| 400 | cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK); |
| 401 | } |
| 402 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD) |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 403 | cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold; |
Alexander Bondar | 8971634 | 2013-08-04 17:52:23 +0300 | [diff] [blame] | 404 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) { |
| 405 | if (mvmvif->dbgfs_pm.snooze_ena) |
| 406 | cmd->flags |= |
| 407 | cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK); |
| 408 | else |
| 409 | cmd->flags &= |
| 410 | cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK); |
| 411 | } |
Alexander Bondar | e45a941 | 2013-12-04 10:13:24 +0200 | [diff] [blame] | 412 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) { |
| 413 | u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK; |
| 414 | if (mvmvif->dbgfs_pm.uapsd_misbehaving) |
| 415 | cmd->flags |= cpu_to_le16(flag); |
| 416 | else |
| 417 | cmd->flags &= cpu_to_le16(flag); |
| 418 | } |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 419 | #endif /* CONFIG_IWLWIFI_DEBUGFS */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 420 | } |
| 421 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 422 | static int iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm, |
| 423 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 424 | { |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 425 | int ret; |
| 426 | bool ba_enable; |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 427 | struct iwl_mac_power_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 428 | |
Alexander Bondar | 51498cf | 2013-09-02 17:10:14 +0300 | [diff] [blame] | 429 | if (vif->type != NL80211_IFTYPE_STATION) |
| 430 | return 0; |
| 431 | |
| 432 | if (vif->p2p && |
| 433 | !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 434 | return 0; |
| 435 | |
Alexander Bondar | f4a3e2f | 2013-03-05 13:47:04 +0200 | [diff] [blame] | 436 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 437 | iwl_mvm_power_log(mvm, &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 438 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 439 | ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC, |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 440 | sizeof(cmd), &cmd); |
| 441 | if (ret) |
| 442 | return ret; |
| 443 | |
| 444 | ba_enable = !!(cmd.flags & |
| 445 | cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)); |
| 446 | |
| 447 | return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 448 | } |
| 449 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 450 | static int iwl_mvm_power_mac_disable(struct iwl_mvm *mvm, |
| 451 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 452 | { |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 453 | struct iwl_mac_power_cmd cmd = {}; |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 454 | struct iwl_mvm_vif *mvmvif __maybe_unused = |
| 455 | iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 456 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 457 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 458 | return 0; |
| 459 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 460 | cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 461 | mvmvif->color)); |
| 462 | |
Alexander Bondar | ade5065 | 2013-04-03 16:28:47 +0300 | [diff] [blame] | 463 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
Alexander Bondar | 9a61304 | 2013-03-05 12:54:00 +0200 | [diff] [blame] | 464 | cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 465 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 466 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 467 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF && |
| 468 | mvmvif->dbgfs_pm.disable_power_off) |
| 469 | cmd.flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 470 | #endif |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 471 | iwl_mvm_power_log(mvm, &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 472 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 473 | return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_ASYNC, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 474 | sizeof(cmd), &cmd); |
| 475 | } |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 476 | |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 477 | static int _iwl_mvm_power_update_device(struct iwl_mvm *mvm, bool force_disable) |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 478 | { |
| 479 | struct iwl_device_power_cmd cmd = { |
| 480 | .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK), |
| 481 | }; |
| 482 | |
| 483 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD)) |
| 484 | return 0; |
| 485 | |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 486 | if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM || |
| 487 | force_disable) |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 488 | cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK); |
| 489 | |
| 490 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 491 | if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 : |
| 492 | mvm->disable_power_off) |
| 493 | cmd.flags &= |
| 494 | cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 495 | #endif |
| 496 | IWL_DEBUG_POWER(mvm, |
| 497 | "Sending device power command with flags = 0x%X\n", |
| 498 | cmd.flags); |
| 499 | |
| 500 | return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_SYNC, sizeof(cmd), |
| 501 | &cmd); |
| 502 | } |
| 503 | |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 504 | static int iwl_mvm_power_update_device(struct iwl_mvm *mvm) |
| 505 | { |
| 506 | return _iwl_mvm_power_update_device(mvm, false); |
| 507 | } |
| 508 | |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 509 | void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 510 | { |
| 511 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 512 | |
| 513 | if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid, |
| 514 | ETH_ALEN)) |
| 515 | memset(mvmvif->uapsd_misbehaving_bssid, 0, ETH_ALEN); |
| 516 | } |
| 517 | |
| 518 | static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac, |
| 519 | struct ieee80211_vif *vif) |
| 520 | { |
| 521 | u8 *ap_sta_id = _data; |
| 522 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 523 | |
| 524 | /* The ap_sta_id is not expected to change during current association |
| 525 | * so no explicit protection is needed |
| 526 | */ |
| 527 | if (mvmvif->ap_sta_id == *ap_sta_id) |
| 528 | memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid, |
| 529 | ETH_ALEN); |
| 530 | } |
| 531 | |
| 532 | int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm, |
| 533 | struct iwl_rx_cmd_buffer *rxb, |
| 534 | struct iwl_device_cmd *cmd) |
| 535 | { |
| 536 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 537 | struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data; |
| 538 | u8 ap_sta_id = le32_to_cpu(notif->sta_id); |
| 539 | |
| 540 | ieee80211_iterate_active_interfaces_atomic( |
| 541 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 542 | iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id); |
| 543 | |
| 544 | return 0; |
| 545 | } |
| 546 | |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 547 | static void iwl_mvm_power_binding_iterator(void *_data, u8 *mac, |
| 548 | struct ieee80211_vif *vif) |
| 549 | { |
| 550 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 551 | struct iwl_mvm *mvm = _data; |
| 552 | int ret; |
| 553 | |
| 554 | mvmvif->pm_prevented = (mvm->bound_vif_cnt <= 1) ? false : true; |
| 555 | |
| 556 | ret = iwl_mvm_power_mac_update_mode(mvm, vif); |
| 557 | WARN_ONCE(ret, "Failed to update power parameters on a specific vif\n"); |
| 558 | } |
| 559 | |
| 560 | static void _iwl_mvm_power_update_binding(struct iwl_mvm *mvm, |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 561 | struct ieee80211_vif *vif, |
| 562 | bool assign) |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 563 | { |
Alexander Bondar | 92d8556 | 2013-10-23 11:50:34 +0200 | [diff] [blame] | 564 | if (vif->type == NL80211_IFTYPE_MONITOR) { |
| 565 | int ret = _iwl_mvm_power_update_device(mvm, assign); |
| 566 | mvm->ps_prevented = assign; |
| 567 | WARN_ONCE(ret, "Failed to update power device state\n"); |
| 568 | } |
| 569 | |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 570 | ieee80211_iterate_active_interfaces(mvm->hw, |
| 571 | IEEE80211_IFACE_ITER_NORMAL, |
| 572 | iwl_mvm_power_binding_iterator, |
| 573 | mvm); |
| 574 | } |
| 575 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 576 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 577 | static int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm, |
| 578 | struct ieee80211_vif *vif, char *buf, |
| 579 | int bufsz) |
| 580 | { |
| 581 | struct iwl_mac_power_cmd cmd = {}; |
| 582 | int pos = 0; |
| 583 | |
| 584 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); |
| 585 | |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 586 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD)) |
| 587 | pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n", |
| 588 | (cmd.flags & |
| 589 | cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ? |
| 590 | 0 : 1); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 591 | pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n", |
| 592 | iwlmvm_mod_params.power_scheme); |
| 593 | pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n", |
| 594 | le16_to_cpu(cmd.flags)); |
| 595 | pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n", |
| 596 | le16_to_cpu(cmd.keep_alive_seconds)); |
| 597 | |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 598 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) |
| 599 | return pos; |
| 600 | |
| 601 | pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n", |
| 602 | (cmd.flags & |
| 603 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0); |
| 604 | pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n", |
| 605 | cmd.skip_dtim_periods); |
| 606 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) { |
| 607 | pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n", |
| 608 | le32_to_cpu(cmd.rx_data_timeout)); |
| 609 | pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n", |
| 610 | le32_to_cpu(cmd.tx_data_timeout)); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 611 | } |
Alexander Bondar | 175a70b | 2013-04-14 20:59:37 +0300 | [diff] [blame] | 612 | if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK)) |
| 613 | pos += scnprintf(buf+pos, bufsz-pos, |
| 614 | "lprx_rssi_threshold = %d\n", |
| 615 | cmd.lprx_rssi_threshold); |
| 616 | |
| 617 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) |
| 618 | return pos; |
| 619 | |
| 620 | pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n", |
| 621 | le32_to_cpu(cmd.rx_data_timeout_uapsd)); |
| 622 | pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n", |
| 623 | le32_to_cpu(cmd.tx_data_timeout_uapsd)); |
| 624 | pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid); |
| 625 | pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n", |
| 626 | cmd.uapsd_ac_flags); |
| 627 | pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n", |
| 628 | cmd.uapsd_max_sp); |
| 629 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n", |
| 630 | cmd.heavy_tx_thld_packets); |
| 631 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n", |
| 632 | cmd.heavy_rx_thld_packets); |
| 633 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n", |
| 634 | cmd.heavy_tx_thld_percentage); |
| 635 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n", |
| 636 | cmd.heavy_rx_thld_percentage); |
| 637 | pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n", |
| 638 | (cmd.flags & |
| 639 | cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ? |
| 640 | 1 : 0); |
| 641 | |
| 642 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK))) |
| 643 | return pos; |
| 644 | |
| 645 | pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n", |
| 646 | cmd.snooze_interval); |
| 647 | pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n", |
| 648 | cmd.snooze_window); |
| 649 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 650 | return pos; |
| 651 | } |
| 652 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 653 | void |
| 654 | iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif, |
| 655 | struct iwl_beacon_filter_cmd *cmd) |
| 656 | { |
| 657 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 658 | struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf; |
| 659 | |
| 660 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 661 | cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 662 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA) |
| 663 | cmd->bf_roaming_energy_delta = |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 664 | cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 665 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 666 | cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state); |
| 667 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD) |
| 668 | cmd->bf_temp_threshold = |
| 669 | cpu_to_le32(dbgfs_bf->bf_temp_threshold); |
| 670 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER) |
| 671 | cmd->bf_temp_fast_filter = |
| 672 | cpu_to_le32(dbgfs_bf->bf_temp_fast_filter); |
| 673 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER) |
| 674 | cmd->bf_temp_slow_filter = |
| 675 | cpu_to_le32(dbgfs_bf->bf_temp_slow_filter); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 676 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 677 | cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 678 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER) |
| 679 | cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer); |
| 680 | if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER) |
| 681 | cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer); |
| 682 | if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 683 | cmd->ba_enable_beacon_abort = |
| 684 | cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 685 | } |
| 686 | #endif |
| 687 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 688 | int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm, |
| 689 | struct ieee80211_vif *vif) |
| 690 | { |
| 691 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 692 | struct iwl_beacon_filter_cmd cmd = { |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 693 | IWL_BF_CMD_CONFIG_DEFAULTS, |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 694 | .bf_enable_beacon_filter = cpu_to_le32(1), |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 695 | }; |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 696 | int ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 697 | |
| 698 | if (mvmvif != mvm->bf_allowed_vif || |
| 699 | vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 700 | return 0; |
| 701 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 702 | iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 703 | iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 704 | ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); |
| 705 | |
| 706 | if (!ret) |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 707 | mvmvif->bf_data.bf_enabled = true; |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 708 | |
| 709 | return ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm, |
| 713 | struct ieee80211_vif *vif) |
| 714 | { |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 715 | struct iwl_beacon_filter_cmd cmd = {}; |
| 716 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 717 | int ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 718 | |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame] | 719 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) || |
| 720 | vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 721 | return 0; |
| 722 | |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 723 | ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); |
| 724 | |
| 725 | if (!ret) |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 726 | mvmvif->bf_data.bf_enabled = false; |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 727 | |
| 728 | return ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 729 | } |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 730 | |
Andrei Otcheretianski | a20fd39 | 2013-07-21 17:23:59 +0300 | [diff] [blame] | 731 | int iwl_mvm_update_beacon_filter(struct iwl_mvm *mvm, |
| 732 | struct ieee80211_vif *vif) |
| 733 | { |
| 734 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 735 | |
| 736 | if (!mvmvif->bf_data.bf_enabled) |
| 737 | return 0; |
| 738 | |
| 739 | return iwl_mvm_enable_beacon_filter(mvm, vif); |
| 740 | } |
| 741 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 742 | const struct iwl_mvm_power_ops pm_mac_ops = { |
| 743 | .power_update_mode = iwl_mvm_power_mac_update_mode, |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 744 | .power_update_device_mode = iwl_mvm_power_update_device, |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 745 | .power_disable = iwl_mvm_power_mac_disable, |
Alexander Bondar | 1c2abf7 | 2013-08-27 20:31:48 +0300 | [diff] [blame] | 746 | .power_update_binding = _iwl_mvm_power_update_binding, |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 747 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 748 | .power_dbgfs_read = iwl_mvm_power_mac_dbgfs_read, |
| 749 | #endif |
| 750 | }; |