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