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 | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 78 | static int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm, |
| 79 | struct iwl_beacon_filter_cmd *cmd) |
| 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 | |
| 109 | static int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm, |
| 110 | struct ieee80211_vif *vif, bool enable) |
| 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 | |
| 122 | return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); |
| 123 | } |
| 124 | |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 125 | static void iwl_mvm_power_log(struct iwl_mvm *mvm, |
| 126 | struct iwl_powertable_cmd *cmd) |
| 127 | { |
| 128 | IWL_DEBUG_POWER(mvm, |
| 129 | "Sending power table command for power level %d, flags = 0x%X\n", |
| 130 | iwlmvm_mod_params.power_scheme, |
| 131 | le16_to_cpu(cmd->flags)); |
| 132 | IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n", cmd->keep_alive_seconds); |
| 133 | |
| 134 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) { |
| 135 | IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n", |
| 136 | le32_to_cpu(cmd->rx_data_timeout)); |
| 137 | IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n", |
| 138 | le32_to_cpu(cmd->tx_data_timeout)); |
| 139 | IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n", |
| 140 | cmd->lprx_rssi_threshold); |
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", |
| 143 | le32_to_cpu(cmd->skip_dtim_periods)); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 144 | } |
| 145 | } |
| 146 | |
Alexander Bondar | 4d1c4b1 | 2013-03-06 16:28:43 +0200 | [diff] [blame] | 147 | void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 148 | struct iwl_powertable_cmd *cmd) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 149 | { |
| 150 | struct ieee80211_hw *hw = mvm->hw; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 151 | struct ieee80211_chanctx_conf *chanctx_conf; |
| 152 | struct ieee80211_channel *chan; |
| 153 | int dtimper, dtimper_msec; |
| 154 | int keep_alive; |
| 155 | bool radar_detect = false; |
| 156 | |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 157 | /* |
| 158 | * Regardless of power management state the driver must set |
| 159 | * keep alive period. FW will use it for sending keep alive NDPs |
| 160 | * immediately after association. |
| 161 | */ |
| 162 | cmd->keep_alive_seconds = POWER_KEEP_ALIVE_PERIOD_SEC; |
| 163 | |
Alexander Bondar | ade5065 | 2013-04-03 16:28:47 +0300 | [diff] [blame] | 164 | if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 165 | return; |
| 166 | |
Alexander Bondar | 9a61304 | 2013-03-05 12:54:00 +0200 | [diff] [blame] | 167 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 168 | |
| 169 | if (!vif->bss_conf.ps) |
| 170 | return; |
| 171 | |
| 172 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 173 | |
| 174 | dtimper = hw->conf.ps_dtim_period ?: 1; |
| 175 | |
| 176 | /* Check if radar detection is required on current channel */ |
| 177 | rcu_read_lock(); |
| 178 | chanctx_conf = rcu_dereference(vif->chanctx_conf); |
| 179 | WARN_ON(!chanctx_conf); |
| 180 | if (chanctx_conf) { |
| 181 | chan = chanctx_conf->def.chan; |
| 182 | radar_detect = chan->flags & IEEE80211_CHAN_RADAR; |
| 183 | } |
| 184 | rcu_read_unlock(); |
| 185 | |
| 186 | /* Check skip over DTIM conditions */ |
| 187 | if (!radar_detect && (dtimper <= 10) && |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 188 | (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP || |
| 189 | mvm->cur_ucode == IWL_UCODE_WOWLAN)) { |
Alexander Bondar | f4a3e2f | 2013-03-05 13:47:04 +0200 | [diff] [blame] | 190 | cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
Alexander Bondar | 1bd2d17 | 2013-05-21 14:49:09 +0300 | [diff] [blame^] | 191 | cmd->skip_dtim_periods = cpu_to_le32(3); |
Alexander Bondar | 5b1dbfc | 2013-04-23 13:32:35 +0300 | [diff] [blame] | 192 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 193 | |
| 194 | /* Check that keep alive period is at least 3 * DTIM */ |
| 195 | dtimper_msec = dtimper * vif->bss_conf.beacon_int; |
| 196 | keep_alive = max_t(int, 3 * dtimper_msec, |
Alexander Bondar | e16cf7e | 2013-03-05 14:01:27 +0200 | [diff] [blame] | 197 | MSEC_PER_SEC * cmd->keep_alive_seconds); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 198 | keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC); |
Alexander Bondar | 83bdad5 | 2013-02-03 21:26:44 +0200 | [diff] [blame] | 199 | cmd->keep_alive_seconds = keep_alive; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 200 | |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 201 | if (mvm->cur_ucode != IWL_UCODE_WOWLAN) { |
| 202 | cmd->rx_data_timeout = cpu_to_le32(100 * USEC_PER_MSEC); |
| 203 | cmd->tx_data_timeout = cpu_to_le32(100 * USEC_PER_MSEC); |
| 204 | } else { |
| 205 | cmd->rx_data_timeout = cpu_to_le32(10 * USEC_PER_MSEC); |
| 206 | cmd->tx_data_timeout = cpu_to_le32(10 * USEC_PER_MSEC); |
| 207 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | int iwl_mvm_power_update_mode(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 211 | { |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 212 | int ret; |
| 213 | bool ba_enable; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 214 | struct iwl_powertable_cmd cmd = {}; |
| 215 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 216 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 217 | return 0; |
| 218 | |
Alexander Bondar | f4a3e2f | 2013-03-05 13:47:04 +0200 | [diff] [blame] | 219 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 220 | iwl_mvm_power_log(mvm, &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 221 | |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 222 | ret = iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_SYNC, |
| 223 | sizeof(cmd), &cmd); |
| 224 | if (ret) |
| 225 | return ret; |
| 226 | |
| 227 | ba_enable = !!(cmd.flags & |
| 228 | cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)); |
| 229 | |
| 230 | return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | int iwl_mvm_power_disable(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 234 | { |
| 235 | struct iwl_powertable_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 236 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 237 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 238 | return 0; |
| 239 | |
Alexander Bondar | ade5065 | 2013-04-03 16:28:47 +0300 | [diff] [blame] | 240 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
Alexander Bondar | 9a61304 | 2013-03-05 12:54:00 +0200 | [diff] [blame] | 241 | cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK); |
| 242 | |
Alexander Bondar | 3f0b2b3 | 2013-03-05 14:08:23 +0200 | [diff] [blame] | 243 | iwl_mvm_power_log(mvm, &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 244 | |
Emmanuel Grumbach | 5360cfb | 2013-02-11 15:56:01 +0200 | [diff] [blame] | 245 | return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_ASYNC, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 246 | sizeof(cmd), &cmd); |
| 247 | } |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 248 | |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 249 | int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm, |
| 250 | struct ieee80211_vif *vif) |
| 251 | { |
| 252 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 253 | struct iwl_beacon_filter_cmd cmd = { |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 254 | IWL_BF_CMD_CONFIG_DEFAULTS, |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 255 | .bf_enable_beacon_filter = 1, |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 256 | }; |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 257 | int ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 258 | |
| 259 | if (mvmvif != mvm->bf_allowed_vif || |
| 260 | vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 261 | return 0; |
| 262 | |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 263 | ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); |
| 264 | |
| 265 | if (!ret) |
| 266 | mvmvif->bf_enabled = true; |
| 267 | |
| 268 | return ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm, |
| 272 | struct ieee80211_vif *vif) |
| 273 | { |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 274 | struct iwl_beacon_filter_cmd cmd = {}; |
| 275 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 276 | int ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 277 | |
| 278 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 279 | return 0; |
| 280 | |
Alexander Bondar | 071d4990 | 2013-05-06 13:03:59 +0300 | [diff] [blame] | 281 | ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); |
| 282 | |
| 283 | if (!ret) |
| 284 | mvmvif->bf_enabled = false; |
| 285 | |
| 286 | return ret; |
Hila Gonen | 7df15b1 | 2012-12-12 11:16:19 +0200 | [diff] [blame] | 287 | } |