blob: 3b582dd6d77fdf1c0eec351f6d4e44eae17d3ad7 [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 Berg8ca151b2013-01-24 14:25:36 +01009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020033 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +010034 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64#include <linux/kernel.h>
65#include <linux/module.h>
66#include <linux/slab.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010067
68#include <net/mac80211.h>
69
70#include "iwl-debug.h"
71#include "mvm.h"
72#include "iwl-modparams.h"
73#include "fw-api-power.h"
74
75#define POWER_KEEP_ALIVE_PERIOD_SEC 25
76
Emmanuel Grumbachd623d242014-01-26 12:58:24 +020077static
Alexander Bondare811ada2013-03-10 15:29:44 +020078int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +020079 struct iwl_beacon_filter_cmd *cmd,
80 u32 flags)
Alexander Bondar071d49902013-05-06 13:03:59 +030081{
Emmanuel Grumbachd623d242014-01-26 12:58:24 +020082 IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n",
83 le32_to_cpu(cmd->ba_enable_beacon_abort));
84 IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
85 le32_to_cpu(cmd->ba_escape_timer));
86 IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
87 le32_to_cpu(cmd->bf_debug_flag));
88 IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
89 le32_to_cpu(cmd->bf_enable_beacon_filter));
90 IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
91 le32_to_cpu(cmd->bf_energy_delta));
92 IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
93 le32_to_cpu(cmd->bf_escape_timer));
94 IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
95 le32_to_cpu(cmd->bf_roaming_energy_delta));
96 IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
97 le32_to_cpu(cmd->bf_roaming_state));
98 IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n",
99 le32_to_cpu(cmd->bf_temp_threshold));
100 IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n",
101 le32_to_cpu(cmd->bf_temp_fast_filter));
102 IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n",
103 le32_to_cpu(cmd->bf_temp_slow_filter));
Alexander Bondar071d49902013-05-06 13:03:59 +0300104
Emmanuel Grumbachd623d242014-01-26 12:58:24 +0200105 return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags,
106 sizeof(struct iwl_beacon_filter_cmd), cmd);
Alexander Bondar071d49902013-05-06 13:03:59 +0300107}
108
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300109static
110void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
111 struct ieee80211_vif *vif,
112 struct iwl_beacon_filter_cmd *cmd)
113{
114 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
115
116 if (vif->bss_conf.cqm_rssi_thold) {
117 cmd->bf_energy_delta =
118 cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
119 /* fw uses an absolute value for this */
120 cmd->bf_roaming_state =
121 cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
122 }
123 cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
124}
125
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200126static void iwl_mvm_power_log(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200127 struct iwl_mac_power_cmd *cmd)
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200128{
129 IWL_DEBUG_POWER(mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200130 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
131 cmd->id_and_color, iwlmvm_mod_params.power_scheme,
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200132 le16_to_cpu(cmd->flags));
Alexander Bondare811ada2013-03-10 15:29:44 +0200133 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
134 le16_to_cpu(cmd->keep_alive_seconds));
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200135
Alexander Bondare3c588e2013-04-07 14:08:59 +0300136 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
137 IWL_DEBUG_POWER(mvm, "Disable power management\n");
138 return;
139 }
140
141 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
142 le32_to_cpu(cmd->rx_data_timeout));
143 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
144 le32_to_cpu(cmd->tx_data_timeout));
145 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
146 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
147 cmd->skip_dtim_periods);
148 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
149 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
150 cmd->lprx_rssi_threshold);
151 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
152 IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
153 IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
154 le32_to_cpu(cmd->rx_data_timeout_uapsd));
155 IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
156 le32_to_cpu(cmd->tx_data_timeout_uapsd));
157 IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
158 IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
159 IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200160 }
161}
162
Alexander Bondar175a70b2013-04-14 20:59:37 +0300163static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm,
164 struct ieee80211_vif *vif,
165 struct iwl_mac_power_cmd *cmd)
166{
167 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
168 enum ieee80211_ac_numbers ac;
169 bool tid_found = false;
170
171 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
172 if (!mvmvif->queue_params[ac].uapsd)
173 continue;
174
175 if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
176 cmd->flags |=
177 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
178
179 cmd->uapsd_ac_flags |= BIT(ac);
180
181 /* QNDP TID - the highest TID with no admission control */
182 if (!tid_found && !mvmvif->queue_params[ac].acm) {
183 tid_found = true;
184 switch (ac) {
185 case IEEE80211_AC_VO:
186 cmd->qndp_tid = 6;
187 break;
188 case IEEE80211_AC_VI:
189 cmd->qndp_tid = 5;
190 break;
191 case IEEE80211_AC_BE:
192 cmd->qndp_tid = 0;
193 break;
194 case IEEE80211_AC_BK:
195 cmd->qndp_tid = 1;
196 break;
197 }
198 }
199 }
200
201 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
202 return;
203
204 cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK);
205
206 if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
207 BIT(IEEE80211_AC_VI) |
208 BIT(IEEE80211_AC_BE) |
209 BIT(IEEE80211_AC_BK))) {
210 cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
211 cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
212 cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
213 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
214 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
215 }
216
217 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
218
219 if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
220 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
221 cmd->rx_data_timeout_uapsd =
222 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
223 cmd->tx_data_timeout_uapsd =
224 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
225 } else {
226 cmd->rx_data_timeout_uapsd =
227 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
228 cmd->tx_data_timeout_uapsd =
229 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
230 }
231
232 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
233 cmd->heavy_tx_thld_packets =
234 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
235 cmd->heavy_rx_thld_packets =
236 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
237 } else {
238 cmd->heavy_tx_thld_packets =
239 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
240 cmd->heavy_rx_thld_packets =
241 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
242 }
243 cmd->heavy_tx_thld_percentage =
244 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
245 cmd->heavy_rx_thld_percentage =
246 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
247}
248
Avri Altmanc6e37a62014-04-01 12:08:13 +0300249static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm,
250 struct ieee80211_vif *vif)
251{
252 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
253
254 if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
255 ETH_ALEN))
256 return false;
257
258 if (vif->p2p &&
259 !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD))
260 return false;
261 /*
262 * Avoid using uAPSD if P2P client is associated to GO that uses
263 * opportunistic power save. This is due to current FW limitation.
264 */
265 if (vif->p2p &&
266 (vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
267 IEEE80211_P2P_OPPPS_ENABLE_BIT))
268 return false;
269
Avri Altman05345282014-05-08 10:06:01 +0300270 /*
271 * Avoid using uAPSD if client is in DCM -
272 * low latency issue in Miracast
273 */
Arik Nemtsovcf7b4912014-05-15 11:44:40 +0300274 if (iwl_mvm_phy_ctx_count(mvm) >= 2)
Avri Altman05345282014-05-08 10:06:01 +0300275 return false;
276
Avri Altmanc6e37a62014-04-01 12:08:13 +0300277 return true;
278}
279
Alexander Bondare811ada2013-03-10 15:29:44 +0200280static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
281 struct ieee80211_vif *vif,
282 struct iwl_mac_power_cmd *cmd)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100283{
284 struct ieee80211_hw *hw = mvm->hw;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100285 struct ieee80211_chanctx_conf *chanctx_conf;
286 struct ieee80211_channel *chan;
287 int dtimper, dtimper_msec;
288 int keep_alive;
289 bool radar_detect = false;
Alexander Bondarb571a692013-05-21 14:49:09 +0300290 struct iwl_mvm_vif *mvmvif __maybe_unused =
291 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100292
Alexander Bondare811ada2013-03-10 15:29:44 +0200293 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
294 mvmvif->color));
295 dtimper = hw->conf.ps_dtim_period ?: 1;
296
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200297 /*
298 * Regardless of power management state the driver must set
299 * keep alive period. FW will use it for sending keep alive NDPs
Alexander Bondare811ada2013-03-10 15:29:44 +0200300 * immediately after association. Check that keep alive period
301 * is at least 3 * DTIM
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200302 */
Alexander Bondare811ada2013-03-10 15:29:44 +0200303 dtimper_msec = dtimper * vif->bss_conf.beacon_int;
304 keep_alive = max_t(int, 3 * dtimper_msec,
305 MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
306 keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
307 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200308
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200309 if (mvm->ps_disabled)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100310 return;
311
Alexander Bondar9a613042013-03-05 12:54:00 +0200312 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
313
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200314 if (!vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif) ||
Avri Altman19889022014-03-19 07:25:06 +0200315 !mvmvif->pm_enabled)
Alexander Bondar9a613042013-03-05 12:54:00 +0200316 return;
317
318 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100319
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200320 if (vif->bss_conf.beacon_rate &&
321 (vif->bss_conf.beacon_rate->bitrate == 10 ||
322 vif->bss_conf.beacon_rate->bitrate == 60)) {
323 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200324 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200325 }
326
Johannes Berg8ca151b2013-01-24 14:25:36 +0100327 /* Check if radar detection is required on current channel */
328 rcu_read_lock();
329 chanctx_conf = rcu_dereference(vif->chanctx_conf);
330 WARN_ON(!chanctx_conf);
331 if (chanctx_conf) {
332 chan = chanctx_conf->def.chan;
333 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
334 }
335 rcu_read_unlock();
336
337 /* Check skip over DTIM conditions */
338 if (!radar_detect && (dtimper <= 10) &&
Alexander Bondaree1e8422013-04-23 13:52:10 +0300339 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
340 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200341 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200342 cmd->skip_dtim_periods = 3;
Alexander Bondar5b1dbfc2013-04-23 13:32:35 +0300343 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100344
Alexander Bondaree1e8422013-04-23 13:52:10 +0300345 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
Johannes Berg99545922013-06-14 13:36:21 +0200346 cmd->rx_data_timeout =
347 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
348 cmd->tx_data_timeout =
349 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300350 } else {
Johannes Berg99545922013-06-14 13:36:21 +0200351 cmd->rx_data_timeout =
352 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
353 cmd->tx_data_timeout =
354 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300355 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300356
Avri Altmanc6e37a62014-04-01 12:08:13 +0300357 if (iwl_mvm_power_allow_uapsd(mvm, vif))
Alexander Bondar175a70b2013-04-14 20:59:37 +0300358 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300359
Alexander Bondarb571a692013-05-21 14:49:09 +0300360#ifdef CONFIG_IWLWIFI_DEBUGFS
361 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200362 cmd->keep_alive_seconds =
363 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300364 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
365 if (mvmvif->dbgfs_pm.skip_over_dtim)
366 cmd->flags |=
367 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
368 else
369 cmd->flags &=
370 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
371 }
372 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
373 cmd->rx_data_timeout =
374 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
375 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
376 cmd->tx_data_timeout =
377 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
378 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200379 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200380 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
381 if (mvmvif->dbgfs_pm.lprx_ena)
382 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
383 else
384 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
385 }
386 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200387 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondar89716342013-08-04 17:52:23 +0300388 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
389 if (mvmvif->dbgfs_pm.snooze_ena)
390 cmd->flags |=
391 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
392 else
393 cmd->flags &=
394 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
395 }
Alexander Bondare45a9412013-12-04 10:13:24 +0200396 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
397 u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
398 if (mvmvif->dbgfs_pm.uapsd_misbehaving)
399 cmd->flags |= cpu_to_le16(flag);
400 else
401 cmd->flags &= cpu_to_le16(flag);
402 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300403#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100404}
405
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200406static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200407 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100408{
Alexander Bondare811ada2013-03-10 15:29:44 +0200409 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100410
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200411 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200412 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200413#ifdef CONFIG_IWLWIFI_DEBUGFS
414 memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
415#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100416
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300417 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0,
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200418 sizeof(cmd), &cmd);
419}
420
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200421int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300422{
423 struct iwl_device_power_cmd cmd = {
424 .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK),
425 };
426
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200427 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
428 mvm->ps_disabled = true;
429
430 if (mvm->ps_disabled)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300431 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK);
432
433#ifdef CONFIG_IWLWIFI_DEBUGFS
434 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
435 mvm->disable_power_off)
436 cmd.flags &=
437 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
438#endif
439 IWL_DEBUG_POWER(mvm,
440 "Sending device power command with flags = 0x%X\n",
441 cmd.flags);
442
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300443 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd),
Alexander Bondar64b928c2013-09-03 14:18:03 +0300444 &cmd);
445}
446
Alexander Bondar175a70b2013-04-14 20:59:37 +0300447void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
448{
449 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
450
451 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
452 ETH_ALEN))
453 memset(mvmvif->uapsd_misbehaving_bssid, 0, ETH_ALEN);
454}
455
456static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
457 struct ieee80211_vif *vif)
458{
459 u8 *ap_sta_id = _data;
460 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
461
462 /* The ap_sta_id is not expected to change during current association
463 * so no explicit protection is needed
464 */
465 if (mvmvif->ap_sta_id == *ap_sta_id)
466 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
467 ETH_ALEN);
468}
469
470int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
471 struct iwl_rx_cmd_buffer *rxb,
472 struct iwl_device_cmd *cmd)
473{
474 struct iwl_rx_packet *pkt = rxb_addr(rxb);
475 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
476 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
477
478 ieee80211_iterate_active_interfaces_atomic(
479 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
480 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
481
482 return 0;
483}
484
Avri Altman19889022014-03-19 07:25:06 +0200485struct iwl_power_vifs {
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200486 struct ieee80211_vif *bf_vif;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200487 struct ieee80211_vif *bss_vif;
Avri Altman8ea0c682014-02-20 13:28:57 +0200488 struct ieee80211_vif *p2p_vif;
Avri Altman19889022014-03-19 07:25:06 +0200489 struct ieee80211_vif *ap_vif;
490 struct ieee80211_vif *monitor_vif;
491 bool p2p_active;
492 bool bss_active;
493 bool ap_active;
494 bool monitor_active;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200495};
496
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200497static void iwl_mvm_power_iterator(void *_data, u8 *mac,
498 struct ieee80211_vif *vif)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300499{
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200500 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman19889022014-03-19 07:25:06 +0200501 struct iwl_power_vifs *power_iterator = _data;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300502
Avri Altman19889022014-03-19 07:25:06 +0200503 mvmvif->pm_enabled = false;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200504 switch (ieee80211_vif_type_p2p(vif)) {
505 case NL80211_IFTYPE_P2P_DEVICE:
506 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200507
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200508 case NL80211_IFTYPE_P2P_GO:
509 case NL80211_IFTYPE_AP:
Avri Altman19889022014-03-19 07:25:06 +0200510 /* only a single MAC of the same type */
511 WARN_ON(power_iterator->ap_vif);
512 power_iterator->ap_vif = vif;
513 if (mvmvif->phy_ctxt)
514 if (mvmvif->phy_ctxt->id < MAX_PHYS)
515 power_iterator->ap_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200516 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200517
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200518 case NL80211_IFTYPE_MONITOR:
Avri Altman19889022014-03-19 07:25:06 +0200519 /* only a single MAC of the same type */
520 WARN_ON(power_iterator->monitor_vif);
521 power_iterator->monitor_vif = vif;
522 if (mvmvif->phy_ctxt)
523 if (mvmvif->phy_ctxt->id < MAX_PHYS)
524 power_iterator->monitor_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200525 break;
526
527 case NL80211_IFTYPE_P2P_CLIENT:
Avri Altman19889022014-03-19 07:25:06 +0200528 /* only a single MAC of the same type */
Avri Altman8ea0c682014-02-20 13:28:57 +0200529 WARN_ON(power_iterator->p2p_vif);
530 power_iterator->p2p_vif = vif;
Avri Altman19889022014-03-19 07:25:06 +0200531 if (mvmvif->phy_ctxt)
532 if (mvmvif->phy_ctxt->id < MAX_PHYS)
533 power_iterator->p2p_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200534 break;
535
536 case NL80211_IFTYPE_STATION:
Avri Altman19889022014-03-19 07:25:06 +0200537 /* only a single MAC of the same type */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200538 WARN_ON(power_iterator->bss_vif);
539 power_iterator->bss_vif = vif;
Avri Altman19889022014-03-19 07:25:06 +0200540 if (mvmvif->phy_ctxt)
541 if (mvmvif->phy_ctxt->id < MAX_PHYS)
542 power_iterator->bss_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200543
544 if (mvmvif->bf_data.bf_enabled &&
545 !WARN_ON(power_iterator->bf_vif))
546 power_iterator->bf_vif = vif;
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200547
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200548 break;
549
550 default:
551 break;
552 }
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300553}
554
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200555static void
Avri Altman19889022014-03-19 07:25:06 +0200556iwl_mvm_power_set_pm(struct iwl_mvm *mvm,
557 struct iwl_power_vifs *vifs)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300558{
Avri Altman19889022014-03-19 07:25:06 +0200559 struct iwl_mvm_vif *bss_mvmvif = NULL;
560 struct iwl_mvm_vif *p2p_mvmvif = NULL;
561 struct iwl_mvm_vif *ap_mvmvif = NULL;
562 bool client_same_channel = false;
563 bool ap_same_channel = false;
564
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200565 lockdep_assert_held(&mvm->mutex);
566
Avri Altman19889022014-03-19 07:25:06 +0200567 /* get vifs info + set pm_enable to false */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200568 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
569 IEEE80211_IFACE_ITER_NORMAL,
Avri Altman19889022014-03-19 07:25:06 +0200570 iwl_mvm_power_iterator, vifs);
571
572 if (vifs->bss_vif)
573 bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif);
574
575 if (vifs->p2p_vif)
576 p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif);
577
578 if (vifs->ap_vif)
579 ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif);
580
581 /* enable PM on bss if bss stand alone */
582 if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active) {
583 bss_mvmvif->pm_enabled = true;
584 return;
585 }
586
587 /* enable PM on p2p if p2p stand alone */
588 if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active) {
589 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
590 p2p_mvmvif->pm_enabled = true;
591 return;
592 }
593
594 if (vifs->bss_active && vifs->p2p_active)
595 client_same_channel = (bss_mvmvif->phy_ctxt->id ==
596 p2p_mvmvif->phy_ctxt->id);
597 if (vifs->bss_active && vifs->ap_active)
598 ap_same_channel = (bss_mvmvif->phy_ctxt->id ==
599 ap_mvmvif->phy_ctxt->id);
600
Avri Altman63ef81c2014-04-02 07:54:07 +0300601 /* clients are not stand alone: enable PM if DCM */
602 if (!(client_same_channel || ap_same_channel) &&
Avri Altman19889022014-03-19 07:25:06 +0200603 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) {
Avri Altman63ef81c2014-04-02 07:54:07 +0300604 if (vifs->bss_active)
Avri Altman19889022014-03-19 07:25:06 +0200605 bss_mvmvif->pm_enabled = true;
Avri Altman63ef81c2014-04-02 07:54:07 +0300606 if (vifs->p2p_active &&
607 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM))
608 p2p_mvmvif->pm_enabled = true;
609 return;
Avri Altman19889022014-03-19 07:25:06 +0200610 }
611
612 /*
613 * There is only one channel in the system and there are only
614 * bss and p2p clients that share it
615 */
616 if (client_same_channel && !vifs->ap_active &&
617 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM)) {
618 /* share same channel*/
619 bss_mvmvif->pm_enabled = true;
620 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
621 p2p_mvmvif->pm_enabled = true;
622 }
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200623}
624
Alexander Bondarb571a692013-05-21 14:49:09 +0300625#ifdef CONFIG_IWLWIFI_DEBUGFS
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200626int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
627 struct ieee80211_vif *vif, char *buf,
628 int bufsz)
Alexander Bondare811ada2013-03-10 15:29:44 +0200629{
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200630 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondare811ada2013-03-10 15:29:44 +0200631 struct iwl_mac_power_cmd cmd = {};
632 int pos = 0;
633
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200634 mutex_lock(&mvm->mutex);
635 memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
636 mutex_unlock(&mvm->mutex);
Alexander Bondare811ada2013-03-10 15:29:44 +0200637
Alexander Bondare811ada2013-03-10 15:29:44 +0200638 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
639 iwlmvm_mod_params.power_scheme);
640 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
641 le16_to_cpu(cmd.flags));
642 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
643 le16_to_cpu(cmd.keep_alive_seconds));
644
Alexander Bondar175a70b2013-04-14 20:59:37 +0300645 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
646 return pos;
647
648 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
649 (cmd.flags &
650 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
651 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
652 cmd.skip_dtim_periods);
653 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
654 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
655 le32_to_cpu(cmd.rx_data_timeout));
656 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
657 le32_to_cpu(cmd.tx_data_timeout));
Alexander Bondare811ada2013-03-10 15:29:44 +0200658 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300659 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
660 pos += scnprintf(buf+pos, bufsz-pos,
661 "lprx_rssi_threshold = %d\n",
662 cmd.lprx_rssi_threshold);
663
664 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
665 return pos;
666
667 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
668 le32_to_cpu(cmd.rx_data_timeout_uapsd));
669 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
670 le32_to_cpu(cmd.tx_data_timeout_uapsd));
671 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
672 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
673 cmd.uapsd_ac_flags);
674 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
675 cmd.uapsd_max_sp);
676 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
677 cmd.heavy_tx_thld_packets);
678 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
679 cmd.heavy_rx_thld_packets);
680 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
681 cmd.heavy_tx_thld_percentage);
682 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
683 cmd.heavy_rx_thld_percentage);
684 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
685 (cmd.flags &
686 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
687 1 : 0);
688
689 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
690 return pos;
691
692 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
693 cmd.snooze_interval);
694 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
695 cmd.snooze_window);
696
Alexander Bondare811ada2013-03-10 15:29:44 +0200697 return pos;
698}
699
Alexander Bondarb571a692013-05-21 14:49:09 +0300700void
701iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
702 struct iwl_beacon_filter_cmd *cmd)
703{
704 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
705 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
706
707 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300708 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300709 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
710 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300711 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300712 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300713 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
714 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
715 cmd->bf_temp_threshold =
716 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
717 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
718 cmd->bf_temp_fast_filter =
719 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
720 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
721 cmd->bf_temp_slow_filter =
722 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300723 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300724 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300725 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
726 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
727 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
728 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
729 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300730 cmd->ba_enable_beacon_abort =
731 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300732}
733#endif
734
Eliad Peller3dd37d02014-01-07 14:00:24 +0200735static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
736 struct ieee80211_vif *vif,
737 struct iwl_beacon_filter_cmd *cmd,
738 u32 cmd_flags,
739 bool d0i3)
Hila Gonen7df15b12012-12-12 11:16:19 +0200740{
741 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondar071d49902013-05-06 13:03:59 +0300742 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200743
Avri Altmanfa7b2e72014-05-20 08:03:24 +0300744 if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period ||
Hila Gonen7df15b12012-12-12 11:16:19 +0200745 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
746 return 0;
747
Eliad Peller3dd37d02014-01-07 14:00:24 +0200748 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd);
749 if (!d0i3)
750 iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
751 ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300752
Eliad Peller3dd37d02014-01-07 14:00:24 +0200753 /* don't change bf_enabled in case of temporary d0i3 configuration */
754 if (!ret && !d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300755 mvmvif->bf_data.bf_enabled = true;
Alexander Bondar071d49902013-05-06 13:03:59 +0300756
757 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200758}
759
Eliad Peller3dd37d02014-01-07 14:00:24 +0200760int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
761 struct ieee80211_vif *vif,
762 u32 flags)
763{
764 struct iwl_beacon_filter_cmd cmd = {
765 IWL_BF_CMD_CONFIG_DEFAULTS,
766 .bf_enable_beacon_filter = cpu_to_le32(1),
767 };
768
769 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
770}
771
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300772static int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
773 struct ieee80211_vif *vif,
774 bool enable)
Avri Altmanfa7b2e72014-05-20 08:03:24 +0300775{
776 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
777 struct iwl_beacon_filter_cmd cmd = {
778 IWL_BF_CMD_CONFIG_DEFAULTS,
779 .bf_enable_beacon_filter = cpu_to_le32(1),
780 };
781
782 if (!mvmvif->bf_data.bf_enabled)
783 return 0;
784
785 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
786 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
787
788 mvmvif->bf_data.ba_enabled = enable;
789 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false);
790}
791
Hila Gonen7df15b12012-12-12 11:16:19 +0200792int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +0200793 struct ieee80211_vif *vif,
794 u32 flags)
Hila Gonen7df15b12012-12-12 11:16:19 +0200795{
Alexander Bondar071d49902013-05-06 13:03:59 +0300796 struct iwl_beacon_filter_cmd cmd = {};
797 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
798 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200799
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +0300800 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200801 return 0;
802
Eliad Peller3dd37d02014-01-07 14:00:24 +0200803 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300804
805 if (!ret)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300806 mvmvif->bf_data.bf_enabled = false;
Alexander Bondar071d49902013-05-06 13:03:59 +0300807
808 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200809}
Alexander Bondare811ada2013-03-10 15:29:44 +0200810
Arik Nemtsov999609f2014-05-15 17:31:51 +0300811int iwl_mvm_power_update_mac(struct iwl_mvm *mvm)
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300812{
813 struct iwl_mvm_vif *mvmvif;
814 struct iwl_power_vifs vifs = {};
815 bool ba_enable;
816 int ret;
817
818 lockdep_assert_held(&mvm->mutex);
819
820 iwl_mvm_power_set_pm(mvm, &vifs);
821
822 /* disable PS if CAM */
823 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) {
824 mvm->ps_disabled = true;
825 } else {
826 /* don't update device power state unless we add / remove monitor */
827 if (vifs.monitor_vif) {
828 if (vifs.monitor_active)
829 mvm->ps_disabled = true;
830 ret = iwl_mvm_power_update_device(mvm);
831 if (ret)
832 return ret;
833 }
834 }
835
836 if (vifs.bss_vif) {
837 ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif);
838 if (ret)
839 return ret;
840 }
841
842 if (vifs.p2p_vif) {
843 ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif);
844 if (ret)
845 return ret;
846 }
847
848 if (!vifs.bf_vif)
849 return 0;
850
Arik Nemtsov999609f2014-05-15 17:31:51 +0300851 mvmvif = iwl_mvm_vif_from_mac80211(vifs.bf_vif);
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300852
853 ba_enable = !(!mvmvif->pm_enabled || mvm->ps_disabled ||
Arik Nemtsov999609f2014-05-15 17:31:51 +0300854 !vifs.bf_vif->bss_conf.ps ||
855 iwl_mvm_vif_low_latency(mvmvif));
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300856
857 return iwl_mvm_update_beacon_abort(mvm, vifs.bf_vif, ba_enable);
858}
859
Eliad Peller3dd37d02014-01-07 14:00:24 +0200860int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
861 struct ieee80211_vif *vif,
862 bool enable, u32 flags)
863{
864 int ret;
865 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
866 struct iwl_mac_power_cmd cmd = {};
867
868 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
869 return 0;
870
871 if (!vif->bss_conf.assoc)
872 return 0;
873
874 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
875 if (enable) {
876 /* configure skip over dtim up to 300 msec */
877 int dtimper = mvm->hw->conf.ps_dtim_period ?: 1;
878 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
879
880 if (WARN_ON(!dtimper_msec))
881 return 0;
882
Eliad Peller3dd37d02014-01-07 14:00:24 +0200883 cmd.skip_dtim_periods = 300 / dtimper_msec;
Eliad Peller6f361052014-05-12 14:22:20 +0300884 if (cmd.skip_dtim_periods)
885 cmd.flags |=
886 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Eliad Peller3dd37d02014-01-07 14:00:24 +0200887 }
888 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200889#ifdef CONFIG_IWLWIFI_DEBUGFS
890 memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
891#endif
Eliad Peller3dd37d02014-01-07 14:00:24 +0200892 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
893 sizeof(cmd), &cmd);
894 if (ret)
895 return ret;
896
897 /* configure beacon filtering */
898 if (mvmvif != mvm->bf_allowed_vif)
899 return 0;
900
901 if (enable) {
902 struct iwl_beacon_filter_cmd cmd_bf = {
903 IWL_BF_CMD_CONFIG_D0I3,
904 .bf_enable_beacon_filter = cpu_to_le32(1),
905 };
906 ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
907 flags, true);
908 } else {
909 if (mvmvif->bf_data.bf_enabled)
910 ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
911 else
912 ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
913 }
914
915 return ret;
916}