blob: d21143495e70b1dab17f6dc2ce9de4452be1ae34 [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 Grumbachf4bfdc52020-04-24 18:48:13 +03008 * Copyright(c) 2012 - 2014, 2018 - 2020 Intel Corporation. All rights reserved.
Luciano Coelho65ff5562015-03-20 13:35:47 +02009 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Luca Coelhofcea37b2017-04-12 16:33:41 +030010 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010011 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of version 2 of the GNU General Public License as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
20 *
Johannes Berg8ca151b2013-01-24 14:25:36 +010021 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020022 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010023 *
24 * Contact Information:
Emmanuel Grumbachcb2f8272015-11-17 15:39:56 +020025 * Intel Linux Wireless <linuxwifi@intel.com>
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 * BSD LICENSE
29 *
Emmanuel Grumbachf4bfdc52020-04-24 18:48:13 +030030 * Copyright(c) 2012 - 2014, 2018 - 2020 Intel Corporation. All rights reserved.
Luciano Coelho65ff5562015-03-20 13:35:47 +020031 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
Luca Coelhofcea37b2017-04-12 16:33:41 +030032 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010033 * All rights reserved.
34 *
35 * Redistribution and use in source and binary forms, with or without
36 * modification, are permitted provided that the following conditions
37 * are met:
38 *
39 * * Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * * Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in
43 * the documentation and/or other materials provided with the
44 * distribution.
45 * * Neither the name Intel Corporation nor the names of its
46 * contributors may be used to endorse or promote products derived
47 * from this software without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
50 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
51 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
52 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
53 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
54 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
55 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
56 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
57 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
58 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
59 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 *
61 *****************************************************************************/
62
Johannes Bergf444eb12013-02-26 12:04:18 +010063#include <linux/etherdevice.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010064#include <linux/ip.h>
Johannes Bergdebff612013-05-14 13:53:45 +020065#include <linux/fs.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010066#include <net/cfg80211.h>
67#include <net/ipv6.h>
Johannes Bergf0c26462013-01-22 20:41:58 +010068#include <net/tcp.h>
Johannes Bergf7fc5982013-08-20 13:04:10 +020069#include <net/addrconf.h>
Johannes Berg8ca151b2013-01-24 14:25:36 +010070#include "iwl-modparams.h"
71#include "fw-api.h"
72#include "mvm.h"
Nathan Errera9e3c3932020-09-28 12:23:15 +030073#include "fw/img.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010074
75void 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
Johannes Berg8ca151b2013-01-24 14:25:36 +010082 mutex_lock(&mvm->mutex);
83
Nathan Errera2a42aea2020-09-30 16:31:17 +030084 mvmvif->rekey_data.kek_len = data->kek_len;
85 mvmvif->rekey_data.kck_len = data->kck_len;
86 memcpy(mvmvif->rekey_data.kek, data->kek, data->kek_len);
87 memcpy(mvmvif->rekey_data.kck, data->kck, data->kck_len);
88 mvmvif->rekey_data.akm = data->akm & 0xFF;
Johannes Berg8ca151b2013-01-24 14:25:36 +010089 mvmvif->rekey_data.replay_ctr =
Johannes Bergcba84572016-11-30 17:04:52 +010090 cpu_to_le64(be64_to_cpup((__be64 *)data->replay_ctr));
Johannes Berg8ca151b2013-01-24 14:25:36 +010091 mvmvif->rekey_data.valid = true;
92
93 mutex_unlock(&mvm->mutex);
94}
95
96#if IS_ENABLED(CONFIG_IPV6)
97void 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
Sara Sharonc97dab42015-11-19 11:53:49 +0200105 memset(mvmvif->tentative_addrs, 0, sizeof(mvmvif->tentative_addrs));
106
Emmanuel Grumbacha3777e02013-02-10 13:07:08 +0200107 read_lock_bh(&idev->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100108 list_for_each_entry(ifa, &idev->addr_list, if_list) {
109 mvmvif->target_ipv6_addrs[idx] = ifa->addr;
Sara Sharonc97dab42015-11-19 11:53:49 +0200110 if (ifa->flags & IFA_F_TENTATIVE)
111 __set_bit(idx, mvmvif->tentative_addrs);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100112 idx++;
Johannes Berg5369d6c2013-07-08 11:17:06 +0200113 if (idx >= IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100114 break;
115 }
Emmanuel Grumbacha3777e02013-02-10 13:07:08 +0200116 read_unlock_bh(&idev->lock);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100117
118 mvmvif->num_target_ipv6_addrs = idx;
119}
120#endif
121
122void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw,
123 struct ieee80211_vif *vif, int idx)
124{
125 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
126
127 mvmvif->tx_key_idx = idx;
128}
129
130static void iwl_mvm_convert_p1k(u16 *p1k, __le16 *out)
131{
132 int i;
133
134 for (i = 0; i < IWL_P1K_SIZE; i++)
135 out[i] = cpu_to_le16(p1k[i]);
136}
137
Johannes Bergf5e28ea2015-12-06 14:58:08 +0200138static const u8 *iwl_mvm_find_max_pn(struct ieee80211_key_conf *key,
139 struct iwl_mvm_key_pn *ptk_pn,
140 struct ieee80211_key_seq *seq,
141 int tid, int queues)
142{
143 const u8 *ret = seq->ccmp.pn;
144 int i;
145
146 /* get the PN from mac80211, used on the default queue */
147 ieee80211_get_key_rx_seq(key, tid, seq);
148
149 /* and use the internal data for the other queues */
150 for (i = 1; i < queues; i++) {
151 const u8 *tmp = ptk_pn->q[i].pn[tid];
152
153 if (memcmp(ret, tmp, IEEE80211_CCMP_PN_LEN) <= 0)
154 ret = tmp;
155 }
156
157 return ret;
158}
159
Johannes Berg8ca151b2013-01-24 14:25:36 +0100160struct wowlan_key_data {
161 struct iwl_wowlan_rsc_tsc_params_cmd *rsc_tsc;
162 struct iwl_wowlan_tkip_params_cmd *tkip;
Nathan Errera2a42aea2020-09-30 16:31:17 +0300163 struct iwl_wowlan_kek_kck_material_cmd_v3 *kek_kck_cmd;
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200164 bool error, use_rsc_tsc, use_tkip, configure_keys;
Johannes Berg5312e542013-07-22 18:26:56 +0200165 int wep_key_idx;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100166};
167
168static void iwl_mvm_wowlan_program_keys(struct ieee80211_hw *hw,
169 struct ieee80211_vif *vif,
170 struct ieee80211_sta *sta,
171 struct ieee80211_key_conf *key,
172 void *_data)
173{
174 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
175 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
176 struct wowlan_key_data *data = _data;
177 struct aes_sc *aes_sc, *aes_tx_sc = NULL;
178 struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL;
179 struct iwl_p1k_cache *rx_p1ks;
180 u8 *rx_mic_key;
181 struct ieee80211_key_seq seq;
182 u32 cur_rx_iv32 = 0;
183 u16 p1k[IWL_P1K_SIZE];
184 int ret, i;
185
Johannes Berg8ca151b2013-01-24 14:25:36 +0100186 switch (key->cipher) {
187 case WLAN_CIPHER_SUITE_WEP40:
188 case WLAN_CIPHER_SUITE_WEP104: { /* hack it for now */
189 struct {
190 struct iwl_mvm_wep_key_cmd wep_key_cmd;
191 struct iwl_mvm_wep_key wep_key;
192 } __packed wkc = {
193 .wep_key_cmd.mac_id_n_color =
194 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
195 mvmvif->color)),
196 .wep_key_cmd.num_keys = 1,
197 /* firmware sets STA_KEY_FLG_WEP_13BYTES */
198 .wep_key_cmd.decryption_type = STA_KEY_FLG_WEP,
199 .wep_key.key_index = key->keyidx,
200 .wep_key.key_size = key->keylen,
201 };
202
203 /*
204 * This will fail -- the key functions don't set support
205 * pairwise WEP keys. However, that's better than silently
206 * failing WoWLAN. Or maybe not?
207 */
208 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
209 break;
210
211 memcpy(&wkc.wep_key.key[3], key->key, key->keylen);
212 if (key->keyidx == mvmvif->tx_key_idx) {
213 /* TX key must be at offset 0 */
214 wkc.wep_key.key_offset = 0;
215 } else {
216 /* others start at 1 */
Johannes Berg5312e542013-07-22 18:26:56 +0200217 data->wep_key_idx++;
218 wkc.wep_key.key_offset = data->wep_key_idx;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100219 }
220
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200221 if (data->configure_keys) {
222 mutex_lock(&mvm->mutex);
223 ret = iwl_mvm_send_cmd_pdu(mvm, WEP_KEY, 0,
224 sizeof(wkc), &wkc);
225 data->error = ret != 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100226
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200227 mvm->ptk_ivlen = key->iv_len;
228 mvm->ptk_icvlen = key->icv_len;
229 mvm->gtk_ivlen = key->iv_len;
230 mvm->gtk_icvlen = key->icv_len;
231 mutex_unlock(&mvm->mutex);
232 }
Johannes Bergf444eb12013-02-26 12:04:18 +0100233
Johannes Berg8ca151b2013-01-24 14:25:36 +0100234 /* don't upload key again */
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200235 return;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100236 }
237 default:
238 data->error = true;
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200239 return;
Nathan Errera2a42aea2020-09-30 16:31:17 +0300240 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
241 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
242 data->kek_kck_cmd->igtk_cipher = cpu_to_le32(STA_KEY_FLG_GCMP);
243 return;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100244 case WLAN_CIPHER_SUITE_AES_CMAC:
Nathan Errera2a42aea2020-09-30 16:31:17 +0300245 data->kek_kck_cmd->igtk_cipher = cpu_to_le32(STA_KEY_FLG_CCM);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100246 /*
247 * Ignore CMAC keys -- the WoWLAN firmware doesn't support them
248 * but we also shouldn't abort suspend due to that. It does have
249 * support for the IGTK key renewal, but doesn't really use the
250 * IGTK for anything. This means we could spuriously wake up or
251 * be deauthenticated, but that was considered acceptable.
252 */
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200253 return;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100254 case WLAN_CIPHER_SUITE_TKIP:
255 if (sta) {
Eliad Peller1ad4f632016-02-14 13:56:36 +0200256 u64 pn64;
257
Dan Halperinee3ae3a2020-09-26 00:30:48 +0300258 tkip_sc =
259 data->rsc_tsc->params.all_tsc_rsc.tkip.unicast_rsc;
260 tkip_tx_sc =
261 &data->rsc_tsc->params.all_tsc_rsc.tkip.tsc;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100262
263 rx_p1ks = data->tkip->rx_uni;
264
Eliad Peller1ad4f632016-02-14 13:56:36 +0200265 pn64 = atomic64_read(&key->tx_pn);
266 tkip_tx_sc->iv16 = cpu_to_le16(TKIP_PN_TO_IV16(pn64));
267 tkip_tx_sc->iv32 = cpu_to_le32(TKIP_PN_TO_IV32(pn64));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100268
Eliad Peller1ad4f632016-02-14 13:56:36 +0200269 ieee80211_get_tkip_p1k_iv(key, TKIP_PN_TO_IV32(pn64),
270 p1k);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100271 iwl_mvm_convert_p1k(p1k, data->tkip->tx.p1k);
272
273 memcpy(data->tkip->mic_keys.tx,
274 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
275 IWL_MIC_KEY_SIZE);
276
277 rx_mic_key = data->tkip->mic_keys.rx_unicast;
278 } else {
279 tkip_sc =
Dan Halperinee3ae3a2020-09-26 00:30:48 +0300280 data->rsc_tsc->params.all_tsc_rsc.tkip.multicast_rsc;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100281 rx_p1ks = data->tkip->rx_multi;
282 rx_mic_key = data->tkip->mic_keys.rx_mcast;
Nathan Errera2a42aea2020-09-30 16:31:17 +0300283 data->kek_kck_cmd->gtk_cipher =
284 cpu_to_le32(STA_KEY_FLG_TKIP);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100285 }
286
287 /*
288 * For non-QoS this relies on the fact that both the uCode and
289 * mac80211 use TID 0 (as they need to to avoid replay attacks)
290 * for checking the IV in the frames.
291 */
292 for (i = 0; i < IWL_NUM_RSC; i++) {
293 ieee80211_get_key_rx_seq(key, i, &seq);
294 tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16);
295 tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32);
296 /* wrapping isn't allowed, AP must rekey */
297 if (seq.tkip.iv32 > cur_rx_iv32)
298 cur_rx_iv32 = seq.tkip.iv32;
299 }
300
301 ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid,
302 cur_rx_iv32, p1k);
303 iwl_mvm_convert_p1k(p1k, rx_p1ks[0].p1k);
304 ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid,
305 cur_rx_iv32 + 1, p1k);
306 iwl_mvm_convert_p1k(p1k, rx_p1ks[1].p1k);
307
308 memcpy(rx_mic_key,
309 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
310 IWL_MIC_KEY_SIZE);
311
312 data->use_tkip = true;
313 data->use_rsc_tsc = true;
314 break;
315 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergc7f996e2020-09-30 16:31:18 +0300316 case WLAN_CIPHER_SUITE_GCMP:
317 case WLAN_CIPHER_SUITE_GCMP_256:
Johannes Berg8ca151b2013-01-24 14:25:36 +0100318 if (sta) {
Johannes Berg6645d5e2015-09-15 09:58:53 +0200319 u64 pn64;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100320
Dan Halperinee3ae3a2020-09-26 00:30:48 +0300321 aes_sc =
322 data->rsc_tsc->params.all_tsc_rsc.aes.unicast_rsc;
323 aes_tx_sc =
324 &data->rsc_tsc->params.all_tsc_rsc.aes.tsc;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100325
Johannes Berg6645d5e2015-09-15 09:58:53 +0200326 pn64 = atomic64_read(&key->tx_pn);
327 aes_tx_sc->pn = cpu_to_le64(pn64);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100328 } else {
Dan Halperinee3ae3a2020-09-26 00:30:48 +0300329 aes_sc =
330 data->rsc_tsc->params.all_tsc_rsc.aes.multicast_rsc;
Nathan Errera2a42aea2020-09-30 16:31:17 +0300331 data->kek_kck_cmd->gtk_cipher =
332 key->cipher == WLAN_CIPHER_SUITE_CCMP ?
333 cpu_to_le32(STA_KEY_FLG_CCM) :
334 cpu_to_le32(STA_KEY_FLG_GCMP);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100335 }
336
337 /*
338 * For non-QoS this relies on the fact that both the uCode and
Johannes Bergf5e28ea2015-12-06 14:58:08 +0200339 * mac80211/our RX code use TID 0 for checking the PN.
Johannes Berg8ca151b2013-01-24 14:25:36 +0100340 */
Johannes Bergf5e28ea2015-12-06 14:58:08 +0200341 if (sta && iwl_mvm_has_new_rx_api(mvm)) {
342 struct iwl_mvm_sta *mvmsta;
343 struct iwl_mvm_key_pn *ptk_pn;
344 const u8 *pn;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100345
Johannes Bergf5e28ea2015-12-06 14:58:08 +0200346 mvmsta = iwl_mvm_sta_from_mac80211(sta);
Sara Sharonefa40c72020-10-08 18:12:42 +0300347 rcu_read_lock();
348 ptk_pn = rcu_dereference(mvmsta->ptk_pn[key->keyidx]);
349 if (WARN_ON(!ptk_pn)) {
350 rcu_read_unlock();
Johannes Bergf5e28ea2015-12-06 14:58:08 +0200351 break;
Sara Sharonefa40c72020-10-08 18:12:42 +0300352 }
Johannes Bergf5e28ea2015-12-06 14:58:08 +0200353
354 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
355 pn = iwl_mvm_find_max_pn(key, ptk_pn, &seq, i,
356 mvm->trans->num_rx_queues);
357 aes_sc[i].pn = cpu_to_le64((u64)pn[5] |
358 ((u64)pn[4] << 8) |
359 ((u64)pn[3] << 16) |
360 ((u64)pn[2] << 24) |
361 ((u64)pn[1] << 32) |
362 ((u64)pn[0] << 40));
363 }
Sara Sharonefa40c72020-10-08 18:12:42 +0300364
365 rcu_read_unlock();
Johannes Bergf5e28ea2015-12-06 14:58:08 +0200366 } else {
367 for (i = 0; i < IWL_NUM_RSC; i++) {
368 u8 *pn = seq.ccmp.pn;
369
370 ieee80211_get_key_rx_seq(key, i, &seq);
371 aes_sc[i].pn = cpu_to_le64((u64)pn[5] |
372 ((u64)pn[4] << 8) |
373 ((u64)pn[3] << 16) |
374 ((u64)pn[2] << 24) |
375 ((u64)pn[1] << 32) |
376 ((u64)pn[0] << 40));
377 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100378 }
379 data->use_rsc_tsc = true;
380 break;
381 }
382
Sara Sharon19d9fa72020-09-30 16:31:20 +0300383 IWL_DEBUG_WOWLAN(mvm, "GTK cipher %d\n", data->kek_kck_cmd->gtk_cipher);
384
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200385 if (data->configure_keys) {
386 mutex_lock(&mvm->mutex);
Johannes Berg5312e542013-07-22 18:26:56 +0200387 /*
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200388 * The D3 firmware hardcodes the key offset 0 as the key it
389 * uses to transmit packets to the AP, i.e. the PTK.
Johannes Berg5312e542013-07-22 18:26:56 +0200390 */
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200391 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
392 mvm->ptk_ivlen = key->iv_len;
393 mvm->ptk_icvlen = key->icv_len;
394 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, 0);
395 } else {
396 /*
397 * firmware only supports TSC/RSC for a single key,
398 * so if there are multiple keep overwriting them
399 * with new ones -- this relies on mac80211 doing
400 * list_add_tail().
401 */
402 mvm->gtk_ivlen = key->iv_len;
403 mvm->gtk_icvlen = key->icv_len;
404 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, 1);
405 }
406 mutex_unlock(&mvm->mutex);
407 data->error = ret != 0;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100408 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100409}
410
Luca Coelho0c546fb2019-03-12 16:01:24 +0200411static int iwl_mvm_send_patterns_v1(struct iwl_mvm *mvm,
412 struct cfg80211_wowlan *wowlan)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100413{
Luca Coelho0c546fb2019-03-12 16:01:24 +0200414 struct iwl_wowlan_patterns_cmd_v1 *pattern_cmd;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100415 struct iwl_host_cmd cmd = {
416 .id = WOWLAN_PATTERNS,
417 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100418 };
419 int i, err;
420
421 if (!wowlan->n_patterns)
422 return 0;
423
Gustavo A. R. Silvae3448962019-04-03 11:03:42 -0500424 cmd.len[0] = struct_size(pattern_cmd, patterns, wowlan->n_patterns);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100425
426 pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
427 if (!pattern_cmd)
428 return -ENOMEM;
429
430 pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
431
432 for (i = 0; i < wowlan->n_patterns; i++) {
433 int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
434
435 memcpy(&pattern_cmd->patterns[i].mask,
436 wowlan->patterns[i].mask, mask_len);
437 memcpy(&pattern_cmd->patterns[i].pattern,
438 wowlan->patterns[i].pattern,
439 wowlan->patterns[i].pattern_len);
440 pattern_cmd->patterns[i].mask_size = mask_len;
441 pattern_cmd->patterns[i].pattern_size =
442 wowlan->patterns[i].pattern_len;
443 }
444
445 cmd.data[0] = pattern_cmd;
446 err = iwl_mvm_send_cmd(mvm, &cmd);
447 kfree(pattern_cmd);
448 return err;
449}
450
Luca Coelho0c546fb2019-03-12 16:01:24 +0200451static int iwl_mvm_send_patterns(struct iwl_mvm *mvm,
452 struct cfg80211_wowlan *wowlan)
453{
454 struct iwl_wowlan_patterns_cmd *pattern_cmd;
455 struct iwl_host_cmd cmd = {
456 .id = WOWLAN_PATTERNS,
457 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
458 };
459 int i, err;
460
461 if (!wowlan->n_patterns)
462 return 0;
463
464 cmd.len[0] = sizeof(*pattern_cmd) +
465 wowlan->n_patterns * sizeof(struct iwl_wowlan_pattern_v2);
466
467 pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
468 if (!pattern_cmd)
469 return -ENOMEM;
470
471 pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
472
473 for (i = 0; i < wowlan->n_patterns; i++) {
474 int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
475
476 pattern_cmd->patterns[i].pattern_type =
477 WOWLAN_PATTERN_TYPE_BITMASK;
478
479 memcpy(&pattern_cmd->patterns[i].u.bitmask.mask,
480 wowlan->patterns[i].mask, mask_len);
481 memcpy(&pattern_cmd->patterns[i].u.bitmask.pattern,
482 wowlan->patterns[i].pattern,
483 wowlan->patterns[i].pattern_len);
484 pattern_cmd->patterns[i].u.bitmask.mask_size = mask_len;
485 pattern_cmd->patterns[i].u.bitmask.pattern_size =
486 wowlan->patterns[i].pattern_len;
487 }
488
489 cmd.data[0] = pattern_cmd;
490 err = iwl_mvm_send_cmd(mvm, &cmd);
491 kfree(pattern_cmd);
492 return err;
493}
494
Johannes Berg8ca151b2013-01-24 14:25:36 +0100495static int iwl_mvm_d3_reprogram(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
496 struct ieee80211_sta *ap_sta)
497{
498 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
499 struct ieee80211_chanctx_conf *ctx;
500 u8 chains_static, chains_dynamic;
501 struct cfg80211_chan_def chandef;
502 int ret, i;
Dreyfuss, Haim10a970d2018-05-21 10:36:46 +0300503 struct iwl_binding_cmd_v1 binding_cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100504 struct iwl_time_quota_cmd quota_cmd = {};
David Spinadel72cbb732017-08-30 16:23:14 +0300505 struct iwl_time_quota_data *quota;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100506 u32 status;
Sara Sharon9415af72016-11-17 13:57:32 +0200507
Dreyfuss, Haim10a970d2018-05-21 10:36:46 +0300508 if (WARN_ON_ONCE(iwl_mvm_is_cdb_supported(mvm)))
509 return -EINVAL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100510
511 /* add back the PHY */
512 if (WARN_ON(!mvmvif->phy_ctxt))
513 return -EINVAL;
514
515 rcu_read_lock();
516 ctx = rcu_dereference(vif->chanctx_conf);
517 if (WARN_ON(!ctx)) {
518 rcu_read_unlock();
519 return -EINVAL;
520 }
521 chandef = ctx->def;
522 chains_static = ctx->rx_chains_static;
523 chains_dynamic = ctx->rx_chains_dynamic;
524 rcu_read_unlock();
525
526 ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt, &chandef,
527 chains_static, chains_dynamic);
528 if (ret)
529 return ret;
530
531 /* add back the MAC */
532 mvmvif->uploaded = false;
533
534 if (WARN_ON(!vif->bss_conf.assoc))
535 return -EINVAL;
Luciano Coelhobca49d92014-05-13 17:33:38 +0300536
Johannes Berg8ca151b2013-01-24 14:25:36 +0100537 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100538 if (ret)
539 return ret;
540
541 /* add back binding - XXX refactor? */
542 binding_cmd.id_and_color =
543 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
544 mvmvif->phy_ctxt->color));
545 binding_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
546 binding_cmd.phy =
547 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
548 mvmvif->phy_ctxt->color));
549 binding_cmd.macs[0] = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
550 mvmvif->color));
551 for (i = 1; i < MAX_MACS_IN_BINDING; i++)
552 binding_cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID);
553
554 status = 0;
555 ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD,
Dreyfuss, Haim10a970d2018-05-21 10:36:46 +0300556 IWL_BINDING_CMD_SIZE_V1, &binding_cmd,
557 &status);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100558 if (ret) {
559 IWL_ERR(mvm, "Failed to add binding: %d\n", ret);
560 return ret;
561 }
562
563 if (status) {
564 IWL_ERR(mvm, "Binding command failed: %u\n", status);
565 return -EIO;
566 }
567
Liad Kaufman24afba72015-07-28 18:56:08 +0300568 ret = iwl_mvm_sta_send_to_fw(mvm, ap_sta, false, 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100569 if (ret)
570 return ret;
571 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], ap_sta);
572
Johannes Berg3dfd3a92014-08-11 21:37:30 +0200573 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100574 if (ret)
575 return ret;
576
577 /* and some quota */
David Spinadel72cbb732017-08-30 16:23:14 +0300578 quota = iwl_mvm_quota_cmd_get_quota(mvm, &quota_cmd, 0);
579 quota->id_and_color =
Johannes Berg8ca151b2013-01-24 14:25:36 +0100580 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
581 mvmvif->phy_ctxt->color));
David Spinadel72cbb732017-08-30 16:23:14 +0300582 quota->quota = cpu_to_le32(IWL_MVM_MAX_QUOTA);
583 quota->max_duration = cpu_to_le32(IWL_MVM_MAX_QUOTA);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100584
David Spinadel72cbb732017-08-30 16:23:14 +0300585 for (i = 1; i < MAX_BINDINGS; i++) {
586 quota = iwl_mvm_quota_cmd_get_quota(mvm, &quota_cmd, i);
587 quota->id_and_color = cpu_to_le32(FW_CTXT_INVALID);
588 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100589
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300590 ret = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, 0,
David Spinadel72cbb732017-08-30 16:23:14 +0300591 iwl_mvm_quota_cmd_size(mvm), &quota_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100592 if (ret)
593 IWL_ERR(mvm, "Failed to send quota: %d\n", ret);
594
Jonathan Doron47c8b152014-11-27 16:55:25 +0200595 if (iwl_mvm_is_lar_supported(mvm) && iwl_mvm_init_fw_regd(mvm))
596 IWL_ERR(mvm, "Failed to initialize D3 LAR information\n");
597
Johannes Berg8ca151b2013-01-24 14:25:36 +0100598 return 0;
599}
600
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200601static int iwl_mvm_get_last_nonqos_seq(struct iwl_mvm *mvm,
602 struct ieee80211_vif *vif)
603{
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200604 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
605 struct iwl_nonqos_seq_query_cmd query_cmd = {
606 .get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_GET),
607 .mac_id_n_color =
608 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
609 mvmvif->color)),
610 };
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200611 struct iwl_host_cmd cmd = {
612 .id = NON_QOS_TX_COUNTER_CMD,
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300613 .flags = CMD_WANT_SKB,
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200614 };
615 int err;
616 u32 size;
617
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +0300618 cmd.data[0] = &query_cmd;
619 cmd.len[0] = sizeof(query_cmd);
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200620
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200621 err = iwl_mvm_send_cmd(mvm, &cmd);
622 if (err)
623 return err;
624
Johannes Berg65b30342014-01-08 13:16:33 +0100625 size = iwl_rx_packet_payload_len(cmd.resp_pkt);
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200626 if (size < sizeof(__le16)) {
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200627 err = -EINVAL;
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200628 } else {
629 err = le16_to_cpup((__le16 *)cmd.resp_pkt->data);
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +0300630 /* firmware returns next, not last-used seqno */
631 err = (u16) (err - 0x10);
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200632 }
Johannes Berg4ac6cb52013-08-08 09:30:13 +0200633
634 iwl_free_resp(&cmd);
635 return err;
636}
637
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200638void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
639{
640 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
641 struct iwl_nonqos_seq_query_cmd query_cmd = {
642 .get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_SET),
643 .mac_id_n_color =
644 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
645 mvmvif->color)),
646 .value = cpu_to_le16(mvmvif->seqno),
647 };
648
649 /* return if called during restart, not resume from D3 */
650 if (!mvmvif->seqno_valid)
651 return;
652
653 mvmvif->seqno_valid = false;
654
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300655 if (iwl_mvm_send_cmd_pdu(mvm, NON_QOS_TX_COUNTER_CMD, 0,
Johannes Berg6d9d32b2013-08-06 18:58:56 +0200656 sizeof(query_cmd), &query_cmd))
657 IWL_ERR(mvm, "failed to set non-QoS seqno\n");
658}
659
Luciano Coelho671b5822014-09-22 10:59:53 +0300660static int iwl_mvm_switch_to_d3(struct iwl_mvm *mvm)
Eliad Peller1a95c8d2013-11-21 19:19:52 +0200661{
Luciano Coelhoc7d42482015-05-07 16:00:26 +0300662 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100663
Chaya Rachel Ivgifcb6b922016-02-22 10:21:41 +0200664 iwl_mvm_stop_device(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100665 /*
666 * Set the HW restart bit -- this is mostly true as we're
667 * going to load new firmware and reprogram that, though
668 * the reprogramming is going to be manual to avoid adding
669 * all the MACs that aren't support.
670 * We don't have to clear up everything though because the
671 * reprogramming is manual. When we resume, we'll actually
672 * go through a proper restart sequence again to switch
673 * back to the runtime firmware image.
674 */
675 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
676
Luca Coelho9c3deeb2015-11-11 01:06:17 +0200677 /* the fw is reset, so all the keys are cleared */
678 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
679
Johannes Bergf444eb12013-02-26 12:04:18 +0100680 mvm->ptk_ivlen = 0;
681 mvm->ptk_icvlen = 0;
682 mvm->ptk_ivlen = 0;
683 mvm->ptk_icvlen = 0;
684
Luciano Coelho671b5822014-09-22 10:59:53 +0300685 return iwl_mvm_load_d3_fw(mvm);
686}
687
688static int
Luciano Coelho671b5822014-09-22 10:59:53 +0300689iwl_mvm_get_wowlan_config(struct iwl_mvm *mvm,
690 struct cfg80211_wowlan *wowlan,
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200691 struct iwl_wowlan_config_cmd *wowlan_config_cmd,
Luciano Coelho671b5822014-09-22 10:59:53 +0300692 struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif,
693 struct ieee80211_sta *ap_sta)
694{
695 int ret;
Johannes Berg9d8ce6a2014-12-23 16:02:40 +0100696 struct iwl_mvm_sta *mvm_ap_sta = iwl_mvm_sta_from_mac80211(ap_sta);
Luciano Coelho671b5822014-09-22 10:59:53 +0300697
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200698 /* TODO: wowlan_config_cmd->wowlan_ba_teardown_tids */
Luciano Coelho671b5822014-09-22 10:59:53 +0300699
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200700 wowlan_config_cmd->is_11n_connection =
Luciano Coelho671b5822014-09-22 10:59:53 +0300701 ap_sta->ht_cap.ht_supported;
Sara Sharon70b4c532015-11-19 13:12:15 +0200702 wowlan_config_cmd->flags = ENABLE_L3_FILTERING |
Matti Gottlieb32795a82016-02-25 10:18:34 +0200703 ENABLE_NBNS_FILTERING | ENABLE_DHCP_FILTERING;
Luciano Coelho671b5822014-09-22 10:59:53 +0300704
705 /* Query the last used seqno and set it */
706 ret = iwl_mvm_get_last_nonqos_seq(mvm, vif);
707 if (ret < 0)
708 return ret;
709
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200710 wowlan_config_cmd->non_qos_seq = cpu_to_le16(ret);
Luciano Coelho671b5822014-09-22 10:59:53 +0300711
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200712 iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, wowlan_config_cmd);
Luciano Coelho671b5822014-09-22 10:59:53 +0300713
714 if (wowlan->disconnect)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200715 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300716 cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS |
717 IWL_WOWLAN_WAKEUP_LINK_CHANGE);
718 if (wowlan->magic_pkt)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200719 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300720 cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET);
721 if (wowlan->gtk_rekey_failure)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200722 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300723 cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL);
724 if (wowlan->eap_identity_req)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200725 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300726 cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ);
727 if (wowlan->four_way_handshake)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200728 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300729 cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE);
730 if (wowlan->n_patterns)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200731 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300732 cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH);
733
734 if (wowlan->rfkill_release)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200735 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300736 cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT);
737
738 if (wowlan->tcp) {
739 /*
740 * Set the "link change" (really "link lost") flag as well
741 * since that implies losing the TCP connection.
742 */
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200743 wowlan_config_cmd->wakeup_filter |=
Luciano Coelho671b5822014-09-22 10:59:53 +0300744 cpu_to_le32(IWL_WOWLAN_WAKEUP_REMOTE_LINK_LOSS |
745 IWL_WOWLAN_WAKEUP_REMOTE_SIGNATURE_TABLE |
746 IWL_WOWLAN_WAKEUP_REMOTE_WAKEUP_PACKET |
747 IWL_WOWLAN_WAKEUP_LINK_CHANGE);
748 }
749
Eliad Pellerd3a6f7f2018-02-22 18:45:49 +0200750 if (wowlan->any) {
751 wowlan_config_cmd->wakeup_filter |=
752 cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS |
753 IWL_WOWLAN_WAKEUP_LINK_CHANGE |
754 IWL_WOWLAN_WAKEUP_RX_FRAME |
755 IWL_WOWLAN_WAKEUP_BCN_FILTERING);
756 }
757
Luciano Coelho671b5822014-09-22 10:59:53 +0300758 return 0;
759}
760
Emmanuel Grumbach0ea93382019-06-06 10:58:46 +0300761static int iwl_mvm_wowlan_config_key_params(struct iwl_mvm *mvm,
762 struct ieee80211_vif *vif,
763 u32 cmd_flags)
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200764{
Nathan Errera9e3c3932020-09-28 12:23:15 +0300765 struct iwl_wowlan_kek_kck_material_cmd_v3 kek_kck_cmd = {};
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200766 struct iwl_wowlan_tkip_params_cmd tkip_cmd = {};
Sara Sharon8c7fd6a2018-07-01 14:52:06 +0300767 bool unified = fw_has_capa(&mvm->fw->ucode_capa,
768 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200769 struct wowlan_key_data key_data = {
Emmanuel Grumbach0ea93382019-06-06 10:58:46 +0300770 .configure_keys = !unified,
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200771 .use_rsc_tsc = false,
772 .tkip = &tkip_cmd,
773 .use_tkip = false,
Nathan Errera2a42aea2020-09-30 16:31:17 +0300774 .kek_kck_cmd = &kek_kck_cmd,
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200775 };
776 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
777 int ret;
Nathan Errera9e3c3932020-09-28 12:23:15 +0300778 u8 cmd_ver;
779 size_t cmd_size;
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200780
781 key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
782 if (!key_data.rsc_tsc)
783 return -ENOMEM;
784
785 /*
Eliad Pellera3f7ba52015-11-11 17:23:59 +0200786 * if we have to configure keys, call ieee80211_iter_keys(),
787 * as we need non-atomic context in order to take the
788 * required locks.
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200789 */
Emmanuel Grumbach0ea93382019-06-06 10:58:46 +0300790 /*
791 * Note that currently we don't propagate cmd_flags
792 * to the iterator. In case of key_data.configure_keys,
793 * all the configured commands are SYNC, and
794 * iwl_mvm_wowlan_program_keys() will take care of
795 * locking/unlocking mvm->mutex.
796 */
797 ieee80211_iter_keys(mvm->hw, vif, iwl_mvm_wowlan_program_keys,
798 &key_data);
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200799
800 if (key_data.error) {
801 ret = -EIO;
802 goto out;
803 }
804
805 if (key_data.use_rsc_tsc) {
Dan Halperinee3ae3a2020-09-26 00:30:48 +0300806 int ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
Mordechay Goodsteine80bfd12020-09-28 12:23:18 +0300807 WOWLAN_TSC_RSC_PARAM,
808 IWL_FW_CMD_VER_UNKNOWN);
Dan Halperinee3ae3a2020-09-26 00:30:48 +0300809 int size;
810
811 if (ver == 4) {
812 size = sizeof(*key_data.rsc_tsc);
813 key_data.rsc_tsc->sta_id =
814 cpu_to_le32(mvmvif->ap_sta_id);
815
816 } else if (ver == 2 || ver == IWL_FW_CMD_VER_UNKNOWN) {
817 size = sizeof(key_data.rsc_tsc->params);
818 } else {
819 ret = 0;
820 WARN_ON_ONCE(1);
821 goto out;
822 }
823
824 ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_TSC_RSC_PARAM,
825 cmd_flags,
826 size,
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200827 key_data.rsc_tsc);
Dan Halperinee3ae3a2020-09-26 00:30:48 +0300828
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200829 if (ret)
830 goto out;
831 }
832
Sara Sharon45c458b2016-11-09 15:43:26 +0200833 if (key_data.use_tkip &&
834 !fw_has_api(&mvm->fw->ucode_capa,
835 IWL_UCODE_TLV_API_TKIP_MIC_KEYS)) {
Dan Halperin870bde72020-09-26 00:30:45 +0300836 int ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
Mordechay Goodsteine80bfd12020-09-28 12:23:18 +0300837 WOWLAN_TKIP_PARAM,
838 IWL_FW_CMD_VER_UNKNOWN);
Dan Halperin870bde72020-09-26 00:30:45 +0300839 int size;
840
841 if (ver == 2) {
842 size = sizeof(tkip_cmd);
843 key_data.tkip->sta_id =
844 cpu_to_le32(mvmvif->ap_sta_id);
845 } else if (ver == 1 || ver == IWL_FW_CMD_VER_UNKNOWN) {
846 size = sizeof(struct iwl_wowlan_tkip_params_cmd_ver_1);
847 } else {
848 ret = -EINVAL;
849 WARN_ON_ONCE(1);
850 goto out;
851 }
852
853 /* send relevant data according to CMD version */
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200854 ret = iwl_mvm_send_cmd_pdu(mvm,
855 WOWLAN_TKIP_PARAM,
Dan Halperin870bde72020-09-26 00:30:45 +0300856 cmd_flags, size,
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200857 &tkip_cmd);
858 if (ret)
859 goto out;
860 }
861
Eliad Pellera3f7ba52015-11-11 17:23:59 +0200862 /* configure rekey data only if offloaded rekey is supported (d3) */
Emmanuel Grumbach0ea93382019-06-06 10:58:46 +0300863 if (mvmvif->rekey_data.valid) {
Mordechay Goodsteine80bfd12020-09-28 12:23:18 +0300864 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw,
865 IWL_ALWAYS_LONG_GROUP,
866 WOWLAN_KEK_KCK_MATERIAL,
867 IWL_FW_CMD_VER_UNKNOWN);
Nathan Errera9e3c3932020-09-28 12:23:15 +0300868 if (WARN_ON(cmd_ver != 2 && cmd_ver != 3 &&
869 cmd_ver != IWL_FW_CMD_VER_UNKNOWN))
870 return -EINVAL;
871 if (cmd_ver == 3)
872 cmd_size = sizeof(struct iwl_wowlan_kek_kck_material_cmd_v3);
873 else
874 cmd_size = sizeof(struct iwl_wowlan_kek_kck_material_cmd_v2);
875
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200876 memcpy(kek_kck_cmd.kck, mvmvif->rekey_data.kck,
Nathan Errera2a42aea2020-09-30 16:31:17 +0300877 mvmvif->rekey_data.kck_len);
878 kek_kck_cmd.kck_len = cpu_to_le16(mvmvif->rekey_data.kck_len);
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200879 memcpy(kek_kck_cmd.kek, mvmvif->rekey_data.kek,
Nathan Errera2a42aea2020-09-30 16:31:17 +0300880 mvmvif->rekey_data.kek_len);
881 kek_kck_cmd.kek_len = cpu_to_le16(mvmvif->rekey_data.kek_len);
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200882 kek_kck_cmd.replay_ctr = mvmvif->rekey_data.replay_ctr;
Nathan Errera2a42aea2020-09-30 16:31:17 +0300883 kek_kck_cmd.akm = cpu_to_le32(mvmvif->rekey_data.akm);
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200884
Sara Sharon19d9fa72020-09-30 16:31:20 +0300885 IWL_DEBUG_WOWLAN(mvm, "setting akm %d\n",
886 mvmvif->rekey_data.akm);
887
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200888 ret = iwl_mvm_send_cmd_pdu(mvm,
889 WOWLAN_KEK_KCK_MATERIAL, cmd_flags,
Nathan Errera9e3c3932020-09-28 12:23:15 +0300890 cmd_size,
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200891 &kek_kck_cmd);
892 if (ret)
893 goto out;
894 }
Eliad Peller3f50a692015-11-15 15:44:17 +0200895 ret = 0;
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200896out:
897 kfree(key_data.rsc_tsc);
898 return ret;
899}
900
Luciano Coelho671b5822014-09-22 10:59:53 +0300901static int
902iwl_mvm_wowlan_config(struct iwl_mvm *mvm,
903 struct cfg80211_wowlan *wowlan,
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200904 struct iwl_wowlan_config_cmd *wowlan_config_cmd,
Luciano Coelho671b5822014-09-22 10:59:53 +0300905 struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif,
906 struct ieee80211_sta *ap_sta)
907{
Luciano Coelho671b5822014-09-22 10:59:53 +0300908 int ret;
Matti Gottlieb23ae6122015-12-31 18:18:02 +0200909 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
910 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100911
Alex Malamudba7136f2019-06-10 15:19:23 +0300912 mvm->offload_tid = wowlan_config_cmd->offloading_tid;
913
Matti Gottlieb23ae6122015-12-31 18:18:02 +0200914 if (!unified_image) {
915 ret = iwl_mvm_switch_to_d3(mvm);
916 if (ret)
917 return ret;
Luciano Coelho3acc9522014-11-19 22:35:37 +0200918
Matti Gottlieb23ae6122015-12-31 18:18:02 +0200919 ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta);
920 if (ret)
921 return ret;
922 }
Luciano Coelho671b5822014-09-22 10:59:53 +0300923
Emmanuel Grumbachf4bfdc52020-04-24 18:48:13 +0300924 /*
925 * This needs to be unlocked due to lock ordering
926 * constraints. Since we're in the suspend path
927 * that isn't really a problem though.
928 */
929 mutex_unlock(&mvm->mutex);
930 ret = iwl_mvm_wowlan_config_key_params(mvm, vif, CMD_ASYNC);
931 mutex_lock(&mvm->mutex);
932 if (ret)
933 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100934
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200935 ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0,
936 sizeof(*wowlan_config_cmd),
937 wowlan_config_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100938 if (ret)
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200939 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100940
Luca Coelho0c546fb2019-03-12 16:01:24 +0200941 if (fw_has_api(&mvm->fw->ucode_capa,
942 IWL_UCODE_TLV_API_WOWLAN_TCP_SYN_WAKE))
943 ret = iwl_mvm_send_patterns(mvm, wowlan);
944 else
945 ret = iwl_mvm_send_patterns_v1(mvm, wowlan);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100946 if (ret)
Eliad Pellerac8ef0c2015-11-12 10:49:38 +0200947 return ret;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100948
Johannes Bergdebdc232017-10-26 22:57:57 +0200949 return iwl_mvm_send_proto_offload(mvm, vif, false, true, 0);
Luciano Coelho671b5822014-09-22 10:59:53 +0300950}
951
Luciano Coelho3acc9522014-11-19 22:35:37 +0200952static int
953iwl_mvm_netdetect_config(struct iwl_mvm *mvm,
954 struct cfg80211_wowlan *wowlan,
955 struct cfg80211_sched_scan_request *nd_config,
956 struct ieee80211_vif *vif)
957{
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200958 struct iwl_wowlan_config_cmd wowlan_config_cmd = {};
Luciano Coelho3acc9522014-11-19 22:35:37 +0200959 int ret;
Matti Gottlieb23ae6122015-12-31 18:18:02 +0200960 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
961 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
Luciano Coelho3acc9522014-11-19 22:35:37 +0200962
Matti Gottlieb23ae6122015-12-31 18:18:02 +0200963 if (!unified_image) {
964 ret = iwl_mvm_switch_to_d3(mvm);
965 if (ret)
966 return ret;
Luca Coelho5a143db2016-10-05 09:28:53 +0300967 } else {
968 /* In theory, we wouldn't have to stop a running sched
969 * scan in order to start another one (for
970 * net-detect). But in practice this doesn't seem to
971 * work properly, so stop any running sched_scan now.
972 */
973 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
974 if (ret)
975 return ret;
Matti Gottlieb23ae6122015-12-31 18:18:02 +0200976 }
Luciano Coelho3acc9522014-11-19 22:35:37 +0200977
978 /* rfkill release can be either for wowlan or netdetect */
979 if (wowlan->rfkill_release)
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200980 wowlan_config_cmd.wakeup_filter |=
Luciano Coelho3acc9522014-11-19 22:35:37 +0200981 cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT);
982
Haim Dreyfussf005fd82019-07-16 12:44:40 +0300983 wowlan_config_cmd.sta_id = mvm->aux_sta.sta_id;
984
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +0200985 ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0,
986 sizeof(wowlan_config_cmd),
987 &wowlan_config_cmd);
Luciano Coelho3acc9522014-11-19 22:35:37 +0200988 if (ret)
989 return ret;
990
Luciano Coelho19945df2015-03-20 16:11:28 +0200991 ret = iwl_mvm_sched_scan_start(mvm, vif, nd_config, &mvm->nd_ies,
992 IWL_MVM_SCAN_NETDETECT);
Luciano Coelhod9718da2014-11-21 09:32:23 +0200993 if (ret)
994 return ret;
Luciano Coelho3acc9522014-11-19 22:35:37 +0200995
Luciano Coelho8ed4e652014-11-21 22:08:01 +0200996 if (WARN_ON(mvm->nd_match_sets || mvm->nd_channels))
Luciano Coelhod9718da2014-11-21 09:32:23 +0200997 return -EBUSY;
998
Luciano Coelho8ed4e652014-11-21 22:08:01 +0200999 /* save the sched scan matchsets... */
Luciano Coelhod9718da2014-11-21 09:32:23 +02001000 if (nd_config->n_match_sets) {
1001 mvm->nd_match_sets = kmemdup(nd_config->match_sets,
1002 sizeof(*nd_config->match_sets) *
1003 nd_config->n_match_sets,
1004 GFP_KERNEL);
1005 if (mvm->nd_match_sets)
1006 mvm->n_nd_match_sets = nd_config->n_match_sets;
1007 }
1008
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001009 /* ...and the sched scan channels for later reporting */
1010 mvm->nd_channels = kmemdup(nd_config->channels,
1011 sizeof(*nd_config->channels) *
1012 nd_config->n_channels,
1013 GFP_KERNEL);
1014 if (mvm->nd_channels)
1015 mvm->n_nd_channels = nd_config->n_channels;
1016
Luciano Coelhod9718da2014-11-21 09:32:23 +02001017 return 0;
1018}
1019
1020static void iwl_mvm_free_nd(struct iwl_mvm *mvm)
1021{
1022 kfree(mvm->nd_match_sets);
1023 mvm->nd_match_sets = NULL;
1024 mvm->n_nd_match_sets = 0;
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001025 kfree(mvm->nd_channels);
1026 mvm->nd_channels = NULL;
1027 mvm->n_nd_channels = 0;
Luciano Coelho3acc9522014-11-19 22:35:37 +02001028}
1029
Luciano Coelho671b5822014-09-22 10:59:53 +03001030static int __iwl_mvm_suspend(struct ieee80211_hw *hw,
1031 struct cfg80211_wowlan *wowlan,
1032 bool test)
1033{
1034 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luciano Coelho671b5822014-09-22 10:59:53 +03001035 struct ieee80211_vif *vif = NULL;
1036 struct iwl_mvm_vif *mvmvif = NULL;
1037 struct ieee80211_sta *ap_sta = NULL;
Luciano Coelho671b5822014-09-22 10:59:53 +03001038 struct iwl_d3_manager_config d3_cfg_cmd_data = {
1039 /*
1040 * Program the minimum sleep time to 10 seconds, as many
1041 * platforms have issues processing a wakeup signal while
1042 * still being in the process of suspending.
1043 */
1044 .min_sleep_time = cpu_to_le32(10 * 1000 * 1000),
1045 };
1046 struct iwl_host_cmd d3_cfg_cmd = {
1047 .id = D3_CONFIG_CMD,
1048 .flags = CMD_WANT_SKB,
1049 .data[0] = &d3_cfg_cmd_data,
1050 .len[0] = sizeof(d3_cfg_cmd_data),
1051 };
1052 int ret;
1053 int len __maybe_unused;
Matti Gottlieb23ae6122015-12-31 18:18:02 +02001054 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
1055 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
Luciano Coelho671b5822014-09-22 10:59:53 +03001056
1057 if (!wowlan) {
1058 /*
1059 * mac80211 shouldn't get here, but for D3 test
1060 * it doesn't warrant a warning
1061 */
1062 WARN_ON(!test);
1063 return -EINVAL;
1064 }
1065
1066 mutex_lock(&mvm->mutex);
1067
Johannes Berg1019f9e2019-09-30 14:45:54 +02001068 set_bit(IWL_MVM_STATUS_IN_D3, &mvm->status);
1069
Luciano Coelho7f549e22014-10-02 15:38:04 +03001070 vif = iwl_mvm_get_bss_vif(mvm);
1071 if (IS_ERR_OR_NULL(vif)) {
Luciano Coelho671b5822014-09-22 10:59:53 +03001072 ret = 1;
1073 goto out_noreset;
1074 }
1075
Luciano Coelho671b5822014-09-22 10:59:53 +03001076 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1077
Sara Sharon0ae98812017-01-04 14:53:58 +02001078 if (mvmvif->ap_sta_id == IWL_MVM_INVALID_STA) {
Luciano Coelho3acc9522014-11-19 22:35:37 +02001079 /* if we're not associated, this must be netdetect */
Luca Coelho566f1652015-10-25 22:55:32 +02001080 if (!wowlan->nd_config) {
Luciano Coelho3acc9522014-11-19 22:35:37 +02001081 ret = 1;
1082 goto out_noreset;
1083 }
1084
1085 ret = iwl_mvm_netdetect_config(
Luca Coelho566f1652015-10-25 22:55:32 +02001086 mvm, wowlan, wowlan->nd_config, vif);
Luciano Coelho3acc9522014-11-19 22:35:37 +02001087 if (ret)
1088 goto out;
Luciano Coelho2021a892014-11-20 08:59:51 +02001089
1090 mvm->net_detect = true;
Luciano Coelho3acc9522014-11-19 22:35:37 +02001091 } else {
Emmanuel Grumbachc8b06a92014-11-24 09:06:57 +02001092 struct iwl_wowlan_config_cmd wowlan_config_cmd = {};
Luciano Coelho3acc9522014-11-19 22:35:37 +02001093
Haim Dreyfussf005fd82019-07-16 12:44:40 +03001094 wowlan_config_cmd.sta_id = mvmvif->ap_sta_id;
1095
Luciano Coelho1e4d19c2014-09-22 13:01:59 +03001096 ap_sta = rcu_dereference_protected(
1097 mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
1098 lockdep_is_held(&mvm->mutex));
1099 if (IS_ERR_OR_NULL(ap_sta)) {
1100 ret = -EINVAL;
1101 goto out_noreset;
1102 }
1103
1104 ret = iwl_mvm_get_wowlan_config(mvm, wowlan, &wowlan_config_cmd,
1105 vif, mvmvif, ap_sta);
1106 if (ret)
1107 goto out_noreset;
Luciano Coelho1e4d19c2014-09-22 13:01:59 +03001108 ret = iwl_mvm_wowlan_config(mvm, wowlan, &wowlan_config_cmd,
1109 vif, mvmvif, ap_sta);
1110 if (ret)
1111 goto out;
Luciano Coelho2021a892014-11-20 08:59:51 +02001112
1113 mvm->net_detect = false;
Luciano Coelho671b5822014-09-22 10:59:53 +03001114 }
1115
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +02001116 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +03001117 if (ret)
1118 goto out;
1119
Arik Nemtsov999609f2014-05-15 17:31:51 +03001120 ret = iwl_mvm_power_update_mac(mvm);
Alexander Bondaree1e8422013-04-23 13:52:10 +03001121 if (ret)
1122 goto out;
1123
Johannes Bergb0114712013-06-12 14:55:40 +02001124#ifdef CONFIG_IWLWIFI_DEBUGFS
1125 if (mvm->d3_wake_sysassert)
1126 d3_cfg_cmd_data.wakeup_flags |=
1127 cpu_to_le32(IWL_WAKEUP_D3_CONFIG_FW_ERROR);
1128#endif
1129
Luca Coelhoe8a583f2018-03-07 18:46:01 +02001130 /*
Shahar S Matityahuc040fe82019-05-19 10:16:13 +03001131 * Prior to 9000 device family the driver needs to stop the dbg
1132 * recording before entering D3. In later devices the FW stops the
1133 * recording automatically.
Luca Coelhoe8a583f2018-03-07 18:46:01 +02001134 */
Luca Coelho286ca8e2019-07-12 15:03:48 +03001135 if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_9000)
Shahar S Matityahu57605832019-05-19 10:52:59 +03001136 iwl_fw_dbg_stop_restart_recording(&mvm->fwrt, NULL, true);
Luca Coelhoe8a583f2018-03-07 18:46:01 +02001137
Johannes Berg8ca151b2013-01-24 14:25:36 +01001138 /* must be last -- this switches firmware state */
Johannes Bergdebff612013-05-14 13:53:45 +02001139 ret = iwl_mvm_send_cmd(mvm, &d3_cfg_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001140 if (ret)
1141 goto out;
Johannes Bergdebff612013-05-14 13:53:45 +02001142#ifdef CONFIG_IWLWIFI_DEBUGFS
Johannes Berg65b30342014-01-08 13:16:33 +01001143 len = iwl_rx_packet_payload_len(d3_cfg_cmd.resp_pkt);
1144 if (len >= sizeof(u32)) {
Johannes Bergdebff612013-05-14 13:53:45 +02001145 mvm->d3_test_pme_ptr =
1146 le32_to_cpup((__le32 *)d3_cfg_cmd.resp_pkt->data);
Johannes Bergdebff612013-05-14 13:53:45 +02001147 }
1148#endif
1149 iwl_free_resp(&d3_cfg_cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001150
1151 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1152
Haim Dreyfusse5f3f212019-04-03 14:37:54 +03001153 ret = iwl_trans_d3_suspend(mvm->trans, test, !unified_image);
Johannes Berg8ca151b2013-01-24 14:25:36 +01001154 out:
Luciano Coelhod9718da2014-11-21 09:32:23 +02001155 if (ret < 0) {
Luciano Coelhod9718da2014-11-21 09:32:23 +02001156 iwl_mvm_free_nd(mvm);
Luca Coelhobac453a2016-10-07 15:16:26 +03001157
1158 if (!unified_image) {
Johannes Berg3b37f4c2017-05-30 16:45:31 +02001159 if (mvm->fw_restart > 0) {
1160 mvm->fw_restart--;
Luca Coelhobac453a2016-10-07 15:16:26 +03001161 ieee80211_restart_hw(mvm->hw);
1162 }
1163 }
Johannes Berg1019f9e2019-09-30 14:45:54 +02001164
1165 clear_bit(IWL_MVM_STATUS_IN_D3, &mvm->status);
Luciano Coelhod9718da2014-11-21 09:32:23 +02001166 }
Luciano Coelhob70ab722013-11-19 22:53:41 +02001167 out_noreset:
Johannes Berg8ca151b2013-01-24 14:25:36 +01001168 mutex_unlock(&mvm->mutex);
1169
1170 return ret;
1171}
1172
Johannes Bergdebff612013-05-14 13:53:45 +02001173int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
1174{
Eliad Pellerd15a7472014-03-27 18:53:12 +02001175 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luca Coelhob7282642015-09-17 23:44:14 +03001176 struct iwl_trans *trans = mvm->trans;
Eliad Pellerc43fe902015-06-04 21:59:32 +03001177 int ret;
Eliad Pellerd15a7472014-03-27 18:53:12 +02001178
Luca Coelho7d9d0d52018-04-12 16:15:07 +03001179 iwl_mvm_pause_tcm(mvm, true);
Luciano Coelhocf8c3cf2015-08-24 14:53:25 +03001180
Haim Dreyfuss7f8ae002017-12-27 15:21:18 +02001181 iwl_fw_runtime_suspend(&mvm->fwrt);
1182
Luca Coelhob7282642015-09-17 23:44:14 +03001183 ret = iwl_trans_suspend(trans);
Eliad Pellerc43fe902015-06-04 21:59:32 +03001184 if (ret)
1185 return ret;
1186
Luca Coelhob7282642015-09-17 23:44:14 +03001187 trans->system_pm_mode = IWL_PLAT_PM_MODE_D3;
1188
Johannes Bergdebff612013-05-14 13:53:45 +02001189 return __iwl_mvm_suspend(hw, wowlan, false);
1190}
1191
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001192/* converted data from the different status responses */
1193struct iwl_wowlan_status_data {
1194 u16 pattern_number;
1195 u16 qos_seq_ctr[8];
1196 u32 wakeup_reasons;
1197 u32 wake_packet_length;
1198 u32 wake_packet_bufsize;
1199 const u8 *wake_packet;
1200};
1201
Johannes Berg7abc4632013-08-06 18:28:26 +02001202static void iwl_mvm_report_wakeup_reasons(struct iwl_mvm *mvm,
1203 struct ieee80211_vif *vif,
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001204 struct iwl_wowlan_status_data *status)
Johannes Berg9b26b502013-01-22 13:02:09 +01001205{
Johannes Berg7abc4632013-08-06 18:28:26 +02001206 struct sk_buff *pkt = NULL;
Johannes Berg9b26b502013-01-22 13:02:09 +01001207 struct cfg80211_wowlan_wakeup wakeup = {
1208 .pattern_idx = -1,
1209 };
1210 struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001211 u32 reasons = status->wakeup_reasons;
Johannes Berg9b26b502013-01-22 13:02:09 +01001212
1213 if (reasons == IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) {
1214 wakeup_report = NULL;
1215 goto report;
1216 }
1217
Derek Basehore06ae2ad2015-11-04 17:37:52 -08001218 pm_wakeup_event(mvm->dev, 0);
1219
Johannes Bergf444eb12013-02-26 12:04:18 +01001220 if (reasons & IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET)
Johannes Berg9b26b502013-01-22 13:02:09 +01001221 wakeup.magic_pkt = true;
Johannes Berg9b26b502013-01-22 13:02:09 +01001222
Johannes Bergf444eb12013-02-26 12:04:18 +01001223 if (reasons & IWL_WOWLAN_WAKEUP_BY_PATTERN)
Johannes Berg9b26b502013-01-22 13:02:09 +01001224 wakeup.pattern_idx =
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001225 status->pattern_number;
Johannes Berg9b26b502013-01-22 13:02:09 +01001226
1227 if (reasons & (IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON |
1228 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH))
1229 wakeup.disconnect = true;
1230
Johannes Bergf444eb12013-02-26 12:04:18 +01001231 if (reasons & IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE)
Johannes Berg9b26b502013-01-22 13:02:09 +01001232 wakeup.gtk_rekey_failure = true;
Johannes Berg9b26b502013-01-22 13:02:09 +01001233
Johannes Bergf444eb12013-02-26 12:04:18 +01001234 if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED)
Johannes Berg9b26b502013-01-22 13:02:09 +01001235 wakeup.rfkill_release = true;
Johannes Berg9b26b502013-01-22 13:02:09 +01001236
Johannes Bergf444eb12013-02-26 12:04:18 +01001237 if (reasons & IWL_WOWLAN_WAKEUP_BY_EAPOL_REQUEST)
Johannes Berg9b26b502013-01-22 13:02:09 +01001238 wakeup.eap_identity_req = true;
Johannes Berg9b26b502013-01-22 13:02:09 +01001239
Johannes Bergf444eb12013-02-26 12:04:18 +01001240 if (reasons & IWL_WOWLAN_WAKEUP_BY_FOUR_WAY_HANDSHAKE)
Johannes Berg9b26b502013-01-22 13:02:09 +01001241 wakeup.four_way_handshake = true;
Johannes Berg9b26b502013-01-22 13:02:09 +01001242
Johannes Bergf0c26462013-01-22 20:41:58 +01001243 if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_LINK_LOSS)
1244 wakeup.tcp_connlost = true;
1245
1246 if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_SIGNATURE_TABLE)
1247 wakeup.tcp_nomoretokens = true;
1248
1249 if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_WAKEUP_PACKET)
1250 wakeup.tcp_match = true;
1251
Johannes Berg9b26b502013-01-22 13:02:09 +01001252 if (status->wake_packet_bufsize) {
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001253 int pktsize = status->wake_packet_bufsize;
1254 int pktlen = status->wake_packet_length;
Johannes Bergf444eb12013-02-26 12:04:18 +01001255 const u8 *pktdata = status->wake_packet;
1256 struct ieee80211_hdr *hdr = (void *)pktdata;
1257 int truncated = pktlen - pktsize;
Johannes Berg9b26b502013-01-22 13:02:09 +01001258
Johannes Bergf444eb12013-02-26 12:04:18 +01001259 /* this would be a firmware bug */
1260 if (WARN_ON_ONCE(truncated < 0))
1261 truncated = 0;
1262
1263 if (ieee80211_is_data(hdr->frame_control)) {
1264 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
1265 int ivlen = 0, icvlen = 4; /* also FCS */
1266
Johannes Berg9b26b502013-01-22 13:02:09 +01001267 pkt = alloc_skb(pktsize, GFP_KERNEL);
1268 if (!pkt)
1269 goto report;
Johannes Bergf444eb12013-02-26 12:04:18 +01001270
Johannes Berg59ae1d12017-06-16 14:29:20 +02001271 skb_put_data(pkt, pktdata, hdrlen);
Johannes Bergf444eb12013-02-26 12:04:18 +01001272 pktdata += hdrlen;
1273 pktsize -= hdrlen;
1274
1275 if (ieee80211_has_protected(hdr->frame_control)) {
Johannes Berg7abc4632013-08-06 18:28:26 +02001276 /*
1277 * This is unlocked and using gtk_i(c)vlen,
1278 * but since everything is under RTNL still
1279 * that's not really a problem - changing
1280 * it would be difficult.
1281 */
Johannes Bergf444eb12013-02-26 12:04:18 +01001282 if (is_multicast_ether_addr(hdr->addr1)) {
1283 ivlen = mvm->gtk_ivlen;
1284 icvlen += mvm->gtk_icvlen;
1285 } else {
1286 ivlen = mvm->ptk_ivlen;
1287 icvlen += mvm->ptk_icvlen;
1288 }
1289 }
1290
1291 /* if truncated, FCS/ICV is (partially) gone */
1292 if (truncated >= icvlen) {
1293 icvlen = 0;
1294 truncated -= icvlen;
1295 } else {
1296 icvlen -= truncated;
1297 truncated = 0;
1298 }
1299
1300 pktsize -= ivlen + icvlen;
1301 pktdata += ivlen;
1302
Johannes Berg59ae1d12017-06-16 14:29:20 +02001303 skb_put_data(pkt, pktdata, pktsize);
Johannes Bergf444eb12013-02-26 12:04:18 +01001304
Johannes Berg9b26b502013-01-22 13:02:09 +01001305 if (ieee80211_data_to_8023(pkt, vif->addr, vif->type))
1306 goto report;
1307 wakeup.packet = pkt->data;
1308 wakeup.packet_present_len = pkt->len;
Johannes Bergf444eb12013-02-26 12:04:18 +01001309 wakeup.packet_len = pkt->len - truncated;
Johannes Berg9b26b502013-01-22 13:02:09 +01001310 wakeup.packet_80211 = false;
1311 } else {
Johannes Bergf444eb12013-02-26 12:04:18 +01001312 int fcslen = 4;
1313
1314 if (truncated >= 4) {
1315 truncated -= 4;
1316 fcslen = 0;
1317 } else {
1318 fcslen -= truncated;
1319 truncated = 0;
1320 }
1321 pktsize -= fcslen;
Johannes Berg9b26b502013-01-22 13:02:09 +01001322 wakeup.packet = status->wake_packet;
1323 wakeup.packet_present_len = pktsize;
Johannes Bergf444eb12013-02-26 12:04:18 +01001324 wakeup.packet_len = pktlen - truncated;
Johannes Berg9b26b502013-01-22 13:02:09 +01001325 wakeup.packet_80211 = true;
1326 }
1327 }
1328
1329 report:
1330 ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL);
1331 kfree_skb(pkt);
Johannes Berg7abc4632013-08-06 18:28:26 +02001332}
Johannes Berg9b26b502013-01-22 13:02:09 +01001333
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001334static void iwl_mvm_aes_sc_to_seq(struct aes_sc *sc,
1335 struct ieee80211_key_seq *seq)
1336{
1337 u64 pn;
1338
1339 pn = le64_to_cpu(sc->pn);
1340 seq->ccmp.pn[0] = pn >> 40;
1341 seq->ccmp.pn[1] = pn >> 32;
1342 seq->ccmp.pn[2] = pn >> 24;
1343 seq->ccmp.pn[3] = pn >> 16;
1344 seq->ccmp.pn[4] = pn >> 8;
1345 seq->ccmp.pn[5] = pn;
1346}
1347
1348static void iwl_mvm_tkip_sc_to_seq(struct tkip_sc *sc,
1349 struct ieee80211_key_seq *seq)
1350{
1351 seq->tkip.iv32 = le32_to_cpu(sc->iv32);
1352 seq->tkip.iv16 = le16_to_cpu(sc->iv16);
1353}
1354
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001355static void iwl_mvm_set_aes_rx_seq(struct iwl_mvm *mvm, struct aes_sc *scs,
1356 struct ieee80211_sta *sta,
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001357 struct ieee80211_key_conf *key)
1358{
1359 int tid;
1360
1361 BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS);
1362
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001363 if (sta && iwl_mvm_has_new_rx_api(mvm)) {
1364 struct iwl_mvm_sta *mvmsta;
1365 struct iwl_mvm_key_pn *ptk_pn;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001366
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001367 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1368
Sara Sharonefa40c72020-10-08 18:12:42 +03001369 rcu_read_lock();
1370 ptk_pn = rcu_dereference(mvmsta->ptk_pn[key->keyidx]);
1371 if (WARN_ON(!ptk_pn)) {
1372 rcu_read_unlock();
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001373 return;
Sara Sharonefa40c72020-10-08 18:12:42 +03001374 }
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001375
1376 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1377 struct ieee80211_key_seq seq = {};
1378 int i;
1379
1380 iwl_mvm_aes_sc_to_seq(&scs[tid], &seq);
1381 ieee80211_set_key_rx_seq(key, tid, &seq);
1382 for (i = 1; i < mvm->trans->num_rx_queues; i++)
1383 memcpy(ptk_pn->q[i].pn[tid],
1384 seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
1385 }
Sara Sharonefa40c72020-10-08 18:12:42 +03001386 rcu_read_unlock();
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001387 } else {
1388 for (tid = 0; tid < IWL_NUM_RSC; tid++) {
1389 struct ieee80211_key_seq seq = {};
1390
1391 iwl_mvm_aes_sc_to_seq(&scs[tid], &seq);
1392 ieee80211_set_key_rx_seq(key, tid, &seq);
1393 }
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001394 }
1395}
1396
1397static void iwl_mvm_set_tkip_rx_seq(struct tkip_sc *scs,
1398 struct ieee80211_key_conf *key)
1399{
1400 int tid;
1401
1402 BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS);
1403
1404 for (tid = 0; tid < IWL_NUM_RSC; tid++) {
1405 struct ieee80211_key_seq seq = {};
1406
1407 iwl_mvm_tkip_sc_to_seq(&scs[tid], &seq);
1408 ieee80211_set_key_rx_seq(key, tid, &seq);
1409 }
1410}
1411
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001412static void iwl_mvm_set_key_rx_seq(struct iwl_mvm *mvm,
1413 struct ieee80211_key_conf *key,
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001414 struct iwl_wowlan_status *status)
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001415{
Luca Coelho2afa6a72018-03-26 10:24:18 +03001416 union iwl_all_tsc_rsc *rsc = &status->gtk[0].rsc.all_tsc_rsc;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001417
1418 switch (key->cipher) {
1419 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergc7f996e2020-09-30 16:31:18 +03001420 case WLAN_CIPHER_SUITE_GCMP:
1421 case WLAN_CIPHER_SUITE_GCMP_256:
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001422 iwl_mvm_set_aes_rx_seq(mvm, rsc->aes.multicast_rsc, NULL, key);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001423 break;
1424 case WLAN_CIPHER_SUITE_TKIP:
1425 iwl_mvm_set_tkip_rx_seq(rsc->tkip.multicast_rsc, key);
1426 break;
1427 default:
1428 WARN_ON(1);
1429 }
1430}
1431
1432struct iwl_mvm_d3_gtk_iter_data {
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001433 struct iwl_mvm *mvm;
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001434 struct iwl_wowlan_status *status;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001435 void *last_gtk;
1436 u32 cipher;
1437 bool find_phase, unhandled_cipher;
1438 int num_keys;
1439};
1440
Emmanuel Grumbach59fd4bf2015-11-01 13:06:37 +02001441static void iwl_mvm_d3_update_keys(struct ieee80211_hw *hw,
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001442 struct ieee80211_vif *vif,
1443 struct ieee80211_sta *sta,
1444 struct ieee80211_key_conf *key,
1445 void *_data)
1446{
1447 struct iwl_mvm_d3_gtk_iter_data *data = _data;
1448
1449 if (data->unhandled_cipher)
1450 return;
1451
1452 switch (key->cipher) {
1453 case WLAN_CIPHER_SUITE_WEP40:
1454 case WLAN_CIPHER_SUITE_WEP104:
1455 /* ignore WEP completely, nothing to do */
1456 return;
1457 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergc7f996e2020-09-30 16:31:18 +03001458 case WLAN_CIPHER_SUITE_GCMP:
1459 case WLAN_CIPHER_SUITE_GCMP_256:
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001460 case WLAN_CIPHER_SUITE_TKIP:
1461 /* we support these */
1462 break;
1463 default:
1464 /* everything else (even CMAC for MFP) - disconnect from AP */
1465 data->unhandled_cipher = true;
1466 return;
1467 }
1468
1469 data->num_keys++;
1470
1471 /*
1472 * pairwise key - update sequence counters only;
1473 * note that this assumes no TDLS sessions are active
1474 */
1475 if (sta) {
1476 struct ieee80211_key_seq seq = {};
Luca Coelho2afa6a72018-03-26 10:24:18 +03001477 union iwl_all_tsc_rsc *sc =
1478 &data->status->gtk[0].rsc.all_tsc_rsc;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001479
1480 if (data->find_phase)
1481 return;
1482
1483 switch (key->cipher) {
1484 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergc7f996e2020-09-30 16:31:18 +03001485 case WLAN_CIPHER_SUITE_GCMP:
1486 case WLAN_CIPHER_SUITE_GCMP_256:
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001487 iwl_mvm_set_aes_rx_seq(data->mvm, sc->aes.unicast_rsc,
1488 sta, key);
Johannes Berg6645d5e2015-09-15 09:58:53 +02001489 atomic64_set(&key->tx_pn, le64_to_cpu(sc->aes.tsc.pn));
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001490 break;
1491 case WLAN_CIPHER_SUITE_TKIP:
1492 iwl_mvm_tkip_sc_to_seq(&sc->tkip.tsc, &seq);
1493 iwl_mvm_set_tkip_rx_seq(sc->tkip.unicast_rsc, key);
Eliad Peller1ad4f632016-02-14 13:56:36 +02001494 atomic64_set(&key->tx_pn,
1495 (u64)seq.tkip.iv16 |
1496 ((u64)seq.tkip.iv32 << 16));
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001497 break;
1498 }
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001499
1500 /* that's it for this key */
1501 return;
1502 }
1503
1504 if (data->find_phase) {
1505 data->last_gtk = key;
1506 data->cipher = key->cipher;
1507 return;
1508 }
1509
1510 if (data->status->num_of_gtk_rekeys)
1511 ieee80211_remove_key(key);
1512 else if (data->last_gtk == key)
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001513 iwl_mvm_set_key_rx_seq(data->mvm, key, data->status);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001514}
1515
1516static bool iwl_mvm_setup_connection_keep(struct iwl_mvm *mvm,
1517 struct ieee80211_vif *vif,
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001518 struct iwl_wowlan_status *status)
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001519{
1520 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1521 struct iwl_mvm_d3_gtk_iter_data gtkdata = {
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001522 .mvm = mvm,
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001523 .status = status,
1524 };
Eliad Peller431591c2013-11-07 14:12:09 +02001525 u32 disconnection_reasons =
1526 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON |
1527 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001528
1529 if (!status || !vif->bss_conf.bssid)
1530 return false;
1531
Eliad Peller431591c2013-11-07 14:12:09 +02001532 if (le32_to_cpu(status->wakeup_reasons) & disconnection_reasons)
1533 return false;
1534
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001535 /* find last GTK that we used initially, if any */
1536 gtkdata.find_phase = true;
1537 ieee80211_iter_keys(mvm->hw, vif,
Emmanuel Grumbach59fd4bf2015-11-01 13:06:37 +02001538 iwl_mvm_d3_update_keys, &gtkdata);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001539 /* not trying to keep connections with MFP/unhandled ciphers */
1540 if (gtkdata.unhandled_cipher)
1541 return false;
1542 if (!gtkdata.num_keys)
Luciano Coelhocfa88892013-11-19 15:38:55 +02001543 goto out;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001544 if (!gtkdata.last_gtk)
1545 return false;
1546
1547 /*
1548 * invalidate all other GTKs that might still exist and update
1549 * the one that we used
1550 */
1551 gtkdata.find_phase = false;
1552 ieee80211_iter_keys(mvm->hw, vif,
Emmanuel Grumbach59fd4bf2015-11-01 13:06:37 +02001553 iwl_mvm_d3_update_keys, &gtkdata);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001554
Sara Sharon19d9fa72020-09-30 16:31:20 +03001555 IWL_DEBUG_WOWLAN(mvm, "num of GTK rekeying %d\n",
1556 le32_to_cpu(status->num_of_gtk_rekeys));
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001557 if (status->num_of_gtk_rekeys) {
1558 struct ieee80211_key_conf *key;
1559 struct {
1560 struct ieee80211_key_conf conf;
1561 u8 key[32];
1562 } conf = {
1563 .conf.cipher = gtkdata.cipher,
Luca Coelho2afa6a72018-03-26 10:24:18 +03001564 .conf.keyidx =
1565 iwlmvm_wowlan_gtk_idx(&status->gtk[0]),
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001566 };
Luca Coelho11a05132018-02-27 16:37:56 +02001567 __be64 replay_ctr;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001568
Sara Sharon19d9fa72020-09-30 16:31:20 +03001569 IWL_DEBUG_WOWLAN(mvm,
1570 "Received from FW GTK cipher %d, key index %d\n",
1571 conf.conf.cipher, conf.conf.keyidx);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001572 switch (gtkdata.cipher) {
1573 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergc7f996e2020-09-30 16:31:18 +03001574 case WLAN_CIPHER_SUITE_GCMP:
1575 BUILD_BUG_ON(WLAN_KEY_LEN_CCMP != WLAN_KEY_LEN_GCMP);
1576 BUILD_BUG_ON(sizeof(conf.key) < WLAN_KEY_LEN_CCMP);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001577 conf.conf.keylen = WLAN_KEY_LEN_CCMP;
Luca Coelho2afa6a72018-03-26 10:24:18 +03001578 memcpy(conf.conf.key, status->gtk[0].key,
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001579 WLAN_KEY_LEN_CCMP);
1580 break;
Johannes Bergc7f996e2020-09-30 16:31:18 +03001581 case WLAN_CIPHER_SUITE_GCMP_256:
1582 BUILD_BUG_ON(sizeof(conf.key) < WLAN_KEY_LEN_GCMP_256);
1583 conf.conf.keylen = WLAN_KEY_LEN_GCMP_256;
1584 memcpy(conf.conf.key, status->gtk[0].key,
1585 WLAN_KEY_LEN_GCMP_256);
1586 break;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001587 case WLAN_CIPHER_SUITE_TKIP:
Johannes Bergc7f996e2020-09-30 16:31:18 +03001588 BUILD_BUG_ON(sizeof(conf.key) < WLAN_KEY_LEN_TKIP);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001589 conf.conf.keylen = WLAN_KEY_LEN_TKIP;
Luca Coelho2afa6a72018-03-26 10:24:18 +03001590 memcpy(conf.conf.key, status->gtk[0].key, 16);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001591 /* leave TX MIC key zeroed, we don't use it anyway */
1592 memcpy(conf.conf.key +
1593 NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY,
Luca Coelho2afa6a72018-03-26 10:24:18 +03001594 status->gtk[0].tkip_mic_key, 8);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001595 break;
1596 }
1597
1598 key = ieee80211_gtk_rekey_add(vif, &conf.conf);
1599 if (IS_ERR(key))
1600 return false;
Johannes Bergf5e28ea2015-12-06 14:58:08 +02001601 iwl_mvm_set_key_rx_seq(mvm, key, status);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001602
Luca Coelho2afa6a72018-03-26 10:24:18 +03001603 replay_ctr =
1604 cpu_to_be64(le64_to_cpu(status->replay_ctr));
Luca Coelho11a05132018-02-27 16:37:56 +02001605
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001606 ieee80211_gtk_rekey_notify(vif, vif->bss_conf.bssid,
1607 (void *)&replay_ctr, GFP_KERNEL);
1608 }
1609
Luciano Coelhocfa88892013-11-19 15:38:55 +02001610out:
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001611 mvmvif->seqno_valid = true;
1612 /* +0x10 because the set API expects next-to-use, not last-used */
1613 mvmvif->seqno = le16_to_cpu(status->non_qos_seq_ctr) + 0x10;
1614
1615 return true;
1616}
1617
Johannes Bergbc681632020-09-30 19:19:50 +03001618/* Occasionally, templates would be nice. This is one of those times ... */
1619#define iwl_mvm_parse_wowlan_status_common(_ver) \
1620static struct iwl_wowlan_status * \
1621iwl_mvm_parse_wowlan_status_common_ ## _ver(struct iwl_mvm *mvm, \
1622 void *_data, int len) \
1623{ \
1624 struct iwl_wowlan_status *status; \
1625 struct iwl_wowlan_status_ ##_ver *data = _data; \
1626 int data_size; \
1627 \
1628 if (len < sizeof(*data)) { \
1629 IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); \
1630 return ERR_PTR(-EIO); \
1631 } \
1632 \
1633 data_size = ALIGN(le32_to_cpu(data->wake_packet_bufsize), 4); \
1634 if (len != sizeof(*data) + data_size) { \
1635 IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); \
1636 return ERR_PTR(-EIO); \
1637 } \
1638 \
1639 status = kzalloc(sizeof(*status) + data_size, GFP_KERNEL); \
1640 if (!status) \
1641 return ERR_PTR(-ENOMEM); \
1642 \
1643 /* copy all the common fields */ \
1644 status->replay_ctr = data->replay_ctr; \
1645 status->pattern_number = data->pattern_number; \
1646 status->non_qos_seq_ctr = data->non_qos_seq_ctr; \
1647 memcpy(status->qos_seq_ctr, data->qos_seq_ctr, \
1648 sizeof(status->qos_seq_ctr)); \
1649 status->wakeup_reasons = data->wakeup_reasons; \
1650 status->num_of_gtk_rekeys = data->num_of_gtk_rekeys; \
1651 status->received_beacons = data->received_beacons; \
1652 status->wake_packet_length = data->wake_packet_length; \
1653 status->wake_packet_bufsize = data->wake_packet_bufsize; \
1654 memcpy(status->wake_packet, data->wake_packet, \
1655 le32_to_cpu(status->wake_packet_bufsize)); \
1656 \
1657 return status; \
1658}
1659
1660iwl_mvm_parse_wowlan_status_common(v6)
1661iwl_mvm_parse_wowlan_status_common(v7)
1662iwl_mvm_parse_wowlan_status_common(v9)
1663
Luca Coelho2afa6a72018-03-26 10:24:18 +03001664struct iwl_wowlan_status *iwl_mvm_send_wowlan_get_status(struct iwl_mvm *mvm)
1665{
Mordechay Goodstein250380c2020-04-17 13:21:37 +03001666 struct iwl_wowlan_status *status;
Luca Coelho2afa6a72018-03-26 10:24:18 +03001667 struct iwl_host_cmd cmd = {
1668 .id = WOWLAN_GET_STATUSES,
1669 .flags = CMD_WANT_SKB,
1670 };
Johannes Bergbc681632020-09-30 19:19:50 +03001671 int ret, len;
Mordechay Goodstein250380c2020-04-17 13:21:37 +03001672 u8 notif_ver;
Luca Coelho2afa6a72018-03-26 10:24:18 +03001673
1674 lockdep_assert_held(&mvm->mutex);
1675
1676 ret = iwl_mvm_send_cmd(mvm, &cmd);
1677 if (ret) {
1678 IWL_ERR(mvm, "failed to query wakeup status (%d)\n", ret);
1679 return ERR_PTR(ret);
1680 }
1681
Mordechay Goodstein250380c2020-04-17 13:21:37 +03001682 len = iwl_rx_packet_payload_len(cmd.resp_pkt);
Johannes Bergbc681632020-09-30 19:19:50 +03001683
1684 /* default to 7 (when we have IWL_UCODE_TLV_API_WOWLAN_KEY_MATERIAL) */
1685 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
1686 WOWLAN_GET_STATUSES, 7);
1687
Luca Coelho2afa6a72018-03-26 10:24:18 +03001688 if (!fw_has_api(&mvm->fw->ucode_capa,
1689 IWL_UCODE_TLV_API_WOWLAN_KEY_MATERIAL)) {
1690 struct iwl_wowlan_status_v6 *v6 = (void *)cmd.resp_pkt->data;
Luca Coelho2afa6a72018-03-26 10:24:18 +03001691
Johannes Bergbc681632020-09-30 19:19:50 +03001692 status = iwl_mvm_parse_wowlan_status_common_v6(mvm,
1693 cmd.resp_pkt->data,
1694 len);
1695 if (IS_ERR(status))
Luca Coelho2afa6a72018-03-26 10:24:18 +03001696 goto out_free_resp;
1697
1698 BUILD_BUG_ON(sizeof(v6->gtk.decrypt_key) >
1699 sizeof(status->gtk[0].key));
1700 BUILD_BUG_ON(sizeof(v6->gtk.tkip_mic_key) >
1701 sizeof(status->gtk[0].tkip_mic_key));
1702
1703 /* copy GTK info to the right place */
1704 memcpy(status->gtk[0].key, v6->gtk.decrypt_key,
1705 sizeof(v6->gtk.decrypt_key));
1706 memcpy(status->gtk[0].tkip_mic_key, v6->gtk.tkip_mic_key,
1707 sizeof(v6->gtk.tkip_mic_key));
1708 memcpy(&status->gtk[0].rsc, &v6->gtk.rsc,
1709 sizeof(status->gtk[0].rsc));
1710
1711 /* hardcode the key length to 16 since v6 only supports 16 */
1712 status->gtk[0].key_len = 16;
1713
1714 /*
1715 * The key index only uses 2 bits (values 0 to 3) and
1716 * we always set bit 7 which means this is the
1717 * currently used key.
1718 */
1719 status->gtk[0].key_flags = v6->gtk.key_index | BIT(7);
Johannes Bergbc681632020-09-30 19:19:50 +03001720 } else if (notif_ver == 7) {
1721 struct iwl_wowlan_status_v7 *v7 = (void *)cmd.resp_pkt->data;
Luca Coelho2afa6a72018-03-26 10:24:18 +03001722
Johannes Bergbc681632020-09-30 19:19:50 +03001723 status = iwl_mvm_parse_wowlan_status_common_v7(mvm,
1724 cmd.resp_pkt->data,
1725 len);
1726 if (IS_ERR(status))
1727 goto out_free_resp;
Luca Coelho2afa6a72018-03-26 10:24:18 +03001728
Johannes Bergbc681632020-09-30 19:19:50 +03001729 status->gtk[0] = v7->gtk[0];
1730 status->igtk[0] = v7->igtk[0];
1731 } else if (notif_ver == 9) {
1732 struct iwl_wowlan_status_v9 *v9 = (void *)cmd.resp_pkt->data;
Luca Coelho2afa6a72018-03-26 10:24:18 +03001733
Johannes Bergbc681632020-09-30 19:19:50 +03001734 status = iwl_mvm_parse_wowlan_status_common_v9(mvm,
1735 cmd.resp_pkt->data,
1736 len);
1737 if (IS_ERR(status))
1738 goto out_free_resp;
Luca Coelho2afa6a72018-03-26 10:24:18 +03001739
Johannes Bergbc681632020-09-30 19:19:50 +03001740 status->gtk[0] = v9->gtk[0];
1741 status->igtk[0] = v9->igtk[0];
Mordechay Goodstein250380c2020-04-17 13:21:37 +03001742
Johannes Bergbc681632020-09-30 19:19:50 +03001743 status->tid_tear_down = v9->tid_tear_down;
1744 } else {
1745 IWL_ERR(mvm,
1746 "Firmware advertises unknown WoWLAN status response %d!\n",
1747 notif_ver);
Luca Coelho2afa6a72018-03-26 10:24:18 +03001748 status = ERR_PTR(-EIO);
Luca Coelho2afa6a72018-03-26 10:24:18 +03001749 }
Luca Coelho2afa6a72018-03-26 10:24:18 +03001750
1751out_free_resp:
1752 iwl_free_resp(&cmd);
1753 return status;
1754}
1755
Luciano Coelhoec12f452014-11-20 10:14:44 +02001756static struct iwl_wowlan_status *
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03001757iwl_mvm_get_wakeup_status(struct iwl_mvm *mvm)
Johannes Berg7abc4632013-08-06 18:28:26 +02001758{
Luca Coelho2afa6a72018-03-26 10:24:18 +03001759 int ret;
Johannes Berg7abc4632013-08-06 18:28:26 +02001760
Johannes Berg7abc4632013-08-06 18:28:26 +02001761 /* only for tracing for now */
Emmanuel Grumbacha1022922014-05-12 11:36:41 +03001762 ret = iwl_mvm_send_cmd_pdu(mvm, OFFLOADS_QUERY_CMD, 0, 0, NULL);
Johannes Berg7abc4632013-08-06 18:28:26 +02001763 if (ret)
1764 IWL_ERR(mvm, "failed to query offload statistics (%d)\n", ret);
1765
Luca Coelho2afa6a72018-03-26 10:24:18 +03001766 return iwl_mvm_send_wowlan_get_status(mvm);
Luciano Coelhoec12f452014-11-20 10:14:44 +02001767}
1768
1769/* releases the MVM mutex */
1770static bool iwl_mvm_query_wakeup_reasons(struct iwl_mvm *mvm,
1771 struct ieee80211_vif *vif)
1772{
1773 struct iwl_wowlan_status_data status;
1774 struct iwl_wowlan_status *fw_status;
1775 int i;
1776 bool keep;
Luciano Coelhoec12f452014-11-20 10:14:44 +02001777 struct iwl_mvm_sta *mvm_ap_sta;
1778
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03001779 fw_status = iwl_mvm_get_wakeup_status(mvm);
Luciano Coelhoec12f452014-11-20 10:14:44 +02001780 if (IS_ERR_OR_NULL(fw_status))
1781 goto out_unlock;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001782
Sara Sharon19d9fa72020-09-30 16:31:20 +03001783 IWL_DEBUG_WOWLAN(mvm, "wakeup reason 0x%x\n",
1784 le32_to_cpu(fw_status->wakeup_reasons));
1785
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001786 status.pattern_number = le16_to_cpu(fw_status->pattern_number);
1787 for (i = 0; i < 8; i++)
1788 status.qos_seq_ctr[i] =
1789 le16_to_cpu(fw_status->qos_seq_ctr[i]);
1790 status.wakeup_reasons = le32_to_cpu(fw_status->wakeup_reasons);
1791 status.wake_packet_length =
1792 le32_to_cpu(fw_status->wake_packet_length);
1793 status.wake_packet_bufsize =
1794 le32_to_cpu(fw_status->wake_packet_bufsize);
1795 status.wake_packet = fw_status->wake_packet;
Johannes Berg7abc4632013-08-06 18:28:26 +02001796
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001797 /* still at hard-coded place 0 for D3 image */
Sara Sharon13303c02016-04-10 15:51:54 +03001798 mvm_ap_sta = iwl_mvm_sta_from_staid_protected(mvm, 0);
1799 if (!mvm_ap_sta)
Luciano Coelhoec12f452014-11-20 10:14:44 +02001800 goto out_free;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001801
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001802 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
1803 u16 seq = status.qos_seq_ctr[i];
1804 /* firmware stores last-used value, we store next value */
1805 seq += 0x10;
1806 mvm_ap_sta->tid_data[i].seq_number = seq;
1807 }
1808
Luca Coelho286ca8e2019-07-12 15:03:48 +03001809 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000) {
Alex Malamudba7136f2019-06-10 15:19:23 +03001810 i = mvm->offload_tid;
1811 iwl_trans_set_q_ptrs(mvm->trans,
1812 mvm_ap_sta->tid_data[i].txq_id,
1813 mvm_ap_sta->tid_data[i].seq_number >> 4);
1814 }
1815
Johannes Berg7abc4632013-08-06 18:28:26 +02001816 /* now we have all the data we need, unlock to avoid mac80211 issues */
1817 mutex_unlock(&mvm->mutex);
1818
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001819 iwl_mvm_report_wakeup_reasons(mvm, vif, &status);
1820
Emmanuel Grumbach3afec6392014-03-30 09:10:28 +03001821 keep = iwl_mvm_setup_connection_keep(mvm, vif, fw_status);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001822
Luciano Coelhoec12f452014-11-20 10:14:44 +02001823 kfree(fw_status);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001824 return keep;
Johannes Berg7abc4632013-08-06 18:28:26 +02001825
Luciano Coelhoec12f452014-11-20 10:14:44 +02001826out_free:
1827 kfree(fw_status);
1828out_unlock:
Johannes Berg7abc4632013-08-06 18:28:26 +02001829 mutex_unlock(&mvm->mutex);
Johannes Berg6d9d32b2013-08-06 18:58:56 +02001830 return false;
Johannes Berg9b26b502013-01-22 13:02:09 +01001831}
1832
Ilan Peere4fe5d42019-02-05 10:59:40 +02001833#define ND_QUERY_BUF_LEN (sizeof(struct iwl_scan_offload_profile_match) * \
1834 IWL_SCAN_MAX_PROFILES)
1835
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001836struct iwl_mvm_nd_query_results {
1837 u32 matched_profiles;
Ilan Peere4fe5d42019-02-05 10:59:40 +02001838 u8 matches[ND_QUERY_BUF_LEN];
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001839};
1840
1841static int
1842iwl_mvm_netdetect_query_results(struct iwl_mvm *mvm,
1843 struct iwl_mvm_nd_query_results *results)
Luciano Coelhob04998f2014-11-20 15:58:34 +02001844{
1845 struct iwl_scan_offload_profiles_query *query;
1846 struct iwl_host_cmd cmd = {
1847 .id = SCAN_OFFLOAD_PROFILES_QUERY_CMD,
1848 .flags = CMD_WANT_SKB,
1849 };
1850 int ret, len;
Ilan Peere4fe5d42019-02-05 10:59:40 +02001851 size_t query_len, matches_len;
Tova Mussai5d1234b2019-11-05 12:56:14 +02001852 int max_profiles = iwl_umac_scan_get_max_profiles(mvm->fw);
Luciano Coelhob04998f2014-11-20 15:58:34 +02001853
1854 ret = iwl_mvm_send_cmd(mvm, &cmd);
1855 if (ret) {
1856 IWL_ERR(mvm, "failed to query matched profiles (%d)\n", ret);
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001857 return ret;
Luciano Coelhob04998f2014-11-20 15:58:34 +02001858 }
1859
Ilan Peere4fe5d42019-02-05 10:59:40 +02001860 if (fw_has_api(&mvm->fw->ucode_capa,
1861 IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) {
1862 query_len = sizeof(struct iwl_scan_offload_profiles_query);
1863 matches_len = sizeof(struct iwl_scan_offload_profile_match) *
Tova Mussai5d1234b2019-11-05 12:56:14 +02001864 max_profiles;
Ilan Peere4fe5d42019-02-05 10:59:40 +02001865 } else {
1866 query_len = sizeof(struct iwl_scan_offload_profiles_query_v1);
1867 matches_len = sizeof(struct iwl_scan_offload_profile_match_v1) *
Tova Mussai5d1234b2019-11-05 12:56:14 +02001868 max_profiles;
Ilan Peere4fe5d42019-02-05 10:59:40 +02001869 }
1870
Luciano Coelhob04998f2014-11-20 15:58:34 +02001871 len = iwl_rx_packet_payload_len(cmd.resp_pkt);
Ilan Peere4fe5d42019-02-05 10:59:40 +02001872 if (len < query_len) {
Luciano Coelhob04998f2014-11-20 15:58:34 +02001873 IWL_ERR(mvm, "Invalid scan offload profiles query response!\n");
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001874 ret = -EIO;
Luciano Coelhob04998f2014-11-20 15:58:34 +02001875 goto out_free_resp;
1876 }
1877
1878 query = (void *)cmd.resp_pkt->data;
1879
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001880 results->matched_profiles = le32_to_cpu(query->matched_profiles);
Ilan Peere4fe5d42019-02-05 10:59:40 +02001881 memcpy(results->matches, query->matches, matches_len);
Luciano Coelhob04998f2014-11-20 15:58:34 +02001882
Emmanuel Grumbach6bbd5522015-04-28 15:00:23 +03001883#ifdef CONFIG_IWLWIFI_DEBUGFS
Luciano Coelho484b3d12015-03-30 20:46:32 +03001884 mvm->last_netdetect_scans = le32_to_cpu(query->n_scans_done);
1885#endif
1886
Luciano Coelhob04998f2014-11-20 15:58:34 +02001887out_free_resp:
1888 iwl_free_resp(&cmd);
1889 return ret;
1890}
1891
Ilan Peere4fe5d42019-02-05 10:59:40 +02001892static int iwl_mvm_query_num_match_chans(struct iwl_mvm *mvm,
1893 struct iwl_mvm_nd_query_results *query,
1894 int idx)
1895{
1896 int n_chans = 0, i;
1897
1898 if (fw_has_api(&mvm->fw->ucode_capa,
1899 IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) {
1900 struct iwl_scan_offload_profile_match *matches =
1901 (struct iwl_scan_offload_profile_match *)query->matches;
1902
1903 for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN; i++)
1904 n_chans += hweight8(matches[idx].matching_channels[i]);
1905 } else {
1906 struct iwl_scan_offload_profile_match_v1 *matches =
1907 (struct iwl_scan_offload_profile_match_v1 *)query->matches;
1908
1909 for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1; i++)
1910 n_chans += hweight8(matches[idx].matching_channels[i]);
1911 }
1912
1913 return n_chans;
1914}
1915
1916static void iwl_mvm_query_set_freqs(struct iwl_mvm *mvm,
1917 struct iwl_mvm_nd_query_results *query,
1918 struct cfg80211_wowlan_nd_match *match,
1919 int idx)
1920{
1921 int i;
1922
1923 if (fw_has_api(&mvm->fw->ucode_capa,
1924 IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) {
1925 struct iwl_scan_offload_profile_match *matches =
1926 (struct iwl_scan_offload_profile_match *)query->matches;
1927
1928 for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN * 8; i++)
1929 if (matches[idx].matching_channels[i / 8] & (BIT(i % 8)))
1930 match->channels[match->n_channels++] =
1931 mvm->nd_channels[i]->center_freq;
1932 } else {
1933 struct iwl_scan_offload_profile_match_v1 *matches =
1934 (struct iwl_scan_offload_profile_match_v1 *)query->matches;
1935
1936 for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1 * 8; i++)
1937 if (matches[idx].matching_channels[i / 8] & (BIT(i % 8)))
1938 match->channels[match->n_channels++] =
1939 mvm->nd_channels[i]->center_freq;
1940 }
1941}
1942
Luciano Coelho2021a892014-11-20 08:59:51 +02001943static void iwl_mvm_query_netdetect_reasons(struct iwl_mvm *mvm,
1944 struct ieee80211_vif *vif)
1945{
Luciano Coelhod9718da2014-11-21 09:32:23 +02001946 struct cfg80211_wowlan_nd_info *net_detect = NULL;
Luciano Coelho2021a892014-11-20 08:59:51 +02001947 struct cfg80211_wowlan_wakeup wakeup = {
1948 .pattern_idx = -1,
1949 };
1950 struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup;
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001951 struct iwl_mvm_nd_query_results query;
Luciano Coelho2021a892014-11-20 08:59:51 +02001952 struct iwl_wowlan_status *fw_status;
Luciano Coelhod9718da2014-11-21 09:32:23 +02001953 unsigned long matched_profiles;
Luciano Coelho2021a892014-11-20 08:59:51 +02001954 u32 reasons = 0;
Ilan Peere4fe5d42019-02-05 10:59:40 +02001955 int i, n_matches, ret;
Luciano Coelho2021a892014-11-20 08:59:51 +02001956
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03001957 fw_status = iwl_mvm_get_wakeup_status(mvm);
Haim Dreyfuss2fc863a2015-05-20 08:10:43 +03001958 if (!IS_ERR_OR_NULL(fw_status)) {
Luciano Coelho2021a892014-11-20 08:59:51 +02001959 reasons = le32_to_cpu(fw_status->wakeup_reasons);
Haim Dreyfuss2fc863a2015-05-20 08:10:43 +03001960 kfree(fw_status);
1961 }
Luciano Coelho2021a892014-11-20 08:59:51 +02001962
1963 if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED)
1964 wakeup.rfkill_release = true;
1965
Luciano Coelhob04998f2014-11-20 15:58:34 +02001966 if (reasons != IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS)
1967 goto out;
1968
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001969 ret = iwl_mvm_netdetect_query_results(mvm, &query);
1970 if (ret || !query.matched_profiles) {
Luciano Coelho2021a892014-11-20 08:59:51 +02001971 wakeup_report = NULL;
Luciano Coelhob04998f2014-11-20 15:58:34 +02001972 goto out;
Luciano Coelho2021a892014-11-20 08:59:51 +02001973 }
1974
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001975 matched_profiles = query.matched_profiles;
Luciano Coelhod9718da2014-11-21 09:32:23 +02001976 if (mvm->n_nd_match_sets) {
1977 n_matches = hweight_long(matched_profiles);
1978 } else {
1979 IWL_ERR(mvm, "no net detect match information available\n");
1980 n_matches = 0;
1981 }
1982
Gustavo A. R. Silva83ea00d2018-08-23 20:15:40 -05001983 net_detect = kzalloc(struct_size(net_detect, matches, n_matches),
Luciano Coelhod9718da2014-11-21 09:32:23 +02001984 GFP_KERNEL);
1985 if (!net_detect || !n_matches)
1986 goto out_report_nd;
1987
1988 for_each_set_bit(i, &matched_profiles, mvm->n_nd_match_sets) {
1989 struct cfg80211_wowlan_nd_match *match;
Luciano Coelhoae90c2e52015-05-06 10:45:42 +03001990 int idx, n_channels = 0;
Luciano Coelhod9718da2014-11-21 09:32:23 +02001991
Ilan Peere4fe5d42019-02-05 10:59:40 +02001992 n_channels = iwl_mvm_query_num_match_chans(mvm, &query, i);
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001993
Gustavo A. R. Silva83ea00d2018-08-23 20:15:40 -05001994 match = kzalloc(struct_size(match, channels, n_channels),
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001995 GFP_KERNEL);
Luciano Coelhod9718da2014-11-21 09:32:23 +02001996 if (!match)
1997 goto out_report_nd;
1998
Luciano Coelho8ed4e652014-11-21 22:08:01 +02001999 net_detect->matches[net_detect->n_matches++] = match;
2000
Luciano Coelhoae90c2e52015-05-06 10:45:42 +03002001 /* We inverted the order of the SSIDs in the scan
2002 * request, so invert the index here.
2003 */
2004 idx = mvm->n_nd_match_sets - i - 1;
2005 match->ssid.ssid_len = mvm->nd_match_sets[idx].ssid.ssid_len;
2006 memcpy(match->ssid.ssid, mvm->nd_match_sets[idx].ssid.ssid,
Luciano Coelhod9718da2014-11-21 09:32:23 +02002007 match->ssid.ssid_len);
2008
Luciano Coelho8ed4e652014-11-21 22:08:01 +02002009 if (mvm->n_nd_channels < n_channels)
2010 continue;
2011
Ilan Peere4fe5d42019-02-05 10:59:40 +02002012 iwl_mvm_query_set_freqs(mvm, &query, match, i);
Luciano Coelhod9718da2014-11-21 09:32:23 +02002013 }
2014
2015out_report_nd:
2016 wakeup.net_detect = net_detect;
Luciano Coelhob04998f2014-11-20 15:58:34 +02002017out:
Luciano Coelhod9718da2014-11-21 09:32:23 +02002018 iwl_mvm_free_nd(mvm);
2019
Luciano Coelho2021a892014-11-20 08:59:51 +02002020 mutex_unlock(&mvm->mutex);
2021 ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL);
Luciano Coelhod9718da2014-11-21 09:32:23 +02002022
2023 if (net_detect) {
2024 for (i = 0; i < net_detect->n_matches; i++)
2025 kfree(net_detect->matches[i]);
2026 kfree(net_detect);
2027 }
Luciano Coelho2021a892014-11-20 08:59:51 +02002028}
2029
Johannes Berg6d9d32b2013-08-06 18:58:56 +02002030static void iwl_mvm_d3_disconnect_iter(void *data, u8 *mac,
2031 struct ieee80211_vif *vif)
2032{
2033 /* skip the one we keep connection on */
2034 if (data == vif)
2035 return;
2036
2037 if (vif->type == NL80211_IFTYPE_STATION)
2038 ieee80211_resume_disconnect(vif);
2039}
2040
Mordechay Goodstein577ddbe2020-01-31 15:45:30 +02002041static bool iwl_mvm_rt_status(struct iwl_trans *trans, u32 base, u32 *err_id)
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03002042{
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03002043 struct error_table_start {
2044 /* cf. struct iwl_error_event_table */
2045 u32 valid;
Mordechay Goodstein577ddbe2020-01-31 15:45:30 +02002046 __le32 err_id;
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03002047 } err_info;
2048
Mordechay Goodstein577ddbe2020-01-31 15:45:30 +02002049 if (!base)
2050 return false;
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03002051
Mordechay Goodstein577ddbe2020-01-31 15:45:30 +02002052 iwl_trans_read_mem_bytes(trans, base,
2053 &err_info, sizeof(err_info));
2054 if (err_info.valid && err_id)
2055 *err_id = le32_to_cpu(err_info.err_id);
2056
2057 return !!err_info.valid;
2058}
2059
2060static bool iwl_mvm_check_rt_status(struct iwl_mvm *mvm,
2061 struct ieee80211_vif *vif)
2062{
2063 u32 err_id;
2064
2065 /* check for lmac1 error */
2066 if (iwl_mvm_rt_status(mvm->trans,
2067 mvm->trans->dbg.lmac_error_event_table[0],
2068 &err_id)) {
2069 if (err_id == RF_KILL_INDICATOR_FOR_WOWLAN) {
2070 struct cfg80211_wowlan_wakeup wakeup = {
2071 .rfkill_release = true,
2072 };
2073 ieee80211_report_wowlan_wakeup(vif, &wakeup,
2074 GFP_KERNEL);
2075 }
2076 return true;
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03002077 }
Mordechay Goodstein577ddbe2020-01-31 15:45:30 +02002078
2079 /* check if we have lmac2 set and check for error */
2080 if (iwl_mvm_rt_status(mvm->trans,
2081 mvm->trans->dbg.lmac_error_event_table[1], NULL))
2082 return true;
2083
2084 /* check for umac error */
2085 if (iwl_mvm_rt_status(mvm->trans,
2086 mvm->trans->dbg.umac_error_event_table, NULL))
2087 return true;
2088
2089 return false;
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03002090}
2091
Johannes Bergdebff612013-05-14 13:53:45 +02002092static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test)
Johannes Berg8ca151b2013-01-24 14:25:36 +01002093{
Johannes Berg8ca151b2013-01-24 14:25:36 +01002094 struct ieee80211_vif *vif = NULL;
Matti Gottlieb23ae6122015-12-31 18:18:02 +02002095 int ret = 1;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002096 enum iwl_d3_status d3_status;
Johannes Berg6d9d32b2013-08-06 18:58:56 +02002097 bool keep = false;
Matti Gottlieb23ae6122015-12-31 18:18:02 +02002098 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
2099 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
Luca Coelhofcea37b2017-04-12 16:33:41 +03002100 bool d0i3_first = fw_has_capa(&mvm->fw->ucode_capa,
2101 IWL_UCODE_TLV_CAPA_D0I3_END_FIRST);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002102
2103 mutex_lock(&mvm->mutex);
2104
Johannes Berg1019f9e2019-09-30 14:45:54 +02002105 clear_bit(IWL_MVM_STATUS_IN_D3, &mvm->status);
2106
Johannes Berg8ca151b2013-01-24 14:25:36 +01002107 /* get the BSS vif pointer again */
Luciano Coelho7f549e22014-10-02 15:38:04 +03002108 vif = iwl_mvm_get_bss_vif(mvm);
2109 if (IS_ERR_OR_NULL(vif))
Luciano Coelhoa500e462015-05-04 17:03:17 +03002110 goto err;
Johannes Berg8ca151b2013-01-24 14:25:36 +01002111
Shahar S Matityahu2d8c2612018-01-29 11:05:37 +02002112 iwl_fw_dbg_read_d3_debug_data(&mvm->fwrt);
Johannes Bergafc66bb2013-05-03 11:44:16 +02002113
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03002114 if (iwl_mvm_check_rt_status(mvm, vif)) {
2115 set_bit(STATUS_FW_ERROR, &mvm->trans->status);
2116 iwl_mvm_dump_nic_error_log(mvm);
Shahar S Matityahu4d75a9e2019-11-15 09:27:40 +02002117 iwl_dbg_tlv_time_point(&mvm->fwrt,
2118 IWL_FW_INI_TIME_POINT_FW_ASSERT, NULL);
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03002119 iwl_fw_dbg_collect_desc(&mvm->fwrt, &iwl_dump_desc_assert,
Sara Sharon124e0eb2018-07-23 13:50:02 +03002120 false, 0);
Shahar S Matityahuf57d1042018-07-04 17:12:49 +03002121 ret = 1;
2122 goto err;
2123 }
2124
Mordechay Goodstein89cb1dd2020-04-24 18:48:17 +03002125 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_HOST_D3_END,
2126 NULL);
2127
Haim Dreyfusse5f3f212019-04-03 14:37:54 +03002128 ret = iwl_trans_d3_resume(mvm->trans, &d3_status, test, !unified_image);
2129 if (ret)
2130 goto err;
2131
2132 if (d3_status != IWL_D3_STATUS_ALIVE) {
2133 IWL_INFO(mvm, "Device was reset during suspend\n");
2134 goto err;
2135 }
2136
Luca Coelhofcea37b2017-04-12 16:33:41 +03002137 if (d0i3_first) {
Haim Dreyfussd3b4dc012019-07-23 18:27:45 +03002138 struct iwl_host_cmd cmd = {
2139 .id = D0I3_END_CMD,
2140 .flags = CMD_WANT_SKB,
2141 };
2142 int len;
2143
2144 ret = iwl_mvm_send_cmd(mvm, &cmd);
Luca Coelhofcea37b2017-04-12 16:33:41 +03002145 if (ret < 0) {
2146 IWL_ERR(mvm, "Failed to send D0I3_END_CMD first (%d)\n",
2147 ret);
2148 goto err;
2149 }
Haim Dreyfussd3b4dc012019-07-23 18:27:45 +03002150 switch (mvm->cmd_ver.d0i3_resp) {
2151 case 0:
2152 break;
2153 case 1:
2154 len = iwl_rx_packet_payload_len(cmd.resp_pkt);
2155 if (len != sizeof(u32)) {
2156 IWL_ERR(mvm,
2157 "Error with D0I3_END_CMD response size (%d)\n",
2158 len);
2159 goto err;
2160 }
2161 if (IWL_D0I3_RESET_REQUIRE &
2162 le32_to_cpu(*(__le32 *)cmd.resp_pkt->data)) {
2163 iwl_write32(mvm->trans, CSR_RESET,
2164 CSR_RESET_REG_FLAG_FORCE_NMI);
2165 iwl_free_resp(&cmd);
2166 }
2167 break;
2168 default:
2169 WARN_ON(1);
2170 }
Luca Coelhofcea37b2017-04-12 16:33:41 +03002171 }
2172
Jonathan Doron47c8b152014-11-27 16:55:25 +02002173 /*
2174 * Query the current location and source from the D3 firmware so we
2175 * can play it back when we re-intiailize the D0 firmware
2176 */
2177 iwl_mvm_update_changed_regdom(mvm);
2178
Gil Adam6ce1e5c2019-06-16 13:18:28 +03002179 /* Re-configure PPAG settings */
2180 iwl_mvm_ppag_send_cmd(mvm);
2181
Luca Coelho42ce76d2017-01-11 23:36:30 +02002182 if (!unified_image)
2183 /* Re-configure default SAR profile */
2184 iwl_mvm_sar_select_profile(mvm, 1, 1);
2185
Luciano Coelho2021a892014-11-20 08:59:51 +02002186 if (mvm->net_detect) {
Luca Coelho5a143db2016-10-05 09:28:53 +03002187 /* If this is a non-unified image, we restart the FW,
2188 * so no need to stop the netdetect scan. If that
2189 * fails, continue and try to get the wake-up reasons,
2190 * but trigger a HW restart by keeping a failure code
2191 * in ret.
2192 */
2193 if (unified_image)
2194 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_NETDETECT,
2195 false);
2196
Luciano Coelho2021a892014-11-20 08:59:51 +02002197 iwl_mvm_query_netdetect_reasons(mvm, vif);
Luciano Coelhoe0ede172015-02-13 21:37:09 +02002198 /* has unlocked the mutex, so skip that */
2199 goto out;
Luciano Coelho2021a892014-11-20 08:59:51 +02002200 } else {
2201 keep = iwl_mvm_query_wakeup_reasons(mvm, vif);
Eliad Peller78c9df62013-11-07 14:13:30 +02002202#ifdef CONFIG_IWLWIFI_DEBUGFS
Luciano Coelho2021a892014-11-20 08:59:51 +02002203 if (keep)
2204 mvm->keep_vif = vif;
Luciano Coelho0c2ae042015-03-12 09:25:15 +02002205#endif
Luciano Coelhoe0ede172015-02-13 21:37:09 +02002206 /* has unlocked the mutex, so skip that */
2207 goto out_iterate;
Luciano Coelho2021a892014-11-20 08:59:51 +02002208 }
Johannes Berg8ca151b2013-01-24 14:25:36 +01002209
Luciano Coelhoa500e462015-05-04 17:03:17 +03002210err:
2211 iwl_mvm_free_nd(mvm);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002212 mutex_unlock(&mvm->mutex);
2213
Luciano Coelhoe0ede172015-02-13 21:37:09 +02002214out_iterate:
Johannes Berg6d9d32b2013-08-06 18:58:56 +02002215 if (!test)
2216 ieee80211_iterate_active_interfaces_rtnl(mvm->hw,
2217 IEEE80211_IFACE_ITER_NORMAL,
2218 iwl_mvm_d3_disconnect_iter, keep ? vif : NULL);
Johannes Berg8ca151b2013-01-24 14:25:36 +01002219
Luciano Coelhoe0ede172015-02-13 21:37:09 +02002220out:
Luca Coelhofcea37b2017-04-12 16:33:41 +03002221 /* no need to reset the device in unified images, if successful */
Matti Gottlieb23ae6122015-12-31 18:18:02 +02002222 if (unified_image && !ret) {
Luca Coelhofcea37b2017-04-12 16:33:41 +03002223 /* nothing else to do if we already sent D0I3_END_CMD */
2224 if (d0i3_first)
2225 return 0;
2226
Luca Coelhof28b9362017-04-12 12:42:12 +03002227 ret = iwl_mvm_send_cmd_pdu(mvm, D0I3_END_CMD, 0, 0, NULL);
Luca Coelhofcea37b2017-04-12 16:33:41 +03002228 if (!ret)
Matti Gottlieb23ae6122015-12-31 18:18:02 +02002229 return 0;
2230 }
2231
2232 /*
2233 * Reconfigure the device in one of the following cases:
2234 * 1. We are not using a unified image
2235 * 2. We are using a unified image but had an error while exiting D3
2236 */
Matt Chen59cd8272017-08-28 14:57:54 +08002237 set_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
Matti Gottlieb23ae6122015-12-31 18:18:02 +02002238
Johannes Berg8ca151b2013-01-24 14:25:36 +01002239 return 1;
2240}
2241
Eliad Peller2d428012015-06-17 15:32:37 +03002242static int iwl_mvm_resume_d3(struct iwl_mvm *mvm)
2243{
2244 iwl_trans_resume(mvm->trans);
2245
2246 return __iwl_mvm_resume(mvm, false);
2247}
2248
Johannes Bergdebff612013-05-14 13:53:45 +02002249int iwl_mvm_resume(struct ieee80211_hw *hw)
2250{
2251 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
Luca Coelhob7282642015-09-17 23:44:14 +03002252 int ret;
Johannes Bergdebff612013-05-14 13:53:45 +02002253
Emmanuel Grumbach45745362019-06-06 10:47:33 +03002254 ret = iwl_mvm_resume_d3(mvm);
Luca Coelhob7282642015-09-17 23:44:14 +03002255
2256 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED;
2257
Luca Coelho7d9d0d52018-04-12 16:15:07 +03002258 iwl_mvm_resume_tcm(mvm);
2259
Haim Dreyfuss7f8ae002017-12-27 15:21:18 +02002260 iwl_fw_runtime_resume(&mvm->fwrt);
2261
Luca Coelhob7282642015-09-17 23:44:14 +03002262 return ret;
Johannes Bergdebff612013-05-14 13:53:45 +02002263}
2264
Johannes Berg8ca151b2013-01-24 14:25:36 +01002265void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled)
2266{
2267 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2268
2269 device_set_wakeup_enable(mvm->trans->dev, enabled);
2270}
Johannes Bergdebff612013-05-14 13:53:45 +02002271
2272#ifdef CONFIG_IWLWIFI_DEBUGFS
2273static int iwl_mvm_d3_test_open(struct inode *inode, struct file *file)
2274{
2275 struct iwl_mvm *mvm = inode->i_private;
2276 int err;
2277
2278 if (mvm->d3_test_active)
2279 return -EBUSY;
2280
2281 file->private_data = inode->i_private;
2282
Johannes Bergdebff612013-05-14 13:53:45 +02002283 synchronize_net();
2284
Luca Coelhob7282642015-09-17 23:44:14 +03002285 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_D3;
2286
Luca Coelho7d9d0d52018-04-12 16:15:07 +03002287 iwl_mvm_pause_tcm(mvm, true);
2288
Haim Dreyfuss7f8ae002017-12-27 15:21:18 +02002289 iwl_fw_runtime_suspend(&mvm->fwrt);
2290
Johannes Bergdebff612013-05-14 13:53:45 +02002291 /* start pseudo D3 */
2292 rtnl_lock();
2293 err = __iwl_mvm_suspend(mvm->hw, mvm->hw->wiphy->wowlan_config, true);
2294 rtnl_unlock();
2295 if (err > 0)
2296 err = -EINVAL;
Sara Sharoncfbc6c42018-08-21 15:23:39 +03002297 if (err)
Johannes Bergdebff612013-05-14 13:53:45 +02002298 return err;
Sara Sharoncfbc6c42018-08-21 15:23:39 +03002299
Johannes Bergdebff612013-05-14 13:53:45 +02002300 mvm->d3_test_active = true;
Eliad Peller78c9df62013-11-07 14:13:30 +02002301 mvm->keep_vif = NULL;
Johannes Bergdebff612013-05-14 13:53:45 +02002302 return 0;
2303}
2304
2305static ssize_t iwl_mvm_d3_test_read(struct file *file, char __user *user_buf,
2306 size_t count, loff_t *ppos)
2307{
2308 struct iwl_mvm *mvm = file->private_data;
2309 u32 pme_asserted;
2310
2311 while (true) {
Eliad Peller4ed80a82013-11-07 13:23:21 +02002312 /* read pme_ptr if available */
2313 if (mvm->d3_test_pme_ptr) {
2314 pme_asserted = iwl_trans_read_mem32(mvm->trans,
2315 mvm->d3_test_pme_ptr);
2316 if (pme_asserted)
2317 break;
2318 }
2319
Johannes Bergdebff612013-05-14 13:53:45 +02002320 if (msleep_interruptible(100))
2321 break;
2322 }
2323
2324 return 0;
2325}
2326
2327static void iwl_mvm_d3_test_disconn_work_iter(void *_data, u8 *mac,
2328 struct ieee80211_vif *vif)
2329{
Eliad Peller78c9df62013-11-07 14:13:30 +02002330 /* skip the one we keep connection on */
2331 if (_data == vif)
2332 return;
2333
Johannes Bergdebff612013-05-14 13:53:45 +02002334 if (vif->type == NL80211_IFTYPE_STATION)
2335 ieee80211_connection_loss(vif);
2336}
2337
2338static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file)
2339{
2340 struct iwl_mvm *mvm = inode->i_private;
Luca Coelho85cd69b2016-10-05 11:24:12 +03002341 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
2342 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
Johannes Bergdebff612013-05-14 13:53:45 +02002343
2344 mvm->d3_test_active = false;
Luca Coelhob7282642015-09-17 23:44:14 +03002345
Shahar S Matityahu2d8c2612018-01-29 11:05:37 +02002346 iwl_fw_dbg_read_d3_debug_data(&mvm->fwrt);
2347
Luciano Coelho31ca09d2014-09-22 13:22:51 +03002348 rtnl_lock();
Johannes Bergdebff612013-05-14 13:53:45 +02002349 __iwl_mvm_resume(mvm, true);
Luciano Coelho31ca09d2014-09-22 13:22:51 +03002350 rtnl_unlock();
Luca Coelhob7282642015-09-17 23:44:14 +03002351
Luca Coelho7d9d0d52018-04-12 16:15:07 +03002352 iwl_mvm_resume_tcm(mvm);
2353
Haim Dreyfuss7f8ae002017-12-27 15:21:18 +02002354 iwl_fw_runtime_resume(&mvm->fwrt);
2355
Luca Coelhob7282642015-09-17 23:44:14 +03002356 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED;
2357
Johannes Bergdebff612013-05-14 13:53:45 +02002358 iwl_abort_notification_waits(&mvm->notif_wait);
Luca Coelho85cd69b2016-10-05 11:24:12 +03002359 if (!unified_image) {
2360 int remaining_time = 10;
Johannes Bergdebff612013-05-14 13:53:45 +02002361
Luca Coelho85cd69b2016-10-05 11:24:12 +03002362 ieee80211_restart_hw(mvm->hw);
2363
2364 /* wait for restart and disconnect all interfaces */
2365 while (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2366 remaining_time > 0) {
2367 remaining_time--;
2368 msleep(1000);
2369 }
2370
2371 if (remaining_time == 0)
2372 IWL_ERR(mvm, "Timed out waiting for HW restart!\n");
Johannes Bergdebff612013-05-14 13:53:45 +02002373 }
2374
Johannes Bergdebff612013-05-14 13:53:45 +02002375 ieee80211_iterate_active_interfaces_atomic(
2376 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
Eliad Peller78c9df62013-11-07 14:13:30 +02002377 iwl_mvm_d3_test_disconn_work_iter, mvm->keep_vif);
Johannes Bergdebff612013-05-14 13:53:45 +02002378
Johannes Bergdebff612013-05-14 13:53:45 +02002379 return 0;
2380}
2381
2382const struct file_operations iwl_dbgfs_d3_test_ops = {
2383 .llseek = no_llseek,
2384 .open = iwl_mvm_d3_test_open,
2385 .read = iwl_mvm_d3_test_read,
2386 .release = iwl_mvm_d3_test_release,
2387};
2388#endif