Commit | Line | Data |
---|---|---|
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 | * | |
51368bf7 | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
8ca151b5 JB |
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 | * | |
51368bf7 | 33 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
8ca151b5 JB |
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> | |
8ca151b5 JB |
67 | |
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 | ||
d623d24a | 77 | static |
e811ada7 | 78 | int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm, |
3dd37d05 EP |
79 | struct iwl_beacon_filter_cmd *cmd, |
80 | u32 flags) | |
071d4990 | 81 | { |
d623d24a EG |
82 | 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)); | |
104 | ||
105 | return iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, flags, | |
106 | sizeof(struct iwl_beacon_filter_cmd), cmd); | |
071d4990 AB |
107 | } |
108 | ||
a20fd398 AO |
109 | static |
110 | void 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 | ||
e811ada7 AB |
126 | int iwl_mvm_update_beacon_abort(struct iwl_mvm *mvm, |
127 | struct ieee80211_vif *vif, bool enable) | |
071d4990 AB |
128 | { |
129 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
130 | struct iwl_beacon_filter_cmd cmd = { | |
131 | IWL_BF_CMD_CONFIG_DEFAULTS, | |
5dca7c24 HG |
132 | .bf_enable_beacon_filter = cpu_to_le32(1), |
133 | .ba_enable_beacon_abort = cpu_to_le32(enable), | |
071d4990 AB |
134 | }; |
135 | ||
a20fd398 | 136 | if (!mvmvif->bf_data.bf_enabled) |
071d4990 AB |
137 | return 0; |
138 | ||
8434925f AB |
139 | if (mvm->cur_ucode == IWL_UCODE_WOWLAN) |
140 | cmd.ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_D3); | |
141 | ||
a20fd398 AO |
142 | mvmvif->bf_data.ba_enabled = enable; |
143 | iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, &cmd); | |
b571a697 | 144 | iwl_mvm_beacon_filter_debugfs_parameters(vif, &cmd); |
3dd37d05 | 145 | return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, CMD_SYNC); |
071d4990 AB |
146 | } |
147 | ||
3f0b2b3e | 148 | static void iwl_mvm_power_log(struct iwl_mvm *mvm, |
e811ada7 | 149 | struct iwl_mac_power_cmd *cmd) |
3f0b2b3e AB |
150 | { |
151 | IWL_DEBUG_POWER(mvm, | |
e811ada7 AB |
152 | "Sending power table command on mac id 0x%X for power level %d, flags = 0x%X\n", |
153 | cmd->id_and_color, iwlmvm_mod_params.power_scheme, | |
3f0b2b3e | 154 | le16_to_cpu(cmd->flags)); |
e811ada7 AB |
155 | IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n", |
156 | le16_to_cpu(cmd->keep_alive_seconds)); | |
3f0b2b3e | 157 | |
e3c588ec AB |
158 | if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) { |
159 | IWL_DEBUG_POWER(mvm, "Disable power management\n"); | |
160 | return; | |
161 | } | |
162 | ||
163 | IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n", | |
164 | le32_to_cpu(cmd->rx_data_timeout)); | |
165 | IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n", | |
166 | le32_to_cpu(cmd->tx_data_timeout)); | |
167 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) | |
168 | IWL_DEBUG_POWER(mvm, "DTIM periods to skip = %u\n", | |
169 | cmd->skip_dtim_periods); | |
170 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK)) | |
171 | IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n", | |
172 | cmd->lprx_rssi_threshold); | |
173 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK)) { | |
174 | IWL_DEBUG_POWER(mvm, "uAPSD enabled\n"); | |
175 | IWL_DEBUG_POWER(mvm, "Rx timeout (uAPSD) = %u usec\n", | |
176 | le32_to_cpu(cmd->rx_data_timeout_uapsd)); | |
177 | IWL_DEBUG_POWER(mvm, "Tx timeout (uAPSD) = %u usec\n", | |
178 | le32_to_cpu(cmd->tx_data_timeout_uapsd)); | |
179 | IWL_DEBUG_POWER(mvm, "QNDP TID = %d\n", cmd->qndp_tid); | |
180 | IWL_DEBUG_POWER(mvm, "ACs flags = 0x%x\n", cmd->uapsd_ac_flags); | |
181 | IWL_DEBUG_POWER(mvm, "Max SP = %d\n", cmd->uapsd_max_sp); | |
3f0b2b3e AB |
182 | } |
183 | } | |
184 | ||
175a70b7 AB |
185 | static void iwl_mvm_power_configure_uapsd(struct iwl_mvm *mvm, |
186 | struct ieee80211_vif *vif, | |
187 | struct iwl_mac_power_cmd *cmd) | |
188 | { | |
189 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
190 | enum ieee80211_ac_numbers ac; | |
191 | bool tid_found = false; | |
192 | ||
193 | for (ac = IEEE80211_AC_VO; ac <= IEEE80211_AC_BK; ac++) { | |
194 | if (!mvmvif->queue_params[ac].uapsd) | |
195 | continue; | |
196 | ||
197 | if (mvm->cur_ucode != IWL_UCODE_WOWLAN) | |
198 | cmd->flags |= | |
199 | cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK); | |
200 | ||
201 | cmd->uapsd_ac_flags |= BIT(ac); | |
202 | ||
203 | /* QNDP TID - the highest TID with no admission control */ | |
204 | if (!tid_found && !mvmvif->queue_params[ac].acm) { | |
205 | tid_found = true; | |
206 | switch (ac) { | |
207 | case IEEE80211_AC_VO: | |
208 | cmd->qndp_tid = 6; | |
209 | break; | |
210 | case IEEE80211_AC_VI: | |
211 | cmd->qndp_tid = 5; | |
212 | break; | |
213 | case IEEE80211_AC_BE: | |
214 | cmd->qndp_tid = 0; | |
215 | break; | |
216 | case IEEE80211_AC_BK: | |
217 | cmd->qndp_tid = 1; | |
218 | break; | |
219 | } | |
220 | } | |
221 | } | |
222 | ||
223 | if (!(cmd->flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) | |
224 | return; | |
225 | ||
226 | cmd->flags |= cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK); | |
227 | ||
228 | if (cmd->uapsd_ac_flags == (BIT(IEEE80211_AC_VO) | | |
229 | BIT(IEEE80211_AC_VI) | | |
230 | BIT(IEEE80211_AC_BE) | | |
231 | BIT(IEEE80211_AC_BK))) { | |
232 | cmd->flags |= cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK); | |
233 | cmd->snooze_interval = cpu_to_le16(IWL_MVM_PS_SNOOZE_INTERVAL); | |
234 | cmd->snooze_window = (mvm->cur_ucode == IWL_UCODE_WOWLAN) ? | |
235 | cpu_to_le16(IWL_MVM_WOWLAN_PS_SNOOZE_WINDOW) : | |
236 | cpu_to_le16(IWL_MVM_PS_SNOOZE_WINDOW); | |
237 | } | |
238 | ||
239 | cmd->uapsd_max_sp = IWL_UAPSD_MAX_SP; | |
240 | ||
241 | if (mvm->cur_ucode == IWL_UCODE_WOWLAN || cmd->flags & | |
242 | cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) { | |
243 | cmd->rx_data_timeout_uapsd = | |
244 | cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT); | |
245 | cmd->tx_data_timeout_uapsd = | |
246 | cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT); | |
247 | } else { | |
248 | cmd->rx_data_timeout_uapsd = | |
249 | cpu_to_le32(IWL_MVM_UAPSD_RX_DATA_TIMEOUT); | |
250 | cmd->tx_data_timeout_uapsd = | |
251 | cpu_to_le32(IWL_MVM_UAPSD_TX_DATA_TIMEOUT); | |
252 | } | |
253 | ||
254 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK)) { | |
255 | cmd->heavy_tx_thld_packets = | |
256 | IWL_MVM_PS_SNOOZE_HEAVY_TX_THLD_PACKETS; | |
257 | cmd->heavy_rx_thld_packets = | |
258 | IWL_MVM_PS_SNOOZE_HEAVY_RX_THLD_PACKETS; | |
259 | } else { | |
260 | cmd->heavy_tx_thld_packets = | |
261 | IWL_MVM_PS_HEAVY_TX_THLD_PACKETS; | |
262 | cmd->heavy_rx_thld_packets = | |
263 | IWL_MVM_PS_HEAVY_RX_THLD_PACKETS; | |
264 | } | |
265 | cmd->heavy_tx_thld_percentage = | |
266 | IWL_MVM_PS_HEAVY_TX_THLD_PERCENT; | |
267 | cmd->heavy_rx_thld_percentage = | |
268 | IWL_MVM_PS_HEAVY_RX_THLD_PERCENT; | |
269 | } | |
270 | ||
0534528e AA |
271 | static void iwl_mvm_binding_iterator(void *_data, u8 *mac, |
272 | struct ieee80211_vif *vif) | |
273 | { | |
274 | unsigned long *data = _data; | |
275 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
276 | ||
277 | if (!mvmvif->phy_ctxt) | |
278 | return; | |
279 | ||
280 | if (vif->type == NL80211_IFTYPE_STATION || | |
281 | vif->type == NL80211_IFTYPE_AP) | |
282 | __set_bit(mvmvif->phy_ctxt->id, data); | |
283 | } | |
284 | ||
c6e37a68 AA |
285 | static bool iwl_mvm_power_allow_uapsd(struct iwl_mvm *mvm, |
286 | struct ieee80211_vif *vif) | |
287 | { | |
288 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
0534528e AA |
289 | unsigned long phy_ctxt_counter = 0; |
290 | ||
291 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, | |
292 | IEEE80211_IFACE_ITER_NORMAL, | |
293 | iwl_mvm_binding_iterator, | |
294 | &phy_ctxt_counter); | |
c6e37a68 AA |
295 | |
296 | if (!memcmp(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid, | |
297 | ETH_ALEN)) | |
298 | return false; | |
299 | ||
300 | if (vif->p2p && | |
301 | !(mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PS_UAPSD)) | |
302 | return false; | |
303 | /* | |
304 | * Avoid using uAPSD if P2P client is associated to GO that uses | |
305 | * opportunistic power save. This is due to current FW limitation. | |
306 | */ | |
307 | if (vif->p2p && | |
308 | (vif->bss_conf.p2p_noa_attr.oppps_ctwindow & | |
309 | IEEE80211_P2P_OPPPS_ENABLE_BIT)) | |
310 | return false; | |
311 | ||
0534528e AA |
312 | /* |
313 | * Avoid using uAPSD if client is in DCM - | |
314 | * low latency issue in Miracast | |
315 | */ | |
316 | if (hweight8(phy_ctxt_counter) >= 2) | |
317 | return false; | |
318 | ||
c6e37a68 AA |
319 | return true; |
320 | } | |
321 | ||
e811ada7 AB |
322 | static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm, |
323 | struct ieee80211_vif *vif, | |
324 | struct iwl_mac_power_cmd *cmd) | |
8ca151b5 JB |
325 | { |
326 | struct ieee80211_hw *hw = mvm->hw; | |
8ca151b5 JB |
327 | struct ieee80211_chanctx_conf *chanctx_conf; |
328 | struct ieee80211_channel *chan; | |
329 | int dtimper, dtimper_msec; | |
330 | int keep_alive; | |
331 | bool radar_detect = false; | |
b571a697 AB |
332 | struct iwl_mvm_vif *mvmvif __maybe_unused = |
333 | iwl_mvm_vif_from_mac80211(vif); | |
8ca151b5 | 334 | |
e811ada7 AB |
335 | cmd->id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
336 | mvmvif->color)); | |
337 | dtimper = hw->conf.ps_dtim_period ?: 1; | |
338 | ||
e16cf7ec AB |
339 | /* |
340 | * Regardless of power management state the driver must set | |
341 | * keep alive period. FW will use it for sending keep alive NDPs | |
e811ada7 AB |
342 | * immediately after association. Check that keep alive period |
343 | * is at least 3 * DTIM | |
e16cf7ec | 344 | */ |
e811ada7 AB |
345 | dtimper_msec = dtimper * vif->bss_conf.beacon_int; |
346 | keep_alive = max_t(int, 3 * dtimper_msec, | |
347 | MSEC_PER_SEC * POWER_KEEP_ALIVE_PERIOD_SEC); | |
348 | keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC); | |
349 | cmd->keep_alive_seconds = cpu_to_le16(keep_alive); | |
e16cf7ec | 350 | |
e5e7aa8e | 351 | if (mvm->ps_disabled) |
8ca151b5 JB |
352 | return; |
353 | ||
9a613048 AB |
354 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK); |
355 | ||
e5e7aa8e | 356 | if (!vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif) || |
19889025 | 357 | !mvmvif->pm_enabled) |
9a613048 AB |
358 | return; |
359 | ||
360 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK); | |
8ca151b5 | 361 | |
bd4ace2a AB |
362 | if (vif->bss_conf.beacon_rate && |
363 | (vif->bss_conf.beacon_rate->bitrate == 10 || | |
364 | vif->bss_conf.beacon_rate->bitrate == 60)) { | |
365 | cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK); | |
e811ada7 | 366 | cmd->lprx_rssi_threshold = POWER_LPRX_RSSI_THRESHOLD; |
bd4ace2a AB |
367 | } |
368 | ||
8ca151b5 JB |
369 | /* Check if radar detection is required on current channel */ |
370 | rcu_read_lock(); | |
371 | chanctx_conf = rcu_dereference(vif->chanctx_conf); | |
372 | WARN_ON(!chanctx_conf); | |
373 | if (chanctx_conf) { | |
374 | chan = chanctx_conf->def.chan; | |
375 | radar_detect = chan->flags & IEEE80211_CHAN_RADAR; | |
376 | } | |
377 | rcu_read_unlock(); | |
378 | ||
379 | /* Check skip over DTIM conditions */ | |
380 | if (!radar_detect && (dtimper <= 10) && | |
ee1e8422 AB |
381 | (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP || |
382 | mvm->cur_ucode == IWL_UCODE_WOWLAN)) { | |
f4a3e2fe | 383 | cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
e811ada7 | 384 | cmd->skip_dtim_periods = 3; |
5b1dbfc3 | 385 | } |
8ca151b5 | 386 | |
ee1e8422 | 387 | if (mvm->cur_ucode != IWL_UCODE_WOWLAN) { |
99545924 JB |
388 | cmd->rx_data_timeout = |
389 | cpu_to_le32(IWL_MVM_DEFAULT_PS_RX_DATA_TIMEOUT); | |
390 | cmd->tx_data_timeout = | |
391 | cpu_to_le32(IWL_MVM_DEFAULT_PS_TX_DATA_TIMEOUT); | |
ee1e8422 | 392 | } else { |
99545924 JB |
393 | cmd->rx_data_timeout = |
394 | cpu_to_le32(IWL_MVM_WOWLAN_PS_RX_DATA_TIMEOUT); | |
395 | cmd->tx_data_timeout = | |
396 | cpu_to_le32(IWL_MVM_WOWLAN_PS_TX_DATA_TIMEOUT); | |
ee1e8422 | 397 | } |
b571a697 | 398 | |
c6e37a68 | 399 | if (iwl_mvm_power_allow_uapsd(mvm, vif)) |
175a70b7 | 400 | iwl_mvm_power_configure_uapsd(mvm, vif, cmd); |
e3c588ec | 401 | |
b571a697 AB |
402 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
403 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_KEEP_ALIVE) | |
e811ada7 AB |
404 | cmd->keep_alive_seconds = |
405 | cpu_to_le16(mvmvif->dbgfs_pm.keep_alive_seconds); | |
b571a697 AB |
406 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_OVER_DTIM) { |
407 | if (mvmvif->dbgfs_pm.skip_over_dtim) | |
408 | cmd->flags |= | |
409 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); | |
410 | else | |
411 | cmd->flags &= | |
412 | cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK); | |
413 | } | |
414 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_RX_DATA_TIMEOUT) | |
415 | cmd->rx_data_timeout = | |
416 | cpu_to_le32(mvmvif->dbgfs_pm.rx_data_timeout); | |
417 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_TX_DATA_TIMEOUT) | |
418 | cmd->tx_data_timeout = | |
419 | cpu_to_le32(mvmvif->dbgfs_pm.tx_data_timeout); | |
420 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS) | |
e811ada7 | 421 | cmd->skip_dtim_periods = mvmvif->dbgfs_pm.skip_dtim_periods; |
bd4ace2a AB |
422 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_ENA) { |
423 | if (mvmvif->dbgfs_pm.lprx_ena) | |
424 | cmd->flags |= cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK); | |
425 | else | |
426 | cmd->flags &= cpu_to_le16(~POWER_FLAGS_LPRX_ENA_MSK); | |
427 | } | |
428 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_LPRX_RSSI_THRESHOLD) | |
e811ada7 | 429 | cmd->lprx_rssi_threshold = mvmvif->dbgfs_pm.lprx_rssi_threshold; |
89716344 AB |
430 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_SNOOZE_ENABLE) { |
431 | if (mvmvif->dbgfs_pm.snooze_ena) | |
432 | cmd->flags |= | |
433 | cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK); | |
434 | else | |
435 | cmd->flags &= | |
436 | cpu_to_le16(~POWER_FLAGS_SNOOZE_ENA_MSK); | |
437 | } | |
e45a941d AB |
438 | if (mvmvif->dbgfs_pm.mask & MVM_DEBUGFS_PM_UAPSD_MISBEHAVING) { |
439 | u16 flag = POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK; | |
440 | if (mvmvif->dbgfs_pm.uapsd_misbehaving) | |
441 | cmd->flags |= cpu_to_le16(flag); | |
442 | else | |
443 | cmd->flags &= cpu_to_le16(flag); | |
444 | } | |
b571a697 | 445 | #endif /* CONFIG_IWLWIFI_DEBUGFS */ |
8ca151b5 JB |
446 | } |
447 | ||
e5e7aa8e | 448 | static int iwl_mvm_power_send_cmd(struct iwl_mvm *mvm, |
e811ada7 | 449 | struct ieee80211_vif *vif) |
8ca151b5 | 450 | { |
e811ada7 | 451 | struct iwl_mac_power_cmd cmd = {}; |
8ca151b5 | 452 | |
f4a3e2fe | 453 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); |
3f0b2b3e | 454 | iwl_mvm_power_log(mvm, &cmd); |
474b50c3 EG |
455 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
456 | memcpy(&iwl_mvm_vif_from_mac80211(vif)->mac_pwr_cmd, &cmd, sizeof(cmd)); | |
457 | #endif | |
8ca151b5 | 458 | |
06280a2b EG |
459 | return iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, CMD_SYNC, |
460 | sizeof(cmd), &cmd); | |
461 | } | |
462 | ||
e5e7aa8e | 463 | int iwl_mvm_power_update_device(struct iwl_mvm *mvm) |
64b928c4 AB |
464 | { |
465 | struct iwl_device_power_cmd cmd = { | |
466 | .flags = cpu_to_le16(DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK), | |
467 | }; | |
468 | ||
e5e7aa8e EG |
469 | if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) |
470 | mvm->ps_disabled = true; | |
471 | ||
472 | if (mvm->ps_disabled) | |
64b928c4 AB |
473 | cmd.flags |= cpu_to_le16(DEVICE_POWER_FLAGS_CAM_MSK); |
474 | ||
475 | #ifdef CONFIG_IWLWIFI_DEBUGFS | |
476 | if ((mvm->cur_ucode == IWL_UCODE_WOWLAN) ? mvm->disable_power_off_d3 : | |
477 | mvm->disable_power_off) | |
478 | cmd.flags &= | |
479 | cpu_to_le16(~DEVICE_POWER_FLAGS_POWER_SAVE_ENA_MSK); | |
480 | #endif | |
481 | IWL_DEBUG_POWER(mvm, | |
482 | "Sending device power command with flags = 0x%X\n", | |
483 | cmd.flags); | |
484 | ||
485 | return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_SYNC, sizeof(cmd), | |
486 | &cmd); | |
487 | } | |
488 | ||
175a70b7 AB |
489 | void iwl_mvm_power_vif_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
490 | { | |
491 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
492 | ||
493 | if (memcmp(vif->bss_conf.bssid, mvmvif->uapsd_misbehaving_bssid, | |
494 | ETH_ALEN)) | |
495 | memset(mvmvif->uapsd_misbehaving_bssid, 0, ETH_ALEN); | |
496 | } | |
497 | ||
498 | static void iwl_mvm_power_uapsd_misbehav_ap_iterator(void *_data, u8 *mac, | |
499 | struct ieee80211_vif *vif) | |
500 | { | |
501 | u8 *ap_sta_id = _data; | |
502 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
503 | ||
504 | /* The ap_sta_id is not expected to change during current association | |
505 | * so no explicit protection is needed | |
506 | */ | |
507 | if (mvmvif->ap_sta_id == *ap_sta_id) | |
508 | memcpy(mvmvif->uapsd_misbehaving_bssid, vif->bss_conf.bssid, | |
509 | ETH_ALEN); | |
510 | } | |
511 | ||
512 | int iwl_mvm_power_uapsd_misbehaving_ap_notif(struct iwl_mvm *mvm, | |
513 | struct iwl_rx_cmd_buffer *rxb, | |
514 | struct iwl_device_cmd *cmd) | |
515 | { | |
516 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
517 | struct iwl_uapsd_misbehaving_ap_notif *notif = (void *)pkt->data; | |
518 | u8 ap_sta_id = le32_to_cpu(notif->sta_id); | |
519 | ||
520 | ieee80211_iterate_active_interfaces_atomic( | |
521 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
522 | iwl_mvm_power_uapsd_misbehav_ap_iterator, &ap_sta_id); | |
523 | ||
524 | return 0; | |
525 | } | |
526 | ||
19889025 | 527 | struct iwl_power_vifs { |
06280a2b | 528 | struct ieee80211_vif *bf_vif; |
e5e7aa8e | 529 | struct ieee80211_vif *bss_vif; |
8ea0c68f | 530 | struct ieee80211_vif *p2p_vif; |
19889025 AA |
531 | struct ieee80211_vif *ap_vif; |
532 | struct ieee80211_vif *monitor_vif; | |
533 | bool p2p_active; | |
534 | bool bss_active; | |
535 | bool ap_active; | |
536 | bool monitor_active; | |
06280a2b EG |
537 | }; |
538 | ||
e5e7aa8e EG |
539 | static void iwl_mvm_power_iterator(void *_data, u8 *mac, |
540 | struct ieee80211_vif *vif) | |
1c2abf72 | 541 | { |
06280a2b | 542 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
19889025 | 543 | struct iwl_power_vifs *power_iterator = _data; |
e5e7aa8e | 544 | |
19889025 | 545 | mvmvif->pm_enabled = false; |
e5e7aa8e EG |
546 | switch (ieee80211_vif_type_p2p(vif)) { |
547 | case NL80211_IFTYPE_P2P_DEVICE: | |
548 | break; | |
549 | ||
550 | case NL80211_IFTYPE_P2P_GO: | |
551 | case NL80211_IFTYPE_AP: | |
19889025 AA |
552 | /* only a single MAC of the same type */ |
553 | WARN_ON(power_iterator->ap_vif); | |
554 | power_iterator->ap_vif = vif; | |
555 | if (mvmvif->phy_ctxt) | |
556 | if (mvmvif->phy_ctxt->id < MAX_PHYS) | |
557 | power_iterator->ap_active = true; | |
e5e7aa8e EG |
558 | break; |
559 | ||
560 | case NL80211_IFTYPE_MONITOR: | |
19889025 AA |
561 | /* only a single MAC of the same type */ |
562 | WARN_ON(power_iterator->monitor_vif); | |
563 | power_iterator->monitor_vif = vif; | |
564 | if (mvmvif->phy_ctxt) | |
565 | if (mvmvif->phy_ctxt->id < MAX_PHYS) | |
566 | power_iterator->monitor_active = true; | |
e5e7aa8e EG |
567 | break; |
568 | ||
569 | case NL80211_IFTYPE_P2P_CLIENT: | |
19889025 | 570 | /* only a single MAC of the same type */ |
8ea0c68f AA |
571 | WARN_ON(power_iterator->p2p_vif); |
572 | power_iterator->p2p_vif = vif; | |
19889025 AA |
573 | if (mvmvif->phy_ctxt) |
574 | if (mvmvif->phy_ctxt->id < MAX_PHYS) | |
575 | power_iterator->p2p_active = true; | |
e5e7aa8e EG |
576 | break; |
577 | ||
578 | case NL80211_IFTYPE_STATION: | |
19889025 | 579 | /* only a single MAC of the same type */ |
e5e7aa8e EG |
580 | WARN_ON(power_iterator->bss_vif); |
581 | power_iterator->bss_vif = vif; | |
19889025 AA |
582 | if (mvmvif->phy_ctxt) |
583 | if (mvmvif->phy_ctxt->id < MAX_PHYS) | |
584 | power_iterator->bss_active = true; | |
e5e7aa8e EG |
585 | |
586 | if (mvmvif->bf_data.bf_enabled && | |
587 | !WARN_ON(power_iterator->bf_vif)) | |
588 | power_iterator->bf_vif = vif; | |
7303dd7f | 589 | |
e5e7aa8e EG |
590 | break; |
591 | ||
592 | default: | |
593 | break; | |
594 | } | |
595 | } | |
1c2abf72 | 596 | |
e5e7aa8e | 597 | static void |
19889025 AA |
598 | iwl_mvm_power_set_pm(struct iwl_mvm *mvm, |
599 | struct iwl_power_vifs *vifs) | |
e5e7aa8e | 600 | { |
19889025 AA |
601 | struct iwl_mvm_vif *bss_mvmvif = NULL; |
602 | struct iwl_mvm_vif *p2p_mvmvif = NULL; | |
603 | struct iwl_mvm_vif *ap_mvmvif = NULL; | |
604 | bool client_same_channel = false; | |
605 | bool ap_same_channel = false; | |
e5e7aa8e | 606 | |
19889025 | 607 | lockdep_assert_held(&mvm->mutex); |
06280a2b | 608 | |
19889025 | 609 | /* get vifs info + set pm_enable to false */ |
e5e7aa8e EG |
610 | ieee80211_iterate_active_interfaces_atomic(mvm->hw, |
611 | IEEE80211_IFACE_ITER_NORMAL, | |
19889025 AA |
612 | iwl_mvm_power_iterator, vifs); |
613 | ||
614 | if (vifs->bss_vif) | |
615 | bss_mvmvif = iwl_mvm_vif_from_mac80211(vifs->bss_vif); | |
616 | ||
617 | if (vifs->p2p_vif) | |
618 | p2p_mvmvif = iwl_mvm_vif_from_mac80211(vifs->p2p_vif); | |
619 | ||
620 | if (vifs->ap_vif) | |
621 | ap_mvmvif = iwl_mvm_vif_from_mac80211(vifs->ap_vif); | |
622 | ||
623 | /* enable PM on bss if bss stand alone */ | |
624 | if (vifs->bss_active && !vifs->p2p_active && !vifs->ap_active) { | |
625 | bss_mvmvif->pm_enabled = true; | |
626 | return; | |
627 | } | |
628 | ||
629 | /* enable PM on p2p if p2p stand alone */ | |
630 | if (vifs->p2p_active && !vifs->bss_active && !vifs->ap_active) { | |
631 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM) | |
632 | p2p_mvmvif->pm_enabled = true; | |
633 | return; | |
634 | } | |
635 | ||
636 | if (vifs->bss_active && vifs->p2p_active) | |
637 | client_same_channel = (bss_mvmvif->phy_ctxt->id == | |
638 | p2p_mvmvif->phy_ctxt->id); | |
639 | if (vifs->bss_active && vifs->ap_active) | |
640 | ap_same_channel = (bss_mvmvif->phy_ctxt->id == | |
641 | ap_mvmvif->phy_ctxt->id); | |
642 | ||
63ef81cf AA |
643 | /* clients are not stand alone: enable PM if DCM */ |
644 | if (!(client_same_channel || ap_same_channel) && | |
19889025 | 645 | (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_DCM)) { |
63ef81cf | 646 | if (vifs->bss_active) |
19889025 | 647 | bss_mvmvif->pm_enabled = true; |
63ef81cf AA |
648 | if (vifs->p2p_active && |
649 | (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM)) | |
650 | p2p_mvmvif->pm_enabled = true; | |
651 | return; | |
19889025 AA |
652 | } |
653 | ||
654 | /* | |
655 | * There is only one channel in the system and there are only | |
656 | * bss and p2p clients that share it | |
657 | */ | |
658 | if (client_same_channel && !vifs->ap_active && | |
659 | (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_BSS_P2P_PS_SCM)) { | |
660 | /* share same channel*/ | |
661 | bss_mvmvif->pm_enabled = true; | |
662 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_P2P_PM) | |
663 | p2p_mvmvif->pm_enabled = true; | |
664 | } | |
1c2abf72 AB |
665 | } |
666 | ||
e5e7aa8e | 667 | int iwl_mvm_power_update_mac(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
1c2abf72 | 668 | { |
19889025 AA |
669 | struct iwl_mvm_vif *mvmvif; |
670 | struct iwl_power_vifs vifs = {}; | |
e5e7aa8e EG |
671 | bool ba_enable; |
672 | int ret; | |
06280a2b EG |
673 | |
674 | lockdep_assert_held(&mvm->mutex); | |
675 | ||
19889025 | 676 | iwl_mvm_power_set_pm(mvm, &vifs); |
c1cb92fc | 677 | |
19889025 AA |
678 | /* disable PS if CAM */ |
679 | if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) { | |
680 | mvm->ps_disabled = true; | |
681 | } else { | |
e5e7aa8e | 682 | /* don't update device power state unless we add / remove monitor */ |
19889025 AA |
683 | if (vifs.monitor_vif) { |
684 | if (vifs.monitor_active) | |
685 | mvm->ps_disabled = true; | |
686 | ret = iwl_mvm_power_update_device(mvm); | |
687 | if (ret) | |
688 | return ret; | |
689 | } | |
92d85562 AB |
690 | } |
691 | ||
19889025 AA |
692 | if (vifs.bss_vif) { |
693 | ret = iwl_mvm_power_send_cmd(mvm, vifs.bss_vif); | |
e5e7aa8e EG |
694 | if (ret) |
695 | return ret; | |
696 | } | |
697 | ||
19889025 AA |
698 | if (vifs.p2p_vif) { |
699 | ret = iwl_mvm_power_send_cmd(mvm, vifs.p2p_vif); | |
8ea0c68f AA |
700 | if (ret) |
701 | return ret; | |
702 | } | |
703 | ||
19889025 | 704 | if (!vifs.bf_vif) |
e5e7aa8e | 705 | return 0; |
06280a2b | 706 | |
19889025 | 707 | vif = vifs.bf_vif; |
06280a2b EG |
708 | mvmvif = iwl_mvm_vif_from_mac80211(vif); |
709 | ||
19889025 | 710 | ba_enable = !(!mvmvif->pm_enabled || mvm->ps_disabled || |
06280a2b EG |
711 | !vif->bss_conf.ps || iwl_mvm_vif_low_latency(mvmvif)); |
712 | ||
19889025 | 713 | return iwl_mvm_update_beacon_abort(mvm, vifs.bf_vif, ba_enable); |
1c2abf72 AB |
714 | } |
715 | ||
b571a697 | 716 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
c1cb92fc EG |
717 | int iwl_mvm_power_mac_dbgfs_read(struct iwl_mvm *mvm, |
718 | struct ieee80211_vif *vif, char *buf, | |
719 | int bufsz) | |
e811ada7 | 720 | { |
474b50c3 | 721 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
e811ada7 AB |
722 | struct iwl_mac_power_cmd cmd = {}; |
723 | int pos = 0; | |
724 | ||
474b50c3 EG |
725 | mutex_lock(&mvm->mutex); |
726 | memcpy(&cmd, &mvmvif->mac_pwr_cmd, sizeof(cmd)); | |
727 | mutex_unlock(&mvm->mutex); | |
e811ada7 | 728 | |
e811ada7 AB |
729 | pos += scnprintf(buf+pos, bufsz-pos, "power_scheme = %d\n", |
730 | iwlmvm_mod_params.power_scheme); | |
731 | pos += scnprintf(buf+pos, bufsz-pos, "flags = 0x%x\n", | |
732 | le16_to_cpu(cmd.flags)); | |
733 | pos += scnprintf(buf+pos, bufsz-pos, "keep_alive = %d\n", | |
734 | le16_to_cpu(cmd.keep_alive_seconds)); | |
735 | ||
175a70b7 AB |
736 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK))) |
737 | return pos; | |
738 | ||
739 | pos += scnprintf(buf+pos, bufsz-pos, "skip_over_dtim = %d\n", | |
740 | (cmd.flags & | |
741 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) ? 1 : 0); | |
742 | pos += scnprintf(buf+pos, bufsz-pos, "skip_dtim_periods = %d\n", | |
743 | cmd.skip_dtim_periods); | |
744 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) { | |
745 | pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout = %d\n", | |
746 | le32_to_cpu(cmd.rx_data_timeout)); | |
747 | pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout = %d\n", | |
748 | le32_to_cpu(cmd.tx_data_timeout)); | |
e811ada7 | 749 | } |
175a70b7 AB |
750 | if (cmd.flags & cpu_to_le16(POWER_FLAGS_LPRX_ENA_MSK)) |
751 | pos += scnprintf(buf+pos, bufsz-pos, | |
752 | "lprx_rssi_threshold = %d\n", | |
753 | cmd.lprx_rssi_threshold); | |
754 | ||
755 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_ADVANCE_PM_ENA_MSK))) | |
756 | return pos; | |
757 | ||
758 | pos += scnprintf(buf+pos, bufsz-pos, "rx_data_timeout_uapsd = %d\n", | |
759 | le32_to_cpu(cmd.rx_data_timeout_uapsd)); | |
760 | pos += scnprintf(buf+pos, bufsz-pos, "tx_data_timeout_uapsd = %d\n", | |
761 | le32_to_cpu(cmd.tx_data_timeout_uapsd)); | |
762 | pos += scnprintf(buf+pos, bufsz-pos, "qndp_tid = %d\n", cmd.qndp_tid); | |
763 | pos += scnprintf(buf+pos, bufsz-pos, "uapsd_ac_flags = 0x%x\n", | |
764 | cmd.uapsd_ac_flags); | |
765 | pos += scnprintf(buf+pos, bufsz-pos, "uapsd_max_sp = %d\n", | |
766 | cmd.uapsd_max_sp); | |
767 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_packets = %d\n", | |
768 | cmd.heavy_tx_thld_packets); | |
769 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_packets = %d\n", | |
770 | cmd.heavy_rx_thld_packets); | |
771 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_tx_thld_percentage = %d\n", | |
772 | cmd.heavy_tx_thld_percentage); | |
773 | pos += scnprintf(buf+pos, bufsz-pos, "heavy_rx_thld_percentage = %d\n", | |
774 | cmd.heavy_rx_thld_percentage); | |
775 | pos += scnprintf(buf+pos, bufsz-pos, "uapsd_misbehaving_enable = %d\n", | |
776 | (cmd.flags & | |
777 | cpu_to_le16(POWER_FLAGS_UAPSD_MISBEHAVING_ENA_MSK)) ? | |
778 | 1 : 0); | |
779 | ||
780 | if (!(cmd.flags & cpu_to_le16(POWER_FLAGS_SNOOZE_ENA_MSK))) | |
781 | return pos; | |
782 | ||
783 | pos += scnprintf(buf+pos, bufsz-pos, "snooze_interval = %d\n", | |
784 | cmd.snooze_interval); | |
785 | pos += scnprintf(buf+pos, bufsz-pos, "snooze_window = %d\n", | |
786 | cmd.snooze_window); | |
787 | ||
e811ada7 AB |
788 | return pos; |
789 | } | |
790 | ||
b571a697 AB |
791 | void |
792 | iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif *vif, | |
793 | struct iwl_beacon_filter_cmd *cmd) | |
794 | { | |
795 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
796 | struct iwl_dbgfs_bf *dbgfs_bf = &mvmvif->dbgfs_bf; | |
797 | ||
798 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ENERGY_DELTA) | |
5dca7c24 | 799 | cmd->bf_energy_delta = cpu_to_le32(dbgfs_bf->bf_energy_delta); |
b571a697 AB |
800 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA) |
801 | cmd->bf_roaming_energy_delta = | |
5dca7c24 | 802 | cpu_to_le32(dbgfs_bf->bf_roaming_energy_delta); |
b571a697 | 803 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ROAMING_STATE) |
5dca7c24 HG |
804 | cmd->bf_roaming_state = cpu_to_le32(dbgfs_bf->bf_roaming_state); |
805 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_THRESHOLD) | |
806 | cmd->bf_temp_threshold = | |
807 | cpu_to_le32(dbgfs_bf->bf_temp_threshold); | |
808 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_FAST_FILTER) | |
809 | cmd->bf_temp_fast_filter = | |
810 | cpu_to_le32(dbgfs_bf->bf_temp_fast_filter); | |
811 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_TEMP_SLOW_FILTER) | |
812 | cmd->bf_temp_slow_filter = | |
813 | cpu_to_le32(dbgfs_bf->bf_temp_slow_filter); | |
b571a697 | 814 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_DEBUG_FLAG) |
5dca7c24 | 815 | cmd->bf_debug_flag = cpu_to_le32(dbgfs_bf->bf_debug_flag); |
b571a697 AB |
816 | if (dbgfs_bf->mask & MVM_DEBUGFS_BF_ESCAPE_TIMER) |
817 | cmd->bf_escape_timer = cpu_to_le32(dbgfs_bf->bf_escape_timer); | |
818 | if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ESCAPE_TIMER) | |
819 | cmd->ba_escape_timer = cpu_to_le32(dbgfs_bf->ba_escape_timer); | |
820 | if (dbgfs_bf->mask & MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT) | |
5dca7c24 HG |
821 | cmd->ba_enable_beacon_abort = |
822 | cpu_to_le32(dbgfs_bf->ba_enable_beacon_abort); | |
b571a697 AB |
823 | } |
824 | #endif | |
825 | ||
3dd37d05 EP |
826 | static int _iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm, |
827 | struct ieee80211_vif *vif, | |
828 | struct iwl_beacon_filter_cmd *cmd, | |
829 | u32 cmd_flags, | |
830 | bool d0i3) | |
7df15b1e HG |
831 | { |
832 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
071d4990 | 833 | int ret; |
7df15b1e HG |
834 | |
835 | if (mvmvif != mvm->bf_allowed_vif || | |
836 | vif->type != NL80211_IFTYPE_STATION || vif->p2p) | |
837 | return 0; | |
838 | ||
3dd37d05 EP |
839 | iwl_mvm_beacon_filter_set_cqm_params(mvm, vif, cmd); |
840 | if (!d0i3) | |
841 | iwl_mvm_beacon_filter_debugfs_parameters(vif, cmd); | |
842 | ret = iwl_mvm_beacon_filter_send_cmd(mvm, cmd, cmd_flags); | |
071d4990 | 843 | |
3dd37d05 EP |
844 | /* don't change bf_enabled in case of temporary d0i3 configuration */ |
845 | if (!ret && !d0i3) | |
a20fd398 | 846 | mvmvif->bf_data.bf_enabled = true; |
071d4990 AB |
847 | |
848 | return ret; | |
7df15b1e HG |
849 | } |
850 | ||
3dd37d05 EP |
851 | int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm, |
852 | struct ieee80211_vif *vif, | |
853 | u32 flags) | |
854 | { | |
855 | struct iwl_beacon_filter_cmd cmd = { | |
856 | IWL_BF_CMD_CONFIG_DEFAULTS, | |
857 | .bf_enable_beacon_filter = cpu_to_le32(1), | |
858 | }; | |
859 | ||
860 | return _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd, flags, false); | |
861 | } | |
862 | ||
7df15b1e | 863 | int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm, |
3dd37d05 EP |
864 | struct ieee80211_vif *vif, |
865 | u32 flags) | |
7df15b1e | 866 | { |
071d4990 AB |
867 | struct iwl_beacon_filter_cmd cmd = {}; |
868 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
869 | int ret; | |
7df15b1e | 870 | |
73e5f2c5 | 871 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
7df15b1e HG |
872 | return 0; |
873 | ||
3dd37d05 | 874 | ret = iwl_mvm_beacon_filter_send_cmd(mvm, &cmd, flags); |
071d4990 AB |
875 | |
876 | if (!ret) | |
a20fd398 | 877 | mvmvif->bf_data.bf_enabled = false; |
071d4990 AB |
878 | |
879 | return ret; | |
7df15b1e | 880 | } |
e811ada7 | 881 | |
3dd37d05 EP |
882 | int iwl_mvm_update_d0i3_power_mode(struct iwl_mvm *mvm, |
883 | struct ieee80211_vif *vif, | |
884 | bool enable, u32 flags) | |
885 | { | |
886 | int ret; | |
887 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
888 | struct iwl_mac_power_cmd cmd = {}; | |
889 | ||
890 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) | |
891 | return 0; | |
892 | ||
893 | if (!vif->bss_conf.assoc) | |
894 | return 0; | |
895 | ||
896 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); | |
897 | if (enable) { | |
898 | /* configure skip over dtim up to 300 msec */ | |
899 | int dtimper = mvm->hw->conf.ps_dtim_period ?: 1; | |
900 | int dtimper_msec = dtimper * vif->bss_conf.beacon_int; | |
901 | ||
902 | if (WARN_ON(!dtimper_msec)) | |
903 | return 0; | |
904 | ||
905 | cmd.flags |= | |
906 | cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); | |
907 | cmd.skip_dtim_periods = 300 / dtimper_msec; | |
908 | } | |
909 | iwl_mvm_power_log(mvm, &cmd); | |
474b50c3 EG |
910 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
911 | memcpy(&mvmvif->mac_pwr_cmd, &cmd, sizeof(cmd)); | |
912 | #endif | |
3dd37d05 EP |
913 | ret = iwl_mvm_send_cmd_pdu(mvm, MAC_PM_POWER_TABLE, flags, |
914 | sizeof(cmd), &cmd); | |
915 | if (ret) | |
916 | return ret; | |
917 | ||
918 | /* configure beacon filtering */ | |
919 | if (mvmvif != mvm->bf_allowed_vif) | |
920 | return 0; | |
921 | ||
922 | if (enable) { | |
923 | struct iwl_beacon_filter_cmd cmd_bf = { | |
924 | IWL_BF_CMD_CONFIG_D0I3, | |
925 | .bf_enable_beacon_filter = cpu_to_le32(1), | |
926 | }; | |
927 | ret = _iwl_mvm_enable_beacon_filter(mvm, vif, &cmd_bf, | |
928 | flags, true); | |
929 | } else { | |
930 | if (mvmvif->bf_data.bf_enabled) | |
931 | ret = iwl_mvm_enable_beacon_filter(mvm, vif, flags); | |
932 | else | |
933 | ret = iwl_mvm_disable_beacon_filter(mvm, vif, flags); | |
934 | } | |
935 | ||
936 | return ret; | |
937 | } | |
938 | ||
a20fd398 | 939 | int iwl_mvm_update_beacon_filter(struct iwl_mvm *mvm, |
3dd37d05 EP |
940 | struct ieee80211_vif *vif, |
941 | bool force, | |
942 | u32 flags) | |
a20fd398 AO |
943 | { |
944 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
945 | ||
3dd37d05 | 946 | if (mvmvif != mvm->bf_allowed_vif) |
a20fd398 AO |
947 | return 0; |
948 | ||
3dd37d05 EP |
949 | if (!mvmvif->bf_data.bf_enabled) { |
950 | /* disable beacon filtering explicitly if force is true */ | |
951 | if (force) | |
952 | return iwl_mvm_disable_beacon_filter(mvm, vif, flags); | |
953 | return 0; | |
954 | } | |
955 | ||
956 | return iwl_mvm_enable_beacon_filter(mvm, vif, flags); | |
a20fd398 | 957 | } |