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 | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2014 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 |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of version 2 of the GNU General Public License as |
| 13 | * published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 23 | * USA |
| 24 | * |
| 25 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 26 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 27 | * |
| 28 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 29 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 30 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 31 | * |
| 32 | * BSD LICENSE |
| 33 | * |
Emmanuel Grumbach | 51368bf | 2013-12-30 13:15:54 +0200 | [diff] [blame] | 34 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
Luciano Coelho | 65ff556 | 2015-03-20 13:35:47 +0200 | [diff] [blame] | 35 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 36 | * All rights reserved. |
| 37 | * |
| 38 | * Redistribution and use in source and binary forms, with or without |
| 39 | * modification, are permitted provided that the following conditions |
| 40 | * are met: |
| 41 | * |
| 42 | * * Redistributions of source code must retain the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer. |
| 44 | * * Redistributions in binary form must reproduce the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer in |
| 46 | * the documentation and/or other materials provided with the |
| 47 | * distribution. |
| 48 | * * Neither the name Intel Corporation nor the names of its |
| 49 | * contributors may be used to endorse or promote products derived |
| 50 | * from this software without specific prior written permission. |
| 51 | * |
| 52 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 53 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 54 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 55 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 56 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 57 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 58 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 59 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 60 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 61 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 62 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 63 | * |
| 64 | *****************************************************************************/ |
| 65 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 66 | #include <linux/etherdevice.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 67 | #include <linux/ip.h> |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 68 | #include <linux/fs.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 69 | #include <net/cfg80211.h> |
| 70 | #include <net/ipv6.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 71 | #include <net/tcp.h> |
Johannes Berg | f7fc598 | 2013-08-20 13:04:10 +0200 | [diff] [blame] | 72 | #include <net/addrconf.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 73 | #include "iwl-modparams.h" |
| 74 | #include "fw-api.h" |
| 75 | #include "mvm.h" |
| 76 | |
| 77 | void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw, |
| 78 | struct ieee80211_vif *vif, |
| 79 | struct cfg80211_gtk_rekey_data *data) |
| 80 | { |
| 81 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 82 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 83 | |
| 84 | if (iwlwifi_mod_params.sw_crypto) |
| 85 | return; |
| 86 | |
| 87 | mutex_lock(&mvm->mutex); |
| 88 | |
| 89 | memcpy(mvmvif->rekey_data.kek, data->kek, NL80211_KEK_LEN); |
| 90 | memcpy(mvmvif->rekey_data.kck, data->kck, NL80211_KCK_LEN); |
| 91 | mvmvif->rekey_data.replay_ctr = |
| 92 | cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr)); |
| 93 | mvmvif->rekey_data.valid = true; |
| 94 | |
| 95 | mutex_unlock(&mvm->mutex); |
| 96 | } |
| 97 | |
| 98 | #if IS_ENABLED(CONFIG_IPV6) |
| 99 | void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw, |
| 100 | struct ieee80211_vif *vif, |
| 101 | struct inet6_dev *idev) |
| 102 | { |
| 103 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 104 | struct inet6_ifaddr *ifa; |
| 105 | int idx = 0; |
| 106 | |
Sara Sharon | c97dab4 | 2015-11-19 11:53:49 +0200 | [diff] [blame] | 107 | memset(mvmvif->tentative_addrs, 0, sizeof(mvmvif->tentative_addrs)); |
| 108 | |
Emmanuel Grumbach | a3777e0 | 2013-02-10 13:07:08 +0200 | [diff] [blame] | 109 | read_lock_bh(&idev->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 110 | list_for_each_entry(ifa, &idev->addr_list, if_list) { |
| 111 | mvmvif->target_ipv6_addrs[idx] = ifa->addr; |
Sara Sharon | c97dab4 | 2015-11-19 11:53:49 +0200 | [diff] [blame] | 112 | if (ifa->flags & IFA_F_TENTATIVE) |
| 113 | __set_bit(idx, mvmvif->tentative_addrs); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 114 | idx++; |
Johannes Berg | 5369d6c | 2013-07-08 11:17:06 +0200 | [diff] [blame] | 115 | if (idx >= IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 116 | break; |
| 117 | } |
Emmanuel Grumbach | a3777e0 | 2013-02-10 13:07:08 +0200 | [diff] [blame] | 118 | read_unlock_bh(&idev->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 119 | |
| 120 | mvmvif->num_target_ipv6_addrs = idx; |
| 121 | } |
| 122 | #endif |
| 123 | |
| 124 | void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw, |
| 125 | struct ieee80211_vif *vif, int idx) |
| 126 | { |
| 127 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 128 | |
| 129 | mvmvif->tx_key_idx = idx; |
| 130 | } |
| 131 | |
| 132 | static void iwl_mvm_convert_p1k(u16 *p1k, __le16 *out) |
| 133 | { |
| 134 | int i; |
| 135 | |
| 136 | for (i = 0; i < IWL_P1K_SIZE; i++) |
| 137 | out[i] = cpu_to_le16(p1k[i]); |
| 138 | } |
| 139 | |
| 140 | struct wowlan_key_data { |
| 141 | struct iwl_wowlan_rsc_tsc_params_cmd *rsc_tsc; |
| 142 | struct iwl_wowlan_tkip_params_cmd *tkip; |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 143 | bool error, use_rsc_tsc, use_tkip, configure_keys; |
Johannes Berg | 5312e54 | 2013-07-22 18:26:56 +0200 | [diff] [blame] | 144 | int wep_key_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | static void iwl_mvm_wowlan_program_keys(struct ieee80211_hw *hw, |
| 148 | struct ieee80211_vif *vif, |
| 149 | struct ieee80211_sta *sta, |
| 150 | struct ieee80211_key_conf *key, |
| 151 | void *_data) |
| 152 | { |
| 153 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 154 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 155 | struct wowlan_key_data *data = _data; |
| 156 | struct aes_sc *aes_sc, *aes_tx_sc = NULL; |
| 157 | struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL; |
| 158 | struct iwl_p1k_cache *rx_p1ks; |
| 159 | u8 *rx_mic_key; |
| 160 | struct ieee80211_key_seq seq; |
| 161 | u32 cur_rx_iv32 = 0; |
| 162 | u16 p1k[IWL_P1K_SIZE]; |
| 163 | int ret, i; |
| 164 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 165 | switch (key->cipher) { |
| 166 | case WLAN_CIPHER_SUITE_WEP40: |
| 167 | case WLAN_CIPHER_SUITE_WEP104: { /* hack it for now */ |
| 168 | struct { |
| 169 | struct iwl_mvm_wep_key_cmd wep_key_cmd; |
| 170 | struct iwl_mvm_wep_key wep_key; |
| 171 | } __packed wkc = { |
| 172 | .wep_key_cmd.mac_id_n_color = |
| 173 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 174 | mvmvif->color)), |
| 175 | .wep_key_cmd.num_keys = 1, |
| 176 | /* firmware sets STA_KEY_FLG_WEP_13BYTES */ |
| 177 | .wep_key_cmd.decryption_type = STA_KEY_FLG_WEP, |
| 178 | .wep_key.key_index = key->keyidx, |
| 179 | .wep_key.key_size = key->keylen, |
| 180 | }; |
| 181 | |
| 182 | /* |
| 183 | * This will fail -- the key functions don't set support |
| 184 | * pairwise WEP keys. However, that's better than silently |
| 185 | * failing WoWLAN. Or maybe not? |
| 186 | */ |
| 187 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 188 | break; |
| 189 | |
| 190 | memcpy(&wkc.wep_key.key[3], key->key, key->keylen); |
| 191 | if (key->keyidx == mvmvif->tx_key_idx) { |
| 192 | /* TX key must be at offset 0 */ |
| 193 | wkc.wep_key.key_offset = 0; |
| 194 | } else { |
| 195 | /* others start at 1 */ |
Johannes Berg | 5312e54 | 2013-07-22 18:26:56 +0200 | [diff] [blame] | 196 | data->wep_key_idx++; |
| 197 | wkc.wep_key.key_offset = data->wep_key_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 200 | if (data->configure_keys) { |
| 201 | mutex_lock(&mvm->mutex); |
| 202 | ret = iwl_mvm_send_cmd_pdu(mvm, WEP_KEY, 0, |
| 203 | sizeof(wkc), &wkc); |
| 204 | data->error = ret != 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 205 | |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 206 | mvm->ptk_ivlen = key->iv_len; |
| 207 | mvm->ptk_icvlen = key->icv_len; |
| 208 | mvm->gtk_ivlen = key->iv_len; |
| 209 | mvm->gtk_icvlen = key->icv_len; |
| 210 | mutex_unlock(&mvm->mutex); |
| 211 | } |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 212 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 213 | /* don't upload key again */ |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 214 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 215 | } |
| 216 | default: |
| 217 | data->error = true; |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 218 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 219 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 220 | /* |
| 221 | * Ignore CMAC keys -- the WoWLAN firmware doesn't support them |
| 222 | * but we also shouldn't abort suspend due to that. It does have |
| 223 | * support for the IGTK key renewal, but doesn't really use the |
| 224 | * IGTK for anything. This means we could spuriously wake up or |
| 225 | * be deauthenticated, but that was considered acceptable. |
| 226 | */ |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 227 | return; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 228 | case WLAN_CIPHER_SUITE_TKIP: |
| 229 | if (sta) { |
| 230 | tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc; |
| 231 | tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc; |
| 232 | |
| 233 | rx_p1ks = data->tkip->rx_uni; |
| 234 | |
| 235 | ieee80211_get_key_tx_seq(key, &seq); |
| 236 | tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16); |
| 237 | tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32); |
| 238 | |
| 239 | ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k); |
| 240 | iwl_mvm_convert_p1k(p1k, data->tkip->tx.p1k); |
| 241 | |
| 242 | memcpy(data->tkip->mic_keys.tx, |
| 243 | &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY], |
| 244 | IWL_MIC_KEY_SIZE); |
| 245 | |
| 246 | rx_mic_key = data->tkip->mic_keys.rx_unicast; |
| 247 | } else { |
| 248 | tkip_sc = |
| 249 | data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc; |
| 250 | rx_p1ks = data->tkip->rx_multi; |
| 251 | rx_mic_key = data->tkip->mic_keys.rx_mcast; |
| 252 | } |
| 253 | |
| 254 | /* |
| 255 | * For non-QoS this relies on the fact that both the uCode and |
| 256 | * mac80211 use TID 0 (as they need to to avoid replay attacks) |
| 257 | * for checking the IV in the frames. |
| 258 | */ |
| 259 | for (i = 0; i < IWL_NUM_RSC; i++) { |
| 260 | ieee80211_get_key_rx_seq(key, i, &seq); |
| 261 | tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16); |
| 262 | tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32); |
| 263 | /* wrapping isn't allowed, AP must rekey */ |
| 264 | if (seq.tkip.iv32 > cur_rx_iv32) |
| 265 | cur_rx_iv32 = seq.tkip.iv32; |
| 266 | } |
| 267 | |
| 268 | ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid, |
| 269 | cur_rx_iv32, p1k); |
| 270 | iwl_mvm_convert_p1k(p1k, rx_p1ks[0].p1k); |
| 271 | ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid, |
| 272 | cur_rx_iv32 + 1, p1k); |
| 273 | iwl_mvm_convert_p1k(p1k, rx_p1ks[1].p1k); |
| 274 | |
| 275 | memcpy(rx_mic_key, |
| 276 | &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY], |
| 277 | IWL_MIC_KEY_SIZE); |
| 278 | |
| 279 | data->use_tkip = true; |
| 280 | data->use_rsc_tsc = true; |
| 281 | break; |
| 282 | case WLAN_CIPHER_SUITE_CCMP: |
| 283 | if (sta) { |
Johannes Berg | 6645d5e | 2015-09-15 09:58:53 +0200 | [diff] [blame] | 284 | u64 pn64; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 285 | |
| 286 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc; |
| 287 | aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc; |
| 288 | |
Johannes Berg | 6645d5e | 2015-09-15 09:58:53 +0200 | [diff] [blame] | 289 | pn64 = atomic64_read(&key->tx_pn); |
| 290 | aes_tx_sc->pn = cpu_to_le64(pn64); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 291 | } else { |
| 292 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc; |
| 293 | } |
| 294 | |
| 295 | /* |
| 296 | * For non-QoS this relies on the fact that both the uCode and |
| 297 | * mac80211 use TID 0 for checking the IV in the frames. |
| 298 | */ |
| 299 | for (i = 0; i < IWL_NUM_RSC; i++) { |
| 300 | u8 *pn = seq.ccmp.pn; |
| 301 | |
| 302 | ieee80211_get_key_rx_seq(key, i, &seq); |
Johannes Berg | 2cf5eb3 | 2015-09-15 14:36:09 +0200 | [diff] [blame] | 303 | aes_sc[i].pn = cpu_to_le64((u64)pn[5] | |
| 304 | ((u64)pn[4] << 8) | |
| 305 | ((u64)pn[3] << 16) | |
| 306 | ((u64)pn[2] << 24) | |
| 307 | ((u64)pn[1] << 32) | |
| 308 | ((u64)pn[0] << 40)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 309 | } |
| 310 | data->use_rsc_tsc = true; |
| 311 | break; |
| 312 | } |
| 313 | |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 314 | if (data->configure_keys) { |
| 315 | mutex_lock(&mvm->mutex); |
Johannes Berg | 5312e54 | 2013-07-22 18:26:56 +0200 | [diff] [blame] | 316 | /* |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 317 | * The D3 firmware hardcodes the key offset 0 as the key it |
| 318 | * uses to transmit packets to the AP, i.e. the PTK. |
Johannes Berg | 5312e54 | 2013-07-22 18:26:56 +0200 | [diff] [blame] | 319 | */ |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 320 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { |
| 321 | mvm->ptk_ivlen = key->iv_len; |
| 322 | mvm->ptk_icvlen = key->icv_len; |
| 323 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, 0); |
| 324 | } else { |
| 325 | /* |
| 326 | * firmware only supports TSC/RSC for a single key, |
| 327 | * so if there are multiple keep overwriting them |
| 328 | * with new ones -- this relies on mac80211 doing |
| 329 | * list_add_tail(). |
| 330 | */ |
| 331 | mvm->gtk_ivlen = key->iv_len; |
| 332 | mvm->gtk_icvlen = key->icv_len; |
| 333 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, 1); |
| 334 | } |
| 335 | mutex_unlock(&mvm->mutex); |
| 336 | data->error = ret != 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 337 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 338 | } |
| 339 | |
| 340 | static int iwl_mvm_send_patterns(struct iwl_mvm *mvm, |
| 341 | struct cfg80211_wowlan *wowlan) |
| 342 | { |
| 343 | struct iwl_wowlan_patterns_cmd *pattern_cmd; |
| 344 | struct iwl_host_cmd cmd = { |
| 345 | .id = WOWLAN_PATTERNS, |
| 346 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 347 | }; |
| 348 | int i, err; |
| 349 | |
| 350 | if (!wowlan->n_patterns) |
| 351 | return 0; |
| 352 | |
| 353 | cmd.len[0] = sizeof(*pattern_cmd) + |
| 354 | wowlan->n_patterns * sizeof(struct iwl_wowlan_pattern); |
| 355 | |
| 356 | pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL); |
| 357 | if (!pattern_cmd) |
| 358 | return -ENOMEM; |
| 359 | |
| 360 | pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns); |
| 361 | |
| 362 | for (i = 0; i < wowlan->n_patterns; i++) { |
| 363 | int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8); |
| 364 | |
| 365 | memcpy(&pattern_cmd->patterns[i].mask, |
| 366 | wowlan->patterns[i].mask, mask_len); |
| 367 | memcpy(&pattern_cmd->patterns[i].pattern, |
| 368 | wowlan->patterns[i].pattern, |
| 369 | wowlan->patterns[i].pattern_len); |
| 370 | pattern_cmd->patterns[i].mask_size = mask_len; |
| 371 | pattern_cmd->patterns[i].pattern_size = |
| 372 | wowlan->patterns[i].pattern_len; |
| 373 | } |
| 374 | |
| 375 | cmd.data[0] = pattern_cmd; |
| 376 | err = iwl_mvm_send_cmd(mvm, &cmd); |
| 377 | kfree(pattern_cmd); |
| 378 | return err; |
| 379 | } |
| 380 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 381 | enum iwl_mvm_tcp_packet_type { |
| 382 | MVM_TCP_TX_SYN, |
| 383 | MVM_TCP_RX_SYNACK, |
| 384 | MVM_TCP_TX_DATA, |
| 385 | MVM_TCP_RX_ACK, |
| 386 | MVM_TCP_RX_WAKE, |
| 387 | MVM_TCP_TX_FIN, |
| 388 | }; |
| 389 | |
| 390 | static __le16 pseudo_hdr_check(int len, __be32 saddr, __be32 daddr) |
| 391 | { |
| 392 | __sum16 check = tcp_v4_check(len, saddr, daddr, 0); |
| 393 | return cpu_to_le16(be16_to_cpu((__force __be16)check)); |
| 394 | } |
| 395 | |
Oren Givon | b002c7e | 2013-06-12 20:37:03 +0300 | [diff] [blame] | 396 | static void iwl_mvm_build_tcp_packet(struct ieee80211_vif *vif, |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 397 | struct cfg80211_wowlan_tcp *tcp, |
| 398 | void *_pkt, u8 *mask, |
| 399 | __le16 *pseudo_hdr_csum, |
| 400 | enum iwl_mvm_tcp_packet_type ptype) |
| 401 | { |
| 402 | struct { |
| 403 | struct ethhdr eth; |
| 404 | struct iphdr ip; |
| 405 | struct tcphdr tcp; |
| 406 | u8 data[]; |
| 407 | } __packed *pkt = _pkt; |
| 408 | u16 ip_tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr); |
| 409 | int i; |
| 410 | |
| 411 | pkt->eth.h_proto = cpu_to_be16(ETH_P_IP), |
| 412 | pkt->ip.version = 4; |
| 413 | pkt->ip.ihl = 5; |
| 414 | pkt->ip.protocol = IPPROTO_TCP; |
| 415 | |
| 416 | switch (ptype) { |
| 417 | case MVM_TCP_TX_SYN: |
| 418 | case MVM_TCP_TX_DATA: |
| 419 | case MVM_TCP_TX_FIN: |
| 420 | memcpy(pkt->eth.h_dest, tcp->dst_mac, ETH_ALEN); |
| 421 | memcpy(pkt->eth.h_source, vif->addr, ETH_ALEN); |
| 422 | pkt->ip.ttl = 128; |
| 423 | pkt->ip.saddr = tcp->src; |
| 424 | pkt->ip.daddr = tcp->dst; |
| 425 | pkt->tcp.source = cpu_to_be16(tcp->src_port); |
| 426 | pkt->tcp.dest = cpu_to_be16(tcp->dst_port); |
| 427 | /* overwritten for TX SYN later */ |
| 428 | pkt->tcp.doff = sizeof(struct tcphdr) / 4; |
| 429 | pkt->tcp.window = cpu_to_be16(65000); |
| 430 | break; |
| 431 | case MVM_TCP_RX_SYNACK: |
| 432 | case MVM_TCP_RX_ACK: |
| 433 | case MVM_TCP_RX_WAKE: |
| 434 | memcpy(pkt->eth.h_dest, vif->addr, ETH_ALEN); |
| 435 | memcpy(pkt->eth.h_source, tcp->dst_mac, ETH_ALEN); |
| 436 | pkt->ip.saddr = tcp->dst; |
| 437 | pkt->ip.daddr = tcp->src; |
| 438 | pkt->tcp.source = cpu_to_be16(tcp->dst_port); |
| 439 | pkt->tcp.dest = cpu_to_be16(tcp->src_port); |
| 440 | break; |
| 441 | default: |
| 442 | WARN_ON(1); |
| 443 | return; |
| 444 | } |
| 445 | |
| 446 | switch (ptype) { |
| 447 | case MVM_TCP_TX_SYN: |
| 448 | /* firmware assumes 8 option bytes - 8 NOPs for now */ |
| 449 | memset(pkt->data, 0x01, 8); |
| 450 | ip_tot_len += 8; |
| 451 | pkt->tcp.doff = (sizeof(struct tcphdr) + 8) / 4; |
| 452 | pkt->tcp.syn = 1; |
| 453 | break; |
| 454 | case MVM_TCP_TX_DATA: |
| 455 | ip_tot_len += tcp->payload_len; |
| 456 | memcpy(pkt->data, tcp->payload, tcp->payload_len); |
| 457 | pkt->tcp.psh = 1; |
| 458 | pkt->tcp.ack = 1; |
| 459 | break; |
| 460 | case MVM_TCP_TX_FIN: |
| 461 | pkt->tcp.fin = 1; |
| 462 | pkt->tcp.ack = 1; |
| 463 | break; |
| 464 | case MVM_TCP_RX_SYNACK: |
| 465 | pkt->tcp.syn = 1; |
| 466 | pkt->tcp.ack = 1; |
| 467 | break; |
| 468 | case MVM_TCP_RX_ACK: |
| 469 | pkt->tcp.ack = 1; |
| 470 | break; |
| 471 | case MVM_TCP_RX_WAKE: |
| 472 | ip_tot_len += tcp->wake_len; |
| 473 | pkt->tcp.psh = 1; |
| 474 | pkt->tcp.ack = 1; |
| 475 | memcpy(pkt->data, tcp->wake_data, tcp->wake_len); |
| 476 | break; |
| 477 | } |
| 478 | |
| 479 | switch (ptype) { |
| 480 | case MVM_TCP_TX_SYN: |
| 481 | case MVM_TCP_TX_DATA: |
| 482 | case MVM_TCP_TX_FIN: |
| 483 | pkt->ip.tot_len = cpu_to_be16(ip_tot_len); |
| 484 | pkt->ip.check = ip_fast_csum(&pkt->ip, pkt->ip.ihl); |
| 485 | break; |
| 486 | case MVM_TCP_RX_WAKE: |
| 487 | for (i = 0; i < DIV_ROUND_UP(tcp->wake_len, 8); i++) { |
| 488 | u8 tmp = tcp->wake_mask[i]; |
| 489 | mask[i + 6] |= tmp << 6; |
| 490 | if (i + 1 < DIV_ROUND_UP(tcp->wake_len, 8)) |
| 491 | mask[i + 7] = tmp >> 2; |
| 492 | } |
| 493 | /* fall through for ethernet/IP/TCP headers mask */ |
| 494 | case MVM_TCP_RX_SYNACK: |
| 495 | case MVM_TCP_RX_ACK: |
| 496 | mask[0] = 0xff; /* match ethernet */ |
| 497 | /* |
| 498 | * match ethernet, ip.version, ip.ihl |
| 499 | * the ip.ihl half byte is really masked out by firmware |
| 500 | */ |
| 501 | mask[1] = 0x7f; |
| 502 | mask[2] = 0x80; /* match ip.protocol */ |
| 503 | mask[3] = 0xfc; /* match ip.saddr, ip.daddr */ |
| 504 | mask[4] = 0x3f; /* match ip.daddr, tcp.source, tcp.dest */ |
| 505 | mask[5] = 0x80; /* match tcp flags */ |
| 506 | /* leave rest (0 or set for MVM_TCP_RX_WAKE) */ |
| 507 | break; |
| 508 | }; |
| 509 | |
| 510 | *pseudo_hdr_csum = pseudo_hdr_check(ip_tot_len - sizeof(struct iphdr), |
| 511 | pkt->ip.saddr, pkt->ip.daddr); |
| 512 | } |
| 513 | |
| 514 | static int iwl_mvm_send_remote_wake_cfg(struct iwl_mvm *mvm, |
| 515 | struct ieee80211_vif *vif, |
| 516 | struct cfg80211_wowlan_tcp *tcp) |
| 517 | { |
| 518 | struct iwl_wowlan_remote_wake_config *cfg; |
| 519 | struct iwl_host_cmd cmd = { |
| 520 | .id = REMOTE_WAKE_CONFIG_CMD, |
| 521 | .len = { sizeof(*cfg), }, |
| 522 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 523 | }; |
| 524 | int ret; |
| 525 | |
| 526 | if (!tcp) |
| 527 | return 0; |
| 528 | |
| 529 | cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); |
| 530 | if (!cfg) |
| 531 | return -ENOMEM; |
| 532 | cmd.data[0] = cfg; |
| 533 | |
| 534 | cfg->max_syn_retries = 10; |
| 535 | cfg->max_data_retries = 10; |
| 536 | cfg->tcp_syn_ack_timeout = 1; /* seconds */ |
| 537 | cfg->tcp_ack_timeout = 1; /* seconds */ |
| 538 | |
| 539 | /* SYN (TX) */ |
| 540 | iwl_mvm_build_tcp_packet( |
Oren Givon | b002c7e | 2013-06-12 20:37:03 +0300 | [diff] [blame] | 541 | vif, tcp, cfg->syn_tx.data, NULL, |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 542 | &cfg->syn_tx.info.tcp_pseudo_header_checksum, |
| 543 | MVM_TCP_TX_SYN); |
| 544 | cfg->syn_tx.info.tcp_payload_length = 0; |
| 545 | |
| 546 | /* SYN/ACK (RX) */ |
| 547 | iwl_mvm_build_tcp_packet( |
Oren Givon | b002c7e | 2013-06-12 20:37:03 +0300 | [diff] [blame] | 548 | vif, tcp, cfg->synack_rx.data, cfg->synack_rx.rx_mask, |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 549 | &cfg->synack_rx.info.tcp_pseudo_header_checksum, |
| 550 | MVM_TCP_RX_SYNACK); |
| 551 | cfg->synack_rx.info.tcp_payload_length = 0; |
| 552 | |
| 553 | /* KEEPALIVE/ACK (TX) */ |
| 554 | iwl_mvm_build_tcp_packet( |
Oren Givon | b002c7e | 2013-06-12 20:37:03 +0300 | [diff] [blame] | 555 | vif, tcp, cfg->keepalive_tx.data, NULL, |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 556 | &cfg->keepalive_tx.info.tcp_pseudo_header_checksum, |
| 557 | MVM_TCP_TX_DATA); |
| 558 | cfg->keepalive_tx.info.tcp_payload_length = |
| 559 | cpu_to_le16(tcp->payload_len); |
| 560 | cfg->sequence_number_offset = tcp->payload_seq.offset; |
| 561 | /* length must be 0..4, the field is little endian */ |
| 562 | cfg->sequence_number_length = tcp->payload_seq.len; |
| 563 | cfg->initial_sequence_number = cpu_to_le32(tcp->payload_seq.start); |
| 564 | cfg->keepalive_interval = cpu_to_le16(tcp->data_interval); |
| 565 | if (tcp->payload_tok.len) { |
| 566 | cfg->token_offset = tcp->payload_tok.offset; |
| 567 | cfg->token_length = tcp->payload_tok.len; |
| 568 | cfg->num_tokens = |
| 569 | cpu_to_le16(tcp->tokens_size % tcp->payload_tok.len); |
| 570 | memcpy(cfg->tokens, tcp->payload_tok.token_stream, |
| 571 | tcp->tokens_size); |
| 572 | } else { |
| 573 | /* set tokens to max value to almost never run out */ |
| 574 | cfg->num_tokens = cpu_to_le16(65535); |
| 575 | } |
| 576 | |
| 577 | /* ACK (RX) */ |
| 578 | iwl_mvm_build_tcp_packet( |
Oren Givon | b002c7e | 2013-06-12 20:37:03 +0300 | [diff] [blame] | 579 | vif, tcp, cfg->keepalive_ack_rx.data, |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 580 | cfg->keepalive_ack_rx.rx_mask, |
| 581 | &cfg->keepalive_ack_rx.info.tcp_pseudo_header_checksum, |
| 582 | MVM_TCP_RX_ACK); |
| 583 | cfg->keepalive_ack_rx.info.tcp_payload_length = 0; |
| 584 | |
| 585 | /* WAKEUP (RX) */ |
| 586 | iwl_mvm_build_tcp_packet( |
Oren Givon | b002c7e | 2013-06-12 20:37:03 +0300 | [diff] [blame] | 587 | vif, tcp, cfg->wake_rx.data, cfg->wake_rx.rx_mask, |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 588 | &cfg->wake_rx.info.tcp_pseudo_header_checksum, |
| 589 | MVM_TCP_RX_WAKE); |
| 590 | cfg->wake_rx.info.tcp_payload_length = |
| 591 | cpu_to_le16(tcp->wake_len); |
| 592 | |
| 593 | /* FIN */ |
| 594 | iwl_mvm_build_tcp_packet( |
Oren Givon | b002c7e | 2013-06-12 20:37:03 +0300 | [diff] [blame] | 595 | vif, tcp, cfg->fin_tx.data, NULL, |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 596 | &cfg->fin_tx.info.tcp_pseudo_header_checksum, |
| 597 | MVM_TCP_TX_FIN); |
| 598 | cfg->fin_tx.info.tcp_payload_length = 0; |
| 599 | |
| 600 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 601 | kfree(cfg); |
| 602 | |
| 603 | return ret; |
| 604 | } |
| 605 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 606 | static int iwl_mvm_d3_reprogram(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 607 | struct ieee80211_sta *ap_sta) |
| 608 | { |
| 609 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 610 | struct ieee80211_chanctx_conf *ctx; |
| 611 | u8 chains_static, chains_dynamic; |
| 612 | struct cfg80211_chan_def chandef; |
| 613 | int ret, i; |
| 614 | struct iwl_binding_cmd binding_cmd = {}; |
| 615 | struct iwl_time_quota_cmd quota_cmd = {}; |
| 616 | u32 status; |
| 617 | |
| 618 | /* add back the PHY */ |
| 619 | if (WARN_ON(!mvmvif->phy_ctxt)) |
| 620 | return -EINVAL; |
| 621 | |
| 622 | rcu_read_lock(); |
| 623 | ctx = rcu_dereference(vif->chanctx_conf); |
| 624 | if (WARN_ON(!ctx)) { |
| 625 | rcu_read_unlock(); |
| 626 | return -EINVAL; |
| 627 | } |
| 628 | chandef = ctx->def; |
| 629 | chains_static = ctx->rx_chains_static; |
| 630 | chains_dynamic = ctx->rx_chains_dynamic; |
| 631 | rcu_read_unlock(); |
| 632 | |
| 633 | ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt, &chandef, |
| 634 | chains_static, chains_dynamic); |
| 635 | if (ret) |
| 636 | return ret; |
| 637 | |
| 638 | /* add back the MAC */ |
| 639 | mvmvif->uploaded = false; |
| 640 | |
| 641 | if (WARN_ON(!vif->bss_conf.assoc)) |
| 642 | return -EINVAL; |
Luciano Coelho | bca49d9 | 2014-05-13 17:33:38 +0300 | [diff] [blame] | 643 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 644 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 645 | if (ret) |
| 646 | return ret; |
| 647 | |
| 648 | /* add back binding - XXX refactor? */ |
| 649 | binding_cmd.id_and_color = |
| 650 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id, |
| 651 | mvmvif->phy_ctxt->color)); |
| 652 | binding_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD); |
| 653 | binding_cmd.phy = |
| 654 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id, |
| 655 | mvmvif->phy_ctxt->color)); |
| 656 | binding_cmd.macs[0] = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 657 | mvmvif->color)); |
| 658 | for (i = 1; i < MAX_MACS_IN_BINDING; i++) |
| 659 | binding_cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID); |
| 660 | |
| 661 | status = 0; |
| 662 | ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD, |
| 663 | sizeof(binding_cmd), &binding_cmd, |
| 664 | &status); |
| 665 | if (ret) { |
| 666 | IWL_ERR(mvm, "Failed to add binding: %d\n", ret); |
| 667 | return ret; |
| 668 | } |
| 669 | |
| 670 | if (status) { |
| 671 | IWL_ERR(mvm, "Binding command failed: %u\n", status); |
| 672 | return -EIO; |
| 673 | } |
| 674 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 675 | ret = iwl_mvm_sta_send_to_fw(mvm, ap_sta, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 676 | if (ret) |
| 677 | return ret; |
| 678 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], ap_sta); |
| 679 | |
Johannes Berg | 3dfd3a9 | 2014-08-11 21:37:30 +0200 | [diff] [blame] | 680 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 681 | if (ret) |
| 682 | return ret; |
| 683 | |
| 684 | /* and some quota */ |
| 685 | quota_cmd.quotas[0].id_and_color = |
| 686 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id, |
| 687 | mvmvif->phy_ctxt->color)); |
Emmanuel Grumbach | 9a3daf8 | 2014-03-05 10:00:44 +0200 | [diff] [blame] | 688 | quota_cmd.quotas[0].quota = cpu_to_le32(IWL_MVM_MAX_QUOTA); |
| 689 | quota_cmd.quotas[0].max_duration = cpu_to_le32(IWL_MVM_MAX_QUOTA); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 690 | |
| 691 | for (i = 1; i < MAX_BINDINGS; i++) |
| 692 | quota_cmd.quotas[i].id_and_color = cpu_to_le32(FW_CTXT_INVALID); |
| 693 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 694 | ret = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 695 | sizeof(quota_cmd), "a_cmd); |
| 696 | if (ret) |
| 697 | IWL_ERR(mvm, "Failed to send quota: %d\n", ret); |
| 698 | |
Jonathan Doron | 47c8b15 | 2014-11-27 16:55:25 +0200 | [diff] [blame] | 699 | if (iwl_mvm_is_lar_supported(mvm) && iwl_mvm_init_fw_regd(mvm)) |
| 700 | IWL_ERR(mvm, "Failed to initialize D3 LAR information\n"); |
| 701 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 702 | return 0; |
| 703 | } |
| 704 | |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 705 | static int iwl_mvm_get_last_nonqos_seq(struct iwl_mvm *mvm, |
| 706 | struct ieee80211_vif *vif) |
| 707 | { |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 708 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 709 | struct iwl_nonqos_seq_query_cmd query_cmd = { |
| 710 | .get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_GET), |
| 711 | .mac_id_n_color = |
| 712 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 713 | mvmvif->color)), |
| 714 | }; |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 715 | struct iwl_host_cmd cmd = { |
| 716 | .id = NON_QOS_TX_COUNTER_CMD, |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 717 | .flags = CMD_WANT_SKB, |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 718 | }; |
| 719 | int err; |
| 720 | u32 size; |
| 721 | |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 722 | cmd.data[0] = &query_cmd; |
| 723 | cmd.len[0] = sizeof(query_cmd); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 724 | |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 725 | err = iwl_mvm_send_cmd(mvm, &cmd); |
| 726 | if (err) |
| 727 | return err; |
| 728 | |
Johannes Berg | 65b3034 | 2014-01-08 13:16:33 +0100 | [diff] [blame] | 729 | size = iwl_rx_packet_payload_len(cmd.resp_pkt); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 730 | if (size < sizeof(__le16)) { |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 731 | err = -EINVAL; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 732 | } else { |
| 733 | err = le16_to_cpup((__le16 *)cmd.resp_pkt->data); |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 734 | /* firmware returns next, not last-used seqno */ |
| 735 | err = (u16) (err - 0x10); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 736 | } |
Johannes Berg | 4ac6cb5 | 2013-08-08 09:30:13 +0200 | [diff] [blame] | 737 | |
| 738 | iwl_free_resp(&cmd); |
| 739 | return err; |
| 740 | } |
| 741 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 742 | void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 743 | { |
| 744 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 745 | struct iwl_nonqos_seq_query_cmd query_cmd = { |
| 746 | .get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_SET), |
| 747 | .mac_id_n_color = |
| 748 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 749 | mvmvif->color)), |
| 750 | .value = cpu_to_le16(mvmvif->seqno), |
| 751 | }; |
| 752 | |
| 753 | /* return if called during restart, not resume from D3 */ |
| 754 | if (!mvmvif->seqno_valid) |
| 755 | return; |
| 756 | |
| 757 | mvmvif->seqno_valid = false; |
| 758 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 759 | 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] | 760 | sizeof(query_cmd), &query_cmd)) |
| 761 | IWL_ERR(mvm, "failed to set non-QoS seqno\n"); |
| 762 | } |
| 763 | |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 764 | static int iwl_mvm_switch_to_d3(struct iwl_mvm *mvm) |
Eliad Peller | 1a95c8d | 2013-11-21 19:19:52 +0200 | [diff] [blame] | 765 | { |
Luciano Coelho | c7d4248 | 2015-05-07 16:00:26 +0300 | [diff] [blame] | 766 | iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 767 | |
| 768 | iwl_trans_stop_device(mvm->trans); |
| 769 | |
| 770 | /* |
| 771 | * Set the HW restart bit -- this is mostly true as we're |
| 772 | * going to load new firmware and reprogram that, though |
| 773 | * the reprogramming is going to be manual to avoid adding |
| 774 | * all the MACs that aren't support. |
| 775 | * We don't have to clear up everything though because the |
| 776 | * reprogramming is manual. When we resume, we'll actually |
| 777 | * go through a proper restart sequence again to switch |
| 778 | * back to the runtime firmware image. |
| 779 | */ |
| 780 | set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 781 | |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 782 | /* the fw is reset, so all the keys are cleared */ |
| 783 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
| 784 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 785 | mvm->ptk_ivlen = 0; |
| 786 | mvm->ptk_icvlen = 0; |
| 787 | mvm->ptk_ivlen = 0; |
| 788 | mvm->ptk_icvlen = 0; |
| 789 | |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 790 | return iwl_mvm_load_d3_fw(mvm); |
| 791 | } |
| 792 | |
| 793 | static int |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 794 | iwl_mvm_get_wowlan_config(struct iwl_mvm *mvm, |
| 795 | struct cfg80211_wowlan *wowlan, |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 796 | struct iwl_wowlan_config_cmd *wowlan_config_cmd, |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 797 | struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif, |
| 798 | struct ieee80211_sta *ap_sta) |
| 799 | { |
| 800 | int ret; |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 801 | 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] | 802 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 803 | /* TODO: wowlan_config_cmd->wowlan_ba_teardown_tids */ |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 804 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 805 | wowlan_config_cmd->is_11n_connection = |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 806 | ap_sta->ht_cap.ht_supported; |
Sara Sharon | 70b4c53 | 2015-11-19 13:12:15 +0200 | [diff] [blame] | 807 | wowlan_config_cmd->flags = ENABLE_L3_FILTERING | |
| 808 | ENABLE_NBNS_FILTERING | ENABLE_DHCP_FILTERING; |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 809 | |
| 810 | /* Query the last used seqno and set it */ |
| 811 | ret = iwl_mvm_get_last_nonqos_seq(mvm, vif); |
| 812 | if (ret < 0) |
| 813 | return ret; |
| 814 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 815 | wowlan_config_cmd->non_qos_seq = cpu_to_le16(ret); |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 816 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 817 | iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, wowlan_config_cmd); |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 818 | |
| 819 | if (wowlan->disconnect) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 820 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 821 | cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS | |
| 822 | IWL_WOWLAN_WAKEUP_LINK_CHANGE); |
| 823 | if (wowlan->magic_pkt) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 824 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 825 | cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET); |
| 826 | if (wowlan->gtk_rekey_failure) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 827 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 828 | cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL); |
| 829 | if (wowlan->eap_identity_req) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 830 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 831 | cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ); |
| 832 | if (wowlan->four_way_handshake) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 833 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 834 | cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE); |
| 835 | if (wowlan->n_patterns) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 836 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 837 | cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH); |
| 838 | |
| 839 | if (wowlan->rfkill_release) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 840 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 841 | cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT); |
| 842 | |
| 843 | if (wowlan->tcp) { |
| 844 | /* |
| 845 | * Set the "link change" (really "link lost") flag as well |
| 846 | * since that implies losing the TCP connection. |
| 847 | */ |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 848 | wowlan_config_cmd->wakeup_filter |= |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 849 | cpu_to_le32(IWL_WOWLAN_WAKEUP_REMOTE_LINK_LOSS | |
| 850 | IWL_WOWLAN_WAKEUP_REMOTE_SIGNATURE_TABLE | |
| 851 | IWL_WOWLAN_WAKEUP_REMOTE_WAKEUP_PACKET | |
| 852 | IWL_WOWLAN_WAKEUP_LINK_CHANGE); |
| 853 | } |
| 854 | |
| 855 | return 0; |
| 856 | } |
| 857 | |
Eliad Peller | a3f7ba5 | 2015-11-11 17:23:59 +0200 | [diff] [blame] | 858 | static void |
| 859 | iwl_mvm_iter_d0i3_ap_keys(struct iwl_mvm *mvm, |
| 860 | struct ieee80211_vif *vif, |
| 861 | void (*iter)(struct ieee80211_hw *hw, |
| 862 | struct ieee80211_vif *vif, |
| 863 | struct ieee80211_sta *sta, |
| 864 | struct ieee80211_key_conf *key, |
| 865 | void *data), |
| 866 | void *data) |
| 867 | { |
| 868 | struct ieee80211_sta *ap_sta; |
| 869 | |
| 870 | rcu_read_lock(); |
| 871 | |
| 872 | ap_sta = rcu_dereference(mvm->fw_id_to_mac_id[mvm->d0i3_ap_sta_id]); |
| 873 | if (IS_ERR_OR_NULL(ap_sta)) |
| 874 | goto out; |
| 875 | |
| 876 | ieee80211_iter_keys_rcu(mvm->hw, vif, iter, data); |
| 877 | out: |
| 878 | rcu_read_unlock(); |
| 879 | } |
| 880 | |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 881 | int iwl_mvm_wowlan_config_key_params(struct iwl_mvm *mvm, |
| 882 | struct ieee80211_vif *vif, |
Eliad Peller | a3f7ba5 | 2015-11-11 17:23:59 +0200 | [diff] [blame] | 883 | bool d0i3, |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 884 | u32 cmd_flags) |
| 885 | { |
| 886 | struct iwl_wowlan_kek_kck_material_cmd kek_kck_cmd = {}; |
| 887 | struct iwl_wowlan_tkip_params_cmd tkip_cmd = {}; |
| 888 | struct wowlan_key_data key_data = { |
Eliad Peller | a3f7ba5 | 2015-11-11 17:23:59 +0200 | [diff] [blame] | 889 | .configure_keys = !d0i3, |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 890 | .use_rsc_tsc = false, |
| 891 | .tkip = &tkip_cmd, |
| 892 | .use_tkip = false, |
| 893 | }; |
| 894 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 895 | int ret; |
| 896 | |
| 897 | key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL); |
| 898 | if (!key_data.rsc_tsc) |
| 899 | return -ENOMEM; |
| 900 | |
| 901 | /* |
Eliad Peller | a3f7ba5 | 2015-11-11 17:23:59 +0200 | [diff] [blame] | 902 | * if we have to configure keys, call ieee80211_iter_keys(), |
| 903 | * as we need non-atomic context in order to take the |
| 904 | * required locks. |
| 905 | * for the d0i3 we can't use ieee80211_iter_keys(), as |
| 906 | * taking (almost) any mutex might result in deadlock. |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 907 | */ |
Eliad Peller | a3f7ba5 | 2015-11-11 17:23:59 +0200 | [diff] [blame] | 908 | if (!d0i3) { |
| 909 | /* |
| 910 | * Note that currently we don't propagate cmd_flags |
| 911 | * to the iterator. In case of key_data.configure_keys, |
| 912 | * all the configured commands are SYNC, and |
| 913 | * iwl_mvm_wowlan_program_keys() will take care of |
| 914 | * locking/unlocking mvm->mutex. |
| 915 | */ |
| 916 | ieee80211_iter_keys(mvm->hw, vif, |
| 917 | iwl_mvm_wowlan_program_keys, |
| 918 | &key_data); |
| 919 | } else { |
| 920 | iwl_mvm_iter_d0i3_ap_keys(mvm, vif, |
| 921 | iwl_mvm_wowlan_program_keys, |
| 922 | &key_data); |
| 923 | } |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 924 | |
| 925 | if (key_data.error) { |
| 926 | ret = -EIO; |
| 927 | goto out; |
| 928 | } |
| 929 | |
| 930 | if (key_data.use_rsc_tsc) { |
| 931 | ret = iwl_mvm_send_cmd_pdu(mvm, |
| 932 | WOWLAN_TSC_RSC_PARAM, cmd_flags, |
| 933 | sizeof(*key_data.rsc_tsc), |
| 934 | key_data.rsc_tsc); |
| 935 | if (ret) |
| 936 | goto out; |
| 937 | } |
| 938 | |
| 939 | if (key_data.use_tkip) { |
| 940 | ret = iwl_mvm_send_cmd_pdu(mvm, |
| 941 | WOWLAN_TKIP_PARAM, |
| 942 | cmd_flags, sizeof(tkip_cmd), |
| 943 | &tkip_cmd); |
| 944 | if (ret) |
| 945 | goto out; |
| 946 | } |
| 947 | |
Eliad Peller | a3f7ba5 | 2015-11-11 17:23:59 +0200 | [diff] [blame] | 948 | /* configure rekey data only if offloaded rekey is supported (d3) */ |
| 949 | if (mvmvif->rekey_data.valid && !d0i3) { |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 950 | memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd)); |
| 951 | memcpy(kek_kck_cmd.kck, mvmvif->rekey_data.kck, |
| 952 | NL80211_KCK_LEN); |
| 953 | kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN); |
| 954 | memcpy(kek_kck_cmd.kek, mvmvif->rekey_data.kek, |
| 955 | NL80211_KEK_LEN); |
| 956 | kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN); |
| 957 | kek_kck_cmd.replay_ctr = mvmvif->rekey_data.replay_ctr; |
| 958 | |
| 959 | ret = iwl_mvm_send_cmd_pdu(mvm, |
| 960 | WOWLAN_KEK_KCK_MATERIAL, cmd_flags, |
| 961 | sizeof(kek_kck_cmd), |
| 962 | &kek_kck_cmd); |
| 963 | if (ret) |
| 964 | goto out; |
| 965 | } |
Eliad Peller | 3f50a69 | 2015-11-15 15:44:17 +0200 | [diff] [blame] | 966 | ret = 0; |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 967 | out: |
| 968 | kfree(key_data.rsc_tsc); |
| 969 | return ret; |
| 970 | } |
| 971 | |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 972 | static int |
| 973 | iwl_mvm_wowlan_config(struct iwl_mvm *mvm, |
| 974 | struct cfg80211_wowlan *wowlan, |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 975 | struct iwl_wowlan_config_cmd *wowlan_config_cmd, |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 976 | struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif, |
| 977 | struct ieee80211_sta *ap_sta) |
| 978 | { |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 979 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 980 | |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 981 | ret = iwl_mvm_switch_to_d3(mvm); |
| 982 | if (ret) |
| 983 | return ret; |
| 984 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 985 | ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta); |
| 986 | if (ret) |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 987 | return ret; |
| 988 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 989 | if (!iwlwifi_mod_params.sw_crypto) { |
| 990 | /* |
| 991 | * This needs to be unlocked due to lock ordering |
| 992 | * constraints. Since we're in the suspend path |
| 993 | * that isn't really a problem though. |
| 994 | */ |
| 995 | mutex_unlock(&mvm->mutex); |
Eliad Peller | a3f7ba5 | 2015-11-11 17:23:59 +0200 | [diff] [blame] | 996 | ret = iwl_mvm_wowlan_config_key_params(mvm, vif, false, |
Eliad Peller | 3f50a69 | 2015-11-15 15:44:17 +0200 | [diff] [blame] | 997 | CMD_ASYNC); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 998 | mutex_lock(&mvm->mutex); |
Eliad Peller | 3f50a69 | 2015-11-15 15:44:17 +0200 | [diff] [blame] | 999 | if (ret) |
| 1000 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1001 | } |
| 1002 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 1003 | ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0, |
| 1004 | sizeof(*wowlan_config_cmd), |
| 1005 | wowlan_config_cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1006 | if (ret) |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 1007 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1008 | |
| 1009 | ret = iwl_mvm_send_patterns(mvm, wowlan); |
| 1010 | if (ret) |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 1011 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1012 | |
Sara Sharon | c97dab4 | 2015-11-19 11:53:49 +0200 | [diff] [blame] | 1013 | ret = iwl_mvm_send_proto_offload(mvm, vif, false, true, 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1014 | if (ret) |
Eliad Peller | ac8ef0c | 2015-11-12 10:49:38 +0200 | [diff] [blame] | 1015 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1016 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 1017 | ret = iwl_mvm_send_remote_wake_cfg(mvm, vif, wowlan->tcp); |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1018 | return ret; |
| 1019 | } |
| 1020 | |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1021 | static int |
| 1022 | iwl_mvm_netdetect_config(struct iwl_mvm *mvm, |
| 1023 | struct cfg80211_wowlan *wowlan, |
| 1024 | struct cfg80211_sched_scan_request *nd_config, |
| 1025 | struct ieee80211_vif *vif) |
| 1026 | { |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 1027 | struct iwl_wowlan_config_cmd wowlan_config_cmd = {}; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1028 | int ret; |
| 1029 | |
| 1030 | ret = iwl_mvm_switch_to_d3(mvm); |
| 1031 | if (ret) |
| 1032 | return ret; |
| 1033 | |
| 1034 | /* rfkill release can be either for wowlan or netdetect */ |
| 1035 | if (wowlan->rfkill_release) |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 1036 | wowlan_config_cmd.wakeup_filter |= |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1037 | cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT); |
| 1038 | |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 1039 | ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0, |
| 1040 | sizeof(wowlan_config_cmd), |
| 1041 | &wowlan_config_cmd); |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1042 | if (ret) |
| 1043 | return ret; |
| 1044 | |
Luciano Coelho | 19945df | 2015-03-20 16:11:28 +0200 | [diff] [blame] | 1045 | ret = iwl_mvm_sched_scan_start(mvm, vif, nd_config, &mvm->nd_ies, |
| 1046 | IWL_MVM_SCAN_NETDETECT); |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1047 | if (ret) |
| 1048 | return ret; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1049 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1050 | if (WARN_ON(mvm->nd_match_sets || mvm->nd_channels)) |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1051 | return -EBUSY; |
| 1052 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1053 | /* save the sched scan matchsets... */ |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1054 | if (nd_config->n_match_sets) { |
| 1055 | mvm->nd_match_sets = kmemdup(nd_config->match_sets, |
| 1056 | sizeof(*nd_config->match_sets) * |
| 1057 | nd_config->n_match_sets, |
| 1058 | GFP_KERNEL); |
| 1059 | if (mvm->nd_match_sets) |
| 1060 | mvm->n_nd_match_sets = nd_config->n_match_sets; |
| 1061 | } |
| 1062 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1063 | /* ...and the sched scan channels for later reporting */ |
| 1064 | mvm->nd_channels = kmemdup(nd_config->channels, |
| 1065 | sizeof(*nd_config->channels) * |
| 1066 | nd_config->n_channels, |
| 1067 | GFP_KERNEL); |
| 1068 | if (mvm->nd_channels) |
| 1069 | mvm->n_nd_channels = nd_config->n_channels; |
| 1070 | |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1071 | return 0; |
| 1072 | } |
| 1073 | |
| 1074 | static void iwl_mvm_free_nd(struct iwl_mvm *mvm) |
| 1075 | { |
| 1076 | kfree(mvm->nd_match_sets); |
| 1077 | mvm->nd_match_sets = NULL; |
| 1078 | mvm->n_nd_match_sets = 0; |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1079 | kfree(mvm->nd_channels); |
| 1080 | mvm->nd_channels = NULL; |
| 1081 | mvm->n_nd_channels = 0; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1084 | static int __iwl_mvm_suspend(struct ieee80211_hw *hw, |
| 1085 | struct cfg80211_wowlan *wowlan, |
| 1086 | bool test) |
| 1087 | { |
| 1088 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1089 | struct ieee80211_vif *vif = NULL; |
| 1090 | struct iwl_mvm_vif *mvmvif = NULL; |
| 1091 | struct ieee80211_sta *ap_sta = NULL; |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1092 | struct iwl_d3_manager_config d3_cfg_cmd_data = { |
| 1093 | /* |
| 1094 | * Program the minimum sleep time to 10 seconds, as many |
| 1095 | * platforms have issues processing a wakeup signal while |
| 1096 | * still being in the process of suspending. |
| 1097 | */ |
| 1098 | .min_sleep_time = cpu_to_le32(10 * 1000 * 1000), |
| 1099 | }; |
| 1100 | struct iwl_host_cmd d3_cfg_cmd = { |
| 1101 | .id = D3_CONFIG_CMD, |
| 1102 | .flags = CMD_WANT_SKB, |
| 1103 | .data[0] = &d3_cfg_cmd_data, |
| 1104 | .len[0] = sizeof(d3_cfg_cmd_data), |
| 1105 | }; |
| 1106 | int ret; |
| 1107 | int len __maybe_unused; |
| 1108 | |
| 1109 | if (!wowlan) { |
| 1110 | /* |
| 1111 | * mac80211 shouldn't get here, but for D3 test |
| 1112 | * it doesn't warrant a warning |
| 1113 | */ |
| 1114 | WARN_ON(!test); |
| 1115 | return -EINVAL; |
| 1116 | } |
| 1117 | |
| 1118 | mutex_lock(&mvm->mutex); |
| 1119 | |
Luciano Coelho | 7f549e2 | 2014-10-02 15:38:04 +0300 | [diff] [blame] | 1120 | vif = iwl_mvm_get_bss_vif(mvm); |
| 1121 | if (IS_ERR_OR_NULL(vif)) { |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1122 | ret = 1; |
| 1123 | goto out_noreset; |
| 1124 | } |
| 1125 | |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1126 | mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1127 | |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1128 | if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT) { |
| 1129 | /* if we're not associated, this must be netdetect */ |
Luca Coelho | 566f165 | 2015-10-25 22:55:32 +0200 | [diff] [blame] | 1130 | if (!wowlan->nd_config) { |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1131 | ret = 1; |
| 1132 | goto out_noreset; |
| 1133 | } |
| 1134 | |
| 1135 | ret = iwl_mvm_netdetect_config( |
Luca Coelho | 566f165 | 2015-10-25 22:55:32 +0200 | [diff] [blame] | 1136 | mvm, wowlan, wowlan->nd_config, vif); |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1137 | if (ret) |
| 1138 | goto out; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1139 | |
| 1140 | mvm->net_detect = true; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1141 | } else { |
Emmanuel Grumbach | c8b06a9 | 2014-11-24 09:06:57 +0200 | [diff] [blame] | 1142 | struct iwl_wowlan_config_cmd wowlan_config_cmd = {}; |
Luciano Coelho | 3acc952 | 2014-11-19 22:35:37 +0200 | [diff] [blame] | 1143 | |
Luciano Coelho | 1e4d19c | 2014-09-22 13:01:59 +0300 | [diff] [blame] | 1144 | ap_sta = rcu_dereference_protected( |
| 1145 | mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], |
| 1146 | lockdep_is_held(&mvm->mutex)); |
| 1147 | if (IS_ERR_OR_NULL(ap_sta)) { |
| 1148 | ret = -EINVAL; |
| 1149 | goto out_noreset; |
| 1150 | } |
| 1151 | |
| 1152 | ret = iwl_mvm_get_wowlan_config(mvm, wowlan, &wowlan_config_cmd, |
| 1153 | vif, mvmvif, ap_sta); |
| 1154 | if (ret) |
| 1155 | goto out_noreset; |
Luciano Coelho | 1e4d19c | 2014-09-22 13:01:59 +0300 | [diff] [blame] | 1156 | ret = iwl_mvm_wowlan_config(mvm, wowlan, &wowlan_config_cmd, |
| 1157 | vif, mvmvif, ap_sta); |
| 1158 | if (ret) |
| 1159 | goto out; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1160 | |
| 1161 | mvm->net_detect = false; |
Luciano Coelho | 671b582 | 2014-09-22 10:59:53 +0300 | [diff] [blame] | 1162 | } |
| 1163 | |
Emmanuel Grumbach | c1cb92f | 2014-01-28 10:17:18 +0200 | [diff] [blame] | 1164 | ret = iwl_mvm_power_update_device(mvm); |
Alexander Bondar | 64b928c | 2013-09-03 14:18:03 +0300 | [diff] [blame] | 1165 | if (ret) |
| 1166 | goto out; |
| 1167 | |
Arik Nemtsov | 999609f | 2014-05-15 17:31:51 +0300 | [diff] [blame] | 1168 | ret = iwl_mvm_power_update_mac(mvm); |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 1169 | if (ret) |
| 1170 | goto out; |
| 1171 | |
Johannes Berg | b011471 | 2013-06-12 14:55:40 +0200 | [diff] [blame] | 1172 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1173 | if (mvm->d3_wake_sysassert) |
| 1174 | d3_cfg_cmd_data.wakeup_flags |= |
| 1175 | cpu_to_le32(IWL_WAKEUP_D3_CONFIG_FW_ERROR); |
| 1176 | #endif |
| 1177 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1178 | /* must be last -- this switches firmware state */ |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1179 | ret = iwl_mvm_send_cmd(mvm, &d3_cfg_cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1180 | if (ret) |
| 1181 | goto out; |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1182 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Johannes Berg | 65b3034 | 2014-01-08 13:16:33 +0100 | [diff] [blame] | 1183 | len = iwl_rx_packet_payload_len(d3_cfg_cmd.resp_pkt); |
| 1184 | if (len >= sizeof(u32)) { |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1185 | mvm->d3_test_pme_ptr = |
| 1186 | le32_to_cpup((__le32 *)d3_cfg_cmd.resp_pkt->data); |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1187 | } |
| 1188 | #endif |
| 1189 | iwl_free_resp(&d3_cfg_cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1190 | |
| 1191 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 1192 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1193 | iwl_trans_d3_suspend(mvm->trans, test); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1194 | out: |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1195 | if (ret < 0) { |
Eliad Peller | 48e6775 | 2015-03-03 12:03:20 +0200 | [diff] [blame] | 1196 | iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1197 | ieee80211_restart_hw(mvm->hw); |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1198 | iwl_mvm_free_nd(mvm); |
| 1199 | } |
Luciano Coelho | b70ab72 | 2013-11-19 22:53:41 +0200 | [diff] [blame] | 1200 | out_noreset: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1201 | mutex_unlock(&mvm->mutex); |
| 1202 | |
| 1203 | return ret; |
| 1204 | } |
| 1205 | |
Eliad Peller | 6735943 | 2014-12-09 15:23:54 +0200 | [diff] [blame] | 1206 | static int iwl_mvm_enter_d0i3_sync(struct iwl_mvm *mvm) |
| 1207 | { |
| 1208 | struct iwl_notification_wait wait_d3; |
Sara Sharon | 6eb031d | 2015-07-13 14:50:47 +0300 | [diff] [blame] | 1209 | static const u16 d3_notif[] = { D3_CONFIG_CMD }; |
Eliad Peller | 6735943 | 2014-12-09 15:23:54 +0200 | [diff] [blame] | 1210 | int ret; |
| 1211 | |
| 1212 | iwl_init_notification_wait(&mvm->notif_wait, &wait_d3, |
| 1213 | d3_notif, ARRAY_SIZE(d3_notif), |
| 1214 | NULL, NULL); |
| 1215 | |
| 1216 | ret = iwl_mvm_enter_d0i3(mvm->hw->priv); |
| 1217 | if (ret) |
| 1218 | goto remove_notif; |
| 1219 | |
| 1220 | ret = iwl_wait_notification(&mvm->notif_wait, &wait_d3, HZ); |
| 1221 | WARN_ON_ONCE(ret); |
| 1222 | return ret; |
| 1223 | |
| 1224 | remove_notif: |
| 1225 | iwl_remove_notification(&mvm->notif_wait, &wait_d3); |
| 1226 | return ret; |
| 1227 | } |
| 1228 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1229 | int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
| 1230 | { |
Eliad Peller | d15a747 | 2014-03-27 18:53:12 +0200 | [diff] [blame] | 1231 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 1232 | struct iwl_trans *trans = mvm->trans; |
Eliad Peller | c43fe90 | 2015-06-04 21:59:32 +0300 | [diff] [blame] | 1233 | int ret; |
Eliad Peller | d15a747 | 2014-03-27 18:53:12 +0200 | [diff] [blame] | 1234 | |
Luciano Coelho | cf8c3cf | 2015-08-24 14:53:25 +0300 | [diff] [blame] | 1235 | /* make sure the d0i3 exit work is not pending */ |
| 1236 | flush_work(&mvm->d0i3_exit_work); |
| 1237 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 1238 | ret = iwl_trans_suspend(trans); |
Eliad Peller | c43fe90 | 2015-06-04 21:59:32 +0300 | [diff] [blame] | 1239 | if (ret) |
| 1240 | return ret; |
| 1241 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 1242 | if (wowlan->any) { |
| 1243 | trans->system_pm_mode = IWL_PLAT_PM_MODE_D0I3; |
| 1244 | |
| 1245 | if (iwl_mvm_enter_d0i3_on_suspend(mvm)) { |
Eliad Peller | c43fe90 | 2015-06-04 21:59:32 +0300 | [diff] [blame] | 1246 | ret = iwl_mvm_enter_d0i3_sync(mvm); |
Eliad Peller | 6735943 | 2014-12-09 15:23:54 +0200 | [diff] [blame] | 1247 | |
| 1248 | if (ret) |
| 1249 | return ret; |
| 1250 | } |
| 1251 | |
Eliad Peller | d15a747 | 2014-03-27 18:53:12 +0200 | [diff] [blame] | 1252 | mutex_lock(&mvm->d0i3_suspend_mutex); |
| 1253 | __set_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags); |
| 1254 | mutex_unlock(&mvm->d0i3_suspend_mutex); |
Eliad Peller | 6dfb36c | 2015-07-09 14:17:24 +0300 | [diff] [blame] | 1255 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 1256 | iwl_trans_d3_suspend(trans, false); |
Eliad Peller | 6dfb36c | 2015-07-09 14:17:24 +0300 | [diff] [blame] | 1257 | |
Eliad Peller | d15a747 | 2014-03-27 18:53:12 +0200 | [diff] [blame] | 1258 | return 0; |
| 1259 | } |
| 1260 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 1261 | trans->system_pm_mode = IWL_PLAT_PM_MODE_D3; |
| 1262 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1263 | return __iwl_mvm_suspend(hw, wowlan, false); |
| 1264 | } |
| 1265 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1266 | /* converted data from the different status responses */ |
| 1267 | struct iwl_wowlan_status_data { |
| 1268 | u16 pattern_number; |
| 1269 | u16 qos_seq_ctr[8]; |
| 1270 | u32 wakeup_reasons; |
| 1271 | u32 wake_packet_length; |
| 1272 | u32 wake_packet_bufsize; |
| 1273 | const u8 *wake_packet; |
| 1274 | }; |
| 1275 | |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1276 | static void iwl_mvm_report_wakeup_reasons(struct iwl_mvm *mvm, |
| 1277 | struct ieee80211_vif *vif, |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1278 | struct iwl_wowlan_status_data *status) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1279 | { |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1280 | struct sk_buff *pkt = NULL; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1281 | struct cfg80211_wowlan_wakeup wakeup = { |
| 1282 | .pattern_idx = -1, |
| 1283 | }; |
| 1284 | struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1285 | u32 reasons = status->wakeup_reasons; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1286 | |
| 1287 | if (reasons == IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) { |
| 1288 | wakeup_report = NULL; |
| 1289 | goto report; |
| 1290 | } |
| 1291 | |
Derek Basehore | 06ae2ad | 2015-11-04 17:37:52 -0800 | [diff] [blame] | 1292 | pm_wakeup_event(mvm->dev, 0); |
| 1293 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1294 | if (reasons & IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1295 | wakeup.magic_pkt = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1296 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1297 | if (reasons & IWL_WOWLAN_WAKEUP_BY_PATTERN) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1298 | wakeup.pattern_idx = |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1299 | status->pattern_number; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1300 | |
| 1301 | if (reasons & (IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON | |
| 1302 | IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH)) |
| 1303 | wakeup.disconnect = true; |
| 1304 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1305 | if (reasons & IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1306 | wakeup.gtk_rekey_failure = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1307 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1308 | if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1309 | wakeup.rfkill_release = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1310 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1311 | if (reasons & IWL_WOWLAN_WAKEUP_BY_EAPOL_REQUEST) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1312 | wakeup.eap_identity_req = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1313 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1314 | if (reasons & IWL_WOWLAN_WAKEUP_BY_FOUR_WAY_HANDSHAKE) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1315 | wakeup.four_way_handshake = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1316 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 1317 | if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_LINK_LOSS) |
| 1318 | wakeup.tcp_connlost = true; |
| 1319 | |
| 1320 | if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_SIGNATURE_TABLE) |
| 1321 | wakeup.tcp_nomoretokens = true; |
| 1322 | |
| 1323 | if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_WAKEUP_PACKET) |
| 1324 | wakeup.tcp_match = true; |
| 1325 | |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1326 | if (status->wake_packet_bufsize) { |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1327 | int pktsize = status->wake_packet_bufsize; |
| 1328 | int pktlen = status->wake_packet_length; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1329 | const u8 *pktdata = status->wake_packet; |
| 1330 | struct ieee80211_hdr *hdr = (void *)pktdata; |
| 1331 | int truncated = pktlen - pktsize; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1332 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1333 | /* this would be a firmware bug */ |
| 1334 | if (WARN_ON_ONCE(truncated < 0)) |
| 1335 | truncated = 0; |
| 1336 | |
| 1337 | if (ieee80211_is_data(hdr->frame_control)) { |
| 1338 | int hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 1339 | int ivlen = 0, icvlen = 4; /* also FCS */ |
| 1340 | |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1341 | pkt = alloc_skb(pktsize, GFP_KERNEL); |
| 1342 | if (!pkt) |
| 1343 | goto report; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1344 | |
| 1345 | memcpy(skb_put(pkt, hdrlen), pktdata, hdrlen); |
| 1346 | pktdata += hdrlen; |
| 1347 | pktsize -= hdrlen; |
| 1348 | |
| 1349 | if (ieee80211_has_protected(hdr->frame_control)) { |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1350 | /* |
| 1351 | * This is unlocked and using gtk_i(c)vlen, |
| 1352 | * but since everything is under RTNL still |
| 1353 | * that's not really a problem - changing |
| 1354 | * it would be difficult. |
| 1355 | */ |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1356 | if (is_multicast_ether_addr(hdr->addr1)) { |
| 1357 | ivlen = mvm->gtk_ivlen; |
| 1358 | icvlen += mvm->gtk_icvlen; |
| 1359 | } else { |
| 1360 | ivlen = mvm->ptk_ivlen; |
| 1361 | icvlen += mvm->ptk_icvlen; |
| 1362 | } |
| 1363 | } |
| 1364 | |
| 1365 | /* if truncated, FCS/ICV is (partially) gone */ |
| 1366 | if (truncated >= icvlen) { |
| 1367 | icvlen = 0; |
| 1368 | truncated -= icvlen; |
| 1369 | } else { |
| 1370 | icvlen -= truncated; |
| 1371 | truncated = 0; |
| 1372 | } |
| 1373 | |
| 1374 | pktsize -= ivlen + icvlen; |
| 1375 | pktdata += ivlen; |
| 1376 | |
| 1377 | memcpy(skb_put(pkt, pktsize), pktdata, pktsize); |
| 1378 | |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1379 | if (ieee80211_data_to_8023(pkt, vif->addr, vif->type)) |
| 1380 | goto report; |
| 1381 | wakeup.packet = pkt->data; |
| 1382 | wakeup.packet_present_len = pkt->len; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1383 | wakeup.packet_len = pkt->len - truncated; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1384 | wakeup.packet_80211 = false; |
| 1385 | } else { |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1386 | int fcslen = 4; |
| 1387 | |
| 1388 | if (truncated >= 4) { |
| 1389 | truncated -= 4; |
| 1390 | fcslen = 0; |
| 1391 | } else { |
| 1392 | fcslen -= truncated; |
| 1393 | truncated = 0; |
| 1394 | } |
| 1395 | pktsize -= fcslen; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1396 | wakeup.packet = status->wake_packet; |
| 1397 | wakeup.packet_present_len = pktsize; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1398 | wakeup.packet_len = pktlen - truncated; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1399 | wakeup.packet_80211 = true; |
| 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | report: |
| 1404 | ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL); |
| 1405 | kfree_skb(pkt); |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1406 | } |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1407 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1408 | static void iwl_mvm_aes_sc_to_seq(struct aes_sc *sc, |
| 1409 | struct ieee80211_key_seq *seq) |
| 1410 | { |
| 1411 | u64 pn; |
| 1412 | |
| 1413 | pn = le64_to_cpu(sc->pn); |
| 1414 | seq->ccmp.pn[0] = pn >> 40; |
| 1415 | seq->ccmp.pn[1] = pn >> 32; |
| 1416 | seq->ccmp.pn[2] = pn >> 24; |
| 1417 | seq->ccmp.pn[3] = pn >> 16; |
| 1418 | seq->ccmp.pn[4] = pn >> 8; |
| 1419 | seq->ccmp.pn[5] = pn; |
| 1420 | } |
| 1421 | |
| 1422 | static void iwl_mvm_tkip_sc_to_seq(struct tkip_sc *sc, |
| 1423 | struct ieee80211_key_seq *seq) |
| 1424 | { |
| 1425 | seq->tkip.iv32 = le32_to_cpu(sc->iv32); |
| 1426 | seq->tkip.iv16 = le16_to_cpu(sc->iv16); |
| 1427 | } |
| 1428 | |
| 1429 | static void iwl_mvm_set_aes_rx_seq(struct aes_sc *scs, |
| 1430 | struct ieee80211_key_conf *key) |
| 1431 | { |
| 1432 | int tid; |
| 1433 | |
| 1434 | BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS); |
| 1435 | |
| 1436 | for (tid = 0; tid < IWL_NUM_RSC; tid++) { |
| 1437 | struct ieee80211_key_seq seq = {}; |
| 1438 | |
| 1439 | iwl_mvm_aes_sc_to_seq(&scs[tid], &seq); |
| 1440 | ieee80211_set_key_rx_seq(key, tid, &seq); |
| 1441 | } |
| 1442 | } |
| 1443 | |
| 1444 | static void iwl_mvm_set_tkip_rx_seq(struct tkip_sc *scs, |
| 1445 | struct ieee80211_key_conf *key) |
| 1446 | { |
| 1447 | int tid; |
| 1448 | |
| 1449 | BUILD_BUG_ON(IWL_NUM_RSC != IEEE80211_NUM_TIDS); |
| 1450 | |
| 1451 | for (tid = 0; tid < IWL_NUM_RSC; tid++) { |
| 1452 | struct ieee80211_key_seq seq = {}; |
| 1453 | |
| 1454 | iwl_mvm_tkip_sc_to_seq(&scs[tid], &seq); |
| 1455 | ieee80211_set_key_rx_seq(key, tid, &seq); |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | static void iwl_mvm_set_key_rx_seq(struct ieee80211_key_conf *key, |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1460 | struct iwl_wowlan_status *status) |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1461 | { |
| 1462 | union iwl_all_tsc_rsc *rsc = &status->gtk.rsc.all_tsc_rsc; |
| 1463 | |
| 1464 | switch (key->cipher) { |
| 1465 | case WLAN_CIPHER_SUITE_CCMP: |
| 1466 | iwl_mvm_set_aes_rx_seq(rsc->aes.multicast_rsc, key); |
| 1467 | break; |
| 1468 | case WLAN_CIPHER_SUITE_TKIP: |
| 1469 | iwl_mvm_set_tkip_rx_seq(rsc->tkip.multicast_rsc, key); |
| 1470 | break; |
| 1471 | default: |
| 1472 | WARN_ON(1); |
| 1473 | } |
| 1474 | } |
| 1475 | |
| 1476 | struct iwl_mvm_d3_gtk_iter_data { |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1477 | struct iwl_wowlan_status *status; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1478 | void *last_gtk; |
| 1479 | u32 cipher; |
| 1480 | bool find_phase, unhandled_cipher; |
| 1481 | int num_keys; |
| 1482 | }; |
| 1483 | |
Emmanuel Grumbach | 59fd4bf | 2015-11-01 13:06:37 +0200 | [diff] [blame] | 1484 | static void iwl_mvm_d3_update_keys(struct ieee80211_hw *hw, |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1485 | struct ieee80211_vif *vif, |
| 1486 | struct ieee80211_sta *sta, |
| 1487 | struct ieee80211_key_conf *key, |
| 1488 | void *_data) |
| 1489 | { |
| 1490 | struct iwl_mvm_d3_gtk_iter_data *data = _data; |
| 1491 | |
| 1492 | if (data->unhandled_cipher) |
| 1493 | return; |
| 1494 | |
| 1495 | switch (key->cipher) { |
| 1496 | case WLAN_CIPHER_SUITE_WEP40: |
| 1497 | case WLAN_CIPHER_SUITE_WEP104: |
| 1498 | /* ignore WEP completely, nothing to do */ |
| 1499 | return; |
| 1500 | case WLAN_CIPHER_SUITE_CCMP: |
| 1501 | case WLAN_CIPHER_SUITE_TKIP: |
| 1502 | /* we support these */ |
| 1503 | break; |
| 1504 | default: |
| 1505 | /* everything else (even CMAC for MFP) - disconnect from AP */ |
| 1506 | data->unhandled_cipher = true; |
| 1507 | return; |
| 1508 | } |
| 1509 | |
| 1510 | data->num_keys++; |
| 1511 | |
| 1512 | /* |
| 1513 | * pairwise key - update sequence counters only; |
| 1514 | * note that this assumes no TDLS sessions are active |
| 1515 | */ |
| 1516 | if (sta) { |
| 1517 | struct ieee80211_key_seq seq = {}; |
| 1518 | union iwl_all_tsc_rsc *sc = &data->status->gtk.rsc.all_tsc_rsc; |
| 1519 | |
| 1520 | if (data->find_phase) |
| 1521 | return; |
| 1522 | |
| 1523 | switch (key->cipher) { |
| 1524 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1525 | iwl_mvm_set_aes_rx_seq(sc->aes.unicast_rsc, key); |
Johannes Berg | 6645d5e | 2015-09-15 09:58:53 +0200 | [diff] [blame] | 1526 | atomic64_set(&key->tx_pn, le64_to_cpu(sc->aes.tsc.pn)); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1527 | break; |
| 1528 | case WLAN_CIPHER_SUITE_TKIP: |
| 1529 | iwl_mvm_tkip_sc_to_seq(&sc->tkip.tsc, &seq); |
| 1530 | iwl_mvm_set_tkip_rx_seq(sc->tkip.unicast_rsc, key); |
Johannes Berg | 6645d5e | 2015-09-15 09:58:53 +0200 | [diff] [blame] | 1531 | ieee80211_set_key_tx_seq(key, &seq); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1532 | break; |
| 1533 | } |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1534 | |
| 1535 | /* that's it for this key */ |
| 1536 | return; |
| 1537 | } |
| 1538 | |
| 1539 | if (data->find_phase) { |
| 1540 | data->last_gtk = key; |
| 1541 | data->cipher = key->cipher; |
| 1542 | return; |
| 1543 | } |
| 1544 | |
| 1545 | if (data->status->num_of_gtk_rekeys) |
| 1546 | ieee80211_remove_key(key); |
| 1547 | else if (data->last_gtk == key) |
| 1548 | iwl_mvm_set_key_rx_seq(key, data->status); |
| 1549 | } |
| 1550 | |
| 1551 | static bool iwl_mvm_setup_connection_keep(struct iwl_mvm *mvm, |
| 1552 | struct ieee80211_vif *vif, |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1553 | struct iwl_wowlan_status *status) |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1554 | { |
| 1555 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1556 | struct iwl_mvm_d3_gtk_iter_data gtkdata = { |
| 1557 | .status = status, |
| 1558 | }; |
Eliad Peller | 431591c | 2013-11-07 14:12:09 +0200 | [diff] [blame] | 1559 | u32 disconnection_reasons = |
| 1560 | IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON | |
| 1561 | IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1562 | |
| 1563 | if (!status || !vif->bss_conf.bssid) |
| 1564 | return false; |
| 1565 | |
Eliad Peller | 431591c | 2013-11-07 14:12:09 +0200 | [diff] [blame] | 1566 | if (le32_to_cpu(status->wakeup_reasons) & disconnection_reasons) |
| 1567 | return false; |
| 1568 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1569 | /* find last GTK that we used initially, if any */ |
| 1570 | gtkdata.find_phase = true; |
| 1571 | ieee80211_iter_keys(mvm->hw, vif, |
Emmanuel Grumbach | 59fd4bf | 2015-11-01 13:06:37 +0200 | [diff] [blame] | 1572 | iwl_mvm_d3_update_keys, >kdata); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1573 | /* not trying to keep connections with MFP/unhandled ciphers */ |
| 1574 | if (gtkdata.unhandled_cipher) |
| 1575 | return false; |
| 1576 | if (!gtkdata.num_keys) |
Luciano Coelho | cfa8889 | 2013-11-19 15:38:55 +0200 | [diff] [blame] | 1577 | goto out; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1578 | if (!gtkdata.last_gtk) |
| 1579 | return false; |
| 1580 | |
| 1581 | /* |
| 1582 | * invalidate all other GTKs that might still exist and update |
| 1583 | * the one that we used |
| 1584 | */ |
| 1585 | gtkdata.find_phase = false; |
| 1586 | ieee80211_iter_keys(mvm->hw, vif, |
Emmanuel Grumbach | 59fd4bf | 2015-11-01 13:06:37 +0200 | [diff] [blame] | 1587 | iwl_mvm_d3_update_keys, >kdata); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1588 | |
| 1589 | if (status->num_of_gtk_rekeys) { |
| 1590 | struct ieee80211_key_conf *key; |
| 1591 | struct { |
| 1592 | struct ieee80211_key_conf conf; |
| 1593 | u8 key[32]; |
| 1594 | } conf = { |
| 1595 | .conf.cipher = gtkdata.cipher, |
| 1596 | .conf.keyidx = status->gtk.key_index, |
| 1597 | }; |
| 1598 | |
| 1599 | switch (gtkdata.cipher) { |
| 1600 | case WLAN_CIPHER_SUITE_CCMP: |
| 1601 | conf.conf.keylen = WLAN_KEY_LEN_CCMP; |
| 1602 | memcpy(conf.conf.key, status->gtk.decrypt_key, |
| 1603 | WLAN_KEY_LEN_CCMP); |
| 1604 | break; |
| 1605 | case WLAN_CIPHER_SUITE_TKIP: |
| 1606 | conf.conf.keylen = WLAN_KEY_LEN_TKIP; |
| 1607 | memcpy(conf.conf.key, status->gtk.decrypt_key, 16); |
| 1608 | /* leave TX MIC key zeroed, we don't use it anyway */ |
| 1609 | memcpy(conf.conf.key + |
| 1610 | NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY, |
| 1611 | status->gtk.tkip_mic_key, 8); |
| 1612 | break; |
| 1613 | } |
| 1614 | |
| 1615 | key = ieee80211_gtk_rekey_add(vif, &conf.conf); |
| 1616 | if (IS_ERR(key)) |
| 1617 | return false; |
| 1618 | iwl_mvm_set_key_rx_seq(key, status); |
| 1619 | } |
| 1620 | |
| 1621 | if (status->num_of_gtk_rekeys) { |
| 1622 | __be64 replay_ctr = |
| 1623 | cpu_to_be64(le64_to_cpu(status->replay_ctr)); |
| 1624 | ieee80211_gtk_rekey_notify(vif, vif->bss_conf.bssid, |
| 1625 | (void *)&replay_ctr, GFP_KERNEL); |
| 1626 | } |
| 1627 | |
Luciano Coelho | cfa8889 | 2013-11-19 15:38:55 +0200 | [diff] [blame] | 1628 | out: |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1629 | mvmvif->seqno_valid = true; |
| 1630 | /* +0x10 because the set API expects next-to-use, not last-used */ |
| 1631 | mvmvif->seqno = le16_to_cpu(status->non_qos_seq_ctr) + 0x10; |
| 1632 | |
| 1633 | return true; |
| 1634 | } |
| 1635 | |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1636 | static struct iwl_wowlan_status * |
| 1637 | iwl_mvm_get_wakeup_status(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1638 | { |
| 1639 | u32 base = mvm->error_event_table; |
| 1640 | struct error_table_start { |
| 1641 | /* cf. struct iwl_error_event_table */ |
| 1642 | u32 valid; |
| 1643 | u32 error_id; |
| 1644 | } err_info; |
| 1645 | struct iwl_host_cmd cmd = { |
| 1646 | .id = WOWLAN_GET_STATUSES, |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1647 | .flags = CMD_WANT_SKB, |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1648 | }; |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1649 | struct iwl_wowlan_status *status, *fw_status; |
| 1650 | int ret, len, status_size; |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1651 | |
| 1652 | iwl_trans_read_mem_bytes(mvm->trans, base, |
| 1653 | &err_info, sizeof(err_info)); |
| 1654 | |
| 1655 | if (err_info.valid) { |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1656 | IWL_INFO(mvm, "error table is valid (%d) with error (%d)\n", |
| 1657 | err_info.valid, err_info.error_id); |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1658 | if (err_info.error_id == RF_KILL_INDICATOR_FOR_WOWLAN) { |
| 1659 | struct cfg80211_wowlan_wakeup wakeup = { |
| 1660 | .rfkill_release = true, |
| 1661 | }; |
| 1662 | ieee80211_report_wowlan_wakeup(vif, &wakeup, |
| 1663 | GFP_KERNEL); |
| 1664 | } |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1665 | return ERR_PTR(-EIO); |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | /* only for tracing for now */ |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1669 | 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] | 1670 | if (ret) |
| 1671 | IWL_ERR(mvm, "failed to query offload statistics (%d)\n", ret); |
| 1672 | |
| 1673 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 1674 | if (ret) { |
| 1675 | IWL_ERR(mvm, "failed to query status (%d)\n", ret); |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1676 | return ERR_PTR(ret); |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | /* RF-kill already asserted again... */ |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1680 | if (!cmd.resp_pkt) { |
Johannes Berg | e111e96 | 2015-03-03 20:23:47 +0100 | [diff] [blame] | 1681 | fw_status = ERR_PTR(-ERFKILL); |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1682 | goto out_free_resp; |
| 1683 | } |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1684 | |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1685 | status_size = sizeof(*fw_status); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1686 | |
Johannes Berg | 65b3034 | 2014-01-08 13:16:33 +0100 | [diff] [blame] | 1687 | len = iwl_rx_packet_payload_len(cmd.resp_pkt); |
| 1688 | if (len < status_size) { |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1689 | IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); |
Johannes Berg | e111e96 | 2015-03-03 20:23:47 +0100 | [diff] [blame] | 1690 | fw_status = ERR_PTR(-EIO); |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1691 | goto out_free_resp; |
| 1692 | } |
| 1693 | |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1694 | status = (void *)cmd.resp_pkt->data; |
| 1695 | if (len != (status_size + |
| 1696 | ALIGN(le32_to_cpu(status->wake_packet_bufsize), 4))) { |
| 1697 | IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); |
Johannes Berg | e111e96 | 2015-03-03 20:23:47 +0100 | [diff] [blame] | 1698 | fw_status = ERR_PTR(-EIO); |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1699 | goto out_free_resp; |
| 1700 | } |
| 1701 | |
| 1702 | fw_status = kmemdup(status, len, GFP_KERNEL); |
| 1703 | |
| 1704 | out_free_resp: |
| 1705 | iwl_free_resp(&cmd); |
Johannes Berg | e111e96 | 2015-03-03 20:23:47 +0100 | [diff] [blame] | 1706 | return fw_status; |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1707 | } |
| 1708 | |
| 1709 | /* releases the MVM mutex */ |
| 1710 | static bool iwl_mvm_query_wakeup_reasons(struct iwl_mvm *mvm, |
| 1711 | struct ieee80211_vif *vif) |
| 1712 | { |
| 1713 | struct iwl_wowlan_status_data status; |
| 1714 | struct iwl_wowlan_status *fw_status; |
| 1715 | int i; |
| 1716 | bool keep; |
| 1717 | struct ieee80211_sta *ap_sta; |
| 1718 | struct iwl_mvm_sta *mvm_ap_sta; |
| 1719 | |
| 1720 | fw_status = iwl_mvm_get_wakeup_status(mvm, vif); |
| 1721 | if (IS_ERR_OR_NULL(fw_status)) |
| 1722 | goto out_unlock; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1723 | |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1724 | status.pattern_number = le16_to_cpu(fw_status->pattern_number); |
| 1725 | for (i = 0; i < 8; i++) |
| 1726 | status.qos_seq_ctr[i] = |
| 1727 | le16_to_cpu(fw_status->qos_seq_ctr[i]); |
| 1728 | status.wakeup_reasons = le32_to_cpu(fw_status->wakeup_reasons); |
| 1729 | status.wake_packet_length = |
| 1730 | le32_to_cpu(fw_status->wake_packet_length); |
| 1731 | status.wake_packet_bufsize = |
| 1732 | le32_to_cpu(fw_status->wake_packet_bufsize); |
| 1733 | status.wake_packet = fw_status->wake_packet; |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1734 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1735 | /* still at hard-coded place 0 for D3 image */ |
| 1736 | ap_sta = rcu_dereference_protected( |
| 1737 | mvm->fw_id_to_mac_id[0], |
| 1738 | lockdep_is_held(&mvm->mutex)); |
| 1739 | if (IS_ERR_OR_NULL(ap_sta)) |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1740 | goto out_free; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1741 | |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1742 | mvm_ap_sta = iwl_mvm_sta_from_mac80211(ap_sta); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1743 | for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
| 1744 | u16 seq = status.qos_seq_ctr[i]; |
| 1745 | /* firmware stores last-used value, we store next value */ |
| 1746 | seq += 0x10; |
| 1747 | mvm_ap_sta->tid_data[i].seq_number = seq; |
| 1748 | } |
| 1749 | |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1750 | /* now we have all the data we need, unlock to avoid mac80211 issues */ |
| 1751 | mutex_unlock(&mvm->mutex); |
| 1752 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1753 | iwl_mvm_report_wakeup_reasons(mvm, vif, &status); |
| 1754 | |
Emmanuel Grumbach | 3afec639 | 2014-03-30 09:10:28 +0300 | [diff] [blame] | 1755 | keep = iwl_mvm_setup_connection_keep(mvm, vif, fw_status); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1756 | |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1757 | kfree(fw_status); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1758 | return keep; |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1759 | |
Luciano Coelho | ec12f45 | 2014-11-20 10:14:44 +0200 | [diff] [blame] | 1760 | out_free: |
| 1761 | kfree(fw_status); |
| 1762 | out_unlock: |
Johannes Berg | 7abc463 | 2013-08-06 18:28:26 +0200 | [diff] [blame] | 1763 | mutex_unlock(&mvm->mutex); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1764 | return false; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1765 | } |
| 1766 | |
Eliad Peller | a3f7ba5 | 2015-11-11 17:23:59 +0200 | [diff] [blame] | 1767 | void iwl_mvm_d0i3_update_keys(struct iwl_mvm *mvm, |
| 1768 | struct ieee80211_vif *vif, |
| 1769 | struct iwl_wowlan_status *status) |
| 1770 | { |
| 1771 | struct iwl_mvm_d3_gtk_iter_data gtkdata = { |
| 1772 | .status = status, |
| 1773 | }; |
| 1774 | |
| 1775 | /* |
| 1776 | * rekey handling requires taking locks that can't be taken now. |
| 1777 | * however, d0i3 doesn't offload rekey, so we're fine. |
| 1778 | */ |
| 1779 | if (WARN_ON_ONCE(status->num_of_gtk_rekeys)) |
| 1780 | return; |
| 1781 | |
| 1782 | /* find last GTK that we used initially, if any */ |
| 1783 | gtkdata.find_phase = true; |
| 1784 | iwl_mvm_iter_d0i3_ap_keys(mvm, vif, iwl_mvm_d3_update_keys, >kdata); |
| 1785 | |
| 1786 | gtkdata.find_phase = false; |
| 1787 | iwl_mvm_iter_d0i3_ap_keys(mvm, vif, iwl_mvm_d3_update_keys, >kdata); |
| 1788 | } |
| 1789 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1790 | struct iwl_mvm_nd_query_results { |
| 1791 | u32 matched_profiles; |
| 1792 | struct iwl_scan_offload_profile_match matches[IWL_SCAN_MAX_PROFILES]; |
| 1793 | }; |
| 1794 | |
| 1795 | static int |
| 1796 | iwl_mvm_netdetect_query_results(struct iwl_mvm *mvm, |
| 1797 | struct iwl_mvm_nd_query_results *results) |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1798 | { |
| 1799 | struct iwl_scan_offload_profiles_query *query; |
| 1800 | struct iwl_host_cmd cmd = { |
| 1801 | .id = SCAN_OFFLOAD_PROFILES_QUERY_CMD, |
| 1802 | .flags = CMD_WANT_SKB, |
| 1803 | }; |
| 1804 | int ret, len; |
| 1805 | |
| 1806 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 1807 | if (ret) { |
| 1808 | IWL_ERR(mvm, "failed to query matched profiles (%d)\n", ret); |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1809 | return ret; |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | /* RF-kill already asserted again... */ |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1813 | if (!cmd.resp_pkt) { |
| 1814 | ret = -ERFKILL; |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1815 | goto out_free_resp; |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1816 | } |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1817 | |
| 1818 | len = iwl_rx_packet_payload_len(cmd.resp_pkt); |
| 1819 | if (len < sizeof(*query)) { |
| 1820 | IWL_ERR(mvm, "Invalid scan offload profiles query response!\n"); |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1821 | ret = -EIO; |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1822 | goto out_free_resp; |
| 1823 | } |
| 1824 | |
| 1825 | query = (void *)cmd.resp_pkt->data; |
| 1826 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1827 | results->matched_profiles = le32_to_cpu(query->matched_profiles); |
| 1828 | memcpy(results->matches, query->matches, sizeof(results->matches)); |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1829 | |
Emmanuel Grumbach | 6bbd552 | 2015-04-28 15:00:23 +0300 | [diff] [blame] | 1830 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Luciano Coelho | 484b3d1 | 2015-03-30 20:46:32 +0300 | [diff] [blame] | 1831 | mvm->last_netdetect_scans = le32_to_cpu(query->n_scans_done); |
| 1832 | #endif |
| 1833 | |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1834 | out_free_resp: |
| 1835 | iwl_free_resp(&cmd); |
| 1836 | return ret; |
| 1837 | } |
| 1838 | |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1839 | static void iwl_mvm_query_netdetect_reasons(struct iwl_mvm *mvm, |
| 1840 | struct ieee80211_vif *vif) |
| 1841 | { |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1842 | struct cfg80211_wowlan_nd_info *net_detect = NULL; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1843 | struct cfg80211_wowlan_wakeup wakeup = { |
| 1844 | .pattern_idx = -1, |
| 1845 | }; |
| 1846 | struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup; |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1847 | struct iwl_mvm_nd_query_results query; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1848 | struct iwl_wowlan_status *fw_status; |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1849 | unsigned long matched_profiles; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1850 | u32 reasons = 0; |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1851 | int i, j, n_matches, ret; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1852 | |
| 1853 | fw_status = iwl_mvm_get_wakeup_status(mvm, vif); |
Haim Dreyfuss | 2fc863a | 2015-05-20 08:10:43 +0300 | [diff] [blame] | 1854 | if (!IS_ERR_OR_NULL(fw_status)) { |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1855 | reasons = le32_to_cpu(fw_status->wakeup_reasons); |
Haim Dreyfuss | 2fc863a | 2015-05-20 08:10:43 +0300 | [diff] [blame] | 1856 | kfree(fw_status); |
| 1857 | } |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1858 | |
| 1859 | if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED) |
| 1860 | wakeup.rfkill_release = true; |
| 1861 | |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1862 | if (reasons != IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) |
| 1863 | goto out; |
| 1864 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1865 | ret = iwl_mvm_netdetect_query_results(mvm, &query); |
| 1866 | if (ret || !query.matched_profiles) { |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1867 | wakeup_report = NULL; |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1868 | goto out; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1869 | } |
| 1870 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1871 | matched_profiles = query.matched_profiles; |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1872 | if (mvm->n_nd_match_sets) { |
| 1873 | n_matches = hweight_long(matched_profiles); |
| 1874 | } else { |
| 1875 | IWL_ERR(mvm, "no net detect match information available\n"); |
| 1876 | n_matches = 0; |
| 1877 | } |
| 1878 | |
| 1879 | net_detect = kzalloc(sizeof(*net_detect) + |
| 1880 | (n_matches * sizeof(net_detect->matches[0])), |
| 1881 | GFP_KERNEL); |
| 1882 | if (!net_detect || !n_matches) |
| 1883 | goto out_report_nd; |
| 1884 | |
| 1885 | for_each_set_bit(i, &matched_profiles, mvm->n_nd_match_sets) { |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1886 | struct iwl_scan_offload_profile_match *fw_match; |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1887 | struct cfg80211_wowlan_nd_match *match; |
Luciano Coelho | ae90c2e5 | 2015-05-06 10:45:42 +0300 | [diff] [blame] | 1888 | int idx, n_channels = 0; |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1889 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1890 | fw_match = &query.matches[i]; |
| 1891 | |
| 1892 | for (j = 0; j < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN; j++) |
| 1893 | n_channels += hweight8(fw_match->matching_channels[j]); |
| 1894 | |
| 1895 | match = kzalloc(sizeof(*match) + |
| 1896 | (n_channels * sizeof(*match->channels)), |
| 1897 | GFP_KERNEL); |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1898 | if (!match) |
| 1899 | goto out_report_nd; |
| 1900 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1901 | net_detect->matches[net_detect->n_matches++] = match; |
| 1902 | |
Luciano Coelho | ae90c2e5 | 2015-05-06 10:45:42 +0300 | [diff] [blame] | 1903 | /* We inverted the order of the SSIDs in the scan |
| 1904 | * request, so invert the index here. |
| 1905 | */ |
| 1906 | idx = mvm->n_nd_match_sets - i - 1; |
| 1907 | match->ssid.ssid_len = mvm->nd_match_sets[idx].ssid.ssid_len; |
| 1908 | memcpy(match->ssid.ssid, mvm->nd_match_sets[idx].ssid.ssid, |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1909 | match->ssid.ssid_len); |
| 1910 | |
Luciano Coelho | 8ed4e65 | 2014-11-21 22:08:01 +0200 | [diff] [blame] | 1911 | if (mvm->n_nd_channels < n_channels) |
| 1912 | continue; |
| 1913 | |
| 1914 | for (j = 0; j < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN * 8; j++) |
| 1915 | if (fw_match->matching_channels[j / 8] & (BIT(j % 8))) |
| 1916 | match->channels[match->n_channels++] = |
| 1917 | mvm->nd_channels[j]->center_freq; |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | out_report_nd: |
| 1921 | wakeup.net_detect = net_detect; |
Luciano Coelho | b04998f | 2014-11-20 15:58:34 +0200 | [diff] [blame] | 1922 | out: |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1923 | iwl_mvm_free_nd(mvm); |
| 1924 | |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1925 | mutex_unlock(&mvm->mutex); |
| 1926 | ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL); |
Luciano Coelho | d9718da | 2014-11-21 09:32:23 +0200 | [diff] [blame] | 1927 | |
| 1928 | if (net_detect) { |
| 1929 | for (i = 0; i < net_detect->n_matches; i++) |
| 1930 | kfree(net_detect->matches[i]); |
| 1931 | kfree(net_detect); |
| 1932 | } |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1933 | } |
| 1934 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1935 | static void iwl_mvm_read_d3_sram(struct iwl_mvm *mvm) |
| 1936 | { |
| 1937 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1938 | const struct fw_img *img = &mvm->fw->img[IWL_UCODE_WOWLAN]; |
| 1939 | u32 len = img->sec[IWL_UCODE_SECTION_DATA].len; |
| 1940 | u32 offs = img->sec[IWL_UCODE_SECTION_DATA].offset; |
| 1941 | |
| 1942 | if (!mvm->store_d3_resume_sram) |
| 1943 | return; |
| 1944 | |
| 1945 | if (!mvm->d3_resume_sram) { |
| 1946 | mvm->d3_resume_sram = kzalloc(len, GFP_KERNEL); |
| 1947 | if (!mvm->d3_resume_sram) |
| 1948 | return; |
| 1949 | } |
| 1950 | |
| 1951 | iwl_trans_read_mem_bytes(mvm->trans, offs, mvm->d3_resume_sram, len); |
| 1952 | #endif |
| 1953 | } |
| 1954 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1955 | static void iwl_mvm_d3_disconnect_iter(void *data, u8 *mac, |
| 1956 | struct ieee80211_vif *vif) |
| 1957 | { |
| 1958 | /* skip the one we keep connection on */ |
| 1959 | if (data == vif) |
| 1960 | return; |
| 1961 | |
| 1962 | if (vif->type == NL80211_IFTYPE_STATION) |
| 1963 | ieee80211_resume_disconnect(vif); |
| 1964 | } |
| 1965 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1966 | static int __iwl_mvm_resume(struct iwl_mvm *mvm, bool test) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1967 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1968 | struct ieee80211_vif *vif = NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1969 | int ret; |
| 1970 | enum iwl_d3_status d3_status; |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1971 | bool keep = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1972 | |
| 1973 | mutex_lock(&mvm->mutex); |
| 1974 | |
| 1975 | /* get the BSS vif pointer again */ |
Luciano Coelho | 7f549e2 | 2014-10-02 15:38:04 +0300 | [diff] [blame] | 1976 | vif = iwl_mvm_get_bss_vif(mvm); |
| 1977 | if (IS_ERR_OR_NULL(vif)) |
Luciano Coelho | a500e46 | 2015-05-04 17:03:17 +0300 | [diff] [blame] | 1978 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1979 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 1980 | ret = iwl_trans_d3_resume(mvm->trans, &d3_status, test); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1981 | if (ret) |
Luciano Coelho | a500e46 | 2015-05-04 17:03:17 +0300 | [diff] [blame] | 1982 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1983 | |
| 1984 | if (d3_status != IWL_D3_STATUS_ALIVE) { |
| 1985 | IWL_INFO(mvm, "Device was reset during suspend\n"); |
Luciano Coelho | a500e46 | 2015-05-04 17:03:17 +0300 | [diff] [blame] | 1986 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1987 | } |
| 1988 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1989 | /* query SRAM first in case we want event logging */ |
| 1990 | iwl_mvm_read_d3_sram(mvm); |
| 1991 | |
Jonathan Doron | 47c8b15 | 2014-11-27 16:55:25 +0200 | [diff] [blame] | 1992 | /* |
| 1993 | * Query the current location and source from the D3 firmware so we |
| 1994 | * can play it back when we re-intiailize the D0 firmware |
| 1995 | */ |
| 1996 | iwl_mvm_update_changed_regdom(mvm); |
| 1997 | |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 1998 | if (mvm->net_detect) { |
| 1999 | iwl_mvm_query_netdetect_reasons(mvm, vif); |
Luciano Coelho | e0ede17 | 2015-02-13 21:37:09 +0200 | [diff] [blame] | 2000 | /* has unlocked the mutex, so skip that */ |
| 2001 | goto out; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 2002 | } else { |
| 2003 | keep = iwl_mvm_query_wakeup_reasons(mvm, vif); |
Eliad Peller | 78c9df6 | 2013-11-07 14:13:30 +0200 | [diff] [blame] | 2004 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 2005 | if (keep) |
| 2006 | mvm->keep_vif = vif; |
Luciano Coelho | 0c2ae04 | 2015-03-12 09:25:15 +0200 | [diff] [blame] | 2007 | #endif |
Luciano Coelho | e0ede17 | 2015-02-13 21:37:09 +0200 | [diff] [blame] | 2008 | /* has unlocked the mutex, so skip that */ |
| 2009 | goto out_iterate; |
Luciano Coelho | 2021a89 | 2014-11-20 08:59:51 +0200 | [diff] [blame] | 2010 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2011 | |
Luciano Coelho | a500e46 | 2015-05-04 17:03:17 +0300 | [diff] [blame] | 2012 | err: |
| 2013 | iwl_mvm_free_nd(mvm); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2014 | mutex_unlock(&mvm->mutex); |
| 2015 | |
Luciano Coelho | e0ede17 | 2015-02-13 21:37:09 +0200 | [diff] [blame] | 2016 | out_iterate: |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 2017 | if (!test) |
| 2018 | ieee80211_iterate_active_interfaces_rtnl(mvm->hw, |
| 2019 | IEEE80211_IFACE_ITER_NORMAL, |
| 2020 | iwl_mvm_d3_disconnect_iter, keep ? vif : NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2021 | |
Luciano Coelho | e0ede17 | 2015-02-13 21:37:09 +0200 | [diff] [blame] | 2022 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2023 | /* return 1 to reconfigure the device */ |
| 2024 | set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
Johannes Berg | 58629d9 | 2014-11-06 09:40:50 +0100 | [diff] [blame] | 2025 | set_bit(IWL_MVM_STATUS_D3_RECONFIG, &mvm->status); |
Luciano Coelho | dcfc7fb | 2015-04-28 08:41:55 +0300 | [diff] [blame] | 2026 | |
| 2027 | /* We always return 1, which causes mac80211 to do a reconfig |
| 2028 | * with IEEE80211_RECONFIG_TYPE_RESTART. This type of |
| 2029 | * reconfig calls iwl_mvm_restart_complete(), where we unref |
| 2030 | * the IWL_MVM_REF_UCODE_DOWN, so we need to take the |
| 2031 | * reference here. |
| 2032 | */ |
| 2033 | iwl_mvm_ref(mvm, IWL_MVM_REF_UCODE_DOWN); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2034 | return 1; |
| 2035 | } |
| 2036 | |
Eliad Peller | 2d42801 | 2015-06-17 15:32:37 +0300 | [diff] [blame] | 2037 | static int iwl_mvm_resume_d3(struct iwl_mvm *mvm) |
| 2038 | { |
| 2039 | iwl_trans_resume(mvm->trans); |
| 2040 | |
| 2041 | return __iwl_mvm_resume(mvm, false); |
| 2042 | } |
| 2043 | |
| 2044 | static int iwl_mvm_resume_d0i3(struct iwl_mvm *mvm) |
| 2045 | { |
| 2046 | bool exit_now; |
Eliad Peller | 6dfb36c | 2015-07-09 14:17:24 +0300 | [diff] [blame] | 2047 | enum iwl_d3_status d3_status; |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2048 | struct iwl_trans *trans = mvm->trans; |
Eliad Peller | 6dfb36c | 2015-07-09 14:17:24 +0300 | [diff] [blame] | 2049 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2050 | iwl_trans_d3_resume(trans, &d3_status, false); |
Eliad Peller | 2d42801 | 2015-06-17 15:32:37 +0300 | [diff] [blame] | 2051 | |
| 2052 | /* |
| 2053 | * make sure to clear D0I3_DEFER_WAKEUP before |
| 2054 | * calling iwl_trans_resume(), which might wait |
| 2055 | * for d0i3 exit completion. |
| 2056 | */ |
| 2057 | mutex_lock(&mvm->d0i3_suspend_mutex); |
| 2058 | __clear_bit(D0I3_DEFER_WAKEUP, &mvm->d0i3_suspend_flags); |
| 2059 | exit_now = __test_and_clear_bit(D0I3_PENDING_WAKEUP, |
| 2060 | &mvm->d0i3_suspend_flags); |
| 2061 | mutex_unlock(&mvm->d0i3_suspend_mutex); |
| 2062 | if (exit_now) { |
| 2063 | IWL_DEBUG_RPM(mvm, "Run deferred d0i3 exit\n"); |
| 2064 | _iwl_mvm_exit_d0i3(mvm); |
| 2065 | } |
| 2066 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2067 | iwl_trans_resume(trans); |
Eliad Peller | 2d42801 | 2015-06-17 15:32:37 +0300 | [diff] [blame] | 2068 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2069 | if (iwl_mvm_enter_d0i3_on_suspend(mvm)) { |
Eliad Peller | 2d42801 | 2015-06-17 15:32:37 +0300 | [diff] [blame] | 2070 | int ret = iwl_mvm_exit_d0i3(mvm->hw->priv); |
| 2071 | |
| 2072 | if (ret) |
| 2073 | return ret; |
| 2074 | /* |
| 2075 | * d0i3 exit will be deferred until reconfig_complete. |
| 2076 | * make sure there we are out of d0i3. |
| 2077 | */ |
| 2078 | } |
| 2079 | return 0; |
| 2080 | } |
| 2081 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2082 | int iwl_mvm_resume(struct ieee80211_hw *hw) |
| 2083 | { |
| 2084 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2085 | int ret; |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2086 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2087 | if (mvm->trans->system_pm_mode == IWL_PLAT_PM_MODE_D0I3) |
| 2088 | ret = iwl_mvm_resume_d0i3(mvm); |
Eliad Peller | 2d42801 | 2015-06-17 15:32:37 +0300 | [diff] [blame] | 2089 | else |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2090 | ret = iwl_mvm_resume_d3(mvm); |
| 2091 | |
| 2092 | mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED; |
| 2093 | |
| 2094 | return ret; |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2095 | } |
| 2096 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2097 | void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled) |
| 2098 | { |
| 2099 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 2100 | |
| 2101 | device_set_wakeup_enable(mvm->trans->dev, enabled); |
| 2102 | } |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2103 | |
| 2104 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 2105 | static int iwl_mvm_d3_test_open(struct inode *inode, struct file *file) |
| 2106 | { |
| 2107 | struct iwl_mvm *mvm = inode->i_private; |
| 2108 | int err; |
| 2109 | |
| 2110 | if (mvm->d3_test_active) |
| 2111 | return -EBUSY; |
| 2112 | |
| 2113 | file->private_data = inode->i_private; |
| 2114 | |
| 2115 | ieee80211_stop_queues(mvm->hw); |
| 2116 | synchronize_net(); |
| 2117 | |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2118 | mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_D3; |
| 2119 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2120 | /* start pseudo D3 */ |
| 2121 | rtnl_lock(); |
| 2122 | err = __iwl_mvm_suspend(mvm->hw, mvm->hw->wiphy->wowlan_config, true); |
| 2123 | rtnl_unlock(); |
| 2124 | if (err > 0) |
| 2125 | err = -EINVAL; |
| 2126 | if (err) { |
| 2127 | ieee80211_wake_queues(mvm->hw); |
| 2128 | return err; |
| 2129 | } |
| 2130 | mvm->d3_test_active = true; |
Eliad Peller | 78c9df6 | 2013-11-07 14:13:30 +0200 | [diff] [blame] | 2131 | mvm->keep_vif = NULL; |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2132 | return 0; |
| 2133 | } |
| 2134 | |
| 2135 | static ssize_t iwl_mvm_d3_test_read(struct file *file, char __user *user_buf, |
| 2136 | size_t count, loff_t *ppos) |
| 2137 | { |
| 2138 | struct iwl_mvm *mvm = file->private_data; |
| 2139 | u32 pme_asserted; |
| 2140 | |
| 2141 | while (true) { |
Eliad Peller | 4ed80a8 | 2013-11-07 13:23:21 +0200 | [diff] [blame] | 2142 | /* read pme_ptr if available */ |
| 2143 | if (mvm->d3_test_pme_ptr) { |
| 2144 | pme_asserted = iwl_trans_read_mem32(mvm->trans, |
| 2145 | mvm->d3_test_pme_ptr); |
| 2146 | if (pme_asserted) |
| 2147 | break; |
| 2148 | } |
| 2149 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2150 | if (msleep_interruptible(100)) |
| 2151 | break; |
| 2152 | } |
| 2153 | |
| 2154 | return 0; |
| 2155 | } |
| 2156 | |
| 2157 | static void iwl_mvm_d3_test_disconn_work_iter(void *_data, u8 *mac, |
| 2158 | struct ieee80211_vif *vif) |
| 2159 | { |
Eliad Peller | 78c9df6 | 2013-11-07 14:13:30 +0200 | [diff] [blame] | 2160 | /* skip the one we keep connection on */ |
| 2161 | if (_data == vif) |
| 2162 | return; |
| 2163 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2164 | if (vif->type == NL80211_IFTYPE_STATION) |
| 2165 | ieee80211_connection_loss(vif); |
| 2166 | } |
| 2167 | |
| 2168 | static int iwl_mvm_d3_test_release(struct inode *inode, struct file *file) |
| 2169 | { |
| 2170 | struct iwl_mvm *mvm = inode->i_private; |
| 2171 | int remaining_time = 10; |
| 2172 | |
| 2173 | mvm->d3_test_active = false; |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2174 | |
Luciano Coelho | 31ca09d | 2014-09-22 13:22:51 +0300 | [diff] [blame] | 2175 | rtnl_lock(); |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2176 | __iwl_mvm_resume(mvm, true); |
Luciano Coelho | 31ca09d | 2014-09-22 13:22:51 +0300 | [diff] [blame] | 2177 | rtnl_unlock(); |
Luca Coelho | b728264 | 2015-09-17 23:44:14 +0300 | [diff] [blame] | 2178 | |
| 2179 | mvm->trans->system_pm_mode = IWL_PLAT_PM_MODE_DISABLED; |
| 2180 | |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2181 | iwl_abort_notification_waits(&mvm->notif_wait); |
| 2182 | ieee80211_restart_hw(mvm->hw); |
| 2183 | |
| 2184 | /* wait for restart and disconnect all interfaces */ |
| 2185 | while (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) && |
| 2186 | remaining_time > 0) { |
| 2187 | remaining_time--; |
| 2188 | msleep(1000); |
| 2189 | } |
| 2190 | |
| 2191 | if (remaining_time == 0) |
| 2192 | IWL_ERR(mvm, "Timed out waiting for HW restart to finish!\n"); |
| 2193 | |
| 2194 | ieee80211_iterate_active_interfaces_atomic( |
| 2195 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
Eliad Peller | 78c9df6 | 2013-11-07 14:13:30 +0200 | [diff] [blame] | 2196 | iwl_mvm_d3_test_disconn_work_iter, mvm->keep_vif); |
Johannes Berg | debff61 | 2013-05-14 13:53:45 +0200 | [diff] [blame] | 2197 | |
| 2198 | ieee80211_wake_queues(mvm->hw); |
| 2199 | |
| 2200 | return 0; |
| 2201 | } |
| 2202 | |
| 2203 | const struct file_operations iwl_dbgfs_d3_test_ops = { |
| 2204 | .llseek = no_llseek, |
| 2205 | .open = iwl_mvm_d3_test_open, |
| 2206 | .read = iwl_mvm_d3_test_read, |
| 2207 | .release = iwl_mvm_d3_test_release, |
| 2208 | }; |
| 2209 | #endif |