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