| 1 |
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause |
| 2 |
/* |
| 3 |
* Copyright (C) 2012-2014, 2018-2026 Intel Corporation |
| 4 |
* Copyright (C) 2013-2015 Intel Mobile Communications GmbH |
| 5 |
* Copyright (C) 2016-2017 Intel Deutschland GmbH |
| 6 |
*/ |
| 7 |
#include <linux/etherdevice.h> |
| 8 |
#include <linux/ip.h> |
| 9 |
#include <linux/fs.h> |
| 10 |
#include <net/cfg80211.h> |
| 11 |
#include <net/ipv6.h> |
| 12 |
#include <net/tcp.h> |
| 13 |
#include <net/addrconf.h> |
| 14 |
#include "iwl-modparams.h" |
| 15 |
#include "fw-api.h" |
| 16 |
#include "mvm.h" |
| 17 |
#include "fw/img.h" |
| 18 |
|
| 19 |
void iwl_mvm_set_rekey_data(struct ieee80211_hw *hw, |
| 20 |
struct ieee80211_vif *vif, |
| 21 |
struct cfg80211_gtk_rekey_data *data) |
| 22 |
{ |
| 23 |
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 24 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 25 |
|
| 26 |
mutex_lock(&mvm->mutex); |
| 27 |
|
| 28 |
mvmvif->rekey_data.kek_len = data->kek_len; |
| 29 |
mvmvif->rekey_data.kck_len = data->kck_len; |
| 30 |
memcpy(mvmvif->rekey_data.kek, data->kek, data->kek_len); |
| 31 |
memcpy(mvmvif->rekey_data.kck, data->kck, data->kck_len); |
| 32 |
mvmvif->rekey_data.akm = data->akm & 0xFF; |
| 33 |
mvmvif->rekey_data.replay_ctr = |
| 34 |
cpu_to_le64(be64_to_cpup((const __be64 *)data->replay_ctr)); |
| 35 |
mvmvif->rekey_data.valid = true; |
| 36 |
|
| 37 |
mutex_unlock(&mvm->mutex); |
| 38 |
} |
| 39 |
|
| 40 |
#if IS_ENABLED(CONFIG_IPV6) |
| 41 |
void iwl_mvm_ipv6_addr_change(struct ieee80211_hw *hw, |
| 42 |
struct ieee80211_vif *vif, |
| 43 |
struct inet6_dev *idev) |
| 44 |
{ |
| 45 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 46 |
struct inet6_ifaddr *ifa; |
| 47 |
int idx = 0; |
| 48 |
|
| 49 |
memset(mvmvif->tentative_addrs, 0, sizeof(mvmvif->tentative_addrs)); |
| 50 |
|
| 51 |
read_lock_bh(&idev->lock); |
| 52 |
list_for_each_entry(ifa, &idev->addr_list, if_list) { |
| 53 |
mvmvif->target_ipv6_addrs[idx] = ifa->addr; |
| 54 |
if (ifa->flags & IFA_F_TENTATIVE) |
| 55 |
__set_bit(idx, mvmvif->tentative_addrs); |
| 56 |
idx++; |
| 57 |
if (idx >= IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX) |
| 58 |
break; |
| 59 |
} |
| 60 |
read_unlock_bh(&idev->lock); |
| 61 |
|
| 62 |
mvmvif->num_target_ipv6_addrs = idx; |
| 63 |
} |
| 64 |
#endif |
| 65 |
|
| 66 |
void iwl_mvm_set_default_unicast_key(struct ieee80211_hw *hw, |
| 67 |
struct ieee80211_vif *vif, int idx) |
| 68 |
{ |
| 69 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 70 |
|
| 71 |
mvmvif->tx_key_idx = idx; |
| 72 |
} |
| 73 |
|
| 74 |
static void iwl_mvm_convert_p1k(u16 *p1k, __le16 *out) |
| 75 |
{ |
| 76 |
int i; |
| 77 |
|
| 78 |
for (i = 0; i < IWL_P1K_SIZE; i++) |
| 79 |
out[i] = cpu_to_le16(p1k[i]); |
| 80 |
} |
| 81 |
|
| 82 |
static const u8 *iwl_mvm_find_max_pn(struct ieee80211_key_conf *key, |
| 83 |
struct iwl_mvm_key_pn *ptk_pn, |
| 84 |
struct ieee80211_key_seq *seq, |
| 85 |
int tid, int queues) |
| 86 |
{ |
| 87 |
const u8 *ret = seq->ccmp.pn; |
| 88 |
int i; |
| 89 |
|
| 90 |
/* get the PN from mac80211, used on the default queue */ |
| 91 |
ieee80211_get_key_rx_seq(key, tid, seq); |
| 92 |
|
| 93 |
/* and use the internal data for the other queues */ |
| 94 |
for (i = 1; i < queues; i++) { |
| 95 |
const u8 *tmp = ptk_pn->q[i].pn[tid]; |
| 96 |
|
| 97 |
if (memcmp(ret, tmp, IEEE80211_CCMP_PN_LEN) <= 0) |
| 98 |
ret = tmp; |
| 99 |
} |
| 100 |
|
| 101 |
return ret; |
| 102 |
} |
| 103 |
|
| 104 |
struct wowlan_key_reprogram_data { |
| 105 |
bool error; |
| 106 |
int wep_key_idx; |
| 107 |
}; |
| 108 |
|
| 109 |
static void iwl_mvm_wowlan_program_keys(struct ieee80211_hw *hw, |
| 110 |
struct ieee80211_vif *vif, |
| 111 |
struct ieee80211_sta *sta, |
| 112 |
struct ieee80211_key_conf *key, |
| 113 |
void *_data) |
| 114 |
{ |
| 115 |
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 116 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 117 |
struct wowlan_key_reprogram_data *data = _data; |
| 118 |
int ret; |
| 119 |
|
| 120 |
switch (key->cipher) { |
| 121 |
case WLAN_CIPHER_SUITE_WEP40: |
| 122 |
case WLAN_CIPHER_SUITE_WEP104: { /* hack it for now */ |
| 123 |
DEFINE_RAW_FLEX(struct iwl_mvm_wep_key_cmd, wkc, wep_key, 1); |
| 124 |
struct iwl_mvm_wep_key *wep_key = wkc->wep_key; |
| 125 |
|
| 126 |
wkc->mac_id_n_color = |
| 127 |
cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 128 |
mvmvif->color)); |
| 129 |
wkc->num_keys = 1; |
| 130 |
/* firmware sets STA_KEY_FLG_WEP_13BYTES */ |
| 131 |
wkc->decryption_type = STA_KEY_FLG_WEP; |
| 132 |
wep_key->key_index = key->keyidx; |
| 133 |
wep_key->key_size = key->keylen; |
| 134 |
|
| 135 |
/* |
| 136 |
* This will fail -- the key functions don't set support |
| 137 |
* pairwise WEP keys. However, that's better than silently |
| 138 |
* failing WoWLAN. Or maybe not? |
| 139 |
*/ |
| 140 |
if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) |
| 141 |
break; |
| 142 |
|
| 143 |
memcpy(&wep_key->key[3], key->key, key->keylen); |
| 144 |
if (key->keyidx == mvmvif->tx_key_idx) { |
| 145 |
/* TX key must be at offset 0 */ |
| 146 |
wep_key->key_offset = 0; |
| 147 |
} else { |
| 148 |
/* others start at 1 */ |
| 149 |
data->wep_key_idx++; |
| 150 |
wep_key->key_offset = data->wep_key_idx; |
| 151 |
} |
| 152 |
|
| 153 |
mutex_lock(&mvm->mutex); |
| 154 |
ret = iwl_mvm_send_cmd_pdu(mvm, WEP_KEY, 0, |
| 155 |
__struct_size(wkc), wkc); |
| 156 |
data->error = ret != 0; |
| 157 |
|
| 158 |
mvm->ptk_ivlen = key->iv_len; |
| 159 |
mvm->ptk_icvlen = key->icv_len; |
| 160 |
mvm->gtk_ivlen = key->iv_len; |
| 161 |
mvm->gtk_icvlen = key->icv_len; |
| 162 |
mutex_unlock(&mvm->mutex); |
| 163 |
|
| 164 |
/* don't upload key again */ |
| 165 |
return; |
| 166 |
} |
| 167 |
default: |
| 168 |
data->error = true; |
| 169 |
return; |
| 170 |
case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 171 |
case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 172 |
return; |
| 173 |
case WLAN_CIPHER_SUITE_AES_CMAC: |
| 174 |
/* |
| 175 |
* Ignore CMAC keys -- the WoWLAN firmware doesn't support them |
| 176 |
* but we also shouldn't abort suspend due to that. It does have |
| 177 |
* support for the IGTK key renewal, but doesn't really use the |
| 178 |
* IGTK for anything. This means we could spuriously wake up or |
| 179 |
* be deauthenticated, but that was considered acceptable. |
| 180 |
*/ |
| 181 |
return; |
| 182 |
case WLAN_CIPHER_SUITE_TKIP: |
| 183 |
case WLAN_CIPHER_SUITE_CCMP: |
| 184 |
case WLAN_CIPHER_SUITE_GCMP: |
| 185 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 186 |
break; |
| 187 |
} |
| 188 |
|
| 189 |
mutex_lock(&mvm->mutex); |
| 190 |
/* |
| 191 |
* The D3 firmware hardcodes the key offset 0 as the key it |
| 192 |
* uses to transmit packets to the AP, i.e. the PTK. |
| 193 |
*/ |
| 194 |
if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE) { |
| 195 |
mvm->ptk_ivlen = key->iv_len; |
| 196 |
mvm->ptk_icvlen = key->icv_len; |
| 197 |
ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, 0); |
| 198 |
} else { |
| 199 |
/* |
| 200 |
* firmware only supports TSC/RSC for a single key, |
| 201 |
* so if there are multiple keep overwriting them |
| 202 |
* with new ones -- this relies on mac80211 doing |
| 203 |
* list_add_tail(). |
| 204 |
*/ |
| 205 |
mvm->gtk_ivlen = key->iv_len; |
| 206 |
mvm->gtk_icvlen = key->icv_len; |
| 207 |
ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, 1); |
| 208 |
} |
| 209 |
mutex_unlock(&mvm->mutex); |
| 210 |
data->error = ret != 0; |
| 211 |
} |
| 212 |
|
| 213 |
struct wowlan_key_rsc_tsc_data { |
| 214 |
struct iwl_wowlan_rsc_tsc_params_cmd_ver_2 *rsc_tsc; |
| 215 |
bool have_rsc_tsc; |
| 216 |
}; |
| 217 |
|
| 218 |
static void iwl_mvm_wowlan_get_rsc_tsc_data(struct ieee80211_hw *hw, |
| 219 |
struct ieee80211_vif *vif, |
| 220 |
struct ieee80211_sta *sta, |
| 221 |
struct ieee80211_key_conf *key, |
| 222 |
void *_data) |
| 223 |
{ |
| 224 |
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 225 |
struct wowlan_key_rsc_tsc_data *data = _data; |
| 226 |
struct aes_sc *aes_sc; |
| 227 |
struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL; |
| 228 |
struct ieee80211_key_seq seq; |
| 229 |
int i; |
| 230 |
|
| 231 |
switch (key->cipher) { |
| 232 |
default: |
| 233 |
break; |
| 234 |
case WLAN_CIPHER_SUITE_TKIP: |
| 235 |
if (sta) { |
| 236 |
u64 pn64; |
| 237 |
|
| 238 |
tkip_sc = |
| 239 |
data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc; |
| 240 |
tkip_tx_sc = |
| 241 |
&data->rsc_tsc->all_tsc_rsc.tkip.tsc; |
| 242 |
|
| 243 |
pn64 = atomic64_read(&key->tx_pn); |
| 244 |
tkip_tx_sc->iv16 = cpu_to_le16(TKIP_PN_TO_IV16(pn64)); |
| 245 |
tkip_tx_sc->iv32 = cpu_to_le32(TKIP_PN_TO_IV32(pn64)); |
| 246 |
} else { |
| 247 |
tkip_sc = |
| 248 |
data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc; |
| 249 |
} |
| 250 |
|
| 251 |
/* |
| 252 |
* For non-QoS this relies on the fact that both the uCode and |
| 253 |
* mac80211 use TID 0 (as they need to avoid replay attacks) |
| 254 |
* for checking the IV in the frames. |
| 255 |
*/ |
| 256 |
for (i = 0; i < IWL_NUM_RSC; i++) { |
| 257 |
ieee80211_get_key_rx_seq(key, i, &seq); |
| 258 |
tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16); |
| 259 |
tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32); |
| 260 |
} |
| 261 |
|
| 262 |
data->have_rsc_tsc = true; |
| 263 |
break; |
| 264 |
case WLAN_CIPHER_SUITE_CCMP: |
| 265 |
case WLAN_CIPHER_SUITE_GCMP: |
| 266 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 267 |
if (sta) { |
| 268 |
struct aes_sc *aes_tx_sc; |
| 269 |
u64 pn64; |
| 270 |
|
| 271 |
aes_sc = |
| 272 |
data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc; |
| 273 |
aes_tx_sc = |
| 274 |
&data->rsc_tsc->all_tsc_rsc.aes.tsc; |
| 275 |
|
| 276 |
pn64 = atomic64_read(&key->tx_pn); |
| 277 |
aes_tx_sc->pn = cpu_to_le64(pn64); |
| 278 |
} else { |
| 279 |
aes_sc = |
| 280 |
data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc; |
| 281 |
} |
| 282 |
|
| 283 |
/* |
| 284 |
* For non-QoS this relies on the fact that both the uCode and |
| 285 |
* mac80211/our RX code use TID 0 for checking the PN. |
| 286 |
*/ |
| 287 |
if (sta && iwl_mvm_has_new_rx_api(mvm)) { |
| 288 |
struct iwl_mvm_sta *mvmsta; |
| 289 |
struct iwl_mvm_key_pn *ptk_pn; |
| 290 |
const u8 *pn; |
| 291 |
|
| 292 |
mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 293 |
rcu_read_lock(); |
| 294 |
ptk_pn = rcu_dereference(mvmsta->ptk_pn[key->keyidx]); |
| 295 |
if (WARN_ON(!ptk_pn)) { |
| 296 |
rcu_read_unlock(); |
| 297 |
break; |
| 298 |
} |
| 299 |
|
| 300 |
for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
| 301 |
pn = iwl_mvm_find_max_pn(key, ptk_pn, &seq, i, |
| 302 |
mvm->trans->info.num_rxqs); |
| 303 |
aes_sc[i].pn = cpu_to_le64((u64)pn[5] | |
| 304 |
((u64)pn[4] << 8) | |
| 305 |
((u64)pn[3] << 16) | |
| 306 |
((u64)pn[2] << 24) | |
| 307 |
((u64)pn[1] << 32) | |
| 308 |
((u64)pn[0] << 40)); |
| 309 |
} |
| 310 |
|
| 311 |
rcu_read_unlock(); |
| 312 |
} else { |
| 313 |
for (i = 0; i < IWL_NUM_RSC; i++) { |
| 314 |
u8 *pn = seq.ccmp.pn; |
| 315 |
|
| 316 |
ieee80211_get_key_rx_seq(key, i, &seq); |
| 317 |
aes_sc[i].pn = cpu_to_le64((u64)pn[5] | |
| 318 |
((u64)pn[4] << 8) | |
| 319 |
((u64)pn[3] << 16) | |
| 320 |
((u64)pn[2] << 24) | |
| 321 |
((u64)pn[1] << 32) | |
| 322 |
((u64)pn[0] << 40)); |
| 323 |
} |
| 324 |
} |
| 325 |
data->have_rsc_tsc = true; |
| 326 |
break; |
| 327 |
} |
| 328 |
} |
| 329 |
|
| 330 |
struct wowlan_key_rsc_v5_data { |
| 331 |
struct iwl_wowlan_rsc_tsc_params_cmd *rsc; |
| 332 |
bool have_rsc; |
| 333 |
int gtks; |
| 334 |
int gtk_ids[4]; |
| 335 |
}; |
| 336 |
|
| 337 |
static void iwl_mvm_wowlan_get_rsc_v5_data(struct ieee80211_hw *hw, |
| 338 |
struct ieee80211_vif *vif, |
| 339 |
struct ieee80211_sta *sta, |
| 340 |
struct ieee80211_key_conf *key, |
| 341 |
void *_data) |
| 342 |
{ |
| 343 |
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 344 |
struct wowlan_key_rsc_v5_data *data = _data; |
| 345 |
struct ieee80211_key_seq seq; |
| 346 |
__le64 *rsc; |
| 347 |
int i; |
| 348 |
|
| 349 |
/* only for ciphers that can be PTK/GTK */ |
| 350 |
switch (key->cipher) { |
| 351 |
default: |
| 352 |
return; |
| 353 |
case WLAN_CIPHER_SUITE_TKIP: |
| 354 |
case WLAN_CIPHER_SUITE_CCMP: |
| 355 |
case WLAN_CIPHER_SUITE_GCMP: |
| 356 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 357 |
break; |
| 358 |
} |
| 359 |
|
| 360 |
if (sta) { |
| 361 |
rsc = data->rsc->ucast_rsc; |
| 362 |
} else { |
| 363 |
if (WARN_ON(data->gtks >= ARRAY_SIZE(data->gtk_ids))) |
| 364 |
return; |
| 365 |
data->gtk_ids[data->gtks] = key->keyidx; |
| 366 |
rsc = data->rsc->mcast_rsc[data->gtks % 2]; |
| 367 |
if (WARN_ON(key->keyidx >= |
| 368 |
ARRAY_SIZE(data->rsc->mcast_key_id_map))) |
| 369 |
return; |
| 370 |
data->rsc->mcast_key_id_map[key->keyidx] = data->gtks % 2; |
| 371 |
if (data->gtks >= 2) { |
| 372 |
int prev = data->gtks - 2; |
| 373 |
int prev_idx = data->gtk_ids[prev]; |
| 374 |
|
| 375 |
data->rsc->mcast_key_id_map[prev_idx] = |
| 376 |
IWL_MCAST_KEY_MAP_INVALID; |
| 377 |
} |
| 378 |
data->gtks++; |
| 379 |
} |
| 380 |
|
| 381 |
switch (key->cipher) { |
| 382 |
default: |
| 383 |
WARN_ON(1); |
| 384 |
break; |
| 385 |
case WLAN_CIPHER_SUITE_TKIP: |
| 386 |
|
| 387 |
/* |
| 388 |
* For non-QoS this relies on the fact that both the uCode and |
| 389 |
* mac80211 use TID 0 (as they need to avoid replay attacks) |
| 390 |
* for checking the IV in the frames. |
| 391 |
*/ |
| 392 |
for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
| 393 |
ieee80211_get_key_rx_seq(key, i, &seq); |
| 394 |
|
| 395 |
rsc[i] = cpu_to_le64(((u64)seq.tkip.iv32 << 16) | |
| 396 |
seq.tkip.iv16); |
| 397 |
} |
| 398 |
|
| 399 |
data->have_rsc = true; |
| 400 |
break; |
| 401 |
case WLAN_CIPHER_SUITE_CCMP: |
| 402 |
case WLAN_CIPHER_SUITE_GCMP: |
| 403 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 404 |
/* |
| 405 |
* For non-QoS this relies on the fact that both the uCode and |
| 406 |
* mac80211/our RX code use TID 0 for checking the PN. |
| 407 |
*/ |
| 408 |
if (sta) { |
| 409 |
struct iwl_mvm_sta *mvmsta; |
| 410 |
struct iwl_mvm_key_pn *ptk_pn; |
| 411 |
const u8 *pn; |
| 412 |
|
| 413 |
mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 414 |
rcu_read_lock(); |
| 415 |
ptk_pn = rcu_dereference(mvmsta->ptk_pn[key->keyidx]); |
| 416 |
if (WARN_ON(!ptk_pn)) { |
| 417 |
rcu_read_unlock(); |
| 418 |
break; |
| 419 |
} |
| 420 |
|
| 421 |
for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
| 422 |
pn = iwl_mvm_find_max_pn(key, ptk_pn, &seq, i, |
| 423 |
mvm->trans->info.num_rxqs); |
| 424 |
rsc[i] = cpu_to_le64((u64)pn[5] | |
| 425 |
((u64)pn[4] << 8) | |
| 426 |
((u64)pn[3] << 16) | |
| 427 |
((u64)pn[2] << 24) | |
| 428 |
((u64)pn[1] << 32) | |
| 429 |
((u64)pn[0] << 40)); |
| 430 |
} |
| 431 |
|
| 432 |
rcu_read_unlock(); |
| 433 |
} else { |
| 434 |
for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
| 435 |
u8 *pn = seq.ccmp.pn; |
| 436 |
|
| 437 |
ieee80211_get_key_rx_seq(key, i, &seq); |
| 438 |
rsc[i] = cpu_to_le64((u64)pn[5] | |
| 439 |
((u64)pn[4] << 8) | |
| 440 |
((u64)pn[3] << 16) | |
| 441 |
((u64)pn[2] << 24) | |
| 442 |
((u64)pn[1] << 32) | |
| 443 |
((u64)pn[0] << 40)); |
| 444 |
} |
| 445 |
} |
| 446 |
data->have_rsc = true; |
| 447 |
break; |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
static int iwl_mvm_wowlan_config_rsc_tsc(struct iwl_mvm *mvm, |
| 452 |
struct ieee80211_vif *vif, |
| 453 |
struct iwl_mvm_vif_link_info *mvm_link) |
| 454 |
{ |
| 455 |
int ver = iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_TSC_RSC_PARAM, |
| 456 |
IWL_FW_CMD_VER_UNKNOWN); |
| 457 |
int ret; |
| 458 |
|
| 459 |
if (ver == 5) { |
| 460 |
struct wowlan_key_rsc_v5_data data = {}; |
| 461 |
int i; |
| 462 |
|
| 463 |
data.rsc = kzalloc_obj(*data.rsc); |
| 464 |
if (!data.rsc) |
| 465 |
return -ENOMEM; |
| 466 |
|
| 467 |
for (i = 0; i < ARRAY_SIZE(data.rsc->mcast_key_id_map); i++) |
| 468 |
data.rsc->mcast_key_id_map[i] = |
| 469 |
IWL_MCAST_KEY_MAP_INVALID; |
| 470 |
data.rsc->sta_id = cpu_to_le32(mvm_link->ap_sta_id); |
| 471 |
|
| 472 |
ieee80211_iter_keys(mvm->hw, vif, |
| 473 |
iwl_mvm_wowlan_get_rsc_v5_data, |
| 474 |
&data); |
| 475 |
|
| 476 |
if (data.have_rsc) |
| 477 |
ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_TSC_RSC_PARAM, |
| 478 |
CMD_ASYNC, sizeof(*data.rsc), |
| 479 |
data.rsc); |
| 480 |
else |
| 481 |
ret = 0; |
| 482 |
kfree(data.rsc); |
| 483 |
} else if (ver == 2 || ver == IWL_FW_CMD_VER_UNKNOWN) { |
| 484 |
struct wowlan_key_rsc_tsc_data data = {}; |
| 485 |
|
| 486 |
data.rsc_tsc = kzalloc_obj(*data.rsc_tsc); |
| 487 |
if (!data.rsc_tsc) |
| 488 |
return -ENOMEM; |
| 489 |
|
| 490 |
ieee80211_iter_keys(mvm->hw, vif, |
| 491 |
iwl_mvm_wowlan_get_rsc_tsc_data, |
| 492 |
&data); |
| 493 |
|
| 494 |
if (data.have_rsc_tsc) |
| 495 |
ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_TSC_RSC_PARAM, |
| 496 |
CMD_ASYNC, |
| 497 |
sizeof(*data.rsc_tsc), |
| 498 |
data.rsc_tsc); |
| 499 |
else |
| 500 |
ret = 0; |
| 501 |
kfree(data.rsc_tsc); |
| 502 |
} else { |
| 503 |
ret = 0; |
| 504 |
WARN_ON_ONCE(1); |
| 505 |
} |
| 506 |
|
| 507 |
return ret; |
| 508 |
} |
| 509 |
|
| 510 |
struct wowlan_key_tkip_data { |
| 511 |
struct iwl_wowlan_tkip_params_cmd tkip; |
| 512 |
bool have_tkip_keys; |
| 513 |
}; |
| 514 |
|
| 515 |
static void iwl_mvm_wowlan_get_tkip_data(struct ieee80211_hw *hw, |
| 516 |
struct ieee80211_vif *vif, |
| 517 |
struct ieee80211_sta *sta, |
| 518 |
struct ieee80211_key_conf *key, |
| 519 |
void *_data) |
| 520 |
{ |
| 521 |
struct wowlan_key_tkip_data *data = _data; |
| 522 |
struct iwl_p1k_cache *rx_p1ks; |
| 523 |
u8 *rx_mic_key; |
| 524 |
struct ieee80211_key_seq seq; |
| 525 |
u32 cur_rx_iv32 = 0; |
| 526 |
u16 p1k[IWL_P1K_SIZE]; |
| 527 |
int i; |
| 528 |
|
| 529 |
switch (key->cipher) { |
| 530 |
default: |
| 531 |
break; |
| 532 |
case WLAN_CIPHER_SUITE_TKIP: |
| 533 |
if (sta) { |
| 534 |
u64 pn64; |
| 535 |
|
| 536 |
rx_p1ks = data->tkip.rx_uni; |
| 537 |
|
| 538 |
pn64 = atomic64_read(&key->tx_pn); |
| 539 |
|
| 540 |
ieee80211_get_tkip_p1k_iv(key, TKIP_PN_TO_IV32(pn64), |
| 541 |
p1k); |
| 542 |
iwl_mvm_convert_p1k(p1k, data->tkip.tx.p1k); |
| 543 |
|
| 544 |
memcpy(data->tkip.mic_keys.tx, |
| 545 |
&key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY], |
| 546 |
IWL_MIC_KEY_SIZE); |
| 547 |
|
| 548 |
rx_mic_key = data->tkip.mic_keys.rx_unicast; |
| 549 |
} else { |
| 550 |
rx_p1ks = data->tkip.rx_multi; |
| 551 |
rx_mic_key = data->tkip.mic_keys.rx_mcast; |
| 552 |
} |
| 553 |
|
| 554 |
for (i = 0; i < IWL_NUM_RSC; i++) { |
| 555 |
ieee80211_get_key_rx_seq(key, i, &seq); |
| 556 |
/* wrapping isn't allowed, AP must rekey */ |
| 557 |
if (seq.tkip.iv32 > cur_rx_iv32) |
| 558 |
cur_rx_iv32 = seq.tkip.iv32; |
| 559 |
} |
| 560 |
|
| 561 |
ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid, |
| 562 |
cur_rx_iv32, p1k); |
| 563 |
iwl_mvm_convert_p1k(p1k, rx_p1ks[0].p1k); |
| 564 |
ieee80211_get_tkip_rx_p1k(key, vif->bss_conf.bssid, |
| 565 |
cur_rx_iv32 + 1, p1k); |
| 566 |
iwl_mvm_convert_p1k(p1k, rx_p1ks[1].p1k); |
| 567 |
|
| 568 |
memcpy(rx_mic_key, |
| 569 |
&key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY], |
| 570 |
IWL_MIC_KEY_SIZE); |
| 571 |
|
| 572 |
data->have_tkip_keys = true; |
| 573 |
break; |
| 574 |
} |
| 575 |
} |
| 576 |
|
| 577 |
struct wowlan_key_gtk_type_iter { |
| 578 |
struct iwl_wowlan_kek_kck_material_cmd_v4 *kek_kck_cmd; |
| 579 |
}; |
| 580 |
|
| 581 |
static void iwl_mvm_wowlan_gtk_type_iter(struct ieee80211_hw *hw, |
| 582 |
struct ieee80211_vif *vif, |
| 583 |
struct ieee80211_sta *sta, |
| 584 |
struct ieee80211_key_conf *key, |
| 585 |
void *_data) |
| 586 |
{ |
| 587 |
struct wowlan_key_gtk_type_iter *data = _data; |
| 588 |
__le32 *cipher = NULL; |
| 589 |
|
| 590 |
if (key->keyidx == 4 || key->keyidx == 5) |
| 591 |
cipher = &data->kek_kck_cmd->igtk_cipher; |
| 592 |
if (key->keyidx == 6 || key->keyidx == 7) |
| 593 |
cipher = &data->kek_kck_cmd->bigtk_cipher; |
| 594 |
|
| 595 |
switch (key->cipher) { |
| 596 |
default: |
| 597 |
return; |
| 598 |
case WLAN_CIPHER_SUITE_TKIP: |
| 599 |
if (!sta) |
| 600 |
data->kek_kck_cmd->gtk_cipher = |
| 601 |
cpu_to_le32(STA_KEY_FLG_TKIP); |
| 602 |
return; |
| 603 |
case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 604 |
case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 605 |
if (cipher) |
| 606 |
*cipher = cpu_to_le32(STA_KEY_FLG_GCMP); |
| 607 |
return; |
| 608 |
case WLAN_CIPHER_SUITE_AES_CMAC: |
| 609 |
case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 610 |
if (cipher) |
| 611 |
*cipher = cpu_to_le32(STA_KEY_FLG_CCM); |
| 612 |
return; |
| 613 |
case WLAN_CIPHER_SUITE_CCMP: |
| 614 |
if (!sta) |
| 615 |
data->kek_kck_cmd->gtk_cipher = |
| 616 |
cpu_to_le32(STA_KEY_FLG_CCM); |
| 617 |
return; |
| 618 |
case WLAN_CIPHER_SUITE_GCMP: |
| 619 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 620 |
if (!sta) |
| 621 |
data->kek_kck_cmd->gtk_cipher = |
| 622 |
cpu_to_le32(STA_KEY_FLG_GCMP); |
| 623 |
return; |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
static int iwl_mvm_send_patterns_v1(struct iwl_mvm *mvm, |
| 628 |
struct cfg80211_wowlan *wowlan) |
| 629 |
{ |
| 630 |
struct iwl_wowlan_patterns_cmd_v1 *pattern_cmd; |
| 631 |
struct iwl_host_cmd cmd = { |
| 632 |
.id = WOWLAN_PATTERNS, |
| 633 |
.dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
| 634 |
}; |
| 635 |
int i, err; |
| 636 |
|
| 637 |
if (!wowlan->n_patterns) |
| 638 |
return 0; |
| 639 |
|
| 640 |
cmd.len[0] = struct_size(pattern_cmd, patterns, wowlan->n_patterns); |
| 641 |
|
| 642 |
pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL); |
| 643 |
if (!pattern_cmd) |
| 644 |
return -ENOMEM; |
| 645 |
|
| 646 |
pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns); |
| 647 |
|
| 648 |
for (i = 0; i < wowlan->n_patterns; i++) { |
| 649 |
int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8); |
| 650 |
|
| 651 |
memcpy(&pattern_cmd->patterns[i].mask, |
| 652 |
wowlan->patterns[i].mask, mask_len); |
| 653 |
memcpy(&pattern_cmd->patterns[i].pattern, |
| 654 |
wowlan->patterns[i].pattern, |
| 655 |
wowlan->patterns[i].pattern_len); |
| 656 |
pattern_cmd->patterns[i].mask_size = mask_len; |
| 657 |
pattern_cmd->patterns[i].pattern_size = |
| 658 |
wowlan->patterns[i].pattern_len; |
| 659 |
} |
| 660 |
|
| 661 |
cmd.data[0] = pattern_cmd; |
| 662 |
err = iwl_mvm_send_cmd(mvm, &cmd); |
| 663 |
kfree(pattern_cmd); |
| 664 |
return err; |
| 665 |
} |
| 666 |
|
| 667 |
static int iwl_mvm_send_patterns(struct iwl_mvm *mvm, |
| 668 |
struct iwl_mvm_vif_link_info *mvm_link, |
| 669 |
struct cfg80211_wowlan *wowlan) |
| 670 |
{ |
| 671 |
struct iwl_wowlan_patterns_cmd *pattern_cmd; |
| 672 |
struct iwl_host_cmd cmd = { |
| 673 |
.id = WOWLAN_PATTERNS, |
| 674 |
.dataflags[0] = IWL_HCMD_DFL_NOCOPY, |
| 675 |
}; |
| 676 |
int i, err; |
| 677 |
int ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd.id, |
| 678 |
IWL_FW_CMD_VER_UNKNOWN); |
| 679 |
|
| 680 |
if (!wowlan->n_patterns) |
| 681 |
return 0; |
| 682 |
|
| 683 |
cmd.len[0] = sizeof(*pattern_cmd) + |
| 684 |
wowlan->n_patterns * sizeof(struct iwl_wowlan_pattern_v2); |
| 685 |
|
| 686 |
pattern_cmd = kzalloc(cmd.len[0], GFP_KERNEL); |
| 687 |
if (!pattern_cmd) |
| 688 |
return -ENOMEM; |
| 689 |
|
| 690 |
pattern_cmd->n_patterns = wowlan->n_patterns; |
| 691 |
if (ver >= 3) |
| 692 |
pattern_cmd->sta_id = mvm_link->ap_sta_id; |
| 693 |
|
| 694 |
for (i = 0; i < wowlan->n_patterns; i++) { |
| 695 |
int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8); |
| 696 |
|
| 697 |
pattern_cmd->patterns[i].pattern_type = |
| 698 |
WOWLAN_PATTERN_TYPE_BITMASK; |
| 699 |
|
| 700 |
memcpy(&pattern_cmd->patterns[i].u.bitmask.mask, |
| 701 |
wowlan->patterns[i].mask, mask_len); |
| 702 |
memcpy(&pattern_cmd->patterns[i].u.bitmask.pattern, |
| 703 |
wowlan->patterns[i].pattern, |
| 704 |
wowlan->patterns[i].pattern_len); |
| 705 |
pattern_cmd->patterns[i].u.bitmask.mask_size = mask_len; |
| 706 |
pattern_cmd->patterns[i].u.bitmask.pattern_size = |
| 707 |
wowlan->patterns[i].pattern_len; |
| 708 |
} |
| 709 |
|
| 710 |
cmd.data[0] = pattern_cmd; |
| 711 |
err = iwl_mvm_send_cmd(mvm, &cmd); |
| 712 |
kfree(pattern_cmd); |
| 713 |
return err; |
| 714 |
} |
| 715 |
|
| 716 |
static int iwl_mvm_d3_reprogram(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 717 |
struct ieee80211_sta *ap_sta) |
| 718 |
{ |
| 719 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 720 |
struct ieee80211_chanctx_conf *ctx; |
| 721 |
u8 chains_static, chains_dynamic; |
| 722 |
struct cfg80211_chan_def chandef, ap_def; |
| 723 |
int ret, i; |
| 724 |
struct iwl_binding_cmd_v1 binding_cmd = {}; |
| 725 |
struct iwl_time_quota_cmd quota_cmd = {}; |
| 726 |
struct iwl_time_quota_data *quota; |
| 727 |
u32 status; |
| 728 |
|
| 729 |
if (WARN_ON_ONCE(iwl_mvm_is_cdb_supported(mvm))) |
| 730 |
return -EINVAL; |
| 731 |
|
| 732 |
/* add back the PHY */ |
| 733 |
if (WARN_ON(!mvmvif->deflink.phy_ctxt)) |
| 734 |
return -EINVAL; |
| 735 |
|
| 736 |
rcu_read_lock(); |
| 737 |
ctx = rcu_dereference(vif->bss_conf.chanctx_conf); |
| 738 |
if (WARN_ON(!ctx)) { |
| 739 |
rcu_read_unlock(); |
| 740 |
return -EINVAL; |
| 741 |
} |
| 742 |
chandef = ctx->def; |
| 743 |
ap_def = ctx->ap; |
| 744 |
chains_static = ctx->rx_chains_static; |
| 745 |
chains_dynamic = ctx->rx_chains_dynamic; |
| 746 |
rcu_read_unlock(); |
| 747 |
|
| 748 |
ret = iwl_mvm_phy_ctxt_add(mvm, mvmvif->deflink.phy_ctxt, &chandef, |
| 749 |
&ap_def, chains_static, chains_dynamic); |
| 750 |
if (ret) |
| 751 |
return ret; |
| 752 |
|
| 753 |
/* add back the MAC */ |
| 754 |
mvmvif->uploaded = false; |
| 755 |
|
| 756 |
if (WARN_ON(!vif->cfg.assoc)) |
| 757 |
return -EINVAL; |
| 758 |
|
| 759 |
ret = iwl_mvm_mac_ctxt_add(mvm, vif); |
| 760 |
if (ret) |
| 761 |
return ret; |
| 762 |
|
| 763 |
/* add back binding - XXX refactor? */ |
| 764 |
binding_cmd.id_and_color = |
| 765 |
cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->deflink.phy_ctxt->id, |
| 766 |
mvmvif->deflink.phy_ctxt->color)); |
| 767 |
binding_cmd.action = cpu_to_le32(FW_CTXT_ACTION_ADD); |
| 768 |
binding_cmd.phy = |
| 769 |
cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->deflink.phy_ctxt->id, |
| 770 |
mvmvif->deflink.phy_ctxt->color)); |
| 771 |
binding_cmd.macs[0] = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 772 |
mvmvif->color)); |
| 773 |
for (i = 1; i < MAX_MACS_IN_BINDING; i++) |
| 774 |
binding_cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID); |
| 775 |
|
| 776 |
status = 0; |
| 777 |
ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD, |
| 778 |
IWL_BINDING_CMD_SIZE_V1, &binding_cmd, |
| 779 |
&status); |
| 780 |
if (ret) { |
| 781 |
IWL_ERR(mvm, "Failed to add binding: %d\n", ret); |
| 782 |
return ret; |
| 783 |
} |
| 784 |
|
| 785 |
if (status) { |
| 786 |
IWL_ERR(mvm, "Binding command failed: %u\n", status); |
| 787 |
return -EIO; |
| 788 |
} |
| 789 |
|
| 790 |
ret = iwl_mvm_sta_send_to_fw(mvm, ap_sta, false, 0); |
| 791 |
if (ret) |
| 792 |
return ret; |
| 793 |
rcu_assign_pointer(mvm->fw_id_to_mac_id[mvmvif->deflink.ap_sta_id], |
| 794 |
ap_sta); |
| 795 |
|
| 796 |
ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); |
| 797 |
if (ret) |
| 798 |
return ret; |
| 799 |
|
| 800 |
/* and some quota */ |
| 801 |
quota = iwl_mvm_quota_cmd_get_quota(mvm, "a_cmd, 0); |
| 802 |
quota->id_and_color = |
| 803 |
cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->deflink.phy_ctxt->id, |
| 804 |
mvmvif->deflink.phy_ctxt->color)); |
| 805 |
quota->quota = cpu_to_le32(IWL_MVM_MAX_QUOTA); |
| 806 |
quota->max_duration = cpu_to_le32(IWL_MVM_MAX_QUOTA); |
| 807 |
|
| 808 |
for (i = 1; i < MAX_BINDINGS; i++) { |
| 809 |
quota = iwl_mvm_quota_cmd_get_quota(mvm, "a_cmd, i); |
| 810 |
quota->id_and_color = cpu_to_le32(FW_CTXT_INVALID); |
| 811 |
} |
| 812 |
|
| 813 |
ret = iwl_mvm_send_cmd_pdu(mvm, TIME_QUOTA_CMD, 0, |
| 814 |
iwl_mvm_quota_cmd_size(mvm), "a_cmd); |
| 815 |
if (ret) |
| 816 |
IWL_ERR(mvm, "Failed to send quota: %d\n", ret); |
| 817 |
|
| 818 |
if (iwl_mvm_is_lar_supported(mvm) && iwl_mvm_init_fw_regd(mvm, false)) |
| 819 |
IWL_ERR(mvm, "Failed to initialize D3 LAR information\n"); |
| 820 |
|
| 821 |
return 0; |
| 822 |
} |
| 823 |
|
| 824 |
static int iwl_mvm_get_last_nonqos_seq(struct iwl_mvm *mvm, |
| 825 |
struct ieee80211_vif *vif) |
| 826 |
{ |
| 827 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 828 |
struct iwl_nonqos_seq_query_cmd query_cmd = { |
| 829 |
.get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_GET), |
| 830 |
.mac_id_n_color = |
| 831 |
cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 832 |
mvmvif->color)), |
| 833 |
}; |
| 834 |
struct iwl_host_cmd cmd = { |
| 835 |
.id = NON_QOS_TX_COUNTER_CMD, |
| 836 |
.flags = CMD_WANT_SKB, |
| 837 |
}; |
| 838 |
int err; |
| 839 |
u32 size; |
| 840 |
|
| 841 |
cmd.data[0] = &query_cmd; |
| 842 |
cmd.len[0] = sizeof(query_cmd); |
| 843 |
|
| 844 |
err = iwl_mvm_send_cmd(mvm, &cmd); |
| 845 |
if (err) |
| 846 |
return err; |
| 847 |
|
| 848 |
size = iwl_rx_packet_payload_len(cmd.resp_pkt); |
| 849 |
if (size < sizeof(__le16)) { |
| 850 |
err = -EINVAL; |
| 851 |
} else { |
| 852 |
err = le16_to_cpup((__le16 *)cmd.resp_pkt->data); |
| 853 |
/* firmware returns next, not last-used seqno */ |
| 854 |
err = (u16) (err - 0x10); |
| 855 |
} |
| 856 |
|
| 857 |
iwl_free_resp(&cmd); |
| 858 |
return err; |
| 859 |
} |
| 860 |
|
| 861 |
void iwl_mvm_set_last_nonqos_seq(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 862 |
{ |
| 863 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 864 |
struct iwl_nonqos_seq_query_cmd query_cmd = { |
| 865 |
.get_set_flag = cpu_to_le32(IWL_NONQOS_SEQ_SET), |
| 866 |
.mac_id_n_color = |
| 867 |
cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 868 |
mvmvif->color)), |
| 869 |
.value = cpu_to_le16(mvmvif->seqno), |
| 870 |
}; |
| 871 |
|
| 872 |
/* return if called during restart, not resume from D3 */ |
| 873 |
if (!mvmvif->seqno_valid) |
| 874 |
return; |
| 875 |
|
| 876 |
mvmvif->seqno_valid = false; |
| 877 |
|
| 878 |
if (iwl_mvm_send_cmd_pdu(mvm, NON_QOS_TX_COUNTER_CMD, 0, |
| 879 |
sizeof(query_cmd), &query_cmd)) |
| 880 |
IWL_ERR(mvm, "failed to set non-QoS seqno\n"); |
| 881 |
} |
| 882 |
|
| 883 |
static int iwl_mvm_switch_to_d3(struct iwl_mvm *mvm) |
| 884 |
{ |
| 885 |
iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true); |
| 886 |
|
| 887 |
iwl_mvm_stop_device(mvm); |
| 888 |
/* |
| 889 |
* Set the HW restart bit -- this is mostly true as we're |
| 890 |
* going to load new firmware and reprogram that, though |
| 891 |
* the reprogramming is going to be manual to avoid adding |
| 892 |
* all the MACs that aren't support. |
| 893 |
* We don't have to clear up everything though because the |
| 894 |
* reprogramming is manual. When we resume, we'll actually |
| 895 |
* go through a proper restart sequence again to switch |
| 896 |
* back to the runtime firmware image. |
| 897 |
*/ |
| 898 |
set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 899 |
|
| 900 |
/* the fw is reset, so all the keys are cleared */ |
| 901 |
memset(mvm->fw_key_table, 0, sizeof(mvm->fw_key_table)); |
| 902 |
|
| 903 |
mvm->ptk_ivlen = 0; |
| 904 |
mvm->ptk_icvlen = 0; |
| 905 |
mvm->ptk_ivlen = 0; |
| 906 |
mvm->ptk_icvlen = 0; |
| 907 |
|
| 908 |
return iwl_mvm_load_d3_fw(mvm); |
| 909 |
} |
| 910 |
|
| 911 |
static int |
| 912 |
iwl_mvm_get_wowlan_config(struct iwl_mvm *mvm, |
| 913 |
struct cfg80211_wowlan *wowlan, |
| 914 |
struct iwl_wowlan_config_cmd_v6 *wowlan_config_cmd, |
| 915 |
struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif, |
| 916 |
struct ieee80211_sta *ap_sta) |
| 917 |
{ |
| 918 |
struct iwl_mvm_sta *mvm_ap_sta = iwl_mvm_sta_from_mac80211(ap_sta); |
| 919 |
|
| 920 |
/* TODO: wowlan_config_cmd->wowlan_ba_teardown_tids */ |
| 921 |
|
| 922 |
wowlan_config_cmd->is_11n_connection = |
| 923 |
ap_sta->deflink.ht_cap.ht_supported; |
| 924 |
wowlan_config_cmd->flags = ENABLE_L3_FILTERING | |
| 925 |
ENABLE_NBNS_FILTERING | ENABLE_DHCP_FILTERING; |
| 926 |
|
| 927 |
if (ap_sta->mfp) |
| 928 |
wowlan_config_cmd->flags |= IS_11W_ASSOC; |
| 929 |
|
| 930 |
if (rcu_access_pointer(mvmvif->bcn_prot.keys[0]) || |
| 931 |
rcu_access_pointer(mvmvif->bcn_prot.keys[1])) |
| 932 |
wowlan_config_cmd->flags |= HAS_BEACON_PROTECTION; |
| 933 |
|
| 934 |
if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_CONFIGURATION, 0) < 6) { |
| 935 |
/* Query the last used seqno and set it */ |
| 936 |
int ret = iwl_mvm_get_last_nonqos_seq(mvm, vif); |
| 937 |
|
| 938 |
if (ret < 0) |
| 939 |
return ret; |
| 940 |
|
| 941 |
wowlan_config_cmd->non_qos_seq = cpu_to_le16(ret); |
| 942 |
} |
| 943 |
|
| 944 |
if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_CONFIGURATION, 0) < 7) |
| 945 |
iwl_mvm_set_wowlan_qos_seq(mvm_ap_sta, wowlan_config_cmd); |
| 946 |
|
| 947 |
if (wowlan->disconnect) |
| 948 |
wowlan_config_cmd->wakeup_filter |= |
| 949 |
cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS | |
| 950 |
IWL_WOWLAN_WAKEUP_LINK_CHANGE); |
| 951 |
if (wowlan->magic_pkt) |
| 952 |
wowlan_config_cmd->wakeup_filter |= |
| 953 |
cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET); |
| 954 |
if (wowlan->gtk_rekey_failure) |
| 955 |
wowlan_config_cmd->wakeup_filter |= |
| 956 |
cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL); |
| 957 |
if (wowlan->eap_identity_req) |
| 958 |
wowlan_config_cmd->wakeup_filter |= |
| 959 |
cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ); |
| 960 |
if (wowlan->four_way_handshake) |
| 961 |
wowlan_config_cmd->wakeup_filter |= |
| 962 |
cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE); |
| 963 |
if (wowlan->n_patterns) |
| 964 |
wowlan_config_cmd->wakeup_filter |= |
| 965 |
cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH); |
| 966 |
|
| 967 |
if (wowlan->rfkill_release) |
| 968 |
wowlan_config_cmd->wakeup_filter |= |
| 969 |
cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT); |
| 970 |
|
| 971 |
if (wowlan->tcp) { |
| 972 |
/* |
| 973 |
* Set the "link change" (really "link lost") flag as well |
| 974 |
* since that implies losing the TCP connection. |
| 975 |
*/ |
| 976 |
wowlan_config_cmd->wakeup_filter |= |
| 977 |
cpu_to_le32(IWL_WOWLAN_WAKEUP_REMOTE_LINK_LOSS | |
| 978 |
IWL_WOWLAN_WAKEUP_REMOTE_SIGNATURE_TABLE | |
| 979 |
IWL_WOWLAN_WAKEUP_REMOTE_WAKEUP_PACKET | |
| 980 |
IWL_WOWLAN_WAKEUP_LINK_CHANGE); |
| 981 |
} |
| 982 |
|
| 983 |
if (wowlan->any) { |
| 984 |
wowlan_config_cmd->wakeup_filter |= |
| 985 |
cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS | |
| 986 |
IWL_WOWLAN_WAKEUP_LINK_CHANGE | |
| 987 |
IWL_WOWLAN_WAKEUP_RX_FRAME | |
| 988 |
IWL_WOWLAN_WAKEUP_BCN_FILTERING); |
| 989 |
} |
| 990 |
|
| 991 |
return 0; |
| 992 |
} |
| 993 |
|
| 994 |
static int iwl_mvm_wowlan_config_key_params(struct iwl_mvm *mvm, |
| 995 |
struct ieee80211_vif *vif, |
| 996 |
struct iwl_mvm_vif_link_info *mvm_link) |
| 997 |
{ |
| 998 |
bool unified = fw_has_capa(&mvm->fw->ucode_capa, |
| 999 |
IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
| 1000 |
struct wowlan_key_reprogram_data key_data = {}; |
| 1001 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1002 |
int ret; |
| 1003 |
u8 cmd_ver; |
| 1004 |
size_t cmd_size; |
| 1005 |
|
| 1006 |
if (!unified) { |
| 1007 |
/* |
| 1008 |
* if we have to configure keys, call ieee80211_iter_keys(), |
| 1009 |
* as we need non-atomic context in order to take the |
| 1010 |
* required locks. |
| 1011 |
*/ |
| 1012 |
/* |
| 1013 |
* Note that currently we don't use CMD_ASYNC in the iterator. |
| 1014 |
* In case of key_data.configure_keys, all the configured |
| 1015 |
* commands are SYNC, and iwl_mvm_wowlan_program_keys() will |
| 1016 |
* take care of locking/unlocking mvm->mutex. |
| 1017 |
*/ |
| 1018 |
ieee80211_iter_keys(mvm->hw, vif, iwl_mvm_wowlan_program_keys, |
| 1019 |
&key_data); |
| 1020 |
|
| 1021 |
if (key_data.error) |
| 1022 |
return -EIO; |
| 1023 |
} |
| 1024 |
|
| 1025 |
ret = iwl_mvm_wowlan_config_rsc_tsc(mvm, vif, mvm_link); |
| 1026 |
if (ret) |
| 1027 |
return ret; |
| 1028 |
|
| 1029 |
if (!fw_has_api(&mvm->fw->ucode_capa, |
| 1030 |
IWL_UCODE_TLV_API_TKIP_MIC_KEYS)) { |
| 1031 |
int ver = iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_TKIP_PARAM, |
| 1032 |
IWL_FW_CMD_VER_UNKNOWN); |
| 1033 |
struct wowlan_key_tkip_data tkip_data = {}; |
| 1034 |
int size; |
| 1035 |
|
| 1036 |
if (ver == 2) { |
| 1037 |
size = sizeof(tkip_data.tkip); |
| 1038 |
tkip_data.tkip.sta_id = |
| 1039 |
cpu_to_le32(mvm_link->ap_sta_id); |
| 1040 |
} else if (ver == 1 || ver == IWL_FW_CMD_VER_UNKNOWN) { |
| 1041 |
size = sizeof(struct iwl_wowlan_tkip_params_cmd_ver_1); |
| 1042 |
} else { |
| 1043 |
WARN_ON_ONCE(1); |
| 1044 |
return -EINVAL; |
| 1045 |
} |
| 1046 |
|
| 1047 |
ieee80211_iter_keys(mvm->hw, vif, iwl_mvm_wowlan_get_tkip_data, |
| 1048 |
&tkip_data); |
| 1049 |
|
| 1050 |
if (tkip_data.have_tkip_keys) { |
| 1051 |
/* send relevant data according to CMD version */ |
| 1052 |
ret = iwl_mvm_send_cmd_pdu(mvm, |
| 1053 |
WOWLAN_TKIP_PARAM, |
| 1054 |
CMD_ASYNC, size, |
| 1055 |
&tkip_data.tkip); |
| 1056 |
if (ret) |
| 1057 |
return ret; |
| 1058 |
} |
| 1059 |
} |
| 1060 |
|
| 1061 |
/* configure rekey data only if offloaded rekey is supported (d3) */ |
| 1062 |
if (mvmvif->rekey_data.valid) { |
| 1063 |
struct iwl_wowlan_kek_kck_material_cmd_v4 kek_kck_cmd = {}; |
| 1064 |
struct iwl_wowlan_kek_kck_material_cmd_v4 *_kek_kck_cmd = |
| 1065 |
&kek_kck_cmd; |
| 1066 |
struct wowlan_key_gtk_type_iter gtk_type_data = { |
| 1067 |
.kek_kck_cmd = _kek_kck_cmd, |
| 1068 |
}; |
| 1069 |
|
| 1070 |
cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, |
| 1071 |
WOWLAN_KEK_KCK_MATERIAL, |
| 1072 |
IWL_FW_CMD_VER_UNKNOWN); |
| 1073 |
if (WARN_ON(cmd_ver != 2 && cmd_ver != 3 && cmd_ver != 4 && |
| 1074 |
cmd_ver != IWL_FW_CMD_VER_UNKNOWN)) |
| 1075 |
return -EINVAL; |
| 1076 |
|
| 1077 |
ieee80211_iter_keys(mvm->hw, vif, iwl_mvm_wowlan_gtk_type_iter, |
| 1078 |
>k_type_data); |
| 1079 |
|
| 1080 |
memcpy(kek_kck_cmd.kck, mvmvif->rekey_data.kck, |
| 1081 |
mvmvif->rekey_data.kck_len); |
| 1082 |
kek_kck_cmd.kck_len = cpu_to_le16(mvmvif->rekey_data.kck_len); |
| 1083 |
memcpy(kek_kck_cmd.kek, mvmvif->rekey_data.kek, |
| 1084 |
mvmvif->rekey_data.kek_len); |
| 1085 |
kek_kck_cmd.kek_len = cpu_to_le16(mvmvif->rekey_data.kek_len); |
| 1086 |
kek_kck_cmd.replay_ctr = mvmvif->rekey_data.replay_ctr; |
| 1087 |
kek_kck_cmd.akm = cpu_to_le32(mvmvif->rekey_data.akm); |
| 1088 |
kek_kck_cmd.sta_id = cpu_to_le32(mvm_link->ap_sta_id); |
| 1089 |
|
| 1090 |
if (cmd_ver == 4) { |
| 1091 |
cmd_size = sizeof(struct iwl_wowlan_kek_kck_material_cmd_v4); |
| 1092 |
} else { |
| 1093 |
if (cmd_ver == 3) |
| 1094 |
cmd_size = |
| 1095 |
sizeof(struct iwl_wowlan_kek_kck_material_cmd_v3); |
| 1096 |
else |
| 1097 |
cmd_size = |
| 1098 |
sizeof(struct iwl_wowlan_kek_kck_material_cmd_v2); |
| 1099 |
/* skip the sta_id at the beginning */ |
| 1100 |
_kek_kck_cmd = (void *) |
| 1101 |
((u8 *)_kek_kck_cmd + sizeof(kek_kck_cmd.sta_id)); |
| 1102 |
} |
| 1103 |
|
| 1104 |
IWL_DEBUG_WOWLAN(mvm, "setting akm %d\n", |
| 1105 |
mvmvif->rekey_data.akm); |
| 1106 |
|
| 1107 |
ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_KEK_KCK_MATERIAL, |
| 1108 |
CMD_ASYNC, cmd_size, _kek_kck_cmd); |
| 1109 |
if (ret) |
| 1110 |
return ret; |
| 1111 |
} |
| 1112 |
|
| 1113 |
return 0; |
| 1114 |
} |
| 1115 |
|
| 1116 |
static int |
| 1117 |
iwl_mvm_wowlan_config(struct iwl_mvm *mvm, |
| 1118 |
struct cfg80211_wowlan *wowlan, |
| 1119 |
struct iwl_wowlan_config_cmd_v6 *wowlan_config_cmd_v6, |
| 1120 |
struct ieee80211_vif *vif, struct iwl_mvm_vif *mvmvif, |
| 1121 |
struct iwl_mvm_vif_link_info *mvm_link, |
| 1122 |
struct ieee80211_sta *ap_sta) |
| 1123 |
{ |
| 1124 |
int ret; |
| 1125 |
bool unified_image = fw_has_capa(&mvm->fw->ucode_capa, |
| 1126 |
IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
| 1127 |
|
| 1128 |
mvm->offload_tid = wowlan_config_cmd_v6->offloading_tid; |
| 1129 |
|
| 1130 |
if (!unified_image) { |
| 1131 |
ret = iwl_mvm_switch_to_d3(mvm); |
| 1132 |
if (ret) |
| 1133 |
return ret; |
| 1134 |
|
| 1135 |
ret = iwl_mvm_d3_reprogram(mvm, vif, ap_sta); |
| 1136 |
if (ret) |
| 1137 |
return ret; |
| 1138 |
} |
| 1139 |
|
| 1140 |
ret = iwl_mvm_wowlan_config_key_params(mvm, vif, mvm_link); |
| 1141 |
if (ret) |
| 1142 |
return ret; |
| 1143 |
|
| 1144 |
if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_CONFIGURATION, 0) > 6) { |
| 1145 |
struct iwl_wowlan_config_cmd wowlan_config_cmd = { |
| 1146 |
.wakeup_filter = wowlan_config_cmd_v6->wakeup_filter, |
| 1147 |
.wowlan_ba_teardown_tids = |
| 1148 |
wowlan_config_cmd_v6->wowlan_ba_teardown_tids, |
| 1149 |
.is_11n_connection = |
| 1150 |
wowlan_config_cmd_v6->is_11n_connection, |
| 1151 |
.offloading_tid = wowlan_config_cmd_v6->offloading_tid, |
| 1152 |
.flags = wowlan_config_cmd_v6->flags, |
| 1153 |
.sta_id = wowlan_config_cmd_v6->sta_id, |
| 1154 |
}; |
| 1155 |
|
| 1156 |
ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0, |
| 1157 |
sizeof(wowlan_config_cmd), |
| 1158 |
&wowlan_config_cmd); |
| 1159 |
} else { |
| 1160 |
ret = iwl_mvm_send_cmd_pdu(mvm, WOWLAN_CONFIGURATION, 0, |
| 1161 |
sizeof(*wowlan_config_cmd_v6), |
| 1162 |
wowlan_config_cmd_v6); |
| 1163 |
} |
| 1164 |
if (ret) |
| 1165 |
return ret; |
| 1166 |
|
| 1167 |
if (fw_has_api(&mvm->fw->ucode_capa, |
| 1168 |
IWL_UCODE_TLV_API_WOWLAN_TCP_SYN_WAKE)) |
| 1169 |
ret = iwl_mvm_send_patterns(mvm, mvm_link, wowlan); |
| 1170 |
else |
| 1171 |
ret = iwl_mvm_send_patterns_v1(mvm, wowlan); |
| 1172 |
if (ret) |
| 1173 |
return ret; |
| 1174 |
|
| 1175 |
return iwl_mvm_send_proto_offload(mvm, vif, false, true, 0, |
| 1176 |
mvm_link->ap_sta_id); |
| 1177 |
} |
| 1178 |
|
| 1179 |
static int |
| 1180 |
iwl_mvm_netdetect_config(struct iwl_mvm *mvm, |
| 1181 |
struct cfg80211_wowlan *wowlan, |
| 1182 |
struct cfg80211_sched_scan_request *nd_config, |
| 1183 |
struct ieee80211_vif *vif) |
| 1184 |
{ |
| 1185 |
int ret; |
| 1186 |
bool unified_image = fw_has_capa(&mvm->fw->ucode_capa, |
| 1187 |
IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
| 1188 |
|
| 1189 |
if (!unified_image) { |
| 1190 |
ret = iwl_mvm_switch_to_d3(mvm); |
| 1191 |
if (ret) |
| 1192 |
return ret; |
| 1193 |
} else { |
| 1194 |
/* In theory, we wouldn't have to stop a running sched |
| 1195 |
* scan in order to start another one (for |
| 1196 |
* net-detect). But in practice this doesn't seem to |
| 1197 |
* work properly, so stop any running sched_scan now. |
| 1198 |
*/ |
| 1199 |
ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, true); |
| 1200 |
if (ret) |
| 1201 |
return ret; |
| 1202 |
} |
| 1203 |
|
| 1204 |
ret = iwl_mvm_sched_scan_start(mvm, vif, nd_config, &mvm->nd_ies, |
| 1205 |
IWL_MVM_SCAN_NETDETECT); |
| 1206 |
if (ret) |
| 1207 |
return ret; |
| 1208 |
|
| 1209 |
if (WARN_ON(mvm->nd_match_sets || mvm->nd_channels)) |
| 1210 |
return -EBUSY; |
| 1211 |
|
| 1212 |
/* save the sched scan matchsets... */ |
| 1213 |
if (nd_config->n_match_sets) { |
| 1214 |
mvm->nd_match_sets = kmemdup(nd_config->match_sets, |
| 1215 |
sizeof(*nd_config->match_sets) * |
| 1216 |
nd_config->n_match_sets, |
| 1217 |
GFP_KERNEL); |
| 1218 |
if (mvm->nd_match_sets) |
| 1219 |
mvm->n_nd_match_sets = nd_config->n_match_sets; |
| 1220 |
} |
| 1221 |
|
| 1222 |
/* ...and the sched scan channels for later reporting */ |
| 1223 |
mvm->nd_channels = kmemdup(nd_config->channels, |
| 1224 |
sizeof(*nd_config->channels) * |
| 1225 |
nd_config->n_channels, |
| 1226 |
GFP_KERNEL); |
| 1227 |
if (mvm->nd_channels) |
| 1228 |
mvm->n_nd_channels = nd_config->n_channels; |
| 1229 |
|
| 1230 |
return 0; |
| 1231 |
} |
| 1232 |
|
| 1233 |
static void iwl_mvm_free_nd(struct iwl_mvm *mvm) |
| 1234 |
{ |
| 1235 |
kfree(mvm->nd_match_sets); |
| 1236 |
mvm->nd_match_sets = NULL; |
| 1237 |
mvm->n_nd_match_sets = 0; |
| 1238 |
kfree(mvm->nd_channels); |
| 1239 |
mvm->nd_channels = NULL; |
| 1240 |
mvm->n_nd_channels = 0; |
| 1241 |
} |
| 1242 |
|
| 1243 |
static int __iwl_mvm_suspend(struct ieee80211_hw *hw, |
| 1244 |
struct cfg80211_wowlan *wowlan) |
| 1245 |
{ |
| 1246 |
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1247 |
struct ieee80211_vif *vif = NULL; |
| 1248 |
struct iwl_mvm_vif *mvmvif = NULL; |
| 1249 |
struct ieee80211_sta *ap_sta = NULL; |
| 1250 |
struct iwl_d3_manager_config d3_cfg_cmd = { |
| 1251 |
/* |
| 1252 |
* Program the minimum sleep time to 10 seconds, as many |
| 1253 |
* platforms have issues processing a wakeup signal while |
| 1254 |
* still being in the process of suspending. |
| 1255 |
*/ |
| 1256 |
.min_sleep_time = cpu_to_le32(10 * 1000 * 1000), |
| 1257 |
}; |
| 1258 |
int ret; |
| 1259 |
int len __maybe_unused; |
| 1260 |
bool unified_image = fw_has_capa(&mvm->fw->ucode_capa, |
| 1261 |
IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
| 1262 |
|
| 1263 |
if (!wowlan) { |
| 1264 |
/* mac80211 shouldn't get here */ |
| 1265 |
WARN_ON(1); |
| 1266 |
return -EINVAL; |
| 1267 |
} |
| 1268 |
|
| 1269 |
vif = iwl_mvm_get_bss_vif(mvm); |
| 1270 |
if (IS_ERR_OR_NULL(vif)) |
| 1271 |
return 1; |
| 1272 |
|
| 1273 |
mutex_lock(&mvm->mutex); |
| 1274 |
|
| 1275 |
set_bit(IWL_MVM_STATUS_IN_D3, &mvm->status); |
| 1276 |
|
| 1277 |
synchronize_net(); |
| 1278 |
|
| 1279 |
mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1280 |
|
| 1281 |
if (mvmvif->deflink.ap_sta_id == IWL_INVALID_STA) { |
| 1282 |
/* if we're not associated, this must be netdetect */ |
| 1283 |
if (!wowlan->nd_config) { |
| 1284 |
ret = 1; |
| 1285 |
goto out_noreset; |
| 1286 |
} |
| 1287 |
|
| 1288 |
ret = iwl_mvm_netdetect_config( |
| 1289 |
mvm, wowlan, wowlan->nd_config, vif); |
| 1290 |
if (ret) |
| 1291 |
goto out; |
| 1292 |
|
| 1293 |
mvm->net_detect = true; |
| 1294 |
} else { |
| 1295 |
struct iwl_wowlan_config_cmd_v6 wowlan_config_cmd = { |
| 1296 |
.offloading_tid = 0, |
| 1297 |
}; |
| 1298 |
|
| 1299 |
wowlan_config_cmd.sta_id = mvmvif->deflink.ap_sta_id; |
| 1300 |
|
| 1301 |
ap_sta = rcu_dereference_protected( |
| 1302 |
mvm->fw_id_to_mac_id[mvmvif->deflink.ap_sta_id], |
| 1303 |
lockdep_is_held(&mvm->mutex)); |
| 1304 |
if (IS_ERR_OR_NULL(ap_sta)) { |
| 1305 |
ret = -EINVAL; |
| 1306 |
goto out_noreset; |
| 1307 |
} |
| 1308 |
|
| 1309 |
ret = iwl_mvm_sta_ensure_queue( |
| 1310 |
mvm, ap_sta->txq[wowlan_config_cmd.offloading_tid]); |
| 1311 |
if (ret) |
| 1312 |
goto out_noreset; |
| 1313 |
|
| 1314 |
ret = iwl_mvm_get_wowlan_config(mvm, wowlan, &wowlan_config_cmd, |
| 1315 |
vif, mvmvif, ap_sta); |
| 1316 |
if (ret) |
| 1317 |
goto out_noreset; |
| 1318 |
ret = iwl_mvm_wowlan_config(mvm, wowlan, &wowlan_config_cmd, |
| 1319 |
vif, mvmvif, &mvmvif->deflink, |
| 1320 |
ap_sta); |
| 1321 |
if (ret) |
| 1322 |
goto out; |
| 1323 |
|
| 1324 |
mvm->net_detect = false; |
| 1325 |
} |
| 1326 |
|
| 1327 |
ret = iwl_mvm_power_update_device(mvm); |
| 1328 |
if (ret) |
| 1329 |
goto out; |
| 1330 |
|
| 1331 |
ret = iwl_mvm_power_update_mac(mvm); |
| 1332 |
if (ret) |
| 1333 |
goto out; |
| 1334 |
|
| 1335 |
#ifdef CONFIG_IWLWIFI_DEBUGFS |
| 1336 |
if (mvm->d3_wake_sysassert) |
| 1337 |
d3_cfg_cmd.wakeup_flags |= |
| 1338 |
cpu_to_le32(IWL_WAKEUP_D3_CONFIG_FW_ERROR); |
| 1339 |
#endif |
| 1340 |
|
| 1341 |
/* |
| 1342 |
* Prior to 9000 device family the driver needs to stop the dbg |
| 1343 |
* recording before entering D3. In later devices the FW stops the |
| 1344 |
* recording automatically. |
| 1345 |
*/ |
| 1346 |
if (mvm->trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_9000) |
| 1347 |
iwl_fw_dbg_stop_restart_recording(&mvm->fwrt, NULL, true); |
| 1348 |
|
| 1349 |
/* must be last -- this switches firmware state */ |
| 1350 |
ret = iwl_mvm_send_cmd_pdu(mvm, D3_CONFIG_CMD, 0, sizeof(d3_cfg_cmd), |
| 1351 |
&d3_cfg_cmd); |
| 1352 |
if (ret) |
| 1353 |
goto out; |
| 1354 |
|
| 1355 |
clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status); |
| 1356 |
|
| 1357 |
ret = iwl_trans_d3_suspend(mvm->trans, !unified_image); |
| 1358 |
out: |
| 1359 |
if (ret < 0) { |
| 1360 |
iwl_mvm_free_nd(mvm); |
| 1361 |
|
| 1362 |
clear_bit(IWL_MVM_STATUS_IN_D3, &mvm->status); |
| 1363 |
} |
| 1364 |
out_noreset: |
| 1365 |
mutex_unlock(&mvm->mutex); |
| 1366 |
|
| 1367 |
return ret; |
| 1368 |
} |
| 1369 |
|
| 1370 |
int iwl_mvm_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan) |
| 1371 |
{ |
| 1372 |
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 1373 |
|
| 1374 |
iwl_mvm_pause_tcm(mvm, true); |
| 1375 |
|
| 1376 |
mutex_lock(&mvm->mutex); |
| 1377 |
iwl_fw_runtime_suspend(&mvm->fwrt); |
| 1378 |
mutex_unlock(&mvm->mutex); |
| 1379 |
|
| 1380 |
return __iwl_mvm_suspend(hw, wowlan); |
| 1381 |
} |
| 1382 |
|
| 1383 |
struct iwl_multicast_key_data { |
| 1384 |
u8 key[WOWLAN_KEY_MAX_SIZE]; |
| 1385 |
u8 len; |
| 1386 |
u8 flags; |
| 1387 |
u8 id; |
| 1388 |
u8 ipn[6]; |
| 1389 |
}; |
| 1390 |
|
| 1391 |
/* converted data from the different status responses */ |
| 1392 |
struct iwl_wowlan_status_data { |
| 1393 |
u64 replay_ctr; |
| 1394 |
u32 num_of_gtk_rekeys; |
| 1395 |
u32 received_beacons; |
| 1396 |
u32 wakeup_reasons; |
| 1397 |
u32 wake_packet_length; |
| 1398 |
u32 wake_packet_bufsize; |
| 1399 |
u16 pattern_number; |
| 1400 |
u16 non_qos_seq_ctr; |
| 1401 |
u16 qos_seq_ctr[8]; |
| 1402 |
u8 tid_tear_down; |
| 1403 |
u8 tid_offloaded_tx; |
| 1404 |
|
| 1405 |
struct { |
| 1406 |
/* including RX MIC key for TKIP */ |
| 1407 |
u8 key[WOWLAN_KEY_MAX_SIZE]; |
| 1408 |
u8 len; |
| 1409 |
u8 flags; |
| 1410 |
u8 id; |
| 1411 |
} gtk[WOWLAN_GTK_KEYS_NUM]; |
| 1412 |
|
| 1413 |
struct { |
| 1414 |
/* |
| 1415 |
* We store both the TKIP and AES representations |
| 1416 |
* coming from the firmware because we decode the |
| 1417 |
* data from there before we iterate the keys and |
| 1418 |
* know which one we need. |
| 1419 |
*/ |
| 1420 |
struct { |
| 1421 |
struct ieee80211_key_seq seq[IWL_MAX_TID_COUNT]; |
| 1422 |
} tkip, aes; |
| 1423 |
|
| 1424 |
/* |
| 1425 |
* We use -1 for when we have valid data but don't know |
| 1426 |
* the key ID from firmware, and thus it needs to be |
| 1427 |
* installed with the last key (depending on rekeying). |
| 1428 |
*/ |
| 1429 |
s8 key_id; |
| 1430 |
bool valid; |
| 1431 |
} gtk_seq[2]; |
| 1432 |
|
| 1433 |
struct { |
| 1434 |
/* Same as above */ |
| 1435 |
struct { |
| 1436 |
struct ieee80211_key_seq seq[IWL_MAX_TID_COUNT]; |
| 1437 |
u64 tx_pn; |
| 1438 |
} tkip, aes; |
| 1439 |
} ptk; |
| 1440 |
|
| 1441 |
struct iwl_multicast_key_data igtk; |
| 1442 |
struct iwl_multicast_key_data bigtk[WOWLAN_BIGTK_KEYS_NUM]; |
| 1443 |
|
| 1444 |
u8 *wake_packet; |
| 1445 |
}; |
| 1446 |
|
| 1447 |
static void iwl_mvm_report_wakeup_reasons(struct iwl_mvm *mvm, |
| 1448 |
struct ieee80211_vif *vif, |
| 1449 |
struct iwl_wowlan_status_data *status) |
| 1450 |
{ |
| 1451 |
struct sk_buff *pkt = NULL; |
| 1452 |
struct cfg80211_wowlan_wakeup wakeup = { |
| 1453 |
.pattern_idx = -1, |
| 1454 |
}; |
| 1455 |
struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup; |
| 1456 |
u32 reasons = status->wakeup_reasons; |
| 1457 |
|
| 1458 |
if (reasons == IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) { |
| 1459 |
wakeup_report = NULL; |
| 1460 |
goto report; |
| 1461 |
} |
| 1462 |
|
| 1463 |
pm_wakeup_event(mvm->dev, 0); |
| 1464 |
|
| 1465 |
if (reasons & IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET) |
| 1466 |
wakeup.magic_pkt = true; |
| 1467 |
|
| 1468 |
if (reasons & IWL_WOWLAN_WAKEUP_BY_PATTERN) |
| 1469 |
wakeup.pattern_idx = |
| 1470 |
status->pattern_number; |
| 1471 |
|
| 1472 |
if (reasons & (IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON | |
| 1473 |
IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH | |
| 1474 |
IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE)) |
| 1475 |
wakeup.disconnect = true; |
| 1476 |
|
| 1477 |
if (reasons & IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE) |
| 1478 |
wakeup.gtk_rekey_failure = true; |
| 1479 |
|
| 1480 |
if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED) |
| 1481 |
wakeup.rfkill_release = true; |
| 1482 |
|
| 1483 |
if (reasons & IWL_WOWLAN_WAKEUP_BY_EAPOL_REQUEST) |
| 1484 |
wakeup.eap_identity_req = true; |
| 1485 |
|
| 1486 |
if (reasons & IWL_WOWLAN_WAKEUP_BY_FOUR_WAY_HANDSHAKE) |
| 1487 |
wakeup.four_way_handshake = true; |
| 1488 |
|
| 1489 |
if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_LINK_LOSS) |
| 1490 |
wakeup.tcp_connlost = true; |
| 1491 |
|
| 1492 |
if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_SIGNATURE_TABLE) |
| 1493 |
wakeup.tcp_nomoretokens = true; |
| 1494 |
|
| 1495 |
if (reasons & IWL_WOWLAN_WAKEUP_BY_REM_WAKE_WAKEUP_PACKET) |
| 1496 |
wakeup.tcp_match = true; |
| 1497 |
|
| 1498 |
if (reasons & IWL_WAKEUP_BY_11W_UNPROTECTED_DEAUTH_OR_DISASSOC) |
| 1499 |
wakeup.unprot_deauth_disassoc = true; |
| 1500 |
|
| 1501 |
if (status->wake_packet) { |
| 1502 |
int pktsize = status->wake_packet_bufsize; |
| 1503 |
int pktlen = status->wake_packet_length; |
| 1504 |
const u8 *pktdata = status->wake_packet; |
| 1505 |
const struct ieee80211_hdr *hdr = (const void *)pktdata; |
| 1506 |
int truncated = pktlen - pktsize; |
| 1507 |
|
| 1508 |
/* this would be a firmware bug */ |
| 1509 |
if (WARN_ON_ONCE(truncated < 0)) |
| 1510 |
truncated = 0; |
| 1511 |
|
| 1512 |
if (ieee80211_is_data(hdr->frame_control)) { |
| 1513 |
int hdrlen = ieee80211_hdrlen(hdr->frame_control); |
| 1514 |
int ivlen = 0, icvlen = 4; /* also FCS */ |
| 1515 |
|
| 1516 |
pkt = alloc_skb(pktsize, GFP_KERNEL); |
| 1517 |
if (!pkt) |
| 1518 |
goto report; |
| 1519 |
|
| 1520 |
skb_put_data(pkt, pktdata, hdrlen); |
| 1521 |
pktdata += hdrlen; |
| 1522 |
pktsize -= hdrlen; |
| 1523 |
|
| 1524 |
if (ieee80211_has_protected(hdr->frame_control)) { |
| 1525 |
/* |
| 1526 |
* This is unlocked and using gtk_i(c)vlen, |
| 1527 |
* but since everything is under RTNL still |
| 1528 |
* that's not really a problem - changing |
| 1529 |
* it would be difficult. |
| 1530 |
*/ |
| 1531 |
if (is_multicast_ether_addr(hdr->addr1)) { |
| 1532 |
ivlen = mvm->gtk_ivlen; |
| 1533 |
icvlen += mvm->gtk_icvlen; |
| 1534 |
} else { |
| 1535 |
ivlen = mvm->ptk_ivlen; |
| 1536 |
icvlen += mvm->ptk_icvlen; |
| 1537 |
} |
| 1538 |
} |
| 1539 |
|
| 1540 |
/* if truncated, FCS/ICV is (partially) gone */ |
| 1541 |
if (truncated >= icvlen) { |
| 1542 |
icvlen = 0; |
| 1543 |
truncated -= icvlen; |
| 1544 |
} else { |
| 1545 |
icvlen -= truncated; |
| 1546 |
truncated = 0; |
| 1547 |
} |
| 1548 |
|
| 1549 |
pktsize -= ivlen + icvlen; |
| 1550 |
pktdata += ivlen; |
| 1551 |
|
| 1552 |
skb_put_data(pkt, pktdata, pktsize); |
| 1553 |
|
| 1554 |
if (ieee80211_data_to_8023(pkt, vif->addr, vif->type)) |
| 1555 |
goto report; |
| 1556 |
wakeup.packet = pkt->data; |
| 1557 |
wakeup.packet_present_len = pkt->len; |
| 1558 |
wakeup.packet_len = pkt->len - truncated; |
| 1559 |
wakeup.packet_80211 = false; |
| 1560 |
} else { |
| 1561 |
int fcslen = 4; |
| 1562 |
|
| 1563 |
if (truncated >= 4) { |
| 1564 |
truncated -= 4; |
| 1565 |
fcslen = 0; |
| 1566 |
} else { |
| 1567 |
fcslen -= truncated; |
| 1568 |
truncated = 0; |
| 1569 |
} |
| 1570 |
pktsize -= fcslen; |
| 1571 |
wakeup.packet = status->wake_packet; |
| 1572 |
wakeup.packet_present_len = pktsize; |
| 1573 |
wakeup.packet_len = pktlen - truncated; |
| 1574 |
wakeup.packet_80211 = true; |
| 1575 |
} |
| 1576 |
} |
| 1577 |
|
| 1578 |
report: |
| 1579 |
ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL); |
| 1580 |
kfree_skb(pkt); |
| 1581 |
} |
| 1582 |
|
| 1583 |
static void iwl_mvm_le64_to_aes_seq(__le64 le_pn, struct ieee80211_key_seq *seq) |
| 1584 |
{ |
| 1585 |
u64 pn = le64_to_cpu(le_pn); |
| 1586 |
|
| 1587 |
seq->ccmp.pn[0] = pn >> 40; |
| 1588 |
seq->ccmp.pn[1] = pn >> 32; |
| 1589 |
seq->ccmp.pn[2] = pn >> 24; |
| 1590 |
seq->ccmp.pn[3] = pn >> 16; |
| 1591 |
seq->ccmp.pn[4] = pn >> 8; |
| 1592 |
seq->ccmp.pn[5] = pn; |
| 1593 |
} |
| 1594 |
|
| 1595 |
static void iwl_mvm_aes_sc_to_seq(struct aes_sc *sc, |
| 1596 |
struct ieee80211_key_seq *seq) |
| 1597 |
{ |
| 1598 |
iwl_mvm_le64_to_aes_seq(sc->pn, seq); |
| 1599 |
} |
| 1600 |
|
| 1601 |
static void iwl_mvm_le64_to_tkip_seq(__le64 le_pn, struct ieee80211_key_seq *seq) |
| 1602 |
{ |
| 1603 |
u64 pn = le64_to_cpu(le_pn); |
| 1604 |
|
| 1605 |
seq->tkip.iv16 = (u16)pn; |
| 1606 |
seq->tkip.iv32 = (u32)(pn >> 16); |
| 1607 |
} |
| 1608 |
|
| 1609 |
static void iwl_mvm_tkip_sc_to_seq(struct tkip_sc *sc, |
| 1610 |
struct ieee80211_key_seq *seq) |
| 1611 |
{ |
| 1612 |
seq->tkip.iv32 = le32_to_cpu(sc->iv32); |
| 1613 |
seq->tkip.iv16 = le16_to_cpu(sc->iv16); |
| 1614 |
} |
| 1615 |
|
| 1616 |
static void iwl_mvm_set_key_rx_seq_tids(struct ieee80211_key_conf *key, |
| 1617 |
struct ieee80211_key_seq *seq) |
| 1618 |
{ |
| 1619 |
int tid; |
| 1620 |
|
| 1621 |
for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) |
| 1622 |
ieee80211_set_key_rx_seq(key, tid, &seq[tid]); |
| 1623 |
} |
| 1624 |
|
| 1625 |
static void iwl_mvm_set_aes_ptk_rx_seq(struct iwl_mvm *mvm, |
| 1626 |
struct iwl_wowlan_status_data *status, |
| 1627 |
struct ieee80211_sta *sta, |
| 1628 |
struct ieee80211_key_conf *key) |
| 1629 |
{ |
| 1630 |
struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 1631 |
struct iwl_mvm_key_pn *ptk_pn; |
| 1632 |
int tid; |
| 1633 |
|
| 1634 |
iwl_mvm_set_key_rx_seq_tids(key, status->ptk.aes.seq); |
| 1635 |
|
| 1636 |
if (!iwl_mvm_has_new_rx_api(mvm)) |
| 1637 |
return; |
| 1638 |
|
| 1639 |
|
| 1640 |
rcu_read_lock(); |
| 1641 |
ptk_pn = rcu_dereference(mvmsta->ptk_pn[key->keyidx]); |
| 1642 |
if (WARN_ON(!ptk_pn)) { |
| 1643 |
rcu_read_unlock(); |
| 1644 |
return; |
| 1645 |
} |
| 1646 |
|
| 1647 |
for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { |
| 1648 |
int i; |
| 1649 |
|
| 1650 |
for (i = 1; i < mvm->trans->info.num_rxqs; i++) |
| 1651 |
memcpy(ptk_pn->q[i].pn[tid], |
| 1652 |
status->ptk.aes.seq[tid].ccmp.pn, |
| 1653 |
IEEE80211_CCMP_PN_LEN); |
| 1654 |
} |
| 1655 |
rcu_read_unlock(); |
| 1656 |
} |
| 1657 |
|
| 1658 |
static void iwl_mvm_convert_key_counters(struct iwl_wowlan_status_data *status, |
| 1659 |
union iwl_all_tsc_rsc *sc, u8 key_idx) |
| 1660 |
{ |
| 1661 |
int i; |
| 1662 |
|
| 1663 |
BUILD_BUG_ON(IWL_MAX_TID_COUNT > IWL_MAX_TID_COUNT); |
| 1664 |
BUILD_BUG_ON(IWL_MAX_TID_COUNT > IWL_NUM_RSC); |
| 1665 |
|
| 1666 |
/* GTK RX counters */ |
| 1667 |
for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
| 1668 |
iwl_mvm_tkip_sc_to_seq(&sc->tkip.multicast_rsc[i], |
| 1669 |
&status->gtk_seq[0].tkip.seq[i]); |
| 1670 |
iwl_mvm_aes_sc_to_seq(&sc->aes.multicast_rsc[i], |
| 1671 |
&status->gtk_seq[0].aes.seq[i]); |
| 1672 |
} |
| 1673 |
status->gtk_seq[0].valid = true; |
| 1674 |
status->gtk_seq[0].key_id = key_idx; |
| 1675 |
|
| 1676 |
/* PTK TX counter */ |
| 1677 |
status->ptk.tkip.tx_pn = (u64)le16_to_cpu(sc->tkip.tsc.iv16) | |
| 1678 |
((u64)le32_to_cpu(sc->tkip.tsc.iv32) << 16); |
| 1679 |
status->ptk.aes.tx_pn = le64_to_cpu(sc->aes.tsc.pn); |
| 1680 |
|
| 1681 |
/* PTK RX counters */ |
| 1682 |
for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
| 1683 |
iwl_mvm_tkip_sc_to_seq(&sc->tkip.unicast_rsc[i], |
| 1684 |
&status->ptk.tkip.seq[i]); |
| 1685 |
iwl_mvm_aes_sc_to_seq(&sc->aes.unicast_rsc[i], |
| 1686 |
&status->ptk.aes.seq[i]); |
| 1687 |
} |
| 1688 |
} |
| 1689 |
|
| 1690 |
static void |
| 1691 |
iwl_mvm_convert_key_counters_v5_gtk_seq(struct iwl_wowlan_status_data *status, |
| 1692 |
struct iwl_wowlan_all_rsc_tsc_v5 *sc, |
| 1693 |
unsigned int idx, unsigned int key_id) |
| 1694 |
{ |
| 1695 |
int tid; |
| 1696 |
|
| 1697 |
for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { |
| 1698 |
iwl_mvm_le64_to_tkip_seq(sc->mcast_rsc[idx][tid], |
| 1699 |
&status->gtk_seq[idx].tkip.seq[tid]); |
| 1700 |
iwl_mvm_le64_to_aes_seq(sc->mcast_rsc[idx][tid], |
| 1701 |
&status->gtk_seq[idx].aes.seq[tid]); |
| 1702 |
} |
| 1703 |
|
| 1704 |
status->gtk_seq[idx].valid = true; |
| 1705 |
status->gtk_seq[idx].key_id = key_id; |
| 1706 |
} |
| 1707 |
|
| 1708 |
static void |
| 1709 |
iwl_mvm_convert_key_counters_v5(struct iwl_wowlan_status_data *status, |
| 1710 |
struct iwl_wowlan_all_rsc_tsc_v5 *sc) |
| 1711 |
{ |
| 1712 |
int i, tid; |
| 1713 |
|
| 1714 |
BUILD_BUG_ON(IWL_MAX_TID_COUNT > IWL_MAX_TID_COUNT); |
| 1715 |
BUILD_BUG_ON(IWL_MAX_TID_COUNT > IWL_NUM_RSC); |
| 1716 |
BUILD_BUG_ON(ARRAY_SIZE(sc->mcast_rsc) != ARRAY_SIZE(status->gtk_seq)); |
| 1717 |
|
| 1718 |
/* GTK RX counters */ |
| 1719 |
for (i = 0; i < ARRAY_SIZE(sc->mcast_key_id_map); i++) { |
| 1720 |
u8 entry = sc->mcast_key_id_map[i]; |
| 1721 |
|
| 1722 |
if (entry < ARRAY_SIZE(sc->mcast_rsc)) |
| 1723 |
iwl_mvm_convert_key_counters_v5_gtk_seq(status, sc, |
| 1724 |
entry, i); |
| 1725 |
} |
| 1726 |
|
| 1727 |
/* PTK TX counters not needed, assigned in device */ |
| 1728 |
|
| 1729 |
/* PTK RX counters */ |
| 1730 |
for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) { |
| 1731 |
iwl_mvm_le64_to_tkip_seq(sc->ucast_rsc[tid], |
| 1732 |
&status->ptk.tkip.seq[tid]); |
| 1733 |
iwl_mvm_le64_to_aes_seq(sc->ucast_rsc[tid], |
| 1734 |
&status->ptk.aes.seq[tid]); |
| 1735 |
} |
| 1736 |
} |
| 1737 |
|
| 1738 |
static void iwl_mvm_set_key_rx_seq_idx(struct ieee80211_key_conf *key, |
| 1739 |
struct iwl_wowlan_status_data *status, |
| 1740 |
int idx) |
| 1741 |
{ |
| 1742 |
switch (key->cipher) { |
| 1743 |
case WLAN_CIPHER_SUITE_CCMP: |
| 1744 |
case WLAN_CIPHER_SUITE_GCMP: |
| 1745 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 1746 |
iwl_mvm_set_key_rx_seq_tids(key, status->gtk_seq[idx].aes.seq); |
| 1747 |
break; |
| 1748 |
case WLAN_CIPHER_SUITE_TKIP: |
| 1749 |
iwl_mvm_set_key_rx_seq_tids(key, status->gtk_seq[idx].tkip.seq); |
| 1750 |
break; |
| 1751 |
default: |
| 1752 |
WARN_ON(1); |
| 1753 |
} |
| 1754 |
} |
| 1755 |
|
| 1756 |
static void iwl_mvm_set_key_rx_seq(struct ieee80211_key_conf *key, |
| 1757 |
struct iwl_wowlan_status_data *status) |
| 1758 |
{ |
| 1759 |
int i; |
| 1760 |
|
| 1761 |
for (i = 0; i < ARRAY_SIZE(status->gtk_seq); i++) { |
| 1762 |
if (!status->gtk_seq[i].valid) |
| 1763 |
continue; |
| 1764 |
|
| 1765 |
if (status->gtk_seq[i].key_id == key->keyidx) |
| 1766 |
iwl_mvm_set_key_rx_seq_idx(key, status, i); |
| 1767 |
} |
| 1768 |
} |
| 1769 |
|
| 1770 |
struct iwl_mvm_d3_gtk_iter_data { |
| 1771 |
struct iwl_mvm *mvm; |
| 1772 |
struct iwl_wowlan_status_data *status; |
| 1773 |
}; |
| 1774 |
|
| 1775 |
static void |
| 1776 |
iwl_mvm_d3_set_igtk_bigtk_ipn(const struct iwl_multicast_key_data *key, |
| 1777 |
struct ieee80211_key_seq *seq, u32 cipher) |
| 1778 |
{ |
| 1779 |
switch (cipher) { |
| 1780 |
case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 1781 |
case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 1782 |
BUILD_BUG_ON(sizeof(seq->aes_gmac.pn) != sizeof(key->ipn)); |
| 1783 |
memcpy(seq->aes_gmac.pn, key->ipn, sizeof(seq->aes_gmac.pn)); |
| 1784 |
break; |
| 1785 |
case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 1786 |
case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1787 |
BUILD_BUG_ON(sizeof(seq->aes_cmac.pn) != sizeof(key->ipn)); |
| 1788 |
memcpy(seq->aes_cmac.pn, key->ipn, sizeof(seq->aes_cmac.pn)); |
| 1789 |
break; |
| 1790 |
default: |
| 1791 |
WARN_ON(1); |
| 1792 |
} |
| 1793 |
} |
| 1794 |
|
| 1795 |
static void |
| 1796 |
iwl_mvm_d3_update_igtk_bigtk(struct iwl_wowlan_status_data *status, |
| 1797 |
struct ieee80211_key_conf *key, |
| 1798 |
struct iwl_multicast_key_data *key_data) |
| 1799 |
{ |
| 1800 |
struct ieee80211_key_seq seq; |
| 1801 |
|
| 1802 |
iwl_mvm_d3_set_igtk_bigtk_ipn(key_data, &seq, key->cipher); |
| 1803 |
ieee80211_set_key_rx_seq(key, 0, &seq); |
| 1804 |
} |
| 1805 |
|
| 1806 |
static void iwl_mvm_d3_update_keys(struct ieee80211_hw *hw, |
| 1807 |
struct ieee80211_vif *vif, |
| 1808 |
struct ieee80211_sta *sta, |
| 1809 |
struct ieee80211_key_conf *key, |
| 1810 |
void *_data) |
| 1811 |
{ |
| 1812 |
struct iwl_mvm_d3_gtk_iter_data *data = _data; |
| 1813 |
struct iwl_wowlan_status_data *status = data->status; |
| 1814 |
s8 keyidx; |
| 1815 |
|
| 1816 |
switch (key->cipher) { |
| 1817 |
case WLAN_CIPHER_SUITE_WEP40: |
| 1818 |
case WLAN_CIPHER_SUITE_WEP104: |
| 1819 |
/* ignore WEP completely, nothing to do */ |
| 1820 |
return; |
| 1821 |
case WLAN_CIPHER_SUITE_CCMP: |
| 1822 |
case WLAN_CIPHER_SUITE_GCMP: |
| 1823 |
case WLAN_CIPHER_SUITE_GCMP_256: |
| 1824 |
if (sta) { |
| 1825 |
atomic64_set(&key->tx_pn, status->ptk.aes.tx_pn); |
| 1826 |
iwl_mvm_set_aes_ptk_rx_seq(data->mvm, status, sta, key); |
| 1827 |
return; |
| 1828 |
} |
| 1829 |
fallthrough; |
| 1830 |
case WLAN_CIPHER_SUITE_TKIP: |
| 1831 |
if (sta) { |
| 1832 |
atomic64_set(&key->tx_pn, status->ptk.tkip.tx_pn); |
| 1833 |
iwl_mvm_set_key_rx_seq_tids(key, status->ptk.tkip.seq); |
| 1834 |
return; |
| 1835 |
} |
| 1836 |
keyidx = key->keyidx; |
| 1837 |
/* |
| 1838 |
* Update the seq even if there was a rekey. If there was a |
| 1839 |
* rekey, we will update again after replacing the key |
| 1840 |
*/ |
| 1841 |
if ((status->gtk[0].len && keyidx == status->gtk[0].id) || |
| 1842 |
(status->gtk[1].len && keyidx == status->gtk[1].id)) |
| 1843 |
iwl_mvm_set_key_rx_seq(key, status); |
| 1844 |
break; |
| 1845 |
case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 1846 |
case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 1847 |
case WLAN_CIPHER_SUITE_BIP_CMAC_256: |
| 1848 |
case WLAN_CIPHER_SUITE_AES_CMAC: |
| 1849 |
if (key->keyidx == 4 || key->keyidx == 5) { |
| 1850 |
iwl_mvm_d3_update_igtk_bigtk(status, key, |
| 1851 |
&status->igtk); |
| 1852 |
} |
| 1853 |
if (key->keyidx == 6 || key->keyidx == 7) { |
| 1854 |
u8 idx = key->keyidx == status->bigtk[1].id; |
| 1855 |
|
| 1856 |
iwl_mvm_d3_update_igtk_bigtk(status, key, |
| 1857 |
&status->bigtk[idx]); |
| 1858 |
} |
| 1859 |
} |
| 1860 |
} |
| 1861 |
|
| 1862 |
static bool iwl_mvm_gtk_rekey(struct iwl_wowlan_status_data *status, |
| 1863 |
struct ieee80211_vif *vif, |
| 1864 |
struct iwl_mvm *mvm) |
| 1865 |
{ |
| 1866 |
int i, j; |
| 1867 |
struct ieee80211_key_conf *key; |
| 1868 |
|
| 1869 |
for (i = 0; i < ARRAY_SIZE(status->gtk); i++) { |
| 1870 |
if (!status->gtk[i].len) |
| 1871 |
continue; |
| 1872 |
|
| 1873 |
IWL_DEBUG_WOWLAN(mvm, |
| 1874 |
"Received from FW GTK: key index %d\n", |
| 1875 |
status->gtk[i].id); |
| 1876 |
|
| 1877 |
key = ieee80211_gtk_rekey_add(vif, status->gtk[i].id, |
| 1878 |
status->gtk[i].key, |
| 1879 |
sizeof(status->gtk[i].key), -1); |
| 1880 |
if (IS_ERR(key)) { |
| 1881 |
/* FW may send also the old keys */ |
| 1882 |
if (PTR_ERR(key) == -EALREADY) |
| 1883 |
continue; |
| 1884 |
return false; |
| 1885 |
} |
| 1886 |
|
| 1887 |
for (j = 0; j < ARRAY_SIZE(status->gtk_seq); j++) { |
| 1888 |
if (!status->gtk_seq[j].valid || |
| 1889 |
status->gtk_seq[j].key_id != key->keyidx) |
| 1890 |
continue; |
| 1891 |
iwl_mvm_set_key_rx_seq_idx(key, status, j); |
| 1892 |
break; |
| 1893 |
} |
| 1894 |
WARN_ON(j == ARRAY_SIZE(status->gtk_seq)); |
| 1895 |
} |
| 1896 |
|
| 1897 |
return true; |
| 1898 |
} |
| 1899 |
|
| 1900 |
static bool |
| 1901 |
iwl_mvm_d3_igtk_bigtk_rekey_add(struct iwl_wowlan_status_data *status, |
| 1902 |
struct ieee80211_vif *vif, |
| 1903 |
struct iwl_multicast_key_data *key_data) |
| 1904 |
{ |
| 1905 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1906 |
struct ieee80211_key_conf *key_config; |
| 1907 |
struct ieee80211_key_seq seq; |
| 1908 |
s8 keyidx = key_data->id; |
| 1909 |
|
| 1910 |
if (!key_data->len) |
| 1911 |
return true; |
| 1912 |
|
| 1913 |
key_config = ieee80211_gtk_rekey_add(vif, keyidx, key_data->key, |
| 1914 |
sizeof(key_data->key), -1); |
| 1915 |
if (IS_ERR(key_config)) { |
| 1916 |
/* FW may send also the old keys */ |
| 1917 |
return PTR_ERR(key_config) == -EALREADY; |
| 1918 |
} |
| 1919 |
|
| 1920 |
iwl_mvm_d3_set_igtk_bigtk_ipn(key_data, &seq, key_config->cipher); |
| 1921 |
ieee80211_set_key_rx_seq(key_config, 0, &seq); |
| 1922 |
|
| 1923 |
if (keyidx == 4 || keyidx == 5) { |
| 1924 |
if (mvmvif->deflink.igtk) |
| 1925 |
mvmvif->deflink.igtk->hw_key_idx = STA_KEY_IDX_INVALID; |
| 1926 |
mvmvif->deflink.igtk = key_config; |
| 1927 |
} |
| 1928 |
|
| 1929 |
if (vif->type == NL80211_IFTYPE_STATION && (keyidx == 6 || keyidx == 7)) |
| 1930 |
rcu_assign_pointer(mvmvif->bcn_prot.keys[keyidx - 6], |
| 1931 |
key_config); |
| 1932 |
|
| 1933 |
return true; |
| 1934 |
} |
| 1935 |
|
| 1936 |
static int iwl_mvm_lookup_wowlan_status_ver(struct iwl_mvm *mvm) |
| 1937 |
{ |
| 1938 |
u8 notif_ver; |
| 1939 |
|
| 1940 |
if (!fw_has_api(&mvm->fw->ucode_capa, |
| 1941 |
IWL_UCODE_TLV_API_WOWLAN_KEY_MATERIAL)) |
| 1942 |
return 6; |
| 1943 |
|
| 1944 |
/* default to 7 (when we have IWL_UCODE_TLV_API_WOWLAN_KEY_MATERIAL) */ |
| 1945 |
notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, LONG_GROUP, |
| 1946 |
WOWLAN_GET_STATUSES, 0); |
| 1947 |
if (!notif_ver) |
| 1948 |
notif_ver = iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP, |
| 1949 |
WOWLAN_GET_STATUSES, 7); |
| 1950 |
|
| 1951 |
return notif_ver; |
| 1952 |
} |
| 1953 |
|
| 1954 |
static bool iwl_mvm_setup_connection_keep(struct iwl_mvm *mvm, |
| 1955 |
struct ieee80211_vif *vif, |
| 1956 |
struct iwl_wowlan_status_data *status) |
| 1957 |
{ |
| 1958 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1959 |
struct iwl_mvm_d3_gtk_iter_data gtkdata = { |
| 1960 |
.mvm = mvm, |
| 1961 |
.status = status, |
| 1962 |
}; |
| 1963 |
int i; |
| 1964 |
u32 disconnection_reasons = |
| 1965 |
IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON | |
| 1966 |
IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH; |
| 1967 |
|
| 1968 |
if (!status || !vif->bss_conf.bssid) |
| 1969 |
return false; |
| 1970 |
/* |
| 1971 |
* invalidate all other GTKs that might still exist and update |
| 1972 |
* the one that we used |
| 1973 |
*/ |
| 1974 |
ieee80211_iter_keys(mvm->hw, vif, |
| 1975 |
iwl_mvm_d3_update_keys, >kdata); |
| 1976 |
|
| 1977 |
if (status->num_of_gtk_rekeys) { |
| 1978 |
__be64 replay_ctr = cpu_to_be64(status->replay_ctr); |
| 1979 |
|
| 1980 |
IWL_DEBUG_WOWLAN(mvm, "num of GTK rekeying %d\n", |
| 1981 |
status->num_of_gtk_rekeys); |
| 1982 |
|
| 1983 |
if (!iwl_mvm_gtk_rekey(status, vif, mvm)) |
| 1984 |
return false; |
| 1985 |
|
| 1986 |
if (!iwl_mvm_d3_igtk_bigtk_rekey_add(status, vif, |
| 1987 |
&status->igtk)) |
| 1988 |
return false; |
| 1989 |
|
| 1990 |
for (i = 0; i < ARRAY_SIZE(status->bigtk); i++) { |
| 1991 |
if (!iwl_mvm_d3_igtk_bigtk_rekey_add(status, vif, |
| 1992 |
&status->bigtk[i])) |
| 1993 |
return false; |
| 1994 |
} |
| 1995 |
|
| 1996 |
ieee80211_gtk_rekey_notify(vif, vif->bss_conf.bssid, |
| 1997 |
(void *)&replay_ctr, GFP_KERNEL); |
| 1998 |
} |
| 1999 |
|
| 2000 |
if (iwl_fw_lookup_notif_ver(mvm->fw, LONG_GROUP, |
| 2001 |
WOWLAN_GET_STATUSES, |
| 2002 |
IWL_FW_CMD_VER_UNKNOWN) < 10) { |
| 2003 |
mvmvif->seqno_valid = true; |
| 2004 |
/* +0x10 because the set API expects next-to-use, not last-used */ |
| 2005 |
mvmvif->seqno = status->non_qos_seq_ctr + 0x10; |
| 2006 |
} |
| 2007 |
|
| 2008 |
if (status->wakeup_reasons & disconnection_reasons) |
| 2009 |
return false; |
| 2010 |
|
| 2011 |
return true; |
| 2012 |
} |
| 2013 |
|
| 2014 |
static void iwl_mvm_convert_gtk_v2(struct iwl_wowlan_status_data *status, |
| 2015 |
struct iwl_wowlan_gtk_status_v2 *data) |
| 2016 |
{ |
| 2017 |
BUILD_BUG_ON(sizeof(status->gtk[0].key) < sizeof(data->key)); |
| 2018 |
BUILD_BUG_ON(NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY + |
| 2019 |
sizeof(data->tkip_mic_key) > |
| 2020 |
sizeof(status->gtk[0].key)); |
| 2021 |
|
| 2022 |
status->gtk[0].len = data->key_len; |
| 2023 |
status->gtk[0].flags = data->key_flags; |
| 2024 |
status->gtk[0].id = status->gtk[0].flags & IWL_WOWLAN_GTK_IDX_MASK; |
| 2025 |
|
| 2026 |
memcpy(status->gtk[0].key, data->key, sizeof(data->key)); |
| 2027 |
|
| 2028 |
/* if it's as long as the TKIP encryption key, copy MIC key */ |
| 2029 |
if (status->gtk[0].len == NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY) |
| 2030 |
memcpy(status->gtk[0].key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY, |
| 2031 |
data->tkip_mic_key, sizeof(data->tkip_mic_key)); |
| 2032 |
} |
| 2033 |
|
| 2034 |
static void iwl_mvm_convert_gtk_v3(struct iwl_wowlan_status_data *status, |
| 2035 |
struct iwl_wowlan_gtk_status_v3 *data) |
| 2036 |
{ |
| 2037 |
int data_idx, status_idx = 0; |
| 2038 |
|
| 2039 |
BUILD_BUG_ON(sizeof(status->gtk[0].key) < sizeof(data[0].key)); |
| 2040 |
BUILD_BUG_ON(NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY + |
| 2041 |
sizeof(data[0].tkip_mic_key) > |
| 2042 |
sizeof(status->gtk[0].key)); |
| 2043 |
BUILD_BUG_ON(ARRAY_SIZE(status->gtk) < WOWLAN_GTK_KEYS_NUM); |
| 2044 |
for (data_idx = 0; data_idx < ARRAY_SIZE(status->gtk); data_idx++) { |
| 2045 |
if (!(data[data_idx].key_len)) |
| 2046 |
continue; |
| 2047 |
status->gtk[status_idx].len = data[data_idx].key_len; |
| 2048 |
status->gtk[status_idx].flags = data[data_idx].key_flags; |
| 2049 |
status->gtk[status_idx].id = status->gtk[status_idx].flags & |
| 2050 |
IWL_WOWLAN_GTK_IDX_MASK; |
| 2051 |
|
| 2052 |
memcpy(status->gtk[status_idx].key, data[data_idx].key, |
| 2053 |
sizeof(data[data_idx].key)); |
| 2054 |
|
| 2055 |
/* if it's as long as the TKIP encryption key, copy MIC key */ |
| 2056 |
if (status->gtk[status_idx].len == |
| 2057 |
NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY) |
| 2058 |
memcpy(status->gtk[status_idx].key + |
| 2059 |
NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY, |
| 2060 |
data[data_idx].tkip_mic_key, |
| 2061 |
sizeof(data[data_idx].tkip_mic_key)); |
| 2062 |
status_idx++; |
| 2063 |
} |
| 2064 |
} |
| 2065 |
|
| 2066 |
static void iwl_mvm_convert_igtk(struct iwl_wowlan_status_data *status, |
| 2067 |
struct iwl_wowlan_igtk_status_v1 *data) |
| 2068 |
{ |
| 2069 |
int i; |
| 2070 |
|
| 2071 |
BUILD_BUG_ON(sizeof(status->igtk.key) < sizeof(data->key)); |
| 2072 |
BUILD_BUG_ON(sizeof(status->igtk.ipn) != sizeof(data->ipn)); |
| 2073 |
|
| 2074 |
if (!data->key_len) |
| 2075 |
return; |
| 2076 |
|
| 2077 |
status->igtk.len = data->key_len; |
| 2078 |
status->igtk.flags = data->key_flags; |
| 2079 |
status->igtk.id = u32_get_bits(data->key_flags, |
| 2080 |
IWL_WOWLAN_IGTK_BIGTK_IDX_MASK) |
| 2081 |
+ WOWLAN_IGTK_MIN_INDEX; |
| 2082 |
|
| 2083 |
memcpy(status->igtk.key, data->key, sizeof(data->key)); |
| 2084 |
|
| 2085 |
/* mac80211 expects big endian for memcmp() to work, convert */ |
| 2086 |
for (i = 0; i < sizeof(data->ipn); i++) |
| 2087 |
status->igtk.ipn[i] = data->ipn[sizeof(data->ipn) - i - 1]; |
| 2088 |
} |
| 2089 |
|
| 2090 |
static void iwl_mvm_convert_bigtk(struct iwl_wowlan_status_data *status, |
| 2091 |
const struct iwl_wowlan_igtk_status_v1 *data) |
| 2092 |
{ |
| 2093 |
int data_idx, status_idx = 0; |
| 2094 |
|
| 2095 |
BUILD_BUG_ON(ARRAY_SIZE(status->bigtk) < WOWLAN_BIGTK_KEYS_NUM); |
| 2096 |
|
| 2097 |
for (data_idx = 0; data_idx < WOWLAN_BIGTK_KEYS_NUM; data_idx++) { |
| 2098 |
if (!data[data_idx].key_len) |
| 2099 |
continue; |
| 2100 |
|
| 2101 |
status->bigtk[status_idx].len = data[data_idx].key_len; |
| 2102 |
status->bigtk[status_idx].flags = data[data_idx].key_flags; |
| 2103 |
status->bigtk[status_idx].id = |
| 2104 |
u32_get_bits(data[data_idx].key_flags, |
| 2105 |
IWL_WOWLAN_IGTK_BIGTK_IDX_MASK) |
| 2106 |
+ WOWLAN_BIGTK_MIN_INDEX; |
| 2107 |
|
| 2108 |
BUILD_BUG_ON(sizeof(status->bigtk[status_idx].key) < |
| 2109 |
sizeof(data[data_idx].key)); |
| 2110 |
BUILD_BUG_ON(sizeof(status->bigtk[status_idx].ipn) < |
| 2111 |
sizeof(data[data_idx].ipn)); |
| 2112 |
|
| 2113 |
memcpy(status->bigtk[status_idx].key, data[data_idx].key, |
| 2114 |
sizeof(data[data_idx].key)); |
| 2115 |
memcpy(status->bigtk[status_idx].ipn, data[data_idx].ipn, |
| 2116 |
sizeof(data[data_idx].ipn)); |
| 2117 |
status_idx++; |
| 2118 |
} |
| 2119 |
} |
| 2120 |
|
| 2121 |
static void iwl_mvm_parse_wowlan_info_notif(struct iwl_mvm *mvm, |
| 2122 |
struct iwl_wowlan_info_notif_v5 *data, |
| 2123 |
struct iwl_wowlan_status_data *status, |
| 2124 |
u32 len) |
| 2125 |
{ |
| 2126 |
if (IWL_FW_CHECK(mvm, data->num_mlo_link_keys, |
| 2127 |
"MLO is not supported, shouldn't receive MLO keys\n")) |
| 2128 |
return; |
| 2129 |
|
| 2130 |
if (len < sizeof(*data)) { |
| 2131 |
IWL_ERR(mvm, "Invalid WoWLAN info notification!\n"); |
| 2132 |
status = NULL; |
| 2133 |
return; |
| 2134 |
} |
| 2135 |
|
| 2136 |
if (mvm->fast_resume) |
| 2137 |
return; |
| 2138 |
|
| 2139 |
iwl_mvm_convert_key_counters_v5(status, &data->gtk[0].sc); |
| 2140 |
iwl_mvm_convert_gtk_v3(status, data->gtk); |
| 2141 |
iwl_mvm_convert_igtk(status, &data->igtk[0]); |
| 2142 |
iwl_mvm_convert_bigtk(status, data->bigtk); |
| 2143 |
status->replay_ctr = le64_to_cpu(data->replay_ctr); |
| 2144 |
status->pattern_number = le16_to_cpu(data->pattern_number); |
| 2145 |
status->tid_offloaded_tx = data->tid_offloaded_tx; |
| 2146 |
if (IWL_FW_CHECK(mvm, |
| 2147 |
data->tid_offloaded_tx >= |
| 2148 |
ARRAY_SIZE(status->qos_seq_ctr), |
| 2149 |
"tid_offloaded_tx is out of bound %d\n", |
| 2150 |
data->tid_offloaded_tx)) |
| 2151 |
data->tid_offloaded_tx = 0; |
| 2152 |
status->qos_seq_ctr[data->tid_offloaded_tx] = |
| 2153 |
le16_to_cpu(data->qos_seq_ctr); |
| 2154 |
status->wakeup_reasons = le32_to_cpu(data->wakeup_reasons); |
| 2155 |
status->num_of_gtk_rekeys = |
| 2156 |
le32_to_cpu(data->num_of_gtk_rekeys); |
| 2157 |
status->received_beacons = le32_to_cpu(data->received_beacons); |
| 2158 |
status->tid_tear_down = data->tid_tear_down; |
| 2159 |
} |
| 2160 |
|
| 2161 |
static void |
| 2162 |
iwl_mvm_parse_wowlan_info_notif_v3(struct iwl_mvm *mvm, |
| 2163 |
struct iwl_wowlan_info_notif_v3 *data, |
| 2164 |
struct iwl_wowlan_status_data *status, |
| 2165 |
u32 len) |
| 2166 |
{ |
| 2167 |
u32 i; |
| 2168 |
|
| 2169 |
if (len < sizeof(*data)) { |
| 2170 |
IWL_ERR(mvm, "Invalid WoWLAN info notification!\n"); |
| 2171 |
status = NULL; |
| 2172 |
return; |
| 2173 |
} |
| 2174 |
|
| 2175 |
if (mvm->fast_resume) |
| 2176 |
return; |
| 2177 |
|
| 2178 |
iwl_mvm_convert_key_counters_v5(status, &data->gtk[0].sc); |
| 2179 |
iwl_mvm_convert_gtk_v3(status, data->gtk); |
| 2180 |
iwl_mvm_convert_igtk(status, &data->igtk[0]); |
| 2181 |
iwl_mvm_convert_bigtk(status, data->bigtk); |
| 2182 |
status->replay_ctr = le64_to_cpu(data->replay_ctr); |
| 2183 |
status->pattern_number = le16_to_cpu(data->pattern_number); |
| 2184 |
for (i = 0; i < IWL_MAX_TID_COUNT; i++) |
| 2185 |
status->qos_seq_ctr[i] = |
| 2186 |
le16_to_cpu(data->qos_seq_ctr[i]); |
| 2187 |
status->wakeup_reasons = le32_to_cpu(data->wakeup_reasons); |
| 2188 |
status->num_of_gtk_rekeys = |
| 2189 |
le32_to_cpu(data->num_of_gtk_rekeys); |
| 2190 |
status->received_beacons = le32_to_cpu(data->received_beacons); |
| 2191 |
status->tid_tear_down = data->tid_tear_down; |
| 2192 |
} |
| 2193 |
|
| 2194 |
static void |
| 2195 |
iwl_mvm_parse_wowlan_info_notif_v1(struct iwl_mvm *mvm, |
| 2196 |
struct iwl_wowlan_info_notif_v1 *data, |
| 2197 |
struct iwl_wowlan_status_data *status, |
| 2198 |
u32 len) |
| 2199 |
{ |
| 2200 |
u32 i; |
| 2201 |
|
| 2202 |
if (len < sizeof(*data)) { |
| 2203 |
IWL_ERR(mvm, "Invalid WoWLAN info notification!\n"); |
| 2204 |
status = NULL; |
| 2205 |
return; |
| 2206 |
} |
| 2207 |
|
| 2208 |
iwl_mvm_convert_key_counters_v5(status, &data->gtk[0].sc); |
| 2209 |
iwl_mvm_convert_gtk_v3(status, data->gtk); |
| 2210 |
iwl_mvm_convert_igtk(status, &data->igtk[0]); |
| 2211 |
status->replay_ctr = le64_to_cpu(data->replay_ctr); |
| 2212 |
status->pattern_number = le16_to_cpu(data->pattern_number); |
| 2213 |
for (i = 0; i < IWL_MAX_TID_COUNT; i++) |
| 2214 |
status->qos_seq_ctr[i] = |
| 2215 |
le16_to_cpu(data->qos_seq_ctr[i]); |
| 2216 |
status->wakeup_reasons = le32_to_cpu(data->wakeup_reasons); |
| 2217 |
status->num_of_gtk_rekeys = |
| 2218 |
le32_to_cpu(data->num_of_gtk_rekeys); |
| 2219 |
status->received_beacons = le32_to_cpu(data->received_beacons); |
| 2220 |
status->tid_tear_down = data->tid_tear_down; |
| 2221 |
} |
| 2222 |
|
| 2223 |
/* Occasionally, templates would be nice. This is one of those times ... */ |
| 2224 |
#define iwl_mvm_parse_wowlan_status_common(_ver) \ |
| 2225 |
static struct iwl_wowlan_status_data * \ |
| 2226 |
iwl_mvm_parse_wowlan_status_common_ ## _ver(struct iwl_mvm *mvm, \ |
| 2227 |
struct iwl_wowlan_status_ ##_ver *data,\ |
| 2228 |
int len) \ |
| 2229 |
{ \ |
| 2230 |
struct iwl_wowlan_status_data *status; \ |
| 2231 |
int data_size, i; \ |
| 2232 |
\ |
| 2233 |
if (len < sizeof(*data)) { \ |
| 2234 |
IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); \ |
| 2235 |
return NULL; \ |
| 2236 |
} \ |
| 2237 |
\ |
| 2238 |
data_size = ALIGN(le32_to_cpu(data->wake_packet_bufsize), 4); \ |
| 2239 |
if (len != sizeof(*data) + data_size) { \ |
| 2240 |
IWL_ERR(mvm, "Invalid WoWLAN status response!\n"); \ |
| 2241 |
return NULL; \ |
| 2242 |
} \ |
| 2243 |
\ |
| 2244 |
status = kzalloc(sizeof(*status), GFP_KERNEL); \ |
| 2245 |
if (!status) \ |
| 2246 |
return NULL; \ |
| 2247 |
\ |
| 2248 |
/* copy all the common fields */ \ |
| 2249 |
status->replay_ctr = le64_to_cpu(data->replay_ctr); \ |
| 2250 |
status->pattern_number = le16_to_cpu(data->pattern_number); \ |
| 2251 |
status->non_qos_seq_ctr = le16_to_cpu(data->non_qos_seq_ctr); \ |
| 2252 |
for (i = 0; i < 8; i++) \ |
| 2253 |
status->qos_seq_ctr[i] = \ |
| 2254 |
le16_to_cpu(data->qos_seq_ctr[i]); \ |
| 2255 |
status->wakeup_reasons = le32_to_cpu(data->wakeup_reasons); \ |
| 2256 |
status->num_of_gtk_rekeys = \ |
| 2257 |
le32_to_cpu(data->num_of_gtk_rekeys); \ |
| 2258 |
status->received_beacons = le32_to_cpu(data->received_beacons); \ |
| 2259 |
status->wake_packet_length = \ |
| 2260 |
le32_to_cpu(data->wake_packet_length); \ |
| 2261 |
status->wake_packet_bufsize = \ |
| 2262 |
le32_to_cpu(data->wake_packet_bufsize); \ |
| 2263 |
if (status->wake_packet_bufsize) { \ |
| 2264 |
status->wake_packet = \ |
| 2265 |
kmemdup(data->wake_packet, \ |
| 2266 |
status->wake_packet_bufsize, \ |
| 2267 |
GFP_KERNEL); \ |
| 2268 |
if (!status->wake_packet) { \ |
| 2269 |
kfree(status); \ |
| 2270 |
return NULL; \ |
| 2271 |
} \ |
| 2272 |
} else { \ |
| 2273 |
status->wake_packet = NULL; \ |
| 2274 |
} \ |
| 2275 |
\ |
| 2276 |
return status; \ |
| 2277 |
} |
| 2278 |
|
| 2279 |
iwl_mvm_parse_wowlan_status_common(v6) |
| 2280 |
iwl_mvm_parse_wowlan_status_common(v7) |
| 2281 |
|
| 2282 |
static struct iwl_wowlan_status_data * |
| 2283 |
iwl_mvm_send_wowlan_get_status(struct iwl_mvm *mvm, u8 sta_id) |
| 2284 |
{ |
| 2285 |
struct iwl_wowlan_status_data *status; |
| 2286 |
struct iwl_wowlan_get_status_cmd get_status_cmd = { |
| 2287 |
.sta_id = cpu_to_le32(sta_id), |
| 2288 |
}; |
| 2289 |
struct iwl_host_cmd cmd = { |
| 2290 |
.id = WOWLAN_GET_STATUSES, |
| 2291 |
.flags = CMD_WANT_SKB, |
| 2292 |
.data = { &get_status_cmd, }, |
| 2293 |
.len = { sizeof(get_status_cmd), }, |
| 2294 |
}; |
| 2295 |
int ret, len; |
| 2296 |
u8 notif_ver; |
| 2297 |
u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd.id, |
| 2298 |
IWL_FW_CMD_VER_UNKNOWN); |
| 2299 |
|
| 2300 |
if (cmd_ver == IWL_FW_CMD_VER_UNKNOWN) |
| 2301 |
cmd.len[0] = 0; |
| 2302 |
|
| 2303 |
lockdep_assert_held(&mvm->mutex); |
| 2304 |
|
| 2305 |
ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 2306 |
if (ret) { |
| 2307 |
IWL_ERR(mvm, "failed to query wakeup status (%d)\n", ret); |
| 2308 |
return ERR_PTR(ret); |
| 2309 |
} |
| 2310 |
|
| 2311 |
len = iwl_rx_packet_payload_len(cmd.resp_pkt); |
| 2312 |
|
| 2313 |
/* default to 7 (when we have IWL_UCODE_TLV_API_WOWLAN_KEY_MATERIAL) */ |
| 2314 |
notif_ver = iwl_mvm_lookup_wowlan_status_ver(mvm); |
| 2315 |
|
| 2316 |
if (notif_ver < 7) { |
| 2317 |
struct iwl_wowlan_status_v6 *v6 = (void *)cmd.resp_pkt->data; |
| 2318 |
|
| 2319 |
status = iwl_mvm_parse_wowlan_status_common_v6(mvm, v6, len); |
| 2320 |
if (!status) |
| 2321 |
goto out_free_resp; |
| 2322 |
|
| 2323 |
BUILD_BUG_ON(sizeof(v6->gtk.decrypt_key) > |
| 2324 |
sizeof(status->gtk[0].key)); |
| 2325 |
BUILD_BUG_ON(NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY + |
| 2326 |
sizeof(v6->gtk.tkip_mic_key) > |
| 2327 |
sizeof(status->gtk[0].key)); |
| 2328 |
|
| 2329 |
/* copy GTK info to the right place */ |
| 2330 |
memcpy(status->gtk[0].key, v6->gtk.decrypt_key, |
| 2331 |
sizeof(v6->gtk.decrypt_key)); |
| 2332 |
memcpy(status->gtk[0].key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY, |
| 2333 |
v6->gtk.tkip_mic_key, |
| 2334 |
sizeof(v6->gtk.tkip_mic_key)); |
| 2335 |
|
| 2336 |
iwl_mvm_convert_key_counters(status, &v6->gtk.rsc.all_tsc_rsc, |
| 2337 |
v6->gtk.key_index); |
| 2338 |
|
| 2339 |
/* hardcode the key length to 16 since v6 only supports 16 */ |
| 2340 |
status->gtk[0].len = 16; |
| 2341 |
|
| 2342 |
/* |
| 2343 |
* The key index only uses 2 bits (values 0 to 3) and |
| 2344 |
* we always set bit 7 which means this is the |
| 2345 |
* currently used key. |
| 2346 |
*/ |
| 2347 |
status->gtk[0].flags = v6->gtk.key_index | BIT(7); |
| 2348 |
status->gtk[0].id = v6->gtk.key_index; |
| 2349 |
} else if (notif_ver == 7) { |
| 2350 |
struct iwl_wowlan_status_v7 *v7 = (void *)cmd.resp_pkt->data; |
| 2351 |
|
| 2352 |
status = iwl_mvm_parse_wowlan_status_common_v7(mvm, v7, len); |
| 2353 |
if (!status) |
| 2354 |
goto out_free_resp; |
| 2355 |
|
| 2356 |
iwl_mvm_convert_key_counters(status, &v7->gtk[0].rsc.all_tsc_rsc, |
| 2357 |
v7->gtk[0].key_flags & IWL_WOWLAN_GTK_IDX_MASK); |
| 2358 |
iwl_mvm_convert_gtk_v2(status, &v7->gtk[0]); |
| 2359 |
iwl_mvm_convert_igtk(status, &v7->igtk[0]); |
| 2360 |
} else { |
| 2361 |
IWL_ERR(mvm, |
| 2362 |
"Firmware advertises unknown WoWLAN status response %d!\n", |
| 2363 |
notif_ver); |
| 2364 |
status = NULL; |
| 2365 |
} |
| 2366 |
|
| 2367 |
out_free_resp: |
| 2368 |
iwl_free_resp(&cmd); |
| 2369 |
return status; |
| 2370 |
} |
| 2371 |
|
| 2372 |
/* releases the MVM mutex */ |
| 2373 |
static bool iwl_mvm_query_wakeup_reasons(struct iwl_mvm *mvm, |
| 2374 |
struct ieee80211_vif *vif, |
| 2375 |
struct iwl_wowlan_status_data *status) |
| 2376 |
{ |
| 2377 |
int i; |
| 2378 |
bool keep = false; |
| 2379 |
struct iwl_mvm_sta *mvm_ap_sta; |
| 2380 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2381 |
int wowlan_info_ver = iwl_fw_lookup_notif_ver(mvm->fw, |
| 2382 |
PROT_OFFLOAD_GROUP, |
| 2383 |
WOWLAN_INFO_NOTIFICATION, |
| 2384 |
IWL_FW_CMD_VER_UNKNOWN); |
| 2385 |
|
| 2386 |
if (!status) |
| 2387 |
goto out_unlock; |
| 2388 |
|
| 2389 |
IWL_DEBUG_WOWLAN(mvm, "wakeup reason 0x%x\n", |
| 2390 |
status->wakeup_reasons); |
| 2391 |
|
| 2392 |
mvm_ap_sta = iwl_mvm_sta_from_staid_protected(mvm, |
| 2393 |
mvmvif->deflink.ap_sta_id); |
| 2394 |
if (!mvm_ap_sta) |
| 2395 |
goto out_unlock; |
| 2396 |
|
| 2397 |
/* firmware stores last-used value, we store next value */ |
| 2398 |
if (wowlan_info_ver >= 5) { |
| 2399 |
mvm_ap_sta->tid_data[status->tid_offloaded_tx].seq_number = |
| 2400 |
status->qos_seq_ctr[status->tid_offloaded_tx] + 0x10; |
| 2401 |
} else { |
| 2402 |
for (i = 0; i < IWL_MAX_TID_COUNT; i++) |
| 2403 |
mvm_ap_sta->tid_data[i].seq_number = |
| 2404 |
status->qos_seq_ctr[i] + 0x10; |
| 2405 |
} |
| 2406 |
|
| 2407 |
if (mvm->trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_22000) { |
| 2408 |
i = mvm->offload_tid; |
| 2409 |
iwl_trans_set_q_ptrs(mvm->trans, |
| 2410 |
mvm_ap_sta->tid_data[i].txq_id, |
| 2411 |
mvm_ap_sta->tid_data[i].seq_number >> 4); |
| 2412 |
} |
| 2413 |
|
| 2414 |
iwl_mvm_report_wakeup_reasons(mvm, vif, status); |
| 2415 |
|
| 2416 |
keep = iwl_mvm_setup_connection_keep(mvm, vif, status); |
| 2417 |
out_unlock: |
| 2418 |
mutex_unlock(&mvm->mutex); |
| 2419 |
return keep; |
| 2420 |
} |
| 2421 |
|
| 2422 |
#define ND_QUERY_BUF_LEN (sizeof(struct iwl_scan_offload_profile_match) * \ |
| 2423 |
IWL_SCAN_MAX_PROFILES) |
| 2424 |
|
| 2425 |
struct iwl_mvm_nd_results { |
| 2426 |
u32 matched_profiles; |
| 2427 |
u8 matches[ND_QUERY_BUF_LEN]; |
| 2428 |
}; |
| 2429 |
|
| 2430 |
static int |
| 2431 |
iwl_mvm_netdetect_query_results(struct iwl_mvm *mvm, |
| 2432 |
struct iwl_mvm_nd_results *results) |
| 2433 |
{ |
| 2434 |
struct iwl_scan_offload_match_info *query; |
| 2435 |
struct iwl_host_cmd cmd = { |
| 2436 |
.id = SCAN_OFFLOAD_PROFILES_QUERY_CMD, |
| 2437 |
.flags = CMD_WANT_SKB, |
| 2438 |
}; |
| 2439 |
int ret, len; |
| 2440 |
size_t query_len, matches_len; |
| 2441 |
int max_profiles = iwl_umac_scan_get_max_profiles(mvm->fw); |
| 2442 |
|
| 2443 |
ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 2444 |
if (ret) { |
| 2445 |
IWL_ERR(mvm, "failed to query matched profiles (%d)\n", ret); |
| 2446 |
return ret; |
| 2447 |
} |
| 2448 |
|
| 2449 |
if (fw_has_api(&mvm->fw->ucode_capa, |
| 2450 |
IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) { |
| 2451 |
query_len = sizeof(struct iwl_scan_offload_match_info); |
| 2452 |
matches_len = sizeof(struct iwl_scan_offload_profile_match) * |
| 2453 |
max_profiles; |
| 2454 |
} else { |
| 2455 |
query_len = sizeof(struct iwl_scan_offload_profiles_query_v1); |
| 2456 |
matches_len = sizeof(struct iwl_scan_offload_profile_match_v1) * |
| 2457 |
max_profiles; |
| 2458 |
} |
| 2459 |
|
| 2460 |
len = iwl_rx_packet_payload_len(cmd.resp_pkt); |
| 2461 |
if (len < query_len) { |
| 2462 |
IWL_ERR(mvm, "Invalid scan offload profiles query response!\n"); |
| 2463 |
ret = -EIO; |
| 2464 |
goto out_free_resp; |
| 2465 |
} |
| 2466 |
|
| 2467 |
query = (void *)cmd.resp_pkt->data; |
| 2468 |
|
| 2469 |
results->matched_profiles = le32_to_cpu(query->matched_profiles); |
| 2470 |
memcpy(results->matches, query->matches, matches_len); |
| 2471 |
|
| 2472 |
#ifdef CONFIG_IWLWIFI_DEBUGFS |
| 2473 |
mvm->last_netdetect_scans = le32_to_cpu(query->n_scans_done); |
| 2474 |
#endif |
| 2475 |
|
| 2476 |
out_free_resp: |
| 2477 |
iwl_free_resp(&cmd); |
| 2478 |
return ret; |
| 2479 |
} |
| 2480 |
|
| 2481 |
static int iwl_mvm_query_num_match_chans(struct iwl_mvm *mvm, |
| 2482 |
struct iwl_mvm_nd_results *results, |
| 2483 |
int idx) |
| 2484 |
{ |
| 2485 |
int n_chans = 0, i; |
| 2486 |
|
| 2487 |
if (fw_has_api(&mvm->fw->ucode_capa, |
| 2488 |
IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) { |
| 2489 |
struct iwl_scan_offload_profile_match *matches = |
| 2490 |
(void *)results->matches; |
| 2491 |
|
| 2492 |
for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN; i++) |
| 2493 |
n_chans += hweight8(matches[idx].matching_channels[i]); |
| 2494 |
} else { |
| 2495 |
struct iwl_scan_offload_profile_match_v1 *matches = |
| 2496 |
(void *)results->matches; |
| 2497 |
|
| 2498 |
for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1; i++) |
| 2499 |
n_chans += hweight8(matches[idx].matching_channels[i]); |
| 2500 |
} |
| 2501 |
|
| 2502 |
return n_chans; |
| 2503 |
} |
| 2504 |
|
| 2505 |
static void iwl_mvm_query_set_freqs(struct iwl_mvm *mvm, |
| 2506 |
struct iwl_mvm_nd_results *results, |
| 2507 |
struct cfg80211_wowlan_nd_match *match, |
| 2508 |
int idx) |
| 2509 |
{ |
| 2510 |
int i; |
| 2511 |
int n_channels = 0; |
| 2512 |
|
| 2513 |
if (fw_has_api(&mvm->fw->ucode_capa, |
| 2514 |
IWL_UCODE_TLV_API_SCAN_OFFLOAD_CHANS)) { |
| 2515 |
struct iwl_scan_offload_profile_match *matches = |
| 2516 |
(void *)results->matches; |
| 2517 |
|
| 2518 |
for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN * 8; i++) |
| 2519 |
if (matches[idx].matching_channels[i / 8] & (BIT(i % 8))) |
| 2520 |
match->channels[n_channels++] = |
| 2521 |
mvm->nd_channels[i]->center_freq; |
| 2522 |
} else { |
| 2523 |
struct iwl_scan_offload_profile_match_v1 *matches = |
| 2524 |
(void *)results->matches; |
| 2525 |
|
| 2526 |
for (i = 0; i < SCAN_OFFLOAD_MATCHING_CHANNELS_LEN_V1 * 8; i++) |
| 2527 |
if (matches[idx].matching_channels[i / 8] & (BIT(i % 8))) |
| 2528 |
match->channels[n_channels++] = |
| 2529 |
mvm->nd_channels[i]->center_freq; |
| 2530 |
} |
| 2531 |
/* We may have ended up with fewer channels than we allocated. */ |
| 2532 |
match->n_channels = n_channels; |
| 2533 |
} |
| 2534 |
|
| 2535 |
/** |
| 2536 |
* enum iwl_d3_notif - d3 notifications |
| 2537 |
* @IWL_D3_NOTIF_WOWLAN_INFO: WOWLAN_INFO_NOTIF was received |
| 2538 |
* @IWL_D3_NOTIF_WOWLAN_WAKE_PKT: WOWLAN_WAKE_PKT_NOTIF was received |
| 2539 |
* @IWL_D3_NOTIF_PROT_OFFLOAD: PROT_OFFLOAD_NOTIF was received |
| 2540 |
* @IWL_D3_ND_MATCH_INFO: OFFLOAD_MATCH_INFO_NOTIF was received |
| 2541 |
* @IWL_D3_NOTIF_D3_END_NOTIF: D3_END_NOTIF was received |
| 2542 |
*/ |
| 2543 |
enum iwl_d3_notif { |
| 2544 |
IWL_D3_NOTIF_WOWLAN_INFO = BIT(0), |
| 2545 |
IWL_D3_NOTIF_WOWLAN_WAKE_PKT = BIT(1), |
| 2546 |
IWL_D3_NOTIF_PROT_OFFLOAD = BIT(2), |
| 2547 |
IWL_D3_ND_MATCH_INFO = BIT(3), |
| 2548 |
IWL_D3_NOTIF_D3_END_NOTIF = BIT(4) |
| 2549 |
}; |
| 2550 |
|
| 2551 |
/* manage d3 resume data */ |
| 2552 |
struct iwl_d3_data { |
| 2553 |
struct iwl_wowlan_status_data *status; |
| 2554 |
u32 d3_end_flags; |
| 2555 |
u32 notif_expected; /* bitmap - see &enum iwl_d3_notif */ |
| 2556 |
u32 notif_received; /* bitmap - see &enum iwl_d3_notif */ |
| 2557 |
struct iwl_mvm_nd_results *nd_results; |
| 2558 |
bool nd_results_valid; |
| 2559 |
}; |
| 2560 |
|
| 2561 |
static void iwl_mvm_query_netdetect_reasons(struct iwl_mvm *mvm, |
| 2562 |
struct ieee80211_vif *vif, |
| 2563 |
struct iwl_d3_data *d3_data) |
| 2564 |
{ |
| 2565 |
struct cfg80211_wowlan_nd_info *net_detect = NULL; |
| 2566 |
struct cfg80211_wowlan_wakeup wakeup = { |
| 2567 |
.pattern_idx = -1, |
| 2568 |
}; |
| 2569 |
struct cfg80211_wowlan_wakeup *wakeup_report = &wakeup; |
| 2570 |
unsigned long matched_profiles; |
| 2571 |
u32 reasons = 0; |
| 2572 |
int i, n_matches, ret; |
| 2573 |
|
| 2574 |
if (WARN_ON(!d3_data || !d3_data->status)) |
| 2575 |
goto out; |
| 2576 |
|
| 2577 |
reasons = d3_data->status->wakeup_reasons; |
| 2578 |
|
| 2579 |
if (reasons & IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED) |
| 2580 |
wakeup.rfkill_release = true; |
| 2581 |
|
| 2582 |
if (reasons != IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) |
| 2583 |
goto out; |
| 2584 |
|
| 2585 |
if (!iwl_fw_lookup_notif_ver(mvm->fw, PROT_OFFLOAD_GROUP, |
| 2586 |
WOWLAN_INFO_NOTIFICATION, 0)) { |
| 2587 |
IWL_INFO(mvm, "Query FW for ND results\n"); |
| 2588 |
ret = iwl_mvm_netdetect_query_results(mvm, d3_data->nd_results); |
| 2589 |
|
| 2590 |
} else { |
| 2591 |
IWL_INFO(mvm, "Notification based ND results\n"); |
| 2592 |
ret = d3_data->nd_results_valid ? 0 : -1; |
| 2593 |
} |
| 2594 |
|
| 2595 |
if (ret || !d3_data->nd_results->matched_profiles) { |
| 2596 |
wakeup_report = NULL; |
| 2597 |
goto out; |
| 2598 |
} |
| 2599 |
|
| 2600 |
matched_profiles = d3_data->nd_results->matched_profiles; |
| 2601 |
if (mvm->n_nd_match_sets) { |
| 2602 |
n_matches = hweight_long(matched_profiles); |
| 2603 |
} else { |
| 2604 |
IWL_ERR(mvm, "no net detect match information available\n"); |
| 2605 |
n_matches = 0; |
| 2606 |
} |
| 2607 |
|
| 2608 |
net_detect = kzalloc_flex(*net_detect, matches, n_matches); |
| 2609 |
if (!net_detect || !n_matches) |
| 2610 |
goto out_report_nd; |
| 2611 |
net_detect->n_matches = n_matches; |
| 2612 |
n_matches = 0; |
| 2613 |
|
| 2614 |
for_each_set_bit(i, &matched_profiles, mvm->n_nd_match_sets) { |
| 2615 |
struct cfg80211_wowlan_nd_match *match; |
| 2616 |
int idx, n_channels = 0; |
| 2617 |
|
| 2618 |
n_channels = iwl_mvm_query_num_match_chans(mvm, |
| 2619 |
d3_data->nd_results, |
| 2620 |
i); |
| 2621 |
|
| 2622 |
match = kzalloc_flex(*match, channels, n_channels); |
| 2623 |
if (!match) |
| 2624 |
goto out_report_nd; |
| 2625 |
match->n_channels = n_channels; |
| 2626 |
|
| 2627 |
net_detect->matches[n_matches++] = match; |
| 2628 |
|
| 2629 |
/* We inverted the order of the SSIDs in the scan |
| 2630 |
* request, so invert the index here. |
| 2631 |
*/ |
| 2632 |
idx = mvm->n_nd_match_sets - i - 1; |
| 2633 |
match->ssid.ssid_len = mvm->nd_match_sets[idx].ssid.ssid_len; |
| 2634 |
memcpy(match->ssid.ssid, mvm->nd_match_sets[idx].ssid.ssid, |
| 2635 |
match->ssid.ssid_len); |
| 2636 |
|
| 2637 |
if (mvm->n_nd_channels < n_channels) |
| 2638 |
continue; |
| 2639 |
|
| 2640 |
iwl_mvm_query_set_freqs(mvm, d3_data->nd_results, match, i); |
| 2641 |
} |
| 2642 |
/* We may have fewer matches than we allocated. */ |
| 2643 |
net_detect->n_matches = n_matches; |
| 2644 |
|
| 2645 |
out_report_nd: |
| 2646 |
wakeup.net_detect = net_detect; |
| 2647 |
out: |
| 2648 |
iwl_mvm_free_nd(mvm); |
| 2649 |
|
| 2650 |
mutex_unlock(&mvm->mutex); |
| 2651 |
ieee80211_report_wowlan_wakeup(vif, wakeup_report, GFP_KERNEL); |
| 2652 |
|
| 2653 |
if (net_detect) { |
| 2654 |
for (i = 0; i < net_detect->n_matches; i++) |
| 2655 |
kfree(net_detect->matches[i]); |
| 2656 |
kfree(net_detect); |
| 2657 |
} |
| 2658 |
} |
| 2659 |
|
| 2660 |
static void iwl_mvm_d3_disconnect_iter(void *data, u8 *mac, |
| 2661 |
struct ieee80211_vif *vif) |
| 2662 |
{ |
| 2663 |
/* skip the one we keep connection on */ |
| 2664 |
if (data == vif) |
| 2665 |
return; |
| 2666 |
|
| 2667 |
if (vif->type == NL80211_IFTYPE_STATION) |
| 2668 |
ieee80211_resume_disconnect(vif); |
| 2669 |
} |
| 2670 |
|
| 2671 |
enum rt_status { |
| 2672 |
FW_ALIVE, |
| 2673 |
FW_NEEDS_RESET, |
| 2674 |
FW_ERROR, |
| 2675 |
}; |
| 2676 |
|
| 2677 |
static enum rt_status iwl_mvm_check_rt_status(struct iwl_mvm *mvm, |
| 2678 |
struct ieee80211_vif *vif) |
| 2679 |
{ |
| 2680 |
u32 err_id; |
| 2681 |
|
| 2682 |
/* check for lmac1 error */ |
| 2683 |
if (iwl_fwrt_read_err_table(mvm->trans, |
| 2684 |
mvm->trans->dbg.lmac_error_event_table[0], |
| 2685 |
&err_id)) { |
| 2686 |
if (err_id == RF_KILL_INDICATOR_FOR_WOWLAN) { |
| 2687 |
IWL_WARN(mvm, "Rfkill was toggled during suspend\n"); |
| 2688 |
if (vif) { |
| 2689 |
struct cfg80211_wowlan_wakeup wakeup = { |
| 2690 |
.rfkill_release = true, |
| 2691 |
}; |
| 2692 |
|
| 2693 |
ieee80211_report_wowlan_wakeup(vif, &wakeup, |
| 2694 |
GFP_KERNEL); |
| 2695 |
} |
| 2696 |
|
| 2697 |
return FW_NEEDS_RESET; |
| 2698 |
} |
| 2699 |
return FW_ERROR; |
| 2700 |
} |
| 2701 |
|
| 2702 |
/* check if we have lmac2 set and check for error */ |
| 2703 |
if (iwl_fwrt_read_err_table(mvm->trans, |
| 2704 |
mvm->trans->dbg.lmac_error_event_table[1], |
| 2705 |
NULL)) |
| 2706 |
return FW_ERROR; |
| 2707 |
|
| 2708 |
/* check for umac error */ |
| 2709 |
if (iwl_fwrt_read_err_table(mvm->trans, |
| 2710 |
mvm->trans->dbg.umac_error_event_table, |
| 2711 |
NULL)) |
| 2712 |
return FW_ERROR; |
| 2713 |
|
| 2714 |
return FW_ALIVE; |
| 2715 |
} |
| 2716 |
|
| 2717 |
/* |
| 2718 |
* This function assumes: |
| 2719 |
* 1. The mutex is already held. |
| 2720 |
* 2. The callee functions unlock the mutex. |
| 2721 |
*/ |
| 2722 |
static bool |
| 2723 |
iwl_mvm_choose_query_wakeup_reasons(struct iwl_mvm *mvm, |
| 2724 |
struct ieee80211_vif *vif, |
| 2725 |
struct iwl_d3_data *d3_data) |
| 2726 |
{ |
| 2727 |
lockdep_assert_held(&mvm->mutex); |
| 2728 |
|
| 2729 |
/* if FW uses status notification, status shouldn't be NULL here */ |
| 2730 |
if (!d3_data->status) { |
| 2731 |
struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2732 |
u8 sta_id = mvm->net_detect ? IWL_INVALID_STA : |
| 2733 |
mvmvif->deflink.ap_sta_id; |
| 2734 |
|
| 2735 |
d3_data->status = iwl_mvm_send_wowlan_get_status(mvm, sta_id); |
| 2736 |
} |
| 2737 |
|
| 2738 |
if (mvm->net_detect) { |
| 2739 |
iwl_mvm_query_netdetect_reasons(mvm, vif, d3_data); |
| 2740 |
return false; |
| 2741 |
} |
| 2742 |
|
| 2743 |
return iwl_mvm_query_wakeup_reasons(mvm, vif, |
| 2744 |
d3_data->status); |
| 2745 |
} |
| 2746 |
|
| 2747 |
#define IWL_WOWLAN_WAKEUP_REASON_HAS_WAKEUP_PKT (IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET | \ |
| 2748 |
IWL_WOWLAN_WAKEUP_BY_PATTERN | \ |
| 2749 |
IWL_WAKEUP_BY_PATTERN_IPV4_TCP_SYN |\ |
| 2750 |
IWL_WAKEUP_BY_PATTERN_IPV4_TCP_SYN_WILDCARD |\ |
| 2751 |
IWL_WAKEUP_BY_PATTERN_IPV6_TCP_SYN |\ |
| 2752 |
IWL_WAKEUP_BY_PATTERN_IPV6_TCP_SYN_WILDCARD) |
| 2753 |
|
| 2754 |
static int iwl_mvm_wowlan_store_wake_pkt(struct iwl_mvm *mvm, |
| 2755 |
struct iwl_wowlan_wake_pkt_notif *notif, |
| 2756 |
struct iwl_wowlan_status_data *status, |
| 2757 |
u32 len) |
| 2758 |
{ |
| 2759 |
u32 data_size, packet_len = le32_to_cpu(notif->wake_packet_length); |
| 2760 |
|
| 2761 |
if (len < sizeof(*notif)) { |
| 2762 |
IWL_ERR(mvm, "Invalid WoWLAN wake packet notification!\n"); |
| 2763 |
return -EIO; |
| 2764 |
} |
| 2765 |
|
| 2766 |
if (WARN_ON(!status)) { |
| 2767 |
IWL_ERR(mvm, "Got wake packet notification but wowlan status data is NULL\n"); |
| 2768 |
return -EIO; |
| 2769 |
} |
| 2770 |
|
| 2771 |
if (WARN_ON(!(status->wakeup_reasons & |
| 2772 |
IWL_WOWLAN_WAKEUP_REASON_HAS_WAKEUP_PKT))) { |
| 2773 |
IWL_ERR(mvm, "Got wakeup packet but wakeup reason is %x\n", |
| 2774 |
status->wakeup_reasons); |
| 2775 |
return -EIO; |
| 2776 |
} |
| 2777 |
|
| 2778 |
data_size = len - offsetof(struct iwl_wowlan_wake_pkt_notif, wake_packet); |
| 2779 |
|
| 2780 |
/* data_size got the padding from the notification, remove it. */ |
| 2781 |
if (packet_len < data_size) |
| 2782 |
data_size = packet_len; |
| 2783 |
|
| 2784 |
status->wake_packet = kmemdup(notif->wake_packet, data_size, |
| 2785 |
GFP_ATOMIC); |
| 2786 |
|
| 2787 |
if (!status->wake_packet) |
| 2788 |
return -ENOMEM; |
| 2789 |
|
| 2790 |
status->wake_packet_length = packet_len; |
| 2791 |
status->wake_packet_bufsize = data_size; |
| 2792 |
|
| 2793 |
return 0; |
| 2794 |
} |
| 2795 |
|
| 2796 |
static void iwl_mvm_nd_match_info_handler(struct iwl_mvm *mvm, |
| 2797 |
struct iwl_d3_data *d3_data, |
| 2798 |
struct iwl_scan_offload_match_info *notif, |
| 2799 |
u32 len) |
| 2800 |
{ |
| 2801 |
struct iwl_wowlan_status_data *status = d3_data->status; |
| 2802 |
struct ieee80211_vif *vif = iwl_mvm_get_bss_vif(mvm); |
| 2803 |
struct iwl_mvm_nd_results *results = d3_data->nd_results; |
| 2804 |
size_t i, matches_len = sizeof(struct iwl_scan_offload_profile_match) * |
| 2805 |
iwl_umac_scan_get_max_profiles(mvm->fw); |
| 2806 |
|
| 2807 |
if (IS_ERR_OR_NULL(vif)) |
| 2808 |
return; |
| 2809 |
|
| 2810 |
if (len < sizeof(struct iwl_scan_offload_match_info) + matches_len) { |
| 2811 |
IWL_ERR(mvm, "Invalid scan match info notification\n"); |
| 2812 |
return; |
| 2813 |
} |
| 2814 |
|
| 2815 |
if (!mvm->net_detect) { |
| 2816 |
IWL_ERR(mvm, "Unexpected scan match info notification\n"); |
| 2817 |
return; |
| 2818 |
} |
| 2819 |
|
| 2820 |
if (!status || status->wakeup_reasons != IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS) { |
| 2821 |
IWL_ERR(mvm, |
| 2822 |
"Ignore scan match info notification: no reason\n"); |
| 2823 |
return; |
| 2824 |
} |
| 2825 |
|
| 2826 |
#ifdef CONFIG_IWLWIFI_DEBUGFS |
| 2827 |
mvm->last_netdetect_scans = le32_to_cpu(notif->n_scans_done); |
| 2828 |
#endif |
| 2829 |
|
| 2830 |
results->matched_profiles = le32_to_cpu(notif->matched_profiles); |
| 2831 |
IWL_INFO(mvm, "number of matched profiles=%u\n", |
| 2832 |
results->matched_profiles); |
| 2833 |
|
| 2834 |
if (results->matched_profiles) { |
| 2835 |
memcpy(results->matches, notif->matches, matches_len); |
| 2836 |
d3_data->nd_results_valid = true; |
| 2837 |
} |
| 2838 |
|
| 2839 |
/* no scan should be active at this point */ |
| 2840 |
mvm->scan_status = 0; |
| 2841 |
for (i = 0; i < mvm->max_scans; i++) |
| 2842 |
mvm->scan_uid_status[i] = 0; |
| 2843 |
} |
| 2844 |
|
| 2845 |
static bool iwl_mvm_wait_d3_notif(struct iwl_notif_wait_data *notif_wait, |
| 2846 |
struct iwl_rx_packet *pkt, void *data) |
| 2847 |
{ |
| 2848 |
struct iwl_mvm *mvm = |
| 2849 |
container_of(notif_wait, struct iwl_mvm, notif_wait); |
| 2850 |
struct iwl_d3_data *d3_data = data; |
| 2851 |
u32 len = iwl_rx_packet_payload_len(pkt); |
| 2852 |
int ret; |
| 2853 |
int wowlan_info_ver = iwl_fw_lookup_notif_ver(mvm->fw, |
| 2854 |
PROT_OFFLOAD_GROUP, |
| 2855 |
WOWLAN_INFO_NOTIFICATION, |
| 2856 |
IWL_FW_CMD_VER_UNKNOWN); |
| 2857 |
|
| 2858 |
|
| 2859 |
switch (WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd)) { |
| 2860 |
case WIDE_ID(PROT_OFFLOAD_GROUP, WOWLAN_INFO_NOTIFICATION): { |
| 2861 |
|
| 2862 |
if (d3_data->notif_received & IWL_D3_NOTIF_WOWLAN_INFO) { |
| 2863 |
/* We might get two notifications due to dual bss */ |
| 2864 |
IWL_DEBUG_WOWLAN(mvm, |
| 2865 |
"Got additional wowlan info notification\n"); |
| 2866 |
break; |
| 2867 |
} |
| 2868 |
|
| 2869 |
if (wowlan_info_ver == 1) { |
| 2870 |
struct iwl_wowlan_info_notif_v1 *notif_v1 = |
| 2871 |
(void *)pkt->data; |
| 2872 |
|
| 2873 |
iwl_mvm_parse_wowlan_info_notif_v1(mvm, notif_v1, |
| 2874 |
d3_data->status, |
| 2875 |
len); |
| 2876 |
} else if (wowlan_info_ver == 3) { |
| 2877 |
struct iwl_wowlan_info_notif_v3 *notif = |
| 2878 |
(void *)pkt->data; |
| 2879 |
|
| 2880 |
iwl_mvm_parse_wowlan_info_notif_v3(mvm, notif, |
| 2881 |
d3_data->status, len); |
| 2882 |
} else if (wowlan_info_ver == 5) { |
| 2883 |
struct iwl_wowlan_info_notif_v5 *notif = |
| 2884 |
(void *)pkt->data; |
| 2885 |
|
| 2886 |
iwl_mvm_parse_wowlan_info_notif(mvm, notif, |
| 2887 |
d3_data->status, len); |
| 2888 |
} else { |
| 2889 |
IWL_FW_CHECK(mvm, 1, |
| 2890 |
"Firmware advertises unknown WoWLAN info notification %d!\n", |
| 2891 |
wowlan_info_ver); |
| 2892 |
return false; |
| 2893 |
} |
| 2894 |
|
| 2895 |
d3_data->notif_received |= IWL_D3_NOTIF_WOWLAN_INFO; |
| 2896 |
|
| 2897 |
if (d3_data->status && |
| 2898 |
d3_data->status->wakeup_reasons & IWL_WOWLAN_WAKEUP_REASON_HAS_WAKEUP_PKT) |
| 2899 |
/* We are supposed to get also wake packet notif */ |
| 2900 |
d3_data->notif_expected |= IWL_D3_NOTIF_WOWLAN_WAKE_PKT; |
| 2901 |
|
| 2902 |
break; |
| 2903 |
} |
| 2904 |
case WIDE_ID(PROT_OFFLOAD_GROUP, WOWLAN_WAKE_PKT_NOTIFICATION): { |
| 2905 |
struct iwl_wowlan_wake_pkt_notif *notif = (void *)pkt->data; |
| 2906 |
|
| 2907 |
if (d3_data->notif_received & IWL_D3_NOTIF_WOWLAN_WAKE_PKT) { |
| 2908 |
/* We shouldn't get two wake packet notifications */ |
| 2909 |
IWL_ERR(mvm, |
| 2910 |
"Got additional wowlan wake packet notification\n"); |
| 2911 |
} else { |
| 2912 |
d3_data->notif_received |= IWL_D3_NOTIF_WOWLAN_WAKE_PKT; |
| 2913 |
len = iwl_rx_packet_payload_len(pkt); |
| 2914 |
ret = iwl_mvm_wowlan_store_wake_pkt(mvm, notif, |
| 2915 |
d3_data->status, |
| 2916 |
len); |
| 2917 |
if (ret) |
| 2918 |
IWL_ERR(mvm, |
| 2919 |
"Can't parse WOWLAN_WAKE_PKT_NOTIFICATION\n"); |
| 2920 |
} |
| 2921 |
|
| 2922 |
break; |
| 2923 |
} |
| 2924 |
case WIDE_ID(SCAN_GROUP, OFFLOAD_MATCH_INFO_NOTIF): { |
| 2925 |
struct iwl_scan_offload_match_info *notif = (void *)pkt->data; |
| 2926 |
|
| 2927 |
if (d3_data->notif_received & IWL_D3_ND_MATCH_INFO) { |
| 2928 |
IWL_ERR(mvm, |
| 2929 |
"Got additional netdetect match info\n"); |
| 2930 |
break; |
| 2931 |
} |
| 2932 |
|
| 2933 |
d3_data->notif_received |= IWL_D3_ND_MATCH_INFO; |
| 2934 |
|
| 2935 |
/* explicitly set this in the 'expected' as well */ |
| 2936 |
d3_data->notif_expected |= IWL_D3_ND_MATCH_INFO; |
| 2937 |
|
| 2938 |
len = iwl_rx_packet_payload_len(pkt); |
| 2939 |
iwl_mvm_nd_match_info_handler(mvm, d3_data, notif, len); |
| 2940 |
break; |
| 2941 |
} |
| 2942 |
case WIDE_ID(PROT_OFFLOAD_GROUP, D3_END_NOTIFICATION): { |
| 2943 |
struct iwl_d3_end_notif *notif = (void *)pkt->data; |
| 2944 |
|
| 2945 |
d3_data->d3_end_flags = __le32_to_cpu(notif->flags); |
| 2946 |
d3_data->notif_received |= IWL_D3_NOTIF_D3_END_NOTIF; |
| 2947 |
|
| 2948 |
break; |
| 2949 |
} |
| 2950 |
default: |
| 2951 |
WARN_ON(1); |
| 2952 |
} |
| 2953 |
|
| 2954 |
return d3_data->notif_received == d3_data->notif_expected; |
| 2955 |
} |
| 2956 |
|
| 2957 |
static int iwl_mvm_resume_firmware(struct iwl_mvm *mvm) |
| 2958 |
{ |
| 2959 |
int ret; |
| 2960 |
struct iwl_host_cmd cmd = { |
| 2961 |
.id = D0I3_END_CMD, |
| 2962 |
.flags = CMD_WANT_SKB, |
| 2963 |
}; |
| 2964 |
bool reset = fw_has_capa(&mvm->fw->ucode_capa, |
| 2965 |
IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
| 2966 |
|
| 2967 |
ret = iwl_trans_d3_resume(mvm->trans, !reset); |
| 2968 |
if (ret) |
| 2969 |
return ret; |
| 2970 |
|
| 2971 |
/* |
| 2972 |
* We should trigger resume flow using command only for 22000 family |
| 2973 |
* AX210 and above don't need the command since they have |
| 2974 |
* the doorbell interrupt. |
| 2975 |
*/ |
| 2976 |
if (mvm->trans->mac_cfg->device_family <= IWL_DEVICE_FAMILY_22000 && |
| 2977 |
fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_D0I3_END_FIRST)) { |
| 2978 |
ret = iwl_mvm_send_cmd(mvm, &cmd); |
| 2979 |
if (ret < 0) |
| 2980 |
IWL_ERR(mvm, "Failed to send D0I3_END_CMD first (%d)\n", |
| 2981 |
ret); |
| 2982 |
} |
| 2983 |
|
| 2984 |
return ret; |
| 2985 |
} |
| 2986 |
|
| 2987 |
#define IWL_MVM_D3_NOTIF_TIMEOUT (HZ / 3) |
| 2988 |
|
| 2989 |
static int iwl_mvm_d3_notif_wait(struct iwl_mvm *mvm, |
| 2990 |
struct iwl_d3_data *d3_data) |
| 2991 |
{ |
| 2992 |
static const u16 d3_resume_notif[] = { |
| 2993 |
WIDE_ID(PROT_OFFLOAD_GROUP, WOWLAN_INFO_NOTIFICATION), |
| 2994 |
WIDE_ID(PROT_OFFLOAD_GROUP, WOWLAN_WAKE_PKT_NOTIFICATION), |
| 2995 |
WIDE_ID(SCAN_GROUP, OFFLOAD_MATCH_INFO_NOTIF), |
| 2996 |
WIDE_ID(PROT_OFFLOAD_GROUP, D3_END_NOTIFICATION) |
| 2997 |
}; |
| 2998 |
static const u16 d3_fast_resume_notif[] = { |
| 2999 |
WIDE_ID(PROT_OFFLOAD_GROUP, D3_END_NOTIFICATION) |
| 3000 |
}; |
| 3001 |
struct iwl_notification_wait wait_d3_notif; |
| 3002 |
int ret; |
| 3003 |
|
| 3004 |
if (mvm->fast_resume) |
| 3005 |
iwl_init_notification_wait(&mvm->notif_wait, &wait_d3_notif, |
| 3006 |
d3_fast_resume_notif, |
| 3007 |
ARRAY_SIZE(d3_fast_resume_notif), |
| 3008 |
iwl_mvm_wait_d3_notif, d3_data); |
| 3009 |
else |
| 3010 |
iwl_init_notification_wait(&mvm->notif_wait, &wait_d3_notif, |
| 3011 |
d3_resume_notif, |
| 3012 |
ARRAY_SIZE(d3_resume_notif), |
| 3013 |
iwl_mvm_wait_d3_notif, d3_data); |
| 3014 |
|
| 3015 |
ret = iwl_mvm_resume_firmware(mvm); |
| 3016 |
if (ret) { |
| 3017 |
iwl_remove_notification(&mvm->notif_wait, &wait_d3_notif); |
| 3018 |
return ret; |
| 3019 |
} |
| 3020 |
|
| 3021 |
return iwl_wait_notification(&mvm->notif_wait, &wait_d3_notif, |
| 3022 |
IWL_MVM_D3_NOTIF_TIMEOUT); |
| 3023 |
} |
| 3024 |
|
| 3025 |
static inline bool iwl_mvm_d3_resume_notif_based(struct iwl_mvm *mvm) |
| 3026 |
{ |
| 3027 |
return iwl_fw_lookup_notif_ver(mvm->fw, PROT_OFFLOAD_GROUP, |
| 3028 |
WOWLAN_INFO_NOTIFICATION, 0) && |
| 3029 |
iwl_fw_lookup_notif_ver(mvm->fw, PROT_OFFLOAD_GROUP, |
| 3030 |
WOWLAN_WAKE_PKT_NOTIFICATION, 0) && |
| 3031 |
iwl_fw_lookup_notif_ver(mvm->fw, PROT_OFFLOAD_GROUP, |
| 3032 |
D3_END_NOTIFICATION, 0); |
| 3033 |
} |
| 3034 |
|
| 3035 |
static int __iwl_mvm_resume(struct iwl_mvm *mvm) |
| 3036 |
{ |
| 3037 |
struct ieee80211_vif *vif = NULL; |
| 3038 |
int ret = 1; |
| 3039 |
struct iwl_mvm_nd_results results = {}; |
| 3040 |
struct iwl_d3_data d3_data = { |
| 3041 |
.notif_expected = |
| 3042 |
IWL_D3_NOTIF_WOWLAN_INFO | |
| 3043 |
IWL_D3_NOTIF_D3_END_NOTIF, |
| 3044 |
.nd_results_valid = false, |
| 3045 |
.nd_results = &results, |
| 3046 |
}; |
| 3047 |
bool unified_image = fw_has_capa(&mvm->fw->ucode_capa, |
| 3048 |
IWL_UCODE_TLV_CAPA_CNSLDTD_D3_D0_IMG); |
| 3049 |
bool d0i3_first = fw_has_capa(&mvm->fw->ucode_capa, |
| 3050 |
IWL_UCODE_TLV_CAPA_D0I3_END_FIRST); |
| 3051 |
bool resume_notif_based = iwl_mvm_d3_resume_notif_based(mvm); |
| 3052 |
enum rt_status rt_status; |
| 3053 |
bool keep = false; |
| 3054 |
|
| 3055 |
mutex_lock(&mvm->mutex); |
| 3056 |
|
| 3057 |
/* Apparently, the device went away and device_powered_off() was called, |
| 3058 |
* don't even try to read the rt_status, the device is currently |
| 3059 |
* inaccessible. |
| 3060 |
*/ |
| 3061 |
if (!test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status)) { |
| 3062 |
IWL_INFO(mvm, |
| 3063 |
"Can't resume, device_powered_off() was called during wowlan\n"); |
| 3064 |
goto err; |
| 3065 |
} |
| 3066 |
|
| 3067 |
mvm->last_reset_or_resume_time_jiffies = jiffies; |
| 3068 |
|
| 3069 |
/* get the BSS vif pointer again */ |
| 3070 |
vif = iwl_mvm_get_bss_vif(mvm); |
| 3071 |
if (IS_ERR_OR_NULL(vif)) |
| 3072 |
goto err; |
| 3073 |
|
| 3074 |
iwl_fw_dbg_read_d3_debug_data(&mvm->fwrt); |
| 3075 |
|
| 3076 |
rt_status = iwl_mvm_check_rt_status(mvm, vif); |
| 3077 |
if (rt_status != FW_ALIVE) { |
| 3078 |
iwl_trans_notify_fw_error(mvm->trans); |
| 3079 |
if (rt_status == FW_ERROR) { |
| 3080 |
IWL_ERR(mvm, "FW Error occurred during suspend. Restarting.\n"); |
| 3081 |
iwl_mvm_dump_nic_error_log(mvm); |
| 3082 |
iwl_dbg_tlv_time_point(&mvm->fwrt, |
| 3083 |
IWL_FW_INI_TIME_POINT_FW_ASSERT, |
| 3084 |
NULL); |
| 3085 |
iwl_fw_dbg_collect_desc(&mvm->fwrt, |
| 3086 |
&iwl_dump_desc_assert, |
| 3087 |
false, 0); |
| 3088 |
} |
| 3089 |
ret = 1; |
| 3090 |
goto err; |
| 3091 |
} |
| 3092 |
|
| 3093 |
if (resume_notif_based) { |
| 3094 |
d3_data.status = kzalloc_obj(*d3_data.status); |
| 3095 |
if (!d3_data.status) { |
| 3096 |
IWL_ERR(mvm, "Failed to allocate wowlan status\n"); |
| 3097 |
ret = -ENOMEM; |
| 3098 |
goto err; |
| 3099 |
} |
| 3100 |
|
| 3101 |
ret = iwl_mvm_d3_notif_wait(mvm, &d3_data); |
| 3102 |
if (ret) |
| 3103 |
goto err; |
| 3104 |
} else { |
| 3105 |
ret = iwl_mvm_resume_firmware(mvm); |
| 3106 |
if (ret < 0) |
| 3107 |
goto err; |
| 3108 |
} |
| 3109 |
|
| 3110 |
/* when reset is required we can't send these following commands */ |
| 3111 |
if (d3_data.d3_end_flags & IWL_D0I3_RESET_REQUIRE) |
| 3112 |
goto query_wakeup_reasons; |
| 3113 |
|
| 3114 |
/* |
| 3115 |
* Query the current location and source from the D3 firmware so we |
| 3116 |
* can play it back when we re-intiailize the D0 firmware |
| 3117 |
*/ |
| 3118 |
iwl_mvm_update_changed_regdom(mvm); |
| 3119 |
|
| 3120 |
/* Re-configure PPAG settings */ |
| 3121 |
iwl_mvm_ppag_send_cmd(mvm); |
| 3122 |
|
| 3123 |
if (!unified_image) |
| 3124 |
/* Re-configure default SAR profile */ |
| 3125 |
iwl_mvm_sar_select_profile(mvm, 1, 1); |
| 3126 |
|
| 3127 |
if (mvm->net_detect && unified_image) { |
| 3128 |
/* If this is a non-unified image, we restart the FW, |
| 3129 |
* so no need to stop the netdetect scan. If that |
| 3130 |
* fails, continue and try to get the wake-up reasons, |
| 3131 |
* but trigger a HW restart by keeping a failure code |
| 3132 |
* in ret. |
| 3133 |
*/ |
| 3134 |
ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_NETDETECT, |
| 3135 |
false); |
| 3136 |
} |
| 3137 |
|
| 3138 |
query_wakeup_reasons: |
| 3139 |
keep = iwl_mvm_choose_query_wakeup_reasons(mvm, vif, &d3_data); |
| 3140 |
/* has unlocked the mutex, so skip that */ |
| 3141 |
goto out; |
| 3142 |
|
| 3143 |
err: |
| 3144 |
mutex_unlock(&mvm->mutex); |
| 3145 |
out: |
| 3146 |
if (d3_data.status) |
| 3147 |
kfree(d3_data.status->wake_packet); |
| 3148 |
kfree(d3_data.status); |
| 3149 |
iwl_mvm_free_nd(mvm); |
| 3150 |
|
| 3151 |
if (!mvm->net_detect) |
| 3152 |
ieee80211_iterate_active_interfaces_mtx(mvm->hw, |
| 3153 |
IEEE80211_IFACE_ITER_NORMAL, |
| 3154 |
iwl_mvm_d3_disconnect_iter, |
| 3155 |
keep ? vif : NULL); |
| 3156 |
|
| 3157 |
clear_bit(IWL_MVM_STATUS_IN_D3, &mvm->status); |
| 3158 |
|
| 3159 |
/* no need to reset the device in unified images, if successful */ |
| 3160 |
if (unified_image && !ret) { |
| 3161 |
/* nothing else to do if we already sent D0I3_END_CMD */ |
| 3162 |
if (d0i3_first) |
| 3163 |
return 0; |
| 3164 |
|
| 3165 |
if (!iwl_fw_lookup_notif_ver(mvm->fw, PROT_OFFLOAD_GROUP, |
| 3166 |
D3_END_NOTIFICATION, 0)) { |
| 3167 |
ret = iwl_mvm_send_cmd_pdu(mvm, D0I3_END_CMD, 0, 0, NULL); |
| 3168 |
if (!ret) |
| 3169 |
return 0; |
| 3170 |
} else if (!(d3_data.d3_end_flags & IWL_D0I3_RESET_REQUIRE)) { |
| 3171 |
return 0; |
| 3172 |
} |
| 3173 |
} |
| 3174 |
|
| 3175 |
/* |
| 3176 |
* Reconfigure the device in one of the following cases: |
| 3177 |
* 1. We are not using a unified image |
| 3178 |
* 2. We are using a unified image but had an error while exiting D3 |
| 3179 |
*/ |
| 3180 |
set_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); |
| 3181 |
|
| 3182 |
return 1; |
| 3183 |
} |
| 3184 |
|
| 3185 |
int iwl_mvm_resume(struct ieee80211_hw *hw) |
| 3186 |
{ |
| 3187 |
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3188 |
int ret; |
| 3189 |
|
| 3190 |
ret = __iwl_mvm_resume(mvm); |
| 3191 |
|
| 3192 |
iwl_mvm_resume_tcm(mvm); |
| 3193 |
|
| 3194 |
iwl_fw_runtime_resume(&mvm->fwrt); |
| 3195 |
|
| 3196 |
return ret; |
| 3197 |
} |
| 3198 |
|
| 3199 |
void iwl_mvm_set_wakeup(struct ieee80211_hw *hw, bool enabled) |
| 3200 |
{ |
| 3201 |
struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); |
| 3202 |
|
| 3203 |
device_set_wakeup_enable(mvm->trans->dev, enabled); |
| 3204 |
} |
| 3205 |
|
| 3206 |
void iwl_mvm_fast_suspend(struct iwl_mvm *mvm) |
| 3207 |
{ |
| 3208 |
struct iwl_d3_manager_config d3_cfg_cmd_data = {}; |
| 3209 |
int ret; |
| 3210 |
|
| 3211 |
lockdep_assert_held(&mvm->mutex); |
| 3212 |
|
| 3213 |
IWL_DEBUG_WOWLAN(mvm, "Starting fast suspend flow\n"); |
| 3214 |
|
| 3215 |
iwl_mvm_pause_tcm(mvm, true); |
| 3216 |
|
| 3217 |
mvm->fast_resume = true; |
| 3218 |
set_bit(IWL_MVM_STATUS_IN_D3, &mvm->status); |
| 3219 |
|
| 3220 |
WARN_ON(iwl_mvm_power_update_device(mvm)); |
| 3221 |
ret = iwl_mvm_send_cmd_pdu(mvm, D3_CONFIG_CMD, 0, |
| 3222 |
sizeof(d3_cfg_cmd_data), &d3_cfg_cmd_data); |
| 3223 |
if (ret) |
| 3224 |
IWL_ERR(mvm, |
| 3225 |
"fast suspend: couldn't send D3_CONFIG_CMD %d\n", ret); |
| 3226 |
|
| 3227 |
ret = iwl_trans_d3_suspend(mvm->trans, false); |
| 3228 |
if (ret) |
| 3229 |
IWL_ERR(mvm, "fast suspend: trans_d3_suspend failed %d\n", ret); |
| 3230 |
} |
| 3231 |
|
| 3232 |
int iwl_mvm_fast_resume(struct iwl_mvm *mvm) |
| 3233 |
{ |
| 3234 |
struct iwl_d3_data d3_data = { |
| 3235 |
.notif_expected = |
| 3236 |
IWL_D3_NOTIF_D3_END_NOTIF, |
| 3237 |
}; |
| 3238 |
enum rt_status rt_status; |
| 3239 |
int ret; |
| 3240 |
|
| 3241 |
lockdep_assert_held(&mvm->mutex); |
| 3242 |
|
| 3243 |
IWL_DEBUG_WOWLAN(mvm, "Starting the fast resume flow\n"); |
| 3244 |
|
| 3245 |
mvm->last_reset_or_resume_time_jiffies = jiffies; |
| 3246 |
iwl_fw_dbg_read_d3_debug_data(&mvm->fwrt); |
| 3247 |
|
| 3248 |
rt_status = iwl_mvm_check_rt_status(mvm, NULL); |
| 3249 |
if (rt_status != FW_ALIVE) { |
| 3250 |
iwl_trans_notify_fw_error(mvm->trans); |
| 3251 |
if (rt_status == FW_ERROR) { |
| 3252 |
IWL_ERR(mvm, |
| 3253 |
"iwl_mvm_check_rt_status failed, device is gone during suspend\n"); |
| 3254 |
iwl_mvm_dump_nic_error_log(mvm); |
| 3255 |
iwl_dbg_tlv_time_point(&mvm->fwrt, |
| 3256 |
IWL_FW_INI_TIME_POINT_FW_ASSERT, |
| 3257 |
NULL); |
| 3258 |
iwl_fw_dbg_collect_desc(&mvm->fwrt, |
| 3259 |
&iwl_dump_desc_assert, |
| 3260 |
false, 0); |
| 3261 |
} |
| 3262 |
ret = -ENODEV; |
| 3263 |
|
| 3264 |
goto out; |
| 3265 |
} |
| 3266 |
ret = iwl_mvm_d3_notif_wait(mvm, &d3_data); |
| 3267 |
|
| 3268 |
if (ret) { |
| 3269 |
IWL_ERR(mvm, "Couldn't get the d3 notif %d\n", ret); |
| 3270 |
mvm->trans->state = IWL_TRANS_NO_FW; |
| 3271 |
} |
| 3272 |
|
| 3273 |
iwl_mvm_resume_tcm(mvm); |
| 3274 |
|
| 3275 |
out: |
| 3276 |
clear_bit(IWL_MVM_STATUS_IN_D3, &mvm->status); |
| 3277 |
mvm->fast_resume = false; |
| 3278 |
|
| 3279 |
return ret; |
| 3280 |
} |