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