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 | * | |
8 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of version 2 of the GNU General Public License as | |
12 | * published by the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | |
22 | * USA | |
23 | * | |
24 | * The full GNU General Public License is included in this distribution | |
410dc5aa | 25 | * in the file called COPYING. |
8ca151b5 JB |
26 | * |
27 | * Contact Information: | |
28 | * Intel Linux Wireless <ilw@linux.intel.com> | |
29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
30 | * | |
31 | * BSD LICENSE | |
32 | * | |
33 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. | |
34 | * All rights reserved. | |
35 | * | |
36 | * Redistribution and use in source and binary forms, with or without | |
37 | * modification, are permitted provided that the following conditions | |
38 | * are met: | |
39 | * | |
40 | * * Redistributions of source code must retain the above copyright | |
41 | * notice, this list of conditions and the following disclaimer. | |
42 | * * Redistributions in binary form must reproduce the above copyright | |
43 | * notice, this list of conditions and the following disclaimer in | |
44 | * the documentation and/or other materials provided with the | |
45 | * distribution. | |
46 | * * Neither the name Intel Corporation nor the names of its | |
47 | * contributors may be used to endorse or promote products derived | |
48 | * from this software without specific prior written permission. | |
49 | * | |
50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
61 | * | |
62 | *****************************************************************************/ | |
63 | ||
64 | #include <linux/kernel.h> | |
65 | #include <linux/module.h> | |
66 | #include <linux/slab.h> | |
67 | #include <linux/init.h> | |
68 | ||
69 | #include <net/mac80211.h> | |
70 | ||
71 | #include "iwl-debug.h" | |
72 | #include "mvm.h" | |
73 | #include "iwl-modparams.h" | |
74 | #include "fw-api-power.h" | |
75 | ||
76 | #define POWER_KEEP_ALIVE_PERIOD_SEC 25 | |
77 | ||
3f0b2b3e AB |
78 | static void iwl_mvm_power_log(struct iwl_mvm *mvm, |
79 | struct iwl_powertable_cmd *cmd) | |
80 | { | |
81 | IWL_DEBUG_POWER(mvm, | |
82 | "Sending power table command for power level %d, flags = 0x%X\n", | |
83 | iwlmvm_mod_params.power_scheme, | |
84 | le16_to_cpu(cmd->flags)); | |
85 | IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n", cmd->keep_alive_seconds); | |
86 | ||
87 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) { | |
88 | IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n", | |
89 | le32_to_cpu(cmd->rx_data_timeout)); | |
90 | IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n", | |
91 | le32_to_cpu(cmd->tx_data_timeout)); | |
92 | IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n", | |
93 | cmd->lprx_rssi_threshold); | |
5b1dbfc3 AB |
94 | if (cmd->flags & cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK)) |
95 | IWL_DEBUG_POWER(mvm, "DTIMs to skip = %u\n", | |
96 | le32_to_cpu(cmd->num_skip_dtim)); | |
3f0b2b3e AB |
97 | } |
98 | } | |
99 | ||
4d1c4b1a AB |
100 | void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
101 | struct iwl_powertable_cmd *cmd) | |
8ca151b5 JB |
102 | { |
103 | struct ieee80211_hw *hw = mvm->hw; | |
8ca151b5 JB |
104 | struct ieee80211_chanctx_conf *chanctx_conf; |
105 | struct ieee80211_channel *chan; | |
106 | int dtimper, dtimper_msec; | |
107 | int keep_alive; | |
108 | bool radar_detect = false; | |
109 | ||
e16cf7ec AB |
110 | /* |
111 | * Regardless of power management state the driver must set | |
112 | * keep alive period. FW will use it for sending keep alive NDPs | |
113 | * immediately after association. | |
114 | */ | |
115 | cmd->keep_alive_seconds = POWER_KEEP_ALIVE_PERIOD_SEC; | |
116 | ||
ade50652 | 117 | if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) |
8ca151b5 JB |
118 | return; |
119 | ||
9a613048 AB |
120 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK); |
121 | ||
122 | if (!vif->bss_conf.ps) | |
123 | return; | |
124 | ||
125 | cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK); | |
8ca151b5 JB |
126 | |
127 | dtimper = hw->conf.ps_dtim_period ?: 1; | |
128 | ||
129 | /* Check if radar detection is required on current channel */ | |
130 | rcu_read_lock(); | |
131 | chanctx_conf = rcu_dereference(vif->chanctx_conf); | |
132 | WARN_ON(!chanctx_conf); | |
133 | if (chanctx_conf) { | |
134 | chan = chanctx_conf->def.chan; | |
135 | radar_detect = chan->flags & IEEE80211_CHAN_RADAR; | |
136 | } | |
137 | rcu_read_unlock(); | |
138 | ||
139 | /* Check skip over DTIM conditions */ | |
140 | if (!radar_detect && (dtimper <= 10) && | |
5b1dbfc3 | 141 | (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP)) { |
f4a3e2fe | 142 | cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK); |
5b1dbfc3 AB |
143 | cmd->num_skip_dtim = cpu_to_le32(2); |
144 | } | |
8ca151b5 JB |
145 | |
146 | /* Check that keep alive period is at least 3 * DTIM */ | |
147 | dtimper_msec = dtimper * vif->bss_conf.beacon_int; | |
148 | keep_alive = max_t(int, 3 * dtimper_msec, | |
e16cf7ec | 149 | MSEC_PER_SEC * cmd->keep_alive_seconds); |
8ca151b5 | 150 | keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC); |
83bdad52 | 151 | cmd->keep_alive_seconds = keep_alive; |
8ca151b5 | 152 | |
0aed849f AB |
153 | cmd->rx_data_timeout = cpu_to_le32(100 * USEC_PER_MSEC); |
154 | cmd->tx_data_timeout = cpu_to_le32(100 * USEC_PER_MSEC); | |
8ca151b5 JB |
155 | } |
156 | ||
157 | int iwl_mvm_power_update_mode(struct iwl_mvm *mvm, struct ieee80211_vif *vif) | |
158 | { | |
159 | struct iwl_powertable_cmd cmd = {}; | |
160 | ||
8ca151b5 JB |
161 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
162 | return 0; | |
163 | ||
f4a3e2fe | 164 | iwl_mvm_power_build_cmd(mvm, vif, &cmd); |
3f0b2b3e | 165 | iwl_mvm_power_log(mvm, &cmd); |
8ca151b5 JB |
166 | |
167 | return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_SYNC, | |
168 | sizeof(cmd), &cmd); | |
169 | } | |
170 | ||
171 | int iwl_mvm_power_disable(struct iwl_mvm *mvm, struct ieee80211_vif *vif) | |
172 | { | |
173 | struct iwl_powertable_cmd cmd = {}; | |
8ca151b5 | 174 | |
8ca151b5 JB |
175 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
176 | return 0; | |
177 | ||
ade50652 | 178 | if (iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) |
9a613048 AB |
179 | cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK); |
180 | ||
3f0b2b3e | 181 | iwl_mvm_power_log(mvm, &cmd); |
8ca151b5 | 182 | |
5360cfb2 | 183 | return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_ASYNC, |
8ca151b5 JB |
184 | sizeof(cmd), &cmd); |
185 | } | |
7df15b1e HG |
186 | |
187 | static int iwl_mvm_beacon_filter_send_cmd(struct iwl_mvm *mvm, | |
188 | struct iwl_beacon_filter_cmd *cmd) | |
189 | { | |
190 | int ret; | |
191 | ||
192 | ret = iwl_mvm_send_cmd_pdu(mvm, REPLY_BEACON_FILTERING_CMD, CMD_SYNC, | |
193 | sizeof(struct iwl_beacon_filter_cmd), cmd); | |
194 | ||
195 | if (!ret) { | |
196 | IWL_DEBUG_POWER(mvm, "ba_enable_beacon_abort is: %d\n", | |
197 | cmd->ba_enable_beacon_abort); | |
198 | IWL_DEBUG_POWER(mvm, "ba_escape_timer is: %d\n", | |
199 | cmd->ba_escape_timer); | |
200 | IWL_DEBUG_POWER(mvm, "bf_debug_flag is: %d\n", | |
201 | cmd->bf_debug_flag); | |
202 | IWL_DEBUG_POWER(mvm, "bf_enable_beacon_filter is: %d\n", | |
203 | cmd->bf_enable_beacon_filter); | |
204 | IWL_DEBUG_POWER(mvm, "bf_energy_delta is: %d\n", | |
205 | cmd->bf_energy_delta); | |
206 | IWL_DEBUG_POWER(mvm, "bf_escape_timer is: %d\n", | |
207 | cmd->bf_escape_timer); | |
208 | IWL_DEBUG_POWER(mvm, "bf_roaming_energy_delta is: %d\n", | |
209 | cmd->bf_roaming_energy_delta); | |
210 | IWL_DEBUG_POWER(mvm, "bf_roaming_state is: %d\n", | |
211 | cmd->bf_roaming_state); | |
212 | IWL_DEBUG_POWER(mvm, "bf_temperature_delta is: %d\n", | |
213 | cmd->bf_temperature_delta); | |
214 | } | |
215 | return ret; | |
216 | } | |
217 | ||
218 | int iwl_mvm_enable_beacon_filter(struct iwl_mvm *mvm, | |
219 | struct ieee80211_vif *vif) | |
220 | { | |
221 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
222 | struct iwl_beacon_filter_cmd cmd = { | |
223 | .bf_enable_beacon_filter = 1, | |
224 | .bf_energy_delta = IWL_BF_ENERGY_DELTA_DEFAULT, | |
225 | .bf_roaming_energy_delta = IWL_BF_ROAMING_ENERGY_DELTA_DEFAULT, | |
226 | .bf_roaming_state = IWL_BF_ROAMING_STATE_DEFAULT, | |
227 | .bf_temperature_delta = IWL_BF_TEMPERATURE_DELTA_DEFAULT, | |
228 | .bf_debug_flag = IWL_BF_DEBUG_FLAG_DEFAULT, | |
229 | .bf_escape_timer = cpu_to_le32(IWL_BF_ESCAPE_TIMER_DEFAULT), | |
230 | .ba_escape_timer = cpu_to_le32(IWL_BA_ESCAPE_TIMER_DEFAULT), | |
231 | .ba_enable_beacon_abort = IWL_BA_ENABLE_BEACON_ABORT_DEFAULT, | |
232 | }; | |
233 | ||
234 | if (mvmvif != mvm->bf_allowed_vif || | |
235 | vif->type != NL80211_IFTYPE_STATION || vif->p2p) | |
236 | return 0; | |
237 | ||
238 | return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); | |
239 | } | |
240 | ||
241 | int iwl_mvm_disable_beacon_filter(struct iwl_mvm *mvm, | |
242 | struct ieee80211_vif *vif) | |
243 | { | |
244 | struct iwl_beacon_filter_cmd cmd = { | |
245 | .bf_enable_beacon_filter = 0, | |
246 | }; | |
247 | ||
248 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) | |
249 | return 0; | |
250 | ||
251 | return iwl_mvm_beacon_filter_send_cmd(mvm, &cmd); | |
252 | } |