blob: 9c9b5bafb57792c665074d07e0240b62153de25e [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
Alexander Bondare3c588e2013-04-07 14:08:59 +0300143 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
144 IWL_DEBUG_POWER(mvm, "Disable power management\n");
145 return;
146 }
147
148 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
149 le32_to_cpu(cmd->rx_data_timeout));
150 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
151 le32_to_cpu(cmd->tx_data_timeout));
152 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
153 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
154 cmd->skip_dtim_periods);
155 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
156 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
157 cmd->lprx_rssi_threshold);
158 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
159 IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
160 IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
161 le32_to_cpu(cmd->rx_data_timeout_uapsd));
162 IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
163 le32_to_cpu(cmd->tx_data_timeout_uapsd));
164 IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
165 IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
166 IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200167 }
168}
169
Alexander Bondare811ada2013-03-10 15:29:44 +0200170static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
171 struct ieee80211_vif *vif,
172 struct iwl_mac_power_cmd *cmd)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100173{
174 struct ieee80211_hw *hw = mvm->hw;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100175 struct ieee80211_chanctx_conf *chanctx_conf;
176 struct ieee80211_channel *chan;
177 int dtimper, dtimper_msec;
178 int keep_alive;
179 bool radar_detect = false;
Alexander Bondarb571a692013-05-21 14:49:09 +0300180 struct iwl_mvm_vif *mvmvif __maybe_unused =
181 iwl_mvm_vif_from_mac80211(vif);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300182 enum ieee80211_ac_numbers ac;
183 bool tid_found = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100184
Alexander Bondare811ada2013-03-10 15:29:44 +0200185 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
186 mvmvif->color));
187 dtimper = hw->conf.ps_dtim_period ?: 1;
188
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200189 /*
190 * Regardless of power management state the driver must set
191 * keep alive period. FW will use it for sending keep alive NDPs
Alexander Bondare811ada2013-03-10 15:29:44 +0200192 * immediately after association. Check that keep alive period
193 * is at least 3 * DTIM
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200194 */
Alexander Bondare811ada2013-03-10 15:29:44 +0200195 dtimper_msec = dtimper * vif->bss_conf.beacon_int;
196 keep_alive = max_t(int, 3 * dtimper_msec,
197 MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
198 keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
199 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200200
Alexander Bondarade50652013-04-03 16:28:47 +0300201 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100202 return;
203
Alexander Bondar9a613042013-03-05 12:54:00 +0200204 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
205
Alexander Bondarb571a692013-05-21 14:49:09 +0300206#ifdef CONFIG_IWLWIFI_DEBUGFS
207 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
208 mvmvif->dbgfs_pm.disable_power_off)
209 cmd->flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
210#endif
Alexander Bondar9a613042013-03-05 12:54:00 +0200211 if (!vif->bss_conf.ps)
212 return;
213
214 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100215
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200216 if (vif->bss_conf.beacon_rate &&
217 (vif->bss_conf.beacon_rate->bitrate == 10 ||
218 vif->bss_conf.beacon_rate->bitrate == 60)) {
219 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200220 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200221 }
222
Johannes Berg8ca151b2013-01-24 14:25:36 +0100223 /* Check if radar detection is required on current channel */
224 rcu_read_lock();
225 chanctx_conf = rcu_dereference(vif->chanctx_conf);
226 WARN_ON(!chanctx_conf);
227 if (chanctx_conf) {
228 chan = chanctx_conf->def.chan;
229 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
230 }
231 rcu_read_unlock();
232
233 /* Check skip over DTIM conditions */
234 if (!radar_detect && (dtimper <= 10) &&
Alexander Bondaree1e8422013-04-23 13:52:10 +0300235 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
236 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200237 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200238 cmd->skip_dtim_periods = 3;
Alexander Bondar5b1dbfc2013-04-23 13:32:35 +0300239 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100240
Alexander Bondaree1e8422013-04-23 13:52:10 +0300241 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
Johannes Berg99545922013-06-14 13:36:21 +0200242 cmd->rx_data_timeout =
243 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
244 cmd->tx_data_timeout =
245 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300246 } else {
Johannes Berg99545922013-06-14 13:36:21 +0200247 cmd->rx_data_timeout =
248 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
249 cmd->tx_data_timeout =
250 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300251 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300252
Alexander Bondare3c588e2013-04-07 14:08:59 +0300253 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
254 if (!mvmvif->queue_params[ac].uapsd)
255 continue;
256
257 cmd->flags |= cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
258 cmd->uapsd_ac_flags |= BIT(ac);
259
260 /* QNDP TID - the highest TID with no admission control */
261 if (!tid_found && !mvmvif->queue_params[ac].acm) {
262 tid_found = true;
263 switch (ac) {
264 case IEEE80211_AC_VO:
265 cmd->qndp_tid = 6;
266 break;
267 case IEEE80211_AC_VI:
268 cmd->qndp_tid = 5;
269 break;
270 case IEEE80211_AC_BE:
271 cmd->qndp_tid = 0;
272 break;
273 case IEEE80211_AC_BK:
274 cmd->qndp_tid = 1;
275 break;
276 }
277 }
278 }
279
280 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
281 cmd->rx_data_timeout_uapsd =
282 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
283 cmd->tx_data_timeout_uapsd =
284 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
285 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
286 cmd->heavy_tx_thld_packets =
287 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
288 cmd->heavy_rx_thld_packets =
289 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
290 cmd->heavy_tx_thld_percentage =
291 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
292 cmd->heavy_rx_thld_percentage =
293 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
294 }
295
Alexander Bondarb571a692013-05-21 14:49:09 +0300296#ifdef CONFIG_IWLWIFI_DEBUGFS
297 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200298 cmd->keep_alive_seconds =
299 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300300 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
301 if (mvmvif->dbgfs_pm.skip_over_dtim)
302 cmd->flags |=
303 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
304 else
305 cmd->flags &=
306 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
307 }
308 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
309 cmd->rx_data_timeout =
310 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
311 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
312 cmd->tx_data_timeout =
313 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
314 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200315 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200316 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
317 if (mvmvif->dbgfs_pm.lprx_ena)
318 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
319 else
320 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
321 }
322 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200323 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondarb571a692013-05-21 14:49:09 +0300324#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100325}
326
Alexander Bondare811ada2013-03-10 15:29:44 +0200327static int iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm,
328 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100329{
Alexander Bondar071d49902013-05-06 13:03:59 +0300330 int ret;
331 bool ba_enable;
Alexander Bondare811ada2013-03-10 15:29:44 +0200332 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100333
Johannes Berg8ca151b2013-01-24 14:25:36 +0100334 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
335 return 0;
336
Alexander Bondar4bf881f2013-05-29 10:19:50 +0300337 /*
338 * TODO: The following vif_count verification is temporary condition.
339 * Avoid power mode update if more than one interface is currently
340 * active. Remove this condition when FW will support power management
341 * on multiple MACs.
342 */
343 IWL_DEBUG_POWER(mvm, "Currently %d interfaces active\n",
344 mvm->vif_count);
345 if (mvm->vif_count > 1)
346 return 0;
347
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200348 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200349 iwl_mvm_power_log(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100350
Alexander Bondare811ada2013-03-10 15:29:44 +0200351 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC,
Alexander Bondar071d49902013-05-06 13:03:59 +0300352 sizeof(cmd), &cmd);
353 if (ret)
354 return ret;
355
356 ba_enable = !!(cmd.flags &
357 cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK));
358
359 return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100360}
361
Alexander Bondare811ada2013-03-10 15:29:44 +0200362static int iwl_mvm_power_mac_disable(struct iwl_mvm *mvm,
363 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100364{
Alexander Bondare811ada2013-03-10 15:29:44 +0200365 struct iwl_mac_power_cmd cmd = {};
Alexander Bondarb571a692013-05-21 14:49:09 +0300366 struct iwl_mvm_vif *mvmvif __maybe_unused =
367 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100368
Johannes Berg8ca151b2013-01-24 14:25:36 +0100369 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
370 return 0;
371
Alexander Bondare811ada2013-03-10 15:29:44 +0200372 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
373 mvmvif->color));
374
Alexander Bondarade50652013-04-03 16:28:47 +0300375 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Alexander Bondar9a613042013-03-05 12:54:00 +0200376 cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
377
Alexander Bondarb571a692013-05-21 14:49:09 +0300378#ifdef CONFIG_IWLWIFI_DEBUGFS
379 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
380 mvmvif->dbgfs_pm.disable_power_off)
381 cmd.flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
382#endif
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200383 iwl_mvm_power_log(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100384
Alexander Bondare811ada2013-03-10 15:29:44 +0200385 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_ASYNC,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100386 sizeof(cmd), &cmd);
387}
Hila Gonen7df15b12012-12-12 11:16:19 +0200388
Alexander Bondarb571a692013-05-21 14:49:09 +0300389#ifdef CONFIG_IWLWIFI_DEBUGFS
Alexander Bondare811ada2013-03-10 15:29:44 +0200390static int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
391 struct ieee80211_vif *vif, char *buf,
392 int bufsz)
393{
394 struct iwl_mac_power_cmd cmd = {};
395 int pos = 0;
396
397 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
398
399 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n",
400 (cmd.flags &
401 cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ?
402 0 : 1);
Alexander Bondare811ada2013-03-10 15:29:44 +0200403 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
404 iwlmvm_mod_params.power_scheme);
405 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
406 le16_to_cpu(cmd.flags));
407 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
408 le16_to_cpu(cmd.keep_alive_seconds));
409
410 if (cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) {
411 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
412 (cmd.flags &
413 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ?
414 1 : 0);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300415 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
416 cmd.skip_dtim_periods);
417 if (!(cmd.flags &
418 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
419 pos += scnprintf(buf+pos, bufsz-pos,
420 "rx_data_timeout = %d\n",
421 le32_to_cpu(cmd.rx_data_timeout));
422 pos += scnprintf(buf+pos, bufsz-pos,
423 "tx_data_timeout = %d\n",
424 le32_to_cpu(cmd.tx_data_timeout));
425 }
Alexander Bondare811ada2013-03-10 15:29:44 +0200426 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
427 pos += scnprintf(buf+pos, bufsz-pos,
428 "lprx_rssi_threshold = %d\n",
429 cmd.lprx_rssi_threshold);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300430 if (cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
431 pos +=
432 scnprintf(buf+pos, bufsz-pos,
433 "rx_data_timeout_uapsd = %d\n",
434 le32_to_cpu(cmd.rx_data_timeout_uapsd));
435 pos +=
436 scnprintf(buf+pos, bufsz-pos,
437 "tx_data_timeout_uapsd = %d\n",
438 le32_to_cpu(cmd.tx_data_timeout_uapsd));
439 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n",
440 cmd.qndp_tid);
441 pos += scnprintf(buf+pos, bufsz-pos,
442 "uapsd_ac_flags = 0x%x\n",
443 cmd.uapsd_ac_flags);
444 pos += scnprintf(buf+pos, bufsz-pos,
445 "uapsd_max_sp = %d\n",
446 cmd.uapsd_max_sp);
447 pos += scnprintf(buf+pos, bufsz-pos,
448 "heavy_tx_thld_packets = %d\n",
449 cmd.heavy_tx_thld_packets);
450 pos += scnprintf(buf+pos, bufsz-pos,
451 "heavy_rx_thld_packets = %d\n",
452 cmd.heavy_rx_thld_packets);
453 pos += scnprintf(buf+pos, bufsz-pos,
454 "heavy_tx_thld_percentage = %d\n",
455 cmd.heavy_tx_thld_percentage);
456 pos += scnprintf(buf+pos, bufsz-pos,
457 "heavy_rx_thld_percentage = %d\n",
458 cmd.heavy_rx_thld_percentage);
459 }
Alexander Bondare811ada2013-03-10 15:29:44 +0200460 }
461 return pos;
462}
463
Alexander Bondarb571a692013-05-21 14:49:09 +0300464void
465iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
466 struct iwl_beacon_filter_cmd *cmd)
467{
468 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
469 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
470
471 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300472 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300473 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
474 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300475 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300476 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300477 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
478 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
479 cmd->bf_temp_threshold =
480 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
481 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
482 cmd->bf_temp_fast_filter =
483 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
484 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
485 cmd->bf_temp_slow_filter =
486 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300487 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300488 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300489 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
490 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
491 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
492 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
493 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300494 cmd->ba_enable_beacon_abort =
495 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300496}
497#endif
498
Hila Gonen7df15b12012-12-12 11:16:19 +0200499int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
500 struct ieee80211_vif *vif)
501{
502 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
503 struct iwl_beacon_filter_cmd cmd = {
Alexander Bondar071d49902013-05-06 13:03:59 +0300504 IWL_BF_CMD_CONFIG_DEFAULTS,
Hila Gonen5dca7c22013-07-16 11:15:35 +0300505 .bf_enable_beacon_filter = cpu_to_le32(1),
Hila Gonen7df15b12012-12-12 11:16:19 +0200506 };
Alexander Bondar071d49902013-05-06 13:03:59 +0300507 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200508
509 if (mvmvif != mvm->bf_allowed_vif ||
510 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
511 return 0;
512
Alexander Bondarb571a692013-05-21 14:49:09 +0300513 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
Alexander Bondar071d49902013-05-06 13:03:59 +0300514 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
515
516 if (!ret)
517 mvmvif->bf_enabled = true;
518
519 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200520}
521
522int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
523 struct ieee80211_vif *vif)
524{
Alexander Bondar071d49902013-05-06 13:03:59 +0300525 struct iwl_beacon_filter_cmd cmd = {};
526 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
527 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200528
Hila Gonen5dca7c22013-07-16 11:15:35 +0300529 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) ||
530 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200531 return 0;
532
Alexander Bondar071d49902013-05-06 13:03:59 +0300533 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
534
535 if (!ret)
536 mvmvif->bf_enabled = false;
537
538 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200539}
Alexander Bondare811ada2013-03-10 15:29:44 +0200540
541const struct iwl_mvm_power_ops pm_mac_ops = {
542 .power_update_mode = iwl_mvm_power_mac_update_mode,
543 .power_disable = iwl_mvm_power_mac_disable,
544#ifdef CONFIG_IWLWIFI_DEBUGFS
545 .power_dbgfs_read = iwl_mvm_power_mac_dbgfs_read,
546#endif
547};