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