blob: ff85865b1dda85c2d4a50b212e44e3379fa4bd4d [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
Sara Sharon0db056d2015-12-29 11:07:15 +020010 * Copyright(c) 2015 - 2016 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 *
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
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020027 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010028 *
29 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020030 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010031 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020035 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020036 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Sara Sharon0db056d2015-12-29 11:07:15 +020037 * Copyright(c) 2015 - 2016 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010038 * 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>
Joe Perches93803b32015-03-02 19:54:49 -080071#include <linux/etherdevice.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010072
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
Emmanuel Grumbachd623d242014-01-26 12:58:24 +020082static
Alexander Bondare811ada2013-03-10 15:29:44 +020083int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +020084 struct iwl_beacon_filter_cmd *cmd,
85 u32 flags)
Alexander Bondar071d49902013-05-06 13:03:59 +030086{
Emmanuel Grumbachd623d242014-01-26 12:58:24 +020087 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));
Alexander Bondar071d49902013-05-06 13:03:59 +0300109
Emmanuel Grumbachd623d242014-01-26 12:58:24 +0200110 return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags,
111 sizeof(struct iwl_beacon_filter_cmd), cmd);
Alexander Bondar071d49902013-05-06 13:03:59 +0300112}
113
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300114static
115void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
116 struct ieee80211_vif *vif,
Gregory Greenmancdc306b2015-07-20 12:55:34 +0300117 struct iwl_beacon_filter_cmd *cmd,
118 bool d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300119{
120 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
121
Gregory Greenmancdc306b2015-07-20 12:55:34 +0300122 if (vif->bss_conf.cqm_rssi_thold && !d0i3) {
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300123 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
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200132static void iwl_mvm_power_log(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200133 struct iwl_mac_power_cmd *cmd)
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200134{
135 IWL_DEBUG_POWER(mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200136 "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,
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200138 le16_to_cpu(cmd->flags));
Alexander Bondare811ada2013-03-10 15:29:44 +0200139 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
140 le16_to_cpu(cmd->keep_alive_seconds));
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200141
Alexander Bondare3c588e2013-04-07 14:08:59 +0300142 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);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200166 }
167}
168
Alexander Bondar175a70b2013-04-14 20:59:37 +0300169static 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
Eliad Peller84fd7602014-07-30 15:42:19 +0300207 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
Alexander Bondar175a70b2013-04-14 20:59:37 +0300214 return;
Eliad Peller84fd7602014-07-30 15:42:19 +0300215 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300216
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
Emmanuel Grumbach6e2611f2016-03-15 11:12:20 +0200230 cmd->uapsd_max_sp = mvm->hw->uapsd_max_sp_len;
Alexander Bondar175a70b2013-04-14 20:59:37 +0300231
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
Avri Altmanee95ed32015-11-25 13:17:10 +0200262static void iwl_mvm_p2p_standalone_iterator(void *_data, u8 *mac,
263 struct ieee80211_vif *vif)
264{
265 bool *is_p2p_standalone = _data;
266
267 switch (ieee80211_vif_type_p2p(vif)) {
268 case NL80211_IFTYPE_P2P_GO:
269 case NL80211_IFTYPE_AP:
270 *is_p2p_standalone = false;
271 break;
272 case NL80211_IFTYPE_STATION:
273 if (vif->bss_conf.assoc)
274 *is_p2p_standalone = false;
275 break;
276
277 default:
278 break;
279 }
280}
281
Avri Altmanc6e37a62014-04-01 12:08:13 +0300282static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm,
283 struct ieee80211_vif *vif)
284{
285 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
286
287 if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
288 ETH_ALEN))
289 return false;
290
Avri Altmanc6e37a62014-04-01 12:08:13 +0300291 /*
292 * Avoid using uAPSD if P2P client is associated to GO that uses
293 * opportunistic power save. This is due to current FW limitation.
294 */
295 if (vif->p2p &&
296 (vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
297 IEEE80211_P2P_OPPPS_ENABLE_BIT))
298 return false;
299
Avri Altman05345282014-05-08 10:06:01 +0300300 /*
301 * Avoid using uAPSD if client is in DCM -
302 * low latency issue in Miracast
303 */
Arik Nemtsovcf7b4912014-05-15 11:44:40 +0300304 if (iwl_mvm_phy_ctx_count(mvm) >= 2)
Avri Altman05345282014-05-08 10:06:01 +0300305 return false;
306
Avri Altmanee95ed32015-11-25 13:17:10 +0200307 if (vif->p2p) {
308 /* Allow U-APSD only if p2p is stand alone */
309 bool is_p2p_standalone = true;
310
Avraham Sternc5241b02016-04-20 09:29:18 +0300311 if (!iwl_mvm_is_p2p_scm_uapsd_supported(mvm))
Avri Altmanee95ed32015-11-25 13:17:10 +0200312 return false;
313
314 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
315 IEEE80211_IFACE_ITER_NORMAL,
316 iwl_mvm_p2p_standalone_iterator,
317 &is_p2p_standalone);
318
319 if (!is_p2p_standalone)
320 return false;
321 }
322
Avri Altmanc6e37a62014-04-01 12:08:13 +0300323 return true;
324}
325
Avri Altman49c6d802014-08-27 19:58:56 +0300326static bool iwl_mvm_power_is_radar(struct ieee80211_vif *vif)
327{
328 struct ieee80211_chanctx_conf *chanctx_conf;
329 struct ieee80211_channel *chan;
330 bool radar_detect = false;
331
332 rcu_read_lock();
333 chanctx_conf = rcu_dereference(vif->chanctx_conf);
334 WARN_ON(!chanctx_conf);
335 if (chanctx_conf) {
336 chan = chanctx_conf->def.chan;
337 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
338 }
339 rcu_read_unlock();
340
341 return radar_detect;
342}
343
Johannes Berga6449122015-09-01 14:15:17 +0200344static void iwl_mvm_power_config_skip_dtim(struct iwl_mvm *mvm,
345 struct ieee80211_vif *vif,
346 struct iwl_mac_power_cmd *cmd,
347 bool host_awake)
348{
349 int dtimper = vif->bss_conf.dtim_period ?: 1;
350 int skip;
351
352 /* disable, in case we're supposed to override */
353 cmd->skip_dtim_periods = 0;
354 cmd->flags &= ~cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
355
356 if (iwl_mvm_power_is_radar(vif))
357 return;
358
359 if (dtimper >= 10)
360 return;
361
362 /* TODO: check that multicast wake lock is off */
363
364 if (host_awake) {
365 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_LP)
366 return;
367 skip = 2;
368 } else {
369 int dtimper_tu = dtimper * vif->bss_conf.beacon_int;
370
371 if (WARN_ON(!dtimper_tu))
372 return;
373 /* configure skip over dtim up to 306TU - 314 msec */
374 skip = max_t(u8, 1, 306 / dtimper_tu);
375 }
376
377 /* the firmware really expects "look at every X DTIMs", so add 1 */
378 cmd->skip_dtim_periods = 1 + skip;
379 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
380}
381
Alexander Bondare811ada2013-03-10 15:29:44 +0200382static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
383 struct ieee80211_vif *vif,
Johannes Berg9645edb2015-10-06 13:28:48 +0200384 struct iwl_mac_power_cmd *cmd,
385 bool host_awake)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100386{
Avri Altman5387b342014-11-11 07:29:59 +0200387 int dtimper, bi;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100388 int keep_alive;
Alexander Bondarb571a692013-05-21 14:49:09 +0300389 struct iwl_mvm_vif *mvmvif __maybe_unused =
390 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100391
Alexander Bondare811ada2013-03-10 15:29:44 +0200392 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
393 mvmvif->color));
Emmanuel Grumbach717e2392014-07-31 14:39:40 +0300394 dtimper = vif->bss_conf.dtim_period;
Avri Altman886ca9f2014-10-02 19:46:16 +0200395 bi = vif->bss_conf.beacon_int;
Alexander Bondare811ada2013-03-10 15:29:44 +0200396
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200397 /*
398 * Regardless of power management state the driver must set
399 * keep alive period. FW will use it for sending keep alive NDPs
Alexander Bondare811ada2013-03-10 15:29:44 +0200400 * immediately after association. Check that keep alive period
401 * is at least 3 * DTIM
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200402 */
Avri Altman5387b342014-11-11 07:29:59 +0200403 keep_alive = DIV_ROUND_UP(ieee80211_tu_to_usec(3 * dtimper * bi),
404 USEC_PER_SEC);
405 keep_alive = max(keep_alive, POWER_KEEP_ALIVE_PERIOD_SEC);
Alexander Bondare811ada2013-03-10 15:29:44 +0200406 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200407
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200408 if (mvm->ps_disabled)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100409 return;
410
Alexander Bondar9a613042013-03-05 12:54:00 +0200411 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
412
Johannes Bergb08dbed2015-10-06 14:07:44 +0200413 if (!vif->bss_conf.ps || !mvmvif->pm_enabled)
414 return;
415
416 if (iwl_mvm_vif_low_latency(mvmvif) && vif->p2p &&
417 (!fw_has_capa(&mvm->fw->ucode_capa,
418 IWL_UCODE_TLV_CAPA_SHORT_PM_TIMEOUTS) ||
419 !IWL_MVM_P2P_LOWLATENCY_PS_ENABLE))
Alexander Bondar9a613042013-03-05 12:54:00 +0200420 return;
421
422 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100423
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200424 if (vif->bss_conf.beacon_rate &&
425 (vif->bss_conf.beacon_rate->bitrate == 10 ||
426 vif->bss_conf.beacon_rate->bitrate == 60)) {
427 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200428 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200429 }
430
Johannes Berg9645edb2015-10-06 13:28:48 +0200431 iwl_mvm_power_config_skip_dtim(mvm, vif, cmd, host_awake);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100432
Johannes Bergb08dbed2015-10-06 14:07:44 +0200433 if (!host_awake) {
Johannes Berg99545922013-06-14 13:36:21 +0200434 cmd->rx_data_timeout =
435 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
436 cmd->tx_data_timeout =
437 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Johannes Bergb08dbed2015-10-06 14:07:44 +0200438 } else if (iwl_mvm_vif_low_latency(mvmvif) && vif->p2p &&
439 fw_has_capa(&mvm->fw->ucode_capa,
440 IWL_UCODE_TLV_CAPA_SHORT_PM_TIMEOUTS)) {
441 cmd->tx_data_timeout =
442 cpu_to_le32(IWL_MVM_SHORT_PS_TX_DATA_TIMEOUT);
443 cmd->rx_data_timeout =
444 cpu_to_le32(IWL_MVM_SHORT_PS_RX_DATA_TIMEOUT);
445 } else {
446 cmd->rx_data_timeout =
447 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
448 cmd->tx_data_timeout =
449 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300450 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300451
Avri Altmanc6e37a62014-04-01 12:08:13 +0300452 if (iwl_mvm_power_allow_uapsd(mvm, vif))
Alexander Bondar175a70b2013-04-14 20:59:37 +0300453 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300454
Alexander Bondarb571a692013-05-21 14:49:09 +0300455#ifdef CONFIG_IWLWIFI_DEBUGFS
456 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200457 cmd->keep_alive_seconds =
458 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300459 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
460 if (mvmvif->dbgfs_pm.skip_over_dtim)
461 cmd->flags |=
462 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
463 else
464 cmd->flags &=
465 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
466 }
467 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
468 cmd->rx_data_timeout =
469 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
470 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
471 cmd->tx_data_timeout =
472 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
473 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200474 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200475 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
476 if (mvmvif->dbgfs_pm.lprx_ena)
477 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
478 else
479 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
480 }
481 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200482 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondar89716342013-08-04 17:52:23 +0300483 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
484 if (mvmvif->dbgfs_pm.snooze_ena)
485 cmd->flags |=
486 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
487 else
488 cmd->flags &=
489 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
490 }
Alexander Bondare45a9412013-12-04 10:13:24 +0200491 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
492 u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
493 if (mvmvif->dbgfs_pm.uapsd_misbehaving)
494 cmd->flags |= cpu_to_le16(flag);
495 else
496 cmd->flags &= cpu_to_le16(flag);
497 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300498#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100499}
500
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200501static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200502 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100503{
Alexander Bondare811ada2013-03-10 15:29:44 +0200504 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100505
Johannes Berg9645edb2015-10-06 13:28:48 +0200506 iwl_mvm_power_build_cmd(mvm, vif, &cmd,
507 mvm->cur_ucode != IWL_UCODE_WOWLAN);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200508 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200509#ifdef CONFIG_IWLWIFI_DEBUGFS
510 memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
511#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100512
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300513 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0,
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200514 sizeof(cmd), &cmd);
515}
516
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200517int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300518{
519 struct iwl_device_power_cmd cmd = {
Johannes Bergceef91c2015-09-04 11:27:25 +0200520 .flags = 0,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300521 };
522
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200523 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
524 mvm->ps_disabled = true;
525
Johannes Bergceef91c2015-09-04 11:27:25 +0200526 if (!mvm->ps_disabled)
527 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300528
529#ifdef CONFIG_IWLWIFI_DEBUGFS
530 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
531 mvm->disable_power_off)
532 cmd.flags &=
533 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
534#endif
535 IWL_DEBUG_POWER(mvm,
536 "Sending device power command with flags = 0x%X\n",
537 cmd.flags);
538
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300539 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd),
Alexander Bondar64b928c2013-09-03 14:18:03 +0300540 &cmd);
541}
542
Alexander Bondar175a70b2013-04-14 20:59:37 +0300543void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
544{
545 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
546
547 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
548 ETH_ALEN))
Joe Perches93803b32015-03-02 19:54:49 -0800549 eth_zero_addr(mvmvif->uapsd_misbehaving_bssid);
Alexander Bondar175a70b2013-04-14 20:59:37 +0300550}
551
552static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
553 struct ieee80211_vif *vif)
554{
555 u8 *ap_sta_id = _data;
556 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
557
558 /* The ap_sta_id is not expected to change during current association
559 * so no explicit protection is needed
560 */
561 if (mvmvif->ap_sta_id == *ap_sta_id)
562 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
563 ETH_ALEN);
564}
565
Johannes Berg04168412015-06-23 21:22:09 +0200566void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
567 struct iwl_rx_cmd_buffer *rxb)
Alexander Bondar175a70b2013-04-14 20:59:37 +0300568{
569 struct iwl_rx_packet *pkt = rxb_addr(rxb);
570 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
571 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
572
573 ieee80211_iterate_active_interfaces_atomic(
574 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
575 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
Alexander Bondar175a70b2013-04-14 20:59:37 +0300576}
577
Avri Altman19889022014-03-19 07:25:06 +0200578struct iwl_power_vifs {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300579 struct iwl_mvm *mvm;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200580 struct ieee80211_vif *bss_vif;
Avri Altman8ea0c682014-02-20 13:28:57 +0200581 struct ieee80211_vif *p2p_vif;
Avri Altman19889022014-03-19 07:25:06 +0200582 struct ieee80211_vif *ap_vif;
583 struct ieee80211_vif *monitor_vif;
584 bool p2p_active;
585 bool bss_active;
586 bool ap_active;
587 bool monitor_active;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200588};
589
Luciano Coelho128aa942014-08-08 18:36:22 +0300590static void iwl_mvm_power_disable_pm_iterator(void *_data, u8* mac,
591 struct ieee80211_vif *vif)
592{
593 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
594
595 mvmvif->pm_enabled = false;
596}
597
Luciano Coelho2533edc2014-08-08 19:50:46 +0300598static void iwl_mvm_power_ps_disabled_iterator(void *_data, u8* mac,
599 struct ieee80211_vif *vif)
600{
601 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
602 bool *disable_ps = _data;
603
604 if (mvmvif->phy_ctxt)
605 if (mvmvif->phy_ctxt->id < MAX_PHYS)
606 *disable_ps |= mvmvif->ps_disabled;
607}
608
Luciano Coelho128aa942014-08-08 18:36:22 +0300609static void iwl_mvm_power_get_vifs_iterator(void *_data, u8 *mac,
610 struct ieee80211_vif *vif)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300611{
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200612 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman19889022014-03-19 07:25:06 +0200613 struct iwl_power_vifs *power_iterator = _data;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300614
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200615 switch (ieee80211_vif_type_p2p(vif)) {
616 case NL80211_IFTYPE_P2P_DEVICE:
617 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200618
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200619 case NL80211_IFTYPE_P2P_GO:
620 case NL80211_IFTYPE_AP:
Avri Altman19889022014-03-19 07:25:06 +0200621 /* only a single MAC of the same type */
622 WARN_ON(power_iterator->ap_vif);
623 power_iterator->ap_vif = vif;
624 if (mvmvif->phy_ctxt)
625 if (mvmvif->phy_ctxt->id < MAX_PHYS)
626 power_iterator->ap_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200627 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200628
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200629 case NL80211_IFTYPE_MONITOR:
Avri Altman19889022014-03-19 07:25:06 +0200630 /* only a single MAC of the same type */
631 WARN_ON(power_iterator->monitor_vif);
632 power_iterator->monitor_vif = vif;
633 if (mvmvif->phy_ctxt)
634 if (mvmvif->phy_ctxt->id < MAX_PHYS)
635 power_iterator->monitor_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200636 break;
637
638 case NL80211_IFTYPE_P2P_CLIENT:
Avri Altman19889022014-03-19 07:25:06 +0200639 /* only a single MAC of the same type */
Avri Altman8ea0c682014-02-20 13:28:57 +0200640 WARN_ON(power_iterator->p2p_vif);
641 power_iterator->p2p_vif = vif;
Avri Altman19889022014-03-19 07:25:06 +0200642 if (mvmvif->phy_ctxt)
643 if (mvmvif->phy_ctxt->id < MAX_PHYS)
644 power_iterator->p2p_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200645 break;
646
647 case NL80211_IFTYPE_STATION:
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200648 power_iterator->bss_vif = vif;
Avri Altman19889022014-03-19 07:25:06 +0200649 if (mvmvif->phy_ctxt)
650 if (mvmvif->phy_ctxt->id < MAX_PHYS)
651 power_iterator->bss_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200652 break;
653
654 default:
655 break;
656 }
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300657}
658
Luciano Coelhob1873302014-08-08 17:12:07 +0300659static void iwl_mvm_power_set_pm(struct iwl_mvm *mvm,
660 struct iwl_power_vifs *vifs)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300661{
Avri Altman19889022014-03-19 07:25:06 +0200662 struct iwl_mvm_vif *bss_mvmvif = NULL;
663 struct iwl_mvm_vif *p2p_mvmvif = NULL;
664 struct iwl_mvm_vif *ap_mvmvif = NULL;
665 bool client_same_channel = false;
666 bool ap_same_channel = false;
667
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200668 lockdep_assert_held(&mvm->mutex);
669
Luciano Coelho128aa942014-08-08 18:36:22 +0300670 /* set pm_enable to false */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200671 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
Luciano Coelho128aa942014-08-08 18:36:22 +0300672 IEEE80211_IFACE_ITER_NORMAL,
673 iwl_mvm_power_disable_pm_iterator,
674 NULL);
Avri Altman19889022014-03-19 07:25:06 +0200675
676 if (vifs->bss_vif)
677 bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif);
678
679 if (vifs->p2p_vif)
680 p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif);
681
682 if (vifs->ap_vif)
683 ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif);
684
Arik Nemtsovfcf23352015-02-22 19:15:04 +0200685 /* don't allow PM if any TDLS stations exist */
686 if (iwl_mvm_tdls_sta_count(mvm, NULL))
687 return;
688
Avri Altman19889022014-03-19 07:25:06 +0200689 /* enable PM on bss if bss stand alone */
Arik Nemtsov9474d442014-09-03 12:09:45 +0300690 if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active) {
Avri Altman19889022014-03-19 07:25:06 +0200691 bss_mvmvif->pm_enabled = true;
692 return;
693 }
694
695 /* enable PM on p2p if p2p stand alone */
Arik Nemtsov9474d442014-09-03 12:09:45 +0300696 if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active) {
Avri Altman19889022014-03-19 07:25:06 +0200697 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
698 p2p_mvmvif->pm_enabled = true;
699 return;
700 }
701
702 if (vifs->bss_active && vifs->p2p_active)
703 client_same_channel = (bss_mvmvif->phy_ctxt->id ==
704 p2p_mvmvif->phy_ctxt->id);
705 if (vifs->bss_active && vifs->ap_active)
706 ap_same_channel = (bss_mvmvif->phy_ctxt->id ==
707 ap_mvmvif->phy_ctxt->id);
708
Avri Altman63ef81c2014-04-02 07:54:07 +0300709 /* clients are not stand alone: enable PM if DCM */
710 if (!(client_same_channel || ap_same_channel) &&
Avri Altman19889022014-03-19 07:25:06 +0200711 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) {
Avri Altman63ef81c2014-04-02 07:54:07 +0300712 if (vifs->bss_active)
Avri Altman19889022014-03-19 07:25:06 +0200713 bss_mvmvif->pm_enabled = true;
Avri Altman63ef81c2014-04-02 07:54:07 +0300714 if (vifs->p2p_active &&
715 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM))
716 p2p_mvmvif->pm_enabled = true;
717 return;
Avri Altman19889022014-03-19 07:25:06 +0200718 }
719
720 /*
721 * There is only one channel in the system and there are only
722 * bss and p2p clients that share it
723 */
724 if (client_same_channel && !vifs->ap_active &&
725 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM)) {
726 /* share same channel*/
727 bss_mvmvif->pm_enabled = true;
728 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
729 p2p_mvmvif->pm_enabled = true;
730 }
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200731}
732
Alexander Bondarb571a692013-05-21 14:49:09 +0300733#ifdef CONFIG_IWLWIFI_DEBUGFS
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200734int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
735 struct ieee80211_vif *vif, char *buf,
736 int bufsz)
Alexander Bondare811ada2013-03-10 15:29:44 +0200737{
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200738 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondare811ada2013-03-10 15:29:44 +0200739 struct iwl_mac_power_cmd cmd = {};
740 int pos = 0;
741
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200742 mutex_lock(&mvm->mutex);
743 memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
744 mutex_unlock(&mvm->mutex);
Alexander Bondare811ada2013-03-10 15:29:44 +0200745
Alexander Bondare811ada2013-03-10 15:29:44 +0200746 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
747 iwlmvm_mod_params.power_scheme);
748 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
749 le16_to_cpu(cmd.flags));
750 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
751 le16_to_cpu(cmd.keep_alive_seconds));
752
Alexander Bondar175a70b2013-04-14 20:59:37 +0300753 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
754 return pos;
755
756 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
757 (cmd.flags &
758 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
759 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
760 cmd.skip_dtim_periods);
761 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
762 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
763 le32_to_cpu(cmd.rx_data_timeout));
764 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
765 le32_to_cpu(cmd.tx_data_timeout));
Alexander Bondare811ada2013-03-10 15:29:44 +0200766 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300767 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
768 pos += scnprintf(buf+pos, bufsz-pos,
769 "lprx_rssi_threshold = %d\n",
770 cmd.lprx_rssi_threshold);
771
772 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
773 return pos;
774
775 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
776 le32_to_cpu(cmd.rx_data_timeout_uapsd));
777 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
778 le32_to_cpu(cmd.tx_data_timeout_uapsd));
779 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
780 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
781 cmd.uapsd_ac_flags);
782 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
783 cmd.uapsd_max_sp);
784 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
785 cmd.heavy_tx_thld_packets);
786 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
787 cmd.heavy_rx_thld_packets);
788 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
789 cmd.heavy_tx_thld_percentage);
790 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
791 cmd.heavy_rx_thld_percentage);
792 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
793 (cmd.flags &
794 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
795 1 : 0);
796
797 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
798 return pos;
799
800 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
801 cmd.snooze_interval);
802 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
803 cmd.snooze_window);
804
Alexander Bondare811ada2013-03-10 15:29:44 +0200805 return pos;
806}
807
Alexander Bondarb571a692013-05-21 14:49:09 +0300808void
809iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
810 struct iwl_beacon_filter_cmd *cmd)
811{
812 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
813 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
814
815 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300816 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300817 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
818 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300819 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300820 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300821 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
822 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
823 cmd->bf_temp_threshold =
824 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
825 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
826 cmd->bf_temp_fast_filter =
827 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
828 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
829 cmd->bf_temp_slow_filter =
830 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300831 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300832 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300833 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
834 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
835 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
836 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
837 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300838 cmd->ba_enable_beacon_abort =
839 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300840}
841#endif
842
Eliad Peller3dd37d02014-01-07 14:00:24 +0200843static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
844 struct ieee80211_vif *vif,
845 struct iwl_beacon_filter_cmd *cmd,
846 u32 cmd_flags,
847 bool d0i3)
Hila Gonen7df15b12012-12-12 11:16:19 +0200848{
849 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondar071d49902013-05-06 13:03:59 +0300850 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200851
Avri Altmanfa7b2e72014-05-20 08:03:24 +0300852 if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period ||
Hila Gonen7df15b12012-12-12 11:16:19 +0200853 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
854 return 0;
855
Gregory Greenmancdc306b2015-07-20 12:55:34 +0300856 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd, d0i3);
Eliad Peller3dd37d02014-01-07 14:00:24 +0200857 if (!d0i3)
858 iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
859 ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300860
Eliad Peller3dd37d02014-01-07 14:00:24 +0200861 /* don't change bf_enabled in case of temporary d0i3 configuration */
862 if (!ret && !d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300863 mvmvif->bf_data.bf_enabled = true;
Alexander Bondar071d49902013-05-06 13:03:59 +0300864
865 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200866}
867
Eliad Peller3dd37d02014-01-07 14:00:24 +0200868int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
869 struct ieee80211_vif *vif,
870 u32 flags)
871{
872 struct iwl_beacon_filter_cmd cmd = {
873 IWL_BF_CMD_CONFIG_DEFAULTS,
874 .bf_enable_beacon_filter = cpu_to_le32(1),
875 };
876
877 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
878}
879
Sara Sharon0db056d2015-12-29 11:07:15 +0200880static int _iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
881 struct ieee80211_vif *vif,
882 u32 flags, bool d0i3)
Hila Gonen7df15b12012-12-12 11:16:19 +0200883{
Alexander Bondar071d49902013-05-06 13:03:59 +0300884 struct iwl_beacon_filter_cmd cmd = {};
885 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
886 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200887
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +0300888 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200889 return 0;
890
Eliad Peller3dd37d02014-01-07 14:00:24 +0200891 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300892
Sara Sharon0db056d2015-12-29 11:07:15 +0200893 /* don't change bf_enabled in case of temporary d0i3 configuration */
894 if (!ret && !d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300895 mvmvif->bf_data.bf_enabled = false;
Alexander Bondar071d49902013-05-06 13:03:59 +0300896
897 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200898}
Alexander Bondare811ada2013-03-10 15:29:44 +0200899
Sara Sharon0db056d2015-12-29 11:07:15 +0200900int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
901 struct ieee80211_vif *vif,
902 u32 flags)
903{
904 return _iwl_mvm_disable_beacon_filter(mvm, vif, flags, false);
905}
906
Luciano Coelho2533edc2014-08-08 19:50:46 +0300907static int iwl_mvm_power_set_ps(struct iwl_mvm *mvm)
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300908{
Luciano Coelho128aa942014-08-08 18:36:22 +0300909 bool disable_ps;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300910 int ret;
911
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300912 /* disable PS if CAM */
Luciano Coelhob1873302014-08-08 17:12:07 +0300913 disable_ps = (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM);
Luciano Coelho2533edc2014-08-08 19:50:46 +0300914 /* ...or if any of the vifs require PS to be off */
915 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
916 IEEE80211_IFACE_ITER_NORMAL,
917 iwl_mvm_power_ps_disabled_iterator,
918 &disable_ps);
Luciano Coelhob1873302014-08-08 17:12:07 +0300919
920 /* update device power state if it has changed */
921 if (mvm->ps_disabled != disable_ps) {
922 bool old_ps_disabled = mvm->ps_disabled;
923
924 mvm->ps_disabled = disable_ps;
925 ret = iwl_mvm_power_update_device(mvm);
926 if (ret) {
927 mvm->ps_disabled = old_ps_disabled;
928 return ret;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300929 }
930 }
931
Luciano Coelho128aa942014-08-08 18:36:22 +0300932 return 0;
933}
934
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300935static int iwl_mvm_power_set_ba(struct iwl_mvm *mvm,
Avri Altman88121822016-01-24 15:18:59 +0200936 struct ieee80211_vif *vif)
Luciano Coelho128aa942014-08-08 18:36:22 +0300937{
Avri Altman88121822016-01-24 15:18:59 +0200938 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman416ec4f2016-01-24 15:56:11 +0200939 struct iwl_beacon_filter_cmd cmd = {
940 IWL_BF_CMD_CONFIG_DEFAULTS,
941 .bf_enable_beacon_filter = cpu_to_le32(1),
942 };
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300943
Avri Altman88121822016-01-24 15:18:59 +0200944 if (!mvmvif->bf_data.bf_enabled)
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300945 return 0;
946
Avri Altman416ec4f2016-01-24 15:56:11 +0200947 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
948 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300949
Avri Altman416ec4f2016-01-24 15:56:11 +0200950 mvmvif->bf_data.ba_enabled = !(!mvmvif->pm_enabled ||
951 mvm->ps_disabled ||
952 !vif->bss_conf.ps ||
953 iwl_mvm_vif_low_latency(mvmvif));
954
955 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false);
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300956}
957
958int iwl_mvm_power_update_ps(struct iwl_mvm *mvm)
959{
Luciano Coelho128aa942014-08-08 18:36:22 +0300960 struct iwl_power_vifs vifs = {
961 .mvm = mvm,
962 };
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300963 int ret;
964
965 lockdep_assert_held(&mvm->mutex);
966
967 /* get vifs info */
968 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
969 IEEE80211_IFACE_ITER_NORMAL,
970 iwl_mvm_power_get_vifs_iterator, &vifs);
971
Luciano Coelho2533edc2014-08-08 19:50:46 +0300972 ret = iwl_mvm_power_set_ps(mvm);
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300973 if (ret)
974 return ret;
975
Avri Altman88121822016-01-24 15:18:59 +0200976 if (vifs.bss_vif)
977 return iwl_mvm_power_set_ba(mvm, vifs.bss_vif);
978
979 return 0;
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300980}
981
982int iwl_mvm_power_update_mac(struct iwl_mvm *mvm)
983{
984 struct iwl_power_vifs vifs = {
985 .mvm = mvm,
986 };
Luciano Coelho128aa942014-08-08 18:36:22 +0300987 int ret;
988
989 lockdep_assert_held(&mvm->mutex);
990
991 /* get vifs info */
992 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
993 IEEE80211_IFACE_ITER_NORMAL,
994 iwl_mvm_power_get_vifs_iterator, &vifs);
995
996 iwl_mvm_power_set_pm(mvm, &vifs);
997
Luciano Coelho2533edc2014-08-08 19:50:46 +0300998 ret = iwl_mvm_power_set_ps(mvm);
Luciano Coelho128aa942014-08-08 18:36:22 +0300999 if (ret)
1000 return ret;
1001
Emmanuel Grumbach13b72322014-05-20 11:28:18 +03001002 if (vifs.bss_vif) {
1003 ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif);
1004 if (ret)
1005 return ret;
1006 }
1007
1008 if (vifs.p2p_vif) {
1009 ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif);
1010 if (ret)
1011 return ret;
1012 }
1013
Avri Altman88121822016-01-24 15:18:59 +02001014 if (vifs.bss_vif)
1015 return iwl_mvm_power_set_ba(mvm, vifs.bss_vif);
1016
1017 return 0;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +03001018}
1019
Eliad Peller3dd37d02014-01-07 14:00:24 +02001020int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
1021 struct ieee80211_vif *vif,
1022 bool enable, u32 flags)
1023{
1024 int ret;
1025 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1026 struct iwl_mac_power_cmd cmd = {};
1027
1028 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
1029 return 0;
1030
1031 if (!vif->bss_conf.assoc)
1032 return 0;
1033
Johannes Berg9645edb2015-10-06 13:28:48 +02001034 iwl_mvm_power_build_cmd(mvm, vif, &cmd, !enable);
Eliad Peller3dd37d02014-01-07 14:00:24 +02001035
Eliad Peller3dd37d02014-01-07 14:00:24 +02001036 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +02001037#ifdef CONFIG_IWLWIFI_DEBUGFS
1038 memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
1039#endif
Eliad Peller3dd37d02014-01-07 14:00:24 +02001040 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
1041 sizeof(cmd), &cmd);
1042 if (ret)
1043 return ret;
1044
1045 /* configure beacon filtering */
1046 if (mvmvif != mvm->bf_allowed_vif)
1047 return 0;
1048
1049 if (enable) {
1050 struct iwl_beacon_filter_cmd cmd_bf = {
1051 IWL_BF_CMD_CONFIG_D0I3,
1052 .bf_enable_beacon_filter = cpu_to_le32(1),
1053 };
Sara Sharon0db056d2015-12-29 11:07:15 +02001054 /*
1055 * When beacon storing is supported - disable beacon filtering
1056 * altogether - the latest beacon will be sent when exiting d0i3
1057 */
1058 if (fw_has_capa(&mvm->fw->ucode_capa,
1059 IWL_UCODE_TLV_CAPA_BEACON_STORING))
1060 ret = _iwl_mvm_disable_beacon_filter(mvm, vif, flags,
1061 true);
1062 else
1063 ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
1064 flags, true);
Eliad Peller3dd37d02014-01-07 14:00:24 +02001065 } else {
1066 if (mvmvif->bf_data.bf_enabled)
1067 ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
1068 else
1069 ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
1070 }
1071
1072 return ret;
1073}