1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2018-2021 Intel Corporation
4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5 * Copyright (C) 2016-2017 Intel Deutschland GmbH
7 #include <linux/etherdevice.h>
10 #include <net/cfg80211.h>
13 #include <net/addrconf.h>
14 #include "iwl-modparams.h"
19 void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw,
20 struct ieee80211_vif *vif,
21 struct cfg80211_gtk_rekey_data *data)
23 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
24 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
26 mutex_lock(&mvm->mutex);
28 mvmvif->rekey_data.kek_len = data->kek_len;
29 mvmvif->rekey_data.kck_len = data->kck_len;
30 memcpy(mvmvif->rekey_data.kek, data->kek, data->kek_len);
31 memcpy(mvmvif->rekey_data.kck, data->kck, data->kck_len);
32 mvmvif->rekey_data.akm = data->akm & 0xFF;
33 mvmvif->rekey_data.replay_ctr =
34 cpu_to_le64(be64_to_cpup((__be64 *)data->replay_ctr));
35 mvmvif->rekey_data.valid = true;
37 mutex_unlock(&mvm->mutex);
40 #if IS_ENABLED(CONFIG_IPV6)
41 void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw,
42 struct ieee80211_vif *vif,
43 struct inet6_dev *idev)
45 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
46 struct inet6_ifaddr *ifa;
49 memset(mvmvif->tentative_addrs, 0, sizeof(mvmvif->tentative_addrs));
51 read_lock_bh(&idev->lock);
52 list_for_each_entry(ifa, &idev->addr_list, if_list) {
53 mvmvif->target_ipv6_addrs[idx] = ifa->addr;
54 if (ifa->flags & IFA_F_TENTATIVE)
55 __set_bit(idx, mvmvif->tentative_addrs);
57 if (idx >= IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX)
60 read_unlock_bh(&idev->lock);
62 mvmvif->num_target_ipv6_addrs = idx;
66 void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw,
67 struct ieee80211_vif *vif, int idx)
69 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
71 mvmvif->tx_key_idx = idx;
74 static void iwl_mvm_convert_p1k(u16 *p1k, __le16 *out)
78 for (i = 0; i < IWL_P1K_SIZE; i++)
79 out[i] = cpu_to_le16(p1k[i]);
82 static const u8 *iwl_mvm_find_max_pn(struct ieee80211_key_conf *key,
83 struct iwl_mvm_key_pn *ptk_pn,
84 struct ieee80211_key_seq *seq,
87 const u8 *ret = seq->ccmp.pn;
90 /* get the PN from mac80211, used on the default queue */
91 ieee80211_get_key_rx_seq(key, tid, seq);
93 /* and use the internal data for the other queues */
94 for (i = 1; i < queues; i++) {
95 const u8 *tmp = ptk_pn->q[i].pn[tid];
97 if (memcmp(ret, tmp, IEEE80211_CCMP_PN_LEN) <= 0)
104 struct wowlan_key_data {
105 struct iwl_wowlan_rsc_tsc_params_cmd *rsc_tsc;
106 struct iwl_wowlan_tkip_params_cmd *tkip;
107 struct iwl_wowlan_kek_kck_material_cmd_v3 *kek_kck_cmd;
108 bool error, use_rsc_tsc, use_tkip, configure_keys;
112 static void iwl_mvm_wowlan_program_keys(struct ieee80211_hw *hw,
113 struct ieee80211_vif *vif,
114 struct ieee80211_sta *sta,
115 struct ieee80211_key_conf *key,
118 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
119 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
120 struct wowlan_key_data *data = _data;
121 struct aes_sc *aes_sc, *aes_tx_sc = NULL;
122 struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL;
123 struct iwl_p1k_cache *rx_p1ks;
125 struct ieee80211_key_seq seq;
127 u16 p1k[IWL_P1K_SIZE];
130 switch (key->cipher) {
131 case WLAN_CIPHER_SUITE_WEP40:
132 case WLAN_CIPHER_SUITE_WEP104: { /* hack it for now */
134 struct iwl_mvm_wep_key_cmd wep_key_cmd;
135 struct iwl_mvm_wep_key wep_key;
137 .wep_key_cmd.mac_id_n_color =
138 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
140 .wep_key_cmd.num_keys = 1,
141 /* firmware sets STA_KEY_FLG_WEP_13BYTES */
142 .wep_key_cmd.decryption_type = STA_KEY_FLG_WEP,
143 .wep_key.key_index = key->keyidx,
144 .wep_key.key_size = key->keylen,
148 * This will fail -- the key functions don't set support
149 * pairwise WEP keys. However, that's better than silently
150 * failing WoWLAN. Or maybe not?
152 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
155 memcpy(&wkc.wep_key.key[3], key->key, key->keylen);
156 if (key->keyidx == mvmvif->tx_key_idx) {
157 /* TX key must be at offset 0 */
158 wkc.wep_key.key_offset = 0;
160 /* others start at 1 */
162 wkc.wep_key.key_offset = data->wep_key_idx;
165 if (data->configure_keys) {
166 mutex_lock(&mvm->mutex);
167 ret = iwl_mvm_send_cmd_pdu(mvm, WEP_KEY, 0,
169 data->error = ret != 0;
171 mvm->ptk_ivlen = key->iv_len;
172 mvm->ptk_icvlen = key->icv_len;
173 mvm->gtk_ivlen = key->iv_len;
174 mvm->gtk_icvlen = key->icv_len;
175 mutex_unlock(&mvm->mutex);
178 /* don't upload key again */
184 case WLAN_CIPHER_SUITE_BIP_GMAC_256:
185 case WLAN_CIPHER_SUITE_BIP_GMAC_128:
186 data->kek_kck_cmd->igtk_cipher = cpu_to_le32(STA_KEY_FLG_GCMP);
188 case WLAN_CIPHER_SUITE_AES_CMAC:
189 data->kek_kck_cmd->igtk_cipher = cpu_to_le32(STA_KEY_FLG_CCM);
191 * Ignore CMAC keys -- the WoWLAN firmware doesn't support them
192 * but we also shouldn't abort suspend due to that. It does have
193 * support for the IGTK key renewal, but doesn't really use the
194 * IGTK for anything. This means we could spuriously wake up or
195 * be deauthenticated, but that was considered acceptable.
198 case WLAN_CIPHER_SUITE_TKIP:
203 data->rsc_tsc->params.all_tsc_rsc.tkip.unicast_rsc;
205 &data->rsc_tsc->params.all_tsc_rsc.tkip.tsc;
207 rx_p1ks = data->tkip->rx_uni;
209 pn64 = atomic64_read(&key->tx_pn);
210 tkip_tx_sc->iv16 = cpu_to_le16(TKIP_PN_TO_IV16(pn64));
211 tkip_tx_sc->iv32 = cpu_to_le32(TKIP_PN_TO_IV32(pn64));
213 ieee80211_get_tkip_p1k_iv(key, TKIP_PN_TO_IV32(pn64),
215 iwl_mvm_convert_p1k(p1k, data->tkip->tx.p1k);
217 memcpy(data->tkip->mic_keys.tx,
218 &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
221 rx_mic_key = data->tkip->mic_keys.rx_unicast;
224 data->rsc_tsc->params.all_tsc_rsc.tkip.multicast_rsc;
225 rx_p1ks = data->tkip->rx_multi;
226 rx_mic_key = data->tkip->mic_keys.rx_mcast;
227 data->kek_kck_cmd->gtk_cipher =
228 cpu_to_le32(STA_KEY_FLG_TKIP);
232 * For non-QoS this relies on the fact that both the uCode and
233 * mac80211 use TID 0 (as they need to to avoid replay attacks)
234 * for checking the IV in the frames.
236 for (i = 0; i < IWL_NUM_RSC; i++) {
237 ieee80211_get_key_rx_seq(key, i, &seq);
238 tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16);
239 tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32);
240 /* wrapping isn't allowed, AP must rekey */
241 if (seq.tkip.iv32 > cur_rx_iv32)
242 cur_rx_iv32 = seq.tkip.iv32;
245 ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid,
247 iwl_mvm_convert_p1k(p1k, rx_p1ks[0].p1k);
248 ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid,
249 cur_rx_iv32 + 1, p1k);
250 iwl_mvm_convert_p1k(p1k, rx_p1ks[1].p1k);
253 &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
256 data->use_tkip = true;
257 data->use_rsc_tsc = true;
259 case WLAN_CIPHER_SUITE_CCMP:
260 case WLAN_CIPHER_SUITE_GCMP:
261 case WLAN_CIPHER_SUITE_GCMP_256:
266 data->rsc_tsc->params.all_tsc_rsc.aes.unicast_rsc;
268 &data->rsc_tsc->params.all_tsc_rsc.aes.tsc;
270 pn64 = atomic64_read(&key->tx_pn);
271 aes_tx_sc->pn = cpu_to_le64(pn64);
274 data->rsc_tsc->params.all_tsc_rsc.aes.multicast_rsc;
275 data->kek_kck_cmd->gtk_cipher =
276 key->cipher == WLAN_CIPHER_SUITE_CCMP ?
277 cpu_to_le32(STA_KEY_FLG_CCM) :
278 cpu_to_le32(STA_KEY_FLG_GCMP);
282 * For non-QoS this relies on the fact that both the uCode and
283 * mac80211/our RX code use TID 0 for checking the PN.
285 if (sta && iwl_mvm_has_new_rx_api(mvm)) {
286 struct iwl_mvm_sta *mvmsta;
287 struct iwl_mvm_key_pn *ptk_pn;
290 mvmsta = iwl_mvm_sta_from_mac80211(sta);
292 ptk_pn = rcu_dereference(mvmsta->ptk_pn[key->keyidx]);
293 if (WARN_ON(!ptk_pn)) {
298 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
299 pn = iwl_mvm_find_max_pn(key, ptk_pn, &seq, i,
300 mvm->trans->num_rx_queues);
301 aes_sc[i].pn = cpu_to_le64((u64)pn[5] |
311 for (i = 0; i < IWL_NUM_RSC; i++) {
312 u8 *pn = seq.ccmp.pn;
314 ieee80211_get_key_rx_seq(key, i, &seq);
315 aes_sc[i].pn = cpu_to_le64((u64)pn[5] |
323 data->use_rsc_tsc = true;
327 IWL_DEBUG_WOWLAN(mvm, "GTK cipher %d\n", data->kek_kck_cmd->gtk_cipher);
329 if (data->configure_keys) {
330 mutex_lock(&mvm->mutex);
332 * The D3 firmware hardcodes the key offset 0 as the key it
333 * uses to transmit packets to the AP, i.e. the PTK.
335 if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) {
336 mvm->ptk_ivlen = key->iv_len;
337 mvm->ptk_icvlen = key->icv_len;
338 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, 0);
341 * firmware only supports TSC/RSC for a single key,
342 * so if there are multiple keep overwriting them
343 * with new ones -- this relies on mac80211 doing
346 mvm->gtk_ivlen = key->iv_len;
347 mvm->gtk_icvlen = key->icv_len;
348 ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, 1);
350 mutex_unlock(&mvm->mutex);
351 data->error = ret != 0;
355 static int iwl_mvm_send_patterns_v1(struct iwl_mvm *mvm,
356 struct cfg80211_wowlan *wowlan)
358 struct iwl_wowlan_patterns_cmd_v1 *pattern_cmd;
359 struct iwl_host_cmd cmd = {
360 .id = WOWLAN_PATTERNS,
361 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
365 if (!wowlan->n_patterns)
368 cmd.len[0] = struct_size(pattern_cmd, patterns, wowlan->n_patterns);
370 pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
374 pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
376 for (i = 0; i < wowlan->n_patterns; i++) {
377 int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
379 memcpy(&pattern_cmd->patterns[i].mask,
380 wowlan->patterns[i].mask, mask_len);
381 memcpy(&pattern_cmd->patterns[i].pattern,
382 wowlan->patterns[i].pattern,
383 wowlan->patterns[i].pattern_len);
384 pattern_cmd->patterns[i].mask_size = mask_len;
385 pattern_cmd->patterns[i].pattern_size =
386 wowlan->patterns[i].pattern_len;
389 cmd.data[0] = pattern_cmd;
390 err = iwl_mvm_send_cmd(mvm, &cmd);
395 static int iwl_mvm_send_patterns(struct iwl_mvm *mvm,
396 struct cfg80211_wowlan *wowlan)
398 struct iwl_wowlan_patterns_cmd *pattern_cmd;
399 struct iwl_host_cmd cmd = {
400 .id = WOWLAN_PATTERNS,
401 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
405 if (!wowlan->n_patterns)
408 cmd.len[0] = sizeof(*pattern_cmd) +
409 wowlan->n_patterns * sizeof(struct iwl_wowlan_pattern_v2);
411 pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
415 pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
417 for (i = 0; i < wowlan->n_patterns; i++) {
418 int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
420 pattern_cmd->patterns[i].pattern_type =
421 WOWLAN_PATTERN_TYPE_BITMASK;
423 memcpy(&pattern_cmd->patterns[i].u.bitmask.mask,
424 wowlan->patterns[i].mask, mask_len);
425 memcpy(&pattern_cmd->patterns[i].u.bitmask.pattern,
426 wowlan->patterns[i].pattern,
427 wowlan->patterns[i].pattern_len);
428 pattern_cmd->patterns[i].u.bitmask.mask_size = mask_len;
429 pattern_cmd->patterns[i].u.bitmask.pattern_size =
430 wowlan->patterns[i].pattern_len;
433 cmd.data[0] = pattern_cmd;
434 err = iwl_mvm_send_cmd(mvm, &cmd);
439 static int iwl_mvm_d3_reprogram(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
440 struct ieee80211_sta *ap_sta)
442 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
443 struct ieee80211_chanctx_conf *ctx;
444 u8 chains_static, chains_dynamic;
445 struct cfg80211_chan_def chandef;
447 struct iwl_binding_cmd_v1 binding_cmd = {};
448 struct iwl_time_quota_cmd quota_cmd = {};
449 struct iwl_time_quota_data *quota;
452 if (WARN_ON_ONCE(iwl_mvm_is_cdb_supported(mvm)))
455 /* add back the PHY */
456 if (WARN_ON(!mvmvif->phy_ctxt))
460 ctx = rcu_dereference(vif->chanctx_conf);
466 chains_static = ctx->rx_chains_static;
467 chains_dynamic = ctx->rx_chains_dynamic;
470 ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt, &chandef,
471 chains_static, chains_dynamic);
475 /* add back the MAC */
476 mvmvif->uploaded = false;
478 if (WARN_ON(!vif->bss_conf.assoc))
481 ret = iwl_mvm_mac_ctxt_add(mvm, vif);
485 /* add back binding - XXX refactor? */
486 binding_cmd.id_and_color =
487 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
488 mvmvif->phy_ctxt->color));
489 binding_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD);
491 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
492 mvmvif->phy_ctxt->color));
493 binding_cmd.macs[0] = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
495 for (i = 1; i < MAX_MACS_IN_BINDING; i++)
496 binding_cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID);
499 ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD,
500 IWL_BINDING_CMD_SIZE_V1, &binding_cmd,
503 IWL_ERR(mvm, "Failed to add binding: %d\n", ret);
508 IWL_ERR(mvm, "Binding command failed: %u\n", status);
512 ret = iwl_mvm_sta_send_to_fw(mvm, ap_sta, false, 0);
515 rcu_assign_pointer(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], ap_sta);
517 ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
522 quota = iwl_mvm_quota_cmd_get_quota(mvm, "a_cmd, 0);
523 quota->id_and_color =
524 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id,
525 mvmvif->phy_ctxt->color));
526 quota->quota = cpu_to_le32(IWL_MVM_MAX_QUOTA);
527 quota->max_duration = cpu_to_le32(IWL_MVM_MAX_QUOTA);
529 for (i = 1; i < MAX_BINDINGS; i++) {
530 quota = iwl_mvm_quota_cmd_get_quota(mvm, "a_cmd, i);
531 quota->id_and_color = cpu_to_le32(FW_CTXT_INVALID);
534 ret = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, 0,
535 iwl_mvm_quota_cmd_size(mvm), "a_cmd);
537 IWL_ERR(mvm, "Failed to send quota: %d\n", ret);
539 if (iwl_mvm_is_lar_supported(mvm) && iwl_mvm_init_fw_regd(mvm))
540 IWL_ERR(mvm, "Failed to initialize D3 LAR information\n");
545 static int iwl_mvm_get_last_nonqos_seq(struct iwl_mvm *mvm,
546 struct ieee80211_vif *vif)
548 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
549 struct iwl_nonqos_seq_query_cmd query_cmd = {
550 .get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_GET),
552 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
555 struct iwl_host_cmd cmd = {
556 .id = NON_QOS_TX_COUNTER_CMD,
557 .flags = CMD_WANT_SKB,
562 cmd.data[0] = &query_cmd;
563 cmd.len[0] = sizeof(query_cmd);
565 err = iwl_mvm_send_cmd(mvm, &cmd);
569 size = iwl_rx_packet_payload_len(cmd.resp_pkt);
570 if (size < sizeof(__le16)) {
573 err = le16_to_cpup((__le16 *)cmd.resp_pkt->data);
574 /* firmware returns next, not last-used seqno */
575 err = (u16) (err - 0x10);
582 void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
584 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
585 struct iwl_nonqos_seq_query_cmd query_cmd = {
586 .get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_SET),
588 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id,
590 .value = cpu_to_le16(mvmvif->seqno),
593 /* return if called during restart, not resume from D3 */
594 if (!mvmvif->seqno_valid)
597 mvmvif->seqno_valid = false;
599 if (iwl_mvm_send_cmd_pdu(mvm, NON_QOS_TX_COUNTER_CMD, 0,
600 sizeof(query_cmd), &query_cmd))
601 IWL_ERR(mvm, "failed to set non-QoS seqno\n");
604 static int iwl_mvm_switch_to_d3(struct iwl_mvm *mvm)
606 iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
608 iwl_mvm_stop_device(mvm);
610 * Set the HW restart bit -- this is mostly true as we're
611 * going to load new firmware and reprogram that, though
612 * the reprogramming is going to be manual to avoid adding
613 * all the MACs that aren't support.
614 * We don't have to clear up everything though because the
615 * reprogramming is manual. When we resume, we'll actually
616 * go through a proper restart sequence again to switch
617 * back to the runtime firmware image.
619 set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
621 /* the fw is reset, so all the keys are cleared */
622 memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table));
629 return iwl_mvm_load_d3_fw(mvm);
633 iwl_mvm_get_wowlan_config(struct iwl_mvm *mvm,
634 struct cfg80211_wowlan *wowlan,
635 struct iwl_wowlan_config_cmd *wowlan_config_cmd,
636 struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif,
637 struct ieee80211_sta *ap_sta)
640 struct iwl_mvm_sta *mvm_ap_sta = iwl_mvm_sta_from_mac80211(ap_sta);
642 /* TODO: wowlan_config_cmd->wowlan_ba_teardown_tids */
644 wowlan_config_cmd->is_11n_connection =
645 ap_sta->ht_cap.ht_supported;
646 wowlan_config_cmd->flags = ENABLE_L3_FILTERING |
647 ENABLE_NBNS_FILTERING | ENABLE_DHCP_FILTERING;
649 /* Query the last used seqno and set it */
650 ret = iwl_mvm_get_last_nonqos_seq(mvm, vif);
654 wowlan_config_cmd->non_qos_seq = cpu_to_le16(ret);
656 iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, wowlan_config_cmd);
658 if (wowlan->disconnect)
659 wowlan_config_cmd->wakeup_filter |=
660 cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS |
661 IWL_WOWLAN_WAKEUP_LINK_CHANGE);
662 if (wowlan->magic_pkt)
663 wowlan_config_cmd->wakeup_filter |=
664 cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET);
665 if (wowlan->gtk_rekey_failure)
666 wowlan_config_cmd->wakeup_filter |=
667 cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL);
668 if (wowlan->eap_identity_req)
669 wowlan_config_cmd->wakeup_filter |=
670 cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ);
671 if (wowlan->four_way_handshake)
672 wowlan_config_cmd->wakeup_filter |=
673 cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE);
674 if (wowlan->n_patterns)
675 wowlan_config_cmd->wakeup_filter |=
676 cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH);
678 if (wowlan->rfkill_release)
679 wowlan_config_cmd->wakeup_filter |=
680 cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT);
684 * Set the "link change" (really "link lost") flag as well
685 * since that implies losing the TCP connection.
687 wowlan_config_cmd->wakeup_filter |=
688 cpu_to_le32(IWL_WOWLAN_WAKEUP_REMOTE_LINK_LOSS |
689 IWL_WOWLAN_WAKEUP_REMOTE_SIGNATURE_TABLE |
690 IWL_WOWLAN_WAKEUP_REMOTE_WAKEUP_PACKET |
691 IWL_WOWLAN_WAKEUP_LINK_CHANGE);
695 wowlan_config_cmd->wakeup_filter |=
696 cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS |
697 IWL_WOWLAN_WAKEUP_LINK_CHANGE |
698 IWL_WOWLAN_WAKEUP_RX_FRAME |
699 IWL_WOWLAN_WAKEUP_BCN_FILTERING);
705 static int iwl_mvm_wowlan_config_key_params(struct iwl_mvm *mvm,
706 struct ieee80211_vif *vif,
709 struct iwl_wowlan_kek_kck_material_cmd_v3 kek_kck_cmd = {};
710 struct iwl_wowlan_tkip_params_cmd tkip_cmd = {};
711 bool unified = fw_has_capa(&mvm->fw->ucode_capa,
712 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
713 struct wowlan_key_data key_data = {
714 .configure_keys = !unified,
715 .use_rsc_tsc = false,
718 .kek_kck_cmd = &kek_kck_cmd,
720 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
725 key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
726 if (!key_data.rsc_tsc)
730 * if we have to configure keys, call ieee80211_iter_keys(),
731 * as we need non-atomic context in order to take the
735 * Note that currently we don't propagate cmd_flags
736 * to the iterator. In case of key_data.configure_keys,
737 * all the configured commands are SYNC, and
738 * iwl_mvm_wowlan_program_keys() will take care of
739 * locking/unlocking mvm->mutex.
741 ieee80211_iter_keys(mvm->hw, vif, iwl_mvm_wowlan_program_keys,
744 if (key_data.error) {
749 if (key_data.use_rsc_tsc) {
750 int ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
751 WOWLAN_TSC_RSC_PARAM,
752 IWL_FW_CMD_VER_UNKNOWN);
756 size = sizeof(*key_data.rsc_tsc);
757 key_data.rsc_tsc->sta_id =
758 cpu_to_le32(mvmvif->ap_sta_id);
760 } else if (ver == 2 || ver == IWL_FW_CMD_VER_UNKNOWN) {
761 size = sizeof(key_data.rsc_tsc->params);
768 ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_TSC_RSC_PARAM,
777 if (key_data.use_tkip &&
778 !fw_has_api(&mvm->fw->ucode_capa,
779 IWL_UCODE_TLV_API_TKIP_MIC_KEYS)) {
780 int ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
782 IWL_FW_CMD_VER_UNKNOWN);
786 size = sizeof(tkip_cmd);
787 key_data.tkip->sta_id =
788 cpu_to_le32(mvmvif->ap_sta_id);
789 } else if (ver == 1 || ver == IWL_FW_CMD_VER_UNKNOWN) {
790 size = sizeof(struct iwl_wowlan_tkip_params_cmd_ver_1);
797 /* send relevant data according to CMD version */
798 ret = iwl_mvm_send_cmd_pdu(mvm,
806 /* configure rekey data only if offloaded rekey is supported (d3) */
807 if (mvmvif->rekey_data.valid) {
808 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw,
809 IWL_ALWAYS_LONG_GROUP,
810 WOWLAN_KEK_KCK_MATERIAL,
811 IWL_FW_CMD_VER_UNKNOWN);
812 if (WARN_ON(cmd_ver != 2 && cmd_ver != 3 &&
813 cmd_ver != IWL_FW_CMD_VER_UNKNOWN))
816 cmd_size = sizeof(struct iwl_wowlan_kek_kck_material_cmd_v3);
818 cmd_size = sizeof(struct iwl_wowlan_kek_kck_material_cmd_v2);
820 memcpy(kek_kck_cmd.kck, mvmvif->rekey_data.kck,
821 mvmvif->rekey_data.kck_len);
822 kek_kck_cmd.kck_len = cpu_to_le16(mvmvif->rekey_data.kck_len);
823 memcpy(kek_kck_cmd.kek, mvmvif->rekey_data.kek,
824 mvmvif->rekey_data.kek_len);
825 kek_kck_cmd.kek_len = cpu_to_le16(mvmvif->rekey_data.kek_len);
826 kek_kck_cmd.replay_ctr = mvmvif->rekey_data.replay_ctr;
827 kek_kck_cmd.akm = cpu_to_le32(mvmvif->rekey_data.akm);
829 IWL_DEBUG_WOWLAN(mvm, "setting akm %d\n",
830 mvmvif->rekey_data.akm);
832 ret = iwl_mvm_send_cmd_pdu(mvm,
833 WOWLAN_KEK_KCK_MATERIAL, cmd_flags,
841 kfree(key_data.rsc_tsc);
846 iwl_mvm_wowlan_config(struct iwl_mvm *mvm,
847 struct cfg80211_wowlan *wowlan,
848 struct iwl_wowlan_config_cmd *wowlan_config_cmd,
849 struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif,
850 struct ieee80211_sta *ap_sta)
853 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
854 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
856 mvm->offload_tid = wowlan_config_cmd->offloading_tid;
858 if (!unified_image) {
859 ret = iwl_mvm_switch_to_d3(mvm);
863 ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta);
869 * This needs to be unlocked due to lock ordering
870 * constraints. Since we're in the suspend path
871 * that isn't really a problem though.
873 mutex_unlock(&mvm->mutex);
874 ret = iwl_mvm_wowlan_config_key_params(mvm, vif, CMD_ASYNC);
875 mutex_lock(&mvm->mutex);
879 ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0,
880 sizeof(*wowlan_config_cmd),
885 if (fw_has_api(&mvm->fw->ucode_capa,
886 IWL_UCODE_TLV_API_WOWLAN_TCP_SYN_WAKE))
887 ret = iwl_mvm_send_patterns(mvm, wowlan);
889 ret = iwl_mvm_send_patterns_v1(mvm, wowlan);
893 return iwl_mvm_send_proto_offload(mvm, vif, false, true, 0);
897 iwl_mvm_netdetect_config(struct iwl_mvm *mvm,
898 struct cfg80211_wowlan *wowlan,
899 struct cfg80211_sched_scan_request *nd_config,
900 struct ieee80211_vif *vif)
903 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
904 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
906 if (!unified_image) {
907 ret = iwl_mvm_switch_to_d3(mvm);
911 /* In theory, we wouldn't have to stop a running sched
912 * scan in order to start another one (for
913 * net-detect). But in practice this doesn't seem to
914 * work properly, so stop any running sched_scan now.
916 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true);
921 ret = iwl_mvm_sched_scan_start(mvm, vif, nd_config, &mvm->nd_ies,
922 IWL_MVM_SCAN_NETDETECT);
926 if (WARN_ON(mvm->nd_match_sets || mvm->nd_channels))
929 /* save the sched scan matchsets... */
930 if (nd_config->n_match_sets) {
931 mvm->nd_match_sets = kmemdup(nd_config->match_sets,
932 sizeof(*nd_config->match_sets) *
933 nd_config->n_match_sets,
935 if (mvm->nd_match_sets)
936 mvm->n_nd_match_sets = nd_config->n_match_sets;
939 /* ...and the sched scan channels for later reporting */
940 mvm->nd_channels = kmemdup(nd_config->channels,
941 sizeof(*nd_config->channels) *
942 nd_config->n_channels,
944 if (mvm->nd_channels)
945 mvm->n_nd_channels = nd_config->n_channels;
950 static void iwl_mvm_free_nd(struct iwl_mvm *mvm)
952 kfree(mvm->nd_match_sets);
953 mvm->nd_match_sets = NULL;
954 mvm->n_nd_match_sets = 0;
955 kfree(mvm->nd_channels);
956 mvm->nd_channels = NULL;
957 mvm->n_nd_channels = 0;
960 static int __iwl_mvm_suspend(struct ieee80211_hw *hw,
961 struct cfg80211_wowlan *wowlan,
964 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
965 struct ieee80211_vif *vif = NULL;
966 struct iwl_mvm_vif *mvmvif = NULL;
967 struct ieee80211_sta *ap_sta = NULL;
968 struct iwl_d3_manager_config d3_cfg_cmd_data = {
970 * Program the minimum sleep time to 10 seconds, as many
971 * platforms have issues processing a wakeup signal while
972 * still being in the process of suspending.
974 .min_sleep_time = cpu_to_le32(10 * 1000 * 1000),
976 struct iwl_host_cmd d3_cfg_cmd = {
978 .flags = CMD_WANT_SKB,
979 .data[0] = &d3_cfg_cmd_data,
980 .len[0] = sizeof(d3_cfg_cmd_data),
983 int len __maybe_unused;
984 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
985 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
989 * mac80211 shouldn't get here, but for D3 test
990 * it doesn't warrant a warning
996 mutex_lock(&mvm->mutex);
998 set_bit(IWL_MVM_STATUS_IN_D3, &mvm->status);
1000 vif = iwl_mvm_get_bss_vif(mvm);
1001 if (IS_ERR_OR_NULL(vif)) {
1006 mvmvif = iwl_mvm_vif_from_mac80211(vif);
1008 if (mvmvif->ap_sta_id == IWL_MVM_INVALID_STA) {
1009 /* if we're not associated, this must be netdetect */
1010 if (!wowlan->nd_config) {
1015 ret = iwl_mvm_netdetect_config(
1016 mvm, wowlan, wowlan->nd_config, vif);
1020 mvm->net_detect = true;
1022 struct iwl_wowlan_config_cmd wowlan_config_cmd = {};
1024 wowlan_config_cmd.sta_id = mvmvif->ap_sta_id;
1026 ap_sta = rcu_dereference_protected(
1027 mvm->fw_id_to_mac_id[mvmvif->ap_sta_id],
1028 lockdep_is_held(&mvm->mutex));
1029 if (IS_ERR_OR_NULL(ap_sta)) {
1034 ret = iwl_mvm_get_wowlan_config(mvm, wowlan, &wowlan_config_cmd,
1035 vif, mvmvif, ap_sta);
1038 ret = iwl_mvm_wowlan_config(mvm, wowlan, &wowlan_config_cmd,
1039 vif, mvmvif, ap_sta);
1043 mvm->net_detect = false;
1046 ret = iwl_mvm_power_update_device(mvm);
1050 ret = iwl_mvm_power_update_mac(mvm);
1054 #ifdef CONFIG_IWLWIFI_DEBUGFS
1055 if (mvm->d3_wake_sysassert)
1056 d3_cfg_cmd_data.wakeup_flags |=
1057 cpu_to_le32(IWL_WAKEUP_D3_CONFIG_FW_ERROR);
1061 * Prior to 9000 device family the driver needs to stop the dbg
1062 * recording before entering D3. In later devices the FW stops the
1063 * recording automatically.
1065 if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_9000)
1066 iwl_fw_dbg_stop_restart_recording(&mvm->fwrt, NULL, true);
1068 /* must be last -- this switches firmware state */
1069 ret = iwl_mvm_send_cmd(mvm, &d3_cfg_cmd);
1072 #ifdef CONFIG_IWLWIFI_DEBUGFS
1073 len = iwl_rx_packet_payload_len(d3_cfg_cmd.resp_pkt);
1074 if (len >= sizeof(u32)) {
1075 mvm->d3_test_pme_ptr =
1076 le32_to_cpup((__le32 *)d3_cfg_cmd.resp_pkt->data);
1079 iwl_free_resp(&d3_cfg_cmd);
1081 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
1083 ret = iwl_trans_d3_suspend(mvm->trans, test, !unified_image);
1086 iwl_mvm_free_nd(mvm);
1088 if (!unified_image) {
1089 if (mvm->fw_restart > 0) {
1091 ieee80211_restart_hw(mvm->hw);
1095 clear_bit(IWL_MVM_STATUS_IN_D3, &mvm->status);
1098 mutex_unlock(&mvm->mutex);
1103 int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
1105 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
1106 struct iwl_trans *trans = mvm->trans;
1109 iwl_mvm_pause_tcm(mvm, true);
1111 iwl_fw_runtime_suspend(&mvm->fwrt);
1113 ret = iwl_trans_suspend(trans);
1117 trans->system_pm_mode = IWL_PLAT_PM_MODE_D3;
1119 return __iwl_mvm_suspend(hw, wowlan, false);
1122 /* converted data from the different status responses */
1123 struct iwl_wowlan_status_data {
1127 u32 wake_packet_length;
1128 u32 wake_packet_bufsize;
1129 const u8 *wake_packet;
1132 static void iwl_mvm_report_wakeup_reasons(struct iwl_mvm *mvm,
1133 struct ieee80211_vif *vif,
1134 struct iwl_wowlan_status_data *status)
1136 struct sk_buff *pkt = NULL;
1137 struct cfg80211_wowlan_wakeup wakeup = {
1140 struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup;
1141 u32 reasons = status->wakeup_reasons;
1143 if (reasons == IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) {
1144 wakeup_report = NULL;
1148 pm_wakeup_event(mvm->dev, 0);
1150 if (reasons & IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET)
1151 wakeup.magic_pkt = true;
1153 if (reasons & IWL_WOWLAN_WAKEUP_BY_PATTERN)
1154 wakeup.pattern_idx =
1155 status->pattern_number;
1157 if (reasons & (IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON |
1158 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH))
1159 wakeup.disconnect = true;
1161 if (reasons & IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE)
1162 wakeup.gtk_rekey_failure = true;
1164 if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED)
1165 wakeup.rfkill_release = true;
1167 if (reasons & IWL_WOWLAN_WAKEUP_BY_EAPOL_REQUEST)
1168 wakeup.eap_identity_req = true;
1170 if (reasons & IWL_WOWLAN_WAKEUP_BY_FOUR_WAY_HANDSHAKE)
1171 wakeup.four_way_handshake = true;
1173 if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_LINK_LOSS)
1174 wakeup.tcp_connlost = true;
1176 if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_SIGNATURE_TABLE)
1177 wakeup.tcp_nomoretokens = true;
1179 if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_WAKEUP_PACKET)
1180 wakeup.tcp_match = true;
1182 if (status->wake_packet_bufsize) {
1183 int pktsize = status->wake_packet_bufsize;
1184 int pktlen = status->wake_packet_length;
1185 const u8 *pktdata = status->wake_packet;
1186 struct ieee80211_hdr *hdr = (void *)pktdata;
1187 int truncated = pktlen - pktsize;
1189 /* this would be a firmware bug */
1190 if (WARN_ON_ONCE(truncated < 0))
1193 if (ieee80211_is_data(hdr->frame_control)) {
1194 int hdrlen = ieee80211_hdrlen(hdr->frame_control);
1195 int ivlen = 0, icvlen = 4; /* also FCS */
1197 pkt = alloc_skb(pktsize, GFP_KERNEL);
1201 skb_put_data(pkt, pktdata, hdrlen);
1205 if (ieee80211_has_protected(hdr->frame_control)) {
1207 * This is unlocked and using gtk_i(c)vlen,
1208 * but since everything is under RTNL still
1209 * that's not really a problem - changing
1210 * it would be difficult.
1212 if (is_multicast_ether_addr(hdr->addr1)) {
1213 ivlen = mvm->gtk_ivlen;
1214 icvlen += mvm->gtk_icvlen;
1216 ivlen = mvm->ptk_ivlen;
1217 icvlen += mvm->ptk_icvlen;
1221 /* if truncated, FCS/ICV is (partially) gone */
1222 if (truncated >= icvlen) {
1224 truncated -= icvlen;
1226 icvlen -= truncated;
1230 pktsize -= ivlen + icvlen;
1233 skb_put_data(pkt, pktdata, pktsize);
1235 if (ieee80211_data_to_8023(pkt, vif->addr, vif->type))
1237 wakeup.packet = pkt->data;
1238 wakeup.packet_present_len = pkt->len;
1239 wakeup.packet_len = pkt->len - truncated;
1240 wakeup.packet_80211 = false;
1244 if (truncated >= 4) {
1248 fcslen -= truncated;
1252 wakeup.packet = status->wake_packet;
1253 wakeup.packet_present_len = pktsize;
1254 wakeup.packet_len = pktlen - truncated;
1255 wakeup.packet_80211 = true;
1260 ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL);
1264 static void iwl_mvm_aes_sc_to_seq(struct aes_sc *sc,
1265 struct ieee80211_key_seq *seq)
1269 pn = le64_to_cpu(sc->pn);
1270 seq->ccmp.pn[0] = pn >> 40;
1271 seq->ccmp.pn[1] = pn >> 32;
1272 seq->ccmp.pn[2] = pn >> 24;
1273 seq->ccmp.pn[3] = pn >> 16;
1274 seq->ccmp.pn[4] = pn >> 8;
1275 seq->ccmp.pn[5] = pn;
1278 static void iwl_mvm_tkip_sc_to_seq(struct tkip_sc *sc,
1279 struct ieee80211_key_seq *seq)
1281 seq->tkip.iv32 = le32_to_cpu(sc->iv32);
1282 seq->tkip.iv16 = le16_to_cpu(sc->iv16);
1285 static void iwl_mvm_set_aes_rx_seq(struct iwl_mvm *mvm, struct aes_sc *scs,
1286 struct ieee80211_sta *sta,
1287 struct ieee80211_key_conf *key)
1291 BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS);
1293 if (sta && iwl_mvm_has_new_rx_api(mvm)) {
1294 struct iwl_mvm_sta *mvmsta;
1295 struct iwl_mvm_key_pn *ptk_pn;
1297 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1300 ptk_pn = rcu_dereference(mvmsta->ptk_pn[key->keyidx]);
1301 if (WARN_ON(!ptk_pn)) {
1306 for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
1307 struct ieee80211_key_seq seq = {};
1310 iwl_mvm_aes_sc_to_seq(&scs[tid], &seq);
1311 ieee80211_set_key_rx_seq(key, tid, &seq);
1312 for (i = 1; i < mvm->trans->num_rx_queues; i++)
1313 memcpy(ptk_pn->q[i].pn[tid],
1314 seq.ccmp.pn, IEEE80211_CCMP_PN_LEN);
1318 for (tid = 0; tid < IWL_NUM_RSC; tid++) {
1319 struct ieee80211_key_seq seq = {};
1321 iwl_mvm_aes_sc_to_seq(&scs[tid], &seq);
1322 ieee80211_set_key_rx_seq(key, tid, &seq);
1327 static void iwl_mvm_set_tkip_rx_seq(struct tkip_sc *scs,
1328 struct ieee80211_key_conf *key)
1332 BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS);
1334 for (tid = 0; tid < IWL_NUM_RSC; tid++) {
1335 struct ieee80211_key_seq seq = {};
1337 iwl_mvm_tkip_sc_to_seq(&scs[tid], &seq);
1338 ieee80211_set_key_rx_seq(key, tid, &seq);
1342 static void iwl_mvm_set_key_rx_seq(struct iwl_mvm *mvm,
1343 struct ieee80211_key_conf *key,
1344 struct iwl_wowlan_status *status)
1346 union iwl_all_tsc_rsc *rsc = &status->gtk[0].rsc.all_tsc_rsc;
1348 switch (key->cipher) {
1349 case WLAN_CIPHER_SUITE_CCMP:
1350 case WLAN_CIPHER_SUITE_GCMP:
1351 case WLAN_CIPHER_SUITE_GCMP_256:
1352 iwl_mvm_set_aes_rx_seq(mvm, rsc->aes.multicast_rsc, NULL, key);
1354 case WLAN_CIPHER_SUITE_TKIP:
1355 iwl_mvm_set_tkip_rx_seq(rsc->tkip.multicast_rsc, key);
1362 struct iwl_mvm_d3_gtk_iter_data {
1363 struct iwl_mvm *mvm;
1364 struct iwl_wowlan_status *status;
1367 bool find_phase, unhandled_cipher;
1371 static void iwl_mvm_d3_update_keys(struct ieee80211_hw *hw,
1372 struct ieee80211_vif *vif,
1373 struct ieee80211_sta *sta,
1374 struct ieee80211_key_conf *key,
1377 struct iwl_mvm_d3_gtk_iter_data *data = _data;
1379 if (data->unhandled_cipher)
1382 switch (key->cipher) {
1383 case WLAN_CIPHER_SUITE_WEP40:
1384 case WLAN_CIPHER_SUITE_WEP104:
1385 /* ignore WEP completely, nothing to do */
1387 case WLAN_CIPHER_SUITE_CCMP:
1388 case WLAN_CIPHER_SUITE_GCMP:
1389 case WLAN_CIPHER_SUITE_GCMP_256:
1390 case WLAN_CIPHER_SUITE_TKIP:
1391 /* we support these */
1394 /* everything else (even CMAC for MFP) - disconnect from AP */
1395 data->unhandled_cipher = true;
1402 * pairwise key - update sequence counters only;
1403 * note that this assumes no TDLS sessions are active
1406 struct ieee80211_key_seq seq = {};
1407 union iwl_all_tsc_rsc *sc =
1408 &data->status->gtk[0].rsc.all_tsc_rsc;
1410 if (data->find_phase)
1413 switch (key->cipher) {
1414 case WLAN_CIPHER_SUITE_CCMP:
1415 case WLAN_CIPHER_SUITE_GCMP:
1416 case WLAN_CIPHER_SUITE_GCMP_256:
1417 iwl_mvm_set_aes_rx_seq(data->mvm, sc->aes.unicast_rsc,
1419 atomic64_set(&key->tx_pn, le64_to_cpu(sc->aes.tsc.pn));
1421 case WLAN_CIPHER_SUITE_TKIP:
1422 iwl_mvm_tkip_sc_to_seq(&sc->tkip.tsc, &seq);
1423 iwl_mvm_set_tkip_rx_seq(sc->tkip.unicast_rsc, key);
1424 atomic64_set(&key->tx_pn,
1425 (u64)seq.tkip.iv16 |
1426 ((u64)seq.tkip.iv32 << 16));
1430 /* that's it for this key */
1434 if (data->find_phase) {
1435 data->last_gtk = key;
1436 data->cipher = key->cipher;
1440 if (data->status->num_of_gtk_rekeys)
1441 ieee80211_remove_key(key);
1442 else if (data->last_gtk == key)
1443 iwl_mvm_set_key_rx_seq(data->mvm, key, data->status);
1446 static bool iwl_mvm_setup_connection_keep(struct iwl_mvm *mvm,
1447 struct ieee80211_vif *vif,
1448 struct iwl_wowlan_status *status)
1450 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1451 struct iwl_mvm_d3_gtk_iter_data gtkdata = {
1455 u32 disconnection_reasons =
1456 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON |
1457 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH;
1459 if (!status || !vif->bss_conf.bssid)
1462 if (le32_to_cpu(status->wakeup_reasons) & disconnection_reasons)
1465 /* find last GTK that we used initially, if any */
1466 gtkdata.find_phase = true;
1467 ieee80211_iter_keys(mvm->hw, vif,
1468 iwl_mvm_d3_update_keys, >kdata);
1469 /* not trying to keep connections with MFP/unhandled ciphers */
1470 if (gtkdata.unhandled_cipher)
1472 if (!gtkdata.num_keys)
1474 if (!gtkdata.last_gtk)
1478 * invalidate all other GTKs that might still exist and update
1479 * the one that we used
1481 gtkdata.find_phase = false;
1482 ieee80211_iter_keys(mvm->hw, vif,
1483 iwl_mvm_d3_update_keys, >kdata);
1485 IWL_DEBUG_WOWLAN(mvm, "num of GTK rekeying %d\n",
1486 le32_to_cpu(status->num_of_gtk_rekeys));
1487 if (status->num_of_gtk_rekeys) {
1488 struct ieee80211_key_conf *key;
1490 struct ieee80211_key_conf conf;
1493 .conf.cipher = gtkdata.cipher,
1495 iwlmvm_wowlan_gtk_idx(&status->gtk[0]),
1499 IWL_DEBUG_WOWLAN(mvm,
1500 "Received from FW GTK cipher %d, key index %d\n",
1501 conf.conf.cipher, conf.conf.keyidx);
1502 switch (gtkdata.cipher) {
1503 case WLAN_CIPHER_SUITE_CCMP:
1504 case WLAN_CIPHER_SUITE_GCMP:
1505 BUILD_BUG_ON(WLAN_KEY_LEN_CCMP != WLAN_KEY_LEN_GCMP);
1506 BUILD_BUG_ON(sizeof(conf.key) < WLAN_KEY_LEN_CCMP);
1507 conf.conf.keylen = WLAN_KEY_LEN_CCMP;
1508 memcpy(conf.conf.key, status->gtk[0].key,
1511 case WLAN_CIPHER_SUITE_GCMP_256:
1512 BUILD_BUG_ON(sizeof(conf.key) < WLAN_KEY_LEN_GCMP_256);
1513 conf.conf.keylen = WLAN_KEY_LEN_GCMP_256;
1514 memcpy(conf.conf.key, status->gtk[0].key,
1515 WLAN_KEY_LEN_GCMP_256);
1517 case WLAN_CIPHER_SUITE_TKIP:
1518 BUILD_BUG_ON(sizeof(conf.key) < WLAN_KEY_LEN_TKIP);
1519 conf.conf.keylen = WLAN_KEY_LEN_TKIP;
1520 memcpy(conf.conf.key, status->gtk[0].key, 16);
1521 /* leave TX MIC key zeroed, we don't use it anyway */
1522 memcpy(conf.conf.key +
1523 NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY,
1524 status->gtk[0].tkip_mic_key, 8);
1528 key = ieee80211_gtk_rekey_add(vif, &conf.conf);
1531 iwl_mvm_set_key_rx_seq(mvm, key, status);
1534 cpu_to_be64(le64_to_cpu(status->replay_ctr));
1536 ieee80211_gtk_rekey_notify(vif, vif->bss_conf.bssid,
1537 (void *)&replay_ctr, GFP_KERNEL);
1541 mvmvif->seqno_valid = true;
1542 /* +0x10 because the set API expects next-to-use, not last-used */
1543 mvmvif->seqno = le16_to_cpu(status->non_qos_seq_ctr) + 0x10;
1548 /* Occasionally, templates would be nice. This is one of those times ... */
1549 #define iwl_mvm_parse_wowlan_status_common(_ver) \
1550 static struct iwl_wowlan_status * \
1551 iwl_mvm_parse_wowlan_status_common_ ## _ver(struct iwl_mvm *mvm, \
1552 void *_data, int len) \
1554 struct iwl_wowlan_status *status; \
1555 struct iwl_wowlan_status_ ##_ver *data = _data; \
1558 if (len < sizeof(*data)) { \
1559 IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); \
1560 return ERR_PTR(-EIO); \
1563 data_size = ALIGN(le32_to_cpu(data->wake_packet_bufsize), 4); \
1564 if (len != sizeof(*data) + data_size) { \
1565 IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); \
1566 return ERR_PTR(-EIO); \
1569 status = kzalloc(sizeof(*status) + data_size, GFP_KERNEL); \
1571 return ERR_PTR(-ENOMEM); \
1573 /* copy all the common fields */ \
1574 status->replay_ctr = data->replay_ctr; \
1575 status->pattern_number = data->pattern_number; \
1576 status->non_qos_seq_ctr = data->non_qos_seq_ctr; \
1577 memcpy(status->qos_seq_ctr, data->qos_seq_ctr, \
1578 sizeof(status->qos_seq_ctr)); \
1579 status->wakeup_reasons = data->wakeup_reasons; \
1580 status->num_of_gtk_rekeys = data->num_of_gtk_rekeys; \
1581 status->received_beacons = data->received_beacons; \
1582 status->wake_packet_length = data->wake_packet_length; \
1583 status->wake_packet_bufsize = data->wake_packet_bufsize; \
1584 memcpy(status->wake_packet, data->wake_packet, \
1585 le32_to_cpu(status->wake_packet_bufsize)); \
1590 iwl_mvm_parse_wowlan_status_common(v6)
1591 iwl_mvm_parse_wowlan_status_common(v7)
1592 iwl_mvm_parse_wowlan_status_common(v9)
1594 struct iwl_wowlan_status *iwl_mvm_send_wowlan_get_status(struct iwl_mvm *mvm)
1596 struct iwl_wowlan_status *status;
1597 struct iwl_host_cmd cmd = {
1598 .id = WOWLAN_GET_STATUSES,
1599 .flags = CMD_WANT_SKB,
1604 lockdep_assert_held(&mvm->mutex);
1606 ret = iwl_mvm_send_cmd(mvm, &cmd);
1608 IWL_ERR(mvm, "failed to query wakeup status (%d)\n", ret);
1609 return ERR_PTR(ret);
1612 len = iwl_rx_packet_payload_len(cmd.resp_pkt);
1614 /* default to 7 (when we have IWL_UCODE_TLV_API_WOWLAN_KEY_MATERIAL) */
1615 notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
1616 WOWLAN_GET_STATUSES, 7);
1618 if (!fw_has_api(&mvm->fw->ucode_capa,
1619 IWL_UCODE_TLV_API_WOWLAN_KEY_MATERIAL)) {
1620 struct iwl_wowlan_status_v6 *v6 = (void *)cmd.resp_pkt->data;
1622 status = iwl_mvm_parse_wowlan_status_common_v6(mvm,
1628 BUILD_BUG_ON(sizeof(v6->gtk.decrypt_key) >
1629 sizeof(status->gtk[0].key));
1630 BUILD_BUG_ON(sizeof(v6->gtk.tkip_mic_key) >
1631 sizeof(status->gtk[0].tkip_mic_key));
1633 /* copy GTK info to the right place */
1634 memcpy(status->gtk[0].key, v6->gtk.decrypt_key,
1635 sizeof(v6->gtk.decrypt_key));
1636 memcpy(status->gtk[0].tkip_mic_key, v6->gtk.tkip_mic_key,
1637 sizeof(v6->gtk.tkip_mic_key));
1638 memcpy(&status->gtk[0].rsc, &v6->gtk.rsc,
1639 sizeof(status->gtk[0].rsc));
1641 /* hardcode the key length to 16 since v6 only supports 16 */
1642 status->gtk[0].key_len = 16;
1645 * The key index only uses 2 bits (values 0 to 3) and
1646 * we always set bit 7 which means this is the
1647 * currently used key.
1649 status->gtk[0].key_flags = v6->gtk.key_index | BIT(7);
1650 } else if (notif_ver == 7) {
1651 struct iwl_wowlan_status_v7 *v7 = (void *)cmd.resp_pkt->data;
1653 status = iwl_mvm_parse_wowlan_status_common_v7(mvm,
1659 status->gtk[0] = v7->gtk[0];
1660 status->igtk[0] = v7->igtk[0];
1661 } else if (notif_ver == 9) {
1662 struct iwl_wowlan_status_v9 *v9 = (void *)cmd.resp_pkt->data;
1664 status = iwl_mvm_parse_wowlan_status_common_v9(mvm,
1670 status->gtk[0] = v9->gtk[0];
1671 status->igtk[0] = v9->igtk[0];
1673 status->tid_tear_down = v9->tid_tear_down;
1676 "Firmware advertises unknown WoWLAN status response %d!\n",
1678 status = ERR_PTR(-EIO);
1682 iwl_free_resp(&cmd);
1686 static struct iwl_wowlan_status *
1687 iwl_mvm_get_wakeup_status(struct iwl_mvm *mvm)
1691 /* only for tracing for now */
1692 ret = iwl_mvm_send_cmd_pdu(mvm, OFFLOADS_QUERY_CMD, 0, 0, NULL);
1694 IWL_ERR(mvm, "failed to query offload statistics (%d)\n", ret);
1696 return iwl_mvm_send_wowlan_get_status(mvm);
1699 /* releases the MVM mutex */
1700 static bool iwl_mvm_query_wakeup_reasons(struct iwl_mvm *mvm,
1701 struct ieee80211_vif *vif)
1703 struct iwl_wowlan_status_data status;
1704 struct iwl_wowlan_status *fw_status;
1707 struct iwl_mvm_sta *mvm_ap_sta;
1709 fw_status = iwl_mvm_get_wakeup_status(mvm);
1710 if (IS_ERR_OR_NULL(fw_status))
1713 IWL_DEBUG_WOWLAN(mvm, "wakeup reason 0x%x\n",
1714 le32_to_cpu(fw_status->wakeup_reasons));
1716 status.pattern_number = le16_to_cpu(fw_status->pattern_number);
1717 for (i = 0; i < 8; i++)
1718 status.qos_seq_ctr[i] =
1719 le16_to_cpu(fw_status->qos_seq_ctr[i]);
1720 status.wakeup_reasons = le32_to_cpu(fw_status->wakeup_reasons);
1721 status.wake_packet_length =
1722 le32_to_cpu(fw_status->wake_packet_length);
1723 status.wake_packet_bufsize =
1724 le32_to_cpu(fw_status->wake_packet_bufsize);
1725 status.wake_packet = fw_status->wake_packet;
1727 /* still at hard-coded place 0 for D3 image */
1728 mvm_ap_sta = iwl_mvm_sta_from_staid_protected(mvm, 0);
1732 for (i = 0; i < IWL_MAX_TID_COUNT; i++) {
1733 u16 seq = status.qos_seq_ctr[i];
1734 /* firmware stores last-used value, we store next value */
1736 mvm_ap_sta->tid_data[i].seq_number = seq;
1739 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000) {
1740 i = mvm->offload_tid;
1741 iwl_trans_set_q_ptrs(mvm->trans,
1742 mvm_ap_sta->tid_data[i].txq_id,
1743 mvm_ap_sta->tid_data[i].seq_number >> 4);
1746 /* now we have all the data we need, unlock to avoid mac80211 issues */
1747 mutex_unlock(&mvm->mutex);
1749 iwl_mvm_report_wakeup_reasons(mvm, vif, &status);
1751 keep = iwl_mvm_setup_connection_keep(mvm, vif, fw_status);
1759 mutex_unlock(&mvm->mutex);
1763 #define ND_QUERY_BUF_LEN (sizeof(struct iwl_scan_offload_profile_match) * \
1764 IWL_SCAN_MAX_PROFILES)
1766 struct iwl_mvm_nd_query_results {
1767 u32 matched_profiles;
1768 u8 matches[ND_QUERY_BUF_LEN];
1772 iwl_mvm_netdetect_query_results(struct iwl_mvm *mvm,
1773 struct iwl_mvm_nd_query_results *results)
1775 struct iwl_scan_offload_profiles_query *query;
1776 struct iwl_host_cmd cmd = {
1777 .id = SCAN_OFFLOAD_PROFILES_QUERY_CMD,
1778 .flags = CMD_WANT_SKB,
1781 size_t query_len, matches_len;
1782 int max_profiles = iwl_umac_scan_get_max_profiles(mvm->fw);
1784 ret = iwl_mvm_send_cmd(mvm, &cmd);
1786 IWL_ERR(mvm, "failed to query matched profiles (%d)\n", ret);
1790 if (fw_has_api(&mvm->fw->ucode_capa,
1791 IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) {
1792 query_len = sizeof(struct iwl_scan_offload_profiles_query);
1793 matches_len = sizeof(struct iwl_scan_offload_profile_match) *
1796 query_len = sizeof(struct iwl_scan_offload_profiles_query_v1);
1797 matches_len = sizeof(struct iwl_scan_offload_profile_match_v1) *
1801 len = iwl_rx_packet_payload_len(cmd.resp_pkt);
1802 if (len < query_len) {
1803 IWL_ERR(mvm, "Invalid scan offload profiles query response!\n");
1808 query = (void *)cmd.resp_pkt->data;
1810 results->matched_profiles = le32_to_cpu(query->matched_profiles);
1811 memcpy(results->matches, query->matches, matches_len);
1813 #ifdef CONFIG_IWLWIFI_DEBUGFS
1814 mvm->last_netdetect_scans = le32_to_cpu(query->n_scans_done);
1818 iwl_free_resp(&cmd);
1822 static int iwl_mvm_query_num_match_chans(struct iwl_mvm *mvm,
1823 struct iwl_mvm_nd_query_results *query,
1828 if (fw_has_api(&mvm->fw->ucode_capa,
1829 IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) {
1830 struct iwl_scan_offload_profile_match *matches =
1831 (struct iwl_scan_offload_profile_match *)query->matches;
1833 for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN; i++)
1834 n_chans += hweight8(matches[idx].matching_channels[i]);
1836 struct iwl_scan_offload_profile_match_v1 *matches =
1837 (struct iwl_scan_offload_profile_match_v1 *)query->matches;
1839 for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1; i++)
1840 n_chans += hweight8(matches[idx].matching_channels[i]);
1846 static void iwl_mvm_query_set_freqs(struct iwl_mvm *mvm,
1847 struct iwl_mvm_nd_query_results *query,
1848 struct cfg80211_wowlan_nd_match *match,
1853 if (fw_has_api(&mvm->fw->ucode_capa,
1854 IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) {
1855 struct iwl_scan_offload_profile_match *matches =
1856 (struct iwl_scan_offload_profile_match *)query->matches;
1858 for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN * 8; i++)
1859 if (matches[idx].matching_channels[i / 8] & (BIT(i % 8)))
1860 match->channels[match->n_channels++] =
1861 mvm->nd_channels[i]->center_freq;
1863 struct iwl_scan_offload_profile_match_v1 *matches =
1864 (struct iwl_scan_offload_profile_match_v1 *)query->matches;
1866 for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1 * 8; i++)
1867 if (matches[idx].matching_channels[i / 8] & (BIT(i % 8)))
1868 match->channels[match->n_channels++] =
1869 mvm->nd_channels[i]->center_freq;
1873 static void iwl_mvm_query_netdetect_reasons(struct iwl_mvm *mvm,
1874 struct ieee80211_vif *vif)
1876 struct cfg80211_wowlan_nd_info *net_detect = NULL;
1877 struct cfg80211_wowlan_wakeup wakeup = {
1880 struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup;
1881 struct iwl_mvm_nd_query_results query;
1882 struct iwl_wowlan_status *fw_status;
1883 unsigned long matched_profiles;
1885 int i, n_matches, ret;
1887 fw_status = iwl_mvm_get_wakeup_status(mvm);
1888 if (!IS_ERR_OR_NULL(fw_status)) {
1889 reasons = le32_to_cpu(fw_status->wakeup_reasons);
1893 if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED)
1894 wakeup.rfkill_release = true;
1896 if (reasons != IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS)
1899 ret = iwl_mvm_netdetect_query_results(mvm, &query);
1900 if (ret || !query.matched_profiles) {
1901 wakeup_report = NULL;
1905 matched_profiles = query.matched_profiles;
1906 if (mvm->n_nd_match_sets) {
1907 n_matches = hweight_long(matched_profiles);
1909 IWL_ERR(mvm, "no net detect match information available\n");
1913 net_detect = kzalloc(struct_size(net_detect, matches, n_matches),
1915 if (!net_detect || !n_matches)
1918 for_each_set_bit(i, &matched_profiles, mvm->n_nd_match_sets) {
1919 struct cfg80211_wowlan_nd_match *match;
1920 int idx, n_channels = 0;
1922 n_channels = iwl_mvm_query_num_match_chans(mvm, &query, i);
1924 match = kzalloc(struct_size(match, channels, n_channels),
1929 net_detect->matches[net_detect->n_matches++] = match;
1931 /* We inverted the order of the SSIDs in the scan
1932 * request, so invert the index here.
1934 idx = mvm->n_nd_match_sets - i - 1;
1935 match->ssid.ssid_len = mvm->nd_match_sets[idx].ssid.ssid_len;
1936 memcpy(match->ssid.ssid, mvm->nd_match_sets[idx].ssid.ssid,
1937 match->ssid.ssid_len);
1939 if (mvm->n_nd_channels < n_channels)
1942 iwl_mvm_query_set_freqs(mvm, &query, match, i);
1946 wakeup.net_detect = net_detect;
1948 iwl_mvm_free_nd(mvm);
1950 mutex_unlock(&mvm->mutex);
1951 ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL);
1954 for (i = 0; i < net_detect->n_matches; i++)
1955 kfree(net_detect->matches[i]);
1960 static void iwl_mvm_d3_disconnect_iter(void *data, u8 *mac,
1961 struct ieee80211_vif *vif)
1963 /* skip the one we keep connection on */
1967 if (vif->type == NL80211_IFTYPE_STATION)
1968 ieee80211_resume_disconnect(vif);
1971 static bool iwl_mvm_rt_status(struct iwl_trans *trans, u32 base, u32 *err_id)
1973 struct error_table_start {
1974 /* cf. struct iwl_error_event_table */
1982 iwl_trans_read_mem_bytes(trans, base,
1983 &err_info, sizeof(err_info));
1984 if (err_info.valid && err_id)
1985 *err_id = le32_to_cpu(err_info.err_id);
1987 return !!err_info.valid;
1990 static bool iwl_mvm_check_rt_status(struct iwl_mvm *mvm,
1991 struct ieee80211_vif *vif)
1995 /* check for lmac1 error */
1996 if (iwl_mvm_rt_status(mvm->trans,
1997 mvm->trans->dbg.lmac_error_event_table[0],
1999 if (err_id == RF_KILL_INDICATOR_FOR_WOWLAN) {
2000 struct cfg80211_wowlan_wakeup wakeup = {
2001 .rfkill_release = true,
2003 ieee80211_report_wowlan_wakeup(vif, &wakeup,
2009 /* check if we have lmac2 set and check for error */
2010 if (iwl_mvm_rt_status(mvm->trans,
2011 mvm->trans->dbg.lmac_error_event_table[1], NULL))
2014 /* check for umac error */
2015 if (iwl_mvm_rt_status(mvm->trans,
2016 mvm->trans->dbg.umac_error_event_table, NULL))
2022 static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test)
2024 struct ieee80211_vif *vif = NULL;
2026 enum iwl_d3_status d3_status;
2028 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
2029 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
2030 bool d0i3_first = fw_has_capa(&mvm->fw->ucode_capa,
2031 IWL_UCODE_TLV_CAPA_D0I3_END_FIRST);
2033 mutex_lock(&mvm->mutex);
2035 /* get the BSS vif pointer again */
2036 vif = iwl_mvm_get_bss_vif(mvm);
2037 if (IS_ERR_OR_NULL(vif))
2040 iwl_fw_dbg_read_d3_debug_data(&mvm->fwrt);
2042 if (iwl_mvm_check_rt_status(mvm, vif)) {
2043 set_bit(STATUS_FW_ERROR, &mvm->trans->status);
2044 iwl_mvm_dump_nic_error_log(mvm);
2045 iwl_dbg_tlv_time_point(&mvm->fwrt,
2046 IWL_FW_INI_TIME_POINT_FW_ASSERT, NULL);
2047 iwl_fw_dbg_collect_desc(&mvm->fwrt, &iwl_dump_desc_assert,
2053 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_HOST_D3_END,
2056 ret = iwl_trans_d3_resume(mvm->trans, &d3_status, test, !unified_image);
2060 if (d3_status != IWL_D3_STATUS_ALIVE) {
2061 IWL_INFO(mvm, "Device was reset during suspend\n");
2066 struct iwl_host_cmd cmd = {
2068 .flags = CMD_WANT_SKB,
2072 ret = iwl_mvm_send_cmd(mvm, &cmd);
2074 IWL_ERR(mvm, "Failed to send D0I3_END_CMD first (%d)\n",
2078 switch (mvm->cmd_ver.d0i3_resp) {
2082 len = iwl_rx_packet_payload_len(cmd.resp_pkt);
2083 if (len != sizeof(u32)) {
2085 "Error with D0I3_END_CMD response size (%d)\n",
2089 if (IWL_D0I3_RESET_REQUIRE &
2090 le32_to_cpu(*(__le32 *)cmd.resp_pkt->data)) {
2091 iwl_write32(mvm->trans, CSR_RESET,
2092 CSR_RESET_REG_FLAG_FORCE_NMI);
2093 iwl_free_resp(&cmd);
2102 * Query the current location and source from the D3 firmware so we
2103 * can play it back when we re-intiailize the D0 firmware
2105 iwl_mvm_update_changed_regdom(mvm);
2107 /* Re-configure PPAG settings */
2108 iwl_mvm_ppag_send_cmd(mvm);
2111 /* Re-configure default SAR profile */
2112 iwl_mvm_sar_select_profile(mvm, 1, 1);
2114 if (mvm->net_detect) {
2115 /* If this is a non-unified image, we restart the FW,
2116 * so no need to stop the netdetect scan. If that
2117 * fails, continue and try to get the wake-up reasons,
2118 * but trigger a HW restart by keeping a failure code
2122 ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_NETDETECT,
2125 iwl_mvm_query_netdetect_reasons(mvm, vif);
2126 /* has unlocked the mutex, so skip that */
2129 keep = iwl_mvm_query_wakeup_reasons(mvm, vif);
2130 #ifdef CONFIG_IWLWIFI_DEBUGFS
2132 mvm->keep_vif = vif;
2134 /* has unlocked the mutex, so skip that */
2139 iwl_mvm_free_nd(mvm);
2140 mutex_unlock(&mvm->mutex);
2144 ieee80211_iterate_active_interfaces_mtx(mvm->hw,
2145 IEEE80211_IFACE_ITER_NORMAL,
2146 iwl_mvm_d3_disconnect_iter, keep ? vif : NULL);
2149 clear_bit(IWL_MVM_STATUS_IN_D3, &mvm->status);
2151 /* no need to reset the device in unified images, if successful */
2152 if (unified_image && !ret) {
2153 /* nothing else to do if we already sent D0I3_END_CMD */
2157 ret = iwl_mvm_send_cmd_pdu(mvm, D0I3_END_CMD, 0, 0, NULL);
2163 * Reconfigure the device in one of the following cases:
2164 * 1. We are not using a unified image
2165 * 2. We are using a unified image but had an error while exiting D3
2167 set_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
2172 static int iwl_mvm_resume_d3(struct iwl_mvm *mvm)
2174 iwl_trans_resume(mvm->trans);
2176 return __iwl_mvm_resume(mvm, false);
2179 int iwl_mvm_resume(struct ieee80211_hw *hw)
2181 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2184 ret = iwl_mvm_resume_d3(mvm);
2186 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED;
2188 iwl_mvm_resume_tcm(mvm);
2190 iwl_fw_runtime_resume(&mvm->fwrt);
2195 void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled)
2197 struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
2199 device_set_wakeup_enable(mvm->trans->dev, enabled);
2202 #ifdef CONFIG_IWLWIFI_DEBUGFS
2203 static int iwl_mvm_d3_test_open(struct inode *inode, struct file *file)
2205 struct iwl_mvm *mvm = inode->i_private;
2208 if (mvm->d3_test_active)
2211 file->private_data = inode->i_private;
2215 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_D3;
2217 iwl_mvm_pause_tcm(mvm, true);
2219 iwl_fw_runtime_suspend(&mvm->fwrt);
2221 /* start pseudo D3 */
2223 err = __iwl_mvm_suspend(mvm->hw, mvm->hw->wiphy->wowlan_config, true);
2230 mvm->d3_test_active = true;
2231 mvm->keep_vif = NULL;
2235 static ssize_t iwl_mvm_d3_test_read(struct file *file, char __user *user_buf,
2236 size_t count, loff_t *ppos)
2238 struct iwl_mvm *mvm = file->private_data;
2242 /* read pme_ptr if available */
2243 if (mvm->d3_test_pme_ptr) {
2244 pme_asserted = iwl_trans_read_mem32(mvm->trans,
2245 mvm->d3_test_pme_ptr);
2250 if (msleep_interruptible(100))
2257 static void iwl_mvm_d3_test_disconn_work_iter(void *_data, u8 *mac,
2258 struct ieee80211_vif *vif)
2260 /* skip the one we keep connection on */
2264 if (vif->type == NL80211_IFTYPE_STATION)
2265 ieee80211_connection_loss(vif);
2268 static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file)
2270 struct iwl_mvm *mvm = inode->i_private;
2271 bool unified_image = fw_has_capa(&mvm->fw->ucode_capa,
2272 IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG);
2274 mvm->d3_test_active = false;
2276 iwl_fw_dbg_read_d3_debug_data(&mvm->fwrt);
2279 __iwl_mvm_resume(mvm, true);
2282 iwl_mvm_resume_tcm(mvm);
2284 iwl_fw_runtime_resume(&mvm->fwrt);
2286 mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED;
2288 iwl_abort_notification_waits(&mvm->notif_wait);
2289 if (!unified_image) {
2290 int remaining_time = 10;
2292 ieee80211_restart_hw(mvm->hw);
2294 /* wait for restart and disconnect all interfaces */
2295 while (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
2296 remaining_time > 0) {
2301 if (remaining_time == 0)
2302 IWL_ERR(mvm, "Timed out waiting for HW restart!\n");
2305 ieee80211_iterate_active_interfaces_atomic(
2306 mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
2307 iwl_mvm_d3_test_disconn_work_iter, mvm->keep_vif);
2312 const struct file_operations iwl_dbgfs_d3_test_ops = {
2313 .llseek = no_llseek,
2314 .open = iwl_mvm_d3_test_open,
2315 .read = iwl_mvm_d3_test_read,
2316 .release = iwl_mvm_d3_test_release,