blob: 7c354feb9be219fc8ef0eabb21cb0c71295c4356 [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 Berga6449122015-09-01 14:15:17 +020010 * Copyright(c) 2015 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:
30 * Intel Linux Wireless <ilw@linux.intel.com>
31 * 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
Johannes Berga6449122015-09-01 14:15:17 +020037 * Copyright(c) 2015 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
230 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
231
232 if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
233 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
234 cmd->rx_data_timeout_uapsd =
235 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
236 cmd->tx_data_timeout_uapsd =
237 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
238 } else {
239 cmd->rx_data_timeout_uapsd =
240 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
241 cmd->tx_data_timeout_uapsd =
242 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
243 }
244
245 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
246 cmd->heavy_tx_thld_packets =
247 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
248 cmd->heavy_rx_thld_packets =
249 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
250 } else {
251 cmd->heavy_tx_thld_packets =
252 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
253 cmd->heavy_rx_thld_packets =
254 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
255 }
256 cmd->heavy_tx_thld_percentage =
257 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
258 cmd->heavy_rx_thld_percentage =
259 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
260}
261
Avri Altmanc6e37a62014-04-01 12:08:13 +0300262static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm,
263 struct ieee80211_vif *vif)
264{
265 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
266
267 if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
268 ETH_ALEN))
269 return false;
270
271 if (vif->p2p &&
272 !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD))
273 return false;
274 /*
275 * Avoid using uAPSD if P2P client is associated to GO that uses
276 * opportunistic power save. This is due to current FW limitation.
277 */
278 if (vif->p2p &&
279 (vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
280 IEEE80211_P2P_OPPPS_ENABLE_BIT))
281 return false;
282
Avri Altman05345282014-05-08 10:06:01 +0300283 /*
284 * Avoid using uAPSD if client is in DCM -
285 * low latency issue in Miracast
286 */
Arik Nemtsovcf7b4912014-05-15 11:44:40 +0300287 if (iwl_mvm_phy_ctx_count(mvm) >= 2)
Avri Altman05345282014-05-08 10:06:01 +0300288 return false;
289
Avri Altmanc6e37a62014-04-01 12:08:13 +0300290 return true;
291}
292
Avri Altman49c6d802014-08-27 19:58:56 +0300293static bool iwl_mvm_power_is_radar(struct ieee80211_vif *vif)
294{
295 struct ieee80211_chanctx_conf *chanctx_conf;
296 struct ieee80211_channel *chan;
297 bool radar_detect = false;
298
299 rcu_read_lock();
300 chanctx_conf = rcu_dereference(vif->chanctx_conf);
301 WARN_ON(!chanctx_conf);
302 if (chanctx_conf) {
303 chan = chanctx_conf->def.chan;
304 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
305 }
306 rcu_read_unlock();
307
308 return radar_detect;
309}
310
Johannes Berga6449122015-09-01 14:15:17 +0200311static void iwl_mvm_power_config_skip_dtim(struct iwl_mvm *mvm,
312 struct ieee80211_vif *vif,
313 struct iwl_mac_power_cmd *cmd,
314 bool host_awake)
315{
316 int dtimper = vif->bss_conf.dtim_period ?: 1;
317 int skip;
318
319 /* disable, in case we're supposed to override */
320 cmd->skip_dtim_periods = 0;
321 cmd->flags &= ~cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
322
323 if (iwl_mvm_power_is_radar(vif))
324 return;
325
326 if (dtimper >= 10)
327 return;
328
329 /* TODO: check that multicast wake lock is off */
330
331 if (host_awake) {
332 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_LP)
333 return;
334 skip = 2;
335 } else {
336 int dtimper_tu = dtimper * vif->bss_conf.beacon_int;
337
338 if (WARN_ON(!dtimper_tu))
339 return;
340 /* configure skip over dtim up to 306TU - 314 msec */
341 skip = max_t(u8, 1, 306 / dtimper_tu);
342 }
343
344 /* the firmware really expects "look at every X DTIMs", so add 1 */
345 cmd->skip_dtim_periods = 1 + skip;
346 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
347}
348
Alexander Bondare811ada2013-03-10 15:29:44 +0200349static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
350 struct ieee80211_vif *vif,
Johannes Berg9645edb2015-10-06 13:28:48 +0200351 struct iwl_mac_power_cmd *cmd,
352 bool host_awake)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100353{
Avri Altman5387b342014-11-11 07:29:59 +0200354 int dtimper, bi;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100355 int keep_alive;
Alexander Bondarb571a692013-05-21 14:49:09 +0300356 struct iwl_mvm_vif *mvmvif __maybe_unused =
357 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100358
Alexander Bondare811ada2013-03-10 15:29:44 +0200359 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
360 mvmvif->color));
Emmanuel Grumbach717e2392014-07-31 14:39:40 +0300361 dtimper = vif->bss_conf.dtim_period;
Avri Altman886ca9f2014-10-02 19:46:16 +0200362 bi = vif->bss_conf.beacon_int;
Alexander Bondare811ada2013-03-10 15:29:44 +0200363
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200364 /*
365 * Regardless of power management state the driver must set
366 * keep alive period. FW will use it for sending keep alive NDPs
Alexander Bondare811ada2013-03-10 15:29:44 +0200367 * immediately after association. Check that keep alive period
368 * is at least 3 * DTIM
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200369 */
Avri Altman5387b342014-11-11 07:29:59 +0200370 keep_alive = DIV_ROUND_UP(ieee80211_tu_to_usec(3 * dtimper * bi),
371 USEC_PER_SEC);
372 keep_alive = max(keep_alive, POWER_KEEP_ALIVE_PERIOD_SEC);
Alexander Bondare811ada2013-03-10 15:29:44 +0200373 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200374
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200375 if (mvm->ps_disabled)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100376 return;
377
Alexander Bondar9a613042013-03-05 12:54:00 +0200378 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
379
Avri Altman3c22a0e2015-08-05 23:07:42 +0300380 if (!vif->bss_conf.ps || !mvmvif->pm_enabled ||
381 (iwl_mvm_vif_low_latency(mvmvif) && vif->p2p))
Alexander Bondar9a613042013-03-05 12:54:00 +0200382 return;
383
384 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100385
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200386 if (vif->bss_conf.beacon_rate &&
387 (vif->bss_conf.beacon_rate->bitrate == 10 ||
388 vif->bss_conf.beacon_rate->bitrate == 60)) {
389 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200390 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200391 }
392
Johannes Berg9645edb2015-10-06 13:28:48 +0200393 iwl_mvm_power_config_skip_dtim(mvm, vif, cmd, host_awake);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100394
Johannes Berg9645edb2015-10-06 13:28:48 +0200395 if (host_awake) {
Johannes Berg99545922013-06-14 13:36:21 +0200396 cmd->rx_data_timeout =
397 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
398 cmd->tx_data_timeout =
399 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300400 } else {
Johannes Berg99545922013-06-14 13:36:21 +0200401 cmd->rx_data_timeout =
402 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
403 cmd->tx_data_timeout =
404 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300405 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300406
Avri Altmanc6e37a62014-04-01 12:08:13 +0300407 if (iwl_mvm_power_allow_uapsd(mvm, vif))
Alexander Bondar175a70b2013-04-14 20:59:37 +0300408 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300409
Alexander Bondarb571a692013-05-21 14:49:09 +0300410#ifdef CONFIG_IWLWIFI_DEBUGFS
411 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200412 cmd->keep_alive_seconds =
413 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300414 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
415 if (mvmvif->dbgfs_pm.skip_over_dtim)
416 cmd->flags |=
417 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
418 else
419 cmd->flags &=
420 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
421 }
422 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
423 cmd->rx_data_timeout =
424 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
425 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
426 cmd->tx_data_timeout =
427 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
428 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200429 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200430 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
431 if (mvmvif->dbgfs_pm.lprx_ena)
432 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
433 else
434 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
435 }
436 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200437 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondar89716342013-08-04 17:52:23 +0300438 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
439 if (mvmvif->dbgfs_pm.snooze_ena)
440 cmd->flags |=
441 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
442 else
443 cmd->flags &=
444 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
445 }
Alexander Bondare45a9412013-12-04 10:13:24 +0200446 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
447 u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
448 if (mvmvif->dbgfs_pm.uapsd_misbehaving)
449 cmd->flags |= cpu_to_le16(flag);
450 else
451 cmd->flags &= cpu_to_le16(flag);
452 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300453#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100454}
455
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200456static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200457 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100458{
Alexander Bondare811ada2013-03-10 15:29:44 +0200459 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100460
Johannes Berg9645edb2015-10-06 13:28:48 +0200461 iwl_mvm_power_build_cmd(mvm, vif, &cmd,
462 mvm->cur_ucode != IWL_UCODE_WOWLAN);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200463 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200464#ifdef CONFIG_IWLWIFI_DEBUGFS
465 memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
466#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100467
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300468 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0,
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200469 sizeof(cmd), &cmd);
470}
471
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200472int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300473{
474 struct iwl_device_power_cmd cmd = {
Johannes Bergceef91c2015-09-04 11:27:25 +0200475 .flags = 0,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300476 };
477
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200478 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
479 mvm->ps_disabled = true;
480
Johannes Bergceef91c2015-09-04 11:27:25 +0200481 if (!mvm->ps_disabled)
482 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300483
484#ifdef CONFIG_IWLWIFI_DEBUGFS
485 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
486 mvm->disable_power_off)
487 cmd.flags &=
488 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
489#endif
490 IWL_DEBUG_POWER(mvm,
491 "Sending device power command with flags = 0x%X\n",
492 cmd.flags);
493
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300494 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd),
Alexander Bondar64b928c2013-09-03 14:18:03 +0300495 &cmd);
496}
497
Alexander Bondar175a70b2013-04-14 20:59:37 +0300498void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
499{
500 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
501
502 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
503 ETH_ALEN))
Joe Perches93803b32015-03-02 19:54:49 -0800504 eth_zero_addr(mvmvif->uapsd_misbehaving_bssid);
Alexander Bondar175a70b2013-04-14 20:59:37 +0300505}
506
507static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
508 struct ieee80211_vif *vif)
509{
510 u8 *ap_sta_id = _data;
511 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
512
513 /* The ap_sta_id is not expected to change during current association
514 * so no explicit protection is needed
515 */
516 if (mvmvif->ap_sta_id == *ap_sta_id)
517 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
518 ETH_ALEN);
519}
520
Johannes Berg04168412015-06-23 21:22:09 +0200521void iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
522 struct iwl_rx_cmd_buffer *rxb)
Alexander Bondar175a70b2013-04-14 20:59:37 +0300523{
524 struct iwl_rx_packet *pkt = rxb_addr(rxb);
525 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
526 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
527
528 ieee80211_iterate_active_interfaces_atomic(
529 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
530 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
Alexander Bondar175a70b2013-04-14 20:59:37 +0300531}
532
Avri Altman19889022014-03-19 07:25:06 +0200533struct iwl_power_vifs {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300534 struct iwl_mvm *mvm;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200535 struct ieee80211_vif *bf_vif;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200536 struct ieee80211_vif *bss_vif;
Avri Altman8ea0c682014-02-20 13:28:57 +0200537 struct ieee80211_vif *p2p_vif;
Avri Altman19889022014-03-19 07:25:06 +0200538 struct ieee80211_vif *ap_vif;
539 struct ieee80211_vif *monitor_vif;
540 bool p2p_active;
541 bool bss_active;
542 bool ap_active;
543 bool monitor_active;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200544};
545
Luciano Coelho128aa942014-08-08 18:36:22 +0300546static void iwl_mvm_power_disable_pm_iterator(void *_data, u8* mac,
547 struct ieee80211_vif *vif)
548{
549 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
550
551 mvmvif->pm_enabled = false;
552}
553
Luciano Coelho2533edc2014-08-08 19:50:46 +0300554static void iwl_mvm_power_ps_disabled_iterator(void *_data, u8* mac,
555 struct ieee80211_vif *vif)
556{
557 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
558 bool *disable_ps = _data;
559
560 if (mvmvif->phy_ctxt)
561 if (mvmvif->phy_ctxt->id < MAX_PHYS)
562 *disable_ps |= mvmvif->ps_disabled;
563}
564
Luciano Coelho128aa942014-08-08 18:36:22 +0300565static void iwl_mvm_power_get_vifs_iterator(void *_data, u8 *mac,
566 struct ieee80211_vif *vif)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300567{
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200568 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman19889022014-03-19 07:25:06 +0200569 struct iwl_power_vifs *power_iterator = _data;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300570
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200571 switch (ieee80211_vif_type_p2p(vif)) {
572 case NL80211_IFTYPE_P2P_DEVICE:
573 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200574
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200575 case NL80211_IFTYPE_P2P_GO:
576 case NL80211_IFTYPE_AP:
Avri Altman19889022014-03-19 07:25:06 +0200577 /* only a single MAC of the same type */
578 WARN_ON(power_iterator->ap_vif);
579 power_iterator->ap_vif = vif;
580 if (mvmvif->phy_ctxt)
581 if (mvmvif->phy_ctxt->id < MAX_PHYS)
582 power_iterator->ap_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200583 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200584
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200585 case NL80211_IFTYPE_MONITOR:
Avri Altman19889022014-03-19 07:25:06 +0200586 /* only a single MAC of the same type */
587 WARN_ON(power_iterator->monitor_vif);
588 power_iterator->monitor_vif = vif;
589 if (mvmvif->phy_ctxt)
590 if (mvmvif->phy_ctxt->id < MAX_PHYS)
591 power_iterator->monitor_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200592 break;
593
594 case NL80211_IFTYPE_P2P_CLIENT:
Avri Altman19889022014-03-19 07:25:06 +0200595 /* only a single MAC of the same type */
Avri Altman8ea0c682014-02-20 13:28:57 +0200596 WARN_ON(power_iterator->p2p_vif);
597 power_iterator->p2p_vif = vif;
Avri Altman19889022014-03-19 07:25:06 +0200598 if (mvmvif->phy_ctxt)
599 if (mvmvif->phy_ctxt->id < MAX_PHYS)
600 power_iterator->p2p_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200601 break;
602
603 case NL80211_IFTYPE_STATION:
Avri Altman19889022014-03-19 07:25:06 +0200604 /* only a single MAC of the same type */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200605 WARN_ON(power_iterator->bss_vif);
606 power_iterator->bss_vif = vif;
Avri Altman19889022014-03-19 07:25:06 +0200607 if (mvmvif->phy_ctxt)
608 if (mvmvif->phy_ctxt->id < MAX_PHYS)
609 power_iterator->bss_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200610
611 if (mvmvif->bf_data.bf_enabled &&
612 !WARN_ON(power_iterator->bf_vif))
613 power_iterator->bf_vif = vif;
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200614
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200615 break;
616
617 default:
618 break;
619 }
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300620}
621
Luciano Coelhob1873302014-08-08 17:12:07 +0300622static void iwl_mvm_power_set_pm(struct iwl_mvm *mvm,
623 struct iwl_power_vifs *vifs)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300624{
Avri Altman19889022014-03-19 07:25:06 +0200625 struct iwl_mvm_vif *bss_mvmvif = NULL;
626 struct iwl_mvm_vif *p2p_mvmvif = NULL;
627 struct iwl_mvm_vif *ap_mvmvif = NULL;
628 bool client_same_channel = false;
629 bool ap_same_channel = false;
630
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200631 lockdep_assert_held(&mvm->mutex);
632
Luciano Coelho128aa942014-08-08 18:36:22 +0300633 /* set pm_enable to false */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200634 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
Luciano Coelho128aa942014-08-08 18:36:22 +0300635 IEEE80211_IFACE_ITER_NORMAL,
636 iwl_mvm_power_disable_pm_iterator,
637 NULL);
Avri Altman19889022014-03-19 07:25:06 +0200638
639 if (vifs->bss_vif)
640 bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif);
641
642 if (vifs->p2p_vif)
643 p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif);
644
645 if (vifs->ap_vif)
646 ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif);
647
Arik Nemtsovfcf23352015-02-22 19:15:04 +0200648 /* don't allow PM if any TDLS stations exist */
649 if (iwl_mvm_tdls_sta_count(mvm, NULL))
650 return;
651
Avri Altman19889022014-03-19 07:25:06 +0200652 /* enable PM on bss if bss stand alone */
Arik Nemtsov9474d442014-09-03 12:09:45 +0300653 if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active) {
Avri Altman19889022014-03-19 07:25:06 +0200654 bss_mvmvif->pm_enabled = true;
655 return;
656 }
657
658 /* enable PM on p2p if p2p stand alone */
Arik Nemtsov9474d442014-09-03 12:09:45 +0300659 if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active) {
Avri Altman19889022014-03-19 07:25:06 +0200660 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
661 p2p_mvmvif->pm_enabled = true;
662 return;
663 }
664
665 if (vifs->bss_active && vifs->p2p_active)
666 client_same_channel = (bss_mvmvif->phy_ctxt->id ==
667 p2p_mvmvif->phy_ctxt->id);
668 if (vifs->bss_active && vifs->ap_active)
669 ap_same_channel = (bss_mvmvif->phy_ctxt->id ==
670 ap_mvmvif->phy_ctxt->id);
671
Avri Altman63ef81c2014-04-02 07:54:07 +0300672 /* clients are not stand alone: enable PM if DCM */
673 if (!(client_same_channel || ap_same_channel) &&
Avri Altman19889022014-03-19 07:25:06 +0200674 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) {
Avri Altman63ef81c2014-04-02 07:54:07 +0300675 if (vifs->bss_active)
Avri Altman19889022014-03-19 07:25:06 +0200676 bss_mvmvif->pm_enabled = true;
Avri Altman63ef81c2014-04-02 07:54:07 +0300677 if (vifs->p2p_active &&
678 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM))
679 p2p_mvmvif->pm_enabled = true;
680 return;
Avri Altman19889022014-03-19 07:25:06 +0200681 }
682
683 /*
684 * There is only one channel in the system and there are only
685 * bss and p2p clients that share it
686 */
687 if (client_same_channel && !vifs->ap_active &&
688 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM)) {
689 /* share same channel*/
690 bss_mvmvif->pm_enabled = true;
691 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
692 p2p_mvmvif->pm_enabled = true;
693 }
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200694}
695
Alexander Bondarb571a692013-05-21 14:49:09 +0300696#ifdef CONFIG_IWLWIFI_DEBUGFS
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200697int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
698 struct ieee80211_vif *vif, char *buf,
699 int bufsz)
Alexander Bondare811ada2013-03-10 15:29:44 +0200700{
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200701 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondare811ada2013-03-10 15:29:44 +0200702 struct iwl_mac_power_cmd cmd = {};
703 int pos = 0;
704
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200705 mutex_lock(&mvm->mutex);
706 memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
707 mutex_unlock(&mvm->mutex);
Alexander Bondare811ada2013-03-10 15:29:44 +0200708
Alexander Bondare811ada2013-03-10 15:29:44 +0200709 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
710 iwlmvm_mod_params.power_scheme);
711 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
712 le16_to_cpu(cmd.flags));
713 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
714 le16_to_cpu(cmd.keep_alive_seconds));
715
Alexander Bondar175a70b2013-04-14 20:59:37 +0300716 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
717 return pos;
718
719 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
720 (cmd.flags &
721 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
722 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
723 cmd.skip_dtim_periods);
724 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
725 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
726 le32_to_cpu(cmd.rx_data_timeout));
727 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
728 le32_to_cpu(cmd.tx_data_timeout));
Alexander Bondare811ada2013-03-10 15:29:44 +0200729 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300730 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
731 pos += scnprintf(buf+pos, bufsz-pos,
732 "lprx_rssi_threshold = %d\n",
733 cmd.lprx_rssi_threshold);
734
735 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
736 return pos;
737
738 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
739 le32_to_cpu(cmd.rx_data_timeout_uapsd));
740 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
741 le32_to_cpu(cmd.tx_data_timeout_uapsd));
742 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
743 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
744 cmd.uapsd_ac_flags);
745 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
746 cmd.uapsd_max_sp);
747 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
748 cmd.heavy_tx_thld_packets);
749 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
750 cmd.heavy_rx_thld_packets);
751 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
752 cmd.heavy_tx_thld_percentage);
753 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
754 cmd.heavy_rx_thld_percentage);
755 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
756 (cmd.flags &
757 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
758 1 : 0);
759
760 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
761 return pos;
762
763 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
764 cmd.snooze_interval);
765 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
766 cmd.snooze_window);
767
Alexander Bondare811ada2013-03-10 15:29:44 +0200768 return pos;
769}
770
Alexander Bondarb571a692013-05-21 14:49:09 +0300771void
772iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
773 struct iwl_beacon_filter_cmd *cmd)
774{
775 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
776 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
777
778 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300779 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300780 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
781 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300782 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300783 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300784 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
785 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
786 cmd->bf_temp_threshold =
787 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
788 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
789 cmd->bf_temp_fast_filter =
790 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
791 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
792 cmd->bf_temp_slow_filter =
793 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300794 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300795 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300796 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
797 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
798 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
799 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
800 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300801 cmd->ba_enable_beacon_abort =
802 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300803}
804#endif
805
Eliad Peller3dd37d02014-01-07 14:00:24 +0200806static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
807 struct ieee80211_vif *vif,
808 struct iwl_beacon_filter_cmd *cmd,
809 u32 cmd_flags,
810 bool d0i3)
Hila Gonen7df15b12012-12-12 11:16:19 +0200811{
812 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondar071d49902013-05-06 13:03:59 +0300813 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200814
Avri Altmanfa7b2e72014-05-20 08:03:24 +0300815 if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period ||
Hila Gonen7df15b12012-12-12 11:16:19 +0200816 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
817 return 0;
818
Gregory Greenmancdc306b2015-07-20 12:55:34 +0300819 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd, d0i3);
Eliad Peller3dd37d02014-01-07 14:00:24 +0200820 if (!d0i3)
821 iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
822 ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300823
Eliad Peller3dd37d02014-01-07 14:00:24 +0200824 /* don't change bf_enabled in case of temporary d0i3 configuration */
825 if (!ret && !d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300826 mvmvif->bf_data.bf_enabled = true;
Alexander Bondar071d49902013-05-06 13:03:59 +0300827
828 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200829}
830
Eliad Peller3dd37d02014-01-07 14:00:24 +0200831int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
832 struct ieee80211_vif *vif,
833 u32 flags)
834{
835 struct iwl_beacon_filter_cmd cmd = {
836 IWL_BF_CMD_CONFIG_DEFAULTS,
837 .bf_enable_beacon_filter = cpu_to_le32(1),
838 };
839
840 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
841}
842
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300843static int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
844 struct ieee80211_vif *vif,
845 bool enable)
Avri Altmanfa7b2e72014-05-20 08:03:24 +0300846{
847 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
848 struct iwl_beacon_filter_cmd cmd = {
849 IWL_BF_CMD_CONFIG_DEFAULTS,
850 .bf_enable_beacon_filter = cpu_to_le32(1),
851 };
852
853 if (!mvmvif->bf_data.bf_enabled)
854 return 0;
855
856 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
857 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
858
859 mvmvif->bf_data.ba_enabled = enable;
860 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false);
861}
862
Hila Gonen7df15b12012-12-12 11:16:19 +0200863int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +0200864 struct ieee80211_vif *vif,
865 u32 flags)
Hila Gonen7df15b12012-12-12 11:16:19 +0200866{
Alexander Bondar071d49902013-05-06 13:03:59 +0300867 struct iwl_beacon_filter_cmd cmd = {};
868 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
869 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200870
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +0300871 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200872 return 0;
873
Eliad Peller3dd37d02014-01-07 14:00:24 +0200874 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300875
876 if (!ret)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300877 mvmvif->bf_data.bf_enabled = false;
Alexander Bondar071d49902013-05-06 13:03:59 +0300878
879 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200880}
Alexander Bondare811ada2013-03-10 15:29:44 +0200881
Luciano Coelho2533edc2014-08-08 19:50:46 +0300882static int iwl_mvm_power_set_ps(struct iwl_mvm *mvm)
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300883{
Luciano Coelho128aa942014-08-08 18:36:22 +0300884 bool disable_ps;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300885 int ret;
886
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300887 /* disable PS if CAM */
Luciano Coelhob1873302014-08-08 17:12:07 +0300888 disable_ps = (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM);
Luciano Coelho2533edc2014-08-08 19:50:46 +0300889 /* ...or if any of the vifs require PS to be off */
890 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
891 IEEE80211_IFACE_ITER_NORMAL,
892 iwl_mvm_power_ps_disabled_iterator,
893 &disable_ps);
Luciano Coelhob1873302014-08-08 17:12:07 +0300894
895 /* update device power state if it has changed */
896 if (mvm->ps_disabled != disable_ps) {
897 bool old_ps_disabled = mvm->ps_disabled;
898
899 mvm->ps_disabled = disable_ps;
900 ret = iwl_mvm_power_update_device(mvm);
901 if (ret) {
902 mvm->ps_disabled = old_ps_disabled;
903 return ret;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300904 }
905 }
906
Luciano Coelho128aa942014-08-08 18:36:22 +0300907 return 0;
908}
909
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300910static int iwl_mvm_power_set_ba(struct iwl_mvm *mvm,
911 struct iwl_power_vifs *vifs)
Luciano Coelho128aa942014-08-08 18:36:22 +0300912{
913 struct iwl_mvm_vif *mvmvif;
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300914 bool ba_enable;
915
916 if (!vifs->bf_vif)
917 return 0;
918
919 mvmvif = iwl_mvm_vif_from_mac80211(vifs->bf_vif);
920
921 ba_enable = !(!mvmvif->pm_enabled || mvm->ps_disabled ||
922 !vifs->bf_vif->bss_conf.ps ||
923 iwl_mvm_vif_low_latency(mvmvif));
924
925 return iwl_mvm_update_beacon_abort(mvm, vifs->bf_vif, ba_enable);
926}
927
928int iwl_mvm_power_update_ps(struct iwl_mvm *mvm)
929{
Luciano Coelho128aa942014-08-08 18:36:22 +0300930 struct iwl_power_vifs vifs = {
931 .mvm = mvm,
932 };
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300933 int ret;
934
935 lockdep_assert_held(&mvm->mutex);
936
937 /* get vifs info */
938 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
939 IEEE80211_IFACE_ITER_NORMAL,
940 iwl_mvm_power_get_vifs_iterator, &vifs);
941
Luciano Coelho2533edc2014-08-08 19:50:46 +0300942 ret = iwl_mvm_power_set_ps(mvm);
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300943 if (ret)
944 return ret;
945
946 return iwl_mvm_power_set_ba(mvm, &vifs);
947}
948
949int iwl_mvm_power_update_mac(struct iwl_mvm *mvm)
950{
951 struct iwl_power_vifs vifs = {
952 .mvm = mvm,
953 };
Luciano Coelho128aa942014-08-08 18:36:22 +0300954 int ret;
955
956 lockdep_assert_held(&mvm->mutex);
957
958 /* get vifs info */
959 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
960 IEEE80211_IFACE_ITER_NORMAL,
961 iwl_mvm_power_get_vifs_iterator, &vifs);
962
963 iwl_mvm_power_set_pm(mvm, &vifs);
964
Luciano Coelho2533edc2014-08-08 19:50:46 +0300965 ret = iwl_mvm_power_set_ps(mvm);
Luciano Coelho128aa942014-08-08 18:36:22 +0300966 if (ret)
967 return ret;
968
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300969 if (vifs.bss_vif) {
970 ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif);
971 if (ret)
972 return ret;
973 }
974
975 if (vifs.p2p_vif) {
976 ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif);
977 if (ret)
978 return ret;
979 }
980
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300981 return iwl_mvm_power_set_ba(mvm, &vifs);
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300982}
983
Eliad Peller3dd37d02014-01-07 14:00:24 +0200984int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
985 struct ieee80211_vif *vif,
986 bool enable, u32 flags)
987{
988 int ret;
989 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
990 struct iwl_mac_power_cmd cmd = {};
991
992 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
993 return 0;
994
995 if (!vif->bss_conf.assoc)
996 return 0;
997
Johannes Berg9645edb2015-10-06 13:28:48 +0200998 iwl_mvm_power_build_cmd(mvm, vif, &cmd, !enable);
Eliad Peller3dd37d02014-01-07 14:00:24 +0200999
Eliad Peller3dd37d02014-01-07 14:00:24 +02001000 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +02001001#ifdef CONFIG_IWLWIFI_DEBUGFS
1002 memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
1003#endif
Eliad Peller3dd37d02014-01-07 14:00:24 +02001004 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
1005 sizeof(cmd), &cmd);
1006 if (ret)
1007 return ret;
1008
1009 /* configure beacon filtering */
1010 if (mvmvif != mvm->bf_allowed_vif)
1011 return 0;
1012
1013 if (enable) {
1014 struct iwl_beacon_filter_cmd cmd_bf = {
1015 IWL_BF_CMD_CONFIG_D0I3,
1016 .bf_enable_beacon_filter = cpu_to_le32(1),
1017 };
1018 ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
1019 flags, true);
1020 } else {
1021 if (mvmvif->bf_data.bf_enabled)
1022 ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
1023 else
1024 ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
1025 }
1026
1027 return ret;
1028}