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.
9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
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.
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.
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,
25 * The full GNU General Public License is included in this distribution
26 * in the file called COPYING.
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
36 * All rights reserved.
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
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
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.
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.
64 *****************************************************************************/
66 #include <linux/kernel.h>
67 #include <linux/module.h>
68 #include <linux/slab.h>
70 #include <net/mac80211.h>
72 #include "iwl-debug.h"
74 #include "iwl-modparams.h"
75 #include "fw-api-power.h"
77 #define POWER_KEEP_ALIVE_PERIOD_SEC 25
80 int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm
*mvm
,
81 struct iwl_beacon_filter_cmd
*cmd
,
84 IWL_DEBUG_POWER(mvm
, "ba_enable_beacon_abort is: %d\n",
85 le32_to_cpu(cmd
->ba_enable_beacon_abort
));
86 IWL_DEBUG_POWER(mvm
, "ba_escape_timer is: %d\n",
87 le32_to_cpu(cmd
->ba_escape_timer
));
88 IWL_DEBUG_POWER(mvm
, "bf_debug_flag is: %d\n",
89 le32_to_cpu(cmd
->bf_debug_flag
));
90 IWL_DEBUG_POWER(mvm
, "bf_enable_beacon_filter is: %d\n",
91 le32_to_cpu(cmd
->bf_enable_beacon_filter
));
92 IWL_DEBUG_POWER(mvm
, "bf_energy_delta is: %d\n",
93 le32_to_cpu(cmd
->bf_energy_delta
));
94 IWL_DEBUG_POWER(mvm
, "bf_escape_timer is: %d\n",
95 le32_to_cpu(cmd
->bf_escape_timer
));
96 IWL_DEBUG_POWER(mvm
, "bf_roaming_energy_delta is: %d\n",
97 le32_to_cpu(cmd
->bf_roaming_energy_delta
));
98 IWL_DEBUG_POWER(mvm
, "bf_roaming_state is: %d\n",
99 le32_to_cpu(cmd
->bf_roaming_state
));
100 IWL_DEBUG_POWER(mvm
, "bf_temp_threshold is: %d\n",
101 le32_to_cpu(cmd
->bf_temp_threshold
));
102 IWL_DEBUG_POWER(mvm
, "bf_temp_fast_filter is: %d\n",
103 le32_to_cpu(cmd
->bf_temp_fast_filter
));
104 IWL_DEBUG_POWER(mvm
, "bf_temp_slow_filter is: %d\n",
105 le32_to_cpu(cmd
->bf_temp_slow_filter
));
107 return iwl_mvm_send_cmd_pdu(mvm
, REPLY_BEACON_FILTERING_CMD
, flags
,
108 sizeof(struct iwl_beacon_filter_cmd
), cmd
);
112 void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm
*mvm
,
113 struct ieee80211_vif
*vif
,
114 struct iwl_beacon_filter_cmd
*cmd
)
116 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
118 if (vif
->bss_conf
.cqm_rssi_thold
) {
119 cmd
->bf_energy_delta
=
120 cpu_to_le32(vif
->bss_conf
.cqm_rssi_hyst
);
121 /* fw uses an absolute value for this */
122 cmd
->bf_roaming_state
=
123 cpu_to_le32(-vif
->bss_conf
.cqm_rssi_thold
);
125 cmd
->ba_enable_beacon_abort
= cpu_to_le32(mvmvif
->bf_data
.ba_enabled
);
128 static void iwl_mvm_power_log(struct iwl_mvm
*mvm
,
129 struct iwl_mac_power_cmd
*cmd
)
132 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
133 cmd
->id_and_color
, iwlmvm_mod_params
.power_scheme
,
134 le16_to_cpu(cmd
->flags
));
135 IWL_DEBUG_POWER(mvm
, "Keep alive = %u sec\n",
136 le16_to_cpu(cmd
->keep_alive_seconds
));
138 if (!(cmd
->flags
& cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
))) {
139 IWL_DEBUG_POWER(mvm
, "Disable power management\n");
143 IWL_DEBUG_POWER(mvm
, "Rx timeout = %u usec\n",
144 le32_to_cpu(cmd
->rx_data_timeout
));
145 IWL_DEBUG_POWER(mvm
, "Tx timeout = %u usec\n",
146 le32_to_cpu(cmd
->tx_data_timeout
));
147 if (cmd
->flags
& cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
))
148 IWL_DEBUG_POWER(mvm
, "DTIM periods to skip = %u\n",
149 cmd
->skip_dtim_periods
);
150 if (cmd
->flags
& cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK
))
151 IWL_DEBUG_POWER(mvm
, "LP RX RSSI threshold = %u\n",
152 cmd
->lprx_rssi_threshold
);
153 if (cmd
->flags
& cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
)) {
154 IWL_DEBUG_POWER(mvm
, "uAPSD enabled\n");
155 IWL_DEBUG_POWER(mvm
, "Rx timeout (uAPSD) = %u usec\n",
156 le32_to_cpu(cmd
->rx_data_timeout_uapsd
));
157 IWL_DEBUG_POWER(mvm
, "Tx timeout (uAPSD) = %u usec\n",
158 le32_to_cpu(cmd
->tx_data_timeout_uapsd
));
159 IWL_DEBUG_POWER(mvm
, "QNDP TID = %d\n", cmd
->qndp_tid
);
160 IWL_DEBUG_POWER(mvm
, "ACs flags = 0x%x\n", cmd
->uapsd_ac_flags
);
161 IWL_DEBUG_POWER(mvm
, "Max SP = %d\n", cmd
->uapsd_max_sp
);
165 static void iwl_mvm_power_configure_uapsd(struct iwl_mvm
*mvm
,
166 struct ieee80211_vif
*vif
,
167 struct iwl_mac_power_cmd
*cmd
)
169 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
170 enum ieee80211_ac_numbers ac
;
171 bool tid_found
= false;
173 for (ac
= IEEE80211_AC_VO
; ac
<= IEEE80211_AC_BK
; ac
++) {
174 if (!mvmvif
->queue_params
[ac
].uapsd
)
177 if (mvm
->cur_ucode
!= IWL_UCODE_WOWLAN
)
179 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
);
181 cmd
->uapsd_ac_flags
|= BIT(ac
);
183 /* QNDP TID - the highest TID with no admission control */
184 if (!tid_found
&& !mvmvif
->queue_params
[ac
].acm
) {
187 case IEEE80211_AC_VO
:
190 case IEEE80211_AC_VI
:
193 case IEEE80211_AC_BE
:
196 case IEEE80211_AC_BK
:
203 if (!(cmd
->flags
& cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
))) {
204 #ifdef CONFIG_IWLWIFI_DEBUGFS
205 /* set advanced pm flag with no uapsd ACs to enable ps-poll */
206 if (mvmvif
->dbgfs_pm
.use_ps_poll
)
208 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
);
213 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK
);
215 if (cmd
->uapsd_ac_flags
== (BIT(IEEE80211_AC_VO
) |
216 BIT(IEEE80211_AC_VI
) |
217 BIT(IEEE80211_AC_BE
) |
218 BIT(IEEE80211_AC_BK
))) {
219 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK
);
220 cmd
->snooze_interval
= cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL
);
221 cmd
->snooze_window
= (mvm
->cur_ucode
== IWL_UCODE_WOWLAN
) ?
222 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW
) :
223 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW
);
226 cmd
->uapsd_max_sp
= IWL_UAPSD_MAX_SP
;
228 if (mvm
->cur_ucode
== IWL_UCODE_WOWLAN
|| cmd
->flags
&
229 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK
)) {
230 cmd
->rx_data_timeout_uapsd
=
231 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT
);
232 cmd
->tx_data_timeout_uapsd
=
233 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT
);
235 cmd
->rx_data_timeout_uapsd
=
236 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT
);
237 cmd
->tx_data_timeout_uapsd
=
238 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT
);
241 if (cmd
->flags
& cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK
)) {
242 cmd
->heavy_tx_thld_packets
=
243 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS
;
244 cmd
->heavy_rx_thld_packets
=
245 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS
;
247 cmd
->heavy_tx_thld_packets
=
248 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS
;
249 cmd
->heavy_rx_thld_packets
=
250 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS
;
252 cmd
->heavy_tx_thld_percentage
=
253 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT
;
254 cmd
->heavy_rx_thld_percentage
=
255 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT
;
258 static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm
*mvm
,
259 struct ieee80211_vif
*vif
)
261 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
263 if (!memcmp(mvmvif
->uapsd_misbehaving_bssid
, vif
->bss_conf
.bssid
,
268 !(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD
))
271 * Avoid using uAPSD if P2P client is associated to GO that uses
272 * opportunistic power save. This is due to current FW limitation.
275 (vif
->bss_conf
.p2p_noa_attr
.oppps_ctwindow
&
276 IEEE80211_P2P_OPPPS_ENABLE_BIT
))
280 * Avoid using uAPSD if client is in DCM -
281 * low latency issue in Miracast
283 if (iwl_mvm_phy_ctx_count(mvm
) >= 2)
289 static int iwl_mvm_power_get_skip_over_dtim(int dtimper
, int bi
)
292 int dtim_interval
= dtimper
* bi
;
294 if (WARN_ON(!dtim_interval
))
302 } else if (dtimper
< 10) {
307 return max(1, (numerator
/ dtim_interval
));
310 static bool iwl_mvm_power_is_radar(struct ieee80211_vif
*vif
)
312 struct ieee80211_chanctx_conf
*chanctx_conf
;
313 struct ieee80211_channel
*chan
;
314 bool radar_detect
= false;
317 chanctx_conf
= rcu_dereference(vif
->chanctx_conf
);
318 WARN_ON(!chanctx_conf
);
320 chan
= chanctx_conf
->def
.chan
;
321 radar_detect
= chan
->flags
& IEEE80211_CHAN_RADAR
;
328 static void iwl_mvm_power_build_cmd(struct iwl_mvm
*mvm
,
329 struct ieee80211_vif
*vif
,
330 struct iwl_mac_power_cmd
*cmd
)
332 int dtimper
, dtimper_msec
, bi
;
334 bool radar_detect
= false;
335 struct iwl_mvm_vif
*mvmvif __maybe_unused
=
336 iwl_mvm_vif_from_mac80211(vif
);
338 cmd
->id_and_color
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
340 dtimper
= vif
->bss_conf
.dtim_period
;
341 bi
= vif
->bss_conf
.beacon_int
;
344 * Regardless of power management state the driver must set
345 * keep alive period. FW will use it for sending keep alive NDPs
346 * immediately after association. Check that keep alive period
347 * is at least 3 * DTIM
349 dtimper_msec
= dtimper
* bi
;
350 keep_alive
= max_t(int, 3 * dtimper_msec
,
351 MSEC_PER_SEC
* POWER_KEEP_ALIVE_PERIOD_SEC
);
352 keep_alive
= DIV_ROUND_UP(keep_alive
, MSEC_PER_SEC
);
353 cmd
->keep_alive_seconds
= cpu_to_le16(keep_alive
);
355 if (mvm
->ps_disabled
)
358 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK
);
360 if (!vif
->bss_conf
.ps
|| iwl_mvm_vif_low_latency(mvmvif
) ||
361 !mvmvif
->pm_enabled
|| iwl_mvm_tdls_sta_count(mvm
, vif
))
364 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
);
366 if (vif
->bss_conf
.beacon_rate
&&
367 (vif
->bss_conf
.beacon_rate
->bitrate
== 10 ||
368 vif
->bss_conf
.beacon_rate
->bitrate
== 60)) {
369 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK
);
370 cmd
->lprx_rssi_threshold
= POWER_LPRX_RSSI_THRESHOLD
;
373 /* Check if radar detection is required on current channel */
374 radar_detect
= iwl_mvm_power_is_radar(vif
);
376 /* Check skip over DTIM conditions */
377 if (!radar_detect
&& (dtimper
< 10) &&
378 (iwlmvm_mod_params
.power_scheme
== IWL_POWER_SCHEME_LP
||
379 mvm
->cur_ucode
== IWL_UCODE_WOWLAN
)) {
380 cmd
->skip_dtim_periods
=
381 iwl_mvm_power_get_skip_over_dtim(dtimper
, bi
);
382 if (cmd
->skip_dtim_periods
)
384 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
387 if (mvm
->cur_ucode
!= IWL_UCODE_WOWLAN
) {
388 cmd
->rx_data_timeout
=
389 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT
);
390 cmd
->tx_data_timeout
=
391 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT
);
393 cmd
->rx_data_timeout
=
394 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT
);
395 cmd
->tx_data_timeout
=
396 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT
);
399 if (iwl_mvm_power_allow_uapsd(mvm
, vif
))
400 iwl_mvm_power_configure_uapsd(mvm
, vif
, cmd
);
402 #ifdef CONFIG_IWLWIFI_DEBUGFS
403 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_KEEP_ALIVE
)
404 cmd
->keep_alive_seconds
=
405 cpu_to_le16(mvmvif
->dbgfs_pm
.keep_alive_seconds
);
406 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_SKIP_OVER_DTIM
) {
407 if (mvmvif
->dbgfs_pm
.skip_over_dtim
)
409 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
412 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
414 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_RX_DATA_TIMEOUT
)
415 cmd
->rx_data_timeout
=
416 cpu_to_le32(mvmvif
->dbgfs_pm
.rx_data_timeout
);
417 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_TX_DATA_TIMEOUT
)
418 cmd
->tx_data_timeout
=
419 cpu_to_le32(mvmvif
->dbgfs_pm
.tx_data_timeout
);
420 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS
)
421 cmd
->skip_dtim_periods
= mvmvif
->dbgfs_pm
.skip_dtim_periods
;
422 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_LPRX_ENA
) {
423 if (mvmvif
->dbgfs_pm
.lprx_ena
)
424 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK
);
426 cmd
->flags
&= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK
);
428 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD
)
429 cmd
->lprx_rssi_threshold
= mvmvif
->dbgfs_pm
.lprx_rssi_threshold
;
430 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_SNOOZE_ENABLE
) {
431 if (mvmvif
->dbgfs_pm
.snooze_ena
)
433 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK
);
436 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK
);
438 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_UAPSD_MISBEHAVING
) {
439 u16 flag
= POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK
;
440 if (mvmvif
->dbgfs_pm
.uapsd_misbehaving
)
441 cmd
->flags
|= cpu_to_le16(flag
);
443 cmd
->flags
&= cpu_to_le16(flag
);
445 #endif /* CONFIG_IWLWIFI_DEBUGFS */
448 static int iwl_mvm_power_send_cmd(struct iwl_mvm
*mvm
,
449 struct ieee80211_vif
*vif
)
451 struct iwl_mac_power_cmd cmd
= {};
453 iwl_mvm_power_build_cmd(mvm
, vif
, &cmd
);
454 iwl_mvm_power_log(mvm
, &cmd
);
455 #ifdef CONFIG_IWLWIFI_DEBUGFS
456 memcpy(&iwl_mvm_vif_from_mac80211(vif
)->mac_pwr_cmd
, &cmd
, sizeof(cmd
));
459 return iwl_mvm_send_cmd_pdu(mvm
, MAC_PM_POWER_TABLE
, 0,
463 int iwl_mvm_power_update_device(struct iwl_mvm
*mvm
)
465 struct iwl_device_power_cmd cmd
= {
466 .flags
= cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK
),
469 if (iwlmvm_mod_params
.power_scheme
== IWL_POWER_SCHEME_CAM
)
470 mvm
->ps_disabled
= true;
472 if (mvm
->ps_disabled
)
473 cmd
.flags
|= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK
);
475 #ifdef CONFIG_IWLWIFI_DEBUGFS
476 if ((mvm
->cur_ucode
== IWL_UCODE_WOWLAN
) ? mvm
->disable_power_off_d3
:
477 mvm
->disable_power_off
)
479 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK
);
482 "Sending device power command with flags = 0x%X\n",
485 return iwl_mvm_send_cmd_pdu(mvm
, POWER_TABLE_CMD
, 0, sizeof(cmd
),
489 void iwl_mvm_power_vif_assoc(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
491 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
493 if (memcmp(vif
->bss_conf
.bssid
, mvmvif
->uapsd_misbehaving_bssid
,
495 memset(mvmvif
->uapsd_misbehaving_bssid
, 0, ETH_ALEN
);
498 static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data
, u8
*mac
,
499 struct ieee80211_vif
*vif
)
501 u8
*ap_sta_id
= _data
;
502 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
504 /* The ap_sta_id is not expected to change during current association
505 * so no explicit protection is needed
507 if (mvmvif
->ap_sta_id
== *ap_sta_id
)
508 memcpy(mvmvif
->uapsd_misbehaving_bssid
, vif
->bss_conf
.bssid
,
512 int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm
*mvm
,
513 struct iwl_rx_cmd_buffer
*rxb
,
514 struct iwl_device_cmd
*cmd
)
516 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
517 struct iwl_uapsd_misbehaving_ap_notif
*notif
= (void *)pkt
->data
;
518 u8 ap_sta_id
= le32_to_cpu(notif
->sta_id
);
520 ieee80211_iterate_active_interfaces_atomic(
521 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
522 iwl_mvm_power_uapsd_misbehav_ap_iterator
, &ap_sta_id
);
527 struct iwl_power_vifs
{
529 struct ieee80211_vif
*bf_vif
;
530 struct ieee80211_vif
*bss_vif
;
531 struct ieee80211_vif
*p2p_vif
;
532 struct ieee80211_vif
*ap_vif
;
533 struct ieee80211_vif
*monitor_vif
;
540 static void iwl_mvm_power_disable_pm_iterator(void *_data
, u8
* mac
,
541 struct ieee80211_vif
*vif
)
543 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
545 mvmvif
->pm_enabled
= false;
548 static void iwl_mvm_power_ps_disabled_iterator(void *_data
, u8
* mac
,
549 struct ieee80211_vif
*vif
)
551 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
552 bool *disable_ps
= _data
;
554 if (mvmvif
->phy_ctxt
)
555 if (mvmvif
->phy_ctxt
->id
< MAX_PHYS
)
556 *disable_ps
|= mvmvif
->ps_disabled
;
559 static void iwl_mvm_power_get_vifs_iterator(void *_data
, u8
*mac
,
560 struct ieee80211_vif
*vif
)
562 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
563 struct iwl_power_vifs
*power_iterator
= _data
;
565 switch (ieee80211_vif_type_p2p(vif
)) {
566 case NL80211_IFTYPE_P2P_DEVICE
:
569 case NL80211_IFTYPE_P2P_GO
:
570 case NL80211_IFTYPE_AP
:
571 /* only a single MAC of the same type */
572 WARN_ON(power_iterator
->ap_vif
);
573 power_iterator
->ap_vif
= vif
;
574 if (mvmvif
->phy_ctxt
)
575 if (mvmvif
->phy_ctxt
->id
< MAX_PHYS
)
576 power_iterator
->ap_active
= true;
579 case NL80211_IFTYPE_MONITOR
:
580 /* only a single MAC of the same type */
581 WARN_ON(power_iterator
->monitor_vif
);
582 power_iterator
->monitor_vif
= vif
;
583 if (mvmvif
->phy_ctxt
)
584 if (mvmvif
->phy_ctxt
->id
< MAX_PHYS
)
585 power_iterator
->monitor_active
= true;
588 case NL80211_IFTYPE_P2P_CLIENT
:
589 /* only a single MAC of the same type */
590 WARN_ON(power_iterator
->p2p_vif
);
591 power_iterator
->p2p_vif
= vif
;
592 if (mvmvif
->phy_ctxt
)
593 if (mvmvif
->phy_ctxt
->id
< MAX_PHYS
)
594 power_iterator
->p2p_active
= true;
597 case NL80211_IFTYPE_STATION
:
598 /* only a single MAC of the same type */
599 WARN_ON(power_iterator
->bss_vif
);
600 power_iterator
->bss_vif
= vif
;
601 if (mvmvif
->phy_ctxt
)
602 if (mvmvif
->phy_ctxt
->id
< MAX_PHYS
)
603 power_iterator
->bss_active
= true;
605 if (mvmvif
->bf_data
.bf_enabled
&&
606 !WARN_ON(power_iterator
->bf_vif
))
607 power_iterator
->bf_vif
= vif
;
616 static void iwl_mvm_power_set_pm(struct iwl_mvm
*mvm
,
617 struct iwl_power_vifs
*vifs
)
619 struct iwl_mvm_vif
*bss_mvmvif
= NULL
;
620 struct iwl_mvm_vif
*p2p_mvmvif
= NULL
;
621 struct iwl_mvm_vif
*ap_mvmvif
= NULL
;
622 bool client_same_channel
= false;
623 bool ap_same_channel
= false;
625 lockdep_assert_held(&mvm
->mutex
);
627 /* set pm_enable to false */
628 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
629 IEEE80211_IFACE_ITER_NORMAL
,
630 iwl_mvm_power_disable_pm_iterator
,
634 bss_mvmvif
= iwl_mvm_vif_from_mac80211(vifs
->bss_vif
);
637 p2p_mvmvif
= iwl_mvm_vif_from_mac80211(vifs
->p2p_vif
);
640 ap_mvmvif
= iwl_mvm_vif_from_mac80211(vifs
->ap_vif
);
642 /* enable PM on bss if bss stand alone */
643 if (vifs
->bss_active
&& !vifs
->p2p_active
&& !vifs
->ap_active
) {
644 bss_mvmvif
->pm_enabled
= true;
648 /* enable PM on p2p if p2p stand alone */
649 if (vifs
->p2p_active
&& !vifs
->bss_active
&& !vifs
->ap_active
) {
650 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_P2P_PM
)
651 p2p_mvmvif
->pm_enabled
= true;
655 if (vifs
->bss_active
&& vifs
->p2p_active
)
656 client_same_channel
= (bss_mvmvif
->phy_ctxt
->id
==
657 p2p_mvmvif
->phy_ctxt
->id
);
658 if (vifs
->bss_active
&& vifs
->ap_active
)
659 ap_same_channel
= (bss_mvmvif
->phy_ctxt
->id
==
660 ap_mvmvif
->phy_ctxt
->id
);
662 /* clients are not stand alone: enable PM if DCM */
663 if (!(client_same_channel
|| ap_same_channel
) &&
664 (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM
)) {
665 if (vifs
->bss_active
)
666 bss_mvmvif
->pm_enabled
= true;
667 if (vifs
->p2p_active
&&
668 (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_P2P_PM
))
669 p2p_mvmvif
->pm_enabled
= true;
674 * There is only one channel in the system and there are only
675 * bss and p2p clients that share it
677 if (client_same_channel
&& !vifs
->ap_active
&&
678 (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM
)) {
679 /* share same channel*/
680 bss_mvmvif
->pm_enabled
= true;
681 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_P2P_PM
)
682 p2p_mvmvif
->pm_enabled
= true;
686 #ifdef CONFIG_IWLWIFI_DEBUGFS
687 int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm
*mvm
,
688 struct ieee80211_vif
*vif
, char *buf
,
691 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
692 struct iwl_mac_power_cmd cmd
= {};
695 mutex_lock(&mvm
->mutex
);
696 memcpy(&cmd
, &mvmvif
->mac_pwr_cmd
, sizeof(cmd
));
697 mutex_unlock(&mvm
->mutex
);
699 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "power_scheme = %d\n",
700 iwlmvm_mod_params
.power_scheme
);
701 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "flags = 0x%x\n",
702 le16_to_cpu(cmd
.flags
));
703 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "keep_alive = %d\n",
704 le16_to_cpu(cmd
.keep_alive_seconds
));
706 if (!(cmd
.flags
& cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
)))
709 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "skip_over_dtim = %d\n",
711 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
)) ? 1 : 0);
712 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "skip_dtim_periods = %d\n",
713 cmd
.skip_dtim_periods
);
714 if (!(cmd
.flags
& cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
))) {
715 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "rx_data_timeout = %d\n",
716 le32_to_cpu(cmd
.rx_data_timeout
));
717 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "tx_data_timeout = %d\n",
718 le32_to_cpu(cmd
.tx_data_timeout
));
720 if (cmd
.flags
& cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK
))
721 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
722 "lprx_rssi_threshold = %d\n",
723 cmd
.lprx_rssi_threshold
);
725 if (!(cmd
.flags
& cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
)))
728 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "rx_data_timeout_uapsd = %d\n",
729 le32_to_cpu(cmd
.rx_data_timeout_uapsd
));
730 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "tx_data_timeout_uapsd = %d\n",
731 le32_to_cpu(cmd
.tx_data_timeout_uapsd
));
732 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "qndp_tid = %d\n", cmd
.qndp_tid
);
733 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "uapsd_ac_flags = 0x%x\n",
735 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "uapsd_max_sp = %d\n",
737 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "heavy_tx_thld_packets = %d\n",
738 cmd
.heavy_tx_thld_packets
);
739 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "heavy_rx_thld_packets = %d\n",
740 cmd
.heavy_rx_thld_packets
);
741 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "heavy_tx_thld_percentage = %d\n",
742 cmd
.heavy_tx_thld_percentage
);
743 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "heavy_rx_thld_percentage = %d\n",
744 cmd
.heavy_rx_thld_percentage
);
745 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "uapsd_misbehaving_enable = %d\n",
747 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK
)) ?
750 if (!(cmd
.flags
& cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK
)))
753 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "snooze_interval = %d\n",
754 cmd
.snooze_interval
);
755 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "snooze_window = %d\n",
762 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif
*vif
,
763 struct iwl_beacon_filter_cmd
*cmd
)
765 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
766 struct iwl_dbgfs_bf
*dbgfs_bf
= &mvmvif
->dbgfs_bf
;
768 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ENERGY_DELTA
)
769 cmd
->bf_energy_delta
= cpu_to_le32(dbgfs_bf
->bf_energy_delta
);
770 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA
)
771 cmd
->bf_roaming_energy_delta
=
772 cpu_to_le32(dbgfs_bf
->bf_roaming_energy_delta
);
773 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ROAMING_STATE
)
774 cmd
->bf_roaming_state
= cpu_to_le32(dbgfs_bf
->bf_roaming_state
);
775 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_TEMP_THRESHOLD
)
776 cmd
->bf_temp_threshold
=
777 cpu_to_le32(dbgfs_bf
->bf_temp_threshold
);
778 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_TEMP_FAST_FILTER
)
779 cmd
->bf_temp_fast_filter
=
780 cpu_to_le32(dbgfs_bf
->bf_temp_fast_filter
);
781 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_TEMP_SLOW_FILTER
)
782 cmd
->bf_temp_slow_filter
=
783 cpu_to_le32(dbgfs_bf
->bf_temp_slow_filter
);
784 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_DEBUG_FLAG
)
785 cmd
->bf_debug_flag
= cpu_to_le32(dbgfs_bf
->bf_debug_flag
);
786 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ESCAPE_TIMER
)
787 cmd
->bf_escape_timer
= cpu_to_le32(dbgfs_bf
->bf_escape_timer
);
788 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BA_ESCAPE_TIMER
)
789 cmd
->ba_escape_timer
= cpu_to_le32(dbgfs_bf
->ba_escape_timer
);
790 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT
)
791 cmd
->ba_enable_beacon_abort
=
792 cpu_to_le32(dbgfs_bf
->ba_enable_beacon_abort
);
796 static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm
*mvm
,
797 struct ieee80211_vif
*vif
,
798 struct iwl_beacon_filter_cmd
*cmd
,
802 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
805 if (mvmvif
!= mvm
->bf_allowed_vif
|| !vif
->bss_conf
.dtim_period
||
806 vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
809 iwl_mvm_beacon_filter_set_cqm_params(mvm
, vif
, cmd
);
811 iwl_mvm_beacon_filter_debugfs_parameters(vif
, cmd
);
812 ret
= iwl_mvm_beacon_filter_send_cmd(mvm
, cmd
, cmd_flags
);
814 /* don't change bf_enabled in case of temporary d0i3 configuration */
816 mvmvif
->bf_data
.bf_enabled
= true;
821 int iwl_mvm_enable_beacon_filter(struct iwl_mvm
*mvm
,
822 struct ieee80211_vif
*vif
,
825 struct iwl_beacon_filter_cmd cmd
= {
826 IWL_BF_CMD_CONFIG_DEFAULTS
,
827 .bf_enable_beacon_filter
= cpu_to_le32(1),
830 return _iwl_mvm_enable_beacon_filter(mvm
, vif
, &cmd
, flags
, false);
833 static int iwl_mvm_update_beacon_abort(struct iwl_mvm
*mvm
,
834 struct ieee80211_vif
*vif
,
837 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
838 struct iwl_beacon_filter_cmd cmd
= {
839 IWL_BF_CMD_CONFIG_DEFAULTS
,
840 .bf_enable_beacon_filter
= cpu_to_le32(1),
843 if (!mvmvif
->bf_data
.bf_enabled
)
846 if (mvm
->cur_ucode
== IWL_UCODE_WOWLAN
)
847 cmd
.ba_escape_timer
= cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3
);
849 mvmvif
->bf_data
.ba_enabled
= enable
;
850 return _iwl_mvm_enable_beacon_filter(mvm
, vif
, &cmd
, 0, false);
853 int iwl_mvm_disable_beacon_filter(struct iwl_mvm
*mvm
,
854 struct ieee80211_vif
*vif
,
857 struct iwl_beacon_filter_cmd cmd
= {};
858 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
861 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
864 ret
= iwl_mvm_beacon_filter_send_cmd(mvm
, &cmd
, flags
);
867 mvmvif
->bf_data
.bf_enabled
= false;
872 static int iwl_mvm_power_set_ps(struct iwl_mvm
*mvm
)
877 /* disable PS if CAM */
878 disable_ps
= (iwlmvm_mod_params
.power_scheme
== IWL_POWER_SCHEME_CAM
);
879 /* ...or if any of the vifs require PS to be off */
880 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
881 IEEE80211_IFACE_ITER_NORMAL
,
882 iwl_mvm_power_ps_disabled_iterator
,
885 /* update device power state if it has changed */
886 if (mvm
->ps_disabled
!= disable_ps
) {
887 bool old_ps_disabled
= mvm
->ps_disabled
;
889 mvm
->ps_disabled
= disable_ps
;
890 ret
= iwl_mvm_power_update_device(mvm
);
892 mvm
->ps_disabled
= old_ps_disabled
;
900 static int iwl_mvm_power_set_ba(struct iwl_mvm
*mvm
,
901 struct iwl_power_vifs
*vifs
)
903 struct iwl_mvm_vif
*mvmvif
;
909 mvmvif
= iwl_mvm_vif_from_mac80211(vifs
->bf_vif
);
911 ba_enable
= !(!mvmvif
->pm_enabled
|| mvm
->ps_disabled
||
912 !vifs
->bf_vif
->bss_conf
.ps
||
913 iwl_mvm_vif_low_latency(mvmvif
));
915 return iwl_mvm_update_beacon_abort(mvm
, vifs
->bf_vif
, ba_enable
);
918 int iwl_mvm_power_update_ps(struct iwl_mvm
*mvm
)
920 struct iwl_power_vifs vifs
= {
925 lockdep_assert_held(&mvm
->mutex
);
928 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
929 IEEE80211_IFACE_ITER_NORMAL
,
930 iwl_mvm_power_get_vifs_iterator
, &vifs
);
932 ret
= iwl_mvm_power_set_ps(mvm
);
936 return iwl_mvm_power_set_ba(mvm
, &vifs
);
939 int iwl_mvm_power_update_mac(struct iwl_mvm
*mvm
)
941 struct iwl_power_vifs vifs
= {
946 lockdep_assert_held(&mvm
->mutex
);
949 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
950 IEEE80211_IFACE_ITER_NORMAL
,
951 iwl_mvm_power_get_vifs_iterator
, &vifs
);
953 iwl_mvm_power_set_pm(mvm
, &vifs
);
955 ret
= iwl_mvm_power_set_ps(mvm
);
960 ret
= iwl_mvm_power_send_cmd(mvm
, vifs
.bss_vif
);
966 ret
= iwl_mvm_power_send_cmd(mvm
, vifs
.p2p_vif
);
971 return iwl_mvm_power_set_ba(mvm
, &vifs
);
974 int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm
*mvm
,
975 struct ieee80211_vif
*vif
,
976 bool enable
, u32 flags
)
979 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
980 struct iwl_mac_power_cmd cmd
= {};
982 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
985 if (!vif
->bss_conf
.assoc
)
988 iwl_mvm_power_build_cmd(mvm
, vif
, &cmd
);
990 /* configure skip over dtim up to 306TU - 314 msec */
991 int dtimper
= vif
->bss_conf
.dtim_period
?: 1;
992 int dtimper_tu
= dtimper
* vif
->bss_conf
.beacon_int
;
993 bool radar_detect
= iwl_mvm_power_is_radar(vif
);
995 if (WARN_ON(!dtimper_tu
))
998 /* Check skip over DTIM conditions */
999 /* TODO: check that multicast wake lock is off */
1000 if (!radar_detect
&& (dtimper
< 10)) {
1001 cmd
.skip_dtim_periods
= 306 / dtimper_tu
;
1002 if (cmd
.skip_dtim_periods
)
1003 cmd
.flags
|= cpu_to_le16(
1004 POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
1007 iwl_mvm_power_log(mvm
, &cmd
);
1008 #ifdef CONFIG_IWLWIFI_DEBUGFS
1009 memcpy(&mvmvif
->mac_pwr_cmd
, &cmd
, sizeof(cmd
));
1011 ret
= iwl_mvm_send_cmd_pdu(mvm
, MAC_PM_POWER_TABLE
, flags
,
1016 /* configure beacon filtering */
1017 if (mvmvif
!= mvm
->bf_allowed_vif
)
1021 struct iwl_beacon_filter_cmd cmd_bf
= {
1022 IWL_BF_CMD_CONFIG_D0I3
,
1023 .bf_enable_beacon_filter
= cpu_to_le32(1),
1025 ret
= _iwl_mvm_enable_beacon_filter(mvm
, vif
, &cmd_bf
,
1028 if (mvmvif
->bf_data
.bf_enabled
)
1029 ret
= iwl_mvm_enable_beacon_filter(mvm
, vif
, flags
);
1031 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, flags
);