blob: 15c9c780323b591ff7520a02516d7423fca13a6b [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 Bondare811ada2013-03-10 15:29:44 +0200126int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
127 struct ieee80211_vif *vif, bool enable)
Alexander Bondar071d49902013-05-06 13:03:59 +0300128{
129 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
130 struct iwl_beacon_filter_cmd cmd = {
131 IWL_BF_CMD_CONFIG_DEFAULTS,
Hila Gonen5dca7c22013-07-16 11:15:35 +0300132 .bf_enable_beacon_filter = cpu_to_le32(1),
133 .ba_enable_beacon_abort = cpu_to_le32(enable),
Alexander Bondar071d49902013-05-06 13:03:59 +0300134 };
135
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300136 if (!mvmvif->bf_data.bf_enabled)
Alexander Bondar071d49902013-05-06 13:03:59 +0300137 return 0;
138
Alexander Bondar84349252013-07-22 15:39:26 +0300139 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
140 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
141
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300142 mvmvif->bf_data.ba_enabled = enable;
143 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
Alexander Bondarb571a692013-05-21 14:49:09 +0300144 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
Eliad Peller3dd37d02014-01-07 14:00:24 +0200145 return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, CMD_SYNC);
Alexander Bondar071d49902013-05-06 13:03:59 +0300146}
147
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200148static void iwl_mvm_power_log(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200149 struct iwl_mac_power_cmd *cmd)
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200150{
151 IWL_DEBUG_POWER(mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200152 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
153 cmd->id_and_color, iwlmvm_mod_params.power_scheme,
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200154 le16_to_cpu(cmd->flags));
Alexander Bondare811ada2013-03-10 15:29:44 +0200155 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
156 le16_to_cpu(cmd->keep_alive_seconds));
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200157
Alexander Bondare3c588e2013-04-07 14:08:59 +0300158 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
159 IWL_DEBUG_POWER(mvm, "Disable power management\n");
160 return;
161 }
162
163 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
164 le32_to_cpu(cmd->rx_data_timeout));
165 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
166 le32_to_cpu(cmd->tx_data_timeout));
167 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
168 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
169 cmd->skip_dtim_periods);
170 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
171 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
172 cmd->lprx_rssi_threshold);
173 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
174 IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
175 IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
176 le32_to_cpu(cmd->rx_data_timeout_uapsd));
177 IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
178 le32_to_cpu(cmd->tx_data_timeout_uapsd));
179 IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
180 IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
181 IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200182 }
183}
184
Alexander Bondar175a70b2013-04-14 20:59:37 +0300185static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm,
186 struct ieee80211_vif *vif,
187 struct iwl_mac_power_cmd *cmd)
188{
189 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
190 enum ieee80211_ac_numbers ac;
191 bool tid_found = false;
192
193 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
194 if (!mvmvif->queue_params[ac].uapsd)
195 continue;
196
197 if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
198 cmd->flags |=
199 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
200
201 cmd->uapsd_ac_flags |= BIT(ac);
202
203 /* QNDP TID - the highest TID with no admission control */
204 if (!tid_found && !mvmvif->queue_params[ac].acm) {
205 tid_found = true;
206 switch (ac) {
207 case IEEE80211_AC_VO:
208 cmd->qndp_tid = 6;
209 break;
210 case IEEE80211_AC_VI:
211 cmd->qndp_tid = 5;
212 break;
213 case IEEE80211_AC_BE:
214 cmd->qndp_tid = 0;
215 break;
216 case IEEE80211_AC_BK:
217 cmd->qndp_tid = 1;
218 break;
219 }
220 }
221 }
222
223 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
224 return;
225
226 cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK);
227
228 if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
229 BIT(IEEE80211_AC_VI) |
230 BIT(IEEE80211_AC_BE) |
231 BIT(IEEE80211_AC_BK))) {
232 cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
233 cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
234 cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
235 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
236 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
237 }
238
239 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
240
241 if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
242 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
243 cmd->rx_data_timeout_uapsd =
244 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
245 cmd->tx_data_timeout_uapsd =
246 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
247 } else {
248 cmd->rx_data_timeout_uapsd =
249 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
250 cmd->tx_data_timeout_uapsd =
251 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
252 }
253
254 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
255 cmd->heavy_tx_thld_packets =
256 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
257 cmd->heavy_rx_thld_packets =
258 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
259 } else {
260 cmd->heavy_tx_thld_packets =
261 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
262 cmd->heavy_rx_thld_packets =
263 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
264 }
265 cmd->heavy_tx_thld_percentage =
266 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
267 cmd->heavy_rx_thld_percentage =
268 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
269}
270
Alexander Bondare811ada2013-03-10 15:29:44 +0200271static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
272 struct ieee80211_vif *vif,
273 struct iwl_mac_power_cmd *cmd)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100274{
275 struct ieee80211_hw *hw = mvm->hw;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100276 struct ieee80211_chanctx_conf *chanctx_conf;
277 struct ieee80211_channel *chan;
278 int dtimper, dtimper_msec;
279 int keep_alive;
280 bool radar_detect = false;
Alexander Bondarb571a692013-05-21 14:49:09 +0300281 struct iwl_mvm_vif *mvmvif __maybe_unused =
282 iwl_mvm_vif_from_mac80211(vif);
Alexander Bondar51498cf2013-09-02 17:10:14 +0300283 bool allow_uapsd = true;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100284
Alexander Bondare811ada2013-03-10 15:29:44 +0200285 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
286 mvmvif->color));
287 dtimper = hw->conf.ps_dtim_period ?: 1;
288
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200289 /*
290 * Regardless of power management state the driver must set
291 * keep alive period. FW will use it for sending keep alive NDPs
Alexander Bondare811ada2013-03-10 15:29:44 +0200292 * immediately after association. Check that keep alive period
293 * is at least 3 * DTIM
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200294 */
Alexander Bondare811ada2013-03-10 15:29:44 +0200295 dtimper_msec = dtimper * vif->bss_conf.beacon_int;
296 keep_alive = max_t(int, 3 * dtimper_msec,
297 MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
298 keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
299 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200300
Alexander Bondar92d85562013-10-23 11:50:34 +0200301 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM ||
302 mvm->ps_prevented)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100303 return;
304
Alexander Bondar9a613042013-03-05 12:54:00 +0200305 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
306
Alexander Bondarb571a692013-05-21 14:49:09 +0300307#ifdef CONFIG_IWLWIFI_DEBUGFS
308 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
309 mvmvif->dbgfs_pm.disable_power_off)
310 cmd->flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
311#endif
Emmanuel Grumbachd623d242014-01-26 12:58:24 +0200312 if (!vif->bss_conf.ps || mvm->bound_vif_cnt > 1 ||
Johannes Berge03f9bef2013-11-13 17:16:19 +0100313 iwl_mvm_vif_low_latency(mvmvif))
Alexander Bondar9a613042013-03-05 12:54:00 +0200314 return;
315
316 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100317
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200318 if (vif->bss_conf.beacon_rate &&
319 (vif->bss_conf.beacon_rate->bitrate == 10 ||
320 vif->bss_conf.beacon_rate->bitrate == 60)) {
321 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200322 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200323 }
324
Johannes Berg8ca151b2013-01-24 14:25:36 +0100325 /* Check if radar detection is required on current channel */
326 rcu_read_lock();
327 chanctx_conf = rcu_dereference(vif->chanctx_conf);
328 WARN_ON(!chanctx_conf);
329 if (chanctx_conf) {
330 chan = chanctx_conf->def.chan;
331 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
332 }
333 rcu_read_unlock();
334
335 /* Check skip over DTIM conditions */
336 if (!radar_detect && (dtimper <= 10) &&
Alexander Bondaree1e8422013-04-23 13:52:10 +0300337 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
338 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200339 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200340 cmd->skip_dtim_periods = 3;
Alexander Bondar5b1dbfc2013-04-23 13:32:35 +0300341 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100342
Alexander Bondaree1e8422013-04-23 13:52:10 +0300343 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
Johannes Berg99545922013-06-14 13:36:21 +0200344 cmd->rx_data_timeout =
345 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
346 cmd->tx_data_timeout =
347 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300348 } else {
Johannes Berg99545922013-06-14 13:36:21 +0200349 cmd->rx_data_timeout =
350 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
351 cmd->tx_data_timeout =
352 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300353 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300354
Alexander Bondar51498cf2013-09-02 17:10:14 +0300355 if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
356 ETH_ALEN))
357 allow_uapsd = false;
Alexander Bondar75209672013-11-12 14:47:59 +0200358
359 if (vif->p2p &&
360 !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD))
361 allow_uapsd = false;
Alexander Bondar51498cf2013-09-02 17:10:14 +0300362 /*
363 * Avoid using uAPSD if P2P client is associated to GO that uses
364 * opportunistic power save. This is due to current FW limitation.
365 */
366 if (vif->p2p &&
367 vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
368 IEEE80211_P2P_OPPPS_ENABLE_BIT)
369 allow_uapsd = false;
370
371 if (allow_uapsd)
Alexander Bondar175a70b2013-04-14 20:59:37 +0300372 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300373
Alexander Bondarb571a692013-05-21 14:49:09 +0300374#ifdef CONFIG_IWLWIFI_DEBUGFS
375 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200376 cmd->keep_alive_seconds =
377 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300378 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
379 if (mvmvif->dbgfs_pm.skip_over_dtim)
380 cmd->flags |=
381 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
382 else
383 cmd->flags &=
384 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
385 }
386 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
387 cmd->rx_data_timeout =
388 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
389 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
390 cmd->tx_data_timeout =
391 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
392 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200393 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200394 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
395 if (mvmvif->dbgfs_pm.lprx_ena)
396 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
397 else
398 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
399 }
400 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200401 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondar89716342013-08-04 17:52:23 +0300402 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
403 if (mvmvif->dbgfs_pm.snooze_ena)
404 cmd->flags |=
405 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
406 else
407 cmd->flags &=
408 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
409 }
Alexander Bondare45a9412013-12-04 10:13:24 +0200410 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
411 u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
412 if (mvmvif->dbgfs_pm.uapsd_misbehaving)
413 cmd->flags |= cpu_to_le16(flag);
414 else
415 cmd->flags &= cpu_to_le16(flag);
416 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300417#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100418}
419
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200420static int _iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200421 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100422{
Alexander Bondare811ada2013-03-10 15:29:44 +0200423 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100424
Alexander Bondar51498cf2013-09-02 17:10:14 +0300425 if (vif->type != NL80211_IFTYPE_STATION)
426 return 0;
427
428 if (vif->p2p &&
429 !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100430 return 0;
431
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200432 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200433 iwl_mvm_power_log(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100434
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200435 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC,
436 sizeof(cmd), &cmd);
437}
438
439static int iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm,
440 struct ieee80211_vif *vif)
441
442{
443 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
444 bool ba_enable;
445 int ret;
446
447 ret = _iwl_mvm_power_mac_update_mode(mvm, vif);
Alexander Bondar071d49902013-05-06 13:03:59 +0300448 if (ret)
449 return ret;
450
Emmanuel Grumbachdcefeec2014-01-26 16:54:05 +0200451 ba_enable = !(iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM ||
452 mvm->ps_prevented || mvm->bound_vif_cnt > 1 ||
453 !vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif));
Alexander Bondar071d49902013-05-06 13:03:59 +0300454
455 return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100456}
457
Alexander Bondare811ada2013-03-10 15:29:44 +0200458static int iwl_mvm_power_mac_disable(struct iwl_mvm *mvm,
459 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100460{
Alexander Bondare811ada2013-03-10 15:29:44 +0200461 struct iwl_mac_power_cmd cmd = {};
Alexander Bondarb571a692013-05-21 14:49:09 +0300462 struct iwl_mvm_vif *mvmvif __maybe_unused =
463 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100464
Johannes Berg8ca151b2013-01-24 14:25:36 +0100465 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
466 return 0;
467
Alexander Bondare811ada2013-03-10 15:29:44 +0200468 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
469 mvmvif->color));
470
Alexander Bondarade50652013-04-03 16:28:47 +0300471 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
Alexander Bondar9a613042013-03-05 12:54:00 +0200472 cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
473
Alexander Bondarb571a692013-05-21 14:49:09 +0300474#ifdef CONFIG_IWLWIFI_DEBUGFS
475 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
476 mvmvif->dbgfs_pm.disable_power_off)
477 cmd.flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
478#endif
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200479 iwl_mvm_power_log(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100480
Alexander Bondare811ada2013-03-10 15:29:44 +0200481 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_ASYNC,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100482 sizeof(cmd), &cmd);
483}
Hila Gonen7df15b12012-12-12 11:16:19 +0200484
Alexander Bondar92d85562013-10-23 11:50:34 +0200485static int _iwl_mvm_power_update_device(struct iwl_mvm *mvm, bool force_disable)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300486{
487 struct iwl_device_power_cmd cmd = {
488 .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK),
489 };
490
491 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD))
492 return 0;
493
Alexander Bondar92d85562013-10-23 11:50:34 +0200494 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM ||
495 force_disable)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300496 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK);
497
498#ifdef CONFIG_IWLWIFI_DEBUGFS
499 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
500 mvm->disable_power_off)
501 cmd.flags &=
502 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
503#endif
504 IWL_DEBUG_POWER(mvm,
505 "Sending device power command with flags = 0x%X\n",
506 cmd.flags);
507
508 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_SYNC, sizeof(cmd),
509 &cmd);
510}
511
Alexander Bondar92d85562013-10-23 11:50:34 +0200512static int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
513{
514 return _iwl_mvm_power_update_device(mvm, false);
515}
516
Alexander Bondar175a70b2013-04-14 20:59:37 +0300517void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
518{
519 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
520
521 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
522 ETH_ALEN))
523 memset(mvmvif->uapsd_misbehaving_bssid, 0, ETH_ALEN);
524}
525
526static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
527 struct ieee80211_vif *vif)
528{
529 u8 *ap_sta_id = _data;
530 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
531
532 /* The ap_sta_id is not expected to change during current association
533 * so no explicit protection is needed
534 */
535 if (mvmvif->ap_sta_id == *ap_sta_id)
536 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
537 ETH_ALEN);
538}
539
540int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
541 struct iwl_rx_cmd_buffer *rxb,
542 struct iwl_device_cmd *cmd)
543{
544 struct iwl_rx_packet *pkt = rxb_addr(rxb);
545 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
546 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
547
548 ieee80211_iterate_active_interfaces_atomic(
549 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
550 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
551
552 return 0;
553}
554
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200555struct iwl_mvm_power_iterator {
556 struct iwl_mvm *mvm;
557 struct ieee80211_vif *bf_vif;
558};
559
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300560static void iwl_mvm_power_binding_iterator(void *_data, u8 *mac,
561 struct ieee80211_vif *vif)
562{
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200563 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
564 struct iwl_mvm_power_iterator *power_iterator = _data;
565 struct iwl_mvm *mvm = power_iterator->mvm;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300566 int ret;
567
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200568 ret = _iwl_mvm_power_mac_update_mode(mvm, vif);
569
570 if (mvmvif->bf_data.bf_enabled && !WARN_ON(power_iterator->bf_vif))
571 power_iterator->bf_vif = vif;
572
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300573 WARN_ONCE(ret, "Failed to update power parameters on a specific vif\n");
574}
575
576static void _iwl_mvm_power_update_binding(struct iwl_mvm *mvm,
Alexander Bondar92d85562013-10-23 11:50:34 +0200577 struct ieee80211_vif *vif,
578 bool assign)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300579{
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200580 bool ba_enable;
581 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
582 struct iwl_mvm_power_iterator power_it = {
583 .mvm = mvm,
584 };
585
586 lockdep_assert_held(&mvm->mutex);
587
Alexander Bondar92d85562013-10-23 11:50:34 +0200588 if (vif->type == NL80211_IFTYPE_MONITOR) {
589 int ret = _iwl_mvm_power_update_device(mvm, assign);
590 mvm->ps_prevented = assign;
591 WARN_ONCE(ret, "Failed to update power device state\n");
592 }
593
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300594 ieee80211_iterate_active_interfaces(mvm->hw,
595 IEEE80211_IFACE_ITER_NORMAL,
596 iwl_mvm_power_binding_iterator,
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200597 &power_it);
598
599 if (!power_it.bf_vif)
600 return;
601
602 vif = power_it.bf_vif;
603 mvmvif = iwl_mvm_vif_from_mac80211(vif);
604
605 ba_enable = !(iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM ||
606 mvm->ps_prevented || mvm->bound_vif_cnt > 1 ||
607 !vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif));
608
609 WARN_ON_ONCE(iwl_mvm_update_beacon_abort(mvm, power_it.bf_vif,
610 ba_enable));
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300611}
612
Alexander Bondarb571a692013-05-21 14:49:09 +0300613#ifdef CONFIG_IWLWIFI_DEBUGFS
Alexander Bondare811ada2013-03-10 15:29:44 +0200614static int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
615 struct ieee80211_vif *vif, char *buf,
616 int bufsz)
617{
618 struct iwl_mac_power_cmd cmd = {};
619 int pos = 0;
620
621 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
622
Alexander Bondar64b928c2013-09-03 14:18:03 +0300623 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD))
624 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n",
625 (cmd.flags &
626 cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ?
627 0 : 1);
Alexander Bondare811ada2013-03-10 15:29:44 +0200628 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
629 iwlmvm_mod_params.power_scheme);
630 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
631 le16_to_cpu(cmd.flags));
632 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
633 le16_to_cpu(cmd.keep_alive_seconds));
634
Alexander Bondar175a70b2013-04-14 20:59:37 +0300635 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
636 return pos;
637
638 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
639 (cmd.flags &
640 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
641 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
642 cmd.skip_dtim_periods);
643 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
644 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
645 le32_to_cpu(cmd.rx_data_timeout));
646 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
647 le32_to_cpu(cmd.tx_data_timeout));
Alexander Bondare811ada2013-03-10 15:29:44 +0200648 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300649 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
650 pos += scnprintf(buf+pos, bufsz-pos,
651 "lprx_rssi_threshold = %d\n",
652 cmd.lprx_rssi_threshold);
653
654 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
655 return pos;
656
657 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
658 le32_to_cpu(cmd.rx_data_timeout_uapsd));
659 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
660 le32_to_cpu(cmd.tx_data_timeout_uapsd));
661 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
662 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
663 cmd.uapsd_ac_flags);
664 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
665 cmd.uapsd_max_sp);
666 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
667 cmd.heavy_tx_thld_packets);
668 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
669 cmd.heavy_rx_thld_packets);
670 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
671 cmd.heavy_tx_thld_percentage);
672 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
673 cmd.heavy_rx_thld_percentage);
674 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
675 (cmd.flags &
676 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
677 1 : 0);
678
679 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
680 return pos;
681
682 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
683 cmd.snooze_interval);
684 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
685 cmd.snooze_window);
686
Alexander Bondare811ada2013-03-10 15:29:44 +0200687 return pos;
688}
689
Alexander Bondarb571a692013-05-21 14:49:09 +0300690void
691iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
692 struct iwl_beacon_filter_cmd *cmd)
693{
694 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
695 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
696
697 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300698 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300699 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
700 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300701 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300702 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300703 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
704 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
705 cmd->bf_temp_threshold =
706 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
707 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
708 cmd->bf_temp_fast_filter =
709 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
710 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
711 cmd->bf_temp_slow_filter =
712 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300713 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300714 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300715 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
716 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
717 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
718 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
719 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300720 cmd->ba_enable_beacon_abort =
721 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300722}
723#endif
724
Eliad Peller3dd37d02014-01-07 14:00:24 +0200725static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
726 struct ieee80211_vif *vif,
727 struct iwl_beacon_filter_cmd *cmd,
728 u32 cmd_flags,
729 bool d0i3)
Hila Gonen7df15b12012-12-12 11:16:19 +0200730{
731 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondar071d49902013-05-06 13:03:59 +0300732 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200733
734 if (mvmvif != mvm->bf_allowed_vif ||
735 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
736 return 0;
737
Eliad Peller3dd37d02014-01-07 14:00:24 +0200738 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd);
739 if (!d0i3)
740 iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
741 ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300742
Eliad Peller3dd37d02014-01-07 14:00:24 +0200743 /* don't change bf_enabled in case of temporary d0i3 configuration */
744 if (!ret && !d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300745 mvmvif->bf_data.bf_enabled = true;
Alexander Bondar071d49902013-05-06 13:03:59 +0300746
747 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200748}
749
Eliad Peller3dd37d02014-01-07 14:00:24 +0200750int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
751 struct ieee80211_vif *vif,
752 u32 flags)
753{
754 struct iwl_beacon_filter_cmd cmd = {
755 IWL_BF_CMD_CONFIG_DEFAULTS,
756 .bf_enable_beacon_filter = cpu_to_le32(1),
757 };
758
759 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
760}
761
Hila Gonen7df15b12012-12-12 11:16:19 +0200762int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +0200763 struct ieee80211_vif *vif,
764 u32 flags)
Hila Gonen7df15b12012-12-12 11:16:19 +0200765{
Alexander Bondar071d49902013-05-06 13:03:59 +0300766 struct iwl_beacon_filter_cmd cmd = {};
767 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
768 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200769
Hila Gonen5dca7c22013-07-16 11:15:35 +0300770 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) ||
771 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200772 return 0;
773
Eliad Peller3dd37d02014-01-07 14:00:24 +0200774 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300775
776 if (!ret)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300777 mvmvif->bf_data.bf_enabled = false;
Alexander Bondar071d49902013-05-06 13:03:59 +0300778
779 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200780}
Alexander Bondare811ada2013-03-10 15:29:44 +0200781
Eliad Peller3dd37d02014-01-07 14:00:24 +0200782int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
783 struct ieee80211_vif *vif,
784 bool enable, u32 flags)
785{
786 int ret;
787 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
788 struct iwl_mac_power_cmd cmd = {};
789
790 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
791 return 0;
792
793 if (!vif->bss_conf.assoc)
794 return 0;
795
796 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
797 if (enable) {
798 /* configure skip over dtim up to 300 msec */
799 int dtimper = mvm->hw->conf.ps_dtim_period ?: 1;
800 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
801
802 if (WARN_ON(!dtimper_msec))
803 return 0;
804
805 cmd.flags |=
806 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
807 cmd.skip_dtim_periods = 300 / dtimper_msec;
808 }
809 iwl_mvm_power_log(mvm, &cmd);
810 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
811 sizeof(cmd), &cmd);
812 if (ret)
813 return ret;
814
815 /* configure beacon filtering */
816 if (mvmvif != mvm->bf_allowed_vif)
817 return 0;
818
819 if (enable) {
820 struct iwl_beacon_filter_cmd cmd_bf = {
821 IWL_BF_CMD_CONFIG_D0I3,
822 .bf_enable_beacon_filter = cpu_to_le32(1),
823 };
824 ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
825 flags, true);
826 } else {
827 if (mvmvif->bf_data.bf_enabled)
828 ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
829 else
830 ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
831 }
832
833 return ret;
834}
835
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300836int iwl_mvm_update_beacon_filter(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +0200837 struct ieee80211_vif *vif,
838 bool force,
839 u32 flags)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300840{
841 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
842
Eliad Peller3dd37d02014-01-07 14:00:24 +0200843 if (mvmvif != mvm->bf_allowed_vif)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300844 return 0;
845
Eliad Peller3dd37d02014-01-07 14:00:24 +0200846 if (!mvmvif->bf_data.bf_enabled) {
847 /* disable beacon filtering explicitly if force is true */
848 if (force)
849 return iwl_mvm_disable_beacon_filter(mvm, vif, flags);
850 return 0;
851 }
852
853 return iwl_mvm_enable_beacon_filter(mvm, vif, flags);
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300854}
855
Alexander Bondare811ada2013-03-10 15:29:44 +0200856const struct iwl_mvm_power_ops pm_mac_ops = {
857 .power_update_mode = iwl_mvm_power_mac_update_mode,
Alexander Bondar64b928c2013-09-03 14:18:03 +0300858 .power_update_device_mode = iwl_mvm_power_update_device,
Alexander Bondare811ada2013-03-10 15:29:44 +0200859 .power_disable = iwl_mvm_power_mac_disable,
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300860 .power_update_binding = _iwl_mvm_power_update_binding,
Alexander Bondare811ada2013-03-10 15:29:44 +0200861#ifdef CONFIG_IWLWIFI_DEBUGFS
862 .power_dbgfs_read = iwl_mvm_power_mac_dbgfs_read,
863#endif
864};