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
10 * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
26 * The full GNU General Public License is included in this distribution
27 * in the file called COPYING.
29 * Contact Information:
30 * Intel Linux Wireless <linuxwifi@intel.com>
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
36 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
37 * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
44 * * Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * * Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in
48 * the documentation and/or other materials provided with the
50 * * Neither the name Intel Corporation nor the names of its
51 * contributors may be used to endorse or promote products derived
52 * from this software without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
55 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
56 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
57 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
58 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
59 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
60 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
61 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
62 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
63 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
64 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
66 *****************************************************************************/
68 #include <linux/kernel.h>
69 #include <linux/module.h>
70 #include <linux/slab.h>
71 #include <linux/etherdevice.h>
73 #include <net/mac80211.h>
75 #include "iwl-debug.h"
77 #include "iwl-modparams.h"
78 #include "fw-api-power.h"
80 #define POWER_KEEP_ALIVE_PERIOD_SEC 25
83 int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm
*mvm
,
84 struct iwl_beacon_filter_cmd
*cmd
,
87 IWL_DEBUG_POWER(mvm
, "ba_enable_beacon_abort is: %d\n",
88 le32_to_cpu(cmd
->ba_enable_beacon_abort
));
89 IWL_DEBUG_POWER(mvm
, "ba_escape_timer is: %d\n",
90 le32_to_cpu(cmd
->ba_escape_timer
));
91 IWL_DEBUG_POWER(mvm
, "bf_debug_flag is: %d\n",
92 le32_to_cpu(cmd
->bf_debug_flag
));
93 IWL_DEBUG_POWER(mvm
, "bf_enable_beacon_filter is: %d\n",
94 le32_to_cpu(cmd
->bf_enable_beacon_filter
));
95 IWL_DEBUG_POWER(mvm
, "bf_energy_delta is: %d\n",
96 le32_to_cpu(cmd
->bf_energy_delta
));
97 IWL_DEBUG_POWER(mvm
, "bf_escape_timer is: %d\n",
98 le32_to_cpu(cmd
->bf_escape_timer
));
99 IWL_DEBUG_POWER(mvm
, "bf_roaming_energy_delta is: %d\n",
100 le32_to_cpu(cmd
->bf_roaming_energy_delta
));
101 IWL_DEBUG_POWER(mvm
, "bf_roaming_state is: %d\n",
102 le32_to_cpu(cmd
->bf_roaming_state
));
103 IWL_DEBUG_POWER(mvm
, "bf_temp_threshold is: %d\n",
104 le32_to_cpu(cmd
->bf_temp_threshold
));
105 IWL_DEBUG_POWER(mvm
, "bf_temp_fast_filter is: %d\n",
106 le32_to_cpu(cmd
->bf_temp_fast_filter
));
107 IWL_DEBUG_POWER(mvm
, "bf_temp_slow_filter is: %d\n",
108 le32_to_cpu(cmd
->bf_temp_slow_filter
));
110 return iwl_mvm_send_cmd_pdu(mvm
, REPLY_BEACON_FILTERING_CMD
, flags
,
111 sizeof(struct iwl_beacon_filter_cmd
), cmd
);
115 void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm
*mvm
,
116 struct ieee80211_vif
*vif
,
117 struct iwl_beacon_filter_cmd
*cmd
,
120 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
122 if (vif
->bss_conf
.cqm_rssi_thold
&& !d0i3
) {
123 cmd
->bf_energy_delta
=
124 cpu_to_le32(vif
->bss_conf
.cqm_rssi_hyst
);
125 /* fw uses an absolute value for this */
126 cmd
->bf_roaming_state
=
127 cpu_to_le32(-vif
->bss_conf
.cqm_rssi_thold
);
129 cmd
->ba_enable_beacon_abort
= cpu_to_le32(mvmvif
->bf_data
.ba_enabled
);
132 static void iwl_mvm_power_log(struct iwl_mvm
*mvm
,
133 struct iwl_mac_power_cmd
*cmd
)
136 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
137 cmd
->id_and_color
, iwlmvm_mod_params
.power_scheme
,
138 le16_to_cpu(cmd
->flags
));
139 IWL_DEBUG_POWER(mvm
, "Keep alive = %u sec\n",
140 le16_to_cpu(cmd
->keep_alive_seconds
));
142 if (!(cmd
->flags
& cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
))) {
143 IWL_DEBUG_POWER(mvm
, "Disable power management\n");
147 IWL_DEBUG_POWER(mvm
, "Rx timeout = %u usec\n",
148 le32_to_cpu(cmd
->rx_data_timeout
));
149 IWL_DEBUG_POWER(mvm
, "Tx timeout = %u usec\n",
150 le32_to_cpu(cmd
->tx_data_timeout
));
151 if (cmd
->flags
& cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
))
152 IWL_DEBUG_POWER(mvm
, "DTIM periods to skip = %u\n",
153 cmd
->skip_dtim_periods
);
154 if (cmd
->flags
& cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK
))
155 IWL_DEBUG_POWER(mvm
, "LP RX RSSI threshold = %u\n",
156 cmd
->lprx_rssi_threshold
);
157 if (cmd
->flags
& cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
)) {
158 IWL_DEBUG_POWER(mvm
, "uAPSD enabled\n");
159 IWL_DEBUG_POWER(mvm
, "Rx timeout (uAPSD) = %u usec\n",
160 le32_to_cpu(cmd
->rx_data_timeout_uapsd
));
161 IWL_DEBUG_POWER(mvm
, "Tx timeout (uAPSD) = %u usec\n",
162 le32_to_cpu(cmd
->tx_data_timeout_uapsd
));
163 IWL_DEBUG_POWER(mvm
, "QNDP TID = %d\n", cmd
->qndp_tid
);
164 IWL_DEBUG_POWER(mvm
, "ACs flags = 0x%x\n", cmd
->uapsd_ac_flags
);
165 IWL_DEBUG_POWER(mvm
, "Max SP = %d\n", cmd
->uapsd_max_sp
);
169 static void iwl_mvm_power_configure_uapsd(struct iwl_mvm
*mvm
,
170 struct ieee80211_vif
*vif
,
171 struct iwl_mac_power_cmd
*cmd
)
173 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
174 enum ieee80211_ac_numbers ac
;
175 bool tid_found
= false;
177 #ifdef CONFIG_IWLWIFI_DEBUGFS
178 /* set advanced pm flag with no uapsd ACs to enable ps-poll */
179 if (mvmvif
->dbgfs_pm
.use_ps_poll
) {
180 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
);
185 for (ac
= IEEE80211_AC_VO
; ac
<= IEEE80211_AC_BK
; ac
++) {
186 if (!mvmvif
->queue_params
[ac
].uapsd
)
189 if (mvm
->cur_ucode
!= IWL_UCODE_WOWLAN
)
191 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
);
193 cmd
->uapsd_ac_flags
|= BIT(ac
);
195 /* QNDP TID - the highest TID with no admission control */
196 if (!tid_found
&& !mvmvif
->queue_params
[ac
].acm
) {
199 case IEEE80211_AC_VO
:
202 case IEEE80211_AC_VI
:
205 case IEEE80211_AC_BE
:
208 case IEEE80211_AC_BK
:
215 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK
);
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
);
228 cmd
->uapsd_max_sp
= mvm
->hw
->uapsd_max_sp_len
;
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
);
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
);
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
;
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
;
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
;
260 static void iwl_mvm_p2p_standalone_iterator(void *_data
, u8
*mac
,
261 struct ieee80211_vif
*vif
)
263 bool *is_p2p_standalone
= _data
;
265 switch (ieee80211_vif_type_p2p(vif
)) {
266 case NL80211_IFTYPE_P2P_GO
:
267 case NL80211_IFTYPE_AP
:
268 *is_p2p_standalone
= false;
270 case NL80211_IFTYPE_STATION
:
271 if (vif
->bss_conf
.assoc
)
272 *is_p2p_standalone
= false;
280 static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm
*mvm
,
281 struct ieee80211_vif
*vif
)
283 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
285 if (!memcmp(mvmvif
->uapsd_misbehaving_bssid
, vif
->bss_conf
.bssid
,
290 * Avoid using uAPSD if P2P client is associated to GO that uses
291 * opportunistic power save. This is due to current FW limitation.
294 (vif
->bss_conf
.p2p_noa_attr
.oppps_ctwindow
&
295 IEEE80211_P2P_OPPPS_ENABLE_BIT
))
299 * Avoid using uAPSD if client is in DCM -
300 * low latency issue in Miracast
302 if (iwl_mvm_phy_ctx_count(mvm
) >= 2)
306 /* Allow U-APSD only if p2p is stand alone */
307 bool is_p2p_standalone
= true;
309 if (!iwl_mvm_is_p2p_scm_uapsd_supported(mvm
))
312 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
313 IEEE80211_IFACE_ITER_NORMAL
,
314 iwl_mvm_p2p_standalone_iterator
,
317 if (!is_p2p_standalone
)
324 static bool iwl_mvm_power_is_radar(struct ieee80211_vif
*vif
)
326 struct ieee80211_chanctx_conf
*chanctx_conf
;
327 struct ieee80211_channel
*chan
;
328 bool radar_detect
= false;
331 chanctx_conf
= rcu_dereference(vif
->chanctx_conf
);
332 WARN_ON(!chanctx_conf
);
334 chan
= chanctx_conf
->def
.chan
;
335 radar_detect
= chan
->flags
& IEEE80211_CHAN_RADAR
;
342 static void iwl_mvm_power_config_skip_dtim(struct iwl_mvm
*mvm
,
343 struct ieee80211_vif
*vif
,
344 struct iwl_mac_power_cmd
*cmd
,
347 int dtimper
= vif
->bss_conf
.dtim_period
?: 1;
350 /* disable, in case we're supposed to override */
351 cmd
->skip_dtim_periods
= 0;
352 cmd
->flags
&= ~cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
354 if (iwl_mvm_power_is_radar(vif
))
360 /* TODO: check that multicast wake lock is off */
363 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_LP
)
367 int dtimper_tu
= dtimper
* vif
->bss_conf
.beacon_int
;
369 if (WARN_ON(!dtimper_tu
))
371 /* configure skip over dtim up to 306TU - 314 msec */
372 skip
= max_t(u8
, 1, 306 / dtimper_tu
);
375 /* the firmware really expects "look at every X DTIMs", so add 1 */
376 cmd
->skip_dtim_periods
= 1 + skip
;
377 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
380 static void iwl_mvm_power_build_cmd(struct iwl_mvm
*mvm
,
381 struct ieee80211_vif
*vif
,
382 struct iwl_mac_power_cmd
*cmd
,
387 struct iwl_mvm_vif
*mvmvif __maybe_unused
=
388 iwl_mvm_vif_from_mac80211(vif
);
390 cmd
->id_and_color
= cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
392 dtimper
= vif
->bss_conf
.dtim_period
;
393 bi
= vif
->bss_conf
.beacon_int
;
396 * Regardless of power management state the driver must set
397 * keep alive period. FW will use it for sending keep alive NDPs
398 * immediately after association. Check that keep alive period
399 * is at least 3 * DTIM
401 keep_alive
= DIV_ROUND_UP(ieee80211_tu_to_usec(3 * dtimper
* bi
),
403 keep_alive
= max(keep_alive
, POWER_KEEP_ALIVE_PERIOD_SEC
);
404 cmd
->keep_alive_seconds
= cpu_to_le16(keep_alive
);
406 if (mvm
->ps_disabled
)
409 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK
);
411 if (!vif
->bss_conf
.ps
|| !mvmvif
->pm_enabled
)
414 if (iwl_mvm_vif_low_latency(mvmvif
) && vif
->p2p
&&
415 (!fw_has_capa(&mvm
->fw
->ucode_capa
,
416 IWL_UCODE_TLV_CAPA_SHORT_PM_TIMEOUTS
) ||
417 !IWL_MVM_P2P_LOWLATENCY_PS_ENABLE
))
420 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
);
422 if (vif
->bss_conf
.beacon_rate
&&
423 (vif
->bss_conf
.beacon_rate
->bitrate
== 10 ||
424 vif
->bss_conf
.beacon_rate
->bitrate
== 60)) {
425 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK
);
426 cmd
->lprx_rssi_threshold
= POWER_LPRX_RSSI_THRESHOLD
;
429 iwl_mvm_power_config_skip_dtim(mvm
, vif
, cmd
, host_awake
);
432 cmd
->rx_data_timeout
=
433 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT
);
434 cmd
->tx_data_timeout
=
435 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT
);
436 } else if (iwl_mvm_vif_low_latency(mvmvif
) && vif
->p2p
&&
437 fw_has_capa(&mvm
->fw
->ucode_capa
,
438 IWL_UCODE_TLV_CAPA_SHORT_PM_TIMEOUTS
)) {
439 cmd
->tx_data_timeout
=
440 cpu_to_le32(IWL_MVM_SHORT_PS_TX_DATA_TIMEOUT
);
441 cmd
->rx_data_timeout
=
442 cpu_to_le32(IWL_MVM_SHORT_PS_RX_DATA_TIMEOUT
);
444 cmd
->rx_data_timeout
=
445 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT
);
446 cmd
->tx_data_timeout
=
447 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT
);
450 if (iwl_mvm_power_allow_uapsd(mvm
, vif
))
451 iwl_mvm_power_configure_uapsd(mvm
, vif
, cmd
);
453 #ifdef CONFIG_IWLWIFI_DEBUGFS
454 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_KEEP_ALIVE
)
455 cmd
->keep_alive_seconds
=
456 cpu_to_le16(mvmvif
->dbgfs_pm
.keep_alive_seconds
);
457 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_SKIP_OVER_DTIM
) {
458 if (mvmvif
->dbgfs_pm
.skip_over_dtim
)
460 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
463 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
465 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_RX_DATA_TIMEOUT
)
466 cmd
->rx_data_timeout
=
467 cpu_to_le32(mvmvif
->dbgfs_pm
.rx_data_timeout
);
468 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_TX_DATA_TIMEOUT
)
469 cmd
->tx_data_timeout
=
470 cpu_to_le32(mvmvif
->dbgfs_pm
.tx_data_timeout
);
471 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS
)
472 cmd
->skip_dtim_periods
= mvmvif
->dbgfs_pm
.skip_dtim_periods
;
473 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_LPRX_ENA
) {
474 if (mvmvif
->dbgfs_pm
.lprx_ena
)
475 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK
);
477 cmd
->flags
&= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK
);
479 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD
)
480 cmd
->lprx_rssi_threshold
= mvmvif
->dbgfs_pm
.lprx_rssi_threshold
;
481 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_SNOOZE_ENABLE
) {
482 if (mvmvif
->dbgfs_pm
.snooze_ena
)
484 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK
);
487 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK
);
489 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_UAPSD_MISBEHAVING
) {
490 u16 flag
= POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK
;
491 if (mvmvif
->dbgfs_pm
.uapsd_misbehaving
)
492 cmd
->flags
|= cpu_to_le16(flag
);
494 cmd
->flags
&= cpu_to_le16(flag
);
496 #endif /* CONFIG_IWLWIFI_DEBUGFS */
499 static int iwl_mvm_power_send_cmd(struct iwl_mvm
*mvm
,
500 struct ieee80211_vif
*vif
)
502 struct iwl_mac_power_cmd cmd
= {};
504 iwl_mvm_power_build_cmd(mvm
, vif
, &cmd
,
505 mvm
->cur_ucode
!= IWL_UCODE_WOWLAN
);
506 iwl_mvm_power_log(mvm
, &cmd
);
507 #ifdef CONFIG_IWLWIFI_DEBUGFS
508 memcpy(&iwl_mvm_vif_from_mac80211(vif
)->mac_pwr_cmd
, &cmd
, sizeof(cmd
));
511 return iwl_mvm_send_cmd_pdu(mvm
, MAC_PM_POWER_TABLE
, 0,
515 int iwl_mvm_power_update_device(struct iwl_mvm
*mvm
)
517 struct iwl_device_power_cmd cmd
= {
521 if (iwlmvm_mod_params
.power_scheme
== IWL_POWER_SCHEME_CAM
)
522 mvm
->ps_disabled
= true;
524 if (!mvm
->ps_disabled
)
525 cmd
.flags
|= cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK
);
527 #ifdef CONFIG_IWLWIFI_DEBUGFS
528 if ((mvm
->cur_ucode
== IWL_UCODE_WOWLAN
) ? mvm
->disable_power_off_d3
:
529 mvm
->disable_power_off
)
531 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK
);
534 "Sending device power command with flags = 0x%X\n",
537 return iwl_mvm_send_cmd_pdu(mvm
, POWER_TABLE_CMD
, 0, sizeof(cmd
),
541 void iwl_mvm_power_vif_assoc(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
543 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
545 if (memcmp(vif
->bss_conf
.bssid
, mvmvif
->uapsd_misbehaving_bssid
,
547 eth_zero_addr(mvmvif
->uapsd_misbehaving_bssid
);
550 static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data
, u8
*mac
,
551 struct ieee80211_vif
*vif
)
553 u8
*ap_sta_id
= _data
;
554 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
556 /* The ap_sta_id is not expected to change during current association
557 * so no explicit protection is needed
559 if (mvmvif
->ap_sta_id
== *ap_sta_id
)
560 memcpy(mvmvif
->uapsd_misbehaving_bssid
, vif
->bss_conf
.bssid
,
564 void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm
*mvm
,
565 struct iwl_rx_cmd_buffer
*rxb
)
567 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
568 struct iwl_uapsd_misbehaving_ap_notif
*notif
= (void *)pkt
->data
;
569 u8 ap_sta_id
= le32_to_cpu(notif
->sta_id
);
571 ieee80211_iterate_active_interfaces_atomic(
572 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
573 iwl_mvm_power_uapsd_misbehav_ap_iterator
, &ap_sta_id
);
576 struct iwl_power_vifs
{
578 struct ieee80211_vif
*bss_vif
;
579 struct ieee80211_vif
*p2p_vif
;
580 struct ieee80211_vif
*ap_vif
;
581 struct ieee80211_vif
*monitor_vif
;
588 static void iwl_mvm_power_disable_pm_iterator(void *_data
, u8
* mac
,
589 struct ieee80211_vif
*vif
)
591 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
593 mvmvif
->pm_enabled
= false;
596 static void iwl_mvm_power_ps_disabled_iterator(void *_data
, u8
* mac
,
597 struct ieee80211_vif
*vif
)
599 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
600 bool *disable_ps
= _data
;
602 if (mvmvif
->phy_ctxt
&& mvmvif
->phy_ctxt
->id
< NUM_PHY_CTX
)
603 *disable_ps
|= mvmvif
->ps_disabled
;
606 static void iwl_mvm_power_get_vifs_iterator(void *_data
, u8
*mac
,
607 struct ieee80211_vif
*vif
)
609 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
610 struct iwl_power_vifs
*power_iterator
= _data
;
611 bool active
= mvmvif
->phy_ctxt
&& mvmvif
->phy_ctxt
->id
< NUM_PHY_CTX
;
613 switch (ieee80211_vif_type_p2p(vif
)) {
614 case NL80211_IFTYPE_P2P_DEVICE
:
617 case NL80211_IFTYPE_P2P_GO
:
618 case NL80211_IFTYPE_AP
:
619 /* only a single MAC of the same type */
620 WARN_ON(power_iterator
->ap_vif
);
621 power_iterator
->ap_vif
= vif
;
623 power_iterator
->ap_active
= true;
626 case NL80211_IFTYPE_MONITOR
:
627 /* only a single MAC of the same type */
628 WARN_ON(power_iterator
->monitor_vif
);
629 power_iterator
->monitor_vif
= vif
;
631 power_iterator
->monitor_active
= true;
634 case NL80211_IFTYPE_P2P_CLIENT
:
635 /* only a single MAC of the same type */
636 WARN_ON(power_iterator
->p2p_vif
);
637 power_iterator
->p2p_vif
= vif
;
639 power_iterator
->p2p_active
= true;
642 case NL80211_IFTYPE_STATION
:
643 power_iterator
->bss_vif
= vif
;
645 power_iterator
->bss_active
= true;
653 static void iwl_mvm_power_set_pm(struct iwl_mvm
*mvm
,
654 struct iwl_power_vifs
*vifs
)
656 struct iwl_mvm_vif
*bss_mvmvif
= NULL
;
657 struct iwl_mvm_vif
*p2p_mvmvif
= NULL
;
658 struct iwl_mvm_vif
*ap_mvmvif
= NULL
;
659 bool client_same_channel
= false;
660 bool ap_same_channel
= false;
662 lockdep_assert_held(&mvm
->mutex
);
664 /* set pm_enable to false */
665 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
666 IEEE80211_IFACE_ITER_NORMAL
,
667 iwl_mvm_power_disable_pm_iterator
,
671 bss_mvmvif
= iwl_mvm_vif_from_mac80211(vifs
->bss_vif
);
674 p2p_mvmvif
= iwl_mvm_vif_from_mac80211(vifs
->p2p_vif
);
677 ap_mvmvif
= iwl_mvm_vif_from_mac80211(vifs
->ap_vif
);
679 /* don't allow PM if any TDLS stations exist */
680 if (iwl_mvm_tdls_sta_count(mvm
, NULL
))
683 /* enable PM on bss if bss stand alone */
684 if (vifs
->bss_active
&& !vifs
->p2p_active
&& !vifs
->ap_active
) {
685 bss_mvmvif
->pm_enabled
= true;
689 /* enable PM on p2p if p2p stand alone */
690 if (vifs
->p2p_active
&& !vifs
->bss_active
&& !vifs
->ap_active
) {
691 p2p_mvmvif
->pm_enabled
= true;
695 if (vifs
->bss_active
&& vifs
->p2p_active
)
696 client_same_channel
= (bss_mvmvif
->phy_ctxt
->id
==
697 p2p_mvmvif
->phy_ctxt
->id
);
698 if (vifs
->bss_active
&& vifs
->ap_active
)
699 ap_same_channel
= (bss_mvmvif
->phy_ctxt
->id
==
700 ap_mvmvif
->phy_ctxt
->id
);
702 /* clients are not stand alone: enable PM if DCM */
703 if (!(client_same_channel
|| ap_same_channel
)) {
704 if (vifs
->bss_active
)
705 bss_mvmvif
->pm_enabled
= true;
706 if (vifs
->p2p_active
)
707 p2p_mvmvif
->pm_enabled
= true;
712 * There is only one channel in the system and there are only
713 * bss and p2p clients that share it
715 if (client_same_channel
&& !vifs
->ap_active
) {
716 /* share same channel*/
717 bss_mvmvif
->pm_enabled
= true;
718 p2p_mvmvif
->pm_enabled
= true;
722 #ifdef CONFIG_IWLWIFI_DEBUGFS
723 int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm
*mvm
,
724 struct ieee80211_vif
*vif
, char *buf
,
727 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
728 struct iwl_mac_power_cmd cmd
= {};
731 mutex_lock(&mvm
->mutex
);
732 memcpy(&cmd
, &mvmvif
->mac_pwr_cmd
, sizeof(cmd
));
733 mutex_unlock(&mvm
->mutex
);
735 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "power_scheme = %d\n",
736 iwlmvm_mod_params
.power_scheme
);
737 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "flags = 0x%x\n",
738 le16_to_cpu(cmd
.flags
));
739 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "keep_alive = %d\n",
740 le16_to_cpu(cmd
.keep_alive_seconds
));
742 if (!(cmd
.flags
& cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
)))
745 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "skip_over_dtim = %d\n",
747 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
)) ? 1 : 0);
748 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "skip_dtim_periods = %d\n",
749 cmd
.skip_dtim_periods
);
750 if (!(cmd
.flags
& cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
))) {
751 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "rx_data_timeout = %d\n",
752 le32_to_cpu(cmd
.rx_data_timeout
));
753 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "tx_data_timeout = %d\n",
754 le32_to_cpu(cmd
.tx_data_timeout
));
756 if (cmd
.flags
& cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK
))
757 pos
+= scnprintf(buf
+pos
, bufsz
-pos
,
758 "lprx_rssi_threshold = %d\n",
759 cmd
.lprx_rssi_threshold
);
761 if (!(cmd
.flags
& cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK
)))
764 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "rx_data_timeout_uapsd = %d\n",
765 le32_to_cpu(cmd
.rx_data_timeout_uapsd
));
766 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "tx_data_timeout_uapsd = %d\n",
767 le32_to_cpu(cmd
.tx_data_timeout_uapsd
));
768 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "qndp_tid = %d\n", cmd
.qndp_tid
);
769 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "uapsd_ac_flags = 0x%x\n",
771 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "uapsd_max_sp = %d\n",
773 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "heavy_tx_thld_packets = %d\n",
774 cmd
.heavy_tx_thld_packets
);
775 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "heavy_rx_thld_packets = %d\n",
776 cmd
.heavy_rx_thld_packets
);
777 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "heavy_tx_thld_percentage = %d\n",
778 cmd
.heavy_tx_thld_percentage
);
779 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "heavy_rx_thld_percentage = %d\n",
780 cmd
.heavy_rx_thld_percentage
);
781 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "uapsd_misbehaving_enable = %d\n",
783 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK
)) ?
786 if (!(cmd
.flags
& cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK
)))
789 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "snooze_interval = %d\n",
790 cmd
.snooze_interval
);
791 pos
+= scnprintf(buf
+pos
, bufsz
-pos
, "snooze_window = %d\n",
798 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif
*vif
,
799 struct iwl_beacon_filter_cmd
*cmd
)
801 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
802 struct iwl_dbgfs_bf
*dbgfs_bf
= &mvmvif
->dbgfs_bf
;
804 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ENERGY_DELTA
)
805 cmd
->bf_energy_delta
= cpu_to_le32(dbgfs_bf
->bf_energy_delta
);
806 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA
)
807 cmd
->bf_roaming_energy_delta
=
808 cpu_to_le32(dbgfs_bf
->bf_roaming_energy_delta
);
809 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ROAMING_STATE
)
810 cmd
->bf_roaming_state
= cpu_to_le32(dbgfs_bf
->bf_roaming_state
);
811 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_TEMP_THRESHOLD
)
812 cmd
->bf_temp_threshold
=
813 cpu_to_le32(dbgfs_bf
->bf_temp_threshold
);
814 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_TEMP_FAST_FILTER
)
815 cmd
->bf_temp_fast_filter
=
816 cpu_to_le32(dbgfs_bf
->bf_temp_fast_filter
);
817 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_TEMP_SLOW_FILTER
)
818 cmd
->bf_temp_slow_filter
=
819 cpu_to_le32(dbgfs_bf
->bf_temp_slow_filter
);
820 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_DEBUG_FLAG
)
821 cmd
->bf_debug_flag
= cpu_to_le32(dbgfs_bf
->bf_debug_flag
);
822 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ESCAPE_TIMER
)
823 cmd
->bf_escape_timer
= cpu_to_le32(dbgfs_bf
->bf_escape_timer
);
824 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BA_ESCAPE_TIMER
)
825 cmd
->ba_escape_timer
= cpu_to_le32(dbgfs_bf
->ba_escape_timer
);
826 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT
)
827 cmd
->ba_enable_beacon_abort
=
828 cpu_to_le32(dbgfs_bf
->ba_enable_beacon_abort
);
832 static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm
*mvm
,
833 struct ieee80211_vif
*vif
,
834 struct iwl_beacon_filter_cmd
*cmd
,
838 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
841 if (mvmvif
!= mvm
->bf_allowed_vif
|| !vif
->bss_conf
.dtim_period
||
842 vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
845 iwl_mvm_beacon_filter_set_cqm_params(mvm
, vif
, cmd
, d0i3
);
847 iwl_mvm_beacon_filter_debugfs_parameters(vif
, cmd
);
848 ret
= iwl_mvm_beacon_filter_send_cmd(mvm
, cmd
, cmd_flags
);
850 /* don't change bf_enabled in case of temporary d0i3 configuration */
852 mvmvif
->bf_data
.bf_enabled
= true;
857 int iwl_mvm_enable_beacon_filter(struct iwl_mvm
*mvm
,
858 struct ieee80211_vif
*vif
,
861 struct iwl_beacon_filter_cmd cmd
= {
862 IWL_BF_CMD_CONFIG_DEFAULTS
,
863 .bf_enable_beacon_filter
= cpu_to_le32(1),
866 return _iwl_mvm_enable_beacon_filter(mvm
, vif
, &cmd
, flags
, false);
869 static int _iwl_mvm_disable_beacon_filter(struct iwl_mvm
*mvm
,
870 struct ieee80211_vif
*vif
,
871 u32 flags
, bool d0i3
)
873 struct iwl_beacon_filter_cmd cmd
= {};
874 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
877 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
880 ret
= iwl_mvm_beacon_filter_send_cmd(mvm
, &cmd
, flags
);
882 /* don't change bf_enabled in case of temporary d0i3 configuration */
884 mvmvif
->bf_data
.bf_enabled
= false;
889 int iwl_mvm_disable_beacon_filter(struct iwl_mvm
*mvm
,
890 struct ieee80211_vif
*vif
,
893 return _iwl_mvm_disable_beacon_filter(mvm
, vif
, flags
, false);
896 static int iwl_mvm_power_set_ps(struct iwl_mvm
*mvm
)
901 /* disable PS if CAM */
902 disable_ps
= (iwlmvm_mod_params
.power_scheme
== IWL_POWER_SCHEME_CAM
);
903 /* ...or if any of the vifs require PS to be off */
904 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
905 IEEE80211_IFACE_ITER_NORMAL
,
906 iwl_mvm_power_ps_disabled_iterator
,
909 /* update device power state if it has changed */
910 if (mvm
->ps_disabled
!= disable_ps
) {
911 bool old_ps_disabled
= mvm
->ps_disabled
;
913 mvm
->ps_disabled
= disable_ps
;
914 ret
= iwl_mvm_power_update_device(mvm
);
916 mvm
->ps_disabled
= old_ps_disabled
;
924 static int iwl_mvm_power_set_ba(struct iwl_mvm
*mvm
,
925 struct ieee80211_vif
*vif
)
927 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
928 struct iwl_beacon_filter_cmd cmd
= {
929 IWL_BF_CMD_CONFIG_DEFAULTS
,
930 .bf_enable_beacon_filter
= cpu_to_le32(1),
933 if (!mvmvif
->bf_data
.bf_enabled
)
936 if (mvm
->cur_ucode
== IWL_UCODE_WOWLAN
)
937 cmd
.ba_escape_timer
= cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3
);
939 mvmvif
->bf_data
.ba_enabled
= !(!mvmvif
->pm_enabled
||
942 iwl_mvm_vif_low_latency(mvmvif
));
944 return _iwl_mvm_enable_beacon_filter(mvm
, vif
, &cmd
, 0, false);
947 int iwl_mvm_power_update_ps(struct iwl_mvm
*mvm
)
949 struct iwl_power_vifs vifs
= {
954 lockdep_assert_held(&mvm
->mutex
);
957 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
958 IEEE80211_IFACE_ITER_NORMAL
,
959 iwl_mvm_power_get_vifs_iterator
, &vifs
);
961 ret
= iwl_mvm_power_set_ps(mvm
);
966 return iwl_mvm_power_set_ba(mvm
, vifs
.bss_vif
);
971 int iwl_mvm_power_update_mac(struct iwl_mvm
*mvm
)
973 struct iwl_power_vifs vifs
= {
978 lockdep_assert_held(&mvm
->mutex
);
981 ieee80211_iterate_active_interfaces_atomic(mvm
->hw
,
982 IEEE80211_IFACE_ITER_NORMAL
,
983 iwl_mvm_power_get_vifs_iterator
, &vifs
);
985 iwl_mvm_power_set_pm(mvm
, &vifs
);
987 ret
= iwl_mvm_power_set_ps(mvm
);
992 ret
= iwl_mvm_power_send_cmd(mvm
, vifs
.bss_vif
);
998 ret
= iwl_mvm_power_send_cmd(mvm
, vifs
.p2p_vif
);
1004 return iwl_mvm_power_set_ba(mvm
, vifs
.bss_vif
);
1009 int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm
*mvm
,
1010 struct ieee80211_vif
*vif
,
1011 bool enable
, u32 flags
)
1014 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1015 struct iwl_mac_power_cmd cmd
= {};
1017 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
1020 if (!vif
->bss_conf
.assoc
)
1023 iwl_mvm_power_build_cmd(mvm
, vif
, &cmd
, !enable
);
1025 iwl_mvm_power_log(mvm
, &cmd
);
1026 #ifdef CONFIG_IWLWIFI_DEBUGFS
1027 memcpy(&mvmvif
->mac_pwr_cmd
, &cmd
, sizeof(cmd
));
1029 ret
= iwl_mvm_send_cmd_pdu(mvm
, MAC_PM_POWER_TABLE
, flags
,
1034 /* configure beacon filtering */
1035 if (mvmvif
!= mvm
->bf_allowed_vif
)
1039 struct iwl_beacon_filter_cmd cmd_bf
= {
1040 IWL_BF_CMD_CONFIG_D0I3
,
1041 .bf_enable_beacon_filter
= cpu_to_le32(1),
1044 * When beacon storing is supported - disable beacon filtering
1045 * altogether - the latest beacon will be sent when exiting d0i3
1047 if (fw_has_capa(&mvm
->fw
->ucode_capa
,
1048 IWL_UCODE_TLV_CAPA_BEACON_STORING
))
1049 ret
= _iwl_mvm_disable_beacon_filter(mvm
, vif
, flags
,
1052 ret
= _iwl_mvm_enable_beacon_filter(mvm
, vif
, &cmd_bf
,
1055 if (mvmvif
->bf_data
.bf_enabled
)
1056 ret
= iwl_mvm_enable_beacon_filter(mvm
, vif
, flags
);
1058 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, flags
);