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 | ||
f444eb10 | 64 | #include <linux/etherdevice.h> |
f0c2646a | 65 | #include <linux/ip.h> |
debff618 | 66 | #include <linux/fs.h> |
8ca151b5 JB |
67 | #include <net/cfg80211.h> |
68 | #include <net/ipv6.h> | |
f0c2646a | 69 | #include <net/tcp.h> |
f7fc5989 | 70 | #include <net/addrconf.h> |
8ca151b5 JB |
71 | #include "iwl-modparams.h" |
72 | #include "fw-api.h" | |
73 | #include "mvm.h" | |
74 | ||
75 | void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw, | |
76 | struct ieee80211_vif *vif, | |
77 | struct cfg80211_gtk_rekey_data *data) | |
78 | { | |
79 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
80 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
81 | ||
82 | if (iwlwifi_mod_params.sw_crypto) | |
83 | return; | |
84 | ||
85 | mutex_lock(&mvm->mutex); | |
86 | ||
87 | memcpy(mvmvif->rekey_data.kek, data->kek, NL80211_KEK_LEN); | |
88 | memcpy(mvmvif->rekey_data.kck, data->kck, NL80211_KCK_LEN); | |
89 | mvmvif->rekey_data.replay_ctr = | |
90 | cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr)); | |
91 | mvmvif->rekey_data.valid = true; | |
92 | ||
93 | mutex_unlock(&mvm->mutex); | |
94 | } | |
95 | ||
96 | #if IS_ENABLED(CONFIG_IPV6) | |
97 | void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw, | |
98 | struct ieee80211_vif *vif, | |
99 | struct inet6_dev *idev) | |
100 | { | |
101 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
102 | struct inet6_ifaddr *ifa; | |
103 | int idx = 0; | |
104 | ||
a3777e0f | 105 | read_lock_bh(&idev->lock); |
8ca151b5 JB |
106 | list_for_each_entry(ifa, &idev->addr_list, if_list) { |
107 | mvmvif->target_ipv6_addrs[idx] = ifa->addr; | |
108 | idx++; | |
5369d6c1 | 109 | if (idx >= IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX) |
8ca151b5 JB |
110 | break; |
111 | } | |
a3777e0f | 112 | read_unlock_bh(&idev->lock); |
8ca151b5 JB |
113 | |
114 | mvmvif->num_target_ipv6_addrs = idx; | |
115 | } | |
116 | #endif | |
117 | ||
118 | void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw, | |
119 | struct ieee80211_vif *vif, int idx) | |
120 | { | |
121 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
122 | ||
123 | mvmvif->tx_key_idx = idx; | |
124 | } | |
125 | ||
126 | static void iwl_mvm_convert_p1k(u16 *p1k, __le16 *out) | |
127 | { | |
128 | int i; | |
129 | ||
130 | for (i = 0; i < IWL_P1K_SIZE; i++) | |
131 | out[i] = cpu_to_le16(p1k[i]); | |
132 | } | |
133 | ||
134 | struct wowlan_key_data { | |
135 | struct iwl_wowlan_rsc_tsc_params_cmd *rsc_tsc; | |
136 | struct iwl_wowlan_tkip_params_cmd *tkip; | |
137 | bool error, use_rsc_tsc, use_tkip; | |
5312e54d | 138 | int wep_key_idx; |
8ca151b5 JB |
139 | }; |
140 | ||
141 | static void iwl_mvm_wowlan_program_keys(struct ieee80211_hw *hw, | |
142 | struct ieee80211_vif *vif, | |
143 | struct ieee80211_sta *sta, | |
144 | struct ieee80211_key_conf *key, | |
145 | void *_data) | |
146 | { | |
147 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
148 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
149 | struct wowlan_key_data *data = _data; | |
150 | struct aes_sc *aes_sc, *aes_tx_sc = NULL; | |
151 | struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL; | |
152 | struct iwl_p1k_cache *rx_p1ks; | |
153 | u8 *rx_mic_key; | |
154 | struct ieee80211_key_seq seq; | |
155 | u32 cur_rx_iv32 = 0; | |
156 | u16 p1k[IWL_P1K_SIZE]; | |
157 | int ret, i; | |
158 | ||
159 | mutex_lock(&mvm->mutex); | |
160 | ||
161 | switch (key->cipher) { | |
162 | case WLAN_CIPHER_SUITE_WEP40: | |
163 | case WLAN_CIPHER_SUITE_WEP104: { /* hack it for now */ | |
164 | struct { | |
165 | struct iwl_mvm_wep_key_cmd wep_key_cmd; | |
166 | struct iwl_mvm_wep_key wep_key; | |
167 | } __packed wkc = { | |
168 | .wep_key_cmd.mac_id_n_color = | |
169 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, | |
170 | mvmvif->color)), | |
171 | .wep_key_cmd.num_keys = 1, | |
172 | /* firmware sets STA_KEY_FLG_WEP_13BYTES */ | |
173 | .wep_key_cmd.decryption_type = STA_KEY_FLG_WEP, | |
174 | .wep_key.key_index = key->keyidx, | |
175 | .wep_key.key_size = key->keylen, | |
176 | }; | |
177 | ||
178 | /* | |
179 | * This will fail -- the key functions don't set support | |
180 | * pairwise WEP keys. However, that's better than silently | |
181 | * failing WoWLAN. Or maybe not? | |
182 | */ | |
183 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) | |
184 | break; | |
185 | ||
186 | memcpy(&wkc.wep_key.key[3], key->key, key->keylen); | |
187 | if (key->keyidx == mvmvif->tx_key_idx) { | |
188 | /* TX key must be at offset 0 */ | |
189 | wkc.wep_key.key_offset = 0; | |
190 | } else { | |
191 | /* others start at 1 */ | |
5312e54d JB |
192 | data->wep_key_idx++; |
193 | wkc.wep_key.key_offset = data->wep_key_idx; | |
8ca151b5 JB |
194 | } |
195 | ||
196 | ret = iwl_mvm_send_cmd_pdu(mvm, WEP_KEY, CMD_SYNC, | |
197 | sizeof(wkc), &wkc); | |
198 | data->error = ret != 0; | |
199 | ||
f444eb10 JB |
200 | mvm->ptk_ivlen = key->iv_len; |
201 | mvm->ptk_icvlen = key->icv_len; | |
202 | mvm->gtk_ivlen = key->iv_len; | |
203 | mvm->gtk_icvlen = key->icv_len; | |
204 | ||
8ca151b5 JB |
205 | /* don't upload key again */ |
206 | goto out_unlock; | |
207 | } | |
208 | default: | |
209 | data->error = true; | |
210 | goto out_unlock; | |
211 | case WLAN_CIPHER_SUITE_AES_CMAC: | |
212 | /* | |
213 | * Ignore CMAC keys -- the WoWLAN firmware doesn't support them | |
214 | * but we also shouldn't abort suspend due to that. It does have | |
215 | * support for the IGTK key renewal, but doesn't really use the | |
216 | * IGTK for anything. This means we could spuriously wake up or | |
217 | * be deauthenticated, but that was considered acceptable. | |
218 | */ | |
219 | goto out_unlock; | |
220 | case WLAN_CIPHER_SUITE_TKIP: | |
221 | if (sta) { | |
222 | tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc; | |
223 | tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc; | |
224 | ||
225 | rx_p1ks = data->tkip->rx_uni; | |
226 | ||
227 | ieee80211_get_key_tx_seq(key, &seq); | |
228 | tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16); | |
229 | tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32); | |
230 | ||
231 | ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k); | |
232 | iwl_mvm_convert_p1k(p1k, data->tkip->tx.p1k); | |
233 | ||
234 | memcpy(data->tkip->mic_keys.tx, | |
235 | &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY], | |
236 | IWL_MIC_KEY_SIZE); | |
237 | ||
238 | rx_mic_key = data->tkip->mic_keys.rx_unicast; | |
239 | } else { | |
240 | tkip_sc = | |
241 | data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc; | |
242 | rx_p1ks = data->tkip->rx_multi; | |
243 | rx_mic_key = data->tkip->mic_keys.rx_mcast; | |
244 | } | |
245 | ||
246 | /* | |
247 | * For non-QoS this relies on the fact that both the uCode and | |
248 | * mac80211 use TID 0 (as they need to to avoid replay attacks) | |
249 | * for checking the IV in the frames. | |
250 | */ | |
251 | for (i = 0; i < IWL_NUM_RSC; i++) { | |
252 | ieee80211_get_key_rx_seq(key, i, &seq); | |
253 | tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16); | |
254 | tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32); | |
255 | /* wrapping isn't allowed, AP must rekey */ | |
256 | if (seq.tkip.iv32 > cur_rx_iv32) | |
257 | cur_rx_iv32 = seq.tkip.iv32; | |
258 | } | |
259 | ||
260 | ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid, | |
261 | cur_rx_iv32, p1k); | |
262 | iwl_mvm_convert_p1k(p1k, rx_p1ks[0].p1k); | |
263 | ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid, | |
264 | cur_rx_iv32 + 1, p1k); | |
265 | iwl_mvm_convert_p1k(p1k, rx_p1ks[1].p1k); | |
266 | ||
267 | memcpy(rx_mic_key, | |
268 | &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY], | |
269 | IWL_MIC_KEY_SIZE); | |
270 | ||
271 | data->use_tkip = true; | |
272 | data->use_rsc_tsc = true; | |
273 | break; | |
274 | case WLAN_CIPHER_SUITE_CCMP: | |
275 | if (sta) { | |
276 | u8 *pn = seq.ccmp.pn; | |
277 | ||
278 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc; | |
279 | aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc; | |
280 | ||
281 | ieee80211_get_key_tx_seq(key, &seq); | |
282 | aes_tx_sc->pn = cpu_to_le64((u64)pn[5] | | |
283 | ((u64)pn[4] << 8) | | |
284 | ((u64)pn[3] << 16) | | |
285 | ((u64)pn[2] << 24) | | |
286 | ((u64)pn[1] << 32) | | |
287 | ((u64)pn[0] << 40)); | |
288 | } else { | |
289 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc; | |
290 | } | |
291 | ||
292 | /* | |
293 | * For non-QoS this relies on the fact that both the uCode and | |
294 | * mac80211 use TID 0 for checking the IV in the frames. | |
295 | */ | |
296 | for (i = 0; i < IWL_NUM_RSC; i++) { | |
297 | u8 *pn = seq.ccmp.pn; | |
298 | ||
299 | ieee80211_get_key_rx_seq(key, i, &seq); | |
300 | aes_sc->pn = cpu_to_le64((u64)pn[5] | | |
301 | ((u64)pn[4] << 8) | | |
302 | ((u64)pn[3] << 16) | | |
303 | ((u64)pn[2] << 24) | | |
304 | ((u64)pn[1] << 32) | | |
305 | ((u64)pn[0] << 40)); | |
306 | } | |
307 | data->use_rsc_tsc = true; | |
308 | break; | |
309 | } | |
310 | ||
311 | /* | |
312 | * The D3 firmware hardcodes the key offset 0 as the key it uses | |
313 | * to transmit packets to the AP, i.e. the PTK. | |
314 | */ | |
315 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { | |
316 | key->hw_key_idx = 0; | |
f444eb10 JB |
317 | mvm->ptk_ivlen = key->iv_len; |
318 | mvm->ptk_icvlen = key->icv_len; | |
8ca151b5 | 319 | } else { |
5312e54d JB |
320 | /* |
321 | * firmware only supports TSC/RSC for a single key, | |
322 | * so if there are multiple keep overwriting them | |
323 | * with new ones -- this relies on mac80211 doing | |
324 | * list_add_tail(). | |
325 | */ | |
326 | key->hw_key_idx = 1; | |
f444eb10 JB |
327 | mvm->gtk_ivlen = key->iv_len; |
328 | mvm->gtk_icvlen = key->icv_len; | |
8ca151b5 JB |
329 | } |
330 | ||
331 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, true); | |
332 | data->error = ret != 0; | |
333 | out_unlock: | |
334 | mutex_unlock(&mvm->mutex); | |
335 | } | |
336 | ||
337 | static int iwl_mvm_send_patterns(struct iwl_mvm *mvm, | |
338 | struct cfg80211_wowlan *wowlan) | |
339 | { | |
340 | struct iwl_wowlan_patterns_cmd *pattern_cmd; | |
341 | struct iwl_host_cmd cmd = { | |
342 | .id = WOWLAN_PATTERNS, | |
343 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, | |
344 | .flags = CMD_SYNC, | |
345 | }; | |
346 | int i, err; | |
347 | ||
348 | if (!wowlan->n_patterns) | |
349 | return 0; | |
350 | ||
351 | cmd.len[0] = sizeof(*pattern_cmd) + | |
352 | wowlan->n_patterns * sizeof(struct iwl_wowlan_pattern); | |
353 | ||
354 | pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL); | |
355 | if (!pattern_cmd) | |
356 | return -ENOMEM; | |
357 | ||
358 | pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns); | |
359 | ||
360 | for (i = 0; i < wowlan->n_patterns; i++) { | |
361 | int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8); | |
362 | ||
363 | memcpy(&pattern_cmd->patterns[i].mask, | |
364 | wowlan->patterns[i].mask, mask_len); | |
365 | memcpy(&pattern_cmd->patterns[i].pattern, | |
366 | wowlan->patterns[i].pattern, | |
367 | wowlan->patterns[i].pattern_len); | |
368 | pattern_cmd->patterns[i].mask_size = mask_len; | |
369 | pattern_cmd->patterns[i].pattern_size = | |
370 | wowlan->patterns[i].pattern_len; | |
371 | } | |
372 | ||
373 | cmd.data[0] = pattern_cmd; | |
374 | err = iwl_mvm_send_cmd(mvm, &cmd); | |
375 | kfree(pattern_cmd); | |
376 | return err; | |
377 | } | |
378 | ||
379 | static int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm, | |
380 | struct ieee80211_vif *vif) | |
381 | { | |
5369d6c1 JB |
382 | union { |
383 | struct iwl_proto_offload_cmd_v1 v1; | |
384 | struct iwl_proto_offload_cmd_v2 v2; | |
f7fc5989 JB |
385 | struct iwl_proto_offload_cmd_v3_small v3s; |
386 | struct iwl_proto_offload_cmd_v3_large v3l; | |
5369d6c1 | 387 | } cmd = {}; |
f7fc5989 JB |
388 | struct iwl_host_cmd hcmd = { |
389 | .id = PROT_OFFLOAD_CONFIG_CMD, | |
390 | .flags = CMD_SYNC, | |
391 | .data[0] = &cmd, | |
392 | .dataflags[0] = IWL_HCMD_DFL_DUP, | |
393 | }; | |
5369d6c1 JB |
394 | struct iwl_proto_offload_cmd_common *common; |
395 | u32 enabled = 0, size; | |
f7fc5989 | 396 | u32 capa_flags = mvm->fw->ucode_capa.flags; |
8ca151b5 JB |
397 | #if IS_ENABLED(CONFIG_IPV6) |
398 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
399 | int i; | |
400 | ||
f7fc5989 JB |
401 | if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL || |
402 | capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_LARGE) { | |
403 | struct iwl_ns_config *nsc; | |
404 | struct iwl_targ_addr *addrs; | |
405 | int n_nsc, n_addrs; | |
406 | int c; | |
407 | ||
408 | if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) { | |
409 | nsc = cmd.v3s.ns_config; | |
410 | n_nsc = IWL_PROTO_OFFLOAD_NUM_NS_CONFIG_V3S; | |
411 | addrs = cmd.v3s.targ_addrs; | |
412 | n_addrs = IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V3S; | |
413 | } else { | |
414 | nsc = cmd.v3l.ns_config; | |
415 | n_nsc = IWL_PROTO_OFFLOAD_NUM_NS_CONFIG_V3L; | |
416 | addrs = cmd.v3l.targ_addrs; | |
417 | n_addrs = IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V3L; | |
418 | } | |
419 | ||
420 | if (mvmvif->num_target_ipv6_addrs) | |
421 | enabled |= IWL_D3_PROTO_OFFLOAD_NS; | |
422 | ||
423 | /* | |
424 | * For each address we have (and that will fit) fill a target | |
425 | * address struct and combine for NS offload structs with the | |
426 | * solicited node addresses. | |
427 | */ | |
428 | for (i = 0, c = 0; | |
429 | i < mvmvif->num_target_ipv6_addrs && | |
430 | i < n_addrs && c < n_nsc; i++) { | |
431 | struct in6_addr solicited_addr; | |
432 | int j; | |
433 | ||
434 | addrconf_addr_solict_mult(&mvmvif->target_ipv6_addrs[i], | |
435 | &solicited_addr); | |
436 | for (j = 0; j < c; j++) | |
437 | if (ipv6_addr_cmp(&nsc[j].dest_ipv6_addr, | |
438 | &solicited_addr) == 0) | |
439 | break; | |
440 | if (j == c) | |
441 | c++; | |
442 | addrs[i].addr = mvmvif->target_ipv6_addrs[i]; | |
443 | addrs[i].config_num = cpu_to_le32(j); | |
444 | nsc[j].dest_ipv6_addr = solicited_addr; | |
445 | memcpy(nsc[j].target_mac_addr, vif->addr, ETH_ALEN); | |
446 | } | |
447 | ||
448 | if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) | |
449 | cmd.v3s.num_valid_ipv6_addrs = cpu_to_le32(i); | |
450 | else | |
451 | cmd.v3l.num_valid_ipv6_addrs = cpu_to_le32(i); | |
452 | } else if (capa_flags & IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS) { | |
5369d6c1 JB |
453 | if (mvmvif->num_target_ipv6_addrs) { |
454 | enabled |= IWL_D3_PROTO_OFFLOAD_NS; | |
455 | memcpy(cmd.v2.ndp_mac_addr, vif->addr, ETH_ALEN); | |
456 | } | |
457 | ||
458 | BUILD_BUG_ON(sizeof(cmd.v2.target_ipv6_addr[0]) != | |
459 | sizeof(mvmvif->target_ipv6_addrs[0])); | |
460 | ||
461 | for (i = 0; i < min(mvmvif->num_target_ipv6_addrs, | |
462 | IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V2); i++) | |
463 | memcpy(cmd.v2.target_ipv6_addr[i], | |
464 | &mvmvif->target_ipv6_addrs[i], | |
465 | sizeof(cmd.v2.target_ipv6_addr[i])); | |
466 | } else { | |
467 | if (mvmvif->num_target_ipv6_addrs) { | |
468 | enabled |= IWL_D3_PROTO_OFFLOAD_NS; | |
469 | memcpy(cmd.v1.ndp_mac_addr, vif->addr, ETH_ALEN); | |
470 | } | |
8ca151b5 | 471 | |
5369d6c1 JB |
472 | BUILD_BUG_ON(sizeof(cmd.v1.target_ipv6_addr[0]) != |
473 | sizeof(mvmvif->target_ipv6_addrs[0])); | |
8ca151b5 | 474 | |
5369d6c1 JB |
475 | for (i = 0; i < min(mvmvif->num_target_ipv6_addrs, |
476 | IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V1); i++) | |
477 | memcpy(cmd.v1.target_ipv6_addr[i], | |
478 | &mvmvif->target_ipv6_addrs[i], | |
479 | sizeof(cmd.v1.target_ipv6_addr[i])); | |
480 | } | |
8ca151b5 JB |
481 | #endif |
482 | ||
f7fc5989 JB |
483 | if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_SMALL) { |
484 | common = &cmd.v3s.common; | |
485 | size = sizeof(cmd.v3s); | |
486 | } else if (capa_flags & IWL_UCODE_TLV_FLAGS_NEW_NSOFFL_LARGE) { | |
487 | common = &cmd.v3l.common; | |
488 | size = sizeof(cmd.v3l); | |
489 | } else if (capa_flags & IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS) { | |
5369d6c1 JB |
490 | common = &cmd.v2.common; |
491 | size = sizeof(cmd.v2); | |
492 | } else { | |
493 | common = &cmd.v1.common; | |
494 | size = sizeof(cmd.v1); | |
495 | } | |
496 | ||
8ca151b5 | 497 | if (vif->bss_conf.arp_addr_cnt) { |
5369d6c1 JB |
498 | enabled |= IWL_D3_PROTO_OFFLOAD_ARP; |
499 | common->host_ipv4_addr = vif->bss_conf.arp_addr_list[0]; | |
500 | memcpy(common->arp_mac_addr, vif->addr, ETH_ALEN); | |
8ca151b5 JB |
501 | } |
502 | ||
5369d6c1 | 503 | if (!enabled) |
8ca151b5 JB |
504 | return 0; |
505 | ||
5369d6c1 JB |
506 | common->enabled = cpu_to_le32(enabled); |
507 | ||
f7fc5989 JB |
508 | hcmd.len[0] = size; |
509 | return iwl_mvm_send_cmd(mvm, &hcmd); | |
8ca151b5 JB |
510 | } |
511 | ||
f0c2646a JB |
512 | enum iwl_mvm_tcp_packet_type { |
513 | MVM_TCP_TX_SYN, | |
514 | MVM_TCP_RX_SYNACK, | |
515 | MVM_TCP_TX_DATA, | |
516 | MVM_TCP_RX_ACK, | |
517 | MVM_TCP_RX_WAKE, | |
518 | MVM_TCP_TX_FIN, | |
519 | }; | |
520 | ||
521 | static __le16 pseudo_hdr_check(int len, __be32 saddr, __be32 daddr) | |
522 | { | |
523 | __sum16 check = tcp_v4_check(len, saddr, daddr, 0); | |
524 | return cpu_to_le16(be16_to_cpu((__force __be16)check)); | |
525 | } | |
526 | ||
b002c7e1 | 527 | static void iwl_mvm_build_tcp_packet(struct ieee80211_vif *vif, |
f0c2646a JB |
528 | struct cfg80211_wowlan_tcp *tcp, |
529 | void *_pkt, u8 *mask, | |
530 | __le16 *pseudo_hdr_csum, | |
531 | enum iwl_mvm_tcp_packet_type ptype) | |
532 | { | |
533 | struct { | |
534 | struct ethhdr eth; | |
535 | struct iphdr ip; | |
536 | struct tcphdr tcp; | |
537 | u8 data[]; | |
538 | } __packed *pkt = _pkt; | |
539 | u16 ip_tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr); | |
540 | int i; | |
541 | ||
542 | pkt->eth.h_proto = cpu_to_be16(ETH_P_IP), | |
543 | pkt->ip.version = 4; | |
544 | pkt->ip.ihl = 5; | |
545 | pkt->ip.protocol = IPPROTO_TCP; | |
546 | ||
547 | switch (ptype) { | |
548 | case MVM_TCP_TX_SYN: | |
549 | case MVM_TCP_TX_DATA: | |
550 | case MVM_TCP_TX_FIN: | |
551 | memcpy(pkt->eth.h_dest, tcp->dst_mac, ETH_ALEN); | |
552 | memcpy(pkt->eth.h_source, vif->addr, ETH_ALEN); | |
553 | pkt->ip.ttl = 128; | |
554 | pkt->ip.saddr = tcp->src; | |
555 | pkt->ip.daddr = tcp->dst; | |
556 | pkt->tcp.source = cpu_to_be16(tcp->src_port); | |
557 | pkt->tcp.dest = cpu_to_be16(tcp->dst_port); | |
558 | /* overwritten for TX SYN later */ | |
559 | pkt->tcp.doff = sizeof(struct tcphdr) / 4; | |
560 | pkt->tcp.window = cpu_to_be16(65000); | |
561 | break; | |
562 | case MVM_TCP_RX_SYNACK: | |
563 | case MVM_TCP_RX_ACK: | |
564 | case MVM_TCP_RX_WAKE: | |
565 | memcpy(pkt->eth.h_dest, vif->addr, ETH_ALEN); | |
566 | memcpy(pkt->eth.h_source, tcp->dst_mac, ETH_ALEN); | |
567 | pkt->ip.saddr = tcp->dst; | |
568 | pkt->ip.daddr = tcp->src; | |
569 | pkt->tcp.source = cpu_to_be16(tcp->dst_port); | |
570 | pkt->tcp.dest = cpu_to_be16(tcp->src_port); | |
571 | break; | |
572 | default: | |
573 | WARN_ON(1); | |
574 | return; | |
575 | } | |
576 | ||
577 | switch (ptype) { | |
578 | case MVM_TCP_TX_SYN: | |
579 | /* firmware assumes 8 option bytes - 8 NOPs for now */ | |
580 | memset(pkt->data, 0x01, 8); | |
581 | ip_tot_len += 8; | |
582 | pkt->tcp.doff = (sizeof(struct tcphdr) + 8) / 4; | |
583 | pkt->tcp.syn = 1; | |
584 | break; | |
585 | case MVM_TCP_TX_DATA: | |
586 | ip_tot_len += tcp->payload_len; | |
587 | memcpy(pkt->data, tcp->payload, tcp->payload_len); | |
588 | pkt->tcp.psh = 1; | |
589 | pkt->tcp.ack = 1; | |
590 | break; | |
591 | case MVM_TCP_TX_FIN: | |
592 | pkt->tcp.fin = 1; | |
593 | pkt->tcp.ack = 1; | |
594 | break; | |
595 | case MVM_TCP_RX_SYNACK: | |
596 | pkt->tcp.syn = 1; | |
597 | pkt->tcp.ack = 1; | |
598 | break; | |
599 | case MVM_TCP_RX_ACK: | |
600 | pkt->tcp.ack = 1; | |
601 | break; | |
602 | case MVM_TCP_RX_WAKE: | |
603 | ip_tot_len += tcp->wake_len; | |
604 | pkt->tcp.psh = 1; | |
605 | pkt->tcp.ack = 1; | |
606 | memcpy(pkt->data, tcp->wake_data, tcp->wake_len); | |
607 | break; | |
608 | } | |
609 | ||
610 | switch (ptype) { | |
611 | case MVM_TCP_TX_SYN: | |
612 | case MVM_TCP_TX_DATA: | |
613 | case MVM_TCP_TX_FIN: | |
614 | pkt->ip.tot_len = cpu_to_be16(ip_tot_len); | |
615 | pkt->ip.check = ip_fast_csum(&pkt->ip, pkt->ip.ihl); | |
616 | break; | |
617 | case MVM_TCP_RX_WAKE: | |
618 | for (i = 0; i < DIV_ROUND_UP(tcp->wake_len, 8); i++) { | |
619 | u8 tmp = tcp->wake_mask[i]; | |
620 | mask[i + 6] |= tmp << 6; | |
621 | if (i + 1 < DIV_ROUND_UP(tcp->wake_len, 8)) | |
622 | mask[i + 7] = tmp >> 2; | |
623 | } | |
624 | /* fall through for ethernet/IP/TCP headers mask */ | |
625 | case MVM_TCP_RX_SYNACK: | |
626 | case MVM_TCP_RX_ACK: | |
627 | mask[0] = 0xff; /* match ethernet */ | |
628 | /* | |
629 | * match ethernet, ip.version, ip.ihl | |
630 | * the ip.ihl half byte is really masked out by firmware | |
631 | */ | |
632 | mask[1] = 0x7f; | |
633 | mask[2] = 0x80; /* match ip.protocol */ | |
634 | mask[3] = 0xfc; /* match ip.saddr, ip.daddr */ | |
635 | mask[4] = 0x3f; /* match ip.daddr, tcp.source, tcp.dest */ | |
636 | mask[5] = 0x80; /* match tcp flags */ | |
637 | /* leave rest (0 or set for MVM_TCP_RX_WAKE) */ | |
638 | break; | |
639 | }; | |
640 | ||
641 | *pseudo_hdr_csum = pseudo_hdr_check(ip_tot_len - sizeof(struct iphdr), | |
642 | pkt->ip.saddr, pkt->ip.daddr); | |
643 | } | |
644 | ||
645 | static int iwl_mvm_send_remote_wake_cfg(struct iwl_mvm *mvm, | |
646 | struct ieee80211_vif *vif, | |
647 | struct cfg80211_wowlan_tcp *tcp) | |
648 | { | |
649 | struct iwl_wowlan_remote_wake_config *cfg; | |
650 | struct iwl_host_cmd cmd = { | |
651 | .id = REMOTE_WAKE_CONFIG_CMD, | |
652 | .len = { sizeof(*cfg), }, | |
653 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, | |
654 | .flags = CMD_SYNC, | |
655 | }; | |
656 | int ret; | |
657 | ||
658 | if (!tcp) | |
659 | return 0; | |
660 | ||
661 | cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); | |
662 | if (!cfg) | |
663 | return -ENOMEM; | |
664 | cmd.data[0] = cfg; | |
665 | ||
666 | cfg->max_syn_retries = 10; | |
667 | cfg->max_data_retries = 10; | |
668 | cfg->tcp_syn_ack_timeout = 1; /* seconds */ | |
669 | cfg->tcp_ack_timeout = 1; /* seconds */ | |
670 | ||
671 | /* SYN (TX) */ | |
672 | iwl_mvm_build_tcp_packet( | |
b002c7e1 | 673 | vif, tcp, cfg->syn_tx.data, NULL, |
f0c2646a JB |
674 | &cfg->syn_tx.info.tcp_pseudo_header_checksum, |
675 | MVM_TCP_TX_SYN); | |
676 | cfg->syn_tx.info.tcp_payload_length = 0; | |
677 | ||
678 | /* SYN/ACK (RX) */ | |
679 | iwl_mvm_build_tcp_packet( | |
b002c7e1 | 680 | vif, tcp, cfg->synack_rx.data, cfg->synack_rx.rx_mask, |
f0c2646a JB |
681 | &cfg->synack_rx.info.tcp_pseudo_header_checksum, |
682 | MVM_TCP_RX_SYNACK); | |
683 | cfg->synack_rx.info.tcp_payload_length = 0; | |
684 | ||
685 | /* KEEPALIVE/ACK (TX) */ | |
686 | iwl_mvm_build_tcp_packet( | |
b002c7e1 | 687 | vif, tcp, cfg->keepalive_tx.data, NULL, |
f0c2646a JB |
688 | &cfg->keepalive_tx.info.tcp_pseudo_header_checksum, |
689 | MVM_TCP_TX_DATA); | |
690 | cfg->keepalive_tx.info.tcp_payload_length = | |
691 | cpu_to_le16(tcp->payload_len); | |
692 | cfg->sequence_number_offset = tcp->payload_seq.offset; | |
693 | /* length must be 0..4, the field is little endian */ | |
694 | cfg->sequence_number_length = tcp->payload_seq.len; | |
695 | cfg->initial_sequence_number = cpu_to_le32(tcp->payload_seq.start); | |
696 | cfg->keepalive_interval = cpu_to_le16(tcp->data_interval); | |
697 | if (tcp->payload_tok.len) { | |
698 | cfg->token_offset = tcp->payload_tok.offset; | |
699 | cfg->token_length = tcp->payload_tok.len; | |
700 | cfg->num_tokens = | |
701 | cpu_to_le16(tcp->tokens_size % tcp->payload_tok.len); | |
702 | memcpy(cfg->tokens, tcp->payload_tok.token_stream, | |
703 | tcp->tokens_size); | |
704 | } else { | |
705 | /* set tokens to max value to almost never run out */ | |
706 | cfg->num_tokens = cpu_to_le16(65535); | |
707 | } | |
708 | ||
709 | /* ACK (RX) */ | |
710 | iwl_mvm_build_tcp_packet( | |
b002c7e1 | 711 | vif, tcp, cfg->keepalive_ack_rx.data, |
f0c2646a JB |
712 | cfg->keepalive_ack_rx.rx_mask, |
713 | &cfg->keepalive_ack_rx.info.tcp_pseudo_header_checksum, | |
714 | MVM_TCP_RX_ACK); | |
715 | cfg->keepalive_ack_rx.info.tcp_payload_length = 0; | |
716 | ||
717 | /* WAKEUP (RX) */ | |
718 | iwl_mvm_build_tcp_packet( | |
b002c7e1 | 719 | vif, tcp, cfg->wake_rx.data, cfg->wake_rx.rx_mask, |
f0c2646a JB |
720 | &cfg->wake_rx.info.tcp_pseudo_header_checksum, |
721 | MVM_TCP_RX_WAKE); | |
722 | cfg->wake_rx.info.tcp_payload_length = | |
723 | cpu_to_le16(tcp->wake_len); | |
724 | ||
725 | /* FIN */ | |
726 | iwl_mvm_build_tcp_packet( | |
b002c7e1 | 727 | vif, tcp, cfg->fin_tx.data, NULL, |
f0c2646a JB |
728 | &cfg->fin_tx.info.tcp_pseudo_header_checksum, |
729 | MVM_TCP_TX_FIN); | |
730 | cfg->fin_tx.info.tcp_payload_length = 0; | |
731 | ||
732 | ret = iwl_mvm_send_cmd(mvm, &cmd); | |
733 | kfree(cfg); | |
734 | ||
735 | return ret; | |
736 | } | |
737 | ||
8ca151b5 JB |
738 | struct iwl_d3_iter_data { |
739 | struct iwl_mvm *mvm; | |
740 | struct ieee80211_vif *vif; | |
741 | bool error; | |
742 | }; | |
743 | ||
744 | static void iwl_mvm_d3_iface_iterator(void *_data, u8 *mac, | |
745 | struct ieee80211_vif *vif) | |
746 | { | |
747 | struct iwl_d3_iter_data *data = _data; | |
748 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
749 | ||
750 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) | |
751 | return; | |
752 | ||
753 | if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT) | |
754 | return; | |
755 | ||
756 | if (data->vif) { | |
757 | IWL_ERR(data->mvm, "More than one managed interface active!\n"); | |
758 | data->error = true; | |
759 | return; | |
760 | } | |
761 | ||
762 | data->vif = vif; | |
763 | } | |
764 | ||
765 | static int iwl_mvm_d3_reprogram(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
766 | struct ieee80211_sta *ap_sta) | |
767 | { | |
768 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
769 | struct ieee80211_chanctx_conf *ctx; | |
770 | u8 chains_static, chains_dynamic; | |
771 | struct cfg80211_chan_def chandef; | |
772 | int ret, i; | |
773 | struct iwl_binding_cmd binding_cmd = {}; | |
774 | struct iwl_time_quota_cmd quota_cmd = {}; | |
775 | u32 status; | |
776 | ||
777 | /* add back the PHY */ | |
778 | if (WARN_ON(!mvmvif->phy_ctxt)) | |
779 | return -EINVAL; | |
780 | ||
781 | rcu_read_lock(); | |
782 | ctx = rcu_dereference(vif->chanctx_conf); | |
783 | if (WARN_ON(!ctx)) { | |
784 | rcu_read_unlock(); | |
785 | return -EINVAL; | |
786 | } | |
787 | chandef = ctx->def; | |
788 | chains_static = ctx->rx_chains_static; | |
789 | chains_dynamic = ctx->rx_chains_dynamic; | |
790 | rcu_read_unlock(); | |
791 | ||
792 | ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt, &chandef, | |
793 | chains_static, chains_dynamic); | |
794 | if (ret) | |
795 | return ret; | |
796 | ||
797 | /* add back the MAC */ | |
798 | mvmvif->uploaded = false; | |
799 | ||
800 | if (WARN_ON(!vif->bss_conf.assoc)) | |
801 | return -EINVAL; | |
802 | /* hack */ | |
803 | vif->bss_conf.assoc = false; | |
804 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); | |
805 | vif->bss_conf.assoc = true; | |
806 | if (ret) | |
807 | return ret; | |
808 | ||
809 | /* add back binding - XXX refactor? */ | |
810 | binding_cmd.id_and_color = | |
811 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id, | |
812 | mvmvif->phy_ctxt->color)); | |
813 | binding_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD); | |
814 | binding_cmd.phy = | |
815 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id, | |
816 | mvmvif->phy_ctxt->color)); | |
817 | binding_cmd.macs[0] = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, | |
818 | mvmvif->color)); | |
819 | for (i = 1; i < MAX_MACS_IN_BINDING; i++) | |
820 | binding_cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID); | |
821 | ||
822 | status = 0; | |
823 | ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD, | |
824 | sizeof(binding_cmd), &binding_cmd, | |
825 | &status); | |
826 | if (ret) { | |
827 | IWL_ERR(mvm, "Failed to add binding: %d\n", ret); | |
828 | return ret; | |
829 | } | |
830 | ||
831 | if (status) { | |
832 | IWL_ERR(mvm, "Binding command failed: %u\n", status); | |
833 | return -EIO; | |
834 | } | |
835 | ||
7a453973 | 836 | ret = iwl_mvm_sta_send_to_fw(mvm, ap_sta, false); |
8ca151b5 JB |
837 | if (ret) |
838 | return ret; | |
839 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], ap_sta); | |
840 | ||
841 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); | |
842 | if (ret) | |
843 | return ret; | |
844 | ||
845 | /* and some quota */ | |
846 | quota_cmd.quotas[0].id_and_color = | |
847 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id, | |
848 | mvmvif->phy_ctxt->color)); | |
849 | quota_cmd.quotas[0].quota = cpu_to_le32(100); | |
850 | quota_cmd.quotas[0].max_duration = cpu_to_le32(1000); | |
851 | ||
852 | for (i = 1; i < MAX_BINDINGS; i++) | |
853 | quota_cmd.quotas[i].id_and_color = cpu_to_le32(FW_CTXT_INVALID); | |
854 | ||
855 | ret = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, CMD_SYNC, | |
856 | sizeof(quota_cmd), "a_cmd); | |
857 | if (ret) | |
858 | IWL_ERR(mvm, "Failed to send quota: %d\n", ret); | |
859 | ||
860 | return 0; | |
861 | } | |
862 | ||
4ac6cb59 JB |
863 | static int iwl_mvm_get_last_nonqos_seq(struct iwl_mvm *mvm, |
864 | struct ieee80211_vif *vif) | |
865 | { | |
6d9d32b8 JB |
866 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
867 | struct iwl_nonqos_seq_query_cmd query_cmd = { | |
868 | .get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_GET), | |
869 | .mac_id_n_color = | |
870 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, | |
871 | mvmvif->color)), | |
872 | }; | |
4ac6cb59 JB |
873 | struct iwl_host_cmd cmd = { |
874 | .id = NON_QOS_TX_COUNTER_CMD, | |
875 | .flags = CMD_SYNC | CMD_WANT_SKB, | |
876 | }; | |
877 | int err; | |
878 | u32 size; | |
879 | ||
6d9d32b8 JB |
880 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_D3_CONTINUITY_API) { |
881 | cmd.data[0] = &query_cmd; | |
882 | cmd.len[0] = sizeof(query_cmd); | |
883 | } | |
884 | ||
4ac6cb59 JB |
885 | err = iwl_mvm_send_cmd(mvm, &cmd); |
886 | if (err) | |
887 | return err; | |
888 | ||
889 | size = le32_to_cpu(cmd.resp_pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; | |
890 | size -= sizeof(cmd.resp_pkt->hdr); | |
6d9d32b8 | 891 | if (size < sizeof(__le16)) { |
4ac6cb59 | 892 | err = -EINVAL; |
6d9d32b8 JB |
893 | } else { |
894 | err = le16_to_cpup((__le16 *)cmd.resp_pkt->data); | |
895 | /* new API returns next, not last-used seqno */ | |
896 | if (mvm->fw->ucode_capa.flags & | |
897 | IWL_UCODE_TLV_FLAGS_D3_CONTINUITY_API) | |
3c5da7ee | 898 | err = (u16) (err - 0x10); |
6d9d32b8 | 899 | } |
4ac6cb59 JB |
900 | |
901 | iwl_free_resp(&cmd); | |
902 | return err; | |
903 | } | |
904 | ||
6d9d32b8 JB |
905 | void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
906 | { | |
907 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
908 | struct iwl_nonqos_seq_query_cmd query_cmd = { | |
909 | .get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_SET), | |
910 | .mac_id_n_color = | |
911 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, | |
912 | mvmvif->color)), | |
913 | .value = cpu_to_le16(mvmvif->seqno), | |
914 | }; | |
915 | ||
916 | /* return if called during restart, not resume from D3 */ | |
917 | if (!mvmvif->seqno_valid) | |
918 | return; | |
919 | ||
920 | mvmvif->seqno_valid = false; | |
921 | ||
922 | if (!(mvm->fw->ucode_capa.flags & | |
923 | IWL_UCODE_TLV_FLAGS_D3_CONTINUITY_API)) | |
924 | return; | |
925 | ||
926 | if (iwl_mvm_send_cmd_pdu(mvm, NON_QOS_TX_COUNTER_CMD, CMD_SYNC, | |
927 | sizeof(query_cmd), &query_cmd)) | |
928 | IWL_ERR(mvm, "failed to set non-QoS seqno\n"); | |
929 | } | |
930 | ||
debff618 JB |
931 | static int __iwl_mvm_suspend(struct ieee80211_hw *hw, |
932 | struct cfg80211_wowlan *wowlan, | |
933 | bool test) | |
8ca151b5 JB |
934 | { |
935 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
936 | struct iwl_d3_iter_data suspend_iter_data = { | |
937 | .mvm = mvm, | |
938 | }; | |
939 | struct ieee80211_vif *vif; | |
940 | struct iwl_mvm_vif *mvmvif; | |
941 | struct ieee80211_sta *ap_sta; | |
942 | struct iwl_mvm_sta *mvm_ap_sta; | |
943 | struct iwl_wowlan_config_cmd wowlan_config_cmd = {}; | |
944 | struct iwl_wowlan_kek_kck_material_cmd kek_kck_cmd = {}; | |
945 | struct iwl_wowlan_tkip_params_cmd tkip_cmd = {}; | |
debff618 | 946 | struct iwl_d3_manager_config d3_cfg_cmd_data = { |
c920487d JB |
947 | /* |
948 | * Program the minimum sleep time to 10 seconds, as many | |
949 | * platforms have issues processing a wakeup signal while | |
950 | * still being in the process of suspending. | |
951 | */ | |
952 | .min_sleep_time = cpu_to_le32(10 * 1000 * 1000), | |
953 | }; | |
debff618 JB |
954 | struct iwl_host_cmd d3_cfg_cmd = { |
955 | .id = D3_CONFIG_CMD, | |
956 | .flags = CMD_SYNC | CMD_WANT_SKB, | |
957 | .data[0] = &d3_cfg_cmd_data, | |
958 | .len[0] = sizeof(d3_cfg_cmd_data), | |
959 | }; | |
8ca151b5 JB |
960 | struct wowlan_key_data key_data = { |
961 | .use_rsc_tsc = false, | |
962 | .tkip = &tkip_cmd, | |
963 | .use_tkip = false, | |
964 | }; | |
965 | int ret, i; | |
debff618 | 966 | int len __maybe_unused; |
8ca151b5 JB |
967 | u8 old_aux_sta_id, old_ap_sta_id = IWL_MVM_STATION_COUNT; |
968 | ||
debff618 JB |
969 | if (!wowlan) { |
970 | /* | |
971 | * mac80211 shouldn't get here, but for D3 test | |
972 | * it doesn't warrant a warning | |
973 | */ | |
974 | WARN_ON(!test); | |
8ca151b5 | 975 | return -EINVAL; |
debff618 | 976 | } |
8ca151b5 JB |
977 | |
978 | key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL); | |
979 | if (!key_data.rsc_tsc) | |
980 | return -ENOMEM; | |
981 | ||
982 | mutex_lock(&mvm->mutex); | |
983 | ||
984 | old_aux_sta_id = mvm->aux_sta.sta_id; | |
985 | ||
986 | /* see if there's only a single BSS vif and it's associated */ | |
987 | ieee80211_iterate_active_interfaces_atomic( | |
988 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
989 | iwl_mvm_d3_iface_iterator, &suspend_iter_data); | |
990 | ||
991 | if (suspend_iter_data.error || !suspend_iter_data.vif) { | |
992 | ret = 1; | |
993 | goto out_noreset; | |
994 | } | |
995 | ||
996 | vif = suspend_iter_data.vif; | |
997 | mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
998 | ||
999 | ap_sta = rcu_dereference_protected( | |
1000 | mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], | |
1001 | lockdep_is_held(&mvm->mutex)); | |
1002 | if (IS_ERR_OR_NULL(ap_sta)) { | |
1003 | ret = -EINVAL; | |
1004 | goto out_noreset; | |
1005 | } | |
1006 | ||
1007 | mvm_ap_sta = (struct iwl_mvm_sta *)ap_sta->drv_priv; | |
1008 | ||
8ca151b5 JB |
1009 | /* TODO: wowlan_config_cmd.wowlan_ba_teardown_tids */ |
1010 | ||
1011 | wowlan_config_cmd.is_11n_connection = ap_sta->ht_cap.ht_supported; | |
1012 | ||
4ac6cb59 JB |
1013 | /* Query the last used seqno and set it */ |
1014 | ret = iwl_mvm_get_last_nonqos_seq(mvm, vif); | |
1015 | if (ret < 0) | |
1016 | goto out_noreset; | |
1017 | wowlan_config_cmd.non_qos_seq = cpu_to_le16(ret); | |
8ca151b5 JB |
1018 | |
1019 | /* | |
1020 | * For QoS counters, we store the one to use next, so subtract 0x10 | |
1021 | * since the uCode will add 0x10 *before* using the value while we | |
1022 | * increment after using the value (i.e. store the next value to use). | |
1023 | */ | |
1024 | for (i = 0; i < IWL_MAX_TID_COUNT; i++) { | |
4ac6cb59 | 1025 | u16 seq = mvm_ap_sta->tid_data[i].seq_number; |
8ca151b5 JB |
1026 | seq -= 0x10; |
1027 | wowlan_config_cmd.qos_seq[i] = cpu_to_le16(seq); | |
1028 | } | |
1029 | ||
1030 | if (wowlan->disconnect) | |
1031 | wowlan_config_cmd.wakeup_filter |= | |
1032 | cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS | | |
1033 | IWL_WOWLAN_WAKEUP_LINK_CHANGE); | |
1034 | if (wowlan->magic_pkt) | |
1035 | wowlan_config_cmd.wakeup_filter |= | |
1036 | cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET); | |
1037 | if (wowlan->gtk_rekey_failure) | |
1038 | wowlan_config_cmd.wakeup_filter |= | |
1039 | cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL); | |
1040 | if (wowlan->eap_identity_req) | |
1041 | wowlan_config_cmd.wakeup_filter |= | |
1042 | cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ); | |
1043 | if (wowlan->four_way_handshake) | |
1044 | wowlan_config_cmd.wakeup_filter |= | |
1045 | cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE); | |
1046 | if (wowlan->n_patterns) | |
1047 | wowlan_config_cmd.wakeup_filter |= | |
1048 | cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH); | |
1049 | ||
1050 | if (wowlan->rfkill_release) | |
6039f3e1 | 1051 | wowlan_config_cmd.wakeup_filter |= |
8ca151b5 JB |
1052 | cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT); |
1053 | ||
f0c2646a JB |
1054 | if (wowlan->tcp) { |
1055 | /* | |
6039f3e1 JB |
1056 | * Set the "link change" (really "link lost") flag as well |
1057 | * since that implies losing the TCP connection. | |
f0c2646a JB |
1058 | */ |
1059 | wowlan_config_cmd.wakeup_filter |= | |
1060 | cpu_to_le32(IWL_WOWLAN_WAKEUP_REMOTE_LINK_LOSS | | |
1061 | IWL_WOWLAN_WAKEUP_REMOTE_SIGNATURE_TABLE | | |
1062 | IWL_WOWLAN_WAKEUP_REMOTE_WAKEUP_PACKET | | |
1063 | IWL_WOWLAN_WAKEUP_LINK_CHANGE); | |
1064 | } | |
1065 | ||
8ca151b5 JB |
1066 | iwl_mvm_cancel_scan(mvm); |
1067 | ||
1068 | iwl_trans_stop_device(mvm->trans); | |
1069 | ||
4ac6cb59 JB |
1070 | /* |
1071 | * The D3 firmware still hardcodes the AP station ID for the | |
1072 | * BSS we're associated with as 0. Store the real STA ID here | |
1073 | * and assign 0. When we leave this function, we'll restore | |
1074 | * the original value for the resume code. | |
1075 | */ | |
1076 | old_ap_sta_id = mvm_ap_sta->sta_id; | |
1077 | mvm_ap_sta->sta_id = 0; | |
1078 | mvmvif->ap_sta_id = 0; | |
1079 | ||
8ca151b5 JB |
1080 | /* |
1081 | * Set the HW restart bit -- this is mostly true as we're | |
1082 | * going to load new firmware and reprogram that, though | |
1083 | * the reprogramming is going to be manual to avoid adding | |
1084 | * all the MACs that aren't support. | |
1085 | * We don't have to clear up everything though because the | |
1086 | * reprogramming is manual. When we resume, we'll actually | |
1087 | * go through a proper restart sequence again to switch | |
1088 | * back to the runtime firmware image. | |
1089 | */ | |
1090 | set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
1091 | ||
1092 | /* We reprogram keys and shouldn't allocate new key indices */ | |
1093 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); | |
1094 | ||
f444eb10 JB |
1095 | mvm->ptk_ivlen = 0; |
1096 | mvm->ptk_icvlen = 0; | |
1097 | mvm->ptk_ivlen = 0; | |
1098 | mvm->ptk_icvlen = 0; | |
1099 | ||
8ca151b5 JB |
1100 | /* |
1101 | * The D3 firmware still hardcodes the AP station ID for the | |
1102 | * BSS we're associated with as 0. As a result, we have to move | |
1103 | * the auxiliary station to ID 1 so the ID 0 remains free for | |
1104 | * the AP station for later. | |
1105 | * We set the sta_id to 1 here, and reset it to its previous | |
1106 | * value (that we stored above) later. | |
1107 | */ | |
1108 | mvm->aux_sta.sta_id = 1; | |
1109 | ||
1110 | ret = iwl_mvm_load_d3_fw(mvm); | |
1111 | if (ret) | |
1112 | goto out; | |
1113 | ||
1114 | ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta); | |
1115 | if (ret) | |
1116 | goto out; | |
1117 | ||
1118 | if (!iwlwifi_mod_params.sw_crypto) { | |
1119 | /* | |
1120 | * This needs to be unlocked due to lock ordering | |
1121 | * constraints. Since we're in the suspend path | |
1122 | * that isn't really a problem though. | |
1123 | */ | |
1124 | mutex_unlock(&mvm->mutex); | |
1125 | ieee80211_iter_keys(mvm->hw, vif, | |
1126 | iwl_mvm_wowlan_program_keys, | |
1127 | &key_data); | |
1128 | mutex_lock(&mvm->mutex); | |
1129 | if (key_data.error) { | |
1130 | ret = -EIO; | |
1131 | goto out; | |
1132 | } | |
1133 | ||
1134 | if (key_data.use_rsc_tsc) { | |
1135 | struct iwl_host_cmd rsc_tsc_cmd = { | |
1136 | .id = WOWLAN_TSC_RSC_PARAM, | |
1137 | .flags = CMD_SYNC, | |
1138 | .data[0] = key_data.rsc_tsc, | |
1139 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, | |
1140 | .len[0] = sizeof(*key_data.rsc_tsc), | |
1141 | }; | |
1142 | ||
1143 | ret = iwl_mvm_send_cmd(mvm, &rsc_tsc_cmd); | |
1144 | if (ret) | |
1145 | goto out; | |
1146 | } | |
1147 | ||
1148 | if (key_data.use_tkip) { | |
1149 | ret = iwl_mvm_send_cmd_pdu(mvm, | |
1150 | WOWLAN_TKIP_PARAM, | |
1151 | CMD_SYNC, sizeof(tkip_cmd), | |
1152 | &tkip_cmd); | |
1153 | if (ret) | |
1154 | goto out; | |
1155 | } | |
1156 | ||
1157 | if (mvmvif->rekey_data.valid) { | |
1158 | memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd)); | |
1159 | memcpy(kek_kck_cmd.kck, mvmvif->rekey_data.kck, | |
1160 | NL80211_KCK_LEN); | |
1161 | kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN); | |
1162 | memcpy(kek_kck_cmd.kek, mvmvif->rekey_data.kek, | |
1163 | NL80211_KEK_LEN); | |
1164 | kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN); | |
1165 | kek_kck_cmd.replay_ctr = mvmvif->rekey_data.replay_ctr; | |
1166 | ||
1167 | ret = iwl_mvm_send_cmd_pdu(mvm, | |
1168 | WOWLAN_KEK_KCK_MATERIAL, | |
1169 | CMD_SYNC, | |
1170 | sizeof(kek_kck_cmd), | |
1171 | &kek_kck_cmd); | |
1172 | if (ret) | |
1173 | goto out; | |
1174 | } | |
1175 | } | |
1176 | ||
1177 | ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, | |
1178 | CMD_SYNC, sizeof(wowlan_config_cmd), | |
1179 | &wowlan_config_cmd); | |
1180 | if (ret) | |
1181 | goto out; | |
1182 | ||
1183 | ret = iwl_mvm_send_patterns(mvm, wowlan); | |
1184 | if (ret) | |
1185 | goto out; | |
1186 | ||
1187 | ret = iwl_mvm_send_proto_offload(mvm, vif); | |
1188 | if (ret) | |
1189 | goto out; | |
1190 | ||
f0c2646a JB |
1191 | ret = iwl_mvm_send_remote_wake_cfg(mvm, vif, wowlan->tcp); |
1192 | if (ret) | |
1193 | goto out; | |
1194 | ||
64b928c4 AB |
1195 | ret = iwl_mvm_power_update_device_mode(mvm); |
1196 | if (ret) | |
1197 | goto out; | |
1198 | ||
ee1e8422 AB |
1199 | ret = iwl_mvm_power_update_mode(mvm, vif); |
1200 | if (ret) | |
1201 | goto out; | |
1202 | ||
b0114714 JB |
1203 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
1204 | if (mvm->d3_wake_sysassert) | |
1205 | d3_cfg_cmd_data.wakeup_flags |= | |
1206 | cpu_to_le32(IWL_WAKEUP_D3_CONFIG_FW_ERROR); | |
1207 | #endif | |
1208 | ||
8ca151b5 | 1209 | /* must be last -- this switches firmware state */ |
debff618 | 1210 | ret = iwl_mvm_send_cmd(mvm, &d3_cfg_cmd); |
8ca151b5 JB |
1211 | if (ret) |
1212 | goto out; | |
debff618 JB |
1213 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
1214 | len = le32_to_cpu(d3_cfg_cmd.resp_pkt->len_n_flags) & | |
1215 | FH_RSCSR_FRAME_SIZE_MSK; | |
1216 | if (len >= sizeof(u32) * 2) { | |
1217 | mvm->d3_test_pme_ptr = | |
1218 | le32_to_cpup((__le32 *)d3_cfg_cmd.resp_pkt->data); | |
debff618 JB |
1219 | } |
1220 | #endif | |
1221 | iwl_free_resp(&d3_cfg_cmd); | |
8ca151b5 JB |
1222 | |
1223 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
1224 | ||
debff618 | 1225 | iwl_trans_d3_suspend(mvm->trans, test); |
8ca151b5 JB |
1226 | out: |
1227 | mvm->aux_sta.sta_id = old_aux_sta_id; | |
1228 | mvm_ap_sta->sta_id = old_ap_sta_id; | |
1229 | mvmvif->ap_sta_id = old_ap_sta_id; | |
1230 | out_noreset: | |
1231 | kfree(key_data.rsc_tsc); | |
1232 | if (ret < 0) | |
1233 | ieee80211_restart_hw(mvm->hw); | |
1234 | ||
1235 | mutex_unlock(&mvm->mutex); | |
1236 | ||
1237 | return ret; | |
1238 | } | |
1239 | ||
debff618 JB |
1240 | int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
1241 | { | |
1242 | return __iwl_mvm_suspend(hw, wowlan, false); | |
1243 | } | |
1244 | ||
6d9d32b8 JB |
1245 | /* converted data from the different status responses */ |
1246 | struct iwl_wowlan_status_data { | |
1247 | u16 pattern_number; | |
1248 | u16 qos_seq_ctr[8]; | |
1249 | u32 wakeup_reasons; | |
1250 | u32 wake_packet_length; | |
1251 | u32 wake_packet_bufsize; | |
1252 | const u8 *wake_packet; | |
1253 | }; | |
1254 | ||
7abc4632 JB |
1255 | static void iwl_mvm_report_wakeup_reasons(struct iwl_mvm *mvm, |
1256 | struct ieee80211_vif *vif, | |
6d9d32b8 | 1257 | struct iwl_wowlan_status_data *status) |
9b26b500 | 1258 | { |
7abc4632 | 1259 | struct sk_buff *pkt = NULL; |
9b26b500 JB |
1260 | struct cfg80211_wowlan_wakeup wakeup = { |
1261 | .pattern_idx = -1, | |
1262 | }; | |
1263 | struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup; | |
6d9d32b8 | 1264 | u32 reasons = status->wakeup_reasons; |
9b26b500 JB |
1265 | |
1266 | if (reasons == IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) { | |
1267 | wakeup_report = NULL; | |
1268 | goto report; | |
1269 | } | |
1270 | ||
f444eb10 | 1271 | if (reasons & IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET) |
9b26b500 | 1272 | wakeup.magic_pkt = true; |
9b26b500 | 1273 | |
f444eb10 | 1274 | if (reasons & IWL_WOWLAN_WAKEUP_BY_PATTERN) |
9b26b500 | 1275 | wakeup.pattern_idx = |
6d9d32b8 | 1276 | status->pattern_number; |
9b26b500 JB |
1277 | |
1278 | if (reasons & (IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON | | |
1279 | IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH)) | |
1280 | wakeup.disconnect = true; | |
1281 | ||
f444eb10 | 1282 | if (reasons & IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE) |
9b26b500 | 1283 | wakeup.gtk_rekey_failure = true; |
9b26b500 | 1284 | |
f444eb10 | 1285 | if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED) |
9b26b500 | 1286 | wakeup.rfkill_release = true; |
9b26b500 | 1287 | |
f444eb10 | 1288 | if (reasons & IWL_WOWLAN_WAKEUP_BY_EAPOL_REQUEST) |
9b26b500 | 1289 | wakeup.eap_identity_req = true; |
9b26b500 | 1290 | |
f444eb10 | 1291 | if (reasons & IWL_WOWLAN_WAKEUP_BY_FOUR_WAY_HANDSHAKE) |
9b26b500 | 1292 | wakeup.four_way_handshake = true; |
9b26b500 | 1293 | |
f0c2646a JB |
1294 | if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_LINK_LOSS) |
1295 | wakeup.tcp_connlost = true; | |
1296 | ||
1297 | if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_SIGNATURE_TABLE) | |
1298 | wakeup.tcp_nomoretokens = true; | |
1299 | ||
1300 | if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_WAKEUP_PACKET) | |
1301 | wakeup.tcp_match = true; | |
1302 | ||
9b26b500 | 1303 | if (status->wake_packet_bufsize) { |
6d9d32b8 JB |
1304 | int pktsize = status->wake_packet_bufsize; |
1305 | int pktlen = status->wake_packet_length; | |
f444eb10 JB |
1306 | const u8 *pktdata = status->wake_packet; |
1307 | struct ieee80211_hdr *hdr = (void *)pktdata; | |
1308 | int truncated = pktlen - pktsize; | |
1309 | ||
1310 | /* this would be a firmware bug */ | |
1311 | if (WARN_ON_ONCE(truncated < 0)) | |
1312 | truncated = 0; | |
1313 | ||
1314 | if (ieee80211_is_data(hdr->frame_control)) { | |
1315 | int hdrlen = ieee80211_hdrlen(hdr->frame_control); | |
1316 | int ivlen = 0, icvlen = 4; /* also FCS */ | |
9b26b500 | 1317 | |
9b26b500 JB |
1318 | pkt = alloc_skb(pktsize, GFP_KERNEL); |
1319 | if (!pkt) | |
1320 | goto report; | |
f444eb10 JB |
1321 | |
1322 | memcpy(skb_put(pkt, hdrlen), pktdata, hdrlen); | |
1323 | pktdata += hdrlen; | |
1324 | pktsize -= hdrlen; | |
1325 | ||
1326 | if (ieee80211_has_protected(hdr->frame_control)) { | |
7abc4632 JB |
1327 | /* |
1328 | * This is unlocked and using gtk_i(c)vlen, | |
1329 | * but since everything is under RTNL still | |
1330 | * that's not really a problem - changing | |
1331 | * it would be difficult. | |
1332 | */ | |
f444eb10 JB |
1333 | if (is_multicast_ether_addr(hdr->addr1)) { |
1334 | ivlen = mvm->gtk_ivlen; | |
1335 | icvlen += mvm->gtk_icvlen; | |
1336 | } else { | |
1337 | ivlen = mvm->ptk_ivlen; | |
1338 | icvlen += mvm->ptk_icvlen; | |
1339 | } | |
1340 | } | |
1341 | ||
1342 | /* if truncated, FCS/ICV is (partially) gone */ | |
1343 | if (truncated >= icvlen) { | |
1344 | icvlen = 0; | |
1345 | truncated -= icvlen; | |
1346 | } else { | |
1347 | icvlen -= truncated; | |
1348 | truncated = 0; | |
1349 | } | |
1350 | ||
1351 | pktsize -= ivlen + icvlen; | |
1352 | pktdata += ivlen; | |
1353 | ||
1354 | memcpy(skb_put(pkt, pktsize), pktdata, pktsize); | |
1355 | ||
9b26b500 JB |
1356 | if (ieee80211_data_to_8023(pkt, vif->addr, vif->type)) |
1357 | goto report; | |
1358 | wakeup.packet = pkt->data; | |
1359 | wakeup.packet_present_len = pkt->len; | |
f444eb10 | 1360 | wakeup.packet_len = pkt->len - truncated; |
9b26b500 JB |
1361 | wakeup.packet_80211 = false; |
1362 | } else { | |
f444eb10 JB |
1363 | int fcslen = 4; |
1364 | ||
1365 | if (truncated >= 4) { | |
1366 | truncated -= 4; | |
1367 | fcslen = 0; | |
1368 | } else { | |
1369 | fcslen -= truncated; | |
1370 | truncated = 0; | |
1371 | } | |
1372 | pktsize -= fcslen; | |
9b26b500 JB |
1373 | wakeup.packet = status->wake_packet; |
1374 | wakeup.packet_present_len = pktsize; | |
f444eb10 | 1375 | wakeup.packet_len = pktlen - truncated; |
9b26b500 JB |
1376 | wakeup.packet_80211 = true; |
1377 | } | |
1378 | } | |
1379 | ||
1380 | report: | |
1381 | ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL); | |
1382 | kfree_skb(pkt); | |
7abc4632 | 1383 | } |
9b26b500 | 1384 | |
6d9d32b8 JB |
1385 | static void iwl_mvm_aes_sc_to_seq(struct aes_sc *sc, |
1386 | struct ieee80211_key_seq *seq) | |
1387 | { | |
1388 | u64 pn; | |
1389 | ||
1390 | pn = le64_to_cpu(sc->pn); | |
1391 | seq->ccmp.pn[0] = pn >> 40; | |
1392 | seq->ccmp.pn[1] = pn >> 32; | |
1393 | seq->ccmp.pn[2] = pn >> 24; | |
1394 | seq->ccmp.pn[3] = pn >> 16; | |
1395 | seq->ccmp.pn[4] = pn >> 8; | |
1396 | seq->ccmp.pn[5] = pn; | |
1397 | } | |
1398 | ||
1399 | static void iwl_mvm_tkip_sc_to_seq(struct tkip_sc *sc, | |
1400 | struct ieee80211_key_seq *seq) | |
1401 | { | |
1402 | seq->tkip.iv32 = le32_to_cpu(sc->iv32); | |
1403 | seq->tkip.iv16 = le16_to_cpu(sc->iv16); | |
1404 | } | |
1405 | ||
1406 | static void iwl_mvm_set_aes_rx_seq(struct aes_sc *scs, | |
1407 | struct ieee80211_key_conf *key) | |
1408 | { | |
1409 | int tid; | |
1410 | ||
1411 | BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS); | |
1412 | ||
1413 | for (tid = 0; tid < IWL_NUM_RSC; tid++) { | |
1414 | struct ieee80211_key_seq seq = {}; | |
1415 | ||
1416 | iwl_mvm_aes_sc_to_seq(&scs[tid], &seq); | |
1417 | ieee80211_set_key_rx_seq(key, tid, &seq); | |
1418 | } | |
1419 | } | |
1420 | ||
1421 | static void iwl_mvm_set_tkip_rx_seq(struct tkip_sc *scs, | |
1422 | struct ieee80211_key_conf *key) | |
1423 | { | |
1424 | int tid; | |
1425 | ||
1426 | BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS); | |
1427 | ||
1428 | for (tid = 0; tid < IWL_NUM_RSC; tid++) { | |
1429 | struct ieee80211_key_seq seq = {}; | |
1430 | ||
1431 | iwl_mvm_tkip_sc_to_seq(&scs[tid], &seq); | |
1432 | ieee80211_set_key_rx_seq(key, tid, &seq); | |
1433 | } | |
1434 | } | |
1435 | ||
1436 | static void iwl_mvm_set_key_rx_seq(struct ieee80211_key_conf *key, | |
1437 | struct iwl_wowlan_status_v6 *status) | |
1438 | { | |
1439 | union iwl_all_tsc_rsc *rsc = &status->gtk.rsc.all_tsc_rsc; | |
1440 | ||
1441 | switch (key->cipher) { | |
1442 | case WLAN_CIPHER_SUITE_CCMP: | |
1443 | iwl_mvm_set_aes_rx_seq(rsc->aes.multicast_rsc, key); | |
1444 | break; | |
1445 | case WLAN_CIPHER_SUITE_TKIP: | |
1446 | iwl_mvm_set_tkip_rx_seq(rsc->tkip.multicast_rsc, key); | |
1447 | break; | |
1448 | default: | |
1449 | WARN_ON(1); | |
1450 | } | |
1451 | } | |
1452 | ||
1453 | struct iwl_mvm_d3_gtk_iter_data { | |
1454 | struct iwl_wowlan_status_v6 *status; | |
1455 | void *last_gtk; | |
1456 | u32 cipher; | |
1457 | bool find_phase, unhandled_cipher; | |
1458 | int num_keys; | |
1459 | }; | |
1460 | ||
1461 | static void iwl_mvm_d3_update_gtks(struct ieee80211_hw *hw, | |
1462 | struct ieee80211_vif *vif, | |
1463 | struct ieee80211_sta *sta, | |
1464 | struct ieee80211_key_conf *key, | |
1465 | void *_data) | |
1466 | { | |
1467 | struct iwl_mvm_d3_gtk_iter_data *data = _data; | |
1468 | ||
1469 | if (data->unhandled_cipher) | |
1470 | return; | |
1471 | ||
1472 | switch (key->cipher) { | |
1473 | case WLAN_CIPHER_SUITE_WEP40: | |
1474 | case WLAN_CIPHER_SUITE_WEP104: | |
1475 | /* ignore WEP completely, nothing to do */ | |
1476 | return; | |
1477 | case WLAN_CIPHER_SUITE_CCMP: | |
1478 | case WLAN_CIPHER_SUITE_TKIP: | |
1479 | /* we support these */ | |
1480 | break; | |
1481 | default: | |
1482 | /* everything else (even CMAC for MFP) - disconnect from AP */ | |
1483 | data->unhandled_cipher = true; | |
1484 | return; | |
1485 | } | |
1486 | ||
1487 | data->num_keys++; | |
1488 | ||
1489 | /* | |
1490 | * pairwise key - update sequence counters only; | |
1491 | * note that this assumes no TDLS sessions are active | |
1492 | */ | |
1493 | if (sta) { | |
1494 | struct ieee80211_key_seq seq = {}; | |
1495 | union iwl_all_tsc_rsc *sc = &data->status->gtk.rsc.all_tsc_rsc; | |
1496 | ||
1497 | if (data->find_phase) | |
1498 | return; | |
1499 | ||
1500 | switch (key->cipher) { | |
1501 | case WLAN_CIPHER_SUITE_CCMP: | |
1502 | iwl_mvm_aes_sc_to_seq(&sc->aes.tsc, &seq); | |
1503 | iwl_mvm_set_aes_rx_seq(sc->aes.unicast_rsc, key); | |
1504 | break; | |
1505 | case WLAN_CIPHER_SUITE_TKIP: | |
1506 | iwl_mvm_tkip_sc_to_seq(&sc->tkip.tsc, &seq); | |
1507 | iwl_mvm_set_tkip_rx_seq(sc->tkip.unicast_rsc, key); | |
1508 | break; | |
1509 | } | |
1510 | ieee80211_set_key_tx_seq(key, &seq); | |
1511 | ||
1512 | /* that's it for this key */ | |
1513 | return; | |
1514 | } | |
1515 | ||
1516 | if (data->find_phase) { | |
1517 | data->last_gtk = key; | |
1518 | data->cipher = key->cipher; | |
1519 | return; | |
1520 | } | |
1521 | ||
1522 | if (data->status->num_of_gtk_rekeys) | |
1523 | ieee80211_remove_key(key); | |
1524 | else if (data->last_gtk == key) | |
1525 | iwl_mvm_set_key_rx_seq(key, data->status); | |
1526 | } | |
1527 | ||
1528 | static bool iwl_mvm_setup_connection_keep(struct iwl_mvm *mvm, | |
1529 | struct ieee80211_vif *vif, | |
1530 | struct iwl_wowlan_status_v6 *status) | |
1531 | { | |
1532 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
1533 | struct iwl_mvm_d3_gtk_iter_data gtkdata = { | |
1534 | .status = status, | |
1535 | }; | |
431591cc EP |
1536 | u32 disconnection_reasons = |
1537 | IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON | | |
1538 | IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH; | |
6d9d32b8 JB |
1539 | |
1540 | if (!status || !vif->bss_conf.bssid) | |
1541 | return false; | |
1542 | ||
431591cc EP |
1543 | if (le32_to_cpu(status->wakeup_reasons) & disconnection_reasons) |
1544 | return false; | |
1545 | ||
6d9d32b8 JB |
1546 | /* find last GTK that we used initially, if any */ |
1547 | gtkdata.find_phase = true; | |
1548 | ieee80211_iter_keys(mvm->hw, vif, | |
1549 | iwl_mvm_d3_update_gtks, >kdata); | |
1550 | /* not trying to keep connections with MFP/unhandled ciphers */ | |
1551 | if (gtkdata.unhandled_cipher) | |
1552 | return false; | |
1553 | if (!gtkdata.num_keys) | |
cfa88893 | 1554 | goto out; |
6d9d32b8 JB |
1555 | if (!gtkdata.last_gtk) |
1556 | return false; | |
1557 | ||
1558 | /* | |
1559 | * invalidate all other GTKs that might still exist and update | |
1560 | * the one that we used | |
1561 | */ | |
1562 | gtkdata.find_phase = false; | |
1563 | ieee80211_iter_keys(mvm->hw, vif, | |
1564 | iwl_mvm_d3_update_gtks, >kdata); | |
1565 | ||
1566 | if (status->num_of_gtk_rekeys) { | |
1567 | struct ieee80211_key_conf *key; | |
1568 | struct { | |
1569 | struct ieee80211_key_conf conf; | |
1570 | u8 key[32]; | |
1571 | } conf = { | |
1572 | .conf.cipher = gtkdata.cipher, | |
1573 | .conf.keyidx = status->gtk.key_index, | |
1574 | }; | |
1575 | ||
1576 | switch (gtkdata.cipher) { | |
1577 | case WLAN_CIPHER_SUITE_CCMP: | |
1578 | conf.conf.keylen = WLAN_KEY_LEN_CCMP; | |
1579 | memcpy(conf.conf.key, status->gtk.decrypt_key, | |
1580 | WLAN_KEY_LEN_CCMP); | |
1581 | break; | |
1582 | case WLAN_CIPHER_SUITE_TKIP: | |
1583 | conf.conf.keylen = WLAN_KEY_LEN_TKIP; | |
1584 | memcpy(conf.conf.key, status->gtk.decrypt_key, 16); | |
1585 | /* leave TX MIC key zeroed, we don't use it anyway */ | |
1586 | memcpy(conf.conf.key + | |
1587 | NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY, | |
1588 | status->gtk.tkip_mic_key, 8); | |
1589 | break; | |
1590 | } | |
1591 | ||
1592 | key = ieee80211_gtk_rekey_add(vif, &conf.conf); | |
1593 | if (IS_ERR(key)) | |
1594 | return false; | |
1595 | iwl_mvm_set_key_rx_seq(key, status); | |
1596 | } | |
1597 | ||
1598 | if (status->num_of_gtk_rekeys) { | |
1599 | __be64 replay_ctr = | |
1600 | cpu_to_be64(le64_to_cpu(status->replay_ctr)); | |
1601 | ieee80211_gtk_rekey_notify(vif, vif->bss_conf.bssid, | |
1602 | (void *)&replay_ctr, GFP_KERNEL); | |
1603 | } | |
1604 | ||
cfa88893 | 1605 | out: |
6d9d32b8 JB |
1606 | mvmvif->seqno_valid = true; |
1607 | /* +0x10 because the set API expects next-to-use, not last-used */ | |
1608 | mvmvif->seqno = le16_to_cpu(status->non_qos_seq_ctr) + 0x10; | |
1609 | ||
1610 | return true; | |
1611 | } | |
1612 | ||
7abc4632 | 1613 | /* releases the MVM mutex */ |
6d9d32b8 | 1614 | static bool iwl_mvm_query_wakeup_reasons(struct iwl_mvm *mvm, |
7abc4632 JB |
1615 | struct ieee80211_vif *vif) |
1616 | { | |
1617 | u32 base = mvm->error_event_table; | |
1618 | struct error_table_start { | |
1619 | /* cf. struct iwl_error_event_table */ | |
1620 | u32 valid; | |
1621 | u32 error_id; | |
1622 | } err_info; | |
1623 | struct iwl_host_cmd cmd = { | |
1624 | .id = WOWLAN_GET_STATUSES, | |
1625 | .flags = CMD_SYNC | CMD_WANT_SKB, | |
1626 | }; | |
6d9d32b8 JB |
1627 | struct iwl_wowlan_status_data status; |
1628 | struct iwl_wowlan_status_v6 *status_v6; | |
1629 | int ret, len, status_size, i; | |
1630 | bool keep; | |
1631 | struct ieee80211_sta *ap_sta; | |
1632 | struct iwl_mvm_sta *mvm_ap_sta; | |
7abc4632 JB |
1633 | |
1634 | iwl_trans_read_mem_bytes(mvm->trans, base, | |
1635 | &err_info, sizeof(err_info)); | |
1636 | ||
1637 | if (err_info.valid) { | |
1638 | IWL_INFO(mvm, "error table is valid (%d)\n", | |
1639 | err_info.valid); | |
1640 | if (err_info.error_id == RF_KILL_INDICATOR_FOR_WOWLAN) { | |
1641 | struct cfg80211_wowlan_wakeup wakeup = { | |
1642 | .rfkill_release = true, | |
1643 | }; | |
1644 | ieee80211_report_wowlan_wakeup(vif, &wakeup, | |
1645 | GFP_KERNEL); | |
1646 | } | |
1647 | goto out_unlock; | |
1648 | } | |
1649 | ||
1650 | /* only for tracing for now */ | |
1651 | ret = iwl_mvm_send_cmd_pdu(mvm, OFFLOADS_QUERY_CMD, CMD_SYNC, 0, NULL); | |
1652 | if (ret) | |
1653 | IWL_ERR(mvm, "failed to query offload statistics (%d)\n", ret); | |
1654 | ||
1655 | ret = iwl_mvm_send_cmd(mvm, &cmd); | |
1656 | if (ret) { | |
1657 | IWL_ERR(mvm, "failed to query status (%d)\n", ret); | |
1658 | goto out_unlock; | |
1659 | } | |
1660 | ||
1661 | /* RF-kill already asserted again... */ | |
1662 | if (!cmd.resp_pkt) | |
1663 | goto out_unlock; | |
1664 | ||
6d9d32b8 JB |
1665 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_D3_CONTINUITY_API) |
1666 | status_size = sizeof(struct iwl_wowlan_status_v6); | |
1667 | else | |
1668 | status_size = sizeof(struct iwl_wowlan_status_v4); | |
1669 | ||
7abc4632 | 1670 | len = le32_to_cpu(cmd.resp_pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
6d9d32b8 | 1671 | if (len - sizeof(struct iwl_cmd_header) < status_size) { |
7abc4632 JB |
1672 | IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); |
1673 | goto out_free_resp; | |
1674 | } | |
1675 | ||
6d9d32b8 JB |
1676 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_D3_CONTINUITY_API) { |
1677 | status_v6 = (void *)cmd.resp_pkt->data; | |
1678 | ||
1679 | status.pattern_number = le16_to_cpu(status_v6->pattern_number); | |
1680 | for (i = 0; i < 8; i++) | |
1681 | status.qos_seq_ctr[i] = | |
1682 | le16_to_cpu(status_v6->qos_seq_ctr[i]); | |
1683 | status.wakeup_reasons = le32_to_cpu(status_v6->wakeup_reasons); | |
1684 | status.wake_packet_length = | |
1685 | le32_to_cpu(status_v6->wake_packet_length); | |
1686 | status.wake_packet_bufsize = | |
1687 | le32_to_cpu(status_v6->wake_packet_bufsize); | |
1688 | status.wake_packet = status_v6->wake_packet; | |
1689 | } else { | |
1690 | struct iwl_wowlan_status_v4 *status_v4; | |
1691 | status_v6 = NULL; | |
1692 | status_v4 = (void *)cmd.resp_pkt->data; | |
1693 | ||
1694 | status.pattern_number = le16_to_cpu(status_v4->pattern_number); | |
1695 | for (i = 0; i < 8; i++) | |
1696 | status.qos_seq_ctr[i] = | |
1697 | le16_to_cpu(status_v4->qos_seq_ctr[i]); | |
1698 | status.wakeup_reasons = le32_to_cpu(status_v4->wakeup_reasons); | |
1699 | status.wake_packet_length = | |
1700 | le32_to_cpu(status_v4->wake_packet_length); | |
1701 | status.wake_packet_bufsize = | |
1702 | le32_to_cpu(status_v4->wake_packet_bufsize); | |
1703 | status.wake_packet = status_v4->wake_packet; | |
1704 | } | |
7abc4632 JB |
1705 | |
1706 | if (len - sizeof(struct iwl_cmd_header) != | |
6d9d32b8 | 1707 | status_size + ALIGN(status.wake_packet_bufsize, 4)) { |
7abc4632 JB |
1708 | IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); |
1709 | goto out_free_resp; | |
1710 | } | |
1711 | ||
6d9d32b8 JB |
1712 | /* still at hard-coded place 0 for D3 image */ |
1713 | ap_sta = rcu_dereference_protected( | |
1714 | mvm->fw_id_to_mac_id[0], | |
1715 | lockdep_is_held(&mvm->mutex)); | |
1716 | if (IS_ERR_OR_NULL(ap_sta)) | |
1717 | goto out_free_resp; | |
1718 | ||
1719 | mvm_ap_sta = (struct iwl_mvm_sta *)ap_sta->drv_priv; | |
1720 | for (i = 0; i < IWL_MAX_TID_COUNT; i++) { | |
1721 | u16 seq = status.qos_seq_ctr[i]; | |
1722 | /* firmware stores last-used value, we store next value */ | |
1723 | seq += 0x10; | |
1724 | mvm_ap_sta->tid_data[i].seq_number = seq; | |
1725 | } | |
1726 | ||
7abc4632 JB |
1727 | /* now we have all the data we need, unlock to avoid mac80211 issues */ |
1728 | mutex_unlock(&mvm->mutex); | |
1729 | ||
6d9d32b8 JB |
1730 | iwl_mvm_report_wakeup_reasons(mvm, vif, &status); |
1731 | ||
1732 | keep = iwl_mvm_setup_connection_keep(mvm, vif, status_v6); | |
1733 | ||
7abc4632 | 1734 | iwl_free_resp(&cmd); |
6d9d32b8 | 1735 | return keep; |
7abc4632 JB |
1736 | |
1737 | out_free_resp: | |
9b26b500 | 1738 | iwl_free_resp(&cmd); |
7abc4632 JB |
1739 | out_unlock: |
1740 | mutex_unlock(&mvm->mutex); | |
6d9d32b8 | 1741 | return false; |
9b26b500 JB |
1742 | } |
1743 | ||
afc66bb7 JB |
1744 | static void iwl_mvm_read_d3_sram(struct iwl_mvm *mvm) |
1745 | { | |
1746 | #ifdef CONFIG_IWLWIFI_DEBUGFS | |
1747 | const struct fw_img *img = &mvm->fw->img[IWL_UCODE_WOWLAN]; | |
1748 | u32 len = img->sec[IWL_UCODE_SECTION_DATA].len; | |
1749 | u32 offs = img->sec[IWL_UCODE_SECTION_DATA].offset; | |
1750 | ||
1751 | if (!mvm->store_d3_resume_sram) | |
1752 | return; | |
1753 | ||
1754 | if (!mvm->d3_resume_sram) { | |
1755 | mvm->d3_resume_sram = kzalloc(len, GFP_KERNEL); | |
1756 | if (!mvm->d3_resume_sram) | |
1757 | return; | |
1758 | } | |
1759 | ||
1760 | iwl_trans_read_mem_bytes(mvm->trans, offs, mvm->d3_resume_sram, len); | |
1761 | #endif | |
1762 | } | |
1763 | ||
6d9d32b8 JB |
1764 | static void iwl_mvm_d3_disconnect_iter(void *data, u8 *mac, |
1765 | struct ieee80211_vif *vif) | |
1766 | { | |
1767 | /* skip the one we keep connection on */ | |
1768 | if (data == vif) | |
1769 | return; | |
1770 | ||
1771 | if (vif->type == NL80211_IFTYPE_STATION) | |
1772 | ieee80211_resume_disconnect(vif); | |
1773 | } | |
1774 | ||
debff618 | 1775 | static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test) |
8ca151b5 | 1776 | { |
8ca151b5 JB |
1777 | struct iwl_d3_iter_data resume_iter_data = { |
1778 | .mvm = mvm, | |
1779 | }; | |
1780 | struct ieee80211_vif *vif = NULL; | |
8ca151b5 JB |
1781 | int ret; |
1782 | enum iwl_d3_status d3_status; | |
6d9d32b8 | 1783 | bool keep = false; |
8ca151b5 JB |
1784 | |
1785 | mutex_lock(&mvm->mutex); | |
1786 | ||
1787 | /* get the BSS vif pointer again */ | |
1788 | ieee80211_iterate_active_interfaces_atomic( | |
1789 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
1790 | iwl_mvm_d3_iface_iterator, &resume_iter_data); | |
1791 | ||
1792 | if (WARN_ON(resume_iter_data.error || !resume_iter_data.vif)) | |
1793 | goto out_unlock; | |
1794 | ||
1795 | vif = resume_iter_data.vif; | |
1796 | ||
debff618 | 1797 | ret = iwl_trans_d3_resume(mvm->trans, &d3_status, test); |
8ca151b5 JB |
1798 | if (ret) |
1799 | goto out_unlock; | |
1800 | ||
1801 | if (d3_status != IWL_D3_STATUS_ALIVE) { | |
1802 | IWL_INFO(mvm, "Device was reset during suspend\n"); | |
1803 | goto out_unlock; | |
1804 | } | |
1805 | ||
afc66bb7 JB |
1806 | /* query SRAM first in case we want event logging */ |
1807 | iwl_mvm_read_d3_sram(mvm); | |
1808 | ||
6d9d32b8 | 1809 | keep = iwl_mvm_query_wakeup_reasons(mvm, vif); |
78c9df66 EP |
1810 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
1811 | if (keep) | |
1812 | mvm->keep_vif = vif; | |
1813 | #endif | |
7abc4632 JB |
1814 | /* has unlocked the mutex, so skip that */ |
1815 | goto out; | |
8ca151b5 JB |
1816 | |
1817 | out_unlock: | |
1818 | mutex_unlock(&mvm->mutex); | |
1819 | ||
7abc4632 | 1820 | out: |
6d9d32b8 JB |
1821 | if (!test) |
1822 | ieee80211_iterate_active_interfaces_rtnl(mvm->hw, | |
1823 | IEEE80211_IFACE_ITER_NORMAL, | |
1824 | iwl_mvm_d3_disconnect_iter, keep ? vif : NULL); | |
8ca151b5 JB |
1825 | |
1826 | /* return 1 to reconfigure the device */ | |
1827 | set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); | |
1828 | return 1; | |
1829 | } | |
1830 | ||
debff618 JB |
1831 | int iwl_mvm_resume(struct ieee80211_hw *hw) |
1832 | { | |
1833 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1834 | ||
1835 | return __iwl_mvm_resume(mvm, false); | |
1836 | } | |
1837 | ||
8ca151b5 JB |
1838 | void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled) |
1839 | { | |
1840 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); | |
1841 | ||
1842 | device_set_wakeup_enable(mvm->trans->dev, enabled); | |
1843 | } | |
debff618 JB |
1844 | |
1845 | #ifdef CONFIG_IWLWIFI_DEBUGFS | |
1846 | static int iwl_mvm_d3_test_open(struct inode *inode, struct file *file) | |
1847 | { | |
1848 | struct iwl_mvm *mvm = inode->i_private; | |
1849 | int err; | |
1850 | ||
1851 | if (mvm->d3_test_active) | |
1852 | return -EBUSY; | |
1853 | ||
1854 | file->private_data = inode->i_private; | |
1855 | ||
1856 | ieee80211_stop_queues(mvm->hw); | |
1857 | synchronize_net(); | |
1858 | ||
1859 | /* start pseudo D3 */ | |
1860 | rtnl_lock(); | |
1861 | err = __iwl_mvm_suspend(mvm->hw, mvm->hw->wiphy->wowlan_config, true); | |
1862 | rtnl_unlock(); | |
1863 | if (err > 0) | |
1864 | err = -EINVAL; | |
1865 | if (err) { | |
1866 | ieee80211_wake_queues(mvm->hw); | |
1867 | return err; | |
1868 | } | |
1869 | mvm->d3_test_active = true; | |
78c9df66 | 1870 | mvm->keep_vif = NULL; |
debff618 JB |
1871 | return 0; |
1872 | } | |
1873 | ||
1874 | static ssize_t iwl_mvm_d3_test_read(struct file *file, char __user *user_buf, | |
1875 | size_t count, loff_t *ppos) | |
1876 | { | |
1877 | struct iwl_mvm *mvm = file->private_data; | |
1878 | u32 pme_asserted; | |
1879 | ||
1880 | while (true) { | |
4ed80a86 EP |
1881 | /* read pme_ptr if available */ |
1882 | if (mvm->d3_test_pme_ptr) { | |
1883 | pme_asserted = iwl_trans_read_mem32(mvm->trans, | |
1884 | mvm->d3_test_pme_ptr); | |
1885 | if (pme_asserted) | |
1886 | break; | |
1887 | } | |
1888 | ||
debff618 JB |
1889 | if (msleep_interruptible(100)) |
1890 | break; | |
1891 | } | |
1892 | ||
1893 | return 0; | |
1894 | } | |
1895 | ||
1896 | static void iwl_mvm_d3_test_disconn_work_iter(void *_data, u8 *mac, | |
1897 | struct ieee80211_vif *vif) | |
1898 | { | |
78c9df66 EP |
1899 | /* skip the one we keep connection on */ |
1900 | if (_data == vif) | |
1901 | return; | |
1902 | ||
debff618 JB |
1903 | if (vif->type == NL80211_IFTYPE_STATION) |
1904 | ieee80211_connection_loss(vif); | |
1905 | } | |
1906 | ||
1907 | static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file) | |
1908 | { | |
1909 | struct iwl_mvm *mvm = inode->i_private; | |
1910 | int remaining_time = 10; | |
1911 | ||
1912 | mvm->d3_test_active = false; | |
1913 | __iwl_mvm_resume(mvm, true); | |
1914 | iwl_abort_notification_waits(&mvm->notif_wait); | |
1915 | ieee80211_restart_hw(mvm->hw); | |
1916 | ||
1917 | /* wait for restart and disconnect all interfaces */ | |
1918 | while (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && | |
1919 | remaining_time > 0) { | |
1920 | remaining_time--; | |
1921 | msleep(1000); | |
1922 | } | |
1923 | ||
1924 | if (remaining_time == 0) | |
1925 | IWL_ERR(mvm, "Timed out waiting for HW restart to finish!\n"); | |
1926 | ||
1927 | ieee80211_iterate_active_interfaces_atomic( | |
1928 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, | |
78c9df66 | 1929 | iwl_mvm_d3_test_disconn_work_iter, mvm->keep_vif); |
debff618 JB |
1930 | |
1931 | ieee80211_wake_queues(mvm->hw); | |
1932 | ||
1933 | return 0; | |
1934 | } | |
1935 | ||
1936 | const struct file_operations iwl_dbgfs_d3_test_ops = { | |
1937 | .llseek = no_llseek, | |
1938 | .open = iwl_mvm_d3_test_open, | |
1939 | .read = iwl_mvm_d3_test_read, | |
1940 | .release = iwl_mvm_d3_test_release, | |
1941 | }; | |
1942 | #endif |