1 /******************************************************************************
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.
8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
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.
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.
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,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
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
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.
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.
62 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/module.h>
66 #include <linux/slab.h>
68 #include <net/mac80211.h>
70 #include "iwl-debug.h"
72 #include "iwl-modparams.h"
73 #include "fw-api-power.h"
75 #define POWER_KEEP_ALIVE_PERIOD_SEC 25
78 int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
79 struct iwl_beacon_filter_cmd *cmd,
82 IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n",
83 le32_to_cpu(cmd->ba_enable_beacon_abort));
84 IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
85 le32_to_cpu(cmd->ba_escape_timer));
86 IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
87 le32_to_cpu(cmd->bf_debug_flag));
88 IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
89 le32_to_cpu(cmd->bf_enable_beacon_filter));
90 IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
91 le32_to_cpu(cmd->bf_energy_delta));
92 IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
93 le32_to_cpu(cmd->bf_escape_timer));
94 IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
95 le32_to_cpu(cmd->bf_roaming_energy_delta));
96 IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
97 le32_to_cpu(cmd->bf_roaming_state));
98 IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n",
99 le32_to_cpu(cmd->bf_temp_threshold));
100 IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n",
101 le32_to_cpu(cmd->bf_temp_fast_filter));
102 IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n",
103 le32_to_cpu(cmd->bf_temp_slow_filter));
105 return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags,
106 sizeof(struct iwl_beacon_filter_cmd), cmd);
110 void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
111 struct ieee80211_vif *vif,
112 struct iwl_beacon_filter_cmd *cmd)
114 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
116 if (vif->bss_conf.cqm_rssi_thold) {
117 cmd->bf_energy_delta =
118 cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
119 /* fw uses an absolute value for this */
120 cmd->bf_roaming_state =
121 cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
123 cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
126 static void iwl_mvm_power_log(struct iwl_mvm *mvm,
127 struct iwl_mac_power_cmd *cmd)
130 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
131 cmd->id_and_color, iwlmvm_mod_params.power_scheme,
132 le16_to_cpu(cmd->flags));
133 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
134 le16_to_cpu(cmd->keep_alive_seconds));
136 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
137 IWL_DEBUG_POWER(mvm, "Disable power management\n");
141 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
142 le32_to_cpu(cmd->rx_data_timeout));
143 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
144 le32_to_cpu(cmd->tx_data_timeout));
145 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
146 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
147 cmd->skip_dtim_periods);
148 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
149 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
150 cmd->lprx_rssi_threshold);
151 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
152 IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
153 IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
154 le32_to_cpu(cmd->rx_data_timeout_uapsd));
155 IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
156 le32_to_cpu(cmd->tx_data_timeout_uapsd));
157 IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
158 IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
159 IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
163 static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm,
164 struct ieee80211_vif *vif,
165 struct iwl_mac_power_cmd *cmd)
167 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
168 enum ieee80211_ac_numbers ac;
169 bool tid_found = false;
171 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
172 if (!mvmvif->queue_params[ac].uapsd)
175 if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
177 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
179 cmd->uapsd_ac_flags |= BIT(ac);
181 /* QNDP TID - the highest TID with no admission control */
182 if (!tid_found && !mvmvif->queue_params[ac].acm) {
185 case IEEE80211_AC_VO:
188 case IEEE80211_AC_VI:
191 case IEEE80211_AC_BE:
194 case IEEE80211_AC_BK:
201 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
202 #ifdef CONFIG_IWLWIFI_DEBUGFS
203 /* set advanced pm flag with no uapsd ACs to enable ps-poll */
204 if (mvmvif->dbgfs_pm.use_ps_poll)
206 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
211 cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK);
213 if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
214 BIT(IEEE80211_AC_VI) |
215 BIT(IEEE80211_AC_BE) |
216 BIT(IEEE80211_AC_BK))) {
217 cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
218 cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
219 cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
220 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
221 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
224 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
226 if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
227 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
228 cmd->rx_data_timeout_uapsd =
229 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
230 cmd->tx_data_timeout_uapsd =
231 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
233 cmd->rx_data_timeout_uapsd =
234 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
235 cmd->tx_data_timeout_uapsd =
236 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
239 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
240 cmd->heavy_tx_thld_packets =
241 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
242 cmd->heavy_rx_thld_packets =
243 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
245 cmd->heavy_tx_thld_packets =
246 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
247 cmd->heavy_rx_thld_packets =
248 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
250 cmd->heavy_tx_thld_percentage =
251 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
252 cmd->heavy_rx_thld_percentage =
253 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
256 static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm,
257 struct ieee80211_vif *vif)
259 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
261 if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
266 !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD))
269 * Avoid using uAPSD if P2P client is associated to GO that uses
270 * opportunistic power save. This is due to current FW limitation.
273 (vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
274 IEEE80211_P2P_OPPPS_ENABLE_BIT))
278 * Avoid using uAPSD if client is in DCM -
279 * low latency issue in Miracast
281 if (iwl_mvm_phy_ctx_count(mvm) >= 2)
287 static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
288 struct ieee80211_vif *vif,
289 struct iwl_mac_power_cmd *cmd)
291 struct ieee80211_hw *hw = mvm->hw;
292 struct ieee80211_chanctx_conf *chanctx_conf;
293 struct ieee80211_channel *chan;
294 int dtimper, dtimper_msec;
296 bool radar_detect = false;
297 struct iwl_mvm_vif *mvmvif __maybe_unused =
298 iwl_mvm_vif_from_mac80211(vif);
300 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
302 dtimper = hw->conf.ps_dtim_period ?: 1;
305 * Regardless of power management state the driver must set
306 * keep alive period. FW will use it for sending keep alive NDPs
307 * immediately after association. Check that keep alive period
308 * is at least 3 * DTIM
310 dtimper_msec = dtimper * vif->bss_conf.beacon_int;
311 keep_alive = max_t(int, 3 * dtimper_msec,
312 MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
313 keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
314 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
316 if (mvm->ps_disabled)
319 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
321 if (!vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif) ||
325 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
327 if (vif->bss_conf.beacon_rate &&
328 (vif->bss_conf.beacon_rate->bitrate == 10 ||
329 vif->bss_conf.beacon_rate->bitrate == 60)) {
330 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
331 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
334 /* Check if radar detection is required on current channel */
336 chanctx_conf = rcu_dereference(vif->chanctx_conf);
337 WARN_ON(!chanctx_conf);
339 chan = chanctx_conf->def.chan;
340 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
344 /* Check skip over DTIM conditions */
345 if (!radar_detect && (dtimper <= 10) &&
346 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
347 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
348 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
349 cmd->skip_dtim_periods = 3;
352 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
353 cmd->rx_data_timeout =
354 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
355 cmd->tx_data_timeout =
356 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
358 cmd->rx_data_timeout =
359 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
360 cmd->tx_data_timeout =
361 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
364 if (iwl_mvm_power_allow_uapsd(mvm, vif))
365 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
367 #ifdef CONFIG_IWLWIFI_DEBUGFS
368 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
369 cmd->keep_alive_seconds =
370 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
371 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
372 if (mvmvif->dbgfs_pm.skip_over_dtim)
374 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
377 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
379 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
380 cmd->rx_data_timeout =
381 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
382 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
383 cmd->tx_data_timeout =
384 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
385 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
386 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
387 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
388 if (mvmvif->dbgfs_pm.lprx_ena)
389 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
391 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
393 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
394 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
395 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
396 if (mvmvif->dbgfs_pm.snooze_ena)
398 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
401 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
403 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
404 u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
405 if (mvmvif->dbgfs_pm.uapsd_misbehaving)
406 cmd->flags |= cpu_to_le16(flag);
408 cmd->flags &= cpu_to_le16(flag);
410 #endif /* CONFIG_IWLWIFI_DEBUGFS */
413 static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
414 struct ieee80211_vif *vif)
416 struct iwl_mac_power_cmd cmd = {};
418 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
419 iwl_mvm_power_log(mvm, &cmd);
420 #ifdef CONFIG_IWLWIFI_DEBUGFS
421 memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
424 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0,
428 int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
430 struct iwl_device_power_cmd cmd = {
431 .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK),
434 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
435 mvm->ps_disabled = true;
437 if (mvm->ps_disabled)
438 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK);
440 #ifdef CONFIG_IWLWIFI_DEBUGFS
441 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
442 mvm->disable_power_off)
444 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
447 "Sending device power command with flags = 0x%X\n",
450 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd),
454 void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
456 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
458 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
460 memset(mvmvif->uapsd_misbehaving_bssid, 0, ETH_ALEN);
463 static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
464 struct ieee80211_vif *vif)
466 u8 *ap_sta_id = _data;
467 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
469 /* The ap_sta_id is not expected to change during current association
470 * so no explicit protection is needed
472 if (mvmvif->ap_sta_id == *ap_sta_id)
473 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
477 int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
478 struct iwl_rx_cmd_buffer *rxb,
479 struct iwl_device_cmd *cmd)
481 struct iwl_rx_packet *pkt = rxb_addr(rxb);
482 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
483 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
485 ieee80211_iterate_active_interfaces_atomic(
486 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
487 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
492 struct iwl_power_vifs {
494 struct ieee80211_vif *bf_vif;
495 struct ieee80211_vif *bss_vif;
496 struct ieee80211_vif *p2p_vif;
497 struct ieee80211_vif *ap_vif;
498 struct ieee80211_vif *monitor_vif;
507 static void iwl_mvm_power_iterator(void *_data, u8 *mac,
508 struct ieee80211_vif *vif)
510 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
511 struct iwl_power_vifs *power_iterator = _data;
513 mvmvif->pm_enabled = false;
514 switch (ieee80211_vif_type_p2p(vif)) {
515 case NL80211_IFTYPE_P2P_DEVICE:
518 case NL80211_IFTYPE_P2P_GO:
519 case NL80211_IFTYPE_AP:
520 /* only a single MAC of the same type */
521 WARN_ON(power_iterator->ap_vif);
522 power_iterator->ap_vif = vif;
523 if (mvmvif->phy_ctxt)
524 if (mvmvif->phy_ctxt->id < MAX_PHYS)
525 power_iterator->ap_active = true;
528 case NL80211_IFTYPE_MONITOR:
529 /* only a single MAC of the same type */
530 WARN_ON(power_iterator->monitor_vif);
531 power_iterator->monitor_vif = vif;
532 if (mvmvif->phy_ctxt)
533 if (mvmvif->phy_ctxt->id < MAX_PHYS)
534 power_iterator->monitor_active = true;
537 case NL80211_IFTYPE_P2P_CLIENT:
538 /* only a single MAC of the same type */
539 WARN_ON(power_iterator->p2p_vif);
540 power_iterator->p2p_vif = vif;
541 power_iterator->p2p_tdls =
542 !!iwl_mvm_tdls_sta_count(power_iterator->mvm, vif);
543 if (mvmvif->phy_ctxt)
544 if (mvmvif->phy_ctxt->id < MAX_PHYS)
545 power_iterator->p2p_active = true;
548 case NL80211_IFTYPE_STATION:
549 /* only a single MAC of the same type */
550 WARN_ON(power_iterator->bss_vif);
551 power_iterator->bss_vif = vif;
552 power_iterator->bss_tdls =
553 !!iwl_mvm_tdls_sta_count(power_iterator->mvm, vif);
554 if (mvmvif->phy_ctxt)
555 if (mvmvif->phy_ctxt->id < MAX_PHYS)
556 power_iterator->bss_active = true;
558 if (mvmvif->bf_data.bf_enabled &&
559 !WARN_ON(power_iterator->bf_vif))
560 power_iterator->bf_vif = vif;
570 iwl_mvm_power_set_pm(struct iwl_mvm *mvm,
571 struct iwl_power_vifs *vifs)
573 struct iwl_mvm_vif *bss_mvmvif = NULL;
574 struct iwl_mvm_vif *p2p_mvmvif = NULL;
575 struct iwl_mvm_vif *ap_mvmvif = NULL;
576 bool client_same_channel = false;
577 bool ap_same_channel = false;
579 lockdep_assert_held(&mvm->mutex);
581 /* get vifs info + set pm_enable to false */
582 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
583 IEEE80211_IFACE_ITER_NORMAL,
584 iwl_mvm_power_iterator, vifs);
587 bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif);
590 p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif);
593 ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif);
595 /* enable PM on bss if bss stand alone */
596 if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active &&
598 bss_mvmvif->pm_enabled = true;
602 /* enable PM on p2p if p2p stand alone */
603 if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active &&
605 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
606 p2p_mvmvif->pm_enabled = true;
610 if (vifs->bss_active && vifs->p2p_active)
611 client_same_channel = (bss_mvmvif->phy_ctxt->id ==
612 p2p_mvmvif->phy_ctxt->id);
613 if (vifs->bss_active && vifs->ap_active)
614 ap_same_channel = (bss_mvmvif->phy_ctxt->id ==
615 ap_mvmvif->phy_ctxt->id);
617 /* clients are not stand alone: enable PM if DCM */
618 if (!(client_same_channel || ap_same_channel) &&
619 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) {
620 if (vifs->bss_active)
621 bss_mvmvif->pm_enabled = true;
622 if (vifs->p2p_active &&
623 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM))
624 p2p_mvmvif->pm_enabled = true;
629 * There is only one channel in the system and there are only
630 * bss and p2p clients that share it
632 if (client_same_channel && !vifs->ap_active &&
633 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM)) {
634 /* share same channel*/
635 bss_mvmvif->pm_enabled = true;
636 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
637 p2p_mvmvif->pm_enabled = true;
641 #ifdef CONFIG_IWLWIFI_DEBUGFS
642 int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
643 struct ieee80211_vif *vif, char *buf,
646 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
647 struct iwl_mac_power_cmd cmd = {};
650 mutex_lock(&mvm->mutex);
651 memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
652 mutex_unlock(&mvm->mutex);
654 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
655 iwlmvm_mod_params.power_scheme);
656 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
657 le16_to_cpu(cmd.flags));
658 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
659 le16_to_cpu(cmd.keep_alive_seconds));
661 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
664 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
666 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
667 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
668 cmd.skip_dtim_periods);
669 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
670 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
671 le32_to_cpu(cmd.rx_data_timeout));
672 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
673 le32_to_cpu(cmd.tx_data_timeout));
675 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
676 pos += scnprintf(buf+pos, bufsz-pos,
677 "lprx_rssi_threshold = %d\n",
678 cmd.lprx_rssi_threshold);
680 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
683 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
684 le32_to_cpu(cmd.rx_data_timeout_uapsd));
685 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
686 le32_to_cpu(cmd.tx_data_timeout_uapsd));
687 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
688 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
690 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
692 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
693 cmd.heavy_tx_thld_packets);
694 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
695 cmd.heavy_rx_thld_packets);
696 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
697 cmd.heavy_tx_thld_percentage);
698 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
699 cmd.heavy_rx_thld_percentage);
700 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
702 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
705 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
708 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
709 cmd.snooze_interval);
710 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
717 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
718 struct iwl_beacon_filter_cmd *cmd)
720 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
721 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
723 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
724 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
725 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
726 cmd->bf_roaming_energy_delta =
727 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
728 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
729 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
730 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
731 cmd->bf_temp_threshold =
732 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
733 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
734 cmd->bf_temp_fast_filter =
735 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
736 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
737 cmd->bf_temp_slow_filter =
738 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
739 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
740 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
741 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
742 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
743 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
744 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
745 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
746 cmd->ba_enable_beacon_abort =
747 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
751 static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
752 struct ieee80211_vif *vif,
753 struct iwl_beacon_filter_cmd *cmd,
757 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
760 if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period ||
761 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
764 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd);
766 iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
767 ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
769 /* don't change bf_enabled in case of temporary d0i3 configuration */
771 mvmvif->bf_data.bf_enabled = true;
776 int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
777 struct ieee80211_vif *vif,
780 struct iwl_beacon_filter_cmd cmd = {
781 IWL_BF_CMD_CONFIG_DEFAULTS,
782 .bf_enable_beacon_filter = cpu_to_le32(1),
785 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
788 static int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
789 struct ieee80211_vif *vif,
792 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
793 struct iwl_beacon_filter_cmd cmd = {
794 IWL_BF_CMD_CONFIG_DEFAULTS,
795 .bf_enable_beacon_filter = cpu_to_le32(1),
798 if (!mvmvif->bf_data.bf_enabled)
801 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
802 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
804 mvmvif->bf_data.ba_enabled = enable;
805 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false);
808 int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
809 struct ieee80211_vif *vif,
812 struct iwl_beacon_filter_cmd cmd = {};
813 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
816 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
819 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
822 mvmvif->bf_data.bf_enabled = false;
827 int iwl_mvm_power_update_mac(struct iwl_mvm *mvm)
829 struct iwl_mvm_vif *mvmvif;
830 struct iwl_power_vifs vifs = {
836 lockdep_assert_held(&mvm->mutex);
838 iwl_mvm_power_set_pm(mvm, &vifs);
840 /* disable PS if CAM */
841 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) {
842 mvm->ps_disabled = true;
844 /* don't update device power state unless we add / remove monitor */
845 if (vifs.monitor_vif) {
846 if (vifs.monitor_active)
847 mvm->ps_disabled = true;
848 ret = iwl_mvm_power_update_device(mvm);
855 ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif);
861 ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif);
869 mvmvif = iwl_mvm_vif_from_mac80211(vifs.bf_vif);
871 ba_enable = !(!mvmvif->pm_enabled || mvm->ps_disabled ||
872 !vifs.bf_vif->bss_conf.ps ||
873 iwl_mvm_vif_low_latency(mvmvif));
875 return iwl_mvm_update_beacon_abort(mvm, vifs.bf_vif, ba_enable);
878 int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
879 struct ieee80211_vif *vif,
880 bool enable, u32 flags)
883 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
884 struct iwl_mac_power_cmd cmd = {};
886 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
889 if (!vif->bss_conf.assoc)
892 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
894 /* configure skip over dtim up to 300 msec */
895 int dtimper = mvm->hw->conf.ps_dtim_period ?: 1;
896 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
898 if (WARN_ON(!dtimper_msec))
901 cmd.skip_dtim_periods = 300 / dtimper_msec;
902 if (cmd.skip_dtim_periods)
904 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
906 iwl_mvm_power_log(mvm, &cmd);
907 #ifdef CONFIG_IWLWIFI_DEBUGFS
908 memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
910 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
915 /* configure beacon filtering */
916 if (mvmvif != mvm->bf_allowed_vif)
920 struct iwl_beacon_filter_cmd cmd_bf = {
921 IWL_BF_CMD_CONFIG_D0I3,
922 .bf_enable_beacon_filter = cpu_to_le32(1),
924 ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
927 if (mvmvif->bf_data.bf_enabled)
928 ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
930 ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);