1 /******************************************************************************
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.
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
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.
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.
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,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
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
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.
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.
62 *****************************************************************************/
64 #include <linux/kernel.h>
65 #include <linux/module.h>
66 #include <linux/slab.h>
67 #include <linux/init.h>
69 #include <net/mac80211.h>
71 #include "iwl-debug.h"
73 #include "iwl-modparams.h"
74 #include "fw-api-power.h"
76 #define POWER_KEEP_ALIVE_PERIOD_SEC 25
78 static int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm
*mvm
,
79 struct iwl_beacon_filter_cmd
*cmd
)
83 ret
= iwl_mvm_send_cmd_pdu(mvm
, REPLY_BEACON_FILTERING_CMD
, CMD_SYNC
,
84 sizeof(struct iwl_beacon_filter_cmd
), cmd
);
87 IWL_DEBUG_POWER(mvm
, "ba_enable_beacon_abort is: %d\n",
88 cmd
->ba_enable_beacon_abort
);
89 IWL_DEBUG_POWER(mvm
, "ba_escape_timer is: %d\n",
90 cmd
->ba_escape_timer
);
91 IWL_DEBUG_POWER(mvm
, "bf_debug_flag is: %d\n",
93 IWL_DEBUG_POWER(mvm
, "bf_enable_beacon_filter is: %d\n",
94 cmd
->bf_enable_beacon_filter
);
95 IWL_DEBUG_POWER(mvm
, "bf_energy_delta is: %d\n",
96 cmd
->bf_energy_delta
);
97 IWL_DEBUG_POWER(mvm
, "bf_escape_timer is: %d\n",
98 cmd
->bf_escape_timer
);
99 IWL_DEBUG_POWER(mvm
, "bf_roaming_energy_delta is: %d\n",
100 cmd
->bf_roaming_energy_delta
);
101 IWL_DEBUG_POWER(mvm
, "bf_roaming_state is: %d\n",
102 cmd
->bf_roaming_state
);
103 IWL_DEBUG_POWER(mvm
, "bf_temperature_delta is: %d\n",
104 cmd
->bf_temperature_delta
);
109 static int iwl_mvm_update_beacon_abort(struct iwl_mvm
*mvm
,
110 struct ieee80211_vif
*vif
, bool enable
)
112 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
113 struct iwl_beacon_filter_cmd cmd
= {
114 IWL_BF_CMD_CONFIG_DEFAULTS
,
115 .bf_enable_beacon_filter
= 1,
116 .ba_enable_beacon_abort
= enable
,
119 if (!mvmvif
->bf_enabled
)
122 iwl_mvm_beacon_filter_debugfs_parameters(vif
, &cmd
);
123 return iwl_mvm_beacon_filter_send_cmd(mvm
, &cmd
);
126 static void iwl_mvm_power_log(struct iwl_mvm
*mvm
,
127 struct iwl_powertable_cmd
*cmd
)
130 "Sending power table command for power level %d, flags = 0x%X\n",
131 iwlmvm_mod_params
.power_scheme
,
132 le16_to_cpu(cmd
->flags
));
133 IWL_DEBUG_POWER(mvm
, "Keep alive = %u sec\n", cmd
->keep_alive_seconds
);
135 if (cmd
->flags
& cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
)) {
136 IWL_DEBUG_POWER(mvm
, "Rx timeout = %u usec\n",
137 le32_to_cpu(cmd
->rx_data_timeout
));
138 IWL_DEBUG_POWER(mvm
, "Tx timeout = %u usec\n",
139 le32_to_cpu(cmd
->tx_data_timeout
));
140 IWL_DEBUG_POWER(mvm
, "LP RX RSSI threshold = %u\n",
141 cmd
->lprx_rssi_threshold
);
142 if (cmd
->flags
& cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
))
143 IWL_DEBUG_POWER(mvm
, "DTIM periods to skip = %u\n",
144 le32_to_cpu(cmd
->skip_dtim_periods
));
148 void iwl_mvm_power_build_cmd(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
149 struct iwl_powertable_cmd
*cmd
)
151 struct ieee80211_hw
*hw
= mvm
->hw
;
152 struct ieee80211_chanctx_conf
*chanctx_conf
;
153 struct ieee80211_channel
*chan
;
154 int dtimper
, dtimper_msec
;
156 bool radar_detect
= false;
157 struct iwl_mvm_vif
*mvmvif __maybe_unused
=
158 iwl_mvm_vif_from_mac80211(vif
);
161 * Regardless of power management state the driver must set
162 * keep alive period. FW will use it for sending keep alive NDPs
163 * immediately after association.
165 cmd
->keep_alive_seconds
= POWER_KEEP_ALIVE_PERIOD_SEC
;
167 if (iwlmvm_mod_params
.power_scheme
== IWL_POWER_SCHEME_CAM
)
170 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK
);
171 if (!vif
->bss_conf
.assoc
)
172 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
);
174 #ifdef CONFIG_IWLWIFI_DEBUGFS
175 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_DISABLE_POWER_OFF
&&
176 mvmvif
->dbgfs_pm
.disable_power_off
)
177 cmd
->flags
&= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK
);
179 if (!vif
->bss_conf
.ps
)
182 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
);
184 dtimper
= hw
->conf
.ps_dtim_period
?: 1;
186 /* Check if radar detection is required on current channel */
188 chanctx_conf
= rcu_dereference(vif
->chanctx_conf
);
189 WARN_ON(!chanctx_conf
);
191 chan
= chanctx_conf
->def
.chan
;
192 radar_detect
= chan
->flags
& IEEE80211_CHAN_RADAR
;
196 /* Check skip over DTIM conditions */
197 if (!radar_detect
&& (dtimper
<= 10) &&
198 (iwlmvm_mod_params
.power_scheme
== IWL_POWER_SCHEME_LP
||
199 mvm
->cur_ucode
== IWL_UCODE_WOWLAN
)) {
200 cmd
->flags
|= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
201 cmd
->skip_dtim_periods
= cpu_to_le32(3);
204 /* Check that keep alive period is at least 3 * DTIM */
205 dtimper_msec
= dtimper
* vif
->bss_conf
.beacon_int
;
206 keep_alive
= max_t(int, 3 * dtimper_msec
,
207 MSEC_PER_SEC
* cmd
->keep_alive_seconds
);
208 keep_alive
= DIV_ROUND_UP(keep_alive
, MSEC_PER_SEC
);
209 cmd
->keep_alive_seconds
= keep_alive
;
211 if (mvm
->cur_ucode
!= IWL_UCODE_WOWLAN
) {
212 cmd
->rx_data_timeout
= cpu_to_le32(100 * USEC_PER_MSEC
);
213 cmd
->tx_data_timeout
= cpu_to_le32(100 * USEC_PER_MSEC
);
215 cmd
->rx_data_timeout
= cpu_to_le32(10 * USEC_PER_MSEC
);
216 cmd
->tx_data_timeout
= cpu_to_le32(10 * USEC_PER_MSEC
);
219 #ifdef CONFIG_IWLWIFI_DEBUGFS
220 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_KEEP_ALIVE
)
221 cmd
->keep_alive_seconds
= mvmvif
->dbgfs_pm
.keep_alive_seconds
;
222 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_SKIP_OVER_DTIM
) {
223 if (mvmvif
->dbgfs_pm
.skip_over_dtim
)
225 cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
228 cpu_to_le16(~POWER_FLAGS_SKIP_OVER_DTIM_MSK
);
230 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_RX_DATA_TIMEOUT
)
231 cmd
->rx_data_timeout
=
232 cpu_to_le32(mvmvif
->dbgfs_pm
.rx_data_timeout
);
233 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_TX_DATA_TIMEOUT
)
234 cmd
->tx_data_timeout
=
235 cpu_to_le32(mvmvif
->dbgfs_pm
.tx_data_timeout
);
236 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_SKIP_DTIM_PERIODS
)
237 cmd
->skip_dtim_periods
=
238 cpu_to_le32(mvmvif
->dbgfs_pm
.skip_dtim_periods
);
239 #endif /* CONFIG_IWLWIFI_DEBUGFS */
242 int iwl_mvm_power_update_mode(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
246 struct iwl_powertable_cmd cmd
= {};
248 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
252 * TODO: The following vif_count verification is temporary condition.
253 * Avoid power mode update if more than one interface is currently
254 * active. Remove this condition when FW will support power management
257 IWL_DEBUG_POWER(mvm
, "Currently %d interfaces active\n",
259 if (mvm
->vif_count
> 1)
262 iwl_mvm_power_build_cmd(mvm
, vif
, &cmd
);
263 iwl_mvm_power_log(mvm
, &cmd
);
265 ret
= iwl_mvm_send_cmd_pdu(mvm
, POWER_TABLE_CMD
, CMD_SYNC
,
270 ba_enable
= !!(cmd
.flags
&
271 cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK
));
273 return iwl_mvm_update_beacon_abort(mvm
, vif
, ba_enable
);
276 int iwl_mvm_power_disable(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
)
278 struct iwl_powertable_cmd cmd
= {};
279 struct iwl_mvm_vif
*mvmvif __maybe_unused
=
280 iwl_mvm_vif_from_mac80211(vif
);
282 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
285 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_CAM
)
286 cmd
.flags
|= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK
);
288 #ifdef CONFIG_IWLWIFI_DEBUGFS
289 if (mvmvif
->dbgfs_pm
.mask
& MVM_DEBUGFS_PM_DISABLE_POWER_OFF
&&
290 mvmvif
->dbgfs_pm
.disable_power_off
)
291 cmd
.flags
&= cpu_to_le16(~POWER_FLAGS_POWER_SAVE_ENA_MSK
);
293 iwl_mvm_power_log(mvm
, &cmd
);
295 return iwl_mvm_send_cmd_pdu(mvm
, POWER_TABLE_CMD
, CMD_ASYNC
,
299 #ifdef CONFIG_IWLWIFI_DEBUGFS
301 iwl_mvm_beacon_filter_debugfs_parameters(struct ieee80211_vif
*vif
,
302 struct iwl_beacon_filter_cmd
*cmd
)
304 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
305 struct iwl_dbgfs_bf
*dbgfs_bf
= &mvmvif
->dbgfs_bf
;
307 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ENERGY_DELTA
)
308 cmd
->bf_energy_delta
= dbgfs_bf
->bf_energy_delta
;
309 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ROAMING_ENERGY_DELTA
)
310 cmd
->bf_roaming_energy_delta
=
311 dbgfs_bf
->bf_roaming_energy_delta
;
312 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ROAMING_STATE
)
313 cmd
->bf_roaming_state
= dbgfs_bf
->bf_roaming_state
;
314 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_TEMPERATURE_DELTA
)
315 cmd
->bf_temperature_delta
= dbgfs_bf
->bf_temperature_delta
;
316 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_DEBUG_FLAG
)
317 cmd
->bf_debug_flag
= dbgfs_bf
->bf_debug_flag
;
318 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BF_ESCAPE_TIMER
)
319 cmd
->bf_escape_timer
= cpu_to_le32(dbgfs_bf
->bf_escape_timer
);
320 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BA_ESCAPE_TIMER
)
321 cmd
->ba_escape_timer
= cpu_to_le32(dbgfs_bf
->ba_escape_timer
);
322 if (dbgfs_bf
->mask
& MVM_DEBUGFS_BA_ENABLE_BEACON_ABORT
)
323 cmd
->ba_enable_beacon_abort
= dbgfs_bf
->ba_enable_beacon_abort
;
327 int iwl_mvm_enable_beacon_filter(struct iwl_mvm
*mvm
,
328 struct ieee80211_vif
*vif
)
330 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
331 struct iwl_beacon_filter_cmd cmd
= {
332 IWL_BF_CMD_CONFIG_DEFAULTS
,
333 .bf_enable_beacon_filter
= 1,
337 if (mvmvif
!= mvm
->bf_allowed_vif
||
338 vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
341 iwl_mvm_beacon_filter_debugfs_parameters(vif
, &cmd
);
342 ret
= iwl_mvm_beacon_filter_send_cmd(mvm
, &cmd
);
345 mvmvif
->bf_enabled
= true;
350 int iwl_mvm_disable_beacon_filter(struct iwl_mvm
*mvm
,
351 struct ieee80211_vif
*vif
)
353 struct iwl_beacon_filter_cmd cmd
= {};
354 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
357 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
360 ret
= iwl_mvm_beacon_filter_send_cmd(mvm
, &cmd
);
363 mvmvif
->bf_enabled
= false;