blob: 4e7c9f24584686ce31c9f3cee57295bcf9d89a57 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
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 Bondare811ada2013-03-10 15:29:44 +020078int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
79 struct iwl_beacon_filter_cmd *cmd)
Alexander Bondar071d49902013-05-06 13:03:59 +030080{
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 Gonen5dca7c22013-07-16 11:15:35 +030088 le32_to_cpu(cmd->ba_enable_beacon_abort));
Alexander Bondar071d49902013-05-06 13:03:59 +030089 IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +030090 le32_to_cpu(cmd->ba_escape_timer));
Alexander Bondar071d49902013-05-06 13:03:59 +030091 IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +030092 le32_to_cpu(cmd->bf_debug_flag));
Alexander Bondar071d49902013-05-06 13:03:59 +030093 IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +030094 le32_to_cpu(cmd->bf_enable_beacon_filter));
Alexander Bondar071d49902013-05-06 13:03:59 +030095 IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +030096 le32_to_cpu(cmd->bf_energy_delta));
Alexander Bondar071d49902013-05-06 13:03:59 +030097 IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +030098 le32_to_cpu(cmd->bf_escape_timer));
Alexander Bondar071d49902013-05-06 13:03:59 +030099 IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +0300100 le32_to_cpu(cmd->bf_roaming_energy_delta));
Alexander Bondar071d49902013-05-06 13:03:59 +0300101 IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
Hila Gonen5dca7c22013-07-16 11:15:35 +0300102 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 Bondar071d49902013-05-06 13:03:59 +0300109 }
110 return ret;
111}
112
Alexander Bondare811ada2013-03-10 15:29:44 +0200113int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
114 struct ieee80211_vif *vif, bool enable)
Alexander Bondar071d49902013-05-06 13:03:59 +0300115{
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 Gonen5dca7c22013-07-16 11:15:35 +0300119 .bf_enable_beacon_filter = cpu_to_le32(1),
120 .ba_enable_beacon_abort = cpu_to_le32(enable),
Alexander Bondar071d49902013-05-06 13:03:59 +0300121 };
122
123 if (!mvmvif->bf_enabled)
124 return 0;
125
Alexander Bondar84349252013-07-22 15:39:26 +0300126 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
127 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
128
Alexander Bondarb571a692013-05-21 14:49:09 +0300129 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
Alexander Bondar071d49902013-05-06 13:03:59 +0300130 return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
131}
132
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200133static void iwl_mvm_power_log(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200134 struct iwl_mac_power_cmd *cmd)
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200135{
136 IWL_DEBUG_POWER(mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200137 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
138 cmd->id_and_color, iwlmvm_mod_params.power_scheme,
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200139 le16_to_cpu(cmd->flags));
Alexander Bondare811ada2013-03-10 15:29:44 +0200140 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
141 le16_to_cpu(cmd->keep_alive_seconds));
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200142
143 if (cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) {
144 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
145 le32_to_cpu(cmd->rx_data_timeout));
146 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
147 le32_to_cpu(cmd->tx_data_timeout));
Alexander Bondar5b1dbfc2013-04-23 13:32:35 +0300148 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
Alexander Bondar1bd2d172013-05-21 14:49:09 +0300149 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
Alexander Bondare811ada2013-03-10 15:29:44 +0200150 cmd->skip_dtim_periods);
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200151 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
152 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
Alexander Bondare811ada2013-03-10 15:29:44 +0200153 cmd->lprx_rssi_threshold);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200154 }
155}
156
Alexander Bondare811ada2013-03-10 15:29:44 +0200157static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
158 struct ieee80211_vif *vif,
159 struct iwl_mac_power_cmd *cmd)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100160{
161 struct ieee80211_hw *hw = mvm->hw;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100162 struct ieee80211_chanctx_conf *chanctx_conf;
163 struct ieee80211_channel *chan;
164 int dtimper, dtimper_msec;
165 int keep_alive;
166 bool radar_detect = false;
Alexander Bondarb571a692013-05-21 14:49:09 +0300167 struct iwl_mvm_vif *mvmvif __maybe_unused =
168 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100169
Alexander Bondare811ada2013-03-10 15:29:44 +0200170 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
171 mvmvif->color));
172 dtimper = hw->conf.ps_dtim_period ?: 1;
173
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200174 /*
175 * Regardless of power management state the driver must set
176 * keep alive period. FW will use it for sending keep alive NDPs
Alexander Bondare811ada2013-03-10 15:29:44 +0200177 * immediately after association. Check that keep alive period
178 * is at least 3 * DTIM
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200179 */
Alexander Bondare811ada2013-03-10 15:29:44 +0200180 dtimper_msec = dtimper * vif->bss_conf.beacon_int;
181 keep_alive = max_t(int, 3 * dtimper_msec,
182 MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
183 keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
184 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200185
Alexander Bondarade50652013-04-03 16:28:47 +0300186 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100187 return;
188
Alexander Bondar9a613042013-03-05 12:54:00 +0200189 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
190
Alexander Bondarb571a692013-05-21 14:49:09 +0300191#ifdef CONFIG_IWLWIFI_DEBUGFS
192 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
193 mvmvif->dbgfs_pm.disable_power_off)
194 cmd->flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
195#endif
Alexander Bondar9a613042013-03-05 12:54:00 +0200196 if (!vif->bss_conf.ps)
197 return;
198
199 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100200
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200201 if (vif->bss_conf.beacon_rate &&
202 (vif->bss_conf.beacon_rate->bitrate == 10 ||
203 vif->bss_conf.beacon_rate->bitrate == 60)) {
204 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200205 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200206 }
207
Johannes Berg8ca151b2013-01-24 14:25:36 +0100208 /* Check if radar detection is required on current channel */
209 rcu_read_lock();
210 chanctx_conf = rcu_dereference(vif->chanctx_conf);
211 WARN_ON(!chanctx_conf);
212 if (chanctx_conf) {
213 chan = chanctx_conf->def.chan;
214 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
215 }
216 rcu_read_unlock();
217
218 /* Check skip over DTIM conditions */
219 if (!radar_detect && (dtimper <= 10) &&
Alexander Bondaree1e8422013-04-23 13:52:10 +0300220 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
221 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200222 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200223 cmd->skip_dtim_periods = 3;
Alexander Bondar5b1dbfc2013-04-23 13:32:35 +0300224 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100225
Alexander Bondaree1e8422013-04-23 13:52:10 +0300226 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
Johannes Berg99545922013-06-14 13:36:21 +0200227 cmd->rx_data_timeout =
228 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
229 cmd->tx_data_timeout =
230 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300231 } else {
Johannes Berg99545922013-06-14 13:36:21 +0200232 cmd->rx_data_timeout =
233 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
234 cmd->tx_data_timeout =
235 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300236 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300237
238#ifdef CONFIG_IWLWIFI_DEBUGFS
239 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200240 cmd->keep_alive_seconds =
241 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300242 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
243 if (mvmvif->dbgfs_pm.skip_over_dtim)
244 cmd->flags |=
245 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
246 else
247 cmd->flags &=
248 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
249 }
250 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
251 cmd->rx_data_timeout =
252 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
253 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
254 cmd->tx_data_timeout =
255 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
256 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200257 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200258 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
259 if (mvmvif->dbgfs_pm.lprx_ena)
260 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
261 else
262 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
263 }
264 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200265 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondarb571a692013-05-21 14:49:09 +0300266#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100267}
268
Alexander Bondare811ada2013-03-10 15:29:44 +0200269static int iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm,
270 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100271{
Alexander Bondar071d49902013-05-06 13:03:59 +0300272 int ret;
273 bool ba_enable;
Alexander Bondare811ada2013-03-10 15:29:44 +0200274 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100275
Johannes Berg8ca151b2013-01-24 14:25:36 +0100276 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
277 return 0;
278
Alexander Bondar4bf881f2013-05-29 10:19:50 +0300279 /*
280 * TODO: The following vif_count verification is temporary condition.
281 * Avoid power mode update if more than one interface is currently
282 * active. Remove this condition when FW will support power management
283 * on multiple MACs.
284 */
285 IWL_DEBUG_POWER(mvm, "Currently %d interfaces active\n",
286 mvm->vif_count);
287 if (mvm->vif_count > 1)
288 return 0;
289
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200290 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200291 iwl_mvm_power_log(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100292
Alexander Bondare811ada2013-03-10 15:29:44 +0200293 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC,
Alexander Bondar071d49902013-05-06 13:03:59 +0300294 sizeof(cmd), &cmd);
295 if (ret)
296 return ret;
297
298 ba_enable = !!(cmd.flags &
299 cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK));
300
301 return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100302}
303
Alexander Bondare811ada2013-03-10 15:29:44 +0200304static int iwl_mvm_power_mac_disable(struct iwl_mvm *mvm,
305 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100306{
Alexander Bondare811ada2013-03-10 15:29:44 +0200307 struct iwl_mac_power_cmd cmd = {};
Alexander Bondarb571a692013-05-21 14:49:09 +0300308 struct iwl_mvm_vif *mvmvif __maybe_unused =
309 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100310
Johannes Berg8ca151b2013-01-24 14:25:36 +0100311 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
312 return 0;
313
Alexander Bondare811ada2013-03-10 15:29:44 +0200314 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
315 mvmvif->color));
316
Alexander Bondarade50652013-04-03 16:28:47 +0300317 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Alexander Bondar9a613042013-03-05 12:54:00 +0200318 cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
319
Alexander Bondarb571a692013-05-21 14:49:09 +0300320#ifdef CONFIG_IWLWIFI_DEBUGFS
321 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
322 mvmvif->dbgfs_pm.disable_power_off)
323 cmd.flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
324#endif
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200325 iwl_mvm_power_log(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100326
Alexander Bondare811ada2013-03-10 15:29:44 +0200327 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_ASYNC,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100328 sizeof(cmd), &cmd);
329}
Hila Gonen7df15b12012-12-12 11:16:19 +0200330
Alexander Bondarb571a692013-05-21 14:49:09 +0300331#ifdef CONFIG_IWLWIFI_DEBUGFS
Alexander Bondare811ada2013-03-10 15:29:44 +0200332static int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
333 struct ieee80211_vif *vif, char *buf,
334 int bufsz)
335{
336 struct iwl_mac_power_cmd cmd = {};
337 int pos = 0;
338
339 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
340
341 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n",
342 (cmd.flags &
343 cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ?
344 0 : 1);
345 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
346 cmd.skip_dtim_periods);
347 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
348 iwlmvm_mod_params.power_scheme);
349 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
350 le16_to_cpu(cmd.flags));
351 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
352 le16_to_cpu(cmd.keep_alive_seconds));
353
354 if (cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) {
355 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
356 (cmd.flags &
357 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ?
358 1 : 0);
359 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
360 le32_to_cpu(cmd.rx_data_timeout));
361 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
362 le32_to_cpu(cmd.tx_data_timeout));
363 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
364 pos += scnprintf(buf+pos, bufsz-pos,
365 "lprx_rssi_threshold = %d\n",
366 cmd.lprx_rssi_threshold);
367 }
368 return pos;
369}
370
Alexander Bondarb571a692013-05-21 14:49:09 +0300371void
372iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
373 struct iwl_beacon_filter_cmd *cmd)
374{
375 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
376 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
377
378 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300379 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300380 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
381 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300382 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300383 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300384 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
385 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
386 cmd->bf_temp_threshold =
387 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
388 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
389 cmd->bf_temp_fast_filter =
390 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
391 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
392 cmd->bf_temp_slow_filter =
393 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300394 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300395 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300396 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
397 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
398 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
399 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
400 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300401 cmd->ba_enable_beacon_abort =
402 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300403}
404#endif
405
Hila Gonen7df15b12012-12-12 11:16:19 +0200406int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
407 struct ieee80211_vif *vif)
408{
409 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
410 struct iwl_beacon_filter_cmd cmd = {
Alexander Bondar071d49902013-05-06 13:03:59 +0300411 IWL_BF_CMD_CONFIG_DEFAULTS,
Hila Gonen5dca7c22013-07-16 11:15:35 +0300412 .bf_enable_beacon_filter = cpu_to_le32(1),
Hila Gonen7df15b12012-12-12 11:16:19 +0200413 };
Alexander Bondar071d49902013-05-06 13:03:59 +0300414 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200415
416 if (mvmvif != mvm->bf_allowed_vif ||
417 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
418 return 0;
419
Alexander Bondarb571a692013-05-21 14:49:09 +0300420 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
Alexander Bondar071d49902013-05-06 13:03:59 +0300421 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
422
423 if (!ret)
424 mvmvif->bf_enabled = true;
425
426 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200427}
428
429int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
430 struct ieee80211_vif *vif)
431{
Alexander Bondar071d49902013-05-06 13:03:59 +0300432 struct iwl_beacon_filter_cmd cmd = {};
433 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
434 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200435
Hila Gonen5dca7c22013-07-16 11:15:35 +0300436 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) ||
437 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200438 return 0;
439
Alexander Bondar071d49902013-05-06 13:03:59 +0300440 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
441
442 if (!ret)
443 mvmvif->bf_enabled = false;
444
445 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200446}
Alexander Bondare811ada2013-03-10 15:29:44 +0200447
448const struct iwl_mvm_power_ops pm_mac_ops = {
449 .power_update_mode = iwl_mvm_power_mac_update_mode,
450 .power_disable = iwl_mvm_power_mac_disable,
451#ifdef CONFIG_IWLWIFI_DEBUGFS
452 .power_dbgfs_read = iwl_mvm_power_mac_dbgfs_read,
453#endif
454};