blob: 754f2b3eae649f3e87ccc6062ac399d2785333db [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +01009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020033 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8ca151b2013-01-24 14:25:36 +010034 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64#include <linux/kernel.h>
65#include <linux/module.h>
66#include <linux/slab.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010067
68#include <net/mac80211.h>
69
70#include "iwl-debug.h"
71#include "mvm.h"
72#include "iwl-modparams.h"
73#include "fw-api-power.h"
74
75#define POWER_KEEP_ALIVE_PERIOD_SEC 25
76
Emmanuel Grumbachd623d242014-01-26 12:58:24 +020077static
Alexander Bondare811ada2013-03-10 15:29:44 +020078int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +020079 struct iwl_beacon_filter_cmd *cmd,
80 u32 flags)
Alexander Bondar071d49902013-05-06 13:03:59 +030081{
Emmanuel Grumbachd623d242014-01-26 12:58:24 +020082 IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n",
83 le32_to_cpu(cmd->ba_enable_beacon_abort));
84 IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
85 le32_to_cpu(cmd->ba_escape_timer));
86 IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
87 le32_to_cpu(cmd->bf_debug_flag));
88 IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
89 le32_to_cpu(cmd->bf_enable_beacon_filter));
90 IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
91 le32_to_cpu(cmd->bf_energy_delta));
92 IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
93 le32_to_cpu(cmd->bf_escape_timer));
94 IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
95 le32_to_cpu(cmd->bf_roaming_energy_delta));
96 IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
97 le32_to_cpu(cmd->bf_roaming_state));
98 IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n",
99 le32_to_cpu(cmd->bf_temp_threshold));
100 IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n",
101 le32_to_cpu(cmd->bf_temp_fast_filter));
102 IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n",
103 le32_to_cpu(cmd->bf_temp_slow_filter));
Alexander Bondar071d49902013-05-06 13:03:59 +0300104
Emmanuel Grumbachd623d242014-01-26 12:58:24 +0200105 return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags,
106 sizeof(struct iwl_beacon_filter_cmd), cmd);
Alexander Bondar071d49902013-05-06 13:03:59 +0300107}
108
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300109static
110void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
111 struct ieee80211_vif *vif,
112 struct iwl_beacon_filter_cmd *cmd)
113{
114 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
115
116 if (vif->bss_conf.cqm_rssi_thold) {
117 cmd->bf_energy_delta =
118 cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
119 /* fw uses an absolute value for this */
120 cmd->bf_roaming_state =
121 cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
122 }
123 cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
124}
125
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200126static void iwl_mvm_power_log(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200127 struct iwl_mac_power_cmd *cmd)
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200128{
129 IWL_DEBUG_POWER(mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200130 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
131 cmd->id_and_color, iwlmvm_mod_params.power_scheme,
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200132 le16_to_cpu(cmd->flags));
Alexander Bondare811ada2013-03-10 15:29:44 +0200133 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
134 le16_to_cpu(cmd->keep_alive_seconds));
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200135
Alexander Bondare3c588e2013-04-07 14:08:59 +0300136 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
137 IWL_DEBUG_POWER(mvm, "Disable power management\n");
138 return;
139 }
140
141 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
142 le32_to_cpu(cmd->rx_data_timeout));
143 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
144 le32_to_cpu(cmd->tx_data_timeout));
145 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
146 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
147 cmd->skip_dtim_periods);
148 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
149 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
150 cmd->lprx_rssi_threshold);
151 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
152 IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
153 IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
154 le32_to_cpu(cmd->rx_data_timeout_uapsd));
155 IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
156 le32_to_cpu(cmd->tx_data_timeout_uapsd));
157 IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
158 IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
159 IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200160 }
161}
162
Alexander Bondar175a70b2013-04-14 20:59:37 +0300163static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm,
164 struct ieee80211_vif *vif,
165 struct iwl_mac_power_cmd *cmd)
166{
167 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
168 enum ieee80211_ac_numbers ac;
169 bool tid_found = false;
170
171 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
172 if (!mvmvif->queue_params[ac].uapsd)
173 continue;
174
175 if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
176 cmd->flags |=
177 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
178
179 cmd->uapsd_ac_flags |= BIT(ac);
180
181 /* QNDP TID - the highest TID with no admission control */
182 if (!tid_found && !mvmvif->queue_params[ac].acm) {
183 tid_found = true;
184 switch (ac) {
185 case IEEE80211_AC_VO:
186 cmd->qndp_tid = 6;
187 break;
188 case IEEE80211_AC_VI:
189 cmd->qndp_tid = 5;
190 break;
191 case IEEE80211_AC_BE:
192 cmd->qndp_tid = 0;
193 break;
194 case IEEE80211_AC_BK:
195 cmd->qndp_tid = 1;
196 break;
197 }
198 }
199 }
200
Eliad Peller84fd7602014-07-30 15:42:19 +0300201 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
202#ifdef CONFIG_IWLWIFI_DEBUGFS
203 /* set advanced pm flag with no uapsd ACs to enable ps-poll */
204 if (mvmvif->dbgfs_pm.use_ps_poll)
205 cmd->flags |=
206 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
207#endif
Alexander Bondar175a70b2013-04-14 20:59:37 +0300208 return;
Eliad Peller84fd7602014-07-30 15:42:19 +0300209 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300210
211 cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK);
212
213 if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
214 BIT(IEEE80211_AC_VI) |
215 BIT(IEEE80211_AC_BE) |
216 BIT(IEEE80211_AC_BK))) {
217 cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
218 cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
219 cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
220 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
221 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
222 }
223
224 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
225
226 if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
227 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
228 cmd->rx_data_timeout_uapsd =
229 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
230 cmd->tx_data_timeout_uapsd =
231 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
232 } else {
233 cmd->rx_data_timeout_uapsd =
234 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
235 cmd->tx_data_timeout_uapsd =
236 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
237 }
238
239 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
240 cmd->heavy_tx_thld_packets =
241 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
242 cmd->heavy_rx_thld_packets =
243 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
244 } else {
245 cmd->heavy_tx_thld_packets =
246 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
247 cmd->heavy_rx_thld_packets =
248 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
249 }
250 cmd->heavy_tx_thld_percentage =
251 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
252 cmd->heavy_rx_thld_percentage =
253 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
254}
255
Avri Altmanc6e37a62014-04-01 12:08:13 +0300256static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm,
257 struct ieee80211_vif *vif)
258{
259 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
260
261 if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
262 ETH_ALEN))
263 return false;
264
265 if (vif->p2p &&
266 !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD))
267 return false;
268 /*
269 * Avoid using uAPSD if P2P client is associated to GO that uses
270 * opportunistic power save. This is due to current FW limitation.
271 */
272 if (vif->p2p &&
273 (vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
274 IEEE80211_P2P_OPPPS_ENABLE_BIT))
275 return false;
276
Avri Altman05345282014-05-08 10:06:01 +0300277 /*
278 * Avoid using uAPSD if client is in DCM -
279 * low latency issue in Miracast
280 */
Arik Nemtsovcf7b4912014-05-15 11:44:40 +0300281 if (iwl_mvm_phy_ctx_count(mvm) >= 2)
Avri Altman05345282014-05-08 10:06:01 +0300282 return false;
283
Avri Altmanc6e37a62014-04-01 12:08:13 +0300284 return true;
285}
286
Alexander Bondare811ada2013-03-10 15:29:44 +0200287static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
288 struct ieee80211_vif *vif,
289 struct iwl_mac_power_cmd *cmd)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100290{
291 struct ieee80211_hw *hw = mvm->hw;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100292 struct ieee80211_chanctx_conf *chanctx_conf;
293 struct ieee80211_channel *chan;
294 int dtimper, dtimper_msec;
295 int keep_alive;
296 bool radar_detect = false;
Alexander Bondarb571a692013-05-21 14:49:09 +0300297 struct iwl_mvm_vif *mvmvif __maybe_unused =
298 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100299
Alexander Bondare811ada2013-03-10 15:29:44 +0200300 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
301 mvmvif->color));
302 dtimper = hw->conf.ps_dtim_period ?: 1;
303
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200304 /*
305 * Regardless of power management state the driver must set
306 * keep alive period. FW will use it for sending keep alive NDPs
Alexander Bondare811ada2013-03-10 15:29:44 +0200307 * immediately after association. Check that keep alive period
308 * is at least 3 * DTIM
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200309 */
Alexander Bondare811ada2013-03-10 15:29:44 +0200310 dtimper_msec = dtimper * vif->bss_conf.beacon_int;
311 keep_alive = max_t(int, 3 * dtimper_msec,
312 MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
313 keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
314 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200315
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200316 if (mvm->ps_disabled)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100317 return;
318
Alexander Bondar9a613042013-03-05 12:54:00 +0200319 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
320
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200321 if (!vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif) ||
Avri Altman19889022014-03-19 07:25:06 +0200322 !mvmvif->pm_enabled)
Alexander Bondar9a613042013-03-05 12:54:00 +0200323 return;
324
325 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100326
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200327 if (vif->bss_conf.beacon_rate &&
328 (vif->bss_conf.beacon_rate->bitrate == 10 ||
329 vif->bss_conf.beacon_rate->bitrate == 60)) {
330 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200331 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200332 }
333
Johannes Berg8ca151b2013-01-24 14:25:36 +0100334 /* Check if radar detection is required on current channel */
335 rcu_read_lock();
336 chanctx_conf = rcu_dereference(vif->chanctx_conf);
337 WARN_ON(!chanctx_conf);
338 if (chanctx_conf) {
339 chan = chanctx_conf->def.chan;
340 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
341 }
342 rcu_read_unlock();
343
344 /* Check skip over DTIM conditions */
345 if (!radar_detect && (dtimper <= 10) &&
Alexander Bondaree1e8422013-04-23 13:52:10 +0300346 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
347 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200348 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200349 cmd->skip_dtim_periods = 3;
Alexander Bondar5b1dbfc2013-04-23 13:32:35 +0300350 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100351
Alexander Bondaree1e8422013-04-23 13:52:10 +0300352 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
Johannes Berg99545922013-06-14 13:36:21 +0200353 cmd->rx_data_timeout =
354 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
355 cmd->tx_data_timeout =
356 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300357 } else {
Johannes Berg99545922013-06-14 13:36:21 +0200358 cmd->rx_data_timeout =
359 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
360 cmd->tx_data_timeout =
361 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300362 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300363
Avri Altmanc6e37a62014-04-01 12:08:13 +0300364 if (iwl_mvm_power_allow_uapsd(mvm, vif))
Alexander Bondar175a70b2013-04-14 20:59:37 +0300365 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300366
Alexander Bondarb571a692013-05-21 14:49:09 +0300367#ifdef CONFIG_IWLWIFI_DEBUGFS
368 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200369 cmd->keep_alive_seconds =
370 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300371 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
372 if (mvmvif->dbgfs_pm.skip_over_dtim)
373 cmd->flags |=
374 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
375 else
376 cmd->flags &=
377 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
378 }
379 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
380 cmd->rx_data_timeout =
381 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
382 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
383 cmd->tx_data_timeout =
384 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
385 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200386 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200387 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
388 if (mvmvif->dbgfs_pm.lprx_ena)
389 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
390 else
391 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
392 }
393 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200394 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondar89716342013-08-04 17:52:23 +0300395 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
396 if (mvmvif->dbgfs_pm.snooze_ena)
397 cmd->flags |=
398 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
399 else
400 cmd->flags &=
401 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
402 }
Alexander Bondare45a9412013-12-04 10:13:24 +0200403 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
404 u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
405 if (mvmvif->dbgfs_pm.uapsd_misbehaving)
406 cmd->flags |= cpu_to_le16(flag);
407 else
408 cmd->flags &= cpu_to_le16(flag);
409 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300410#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100411}
412
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200413static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200414 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100415{
Alexander Bondare811ada2013-03-10 15:29:44 +0200416 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100417
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200418 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200419 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200420#ifdef CONFIG_IWLWIFI_DEBUGFS
421 memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
422#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100423
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300424 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0,
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200425 sizeof(cmd), &cmd);
426}
427
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200428int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300429{
430 struct iwl_device_power_cmd cmd = {
431 .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK),
432 };
433
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200434 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
435 mvm->ps_disabled = true;
436
437 if (mvm->ps_disabled)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300438 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK);
439
440#ifdef CONFIG_IWLWIFI_DEBUGFS
441 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
442 mvm->disable_power_off)
443 cmd.flags &=
444 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
445#endif
446 IWL_DEBUG_POWER(mvm,
447 "Sending device power command with flags = 0x%X\n",
448 cmd.flags);
449
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300450 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd),
Alexander Bondar64b928c2013-09-03 14:18:03 +0300451 &cmd);
452}
453
Alexander Bondar175a70b2013-04-14 20:59:37 +0300454void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
455{
456 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
457
458 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
459 ETH_ALEN))
460 memset(mvmvif->uapsd_misbehaving_bssid, 0, ETH_ALEN);
461}
462
463static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
464 struct ieee80211_vif *vif)
465{
466 u8 *ap_sta_id = _data;
467 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
468
469 /* The ap_sta_id is not expected to change during current association
470 * so no explicit protection is needed
471 */
472 if (mvmvif->ap_sta_id == *ap_sta_id)
473 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
474 ETH_ALEN);
475}
476
477int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
478 struct iwl_rx_cmd_buffer *rxb,
479 struct iwl_device_cmd *cmd)
480{
481 struct iwl_rx_packet *pkt = rxb_addr(rxb);
482 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
483 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
484
485 ieee80211_iterate_active_interfaces_atomic(
486 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
487 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
488
489 return 0;
490}
491
Avri Altman19889022014-03-19 07:25:06 +0200492struct iwl_power_vifs {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300493 struct iwl_mvm *mvm;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200494 struct ieee80211_vif *bf_vif;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200495 struct ieee80211_vif *bss_vif;
Avri Altman8ea0c682014-02-20 13:28:57 +0200496 struct ieee80211_vif *p2p_vif;
Avri Altman19889022014-03-19 07:25:06 +0200497 struct ieee80211_vif *ap_vif;
498 struct ieee80211_vif *monitor_vif;
499 bool p2p_active;
500 bool bss_active;
501 bool ap_active;
502 bool monitor_active;
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300503 bool bss_tdls;
504 bool p2p_tdls;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200505};
506
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200507static void iwl_mvm_power_iterator(void *_data, u8 *mac,
508 struct ieee80211_vif *vif)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300509{
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200510 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman19889022014-03-19 07:25:06 +0200511 struct iwl_power_vifs *power_iterator = _data;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300512
Avri Altman19889022014-03-19 07:25:06 +0200513 mvmvif->pm_enabled = false;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200514 switch (ieee80211_vif_type_p2p(vif)) {
515 case NL80211_IFTYPE_P2P_DEVICE:
516 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200517
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200518 case NL80211_IFTYPE_P2P_GO:
519 case NL80211_IFTYPE_AP:
Avri Altman19889022014-03-19 07:25:06 +0200520 /* only a single MAC of the same type */
521 WARN_ON(power_iterator->ap_vif);
522 power_iterator->ap_vif = vif;
523 if (mvmvif->phy_ctxt)
524 if (mvmvif->phy_ctxt->id < MAX_PHYS)
525 power_iterator->ap_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200526 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200527
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200528 case NL80211_IFTYPE_MONITOR:
Avri Altman19889022014-03-19 07:25:06 +0200529 /* only a single MAC of the same type */
530 WARN_ON(power_iterator->monitor_vif);
531 power_iterator->monitor_vif = vif;
532 if (mvmvif->phy_ctxt)
533 if (mvmvif->phy_ctxt->id < MAX_PHYS)
534 power_iterator->monitor_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200535 break;
536
537 case NL80211_IFTYPE_P2P_CLIENT:
Avri Altman19889022014-03-19 07:25:06 +0200538 /* only a single MAC of the same type */
Avri Altman8ea0c682014-02-20 13:28:57 +0200539 WARN_ON(power_iterator->p2p_vif);
540 power_iterator->p2p_vif = vif;
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300541 power_iterator->p2p_tdls =
542 !!iwl_mvm_tdls_sta_count(power_iterator->mvm, vif);
Avri Altman19889022014-03-19 07:25:06 +0200543 if (mvmvif->phy_ctxt)
544 if (mvmvif->phy_ctxt->id < MAX_PHYS)
545 power_iterator->p2p_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200546 break;
547
548 case NL80211_IFTYPE_STATION:
Avri Altman19889022014-03-19 07:25:06 +0200549 /* only a single MAC of the same type */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200550 WARN_ON(power_iterator->bss_vif);
551 power_iterator->bss_vif = vif;
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300552 power_iterator->bss_tdls =
553 !!iwl_mvm_tdls_sta_count(power_iterator->mvm, vif);
Avri Altman19889022014-03-19 07:25:06 +0200554 if (mvmvif->phy_ctxt)
555 if (mvmvif->phy_ctxt->id < MAX_PHYS)
556 power_iterator->bss_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200557
558 if (mvmvif->bf_data.bf_enabled &&
559 !WARN_ON(power_iterator->bf_vif))
560 power_iterator->bf_vif = vif;
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200561
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200562 break;
563
564 default:
565 break;
566 }
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300567}
568
Luciano Coelhob1873302014-08-08 17:12:07 +0300569static void iwl_mvm_power_set_pm(struct iwl_mvm *mvm,
570 struct iwl_power_vifs *vifs)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300571{
Avri Altman19889022014-03-19 07:25:06 +0200572 struct iwl_mvm_vif *bss_mvmvif = NULL;
573 struct iwl_mvm_vif *p2p_mvmvif = NULL;
574 struct iwl_mvm_vif *ap_mvmvif = NULL;
575 bool client_same_channel = false;
576 bool ap_same_channel = false;
577
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200578 lockdep_assert_held(&mvm->mutex);
579
Avri Altman19889022014-03-19 07:25:06 +0200580 /* get vifs info + set pm_enable to false */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200581 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
582 IEEE80211_IFACE_ITER_NORMAL,
Avri Altman19889022014-03-19 07:25:06 +0200583 iwl_mvm_power_iterator, vifs);
584
585 if (vifs->bss_vif)
586 bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif);
587
588 if (vifs->p2p_vif)
589 p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif);
590
591 if (vifs->ap_vif)
592 ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif);
593
594 /* enable PM on bss if bss stand alone */
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300595 if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active &&
596 !vifs->bss_tdls) {
Avri Altman19889022014-03-19 07:25:06 +0200597 bss_mvmvif->pm_enabled = true;
598 return;
599 }
600
601 /* enable PM on p2p if p2p stand alone */
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300602 if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active &&
603 !vifs->p2p_tdls) {
Avri Altman19889022014-03-19 07:25:06 +0200604 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
605 p2p_mvmvif->pm_enabled = true;
606 return;
607 }
608
609 if (vifs->bss_active && vifs->p2p_active)
610 client_same_channel = (bss_mvmvif->phy_ctxt->id ==
611 p2p_mvmvif->phy_ctxt->id);
612 if (vifs->bss_active && vifs->ap_active)
613 ap_same_channel = (bss_mvmvif->phy_ctxt->id ==
614 ap_mvmvif->phy_ctxt->id);
615
Avri Altman63ef81c2014-04-02 07:54:07 +0300616 /* clients are not stand alone: enable PM if DCM */
617 if (!(client_same_channel || ap_same_channel) &&
Avri Altman19889022014-03-19 07:25:06 +0200618 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) {
Avri Altman63ef81c2014-04-02 07:54:07 +0300619 if (vifs->bss_active)
Avri Altman19889022014-03-19 07:25:06 +0200620 bss_mvmvif->pm_enabled = true;
Avri Altman63ef81c2014-04-02 07:54:07 +0300621 if (vifs->p2p_active &&
622 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM))
623 p2p_mvmvif->pm_enabled = true;
624 return;
Avri Altman19889022014-03-19 07:25:06 +0200625 }
626
627 /*
628 * There is only one channel in the system and there are only
629 * bss and p2p clients that share it
630 */
631 if (client_same_channel && !vifs->ap_active &&
632 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM)) {
633 /* share same channel*/
634 bss_mvmvif->pm_enabled = true;
635 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
636 p2p_mvmvif->pm_enabled = true;
637 }
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200638}
639
Alexander Bondarb571a692013-05-21 14:49:09 +0300640#ifdef CONFIG_IWLWIFI_DEBUGFS
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200641int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
642 struct ieee80211_vif *vif, char *buf,
643 int bufsz)
Alexander Bondare811ada2013-03-10 15:29:44 +0200644{
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200645 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondare811ada2013-03-10 15:29:44 +0200646 struct iwl_mac_power_cmd cmd = {};
647 int pos = 0;
648
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200649 mutex_lock(&mvm->mutex);
650 memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
651 mutex_unlock(&mvm->mutex);
Alexander Bondare811ada2013-03-10 15:29:44 +0200652
Alexander Bondare811ada2013-03-10 15:29:44 +0200653 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
654 iwlmvm_mod_params.power_scheme);
655 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
656 le16_to_cpu(cmd.flags));
657 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
658 le16_to_cpu(cmd.keep_alive_seconds));
659
Alexander Bondar175a70b2013-04-14 20:59:37 +0300660 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
661 return pos;
662
663 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
664 (cmd.flags &
665 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
666 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
667 cmd.skip_dtim_periods);
668 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
669 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
670 le32_to_cpu(cmd.rx_data_timeout));
671 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
672 le32_to_cpu(cmd.tx_data_timeout));
Alexander Bondare811ada2013-03-10 15:29:44 +0200673 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300674 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
675 pos += scnprintf(buf+pos, bufsz-pos,
676 "lprx_rssi_threshold = %d\n",
677 cmd.lprx_rssi_threshold);
678
679 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
680 return pos;
681
682 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
683 le32_to_cpu(cmd.rx_data_timeout_uapsd));
684 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
685 le32_to_cpu(cmd.tx_data_timeout_uapsd));
686 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
687 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
688 cmd.uapsd_ac_flags);
689 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
690 cmd.uapsd_max_sp);
691 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
692 cmd.heavy_tx_thld_packets);
693 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
694 cmd.heavy_rx_thld_packets);
695 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
696 cmd.heavy_tx_thld_percentage);
697 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
698 cmd.heavy_rx_thld_percentage);
699 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
700 (cmd.flags &
701 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
702 1 : 0);
703
704 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
705 return pos;
706
707 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
708 cmd.snooze_interval);
709 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
710 cmd.snooze_window);
711
Alexander Bondare811ada2013-03-10 15:29:44 +0200712 return pos;
713}
714
Alexander Bondarb571a692013-05-21 14:49:09 +0300715void
716iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
717 struct iwl_beacon_filter_cmd *cmd)
718{
719 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
720 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
721
722 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300723 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300724 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
725 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300726 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300727 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300728 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
729 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
730 cmd->bf_temp_threshold =
731 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
732 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
733 cmd->bf_temp_fast_filter =
734 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
735 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
736 cmd->bf_temp_slow_filter =
737 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300738 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300739 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300740 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
741 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
742 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
743 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
744 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300745 cmd->ba_enable_beacon_abort =
746 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300747}
748#endif
749
Eliad Peller3dd37d02014-01-07 14:00:24 +0200750static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
751 struct ieee80211_vif *vif,
752 struct iwl_beacon_filter_cmd *cmd,
753 u32 cmd_flags,
754 bool d0i3)
Hila Gonen7df15b12012-12-12 11:16:19 +0200755{
756 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondar071d49902013-05-06 13:03:59 +0300757 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200758
Avri Altmanfa7b2e72014-05-20 08:03:24 +0300759 if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period ||
Hila Gonen7df15b12012-12-12 11:16:19 +0200760 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
761 return 0;
762
Eliad Peller3dd37d02014-01-07 14:00:24 +0200763 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd);
764 if (!d0i3)
765 iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
766 ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300767
Eliad Peller3dd37d02014-01-07 14:00:24 +0200768 /* don't change bf_enabled in case of temporary d0i3 configuration */
769 if (!ret && !d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300770 mvmvif->bf_data.bf_enabled = true;
Alexander Bondar071d49902013-05-06 13:03:59 +0300771
772 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200773}
774
Eliad Peller3dd37d02014-01-07 14:00:24 +0200775int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
776 struct ieee80211_vif *vif,
777 u32 flags)
778{
779 struct iwl_beacon_filter_cmd cmd = {
780 IWL_BF_CMD_CONFIG_DEFAULTS,
781 .bf_enable_beacon_filter = cpu_to_le32(1),
782 };
783
784 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
785}
786
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300787static int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
788 struct ieee80211_vif *vif,
789 bool enable)
Avri Altmanfa7b2e72014-05-20 08:03:24 +0300790{
791 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
792 struct iwl_beacon_filter_cmd cmd = {
793 IWL_BF_CMD_CONFIG_DEFAULTS,
794 .bf_enable_beacon_filter = cpu_to_le32(1),
795 };
796
797 if (!mvmvif->bf_data.bf_enabled)
798 return 0;
799
800 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
801 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
802
803 mvmvif->bf_data.ba_enabled = enable;
804 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false);
805}
806
Hila Gonen7df15b12012-12-12 11:16:19 +0200807int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +0200808 struct ieee80211_vif *vif,
809 u32 flags)
Hila Gonen7df15b12012-12-12 11:16:19 +0200810{
Alexander Bondar071d49902013-05-06 13:03:59 +0300811 struct iwl_beacon_filter_cmd cmd = {};
812 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
813 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200814
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +0300815 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200816 return 0;
817
Eliad Peller3dd37d02014-01-07 14:00:24 +0200818 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300819
820 if (!ret)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300821 mvmvif->bf_data.bf_enabled = false;
Alexander Bondar071d49902013-05-06 13:03:59 +0300822
823 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200824}
Alexander Bondare811ada2013-03-10 15:29:44 +0200825
Arik Nemtsov999609f2014-05-15 17:31:51 +0300826int iwl_mvm_power_update_mac(struct iwl_mvm *mvm)
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300827{
828 struct iwl_mvm_vif *mvmvif;
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300829 struct iwl_power_vifs vifs = {
830 .mvm = mvm,
831 };
Luciano Coelhob1873302014-08-08 17:12:07 +0300832 bool ba_enable, disable_ps;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300833 int ret;
834
835 lockdep_assert_held(&mvm->mutex);
836
837 iwl_mvm_power_set_pm(mvm, &vifs);
838
839 /* disable PS if CAM */
Luciano Coelhob1873302014-08-08 17:12:07 +0300840 disable_ps = (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM);
841 /* ...or if there is an active monitor vif */
842 disable_ps |= (vifs.monitor_vif && vifs.monitor_active);
843
844 /* update device power state if it has changed */
845 if (mvm->ps_disabled != disable_ps) {
846 bool old_ps_disabled = mvm->ps_disabled;
847
848 mvm->ps_disabled = disable_ps;
849 ret = iwl_mvm_power_update_device(mvm);
850 if (ret) {
851 mvm->ps_disabled = old_ps_disabled;
852 return ret;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300853 }
854 }
855
856 if (vifs.bss_vif) {
857 ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif);
858 if (ret)
859 return ret;
860 }
861
862 if (vifs.p2p_vif) {
863 ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif);
864 if (ret)
865 return ret;
866 }
867
868 if (!vifs.bf_vif)
869 return 0;
870
Arik Nemtsov999609f2014-05-15 17:31:51 +0300871 mvmvif = iwl_mvm_vif_from_mac80211(vifs.bf_vif);
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300872
873 ba_enable = !(!mvmvif->pm_enabled || mvm->ps_disabled ||
Arik Nemtsov999609f2014-05-15 17:31:51 +0300874 !vifs.bf_vif->bss_conf.ps ||
875 iwl_mvm_vif_low_latency(mvmvif));
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300876
877 return iwl_mvm_update_beacon_abort(mvm, vifs.bf_vif, ba_enable);
878}
879
Eliad Peller3dd37d02014-01-07 14:00:24 +0200880int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
881 struct ieee80211_vif *vif,
882 bool enable, u32 flags)
883{
884 int ret;
885 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
886 struct iwl_mac_power_cmd cmd = {};
887
888 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
889 return 0;
890
891 if (!vif->bss_conf.assoc)
892 return 0;
893
894 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
895 if (enable) {
896 /* configure skip over dtim up to 300 msec */
897 int dtimper = mvm->hw->conf.ps_dtim_period ?: 1;
898 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
899
900 if (WARN_ON(!dtimper_msec))
901 return 0;
902
Eliad Peller3dd37d02014-01-07 14:00:24 +0200903 cmd.skip_dtim_periods = 300 / dtimper_msec;
Eliad Peller6f361052014-05-12 14:22:20 +0300904 if (cmd.skip_dtim_periods)
905 cmd.flags |=
906 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Eliad Peller3dd37d02014-01-07 14:00:24 +0200907 }
908 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200909#ifdef CONFIG_IWLWIFI_DEBUGFS
910 memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
911#endif
Eliad Peller3dd37d02014-01-07 14:00:24 +0200912 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
913 sizeof(cmd), &cmd);
914 if (ret)
915 return ret;
916
917 /* configure beacon filtering */
918 if (mvmvif != mvm->bf_allowed_vif)
919 return 0;
920
921 if (enable) {
922 struct iwl_beacon_filter_cmd cmd_bf = {
923 IWL_BF_CMD_CONFIG_D0I3,
924 .bf_enable_beacon_filter = cpu_to_le32(1),
925 };
926 ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
927 flags, true);
928 } else {
929 if (mvmvif->bf_data.bf_enabled)
930 ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
931 else
932 ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
933 }
934
935 return ret;
936}