iwlwifi: mvm: Add uAPSD misbehaving AP notification handling
[deliverable/linux.git] / drivers / net / wireless / iwlwifi / mvm / power.c
CommitLineData
8ca151b5
JB
1/******************************************************************************
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 *
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
9 *
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
410dc5aa 25 * in the file called COPYING.
8ca151b5
JB
26 *
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 *
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * 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>
67#include <linux/init.h>
68
69#include <net/mac80211.h>
70
71#include "iwl-debug.h"
72#include "mvm.h"
73#include "iwl-modparams.h"
74#include "fw-api-power.h"
75
76#define POWER_KEEP_ALIVE_PERIOD_SEC 25
77
e811ada7
AB
78int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
79 struct iwl_beacon_filter_cmd *cmd)
071d4990
AB
80{
81 int ret;
82
83 ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, CMD_SYNC,
84 sizeof(struct iwl_beacon_filter_cmd), cmd);
85
86 if (!ret) {
87 IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n",
5dca7c24 88 le32_to_cpu(cmd->ba_enable_beacon_abort));
071d4990 89 IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
5dca7c24 90 le32_to_cpu(cmd->ba_escape_timer));
071d4990 91 IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
5dca7c24 92 le32_to_cpu(cmd->bf_debug_flag));
071d4990 93 IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
5dca7c24 94 le32_to_cpu(cmd->bf_enable_beacon_filter));
071d4990 95 IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
5dca7c24 96 le32_to_cpu(cmd->bf_energy_delta));
071d4990 97 IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
5dca7c24 98 le32_to_cpu(cmd->bf_escape_timer));
071d4990 99 IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
5dca7c24 100 le32_to_cpu(cmd->bf_roaming_energy_delta));
071d4990 101 IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
5dca7c24
HG
102 le32_to_cpu(cmd->bf_roaming_state));
103 IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n",
104 le32_to_cpu(cmd->bf_temp_threshold));
105 IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n",
106 le32_to_cpu(cmd->bf_temp_fast_filter));
107 IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n",
108 le32_to_cpu(cmd->bf_temp_slow_filter));
071d4990
AB
109 }
110 return ret;
111}
112
a20fd398
AO
113static
114void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
115 struct ieee80211_vif *vif,
116 struct iwl_beacon_filter_cmd *cmd)
117{
118 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
119
120 if (vif->bss_conf.cqm_rssi_thold) {
121 cmd->bf_energy_delta =
122 cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
123 /* fw uses an absolute value for this */
124 cmd->bf_roaming_state =
125 cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
126 }
127 cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
128}
129
e811ada7
AB
130int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
131 struct ieee80211_vif *vif, bool enable)
071d4990
AB
132{
133 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
134 struct iwl_beacon_filter_cmd cmd = {
135 IWL_BF_CMD_CONFIG_DEFAULTS,
5dca7c24
HG
136 .bf_enable_beacon_filter = cpu_to_le32(1),
137 .ba_enable_beacon_abort = cpu_to_le32(enable),
071d4990
AB
138 };
139
a20fd398 140 if (!mvmvif->bf_data.bf_enabled)
071d4990
AB
141 return 0;
142
8434925f
AB
143 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
144 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
145
a20fd398
AO
146 mvmvif->bf_data.ba_enabled = enable;
147 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
b571a697 148 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
071d4990
AB
149 return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
150}
151
3f0b2b3e 152static void iwl_mvm_power_log(struct iwl_mvm *mvm,
e811ada7 153 struct iwl_mac_power_cmd *cmd)
3f0b2b3e
AB
154{
155 IWL_DEBUG_POWER(mvm,
e811ada7
AB
156 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
157 cmd->id_and_color, iwlmvm_mod_params.power_scheme,
3f0b2b3e 158 le16_to_cpu(cmd->flags));
e811ada7
AB
159 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
160 le16_to_cpu(cmd->keep_alive_seconds));
3f0b2b3e 161
e3c588ec
AB
162 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
163 IWL_DEBUG_POWER(mvm, "Disable power management\n");
164 return;
165 }
166
167 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
168 le32_to_cpu(cmd->rx_data_timeout));
169 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
170 le32_to_cpu(cmd->tx_data_timeout));
171 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
172 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
173 cmd->skip_dtim_periods);
174 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
175 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
176 cmd->lprx_rssi_threshold);
177 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
178 IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
179 IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
180 le32_to_cpu(cmd->rx_data_timeout_uapsd));
181 IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
182 le32_to_cpu(cmd->tx_data_timeout_uapsd));
183 IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
184 IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
185 IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
3f0b2b3e
AB
186 }
187}
188
175a70b7
AB
189static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm,
190 struct ieee80211_vif *vif,
191 struct iwl_mac_power_cmd *cmd)
192{
193 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
194 enum ieee80211_ac_numbers ac;
195 bool tid_found = false;
196
197 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
198 if (!mvmvif->queue_params[ac].uapsd)
199 continue;
200
201 if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
202 cmd->flags |=
203 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
204
205 cmd->uapsd_ac_flags |= BIT(ac);
206
207 /* QNDP TID - the highest TID with no admission control */
208 if (!tid_found && !mvmvif->queue_params[ac].acm) {
209 tid_found = true;
210 switch (ac) {
211 case IEEE80211_AC_VO:
212 cmd->qndp_tid = 6;
213 break;
214 case IEEE80211_AC_VI:
215 cmd->qndp_tid = 5;
216 break;
217 case IEEE80211_AC_BE:
218 cmd->qndp_tid = 0;
219 break;
220 case IEEE80211_AC_BK:
221 cmd->qndp_tid = 1;
222 break;
223 }
224 }
225 }
226
227 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
228 return;
229
230 cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK);
231
232 if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
233 BIT(IEEE80211_AC_VI) |
234 BIT(IEEE80211_AC_BE) |
235 BIT(IEEE80211_AC_BK))) {
236 cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
237 cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
238 cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
239 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
240 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
241 }
242
243 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
244
245 if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
246 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
247 cmd->rx_data_timeout_uapsd =
248 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
249 cmd->tx_data_timeout_uapsd =
250 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
251 } else {
252 cmd->rx_data_timeout_uapsd =
253 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
254 cmd->tx_data_timeout_uapsd =
255 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
256 }
257
258 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
259 cmd->heavy_tx_thld_packets =
260 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
261 cmd->heavy_rx_thld_packets =
262 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
263 } else {
264 cmd->heavy_tx_thld_packets =
265 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
266 cmd->heavy_rx_thld_packets =
267 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
268 }
269 cmd->heavy_tx_thld_percentage =
270 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
271 cmd->heavy_rx_thld_percentage =
272 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
273}
274
e811ada7
AB
275static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
276 struct ieee80211_vif *vif,
277 struct iwl_mac_power_cmd *cmd)
8ca151b5
JB
278{
279 struct ieee80211_hw *hw = mvm->hw;
8ca151b5
JB
280 struct ieee80211_chanctx_conf *chanctx_conf;
281 struct ieee80211_channel *chan;
282 int dtimper, dtimper_msec;
283 int keep_alive;
284 bool radar_detect = false;
b571a697
AB
285 struct iwl_mvm_vif *mvmvif __maybe_unused =
286 iwl_mvm_vif_from_mac80211(vif);
8ca151b5 287
e811ada7
AB
288 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
289 mvmvif->color));
290 dtimper = hw->conf.ps_dtim_period ?: 1;
291
e16cf7ec
AB
292 /*
293 * Regardless of power management state the driver must set
294 * keep alive period. FW will use it for sending keep alive NDPs
e811ada7
AB
295 * immediately after association. Check that keep alive period
296 * is at least 3 * DTIM
e16cf7ec 297 */
e811ada7
AB
298 dtimper_msec = dtimper * vif->bss_conf.beacon_int;
299 keep_alive = max_t(int, 3 * dtimper_msec,
300 MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
301 keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
302 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
e16cf7ec 303
ade50652 304 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
8ca151b5
JB
305 return;
306
9a613048
AB
307 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
308
b571a697
AB
309#ifdef CONFIG_IWLWIFI_DEBUGFS
310 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
311 mvmvif->dbgfs_pm.disable_power_off)
312 cmd->flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
313#endif
9a613048
AB
314 if (!vif->bss_conf.ps)
315 return;
316
317 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
8ca151b5 318
bd4ace2a
AB
319 if (vif->bss_conf.beacon_rate &&
320 (vif->bss_conf.beacon_rate->bitrate == 10 ||
321 vif->bss_conf.beacon_rate->bitrate == 60)) {
322 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
e811ada7 323 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
bd4ace2a
AB
324 }
325
8ca151b5
JB
326 /* Check if radar detection is required on current channel */
327 rcu_read_lock();
328 chanctx_conf = rcu_dereference(vif->chanctx_conf);
329 WARN_ON(!chanctx_conf);
330 if (chanctx_conf) {
331 chan = chanctx_conf->def.chan;
332 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
333 }
334 rcu_read_unlock();
335
336 /* Check skip over DTIM conditions */
337 if (!radar_detect && (dtimper <= 10) &&
ee1e8422
AB
338 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
339 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
f4a3e2fe 340 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
e811ada7 341 cmd->skip_dtim_periods = 3;
5b1dbfc3 342 }
8ca151b5 343
ee1e8422 344 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
99545924
JB
345 cmd->rx_data_timeout =
346 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
347 cmd->tx_data_timeout =
348 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
ee1e8422 349 } else {
99545924
JB
350 cmd->rx_data_timeout =
351 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
352 cmd->tx_data_timeout =
353 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
ee1e8422 354 }
b571a697 355
175a70b7
AB
356 if (memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
357 ETH_ALEN))
358 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
e3c588ec 359
b571a697
AB
360#ifdef CONFIG_IWLWIFI_DEBUGFS
361 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
e811ada7
AB
362 cmd->keep_alive_seconds =
363 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
b571a697
AB
364 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)
e811ada7 379 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
bd4ace2a
AB
380 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)
e811ada7 387 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
89716344
AB
388 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 }
b571a697 396#endif /* CONFIG_IWLWIFI_DEBUGFS */
8ca151b5
JB
397}
398
e811ada7
AB
399static int iwl_mvm_power_mac_update_mode(struct iwl_mvm *mvm,
400 struct ieee80211_vif *vif)
8ca151b5 401{
071d4990
AB
402 int ret;
403 bool ba_enable;
e811ada7 404 struct iwl_mac_power_cmd cmd = {};
8ca151b5 405
8ca151b5
JB
406 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
407 return 0;
408
4bf881f5
AB
409 /*
410 * TODO: The following vif_count verification is temporary condition.
411 * Avoid power mode update if more than one interface is currently
412 * active. Remove this condition when FW will support power management
413 * on multiple MACs.
414 */
415 IWL_DEBUG_POWER(mvm, "Currently %d interfaces active\n",
416 mvm->vif_count);
417 if (mvm->vif_count > 1)
418 return 0;
419
f4a3e2fe 420 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
3f0b2b3e 421 iwl_mvm_power_log(mvm, &cmd);
8ca151b5 422
e811ada7 423 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC,
071d4990
AB
424 sizeof(cmd), &cmd);
425 if (ret)
426 return ret;
427
428 ba_enable = !!(cmd.flags &
429 cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK));
430
431 return iwl_mvm_update_beacon_abort(mvm, vif, ba_enable);
8ca151b5
JB
432}
433
e811ada7
AB
434static int iwl_mvm_power_mac_disable(struct iwl_mvm *mvm,
435 struct ieee80211_vif *vif)
8ca151b5 436{
e811ada7 437 struct iwl_mac_power_cmd cmd = {};
b571a697
AB
438 struct iwl_mvm_vif *mvmvif __maybe_unused =
439 iwl_mvm_vif_from_mac80211(vif);
8ca151b5 440
8ca151b5
JB
441 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
442 return 0;
443
e811ada7
AB
444 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
445 mvmvif->color));
446
ade50652 447 if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM)
9a613048
AB
448 cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
449
b571a697
AB
450#ifdef CONFIG_IWLWIFI_DEBUGFS
451 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_DISABLE_POWER_OFF &&
452 mvmvif->dbgfs_pm.disable_power_off)
453 cmd.flags &= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK);
454#endif
3f0b2b3e 455 iwl_mvm_power_log(mvm, &cmd);
8ca151b5 456
e811ada7 457 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_ASYNC,
8ca151b5
JB
458 sizeof(cmd), &cmd);
459}
7df15b1e 460
64b928c4
AB
461static int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
462{
463 struct iwl_device_power_cmd cmd = {
464 .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK),
465 };
466
467 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD))
468 return 0;
469
470 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
471 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK);
472
473#ifdef CONFIG_IWLWIFI_DEBUGFS
474 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
475 mvm->disable_power_off)
476 cmd.flags &=
477 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
478#endif
479 IWL_DEBUG_POWER(mvm,
480 "Sending device power command with flags = 0x%X\n",
481 cmd.flags);
482
483 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_SYNC, sizeof(cmd),
484 &cmd);
485}
486
175a70b7
AB
487void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
488{
489 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
490
491 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
492 ETH_ALEN))
493 memset(mvmvif->uapsd_misbehaving_bssid, 0, ETH_ALEN);
494}
495
496static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
497 struct ieee80211_vif *vif)
498{
499 u8 *ap_sta_id = _data;
500 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
501
502 /* The ap_sta_id is not expected to change during current association
503 * so no explicit protection is needed
504 */
505 if (mvmvif->ap_sta_id == *ap_sta_id)
506 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
507 ETH_ALEN);
508}
509
510int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
511 struct iwl_rx_cmd_buffer *rxb,
512 struct iwl_device_cmd *cmd)
513{
514 struct iwl_rx_packet *pkt = rxb_addr(rxb);
515 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
516 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
517
518 ieee80211_iterate_active_interfaces_atomic(
519 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
520 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
521
522 return 0;
523}
524
b571a697 525#ifdef CONFIG_IWLWIFI_DEBUGFS
e811ada7
AB
526static int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
527 struct ieee80211_vif *vif, char *buf,
528 int bufsz)
529{
530 struct iwl_mac_power_cmd cmd = {};
531 int pos = 0;
532
533 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
534
64b928c4
AB
535 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_DEVICE_PS_CMD))
536 pos += scnprintf(buf+pos, bufsz-pos, "disable_power_off = %d\n",
537 (cmd.flags &
538 cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK)) ?
539 0 : 1);
e811ada7
AB
540 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
541 iwlmvm_mod_params.power_scheme);
542 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
543 le16_to_cpu(cmd.flags));
544 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
545 le16_to_cpu(cmd.keep_alive_seconds));
546
175a70b7
AB
547 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
548 return pos;
549
550 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
551 (cmd.flags &
552 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
553 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
554 cmd.skip_dtim_periods);
555 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
556 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
557 le32_to_cpu(cmd.rx_data_timeout));
558 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
559 le32_to_cpu(cmd.tx_data_timeout));
e811ada7 560 }
175a70b7
AB
561 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
562 pos += scnprintf(buf+pos, bufsz-pos,
563 "lprx_rssi_threshold = %d\n",
564 cmd.lprx_rssi_threshold);
565
566 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
567 return pos;
568
569 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
570 le32_to_cpu(cmd.rx_data_timeout_uapsd));
571 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
572 le32_to_cpu(cmd.tx_data_timeout_uapsd));
573 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
574 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
575 cmd.uapsd_ac_flags);
576 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
577 cmd.uapsd_max_sp);
578 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
579 cmd.heavy_tx_thld_packets);
580 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
581 cmd.heavy_rx_thld_packets);
582 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
583 cmd.heavy_tx_thld_percentage);
584 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
585 cmd.heavy_rx_thld_percentage);
586 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
587 (cmd.flags &
588 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
589 1 : 0);
590
591 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
592 return pos;
593
594 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
595 cmd.snooze_interval);
596 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
597 cmd.snooze_window);
598
e811ada7
AB
599 return pos;
600}
601
b571a697
AB
602void
603iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
604 struct iwl_beacon_filter_cmd *cmd)
605{
606 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
607 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
608
609 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
5dca7c24 610 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
b571a697
AB
611 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
612 cmd->bf_roaming_energy_delta =
5dca7c24 613 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
b571a697 614 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
5dca7c24
HG
615 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
616 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
617 cmd->bf_temp_threshold =
618 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
619 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
620 cmd->bf_temp_fast_filter =
621 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
622 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
623 cmd->bf_temp_slow_filter =
624 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
b571a697 625 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
5dca7c24 626 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
b571a697
AB
627 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
628 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
629 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
630 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
631 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
5dca7c24
HG
632 cmd->ba_enable_beacon_abort =
633 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
b571a697
AB
634}
635#endif
636
7df15b1e
HG
637int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
638 struct ieee80211_vif *vif)
639{
640 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
641 struct iwl_beacon_filter_cmd cmd = {
071d4990 642 IWL_BF_CMD_CONFIG_DEFAULTS,
5dca7c24 643 .bf_enable_beacon_filter = cpu_to_le32(1),
7df15b1e 644 };
071d4990 645 int ret;
7df15b1e
HG
646
647 if (mvmvif != mvm->bf_allowed_vif ||
648 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
649 return 0;
650
a20fd398 651 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd);
b571a697 652 iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd);
071d4990
AB
653 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
654
655 if (!ret)
a20fd398 656 mvmvif->bf_data.bf_enabled = true;
071d4990
AB
657
658 return ret;
7df15b1e
HG
659}
660
661int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
662 struct ieee80211_vif *vif)
663{
071d4990
AB
664 struct iwl_beacon_filter_cmd cmd = {};
665 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
666 int ret;
7df15b1e 667
5dca7c24
HG
668 if (!(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BF_UPDATED) ||
669 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
7df15b1e
HG
670 return 0;
671
071d4990
AB
672 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd);
673
674 if (!ret)
a20fd398 675 mvmvif->bf_data.bf_enabled = false;
071d4990
AB
676
677 return ret;
7df15b1e 678}
e811ada7 679
a20fd398
AO
680int iwl_mvm_update_beacon_filter(struct iwl_mvm *mvm,
681 struct ieee80211_vif *vif)
682{
683 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
684
685 if (!mvmvif->bf_data.bf_enabled)
686 return 0;
687
688 return iwl_mvm_enable_beacon_filter(mvm, vif);
689}
690
e811ada7
AB
691const struct iwl_mvm_power_ops pm_mac_ops = {
692 .power_update_mode = iwl_mvm_power_mac_update_mode,
64b928c4 693 .power_update_device_mode = iwl_mvm_power_update_device,
e811ada7
AB
694 .power_disable = iwl_mvm_power_mac_disable,
695#ifdef CONFIG_IWLWIFI_DEBUGFS
696 .power_dbgfs_read = iwl_mvm_power_mac_dbgfs_read,
697#endif
698};
This page took 0.099988 seconds and 5 git commands to generate.