blob: 6ac40727541e6632f70ccab0d5fed47bf583d407 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Luciano Coelho65ff5562015-03-20 13:35:47 +02009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
28 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020029 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010030 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Luciano Coelho65ff5562015-03-20 13:35:47 +020035 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65
Johannes Bergf444eb12013-02-26 12:04:18 +010066#include <linux/etherdevice.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010067#include <linux/ip.h>
Johannes Bergdebff612013-05-14 13:53:45 +020068#include <linux/fs.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010069#include <net/cfg80211.h>
70#include <net/ipv6.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010071#include <net/tcp.h>
Johannes Bergf7fc5982013-08-20 13:04:10 +020072#include <net/addrconf.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010073#include "iwl-modparams.h"
74#include "fw-api.h"
75#include "mvm.h"
76
77void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw,
78 struct ieee80211_vif *vif,
79 struct cfg80211_gtk_rekey_data *data)
80{
81 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
82 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
83
84 if (iwlwifi_mod_params.sw_crypto)
85 return;
86
87 mutex_lock(&mvm->mutex);
88
89 memcpy(mvmvif->rekey_data.kek, data->kek, NL80211_KEK_LEN);
90 memcpy(mvmvif->rekey_data.kck, data->kck, NL80211_KCK_LEN);
91 mvmvif->rekey_data.replay_ctr =
92 cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
93 mvmvif->rekey_data.valid = true;
94
95 mutex_unlock(&mvm->mutex);
96}
97
98#if IS_ENABLED(CONFIG_IPV6)
99void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw,
100 struct ieee80211_vif *vif,
101 struct inet6_dev *idev)
102{
103 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
104 struct inet6_ifaddr *ifa;
105 int idx = 0;
106
Sara Sharonc97dab42015-11-19 11:53:49 +0200107 memset(mvmvif->tentative_addrs, 0, sizeof(mvmvif->tentative_addrs));
108
Emmanuel Grumbacha3777e02013-02-10 13:07:08 +0200109 read_lock_bh(&idev->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100110 list_for_each_entry(ifa, &idev->addr_list, if_list) {
111 mvmvif->target_ipv6_addrs[idx] = ifa->addr;
Sara Sharonc97dab42015-11-19 11:53:49 +0200112 if (ifa->flags & IFA_F_TENTATIVE)
113 __set_bit(idx, mvmvif->tentative_addrs);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100114 idx++;
Johannes Berg5369d6c2013-07-08 11:17:06 +0200115 if (idx >= IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100116 break;
117 }
Emmanuel Grumbacha3777e02013-02-10 13:07:08 +0200118 read_unlock_bh(&idev->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100119
120 mvmvif->num_target_ipv6_addrs = idx;
121}
122#endif
123
124void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw,
125 struct ieee80211_vif *vif, int idx)
126{
127 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
128
129 mvmvif->tx_key_idx = idx;
130}
131
132static void iwl_mvm_convert_p1k(u16 *p1k, __le16 *out)
133{
134 int i;
135
136 for (i = 0; i < IWL_P1K_SIZE; i++)
137 out[i] = cpu_to_le16(p1k[i]);
138}
139
140struct wowlan_key_data {
141 struct iwl_wowlan_rsc_tsc_params_cmd *rsc_tsc;
142 struct iwl_wowlan_tkip_params_cmd *tkip;
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200143 bool error, use_rsc_tsc, use_tkip, configure_keys;
Johannes Berg5312e542013-07-22 18:26:56 +0200144 int wep_key_idx;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100145};
146
147static void iwl_mvm_wowlan_program_keys(struct ieee80211_hw *hw,
148 struct ieee80211_vif *vif,
149 struct ieee80211_sta *sta,
150 struct ieee80211_key_conf *key,
151 void *_data)
152{
153 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
154 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
155 struct wowlan_key_data *data = _data;
156 struct aes_sc *aes_sc, *aes_tx_sc = NULL;
157 struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL;
158 struct iwl_p1k_cache *rx_p1ks;
159 u8 *rx_mic_key;
160 struct ieee80211_key_seq seq;
161 u32 cur_rx_iv32 = 0;
162 u16 p1k[IWL_P1K_SIZE];
163 int ret, i;
164
Johannes Berg8ca151b2013-01-24 14:25:36 +0100165 switch (key->cipher) {
166 case WLAN_CIPHER_SUITE_WEP40:
167 case WLAN_CIPHER_SUITE_WEP104: { /* hack it for now */
168 struct {
169 struct iwl_mvm_wep_key_cmd wep_key_cmd;
170 struct iwl_mvm_wep_key wep_key;
171 } __packed wkc = {
172 .wep_key_cmd.mac_id_n_color =
173 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
174 mvmvif->color)),
175 .wep_key_cmd.num_keys = 1,
176 /* firmware sets STA_KEY_FLG_WEP_13BYTES */
177 .wep_key_cmd.decryption_type = STA_KEY_FLG_WEP,
178 .wep_key.key_index = key->keyidx,
179 .wep_key.key_size = key->keylen,
180 };
181
182 /*
183 * This will fail -- the key functions don't set support
184 * pairwise WEP keys. However, that's better than silently
185 * failing WoWLAN. Or maybe not?
186 */
187 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
188 break;
189
190 memcpy(&wkc.wep_key.key[3], key->key, key->keylen);
191 if (key->keyidx == mvmvif->tx_key_idx) {
192 /* TX key must be at offset 0 */
193 wkc.wep_key.key_offset = 0;
194 } else {
195 /* others start at 1 */
Johannes Berg5312e542013-07-22 18:26:56 +0200196 data->wep_key_idx++;
197 wkc.wep_key.key_offset = data->wep_key_idx;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100198 }
199
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200200 if (data->configure_keys) {
201 mutex_lock(&mvm->mutex);
202 ret = iwl_mvm_send_cmd_pdu(mvm, WEP_KEY, 0,
203 sizeof(wkc), &wkc);
204 data->error = ret != 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100205
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200206 mvm->ptk_ivlen = key->iv_len;
207 mvm->ptk_icvlen = key->icv_len;
208 mvm->gtk_ivlen = key->iv_len;
209 mvm->gtk_icvlen = key->icv_len;
210 mutex_unlock(&mvm->mutex);
211 }
Johannes Bergf444eb12013-02-26 12:04:18 +0100212
Johannes Berg8ca151b2013-01-24 14:25:36 +0100213 /* don't upload key again */
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200214 return;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100215 }
216 default:
217 data->error = true;
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200218 return;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100219 case WLAN_CIPHER_SUITE_AES_CMAC:
220 /*
221 * Ignore CMAC keys -- the WoWLAN firmware doesn't support them
222 * but we also shouldn't abort suspend due to that. It does have
223 * support for the IGTK key renewal, but doesn't really use the
224 * IGTK for anything. This means we could spuriously wake up or
225 * be deauthenticated, but that was considered acceptable.
226 */
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200227 return;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100228 case WLAN_CIPHER_SUITE_TKIP:
229 if (sta) {
230 tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc;
231 tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc;
232
233 rx_p1ks = data->tkip->rx_uni;
234
235 ieee80211_get_key_tx_seq(key, &seq);
236 tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16);
237 tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32);
238
239 ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k);
240 iwl_mvm_convert_p1k(p1k, data->tkip->tx.p1k);
241
242 memcpy(data->tkip->mic_keys.tx,
243 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
244 IWL_MIC_KEY_SIZE);
245
246 rx_mic_key = data->tkip->mic_keys.rx_unicast;
247 } else {
248 tkip_sc =
249 data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc;
250 rx_p1ks = data->tkip->rx_multi;
251 rx_mic_key = data->tkip->mic_keys.rx_mcast;
252 }
253
254 /*
255 * For non-QoS this relies on the fact that both the uCode and
256 * mac80211 use TID 0 (as they need to to avoid replay attacks)
257 * for checking the IV in the frames.
258 */
259 for (i = 0; i < IWL_NUM_RSC; i++) {
260 ieee80211_get_key_rx_seq(key, i, &seq);
261 tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16);
262 tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32);
263 /* wrapping isn't allowed, AP must rekey */
264 if (seq.tkip.iv32 > cur_rx_iv32)
265 cur_rx_iv32 = seq.tkip.iv32;
266 }
267
268 ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid,
269 cur_rx_iv32, p1k);
270 iwl_mvm_convert_p1k(p1k, rx_p1ks[0].p1k);
271 ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid,
272 cur_rx_iv32 + 1, p1k);
273 iwl_mvm_convert_p1k(p1k, rx_p1ks[1].p1k);
274
275 memcpy(rx_mic_key,
276 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
277 IWL_MIC_KEY_SIZE);
278
279 data->use_tkip = true;
280 data->use_rsc_tsc = true;
281 break;
282 case WLAN_CIPHER_SUITE_CCMP:
283 if (sta) {
Johannes Berg6645d5e2015-09-15 09:58:53 +0200284 u64 pn64;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100285
286 aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc;
287 aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc;
288
Johannes Berg6645d5e2015-09-15 09:58:53 +0200289 pn64 = atomic64_read(&key->tx_pn);
290 aes_tx_sc->pn = cpu_to_le64(pn64);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100291 } else {
292 aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc;
293 }
294
295 /*
296 * For non-QoS this relies on the fact that both the uCode and
297 * mac80211 use TID 0 for checking the IV in the frames.
298 */
299 for (i = 0; i < IWL_NUM_RSC; i++) {
300 u8 *pn = seq.ccmp.pn;
301
302 ieee80211_get_key_rx_seq(key, i, &seq);
Johannes Berg2cf5eb32015-09-15 14:36:09 +0200303 aes_sc[i].pn = cpu_to_le64((u64)pn[5] |
304 ((u64)pn[4] << 8) |
305 ((u64)pn[3] << 16) |
306 ((u64)pn[2] << 24) |
307 ((u64)pn[1] << 32) |
308 ((u64)pn[0] << 40));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100309 }
310 data->use_rsc_tsc = true;
311 break;
312 }
313
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200314 if (data->configure_keys) {
315 mutex_lock(&mvm->mutex);
Johannes Berg5312e542013-07-22 18:26:56 +0200316 /*
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200317 * The D3 firmware hardcodes the key offset 0 as the key it
318 * uses to transmit packets to the AP, i.e. the PTK.
Johannes Berg5312e542013-07-22 18:26:56 +0200319 */
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200320 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
321 mvm->ptk_ivlen = key->iv_len;
322 mvm->ptk_icvlen = key->icv_len;
323 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, 0);
324 } else {
325 /*
326 * firmware only supports TSC/RSC for a single key,
327 * so if there are multiple keep overwriting them
328 * with new ones -- this relies on mac80211 doing
329 * list_add_tail().
330 */
331 mvm->gtk_ivlen = key->iv_len;
332 mvm->gtk_icvlen = key->icv_len;
333 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, 1);
334 }
335 mutex_unlock(&mvm->mutex);
336 data->error = ret != 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100337 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100338}
339
340static int iwl_mvm_send_patterns(struct iwl_mvm *mvm,
341 struct cfg80211_wowlan *wowlan)
342{
343 struct iwl_wowlan_patterns_cmd *pattern_cmd;
344 struct iwl_host_cmd cmd = {
345 .id = WOWLAN_PATTERNS,
346 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100347 };
348 int i, err;
349
350 if (!wowlan->n_patterns)
351 return 0;
352
353 cmd.len[0] = sizeof(*pattern_cmd) +
354 wowlan->n_patterns * sizeof(struct iwl_wowlan_pattern);
355
356 pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
357 if (!pattern_cmd)
358 return -ENOMEM;
359
360 pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
361
362 for (i = 0; i < wowlan->n_patterns; i++) {
363 int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
364
365 memcpy(&pattern_cmd->patterns[i].mask,
366 wowlan->patterns[i].mask, mask_len);
367 memcpy(&pattern_cmd->patterns[i].pattern,
368 wowlan->patterns[i].pattern,
369 wowlan->patterns[i].pattern_len);
370 pattern_cmd->patterns[i].mask_size = mask_len;
371 pattern_cmd->patterns[i].pattern_size =
372 wowlan->patterns[i].pattern_len;
373 }
374
375 cmd.data[0] = pattern_cmd;
376 err = iwl_mvm_send_cmd(mvm, &cmd);
377 kfree(pattern_cmd);
378 return err;
379}
380
Johannes Bergf0c26462013-01-22 20:41:58 +0100381enum iwl_mvm_tcp_packet_type {
382 MVM_TCP_TX_SYN,
383 MVM_TCP_RX_SYNACK,
384 MVM_TCP_TX_DATA,
385 MVM_TCP_RX_ACK,
386 MVM_TCP_RX_WAKE,
387 MVM_TCP_TX_FIN,
388};
389
390static __le16 pseudo_hdr_check(int len, __be32 saddr, __be32 daddr)
391{
392 __sum16 check = tcp_v4_check(len, saddr, daddr, 0);
393 return cpu_to_le16(be16_to_cpu((__force __be16)check));
394}
395
Oren Givonb002c7e2013-06-12 20:37:03 +0300396static void iwl_mvm_build_tcp_packet(struct ieee80211_vif *vif,
Johannes Bergf0c26462013-01-22 20:41:58 +0100397 struct cfg80211_wowlan_tcp *tcp,
398 void *_pkt, u8 *mask,
399 __le16 *pseudo_hdr_csum,
400 enum iwl_mvm_tcp_packet_type ptype)
401{
402 struct {
403 struct ethhdr eth;
404 struct iphdr ip;
405 struct tcphdr tcp;
406 u8 data[];
407 } __packed *pkt = _pkt;
408 u16 ip_tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr);
409 int i;
410
411 pkt->eth.h_proto = cpu_to_be16(ETH_P_IP),
412 pkt->ip.version = 4;
413 pkt->ip.ihl = 5;
414 pkt->ip.protocol = IPPROTO_TCP;
415
416 switch (ptype) {
417 case MVM_TCP_TX_SYN:
418 case MVM_TCP_TX_DATA:
419 case MVM_TCP_TX_FIN:
420 memcpy(pkt->eth.h_dest, tcp->dst_mac, ETH_ALEN);
421 memcpy(pkt->eth.h_source, vif->addr, ETH_ALEN);
422 pkt->ip.ttl = 128;
423 pkt->ip.saddr = tcp->src;
424 pkt->ip.daddr = tcp->dst;
425 pkt->tcp.source = cpu_to_be16(tcp->src_port);
426 pkt->tcp.dest = cpu_to_be16(tcp->dst_port);
427 /* overwritten for TX SYN later */
428 pkt->tcp.doff = sizeof(struct tcphdr) / 4;
429 pkt->tcp.window = cpu_to_be16(65000);
430 break;
431 case MVM_TCP_RX_SYNACK:
432 case MVM_TCP_RX_ACK:
433 case MVM_TCP_RX_WAKE:
434 memcpy(pkt->eth.h_dest, vif->addr, ETH_ALEN);
435 memcpy(pkt->eth.h_source, tcp->dst_mac, ETH_ALEN);
436 pkt->ip.saddr = tcp->dst;
437 pkt->ip.daddr = tcp->src;
438 pkt->tcp.source = cpu_to_be16(tcp->dst_port);
439 pkt->tcp.dest = cpu_to_be16(tcp->src_port);
440 break;
441 default:
442 WARN_ON(1);
443 return;
444 }
445
446 switch (ptype) {
447 case MVM_TCP_TX_SYN:
448 /* firmware assumes 8 option bytes - 8 NOPs for now */
449 memset(pkt->data, 0x01, 8);
450 ip_tot_len += 8;
451 pkt->tcp.doff = (sizeof(struct tcphdr) + 8) / 4;
452 pkt->tcp.syn = 1;
453 break;
454 case MVM_TCP_TX_DATA:
455 ip_tot_len += tcp->payload_len;
456 memcpy(pkt->data, tcp->payload, tcp->payload_len);
457 pkt->tcp.psh = 1;
458 pkt->tcp.ack = 1;
459 break;
460 case MVM_TCP_TX_FIN:
461 pkt->tcp.fin = 1;
462 pkt->tcp.ack = 1;
463 break;
464 case MVM_TCP_RX_SYNACK:
465 pkt->tcp.syn = 1;
466 pkt->tcp.ack = 1;
467 break;
468 case MVM_TCP_RX_ACK:
469 pkt->tcp.ack = 1;
470 break;
471 case MVM_TCP_RX_WAKE:
472 ip_tot_len += tcp->wake_len;
473 pkt->tcp.psh = 1;
474 pkt->tcp.ack = 1;
475 memcpy(pkt->data, tcp->wake_data, tcp->wake_len);
476 break;
477 }
478
479 switch (ptype) {
480 case MVM_TCP_TX_SYN:
481 case MVM_TCP_TX_DATA:
482 case MVM_TCP_TX_FIN:
483 pkt->ip.tot_len = cpu_to_be16(ip_tot_len);
484 pkt->ip.check = ip_fast_csum(&pkt->ip, pkt->ip.ihl);
485 break;
486 case MVM_TCP_RX_WAKE:
487 for (i = 0; i < DIV_ROUND_UP(tcp->wake_len, 8); i++) {
488 u8 tmp = tcp->wake_mask[i];
489 mask[i + 6] |= tmp << 6;
490 if (i + 1 < DIV_ROUND_UP(tcp->wake_len, 8))
491 mask[i + 7] = tmp >> 2;
492 }
493 /* fall through for ethernet/IP/TCP headers mask */
494 case MVM_TCP_RX_SYNACK:
495 case MVM_TCP_RX_ACK:
496 mask[0] = 0xff; /* match ethernet */
497 /*
498 * match ethernet, ip.version, ip.ihl
499 * the ip.ihl half byte is really masked out by firmware
500 */
501 mask[1] = 0x7f;
502 mask[2] = 0x80; /* match ip.protocol */
503 mask[3] = 0xfc; /* match ip.saddr, ip.daddr */
504 mask[4] = 0x3f; /* match ip.daddr, tcp.source, tcp.dest */
505 mask[5] = 0x80; /* match tcp flags */
506 /* leave rest (0 or set for MVM_TCP_RX_WAKE) */
507 break;
508 };
509
510 *pseudo_hdr_csum = pseudo_hdr_check(ip_tot_len - sizeof(struct iphdr),
511 pkt->ip.saddr, pkt->ip.daddr);
512}
513
514static int iwl_mvm_send_remote_wake_cfg(struct iwl_mvm *mvm,
515 struct ieee80211_vif *vif,
516 struct cfg80211_wowlan_tcp *tcp)
517{
518 struct iwl_wowlan_remote_wake_config *cfg;
519 struct iwl_host_cmd cmd = {
520 .id = REMOTE_WAKE_CONFIG_CMD,
521 .len = { sizeof(*cfg), },
522 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
Johannes Bergf0c26462013-01-22 20:41:58 +0100523 };
524 int ret;
525
526 if (!tcp)
527 return 0;
528
529 cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
530 if (!cfg)
531 return -ENOMEM;
532 cmd.data[0] = cfg;
533
534 cfg->max_syn_retries = 10;
535 cfg->max_data_retries = 10;
536 cfg->tcp_syn_ack_timeout = 1; /* seconds */
537 cfg->tcp_ack_timeout = 1; /* seconds */
538
539 /* SYN (TX) */
540 iwl_mvm_build_tcp_packet(
Oren Givonb002c7e2013-06-12 20:37:03 +0300541 vif, tcp, cfg->syn_tx.data, NULL,
Johannes Bergf0c26462013-01-22 20:41:58 +0100542 &cfg->syn_tx.info.tcp_pseudo_header_checksum,
543 MVM_TCP_TX_SYN);
544 cfg->syn_tx.info.tcp_payload_length = 0;
545
546 /* SYN/ACK (RX) */
547 iwl_mvm_build_tcp_packet(
Oren Givonb002c7e2013-06-12 20:37:03 +0300548 vif, tcp, cfg->synack_rx.data, cfg->synack_rx.rx_mask,
Johannes Bergf0c26462013-01-22 20:41:58 +0100549 &cfg->synack_rx.info.tcp_pseudo_header_checksum,
550 MVM_TCP_RX_SYNACK);
551 cfg->synack_rx.info.tcp_payload_length = 0;
552
553 /* KEEPALIVE/ACK (TX) */
554 iwl_mvm_build_tcp_packet(
Oren Givonb002c7e2013-06-12 20:37:03 +0300555 vif, tcp, cfg->keepalive_tx.data, NULL,
Johannes Bergf0c26462013-01-22 20:41:58 +0100556 &cfg->keepalive_tx.info.tcp_pseudo_header_checksum,
557 MVM_TCP_TX_DATA);
558 cfg->keepalive_tx.info.tcp_payload_length =
559 cpu_to_le16(tcp->payload_len);
560 cfg->sequence_number_offset = tcp->payload_seq.offset;
561 /* length must be 0..4, the field is little endian */
562 cfg->sequence_number_length = tcp->payload_seq.len;
563 cfg->initial_sequence_number = cpu_to_le32(tcp->payload_seq.start);
564 cfg->keepalive_interval = cpu_to_le16(tcp->data_interval);
565 if (tcp->payload_tok.len) {
566 cfg->token_offset = tcp->payload_tok.offset;
567 cfg->token_length = tcp->payload_tok.len;
568 cfg->num_tokens =
569 cpu_to_le16(tcp->tokens_size % tcp->payload_tok.len);
570 memcpy(cfg->tokens, tcp->payload_tok.token_stream,
571 tcp->tokens_size);
572 } else {
573 /* set tokens to max value to almost never run out */
574 cfg->num_tokens = cpu_to_le16(65535);
575 }
576
577 /* ACK (RX) */
578 iwl_mvm_build_tcp_packet(
Oren Givonb002c7e2013-06-12 20:37:03 +0300579 vif, tcp, cfg->keepalive_ack_rx.data,
Johannes Bergf0c26462013-01-22 20:41:58 +0100580 cfg->keepalive_ack_rx.rx_mask,
581 &cfg->keepalive_ack_rx.info.tcp_pseudo_header_checksum,
582 MVM_TCP_RX_ACK);
583 cfg->keepalive_ack_rx.info.tcp_payload_length = 0;
584
585 /* WAKEUP (RX) */
586 iwl_mvm_build_tcp_packet(
Oren Givonb002c7e2013-06-12 20:37:03 +0300587 vif, tcp, cfg->wake_rx.data, cfg->wake_rx.rx_mask,
Johannes Bergf0c26462013-01-22 20:41:58 +0100588 &cfg->wake_rx.info.tcp_pseudo_header_checksum,
589 MVM_TCP_RX_WAKE);
590 cfg->wake_rx.info.tcp_payload_length =
591 cpu_to_le16(tcp->wake_len);
592
593 /* FIN */
594 iwl_mvm_build_tcp_packet(
Oren Givonb002c7e2013-06-12 20:37:03 +0300595 vif, tcp, cfg->fin_tx.data, NULL,
Johannes Bergf0c26462013-01-22 20:41:58 +0100596 &cfg->fin_tx.info.tcp_pseudo_header_checksum,
597 MVM_TCP_TX_FIN);
598 cfg->fin_tx.info.tcp_payload_length = 0;
599
600 ret = iwl_mvm_send_cmd(mvm, &cmd);
601 kfree(cfg);
602
603 return ret;
604}
605
Johannes Berg8ca151b2013-01-24 14:25:36 +0100606static int iwl_mvm_d3_reprogram(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
607 struct ieee80211_sta *ap_sta)
608{
609 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
610 struct ieee80211_chanctx_conf *ctx;
611 u8 chains_static, chains_dynamic;
612 struct cfg80211_chan_def chandef;
613 int ret, i;
614 struct iwl_binding_cmd binding_cmd = {};
615 struct iwl_time_quota_cmd quota_cmd = {};
616 u32 status;
617
618 /* add back the PHY */
619 if (WARN_ON(!mvmvif->phy_ctxt))
620 return -EINVAL;
621
622 rcu_read_lock();
623 ctx = rcu_dereference(vif->chanctx_conf);
624 if (WARN_ON(!ctx)) {
625 rcu_read_unlock();
626 return -EINVAL;
627 }
628 chandef = ctx->def;
629 chains_static = ctx->rx_chains_static;
630 chains_dynamic = ctx->rx_chains_dynamic;
631 rcu_read_unlock();
632
633 ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt, &chandef,
634 chains_static, chains_dynamic);
635 if (ret)
636 return ret;
637
638 /* add back the MAC */
639 mvmvif->uploaded = false;
640
641 if (WARN_ON(!vif->bss_conf.assoc))
642 return -EINVAL;
Luciano Coelhobca49d92014-05-13 17:33:38 +0300643
Johannes Berg8ca151b2013-01-24 14:25:36 +0100644 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100645 if (ret)
646 return ret;
647
648 /* add back binding - XXX refactor? */
649 binding_cmd.id_and_color =
650 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
651 mvmvif->phy_ctxt->color));
652 binding_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
653 binding_cmd.phy =
654 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
655 mvmvif->phy_ctxt->color));
656 binding_cmd.macs[0] = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
657 mvmvif->color));
658 for (i = 1; i < MAX_MACS_IN_BINDING; i++)
659 binding_cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID);
660
661 status = 0;
662 ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD,
663 sizeof(binding_cmd), &binding_cmd,
664 &status);
665 if (ret) {
666 IWL_ERR(mvm, "Failed to add binding: %d\n", ret);
667 return ret;
668 }
669
670 if (status) {
671 IWL_ERR(mvm, "Binding command failed: %u\n", status);
672 return -EIO;
673 }
674
Johannes Berg7a453972013-02-12 13:10:44 +0100675 ret = iwl_mvm_sta_send_to_fw(mvm, ap_sta, false);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100676 if (ret)
677 return ret;
678 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], ap_sta);
679
Johannes Berg3dfd3a92014-08-11 21:37:30 +0200680 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100681 if (ret)
682 return ret;
683
684 /* and some quota */
685 quota_cmd.quotas[0].id_and_color =
686 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
687 mvmvif->phy_ctxt->color));
Emmanuel Grumbach9a3daf82014-03-05 10:00:44 +0200688 quota_cmd.quotas[0].quota = cpu_to_le32(IWL_MVM_MAX_QUOTA);
689 quota_cmd.quotas[0].max_duration = cpu_to_le32(IWL_MVM_MAX_QUOTA);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100690
691 for (i = 1; i < MAX_BINDINGS; i++)
692 quota_cmd.quotas[i].id_and_color = cpu_to_le32(FW_CTXT_INVALID);
693
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300694 ret = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100695 sizeof(quota_cmd), &quota_cmd);
696 if (ret)
697 IWL_ERR(mvm, "Failed to send quota: %d\n", ret);
698
Jonathan Doron47c8b152014-11-27 16:55:25 +0200699 if (iwl_mvm_is_lar_supported(mvm) && iwl_mvm_init_fw_regd(mvm))
700 IWL_ERR(mvm, "Failed to initialize D3 LAR information\n");
701
Johannes Berg8ca151b2013-01-24 14:25:36 +0100702 return 0;
703}
704
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200705static int iwl_mvm_get_last_nonqos_seq(struct iwl_mvm *mvm,
706 struct ieee80211_vif *vif)
707{
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200708 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
709 struct iwl_nonqos_seq_query_cmd query_cmd = {
710 .get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_GET),
711 .mac_id_n_color =
712 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
713 mvmvif->color)),
714 };
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200715 struct iwl_host_cmd cmd = {
716 .id = NON_QOS_TX_COUNTER_CMD,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300717 .flags = CMD_WANT_SKB,
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200718 };
719 int err;
720 u32 size;
721
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +0300722 cmd.data[0] = &query_cmd;
723 cmd.len[0] = sizeof(query_cmd);
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200724
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200725 err = iwl_mvm_send_cmd(mvm, &cmd);
726 if (err)
727 return err;
728
Johannes Berg65b30342014-01-08 13:16:33 +0100729 size = iwl_rx_packet_payload_len(cmd.resp_pkt);
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200730 if (size < sizeof(__le16)) {
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200731 err = -EINVAL;
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200732 } else {
733 err = le16_to_cpup((__le16 *)cmd.resp_pkt->data);
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +0300734 /* firmware returns next, not last-used seqno */
735 err = (u16) (err - 0x10);
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200736 }
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200737
738 iwl_free_resp(&cmd);
739 return err;
740}
741
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200742void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
743{
744 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
745 struct iwl_nonqos_seq_query_cmd query_cmd = {
746 .get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_SET),
747 .mac_id_n_color =
748 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
749 mvmvif->color)),
750 .value = cpu_to_le16(mvmvif->seqno),
751 };
752
753 /* return if called during restart, not resume from D3 */
754 if (!mvmvif->seqno_valid)
755 return;
756
757 mvmvif->seqno_valid = false;
758
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300759 if (iwl_mvm_send_cmd_pdu(mvm, NON_QOS_TX_COUNTER_CMD, 0,
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200760 sizeof(query_cmd), &query_cmd))
761 IWL_ERR(mvm, "failed to set non-QoS seqno\n");
762}
763
Luciano Coelho671b5822014-09-22 10:59:53 +0300764static int iwl_mvm_switch_to_d3(struct iwl_mvm *mvm)
Eliad Peller1a95c8d2013-11-21 19:19:52 +0200765{
Luciano Coelhoc7d42482015-05-07 16:00:26 +0300766 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100767
768 iwl_trans_stop_device(mvm->trans);
769
770 /*
771 * Set the HW restart bit -- this is mostly true as we're
772 * going to load new firmware and reprogram that, though
773 * the reprogramming is going to be manual to avoid adding
774 * all the MACs that aren't support.
775 * We don't have to clear up everything though because the
776 * reprogramming is manual. When we resume, we'll actually
777 * go through a proper restart sequence again to switch
778 * back to the runtime firmware image.
779 */
780 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
781
Luca Coelho9c3deeb2015-11-11 01:06:17 +0200782 /* the fw is reset, so all the keys are cleared */
783 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
784
Johannes Bergf444eb12013-02-26 12:04:18 +0100785 mvm->ptk_ivlen = 0;
786 mvm->ptk_icvlen = 0;
787 mvm->ptk_ivlen = 0;
788 mvm->ptk_icvlen = 0;
789
Luciano Coelho671b5822014-09-22 10:59:53 +0300790 return iwl_mvm_load_d3_fw(mvm);
791}
792
793static int
Luciano Coelho671b5822014-09-22 10:59:53 +0300794iwl_mvm_get_wowlan_config(struct iwl_mvm *mvm,
795 struct cfg80211_wowlan *wowlan,
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200796 struct iwl_wowlan_config_cmd *wowlan_config_cmd,
Luciano Coelho671b5822014-09-22 10:59:53 +0300797 struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif,
798 struct ieee80211_sta *ap_sta)
799{
800 int ret;
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100801 struct iwl_mvm_sta *mvm_ap_sta = iwl_mvm_sta_from_mac80211(ap_sta);
Luciano Coelho671b5822014-09-22 10:59:53 +0300802
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200803 /* TODO: wowlan_config_cmd->wowlan_ba_teardown_tids */
Luciano Coelho671b5822014-09-22 10:59:53 +0300804
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200805 wowlan_config_cmd->is_11n_connection =
Luciano Coelho671b5822014-09-22 10:59:53 +0300806 ap_sta->ht_cap.ht_supported;
Sara Sharon70b4c532015-11-19 13:12:15 +0200807 wowlan_config_cmd->flags = ENABLE_L3_FILTERING |
808 ENABLE_NBNS_FILTERING | ENABLE_DHCP_FILTERING;
Luciano Coelho671b5822014-09-22 10:59:53 +0300809
810 /* Query the last used seqno and set it */
811 ret = iwl_mvm_get_last_nonqos_seq(mvm, vif);
812 if (ret < 0)
813 return ret;
814
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200815 wowlan_config_cmd->non_qos_seq = cpu_to_le16(ret);
Luciano Coelho671b5822014-09-22 10:59:53 +0300816
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200817 iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, wowlan_config_cmd);
Luciano Coelho671b5822014-09-22 10:59:53 +0300818
819 if (wowlan->disconnect)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200820 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300821 cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS |
822 IWL_WOWLAN_WAKEUP_LINK_CHANGE);
823 if (wowlan->magic_pkt)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200824 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300825 cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET);
826 if (wowlan->gtk_rekey_failure)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200827 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300828 cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL);
829 if (wowlan->eap_identity_req)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200830 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300831 cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ);
832 if (wowlan->four_way_handshake)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200833 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300834 cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE);
835 if (wowlan->n_patterns)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200836 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300837 cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH);
838
839 if (wowlan->rfkill_release)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200840 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300841 cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT);
842
843 if (wowlan->tcp) {
844 /*
845 * Set the "link change" (really "link lost") flag as well
846 * since that implies losing the TCP connection.
847 */
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200848 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300849 cpu_to_le32(IWL_WOWLAN_WAKEUP_REMOTE_LINK_LOSS |
850 IWL_WOWLAN_WAKEUP_REMOTE_SIGNATURE_TABLE |
851 IWL_WOWLAN_WAKEUP_REMOTE_WAKEUP_PACKET |
852 IWL_WOWLAN_WAKEUP_LINK_CHANGE);
853 }
854
855 return 0;
856}
857
Eliad Pellera3f7ba52015-11-11 17:23:59 +0200858static void
859iwl_mvm_iter_d0i3_ap_keys(struct iwl_mvm *mvm,
860 struct ieee80211_vif *vif,
861 void (*iter)(struct ieee80211_hw *hw,
862 struct ieee80211_vif *vif,
863 struct ieee80211_sta *sta,
864 struct ieee80211_key_conf *key,
865 void *data),
866 void *data)
867{
868 struct ieee80211_sta *ap_sta;
869
870 rcu_read_lock();
871
872 ap_sta = rcu_dereference(mvm->fw_id_to_mac_id[mvm->d0i3_ap_sta_id]);
873 if (IS_ERR_OR_NULL(ap_sta))
874 goto out;
875
876 ieee80211_iter_keys_rcu(mvm->hw, vif, iter, data);
877out:
878 rcu_read_unlock();
879}
880
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200881int iwl_mvm_wowlan_config_key_params(struct iwl_mvm *mvm,
882 struct ieee80211_vif *vif,
Eliad Pellera3f7ba52015-11-11 17:23:59 +0200883 bool d0i3,
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200884 u32 cmd_flags)
885{
886 struct iwl_wowlan_kek_kck_material_cmd kek_kck_cmd = {};
887 struct iwl_wowlan_tkip_params_cmd tkip_cmd = {};
888 struct wowlan_key_data key_data = {
Eliad Pellera3f7ba52015-11-11 17:23:59 +0200889 .configure_keys = !d0i3,
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200890 .use_rsc_tsc = false,
891 .tkip = &tkip_cmd,
892 .use_tkip = false,
893 };
894 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
895 int ret;
896
897 key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
898 if (!key_data.rsc_tsc)
899 return -ENOMEM;
900
901 /*
Eliad Pellera3f7ba52015-11-11 17:23:59 +0200902 * if we have to configure keys, call ieee80211_iter_keys(),
903 * as we need non-atomic context in order to take the
904 * required locks.
905 * for the d0i3 we can't use ieee80211_iter_keys(), as
906 * taking (almost) any mutex might result in deadlock.
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200907 */
Eliad Pellera3f7ba52015-11-11 17:23:59 +0200908 if (!d0i3) {
909 /*
910 * Note that currently we don't propagate cmd_flags
911 * to the iterator. In case of key_data.configure_keys,
912 * all the configured commands are SYNC, and
913 * iwl_mvm_wowlan_program_keys() will take care of
914 * locking/unlocking mvm->mutex.
915 */
916 ieee80211_iter_keys(mvm->hw, vif,
917 iwl_mvm_wowlan_program_keys,
918 &key_data);
919 } else {
920 iwl_mvm_iter_d0i3_ap_keys(mvm, vif,
921 iwl_mvm_wowlan_program_keys,
922 &key_data);
923 }
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200924
925 if (key_data.error) {
926 ret = -EIO;
927 goto out;
928 }
929
930 if (key_data.use_rsc_tsc) {
931 ret = iwl_mvm_send_cmd_pdu(mvm,
932 WOWLAN_TSC_RSC_PARAM, cmd_flags,
933 sizeof(*key_data.rsc_tsc),
934 key_data.rsc_tsc);
935 if (ret)
936 goto out;
937 }
938
939 if (key_data.use_tkip) {
940 ret = iwl_mvm_send_cmd_pdu(mvm,
941 WOWLAN_TKIP_PARAM,
942 cmd_flags, sizeof(tkip_cmd),
943 &tkip_cmd);
944 if (ret)
945 goto out;
946 }
947
Eliad Pellera3f7ba52015-11-11 17:23:59 +0200948 /* configure rekey data only if offloaded rekey is supported (d3) */
949 if (mvmvif->rekey_data.valid && !d0i3) {
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200950 memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd));
951 memcpy(kek_kck_cmd.kck, mvmvif->rekey_data.kck,
952 NL80211_KCK_LEN);
953 kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN);
954 memcpy(kek_kck_cmd.kek, mvmvif->rekey_data.kek,
955 NL80211_KEK_LEN);
956 kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN);
957 kek_kck_cmd.replay_ctr = mvmvif->rekey_data.replay_ctr;
958
959 ret = iwl_mvm_send_cmd_pdu(mvm,
960 WOWLAN_KEK_KCK_MATERIAL, cmd_flags,
961 sizeof(kek_kck_cmd),
962 &kek_kck_cmd);
963 if (ret)
964 goto out;
965 }
Eliad Peller3f50a692015-11-15 15:44:17 +0200966 ret = 0;
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200967out:
968 kfree(key_data.rsc_tsc);
969 return ret;
970}
971
Luciano Coelho671b5822014-09-22 10:59:53 +0300972static int
973iwl_mvm_wowlan_config(struct iwl_mvm *mvm,
974 struct cfg80211_wowlan *wowlan,
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200975 struct iwl_wowlan_config_cmd *wowlan_config_cmd,
Luciano Coelho671b5822014-09-22 10:59:53 +0300976 struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif,
977 struct ieee80211_sta *ap_sta)
978{
Luciano Coelho671b5822014-09-22 10:59:53 +0300979 int ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100980
Luciano Coelho3acc9522014-11-19 22:35:37 +0200981 ret = iwl_mvm_switch_to_d3(mvm);
982 if (ret)
983 return ret;
984
Johannes Berg8ca151b2013-01-24 14:25:36 +0100985 ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta);
986 if (ret)
Luciano Coelho671b5822014-09-22 10:59:53 +0300987 return ret;
988
Johannes Berg8ca151b2013-01-24 14:25:36 +0100989 if (!iwlwifi_mod_params.sw_crypto) {
990 /*
991 * This needs to be unlocked due to lock ordering
992 * constraints. Since we're in the suspend path
993 * that isn't really a problem though.
994 */
995 mutex_unlock(&mvm->mutex);
Eliad Pellera3f7ba52015-11-11 17:23:59 +0200996 ret = iwl_mvm_wowlan_config_key_params(mvm, vif, false,
Eliad Peller3f50a692015-11-15 15:44:17 +0200997 CMD_ASYNC);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100998 mutex_lock(&mvm->mutex);
Eliad Peller3f50a692015-11-15 15:44:17 +0200999 if (ret)
1000 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001001 }
1002
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +02001003 ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0,
1004 sizeof(*wowlan_config_cmd),
1005 wowlan_config_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001006 if (ret)
Eliad Pellerac8ef0c2015-11-12 10:49:38 +02001007 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001008
1009 ret = iwl_mvm_send_patterns(mvm, wowlan);
1010 if (ret)
Eliad Pellerac8ef0c2015-11-12 10:49:38 +02001011 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001012
Sara Sharonc97dab42015-11-19 11:53:49 +02001013 ret = iwl_mvm_send_proto_offload(mvm, vif, false, true, 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001014 if (ret)
Eliad Pellerac8ef0c2015-11-12 10:49:38 +02001015 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001016
Johannes Bergf0c26462013-01-22 20:41:58 +01001017 ret = iwl_mvm_send_remote_wake_cfg(mvm, vif, wowlan->tcp);
Luciano Coelho671b5822014-09-22 10:59:53 +03001018 return ret;
1019}
1020
Luciano Coelho3acc9522014-11-19 22:35:37 +02001021static int
1022iwl_mvm_netdetect_config(struct iwl_mvm *mvm,
1023 struct cfg80211_wowlan *wowlan,
1024 struct cfg80211_sched_scan_request *nd_config,
1025 struct ieee80211_vif *vif)
1026{
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +02001027 struct iwl_wowlan_config_cmd wowlan_config_cmd = {};
Luciano Coelho3acc9522014-11-19 22:35:37 +02001028 int ret;
1029
1030 ret = iwl_mvm_switch_to_d3(mvm);
1031 if (ret)
1032 return ret;
1033
1034 /* rfkill release can be either for wowlan or netdetect */
1035 if (wowlan->rfkill_release)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +02001036 wowlan_config_cmd.wakeup_filter |=
Luciano Coelho3acc9522014-11-19 22:35:37 +02001037 cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT);
1038
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +02001039 ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0,
1040 sizeof(wowlan_config_cmd),
1041 &wowlan_config_cmd);
Luciano Coelho3acc9522014-11-19 22:35:37 +02001042 if (ret)
1043 return ret;
1044
Luciano Coelho19945df2015-03-20 16:11:28 +02001045 ret = iwl_mvm_sched_scan_start(mvm, vif, nd_config, &mvm->nd_ies,
1046 IWL_MVM_SCAN_NETDETECT);
Luciano Coelhod9718da2014-11-21 09:32:23 +02001047 if (ret)
1048 return ret;
Luciano Coelho3acc9522014-11-19 22:35:37 +02001049
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001050 if (WARN_ON(mvm->nd_match_sets || mvm->nd_channels))
Luciano Coelhod9718da2014-11-21 09:32:23 +02001051 return -EBUSY;
1052
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001053 /* save the sched scan matchsets... */
Luciano Coelhod9718da2014-11-21 09:32:23 +02001054 if (nd_config->n_match_sets) {
1055 mvm->nd_match_sets = kmemdup(nd_config->match_sets,
1056 sizeof(*nd_config->match_sets) *
1057 nd_config->n_match_sets,
1058 GFP_KERNEL);
1059 if (mvm->nd_match_sets)
1060 mvm->n_nd_match_sets = nd_config->n_match_sets;
1061 }
1062
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001063 /* ...and the sched scan channels for later reporting */
1064 mvm->nd_channels = kmemdup(nd_config->channels,
1065 sizeof(*nd_config->channels) *
1066 nd_config->n_channels,
1067 GFP_KERNEL);
1068 if (mvm->nd_channels)
1069 mvm->n_nd_channels = nd_config->n_channels;
1070
Luciano Coelhod9718da2014-11-21 09:32:23 +02001071 return 0;
1072}
1073
1074static void iwl_mvm_free_nd(struct iwl_mvm *mvm)
1075{
1076 kfree(mvm->nd_match_sets);
1077 mvm->nd_match_sets = NULL;
1078 mvm->n_nd_match_sets = 0;
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001079 kfree(mvm->nd_channels);
1080 mvm->nd_channels = NULL;
1081 mvm->n_nd_channels = 0;
Luciano Coelho3acc9522014-11-19 22:35:37 +02001082}
1083
Luciano Coelho671b5822014-09-22 10:59:53 +03001084static int __iwl_mvm_suspend(struct ieee80211_hw *hw,
1085 struct cfg80211_wowlan *wowlan,
1086 bool test)
1087{
1088 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelho671b5822014-09-22 10:59:53 +03001089 struct ieee80211_vif *vif = NULL;
1090 struct iwl_mvm_vif *mvmvif = NULL;
1091 struct ieee80211_sta *ap_sta = NULL;
Luciano Coelho671b5822014-09-22 10:59:53 +03001092 struct iwl_d3_manager_config d3_cfg_cmd_data = {
1093 /*
1094 * Program the minimum sleep time to 10 seconds, as many
1095 * platforms have issues processing a wakeup signal while
1096 * still being in the process of suspending.
1097 */
1098 .min_sleep_time = cpu_to_le32(10 * 1000 * 1000),
1099 };
1100 struct iwl_host_cmd d3_cfg_cmd = {
1101 .id = D3_CONFIG_CMD,
1102 .flags = CMD_WANT_SKB,
1103 .data[0] = &d3_cfg_cmd_data,
1104 .len[0] = sizeof(d3_cfg_cmd_data),
1105 };
1106 int ret;
1107 int len __maybe_unused;
1108
1109 if (!wowlan) {
1110 /*
1111 * mac80211 shouldn't get here, but for D3 test
1112 * it doesn't warrant a warning
1113 */
1114 WARN_ON(!test);
1115 return -EINVAL;
1116 }
1117
1118 mutex_lock(&mvm->mutex);
1119
Luciano Coelho7f549e22014-10-02 15:38:04 +03001120 vif = iwl_mvm_get_bss_vif(mvm);
1121 if (IS_ERR_OR_NULL(vif)) {
Luciano Coelho671b5822014-09-22 10:59:53 +03001122 ret = 1;
1123 goto out_noreset;
1124 }
1125
Luciano Coelho671b5822014-09-22 10:59:53 +03001126 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1127
Luciano Coelho3acc9522014-11-19 22:35:37 +02001128 if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT) {
1129 /* if we're not associated, this must be netdetect */
Luca Coelho566f1652015-10-25 22:55:32 +02001130 if (!wowlan->nd_config) {
Luciano Coelho3acc9522014-11-19 22:35:37 +02001131 ret = 1;
1132 goto out_noreset;
1133 }
1134
1135 ret = iwl_mvm_netdetect_config(
Luca Coelho566f1652015-10-25 22:55:32 +02001136 mvm, wowlan, wowlan->nd_config, vif);
Luciano Coelho3acc9522014-11-19 22:35:37 +02001137 if (ret)
1138 goto out;
Luciano Coelho2021a892014-11-20 08:59:51 +02001139
1140 mvm->net_detect = true;
Luciano Coelho3acc9522014-11-19 22:35:37 +02001141 } else {
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +02001142 struct iwl_wowlan_config_cmd wowlan_config_cmd = {};
Luciano Coelho3acc9522014-11-19 22:35:37 +02001143
Luciano Coelho1e4d19c2014-09-22 13:01:59 +03001144 ap_sta = rcu_dereference_protected(
1145 mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
1146 lockdep_is_held(&mvm->mutex));
1147 if (IS_ERR_OR_NULL(ap_sta)) {
1148 ret = -EINVAL;
1149 goto out_noreset;
1150 }
1151
1152 ret = iwl_mvm_get_wowlan_config(mvm, wowlan, &wowlan_config_cmd,
1153 vif, mvmvif, ap_sta);
1154 if (ret)
1155 goto out_noreset;
Luciano Coelho1e4d19c2014-09-22 13:01:59 +03001156 ret = iwl_mvm_wowlan_config(mvm, wowlan, &wowlan_config_cmd,
1157 vif, mvmvif, ap_sta);
1158 if (ret)
1159 goto out;
Luciano Coelho2021a892014-11-20 08:59:51 +02001160
1161 mvm->net_detect = false;
Luciano Coelho671b5822014-09-22 10:59:53 +03001162 }
1163
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +02001164 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +03001165 if (ret)
1166 goto out;
1167
Arik Nemtsov999609f2014-05-15 17:31:51 +03001168 ret = iwl_mvm_power_update_mac(mvm);
Alexander Bondaree1e8422013-04-23 13:52:10 +03001169 if (ret)
1170 goto out;
1171
Johannes Bergb0114712013-06-12 14:55:40 +02001172#ifdef CONFIG_IWLWIFI_DEBUGFS
1173 if (mvm->d3_wake_sysassert)
1174 d3_cfg_cmd_data.wakeup_flags |=
1175 cpu_to_le32(IWL_WAKEUP_D3_CONFIG_FW_ERROR);
1176#endif
1177
Johannes Berg8ca151b2013-01-24 14:25:36 +01001178 /* must be last -- this switches firmware state */
Johannes Bergdebff612013-05-14 13:53:45 +02001179 ret = iwl_mvm_send_cmd(mvm, &d3_cfg_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001180 if (ret)
1181 goto out;
Johannes Bergdebff612013-05-14 13:53:45 +02001182#ifdef CONFIG_IWLWIFI_DEBUGFS
Johannes Berg65b30342014-01-08 13:16:33 +01001183 len = iwl_rx_packet_payload_len(d3_cfg_cmd.resp_pkt);
1184 if (len >= sizeof(u32)) {
Johannes Bergdebff612013-05-14 13:53:45 +02001185 mvm->d3_test_pme_ptr =
1186 le32_to_cpup((__le32 *)d3_cfg_cmd.resp_pkt->data);
Johannes Bergdebff612013-05-14 13:53:45 +02001187 }
1188#endif
1189 iwl_free_resp(&d3_cfg_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001190
1191 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1192
Johannes Bergdebff612013-05-14 13:53:45 +02001193 iwl_trans_d3_suspend(mvm->trans, test);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001194 out:
Luciano Coelhod9718da2014-11-21 09:32:23 +02001195 if (ret < 0) {
Eliad Peller48e67752015-03-03 12:03:20 +02001196 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001197 ieee80211_restart_hw(mvm->hw);
Luciano Coelhod9718da2014-11-21 09:32:23 +02001198 iwl_mvm_free_nd(mvm);
1199 }
Luciano Coelhob70ab722013-11-19 22:53:41 +02001200 out_noreset:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001201 mutex_unlock(&mvm->mutex);
1202
1203 return ret;
1204}
1205
Eliad Peller67359432014-12-09 15:23:54 +02001206static int iwl_mvm_enter_d0i3_sync(struct iwl_mvm *mvm)
1207{
1208 struct iwl_notification_wait wait_d3;
Sara Sharon6eb031d2015-07-13 14:50:47 +03001209 static const u16 d3_notif[] = { D3_CONFIG_CMD };
Eliad Peller67359432014-12-09 15:23:54 +02001210 int ret;
1211
1212 iwl_init_notification_wait(&mvm->notif_wait, &wait_d3,
1213 d3_notif, ARRAY_SIZE(d3_notif),
1214 NULL, NULL);
1215
1216 ret = iwl_mvm_enter_d0i3(mvm->hw->priv);
1217 if (ret)
1218 goto remove_notif;
1219
1220 ret = iwl_wait_notification(&mvm->notif_wait, &wait_d3, HZ);
1221 WARN_ON_ONCE(ret);
1222 return ret;
1223
1224remove_notif:
1225 iwl_remove_notification(&mvm->notif_wait, &wait_d3);
1226 return ret;
1227}
1228
Johannes Bergdebff612013-05-14 13:53:45 +02001229int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
1230{
Eliad Pellerd15a7472014-03-27 18:53:12 +02001231 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luca Coelhob7282642015-09-17 23:44:14 +03001232 struct iwl_trans *trans = mvm->trans;
Eliad Pellerc43fe902015-06-04 21:59:32 +03001233 int ret;
Eliad Pellerd15a7472014-03-27 18:53:12 +02001234
Luciano Coelhocf8c3cf2015-08-24 14:53:25 +03001235 /* make sure the d0i3 exit work is not pending */
1236 flush_work(&mvm->d0i3_exit_work);
1237
Luca Coelhob7282642015-09-17 23:44:14 +03001238 ret = iwl_trans_suspend(trans);
Eliad Pellerc43fe902015-06-04 21:59:32 +03001239 if (ret)
1240 return ret;
1241
Luca Coelhob7282642015-09-17 23:44:14 +03001242 if (wowlan->any) {
1243 trans->system_pm_mode = IWL_PLAT_PM_MODE_D0I3;
1244
1245 if (iwl_mvm_enter_d0i3_on_suspend(mvm)) {
Eliad Pellerc43fe902015-06-04 21:59:32 +03001246 ret = iwl_mvm_enter_d0i3_sync(mvm);
Eliad Peller67359432014-12-09 15:23:54 +02001247
1248 if (ret)
1249 return ret;
1250 }
1251
Eliad Pellerd15a7472014-03-27 18:53:12 +02001252 mutex_lock(&mvm->d0i3_suspend_mutex);
1253 __set_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
1254 mutex_unlock(&mvm->d0i3_suspend_mutex);
Eliad Peller6dfb36c2015-07-09 14:17:24 +03001255
Luca Coelhob7282642015-09-17 23:44:14 +03001256 iwl_trans_d3_suspend(trans, false);
Eliad Peller6dfb36c2015-07-09 14:17:24 +03001257
Eliad Pellerd15a7472014-03-27 18:53:12 +02001258 return 0;
1259 }
1260
Luca Coelhob7282642015-09-17 23:44:14 +03001261 trans->system_pm_mode = IWL_PLAT_PM_MODE_D3;
1262
Johannes Bergdebff612013-05-14 13:53:45 +02001263 return __iwl_mvm_suspend(hw, wowlan, false);
1264}
1265
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001266/* converted data from the different status responses */
1267struct iwl_wowlan_status_data {
1268 u16 pattern_number;
1269 u16 qos_seq_ctr[8];
1270 u32 wakeup_reasons;
1271 u32 wake_packet_length;
1272 u32 wake_packet_bufsize;
1273 const u8 *wake_packet;
1274};
1275
Johannes Berg7abc4632013-08-06 18:28:26 +02001276static void iwl_mvm_report_wakeup_reasons(struct iwl_mvm *mvm,
1277 struct ieee80211_vif *vif,
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001278 struct iwl_wowlan_status_data *status)
Johannes Berg9b26b502013-01-22 13:02:09 +01001279{
Johannes Berg7abc4632013-08-06 18:28:26 +02001280 struct sk_buff *pkt = NULL;
Johannes Berg9b26b502013-01-22 13:02:09 +01001281 struct cfg80211_wowlan_wakeup wakeup = {
1282 .pattern_idx = -1,
1283 };
1284 struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001285 u32 reasons = status->wakeup_reasons;
Johannes Berg9b26b502013-01-22 13:02:09 +01001286
1287 if (reasons == IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) {
1288 wakeup_report = NULL;
1289 goto report;
1290 }
1291
Derek Basehore06ae2ad2015-11-04 17:37:52 -08001292 pm_wakeup_event(mvm->dev, 0);
1293
Johannes Bergf444eb12013-02-26 12:04:18 +01001294 if (reasons & IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET)
Johannes Berg9b26b502013-01-22 13:02:09 +01001295 wakeup.magic_pkt = true;
Johannes Berg9b26b502013-01-22 13:02:09 +01001296
Johannes Bergf444eb12013-02-26 12:04:18 +01001297 if (reasons & IWL_WOWLAN_WAKEUP_BY_PATTERN)
Johannes Berg9b26b502013-01-22 13:02:09 +01001298 wakeup.pattern_idx =
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001299 status->pattern_number;
Johannes Berg9b26b502013-01-22 13:02:09 +01001300
1301 if (reasons & (IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON |
1302 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH))
1303 wakeup.disconnect = true;
1304
Johannes Bergf444eb12013-02-26 12:04:18 +01001305 if (reasons & IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE)
Johannes Berg9b26b502013-01-22 13:02:09 +01001306 wakeup.gtk_rekey_failure = true;
Johannes Berg9b26b502013-01-22 13:02:09 +01001307
Johannes Bergf444eb12013-02-26 12:04:18 +01001308 if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED)
Johannes Berg9b26b502013-01-22 13:02:09 +01001309 wakeup.rfkill_release = true;
Johannes Berg9b26b502013-01-22 13:02:09 +01001310
Johannes Bergf444eb12013-02-26 12:04:18 +01001311 if (reasons & IWL_WOWLAN_WAKEUP_BY_EAPOL_REQUEST)
Johannes Berg9b26b502013-01-22 13:02:09 +01001312 wakeup.eap_identity_req = true;
Johannes Berg9b26b502013-01-22 13:02:09 +01001313
Johannes Bergf444eb12013-02-26 12:04:18 +01001314 if (reasons & IWL_WOWLAN_WAKEUP_BY_FOUR_WAY_HANDSHAKE)
Johannes Berg9b26b502013-01-22 13:02:09 +01001315 wakeup.four_way_handshake = true;
Johannes Berg9b26b502013-01-22 13:02:09 +01001316
Johannes Bergf0c26462013-01-22 20:41:58 +01001317 if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_LINK_LOSS)
1318 wakeup.tcp_connlost = true;
1319
1320 if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_SIGNATURE_TABLE)
1321 wakeup.tcp_nomoretokens = true;
1322
1323 if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_WAKEUP_PACKET)
1324 wakeup.tcp_match = true;
1325
Johannes Berg9b26b502013-01-22 13:02:09 +01001326 if (status->wake_packet_bufsize) {
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001327 int pktsize = status->wake_packet_bufsize;
1328 int pktlen = status->wake_packet_length;
Johannes Bergf444eb12013-02-26 12:04:18 +01001329 const u8 *pktdata = status->wake_packet;
1330 struct ieee80211_hdr *hdr = (void *)pktdata;
1331 int truncated = pktlen - pktsize;
Johannes Berg9b26b502013-01-22 13:02:09 +01001332
Johannes Bergf444eb12013-02-26 12:04:18 +01001333 /* this would be a firmware bug */
1334 if (WARN_ON_ONCE(truncated < 0))
1335 truncated = 0;
1336
1337 if (ieee80211_is_data(hdr->frame_control)) {
1338 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
1339 int ivlen = 0, icvlen = 4; /* also FCS */
1340
Johannes Berg9b26b502013-01-22 13:02:09 +01001341 pkt = alloc_skb(pktsize, GFP_KERNEL);
1342 if (!pkt)
1343 goto report;
Johannes Bergf444eb12013-02-26 12:04:18 +01001344
1345 memcpy(skb_put(pkt, hdrlen), pktdata, hdrlen);
1346 pktdata += hdrlen;
1347 pktsize -= hdrlen;
1348
1349 if (ieee80211_has_protected(hdr->frame_control)) {
Johannes Berg7abc4632013-08-06 18:28:26 +02001350 /*
1351 * This is unlocked and using gtk_i(c)vlen,
1352 * but since everything is under RTNL still
1353 * that's not really a problem - changing
1354 * it would be difficult.
1355 */
Johannes Bergf444eb12013-02-26 12:04:18 +01001356 if (is_multicast_ether_addr(hdr->addr1)) {
1357 ivlen = mvm->gtk_ivlen;
1358 icvlen += mvm->gtk_icvlen;
1359 } else {
1360 ivlen = mvm->ptk_ivlen;
1361 icvlen += mvm->ptk_icvlen;
1362 }
1363 }
1364
1365 /* if truncated, FCS/ICV is (partially) gone */
1366 if (truncated >= icvlen) {
1367 icvlen = 0;
1368 truncated -= icvlen;
1369 } else {
1370 icvlen -= truncated;
1371 truncated = 0;
1372 }
1373
1374 pktsize -= ivlen + icvlen;
1375 pktdata += ivlen;
1376
1377 memcpy(skb_put(pkt, pktsize), pktdata, pktsize);
1378
Johannes Berg9b26b502013-01-22 13:02:09 +01001379 if (ieee80211_data_to_8023(pkt, vif->addr, vif->type))
1380 goto report;
1381 wakeup.packet = pkt->data;
1382 wakeup.packet_present_len = pkt->len;
Johannes Bergf444eb12013-02-26 12:04:18 +01001383 wakeup.packet_len = pkt->len - truncated;
Johannes Berg9b26b502013-01-22 13:02:09 +01001384 wakeup.packet_80211 = false;
1385 } else {
Johannes Bergf444eb12013-02-26 12:04:18 +01001386 int fcslen = 4;
1387
1388 if (truncated >= 4) {
1389 truncated -= 4;
1390 fcslen = 0;
1391 } else {
1392 fcslen -= truncated;
1393 truncated = 0;
1394 }
1395 pktsize -= fcslen;
Johannes Berg9b26b502013-01-22 13:02:09 +01001396 wakeup.packet = status->wake_packet;
1397 wakeup.packet_present_len = pktsize;
Johannes Bergf444eb12013-02-26 12:04:18 +01001398 wakeup.packet_len = pktlen - truncated;
Johannes Berg9b26b502013-01-22 13:02:09 +01001399 wakeup.packet_80211 = true;
1400 }
1401 }
1402
1403 report:
1404 ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL);
1405 kfree_skb(pkt);
Johannes Berg7abc4632013-08-06 18:28:26 +02001406}
Johannes Berg9b26b502013-01-22 13:02:09 +01001407
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001408static void iwl_mvm_aes_sc_to_seq(struct aes_sc *sc,
1409 struct ieee80211_key_seq *seq)
1410{
1411 u64 pn;
1412
1413 pn = le64_to_cpu(sc->pn);
1414 seq->ccmp.pn[0] = pn >> 40;
1415 seq->ccmp.pn[1] = pn >> 32;
1416 seq->ccmp.pn[2] = pn >> 24;
1417 seq->ccmp.pn[3] = pn >> 16;
1418 seq->ccmp.pn[4] = pn >> 8;
1419 seq->ccmp.pn[5] = pn;
1420}
1421
1422static void iwl_mvm_tkip_sc_to_seq(struct tkip_sc *sc,
1423 struct ieee80211_key_seq *seq)
1424{
1425 seq->tkip.iv32 = le32_to_cpu(sc->iv32);
1426 seq->tkip.iv16 = le16_to_cpu(sc->iv16);
1427}
1428
1429static void iwl_mvm_set_aes_rx_seq(struct aes_sc *scs,
1430 struct ieee80211_key_conf *key)
1431{
1432 int tid;
1433
1434 BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS);
1435
1436 for (tid = 0; tid < IWL_NUM_RSC; tid++) {
1437 struct ieee80211_key_seq seq = {};
1438
1439 iwl_mvm_aes_sc_to_seq(&scs[tid], &seq);
1440 ieee80211_set_key_rx_seq(key, tid, &seq);
1441 }
1442}
1443
1444static void iwl_mvm_set_tkip_rx_seq(struct tkip_sc *scs,
1445 struct ieee80211_key_conf *key)
1446{
1447 int tid;
1448
1449 BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS);
1450
1451 for (tid = 0; tid < IWL_NUM_RSC; tid++) {
1452 struct ieee80211_key_seq seq = {};
1453
1454 iwl_mvm_tkip_sc_to_seq(&scs[tid], &seq);
1455 ieee80211_set_key_rx_seq(key, tid, &seq);
1456 }
1457}
1458
1459static void iwl_mvm_set_key_rx_seq(struct ieee80211_key_conf *key,
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001460 struct iwl_wowlan_status *status)
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001461{
1462 union iwl_all_tsc_rsc *rsc = &status->gtk.rsc.all_tsc_rsc;
1463
1464 switch (key->cipher) {
1465 case WLAN_CIPHER_SUITE_CCMP:
1466 iwl_mvm_set_aes_rx_seq(rsc->aes.multicast_rsc, key);
1467 break;
1468 case WLAN_CIPHER_SUITE_TKIP:
1469 iwl_mvm_set_tkip_rx_seq(rsc->tkip.multicast_rsc, key);
1470 break;
1471 default:
1472 WARN_ON(1);
1473 }
1474}
1475
1476struct iwl_mvm_d3_gtk_iter_data {
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001477 struct iwl_wowlan_status *status;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001478 void *last_gtk;
1479 u32 cipher;
1480 bool find_phase, unhandled_cipher;
1481 int num_keys;
1482};
1483
Emmanuel Grumbach59fd4bf2015-11-01 13:06:37 +02001484static void iwl_mvm_d3_update_keys(struct ieee80211_hw *hw,
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001485 struct ieee80211_vif *vif,
1486 struct ieee80211_sta *sta,
1487 struct ieee80211_key_conf *key,
1488 void *_data)
1489{
1490 struct iwl_mvm_d3_gtk_iter_data *data = _data;
1491
1492 if (data->unhandled_cipher)
1493 return;
1494
1495 switch (key->cipher) {
1496 case WLAN_CIPHER_SUITE_WEP40:
1497 case WLAN_CIPHER_SUITE_WEP104:
1498 /* ignore WEP completely, nothing to do */
1499 return;
1500 case WLAN_CIPHER_SUITE_CCMP:
1501 case WLAN_CIPHER_SUITE_TKIP:
1502 /* we support these */
1503 break;
1504 default:
1505 /* everything else (even CMAC for MFP) - disconnect from AP */
1506 data->unhandled_cipher = true;
1507 return;
1508 }
1509
1510 data->num_keys++;
1511
1512 /*
1513 * pairwise key - update sequence counters only;
1514 * note that this assumes no TDLS sessions are active
1515 */
1516 if (sta) {
1517 struct ieee80211_key_seq seq = {};
1518 union iwl_all_tsc_rsc *sc = &data->status->gtk.rsc.all_tsc_rsc;
1519
1520 if (data->find_phase)
1521 return;
1522
1523 switch (key->cipher) {
1524 case WLAN_CIPHER_SUITE_CCMP:
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001525 iwl_mvm_set_aes_rx_seq(sc->aes.unicast_rsc, key);
Johannes Berg6645d5e2015-09-15 09:58:53 +02001526 atomic64_set(&key->tx_pn, le64_to_cpu(sc->aes.tsc.pn));
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001527 break;
1528 case WLAN_CIPHER_SUITE_TKIP:
1529 iwl_mvm_tkip_sc_to_seq(&sc->tkip.tsc, &seq);
1530 iwl_mvm_set_tkip_rx_seq(sc->tkip.unicast_rsc, key);
Johannes Berg6645d5e2015-09-15 09:58:53 +02001531 ieee80211_set_key_tx_seq(key, &seq);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001532 break;
1533 }
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001534
1535 /* that's it for this key */
1536 return;
1537 }
1538
1539 if (data->find_phase) {
1540 data->last_gtk = key;
1541 data->cipher = key->cipher;
1542 return;
1543 }
1544
1545 if (data->status->num_of_gtk_rekeys)
1546 ieee80211_remove_key(key);
1547 else if (data->last_gtk == key)
1548 iwl_mvm_set_key_rx_seq(key, data->status);
1549}
1550
1551static bool iwl_mvm_setup_connection_keep(struct iwl_mvm *mvm,
1552 struct ieee80211_vif *vif,
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001553 struct iwl_wowlan_status *status)
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001554{
1555 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1556 struct iwl_mvm_d3_gtk_iter_data gtkdata = {
1557 .status = status,
1558 };
Eliad Peller431591c2013-11-07 14:12:09 +02001559 u32 disconnection_reasons =
1560 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON |
1561 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001562
1563 if (!status || !vif->bss_conf.bssid)
1564 return false;
1565
Eliad Peller431591c2013-11-07 14:12:09 +02001566 if (le32_to_cpu(status->wakeup_reasons) & disconnection_reasons)
1567 return false;
1568
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001569 /* find last GTK that we used initially, if any */
1570 gtkdata.find_phase = true;
1571 ieee80211_iter_keys(mvm->hw, vif,
Emmanuel Grumbach59fd4bf2015-11-01 13:06:37 +02001572 iwl_mvm_d3_update_keys, &gtkdata);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001573 /* not trying to keep connections with MFP/unhandled ciphers */
1574 if (gtkdata.unhandled_cipher)
1575 return false;
1576 if (!gtkdata.num_keys)
Luciano Coelhocfa88892013-11-19 15:38:55 +02001577 goto out;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001578 if (!gtkdata.last_gtk)
1579 return false;
1580
1581 /*
1582 * invalidate all other GTKs that might still exist and update
1583 * the one that we used
1584 */
1585 gtkdata.find_phase = false;
1586 ieee80211_iter_keys(mvm->hw, vif,
Emmanuel Grumbach59fd4bf2015-11-01 13:06:37 +02001587 iwl_mvm_d3_update_keys, &gtkdata);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001588
1589 if (status->num_of_gtk_rekeys) {
1590 struct ieee80211_key_conf *key;
1591 struct {
1592 struct ieee80211_key_conf conf;
1593 u8 key[32];
1594 } conf = {
1595 .conf.cipher = gtkdata.cipher,
1596 .conf.keyidx = status->gtk.key_index,
1597 };
1598
1599 switch (gtkdata.cipher) {
1600 case WLAN_CIPHER_SUITE_CCMP:
1601 conf.conf.keylen = WLAN_KEY_LEN_CCMP;
1602 memcpy(conf.conf.key, status->gtk.decrypt_key,
1603 WLAN_KEY_LEN_CCMP);
1604 break;
1605 case WLAN_CIPHER_SUITE_TKIP:
1606 conf.conf.keylen = WLAN_KEY_LEN_TKIP;
1607 memcpy(conf.conf.key, status->gtk.decrypt_key, 16);
1608 /* leave TX MIC key zeroed, we don't use it anyway */
1609 memcpy(conf.conf.key +
1610 NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY,
1611 status->gtk.tkip_mic_key, 8);
1612 break;
1613 }
1614
1615 key = ieee80211_gtk_rekey_add(vif, &conf.conf);
1616 if (IS_ERR(key))
1617 return false;
1618 iwl_mvm_set_key_rx_seq(key, status);
1619 }
1620
1621 if (status->num_of_gtk_rekeys) {
1622 __be64 replay_ctr =
1623 cpu_to_be64(le64_to_cpu(status->replay_ctr));
1624 ieee80211_gtk_rekey_notify(vif, vif->bss_conf.bssid,
1625 (void *)&replay_ctr, GFP_KERNEL);
1626 }
1627
Luciano Coelhocfa88892013-11-19 15:38:55 +02001628out:
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001629 mvmvif->seqno_valid = true;
1630 /* +0x10 because the set API expects next-to-use, not last-used */
1631 mvmvif->seqno = le16_to_cpu(status->non_qos_seq_ctr) + 0x10;
1632
1633 return true;
1634}
1635
Luciano Coelhoec12f452014-11-20 10:14:44 +02001636static struct iwl_wowlan_status *
1637iwl_mvm_get_wakeup_status(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
Johannes Berg7abc4632013-08-06 18:28:26 +02001638{
1639 u32 base = mvm->error_event_table;
1640 struct error_table_start {
1641 /* cf. struct iwl_error_event_table */
1642 u32 valid;
1643 u32 error_id;
1644 } err_info;
1645 struct iwl_host_cmd cmd = {
1646 .id = WOWLAN_GET_STATUSES,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001647 .flags = CMD_WANT_SKB,
Johannes Berg7abc4632013-08-06 18:28:26 +02001648 };
Luciano Coelhoec12f452014-11-20 10:14:44 +02001649 struct iwl_wowlan_status *status, *fw_status;
1650 int ret, len, status_size;
Johannes Berg7abc4632013-08-06 18:28:26 +02001651
1652 iwl_trans_read_mem_bytes(mvm->trans, base,
1653 &err_info, sizeof(err_info));
1654
1655 if (err_info.valid) {
Luciano Coelhoec12f452014-11-20 10:14:44 +02001656 IWL_INFO(mvm, "error table is valid (%d) with error (%d)\n",
1657 err_info.valid, err_info.error_id);
Johannes Berg7abc4632013-08-06 18:28:26 +02001658 if (err_info.error_id == RF_KILL_INDICATOR_FOR_WOWLAN) {
1659 struct cfg80211_wowlan_wakeup wakeup = {
1660 .rfkill_release = true,
1661 };
1662 ieee80211_report_wowlan_wakeup(vif, &wakeup,
1663 GFP_KERNEL);
1664 }
Luciano Coelhoec12f452014-11-20 10:14:44 +02001665 return ERR_PTR(-EIO);
Johannes Berg7abc4632013-08-06 18:28:26 +02001666 }
1667
1668 /* only for tracing for now */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001669 ret = iwl_mvm_send_cmd_pdu(mvm, OFFLOADS_QUERY_CMD, 0, 0, NULL);
Johannes Berg7abc4632013-08-06 18:28:26 +02001670 if (ret)
1671 IWL_ERR(mvm, "failed to query offload statistics (%d)\n", ret);
1672
1673 ret = iwl_mvm_send_cmd(mvm, &cmd);
1674 if (ret) {
1675 IWL_ERR(mvm, "failed to query status (%d)\n", ret);
Luciano Coelhoec12f452014-11-20 10:14:44 +02001676 return ERR_PTR(ret);
Johannes Berg7abc4632013-08-06 18:28:26 +02001677 }
1678
1679 /* RF-kill already asserted again... */
Luciano Coelhoec12f452014-11-20 10:14:44 +02001680 if (!cmd.resp_pkt) {
Johannes Berge111e962015-03-03 20:23:47 +01001681 fw_status = ERR_PTR(-ERFKILL);
Luciano Coelhoec12f452014-11-20 10:14:44 +02001682 goto out_free_resp;
1683 }
Johannes Berg7abc4632013-08-06 18:28:26 +02001684
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001685 status_size = sizeof(*fw_status);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001686
Johannes Berg65b30342014-01-08 13:16:33 +01001687 len = iwl_rx_packet_payload_len(cmd.resp_pkt);
1688 if (len < status_size) {
Johannes Berg7abc4632013-08-06 18:28:26 +02001689 IWL_ERR(mvm, "Invalid WoWLAN status response!\n");
Johannes Berge111e962015-03-03 20:23:47 +01001690 fw_status = ERR_PTR(-EIO);
Johannes Berg7abc4632013-08-06 18:28:26 +02001691 goto out_free_resp;
1692 }
1693
Luciano Coelhoec12f452014-11-20 10:14:44 +02001694 status = (void *)cmd.resp_pkt->data;
1695 if (len != (status_size +
1696 ALIGN(le32_to_cpu(status->wake_packet_bufsize), 4))) {
1697 IWL_ERR(mvm, "Invalid WoWLAN status response!\n");
Johannes Berge111e962015-03-03 20:23:47 +01001698 fw_status = ERR_PTR(-EIO);
Luciano Coelhoec12f452014-11-20 10:14:44 +02001699 goto out_free_resp;
1700 }
1701
1702 fw_status = kmemdup(status, len, GFP_KERNEL);
1703
1704out_free_resp:
1705 iwl_free_resp(&cmd);
Johannes Berge111e962015-03-03 20:23:47 +01001706 return fw_status;
Luciano Coelhoec12f452014-11-20 10:14:44 +02001707}
1708
1709/* releases the MVM mutex */
1710static bool iwl_mvm_query_wakeup_reasons(struct iwl_mvm *mvm,
1711 struct ieee80211_vif *vif)
1712{
1713 struct iwl_wowlan_status_data status;
1714 struct iwl_wowlan_status *fw_status;
1715 int i;
1716 bool keep;
1717 struct ieee80211_sta *ap_sta;
1718 struct iwl_mvm_sta *mvm_ap_sta;
1719
1720 fw_status = iwl_mvm_get_wakeup_status(mvm, vif);
1721 if (IS_ERR_OR_NULL(fw_status))
1722 goto out_unlock;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001723
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001724 status.pattern_number = le16_to_cpu(fw_status->pattern_number);
1725 for (i = 0; i < 8; i++)
1726 status.qos_seq_ctr[i] =
1727 le16_to_cpu(fw_status->qos_seq_ctr[i]);
1728 status.wakeup_reasons = le32_to_cpu(fw_status->wakeup_reasons);
1729 status.wake_packet_length =
1730 le32_to_cpu(fw_status->wake_packet_length);
1731 status.wake_packet_bufsize =
1732 le32_to_cpu(fw_status->wake_packet_bufsize);
1733 status.wake_packet = fw_status->wake_packet;
Johannes Berg7abc4632013-08-06 18:28:26 +02001734
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001735 /* still at hard-coded place 0 for D3 image */
1736 ap_sta = rcu_dereference_protected(
1737 mvm->fw_id_to_mac_id[0],
1738 lockdep_is_held(&mvm->mutex));
1739 if (IS_ERR_OR_NULL(ap_sta))
Luciano Coelhoec12f452014-11-20 10:14:44 +02001740 goto out_free;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001741
Johannes Berg9d8ce6a2014-12-23 16:02:40 +01001742 mvm_ap_sta = iwl_mvm_sta_from_mac80211(ap_sta);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001743 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
1744 u16 seq = status.qos_seq_ctr[i];
1745 /* firmware stores last-used value, we store next value */
1746 seq += 0x10;
1747 mvm_ap_sta->tid_data[i].seq_number = seq;
1748 }
1749
Johannes Berg7abc4632013-08-06 18:28:26 +02001750 /* now we have all the data we need, unlock to avoid mac80211 issues */
1751 mutex_unlock(&mvm->mutex);
1752
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001753 iwl_mvm_report_wakeup_reasons(mvm, vif, &status);
1754
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001755 keep = iwl_mvm_setup_connection_keep(mvm, vif, fw_status);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001756
Luciano Coelhoec12f452014-11-20 10:14:44 +02001757 kfree(fw_status);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001758 return keep;
Johannes Berg7abc4632013-08-06 18:28:26 +02001759
Luciano Coelhoec12f452014-11-20 10:14:44 +02001760out_free:
1761 kfree(fw_status);
1762out_unlock:
Johannes Berg7abc4632013-08-06 18:28:26 +02001763 mutex_unlock(&mvm->mutex);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001764 return false;
Johannes Berg9b26b502013-01-22 13:02:09 +01001765}
1766
Eliad Pellera3f7ba52015-11-11 17:23:59 +02001767void iwl_mvm_d0i3_update_keys(struct iwl_mvm *mvm,
1768 struct ieee80211_vif *vif,
1769 struct iwl_wowlan_status *status)
1770{
1771 struct iwl_mvm_d3_gtk_iter_data gtkdata = {
1772 .status = status,
1773 };
1774
1775 /*
1776 * rekey handling requires taking locks that can't be taken now.
1777 * however, d0i3 doesn't offload rekey, so we're fine.
1778 */
1779 if (WARN_ON_ONCE(status->num_of_gtk_rekeys))
1780 return;
1781
1782 /* find last GTK that we used initially, if any */
1783 gtkdata.find_phase = true;
1784 iwl_mvm_iter_d0i3_ap_keys(mvm, vif, iwl_mvm_d3_update_keys, &gtkdata);
1785
1786 gtkdata.find_phase = false;
1787 iwl_mvm_iter_d0i3_ap_keys(mvm, vif, iwl_mvm_d3_update_keys, &gtkdata);
1788}
1789
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001790struct iwl_mvm_nd_query_results {
1791 u32 matched_profiles;
1792 struct iwl_scan_offload_profile_match matches[IWL_SCAN_MAX_PROFILES];
1793};
1794
1795static int
1796iwl_mvm_netdetect_query_results(struct iwl_mvm *mvm,
1797 struct iwl_mvm_nd_query_results *results)
Luciano Coelhob04998f2014-11-20 15:58:34 +02001798{
1799 struct iwl_scan_offload_profiles_query *query;
1800 struct iwl_host_cmd cmd = {
1801 .id = SCAN_OFFLOAD_PROFILES_QUERY_CMD,
1802 .flags = CMD_WANT_SKB,
1803 };
1804 int ret, len;
1805
1806 ret = iwl_mvm_send_cmd(mvm, &cmd);
1807 if (ret) {
1808 IWL_ERR(mvm, "failed to query matched profiles (%d)\n", ret);
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001809 return ret;
Luciano Coelhob04998f2014-11-20 15:58:34 +02001810 }
1811
1812 /* RF-kill already asserted again... */
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001813 if (!cmd.resp_pkt) {
1814 ret = -ERFKILL;
Luciano Coelhob04998f2014-11-20 15:58:34 +02001815 goto out_free_resp;
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001816 }
Luciano Coelhob04998f2014-11-20 15:58:34 +02001817
1818 len = iwl_rx_packet_payload_len(cmd.resp_pkt);
1819 if (len < sizeof(*query)) {
1820 IWL_ERR(mvm, "Invalid scan offload profiles query response!\n");
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001821 ret = -EIO;
Luciano Coelhob04998f2014-11-20 15:58:34 +02001822 goto out_free_resp;
1823 }
1824
1825 query = (void *)cmd.resp_pkt->data;
1826
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001827 results->matched_profiles = le32_to_cpu(query->matched_profiles);
1828 memcpy(results->matches, query->matches, sizeof(results->matches));
Luciano Coelhob04998f2014-11-20 15:58:34 +02001829
Emmanuel Grumbach6bbd5522015-04-28 15:00:23 +03001830#ifdef CONFIG_IWLWIFI_DEBUGFS
Luciano Coelho484b3d12015-03-30 20:46:32 +03001831 mvm->last_netdetect_scans = le32_to_cpu(query->n_scans_done);
1832#endif
1833
Luciano Coelhob04998f2014-11-20 15:58:34 +02001834out_free_resp:
1835 iwl_free_resp(&cmd);
1836 return ret;
1837}
1838
Luciano Coelho2021a892014-11-20 08:59:51 +02001839static void iwl_mvm_query_netdetect_reasons(struct iwl_mvm *mvm,
1840 struct ieee80211_vif *vif)
1841{
Luciano Coelhod9718da2014-11-21 09:32:23 +02001842 struct cfg80211_wowlan_nd_info *net_detect = NULL;
Luciano Coelho2021a892014-11-20 08:59:51 +02001843 struct cfg80211_wowlan_wakeup wakeup = {
1844 .pattern_idx = -1,
1845 };
1846 struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup;
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001847 struct iwl_mvm_nd_query_results query;
Luciano Coelho2021a892014-11-20 08:59:51 +02001848 struct iwl_wowlan_status *fw_status;
Luciano Coelhod9718da2014-11-21 09:32:23 +02001849 unsigned long matched_profiles;
Luciano Coelho2021a892014-11-20 08:59:51 +02001850 u32 reasons = 0;
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001851 int i, j, n_matches, ret;
Luciano Coelho2021a892014-11-20 08:59:51 +02001852
1853 fw_status = iwl_mvm_get_wakeup_status(mvm, vif);
Haim Dreyfuss2fc863a2015-05-20 08:10:43 +03001854 if (!IS_ERR_OR_NULL(fw_status)) {
Luciano Coelho2021a892014-11-20 08:59:51 +02001855 reasons = le32_to_cpu(fw_status->wakeup_reasons);
Haim Dreyfuss2fc863a2015-05-20 08:10:43 +03001856 kfree(fw_status);
1857 }
Luciano Coelho2021a892014-11-20 08:59:51 +02001858
1859 if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED)
1860 wakeup.rfkill_release = true;
1861
Luciano Coelhob04998f2014-11-20 15:58:34 +02001862 if (reasons != IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS)
1863 goto out;
1864
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001865 ret = iwl_mvm_netdetect_query_results(mvm, &query);
1866 if (ret || !query.matched_profiles) {
Luciano Coelho2021a892014-11-20 08:59:51 +02001867 wakeup_report = NULL;
Luciano Coelhob04998f2014-11-20 15:58:34 +02001868 goto out;
Luciano Coelho2021a892014-11-20 08:59:51 +02001869 }
1870
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001871 matched_profiles = query.matched_profiles;
Luciano Coelhod9718da2014-11-21 09:32:23 +02001872 if (mvm->n_nd_match_sets) {
1873 n_matches = hweight_long(matched_profiles);
1874 } else {
1875 IWL_ERR(mvm, "no net detect match information available\n");
1876 n_matches = 0;
1877 }
1878
1879 net_detect = kzalloc(sizeof(*net_detect) +
1880 (n_matches * sizeof(net_detect->matches[0])),
1881 GFP_KERNEL);
1882 if (!net_detect || !n_matches)
1883 goto out_report_nd;
1884
1885 for_each_set_bit(i, &matched_profiles, mvm->n_nd_match_sets) {
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001886 struct iwl_scan_offload_profile_match *fw_match;
Luciano Coelhod9718da2014-11-21 09:32:23 +02001887 struct cfg80211_wowlan_nd_match *match;
Luciano Coelhoae90c2e52015-05-06 10:45:42 +03001888 int idx, n_channels = 0;
Luciano Coelhod9718da2014-11-21 09:32:23 +02001889
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001890 fw_match = &query.matches[i];
1891
1892 for (j = 0; j < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN; j++)
1893 n_channels += hweight8(fw_match->matching_channels[j]);
1894
1895 match = kzalloc(sizeof(*match) +
1896 (n_channels * sizeof(*match->channels)),
1897 GFP_KERNEL);
Luciano Coelhod9718da2014-11-21 09:32:23 +02001898 if (!match)
1899 goto out_report_nd;
1900
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001901 net_detect->matches[net_detect->n_matches++] = match;
1902
Luciano Coelhoae90c2e52015-05-06 10:45:42 +03001903 /* We inverted the order of the SSIDs in the scan
1904 * request, so invert the index here.
1905 */
1906 idx = mvm->n_nd_match_sets - i - 1;
1907 match->ssid.ssid_len = mvm->nd_match_sets[idx].ssid.ssid_len;
1908 memcpy(match->ssid.ssid, mvm->nd_match_sets[idx].ssid.ssid,
Luciano Coelhod9718da2014-11-21 09:32:23 +02001909 match->ssid.ssid_len);
1910
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001911 if (mvm->n_nd_channels < n_channels)
1912 continue;
1913
1914 for (j = 0; j < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN * 8; j++)
1915 if (fw_match->matching_channels[j / 8] & (BIT(j % 8)))
1916 match->channels[match->n_channels++] =
1917 mvm->nd_channels[j]->center_freq;
Luciano Coelhod9718da2014-11-21 09:32:23 +02001918 }
1919
1920out_report_nd:
1921 wakeup.net_detect = net_detect;
Luciano Coelhob04998f2014-11-20 15:58:34 +02001922out:
Luciano Coelhod9718da2014-11-21 09:32:23 +02001923 iwl_mvm_free_nd(mvm);
1924
Luciano Coelho2021a892014-11-20 08:59:51 +02001925 mutex_unlock(&mvm->mutex);
1926 ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL);
Luciano Coelhod9718da2014-11-21 09:32:23 +02001927
1928 if (net_detect) {
1929 for (i = 0; i < net_detect->n_matches; i++)
1930 kfree(net_detect->matches[i]);
1931 kfree(net_detect);
1932 }
Luciano Coelho2021a892014-11-20 08:59:51 +02001933}
1934
Johannes Bergafc66bb2013-05-03 11:44:16 +02001935static void iwl_mvm_read_d3_sram(struct iwl_mvm *mvm)
1936{
1937#ifdef CONFIG_IWLWIFI_DEBUGFS
1938 const struct fw_img *img = &mvm->fw->img[IWL_UCODE_WOWLAN];
1939 u32 len = img->sec[IWL_UCODE_SECTION_DATA].len;
1940 u32 offs = img->sec[IWL_UCODE_SECTION_DATA].offset;
1941
1942 if (!mvm->store_d3_resume_sram)
1943 return;
1944
1945 if (!mvm->d3_resume_sram) {
1946 mvm->d3_resume_sram = kzalloc(len, GFP_KERNEL);
1947 if (!mvm->d3_resume_sram)
1948 return;
1949 }
1950
1951 iwl_trans_read_mem_bytes(mvm->trans, offs, mvm->d3_resume_sram, len);
1952#endif
1953}
1954
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001955static void iwl_mvm_d3_disconnect_iter(void *data, u8 *mac,
1956 struct ieee80211_vif *vif)
1957{
1958 /* skip the one we keep connection on */
1959 if (data == vif)
1960 return;
1961
1962 if (vif->type == NL80211_IFTYPE_STATION)
1963 ieee80211_resume_disconnect(vif);
1964}
1965
Johannes Bergdebff612013-05-14 13:53:45 +02001966static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test)
Johannes Berg8ca151b2013-01-24 14:25:36 +01001967{
Johannes Berg8ca151b2013-01-24 14:25:36 +01001968 struct ieee80211_vif *vif = NULL;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001969 int ret;
1970 enum iwl_d3_status d3_status;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001971 bool keep = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001972
1973 mutex_lock(&mvm->mutex);
1974
1975 /* get the BSS vif pointer again */
Luciano Coelho7f549e22014-10-02 15:38:04 +03001976 vif = iwl_mvm_get_bss_vif(mvm);
1977 if (IS_ERR_OR_NULL(vif))
Luciano Coelhoa500e462015-05-04 17:03:17 +03001978 goto err;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001979
Johannes Bergdebff612013-05-14 13:53:45 +02001980 ret = iwl_trans_d3_resume(mvm->trans, &d3_status, test);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001981 if (ret)
Luciano Coelhoa500e462015-05-04 17:03:17 +03001982 goto err;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001983
1984 if (d3_status != IWL_D3_STATUS_ALIVE) {
1985 IWL_INFO(mvm, "Device was reset during suspend\n");
Luciano Coelhoa500e462015-05-04 17:03:17 +03001986 goto err;
Johannes Berg8ca151b2013-01-24 14:25:36 +01001987 }
1988
Johannes Bergafc66bb2013-05-03 11:44:16 +02001989 /* query SRAM first in case we want event logging */
1990 iwl_mvm_read_d3_sram(mvm);
1991
Jonathan Doron47c8b152014-11-27 16:55:25 +02001992 /*
1993 * Query the current location and source from the D3 firmware so we
1994 * can play it back when we re-intiailize the D0 firmware
1995 */
1996 iwl_mvm_update_changed_regdom(mvm);
1997
Luciano Coelho2021a892014-11-20 08:59:51 +02001998 if (mvm->net_detect) {
1999 iwl_mvm_query_netdetect_reasons(mvm, vif);
Luciano Coelhoe0ede172015-02-13 21:37:09 +02002000 /* has unlocked the mutex, so skip that */
2001 goto out;
Luciano Coelho2021a892014-11-20 08:59:51 +02002002 } else {
2003 keep = iwl_mvm_query_wakeup_reasons(mvm, vif);
Eliad Peller78c9df62013-11-07 14:13:30 +02002004#ifdef CONFIG_IWLWIFI_DEBUGFS
Luciano Coelho2021a892014-11-20 08:59:51 +02002005 if (keep)
2006 mvm->keep_vif = vif;
Luciano Coelho0c2ae042015-03-12 09:25:15 +02002007#endif
Luciano Coelhoe0ede172015-02-13 21:37:09 +02002008 /* has unlocked the mutex, so skip that */
2009 goto out_iterate;
Luciano Coelho2021a892014-11-20 08:59:51 +02002010 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002011
Luciano Coelhoa500e462015-05-04 17:03:17 +03002012err:
2013 iwl_mvm_free_nd(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002014 mutex_unlock(&mvm->mutex);
2015
Luciano Coelhoe0ede172015-02-13 21:37:09 +02002016out_iterate:
Johannes Berg6d9d32b2013-08-06 18:58:56 +02002017 if (!test)
2018 ieee80211_iterate_active_interfaces_rtnl(mvm->hw,
2019 IEEE80211_IFACE_ITER_NORMAL,
2020 iwl_mvm_d3_disconnect_iter, keep ? vif : NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002021
Luciano Coelhoe0ede172015-02-13 21:37:09 +02002022out:
Johannes Berg8ca151b2013-01-24 14:25:36 +01002023 /* return 1 to reconfigure the device */
2024 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
Johannes Berg58629d92014-11-06 09:40:50 +01002025 set_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status);
Luciano Coelhodcfc7fb2015-04-28 08:41:55 +03002026
2027 /* We always return 1, which causes mac80211 to do a reconfig
2028 * with IEEE80211_RECONFIG_TYPE_RESTART. This type of
2029 * reconfig calls iwl_mvm_restart_complete(), where we unref
2030 * the IWL_MVM_REF_UCODE_DOWN, so we need to take the
2031 * reference here.
2032 */
2033 iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002034 return 1;
2035}
2036
Eliad Peller2d428012015-06-17 15:32:37 +03002037static int iwl_mvm_resume_d3(struct iwl_mvm *mvm)
2038{
2039 iwl_trans_resume(mvm->trans);
2040
2041 return __iwl_mvm_resume(mvm, false);
2042}
2043
2044static int iwl_mvm_resume_d0i3(struct iwl_mvm *mvm)
2045{
2046 bool exit_now;
Eliad Peller6dfb36c2015-07-09 14:17:24 +03002047 enum iwl_d3_status d3_status;
Luca Coelhob7282642015-09-17 23:44:14 +03002048 struct iwl_trans *trans = mvm->trans;
Eliad Peller6dfb36c2015-07-09 14:17:24 +03002049
Luca Coelhob7282642015-09-17 23:44:14 +03002050 iwl_trans_d3_resume(trans, &d3_status, false);
Eliad Peller2d428012015-06-17 15:32:37 +03002051
2052 /*
2053 * make sure to clear D0I3_DEFER_WAKEUP before
2054 * calling iwl_trans_resume(), which might wait
2055 * for d0i3 exit completion.
2056 */
2057 mutex_lock(&mvm->d0i3_suspend_mutex);
2058 __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags);
2059 exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP,
2060 &mvm->d0i3_suspend_flags);
2061 mutex_unlock(&mvm->d0i3_suspend_mutex);
2062 if (exit_now) {
2063 IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n");
2064 _iwl_mvm_exit_d0i3(mvm);
2065 }
2066
Luca Coelhob7282642015-09-17 23:44:14 +03002067 iwl_trans_resume(trans);
Eliad Peller2d428012015-06-17 15:32:37 +03002068
Luca Coelhob7282642015-09-17 23:44:14 +03002069 if (iwl_mvm_enter_d0i3_on_suspend(mvm)) {
Eliad Peller2d428012015-06-17 15:32:37 +03002070 int ret = iwl_mvm_exit_d0i3(mvm->hw->priv);
2071
2072 if (ret)
2073 return ret;
2074 /*
2075 * d0i3 exit will be deferred until reconfig_complete.
2076 * make sure there we are out of d0i3.
2077 */
2078 }
2079 return 0;
2080}
2081
Johannes Bergdebff612013-05-14 13:53:45 +02002082int iwl_mvm_resume(struct ieee80211_hw *hw)
2083{
2084 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luca Coelhob7282642015-09-17 23:44:14 +03002085 int ret;
Johannes Bergdebff612013-05-14 13:53:45 +02002086
Luca Coelhob7282642015-09-17 23:44:14 +03002087 if (mvm->trans->system_pm_mode == IWL_PLAT_PM_MODE_D0I3)
2088 ret = iwl_mvm_resume_d0i3(mvm);
Eliad Peller2d428012015-06-17 15:32:37 +03002089 else
Luca Coelhob7282642015-09-17 23:44:14 +03002090 ret = iwl_mvm_resume_d3(mvm);
2091
2092 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED;
2093
2094 return ret;
Johannes Bergdebff612013-05-14 13:53:45 +02002095}
2096
Johannes Berg8ca151b2013-01-24 14:25:36 +01002097void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled)
2098{
2099 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2100
2101 device_set_wakeup_enable(mvm->trans->dev, enabled);
2102}
Johannes Bergdebff612013-05-14 13:53:45 +02002103
2104#ifdef CONFIG_IWLWIFI_DEBUGFS
2105static int iwl_mvm_d3_test_open(struct inode *inode, struct file *file)
2106{
2107 struct iwl_mvm *mvm = inode->i_private;
2108 int err;
2109
2110 if (mvm->d3_test_active)
2111 return -EBUSY;
2112
2113 file->private_data = inode->i_private;
2114
2115 ieee80211_stop_queues(mvm->hw);
2116 synchronize_net();
2117
Luca Coelhob7282642015-09-17 23:44:14 +03002118 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_D3;
2119
Johannes Bergdebff612013-05-14 13:53:45 +02002120 /* start pseudo D3 */
2121 rtnl_lock();
2122 err = __iwl_mvm_suspend(mvm->hw, mvm->hw->wiphy->wowlan_config, true);
2123 rtnl_unlock();
2124 if (err > 0)
2125 err = -EINVAL;
2126 if (err) {
2127 ieee80211_wake_queues(mvm->hw);
2128 return err;
2129 }
2130 mvm->d3_test_active = true;
Eliad Peller78c9df62013-11-07 14:13:30 +02002131 mvm->keep_vif = NULL;
Johannes Bergdebff612013-05-14 13:53:45 +02002132 return 0;
2133}
2134
2135static ssize_t iwl_mvm_d3_test_read(struct file *file, char __user *user_buf,
2136 size_t count, loff_t *ppos)
2137{
2138 struct iwl_mvm *mvm = file->private_data;
2139 u32 pme_asserted;
2140
2141 while (true) {
Eliad Peller4ed80a82013-11-07 13:23:21 +02002142 /* read pme_ptr if available */
2143 if (mvm->d3_test_pme_ptr) {
2144 pme_asserted = iwl_trans_read_mem32(mvm->trans,
2145 mvm->d3_test_pme_ptr);
2146 if (pme_asserted)
2147 break;
2148 }
2149
Johannes Bergdebff612013-05-14 13:53:45 +02002150 if (msleep_interruptible(100))
2151 break;
2152 }
2153
2154 return 0;
2155}
2156
2157static void iwl_mvm_d3_test_disconn_work_iter(void *_data, u8 *mac,
2158 struct ieee80211_vif *vif)
2159{
Eliad Peller78c9df62013-11-07 14:13:30 +02002160 /* skip the one we keep connection on */
2161 if (_data == vif)
2162 return;
2163
Johannes Bergdebff612013-05-14 13:53:45 +02002164 if (vif->type == NL80211_IFTYPE_STATION)
2165 ieee80211_connection_loss(vif);
2166}
2167
2168static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file)
2169{
2170 struct iwl_mvm *mvm = inode->i_private;
2171 int remaining_time = 10;
2172
2173 mvm->d3_test_active = false;
Luca Coelhob7282642015-09-17 23:44:14 +03002174
Luciano Coelho31ca09d2014-09-22 13:22:51 +03002175 rtnl_lock();
Johannes Bergdebff612013-05-14 13:53:45 +02002176 __iwl_mvm_resume(mvm, true);
Luciano Coelho31ca09d2014-09-22 13:22:51 +03002177 rtnl_unlock();
Luca Coelhob7282642015-09-17 23:44:14 +03002178
2179 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED;
2180
Johannes Bergdebff612013-05-14 13:53:45 +02002181 iwl_abort_notification_waits(&mvm->notif_wait);
2182 ieee80211_restart_hw(mvm->hw);
2183
2184 /* wait for restart and disconnect all interfaces */
2185 while (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2186 remaining_time > 0) {
2187 remaining_time--;
2188 msleep(1000);
2189 }
2190
2191 if (remaining_time == 0)
2192 IWL_ERR(mvm, "Timed out waiting for HW restart to finish!\n");
2193
2194 ieee80211_iterate_active_interfaces_atomic(
2195 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
Eliad Peller78c9df62013-11-07 14:13:30 +02002196 iwl_mvm_d3_test_disconn_work_iter, mvm->keep_vif);
Johannes Bergdebff612013-05-14 13:53:45 +02002197
2198 ieee80211_wake_queues(mvm->hw);
2199
2200 return 0;
2201}
2202
2203const struct file_operations iwl_dbgfs_d3_test_ops = {
2204 .llseek = no_llseek,
2205 .open = iwl_mvm_d3_test_open,
2206 .read = iwl_mvm_d3_test_read,
2207 .release = iwl_mvm_d3_test_release,
2208};
2209#endif