Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | * redistributing this file, you may do so under either license. |
| 5 | * |
| 6 | * GPL LICENSE SUMMARY |
| 7 | * |
Emmanuel Grumbach | f4bfdc5 | 2020-04-24 18:48:13 +0300 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2014, 2018 - 2020 Intel Corporation. All rights reserved. |
Luciano Coelho | 65ff556 | 2015-03-20 13:35:47 +0200 | [diff] [blame] | 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Luca Coelho | fcea37b | 2017-04-12 16:33:41 +0300 | [diff] [blame] | 10 | * Copyright(c) 2016 - 2017 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 11 | * |
| 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 21 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 22 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 23 | * |
| 24 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 25 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | * BSD LICENSE |
| 29 | * |
Emmanuel Grumbach | f4bfdc5 | 2020-04-24 18:48:13 +0300 | [diff] [blame] | 30 | * Copyright(c) 2012 - 2014, 2018 - 2020 Intel Corporation. All rights reserved. |
Luciano Coelho | 65ff556 | 2015-03-20 13:35:47 +0200 | [diff] [blame] | 31 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Luca Coelho | fcea37b | 2017-04-12 16:33:41 +0300 | [diff] [blame] | 32 | * Copyright(c) 2016 - 2017 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 33 | * 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 Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 63 | #include <linux/etherdevice.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 64 | #include <linux/ip.h> |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 65 | #include <linux/fs.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 66 | #include <net/cfg80211.h> |
| 67 | #include <net/ipv6.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 68 | #include <net/tcp.h> |
Johannes Berg | f7fc598 | 2013-08-20 13:04:10 +0200 | [diff] [blame] | 69 | #include <net/addrconf.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 70 | #include "iwl-modparams.h" |
| 71 | #include "fw-api.h" |
| 72 | #include "mvm.h" |
Nathan Errera | 9e3c393 | 2020-09-28 12:23:15 +0300 | [diff] [blame] | 73 | #include "fw/img.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 74 | |
| 75 | void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw, |
| 76 | struct ieee80211_vif *vif, |
| 77 | struct cfg80211_gtk_rekey_data *data) |
| 78 | { |
| 79 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 80 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 81 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 82 | mutex_lock(&mvm->mutex); |
| 83 | |
Nathan Errera | 2a42aea | 2020-09-30 16:31:17 +0300 | [diff] [blame] | 84 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 89 | mvmvif->rekey_data.replay_ctr = |
Johannes Berg | cba8457 | 2016-11-30 17:04:52 +0100 | [diff] [blame] | 90 | cpu_to_le64(be64_to_cpup((__be64 *)data->replay_ctr)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 91 | mvmvif->rekey_data.valid = true; |
| 92 | |
| 93 | mutex_unlock(&mvm->mutex); |
| 94 | } |
| 95 | |
| 96 | #if IS_ENABLED(CONFIG_IPV6) |
| 97 | void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw, |
| 98 | struct ieee80211_vif *vif, |
| 99 | struct inet6_dev *idev) |
| 100 | { |
| 101 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 102 | struct inet6_ifaddr *ifa; |
| 103 | int idx = 0; |
| 104 | |
Sara Sharon | c97dab4 | 2015-11-19 11:53:49 +0200 | [diff] [blame] | 105 | memset(mvmvif->tentative_addrs, 0, sizeof(mvmvif->tentative_addrs)); |
| 106 | |
Emmanuel Grumbach | a3777e0 | 2013-02-10 13:07:08 +0200 | [diff] [blame] | 107 | read_lock_bh(&idev->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 108 | list_for_each_entry(ifa, &idev->addr_list, if_list) { |
| 109 | mvmvif->target_ipv6_addrs[idx] = ifa->addr; |
Sara Sharon | c97dab4 | 2015-11-19 11:53:49 +0200 | [diff] [blame] | 110 | if (ifa->flags & IFA_F_TENTATIVE) |
| 111 | __set_bit(idx, mvmvif->tentative_addrs); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 112 | idx++; |
Johannes Berg | 5369d6c | 2013-07-08 11:17:06 +0200 | [diff] [blame] | 113 | if (idx >= IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 114 | break; |
| 115 | } |
Emmanuel Grumbach | a3777e0 | 2013-02-10 13:07:08 +0200 | [diff] [blame] | 116 | read_unlock_bh(&idev->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 117 | |
| 118 | mvmvif->num_target_ipv6_addrs = idx; |
| 119 | } |
| 120 | #endif |
| 121 | |
| 122 | void 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 | |
| 130 | static 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 Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 138 | static 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 160 | struct wowlan_key_data { |
| 161 | struct iwl_wowlan_rsc_tsc_params_cmd *rsc_tsc; |
| 162 | struct iwl_wowlan_tkip_params_cmd *tkip; |
Nathan Errera | 2a42aea | 2020-09-30 16:31:17 +0300 | [diff] [blame] | 163 | struct iwl_wowlan_kek_kck_material_cmd_v3 *kek_kck_cmd; |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 164 | bool error, use_rsc_tsc, use_tkip, configure_keys; |
Johannes Berg | 5312e54 | 2013-07-22 18:26:56 +0200 | [diff] [blame] | 165 | int wep_key_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | static 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 186 | 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 Berg | 5312e54 | 2013-07-22 18:26:56 +0200 | [diff] [blame] | 217 | data->wep_key_idx++; |
| 218 | wkc.wep_key.key_offset = data->wep_key_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 221 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 226 | |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 227 | 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 Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 233 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 234 | /* don't upload key again */ |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 235 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 236 | } |
| 237 | default: |
| 238 | data->error = true; |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 239 | return; |
Nathan Errera | 2a42aea | 2020-09-30 16:31:17 +0300 | [diff] [blame] | 240 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 244 | case WLAN_CIPHER_SUITE_AES_CMAC: |
Nathan Errera | 2a42aea | 2020-09-30 16:31:17 +0300 | [diff] [blame] | 245 | data->kek_kck_cmd->igtk_cipher = cpu_to_le32(STA_KEY_FLG_CCM); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 246 | /* |
| 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 Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 253 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 254 | case WLAN_CIPHER_SUITE_TKIP: |
| 255 | if (sta) { |
Eliad Peller | 1ad4f63 | 2016-02-14 13:56:36 +0200 | [diff] [blame] | 256 | u64 pn64; |
| 257 | |
Dan Halperin | ee3ae3a | 2020-09-26 00:30:48 +0300 | [diff] [blame] | 258 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 262 | |
| 263 | rx_p1ks = data->tkip->rx_uni; |
| 264 | |
Eliad Peller | 1ad4f63 | 2016-02-14 13:56:36 +0200 | [diff] [blame] | 265 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 268 | |
Eliad Peller | 1ad4f63 | 2016-02-14 13:56:36 +0200 | [diff] [blame] | 269 | ieee80211_get_tkip_p1k_iv(key, TKIP_PN_TO_IV32(pn64), |
| 270 | p1k); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 271 | 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 Halperin | ee3ae3a | 2020-09-26 00:30:48 +0300 | [diff] [blame] | 280 | data->rsc_tsc->params.all_tsc_rsc.tkip.multicast_rsc; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 281 | rx_p1ks = data->tkip->rx_multi; |
| 282 | rx_mic_key = data->tkip->mic_keys.rx_mcast; |
Nathan Errera | 2a42aea | 2020-09-30 16:31:17 +0300 | [diff] [blame] | 283 | data->kek_kck_cmd->gtk_cipher = |
| 284 | cpu_to_le32(STA_KEY_FLG_TKIP); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 285 | } |
| 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 Berg | c7f996e | 2020-09-30 16:31:18 +0300 | [diff] [blame] | 316 | case WLAN_CIPHER_SUITE_GCMP: |
| 317 | case WLAN_CIPHER_SUITE_GCMP_256: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 318 | if (sta) { |
Johannes Berg | 6645d5e | 2015-09-15 09:58:53 +0200 | [diff] [blame] | 319 | u64 pn64; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 320 | |
Dan Halperin | ee3ae3a | 2020-09-26 00:30:48 +0300 | [diff] [blame] | 321 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 325 | |
Johannes Berg | 6645d5e | 2015-09-15 09:58:53 +0200 | [diff] [blame] | 326 | pn64 = atomic64_read(&key->tx_pn); |
| 327 | aes_tx_sc->pn = cpu_to_le64(pn64); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 328 | } else { |
Dan Halperin | ee3ae3a | 2020-09-26 00:30:48 +0300 | [diff] [blame] | 329 | aes_sc = |
| 330 | data->rsc_tsc->params.all_tsc_rsc.aes.multicast_rsc; |
Nathan Errera | 2a42aea | 2020-09-30 16:31:17 +0300 | [diff] [blame] | 331 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | /* |
| 338 | * For non-QoS this relies on the fact that both the uCode and |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 339 | * mac80211/our RX code use TID 0 for checking the PN. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 340 | */ |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 341 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 345 | |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 346 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Sara Sharon | efa40c7 | 2020-10-08 18:12:42 +0300 | [diff] [blame] | 347 | rcu_read_lock(); |
| 348 | ptk_pn = rcu_dereference(mvmsta->ptk_pn[key->keyidx]); |
| 349 | if (WARN_ON(!ptk_pn)) { |
| 350 | rcu_read_unlock(); |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 351 | break; |
Sara Sharon | efa40c7 | 2020-10-08 18:12:42 +0300 | [diff] [blame] | 352 | } |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 353 | |
| 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 Sharon | efa40c7 | 2020-10-08 18:12:42 +0300 | [diff] [blame] | 364 | |
| 365 | rcu_read_unlock(); |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 366 | } 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 378 | } |
| 379 | data->use_rsc_tsc = true; |
| 380 | break; |
| 381 | } |
| 382 | |
Sara Sharon | 19d9fa7 | 2020-09-30 16:31:20 +0300 | [diff] [blame] | 383 | IWL_DEBUG_WOWLAN(mvm, "GTK cipher %d\n", data->kek_kck_cmd->gtk_cipher); |
| 384 | |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 385 | if (data->configure_keys) { |
| 386 | mutex_lock(&mvm->mutex); |
Johannes Berg | 5312e54 | 2013-07-22 18:26:56 +0200 | [diff] [blame] | 387 | /* |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 388 | * 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 Berg | 5312e54 | 2013-07-22 18:26:56 +0200 | [diff] [blame] | 390 | */ |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 391 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 408 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 409 | } |
| 410 | |
Luca Coelho | 0c546fb | 2019-03-12 16:01:24 +0200 | [diff] [blame] | 411 | static int iwl_mvm_send_patterns_v1(struct iwl_mvm *mvm, |
| 412 | struct cfg80211_wowlan *wowlan) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 413 | { |
Luca Coelho | 0c546fb | 2019-03-12 16:01:24 +0200 | [diff] [blame] | 414 | struct iwl_wowlan_patterns_cmd_v1 *pattern_cmd; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 415 | struct iwl_host_cmd cmd = { |
| 416 | .id = WOWLAN_PATTERNS, |
| 417 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 418 | }; |
| 419 | int i, err; |
| 420 | |
| 421 | if (!wowlan->n_patterns) |
| 422 | return 0; |
| 423 | |
Gustavo A. R. Silva | e344896 | 2019-04-03 11:03:42 -0500 | [diff] [blame] | 424 | cmd.len[0] = struct_size(pattern_cmd, patterns, wowlan->n_patterns); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 425 | |
| 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 Coelho | 0c546fb | 2019-03-12 16:01:24 +0200 | [diff] [blame] | 451 | static 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 495 | static 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, Haim | 10a970d | 2018-05-21 10:36:46 +0300 | [diff] [blame] | 503 | struct iwl_binding_cmd_v1 binding_cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 504 | struct iwl_time_quota_cmd quota_cmd = {}; |
David Spinadel | 72cbb73 | 2017-08-30 16:23:14 +0300 | [diff] [blame] | 505 | struct iwl_time_quota_data *quota; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 506 | u32 status; |
Sara Sharon | 9415af7 | 2016-11-17 13:57:32 +0200 | [diff] [blame] | 507 | |
Dreyfuss, Haim | 10a970d | 2018-05-21 10:36:46 +0300 | [diff] [blame] | 508 | if (WARN_ON_ONCE(iwl_mvm_is_cdb_supported(mvm))) |
| 509 | return -EINVAL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 510 | |
| 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 Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 536 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 537 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 538 | 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, Haim | 10a970d | 2018-05-21 10:36:46 +0300 | [diff] [blame] | 556 | IWL_BINDING_CMD_SIZE_V1, &binding_cmd, |
| 557 | &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 558 | 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 Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 568 | ret = iwl_mvm_sta_send_to_fw(mvm, ap_sta, false, 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 569 | if (ret) |
| 570 | return ret; |
| 571 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], ap_sta); |
| 572 | |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 573 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 574 | if (ret) |
| 575 | return ret; |
| 576 | |
| 577 | /* and some quota */ |
David Spinadel | 72cbb73 | 2017-08-30 16:23:14 +0300 | [diff] [blame] | 578 | quota = iwl_mvm_quota_cmd_get_quota(mvm, "a_cmd, 0); |
| 579 | quota->id_and_color = |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 580 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id, |
| 581 | mvmvif->phy_ctxt->color)); |
David Spinadel | 72cbb73 | 2017-08-30 16:23:14 +0300 | [diff] [blame] | 582 | quota->quota = cpu_to_le32(IWL_MVM_MAX_QUOTA); |
| 583 | quota->max_duration = cpu_to_le32(IWL_MVM_MAX_QUOTA); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 584 | |
David Spinadel | 72cbb73 | 2017-08-30 16:23:14 +0300 | [diff] [blame] | 585 | for (i = 1; i < MAX_BINDINGS; i++) { |
| 586 | quota = iwl_mvm_quota_cmd_get_quota(mvm, "a_cmd, i); |
| 587 | quota->id_and_color = cpu_to_le32(FW_CTXT_INVALID); |
| 588 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 589 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 590 | ret = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, 0, |
David Spinadel | 72cbb73 | 2017-08-30 16:23:14 +0300 | [diff] [blame] | 591 | iwl_mvm_quota_cmd_size(mvm), "a_cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 592 | if (ret) |
| 593 | IWL_ERR(mvm, "Failed to send quota: %d\n", ret); |
| 594 | |
Jonathan Doron | 47c8b15 | 2014-11-27 16:55:25 +0200 | [diff] [blame] | 595 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 598 | return 0; |
| 599 | } |
| 600 | |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 601 | static int iwl_mvm_get_last_nonqos_seq(struct iwl_mvm *mvm, |
| 602 | struct ieee80211_vif *vif) |
| 603 | { |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 604 | 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 Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 611 | struct iwl_host_cmd cmd = { |
| 612 | .id = NON_QOS_TX_COUNTER_CMD, |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 613 | .flags = CMD_WANT_SKB, |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 614 | }; |
| 615 | int err; |
| 616 | u32 size; |
| 617 | |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 618 | cmd.data[0] = &query_cmd; |
| 619 | cmd.len[0] = sizeof(query_cmd); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 620 | |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 621 | err = iwl_mvm_send_cmd(mvm, &cmd); |
| 622 | if (err) |
| 623 | return err; |
| 624 | |
Johannes Berg | 65b3034 | 2014-01-08 13:16:33 +0100 | [diff] [blame] | 625 | size = iwl_rx_packet_payload_len(cmd.resp_pkt); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 626 | if (size < sizeof(__le16)) { |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 627 | err = -EINVAL; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 628 | } else { |
| 629 | err = le16_to_cpup((__le16 *)cmd.resp_pkt->data); |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 630 | /* firmware returns next, not last-used seqno */ |
| 631 | err = (u16) (err - 0x10); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 632 | } |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 633 | |
| 634 | iwl_free_resp(&cmd); |
| 635 | return err; |
| 636 | } |
| 637 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 638 | void 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 Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 655 | if (iwl_mvm_send_cmd_pdu(mvm, NON_QOS_TX_COUNTER_CMD, 0, |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 656 | sizeof(query_cmd), &query_cmd)) |
| 657 | IWL_ERR(mvm, "failed to set non-QoS seqno\n"); |
| 658 | } |
| 659 | |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 660 | static int iwl_mvm_switch_to_d3(struct iwl_mvm *mvm) |
Eliad Peller | 1a95c8d | 2013-11-21 19:19:52 +0200 | [diff] [blame] | 661 | { |
Luciano Coelho | c7d4248 | 2015-05-07 16:00:26 +0300 | [diff] [blame] | 662 | iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 663 | |
Chaya Rachel Ivgi | fcb6b92 | 2016-02-22 10:21:41 +0200 | [diff] [blame] | 664 | iwl_mvm_stop_device(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 665 | /* |
| 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 Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 677 | /* the fw is reset, so all the keys are cleared */ |
| 678 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
| 679 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 680 | mvm->ptk_ivlen = 0; |
| 681 | mvm->ptk_icvlen = 0; |
| 682 | mvm->ptk_ivlen = 0; |
| 683 | mvm->ptk_icvlen = 0; |
| 684 | |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 685 | return iwl_mvm_load_d3_fw(mvm); |
| 686 | } |
| 687 | |
| 688 | static int |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 689 | iwl_mvm_get_wowlan_config(struct iwl_mvm *mvm, |
| 690 | struct cfg80211_wowlan *wowlan, |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 691 | struct iwl_wowlan_config_cmd *wowlan_config_cmd, |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 692 | struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif, |
| 693 | struct ieee80211_sta *ap_sta) |
| 694 | { |
| 695 | int ret; |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 696 | struct iwl_mvm_sta *mvm_ap_sta = iwl_mvm_sta_from_mac80211(ap_sta); |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 697 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 698 | /* TODO: wowlan_config_cmd->wowlan_ba_teardown_tids */ |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 699 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 700 | wowlan_config_cmd->is_11n_connection = |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 701 | ap_sta->ht_cap.ht_supported; |
Sara Sharon | 70b4c53 | 2015-11-19 13:12:15 +0200 | [diff] [blame] | 702 | wowlan_config_cmd->flags = ENABLE_L3_FILTERING | |
Matti Gottlieb | 32795a8 | 2016-02-25 10:18:34 +0200 | [diff] [blame] | 703 | ENABLE_NBNS_FILTERING | ENABLE_DHCP_FILTERING; |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 704 | |
| 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 Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 710 | wowlan_config_cmd->non_qos_seq = cpu_to_le16(ret); |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 711 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 712 | iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, wowlan_config_cmd); |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 713 | |
| 714 | if (wowlan->disconnect) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 715 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 716 | cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS | |
| 717 | IWL_WOWLAN_WAKEUP_LINK_CHANGE); |
| 718 | if (wowlan->magic_pkt) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 719 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 720 | cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET); |
| 721 | if (wowlan->gtk_rekey_failure) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 722 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 723 | cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL); |
| 724 | if (wowlan->eap_identity_req) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 725 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 726 | cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ); |
| 727 | if (wowlan->four_way_handshake) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 728 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 729 | cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE); |
| 730 | if (wowlan->n_patterns) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 731 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 732 | cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH); |
| 733 | |
| 734 | if (wowlan->rfkill_release) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 735 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 736 | 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 Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 743 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 744 | 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 Peller | d3a6f7f | 2018-02-22 18:45:49 +0200 | [diff] [blame] | 750 | 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 Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 758 | return 0; |
| 759 | } |
| 760 | |
Emmanuel Grumbach | 0ea9338 | 2019-06-06 10:58:46 +0300 | [diff] [blame] | 761 | static int iwl_mvm_wowlan_config_key_params(struct iwl_mvm *mvm, |
| 762 | struct ieee80211_vif *vif, |
| 763 | u32 cmd_flags) |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 764 | { |
Nathan Errera | 9e3c393 | 2020-09-28 12:23:15 +0300 | [diff] [blame] | 765 | struct iwl_wowlan_kek_kck_material_cmd_v3 kek_kck_cmd = {}; |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 766 | struct iwl_wowlan_tkip_params_cmd tkip_cmd = {}; |
Sara Sharon | 8c7fd6a | 2018-07-01 14:52:06 +0300 | [diff] [blame] | 767 | bool unified = fw_has_capa(&mvm->fw->ucode_capa, |
| 768 | IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 769 | struct wowlan_key_data key_data = { |
Emmanuel Grumbach | 0ea9338 | 2019-06-06 10:58:46 +0300 | [diff] [blame] | 770 | .configure_keys = !unified, |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 771 | .use_rsc_tsc = false, |
| 772 | .tkip = &tkip_cmd, |
| 773 | .use_tkip = false, |
Nathan Errera | 2a42aea | 2020-09-30 16:31:17 +0300 | [diff] [blame] | 774 | .kek_kck_cmd = &kek_kck_cmd, |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 775 | }; |
| 776 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 777 | int ret; |
Nathan Errera | 9e3c393 | 2020-09-28 12:23:15 +0300 | [diff] [blame] | 778 | u8 cmd_ver; |
| 779 | size_t cmd_size; |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 780 | |
| 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 Peller | a3f7ba5 | 2015-11-11 17:23:59 +0200 | [diff] [blame] | 786 | * 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 Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 789 | */ |
Emmanuel Grumbach | 0ea9338 | 2019-06-06 10:58:46 +0300 | [diff] [blame] | 790 | /* |
| 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 Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 799 | |
| 800 | if (key_data.error) { |
| 801 | ret = -EIO; |
| 802 | goto out; |
| 803 | } |
| 804 | |
| 805 | if (key_data.use_rsc_tsc) { |
Dan Halperin | ee3ae3a | 2020-09-26 00:30:48 +0300 | [diff] [blame] | 806 | int ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP, |
Mordechay Goodstein | e80bfd1 | 2020-09-28 12:23:18 +0300 | [diff] [blame] | 807 | WOWLAN_TSC_RSC_PARAM, |
| 808 | IWL_FW_CMD_VER_UNKNOWN); |
Dan Halperin | ee3ae3a | 2020-09-26 00:30:48 +0300 | [diff] [blame] | 809 | 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 Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 827 | key_data.rsc_tsc); |
Dan Halperin | ee3ae3a | 2020-09-26 00:30:48 +0300 | [diff] [blame] | 828 | |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 829 | if (ret) |
| 830 | goto out; |
| 831 | } |
| 832 | |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 833 | if (key_data.use_tkip && |
| 834 | !fw_has_api(&mvm->fw->ucode_capa, |
| 835 | IWL_UCODE_TLV_API_TKIP_MIC_KEYS)) { |
Dan Halperin | 870bde7 | 2020-09-26 00:30:45 +0300 | [diff] [blame] | 836 | int ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP, |
Mordechay Goodstein | e80bfd1 | 2020-09-28 12:23:18 +0300 | [diff] [blame] | 837 | WOWLAN_TKIP_PARAM, |
| 838 | IWL_FW_CMD_VER_UNKNOWN); |
Dan Halperin | 870bde7 | 2020-09-26 00:30:45 +0300 | [diff] [blame] | 839 | 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 Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 854 | ret = iwl_mvm_send_cmd_pdu(mvm, |
| 855 | WOWLAN_TKIP_PARAM, |
Dan Halperin | 870bde7 | 2020-09-26 00:30:45 +0300 | [diff] [blame] | 856 | cmd_flags, size, |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 857 | &tkip_cmd); |
| 858 | if (ret) |
| 859 | goto out; |
| 860 | } |
| 861 | |
Eliad Peller | a3f7ba5 | 2015-11-11 17:23:59 +0200 | [diff] [blame] | 862 | /* configure rekey data only if offloaded rekey is supported (d3) */ |
Emmanuel Grumbach | 0ea9338 | 2019-06-06 10:58:46 +0300 | [diff] [blame] | 863 | if (mvmvif->rekey_data.valid) { |
Mordechay Goodstein | e80bfd1 | 2020-09-28 12:23:18 +0300 | [diff] [blame] | 864 | 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 Errera | 9e3c393 | 2020-09-28 12:23:15 +0300 | [diff] [blame] | 868 | 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 Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 876 | memcpy(kek_kck_cmd.kck, mvmvif->rekey_data.kck, |
Nathan Errera | 2a42aea | 2020-09-30 16:31:17 +0300 | [diff] [blame] | 877 | mvmvif->rekey_data.kck_len); |
| 878 | kek_kck_cmd.kck_len = cpu_to_le16(mvmvif->rekey_data.kck_len); |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 879 | memcpy(kek_kck_cmd.kek, mvmvif->rekey_data.kek, |
Nathan Errera | 2a42aea | 2020-09-30 16:31:17 +0300 | [diff] [blame] | 880 | mvmvif->rekey_data.kek_len); |
| 881 | kek_kck_cmd.kek_len = cpu_to_le16(mvmvif->rekey_data.kek_len); |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 882 | kek_kck_cmd.replay_ctr = mvmvif->rekey_data.replay_ctr; |
Nathan Errera | 2a42aea | 2020-09-30 16:31:17 +0300 | [diff] [blame] | 883 | kek_kck_cmd.akm = cpu_to_le32(mvmvif->rekey_data.akm); |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 884 | |
Sara Sharon | 19d9fa7 | 2020-09-30 16:31:20 +0300 | [diff] [blame] | 885 | IWL_DEBUG_WOWLAN(mvm, "setting akm %d\n", |
| 886 | mvmvif->rekey_data.akm); |
| 887 | |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 888 | ret = iwl_mvm_send_cmd_pdu(mvm, |
| 889 | WOWLAN_KEK_KCK_MATERIAL, cmd_flags, |
Nathan Errera | 9e3c393 | 2020-09-28 12:23:15 +0300 | [diff] [blame] | 890 | cmd_size, |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 891 | &kek_kck_cmd); |
| 892 | if (ret) |
| 893 | goto out; |
| 894 | } |
Eliad Peller | 3f50a69 | 2015-11-15 15:44:17 +0200 | [diff] [blame] | 895 | ret = 0; |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 896 | out: |
| 897 | kfree(key_data.rsc_tsc); |
| 898 | return ret; |
| 899 | } |
| 900 | |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 901 | static int |
| 902 | iwl_mvm_wowlan_config(struct iwl_mvm *mvm, |
| 903 | struct cfg80211_wowlan *wowlan, |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 904 | struct iwl_wowlan_config_cmd *wowlan_config_cmd, |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 905 | struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif, |
| 906 | struct ieee80211_sta *ap_sta) |
| 907 | { |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 908 | int ret; |
Matti Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 909 | bool unified_image = fw_has_capa(&mvm->fw->ucode_capa, |
| 910 | IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 911 | |
Alex Malamud | ba7136f | 2019-06-10 15:19:23 +0300 | [diff] [blame] | 912 | mvm->offload_tid = wowlan_config_cmd->offloading_tid; |
| 913 | |
Matti Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 914 | if (!unified_image) { |
| 915 | ret = iwl_mvm_switch_to_d3(mvm); |
| 916 | if (ret) |
| 917 | return ret; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 918 | |
Matti Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 919 | ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta); |
| 920 | if (ret) |
| 921 | return ret; |
| 922 | } |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 923 | |
Emmanuel Grumbach | f4bfdc5 | 2020-04-24 18:48:13 +0300 | [diff] [blame] | 924 | /* |
| 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 934 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 935 | ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0, |
| 936 | sizeof(*wowlan_config_cmd), |
| 937 | wowlan_config_cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 938 | if (ret) |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 939 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 940 | |
Luca Coelho | 0c546fb | 2019-03-12 16:01:24 +0200 | [diff] [blame] | 941 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 946 | if (ret) |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 947 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 948 | |
Johannes Berg | debdc23 | 2017-10-26 22:57:57 +0200 | [diff] [blame] | 949 | return iwl_mvm_send_proto_offload(mvm, vif, false, true, 0); |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 950 | } |
| 951 | |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 952 | static int |
| 953 | iwl_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 Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 958 | struct iwl_wowlan_config_cmd wowlan_config_cmd = {}; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 959 | int ret; |
Matti Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 960 | bool unified_image = fw_has_capa(&mvm->fw->ucode_capa, |
| 961 | IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 962 | |
Matti Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 963 | if (!unified_image) { |
| 964 | ret = iwl_mvm_switch_to_d3(mvm); |
| 965 | if (ret) |
| 966 | return ret; |
Luca Coelho | 5a143db | 2016-10-05 09:28:53 +0300 | [diff] [blame] | 967 | } 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 Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 976 | } |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 977 | |
| 978 | /* rfkill release can be either for wowlan or netdetect */ |
| 979 | if (wowlan->rfkill_release) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 980 | wowlan_config_cmd.wakeup_filter |= |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 981 | cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT); |
| 982 | |
Haim Dreyfuss | f005fd8 | 2019-07-16 12:44:40 +0300 | [diff] [blame] | 983 | wowlan_config_cmd.sta_id = mvm->aux_sta.sta_id; |
| 984 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 985 | ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0, |
| 986 | sizeof(wowlan_config_cmd), |
| 987 | &wowlan_config_cmd); |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 988 | if (ret) |
| 989 | return ret; |
| 990 | |
Luciano Coelho | 19945df | 2015-03-20 16:11:28 +0200 | [diff] [blame] | 991 | ret = iwl_mvm_sched_scan_start(mvm, vif, nd_config, &mvm->nd_ies, |
| 992 | IWL_MVM_SCAN_NETDETECT); |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 993 | if (ret) |
| 994 | return ret; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 995 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 996 | if (WARN_ON(mvm->nd_match_sets || mvm->nd_channels)) |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 997 | return -EBUSY; |
| 998 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 999 | /* save the sched scan matchsets... */ |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1000 | 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 Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1009 | /* ...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 Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1017 | return 0; |
| 1018 | } |
| 1019 | |
| 1020 | static 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 Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1025 | kfree(mvm->nd_channels); |
| 1026 | mvm->nd_channels = NULL; |
| 1027 | mvm->n_nd_channels = 0; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1028 | } |
| 1029 | |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1030 | static 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 Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1035 | struct ieee80211_vif *vif = NULL; |
| 1036 | struct iwl_mvm_vif *mvmvif = NULL; |
| 1037 | struct ieee80211_sta *ap_sta = NULL; |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1038 | 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 Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 1054 | bool unified_image = fw_has_capa(&mvm->fw->ucode_capa, |
| 1055 | IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1056 | |
| 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 Berg | 1019f9e | 2019-09-30 14:45:54 +0200 | [diff] [blame] | 1068 | set_bit(IWL_MVM_STATUS_IN_D3, &mvm->status); |
| 1069 | |
Luciano Coelho | 7f549e2 | 2014-10-02 15:38:04 +0300 | [diff] [blame] | 1070 | vif = iwl_mvm_get_bss_vif(mvm); |
| 1071 | if (IS_ERR_OR_NULL(vif)) { |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1072 | ret = 1; |
| 1073 | goto out_noreset; |
| 1074 | } |
| 1075 | |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1076 | mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1077 | |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1078 | if (mvmvif->ap_sta_id == IWL_MVM_INVALID_STA) { |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1079 | /* if we're not associated, this must be netdetect */ |
Luca Coelho | 566f165 | 2015-10-25 22:55:32 +0200 | [diff] [blame] | 1080 | if (!wowlan->nd_config) { |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1081 | ret = 1; |
| 1082 | goto out_noreset; |
| 1083 | } |
| 1084 | |
| 1085 | ret = iwl_mvm_netdetect_config( |
Luca Coelho | 566f165 | 2015-10-25 22:55:32 +0200 | [diff] [blame] | 1086 | mvm, wowlan, wowlan->nd_config, vif); |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1087 | if (ret) |
| 1088 | goto out; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1089 | |
| 1090 | mvm->net_detect = true; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1091 | } else { |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 1092 | struct iwl_wowlan_config_cmd wowlan_config_cmd = {}; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1093 | |
Haim Dreyfuss | f005fd8 | 2019-07-16 12:44:40 +0300 | [diff] [blame] | 1094 | wowlan_config_cmd.sta_id = mvmvif->ap_sta_id; |
| 1095 | |
Luciano Coelho | 1e4d19c | 2014-09-22 13:01:59 +0300 | [diff] [blame] | 1096 | 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 Coelho | 1e4d19c | 2014-09-22 13:01:59 +0300 | [diff] [blame] | 1108 | ret = iwl_mvm_wowlan_config(mvm, wowlan, &wowlan_config_cmd, |
| 1109 | vif, mvmvif, ap_sta); |
| 1110 | if (ret) |
| 1111 | goto out; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1112 | |
| 1113 | mvm->net_detect = false; |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1114 | } |
| 1115 | |
Emmanuel Grumbach | c1cb92f | 2014-01-28 10:17:18 +0200 | [diff] [blame] | 1116 | ret = iwl_mvm_power_update_device(mvm); |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 1117 | if (ret) |
| 1118 | goto out; |
| 1119 | |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 1120 | ret = iwl_mvm_power_update_mac(mvm); |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 1121 | if (ret) |
| 1122 | goto out; |
| 1123 | |
Johannes Berg | b011471 | 2013-06-12 14:55:40 +0200 | [diff] [blame] | 1124 | #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 Coelho | e8a583f | 2018-03-07 18:46:01 +0200 | [diff] [blame] | 1130 | /* |
Shahar S Matityahu | c040fe8 | 2019-05-19 10:16:13 +0300 | [diff] [blame] | 1131 | * 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 Coelho | e8a583f | 2018-03-07 18:46:01 +0200 | [diff] [blame] | 1134 | */ |
Luca Coelho | 286ca8e | 2019-07-12 15:03:48 +0300 | [diff] [blame] | 1135 | if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_9000) |
Shahar S Matityahu | 5760583 | 2019-05-19 10:52:59 +0300 | [diff] [blame] | 1136 | iwl_fw_dbg_stop_restart_recording(&mvm->fwrt, NULL, true); |
Luca Coelho | e8a583f | 2018-03-07 18:46:01 +0200 | [diff] [blame] | 1137 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1138 | /* must be last -- this switches firmware state */ |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1139 | ret = iwl_mvm_send_cmd(mvm, &d3_cfg_cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1140 | if (ret) |
| 1141 | goto out; |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1142 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Johannes Berg | 65b3034 | 2014-01-08 13:16:33 +0100 | [diff] [blame] | 1143 | len = iwl_rx_packet_payload_len(d3_cfg_cmd.resp_pkt); |
| 1144 | if (len >= sizeof(u32)) { |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1145 | mvm->d3_test_pme_ptr = |
| 1146 | le32_to_cpup((__le32 *)d3_cfg_cmd.resp_pkt->data); |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1147 | } |
| 1148 | #endif |
| 1149 | iwl_free_resp(&d3_cfg_cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1150 | |
| 1151 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 1152 | |
Haim Dreyfuss | e5f3f21 | 2019-04-03 14:37:54 +0300 | [diff] [blame] | 1153 | ret = iwl_trans_d3_suspend(mvm->trans, test, !unified_image); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1154 | out: |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1155 | if (ret < 0) { |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1156 | iwl_mvm_free_nd(mvm); |
Luca Coelho | bac453a | 2016-10-07 15:16:26 +0300 | [diff] [blame] | 1157 | |
| 1158 | if (!unified_image) { |
Johannes Berg | 3b37f4c | 2017-05-30 16:45:31 +0200 | [diff] [blame] | 1159 | if (mvm->fw_restart > 0) { |
| 1160 | mvm->fw_restart--; |
Luca Coelho | bac453a | 2016-10-07 15:16:26 +0300 | [diff] [blame] | 1161 | ieee80211_restart_hw(mvm->hw); |
| 1162 | } |
| 1163 | } |
Johannes Berg | 1019f9e | 2019-09-30 14:45:54 +0200 | [diff] [blame] | 1164 | |
| 1165 | clear_bit(IWL_MVM_STATUS_IN_D3, &mvm->status); |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1166 | } |
Luciano Coelho | b70ab72 | 2013-11-19 22:53:41 +0200 | [diff] [blame] | 1167 | out_noreset: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1168 | mutex_unlock(&mvm->mutex); |
| 1169 | |
| 1170 | return ret; |
| 1171 | } |
| 1172 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1173 | int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
| 1174 | { |
Eliad Peller | d15a747 | 2014-03-27 18:53:12 +0200 | [diff] [blame] | 1175 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 1176 | struct iwl_trans *trans = mvm->trans; |
Eliad Peller | c43fe90 | 2015-06-04 21:59:32 +0300 | [diff] [blame] | 1177 | int ret; |
Eliad Peller | d15a747 | 2014-03-27 18:53:12 +0200 | [diff] [blame] | 1178 | |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 1179 | iwl_mvm_pause_tcm(mvm, true); |
Luciano Coelho | cf8c3cf | 2015-08-24 14:53:25 +0300 | [diff] [blame] | 1180 | |
Haim Dreyfuss | 7f8ae00 | 2017-12-27 15:21:18 +0200 | [diff] [blame] | 1181 | iwl_fw_runtime_suspend(&mvm->fwrt); |
| 1182 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 1183 | ret = iwl_trans_suspend(trans); |
Eliad Peller | c43fe90 | 2015-06-04 21:59:32 +0300 | [diff] [blame] | 1184 | if (ret) |
| 1185 | return ret; |
| 1186 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 1187 | trans->system_pm_mode = IWL_PLAT_PM_MODE_D3; |
| 1188 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1189 | return __iwl_mvm_suspend(hw, wowlan, false); |
| 1190 | } |
| 1191 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1192 | /* converted data from the different status responses */ |
| 1193 | struct 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 Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1202 | static void iwl_mvm_report_wakeup_reasons(struct iwl_mvm *mvm, |
| 1203 | struct ieee80211_vif *vif, |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1204 | struct iwl_wowlan_status_data *status) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1205 | { |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1206 | struct sk_buff *pkt = NULL; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1207 | struct cfg80211_wowlan_wakeup wakeup = { |
| 1208 | .pattern_idx = -1, |
| 1209 | }; |
| 1210 | struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1211 | u32 reasons = status->wakeup_reasons; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1212 | |
| 1213 | if (reasons == IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) { |
| 1214 | wakeup_report = NULL; |
| 1215 | goto report; |
| 1216 | } |
| 1217 | |
Derek Basehore | 06ae2ad | 2015-11-04 17:37:52 -0800 | [diff] [blame] | 1218 | pm_wakeup_event(mvm->dev, 0); |
| 1219 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1220 | if (reasons & IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1221 | wakeup.magic_pkt = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1222 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1223 | if (reasons & IWL_WOWLAN_WAKEUP_BY_PATTERN) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1224 | wakeup.pattern_idx = |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1225 | status->pattern_number; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1226 | |
| 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 Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1231 | if (reasons & IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1232 | wakeup.gtk_rekey_failure = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1233 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1234 | if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1235 | wakeup.rfkill_release = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1236 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1237 | if (reasons & IWL_WOWLAN_WAKEUP_BY_EAPOL_REQUEST) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1238 | wakeup.eap_identity_req = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1239 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1240 | if (reasons & IWL_WOWLAN_WAKEUP_BY_FOUR_WAY_HANDSHAKE) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1241 | wakeup.four_way_handshake = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1242 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 1243 | 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 Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1252 | if (status->wake_packet_bufsize) { |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1253 | int pktsize = status->wake_packet_bufsize; |
| 1254 | int pktlen = status->wake_packet_length; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1255 | const u8 *pktdata = status->wake_packet; |
| 1256 | struct ieee80211_hdr *hdr = (void *)pktdata; |
| 1257 | int truncated = pktlen - pktsize; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1258 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1259 | /* 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 Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1267 | pkt = alloc_skb(pktsize, GFP_KERNEL); |
| 1268 | if (!pkt) |
| 1269 | goto report; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1270 | |
Johannes Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 1271 | skb_put_data(pkt, pktdata, hdrlen); |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1272 | pktdata += hdrlen; |
| 1273 | pktsize -= hdrlen; |
| 1274 | |
| 1275 | if (ieee80211_has_protected(hdr->frame_control)) { |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1276 | /* |
| 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 Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1282 | 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 Berg | 59ae1d1 | 2017-06-16 14:29:20 +0200 | [diff] [blame] | 1303 | skb_put_data(pkt, pktdata, pktsize); |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1304 | |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1305 | 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 Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1309 | wakeup.packet_len = pkt->len - truncated; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1310 | wakeup.packet_80211 = false; |
| 1311 | } else { |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1312 | 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 Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1322 | wakeup.packet = status->wake_packet; |
| 1323 | wakeup.packet_present_len = pktsize; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1324 | wakeup.packet_len = pktlen - truncated; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1325 | wakeup.packet_80211 = true; |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | report: |
| 1330 | ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL); |
| 1331 | kfree_skb(pkt); |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1332 | } |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1333 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1334 | static 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 | |
| 1348 | static 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 Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1355 | static void iwl_mvm_set_aes_rx_seq(struct iwl_mvm *mvm, struct aes_sc *scs, |
| 1356 | struct ieee80211_sta *sta, |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1357 | struct ieee80211_key_conf *key) |
| 1358 | { |
| 1359 | int tid; |
| 1360 | |
| 1361 | BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS); |
| 1362 | |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1363 | if (sta && iwl_mvm_has_new_rx_api(mvm)) { |
| 1364 | struct iwl_mvm_sta *mvmsta; |
| 1365 | struct iwl_mvm_key_pn *ptk_pn; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1366 | |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1367 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 1368 | |
Sara Sharon | efa40c7 | 2020-10-08 18:12:42 +0300 | [diff] [blame] | 1369 | rcu_read_lock(); |
| 1370 | ptk_pn = rcu_dereference(mvmsta->ptk_pn[key->keyidx]); |
| 1371 | if (WARN_ON(!ptk_pn)) { |
| 1372 | rcu_read_unlock(); |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1373 | return; |
Sara Sharon | efa40c7 | 2020-10-08 18:12:42 +0300 | [diff] [blame] | 1374 | } |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1375 | |
| 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 Sharon | efa40c7 | 2020-10-08 18:12:42 +0300 | [diff] [blame] | 1386 | rcu_read_unlock(); |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1387 | } 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 Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1394 | } |
| 1395 | } |
| 1396 | |
| 1397 | static 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 Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1412 | static void iwl_mvm_set_key_rx_seq(struct iwl_mvm *mvm, |
| 1413 | struct ieee80211_key_conf *key, |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1414 | struct iwl_wowlan_status *status) |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1415 | { |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1416 | union iwl_all_tsc_rsc *rsc = &status->gtk[0].rsc.all_tsc_rsc; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1417 | |
| 1418 | switch (key->cipher) { |
| 1419 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | c7f996e | 2020-09-30 16:31:18 +0300 | [diff] [blame] | 1420 | case WLAN_CIPHER_SUITE_GCMP: |
| 1421 | case WLAN_CIPHER_SUITE_GCMP_256: |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1422 | iwl_mvm_set_aes_rx_seq(mvm, rsc->aes.multicast_rsc, NULL, key); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1423 | 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 | |
| 1432 | struct iwl_mvm_d3_gtk_iter_data { |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1433 | struct iwl_mvm *mvm; |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1434 | struct iwl_wowlan_status *status; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1435 | void *last_gtk; |
| 1436 | u32 cipher; |
| 1437 | bool find_phase, unhandled_cipher; |
| 1438 | int num_keys; |
| 1439 | }; |
| 1440 | |
Emmanuel Grumbach | 59fd4bf | 2015-11-01 13:06:37 +0200 | [diff] [blame] | 1441 | static void iwl_mvm_d3_update_keys(struct ieee80211_hw *hw, |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1442 | 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 Berg | c7f996e | 2020-09-30 16:31:18 +0300 | [diff] [blame] | 1458 | case WLAN_CIPHER_SUITE_GCMP: |
| 1459 | case WLAN_CIPHER_SUITE_GCMP_256: |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1460 | 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 Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1477 | union iwl_all_tsc_rsc *sc = |
| 1478 | &data->status->gtk[0].rsc.all_tsc_rsc; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1479 | |
| 1480 | if (data->find_phase) |
| 1481 | return; |
| 1482 | |
| 1483 | switch (key->cipher) { |
| 1484 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | c7f996e | 2020-09-30 16:31:18 +0300 | [diff] [blame] | 1485 | case WLAN_CIPHER_SUITE_GCMP: |
| 1486 | case WLAN_CIPHER_SUITE_GCMP_256: |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1487 | iwl_mvm_set_aes_rx_seq(data->mvm, sc->aes.unicast_rsc, |
| 1488 | sta, key); |
Johannes Berg | 6645d5e | 2015-09-15 09:58:53 +0200 | [diff] [blame] | 1489 | atomic64_set(&key->tx_pn, le64_to_cpu(sc->aes.tsc.pn)); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1490 | 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 Peller | 1ad4f63 | 2016-02-14 13:56:36 +0200 | [diff] [blame] | 1494 | atomic64_set(&key->tx_pn, |
| 1495 | (u64)seq.tkip.iv16 | |
| 1496 | ((u64)seq.tkip.iv32 << 16)); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1497 | break; |
| 1498 | } |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1499 | |
| 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 Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1513 | iwl_mvm_set_key_rx_seq(data->mvm, key, data->status); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1514 | } |
| 1515 | |
| 1516 | static bool iwl_mvm_setup_connection_keep(struct iwl_mvm *mvm, |
| 1517 | struct ieee80211_vif *vif, |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1518 | struct iwl_wowlan_status *status) |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1519 | { |
| 1520 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1521 | struct iwl_mvm_d3_gtk_iter_data gtkdata = { |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1522 | .mvm = mvm, |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1523 | .status = status, |
| 1524 | }; |
Eliad Peller | 431591c | 2013-11-07 14:12:09 +0200 | [diff] [blame] | 1525 | u32 disconnection_reasons = |
| 1526 | IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON | |
| 1527 | IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1528 | |
| 1529 | if (!status || !vif->bss_conf.bssid) |
| 1530 | return false; |
| 1531 | |
Eliad Peller | 431591c | 2013-11-07 14:12:09 +0200 | [diff] [blame] | 1532 | if (le32_to_cpu(status->wakeup_reasons) & disconnection_reasons) |
| 1533 | return false; |
| 1534 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1535 | /* find last GTK that we used initially, if any */ |
| 1536 | gtkdata.find_phase = true; |
| 1537 | ieee80211_iter_keys(mvm->hw, vif, |
Emmanuel Grumbach | 59fd4bf | 2015-11-01 13:06:37 +0200 | [diff] [blame] | 1538 | iwl_mvm_d3_update_keys, >kdata); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1539 | /* not trying to keep connections with MFP/unhandled ciphers */ |
| 1540 | if (gtkdata.unhandled_cipher) |
| 1541 | return false; |
| 1542 | if (!gtkdata.num_keys) |
Luciano Coelho | cfa8889 | 2013-11-19 15:38:55 +0200 | [diff] [blame] | 1543 | goto out; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1544 | 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 Grumbach | 59fd4bf | 2015-11-01 13:06:37 +0200 | [diff] [blame] | 1553 | iwl_mvm_d3_update_keys, >kdata); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1554 | |
Sara Sharon | 19d9fa7 | 2020-09-30 16:31:20 +0300 | [diff] [blame] | 1555 | IWL_DEBUG_WOWLAN(mvm, "num of GTK rekeying %d\n", |
| 1556 | le32_to_cpu(status->num_of_gtk_rekeys)); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1557 | 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 Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1564 | .conf.keyidx = |
| 1565 | iwlmvm_wowlan_gtk_idx(&status->gtk[0]), |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1566 | }; |
Luca Coelho | 11a0513 | 2018-02-27 16:37:56 +0200 | [diff] [blame] | 1567 | __be64 replay_ctr; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1568 | |
Sara Sharon | 19d9fa7 | 2020-09-30 16:31:20 +0300 | [diff] [blame] | 1569 | IWL_DEBUG_WOWLAN(mvm, |
| 1570 | "Received from FW GTK cipher %d, key index %d\n", |
| 1571 | conf.conf.cipher, conf.conf.keyidx); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1572 | switch (gtkdata.cipher) { |
| 1573 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | c7f996e | 2020-09-30 16:31:18 +0300 | [diff] [blame] | 1574 | 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 Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1577 | conf.conf.keylen = WLAN_KEY_LEN_CCMP; |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1578 | memcpy(conf.conf.key, status->gtk[0].key, |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1579 | WLAN_KEY_LEN_CCMP); |
| 1580 | break; |
Johannes Berg | c7f996e | 2020-09-30 16:31:18 +0300 | [diff] [blame] | 1581 | 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 Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1587 | case WLAN_CIPHER_SUITE_TKIP: |
Johannes Berg | c7f996e | 2020-09-30 16:31:18 +0300 | [diff] [blame] | 1588 | BUILD_BUG_ON(sizeof(conf.key) < WLAN_KEY_LEN_TKIP); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1589 | conf.conf.keylen = WLAN_KEY_LEN_TKIP; |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1590 | memcpy(conf.conf.key, status->gtk[0].key, 16); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1591 | /* 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 Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1594 | status->gtk[0].tkip_mic_key, 8); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1595 | break; |
| 1596 | } |
| 1597 | |
| 1598 | key = ieee80211_gtk_rekey_add(vif, &conf.conf); |
| 1599 | if (IS_ERR(key)) |
| 1600 | return false; |
Johannes Berg | f5e28ea | 2015-12-06 14:58:08 +0200 | [diff] [blame] | 1601 | iwl_mvm_set_key_rx_seq(mvm, key, status); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1602 | |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1603 | replay_ctr = |
| 1604 | cpu_to_be64(le64_to_cpu(status->replay_ctr)); |
Luca Coelho | 11a0513 | 2018-02-27 16:37:56 +0200 | [diff] [blame] | 1605 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1606 | ieee80211_gtk_rekey_notify(vif, vif->bss_conf.bssid, |
| 1607 | (void *)&replay_ctr, GFP_KERNEL); |
| 1608 | } |
| 1609 | |
Luciano Coelho | cfa8889 | 2013-11-19 15:38:55 +0200 | [diff] [blame] | 1610 | out: |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1611 | 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 Berg | bc68163 | 2020-09-30 19:19:50 +0300 | [diff] [blame] | 1618 | /* Occasionally, templates would be nice. This is one of those times ... */ |
| 1619 | #define iwl_mvm_parse_wowlan_status_common(_ver) \ |
| 1620 | static struct iwl_wowlan_status * \ |
| 1621 | iwl_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 | |
| 1660 | iwl_mvm_parse_wowlan_status_common(v6) |
| 1661 | iwl_mvm_parse_wowlan_status_common(v7) |
| 1662 | iwl_mvm_parse_wowlan_status_common(v9) |
| 1663 | |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1664 | struct iwl_wowlan_status *iwl_mvm_send_wowlan_get_status(struct iwl_mvm *mvm) |
| 1665 | { |
Mordechay Goodstein | 250380c | 2020-04-17 13:21:37 +0300 | [diff] [blame] | 1666 | struct iwl_wowlan_status *status; |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1667 | struct iwl_host_cmd cmd = { |
| 1668 | .id = WOWLAN_GET_STATUSES, |
| 1669 | .flags = CMD_WANT_SKB, |
| 1670 | }; |
Johannes Berg | bc68163 | 2020-09-30 19:19:50 +0300 | [diff] [blame] | 1671 | int ret, len; |
Mordechay Goodstein | 250380c | 2020-04-17 13:21:37 +0300 | [diff] [blame] | 1672 | u8 notif_ver; |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1673 | |
| 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 Goodstein | 250380c | 2020-04-17 13:21:37 +0300 | [diff] [blame] | 1682 | len = iwl_rx_packet_payload_len(cmd.resp_pkt); |
Johannes Berg | bc68163 | 2020-09-30 19:19:50 +0300 | [diff] [blame] | 1683 | |
| 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 Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1688 | 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 Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1691 | |
Johannes Berg | bc68163 | 2020-09-30 19:19:50 +0300 | [diff] [blame] | 1692 | status = iwl_mvm_parse_wowlan_status_common_v6(mvm, |
| 1693 | cmd.resp_pkt->data, |
| 1694 | len); |
| 1695 | if (IS_ERR(status)) |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1696 | 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 Berg | bc68163 | 2020-09-30 19:19:50 +0300 | [diff] [blame] | 1720 | } else if (notif_ver == 7) { |
| 1721 | struct iwl_wowlan_status_v7 *v7 = (void *)cmd.resp_pkt->data; |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1722 | |
Johannes Berg | bc68163 | 2020-09-30 19:19:50 +0300 | [diff] [blame] | 1723 | 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 Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1728 | |
Johannes Berg | bc68163 | 2020-09-30 19:19:50 +0300 | [diff] [blame] | 1729 | 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 Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1733 | |
Johannes Berg | bc68163 | 2020-09-30 19:19:50 +0300 | [diff] [blame] | 1734 | 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 Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1739 | |
Johannes Berg | bc68163 | 2020-09-30 19:19:50 +0300 | [diff] [blame] | 1740 | status->gtk[0] = v9->gtk[0]; |
| 1741 | status->igtk[0] = v9->igtk[0]; |
Mordechay Goodstein | 250380c | 2020-04-17 13:21:37 +0300 | [diff] [blame] | 1742 | |
Johannes Berg | bc68163 | 2020-09-30 19:19:50 +0300 | [diff] [blame] | 1743 | 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 Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1748 | status = ERR_PTR(-EIO); |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1749 | } |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1750 | |
| 1751 | out_free_resp: |
| 1752 | iwl_free_resp(&cmd); |
| 1753 | return status; |
| 1754 | } |
| 1755 | |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1756 | static struct iwl_wowlan_status * |
Shahar S Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 1757 | iwl_mvm_get_wakeup_status(struct iwl_mvm *mvm) |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1758 | { |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1759 | int ret; |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1760 | |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1761 | /* only for tracing for now */ |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1762 | ret = iwl_mvm_send_cmd_pdu(mvm, OFFLOADS_QUERY_CMD, 0, 0, NULL); |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1763 | if (ret) |
| 1764 | IWL_ERR(mvm, "failed to query offload statistics (%d)\n", ret); |
| 1765 | |
Luca Coelho | 2afa6a7 | 2018-03-26 10:24:18 +0300 | [diff] [blame] | 1766 | return iwl_mvm_send_wowlan_get_status(mvm); |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | /* releases the MVM mutex */ |
| 1770 | static 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 Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1777 | struct iwl_mvm_sta *mvm_ap_sta; |
| 1778 | |
Shahar S Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 1779 | fw_status = iwl_mvm_get_wakeup_status(mvm); |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1780 | if (IS_ERR_OR_NULL(fw_status)) |
| 1781 | goto out_unlock; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1782 | |
Sara Sharon | 19d9fa7 | 2020-09-30 16:31:20 +0300 | [diff] [blame] | 1783 | IWL_DEBUG_WOWLAN(mvm, "wakeup reason 0x%x\n", |
| 1784 | le32_to_cpu(fw_status->wakeup_reasons)); |
| 1785 | |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1786 | 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 Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1796 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1797 | /* still at hard-coded place 0 for D3 image */ |
Sara Sharon | 13303c0 | 2016-04-10 15:51:54 +0300 | [diff] [blame] | 1798 | mvm_ap_sta = iwl_mvm_sta_from_staid_protected(mvm, 0); |
| 1799 | if (!mvm_ap_sta) |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1800 | goto out_free; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1801 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1802 | 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 Coelho | 286ca8e | 2019-07-12 15:03:48 +0300 | [diff] [blame] | 1809 | if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000) { |
Alex Malamud | ba7136f | 2019-06-10 15:19:23 +0300 | [diff] [blame] | 1810 | 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 Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1816 | /* now we have all the data we need, unlock to avoid mac80211 issues */ |
| 1817 | mutex_unlock(&mvm->mutex); |
| 1818 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1819 | iwl_mvm_report_wakeup_reasons(mvm, vif, &status); |
| 1820 | |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1821 | keep = iwl_mvm_setup_connection_keep(mvm, vif, fw_status); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1822 | |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1823 | kfree(fw_status); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1824 | return keep; |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1825 | |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1826 | out_free: |
| 1827 | kfree(fw_status); |
| 1828 | out_unlock: |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1829 | mutex_unlock(&mvm->mutex); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1830 | return false; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1831 | } |
| 1832 | |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1833 | #define ND_QUERY_BUF_LEN (sizeof(struct iwl_scan_offload_profile_match) * \ |
| 1834 | IWL_SCAN_MAX_PROFILES) |
| 1835 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1836 | struct iwl_mvm_nd_query_results { |
| 1837 | u32 matched_profiles; |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1838 | u8 matches[ND_QUERY_BUF_LEN]; |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1839 | }; |
| 1840 | |
| 1841 | static int |
| 1842 | iwl_mvm_netdetect_query_results(struct iwl_mvm *mvm, |
| 1843 | struct iwl_mvm_nd_query_results *results) |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1844 | { |
| 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 Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1851 | size_t query_len, matches_len; |
Tova Mussai | 5d1234b | 2019-11-05 12:56:14 +0200 | [diff] [blame] | 1852 | int max_profiles = iwl_umac_scan_get_max_profiles(mvm->fw); |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1853 | |
| 1854 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 1855 | if (ret) { |
| 1856 | IWL_ERR(mvm, "failed to query matched profiles (%d)\n", ret); |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1857 | return ret; |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1858 | } |
| 1859 | |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1860 | 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 Mussai | 5d1234b | 2019-11-05 12:56:14 +0200 | [diff] [blame] | 1864 | max_profiles; |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1865 | } else { |
| 1866 | query_len = sizeof(struct iwl_scan_offload_profiles_query_v1); |
| 1867 | matches_len = sizeof(struct iwl_scan_offload_profile_match_v1) * |
Tova Mussai | 5d1234b | 2019-11-05 12:56:14 +0200 | [diff] [blame] | 1868 | max_profiles; |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1869 | } |
| 1870 | |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1871 | len = iwl_rx_packet_payload_len(cmd.resp_pkt); |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1872 | if (len < query_len) { |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1873 | IWL_ERR(mvm, "Invalid scan offload profiles query response!\n"); |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1874 | ret = -EIO; |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1875 | goto out_free_resp; |
| 1876 | } |
| 1877 | |
| 1878 | query = (void *)cmd.resp_pkt->data; |
| 1879 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1880 | results->matched_profiles = le32_to_cpu(query->matched_profiles); |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1881 | memcpy(results->matches, query->matches, matches_len); |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1882 | |
Emmanuel Grumbach | 6bbd552 | 2015-04-28 15:00:23 +0300 | [diff] [blame] | 1883 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Luciano Coelho | 484b3d1 | 2015-03-30 20:46:32 +0300 | [diff] [blame] | 1884 | mvm->last_netdetect_scans = le32_to_cpu(query->n_scans_done); |
| 1885 | #endif |
| 1886 | |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1887 | out_free_resp: |
| 1888 | iwl_free_resp(&cmd); |
| 1889 | return ret; |
| 1890 | } |
| 1891 | |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1892 | static 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 | |
| 1916 | static 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 Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1943 | static void iwl_mvm_query_netdetect_reasons(struct iwl_mvm *mvm, |
| 1944 | struct ieee80211_vif *vif) |
| 1945 | { |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1946 | struct cfg80211_wowlan_nd_info *net_detect = NULL; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1947 | struct cfg80211_wowlan_wakeup wakeup = { |
| 1948 | .pattern_idx = -1, |
| 1949 | }; |
| 1950 | struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup; |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1951 | struct iwl_mvm_nd_query_results query; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1952 | struct iwl_wowlan_status *fw_status; |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1953 | unsigned long matched_profiles; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1954 | u32 reasons = 0; |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1955 | int i, n_matches, ret; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1956 | |
Shahar S Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 1957 | fw_status = iwl_mvm_get_wakeup_status(mvm); |
Haim Dreyfuss | 2fc863a | 2015-05-20 08:10:43 +0300 | [diff] [blame] | 1958 | if (!IS_ERR_OR_NULL(fw_status)) { |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1959 | reasons = le32_to_cpu(fw_status->wakeup_reasons); |
Haim Dreyfuss | 2fc863a | 2015-05-20 08:10:43 +0300 | [diff] [blame] | 1960 | kfree(fw_status); |
| 1961 | } |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1962 | |
| 1963 | if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED) |
| 1964 | wakeup.rfkill_release = true; |
| 1965 | |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1966 | if (reasons != IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) |
| 1967 | goto out; |
| 1968 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1969 | ret = iwl_mvm_netdetect_query_results(mvm, &query); |
| 1970 | if (ret || !query.matched_profiles) { |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1971 | wakeup_report = NULL; |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1972 | goto out; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1973 | } |
| 1974 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1975 | matched_profiles = query.matched_profiles; |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1976 | 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. Silva | 83ea00d | 2018-08-23 20:15:40 -0500 | [diff] [blame] | 1983 | net_detect = kzalloc(struct_size(net_detect, matches, n_matches), |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1984 | 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 Coelho | ae90c2e5 | 2015-05-06 10:45:42 +0300 | [diff] [blame] | 1990 | int idx, n_channels = 0; |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1991 | |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 1992 | n_channels = iwl_mvm_query_num_match_chans(mvm, &query, i); |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1993 | |
Gustavo A. R. Silva | 83ea00d | 2018-08-23 20:15:40 -0500 | [diff] [blame] | 1994 | match = kzalloc(struct_size(match, channels, n_channels), |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1995 | GFP_KERNEL); |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1996 | if (!match) |
| 1997 | goto out_report_nd; |
| 1998 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1999 | net_detect->matches[net_detect->n_matches++] = match; |
| 2000 | |
Luciano Coelho | ae90c2e5 | 2015-05-06 10:45:42 +0300 | [diff] [blame] | 2001 | /* 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 Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 2007 | match->ssid.ssid_len); |
| 2008 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 2009 | if (mvm->n_nd_channels < n_channels) |
| 2010 | continue; |
| 2011 | |
Ilan Peer | e4fe5d4 | 2019-02-05 10:59:40 +0200 | [diff] [blame] | 2012 | iwl_mvm_query_set_freqs(mvm, &query, match, i); |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | out_report_nd: |
| 2016 | wakeup.net_detect = net_detect; |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 2017 | out: |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 2018 | iwl_mvm_free_nd(mvm); |
| 2019 | |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 2020 | mutex_unlock(&mvm->mutex); |
| 2021 | ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL); |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 2022 | |
| 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 Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 2028 | } |
| 2029 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 2030 | static 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 Goodstein | 577ddbe | 2020-01-31 15:45:30 +0200 | [diff] [blame] | 2041 | static bool iwl_mvm_rt_status(struct iwl_trans *trans, u32 base, u32 *err_id) |
Shahar S Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 2042 | { |
Shahar S Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 2043 | struct error_table_start { |
| 2044 | /* cf. struct iwl_error_event_table */ |
| 2045 | u32 valid; |
Mordechay Goodstein | 577ddbe | 2020-01-31 15:45:30 +0200 | [diff] [blame] | 2046 | __le32 err_id; |
Shahar S Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 2047 | } err_info; |
| 2048 | |
Mordechay Goodstein | 577ddbe | 2020-01-31 15:45:30 +0200 | [diff] [blame] | 2049 | if (!base) |
| 2050 | return false; |
Shahar S Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 2051 | |
Mordechay Goodstein | 577ddbe | 2020-01-31 15:45:30 +0200 | [diff] [blame] | 2052 | 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 | |
| 2060 | static 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 Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 2077 | } |
Mordechay Goodstein | 577ddbe | 2020-01-31 15:45:30 +0200 | [diff] [blame] | 2078 | |
| 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 Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 2090 | } |
| 2091 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2092 | static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2093 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2094 | struct ieee80211_vif *vif = NULL; |
Matti Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 2095 | int ret = 1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2096 | enum iwl_d3_status d3_status; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 2097 | bool keep = false; |
Matti Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 2098 | bool unified_image = fw_has_capa(&mvm->fw->ucode_capa, |
| 2099 | IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
Luca Coelho | fcea37b | 2017-04-12 16:33:41 +0300 | [diff] [blame] | 2100 | bool d0i3_first = fw_has_capa(&mvm->fw->ucode_capa, |
| 2101 | IWL_UCODE_TLV_CAPA_D0I3_END_FIRST); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2102 | |
| 2103 | mutex_lock(&mvm->mutex); |
| 2104 | |
Johannes Berg | 1019f9e | 2019-09-30 14:45:54 +0200 | [diff] [blame] | 2105 | clear_bit(IWL_MVM_STATUS_IN_D3, &mvm->status); |
| 2106 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2107 | /* get the BSS vif pointer again */ |
Luciano Coelho | 7f549e2 | 2014-10-02 15:38:04 +0300 | [diff] [blame] | 2108 | vif = iwl_mvm_get_bss_vif(mvm); |
| 2109 | if (IS_ERR_OR_NULL(vif)) |
Luciano Coelho | a500e46 | 2015-05-04 17:03:17 +0300 | [diff] [blame] | 2110 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2111 | |
Shahar S Matityahu | 2d8c261 | 2018-01-29 11:05:37 +0200 | [diff] [blame] | 2112 | iwl_fw_dbg_read_d3_debug_data(&mvm->fwrt); |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 2113 | |
Shahar S Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 2114 | 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 Matityahu | 4d75a9e | 2019-11-15 09:27:40 +0200 | [diff] [blame] | 2117 | iwl_dbg_tlv_time_point(&mvm->fwrt, |
| 2118 | IWL_FW_INI_TIME_POINT_FW_ASSERT, NULL); |
Shahar S Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 2119 | iwl_fw_dbg_collect_desc(&mvm->fwrt, &iwl_dump_desc_assert, |
Sara Sharon | 124e0eb | 2018-07-23 13:50:02 +0300 | [diff] [blame] | 2120 | false, 0); |
Shahar S Matityahu | f57d104 | 2018-07-04 17:12:49 +0300 | [diff] [blame] | 2121 | ret = 1; |
| 2122 | goto err; |
| 2123 | } |
| 2124 | |
Mordechay Goodstein | 89cb1dd | 2020-04-24 18:48:17 +0300 | [diff] [blame] | 2125 | iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_HOST_D3_END, |
| 2126 | NULL); |
| 2127 | |
Haim Dreyfuss | e5f3f21 | 2019-04-03 14:37:54 +0300 | [diff] [blame] | 2128 | 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 Coelho | fcea37b | 2017-04-12 16:33:41 +0300 | [diff] [blame] | 2137 | if (d0i3_first) { |
Haim Dreyfuss | d3b4dc01 | 2019-07-23 18:27:45 +0300 | [diff] [blame] | 2138 | 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 Coelho | fcea37b | 2017-04-12 16:33:41 +0300 | [diff] [blame] | 2145 | if (ret < 0) { |
| 2146 | IWL_ERR(mvm, "Failed to send D0I3_END_CMD first (%d)\n", |
| 2147 | ret); |
| 2148 | goto err; |
| 2149 | } |
Haim Dreyfuss | d3b4dc01 | 2019-07-23 18:27:45 +0300 | [diff] [blame] | 2150 | 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 Coelho | fcea37b | 2017-04-12 16:33:41 +0300 | [diff] [blame] | 2171 | } |
| 2172 | |
Jonathan Doron | 47c8b15 | 2014-11-27 16:55:25 +0200 | [diff] [blame] | 2173 | /* |
| 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 Adam | 6ce1e5c | 2019-06-16 13:18:28 +0300 | [diff] [blame] | 2179 | /* Re-configure PPAG settings */ |
| 2180 | iwl_mvm_ppag_send_cmd(mvm); |
| 2181 | |
Luca Coelho | 42ce76d | 2017-01-11 23:36:30 +0200 | [diff] [blame] | 2182 | if (!unified_image) |
| 2183 | /* Re-configure default SAR profile */ |
| 2184 | iwl_mvm_sar_select_profile(mvm, 1, 1); |
| 2185 | |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 2186 | if (mvm->net_detect) { |
Luca Coelho | 5a143db | 2016-10-05 09:28:53 +0300 | [diff] [blame] | 2187 | /* 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 Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 2197 | iwl_mvm_query_netdetect_reasons(mvm, vif); |
Luciano Coelho | e0ede17 | 2015-02-13 21:37:09 +0200 | [diff] [blame] | 2198 | /* has unlocked the mutex, so skip that */ |
| 2199 | goto out; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 2200 | } else { |
| 2201 | keep = iwl_mvm_query_wakeup_reasons(mvm, vif); |
Eliad Peller | 78c9df6 | 2013-11-07 14:13:30 +0200 | [diff] [blame] | 2202 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 2203 | if (keep) |
| 2204 | mvm->keep_vif = vif; |
Luciano Coelho | 0c2ae04 | 2015-03-12 09:25:15 +0200 | [diff] [blame] | 2205 | #endif |
Luciano Coelho | e0ede17 | 2015-02-13 21:37:09 +0200 | [diff] [blame] | 2206 | /* has unlocked the mutex, so skip that */ |
| 2207 | goto out_iterate; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 2208 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2209 | |
Luciano Coelho | a500e46 | 2015-05-04 17:03:17 +0300 | [diff] [blame] | 2210 | err: |
| 2211 | iwl_mvm_free_nd(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2212 | mutex_unlock(&mvm->mutex); |
| 2213 | |
Luciano Coelho | e0ede17 | 2015-02-13 21:37:09 +0200 | [diff] [blame] | 2214 | out_iterate: |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 2215 | 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 Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2219 | |
Luciano Coelho | e0ede17 | 2015-02-13 21:37:09 +0200 | [diff] [blame] | 2220 | out: |
Luca Coelho | fcea37b | 2017-04-12 16:33:41 +0300 | [diff] [blame] | 2221 | /* no need to reset the device in unified images, if successful */ |
Matti Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 2222 | if (unified_image && !ret) { |
Luca Coelho | fcea37b | 2017-04-12 16:33:41 +0300 | [diff] [blame] | 2223 | /* nothing else to do if we already sent D0I3_END_CMD */ |
| 2224 | if (d0i3_first) |
| 2225 | return 0; |
| 2226 | |
Luca Coelho | f28b936 | 2017-04-12 12:42:12 +0300 | [diff] [blame] | 2227 | ret = iwl_mvm_send_cmd_pdu(mvm, D0I3_END_CMD, 0, 0, NULL); |
Luca Coelho | fcea37b | 2017-04-12 16:33:41 +0300 | [diff] [blame] | 2228 | if (!ret) |
Matti Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 2229 | 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 Chen | 59cd827 | 2017-08-28 14:57:54 +0800 | [diff] [blame] | 2237 | set_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); |
Matti Gottlieb | 23ae612 | 2015-12-31 18:18:02 +0200 | [diff] [blame] | 2238 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2239 | return 1; |
| 2240 | } |
| 2241 | |
Eliad Peller | 2d42801 | 2015-06-17 15:32:37 +0300 | [diff] [blame] | 2242 | static 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 Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2249 | int iwl_mvm_resume(struct ieee80211_hw *hw) |
| 2250 | { |
| 2251 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2252 | int ret; |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2253 | |
Emmanuel Grumbach | 4574536 | 2019-06-06 10:47:33 +0300 | [diff] [blame] | 2254 | ret = iwl_mvm_resume_d3(mvm); |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2255 | |
| 2256 | mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED; |
| 2257 | |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 2258 | iwl_mvm_resume_tcm(mvm); |
| 2259 | |
Haim Dreyfuss | 7f8ae00 | 2017-12-27 15:21:18 +0200 | [diff] [blame] | 2260 | iwl_fw_runtime_resume(&mvm->fwrt); |
| 2261 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2262 | return ret; |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2263 | } |
| 2264 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2265 | void 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 Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2271 | |
| 2272 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 2273 | static 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 Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2283 | synchronize_net(); |
| 2284 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2285 | mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_D3; |
| 2286 | |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 2287 | iwl_mvm_pause_tcm(mvm, true); |
| 2288 | |
Haim Dreyfuss | 7f8ae00 | 2017-12-27 15:21:18 +0200 | [diff] [blame] | 2289 | iwl_fw_runtime_suspend(&mvm->fwrt); |
| 2290 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2291 | /* 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 Sharon | cfbc6c4 | 2018-08-21 15:23:39 +0300 | [diff] [blame] | 2297 | if (err) |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2298 | return err; |
Sara Sharon | cfbc6c4 | 2018-08-21 15:23:39 +0300 | [diff] [blame] | 2299 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2300 | mvm->d3_test_active = true; |
Eliad Peller | 78c9df6 | 2013-11-07 14:13:30 +0200 | [diff] [blame] | 2301 | mvm->keep_vif = NULL; |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2302 | return 0; |
| 2303 | } |
| 2304 | |
| 2305 | static 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 Peller | 4ed80a8 | 2013-11-07 13:23:21 +0200 | [diff] [blame] | 2312 | /* 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 Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2320 | if (msleep_interruptible(100)) |
| 2321 | break; |
| 2322 | } |
| 2323 | |
| 2324 | return 0; |
| 2325 | } |
| 2326 | |
| 2327 | static void iwl_mvm_d3_test_disconn_work_iter(void *_data, u8 *mac, |
| 2328 | struct ieee80211_vif *vif) |
| 2329 | { |
Eliad Peller | 78c9df6 | 2013-11-07 14:13:30 +0200 | [diff] [blame] | 2330 | /* skip the one we keep connection on */ |
| 2331 | if (_data == vif) |
| 2332 | return; |
| 2333 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2334 | if (vif->type == NL80211_IFTYPE_STATION) |
| 2335 | ieee80211_connection_loss(vif); |
| 2336 | } |
| 2337 | |
| 2338 | static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file) |
| 2339 | { |
| 2340 | struct iwl_mvm *mvm = inode->i_private; |
Luca Coelho | 85cd69b | 2016-10-05 11:24:12 +0300 | [diff] [blame] | 2341 | bool unified_image = fw_has_capa(&mvm->fw->ucode_capa, |
| 2342 | IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2343 | |
| 2344 | mvm->d3_test_active = false; |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2345 | |
Shahar S Matityahu | 2d8c261 | 2018-01-29 11:05:37 +0200 | [diff] [blame] | 2346 | iwl_fw_dbg_read_d3_debug_data(&mvm->fwrt); |
| 2347 | |
Luciano Coelho | 31ca09d | 2014-09-22 13:22:51 +0300 | [diff] [blame] | 2348 | rtnl_lock(); |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2349 | __iwl_mvm_resume(mvm, true); |
Luciano Coelho | 31ca09d | 2014-09-22 13:22:51 +0300 | [diff] [blame] | 2350 | rtnl_unlock(); |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2351 | |
Luca Coelho | 7d9d0d5 | 2018-04-12 16:15:07 +0300 | [diff] [blame] | 2352 | iwl_mvm_resume_tcm(mvm); |
| 2353 | |
Haim Dreyfuss | 7f8ae00 | 2017-12-27 15:21:18 +0200 | [diff] [blame] | 2354 | iwl_fw_runtime_resume(&mvm->fwrt); |
| 2355 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2356 | mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED; |
| 2357 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2358 | iwl_abort_notification_waits(&mvm->notif_wait); |
Luca Coelho | 85cd69b | 2016-10-05 11:24:12 +0300 | [diff] [blame] | 2359 | if (!unified_image) { |
| 2360 | int remaining_time = 10; |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2361 | |
Luca Coelho | 85cd69b | 2016-10-05 11:24:12 +0300 | [diff] [blame] | 2362 | 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 Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2373 | } |
| 2374 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2375 | ieee80211_iterate_active_interfaces_atomic( |
| 2376 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
Eliad Peller | 78c9df6 | 2013-11-07 14:13:30 +0200 | [diff] [blame] | 2377 | iwl_mvm_d3_test_disconn_work_iter, mvm->keep_vif); |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2378 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2379 | return 0; |
| 2380 | } |
| 2381 | |
| 2382 | const 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 |