iwlwifi: mvm: support beacon storing
[deliverable/linux.git] / drivers / net / wireless / intel / 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 *
51368bf7 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8b4139dc 9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
0db056d3 10 * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
8ca151b5
JB
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * USA
25 *
26 * The full GNU General Public License is included in this distribution
410dc5aa 27 * in the file called COPYING.
8ca151b5
JB
28 *
29 * Contact Information:
cb2f8277 30 * Intel Linux Wireless <linuxwifi@intel.com>
8ca151b5
JB
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
51368bf7 35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8b4139dc 36 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
0db056d3 37 * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
8ca151b5
JB
38 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
49 * distribution.
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
65 *
66 *****************************************************************************/
67
68#include <linux/kernel.h>
69#include <linux/module.h>
70#include <linux/slab.h>
93803b33 71#include <linux/etherdevice.h>
8ca151b5
JB
72
73#include <net/mac80211.h>
74
75#include "iwl-debug.h"
76#include "mvm.h"
77#include "iwl-modparams.h"
78#include "fw-api-power.h"
79
80#define POWER_KEEP_ALIVE_PERIOD_SEC 25
81
d623d24a 82static
e811ada7 83int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
3dd37d05
EP
84 struct iwl_beacon_filter_cmd *cmd,
85 u32 flags)
071d4990 86{
d623d24a
EG
87 IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n",
88 le32_to_cpu(cmd->ba_enable_beacon_abort));
89 IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
90 le32_to_cpu(cmd->ba_escape_timer));
91 IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
92 le32_to_cpu(cmd->bf_debug_flag));
93 IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
94 le32_to_cpu(cmd->bf_enable_beacon_filter));
95 IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
96 le32_to_cpu(cmd->bf_energy_delta));
97 IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
98 le32_to_cpu(cmd->bf_escape_timer));
99 IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
100 le32_to_cpu(cmd->bf_roaming_energy_delta));
101 IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
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));
109
110 return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags,
111 sizeof(struct iwl_beacon_filter_cmd), cmd);
071d4990
AB
112}
113
a20fd398
AO
114static
115void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
116 struct ieee80211_vif *vif,
cdc306b2
GG
117 struct iwl_beacon_filter_cmd *cmd,
118 bool d0i3)
a20fd398
AO
119{
120 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
121
cdc306b2 122 if (vif->bss_conf.cqm_rssi_thold && !d0i3) {
a20fd398
AO
123 cmd->bf_energy_delta =
124 cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
125 /* fw uses an absolute value for this */
126 cmd->bf_roaming_state =
127 cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
128 }
129 cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
130}
131
3f0b2b3e 132static void iwl_mvm_power_log(struct iwl_mvm *mvm,
e811ada7 133 struct iwl_mac_power_cmd *cmd)
3f0b2b3e
AB
134{
135 IWL_DEBUG_POWER(mvm,
e811ada7
AB
136 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
137 cmd->id_and_color, iwlmvm_mod_params.power_scheme,
3f0b2b3e 138 le16_to_cpu(cmd->flags));
e811ada7
AB
139 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
140 le16_to_cpu(cmd->keep_alive_seconds));
3f0b2b3e 141
e3c588ec
AB
142 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
143 IWL_DEBUG_POWER(mvm, "Disable power management\n");
144 return;
145 }
146
147 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
148 le32_to_cpu(cmd->rx_data_timeout));
149 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
150 le32_to_cpu(cmd->tx_data_timeout));
151 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
152 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
153 cmd->skip_dtim_periods);
154 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
155 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
156 cmd->lprx_rssi_threshold);
157 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
158 IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
159 IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
160 le32_to_cpu(cmd->rx_data_timeout_uapsd));
161 IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
162 le32_to_cpu(cmd->tx_data_timeout_uapsd));
163 IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
164 IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
165 IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
3f0b2b3e
AB
166 }
167}
168
175a70b7
AB
169static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm,
170 struct ieee80211_vif *vif,
171 struct iwl_mac_power_cmd *cmd)
172{
173 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
174 enum ieee80211_ac_numbers ac;
175 bool tid_found = false;
176
177 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
178 if (!mvmvif->queue_params[ac].uapsd)
179 continue;
180
181 if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
182 cmd->flags |=
183 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
184
185 cmd->uapsd_ac_flags |= BIT(ac);
186
187 /* QNDP TID - the highest TID with no admission control */
188 if (!tid_found && !mvmvif->queue_params[ac].acm) {
189 tid_found = true;
190 switch (ac) {
191 case IEEE80211_AC_VO:
192 cmd->qndp_tid = 6;
193 break;
194 case IEEE80211_AC_VI:
195 cmd->qndp_tid = 5;
196 break;
197 case IEEE80211_AC_BE:
198 cmd->qndp_tid = 0;
199 break;
200 case IEEE80211_AC_BK:
201 cmd->qndp_tid = 1;
202 break;
203 }
204 }
205 }
206
84fd7608
EP
207 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
208#ifdef CONFIG_IWLWIFI_DEBUGFS
209 /* set advanced pm flag with no uapsd ACs to enable ps-poll */
210 if (mvmvif->dbgfs_pm.use_ps_poll)
211 cmd->flags |=
212 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
213#endif
175a70b7 214 return;
84fd7608 215 }
175a70b7
AB
216
217 cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK);
218
219 if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
220 BIT(IEEE80211_AC_VI) |
221 BIT(IEEE80211_AC_BE) |
222 BIT(IEEE80211_AC_BK))) {
223 cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
224 cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
225 cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
226 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
227 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
228 }
229
230 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
231
232 if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
233 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
234 cmd->rx_data_timeout_uapsd =
235 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
236 cmd->tx_data_timeout_uapsd =
237 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
238 } else {
239 cmd->rx_data_timeout_uapsd =
240 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
241 cmd->tx_data_timeout_uapsd =
242 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
243 }
244
245 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
246 cmd->heavy_tx_thld_packets =
247 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
248 cmd->heavy_rx_thld_packets =
249 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
250 } else {
251 cmd->heavy_tx_thld_packets =
252 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
253 cmd->heavy_rx_thld_packets =
254 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
255 }
256 cmd->heavy_tx_thld_percentage =
257 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
258 cmd->heavy_rx_thld_percentage =
259 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
260}
261
ee95ed37
AA
262static void iwl_mvm_p2p_standalone_iterator(void *_data, u8 *mac,
263 struct ieee80211_vif *vif)
264{
265 bool *is_p2p_standalone = _data;
266
267 switch (ieee80211_vif_type_p2p(vif)) {
268 case NL80211_IFTYPE_P2P_GO:
269 case NL80211_IFTYPE_AP:
270 *is_p2p_standalone = false;
271 break;
272 case NL80211_IFTYPE_STATION:
273 if (vif->bss_conf.assoc)
274 *is_p2p_standalone = false;
275 break;
276
277 default:
278 break;
279 }
280}
281
c6e37a68
AA
282static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm,
283 struct ieee80211_vif *vif)
284{
285 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
286
287 if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
288 ETH_ALEN))
289 return false;
290
c6e37a68
AA
291 /*
292 * Avoid using uAPSD if P2P client is associated to GO that uses
293 * opportunistic power save. This is due to current FW limitation.
294 */
295 if (vif->p2p &&
296 (vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
297 IEEE80211_P2P_OPPPS_ENABLE_BIT))
298 return false;
299
0534528e
AA
300 /*
301 * Avoid using uAPSD if client is in DCM -
302 * low latency issue in Miracast
303 */
cf7b491d 304 if (iwl_mvm_phy_ctx_count(mvm) >= 2)
0534528e
AA
305 return false;
306
ee95ed37
AA
307 if (vif->p2p) {
308 /* Allow U-APSD only if p2p is stand alone */
309 bool is_p2p_standalone = true;
310
311 if (!iwl_mvm_is_p2p_standalone_uapsd_supported(mvm))
312 return false;
313
314 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
315 IEEE80211_IFACE_ITER_NORMAL,
316 iwl_mvm_p2p_standalone_iterator,
317 &is_p2p_standalone);
318
319 if (!is_p2p_standalone)
320 return false;
321 }
322
c6e37a68
AA
323 return true;
324}
325
49c6d802
AA
326static bool iwl_mvm_power_is_radar(struct ieee80211_vif *vif)
327{
328 struct ieee80211_chanctx_conf *chanctx_conf;
329 struct ieee80211_channel *chan;
330 bool radar_detect = false;
331
332 rcu_read_lock();
333 chanctx_conf = rcu_dereference(vif->chanctx_conf);
334 WARN_ON(!chanctx_conf);
335 if (chanctx_conf) {
336 chan = chanctx_conf->def.chan;
337 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
338 }
339 rcu_read_unlock();
340
341 return radar_detect;
342}
343
a6449126
JB
344static void iwl_mvm_power_config_skip_dtim(struct iwl_mvm *mvm,
345 struct ieee80211_vif *vif,
346 struct iwl_mac_power_cmd *cmd,
347 bool host_awake)
348{
349 int dtimper = vif->bss_conf.dtim_period ?: 1;
350 int skip;
351
352 /* disable, in case we're supposed to override */
353 cmd->skip_dtim_periods = 0;
354 cmd->flags &= ~cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
355
356 if (iwl_mvm_power_is_radar(vif))
357 return;
358
359 if (dtimper >= 10)
360 return;
361
362 /* TODO: check that multicast wake lock is off */
363
364 if (host_awake) {
365 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_LP)
366 return;
367 skip = 2;
368 } else {
369 int dtimper_tu = dtimper * vif->bss_conf.beacon_int;
370
371 if (WARN_ON(!dtimper_tu))
372 return;
373 /* configure skip over dtim up to 306TU - 314 msec */
374 skip = max_t(u8, 1, 306 / dtimper_tu);
375 }
376
377 /* the firmware really expects "look at every X DTIMs", so add 1 */
378 cmd->skip_dtim_periods = 1 + skip;
379 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
380}
381
e811ada7
AB
382static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
383 struct ieee80211_vif *vif,
9645edb6
JB
384 struct iwl_mac_power_cmd *cmd,
385 bool host_awake)
8ca151b5 386{
5387b348 387 int dtimper, bi;
8ca151b5 388 int keep_alive;
b571a697
AB
389 struct iwl_mvm_vif *mvmvif __maybe_unused =
390 iwl_mvm_vif_from_mac80211(vif);
8ca151b5 391
e811ada7
AB
392 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
393 mvmvif->color));
717e2390 394 dtimper = vif->bss_conf.dtim_period;
886ca9f5 395 bi = vif->bss_conf.beacon_int;
e811ada7 396
e16cf7ec
AB
397 /*
398 * Regardless of power management state the driver must set
399 * keep alive period. FW will use it for sending keep alive NDPs
e811ada7
AB
400 * immediately after association. Check that keep alive period
401 * is at least 3 * DTIM
e16cf7ec 402 */
5387b348
AA
403 keep_alive = DIV_ROUND_UP(ieee80211_tu_to_usec(3 * dtimper * bi),
404 USEC_PER_SEC);
405 keep_alive = max(keep_alive, POWER_KEEP_ALIVE_PERIOD_SEC);
e811ada7 406 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
e16cf7ec 407
e5e7aa8e 408 if (mvm->ps_disabled)
8ca151b5
JB
409 return;
410
9a613048
AB
411 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
412
b08dbed7
JB
413 if (!vif->bss_conf.ps || !mvmvif->pm_enabled)
414 return;
415
416 if (iwl_mvm_vif_low_latency(mvmvif) && vif->p2p &&
417 (!fw_has_capa(&mvm->fw->ucode_capa,
418 IWL_UCODE_TLV_CAPA_SHORT_PM_TIMEOUTS) ||
419 !IWL_MVM_P2P_LOWLATENCY_PS_ENABLE))
9a613048
AB
420 return;
421
422 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
8ca151b5 423
bd4ace2a
AB
424 if (vif->bss_conf.beacon_rate &&
425 (vif->bss_conf.beacon_rate->bitrate == 10 ||
426 vif->bss_conf.beacon_rate->bitrate == 60)) {
427 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
e811ada7 428 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
bd4ace2a
AB
429 }
430
9645edb6 431 iwl_mvm_power_config_skip_dtim(mvm, vif, cmd, host_awake);
8ca151b5 432
b08dbed7 433 if (!host_awake) {
99545924 434 cmd->rx_data_timeout =
b08dbed7 435 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
99545924 436 cmd->tx_data_timeout =
b08dbed7
JB
437 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
438 } else if (iwl_mvm_vif_low_latency(mvmvif) && vif->p2p &&
439 fw_has_capa(&mvm->fw->ucode_capa,
440 IWL_UCODE_TLV_CAPA_SHORT_PM_TIMEOUTS)) {
441 cmd->tx_data_timeout =
442 cpu_to_le32(IWL_MVM_SHORT_PS_TX_DATA_TIMEOUT);
443 cmd->rx_data_timeout =
444 cpu_to_le32(IWL_MVM_SHORT_PS_RX_DATA_TIMEOUT);
ee1e8422 445 } else {
99545924 446 cmd->rx_data_timeout =
b08dbed7 447 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
99545924 448 cmd->tx_data_timeout =
b08dbed7 449 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
ee1e8422 450 }
b571a697 451
c6e37a68 452 if (iwl_mvm_power_allow_uapsd(mvm, vif))
175a70b7 453 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
e3c588ec 454
b571a697
AB
455#ifdef CONFIG_IWLWIFI_DEBUGFS
456 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
e811ada7
AB
457 cmd->keep_alive_seconds =
458 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
b571a697
AB
459 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
460 if (mvmvif->dbgfs_pm.skip_over_dtim)
461 cmd->flags |=
462 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
463 else
464 cmd->flags &=
465 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
466 }
467 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
468 cmd->rx_data_timeout =
469 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
470 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
471 cmd->tx_data_timeout =
472 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
473 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
e811ada7 474 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
bd4ace2a
AB
475 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
476 if (mvmvif->dbgfs_pm.lprx_ena)
477 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
478 else
479 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
480 }
481 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
e811ada7 482 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
89716344
AB
483 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
484 if (mvmvif->dbgfs_pm.snooze_ena)
485 cmd->flags |=
486 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
487 else
488 cmd->flags &=
489 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
490 }
e45a941d
AB
491 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
492 u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
493 if (mvmvif->dbgfs_pm.uapsd_misbehaving)
494 cmd->flags |= cpu_to_le16(flag);
495 else
496 cmd->flags &= cpu_to_le16(flag);
497 }
b571a697 498#endif /* CONFIG_IWLWIFI_DEBUGFS */
8ca151b5
JB
499}
500
e5e7aa8e 501static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
e811ada7 502 struct ieee80211_vif *vif)
8ca151b5 503{
e811ada7 504 struct iwl_mac_power_cmd cmd = {};
8ca151b5 505
9645edb6
JB
506 iwl_mvm_power_build_cmd(mvm, vif, &cmd,
507 mvm->cur_ucode != IWL_UCODE_WOWLAN);
3f0b2b3e 508 iwl_mvm_power_log(mvm, &cmd);
474b50c3
EG
509#ifdef CONFIG_IWLWIFI_DEBUGFS
510 memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
511#endif
8ca151b5 512
a1022927 513 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0,
06280a2b
EG
514 sizeof(cmd), &cmd);
515}
516
e5e7aa8e 517int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
64b928c4
AB
518{
519 struct iwl_device_power_cmd cmd = {
ceef91c8 520 .flags = 0,
64b928c4
AB
521 };
522
e5e7aa8e
EG
523 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
524 mvm->ps_disabled = true;
525
ceef91c8
JB
526 if (!mvm->ps_disabled)
527 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
64b928c4
AB
528
529#ifdef CONFIG_IWLWIFI_DEBUGFS
530 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
531 mvm->disable_power_off)
532 cmd.flags &=
533 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
534#endif
535 IWL_DEBUG_POWER(mvm,
536 "Sending device power command with flags = 0x%X\n",
537 cmd.flags);
538
a1022927 539 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd),
64b928c4
AB
540 &cmd);
541}
542
175a70b7
AB
543void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
544{
545 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
546
547 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
548 ETH_ALEN))
93803b33 549 eth_zero_addr(mvmvif->uapsd_misbehaving_bssid);
175a70b7
AB
550}
551
552static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
553 struct ieee80211_vif *vif)
554{
555 u8 *ap_sta_id = _data;
556 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
557
558 /* The ap_sta_id is not expected to change during current association
559 * so no explicit protection is needed
560 */
561 if (mvmvif->ap_sta_id == *ap_sta_id)
562 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
563 ETH_ALEN);
564}
565
0416841d
JB
566void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
567 struct iwl_rx_cmd_buffer *rxb)
175a70b7
AB
568{
569 struct iwl_rx_packet *pkt = rxb_addr(rxb);
570 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
571 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
572
573 ieee80211_iterate_active_interfaces_atomic(
574 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
575 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
175a70b7
AB
576}
577
19889025 578struct iwl_power_vifs {
fa3d07e4 579 struct iwl_mvm *mvm;
06280a2b 580 struct ieee80211_vif *bf_vif;
e5e7aa8e 581 struct ieee80211_vif *bss_vif;
8ea0c68f 582 struct ieee80211_vif *p2p_vif;
19889025
AA
583 struct ieee80211_vif *ap_vif;
584 struct ieee80211_vif *monitor_vif;
585 bool p2p_active;
586 bool bss_active;
587 bool ap_active;
588 bool monitor_active;
06280a2b
EG
589};
590
128aa948
LC
591static void iwl_mvm_power_disable_pm_iterator(void *_data, u8* mac,
592 struct ieee80211_vif *vif)
1c2abf72 593{
06280a2b 594 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
e5e7aa8e 595
19889025 596 mvmvif->pm_enabled = false;
128aa948
LC
597}
598
2533edce
LC
599static void iwl_mvm_power_ps_disabled_iterator(void *_data, u8* mac,
600 struct ieee80211_vif *vif)
601{
602 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
603 bool *disable_ps = _data;
604
605 if (mvmvif->phy_ctxt)
606 if (mvmvif->phy_ctxt->id < MAX_PHYS)
607 *disable_ps |= mvmvif->ps_disabled;
608}
609
128aa948
LC
610static void iwl_mvm_power_get_vifs_iterator(void *_data, u8 *mac,
611 struct ieee80211_vif *vif)
612{
613 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
614 struct iwl_power_vifs *power_iterator = _data;
615
e5e7aa8e
EG
616 switch (ieee80211_vif_type_p2p(vif)) {
617 case NL80211_IFTYPE_P2P_DEVICE:
618 break;
619
620 case NL80211_IFTYPE_P2P_GO:
621 case NL80211_IFTYPE_AP:
19889025
AA
622 /* only a single MAC of the same type */
623 WARN_ON(power_iterator->ap_vif);
624 power_iterator->ap_vif = vif;
625 if (mvmvif->phy_ctxt)
626 if (mvmvif->phy_ctxt->id < MAX_PHYS)
627 power_iterator->ap_active = true;
e5e7aa8e
EG
628 break;
629
630 case NL80211_IFTYPE_MONITOR:
19889025
AA
631 /* only a single MAC of the same type */
632 WARN_ON(power_iterator->monitor_vif);
633 power_iterator->monitor_vif = vif;
634 if (mvmvif->phy_ctxt)
635 if (mvmvif->phy_ctxt->id < MAX_PHYS)
636 power_iterator->monitor_active = true;
e5e7aa8e
EG
637 break;
638
639 case NL80211_IFTYPE_P2P_CLIENT:
19889025 640 /* only a single MAC of the same type */
8ea0c68f
AA
641 WARN_ON(power_iterator->p2p_vif);
642 power_iterator->p2p_vif = vif;
19889025
AA
643 if (mvmvif->phy_ctxt)
644 if (mvmvif->phy_ctxt->id < MAX_PHYS)
645 power_iterator->p2p_active = true;
e5e7aa8e
EG
646 break;
647
648 case NL80211_IFTYPE_STATION:
e5e7aa8e 649 power_iterator->bss_vif = vif;
19889025
AA
650 if (mvmvif->phy_ctxt)
651 if (mvmvif->phy_ctxt->id < MAX_PHYS)
652 power_iterator->bss_active = true;
e5e7aa8e
EG
653
654 if (mvmvif->bf_data.bf_enabled &&
655 !WARN_ON(power_iterator->bf_vif))
656 power_iterator->bf_vif = vif;
7303dd7f 657
e5e7aa8e
EG
658 break;
659
660 default:
661 break;
662 }
663}
1c2abf72 664
b1873300
LC
665static void iwl_mvm_power_set_pm(struct iwl_mvm *mvm,
666 struct iwl_power_vifs *vifs)
e5e7aa8e 667{
19889025
AA
668 struct iwl_mvm_vif *bss_mvmvif = NULL;
669 struct iwl_mvm_vif *p2p_mvmvif = NULL;
670 struct iwl_mvm_vif *ap_mvmvif = NULL;
671 bool client_same_channel = false;
672 bool ap_same_channel = false;
e5e7aa8e 673
19889025 674 lockdep_assert_held(&mvm->mutex);
06280a2b 675
128aa948 676 /* set pm_enable to false */
e5e7aa8e 677 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
128aa948
LC
678 IEEE80211_IFACE_ITER_NORMAL,
679 iwl_mvm_power_disable_pm_iterator,
680 NULL);
19889025
AA
681
682 if (vifs->bss_vif)
683 bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif);
684
685 if (vifs->p2p_vif)
686 p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif);
687
688 if (vifs->ap_vif)
689 ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif);
690
fcf23352
AN
691 /* don't allow PM if any TDLS stations exist */
692 if (iwl_mvm_tdls_sta_count(mvm, NULL))
693 return;
694
19889025 695 /* enable PM on bss if bss stand alone */
9474d444 696 if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active) {
19889025
AA
697 bss_mvmvif->pm_enabled = true;
698 return;
699 }
700
701 /* enable PM on p2p if p2p stand alone */
9474d444 702 if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active) {
19889025
AA
703 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
704 p2p_mvmvif->pm_enabled = true;
705 return;
706 }
707
708 if (vifs->bss_active && vifs->p2p_active)
709 client_same_channel = (bss_mvmvif->phy_ctxt->id ==
710 p2p_mvmvif->phy_ctxt->id);
711 if (vifs->bss_active && vifs->ap_active)
712 ap_same_channel = (bss_mvmvif->phy_ctxt->id ==
713 ap_mvmvif->phy_ctxt->id);
714
63ef81cf
AA
715 /* clients are not stand alone: enable PM if DCM */
716 if (!(client_same_channel || ap_same_channel) &&
19889025 717 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) {
63ef81cf 718 if (vifs->bss_active)
19889025 719 bss_mvmvif->pm_enabled = true;
63ef81cf
AA
720 if (vifs->p2p_active &&
721 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM))
722 p2p_mvmvif->pm_enabled = true;
723 return;
19889025
AA
724 }
725
726 /*
727 * There is only one channel in the system and there are only
728 * bss and p2p clients that share it
729 */
730 if (client_same_channel && !vifs->ap_active &&
731 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM)) {
732 /* share same channel*/
733 bss_mvmvif->pm_enabled = true;
734 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
735 p2p_mvmvif->pm_enabled = true;
736 }
1c2abf72
AB
737}
738
b571a697 739#ifdef CONFIG_IWLWIFI_DEBUGFS
c1cb92fc
EG
740int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
741 struct ieee80211_vif *vif, char *buf,
742 int bufsz)
e811ada7 743{
474b50c3 744 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
e811ada7
AB
745 struct iwl_mac_power_cmd cmd = {};
746 int pos = 0;
747
474b50c3
EG
748 mutex_lock(&mvm->mutex);
749 memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
750 mutex_unlock(&mvm->mutex);
e811ada7 751
e811ada7
AB
752 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
753 iwlmvm_mod_params.power_scheme);
754 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
755 le16_to_cpu(cmd.flags));
756 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
757 le16_to_cpu(cmd.keep_alive_seconds));
758
175a70b7
AB
759 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
760 return pos;
761
762 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
763 (cmd.flags &
764 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
765 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
766 cmd.skip_dtim_periods);
767 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
768 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
769 le32_to_cpu(cmd.rx_data_timeout));
770 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
771 le32_to_cpu(cmd.tx_data_timeout));
e811ada7 772 }
175a70b7
AB
773 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
774 pos += scnprintf(buf+pos, bufsz-pos,
775 "lprx_rssi_threshold = %d\n",
776 cmd.lprx_rssi_threshold);
777
778 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
779 return pos;
780
781 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
782 le32_to_cpu(cmd.rx_data_timeout_uapsd));
783 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
784 le32_to_cpu(cmd.tx_data_timeout_uapsd));
785 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
786 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
787 cmd.uapsd_ac_flags);
788 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
789 cmd.uapsd_max_sp);
790 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
791 cmd.heavy_tx_thld_packets);
792 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
793 cmd.heavy_rx_thld_packets);
794 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
795 cmd.heavy_tx_thld_percentage);
796 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
797 cmd.heavy_rx_thld_percentage);
798 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
799 (cmd.flags &
800 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
801 1 : 0);
802
803 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
804 return pos;
805
806 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
807 cmd.snooze_interval);
808 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
809 cmd.snooze_window);
810
e811ada7
AB
811 return pos;
812}
813
b571a697
AB
814void
815iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
816 struct iwl_beacon_filter_cmd *cmd)
817{
818 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
819 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
820
821 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
5dca7c24 822 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
b571a697
AB
823 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
824 cmd->bf_roaming_energy_delta =
5dca7c24 825 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
b571a697 826 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
5dca7c24
HG
827 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
828 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
829 cmd->bf_temp_threshold =
830 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
831 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
832 cmd->bf_temp_fast_filter =
833 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
834 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
835 cmd->bf_temp_slow_filter =
836 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
b571a697 837 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
5dca7c24 838 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
b571a697
AB
839 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
840 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
841 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
842 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
843 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
5dca7c24
HG
844 cmd->ba_enable_beacon_abort =
845 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
b571a697
AB
846}
847#endif
848
3dd37d05
EP
849static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
850 struct ieee80211_vif *vif,
851 struct iwl_beacon_filter_cmd *cmd,
852 u32 cmd_flags,
853 bool d0i3)
7df15b1e
HG
854{
855 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
071d4990 856 int ret;
7df15b1e 857
fa7b2e7f 858 if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period ||
7df15b1e
HG
859 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
860 return 0;
861
cdc306b2 862 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd, d0i3);
3dd37d05
EP
863 if (!d0i3)
864 iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
865 ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
071d4990 866
3dd37d05
EP
867 /* don't change bf_enabled in case of temporary d0i3 configuration */
868 if (!ret && !d0i3)
a20fd398 869 mvmvif->bf_data.bf_enabled = true;
071d4990
AB
870
871 return ret;
7df15b1e
HG
872}
873
3dd37d05
EP
874int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
875 struct ieee80211_vif *vif,
876 u32 flags)
877{
878 struct iwl_beacon_filter_cmd cmd = {
879 IWL_BF_CMD_CONFIG_DEFAULTS,
880 .bf_enable_beacon_filter = cpu_to_le32(1),
881 };
882
883 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
884}
885
13b72322
EG
886static int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
887 struct ieee80211_vif *vif,
888 bool enable)
fa7b2e7f
AA
889{
890 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
891 struct iwl_beacon_filter_cmd cmd = {
892 IWL_BF_CMD_CONFIG_DEFAULTS,
893 .bf_enable_beacon_filter = cpu_to_le32(1),
894 };
895
896 if (!mvmvif->bf_data.bf_enabled)
897 return 0;
898
899 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
900 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
901
902 mvmvif->bf_data.ba_enabled = enable;
903 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false);
904}
905
0db056d3
SS
906static int _iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
907 struct ieee80211_vif *vif,
908 u32 flags, bool d0i3)
7df15b1e 909{
071d4990
AB
910 struct iwl_beacon_filter_cmd cmd = {};
911 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
912 int ret;
7df15b1e 913
73e5f2c5 914 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
7df15b1e
HG
915 return 0;
916
3dd37d05 917 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
071d4990 918
0db056d3
SS
919 /* don't change bf_enabled in case of temporary d0i3 configuration */
920 if (!ret && !d0i3)
a20fd398 921 mvmvif->bf_data.bf_enabled = false;
071d4990
AB
922
923 return ret;
7df15b1e 924}
e811ada7 925
0db056d3
SS
926int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
927 struct ieee80211_vif *vif,
928 u32 flags)
929{
930 return _iwl_mvm_disable_beacon_filter(mvm, vif, flags, false);
931}
932
2533edce 933static int iwl_mvm_power_set_ps(struct iwl_mvm *mvm)
13b72322 934{
128aa948 935 bool disable_ps;
13b72322
EG
936 int ret;
937
13b72322 938 /* disable PS if CAM */
b1873300 939 disable_ps = (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM);
2533edce
LC
940 /* ...or if any of the vifs require PS to be off */
941 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
942 IEEE80211_IFACE_ITER_NORMAL,
943 iwl_mvm_power_ps_disabled_iterator,
944 &disable_ps);
b1873300
LC
945
946 /* update device power state if it has changed */
947 if (mvm->ps_disabled != disable_ps) {
948 bool old_ps_disabled = mvm->ps_disabled;
949
950 mvm->ps_disabled = disable_ps;
951 ret = iwl_mvm_power_update_device(mvm);
952 if (ret) {
953 mvm->ps_disabled = old_ps_disabled;
954 return ret;
13b72322
EG
955 }
956 }
957
128aa948
LC
958 return 0;
959}
960
ef9203d2
LC
961static int iwl_mvm_power_set_ba(struct iwl_mvm *mvm,
962 struct iwl_power_vifs *vifs)
128aa948
LC
963{
964 struct iwl_mvm_vif *mvmvif;
ef9203d2
LC
965 bool ba_enable;
966
967 if (!vifs->bf_vif)
968 return 0;
969
970 mvmvif = iwl_mvm_vif_from_mac80211(vifs->bf_vif);
971
972 ba_enable = !(!mvmvif->pm_enabled || mvm->ps_disabled ||
973 !vifs->bf_vif->bss_conf.ps ||
974 iwl_mvm_vif_low_latency(mvmvif));
975
976 return iwl_mvm_update_beacon_abort(mvm, vifs->bf_vif, ba_enable);
977}
978
979int iwl_mvm_power_update_ps(struct iwl_mvm *mvm)
980{
981 struct iwl_power_vifs vifs = {
982 .mvm = mvm,
983 };
984 int ret;
985
986 lockdep_assert_held(&mvm->mutex);
987
988 /* get vifs info */
989 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
990 IEEE80211_IFACE_ITER_NORMAL,
991 iwl_mvm_power_get_vifs_iterator, &vifs);
992
2533edce 993 ret = iwl_mvm_power_set_ps(mvm);
ef9203d2
LC
994 if (ret)
995 return ret;
996
997 return iwl_mvm_power_set_ba(mvm, &vifs);
998}
999
1000int iwl_mvm_power_update_mac(struct iwl_mvm *mvm)
1001{
128aa948
LC
1002 struct iwl_power_vifs vifs = {
1003 .mvm = mvm,
1004 };
128aa948
LC
1005 int ret;
1006
1007 lockdep_assert_held(&mvm->mutex);
1008
1009 /* get vifs info */
1010 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
1011 IEEE80211_IFACE_ITER_NORMAL,
1012 iwl_mvm_power_get_vifs_iterator, &vifs);
1013
1014 iwl_mvm_power_set_pm(mvm, &vifs);
1015
2533edce 1016 ret = iwl_mvm_power_set_ps(mvm);
128aa948
LC
1017 if (ret)
1018 return ret;
1019
13b72322
EG
1020 if (vifs.bss_vif) {
1021 ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif);
1022 if (ret)
1023 return ret;
1024 }
1025
1026 if (vifs.p2p_vif) {
1027 ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif);
1028 if (ret)
1029 return ret;
1030 }
1031
ef9203d2 1032 return iwl_mvm_power_set_ba(mvm, &vifs);
13b72322
EG
1033}
1034
3dd37d05
EP
1035int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
1036 struct ieee80211_vif *vif,
1037 bool enable, u32 flags)
1038{
1039 int ret;
1040 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1041 struct iwl_mac_power_cmd cmd = {};
1042
1043 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
1044 return 0;
1045
1046 if (!vif->bss_conf.assoc)
1047 return 0;
1048
9645edb6 1049 iwl_mvm_power_build_cmd(mvm, vif, &cmd, !enable);
a6449126 1050
3dd37d05 1051 iwl_mvm_power_log(mvm, &cmd);
474b50c3
EG
1052#ifdef CONFIG_IWLWIFI_DEBUGFS
1053 memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
1054#endif
3dd37d05
EP
1055 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
1056 sizeof(cmd), &cmd);
1057 if (ret)
1058 return ret;
1059
1060 /* configure beacon filtering */
1061 if (mvmvif != mvm->bf_allowed_vif)
1062 return 0;
1063
1064 if (enable) {
1065 struct iwl_beacon_filter_cmd cmd_bf = {
1066 IWL_BF_CMD_CONFIG_D0I3,
1067 .bf_enable_beacon_filter = cpu_to_le32(1),
1068 };
0db056d3
SS
1069 /*
1070 * When beacon storing is supported - disable beacon filtering
1071 * altogether - the latest beacon will be sent when exiting d0i3
1072 */
1073 if (fw_has_capa(&mvm->fw->ucode_capa,
1074 IWL_UCODE_TLV_CAPA_BEACON_STORING))
1075 ret = _iwl_mvm_disable_beacon_filter(mvm, vif, flags,
1076 true);
1077 else
1078 ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
1079 flags, true);
3dd37d05
EP
1080 } else {
1081 if (mvmvif->bf_data.bf_enabled)
1082 ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
1083 else
1084 ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
1085 }
1086
1087 return ret;
1088}
This page took 0.223762 seconds and 5 git commands to generate.