iwlwifi: mvm: Disable uAPSD for D3 image
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / power.c
CommitLineData
8ca151b5
JB
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
410dc5aa 25 * in the file called COPYING.
8ca151b5
JB
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
e811ada7
AB
78int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
79 struct iwl_beacon_filter_cmd *cmd)
071d4990
AB
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",
5dca7c24 88 le32_to_cpu(cmd->ba_enable_beacon_abort));
071d4990 89 IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
5dca7c24 90 le32_to_cpu(cmd->ba_escape_timer));
071d4990 91 IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
5dca7c24 92 le32_to_cpu(cmd->bf_debug_flag));
071d4990 93 IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
5dca7c24 94 le32_to_cpu(cmd->bf_enable_beacon_filter));
071d4990 95 IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
5dca7c24 96 le32_to_cpu(cmd->bf_energy_delta));
071d4990 97 IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
5dca7c24 98 le32_to_cpu(cmd->bf_escape_timer));
071d4990 99 IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
5dca7c24 100 le32_to_cpu(cmd->bf_roaming_energy_delta));
071d4990 101 IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
5dca7c24
HG
102 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));
071d4990
AB
109 }
110 return ret;
111}
112
a20fd398
AO
113static
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
e811ada7
AB
130int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
131 struct ieee80211_vif *vif, bool enable)
071d4990
AB
132{
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,
5dca7c24
HG
136 .bf_enable_beacon_filter = cpu_to_le32(1),
137 .ba_enable_beacon_abort = cpu_to_le32(enable),
071d4990
AB
138 };
139
a20fd398 140 if (!mvmvif->bf_data.bf_enabled)
071d4990
AB
141 return 0;
142
8434925f
AB
143 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
144 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
145
a20fd398
AO
146 mvmvif->bf_data.ba_enabled = enable;
147 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
b571a697 148 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
071d4990
AB
149 return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
150}
151
3f0b2b3e 152static void iwl_mvm_power_log(struct iwl_mvm *mvm,
e811ada7 153 struct iwl_mac_power_cmd *cmd)
3f0b2b3e
AB
154{
155 IWL_DEBUG_POWER(mvm,
e811ada7
AB
156 "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,
3f0b2b3e 158 le16_to_cpu(cmd->flags));
e811ada7
AB
159 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
160 le16_to_cpu(cmd->keep_alive_seconds));
3f0b2b3e 161
e3c588ec
AB
162 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);
3f0b2b3e
AB
186 }
187}
188
e811ada7
AB
189static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
190 struct ieee80211_vif *vif,
191 struct iwl_mac_power_cmd *cmd)
8ca151b5
JB
192{
193 struct ieee80211_hw *hw = mvm->hw;
8ca151b5
JB
194 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;
b571a697
AB
199 struct iwl_mvm_vif *mvmvif __maybe_unused =
200 iwl_mvm_vif_from_mac80211(vif);
e3c588ec
AB
201 enum ieee80211_ac_numbers ac;
202 bool tid_found = false;
8ca151b5 203
e811ada7
AB
204 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
e16cf7ec
AB
208 /*
209 * Regardless of power management state the driver must set
210 * keep alive period. FW will use it for sending keep alive NDPs
e811ada7
AB
211 * immediately after association. Check that keep alive period
212 * is at least 3 * DTIM
e16cf7ec 213 */
e811ada7
AB
214 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);
e16cf7ec 219
ade50652 220 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
8ca151b5
JB
221 return;
222
9a613048
AB
223 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
224
b571a697
AB
225#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
9a613048
AB
230 if (!vif->bss_conf.ps)
231 return;
232
233 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
8ca151b5 234
bd4ace2a
AB
235 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);
e811ada7 239 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
bd4ace2a
AB
240 }
241
8ca151b5
JB
242 /* 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) &&
ee1e8422
AB
254 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
255 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
f4a3e2fe 256 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
e811ada7 257 cmd->skip_dtim_periods = 3;
5b1dbfc3 258 }
8ca151b5 259
ee1e8422 260 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
99545924
JB
261 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);
ee1e8422 265 } else {
99545924
JB
266 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);
ee1e8422 270 }
b571a697 271
e3c588ec
AB
272 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
273 if (!mvmvif->queue_params[ac].uapsd)
274 continue;
275
01ea748c
AB
276 if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
277 cmd->flags |=
278 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
279
e3c588ec
AB
280 cmd->uapsd_ac_flags |= BIT(ac);
281
282 /* QNDP TID - the highest TID with no admission control */
283 if (!tid_found && !mvmvif->queue_params[ac].acm) {
284 tid_found = true;
285 switch (ac) {
286 case IEEE80211_AC_VO:
287 cmd->qndp_tid = 6;
288 break;
289 case IEEE80211_AC_VI:
290 cmd->qndp_tid = 5;
291 break;
292 case IEEE80211_AC_BE:
293 cmd->qndp_tid = 0;
294 break;
295 case IEEE80211_AC_BK:
296 cmd->qndp_tid = 1;
297 break;
298 }
299 }
300 }
301
302 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
303 cmd->rx_data_timeout_uapsd =
304 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
305 cmd->tx_data_timeout_uapsd =
306 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
89716344
AB
307
308 if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
309 BIT(IEEE80211_AC_VI) |
310 BIT(IEEE80211_AC_BE) |
311 BIT(IEEE80211_AC_BK))) {
312 cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
313 cmd->snooze_interval =
314 cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
315 cmd->snooze_window =
316 (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
317 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
318 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
319 }
320
e3c588ec
AB
321 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
322 cmd->heavy_tx_thld_packets =
323 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
324 cmd->heavy_rx_thld_packets =
325 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
326 cmd->heavy_tx_thld_percentage =
327 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
328 cmd->heavy_rx_thld_percentage =
329 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
330 }
331
b571a697
AB
332#ifdef CONFIG_IWLWIFI_DEBUGFS
333 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
e811ada7
AB
334 cmd->keep_alive_seconds =
335 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
b571a697
AB
336 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
337 if (mvmvif->dbgfs_pm.skip_over_dtim)
338 cmd->flags |=
339 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
340 else
341 cmd->flags &=
342 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
343 }
344 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
345 cmd->rx_data_timeout =
346 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
347 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
348 cmd->tx_data_timeout =
349 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
350 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
e811ada7 351 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
bd4ace2a
AB
352 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
353 if (mvmvif->dbgfs_pm.lprx_ena)
354 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
355 else
356 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
357 }
358 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
e811ada7 359 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
89716344
AB
360 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
361 if (mvmvif->dbgfs_pm.snooze_ena)
362 cmd->flags |=
363 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
364 else
365 cmd->flags &=
366 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
367 }
b571a697 368#endif /* CONFIG_IWLWIFI_DEBUGFS */
8ca151b5
JB
369}
370
e811ada7
AB
371static int iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm,
372 struct ieee80211_vif *vif)
8ca151b5 373{
071d4990
AB
374 int ret;
375 bool ba_enable;
e811ada7 376 struct iwl_mac_power_cmd cmd = {};
8ca151b5 377
8ca151b5
JB
378 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
379 return 0;
380
4bf881f5
AB
381 /*
382 * TODO: The following vif_count verification is temporary condition.
383 * Avoid power mode update if more than one interface is currently
384 * active. Remove this condition when FW will support power management
385 * on multiple MACs.
386 */
387 IWL_DEBUG_POWER(mvm, "Currently %d interfaces active\n",
388 mvm->vif_count);
389 if (mvm->vif_count > 1)
390 return 0;
391
f4a3e2fe 392 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
3f0b2b3e 393 iwl_mvm_power_log(mvm, &cmd);
8ca151b5 394
e811ada7 395 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC,
071d4990
AB
396 sizeof(cmd), &cmd);
397 if (ret)
398 return ret;
399
400 ba_enable = !!(cmd.flags &
401 cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK));
402
403 return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable);
8ca151b5
JB
404}
405
e811ada7
AB
406static int iwl_mvm_power_mac_disable(struct iwl_mvm *mvm,
407 struct ieee80211_vif *vif)
8ca151b5 408{
e811ada7 409 struct iwl_mac_power_cmd cmd = {};
b571a697
AB
410 struct iwl_mvm_vif *mvmvif __maybe_unused =
411 iwl_mvm_vif_from_mac80211(vif);
8ca151b5 412
8ca151b5
JB
413 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
414 return 0;
415
e811ada7
AB
416 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
417 mvmvif->color));
418
ade50652 419 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
9a613048
AB
420 cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
421
b571a697
AB
422#ifdef CONFIG_IWLWIFI_DEBUGFS
423 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
424 mvmvif->dbgfs_pm.disable_power_off)
425 cmd.flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
426#endif
3f0b2b3e 427 iwl_mvm_power_log(mvm, &cmd);
8ca151b5 428
e811ada7 429 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_ASYNC,
8ca151b5
JB
430 sizeof(cmd), &cmd);
431}
7df15b1e 432
b571a697 433#ifdef CONFIG_IWLWIFI_DEBUGFS
e811ada7
AB
434static int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
435 struct ieee80211_vif *vif, char *buf,
436 int bufsz)
437{
438 struct iwl_mac_power_cmd cmd = {};
439 int pos = 0;
440
441 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
442
443 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n",
444 (cmd.flags &
445 cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ?
446 0 : 1);
e811ada7
AB
447 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
448 iwlmvm_mod_params.power_scheme);
449 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
450 le16_to_cpu(cmd.flags));
451 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
452 le16_to_cpu(cmd.keep_alive_seconds));
453
454 if (cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) {
455 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
456 (cmd.flags &
457 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ?
458 1 : 0);
e3c588ec
AB
459 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
460 cmd.skip_dtim_periods);
461 if (!(cmd.flags &
462 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
463 pos += scnprintf(buf+pos, bufsz-pos,
464 "rx_data_timeout = %d\n",
465 le32_to_cpu(cmd.rx_data_timeout));
466 pos += scnprintf(buf+pos, bufsz-pos,
467 "tx_data_timeout = %d\n",
468 le32_to_cpu(cmd.tx_data_timeout));
469 }
e811ada7
AB
470 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
471 pos += scnprintf(buf+pos, bufsz-pos,
472 "lprx_rssi_threshold = %d\n",
473 cmd.lprx_rssi_threshold);
e3c588ec
AB
474 if (cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
475 pos +=
476 scnprintf(buf+pos, bufsz-pos,
477 "rx_data_timeout_uapsd = %d\n",
478 le32_to_cpu(cmd.rx_data_timeout_uapsd));
479 pos +=
480 scnprintf(buf+pos, bufsz-pos,
481 "tx_data_timeout_uapsd = %d\n",
482 le32_to_cpu(cmd.tx_data_timeout_uapsd));
483 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n",
484 cmd.qndp_tid);
485 pos += scnprintf(buf+pos, bufsz-pos,
486 "uapsd_ac_flags = 0x%x\n",
487 cmd.uapsd_ac_flags);
488 pos += scnprintf(buf+pos, bufsz-pos,
489 "uapsd_max_sp = %d\n",
490 cmd.uapsd_max_sp);
491 pos += scnprintf(buf+pos, bufsz-pos,
492 "heavy_tx_thld_packets = %d\n",
493 cmd.heavy_tx_thld_packets);
494 pos += scnprintf(buf+pos, bufsz-pos,
495 "heavy_rx_thld_packets = %d\n",
496 cmd.heavy_rx_thld_packets);
497 pos += scnprintf(buf+pos, bufsz-pos,
498 "heavy_tx_thld_percentage = %d\n",
499 cmd.heavy_tx_thld_percentage);
500 pos += scnprintf(buf+pos, bufsz-pos,
501 "heavy_rx_thld_percentage = %d\n",
502 cmd.heavy_rx_thld_percentage);
89716344
AB
503 pos +=
504 scnprintf(buf+pos, bufsz-pos, "snooze_enable = %d\n",
505 (cmd.flags &
506 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) ?
507 1 : 0);
508 }
509 if (cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
510 pos += scnprintf(buf+pos, bufsz-pos,
511 "snooze_interval = %d\n",
512 cmd.snooze_interval);
513 pos += scnprintf(buf+pos, bufsz-pos,
514 "snooze_window = %d\n",
515 cmd.snooze_window);
e3c588ec 516 }
e811ada7
AB
517 }
518 return pos;
519}
520
b571a697
AB
521void
522iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
523 struct iwl_beacon_filter_cmd *cmd)
524{
525 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
526 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
527
528 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
5dca7c24 529 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
b571a697
AB
530 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
531 cmd->bf_roaming_energy_delta =
5dca7c24 532 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
b571a697 533 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
5dca7c24
HG
534 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
535 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
536 cmd->bf_temp_threshold =
537 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
538 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
539 cmd->bf_temp_fast_filter =
540 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
541 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
542 cmd->bf_temp_slow_filter =
543 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
b571a697 544 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
5dca7c24 545 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
b571a697
AB
546 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
547 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
548 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
549 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
550 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
5dca7c24
HG
551 cmd->ba_enable_beacon_abort =
552 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
b571a697
AB
553}
554#endif
555
7df15b1e
HG
556int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
557 struct ieee80211_vif *vif)
558{
559 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
560 struct iwl_beacon_filter_cmd cmd = {
071d4990 561 IWL_BF_CMD_CONFIG_DEFAULTS,
5dca7c24 562 .bf_enable_beacon_filter = cpu_to_le32(1),
7df15b1e 563 };
071d4990 564 int ret;
7df15b1e
HG
565
566 if (mvmvif != mvm->bf_allowed_vif ||
567 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
568 return 0;
569
a20fd398 570 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
b571a697 571 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
071d4990
AB
572 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
573
574 if (!ret)
a20fd398 575 mvmvif->bf_data.bf_enabled = true;
071d4990
AB
576
577 return ret;
7df15b1e
HG
578}
579
580int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
581 struct ieee80211_vif *vif)
582{
071d4990
AB
583 struct iwl_beacon_filter_cmd cmd = {};
584 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
585 int ret;
7df15b1e 586
5dca7c24
HG
587 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) ||
588 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
7df15b1e
HG
589 return 0;
590
071d4990
AB
591 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
592
593 if (!ret)
a20fd398 594 mvmvif->bf_data.bf_enabled = false;
071d4990
AB
595
596 return ret;
7df15b1e 597}
e811ada7 598
a20fd398
AO
599int iwl_mvm_update_beacon_filter(struct iwl_mvm *mvm,
600 struct ieee80211_vif *vif)
601{
602 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
603
604 if (!mvmvif->bf_data.bf_enabled)
605 return 0;
606
607 return iwl_mvm_enable_beacon_filter(mvm, vif);
608}
609
e811ada7
AB
610const struct iwl_mvm_power_ops pm_mac_ops = {
611 .power_update_mode = iwl_mvm_power_mac_update_mode,
612 .power_disable = iwl_mvm_power_mac_disable,
613#ifdef CONFIG_IWLWIFI_DEBUGFS
614 .power_dbgfs_read = iwl_mvm_power_mac_dbgfs_read,
615#endif
616};
This page took 0.087628 seconds and 5 git commands to generate.