blob: 5a0a28fd762d7557071694b449cc1013a56ec638 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg702e9752017-06-02 11:56:58 +020010 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010011 *
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 *
Johannes Berg8ca151b2013-01-24 14:25:36 +010021 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020022 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010023 *
24 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020025 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 * BSD LICENSE
29 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020030 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020031 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg702e9752017-06-02 11:56:58 +020032 * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010033 * All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 *
39 * * Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * * Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in
43 * the documentation and/or other materials provided with the
44 * distribution.
45 * * Neither the name Intel Corporation nor the names of its
46 * contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 *
61 *****************************************************************************/
62
63#include <linux/kernel.h>
64#include <linux/module.h>
65#include <linux/slab.h>
Joe Perches93803b32015-03-02 19:54:49 -080066#include <linux/etherdevice.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010067
68#include <net/mac80211.h>
69
70#include "iwl-debug.h"
71#include "mvm.h"
72#include "iwl-modparams.h"
Johannes Bergd172a5e2017-06-02 15:15:53 +020073#include "fw/api/power.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010074
75#define POWER_KEEP_ALIVE_PERIOD_SEC 25
76
Emmanuel Grumbachd623d242014-01-26 12:58:24 +020077static
Alexander Bondare811ada2013-03-10 15:29:44 +020078int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +020079 struct iwl_beacon_filter_cmd *cmd,
80 u32 flags)
Alexander Bondar071d49902013-05-06 13:03:59 +030081{
Emmanuel Grumbachd623d242014-01-26 12:58:24 +020082 IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n",
83 le32_to_cpu(cmd->ba_enable_beacon_abort));
84 IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
85 le32_to_cpu(cmd->ba_escape_timer));
86 IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
87 le32_to_cpu(cmd->bf_debug_flag));
88 IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
89 le32_to_cpu(cmd->bf_enable_beacon_filter));
90 IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
91 le32_to_cpu(cmd->bf_energy_delta));
92 IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
93 le32_to_cpu(cmd->bf_escape_timer));
94 IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
95 le32_to_cpu(cmd->bf_roaming_energy_delta));
96 IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
97 le32_to_cpu(cmd->bf_roaming_state));
98 IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n",
99 le32_to_cpu(cmd->bf_temp_threshold));
100 IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n",
101 le32_to_cpu(cmd->bf_temp_fast_filter));
102 IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n",
103 le32_to_cpu(cmd->bf_temp_slow_filter));
Alexander Bondar071d49902013-05-06 13:03:59 +0300104
Emmanuel Grumbachd623d242014-01-26 12:58:24 +0200105 return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags,
106 sizeof(struct iwl_beacon_filter_cmd), cmd);
Alexander Bondar071d49902013-05-06 13:03:59 +0300107}
108
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300109static
110void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
111 struct ieee80211_vif *vif,
Gregory Greenmancdc306b2015-07-20 12:55:34 +0300112 struct iwl_beacon_filter_cmd *cmd,
113 bool d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300114{
115 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
116
Gregory Greenmancdc306b2015-07-20 12:55:34 +0300117 if (vif->bss_conf.cqm_rssi_thold && !d0i3) {
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300118 cmd->bf_energy_delta =
119 cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
120 /* fw uses an absolute value for this */
121 cmd->bf_roaming_state =
122 cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
123 }
124 cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
125}
126
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200127static void iwl_mvm_power_log(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200128 struct iwl_mac_power_cmd *cmd)
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200129{
130 IWL_DEBUG_POWER(mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200131 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
132 cmd->id_and_color, iwlmvm_mod_params.power_scheme,
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200133 le16_to_cpu(cmd->flags));
Alexander Bondare811ada2013-03-10 15:29:44 +0200134 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
135 le16_to_cpu(cmd->keep_alive_seconds));
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200136
Alexander Bondare3c588e2013-04-07 14:08:59 +0300137 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
138 IWL_DEBUG_POWER(mvm, "Disable power management\n");
139 return;
140 }
141
142 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
143 le32_to_cpu(cmd->rx_data_timeout));
144 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
145 le32_to_cpu(cmd->tx_data_timeout));
146 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
147 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
148 cmd->skip_dtim_periods);
149 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
150 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
151 cmd->lprx_rssi_threshold);
152 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
153 IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
154 IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
155 le32_to_cpu(cmd->rx_data_timeout_uapsd));
156 IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
157 le32_to_cpu(cmd->tx_data_timeout_uapsd));
158 IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
159 IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
160 IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200161 }
162}
163
Alexander Bondar175a70b2013-04-14 20:59:37 +0300164static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm,
165 struct ieee80211_vif *vif,
166 struct iwl_mac_power_cmd *cmd)
167{
168 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
169 enum ieee80211_ac_numbers ac;
170 bool tid_found = false;
171
Emmanuel Grumbach143b0b22016-10-26 14:21:27 +0300172#ifdef CONFIG_IWLWIFI_DEBUGFS
173 /* set advanced pm flag with no uapsd ACs to enable ps-poll */
174 if (mvmvif->dbgfs_pm.use_ps_poll) {
175 cmd->flags |= cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
176 return;
177 }
178#endif
179
Alexander Bondar175a70b2013-04-14 20:59:37 +0300180 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
181 if (!mvmvif->queue_params[ac].uapsd)
182 continue;
183
Johannes Berg702e9752017-06-02 11:56:58 +0200184 if (mvm->fwrt.cur_fw_img != IWL_UCODE_WOWLAN)
Alexander Bondar175a70b2013-04-14 20:59:37 +0300185 cmd->flags |=
186 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
187
188 cmd->uapsd_ac_flags |= BIT(ac);
189
190 /* QNDP TID - the highest TID with no admission control */
191 if (!tid_found && !mvmvif->queue_params[ac].acm) {
192 tid_found = true;
193 switch (ac) {
194 case IEEE80211_AC_VO:
195 cmd->qndp_tid = 6;
196 break;
197 case IEEE80211_AC_VI:
198 cmd->qndp_tid = 5;
199 break;
200 case IEEE80211_AC_BE:
201 cmd->qndp_tid = 0;
202 break;
203 case IEEE80211_AC_BK:
204 cmd->qndp_tid = 1;
205 break;
206 }
207 }
208 }
209
Alexander Bondar175a70b2013-04-14 20:59:37 +0300210 cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK);
211
212 if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
213 BIT(IEEE80211_AC_VI) |
214 BIT(IEEE80211_AC_BE) |
215 BIT(IEEE80211_AC_BK))) {
216 cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
217 cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
Johannes Berg702e9752017-06-02 11:56:58 +0200218 cmd->snooze_window =
219 (mvm->fwrt.cur_fw_img == IWL_UCODE_WOWLAN) ?
220 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
221 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
Alexander Bondar175a70b2013-04-14 20:59:37 +0300222 }
223
Emmanuel Grumbach6e2611f2016-03-15 11:12:20 +0200224 cmd->uapsd_max_sp = mvm->hw->uapsd_max_sp_len;
Alexander Bondar175a70b2013-04-14 20:59:37 +0300225
Johannes Berg702e9752017-06-02 11:56:58 +0200226 if (mvm->fwrt.cur_fw_img == IWL_UCODE_WOWLAN || cmd->flags &
Alexander Bondar175a70b2013-04-14 20:59:37 +0300227 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
228 cmd->rx_data_timeout_uapsd =
229 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
230 cmd->tx_data_timeout_uapsd =
231 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
232 } else {
233 cmd->rx_data_timeout_uapsd =
234 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
235 cmd->tx_data_timeout_uapsd =
236 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
237 }
238
239 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
240 cmd->heavy_tx_thld_packets =
241 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
242 cmd->heavy_rx_thld_packets =
243 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
244 } else {
245 cmd->heavy_tx_thld_packets =
246 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
247 cmd->heavy_rx_thld_packets =
248 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
249 }
250 cmd->heavy_tx_thld_percentage =
251 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
252 cmd->heavy_rx_thld_percentage =
253 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
254}
255
Avri Altmanee95ed32015-11-25 13:17:10 +0200256static void iwl_mvm_p2p_standalone_iterator(void *_data, u8 *mac,
257 struct ieee80211_vif *vif)
258{
259 bool *is_p2p_standalone = _data;
260
261 switch (ieee80211_vif_type_p2p(vif)) {
262 case NL80211_IFTYPE_P2P_GO:
263 case NL80211_IFTYPE_AP:
264 *is_p2p_standalone = false;
265 break;
266 case NL80211_IFTYPE_STATION:
267 if (vif->bss_conf.assoc)
268 *is_p2p_standalone = false;
269 break;
270
271 default:
272 break;
273 }
274}
275
Avri Altmanc6e37a62014-04-01 12:08:13 +0300276static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm,
277 struct ieee80211_vif *vif)
278{
279 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
280
281 if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
282 ETH_ALEN))
283 return false;
284
Avri Altmanc6e37a62014-04-01 12:08:13 +0300285 /*
286 * Avoid using uAPSD if P2P client is associated to GO that uses
287 * opportunistic power save. This is due to current FW limitation.
288 */
289 if (vif->p2p &&
290 (vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
291 IEEE80211_P2P_OPPPS_ENABLE_BIT))
292 return false;
293
Avri Altman05345282014-05-08 10:06:01 +0300294 /*
295 * Avoid using uAPSD if client is in DCM -
296 * low latency issue in Miracast
297 */
Arik Nemtsovcf7b4912014-05-15 11:44:40 +0300298 if (iwl_mvm_phy_ctx_count(mvm) >= 2)
Avri Altman05345282014-05-08 10:06:01 +0300299 return false;
300
Avri Altmanee95ed32015-11-25 13:17:10 +0200301 if (vif->p2p) {
302 /* Allow U-APSD only if p2p is stand alone */
303 bool is_p2p_standalone = true;
304
Avraham Sternc5241b02016-04-20 09:29:18 +0300305 if (!iwl_mvm_is_p2p_scm_uapsd_supported(mvm))
Avri Altmanee95ed32015-11-25 13:17:10 +0200306 return false;
307
308 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
309 IEEE80211_IFACE_ITER_NORMAL,
310 iwl_mvm_p2p_standalone_iterator,
311 &is_p2p_standalone);
312
313 if (!is_p2p_standalone)
314 return false;
315 }
316
Avri Altmanc6e37a62014-04-01 12:08:13 +0300317 return true;
318}
319
Avri Altman49c6d802014-08-27 19:58:56 +0300320static bool iwl_mvm_power_is_radar(struct ieee80211_vif *vif)
321{
322 struct ieee80211_chanctx_conf *chanctx_conf;
323 struct ieee80211_channel *chan;
324 bool radar_detect = false;
325
326 rcu_read_lock();
327 chanctx_conf = rcu_dereference(vif->chanctx_conf);
328 WARN_ON(!chanctx_conf);
329 if (chanctx_conf) {
330 chan = chanctx_conf->def.chan;
331 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
332 }
333 rcu_read_unlock();
334
335 return radar_detect;
336}
337
Johannes Berga6449122015-09-01 14:15:17 +0200338static void iwl_mvm_power_config_skip_dtim(struct iwl_mvm *mvm,
339 struct ieee80211_vif *vif,
340 struct iwl_mac_power_cmd *cmd,
341 bool host_awake)
342{
343 int dtimper = vif->bss_conf.dtim_period ?: 1;
344 int skip;
345
346 /* disable, in case we're supposed to override */
347 cmd->skip_dtim_periods = 0;
348 cmd->flags &= ~cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
349
350 if (iwl_mvm_power_is_radar(vif))
351 return;
352
353 if (dtimper >= 10)
354 return;
355
356 /* TODO: check that multicast wake lock is off */
357
358 if (host_awake) {
359 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_LP)
360 return;
361 skip = 2;
362 } else {
363 int dtimper_tu = dtimper * vif->bss_conf.beacon_int;
364
365 if (WARN_ON(!dtimper_tu))
366 return;
367 /* configure skip over dtim up to 306TU - 314 msec */
368 skip = max_t(u8, 1, 306 / dtimper_tu);
369 }
370
371 /* the firmware really expects "look at every X DTIMs", so add 1 */
372 cmd->skip_dtim_periods = 1 + skip;
373 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
374}
375
Alexander Bondare811ada2013-03-10 15:29:44 +0200376static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
377 struct ieee80211_vif *vif,
Johannes Berg9645edb2015-10-06 13:28:48 +0200378 struct iwl_mac_power_cmd *cmd,
379 bool host_awake)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100380{
Avri Altman5387b342014-11-11 07:29:59 +0200381 int dtimper, bi;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100382 int keep_alive;
Alexander Bondarb571a692013-05-21 14:49:09 +0300383 struct iwl_mvm_vif *mvmvif __maybe_unused =
384 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100385
Alexander Bondare811ada2013-03-10 15:29:44 +0200386 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
387 mvmvif->color));
Emmanuel Grumbach717e2392014-07-31 14:39:40 +0300388 dtimper = vif->bss_conf.dtim_period;
Avri Altman886ca9f2014-10-02 19:46:16 +0200389 bi = vif->bss_conf.beacon_int;
Alexander Bondare811ada2013-03-10 15:29:44 +0200390
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200391 /*
392 * Regardless of power management state the driver must set
393 * keep alive period. FW will use it for sending keep alive NDPs
Alexander Bondare811ada2013-03-10 15:29:44 +0200394 * immediately after association. Check that keep alive period
395 * is at least 3 * DTIM
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200396 */
Avri Altman5387b342014-11-11 07:29:59 +0200397 keep_alive = DIV_ROUND_UP(ieee80211_tu_to_usec(3 * dtimper * bi),
398 USEC_PER_SEC);
399 keep_alive = max(keep_alive, POWER_KEEP_ALIVE_PERIOD_SEC);
Alexander Bondare811ada2013-03-10 15:29:44 +0200400 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200401
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200402 if (mvm->ps_disabled)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100403 return;
404
Alexander Bondar9a613042013-03-05 12:54:00 +0200405 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
406
Johannes Bergb08dbed2015-10-06 14:07:44 +0200407 if (!vif->bss_conf.ps || !mvmvif->pm_enabled)
408 return;
409
410 if (iwl_mvm_vif_low_latency(mvmvif) && vif->p2p &&
411 (!fw_has_capa(&mvm->fw->ucode_capa,
412 IWL_UCODE_TLV_CAPA_SHORT_PM_TIMEOUTS) ||
413 !IWL_MVM_P2P_LOWLATENCY_PS_ENABLE))
Alexander Bondar9a613042013-03-05 12:54:00 +0200414 return;
415
416 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100417
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200418 if (vif->bss_conf.beacon_rate &&
419 (vif->bss_conf.beacon_rate->bitrate == 10 ||
420 vif->bss_conf.beacon_rate->bitrate == 60)) {
421 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200422 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200423 }
424
Johannes Berg9645edb2015-10-06 13:28:48 +0200425 iwl_mvm_power_config_skip_dtim(mvm, vif, cmd, host_awake);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100426
Johannes Bergb08dbed2015-10-06 14:07:44 +0200427 if (!host_awake) {
Johannes Berg99545922013-06-14 13:36:21 +0200428 cmd->rx_data_timeout =
429 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
430 cmd->tx_data_timeout =
431 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Johannes Bergb08dbed2015-10-06 14:07:44 +0200432 } else if (iwl_mvm_vif_low_latency(mvmvif) && vif->p2p &&
433 fw_has_capa(&mvm->fw->ucode_capa,
434 IWL_UCODE_TLV_CAPA_SHORT_PM_TIMEOUTS)) {
435 cmd->tx_data_timeout =
436 cpu_to_le32(IWL_MVM_SHORT_PS_TX_DATA_TIMEOUT);
437 cmd->rx_data_timeout =
438 cpu_to_le32(IWL_MVM_SHORT_PS_RX_DATA_TIMEOUT);
439 } else {
440 cmd->rx_data_timeout =
441 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
442 cmd->tx_data_timeout =
443 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300444 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300445
Avri Altmanc6e37a62014-04-01 12:08:13 +0300446 if (iwl_mvm_power_allow_uapsd(mvm, vif))
Alexander Bondar175a70b2013-04-14 20:59:37 +0300447 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300448
Alexander Bondarb571a692013-05-21 14:49:09 +0300449#ifdef CONFIG_IWLWIFI_DEBUGFS
450 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200451 cmd->keep_alive_seconds =
452 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300453 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
454 if (mvmvif->dbgfs_pm.skip_over_dtim)
455 cmd->flags |=
456 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
457 else
458 cmd->flags &=
459 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
460 }
461 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
462 cmd->rx_data_timeout =
463 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
464 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
465 cmd->tx_data_timeout =
466 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
467 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200468 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200469 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
470 if (mvmvif->dbgfs_pm.lprx_ena)
471 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
472 else
473 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
474 }
475 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200476 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondar89716342013-08-04 17:52:23 +0300477 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
478 if (mvmvif->dbgfs_pm.snooze_ena)
479 cmd->flags |=
480 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
481 else
482 cmd->flags &=
483 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
484 }
Alexander Bondare45a9412013-12-04 10:13:24 +0200485 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
486 u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
487 if (mvmvif->dbgfs_pm.uapsd_misbehaving)
488 cmd->flags |= cpu_to_le16(flag);
489 else
490 cmd->flags &= cpu_to_le16(flag);
491 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300492#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100493}
494
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200495static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200496 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100497{
Alexander Bondare811ada2013-03-10 15:29:44 +0200498 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100499
Johannes Berg9645edb2015-10-06 13:28:48 +0200500 iwl_mvm_power_build_cmd(mvm, vif, &cmd,
Johannes Berg702e9752017-06-02 11:56:58 +0200501 mvm->fwrt.cur_fw_img != IWL_UCODE_WOWLAN);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200502 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200503#ifdef CONFIG_IWLWIFI_DEBUGFS
504 memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
505#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100506
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300507 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0,
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200508 sizeof(cmd), &cmd);
509}
510
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200511int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300512{
513 struct iwl_device_power_cmd cmd = {
Johannes Bergceef91c2015-09-04 11:27:25 +0200514 .flags = 0,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300515 };
516
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200517 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
518 mvm->ps_disabled = true;
519
Johannes Bergceef91c2015-09-04 11:27:25 +0200520 if (!mvm->ps_disabled)
521 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300522
523#ifdef CONFIG_IWLWIFI_DEBUGFS
Johannes Berg702e9752017-06-02 11:56:58 +0200524 if ((mvm->fwrt.cur_fw_img == IWL_UCODE_WOWLAN) ?
525 mvm->disable_power_off_d3 : mvm->disable_power_off)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300526 cmd.flags &=
527 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
528#endif
529 IWL_DEBUG_POWER(mvm,
530 "Sending device power command with flags = 0x%X\n",
531 cmd.flags);
532
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300533 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd),
Alexander Bondar64b928c2013-09-03 14:18:03 +0300534 &cmd);
535}
536
Alexander Bondar175a70b2013-04-14 20:59:37 +0300537void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
538{
539 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
540
541 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
542 ETH_ALEN))
Joe Perches93803b32015-03-02 19:54:49 -0800543 eth_zero_addr(mvmvif->uapsd_misbehaving_bssid);
Alexander Bondar175a70b2013-04-14 20:59:37 +0300544}
545
546static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
547 struct ieee80211_vif *vif)
548{
549 u8 *ap_sta_id = _data;
550 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
551
552 /* The ap_sta_id is not expected to change during current association
553 * so no explicit protection is needed
554 */
555 if (mvmvif->ap_sta_id == *ap_sta_id)
556 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
557 ETH_ALEN);
558}
559
Johannes Berg04168412015-06-23 21:22:09 +0200560void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
561 struct iwl_rx_cmd_buffer *rxb)
Alexander Bondar175a70b2013-04-14 20:59:37 +0300562{
563 struct iwl_rx_packet *pkt = rxb_addr(rxb);
564 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
565 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
566
567 ieee80211_iterate_active_interfaces_atomic(
568 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
569 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
Alexander Bondar175a70b2013-04-14 20:59:37 +0300570}
571
Avri Altman19889022014-03-19 07:25:06 +0200572struct iwl_power_vifs {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300573 struct iwl_mvm *mvm;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200574 struct ieee80211_vif *bss_vif;
Avri Altman8ea0c682014-02-20 13:28:57 +0200575 struct ieee80211_vif *p2p_vif;
Avri Altman19889022014-03-19 07:25:06 +0200576 struct ieee80211_vif *ap_vif;
577 struct ieee80211_vif *monitor_vif;
578 bool p2p_active;
579 bool bss_active;
580 bool ap_active;
581 bool monitor_active;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200582};
583
Luciano Coelho128aa942014-08-08 18:36:22 +0300584static void iwl_mvm_power_disable_pm_iterator(void *_data, u8* mac,
585 struct ieee80211_vif *vif)
586{
587 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
588
589 mvmvif->pm_enabled = false;
590}
591
Luciano Coelho2533edc2014-08-08 19:50:46 +0300592static void iwl_mvm_power_ps_disabled_iterator(void *_data, u8* mac,
593 struct ieee80211_vif *vif)
594{
595 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
596 bool *disable_ps = _data;
597
Sara Sharon4f23f202016-11-20 13:50:39 +0200598 if (mvmvif->phy_ctxt && mvmvif->phy_ctxt->id < NUM_PHY_CTX)
599 *disable_ps |= mvmvif->ps_disabled;
Luciano Coelho2533edc2014-08-08 19:50:46 +0300600}
601
Luciano Coelho128aa942014-08-08 18:36:22 +0300602static void iwl_mvm_power_get_vifs_iterator(void *_data, u8 *mac,
603 struct ieee80211_vif *vif)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300604{
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200605 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman19889022014-03-19 07:25:06 +0200606 struct iwl_power_vifs *power_iterator = _data;
Sara Sharon4f23f202016-11-20 13:50:39 +0200607 bool active = mvmvif->phy_ctxt && mvmvif->phy_ctxt->id < NUM_PHY_CTX;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300608
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200609 switch (ieee80211_vif_type_p2p(vif)) {
610 case NL80211_IFTYPE_P2P_DEVICE:
611 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200612
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200613 case NL80211_IFTYPE_P2P_GO:
614 case NL80211_IFTYPE_AP:
Avri Altman19889022014-03-19 07:25:06 +0200615 /* only a single MAC of the same type */
616 WARN_ON(power_iterator->ap_vif);
617 power_iterator->ap_vif = vif;
Sara Sharon4f23f202016-11-20 13:50:39 +0200618 if (active)
619 power_iterator->ap_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200620 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200621
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200622 case NL80211_IFTYPE_MONITOR:
Avri Altman19889022014-03-19 07:25:06 +0200623 /* only a single MAC of the same type */
624 WARN_ON(power_iterator->monitor_vif);
625 power_iterator->monitor_vif = vif;
Sara Sharon4f23f202016-11-20 13:50:39 +0200626 if (active)
627 power_iterator->monitor_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200628 break;
629
630 case NL80211_IFTYPE_P2P_CLIENT:
Avri Altman19889022014-03-19 07:25:06 +0200631 /* only a single MAC of the same type */
Avri Altman8ea0c682014-02-20 13:28:57 +0200632 WARN_ON(power_iterator->p2p_vif);
633 power_iterator->p2p_vif = vif;
Sara Sharon4f23f202016-11-20 13:50:39 +0200634 if (active)
635 power_iterator->p2p_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200636 break;
637
638 case NL80211_IFTYPE_STATION:
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200639 power_iterator->bss_vif = vif;
Sara Sharon4f23f202016-11-20 13:50:39 +0200640 if (active)
641 power_iterator->bss_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200642 break;
643
644 default:
645 break;
646 }
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300647}
648
Luciano Coelhob1873302014-08-08 17:12:07 +0300649static void iwl_mvm_power_set_pm(struct iwl_mvm *mvm,
650 struct iwl_power_vifs *vifs)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300651{
Avri Altman19889022014-03-19 07:25:06 +0200652 struct iwl_mvm_vif *bss_mvmvif = NULL;
653 struct iwl_mvm_vif *p2p_mvmvif = NULL;
654 struct iwl_mvm_vif *ap_mvmvif = NULL;
655 bool client_same_channel = false;
656 bool ap_same_channel = false;
657
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200658 lockdep_assert_held(&mvm->mutex);
659
Luciano Coelho128aa942014-08-08 18:36:22 +0300660 /* set pm_enable to false */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200661 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
Luciano Coelho128aa942014-08-08 18:36:22 +0300662 IEEE80211_IFACE_ITER_NORMAL,
663 iwl_mvm_power_disable_pm_iterator,
664 NULL);
Avri Altman19889022014-03-19 07:25:06 +0200665
666 if (vifs->bss_vif)
667 bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif);
668
669 if (vifs->p2p_vif)
670 p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif);
671
672 if (vifs->ap_vif)
673 ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif);
674
Arik Nemtsovfcf23352015-02-22 19:15:04 +0200675 /* don't allow PM if any TDLS stations exist */
676 if (iwl_mvm_tdls_sta_count(mvm, NULL))
677 return;
678
Avri Altman19889022014-03-19 07:25:06 +0200679 /* enable PM on bss if bss stand alone */
Arik Nemtsov9474d442014-09-03 12:09:45 +0300680 if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active) {
Avri Altman19889022014-03-19 07:25:06 +0200681 bss_mvmvif->pm_enabled = true;
682 return;
683 }
684
685 /* enable PM on p2p if p2p stand alone */
Arik Nemtsov9474d442014-09-03 12:09:45 +0300686 if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active) {
Luca Coelho4b87e5a2016-09-12 16:03:30 +0300687 p2p_mvmvif->pm_enabled = true;
Avri Altman19889022014-03-19 07:25:06 +0200688 return;
689 }
690
691 if (vifs->bss_active && vifs->p2p_active)
692 client_same_channel = (bss_mvmvif->phy_ctxt->id ==
693 p2p_mvmvif->phy_ctxt->id);
694 if (vifs->bss_active && vifs->ap_active)
695 ap_same_channel = (bss_mvmvif->phy_ctxt->id ==
696 ap_mvmvif->phy_ctxt->id);
697
Avri Altman63ef81c2014-04-02 07:54:07 +0300698 /* clients are not stand alone: enable PM if DCM */
Luca Coelho4b87e5a2016-09-12 16:03:30 +0300699 if (!(client_same_channel || ap_same_channel)) {
Avri Altman63ef81c2014-04-02 07:54:07 +0300700 if (vifs->bss_active)
Avri Altman19889022014-03-19 07:25:06 +0200701 bss_mvmvif->pm_enabled = true;
Luca Coelho4b87e5a2016-09-12 16:03:30 +0300702 if (vifs->p2p_active)
Avri Altman63ef81c2014-04-02 07:54:07 +0300703 p2p_mvmvif->pm_enabled = true;
704 return;
Avri Altman19889022014-03-19 07:25:06 +0200705 }
706
707 /*
708 * There is only one channel in the system and there are only
709 * bss and p2p clients that share it
710 */
Luca Coelho4b87e5a2016-09-12 16:03:30 +0300711 if (client_same_channel && !vifs->ap_active) {
Avri Altman19889022014-03-19 07:25:06 +0200712 /* share same channel*/
713 bss_mvmvif->pm_enabled = true;
Luca Coelho4b87e5a2016-09-12 16:03:30 +0300714 p2p_mvmvif->pm_enabled = true;
Avri Altman19889022014-03-19 07:25:06 +0200715 }
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200716}
717
Alexander Bondarb571a692013-05-21 14:49:09 +0300718#ifdef CONFIG_IWLWIFI_DEBUGFS
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200719int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
720 struct ieee80211_vif *vif, char *buf,
721 int bufsz)
Alexander Bondare811ada2013-03-10 15:29:44 +0200722{
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200723 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondare811ada2013-03-10 15:29:44 +0200724 struct iwl_mac_power_cmd cmd = {};
725 int pos = 0;
726
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200727 mutex_lock(&mvm->mutex);
728 memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
729 mutex_unlock(&mvm->mutex);
Alexander Bondare811ada2013-03-10 15:29:44 +0200730
Alexander Bondare811ada2013-03-10 15:29:44 +0200731 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
732 iwlmvm_mod_params.power_scheme);
733 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
734 le16_to_cpu(cmd.flags));
735 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
736 le16_to_cpu(cmd.keep_alive_seconds));
737
Alexander Bondar175a70b2013-04-14 20:59:37 +0300738 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
739 return pos;
740
741 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
742 (cmd.flags &
743 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
744 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
745 cmd.skip_dtim_periods);
746 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
747 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
748 le32_to_cpu(cmd.rx_data_timeout));
749 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
750 le32_to_cpu(cmd.tx_data_timeout));
Alexander Bondare811ada2013-03-10 15:29:44 +0200751 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300752 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
753 pos += scnprintf(buf+pos, bufsz-pos,
754 "lprx_rssi_threshold = %d\n",
755 cmd.lprx_rssi_threshold);
756
757 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
758 return pos;
759
760 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
761 le32_to_cpu(cmd.rx_data_timeout_uapsd));
762 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
763 le32_to_cpu(cmd.tx_data_timeout_uapsd));
764 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
765 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
766 cmd.uapsd_ac_flags);
767 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
768 cmd.uapsd_max_sp);
769 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
770 cmd.heavy_tx_thld_packets);
771 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
772 cmd.heavy_rx_thld_packets);
773 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
774 cmd.heavy_tx_thld_percentage);
775 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
776 cmd.heavy_rx_thld_percentage);
777 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
778 (cmd.flags &
779 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
780 1 : 0);
781
782 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
783 return pos;
784
785 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
786 cmd.snooze_interval);
787 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
788 cmd.snooze_window);
789
Alexander Bondare811ada2013-03-10 15:29:44 +0200790 return pos;
791}
792
Alexander Bondarb571a692013-05-21 14:49:09 +0300793void
794iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
795 struct iwl_beacon_filter_cmd *cmd)
796{
797 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
798 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
799
800 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300801 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300802 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
803 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300804 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300805 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300806 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
807 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
808 cmd->bf_temp_threshold =
809 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
810 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
811 cmd->bf_temp_fast_filter =
812 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
813 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
814 cmd->bf_temp_slow_filter =
815 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300816 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300817 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300818 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
819 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
820 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
821 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
822 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300823 cmd->ba_enable_beacon_abort =
824 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300825}
826#endif
827
Eliad Peller3dd37d02014-01-07 14:00:24 +0200828static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
829 struct ieee80211_vif *vif,
830 struct iwl_beacon_filter_cmd *cmd,
831 u32 cmd_flags,
832 bool d0i3)
Hila Gonen7df15b12012-12-12 11:16:19 +0200833{
834 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondar071d49902013-05-06 13:03:59 +0300835 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200836
Avri Altmanfa7b2e72014-05-20 08:03:24 +0300837 if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period ||
Hila Gonen7df15b12012-12-12 11:16:19 +0200838 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
839 return 0;
840
Gregory Greenmancdc306b2015-07-20 12:55:34 +0300841 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd, d0i3);
Eliad Peller3dd37d02014-01-07 14:00:24 +0200842 if (!d0i3)
843 iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
844 ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300845
Eliad Peller3dd37d02014-01-07 14:00:24 +0200846 /* don't change bf_enabled in case of temporary d0i3 configuration */
847 if (!ret && !d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300848 mvmvif->bf_data.bf_enabled = true;
Alexander Bondar071d49902013-05-06 13:03:59 +0300849
850 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200851}
852
Eliad Peller3dd37d02014-01-07 14:00:24 +0200853int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
854 struct ieee80211_vif *vif,
855 u32 flags)
856{
857 struct iwl_beacon_filter_cmd cmd = {
858 IWL_BF_CMD_CONFIG_DEFAULTS,
859 .bf_enable_beacon_filter = cpu_to_le32(1),
860 };
861
862 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
863}
864
Sara Sharon0db056d2015-12-29 11:07:15 +0200865static int _iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
866 struct ieee80211_vif *vif,
867 u32 flags, bool d0i3)
Hila Gonen7df15b12012-12-12 11:16:19 +0200868{
Alexander Bondar071d49902013-05-06 13:03:59 +0300869 struct iwl_beacon_filter_cmd cmd = {};
870 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
871 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200872
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +0300873 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200874 return 0;
875
Eliad Peller3dd37d02014-01-07 14:00:24 +0200876 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300877
Sara Sharon0db056d2015-12-29 11:07:15 +0200878 /* don't change bf_enabled in case of temporary d0i3 configuration */
879 if (!ret && !d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300880 mvmvif->bf_data.bf_enabled = false;
Alexander Bondar071d49902013-05-06 13:03:59 +0300881
882 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200883}
Alexander Bondare811ada2013-03-10 15:29:44 +0200884
Sara Sharon0db056d2015-12-29 11:07:15 +0200885int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
886 struct ieee80211_vif *vif,
887 u32 flags)
888{
889 return _iwl_mvm_disable_beacon_filter(mvm, vif, flags, false);
890}
891
Luciano Coelho2533edc2014-08-08 19:50:46 +0300892static int iwl_mvm_power_set_ps(struct iwl_mvm *mvm)
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300893{
Luciano Coelho128aa942014-08-08 18:36:22 +0300894 bool disable_ps;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300895 int ret;
896
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300897 /* disable PS if CAM */
Luciano Coelhob1873302014-08-08 17:12:07 +0300898 disable_ps = (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM);
Luciano Coelho2533edc2014-08-08 19:50:46 +0300899 /* ...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);
Luciano Coelhob1873302014-08-08 17:12:07 +0300904
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;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300914 }
915 }
916
Luciano Coelho128aa942014-08-08 18:36:22 +0300917 return 0;
918}
919
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300920static int iwl_mvm_power_set_ba(struct iwl_mvm *mvm,
Avri Altman88121822016-01-24 15:18:59 +0200921 struct ieee80211_vif *vif)
Luciano Coelho128aa942014-08-08 18:36:22 +0300922{
Avri Altman88121822016-01-24 15:18:59 +0200923 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman416ec4f2016-01-24 15:56:11 +0200924 struct iwl_beacon_filter_cmd cmd = {
925 IWL_BF_CMD_CONFIG_DEFAULTS,
926 .bf_enable_beacon_filter = cpu_to_le32(1),
927 };
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300928
Avri Altman88121822016-01-24 15:18:59 +0200929 if (!mvmvif->bf_data.bf_enabled)
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300930 return 0;
931
Johannes Berg702e9752017-06-02 11:56:58 +0200932 if (mvm->fwrt.cur_fw_img == IWL_UCODE_WOWLAN)
Avri Altman416ec4f2016-01-24 15:56:11 +0200933 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300934
Avri Altman416ec4f2016-01-24 15:56:11 +0200935 mvmvif->bf_data.ba_enabled = !(!mvmvif->pm_enabled ||
936 mvm->ps_disabled ||
937 !vif->bss_conf.ps ||
938 iwl_mvm_vif_low_latency(mvmvif));
939
940 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false);
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300941}
942
943int iwl_mvm_power_update_ps(struct iwl_mvm *mvm)
944{
Luciano Coelho128aa942014-08-08 18:36:22 +0300945 struct iwl_power_vifs vifs = {
946 .mvm = mvm,
947 };
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300948 int ret;
949
950 lockdep_assert_held(&mvm->mutex);
951
952 /* get vifs info */
953 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
954 IEEE80211_IFACE_ITER_NORMAL,
955 iwl_mvm_power_get_vifs_iterator, &vifs);
956
Luciano Coelho2533edc2014-08-08 19:50:46 +0300957 ret = iwl_mvm_power_set_ps(mvm);
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300958 if (ret)
959 return ret;
960
Avri Altman88121822016-01-24 15:18:59 +0200961 if (vifs.bss_vif)
962 return iwl_mvm_power_set_ba(mvm, vifs.bss_vif);
963
964 return 0;
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300965}
966
967int iwl_mvm_power_update_mac(struct iwl_mvm *mvm)
968{
969 struct iwl_power_vifs vifs = {
970 .mvm = mvm,
971 };
Luciano Coelho128aa942014-08-08 18:36:22 +0300972 int ret;
973
974 lockdep_assert_held(&mvm->mutex);
975
976 /* get vifs info */
977 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
978 IEEE80211_IFACE_ITER_NORMAL,
979 iwl_mvm_power_get_vifs_iterator, &vifs);
980
981 iwl_mvm_power_set_pm(mvm, &vifs);
982
Luciano Coelho2533edc2014-08-08 19:50:46 +0300983 ret = iwl_mvm_power_set_ps(mvm);
Luciano Coelho128aa942014-08-08 18:36:22 +0300984 if (ret)
985 return ret;
986
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300987 if (vifs.bss_vif) {
988 ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif);
989 if (ret)
990 return ret;
991 }
992
993 if (vifs.p2p_vif) {
994 ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif);
995 if (ret)
996 return ret;
997 }
998
Avri Altman88121822016-01-24 15:18:59 +0200999 if (vifs.bss_vif)
1000 return iwl_mvm_power_set_ba(mvm, vifs.bss_vif);
1001
1002 return 0;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +03001003}
1004
Eliad Peller3dd37d02014-01-07 14:00:24 +02001005int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
1006 struct ieee80211_vif *vif,
1007 bool enable, u32 flags)
1008{
1009 int ret;
1010 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1011 struct iwl_mac_power_cmd cmd = {};
1012
1013 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
1014 return 0;
1015
1016 if (!vif->bss_conf.assoc)
1017 return 0;
1018
Johannes Berg9645edb2015-10-06 13:28:48 +02001019 iwl_mvm_power_build_cmd(mvm, vif, &cmd, !enable);
Eliad Peller3dd37d02014-01-07 14:00:24 +02001020
Eliad Peller3dd37d02014-01-07 14:00:24 +02001021 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +02001022#ifdef CONFIG_IWLWIFI_DEBUGFS
1023 memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
1024#endif
Eliad Peller3dd37d02014-01-07 14:00:24 +02001025 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
1026 sizeof(cmd), &cmd);
1027 if (ret)
1028 return ret;
1029
1030 /* configure beacon filtering */
1031 if (mvmvif != mvm->bf_allowed_vif)
1032 return 0;
1033
1034 if (enable) {
1035 struct iwl_beacon_filter_cmd cmd_bf = {
1036 IWL_BF_CMD_CONFIG_D0I3,
1037 .bf_enable_beacon_filter = cpu_to_le32(1),
1038 };
Sara Sharon0db056d2015-12-29 11:07:15 +02001039 /*
1040 * When beacon storing is supported - disable beacon filtering
1041 * altogether - the latest beacon will be sent when exiting d0i3
1042 */
1043 if (fw_has_capa(&mvm->fw->ucode_capa,
1044 IWL_UCODE_TLV_CAPA_BEACON_STORING))
1045 ret = _iwl_mvm_disable_beacon_filter(mvm, vif, flags,
1046 true);
1047 else
1048 ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
1049 flags, true);
Eliad Peller3dd37d02014-01-07 14:00:24 +02001050 } else {
1051 if (mvmvif->bf_data.bf_enabled)
1052 ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
1053 else
1054 ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
1055 }
1056
1057 return ret;
1058}