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