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