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 | * |
| 8 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of version 2 of the GNU General Public License as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 22 | * USA |
| 23 | * |
| 24 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 25 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 26 | * |
| 27 | * Contact Information: |
| 28 | * Intel Linux Wireless <ilw@linux.intel.com> |
| 29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 30 | * |
| 31 | * BSD LICENSE |
| 32 | * |
| 33 | * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved. |
| 34 | * All rights reserved. |
| 35 | * |
| 36 | * Redistribution and use in source and binary forms, with or without |
| 37 | * modification, are permitted provided that the following conditions |
| 38 | * are met: |
| 39 | * |
| 40 | * * Redistributions of source code must retain the above copyright |
| 41 | * notice, this list of conditions and the following disclaimer. |
| 42 | * * Redistributions in binary form must reproduce the above copyright |
| 43 | * notice, this list of conditions and the following disclaimer in |
| 44 | * the documentation and/or other materials provided with the |
| 45 | * distribution. |
| 46 | * * Neither the name Intel Corporation nor the names of its |
| 47 | * contributors may be used to endorse or promote products derived |
| 48 | * from this software without specific prior written permission. |
| 49 | * |
| 50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 61 | * |
| 62 | *****************************************************************************/ |
| 63 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 64 | #include <linux/etherdevice.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 65 | #include <linux/ip.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 66 | #include <net/cfg80211.h> |
| 67 | #include <net/ipv6.h> |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 68 | #include <net/tcp.h> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 69 | #include "iwl-modparams.h" |
| 70 | #include "fw-api.h" |
| 71 | #include "mvm.h" |
| 72 | |
| 73 | void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw, |
| 74 | struct ieee80211_vif *vif, |
| 75 | struct cfg80211_gtk_rekey_data *data) |
| 76 | { |
| 77 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 78 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 79 | |
| 80 | if (iwlwifi_mod_params.sw_crypto) |
| 81 | return; |
| 82 | |
| 83 | mutex_lock(&mvm->mutex); |
| 84 | |
| 85 | memcpy(mvmvif->rekey_data.kek, data->kek, NL80211_KEK_LEN); |
| 86 | memcpy(mvmvif->rekey_data.kck, data->kck, NL80211_KCK_LEN); |
| 87 | mvmvif->rekey_data.replay_ctr = |
| 88 | cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr)); |
| 89 | mvmvif->rekey_data.valid = true; |
| 90 | |
| 91 | mutex_unlock(&mvm->mutex); |
| 92 | } |
| 93 | |
| 94 | #if IS_ENABLED(CONFIG_IPV6) |
| 95 | void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw, |
| 96 | struct ieee80211_vif *vif, |
| 97 | struct inet6_dev *idev) |
| 98 | { |
| 99 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 100 | struct inet6_ifaddr *ifa; |
| 101 | int idx = 0; |
| 102 | |
Emmanuel Grumbach | a3777e0 | 2013-02-10 13:07:08 +0200 | [diff] [blame] | 103 | read_lock_bh(&idev->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 104 | list_for_each_entry(ifa, &idev->addr_list, if_list) { |
| 105 | mvmvif->target_ipv6_addrs[idx] = ifa->addr; |
| 106 | idx++; |
| 107 | if (idx >= IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS) |
| 108 | break; |
| 109 | } |
Emmanuel Grumbach | a3777e0 | 2013-02-10 13:07:08 +0200 | [diff] [blame] | 110 | read_unlock_bh(&idev->lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 111 | |
| 112 | mvmvif->num_target_ipv6_addrs = idx; |
| 113 | } |
| 114 | #endif |
| 115 | |
| 116 | void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw, |
| 117 | struct ieee80211_vif *vif, int idx) |
| 118 | { |
| 119 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 120 | |
| 121 | mvmvif->tx_key_idx = idx; |
| 122 | } |
| 123 | |
| 124 | static void iwl_mvm_convert_p1k(u16 *p1k, __le16 *out) |
| 125 | { |
| 126 | int i; |
| 127 | |
| 128 | for (i = 0; i < IWL_P1K_SIZE; i++) |
| 129 | out[i] = cpu_to_le16(p1k[i]); |
| 130 | } |
| 131 | |
| 132 | struct wowlan_key_data { |
| 133 | struct iwl_wowlan_rsc_tsc_params_cmd *rsc_tsc; |
| 134 | struct iwl_wowlan_tkip_params_cmd *tkip; |
| 135 | bool error, use_rsc_tsc, use_tkip; |
| 136 | int gtk_key_idx; |
| 137 | }; |
| 138 | |
| 139 | static void iwl_mvm_wowlan_program_keys(struct ieee80211_hw *hw, |
| 140 | struct ieee80211_vif *vif, |
| 141 | struct ieee80211_sta *sta, |
| 142 | struct ieee80211_key_conf *key, |
| 143 | void *_data) |
| 144 | { |
| 145 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 146 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 147 | struct wowlan_key_data *data = _data; |
| 148 | struct aes_sc *aes_sc, *aes_tx_sc = NULL; |
| 149 | struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL; |
| 150 | struct iwl_p1k_cache *rx_p1ks; |
| 151 | u8 *rx_mic_key; |
| 152 | struct ieee80211_key_seq seq; |
| 153 | u32 cur_rx_iv32 = 0; |
| 154 | u16 p1k[IWL_P1K_SIZE]; |
| 155 | int ret, i; |
| 156 | |
| 157 | mutex_lock(&mvm->mutex); |
| 158 | |
| 159 | switch (key->cipher) { |
| 160 | case WLAN_CIPHER_SUITE_WEP40: |
| 161 | case WLAN_CIPHER_SUITE_WEP104: { /* hack it for now */ |
| 162 | struct { |
| 163 | struct iwl_mvm_wep_key_cmd wep_key_cmd; |
| 164 | struct iwl_mvm_wep_key wep_key; |
| 165 | } __packed wkc = { |
| 166 | .wep_key_cmd.mac_id_n_color = |
| 167 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 168 | mvmvif->color)), |
| 169 | .wep_key_cmd.num_keys = 1, |
| 170 | /* firmware sets STA_KEY_FLG_WEP_13BYTES */ |
| 171 | .wep_key_cmd.decryption_type = STA_KEY_FLG_WEP, |
| 172 | .wep_key.key_index = key->keyidx, |
| 173 | .wep_key.key_size = key->keylen, |
| 174 | }; |
| 175 | |
| 176 | /* |
| 177 | * This will fail -- the key functions don't set support |
| 178 | * pairwise WEP keys. However, that's better than silently |
| 179 | * failing WoWLAN. Or maybe not? |
| 180 | */ |
| 181 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 182 | break; |
| 183 | |
| 184 | memcpy(&wkc.wep_key.key[3], key->key, key->keylen); |
| 185 | if (key->keyidx == mvmvif->tx_key_idx) { |
| 186 | /* TX key must be at offset 0 */ |
| 187 | wkc.wep_key.key_offset = 0; |
| 188 | } else { |
| 189 | /* others start at 1 */ |
| 190 | data->gtk_key_idx++; |
| 191 | wkc.wep_key.key_offset = data->gtk_key_idx; |
| 192 | } |
| 193 | |
| 194 | ret = iwl_mvm_send_cmd_pdu(mvm, WEP_KEY, CMD_SYNC, |
| 195 | sizeof(wkc), &wkc); |
| 196 | data->error = ret != 0; |
| 197 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 198 | mvm->ptk_ivlen = key->iv_len; |
| 199 | mvm->ptk_icvlen = key->icv_len; |
| 200 | mvm->gtk_ivlen = key->iv_len; |
| 201 | mvm->gtk_icvlen = key->icv_len; |
| 202 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 203 | /* don't upload key again */ |
| 204 | goto out_unlock; |
| 205 | } |
| 206 | default: |
| 207 | data->error = true; |
| 208 | goto out_unlock; |
| 209 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 210 | /* |
| 211 | * Ignore CMAC keys -- the WoWLAN firmware doesn't support them |
| 212 | * but we also shouldn't abort suspend due to that. It does have |
| 213 | * support for the IGTK key renewal, but doesn't really use the |
| 214 | * IGTK for anything. This means we could spuriously wake up or |
| 215 | * be deauthenticated, but that was considered acceptable. |
| 216 | */ |
| 217 | goto out_unlock; |
| 218 | case WLAN_CIPHER_SUITE_TKIP: |
| 219 | if (sta) { |
| 220 | tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc; |
| 221 | tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc; |
| 222 | |
| 223 | rx_p1ks = data->tkip->rx_uni; |
| 224 | |
| 225 | ieee80211_get_key_tx_seq(key, &seq); |
| 226 | tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16); |
| 227 | tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32); |
| 228 | |
| 229 | ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k); |
| 230 | iwl_mvm_convert_p1k(p1k, data->tkip->tx.p1k); |
| 231 | |
| 232 | memcpy(data->tkip->mic_keys.tx, |
| 233 | &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY], |
| 234 | IWL_MIC_KEY_SIZE); |
| 235 | |
| 236 | rx_mic_key = data->tkip->mic_keys.rx_unicast; |
| 237 | } else { |
| 238 | tkip_sc = |
| 239 | data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc; |
| 240 | rx_p1ks = data->tkip->rx_multi; |
| 241 | rx_mic_key = data->tkip->mic_keys.rx_mcast; |
| 242 | } |
| 243 | |
| 244 | /* |
| 245 | * For non-QoS this relies on the fact that both the uCode and |
| 246 | * mac80211 use TID 0 (as they need to to avoid replay attacks) |
| 247 | * for checking the IV in the frames. |
| 248 | */ |
| 249 | for (i = 0; i < IWL_NUM_RSC; i++) { |
| 250 | ieee80211_get_key_rx_seq(key, i, &seq); |
| 251 | tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16); |
| 252 | tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32); |
| 253 | /* wrapping isn't allowed, AP must rekey */ |
| 254 | if (seq.tkip.iv32 > cur_rx_iv32) |
| 255 | cur_rx_iv32 = seq.tkip.iv32; |
| 256 | } |
| 257 | |
| 258 | ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid, |
| 259 | cur_rx_iv32, p1k); |
| 260 | iwl_mvm_convert_p1k(p1k, rx_p1ks[0].p1k); |
| 261 | ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid, |
| 262 | cur_rx_iv32 + 1, p1k); |
| 263 | iwl_mvm_convert_p1k(p1k, rx_p1ks[1].p1k); |
| 264 | |
| 265 | memcpy(rx_mic_key, |
| 266 | &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY], |
| 267 | IWL_MIC_KEY_SIZE); |
| 268 | |
| 269 | data->use_tkip = true; |
| 270 | data->use_rsc_tsc = true; |
| 271 | break; |
| 272 | case WLAN_CIPHER_SUITE_CCMP: |
| 273 | if (sta) { |
| 274 | u8 *pn = seq.ccmp.pn; |
| 275 | |
| 276 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc; |
| 277 | aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc; |
| 278 | |
| 279 | ieee80211_get_key_tx_seq(key, &seq); |
| 280 | aes_tx_sc->pn = cpu_to_le64((u64)pn[5] | |
| 281 | ((u64)pn[4] << 8) | |
| 282 | ((u64)pn[3] << 16) | |
| 283 | ((u64)pn[2] << 24) | |
| 284 | ((u64)pn[1] << 32) | |
| 285 | ((u64)pn[0] << 40)); |
| 286 | } else { |
| 287 | aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc; |
| 288 | } |
| 289 | |
| 290 | /* |
| 291 | * For non-QoS this relies on the fact that both the uCode and |
| 292 | * mac80211 use TID 0 for checking the IV in the frames. |
| 293 | */ |
| 294 | for (i = 0; i < IWL_NUM_RSC; i++) { |
| 295 | u8 *pn = seq.ccmp.pn; |
| 296 | |
| 297 | ieee80211_get_key_rx_seq(key, i, &seq); |
| 298 | aes_sc->pn = cpu_to_le64((u64)pn[5] | |
| 299 | ((u64)pn[4] << 8) | |
| 300 | ((u64)pn[3] << 16) | |
| 301 | ((u64)pn[2] << 24) | |
| 302 | ((u64)pn[1] << 32) | |
| 303 | ((u64)pn[0] << 40)); |
| 304 | } |
| 305 | data->use_rsc_tsc = true; |
| 306 | break; |
| 307 | } |
| 308 | |
| 309 | /* |
| 310 | * The D3 firmware hardcodes the key offset 0 as the key it uses |
| 311 | * to transmit packets to the AP, i.e. the PTK. |
| 312 | */ |
| 313 | if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { |
| 314 | key->hw_key_idx = 0; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 315 | mvm->ptk_ivlen = key->iv_len; |
| 316 | mvm->ptk_icvlen = key->icv_len; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 317 | } else { |
| 318 | data->gtk_key_idx++; |
| 319 | key->hw_key_idx = data->gtk_key_idx; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 320 | mvm->gtk_ivlen = key->iv_len; |
| 321 | mvm->gtk_icvlen = key->icv_len; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, true); |
| 325 | data->error = ret != 0; |
| 326 | out_unlock: |
| 327 | mutex_unlock(&mvm->mutex); |
| 328 | } |
| 329 | |
| 330 | static int iwl_mvm_send_patterns(struct iwl_mvm *mvm, |
| 331 | struct cfg80211_wowlan *wowlan) |
| 332 | { |
| 333 | struct iwl_wowlan_patterns_cmd *pattern_cmd; |
| 334 | struct iwl_host_cmd cmd = { |
| 335 | .id = WOWLAN_PATTERNS, |
| 336 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
| 337 | .flags = CMD_SYNC, |
| 338 | }; |
| 339 | int i, err; |
| 340 | |
| 341 | if (!wowlan->n_patterns) |
| 342 | return 0; |
| 343 | |
| 344 | cmd.len[0] = sizeof(*pattern_cmd) + |
| 345 | wowlan->n_patterns * sizeof(struct iwl_wowlan_pattern); |
| 346 | |
| 347 | pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL); |
| 348 | if (!pattern_cmd) |
| 349 | return -ENOMEM; |
| 350 | |
| 351 | pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns); |
| 352 | |
| 353 | for (i = 0; i < wowlan->n_patterns; i++) { |
| 354 | int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8); |
| 355 | |
| 356 | memcpy(&pattern_cmd->patterns[i].mask, |
| 357 | wowlan->patterns[i].mask, mask_len); |
| 358 | memcpy(&pattern_cmd->patterns[i].pattern, |
| 359 | wowlan->patterns[i].pattern, |
| 360 | wowlan->patterns[i].pattern_len); |
| 361 | pattern_cmd->patterns[i].mask_size = mask_len; |
| 362 | pattern_cmd->patterns[i].pattern_size = |
| 363 | wowlan->patterns[i].pattern_len; |
| 364 | } |
| 365 | |
| 366 | cmd.data[0] = pattern_cmd; |
| 367 | err = iwl_mvm_send_cmd(mvm, &cmd); |
| 368 | kfree(pattern_cmd); |
| 369 | return err; |
| 370 | } |
| 371 | |
| 372 | static int iwl_mvm_send_proto_offload(struct iwl_mvm *mvm, |
| 373 | struct ieee80211_vif *vif) |
| 374 | { |
| 375 | struct iwl_proto_offload_cmd cmd = {}; |
| 376 | #if IS_ENABLED(CONFIG_IPV6) |
| 377 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 378 | int i; |
| 379 | |
| 380 | if (mvmvif->num_target_ipv6_addrs) { |
| 381 | cmd.enabled |= cpu_to_le32(IWL_D3_PROTO_OFFLOAD_NS); |
| 382 | memcpy(cmd.ndp_mac_addr, vif->addr, ETH_ALEN); |
| 383 | } |
| 384 | |
| 385 | BUILD_BUG_ON(sizeof(cmd.target_ipv6_addr[i]) != |
| 386 | sizeof(mvmvif->target_ipv6_addrs[i])); |
| 387 | |
| 388 | for (i = 0; i < mvmvif->num_target_ipv6_addrs; i++) |
| 389 | memcpy(cmd.target_ipv6_addr[i], |
| 390 | &mvmvif->target_ipv6_addrs[i], |
| 391 | sizeof(cmd.target_ipv6_addr[i])); |
| 392 | #endif |
| 393 | |
| 394 | if (vif->bss_conf.arp_addr_cnt) { |
| 395 | cmd.enabled |= cpu_to_le32(IWL_D3_PROTO_OFFLOAD_ARP); |
| 396 | cmd.host_ipv4_addr = vif->bss_conf.arp_addr_list[0]; |
| 397 | memcpy(cmd.arp_mac_addr, vif->addr, ETH_ALEN); |
| 398 | } |
| 399 | |
| 400 | if (!cmd.enabled) |
| 401 | return 0; |
| 402 | |
| 403 | return iwl_mvm_send_cmd_pdu(mvm, PROT_OFFLOAD_CONFIG_CMD, CMD_SYNC, |
| 404 | sizeof(cmd), &cmd); |
| 405 | } |
| 406 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 407 | enum iwl_mvm_tcp_packet_type { |
| 408 | MVM_TCP_TX_SYN, |
| 409 | MVM_TCP_RX_SYNACK, |
| 410 | MVM_TCP_TX_DATA, |
| 411 | MVM_TCP_RX_ACK, |
| 412 | MVM_TCP_RX_WAKE, |
| 413 | MVM_TCP_TX_FIN, |
| 414 | }; |
| 415 | |
| 416 | static __le16 pseudo_hdr_check(int len, __be32 saddr, __be32 daddr) |
| 417 | { |
| 418 | __sum16 check = tcp_v4_check(len, saddr, daddr, 0); |
| 419 | return cpu_to_le16(be16_to_cpu((__force __be16)check)); |
| 420 | } |
| 421 | |
| 422 | static void iwl_mvm_build_tcp_packet(struct iwl_mvm *mvm, |
| 423 | struct ieee80211_vif *vif, |
| 424 | struct cfg80211_wowlan_tcp *tcp, |
| 425 | void *_pkt, u8 *mask, |
| 426 | __le16 *pseudo_hdr_csum, |
| 427 | enum iwl_mvm_tcp_packet_type ptype) |
| 428 | { |
| 429 | struct { |
| 430 | struct ethhdr eth; |
| 431 | struct iphdr ip; |
| 432 | struct tcphdr tcp; |
| 433 | u8 data[]; |
| 434 | } __packed *pkt = _pkt; |
| 435 | u16 ip_tot_len = sizeof(struct iphdr) + sizeof(struct tcphdr); |
| 436 | int i; |
| 437 | |
| 438 | pkt->eth.h_proto = cpu_to_be16(ETH_P_IP), |
| 439 | pkt->ip.version = 4; |
| 440 | pkt->ip.ihl = 5; |
| 441 | pkt->ip.protocol = IPPROTO_TCP; |
| 442 | |
| 443 | switch (ptype) { |
| 444 | case MVM_TCP_TX_SYN: |
| 445 | case MVM_TCP_TX_DATA: |
| 446 | case MVM_TCP_TX_FIN: |
| 447 | memcpy(pkt->eth.h_dest, tcp->dst_mac, ETH_ALEN); |
| 448 | memcpy(pkt->eth.h_source, vif->addr, ETH_ALEN); |
| 449 | pkt->ip.ttl = 128; |
| 450 | pkt->ip.saddr = tcp->src; |
| 451 | pkt->ip.daddr = tcp->dst; |
| 452 | pkt->tcp.source = cpu_to_be16(tcp->src_port); |
| 453 | pkt->tcp.dest = cpu_to_be16(tcp->dst_port); |
| 454 | /* overwritten for TX SYN later */ |
| 455 | pkt->tcp.doff = sizeof(struct tcphdr) / 4; |
| 456 | pkt->tcp.window = cpu_to_be16(65000); |
| 457 | break; |
| 458 | case MVM_TCP_RX_SYNACK: |
| 459 | case MVM_TCP_RX_ACK: |
| 460 | case MVM_TCP_RX_WAKE: |
| 461 | memcpy(pkt->eth.h_dest, vif->addr, ETH_ALEN); |
| 462 | memcpy(pkt->eth.h_source, tcp->dst_mac, ETH_ALEN); |
| 463 | pkt->ip.saddr = tcp->dst; |
| 464 | pkt->ip.daddr = tcp->src; |
| 465 | pkt->tcp.source = cpu_to_be16(tcp->dst_port); |
| 466 | pkt->tcp.dest = cpu_to_be16(tcp->src_port); |
| 467 | break; |
| 468 | default: |
| 469 | WARN_ON(1); |
| 470 | return; |
| 471 | } |
| 472 | |
| 473 | switch (ptype) { |
| 474 | case MVM_TCP_TX_SYN: |
| 475 | /* firmware assumes 8 option bytes - 8 NOPs for now */ |
| 476 | memset(pkt->data, 0x01, 8); |
| 477 | ip_tot_len += 8; |
| 478 | pkt->tcp.doff = (sizeof(struct tcphdr) + 8) / 4; |
| 479 | pkt->tcp.syn = 1; |
| 480 | break; |
| 481 | case MVM_TCP_TX_DATA: |
| 482 | ip_tot_len += tcp->payload_len; |
| 483 | memcpy(pkt->data, tcp->payload, tcp->payload_len); |
| 484 | pkt->tcp.psh = 1; |
| 485 | pkt->tcp.ack = 1; |
| 486 | break; |
| 487 | case MVM_TCP_TX_FIN: |
| 488 | pkt->tcp.fin = 1; |
| 489 | pkt->tcp.ack = 1; |
| 490 | break; |
| 491 | case MVM_TCP_RX_SYNACK: |
| 492 | pkt->tcp.syn = 1; |
| 493 | pkt->tcp.ack = 1; |
| 494 | break; |
| 495 | case MVM_TCP_RX_ACK: |
| 496 | pkt->tcp.ack = 1; |
| 497 | break; |
| 498 | case MVM_TCP_RX_WAKE: |
| 499 | ip_tot_len += tcp->wake_len; |
| 500 | pkt->tcp.psh = 1; |
| 501 | pkt->tcp.ack = 1; |
| 502 | memcpy(pkt->data, tcp->wake_data, tcp->wake_len); |
| 503 | break; |
| 504 | } |
| 505 | |
| 506 | switch (ptype) { |
| 507 | case MVM_TCP_TX_SYN: |
| 508 | case MVM_TCP_TX_DATA: |
| 509 | case MVM_TCP_TX_FIN: |
| 510 | pkt->ip.tot_len = cpu_to_be16(ip_tot_len); |
| 511 | pkt->ip.check = ip_fast_csum(&pkt->ip, pkt->ip.ihl); |
| 512 | break; |
| 513 | case MVM_TCP_RX_WAKE: |
| 514 | for (i = 0; i < DIV_ROUND_UP(tcp->wake_len, 8); i++) { |
| 515 | u8 tmp = tcp->wake_mask[i]; |
| 516 | mask[i + 6] |= tmp << 6; |
| 517 | if (i + 1 < DIV_ROUND_UP(tcp->wake_len, 8)) |
| 518 | mask[i + 7] = tmp >> 2; |
| 519 | } |
| 520 | /* fall through for ethernet/IP/TCP headers mask */ |
| 521 | case MVM_TCP_RX_SYNACK: |
| 522 | case MVM_TCP_RX_ACK: |
| 523 | mask[0] = 0xff; /* match ethernet */ |
| 524 | /* |
| 525 | * match ethernet, ip.version, ip.ihl |
| 526 | * the ip.ihl half byte is really masked out by firmware |
| 527 | */ |
| 528 | mask[1] = 0x7f; |
| 529 | mask[2] = 0x80; /* match ip.protocol */ |
| 530 | mask[3] = 0xfc; /* match ip.saddr, ip.daddr */ |
| 531 | mask[4] = 0x3f; /* match ip.daddr, tcp.source, tcp.dest */ |
| 532 | mask[5] = 0x80; /* match tcp flags */ |
| 533 | /* leave rest (0 or set for MVM_TCP_RX_WAKE) */ |
| 534 | break; |
| 535 | }; |
| 536 | |
| 537 | *pseudo_hdr_csum = pseudo_hdr_check(ip_tot_len - sizeof(struct iphdr), |
| 538 | pkt->ip.saddr, pkt->ip.daddr); |
| 539 | } |
| 540 | |
| 541 | static int iwl_mvm_send_remote_wake_cfg(struct iwl_mvm *mvm, |
| 542 | struct ieee80211_vif *vif, |
| 543 | struct cfg80211_wowlan_tcp *tcp) |
| 544 | { |
| 545 | struct iwl_wowlan_remote_wake_config *cfg; |
| 546 | struct iwl_host_cmd cmd = { |
| 547 | .id = REMOTE_WAKE_CONFIG_CMD, |
| 548 | .len = { sizeof(*cfg), }, |
| 549 | .dataflags = { IWL_HCMD_DFL_NOCOPY, }, |
| 550 | .flags = CMD_SYNC, |
| 551 | }; |
| 552 | int ret; |
| 553 | |
| 554 | if (!tcp) |
| 555 | return 0; |
| 556 | |
| 557 | cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); |
| 558 | if (!cfg) |
| 559 | return -ENOMEM; |
| 560 | cmd.data[0] = cfg; |
| 561 | |
| 562 | cfg->max_syn_retries = 10; |
| 563 | cfg->max_data_retries = 10; |
| 564 | cfg->tcp_syn_ack_timeout = 1; /* seconds */ |
| 565 | cfg->tcp_ack_timeout = 1; /* seconds */ |
| 566 | |
| 567 | /* SYN (TX) */ |
| 568 | iwl_mvm_build_tcp_packet( |
| 569 | mvm, vif, tcp, cfg->syn_tx.data, NULL, |
| 570 | &cfg->syn_tx.info.tcp_pseudo_header_checksum, |
| 571 | MVM_TCP_TX_SYN); |
| 572 | cfg->syn_tx.info.tcp_payload_length = 0; |
| 573 | |
| 574 | /* SYN/ACK (RX) */ |
| 575 | iwl_mvm_build_tcp_packet( |
| 576 | mvm, vif, tcp, cfg->synack_rx.data, cfg->synack_rx.rx_mask, |
| 577 | &cfg->synack_rx.info.tcp_pseudo_header_checksum, |
| 578 | MVM_TCP_RX_SYNACK); |
| 579 | cfg->synack_rx.info.tcp_payload_length = 0; |
| 580 | |
| 581 | /* KEEPALIVE/ACK (TX) */ |
| 582 | iwl_mvm_build_tcp_packet( |
| 583 | mvm, vif, tcp, cfg->keepalive_tx.data, NULL, |
| 584 | &cfg->keepalive_tx.info.tcp_pseudo_header_checksum, |
| 585 | MVM_TCP_TX_DATA); |
| 586 | cfg->keepalive_tx.info.tcp_payload_length = |
| 587 | cpu_to_le16(tcp->payload_len); |
| 588 | cfg->sequence_number_offset = tcp->payload_seq.offset; |
| 589 | /* length must be 0..4, the field is little endian */ |
| 590 | cfg->sequence_number_length = tcp->payload_seq.len; |
| 591 | cfg->initial_sequence_number = cpu_to_le32(tcp->payload_seq.start); |
| 592 | cfg->keepalive_interval = cpu_to_le16(tcp->data_interval); |
| 593 | if (tcp->payload_tok.len) { |
| 594 | cfg->token_offset = tcp->payload_tok.offset; |
| 595 | cfg->token_length = tcp->payload_tok.len; |
| 596 | cfg->num_tokens = |
| 597 | cpu_to_le16(tcp->tokens_size % tcp->payload_tok.len); |
| 598 | memcpy(cfg->tokens, tcp->payload_tok.token_stream, |
| 599 | tcp->tokens_size); |
| 600 | } else { |
| 601 | /* set tokens to max value to almost never run out */ |
| 602 | cfg->num_tokens = cpu_to_le16(65535); |
| 603 | } |
| 604 | |
| 605 | /* ACK (RX) */ |
| 606 | iwl_mvm_build_tcp_packet( |
| 607 | mvm, vif, tcp, cfg->keepalive_ack_rx.data, |
| 608 | cfg->keepalive_ack_rx.rx_mask, |
| 609 | &cfg->keepalive_ack_rx.info.tcp_pseudo_header_checksum, |
| 610 | MVM_TCP_RX_ACK); |
| 611 | cfg->keepalive_ack_rx.info.tcp_payload_length = 0; |
| 612 | |
| 613 | /* WAKEUP (RX) */ |
| 614 | iwl_mvm_build_tcp_packet( |
| 615 | mvm, vif, tcp, cfg->wake_rx.data, cfg->wake_rx.rx_mask, |
| 616 | &cfg->wake_rx.info.tcp_pseudo_header_checksum, |
| 617 | MVM_TCP_RX_WAKE); |
| 618 | cfg->wake_rx.info.tcp_payload_length = |
| 619 | cpu_to_le16(tcp->wake_len); |
| 620 | |
| 621 | /* FIN */ |
| 622 | iwl_mvm_build_tcp_packet( |
| 623 | mvm, vif, tcp, cfg->fin_tx.data, NULL, |
| 624 | &cfg->fin_tx.info.tcp_pseudo_header_checksum, |
| 625 | MVM_TCP_TX_FIN); |
| 626 | cfg->fin_tx.info.tcp_payload_length = 0; |
| 627 | |
| 628 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 629 | kfree(cfg); |
| 630 | |
| 631 | return ret; |
| 632 | } |
| 633 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 634 | struct iwl_d3_iter_data { |
| 635 | struct iwl_mvm *mvm; |
| 636 | struct ieee80211_vif *vif; |
| 637 | bool error; |
| 638 | }; |
| 639 | |
| 640 | static void iwl_mvm_d3_iface_iterator(void *_data, u8 *mac, |
| 641 | struct ieee80211_vif *vif) |
| 642 | { |
| 643 | struct iwl_d3_iter_data *data = _data; |
| 644 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 645 | |
| 646 | if (vif->type != NL80211_IFTYPE_STATION || vif->p2p) |
| 647 | return; |
| 648 | |
| 649 | if (mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT) |
| 650 | return; |
| 651 | |
| 652 | if (data->vif) { |
| 653 | IWL_ERR(data->mvm, "More than one managed interface active!\n"); |
| 654 | data->error = true; |
| 655 | return; |
| 656 | } |
| 657 | |
| 658 | data->vif = vif; |
| 659 | } |
| 660 | |
| 661 | static int iwl_mvm_d3_reprogram(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 662 | struct ieee80211_sta *ap_sta) |
| 663 | { |
| 664 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 665 | struct ieee80211_chanctx_conf *ctx; |
| 666 | u8 chains_static, chains_dynamic; |
| 667 | struct cfg80211_chan_def chandef; |
| 668 | int ret, i; |
| 669 | struct iwl_binding_cmd binding_cmd = {}; |
| 670 | struct iwl_time_quota_cmd quota_cmd = {}; |
| 671 | u32 status; |
| 672 | |
| 673 | /* add back the PHY */ |
| 674 | if (WARN_ON(!mvmvif->phy_ctxt)) |
| 675 | return -EINVAL; |
| 676 | |
| 677 | rcu_read_lock(); |
| 678 | ctx = rcu_dereference(vif->chanctx_conf); |
| 679 | if (WARN_ON(!ctx)) { |
| 680 | rcu_read_unlock(); |
| 681 | return -EINVAL; |
| 682 | } |
| 683 | chandef = ctx->def; |
| 684 | chains_static = ctx->rx_chains_static; |
| 685 | chains_dynamic = ctx->rx_chains_dynamic; |
| 686 | rcu_read_unlock(); |
| 687 | |
| 688 | ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->phy_ctxt, &chandef, |
| 689 | chains_static, chains_dynamic); |
| 690 | if (ret) |
| 691 | return ret; |
| 692 | |
| 693 | /* add back the MAC */ |
| 694 | mvmvif->uploaded = false; |
| 695 | |
| 696 | if (WARN_ON(!vif->bss_conf.assoc)) |
| 697 | return -EINVAL; |
| 698 | /* hack */ |
| 699 | vif->bss_conf.assoc = false; |
| 700 | ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 701 | vif->bss_conf.assoc = true; |
| 702 | if (ret) |
| 703 | return ret; |
| 704 | |
| 705 | /* add back binding - XXX refactor? */ |
| 706 | binding_cmd.id_and_color = |
| 707 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id, |
| 708 | mvmvif->phy_ctxt->color)); |
| 709 | binding_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD); |
| 710 | binding_cmd.phy = |
| 711 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id, |
| 712 | mvmvif->phy_ctxt->color)); |
| 713 | binding_cmd.macs[0] = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 714 | mvmvif->color)); |
| 715 | for (i = 1; i < MAX_MACS_IN_BINDING; i++) |
| 716 | binding_cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID); |
| 717 | |
| 718 | status = 0; |
| 719 | ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD, |
| 720 | sizeof(binding_cmd), &binding_cmd, |
| 721 | &status); |
| 722 | if (ret) { |
| 723 | IWL_ERR(mvm, "Failed to add binding: %d\n", ret); |
| 724 | return ret; |
| 725 | } |
| 726 | |
| 727 | if (status) { |
| 728 | IWL_ERR(mvm, "Binding command failed: %u\n", status); |
| 729 | return -EIO; |
| 730 | } |
| 731 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 732 | ret = iwl_mvm_sta_send_to_fw(mvm, ap_sta, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 733 | if (ret) |
| 734 | return ret; |
| 735 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], ap_sta); |
| 736 | |
| 737 | ret = iwl_mvm_mac_ctxt_changed(mvm, vif); |
| 738 | if (ret) |
| 739 | return ret; |
| 740 | |
| 741 | /* and some quota */ |
| 742 | quota_cmd.quotas[0].id_and_color = |
| 743 | cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->phy_ctxt->id, |
| 744 | mvmvif->phy_ctxt->color)); |
| 745 | quota_cmd.quotas[0].quota = cpu_to_le32(100); |
| 746 | quota_cmd.quotas[0].max_duration = cpu_to_le32(1000); |
| 747 | |
| 748 | for (i = 1; i < MAX_BINDINGS; i++) |
| 749 | quota_cmd.quotas[i].id_and_color = cpu_to_le32(FW_CTXT_INVALID); |
| 750 | |
| 751 | ret = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, CMD_SYNC, |
| 752 | sizeof(quota_cmd), "a_cmd); |
| 753 | if (ret) |
| 754 | IWL_ERR(mvm, "Failed to send quota: %d\n", ret); |
| 755 | |
| 756 | return 0; |
| 757 | } |
| 758 | |
| 759 | int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
| 760 | { |
| 761 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 762 | struct iwl_d3_iter_data suspend_iter_data = { |
| 763 | .mvm = mvm, |
| 764 | }; |
| 765 | struct ieee80211_vif *vif; |
| 766 | struct iwl_mvm_vif *mvmvif; |
| 767 | struct ieee80211_sta *ap_sta; |
| 768 | struct iwl_mvm_sta *mvm_ap_sta; |
| 769 | struct iwl_wowlan_config_cmd wowlan_config_cmd = {}; |
| 770 | struct iwl_wowlan_kek_kck_material_cmd kek_kck_cmd = {}; |
| 771 | struct iwl_wowlan_tkip_params_cmd tkip_cmd = {}; |
Johannes Berg | c920487 | 2013-02-15 11:00:58 +0100 | [diff] [blame] | 772 | struct iwl_d3_manager_config d3_cfg_cmd = { |
| 773 | /* |
| 774 | * Program the minimum sleep time to 10 seconds, as many |
| 775 | * platforms have issues processing a wakeup signal while |
| 776 | * still being in the process of suspending. |
| 777 | */ |
| 778 | .min_sleep_time = cpu_to_le32(10 * 1000 * 1000), |
| 779 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 780 | struct wowlan_key_data key_data = { |
| 781 | .use_rsc_tsc = false, |
| 782 | .tkip = &tkip_cmd, |
| 783 | .use_tkip = false, |
| 784 | }; |
| 785 | int ret, i; |
| 786 | u16 seq; |
| 787 | u8 old_aux_sta_id, old_ap_sta_id = IWL_MVM_STATION_COUNT; |
| 788 | |
| 789 | if (WARN_ON(!wowlan)) |
| 790 | return -EINVAL; |
| 791 | |
| 792 | key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL); |
| 793 | if (!key_data.rsc_tsc) |
| 794 | return -ENOMEM; |
| 795 | |
| 796 | mutex_lock(&mvm->mutex); |
| 797 | |
| 798 | old_aux_sta_id = mvm->aux_sta.sta_id; |
| 799 | |
| 800 | /* see if there's only a single BSS vif and it's associated */ |
| 801 | ieee80211_iterate_active_interfaces_atomic( |
| 802 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 803 | iwl_mvm_d3_iface_iterator, &suspend_iter_data); |
| 804 | |
| 805 | if (suspend_iter_data.error || !suspend_iter_data.vif) { |
| 806 | ret = 1; |
| 807 | goto out_noreset; |
| 808 | } |
| 809 | |
| 810 | vif = suspend_iter_data.vif; |
| 811 | mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 812 | |
| 813 | ap_sta = rcu_dereference_protected( |
| 814 | mvm->fw_id_to_mac_id[mvmvif->ap_sta_id], |
| 815 | lockdep_is_held(&mvm->mutex)); |
| 816 | if (IS_ERR_OR_NULL(ap_sta)) { |
| 817 | ret = -EINVAL; |
| 818 | goto out_noreset; |
| 819 | } |
| 820 | |
| 821 | mvm_ap_sta = (struct iwl_mvm_sta *)ap_sta->drv_priv; |
| 822 | |
| 823 | /* |
| 824 | * The D3 firmware still hardcodes the AP station ID for the |
| 825 | * BSS we're associated with as 0. Store the real STA ID here |
| 826 | * and assign 0. When we leave this function, we'll restore |
| 827 | * the original value for the resume code. |
| 828 | */ |
| 829 | old_ap_sta_id = mvm_ap_sta->sta_id; |
| 830 | mvm_ap_sta->sta_id = 0; |
| 831 | mvmvif->ap_sta_id = 0; |
| 832 | |
| 833 | /* TODO: wowlan_config_cmd.wowlan_ba_teardown_tids */ |
| 834 | |
| 835 | wowlan_config_cmd.is_11n_connection = ap_sta->ht_cap.ht_supported; |
| 836 | |
| 837 | /* |
| 838 | * We know the last used seqno, and the uCode expects to know that |
| 839 | * one, it will increment before TX. |
| 840 | */ |
| 841 | seq = mvm_ap_sta->last_seq_ctl & IEEE80211_SCTL_SEQ; |
| 842 | wowlan_config_cmd.non_qos_seq = cpu_to_le16(seq); |
| 843 | |
| 844 | /* |
| 845 | * For QoS counters, we store the one to use next, so subtract 0x10 |
| 846 | * since the uCode will add 0x10 *before* using the value while we |
| 847 | * increment after using the value (i.e. store the next value to use). |
| 848 | */ |
| 849 | for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
| 850 | seq = mvm_ap_sta->tid_data[i].seq_number; |
| 851 | seq -= 0x10; |
| 852 | wowlan_config_cmd.qos_seq[i] = cpu_to_le16(seq); |
| 853 | } |
| 854 | |
| 855 | if (wowlan->disconnect) |
| 856 | wowlan_config_cmd.wakeup_filter |= |
| 857 | cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS | |
| 858 | IWL_WOWLAN_WAKEUP_LINK_CHANGE); |
| 859 | if (wowlan->magic_pkt) |
| 860 | wowlan_config_cmd.wakeup_filter |= |
| 861 | cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET); |
| 862 | if (wowlan->gtk_rekey_failure) |
| 863 | wowlan_config_cmd.wakeup_filter |= |
| 864 | cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL); |
| 865 | if (wowlan->eap_identity_req) |
| 866 | wowlan_config_cmd.wakeup_filter |= |
| 867 | cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ); |
| 868 | if (wowlan->four_way_handshake) |
| 869 | wowlan_config_cmd.wakeup_filter |= |
| 870 | cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE); |
| 871 | if (wowlan->n_patterns) |
| 872 | wowlan_config_cmd.wakeup_filter |= |
| 873 | cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH); |
| 874 | |
| 875 | if (wowlan->rfkill_release) |
Johannes Berg | 6039f3e | 2013-03-20 10:40:05 +0100 | [diff] [blame] | 876 | wowlan_config_cmd.wakeup_filter |= |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 877 | cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT); |
| 878 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 879 | if (wowlan->tcp) { |
| 880 | /* |
Johannes Berg | 6039f3e | 2013-03-20 10:40:05 +0100 | [diff] [blame] | 881 | * Set the "link change" (really "link lost") flag as well |
| 882 | * since that implies losing the TCP connection. |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 883 | */ |
| 884 | wowlan_config_cmd.wakeup_filter |= |
| 885 | cpu_to_le32(IWL_WOWLAN_WAKEUP_REMOTE_LINK_LOSS | |
| 886 | IWL_WOWLAN_WAKEUP_REMOTE_SIGNATURE_TABLE | |
| 887 | IWL_WOWLAN_WAKEUP_REMOTE_WAKEUP_PACKET | |
| 888 | IWL_WOWLAN_WAKEUP_LINK_CHANGE); |
| 889 | } |
| 890 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 891 | iwl_mvm_cancel_scan(mvm); |
| 892 | |
| 893 | iwl_trans_stop_device(mvm->trans); |
| 894 | |
| 895 | /* |
| 896 | * Set the HW restart bit -- this is mostly true as we're |
| 897 | * going to load new firmware and reprogram that, though |
| 898 | * the reprogramming is going to be manual to avoid adding |
| 899 | * all the MACs that aren't support. |
| 900 | * We don't have to clear up everything though because the |
| 901 | * reprogramming is manual. When we resume, we'll actually |
| 902 | * go through a proper restart sequence again to switch |
| 903 | * back to the runtime firmware image. |
| 904 | */ |
| 905 | set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 906 | |
| 907 | /* We reprogram keys and shouldn't allocate new key indices */ |
| 908 | memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
| 909 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 910 | mvm->ptk_ivlen = 0; |
| 911 | mvm->ptk_icvlen = 0; |
| 912 | mvm->ptk_ivlen = 0; |
| 913 | mvm->ptk_icvlen = 0; |
| 914 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 915 | /* |
| 916 | * The D3 firmware still hardcodes the AP station ID for the |
| 917 | * BSS we're associated with as 0. As a result, we have to move |
| 918 | * the auxiliary station to ID 1 so the ID 0 remains free for |
| 919 | * the AP station for later. |
| 920 | * We set the sta_id to 1 here, and reset it to its previous |
| 921 | * value (that we stored above) later. |
| 922 | */ |
| 923 | mvm->aux_sta.sta_id = 1; |
| 924 | |
| 925 | ret = iwl_mvm_load_d3_fw(mvm); |
| 926 | if (ret) |
| 927 | goto out; |
| 928 | |
| 929 | ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta); |
| 930 | if (ret) |
| 931 | goto out; |
| 932 | |
| 933 | if (!iwlwifi_mod_params.sw_crypto) { |
| 934 | /* |
| 935 | * This needs to be unlocked due to lock ordering |
| 936 | * constraints. Since we're in the suspend path |
| 937 | * that isn't really a problem though. |
| 938 | */ |
| 939 | mutex_unlock(&mvm->mutex); |
| 940 | ieee80211_iter_keys(mvm->hw, vif, |
| 941 | iwl_mvm_wowlan_program_keys, |
| 942 | &key_data); |
| 943 | mutex_lock(&mvm->mutex); |
| 944 | if (key_data.error) { |
| 945 | ret = -EIO; |
| 946 | goto out; |
| 947 | } |
| 948 | |
| 949 | if (key_data.use_rsc_tsc) { |
| 950 | struct iwl_host_cmd rsc_tsc_cmd = { |
| 951 | .id = WOWLAN_TSC_RSC_PARAM, |
| 952 | .flags = CMD_SYNC, |
| 953 | .data[0] = key_data.rsc_tsc, |
| 954 | .dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
| 955 | .len[0] = sizeof(*key_data.rsc_tsc), |
| 956 | }; |
| 957 | |
| 958 | ret = iwl_mvm_send_cmd(mvm, &rsc_tsc_cmd); |
| 959 | if (ret) |
| 960 | goto out; |
| 961 | } |
| 962 | |
| 963 | if (key_data.use_tkip) { |
| 964 | ret = iwl_mvm_send_cmd_pdu(mvm, |
| 965 | WOWLAN_TKIP_PARAM, |
| 966 | CMD_SYNC, sizeof(tkip_cmd), |
| 967 | &tkip_cmd); |
| 968 | if (ret) |
| 969 | goto out; |
| 970 | } |
| 971 | |
| 972 | if (mvmvif->rekey_data.valid) { |
| 973 | memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd)); |
| 974 | memcpy(kek_kck_cmd.kck, mvmvif->rekey_data.kck, |
| 975 | NL80211_KCK_LEN); |
| 976 | kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN); |
| 977 | memcpy(kek_kck_cmd.kek, mvmvif->rekey_data.kek, |
| 978 | NL80211_KEK_LEN); |
| 979 | kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN); |
| 980 | kek_kck_cmd.replay_ctr = mvmvif->rekey_data.replay_ctr; |
| 981 | |
| 982 | ret = iwl_mvm_send_cmd_pdu(mvm, |
| 983 | WOWLAN_KEK_KCK_MATERIAL, |
| 984 | CMD_SYNC, |
| 985 | sizeof(kek_kck_cmd), |
| 986 | &kek_kck_cmd); |
| 987 | if (ret) |
| 988 | goto out; |
| 989 | } |
| 990 | } |
| 991 | |
| 992 | ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, |
| 993 | CMD_SYNC, sizeof(wowlan_config_cmd), |
| 994 | &wowlan_config_cmd); |
| 995 | if (ret) |
| 996 | goto out; |
| 997 | |
| 998 | ret = iwl_mvm_send_patterns(mvm, wowlan); |
| 999 | if (ret) |
| 1000 | goto out; |
| 1001 | |
| 1002 | ret = iwl_mvm_send_proto_offload(mvm, vif); |
| 1003 | if (ret) |
| 1004 | goto out; |
| 1005 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 1006 | ret = iwl_mvm_send_remote_wake_cfg(mvm, vif, wowlan->tcp); |
| 1007 | if (ret) |
| 1008 | goto out; |
| 1009 | |
Alexander Bondar | ee1e842 | 2013-04-23 13:52:10 +0300 | [diff] [blame] | 1010 | ret = iwl_mvm_power_update_mode(mvm, vif); |
| 1011 | if (ret) |
| 1012 | goto out; |
| 1013 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1014 | /* must be last -- this switches firmware state */ |
| 1015 | ret = iwl_mvm_send_cmd_pdu(mvm, D3_CONFIG_CMD, CMD_SYNC, |
| 1016 | sizeof(d3_cfg_cmd), &d3_cfg_cmd); |
| 1017 | if (ret) |
| 1018 | goto out; |
| 1019 | |
| 1020 | clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 1021 | |
| 1022 | iwl_trans_d3_suspend(mvm->trans); |
| 1023 | out: |
| 1024 | mvm->aux_sta.sta_id = old_aux_sta_id; |
| 1025 | mvm_ap_sta->sta_id = old_ap_sta_id; |
| 1026 | mvmvif->ap_sta_id = old_ap_sta_id; |
| 1027 | out_noreset: |
| 1028 | kfree(key_data.rsc_tsc); |
| 1029 | if (ret < 0) |
| 1030 | ieee80211_restart_hw(mvm->hw); |
| 1031 | |
| 1032 | mutex_unlock(&mvm->mutex); |
| 1033 | |
| 1034 | return ret; |
| 1035 | } |
| 1036 | |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1037 | static void iwl_mvm_query_wakeup_reasons(struct iwl_mvm *mvm, |
| 1038 | struct ieee80211_vif *vif) |
| 1039 | { |
| 1040 | u32 base = mvm->error_event_table; |
| 1041 | struct error_table_start { |
| 1042 | /* cf. struct iwl_error_event_table */ |
| 1043 | u32 valid; |
| 1044 | u32 error_id; |
| 1045 | } err_info; |
| 1046 | struct cfg80211_wowlan_wakeup wakeup = { |
| 1047 | .pattern_idx = -1, |
| 1048 | }; |
| 1049 | struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup; |
| 1050 | struct iwl_host_cmd cmd = { |
| 1051 | .id = WOWLAN_GET_STATUSES, |
| 1052 | .flags = CMD_SYNC | CMD_WANT_SKB, |
| 1053 | }; |
| 1054 | struct iwl_wowlan_status *status; |
| 1055 | u32 reasons; |
| 1056 | int ret, len; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1057 | struct sk_buff *pkt = NULL; |
| 1058 | |
| 1059 | iwl_trans_read_mem_bytes(mvm->trans, base, |
| 1060 | &err_info, sizeof(err_info)); |
| 1061 | |
| 1062 | if (err_info.valid) { |
| 1063 | IWL_INFO(mvm, "error table is valid (%d)\n", |
| 1064 | err_info.valid); |
| 1065 | if (err_info.error_id == RF_KILL_INDICATOR_FOR_WOWLAN) { |
| 1066 | wakeup.rfkill_release = true; |
| 1067 | ieee80211_report_wowlan_wakeup(vif, &wakeup, |
| 1068 | GFP_KERNEL); |
| 1069 | } |
| 1070 | return; |
| 1071 | } |
| 1072 | |
| 1073 | /* only for tracing for now */ |
| 1074 | ret = iwl_mvm_send_cmd_pdu(mvm, OFFLOADS_QUERY_CMD, CMD_SYNC, 0, NULL); |
| 1075 | if (ret) |
| 1076 | IWL_ERR(mvm, "failed to query offload statistics (%d)\n", ret); |
| 1077 | |
| 1078 | ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 1079 | if (ret) { |
| 1080 | IWL_ERR(mvm, "failed to query status (%d)\n", ret); |
| 1081 | return; |
| 1082 | } |
| 1083 | |
| 1084 | /* RF-kill already asserted again... */ |
| 1085 | if (!cmd.resp_pkt) |
| 1086 | return; |
| 1087 | |
| 1088 | len = le32_to_cpu(cmd.resp_pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK; |
| 1089 | if (len - sizeof(struct iwl_cmd_header) < sizeof(*status)) { |
| 1090 | IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); |
| 1091 | goto out; |
| 1092 | } |
| 1093 | |
| 1094 | status = (void *)cmd.resp_pkt->data; |
| 1095 | |
| 1096 | if (len - sizeof(struct iwl_cmd_header) != |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1097 | sizeof(*status) + |
| 1098 | ALIGN(le32_to_cpu(status->wake_packet_bufsize), 4)) { |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1099 | IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); |
| 1100 | goto out; |
| 1101 | } |
| 1102 | |
| 1103 | reasons = le32_to_cpu(status->wakeup_reasons); |
| 1104 | |
| 1105 | if (reasons == IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) { |
| 1106 | wakeup_report = NULL; |
| 1107 | goto report; |
| 1108 | } |
| 1109 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1110 | if (reasons & IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1111 | wakeup.magic_pkt = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1112 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1113 | if (reasons & IWL_WOWLAN_WAKEUP_BY_PATTERN) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1114 | wakeup.pattern_idx = |
| 1115 | le16_to_cpu(status->pattern_number); |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1116 | |
| 1117 | if (reasons & (IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON | |
| 1118 | IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH)) |
| 1119 | wakeup.disconnect = true; |
| 1120 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1121 | if (reasons & IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1122 | wakeup.gtk_rekey_failure = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1123 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1124 | if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1125 | wakeup.rfkill_release = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1126 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1127 | if (reasons & IWL_WOWLAN_WAKEUP_BY_EAPOL_REQUEST) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1128 | wakeup.eap_identity_req = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1129 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1130 | if (reasons & IWL_WOWLAN_WAKEUP_BY_FOUR_WAY_HANDSHAKE) |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1131 | wakeup.four_way_handshake = true; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1132 | |
Johannes Berg | f0c2646 | 2013-01-22 20:41:58 +0100 | [diff] [blame] | 1133 | if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_LINK_LOSS) |
| 1134 | wakeup.tcp_connlost = true; |
| 1135 | |
| 1136 | if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_SIGNATURE_TABLE) |
| 1137 | wakeup.tcp_nomoretokens = true; |
| 1138 | |
| 1139 | if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_WAKEUP_PACKET) |
| 1140 | wakeup.tcp_match = true; |
| 1141 | |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1142 | if (status->wake_packet_bufsize) { |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1143 | int pktsize = le32_to_cpu(status->wake_packet_bufsize); |
| 1144 | int pktlen = le32_to_cpu(status->wake_packet_length); |
| 1145 | const u8 *pktdata = status->wake_packet; |
| 1146 | struct ieee80211_hdr *hdr = (void *)pktdata; |
| 1147 | int truncated = pktlen - pktsize; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1148 | |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1149 | /* this would be a firmware bug */ |
| 1150 | if (WARN_ON_ONCE(truncated < 0)) |
| 1151 | truncated = 0; |
| 1152 | |
| 1153 | if (ieee80211_is_data(hdr->frame_control)) { |
| 1154 | int hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 1155 | int ivlen = 0, icvlen = 4; /* also FCS */ |
| 1156 | |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1157 | pkt = alloc_skb(pktsize, GFP_KERNEL); |
| 1158 | if (!pkt) |
| 1159 | goto report; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1160 | |
| 1161 | memcpy(skb_put(pkt, hdrlen), pktdata, hdrlen); |
| 1162 | pktdata += hdrlen; |
| 1163 | pktsize -= hdrlen; |
| 1164 | |
| 1165 | if (ieee80211_has_protected(hdr->frame_control)) { |
| 1166 | if (is_multicast_ether_addr(hdr->addr1)) { |
| 1167 | ivlen = mvm->gtk_ivlen; |
| 1168 | icvlen += mvm->gtk_icvlen; |
| 1169 | } else { |
| 1170 | ivlen = mvm->ptk_ivlen; |
| 1171 | icvlen += mvm->ptk_icvlen; |
| 1172 | } |
| 1173 | } |
| 1174 | |
| 1175 | /* if truncated, FCS/ICV is (partially) gone */ |
| 1176 | if (truncated >= icvlen) { |
| 1177 | icvlen = 0; |
| 1178 | truncated -= icvlen; |
| 1179 | } else { |
| 1180 | icvlen -= truncated; |
| 1181 | truncated = 0; |
| 1182 | } |
| 1183 | |
| 1184 | pktsize -= ivlen + icvlen; |
| 1185 | pktdata += ivlen; |
| 1186 | |
| 1187 | memcpy(skb_put(pkt, pktsize), pktdata, pktsize); |
| 1188 | |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1189 | if (ieee80211_data_to_8023(pkt, vif->addr, vif->type)) |
| 1190 | goto report; |
| 1191 | wakeup.packet = pkt->data; |
| 1192 | wakeup.packet_present_len = pkt->len; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1193 | wakeup.packet_len = pkt->len - truncated; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1194 | wakeup.packet_80211 = false; |
| 1195 | } else { |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1196 | int fcslen = 4; |
| 1197 | |
| 1198 | if (truncated >= 4) { |
| 1199 | truncated -= 4; |
| 1200 | fcslen = 0; |
| 1201 | } else { |
| 1202 | fcslen -= truncated; |
| 1203 | truncated = 0; |
| 1204 | } |
| 1205 | pktsize -= fcslen; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1206 | wakeup.packet = status->wake_packet; |
| 1207 | wakeup.packet_present_len = pktsize; |
Johannes Berg | f444eb1 | 2013-02-26 12:04:18 +0100 | [diff] [blame] | 1208 | wakeup.packet_len = pktlen - truncated; |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1209 | wakeup.packet_80211 = true; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | report: |
| 1214 | ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL); |
| 1215 | kfree_skb(pkt); |
| 1216 | |
| 1217 | out: |
| 1218 | iwl_free_resp(&cmd); |
| 1219 | } |
| 1220 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1221 | static void iwl_mvm_read_d3_sram(struct iwl_mvm *mvm) |
| 1222 | { |
| 1223 | #ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1224 | const struct fw_img *img = &mvm->fw->img[IWL_UCODE_WOWLAN]; |
| 1225 | u32 len = img->sec[IWL_UCODE_SECTION_DATA].len; |
| 1226 | u32 offs = img->sec[IWL_UCODE_SECTION_DATA].offset; |
| 1227 | |
| 1228 | if (!mvm->store_d3_resume_sram) |
| 1229 | return; |
| 1230 | |
| 1231 | if (!mvm->d3_resume_sram) { |
| 1232 | mvm->d3_resume_sram = kzalloc(len, GFP_KERNEL); |
| 1233 | if (!mvm->d3_resume_sram) |
| 1234 | return; |
| 1235 | } |
| 1236 | |
| 1237 | iwl_trans_read_mem_bytes(mvm->trans, offs, mvm->d3_resume_sram, len); |
| 1238 | #endif |
| 1239 | } |
| 1240 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1241 | int iwl_mvm_resume(struct ieee80211_hw *hw) |
| 1242 | { |
| 1243 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1244 | struct iwl_d3_iter_data resume_iter_data = { |
| 1245 | .mvm = mvm, |
| 1246 | }; |
| 1247 | struct ieee80211_vif *vif = NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1248 | int ret; |
| 1249 | enum iwl_d3_status d3_status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1250 | |
| 1251 | mutex_lock(&mvm->mutex); |
| 1252 | |
| 1253 | /* get the BSS vif pointer again */ |
| 1254 | ieee80211_iterate_active_interfaces_atomic( |
| 1255 | mvm->hw, IEEE80211_IFACE_ITER_NORMAL, |
| 1256 | iwl_mvm_d3_iface_iterator, &resume_iter_data); |
| 1257 | |
| 1258 | if (WARN_ON(resume_iter_data.error || !resume_iter_data.vif)) |
| 1259 | goto out_unlock; |
| 1260 | |
| 1261 | vif = resume_iter_data.vif; |
| 1262 | |
| 1263 | ret = iwl_trans_d3_resume(mvm->trans, &d3_status); |
| 1264 | if (ret) |
| 1265 | goto out_unlock; |
| 1266 | |
| 1267 | if (d3_status != IWL_D3_STATUS_ALIVE) { |
| 1268 | IWL_INFO(mvm, "Device was reset during suspend\n"); |
| 1269 | goto out_unlock; |
| 1270 | } |
| 1271 | |
Johannes Berg | afc66bb | 2013-05-03 11:44:16 +0200 | [diff] [blame] | 1272 | /* query SRAM first in case we want event logging */ |
| 1273 | iwl_mvm_read_d3_sram(mvm); |
| 1274 | |
Johannes Berg | 9b26b50 | 2013-01-22 13:02:09 +0100 | [diff] [blame] | 1275 | iwl_mvm_query_wakeup_reasons(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1276 | |
| 1277 | out_unlock: |
| 1278 | mutex_unlock(&mvm->mutex); |
| 1279 | |
| 1280 | if (vif) |
| 1281 | ieee80211_resume_disconnect(vif); |
| 1282 | |
| 1283 | /* return 1 to reconfigure the device */ |
| 1284 | set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 1285 | return 1; |
| 1286 | } |
| 1287 | |
| 1288 | void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled) |
| 1289 | { |
| 1290 | struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1291 | |
| 1292 | device_set_wakeup_enable(mvm->trans->dev, enabled); |
| 1293 | } |