blob: e7a6626fe8397691904f6ef1321541f002837ac9 [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 Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020035 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65
66#include <linux/kernel.h>
67#include <linux/module.h>
68#include <linux/slab.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010069
70#include <net/mac80211.h>
71
72#include "iwl-debug.h"
73#include "mvm.h"
74#include "iwl-modparams.h"
75#include "fw-api-power.h"
76
77#define POWER_KEEP_ALIVE_PERIOD_SEC 25
78
Emmanuel Grumbachd623d242014-01-26 12:58:24 +020079static
Alexander Bondare811ada2013-03-10 15:29:44 +020080int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +020081 struct iwl_beacon_filter_cmd *cmd,
82 u32 flags)
Alexander Bondar071d49902013-05-06 13:03:59 +030083{
Emmanuel Grumbachd623d242014-01-26 12:58:24 +020084 IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n",
85 le32_to_cpu(cmd->ba_enable_beacon_abort));
86 IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n",
87 le32_to_cpu(cmd->ba_escape_timer));
88 IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n",
89 le32_to_cpu(cmd->bf_debug_flag));
90 IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n",
91 le32_to_cpu(cmd->bf_enable_beacon_filter));
92 IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n",
93 le32_to_cpu(cmd->bf_energy_delta));
94 IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n",
95 le32_to_cpu(cmd->bf_escape_timer));
96 IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n",
97 le32_to_cpu(cmd->bf_roaming_energy_delta));
98 IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n",
99 le32_to_cpu(cmd->bf_roaming_state));
100 IWL_DEBUG_POWER(mvm, "bf_temp_threshold is: %d\n",
101 le32_to_cpu(cmd->bf_temp_threshold));
102 IWL_DEBUG_POWER(mvm, "bf_temp_fast_filter is: %d\n",
103 le32_to_cpu(cmd->bf_temp_fast_filter));
104 IWL_DEBUG_POWER(mvm, "bf_temp_slow_filter is: %d\n",
105 le32_to_cpu(cmd->bf_temp_slow_filter));
Alexander Bondar071d49902013-05-06 13:03:59 +0300106
Emmanuel Grumbachd623d242014-01-26 12:58:24 +0200107 return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags,
108 sizeof(struct iwl_beacon_filter_cmd), cmd);
Alexander Bondar071d49902013-05-06 13:03:59 +0300109}
110
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300111static
112void iwl_mvm_beacon_filter_set_cqm_params(struct iwl_mvm *mvm,
113 struct ieee80211_vif *vif,
114 struct iwl_beacon_filter_cmd *cmd)
115{
116 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
117
118 if (vif->bss_conf.cqm_rssi_thold) {
119 cmd->bf_energy_delta =
120 cpu_to_le32(vif->bss_conf.cqm_rssi_hyst);
121 /* fw uses an absolute value for this */
122 cmd->bf_roaming_state =
123 cpu_to_le32(-vif->bss_conf.cqm_rssi_thold);
124 }
125 cmd->ba_enable_beacon_abort = cpu_to_le32(mvmvif->bf_data.ba_enabled);
126}
127
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200128static void iwl_mvm_power_log(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200129 struct iwl_mac_power_cmd *cmd)
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200130{
131 IWL_DEBUG_POWER(mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200132 "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n",
133 cmd->id_and_color, iwlmvm_mod_params.power_scheme,
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200134 le16_to_cpu(cmd->flags));
Alexander Bondare811ada2013-03-10 15:29:44 +0200135 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n",
136 le16_to_cpu(cmd->keep_alive_seconds));
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200137
Alexander Bondare3c588e2013-04-07 14:08:59 +0300138 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) {
139 IWL_DEBUG_POWER(mvm, "Disable power management\n");
140 return;
141 }
142
143 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
144 le32_to_cpu(cmd->rx_data_timeout));
145 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
146 le32_to_cpu(cmd->tx_data_timeout));
147 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK))
148 IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n",
149 cmd->skip_dtim_periods);
150 if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
151 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
152 cmd->lprx_rssi_threshold);
153 if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) {
154 IWL_DEBUG_POWER(mvm, "uAPSD enabled\n");
155 IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n",
156 le32_to_cpu(cmd->rx_data_timeout_uapsd));
157 IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n",
158 le32_to_cpu(cmd->tx_data_timeout_uapsd));
159 IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid);
160 IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags);
161 IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200162 }
163}
164
Alexander Bondar175a70b2013-04-14 20:59:37 +0300165static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm,
166 struct ieee80211_vif *vif,
167 struct iwl_mac_power_cmd *cmd)
168{
169 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
170 enum ieee80211_ac_numbers ac;
171 bool tid_found = false;
172
173 for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) {
174 if (!mvmvif->queue_params[ac].uapsd)
175 continue;
176
177 if (mvm->cur_ucode != IWL_UCODE_WOWLAN)
178 cmd->flags |=
179 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
180
181 cmd->uapsd_ac_flags |= BIT(ac);
182
183 /* QNDP TID - the highest TID with no admission control */
184 if (!tid_found && !mvmvif->queue_params[ac].acm) {
185 tid_found = true;
186 switch (ac) {
187 case IEEE80211_AC_VO:
188 cmd->qndp_tid = 6;
189 break;
190 case IEEE80211_AC_VI:
191 cmd->qndp_tid = 5;
192 break;
193 case IEEE80211_AC_BE:
194 cmd->qndp_tid = 0;
195 break;
196 case IEEE80211_AC_BK:
197 cmd->qndp_tid = 1;
198 break;
199 }
200 }
201 }
202
Eliad Peller84fd7602014-07-30 15:42:19 +0300203 if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
204#ifdef CONFIG_IWLWIFI_DEBUGFS
205 /* set advanced pm flag with no uapsd ACs to enable ps-poll */
206 if (mvmvif->dbgfs_pm.use_ps_poll)
207 cmd->flags |=
208 cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK);
209#endif
Alexander Bondar175a70b2013-04-14 20:59:37 +0300210 return;
Eliad Peller84fd7602014-07-30 15:42:19 +0300211 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300212
213 cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK);
214
215 if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) |
216 BIT(IEEE80211_AC_VI) |
217 BIT(IEEE80211_AC_BE) |
218 BIT(IEEE80211_AC_BK))) {
219 cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
220 cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL);
221 cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ?
222 cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) :
223 cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW);
224 }
225
226 cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP;
227
228 if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags &
229 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
230 cmd->rx_data_timeout_uapsd =
231 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
232 cmd->tx_data_timeout_uapsd =
233 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
234 } else {
235 cmd->rx_data_timeout_uapsd =
236 cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT);
237 cmd->tx_data_timeout_uapsd =
238 cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT);
239 }
240
241 if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) {
242 cmd->heavy_tx_thld_packets =
243 IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS;
244 cmd->heavy_rx_thld_packets =
245 IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS;
246 } else {
247 cmd->heavy_tx_thld_packets =
248 IWL_MVM_PS_HEAVY_TX_THLD_PACKETS;
249 cmd->heavy_rx_thld_packets =
250 IWL_MVM_PS_HEAVY_RX_THLD_PACKETS;
251 }
252 cmd->heavy_tx_thld_percentage =
253 IWL_MVM_PS_HEAVY_TX_THLD_PERCENT;
254 cmd->heavy_rx_thld_percentage =
255 IWL_MVM_PS_HEAVY_RX_THLD_PERCENT;
256}
257
Avri Altmanc6e37a62014-04-01 12:08:13 +0300258static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm,
259 struct ieee80211_vif *vif)
260{
261 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
262
263 if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
264 ETH_ALEN))
265 return false;
266
267 if (vif->p2p &&
268 !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD))
269 return false;
270 /*
271 * Avoid using uAPSD if P2P client is associated to GO that uses
272 * opportunistic power save. This is due to current FW limitation.
273 */
274 if (vif->p2p &&
275 (vif->bss_conf.p2p_noa_attr.oppps_ctwindow &
276 IEEE80211_P2P_OPPPS_ENABLE_BIT))
277 return false;
278
Avri Altman05345282014-05-08 10:06:01 +0300279 /*
280 * Avoid using uAPSD if client is in DCM -
281 * low latency issue in Miracast
282 */
Arik Nemtsovcf7b4912014-05-15 11:44:40 +0300283 if (iwl_mvm_phy_ctx_count(mvm) >= 2)
Avri Altman05345282014-05-08 10:06:01 +0300284 return false;
285
Avri Altmanc6e37a62014-04-01 12:08:13 +0300286 return true;
287}
288
Alexander Bondare811ada2013-03-10 15:29:44 +0200289static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
290 struct ieee80211_vif *vif,
291 struct iwl_mac_power_cmd *cmd)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100292{
293 struct ieee80211_hw *hw = mvm->hw;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100294 struct ieee80211_chanctx_conf *chanctx_conf;
295 struct ieee80211_channel *chan;
296 int dtimper, dtimper_msec;
297 int keep_alive;
298 bool radar_detect = false;
Alexander Bondarb571a692013-05-21 14:49:09 +0300299 struct iwl_mvm_vif *mvmvif __maybe_unused =
300 iwl_mvm_vif_from_mac80211(vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100301
Alexander Bondare811ada2013-03-10 15:29:44 +0200302 cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
303 mvmvif->color));
304 dtimper = hw->conf.ps_dtim_period ?: 1;
305
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200306 /*
307 * Regardless of power management state the driver must set
308 * keep alive period. FW will use it for sending keep alive NDPs
Alexander Bondare811ada2013-03-10 15:29:44 +0200309 * immediately after association. Check that keep alive period
310 * is at least 3 * DTIM
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200311 */
Alexander Bondare811ada2013-03-10 15:29:44 +0200312 dtimper_msec = dtimper * vif->bss_conf.beacon_int;
313 keep_alive = max_t(int, 3 * dtimper_msec,
314 MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC);
315 keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
316 cmd->keep_alive_seconds = cpu_to_le16(keep_alive);
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200317
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200318 if (mvm->ps_disabled)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100319 return;
320
Alexander Bondar9a613042013-03-05 12:54:00 +0200321 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
322
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200323 if (!vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif) ||
Avri Altman19889022014-03-19 07:25:06 +0200324 !mvmvif->pm_enabled)
Alexander Bondar9a613042013-03-05 12:54:00 +0200325 return;
326
327 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100328
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200329 if (vif->bss_conf.beacon_rate &&
330 (vif->bss_conf.beacon_rate->bitrate == 10 ||
331 vif->bss_conf.beacon_rate->bitrate == 60)) {
332 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200333 cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200334 }
335
Johannes Berg8ca151b2013-01-24 14:25:36 +0100336 /* Check if radar detection is required on current channel */
337 rcu_read_lock();
338 chanctx_conf = rcu_dereference(vif->chanctx_conf);
339 WARN_ON(!chanctx_conf);
340 if (chanctx_conf) {
341 chan = chanctx_conf->def.chan;
342 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
343 }
344 rcu_read_unlock();
345
346 /* Check skip over DTIM conditions */
347 if (!radar_detect && (dtimper <= 10) &&
Alexander Bondaree1e8422013-04-23 13:52:10 +0300348 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP ||
349 mvm->cur_ucode == IWL_UCODE_WOWLAN)) {
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200350 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Alexander Bondare811ada2013-03-10 15:29:44 +0200351 cmd->skip_dtim_periods = 3;
Alexander Bondar5b1dbfc2013-04-23 13:32:35 +0300352 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100353
Alexander Bondaree1e8422013-04-23 13:52:10 +0300354 if (mvm->cur_ucode != IWL_UCODE_WOWLAN) {
Johannes Berg99545922013-06-14 13:36:21 +0200355 cmd->rx_data_timeout =
356 cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT);
357 cmd->tx_data_timeout =
358 cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300359 } else {
Johannes Berg99545922013-06-14 13:36:21 +0200360 cmd->rx_data_timeout =
361 cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT);
362 cmd->tx_data_timeout =
363 cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT);
Alexander Bondaree1e8422013-04-23 13:52:10 +0300364 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300365
Avri Altmanc6e37a62014-04-01 12:08:13 +0300366 if (iwl_mvm_power_allow_uapsd(mvm, vif))
Alexander Bondar175a70b2013-04-14 20:59:37 +0300367 iwl_mvm_power_configure_uapsd(mvm, vif, cmd);
Alexander Bondare3c588e2013-04-07 14:08:59 +0300368
Alexander Bondarb571a692013-05-21 14:49:09 +0300369#ifdef CONFIG_IWLWIFI_DEBUGFS
370 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE)
Alexander Bondare811ada2013-03-10 15:29:44 +0200371 cmd->keep_alive_seconds =
372 cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds);
Alexander Bondarb571a692013-05-21 14:49:09 +0300373 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) {
374 if (mvmvif->dbgfs_pm.skip_over_dtim)
375 cmd->flags |=
376 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
377 else
378 cmd->flags &=
379 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK);
380 }
381 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT)
382 cmd->rx_data_timeout =
383 cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout);
384 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT)
385 cmd->tx_data_timeout =
386 cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout);
387 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS)
Alexander Bondare811ada2013-03-10 15:29:44 +0200388 cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods;
Alexander Bondarbd4ace22013-03-21 17:14:14 +0200389 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) {
390 if (mvmvif->dbgfs_pm.lprx_ena)
391 cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK);
392 else
393 cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK);
394 }
395 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD)
Alexander Bondare811ada2013-03-10 15:29:44 +0200396 cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold;
Alexander Bondar89716342013-08-04 17:52:23 +0300397 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) {
398 if (mvmvif->dbgfs_pm.snooze_ena)
399 cmd->flags |=
400 cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK);
401 else
402 cmd->flags &=
403 cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK);
404 }
Alexander Bondare45a9412013-12-04 10:13:24 +0200405 if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) {
406 u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK;
407 if (mvmvif->dbgfs_pm.uapsd_misbehaving)
408 cmd->flags |= cpu_to_le16(flag);
409 else
410 cmd->flags &= cpu_to_le16(flag);
411 }
Alexander Bondarb571a692013-05-21 14:49:09 +0300412#endif /* CONFIG_IWLWIFI_DEBUGFS */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100413}
414
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200415static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm,
Alexander Bondare811ada2013-03-10 15:29:44 +0200416 struct ieee80211_vif *vif)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100417{
Alexander Bondare811ada2013-03-10 15:29:44 +0200418 struct iwl_mac_power_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100419
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200420 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200421 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200422#ifdef CONFIG_IWLWIFI_DEBUGFS
423 memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd));
424#endif
Johannes Berg8ca151b2013-01-24 14:25:36 +0100425
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300426 return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, 0,
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200427 sizeof(cmd), &cmd);
428}
429
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200430int iwl_mvm_power_update_device(struct iwl_mvm *mvm)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300431{
432 struct iwl_device_power_cmd cmd = {
433 .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK),
434 };
435
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200436 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM)
437 mvm->ps_disabled = true;
438
439 if (mvm->ps_disabled)
Alexander Bondar64b928c2013-09-03 14:18:03 +0300440 cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK);
441
442#ifdef CONFIG_IWLWIFI_DEBUGFS
443 if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 :
444 mvm->disable_power_off)
445 cmd.flags &=
446 cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK);
447#endif
448 IWL_DEBUG_POWER(mvm,
449 "Sending device power command with flags = 0x%X\n",
450 cmd.flags);
451
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300452 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, 0, sizeof(cmd),
Alexander Bondar64b928c2013-09-03 14:18:03 +0300453 &cmd);
454}
455
Alexander Bondar175a70b2013-04-14 20:59:37 +0300456void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
457{
458 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
459
460 if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid,
461 ETH_ALEN))
462 memset(mvmvif->uapsd_misbehaving_bssid, 0, ETH_ALEN);
463}
464
465static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac,
466 struct ieee80211_vif *vif)
467{
468 u8 *ap_sta_id = _data;
469 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
470
471 /* The ap_sta_id is not expected to change during current association
472 * so no explicit protection is needed
473 */
474 if (mvmvif->ap_sta_id == *ap_sta_id)
475 memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid,
476 ETH_ALEN);
477}
478
479int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm,
480 struct iwl_rx_cmd_buffer *rxb,
481 struct iwl_device_cmd *cmd)
482{
483 struct iwl_rx_packet *pkt = rxb_addr(rxb);
484 struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data;
485 u8 ap_sta_id = le32_to_cpu(notif->sta_id);
486
487 ieee80211_iterate_active_interfaces_atomic(
488 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
489 iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id);
490
491 return 0;
492}
493
Avri Altman19889022014-03-19 07:25:06 +0200494struct iwl_power_vifs {
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300495 struct iwl_mvm *mvm;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200496 struct ieee80211_vif *bf_vif;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200497 struct ieee80211_vif *bss_vif;
Avri Altman8ea0c682014-02-20 13:28:57 +0200498 struct ieee80211_vif *p2p_vif;
Avri Altman19889022014-03-19 07:25:06 +0200499 struct ieee80211_vif *ap_vif;
500 struct ieee80211_vif *monitor_vif;
501 bool p2p_active;
502 bool bss_active;
503 bool ap_active;
504 bool monitor_active;
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300505 bool bss_tdls;
506 bool p2p_tdls;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200507};
508
Luciano Coelho128aa942014-08-08 18:36:22 +0300509static void iwl_mvm_power_disable_pm_iterator(void *_data, u8* mac,
510 struct ieee80211_vif *vif)
511{
512 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
513
514 mvmvif->pm_enabled = false;
515}
516
Luciano Coelho2533edc2014-08-08 19:50:46 +0300517static void iwl_mvm_power_ps_disabled_iterator(void *_data, u8* mac,
518 struct ieee80211_vif *vif)
519{
520 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
521 bool *disable_ps = _data;
522
523 if (mvmvif->phy_ctxt)
524 if (mvmvif->phy_ctxt->id < MAX_PHYS)
525 *disable_ps |= mvmvif->ps_disabled;
526}
527
Luciano Coelho128aa942014-08-08 18:36:22 +0300528static void iwl_mvm_power_get_vifs_iterator(void *_data, u8 *mac,
529 struct ieee80211_vif *vif)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300530{
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200531 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Avri Altman19889022014-03-19 07:25:06 +0200532 struct iwl_power_vifs *power_iterator = _data;
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300533
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200534 switch (ieee80211_vif_type_p2p(vif)) {
535 case NL80211_IFTYPE_P2P_DEVICE:
536 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200537
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200538 case NL80211_IFTYPE_P2P_GO:
539 case NL80211_IFTYPE_AP:
Avri Altman19889022014-03-19 07:25:06 +0200540 /* only a single MAC of the same type */
541 WARN_ON(power_iterator->ap_vif);
542 power_iterator->ap_vif = vif;
543 if (mvmvif->phy_ctxt)
544 if (mvmvif->phy_ctxt->id < MAX_PHYS)
545 power_iterator->ap_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200546 break;
Emmanuel Grumbach06280a22014-01-27 08:09:23 +0200547
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200548 case NL80211_IFTYPE_MONITOR:
Avri Altman19889022014-03-19 07:25:06 +0200549 /* only a single MAC of the same type */
550 WARN_ON(power_iterator->monitor_vif);
551 power_iterator->monitor_vif = vif;
552 if (mvmvif->phy_ctxt)
553 if (mvmvif->phy_ctxt->id < MAX_PHYS)
554 power_iterator->monitor_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200555 break;
556
557 case NL80211_IFTYPE_P2P_CLIENT:
Avri Altman19889022014-03-19 07:25:06 +0200558 /* only a single MAC of the same type */
Avri Altman8ea0c682014-02-20 13:28:57 +0200559 WARN_ON(power_iterator->p2p_vif);
560 power_iterator->p2p_vif = vif;
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300561 power_iterator->p2p_tdls =
562 !!iwl_mvm_tdls_sta_count(power_iterator->mvm, vif);
Avri Altman19889022014-03-19 07:25:06 +0200563 if (mvmvif->phy_ctxt)
564 if (mvmvif->phy_ctxt->id < MAX_PHYS)
565 power_iterator->p2p_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200566 break;
567
568 case NL80211_IFTYPE_STATION:
Avri Altman19889022014-03-19 07:25:06 +0200569 /* only a single MAC of the same type */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200570 WARN_ON(power_iterator->bss_vif);
571 power_iterator->bss_vif = vif;
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300572 power_iterator->bss_tdls =
573 !!iwl_mvm_tdls_sta_count(power_iterator->mvm, vif);
Avri Altman19889022014-03-19 07:25:06 +0200574 if (mvmvif->phy_ctxt)
575 if (mvmvif->phy_ctxt->id < MAX_PHYS)
576 power_iterator->bss_active = true;
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200577
578 if (mvmvif->bf_data.bf_enabled &&
579 !WARN_ON(power_iterator->bf_vif))
580 power_iterator->bf_vif = vif;
Alexander Bondar7303dd7f2014-02-03 21:57:28 +0200581
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200582 break;
583
584 default:
585 break;
586 }
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300587}
588
Luciano Coelhob1873302014-08-08 17:12:07 +0300589static void iwl_mvm_power_set_pm(struct iwl_mvm *mvm,
590 struct iwl_power_vifs *vifs)
Alexander Bondar1c2abf72013-08-27 20:31:48 +0300591{
Avri Altman19889022014-03-19 07:25:06 +0200592 struct iwl_mvm_vif *bss_mvmvif = NULL;
593 struct iwl_mvm_vif *p2p_mvmvif = NULL;
594 struct iwl_mvm_vif *ap_mvmvif = NULL;
595 bool client_same_channel = false;
596 bool ap_same_channel = false;
597
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200598 lockdep_assert_held(&mvm->mutex);
599
Luciano Coelho128aa942014-08-08 18:36:22 +0300600 /* set pm_enable to false */
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200601 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
Luciano Coelho128aa942014-08-08 18:36:22 +0300602 IEEE80211_IFACE_ITER_NORMAL,
603 iwl_mvm_power_disable_pm_iterator,
604 NULL);
Avri Altman19889022014-03-19 07:25:06 +0200605
606 if (vifs->bss_vif)
607 bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif);
608
609 if (vifs->p2p_vif)
610 p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif);
611
612 if (vifs->ap_vif)
613 ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif);
614
615 /* enable PM on bss if bss stand alone */
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300616 if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active &&
617 !vifs->bss_tdls) {
Avri Altman19889022014-03-19 07:25:06 +0200618 bss_mvmvif->pm_enabled = true;
619 return;
620 }
621
622 /* enable PM on p2p if p2p stand alone */
Arik Nemtsovfa3d07e2014-05-15 18:59:32 +0300623 if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active &&
624 !vifs->p2p_tdls) {
Avri Altman19889022014-03-19 07:25:06 +0200625 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
626 p2p_mvmvif->pm_enabled = true;
627 return;
628 }
629
630 if (vifs->bss_active && vifs->p2p_active)
631 client_same_channel = (bss_mvmvif->phy_ctxt->id ==
632 p2p_mvmvif->phy_ctxt->id);
633 if (vifs->bss_active && vifs->ap_active)
634 ap_same_channel = (bss_mvmvif->phy_ctxt->id ==
635 ap_mvmvif->phy_ctxt->id);
636
Avri Altman63ef81c2014-04-02 07:54:07 +0300637 /* clients are not stand alone: enable PM if DCM */
638 if (!(client_same_channel || ap_same_channel) &&
Avri Altman19889022014-03-19 07:25:06 +0200639 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) {
Avri Altman63ef81c2014-04-02 07:54:07 +0300640 if (vifs->bss_active)
Avri Altman19889022014-03-19 07:25:06 +0200641 bss_mvmvif->pm_enabled = true;
Avri Altman63ef81c2014-04-02 07:54:07 +0300642 if (vifs->p2p_active &&
643 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM))
644 p2p_mvmvif->pm_enabled = true;
645 return;
Avri Altman19889022014-03-19 07:25:06 +0200646 }
647
648 /*
649 * There is only one channel in the system and there are only
650 * bss and p2p clients that share it
651 */
652 if (client_same_channel && !vifs->ap_active &&
653 (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM)) {
654 /* share same channel*/
655 bss_mvmvif->pm_enabled = true;
656 if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)
657 p2p_mvmvif->pm_enabled = true;
658 }
Emmanuel Grumbache5e7aa82014-01-27 16:57:33 +0200659}
660
Alexander Bondarb571a692013-05-21 14:49:09 +0300661#ifdef CONFIG_IWLWIFI_DEBUGFS
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200662int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm,
663 struct ieee80211_vif *vif, char *buf,
664 int bufsz)
Alexander Bondare811ada2013-03-10 15:29:44 +0200665{
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200666 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondare811ada2013-03-10 15:29:44 +0200667 struct iwl_mac_power_cmd cmd = {};
668 int pos = 0;
669
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200670 mutex_lock(&mvm->mutex);
671 memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd));
672 mutex_unlock(&mvm->mutex);
Alexander Bondare811ada2013-03-10 15:29:44 +0200673
Alexander Bondare811ada2013-03-10 15:29:44 +0200674 pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n",
675 iwlmvm_mod_params.power_scheme);
676 pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n",
677 le16_to_cpu(cmd.flags));
678 pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n",
679 le16_to_cpu(cmd.keep_alive_seconds));
680
Alexander Bondar175a70b2013-04-14 20:59:37 +0300681 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)))
682 return pos;
683
684 pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n",
685 (cmd.flags &
686 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0);
687 pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n",
688 cmd.skip_dtim_periods);
689 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) {
690 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n",
691 le32_to_cpu(cmd.rx_data_timeout));
692 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n",
693 le32_to_cpu(cmd.tx_data_timeout));
Alexander Bondare811ada2013-03-10 15:29:44 +0200694 }
Alexander Bondar175a70b2013-04-14 20:59:37 +0300695 if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK))
696 pos += scnprintf(buf+pos, bufsz-pos,
697 "lprx_rssi_threshold = %d\n",
698 cmd.lprx_rssi_threshold);
699
700 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)))
701 return pos;
702
703 pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n",
704 le32_to_cpu(cmd.rx_data_timeout_uapsd));
705 pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n",
706 le32_to_cpu(cmd.tx_data_timeout_uapsd));
707 pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid);
708 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n",
709 cmd.uapsd_ac_flags);
710 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n",
711 cmd.uapsd_max_sp);
712 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n",
713 cmd.heavy_tx_thld_packets);
714 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n",
715 cmd.heavy_rx_thld_packets);
716 pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n",
717 cmd.heavy_tx_thld_percentage);
718 pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n",
719 cmd.heavy_rx_thld_percentage);
720 pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n",
721 (cmd.flags &
722 cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ?
723 1 : 0);
724
725 if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)))
726 return pos;
727
728 pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n",
729 cmd.snooze_interval);
730 pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n",
731 cmd.snooze_window);
732
Alexander Bondare811ada2013-03-10 15:29:44 +0200733 return pos;
734}
735
Alexander Bondarb571a692013-05-21 14:49:09 +0300736void
737iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif,
738 struct iwl_beacon_filter_cmd *cmd)
739{
740 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
741 struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf;
742
743 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300744 cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300745 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA)
746 cmd->bf_roaming_energy_delta =
Hila Gonen5dca7c22013-07-16 11:15:35 +0300747 cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta);
Alexander Bondarb571a692013-05-21 14:49:09 +0300748 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300749 cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state);
750 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD)
751 cmd->bf_temp_threshold =
752 cpu_to_le32(dbgfs_bf->bf_temp_threshold);
753 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER)
754 cmd->bf_temp_fast_filter =
755 cpu_to_le32(dbgfs_bf->bf_temp_fast_filter);
756 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER)
757 cmd->bf_temp_slow_filter =
758 cpu_to_le32(dbgfs_bf->bf_temp_slow_filter);
Alexander Bondarb571a692013-05-21 14:49:09 +0300759 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300760 cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag);
Alexander Bondarb571a692013-05-21 14:49:09 +0300761 if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER)
762 cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer);
763 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER)
764 cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer);
765 if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT)
Hila Gonen5dca7c22013-07-16 11:15:35 +0300766 cmd->ba_enable_beacon_abort =
767 cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort);
Alexander Bondarb571a692013-05-21 14:49:09 +0300768}
769#endif
770
Eliad Peller3dd37d02014-01-07 14:00:24 +0200771static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
772 struct ieee80211_vif *vif,
773 struct iwl_beacon_filter_cmd *cmd,
774 u32 cmd_flags,
775 bool d0i3)
Hila Gonen7df15b12012-12-12 11:16:19 +0200776{
777 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
Alexander Bondar071d49902013-05-06 13:03:59 +0300778 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200779
Avri Altmanfa7b2e72014-05-20 08:03:24 +0300780 if (mvmvif != mvm->bf_allowed_vif || !vif->bss_conf.dtim_period ||
Hila Gonen7df15b12012-12-12 11:16:19 +0200781 vif->type != NL80211_IFTYPE_STATION || vif->p2p)
782 return 0;
783
Eliad Peller3dd37d02014-01-07 14:00:24 +0200784 iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd);
785 if (!d0i3)
786 iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd);
787 ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300788
Eliad Peller3dd37d02014-01-07 14:00:24 +0200789 /* don't change bf_enabled in case of temporary d0i3 configuration */
790 if (!ret && !d0i3)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300791 mvmvif->bf_data.bf_enabled = true;
Alexander Bondar071d49902013-05-06 13:03:59 +0300792
793 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200794}
795
Eliad Peller3dd37d02014-01-07 14:00:24 +0200796int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm,
797 struct ieee80211_vif *vif,
798 u32 flags)
799{
800 struct iwl_beacon_filter_cmd cmd = {
801 IWL_BF_CMD_CONFIG_DEFAULTS,
802 .bf_enable_beacon_filter = cpu_to_le32(1),
803 };
804
805 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false);
806}
807
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300808static int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm,
809 struct ieee80211_vif *vif,
810 bool enable)
Avri Altmanfa7b2e72014-05-20 08:03:24 +0300811{
812 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
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 if (!mvmvif->bf_data.bf_enabled)
819 return 0;
820
821 if (mvm->cur_ucode == IWL_UCODE_WOWLAN)
822 cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3);
823
824 mvmvif->bf_data.ba_enabled = enable;
825 return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, 0, false);
826}
827
Hila Gonen7df15b12012-12-12 11:16:19 +0200828int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm,
Eliad Peller3dd37d02014-01-07 14:00:24 +0200829 struct ieee80211_vif *vif,
830 u32 flags)
Hila Gonen7df15b12012-12-12 11:16:19 +0200831{
Alexander Bondar071d49902013-05-06 13:03:59 +0300832 struct iwl_beacon_filter_cmd cmd = {};
833 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
834 int ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200835
Emmanuel Grumbach73e5f2c2014-03-30 08:57:30 +0300836 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
Hila Gonen7df15b12012-12-12 11:16:19 +0200837 return 0;
838
Eliad Peller3dd37d02014-01-07 14:00:24 +0200839 ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags);
Alexander Bondar071d49902013-05-06 13:03:59 +0300840
841 if (!ret)
Andrei Otcheretianskia20fd392013-07-21 17:23:59 +0300842 mvmvif->bf_data.bf_enabled = false;
Alexander Bondar071d49902013-05-06 13:03:59 +0300843
844 return ret;
Hila Gonen7df15b12012-12-12 11:16:19 +0200845}
Alexander Bondare811ada2013-03-10 15:29:44 +0200846
Luciano Coelho2533edc2014-08-08 19:50:46 +0300847static int iwl_mvm_power_set_ps(struct iwl_mvm *mvm)
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300848{
Luciano Coelho128aa942014-08-08 18:36:22 +0300849 bool disable_ps;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300850 int ret;
851
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300852 /* disable PS if CAM */
Luciano Coelhob1873302014-08-08 17:12:07 +0300853 disable_ps = (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM);
Luciano Coelho2533edc2014-08-08 19:50:46 +0300854 /* ...or if any of the vifs require PS to be off */
855 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
856 IEEE80211_IFACE_ITER_NORMAL,
857 iwl_mvm_power_ps_disabled_iterator,
858 &disable_ps);
Luciano Coelhob1873302014-08-08 17:12:07 +0300859
860 /* update device power state if it has changed */
861 if (mvm->ps_disabled != disable_ps) {
862 bool old_ps_disabled = mvm->ps_disabled;
863
864 mvm->ps_disabled = disable_ps;
865 ret = iwl_mvm_power_update_device(mvm);
866 if (ret) {
867 mvm->ps_disabled = old_ps_disabled;
868 return ret;
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300869 }
870 }
871
Luciano Coelho128aa942014-08-08 18:36:22 +0300872 return 0;
873}
874
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300875static int iwl_mvm_power_set_ba(struct iwl_mvm *mvm,
876 struct iwl_power_vifs *vifs)
Luciano Coelho128aa942014-08-08 18:36:22 +0300877{
878 struct iwl_mvm_vif *mvmvif;
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300879 bool ba_enable;
880
881 if (!vifs->bf_vif)
882 return 0;
883
884 mvmvif = iwl_mvm_vif_from_mac80211(vifs->bf_vif);
885
886 ba_enable = !(!mvmvif->pm_enabled || mvm->ps_disabled ||
887 !vifs->bf_vif->bss_conf.ps ||
888 iwl_mvm_vif_low_latency(mvmvif));
889
890 return iwl_mvm_update_beacon_abort(mvm, vifs->bf_vif, ba_enable);
891}
892
893int iwl_mvm_power_update_ps(struct iwl_mvm *mvm)
894{
Luciano Coelho128aa942014-08-08 18:36:22 +0300895 struct iwl_power_vifs vifs = {
896 .mvm = mvm,
897 };
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300898 int ret;
899
900 lockdep_assert_held(&mvm->mutex);
901
902 /* get vifs info */
903 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
904 IEEE80211_IFACE_ITER_NORMAL,
905 iwl_mvm_power_get_vifs_iterator, &vifs);
906
Luciano Coelho2533edc2014-08-08 19:50:46 +0300907 ret = iwl_mvm_power_set_ps(mvm);
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300908 if (ret)
909 return ret;
910
911 return iwl_mvm_power_set_ba(mvm, &vifs);
912}
913
914int iwl_mvm_power_update_mac(struct iwl_mvm *mvm)
915{
916 struct iwl_power_vifs vifs = {
917 .mvm = mvm,
918 };
Luciano Coelho128aa942014-08-08 18:36:22 +0300919 int ret;
920
921 lockdep_assert_held(&mvm->mutex);
922
923 /* get vifs info */
924 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
925 IEEE80211_IFACE_ITER_NORMAL,
926 iwl_mvm_power_get_vifs_iterator, &vifs);
927
928 iwl_mvm_power_set_pm(mvm, &vifs);
929
Luciano Coelho2533edc2014-08-08 19:50:46 +0300930 ret = iwl_mvm_power_set_ps(mvm);
Luciano Coelho128aa942014-08-08 18:36:22 +0300931 if (ret)
932 return ret;
933
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300934 if (vifs.bss_vif) {
935 ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif);
936 if (ret)
937 return ret;
938 }
939
940 if (vifs.p2p_vif) {
941 ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif);
942 if (ret)
943 return ret;
944 }
945
Luciano Coelhoef9203d2014-08-08 19:18:35 +0300946 return iwl_mvm_power_set_ba(mvm, &vifs);
Emmanuel Grumbach13b72322014-05-20 11:28:18 +0300947}
948
Eliad Peller3dd37d02014-01-07 14:00:24 +0200949int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm,
950 struct ieee80211_vif *vif,
951 bool enable, u32 flags)
952{
953 int ret;
954 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
955 struct iwl_mac_power_cmd cmd = {};
956
957 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
958 return 0;
959
960 if (!vif->bss_conf.assoc)
961 return 0;
962
963 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
964 if (enable) {
965 /* configure skip over dtim up to 300 msec */
966 int dtimper = mvm->hw->conf.ps_dtim_period ?: 1;
967 int dtimper_msec = dtimper * vif->bss_conf.beacon_int;
968
969 if (WARN_ON(!dtimper_msec))
970 return 0;
971
Eliad Peller3dd37d02014-01-07 14:00:24 +0200972 cmd.skip_dtim_periods = 300 / dtimper_msec;
Eliad Peller6f361052014-05-12 14:22:20 +0300973 if (cmd.skip_dtim_periods)
974 cmd.flags |=
975 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Eliad Peller3dd37d02014-01-07 14:00:24 +0200976 }
977 iwl_mvm_power_log(mvm, &cmd);
Emmanuel Grumbach474b50c2014-01-28 09:13:04 +0200978#ifdef CONFIG_IWLWIFI_DEBUGFS
979 memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd));
980#endif
Eliad Peller3dd37d02014-01-07 14:00:24 +0200981 ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags,
982 sizeof(cmd), &cmd);
983 if (ret)
984 return ret;
985
986 /* configure beacon filtering */
987 if (mvmvif != mvm->bf_allowed_vif)
988 return 0;
989
990 if (enable) {
991 struct iwl_beacon_filter_cmd cmd_bf = {
992 IWL_BF_CMD_CONFIG_D0I3,
993 .bf_enable_beacon_filter = cpu_to_le32(1),
994 };
995 ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf,
996 flags, true);
997 } else {
998 if (mvmvif->bf_data.bf_enabled)
999 ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags);
1000 else
1001 ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags);
1002 }
1003
1004 return ret;
1005}