blob: 6b636eab33391cbec4957180efe2e74d2ad07388 [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
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200301 if (mvm->ps_disabled)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100302 return;
303
Alexander Bondar9a613042013-03-05 12:54:00 +0200304 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
305
Alexander Bondarb571a692013-05-21 14:49:09 +0300306#ifdef CONFIG_IWLWIFI_DEBUGFS
307 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
308 mvmvif->dbgfs_pm.disable_power_off)
309 cmd->flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
310#endif
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200311 if (!vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif) ||
312 mvm->pm_disabled)
Alexander Bondar9a613042013-03-05 12:54:00 +0200313 return;
314
315 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100316
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200317 if (vif->bss_conf.beacon_rate &&
318 (vif->bss_conf.beacon_rate->bitrate == 10 ||
319 vif->bss_conf.beacon_rate->bitrate == 60)) {
320 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200321 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200322 }
323
Johannes Berg8ca151b2013-01-24 14:25:36 +0100324 /* Check if radar detection is required on current channel */
325 rcu_read_lock();
326 chanctx_conf = rcu_dereference(vif->chanctx_conf);
327 WARN_ON(!chanctx_conf);
328 if (chanctx_conf) {
329 chan = chanctx_conf->def.chan;
330 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
331 }
332 rcu_read_unlock();
333
334 /* Check skip over DTIM conditions */
335 if (!radar_detect && (dtimper <= 10) &&
Alexander Bondaree1e8422013-04-23 13:52:10 +0300336 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
337 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200338 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200339 cmd->skip_dtim_periods = 3;
Alexander Bondar5b1dbfc2013-04-23 13:32:35 +0300340 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100341
Alexander Bondaree1e8422013-04-23 13:52:10 +0300342 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
Johannes Berg99545922013-06-14 13:36:21 +0200343 cmd->rx_data_timeout =
344 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
345 cmd->tx_data_timeout =
346 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300347 } else {
Johannes Berg99545922013-06-14 13:36:21 +0200348 cmd->rx_data_timeout =
349 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
350 cmd->tx_data_timeout =
351 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300352 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300353
Alexander Bondar51498cf2013-09-02 17:10:14 +0300354 if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
355 ETH_ALEN))
356 allow_uapsd = false;
Alexander Bondar75209672013-11-12 14:47:59 +0200357
358 if (vif->p2p &&
359 !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD))
360 allow_uapsd = false;
Alexander Bondar51498cf2013-09-02 17:10:14 +0300361 /*
362 * Avoid using uAPSD if P2P client is associated to GO that uses
363 * opportunistic power save. This is due to current FW limitation.
364 */
365 if (vif->p2p &&
366 vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
367 IEEE80211_P2P_OPPPS_ENABLE_BIT)
368 allow_uapsd = false;
369
370 if (allow_uapsd)
Alexander Bondar175a70b2013-04-14 20:59:37 +0300371 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300372
Alexander Bondarb571a692013-05-21 14:49:09 +0300373#ifdef CONFIG_IWLWIFI_DEBUGFS
374 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200375 cmd->keep_alive_seconds =
376 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300377 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
378 if (mvmvif->dbgfs_pm.skip_over_dtim)
379 cmd->flags |=
380 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
381 else
382 cmd->flags &=
383 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
384 }
385 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
386 cmd->rx_data_timeout =
387 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
388 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
389 cmd->tx_data_timeout =
390 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
391 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200392 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200393 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
394 if (mvmvif->dbgfs_pm.lprx_ena)
395 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
396 else
397 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
398 }
399 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200400 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondar89716342013-08-04 17:52:23 +0300401 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
402 if (mvmvif->dbgfs_pm.snooze_ena)
403 cmd->flags |=
404 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
405 else
406 cmd->flags &=
407 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
408 }
Alexander Bondare45a9412013-12-04 10:13:24 +0200409 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
410 u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
411 if (mvmvif->dbgfs_pm.uapsd_misbehaving)
412 cmd->flags |= cpu_to_le16(flag);
413 else
414 cmd->flags &= cpu_to_le16(flag);
415 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300416#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100417}
418
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200419static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200420 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100421{
Alexander Bondare811ada2013-03-10 15:29:44 +0200422 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100423
Alexander Bondar51498cf2013-09-02 17:10:14 +0300424 if (vif->type != NL80211_IFTYPE_STATION)
425 return 0;
426
427 if (vif->p2p &&
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200428 !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100429 return 0;
430
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200431 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200432 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200433#ifdef CONFIG_IWLWIFI_DEBUGFS
434 memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
435#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100436
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200437 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC,
438 sizeof(cmd), &cmd);
439}
440
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200441int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300442{
443 struct iwl_device_power_cmd cmd = {
444 .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK),
445 };
446
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200447 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT))
448 return 0;
449
Alexander Bondar64b928c2013-09-03 14:18:03 +0300450 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD))
451 return 0;
452
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200453 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
454 mvm->ps_disabled = true;
455
456 if (mvm->ps_disabled)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300457 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK);
458
459#ifdef CONFIG_IWLWIFI_DEBUGFS
460 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
461 mvm->disable_power_off)
462 cmd.flags &=
463 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
464#endif
465 IWL_DEBUG_POWER(mvm,
466 "Sending device power command with flags = 0x%X\n",
467 cmd.flags);
468
469 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_SYNC, sizeof(cmd),
470 &cmd);
471}
472
Alexander Bondar175a70b2013-04-14 20:59:37 +0300473void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
474{
475 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
476
477 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
478 ETH_ALEN))
479 memset(mvmvif->uapsd_misbehaving_bssid, 0, ETH_ALEN);
480}
481
482static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
483 struct ieee80211_vif *vif)
484{
485 u8 *ap_sta_id = _data;
486 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
487
488 /* The ap_sta_id is not expected to change during current association
489 * so no explicit protection is needed
490 */
491 if (mvmvif->ap_sta_id == *ap_sta_id)
492 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
493 ETH_ALEN);
494}
495
496int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
497 struct iwl_rx_cmd_buffer *rxb,
498 struct iwl_device_cmd *cmd)
499{
500 struct iwl_rx_packet *pkt = rxb_addr(rxb);
501 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
502 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
503
504 ieee80211_iterate_active_interfaces_atomic(
505 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
506 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
507
508 return 0;
509}
510
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200511struct iwl_power_constraint {
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200512 struct ieee80211_vif *bf_vif;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200513 struct ieee80211_vif *bss_vif;
Avri Altman8ea0c682014-02-20 13:28:57 +0200514 struct ieee80211_vif *p2p_vif;
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200515 u16 bss_phyctx_id;
516 u16 p2p_phyctx_id;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200517 bool pm_disabled;
518 bool ps_disabled;
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200519 struct iwl_mvm *mvm;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200520};
521
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200522static void iwl_mvm_power_iterator(void *_data, u8 *mac,
523 struct ieee80211_vif *vif)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300524{
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200525 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200526 struct iwl_power_constraint *power_iterator = _data;
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200527 struct iwl_mvm *mvm = power_iterator->mvm;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300528
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200529 switch (ieee80211_vif_type_p2p(vif)) {
530 case NL80211_IFTYPE_P2P_DEVICE:
531 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200532
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200533 case NL80211_IFTYPE_P2P_GO:
534 case NL80211_IFTYPE_AP:
535 /* no BSS power mgmt if we have an active AP */
536 if (mvmvif->ap_ibss_active)
537 power_iterator->pm_disabled = true;
538 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200539
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200540 case NL80211_IFTYPE_MONITOR:
541 /* no BSS power mgmt and no device power save */
542 power_iterator->pm_disabled = true;
543 power_iterator->ps_disabled = true;
544 break;
545
546 case NL80211_IFTYPE_P2P_CLIENT:
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200547 if (mvmvif->phy_ctxt)
548 power_iterator->p2p_phyctx_id = mvmvif->phy_ctxt->id;
549
Avri Altman8ea0c682014-02-20 13:28:57 +0200550 /* we should have only one P2P vif */
551 WARN_ON(power_iterator->p2p_vif);
552 power_iterator->p2p_vif = vif;
553
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200554 IWL_DEBUG_POWER(mvm, "p2p: p2p_id=%d, bss_id=%d\n",
555 power_iterator->p2p_phyctx_id,
556 power_iterator->bss_phyctx_id);
557 if (!(mvm->fw->ucode_capa.flags &
558 IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) {
559 /* no BSS power mgmt if we have a P2P client*/
560 power_iterator->pm_disabled = true;
561 } else if (power_iterator->p2p_phyctx_id < MAX_PHYS &&
562 power_iterator->bss_phyctx_id < MAX_PHYS &&
563 power_iterator->p2p_phyctx_id ==
564 power_iterator->bss_phyctx_id) {
565 power_iterator->pm_disabled = true;
566 }
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200567 break;
568
569 case NL80211_IFTYPE_STATION:
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200570 if (mvmvif->phy_ctxt)
571 power_iterator->bss_phyctx_id = mvmvif->phy_ctxt->id;
572
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200573 /* we should have only one BSS vif */
574 WARN_ON(power_iterator->bss_vif);
575 power_iterator->bss_vif = vif;
576
577 if (mvmvif->bf_data.bf_enabled &&
578 !WARN_ON(power_iterator->bf_vif))
579 power_iterator->bf_vif = vif;
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200580
581 IWL_DEBUG_POWER(mvm, "bss: p2p_id=%d, bss_id=%d\n",
582 power_iterator->p2p_phyctx_id,
583 power_iterator->bss_phyctx_id);
584 if (mvm->fw->ucode_capa.flags &
585 IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM &&
586 (power_iterator->p2p_phyctx_id < MAX_PHYS &&
587 power_iterator->bss_phyctx_id < MAX_PHYS &&
588 power_iterator->p2p_phyctx_id ==
589 power_iterator->bss_phyctx_id))
590 power_iterator->pm_disabled = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200591 break;
592
593 default:
594 break;
595 }
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300596}
597
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200598static void
599iwl_mvm_power_get_global_constraint(struct iwl_mvm *mvm,
600 struct iwl_power_constraint *constraint)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300601{
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200602 lockdep_assert_held(&mvm->mutex);
603
604 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) {
605 constraint->pm_disabled = true;
606 constraint->ps_disabled = true;
607 }
608
609 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
610 IEEE80211_IFACE_ITER_NORMAL,
611 iwl_mvm_power_iterator, constraint);
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200612}
613
614int iwl_mvm_power_update_mac(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
615{
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200616 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200617 struct iwl_power_constraint constraint = {
618 .p2p_phyctx_id = MAX_PHYS,
619 .bss_phyctx_id = MAX_PHYS,
620 .mvm = mvm,
621 };
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200622 bool ba_enable;
623 int ret;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200624
625 lockdep_assert_held(&mvm->mutex);
626
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200627 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT))
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200628 return 0;
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200629
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200630 iwl_mvm_power_get_global_constraint(mvm, &constraint);
631 mvm->ps_disabled = constraint.ps_disabled;
632 mvm->pm_disabled = constraint.pm_disabled;
633
634 /* don't update device power state unless we add / remove monitor */
Alexander Bondar92d85562013-10-23 11:50:34 +0200635 if (vif->type == NL80211_IFTYPE_MONITOR) {
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200636 ret = iwl_mvm_power_update_device(mvm);
637 if (ret)
638 return ret;
Alexander Bondar92d85562013-10-23 11:50:34 +0200639 }
640
Avri Altman8ea0c682014-02-20 13:28:57 +0200641 if (constraint.bss_vif) {
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200642 ret = iwl_mvm_power_send_cmd(mvm, constraint.bss_vif);
643 if (ret)
644 return ret;
645 }
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200646
Avri Altman8ea0c682014-02-20 13:28:57 +0200647 if (constraint.p2p_vif) {
648 ret = iwl_mvm_power_send_cmd(mvm, constraint.p2p_vif);
649 if (ret)
650 return ret;
651 }
652
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200653 if (!constraint.bf_vif)
654 return 0;
655
656 vif = constraint.bf_vif;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200657 mvmvif = iwl_mvm_vif_from_mac80211(vif);
658
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200659 ba_enable = !(constraint.pm_disabled || constraint.ps_disabled ||
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200660 !vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif));
661
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200662 return iwl_mvm_update_beacon_abort(mvm, constraint.bf_vif, ba_enable);
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300663}
664
Alexander Bondarb571a692013-05-21 14:49:09 +0300665#ifdef CONFIG_IWLWIFI_DEBUGFS
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200666int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
667 struct ieee80211_vif *vif, char *buf,
668 int bufsz)
Alexander Bondare811ada2013-03-10 15:29:44 +0200669{
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200670 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondare811ada2013-03-10 15:29:44 +0200671 struct iwl_mac_power_cmd cmd = {};
672 int pos = 0;
673
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200674 if (WARN_ON(!(mvm->fw->ucode_capa.flags &
675 IWL_UCODE_TLV_FLAGS_PM_CMD_SUPPORT)))
676 return 0;
677
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200678 mutex_lock(&mvm->mutex);
679 memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
680 mutex_unlock(&mvm->mutex);
Alexander Bondare811ada2013-03-10 15:29:44 +0200681
Alexander Bondar64b928c2013-09-03 14:18:03 +0300682 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD))
683 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n",
684 (cmd.flags &
685 cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ?
686 0 : 1);
Alexander Bondare811ada2013-03-10 15:29:44 +0200687 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
688 iwlmvm_mod_params.power_scheme);
689 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
690 le16_to_cpu(cmd.flags));
691 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
692 le16_to_cpu(cmd.keep_alive_seconds));
693
Alexander Bondar175a70b2013-04-14 20:59:37 +0300694 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
695 return pos;
696
697 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
698 (cmd.flags &
699 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
700 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
701 cmd.skip_dtim_periods);
702 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
703 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
704 le32_to_cpu(cmd.rx_data_timeout));
705 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
706 le32_to_cpu(cmd.tx_data_timeout));
Alexander Bondare811ada2013-03-10 15:29:44 +0200707 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300708 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
709 pos += scnprintf(buf+pos, bufsz-pos,
710 "lprx_rssi_threshold = %d\n",
711 cmd.lprx_rssi_threshold);
712
713 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
714 return pos;
715
716 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
717 le32_to_cpu(cmd.rx_data_timeout_uapsd));
718 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
719 le32_to_cpu(cmd.tx_data_timeout_uapsd));
720 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
721 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
722 cmd.uapsd_ac_flags);
723 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
724 cmd.uapsd_max_sp);
725 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
726 cmd.heavy_tx_thld_packets);
727 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
728 cmd.heavy_rx_thld_packets);
729 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
730 cmd.heavy_tx_thld_percentage);
731 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
732 cmd.heavy_rx_thld_percentage);
733 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
734 (cmd.flags &
735 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
736 1 : 0);
737
738 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
739 return pos;
740
741 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
742 cmd.snooze_interval);
743 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
744 cmd.snooze_window);
745
Alexander Bondare811ada2013-03-10 15:29:44 +0200746 return pos;
747}
748
Alexander Bondarb571a692013-05-21 14:49:09 +0300749void
750iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
751 struct iwl_beacon_filter_cmd *cmd)
752{
753 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
754 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
755
756 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300757 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300758 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
759 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300760 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300761 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300762 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
763 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
764 cmd->bf_temp_threshold =
765 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
766 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
767 cmd->bf_temp_fast_filter =
768 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
769 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
770 cmd->bf_temp_slow_filter =
771 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300772 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300773 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300774 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
775 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
776 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
777 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
778 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300779 cmd->ba_enable_beacon_abort =
780 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300781}
782#endif
783
Eliad Peller3dd37d02014-01-07 14:00:24 +0200784static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
785 struct ieee80211_vif *vif,
786 struct iwl_beacon_filter_cmd *cmd,
787 u32 cmd_flags,
788 bool d0i3)
Hila Gonen7df15b12012-12-12 11:16:19 +0200789{
790 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondar071d49902013-05-06 13:03:59 +0300791 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200792
793 if (mvmvif != mvm->bf_allowed_vif ||
794 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
795 return 0;
796
Eliad Peller3dd37d02014-01-07 14:00:24 +0200797 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd);
798 if (!d0i3)
799 iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
800 ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300801
Eliad Peller3dd37d02014-01-07 14:00:24 +0200802 /* don't change bf_enabled in case of temporary d0i3 configuration */
803 if (!ret && !d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300804 mvmvif->bf_data.bf_enabled = true;
Alexander Bondar071d49902013-05-06 13:03:59 +0300805
806 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200807}
808
Eliad Peller3dd37d02014-01-07 14:00:24 +0200809int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
810 struct ieee80211_vif *vif,
811 u32 flags)
812{
813 struct iwl_beacon_filter_cmd cmd = {
814 IWL_BF_CMD_CONFIG_DEFAULTS,
815 .bf_enable_beacon_filter = cpu_to_le32(1),
816 };
817
818 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
819}
820
Hila Gonen7df15b12012-12-12 11:16:19 +0200821int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +0200822 struct ieee80211_vif *vif,
823 u32 flags)
Hila Gonen7df15b12012-12-12 11:16:19 +0200824{
Alexander Bondar071d49902013-05-06 13:03:59 +0300825 struct iwl_beacon_filter_cmd cmd = {};
826 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
827 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200828
Hila Gonen5dca7c22013-07-16 11:15:35 +0300829 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) ||
830 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200831 return 0;
832
Eliad Peller3dd37d02014-01-07 14:00:24 +0200833 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300834
835 if (!ret)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300836 mvmvif->bf_data.bf_enabled = false;
Alexander Bondar071d49902013-05-06 13:03:59 +0300837
838 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200839}
Alexander Bondare811ada2013-03-10 15:29:44 +0200840
Eliad Peller3dd37d02014-01-07 14:00:24 +0200841int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
842 struct ieee80211_vif *vif,
843 bool enable, u32 flags)
844{
845 int ret;
846 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
847 struct iwl_mac_power_cmd cmd = {};
848
849 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
850 return 0;
851
852 if (!vif->bss_conf.assoc)
853 return 0;
854
855 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
856 if (enable) {
857 /* configure skip over dtim up to 300 msec */
858 int dtimper = mvm->hw->conf.ps_dtim_period ?: 1;
859 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
860
861 if (WARN_ON(!dtimper_msec))
862 return 0;
863
864 cmd.flags |=
865 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
866 cmd.skip_dtim_periods = 300 / dtimper_msec;
867 }
868 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200869#ifdef CONFIG_IWLWIFI_DEBUGFS
870 memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
871#endif
Eliad Peller3dd37d02014-01-07 14:00:24 +0200872 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
873 sizeof(cmd), &cmd);
874 if (ret)
875 return ret;
876
877 /* configure beacon filtering */
878 if (mvmvif != mvm->bf_allowed_vif)
879 return 0;
880
881 if (enable) {
882 struct iwl_beacon_filter_cmd cmd_bf = {
883 IWL_BF_CMD_CONFIG_D0I3,
884 .bf_enable_beacon_filter = cpu_to_le32(1),
885 };
886 ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
887 flags, true);
888 } else {
889 if (mvmvif->bf_data.bf_enabled)
890 ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
891 else
892 ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
893 }
894
895 return ret;
896}
897
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300898int iwl_mvm_update_beacon_filter(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +0200899 struct ieee80211_vif *vif,
900 bool force,
901 u32 flags)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300902{
903 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
904
Eliad Peller3dd37d02014-01-07 14:00:24 +0200905 if (mvmvif != mvm->bf_allowed_vif)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300906 return 0;
907
Eliad Peller3dd37d02014-01-07 14:00:24 +0200908 if (!mvmvif->bf_data.bf_enabled) {
909 /* disable beacon filtering explicitly if force is true */
910 if (force)
911 return iwl_mvm_disable_beacon_filter(mvm, vif, flags);
912 return 0;
913 }
914
915 return iwl_mvm_enable_beacon_filter(mvm, vif, flags);
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300916}
917
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200918int iwl_power_legacy_set_cam_mode(struct iwl_mvm *mvm)
919{
920 struct iwl_powertable_cmd cmd = {
921 .keep_alive_seconds = POWER_KEEP_ALIVE_PERIOD_SEC,
922 };
923
924 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_SYNC,
925 sizeof(cmd), &cmd);
926}