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 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 113 | int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm, |
| 114 | struct ieee80211_vif *vif, bool enable) |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 115 | { |
| 116 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 117 | struct iwl_beacon_filter_cmd cmd = { |
| 118 | IWL_BF_CMD_CONFIG_DEFAULTS, |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame^] | 119 | .bf_enable_beacon_filter = cpu_to_le32(1), |
| 120 | .ba_enable_beacon_abort = cpu_to_le32(enable), |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | if (!mvmvif->bf_enabled) |
| 124 | return 0; |
| 125 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 126 | iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 127 | return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); |
| 128 | } |
| 129 | |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 130 | static void iwl_mvm_power_log(struct iwl_mvm *mvm, |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 131 | struct iwl_mac_power_cmd *cmd) |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 132 | { |
| 133 | IWL_DEBUG_POWER(mvm, |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 134 | "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n", |
| 135 | cmd->id_and_color, iwlmvm_mod_params.power_scheme, |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 136 | le16_to_cpu(cmd->flags)); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 137 | IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n", |
| 138 | le16_to_cpu(cmd->keep_alive_seconds)); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 139 | |
| 140 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) { |
| 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)); |
Alexander Bondar | 5b1dbfc | 2013-04-23 13:32:35 +0300 | [diff] [blame] | 145 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) |
Alexander Bondar | 1bd2d17 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 146 | IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n", |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 147 | cmd->skip_dtim_periods); |
Alexander Bondar | bd4ace2 | 2013-03-21 17:14:14 +0200 | [diff] [blame] | 148 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK)) |
| 149 | IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n", |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 150 | cmd->lprx_rssi_threshold); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 154 | static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm, |
| 155 | struct ieee80211_vif *vif, |
| 156 | struct iwl_mac_power_cmd *cmd) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 157 | { |
| 158 | struct ieee80211_hw *hw = mvm->hw; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 159 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 160 | struct ieee80211_channel *chan; |
| 161 | int dtimper, dtimper_msec; |
| 162 | int keep_alive; |
| 163 | bool radar_detect = false; |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 164 | struct iwl_mvm_vif *mvmvif __maybe_unused = |
| 165 | iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 166 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 167 | cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 168 | mvmvif->color)); |
| 169 | dtimper = hw->conf.ps_dtim_period ?: 1; |
| 170 | |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 171 | /* |
| 172 | * Regardless of power management state the driver must set |
| 173 | * keep alive period. FW will use it for sending keep alive NDPs |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 174 | * immediately after association. Check that keep alive period |
| 175 | * is at least 3 * DTIM |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 176 | */ |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 177 | dtimper_msec = dtimper * vif->bss_conf.beacon_int; |
| 178 | keep_alive = max_t(int, 3 * dtimper_msec, |
| 179 | MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC); |
| 180 | keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC); |
| 181 | cmd->keep_alive_seconds = cpu_to_le16(keep_alive); |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 182 | |
Alexander Bondar | ade5065 | 2013-04-03 16:28:47 +0300 | [diff] [blame] | 183 | if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 184 | return; |
| 185 | |
Alexander Bondar | 9a61304 | 2013-03-05 12:54:00 +0200 | [diff] [blame] | 186 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 187 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 188 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 189 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF && |
| 190 | mvmvif->dbgfs_pm.disable_power_off) |
| 191 | cmd->flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 192 | #endif |
Alexander Bondar | 9a61304 | 2013-03-05 12:54:00 +0200 | [diff] [blame] | 193 | if (!vif->bss_conf.ps) |
| 194 | return; |
| 195 | |
| 196 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 197 | |
Alexander Bondar | bd4ace2 | 2013-03-21 17:14:14 +0200 | [diff] [blame] | 198 | if (vif->bss_conf.beacon_rate && |
| 199 | (vif->bss_conf.beacon_rate->bitrate == 10 || |
| 200 | vif->bss_conf.beacon_rate->bitrate == 60)) { |
| 201 | cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 202 | cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD; |
Alexander Bondar | bd4ace2 | 2013-03-21 17:14:14 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 205 | /* Check if radar detection is required on current channel */ |
| 206 | rcu_read_lock(); |
| 207 | chanctx_conf = rcu_dereference(vif->chanctx_conf); |
| 208 | WARN_ON(!chanctx_conf); |
| 209 | if (chanctx_conf) { |
| 210 | chan = chanctx_conf->def.chan; |
| 211 | radar_detect = chan->flags & IEEE80211_CHAN_RADAR; |
| 212 | } |
| 213 | rcu_read_unlock(); |
| 214 | |
| 215 | /* Check skip over DTIM conditions */ |
| 216 | if (!radar_detect && (dtimper <= 10) && |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 217 | (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP || |
| 218 | mvm->cur_ucode == IWL_UCODE_WOWLAN)) { |
Alexander Bondar | f4a3e2f | 2013-03-05 13:47:04 +0200 | [diff] [blame] | 219 | cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 220 | cmd->skip_dtim_periods = 3; |
Alexander Bondar | 5b1dbfc | 2013-04-23 13:32:35 +0300 | [diff] [blame] | 221 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 222 | |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 223 | if (mvm->cur_ucode != IWL_UCODE_WOWLAN) { |
Johannes Berg | 9954592 | 2013-06-14 13:36:21 +0200 | [diff] [blame] | 224 | cmd->rx_data_timeout = |
| 225 | cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT); |
| 226 | cmd->tx_data_timeout = |
| 227 | cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT); |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 228 | } else { |
Johannes Berg | 9954592 | 2013-06-14 13:36:21 +0200 | [diff] [blame] | 229 | cmd->rx_data_timeout = |
| 230 | cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT); |
| 231 | cmd->tx_data_timeout = |
| 232 | cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT); |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 233 | } |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 234 | |
| 235 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 236 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE) |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 237 | cmd->keep_alive_seconds = |
| 238 | cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 239 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) { |
| 240 | if (mvmvif->dbgfs_pm.skip_over_dtim) |
| 241 | cmd->flags |= |
| 242 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
| 243 | else |
| 244 | cmd->flags &= |
| 245 | cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
| 246 | } |
| 247 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT) |
| 248 | cmd->rx_data_timeout = |
| 249 | cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout); |
| 250 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT) |
| 251 | cmd->tx_data_timeout = |
| 252 | cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout); |
| 253 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS) |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 254 | cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods; |
Alexander Bondar | bd4ace2 | 2013-03-21 17:14:14 +0200 | [diff] [blame] | 255 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) { |
| 256 | if (mvmvif->dbgfs_pm.lprx_ena) |
| 257 | cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK); |
| 258 | else |
| 259 | cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK); |
| 260 | } |
| 261 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD) |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 262 | cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold; |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 263 | #endif /* CONFIG_IWLWIFI_DEBUGFS */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 264 | } |
| 265 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 266 | static int iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm, |
| 267 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 268 | { |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 269 | int ret; |
| 270 | bool ba_enable; |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 271 | struct iwl_mac_power_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 272 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 273 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 274 | return 0; |
| 275 | |
Alexander Bondar | 4bf881f | 2013-05-29 10:19:50 +0300 | [diff] [blame] | 276 | /* |
| 277 | * TODO: The following vif_count verification is temporary condition. |
| 278 | * Avoid power mode update if more than one interface is currently |
| 279 | * active. Remove this condition when FW will support power management |
| 280 | * on multiple MACs. |
| 281 | */ |
| 282 | IWL_DEBUG_POWER(mvm, "Currently %d interfaces active\n", |
| 283 | mvm->vif_count); |
| 284 | if (mvm->vif_count > 1) |
| 285 | return 0; |
| 286 | |
Alexander Bondar | f4a3e2f | 2013-03-05 13:47:04 +0200 | [diff] [blame] | 287 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 288 | iwl_mvm_power_log(mvm, &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 289 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 290 | 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] | 291 | sizeof(cmd), &cmd); |
| 292 | if (ret) |
| 293 | return ret; |
| 294 | |
| 295 | ba_enable = !!(cmd.flags & |
| 296 | cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)); |
| 297 | |
| 298 | return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 301 | static int iwl_mvm_power_mac_disable(struct iwl_mvm *mvm, |
| 302 | struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 303 | { |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 304 | struct iwl_mac_power_cmd cmd = {}; |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 305 | struct iwl_mvm_vif *mvmvif __maybe_unused = |
| 306 | iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 307 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 308 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 309 | return 0; |
| 310 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 311 | cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 312 | mvmvif->color)); |
| 313 | |
Alexander Bondar | ade5065 | 2013-04-03 16:28:47 +0300 | [diff] [blame] | 314 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
Alexander Bondar | 9a61304 | 2013-03-05 12:54:00 +0200 | [diff] [blame] | 315 | cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 316 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 317 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 318 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF && |
| 319 | mvmvif->dbgfs_pm.disable_power_off) |
| 320 | cmd.flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 321 | #endif |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 322 | iwl_mvm_power_log(mvm, &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 323 | |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 324 | 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] | 325 | sizeof(cmd), &cmd); |
| 326 | } |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 327 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 328 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 329 | static int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm, |
| 330 | struct ieee80211_vif *vif, char *buf, |
| 331 | int bufsz) |
| 332 | { |
| 333 | struct iwl_mac_power_cmd cmd = {}; |
| 334 | int pos = 0; |
| 335 | |
| 336 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); |
| 337 | |
| 338 | pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n", |
| 339 | (cmd.flags & |
| 340 | cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ? |
| 341 | 0 : 1); |
| 342 | pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n", |
| 343 | cmd.skip_dtim_periods); |
| 344 | pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n", |
| 345 | iwlmvm_mod_params.power_scheme); |
| 346 | pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n", |
| 347 | le16_to_cpu(cmd.flags)); |
| 348 | pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n", |
| 349 | le16_to_cpu(cmd.keep_alive_seconds)); |
| 350 | |
| 351 | if (cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) { |
| 352 | pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n", |
| 353 | (cmd.flags & |
| 354 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? |
| 355 | 1 : 0); |
| 356 | pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n", |
| 357 | le32_to_cpu(cmd.rx_data_timeout)); |
| 358 | pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n", |
| 359 | le32_to_cpu(cmd.tx_data_timeout)); |
| 360 | if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK)) |
| 361 | pos += scnprintf(buf+pos, bufsz-pos, |
| 362 | "lprx_rssi_threshold = %d\n", |
| 363 | cmd.lprx_rssi_threshold); |
| 364 | } |
| 365 | return pos; |
| 366 | } |
| 367 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 368 | void |
| 369 | iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif, |
| 370 | struct iwl_beacon_filter_cmd *cmd) |
| 371 | { |
| 372 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 373 | struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf; |
| 374 | |
| 375 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame^] | 376 | cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 377 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA) |
| 378 | cmd->bf_roaming_energy_delta = |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame^] | 379 | cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 380 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame^] | 381 | cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state); |
| 382 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD) |
| 383 | cmd->bf_temp_threshold = |
| 384 | cpu_to_le32(dbgfs_bf->bf_temp_threshold); |
| 385 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER) |
| 386 | cmd->bf_temp_fast_filter = |
| 387 | cpu_to_le32(dbgfs_bf->bf_temp_fast_filter); |
| 388 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER) |
| 389 | cmd->bf_temp_slow_filter = |
| 390 | cpu_to_le32(dbgfs_bf->bf_temp_slow_filter); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 391 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame^] | 392 | cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 393 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER) |
| 394 | cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer); |
| 395 | if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER) |
| 396 | cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer); |
| 397 | if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT) |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame^] | 398 | cmd->ba_enable_beacon_abort = |
| 399 | cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort); |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 400 | } |
| 401 | #endif |
| 402 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 403 | int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm, |
| 404 | struct ieee80211_vif *vif) |
| 405 | { |
| 406 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 407 | struct iwl_beacon_filter_cmd cmd = { |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 408 | IWL_BF_CMD_CONFIG_DEFAULTS, |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame^] | 409 | .bf_enable_beacon_filter = cpu_to_le32(1), |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 410 | }; |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 411 | int ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 412 | |
| 413 | if (mvmvif != mvm->bf_allowed_vif || |
| 414 | vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 415 | return 0; |
| 416 | |
Alexander Bondar | b571a69 | 2013-05-21 14:49:09 +0300 | [diff] [blame] | 417 | iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd); |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 418 | ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); |
| 419 | |
| 420 | if (!ret) |
| 421 | mvmvif->bf_enabled = true; |
| 422 | |
| 423 | return ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm, |
| 427 | struct ieee80211_vif *vif) |
| 428 | { |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 429 | struct iwl_beacon_filter_cmd cmd = {}; |
| 430 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 431 | int ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 432 | |
Hila Gonen | 5dca7c2 | 2013-07-16 11:15:35 +0300 | [diff] [blame^] | 433 | if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) || |
| 434 | vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 435 | return 0; |
| 436 | |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 437 | ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); |
| 438 | |
| 439 | if (!ret) |
| 440 | mvmvif->bf_enabled = false; |
| 441 | |
| 442 | return ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 443 | } |
Alexander Bondar | e811ada | 2013-03-10 15:29:44 +0200 | [diff] [blame] | 444 | |
| 445 | const struct iwl_mvm_power_ops pm_mac_ops = { |
| 446 | .power_update_mode = iwl_mvm_power_mac_update_mode, |
| 447 | .power_disable = iwl_mvm_power_mac_disable, |
| 448 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 449 | .power_dbgfs_read = iwl_mvm_power_mac_dbgfs_read, |
| 450 | #endif |
| 451 | }; |