blob: 80d5f88a9d321b080c8cc63a4f0b58b0a35f0d0f [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
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300113static
114void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
115 struct ieee80211_vif *vif,
116 struct iwl_beacon_filter_cmd *cmd)
117{
118 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
119
120 if (vif->bss_conf.cqm_rssi_thold) {
121 cmd->bf_energy_delta =
122 cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
123 /* fw uses an absolute value for this */
124 cmd->bf_roaming_state =
125 cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
126 }
127 cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
128}
129
Alexander Bondare811ada2013-03-10 15:29:44 +0200130int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
131 struct ieee80211_vif *vif, bool enable)
Alexander Bondar071d49902013-05-06 13:03:59 +0300132{
133 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
134 struct iwl_beacon_filter_cmd cmd = {
135 IWL_BF_CMD_CONFIG_DEFAULTS,
Hila Gonen5dca7c22013-07-16 11:15:35 +0300136 .bf_enable_beacon_filter = cpu_to_le32(1),
137 .ba_enable_beacon_abort = cpu_to_le32(enable),
Alexander Bondar071d49902013-05-06 13:03:59 +0300138 };
139
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300140 if (!mvmvif->bf_data.bf_enabled)
Alexander Bondar071d49902013-05-06 13:03:59 +0300141 return 0;
142
Alexander Bondar84349252013-07-22 15:39:26 +0300143 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
144 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
145
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300146 mvmvif->bf_data.ba_enabled = enable;
147 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
Alexander Bondarb571a692013-05-21 14:49:09 +0300148 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
Alexander Bondar071d49902013-05-06 13:03:59 +0300149 return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
150}
151
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200152static void iwl_mvm_power_log(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200153 struct iwl_mac_power_cmd *cmd)
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200154{
155 IWL_DEBUG_POWER(mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200156 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
157 cmd->id_and_color, iwlmvm_mod_params.power_scheme,
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200158 le16_to_cpu(cmd->flags));
Alexander Bondare811ada2013-03-10 15:29:44 +0200159 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
160 le16_to_cpu(cmd->keep_alive_seconds));
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200161
Alexander Bondare3c588e2013-04-07 14:08:59 +0300162 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
163 IWL_DEBUG_POWER(mvm, "Disable power management\n");
164 return;
165 }
166
167 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
168 le32_to_cpu(cmd->rx_data_timeout));
169 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
170 le32_to_cpu(cmd->tx_data_timeout));
171 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
172 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
173 cmd->skip_dtim_periods);
174 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
175 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
176 cmd->lprx_rssi_threshold);
177 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
178 IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
179 IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
180 le32_to_cpu(cmd->rx_data_timeout_uapsd));
181 IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
182 le32_to_cpu(cmd->tx_data_timeout_uapsd));
183 IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
184 IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
185 IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200186 }
187}
188
Alexander Bondare811ada2013-03-10 15:29:44 +0200189static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
190 struct ieee80211_vif *vif,
191 struct iwl_mac_power_cmd *cmd)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100192{
193 struct ieee80211_hw *hw = mvm->hw;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100194 struct ieee80211_chanctx_conf *chanctx_conf;
195 struct ieee80211_channel *chan;
196 int dtimper, dtimper_msec;
197 int keep_alive;
198 bool radar_detect = false;
Alexander Bondarb571a692013-05-21 14:49:09 +0300199 struct iwl_mvm_vif *mvmvif __maybe_unused =
200 iwl_mvm_vif_from_mac80211(vif);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300201 enum ieee80211_ac_numbers ac;
202 bool tid_found = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100203
Alexander Bondare811ada2013-03-10 15:29:44 +0200204 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
205 mvmvif->color));
206 dtimper = hw->conf.ps_dtim_period ?: 1;
207
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200208 /*
209 * Regardless of power management state the driver must set
210 * keep alive period. FW will use it for sending keep alive NDPs
Alexander Bondare811ada2013-03-10 15:29:44 +0200211 * immediately after association. Check that keep alive period
212 * is at least 3 * DTIM
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200213 */
Alexander Bondare811ada2013-03-10 15:29:44 +0200214 dtimper_msec = dtimper * vif->bss_conf.beacon_int;
215 keep_alive = max_t(int, 3 * dtimper_msec,
216 MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
217 keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
218 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200219
Alexander Bondarade50652013-04-03 16:28:47 +0300220 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100221 return;
222
Alexander Bondar9a613042013-03-05 12:54:00 +0200223 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
224
Alexander Bondarb571a692013-05-21 14:49:09 +0300225#ifdef CONFIG_IWLWIFI_DEBUGFS
226 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
227 mvmvif->dbgfs_pm.disable_power_off)
228 cmd->flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
229#endif
Alexander Bondar9a613042013-03-05 12:54:00 +0200230 if (!vif->bss_conf.ps)
231 return;
232
233 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100234
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200235 if (vif->bss_conf.beacon_rate &&
236 (vif->bss_conf.beacon_rate->bitrate == 10 ||
237 vif->bss_conf.beacon_rate->bitrate == 60)) {
238 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200239 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200240 }
241
Johannes Berg8ca151b2013-01-24 14:25:36 +0100242 /* Check if radar detection is required on current channel */
243 rcu_read_lock();
244 chanctx_conf = rcu_dereference(vif->chanctx_conf);
245 WARN_ON(!chanctx_conf);
246 if (chanctx_conf) {
247 chan = chanctx_conf->def.chan;
248 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
249 }
250 rcu_read_unlock();
251
252 /* Check skip over DTIM conditions */
253 if (!radar_detect && (dtimper <= 10) &&
Alexander Bondaree1e8422013-04-23 13:52:10 +0300254 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
255 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200256 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200257 cmd->skip_dtim_periods = 3;
Alexander Bondar5b1dbfc2013-04-23 13:32:35 +0300258 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100259
Alexander Bondaree1e8422013-04-23 13:52:10 +0300260 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
Johannes Berg99545922013-06-14 13:36:21 +0200261 cmd->rx_data_timeout =
262 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
263 cmd->tx_data_timeout =
264 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300265 } else {
Johannes Berg99545922013-06-14 13:36:21 +0200266 cmd->rx_data_timeout =
267 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
268 cmd->tx_data_timeout =
269 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300270 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300271
Alexander Bondare3c588e2013-04-07 14:08:59 +0300272 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
273 if (!mvmvif->queue_params[ac].uapsd)
274 continue;
275
276 cmd->flags |= cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
277 cmd->uapsd_ac_flags |= BIT(ac);
278
279 /* QNDP TID - the highest TID with no admission control */
280 if (!tid_found && !mvmvif->queue_params[ac].acm) {
281 tid_found = true;
282 switch (ac) {
283 case IEEE80211_AC_VO:
284 cmd->qndp_tid = 6;
285 break;
286 case IEEE80211_AC_VI:
287 cmd->qndp_tid = 5;
288 break;
289 case IEEE80211_AC_BE:
290 cmd->qndp_tid = 0;
291 break;
292 case IEEE80211_AC_BK:
293 cmd->qndp_tid = 1;
294 break;
295 }
296 }
297 }
298
299 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
Alexander Bondar89716342013-08-04 17:52:23 +0300300 if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
301 BIT(IEEE80211_AC_VI) |
302 BIT(IEEE80211_AC_BE) |
303 BIT(IEEE80211_AC_BK))) {
304 cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
305 cmd->snooze_interval =
306 cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
307 cmd->snooze_window =
308 (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
309 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
310 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
311 }
312
Alexander Bondare3c588e2013-04-07 14:08:59 +0300313 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
Alexander Bondarb34b9122013-08-18 16:22:52 +0300314
315 if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
316 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
317 cmd->rx_data_timeout_uapsd =
318 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
319 cmd->tx_data_timeout_uapsd =
320 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
321 } else {
322 cmd->rx_data_timeout_uapsd =
323 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
324 cmd->tx_data_timeout_uapsd =
325 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
326 }
327
328 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
329 cmd->heavy_tx_thld_packets =
330 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
331 cmd->heavy_rx_thld_packets =
332 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
333 } else {
334 cmd->heavy_tx_thld_packets =
335 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
336 cmd->heavy_rx_thld_packets =
337 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
338 }
Alexander Bondare3c588e2013-04-07 14:08:59 +0300339 cmd->heavy_tx_thld_percentage =
340 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
341 cmd->heavy_rx_thld_percentage =
342 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
343 }
344
Alexander Bondarb571a692013-05-21 14:49:09 +0300345#ifdef CONFIG_IWLWIFI_DEBUGFS
346 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200347 cmd->keep_alive_seconds =
348 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300349 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
350 if (mvmvif->dbgfs_pm.skip_over_dtim)
351 cmd->flags |=
352 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
353 else
354 cmd->flags &=
355 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
356 }
357 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
358 cmd->rx_data_timeout =
359 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
360 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
361 cmd->tx_data_timeout =
362 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
363 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200364 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200365 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
366 if (mvmvif->dbgfs_pm.lprx_ena)
367 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
368 else
369 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
370 }
371 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200372 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondar89716342013-08-04 17:52:23 +0300373 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
374 if (mvmvif->dbgfs_pm.snooze_ena)
375 cmd->flags |=
376 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
377 else
378 cmd->flags &=
379 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
380 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300381#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100382}
383
Alexander Bondare811ada2013-03-10 15:29:44 +0200384static int iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm,
385 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100386{
Alexander Bondar071d49902013-05-06 13:03:59 +0300387 int ret;
388 bool ba_enable;
Alexander Bondare811ada2013-03-10 15:29:44 +0200389 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100390
Johannes Berg8ca151b2013-01-24 14:25:36 +0100391 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
392 return 0;
393
Alexander Bondar4bf881f2013-05-29 10:19:50 +0300394 /*
395 * TODO: The following vif_count verification is temporary condition.
396 * Avoid power mode update if more than one interface is currently
397 * active. Remove this condition when FW will support power management
398 * on multiple MACs.
399 */
400 IWL_DEBUG_POWER(mvm, "Currently %d interfaces active\n",
401 mvm->vif_count);
402 if (mvm->vif_count > 1)
403 return 0;
404
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200405 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200406 iwl_mvm_power_log(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100407
Alexander Bondare811ada2013-03-10 15:29:44 +0200408 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC,
Alexander Bondar071d49902013-05-06 13:03:59 +0300409 sizeof(cmd), &cmd);
410 if (ret)
411 return ret;
412
413 ba_enable = !!(cmd.flags &
414 cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK));
415
416 return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100417}
418
Alexander Bondare811ada2013-03-10 15:29:44 +0200419static int iwl_mvm_power_mac_disable(struct iwl_mvm *mvm,
420 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100421{
Alexander Bondare811ada2013-03-10 15:29:44 +0200422 struct iwl_mac_power_cmd cmd = {};
Alexander Bondarb571a692013-05-21 14:49:09 +0300423 struct iwl_mvm_vif *mvmvif __maybe_unused =
424 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100425
Johannes Berg8ca151b2013-01-24 14:25:36 +0100426 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
427 return 0;
428
Alexander Bondare811ada2013-03-10 15:29:44 +0200429 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
430 mvmvif->color));
431
Alexander Bondarade50652013-04-03 16:28:47 +0300432 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Alexander Bondar9a613042013-03-05 12:54:00 +0200433 cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
434
Alexander Bondarb571a692013-05-21 14:49:09 +0300435#ifdef CONFIG_IWLWIFI_DEBUGFS
436 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
437 mvmvif->dbgfs_pm.disable_power_off)
438 cmd.flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
439#endif
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200440 iwl_mvm_power_log(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100441
Alexander Bondare811ada2013-03-10 15:29:44 +0200442 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_ASYNC,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100443 sizeof(cmd), &cmd);
444}
Hila Gonen7df15b12012-12-12 11:16:19 +0200445
Alexander Bondar64b928c2013-09-03 14:18:03 +0300446static int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
447{
448 struct iwl_device_power_cmd cmd = {
449 .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK),
450 };
451
452 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD))
453 return 0;
454
455 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
456 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK);
457
458#ifdef CONFIG_IWLWIFI_DEBUGFS
459 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
460 mvm->disable_power_off)
461 cmd.flags &=
462 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
463#endif
464 IWL_DEBUG_POWER(mvm,
465 "Sending device power command with flags = 0x%X\n",
466 cmd.flags);
467
468 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_SYNC, sizeof(cmd),
469 &cmd);
470}
471
Alexander Bondarb571a692013-05-21 14:49:09 +0300472#ifdef CONFIG_IWLWIFI_DEBUGFS
Alexander Bondare811ada2013-03-10 15:29:44 +0200473static int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
474 struct ieee80211_vif *vif, char *buf,
475 int bufsz)
476{
477 struct iwl_mac_power_cmd cmd = {};
478 int pos = 0;
479
480 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
481
Alexander Bondar64b928c2013-09-03 14:18:03 +0300482 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD))
483 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n",
484 (cmd.flags &
485 cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ?
486 0 : 1);
Alexander Bondare811ada2013-03-10 15:29:44 +0200487 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
488 iwlmvm_mod_params.power_scheme);
489 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
490 le16_to_cpu(cmd.flags));
491 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
492 le16_to_cpu(cmd.keep_alive_seconds));
493
494 if (cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) {
495 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
496 (cmd.flags &
497 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ?
498 1 : 0);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300499 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
500 cmd.skip_dtim_periods);
501 if (!(cmd.flags &
502 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
503 pos += scnprintf(buf+pos, bufsz-pos,
504 "rx_data_timeout = %d\n",
505 le32_to_cpu(cmd.rx_data_timeout));
506 pos += scnprintf(buf+pos, bufsz-pos,
507 "tx_data_timeout = %d\n",
508 le32_to_cpu(cmd.tx_data_timeout));
509 }
Alexander Bondare811ada2013-03-10 15:29:44 +0200510 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
511 pos += scnprintf(buf+pos, bufsz-pos,
512 "lprx_rssi_threshold = %d\n",
513 cmd.lprx_rssi_threshold);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300514 if (cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
515 pos +=
516 scnprintf(buf+pos, bufsz-pos,
517 "rx_data_timeout_uapsd = %d\n",
518 le32_to_cpu(cmd.rx_data_timeout_uapsd));
519 pos +=
520 scnprintf(buf+pos, bufsz-pos,
521 "tx_data_timeout_uapsd = %d\n",
522 le32_to_cpu(cmd.tx_data_timeout_uapsd));
523 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n",
524 cmd.qndp_tid);
525 pos += scnprintf(buf+pos, bufsz-pos,
526 "uapsd_ac_flags = 0x%x\n",
527 cmd.uapsd_ac_flags);
528 pos += scnprintf(buf+pos, bufsz-pos,
529 "uapsd_max_sp = %d\n",
530 cmd.uapsd_max_sp);
531 pos += scnprintf(buf+pos, bufsz-pos,
532 "heavy_tx_thld_packets = %d\n",
533 cmd.heavy_tx_thld_packets);
534 pos += scnprintf(buf+pos, bufsz-pos,
535 "heavy_rx_thld_packets = %d\n",
536 cmd.heavy_rx_thld_packets);
537 pos += scnprintf(buf+pos, bufsz-pos,
538 "heavy_tx_thld_percentage = %d\n",
539 cmd.heavy_tx_thld_percentage);
540 pos += scnprintf(buf+pos, bufsz-pos,
541 "heavy_rx_thld_percentage = %d\n",
542 cmd.heavy_rx_thld_percentage);
Alexander Bondar89716342013-08-04 17:52:23 +0300543 pos +=
544 scnprintf(buf+pos, bufsz-pos, "snooze_enable = %d\n",
545 (cmd.flags &
546 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) ?
547 1 : 0);
548 }
549 if (cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
550 pos += scnprintf(buf+pos, bufsz-pos,
551 "snooze_interval = %d\n",
552 cmd.snooze_interval);
553 pos += scnprintf(buf+pos, bufsz-pos,
554 "snooze_window = %d\n",
555 cmd.snooze_window);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300556 }
Alexander Bondare811ada2013-03-10 15:29:44 +0200557 }
558 return pos;
559}
560
Alexander Bondarb571a692013-05-21 14:49:09 +0300561void
562iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
563 struct iwl_beacon_filter_cmd *cmd)
564{
565 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
566 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
567
568 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300569 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300570 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
571 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300572 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300573 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300574 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
575 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
576 cmd->bf_temp_threshold =
577 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
578 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
579 cmd->bf_temp_fast_filter =
580 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
581 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
582 cmd->bf_temp_slow_filter =
583 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300584 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300585 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300586 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
587 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
588 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
589 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
590 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300591 cmd->ba_enable_beacon_abort =
592 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300593}
594#endif
595
Hila Gonen7df15b12012-12-12 11:16:19 +0200596int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
597 struct ieee80211_vif *vif)
598{
599 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
600 struct iwl_beacon_filter_cmd cmd = {
Alexander Bondar071d49902013-05-06 13:03:59 +0300601 IWL_BF_CMD_CONFIG_DEFAULTS,
Hila Gonen5dca7c22013-07-16 11:15:35 +0300602 .bf_enable_beacon_filter = cpu_to_le32(1),
Hila Gonen7df15b12012-12-12 11:16:19 +0200603 };
Alexander Bondar071d49902013-05-06 13:03:59 +0300604 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200605
606 if (mvmvif != mvm->bf_allowed_vif ||
607 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
608 return 0;
609
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300610 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
Alexander Bondarb571a692013-05-21 14:49:09 +0300611 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
Alexander Bondar071d49902013-05-06 13:03:59 +0300612 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
613
614 if (!ret)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300615 mvmvif->bf_data.bf_enabled = true;
Alexander Bondar071d49902013-05-06 13:03:59 +0300616
617 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200618}
619
620int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
621 struct ieee80211_vif *vif)
622{
Alexander Bondar071d49902013-05-06 13:03:59 +0300623 struct iwl_beacon_filter_cmd cmd = {};
624 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
625 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200626
Hila Gonen5dca7c22013-07-16 11:15:35 +0300627 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) ||
628 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200629 return 0;
630
Alexander Bondar071d49902013-05-06 13:03:59 +0300631 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
632
633 if (!ret)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300634 mvmvif->bf_data.bf_enabled = false;
Alexander Bondar071d49902013-05-06 13:03:59 +0300635
636 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200637}
Alexander Bondare811ada2013-03-10 15:29:44 +0200638
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300639int iwl_mvm_update_beacon_filter(struct iwl_mvm *mvm,
640 struct ieee80211_vif *vif)
641{
642 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
643
644 if (!mvmvif->bf_data.bf_enabled)
645 return 0;
646
647 return iwl_mvm_enable_beacon_filter(mvm, vif);
648}
649
Alexander Bondare811ada2013-03-10 15:29:44 +0200650const struct iwl_mvm_power_ops pm_mac_ops = {
651 .power_update_mode = iwl_mvm_power_mac_update_mode,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300652 .power_update_device_mode = iwl_mvm_power_update_device,
Alexander Bondare811ada2013-03-10 15:29:44 +0200653 .power_disable = iwl_mvm_power_mac_disable,
654#ifdef CONFIG_IWLWIFI_DEBUGFS
655 .power_dbgfs_read = iwl_mvm_power_mac_dbgfs_read,
656#endif
657};