1 /******************************************************************************
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
62 *****************************************************************************/
64 #include <linux/etherdevice.h>
67 #include <net/cfg80211.h>
70 #include "iwl-modparams.h"
74 void iwl_mvm_set_rekey_data(struct ieee80211_hw
*hw
,
75 struct ieee80211_vif
*vif
,
76 struct cfg80211_gtk_rekey_data
*data
)
78 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
79 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
81 if (iwlwifi_mod_params
.sw_crypto
)
84 mutex_lock(&mvm
->mutex
);
86 memcpy(mvmvif
->rekey_data
.kek
, data
->kek
, NL80211_KEK_LEN
);
87 memcpy(mvmvif
->rekey_data
.kck
, data
->kck
, NL80211_KCK_LEN
);
88 mvmvif
->rekey_data
.replay_ctr
=
89 cpu_to_le64(be64_to_cpup((__be64
*)&data
->replay_ctr
));
90 mvmvif
->rekey_data
.valid
= true;
92 mutex_unlock(&mvm
->mutex
);
95 #if IS_ENABLED(CONFIG_IPV6)
96 void iwl_mvm_ipv6_addr_change(struct ieee80211_hw
*hw
,
97 struct ieee80211_vif
*vif
,
98 struct inet6_dev
*idev
)
100 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
101 struct inet6_ifaddr
*ifa
;
104 read_lock_bh(&idev
->lock
);
105 list_for_each_entry(ifa
, &idev
->addr_list
, if_list
) {
106 mvmvif
->target_ipv6_addrs
[idx
] = ifa
->addr
;
108 if (idx
>= IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_MAX
)
111 read_unlock_bh(&idev
->lock
);
113 mvmvif
->num_target_ipv6_addrs
= idx
;
117 void iwl_mvm_set_default_unicast_key(struct ieee80211_hw
*hw
,
118 struct ieee80211_vif
*vif
, int idx
)
120 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
122 mvmvif
->tx_key_idx
= idx
;
125 static void iwl_mvm_convert_p1k(u16
*p1k
, __le16
*out
)
129 for (i
= 0; i
< IWL_P1K_SIZE
; i
++)
130 out
[i
] = cpu_to_le16(p1k
[i
]);
133 struct wowlan_key_data
{
134 struct iwl_wowlan_rsc_tsc_params_cmd
*rsc_tsc
;
135 struct iwl_wowlan_tkip_params_cmd
*tkip
;
136 bool error
, use_rsc_tsc
, use_tkip
;
140 static void iwl_mvm_wowlan_program_keys(struct ieee80211_hw
*hw
,
141 struct ieee80211_vif
*vif
,
142 struct ieee80211_sta
*sta
,
143 struct ieee80211_key_conf
*key
,
146 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
147 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
148 struct wowlan_key_data
*data
= _data
;
149 struct aes_sc
*aes_sc
, *aes_tx_sc
= NULL
;
150 struct tkip_sc
*tkip_sc
, *tkip_tx_sc
= NULL
;
151 struct iwl_p1k_cache
*rx_p1ks
;
153 struct ieee80211_key_seq seq
;
155 u16 p1k
[IWL_P1K_SIZE
];
158 mutex_lock(&mvm
->mutex
);
160 switch (key
->cipher
) {
161 case WLAN_CIPHER_SUITE_WEP40
:
162 case WLAN_CIPHER_SUITE_WEP104
: { /* hack it for now */
164 struct iwl_mvm_wep_key_cmd wep_key_cmd
;
165 struct iwl_mvm_wep_key wep_key
;
167 .wep_key_cmd
.mac_id_n_color
=
168 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
170 .wep_key_cmd
.num_keys
= 1,
171 /* firmware sets STA_KEY_FLG_WEP_13BYTES */
172 .wep_key_cmd
.decryption_type
= STA_KEY_FLG_WEP
,
173 .wep_key
.key_index
= key
->keyidx
,
174 .wep_key
.key_size
= key
->keylen
,
178 * This will fail -- the key functions don't set support
179 * pairwise WEP keys. However, that's better than silently
180 * failing WoWLAN. Or maybe not?
182 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
)
185 memcpy(&wkc
.wep_key
.key
[3], key
->key
, key
->keylen
);
186 if (key
->keyidx
== mvmvif
->tx_key_idx
) {
187 /* TX key must be at offset 0 */
188 wkc
.wep_key
.key_offset
= 0;
190 /* others start at 1 */
192 wkc
.wep_key
.key_offset
= data
->wep_key_idx
;
195 ret
= iwl_mvm_send_cmd_pdu(mvm
, WEP_KEY
, CMD_SYNC
,
197 data
->error
= ret
!= 0;
199 mvm
->ptk_ivlen
= key
->iv_len
;
200 mvm
->ptk_icvlen
= key
->icv_len
;
201 mvm
->gtk_ivlen
= key
->iv_len
;
202 mvm
->gtk_icvlen
= key
->icv_len
;
204 /* don't upload key again */
210 case WLAN_CIPHER_SUITE_AES_CMAC
:
212 * Ignore CMAC keys -- the WoWLAN firmware doesn't support them
213 * but we also shouldn't abort suspend due to that. It does have
214 * support for the IGTK key renewal, but doesn't really use the
215 * IGTK for anything. This means we could spuriously wake up or
216 * be deauthenticated, but that was considered acceptable.
219 case WLAN_CIPHER_SUITE_TKIP
:
221 tkip_sc
= data
->rsc_tsc
->all_tsc_rsc
.tkip
.unicast_rsc
;
222 tkip_tx_sc
= &data
->rsc_tsc
->all_tsc_rsc
.tkip
.tsc
;
224 rx_p1ks
= data
->tkip
->rx_uni
;
226 ieee80211_get_key_tx_seq(key
, &seq
);
227 tkip_tx_sc
->iv16
= cpu_to_le16(seq
.tkip
.iv16
);
228 tkip_tx_sc
->iv32
= cpu_to_le32(seq
.tkip
.iv32
);
230 ieee80211_get_tkip_p1k_iv(key
, seq
.tkip
.iv32
, p1k
);
231 iwl_mvm_convert_p1k(p1k
, data
->tkip
->tx
.p1k
);
233 memcpy(data
->tkip
->mic_keys
.tx
,
234 &key
->key
[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY
],
237 rx_mic_key
= data
->tkip
->mic_keys
.rx_unicast
;
240 data
->rsc_tsc
->all_tsc_rsc
.tkip
.multicast_rsc
;
241 rx_p1ks
= data
->tkip
->rx_multi
;
242 rx_mic_key
= data
->tkip
->mic_keys
.rx_mcast
;
246 * For non-QoS this relies on the fact that both the uCode and
247 * mac80211 use TID 0 (as they need to to avoid replay attacks)
248 * for checking the IV in the frames.
250 for (i
= 0; i
< IWL_NUM_RSC
; i
++) {
251 ieee80211_get_key_rx_seq(key
, i
, &seq
);
252 tkip_sc
[i
].iv16
= cpu_to_le16(seq
.tkip
.iv16
);
253 tkip_sc
[i
].iv32
= cpu_to_le32(seq
.tkip
.iv32
);
254 /* wrapping isn't allowed, AP must rekey */
255 if (seq
.tkip
.iv32
> cur_rx_iv32
)
256 cur_rx_iv32
= seq
.tkip
.iv32
;
259 ieee80211_get_tkip_rx_p1k(key
, vif
->bss_conf
.bssid
,
261 iwl_mvm_convert_p1k(p1k
, rx_p1ks
[0].p1k
);
262 ieee80211_get_tkip_rx_p1k(key
, vif
->bss_conf
.bssid
,
263 cur_rx_iv32
+ 1, p1k
);
264 iwl_mvm_convert_p1k(p1k
, rx_p1ks
[1].p1k
);
267 &key
->key
[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY
],
270 data
->use_tkip
= true;
271 data
->use_rsc_tsc
= true;
273 case WLAN_CIPHER_SUITE_CCMP
:
275 u8
*pn
= seq
.ccmp
.pn
;
277 aes_sc
= data
->rsc_tsc
->all_tsc_rsc
.aes
.unicast_rsc
;
278 aes_tx_sc
= &data
->rsc_tsc
->all_tsc_rsc
.aes
.tsc
;
280 ieee80211_get_key_tx_seq(key
, &seq
);
281 aes_tx_sc
->pn
= cpu_to_le64((u64
)pn
[5] |
288 aes_sc
= data
->rsc_tsc
->all_tsc_rsc
.aes
.multicast_rsc
;
292 * For non-QoS this relies on the fact that both the uCode and
293 * mac80211 use TID 0 for checking the IV in the frames.
295 for (i
= 0; i
< IWL_NUM_RSC
; i
++) {
296 u8
*pn
= seq
.ccmp
.pn
;
298 ieee80211_get_key_rx_seq(key
, i
, &seq
);
299 aes_sc
[i
].pn
= cpu_to_le64((u64
)pn
[5] |
306 data
->use_rsc_tsc
= true;
311 * The D3 firmware hardcodes the key offset 0 as the key it uses
312 * to transmit packets to the AP, i.e. the PTK.
314 if (key
->flags
& IEEE80211_KEY_FLAG_PAIRWISE
) {
316 mvm
->ptk_ivlen
= key
->iv_len
;
317 mvm
->ptk_icvlen
= key
->icv_len
;
320 * firmware only supports TSC/RSC for a single key,
321 * so if there are multiple keep overwriting them
322 * with new ones -- this relies on mac80211 doing
326 mvm
->gtk_ivlen
= key
->iv_len
;
327 mvm
->gtk_icvlen
= key
->icv_len
;
330 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, true);
331 data
->error
= ret
!= 0;
333 mutex_unlock(&mvm
->mutex
);
336 static int iwl_mvm_send_patterns(struct iwl_mvm
*mvm
,
337 struct cfg80211_wowlan
*wowlan
)
339 struct iwl_wowlan_patterns_cmd
*pattern_cmd
;
340 struct iwl_host_cmd cmd
= {
341 .id
= WOWLAN_PATTERNS
,
342 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
347 if (!wowlan
->n_patterns
)
350 cmd
.len
[0] = sizeof(*pattern_cmd
) +
351 wowlan
->n_patterns
* sizeof(struct iwl_wowlan_pattern
);
353 pattern_cmd
= kmalloc(cmd
.len
[0], GFP_KERNEL
);
357 pattern_cmd
->n_patterns
= cpu_to_le32(wowlan
->n_patterns
);
359 for (i
= 0; i
< wowlan
->n_patterns
; i
++) {
360 int mask_len
= DIV_ROUND_UP(wowlan
->patterns
[i
].pattern_len
, 8);
362 memcpy(&pattern_cmd
->patterns
[i
].mask
,
363 wowlan
->patterns
[i
].mask
, mask_len
);
364 memcpy(&pattern_cmd
->patterns
[i
].pattern
,
365 wowlan
->patterns
[i
].pattern
,
366 wowlan
->patterns
[i
].pattern_len
);
367 pattern_cmd
->patterns
[i
].mask_size
= mask_len
;
368 pattern_cmd
->patterns
[i
].pattern_size
=
369 wowlan
->patterns
[i
].pattern_len
;
372 cmd
.data
[0] = pattern_cmd
;
373 err
= iwl_mvm_send_cmd(mvm
, &cmd
);
378 static int iwl_mvm_send_proto_offload(struct iwl_mvm
*mvm
,
379 struct ieee80211_vif
*vif
)
382 struct iwl_proto_offload_cmd_v1 v1
;
383 struct iwl_proto_offload_cmd_v2 v2
;
385 struct iwl_proto_offload_cmd_common
*common
;
386 u32 enabled
= 0, size
;
387 #if IS_ENABLED(CONFIG_IPV6)
388 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
391 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS
) {
392 if (mvmvif
->num_target_ipv6_addrs
) {
393 enabled
|= IWL_D3_PROTO_OFFLOAD_NS
;
394 memcpy(cmd
.v2
.ndp_mac_addr
, vif
->addr
, ETH_ALEN
);
397 BUILD_BUG_ON(sizeof(cmd
.v2
.target_ipv6_addr
[0]) !=
398 sizeof(mvmvif
->target_ipv6_addrs
[0]));
400 for (i
= 0; i
< min(mvmvif
->num_target_ipv6_addrs
,
401 IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V2
); i
++)
402 memcpy(cmd
.v2
.target_ipv6_addr
[i
],
403 &mvmvif
->target_ipv6_addrs
[i
],
404 sizeof(cmd
.v2
.target_ipv6_addr
[i
]));
406 if (mvmvif
->num_target_ipv6_addrs
) {
407 enabled
|= IWL_D3_PROTO_OFFLOAD_NS
;
408 memcpy(cmd
.v1
.ndp_mac_addr
, vif
->addr
, ETH_ALEN
);
411 BUILD_BUG_ON(sizeof(cmd
.v1
.target_ipv6_addr
[0]) !=
412 sizeof(mvmvif
->target_ipv6_addrs
[0]));
414 for (i
= 0; i
< min(mvmvif
->num_target_ipv6_addrs
,
415 IWL_PROTO_OFFLOAD_NUM_IPV6_ADDRS_V1
); i
++)
416 memcpy(cmd
.v1
.target_ipv6_addr
[i
],
417 &mvmvif
->target_ipv6_addrs
[i
],
418 sizeof(cmd
.v1
.target_ipv6_addr
[i
]));
422 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_D3_6_IPV6_ADDRS
) {
423 common
= &cmd
.v2
.common
;
424 size
= sizeof(cmd
.v2
);
426 common
= &cmd
.v1
.common
;
427 size
= sizeof(cmd
.v1
);
430 if (vif
->bss_conf
.arp_addr_cnt
) {
431 enabled
|= IWL_D3_PROTO_OFFLOAD_ARP
;
432 common
->host_ipv4_addr
= vif
->bss_conf
.arp_addr_list
[0];
433 memcpy(common
->arp_mac_addr
, vif
->addr
, ETH_ALEN
);
439 common
->enabled
= cpu_to_le32(enabled
);
441 return iwl_mvm_send_cmd_pdu(mvm
, PROT_OFFLOAD_CONFIG_CMD
, CMD_SYNC
,
445 enum iwl_mvm_tcp_packet_type
{
454 static __le16
pseudo_hdr_check(int len
, __be32 saddr
, __be32 daddr
)
456 __sum16 check
= tcp_v4_check(len
, saddr
, daddr
, 0);
457 return cpu_to_le16(be16_to_cpu((__force __be16
)check
));
460 static void iwl_mvm_build_tcp_packet(struct ieee80211_vif
*vif
,
461 struct cfg80211_wowlan_tcp
*tcp
,
462 void *_pkt
, u8
*mask
,
463 __le16
*pseudo_hdr_csum
,
464 enum iwl_mvm_tcp_packet_type ptype
)
471 } __packed
*pkt
= _pkt
;
472 u16 ip_tot_len
= sizeof(struct iphdr
) + sizeof(struct tcphdr
);
475 pkt
->eth
.h_proto
= cpu_to_be16(ETH_P_IP
),
478 pkt
->ip
.protocol
= IPPROTO_TCP
;
482 case MVM_TCP_TX_DATA
:
484 memcpy(pkt
->eth
.h_dest
, tcp
->dst_mac
, ETH_ALEN
);
485 memcpy(pkt
->eth
.h_source
, vif
->addr
, ETH_ALEN
);
487 pkt
->ip
.saddr
= tcp
->src
;
488 pkt
->ip
.daddr
= tcp
->dst
;
489 pkt
->tcp
.source
= cpu_to_be16(tcp
->src_port
);
490 pkt
->tcp
.dest
= cpu_to_be16(tcp
->dst_port
);
491 /* overwritten for TX SYN later */
492 pkt
->tcp
.doff
= sizeof(struct tcphdr
) / 4;
493 pkt
->tcp
.window
= cpu_to_be16(65000);
495 case MVM_TCP_RX_SYNACK
:
497 case MVM_TCP_RX_WAKE
:
498 memcpy(pkt
->eth
.h_dest
, vif
->addr
, ETH_ALEN
);
499 memcpy(pkt
->eth
.h_source
, tcp
->dst_mac
, ETH_ALEN
);
500 pkt
->ip
.saddr
= tcp
->dst
;
501 pkt
->ip
.daddr
= tcp
->src
;
502 pkt
->tcp
.source
= cpu_to_be16(tcp
->dst_port
);
503 pkt
->tcp
.dest
= cpu_to_be16(tcp
->src_port
);
512 /* firmware assumes 8 option bytes - 8 NOPs for now */
513 memset(pkt
->data
, 0x01, 8);
515 pkt
->tcp
.doff
= (sizeof(struct tcphdr
) + 8) / 4;
518 case MVM_TCP_TX_DATA
:
519 ip_tot_len
+= tcp
->payload_len
;
520 memcpy(pkt
->data
, tcp
->payload
, tcp
->payload_len
);
528 case MVM_TCP_RX_SYNACK
:
535 case MVM_TCP_RX_WAKE
:
536 ip_tot_len
+= tcp
->wake_len
;
539 memcpy(pkt
->data
, tcp
->wake_data
, tcp
->wake_len
);
545 case MVM_TCP_TX_DATA
:
547 pkt
->ip
.tot_len
= cpu_to_be16(ip_tot_len
);
548 pkt
->ip
.check
= ip_fast_csum(&pkt
->ip
, pkt
->ip
.ihl
);
550 case MVM_TCP_RX_WAKE
:
551 for (i
= 0; i
< DIV_ROUND_UP(tcp
->wake_len
, 8); i
++) {
552 u8 tmp
= tcp
->wake_mask
[i
];
553 mask
[i
+ 6] |= tmp
<< 6;
554 if (i
+ 1 < DIV_ROUND_UP(tcp
->wake_len
, 8))
555 mask
[i
+ 7] = tmp
>> 2;
557 /* fall through for ethernet/IP/TCP headers mask */
558 case MVM_TCP_RX_SYNACK
:
560 mask
[0] = 0xff; /* match ethernet */
562 * match ethernet, ip.version, ip.ihl
563 * the ip.ihl half byte is really masked out by firmware
566 mask
[2] = 0x80; /* match ip.protocol */
567 mask
[3] = 0xfc; /* match ip.saddr, ip.daddr */
568 mask
[4] = 0x3f; /* match ip.daddr, tcp.source, tcp.dest */
569 mask
[5] = 0x80; /* match tcp flags */
570 /* leave rest (0 or set for MVM_TCP_RX_WAKE) */
574 *pseudo_hdr_csum
= pseudo_hdr_check(ip_tot_len
- sizeof(struct iphdr
),
575 pkt
->ip
.saddr
, pkt
->ip
.daddr
);
578 static int iwl_mvm_send_remote_wake_cfg(struct iwl_mvm
*mvm
,
579 struct ieee80211_vif
*vif
,
580 struct cfg80211_wowlan_tcp
*tcp
)
582 struct iwl_wowlan_remote_wake_config
*cfg
;
583 struct iwl_host_cmd cmd
= {
584 .id
= REMOTE_WAKE_CONFIG_CMD
,
585 .len
= { sizeof(*cfg
), },
586 .dataflags
= { IWL_HCMD_DFL_NOCOPY
, },
594 cfg
= kzalloc(sizeof(*cfg
), GFP_KERNEL
);
599 cfg
->max_syn_retries
= 10;
600 cfg
->max_data_retries
= 10;
601 cfg
->tcp_syn_ack_timeout
= 1; /* seconds */
602 cfg
->tcp_ack_timeout
= 1; /* seconds */
605 iwl_mvm_build_tcp_packet(
606 vif
, tcp
, cfg
->syn_tx
.data
, NULL
,
607 &cfg
->syn_tx
.info
.tcp_pseudo_header_checksum
,
609 cfg
->syn_tx
.info
.tcp_payload_length
= 0;
612 iwl_mvm_build_tcp_packet(
613 vif
, tcp
, cfg
->synack_rx
.data
, cfg
->synack_rx
.rx_mask
,
614 &cfg
->synack_rx
.info
.tcp_pseudo_header_checksum
,
616 cfg
->synack_rx
.info
.tcp_payload_length
= 0;
618 /* KEEPALIVE/ACK (TX) */
619 iwl_mvm_build_tcp_packet(
620 vif
, tcp
, cfg
->keepalive_tx
.data
, NULL
,
621 &cfg
->keepalive_tx
.info
.tcp_pseudo_header_checksum
,
623 cfg
->keepalive_tx
.info
.tcp_payload_length
=
624 cpu_to_le16(tcp
->payload_len
);
625 cfg
->sequence_number_offset
= tcp
->payload_seq
.offset
;
626 /* length must be 0..4, the field is little endian */
627 cfg
->sequence_number_length
= tcp
->payload_seq
.len
;
628 cfg
->initial_sequence_number
= cpu_to_le32(tcp
->payload_seq
.start
);
629 cfg
->keepalive_interval
= cpu_to_le16(tcp
->data_interval
);
630 if (tcp
->payload_tok
.len
) {
631 cfg
->token_offset
= tcp
->payload_tok
.offset
;
632 cfg
->token_length
= tcp
->payload_tok
.len
;
634 cpu_to_le16(tcp
->tokens_size
% tcp
->payload_tok
.len
);
635 memcpy(cfg
->tokens
, tcp
->payload_tok
.token_stream
,
638 /* set tokens to max value to almost never run out */
639 cfg
->num_tokens
= cpu_to_le16(65535);
643 iwl_mvm_build_tcp_packet(
644 vif
, tcp
, cfg
->keepalive_ack_rx
.data
,
645 cfg
->keepalive_ack_rx
.rx_mask
,
646 &cfg
->keepalive_ack_rx
.info
.tcp_pseudo_header_checksum
,
648 cfg
->keepalive_ack_rx
.info
.tcp_payload_length
= 0;
651 iwl_mvm_build_tcp_packet(
652 vif
, tcp
, cfg
->wake_rx
.data
, cfg
->wake_rx
.rx_mask
,
653 &cfg
->wake_rx
.info
.tcp_pseudo_header_checksum
,
655 cfg
->wake_rx
.info
.tcp_payload_length
=
656 cpu_to_le16(tcp
->wake_len
);
659 iwl_mvm_build_tcp_packet(
660 vif
, tcp
, cfg
->fin_tx
.data
, NULL
,
661 &cfg
->fin_tx
.info
.tcp_pseudo_header_checksum
,
663 cfg
->fin_tx
.info
.tcp_payload_length
= 0;
665 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
671 struct iwl_d3_iter_data
{
673 struct ieee80211_vif
*vif
;
677 static void iwl_mvm_d3_iface_iterator(void *_data
, u8
*mac
,
678 struct ieee80211_vif
*vif
)
680 struct iwl_d3_iter_data
*data
= _data
;
681 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
683 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
)
686 if (mvmvif
->ap_sta_id
== IWL_MVM_STATION_COUNT
)
690 IWL_ERR(data
->mvm
, "More than one managed interface active!\n");
698 static int iwl_mvm_d3_reprogram(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
699 struct ieee80211_sta
*ap_sta
)
701 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
702 struct ieee80211_chanctx_conf
*ctx
;
703 u8 chains_static
, chains_dynamic
;
704 struct cfg80211_chan_def chandef
;
706 struct iwl_binding_cmd binding_cmd
= {};
707 struct iwl_time_quota_cmd quota_cmd
= {};
710 /* add back the PHY */
711 if (WARN_ON(!mvmvif
->phy_ctxt
))
715 ctx
= rcu_dereference(vif
->chanctx_conf
);
721 chains_static
= ctx
->rx_chains_static
;
722 chains_dynamic
= ctx
->rx_chains_dynamic
;
725 ret
= iwl_mvm_phy_ctxt_add(mvm
, mvmvif
->phy_ctxt
, &chandef
,
726 chains_static
, chains_dynamic
);
730 /* add back the MAC */
731 mvmvif
->uploaded
= false;
733 if (WARN_ON(!vif
->bss_conf
.assoc
))
736 vif
->bss_conf
.assoc
= false;
737 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
738 vif
->bss_conf
.assoc
= true;
742 /* add back binding - XXX refactor? */
743 binding_cmd
.id_and_color
=
744 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->phy_ctxt
->id
,
745 mvmvif
->phy_ctxt
->color
));
746 binding_cmd
.action
= cpu_to_le32(FW_CTXT_ACTION_ADD
);
748 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->phy_ctxt
->id
,
749 mvmvif
->phy_ctxt
->color
));
750 binding_cmd
.macs
[0] = cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->id
,
752 for (i
= 1; i
< MAX_MACS_IN_BINDING
; i
++)
753 binding_cmd
.macs
[i
] = cpu_to_le32(FW_CTXT_INVALID
);
756 ret
= iwl_mvm_send_cmd_pdu_status(mvm
, BINDING_CONTEXT_CMD
,
757 sizeof(binding_cmd
), &binding_cmd
,
760 IWL_ERR(mvm
, "Failed to add binding: %d\n", ret
);
765 IWL_ERR(mvm
, "Binding command failed: %u\n", status
);
769 ret
= iwl_mvm_sta_send_to_fw(mvm
, ap_sta
, false);
772 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvmvif
->ap_sta_id
], ap_sta
);
774 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
779 quota_cmd
.quotas
[0].id_and_color
=
780 cpu_to_le32(FW_CMD_ID_AND_COLOR(mvmvif
->phy_ctxt
->id
,
781 mvmvif
->phy_ctxt
->color
));
782 quota_cmd
.quotas
[0].quota
= cpu_to_le32(100);
783 quota_cmd
.quotas
[0].max_duration
= cpu_to_le32(1000);
785 for (i
= 1; i
< MAX_BINDINGS
; i
++)
786 quota_cmd
.quotas
[i
].id_and_color
= cpu_to_le32(FW_CTXT_INVALID
);
788 ret
= iwl_mvm_send_cmd_pdu(mvm
, TIME_QUOTA_CMD
, CMD_SYNC
,
789 sizeof(quota_cmd
), "a_cmd
);
791 IWL_ERR(mvm
, "Failed to send quota: %d\n", ret
);
796 static int __iwl_mvm_suspend(struct ieee80211_hw
*hw
,
797 struct cfg80211_wowlan
*wowlan
,
800 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
801 struct iwl_d3_iter_data suspend_iter_data
= {
804 struct ieee80211_vif
*vif
;
805 struct iwl_mvm_vif
*mvmvif
;
806 struct ieee80211_sta
*ap_sta
;
807 struct iwl_mvm_sta
*mvm_ap_sta
;
808 struct iwl_wowlan_config_cmd wowlan_config_cmd
= {};
809 struct iwl_wowlan_kek_kck_material_cmd kek_kck_cmd
= {};
810 struct iwl_wowlan_tkip_params_cmd tkip_cmd
= {};
811 struct iwl_d3_manager_config d3_cfg_cmd_data
= {
813 * Program the minimum sleep time to 10 seconds, as many
814 * platforms have issues processing a wakeup signal while
815 * still being in the process of suspending.
817 .min_sleep_time
= cpu_to_le32(10 * 1000 * 1000),
819 struct iwl_host_cmd d3_cfg_cmd
= {
821 .flags
= CMD_SYNC
| CMD_WANT_SKB
,
822 .data
[0] = &d3_cfg_cmd_data
,
823 .len
[0] = sizeof(d3_cfg_cmd_data
),
825 struct wowlan_key_data key_data
= {
826 .use_rsc_tsc
= false,
831 int len __maybe_unused
;
833 u8 old_aux_sta_id
, old_ap_sta_id
= IWL_MVM_STATION_COUNT
;
837 * mac80211 shouldn't get here, but for D3 test
838 * it doesn't warrant a warning
844 key_data
.rsc_tsc
= kzalloc(sizeof(*key_data
.rsc_tsc
), GFP_KERNEL
);
845 if (!key_data
.rsc_tsc
)
848 mutex_lock(&mvm
->mutex
);
850 old_aux_sta_id
= mvm
->aux_sta
.sta_id
;
852 /* see if there's only a single BSS vif and it's associated */
853 ieee80211_iterate_active_interfaces_atomic(
854 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
855 iwl_mvm_d3_iface_iterator
, &suspend_iter_data
);
857 if (suspend_iter_data
.error
|| !suspend_iter_data
.vif
) {
862 vif
= suspend_iter_data
.vif
;
863 mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
865 ap_sta
= rcu_dereference_protected(
866 mvm
->fw_id_to_mac_id
[mvmvif
->ap_sta_id
],
867 lockdep_is_held(&mvm
->mutex
));
868 if (IS_ERR_OR_NULL(ap_sta
)) {
873 mvm_ap_sta
= (struct iwl_mvm_sta
*)ap_sta
->drv_priv
;
876 * The D3 firmware still hardcodes the AP station ID for the
877 * BSS we're associated with as 0. Store the real STA ID here
878 * and assign 0. When we leave this function, we'll restore
879 * the original value for the resume code.
881 old_ap_sta_id
= mvm_ap_sta
->sta_id
;
882 mvm_ap_sta
->sta_id
= 0;
883 mvmvif
->ap_sta_id
= 0;
885 /* TODO: wowlan_config_cmd.wowlan_ba_teardown_tids */
887 wowlan_config_cmd
.is_11n_connection
= ap_sta
->ht_cap
.ht_supported
;
890 * We know the last used seqno, and the uCode expects to know that
891 * one, it will increment before TX.
893 seq
= mvm_ap_sta
->last_seq_ctl
& IEEE80211_SCTL_SEQ
;
894 wowlan_config_cmd
.non_qos_seq
= cpu_to_le16(seq
);
897 * For QoS counters, we store the one to use next, so subtract 0x10
898 * since the uCode will add 0x10 *before* using the value while we
899 * increment after using the value (i.e. store the next value to use).
901 for (i
= 0; i
< IWL_MAX_TID_COUNT
; i
++) {
902 seq
= mvm_ap_sta
->tid_data
[i
].seq_number
;
904 wowlan_config_cmd
.qos_seq
[i
] = cpu_to_le16(seq
);
907 if (wowlan
->disconnect
)
908 wowlan_config_cmd
.wakeup_filter
|=
909 cpu_to_le32(IWL_WOWLAN_WAKEUP_BEACON_MISS
|
910 IWL_WOWLAN_WAKEUP_LINK_CHANGE
);
911 if (wowlan
->magic_pkt
)
912 wowlan_config_cmd
.wakeup_filter
|=
913 cpu_to_le32(IWL_WOWLAN_WAKEUP_MAGIC_PACKET
);
914 if (wowlan
->gtk_rekey_failure
)
915 wowlan_config_cmd
.wakeup_filter
|=
916 cpu_to_le32(IWL_WOWLAN_WAKEUP_GTK_REKEY_FAIL
);
917 if (wowlan
->eap_identity_req
)
918 wowlan_config_cmd
.wakeup_filter
|=
919 cpu_to_le32(IWL_WOWLAN_WAKEUP_EAP_IDENT_REQ
);
920 if (wowlan
->four_way_handshake
)
921 wowlan_config_cmd
.wakeup_filter
|=
922 cpu_to_le32(IWL_WOWLAN_WAKEUP_4WAY_HANDSHAKE
);
923 if (wowlan
->n_patterns
)
924 wowlan_config_cmd
.wakeup_filter
|=
925 cpu_to_le32(IWL_WOWLAN_WAKEUP_PATTERN_MATCH
);
927 if (wowlan
->rfkill_release
)
928 wowlan_config_cmd
.wakeup_filter
|=
929 cpu_to_le32(IWL_WOWLAN_WAKEUP_RF_KILL_DEASSERT
);
933 * Set the "link change" (really "link lost") flag as well
934 * since that implies losing the TCP connection.
936 wowlan_config_cmd
.wakeup_filter
|=
937 cpu_to_le32(IWL_WOWLAN_WAKEUP_REMOTE_LINK_LOSS
|
938 IWL_WOWLAN_WAKEUP_REMOTE_SIGNATURE_TABLE
|
939 IWL_WOWLAN_WAKEUP_REMOTE_WAKEUP_PACKET
|
940 IWL_WOWLAN_WAKEUP_LINK_CHANGE
);
943 iwl_mvm_cancel_scan(mvm
);
945 iwl_trans_stop_device(mvm
->trans
);
948 * Set the HW restart bit -- this is mostly true as we're
949 * going to load new firmware and reprogram that, though
950 * the reprogramming is going to be manual to avoid adding
951 * all the MACs that aren't support.
952 * We don't have to clear up everything though because the
953 * reprogramming is manual. When we resume, we'll actually
954 * go through a proper restart sequence again to switch
955 * back to the runtime firmware image.
957 set_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
959 /* We reprogram keys and shouldn't allocate new key indices */
960 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
968 * The D3 firmware still hardcodes the AP station ID for the
969 * BSS we're associated with as 0. As a result, we have to move
970 * the auxiliary station to ID 1 so the ID 0 remains free for
971 * the AP station for later.
972 * We set the sta_id to 1 here, and reset it to its previous
973 * value (that we stored above) later.
975 mvm
->aux_sta
.sta_id
= 1;
977 ret
= iwl_mvm_load_d3_fw(mvm
);
981 ret
= iwl_mvm_d3_reprogram(mvm
, vif
, ap_sta
);
985 if (!iwlwifi_mod_params
.sw_crypto
) {
987 * This needs to be unlocked due to lock ordering
988 * constraints. Since we're in the suspend path
989 * that isn't really a problem though.
991 mutex_unlock(&mvm
->mutex
);
992 ieee80211_iter_keys(mvm
->hw
, vif
,
993 iwl_mvm_wowlan_program_keys
,
995 mutex_lock(&mvm
->mutex
);
996 if (key_data
.error
) {
1001 if (key_data
.use_rsc_tsc
) {
1002 struct iwl_host_cmd rsc_tsc_cmd
= {
1003 .id
= WOWLAN_TSC_RSC_PARAM
,
1005 .data
[0] = key_data
.rsc_tsc
,
1006 .dataflags
[0] = IWL_HCMD_DFL_NOCOPY
,
1007 .len
[0] = sizeof(*key_data
.rsc_tsc
),
1010 ret
= iwl_mvm_send_cmd(mvm
, &rsc_tsc_cmd
);
1015 if (key_data
.use_tkip
) {
1016 ret
= iwl_mvm_send_cmd_pdu(mvm
,
1018 CMD_SYNC
, sizeof(tkip_cmd
),
1024 if (mvmvif
->rekey_data
.valid
) {
1025 memset(&kek_kck_cmd
, 0, sizeof(kek_kck_cmd
));
1026 memcpy(kek_kck_cmd
.kck
, mvmvif
->rekey_data
.kck
,
1028 kek_kck_cmd
.kck_len
= cpu_to_le16(NL80211_KCK_LEN
);
1029 memcpy(kek_kck_cmd
.kek
, mvmvif
->rekey_data
.kek
,
1031 kek_kck_cmd
.kek_len
= cpu_to_le16(NL80211_KEK_LEN
);
1032 kek_kck_cmd
.replay_ctr
= mvmvif
->rekey_data
.replay_ctr
;
1034 ret
= iwl_mvm_send_cmd_pdu(mvm
,
1035 WOWLAN_KEK_KCK_MATERIAL
,
1037 sizeof(kek_kck_cmd
),
1044 ret
= iwl_mvm_send_cmd_pdu(mvm
, WOWLAN_CONFIGURATION
,
1045 CMD_SYNC
, sizeof(wowlan_config_cmd
),
1046 &wowlan_config_cmd
);
1050 ret
= iwl_mvm_send_patterns(mvm
, wowlan
);
1054 ret
= iwl_mvm_send_proto_offload(mvm
, vif
);
1058 ret
= iwl_mvm_send_remote_wake_cfg(mvm
, vif
, wowlan
->tcp
);
1062 ret
= iwl_mvm_power_update_mode(mvm
, vif
);
1066 #ifdef CONFIG_IWLWIFI_DEBUGFS
1067 if (mvm
->d3_wake_sysassert
)
1068 d3_cfg_cmd_data
.wakeup_flags
|=
1069 cpu_to_le32(IWL_WAKEUP_D3_CONFIG_FW_ERROR
);
1072 /* must be last -- this switches firmware state */
1073 ret
= iwl_mvm_send_cmd(mvm
, &d3_cfg_cmd
);
1076 #ifdef CONFIG_IWLWIFI_DEBUGFS
1077 len
= le32_to_cpu(d3_cfg_cmd
.resp_pkt
->len_n_flags
) &
1078 FH_RSCSR_FRAME_SIZE_MSK
;
1079 if (len
>= sizeof(u32
) * 2) {
1080 mvm
->d3_test_pme_ptr
=
1081 le32_to_cpup((__le32
*)d3_cfg_cmd
.resp_pkt
->data
);
1083 /* in test mode we require the pointer */
1088 iwl_free_resp(&d3_cfg_cmd
);
1090 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
1092 iwl_trans_d3_suspend(mvm
->trans
, test
);
1094 mvm
->aux_sta
.sta_id
= old_aux_sta_id
;
1095 mvm_ap_sta
->sta_id
= old_ap_sta_id
;
1096 mvmvif
->ap_sta_id
= old_ap_sta_id
;
1098 kfree(key_data
.rsc_tsc
);
1100 ieee80211_restart_hw(mvm
->hw
);
1102 mutex_unlock(&mvm
->mutex
);
1107 int iwl_mvm_suspend(struct ieee80211_hw
*hw
, struct cfg80211_wowlan
*wowlan
)
1109 return __iwl_mvm_suspend(hw
, wowlan
, false);
1112 static void iwl_mvm_report_wakeup_reasons(struct iwl_mvm
*mvm
,
1113 struct ieee80211_vif
*vif
,
1114 struct iwl_wowlan_status
*status
)
1116 struct sk_buff
*pkt
= NULL
;
1117 struct cfg80211_wowlan_wakeup wakeup
= {
1120 struct cfg80211_wowlan_wakeup
*wakeup_report
= &wakeup
;
1121 u32 reasons
= le32_to_cpu(status
->wakeup_reasons
);
1123 if (reasons
== IWL_WOWLAN_WAKEUP_BY_NON_WIRELESS
) {
1124 wakeup_report
= NULL
;
1128 if (reasons
& IWL_WOWLAN_WAKEUP_BY_MAGIC_PACKET
)
1129 wakeup
.magic_pkt
= true;
1131 if (reasons
& IWL_WOWLAN_WAKEUP_BY_PATTERN
)
1132 wakeup
.pattern_idx
=
1133 le16_to_cpu(status
->pattern_number
);
1135 if (reasons
& (IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_MISSED_BEACON
|
1136 IWL_WOWLAN_WAKEUP_BY_DISCONNECTION_ON_DEAUTH
))
1137 wakeup
.disconnect
= true;
1139 if (reasons
& IWL_WOWLAN_WAKEUP_BY_GTK_REKEY_FAILURE
)
1140 wakeup
.gtk_rekey_failure
= true;
1142 if (reasons
& IWL_WOWLAN_WAKEUP_BY_RFKILL_DEASSERTED
)
1143 wakeup
.rfkill_release
= true;
1145 if (reasons
& IWL_WOWLAN_WAKEUP_BY_EAPOL_REQUEST
)
1146 wakeup
.eap_identity_req
= true;
1148 if (reasons
& IWL_WOWLAN_WAKEUP_BY_FOUR_WAY_HANDSHAKE
)
1149 wakeup
.four_way_handshake
= true;
1151 if (reasons
& IWL_WOWLAN_WAKEUP_BY_REM_WAKE_LINK_LOSS
)
1152 wakeup
.tcp_connlost
= true;
1154 if (reasons
& IWL_WOWLAN_WAKEUP_BY_REM_WAKE_SIGNATURE_TABLE
)
1155 wakeup
.tcp_nomoretokens
= true;
1157 if (reasons
& IWL_WOWLAN_WAKEUP_BY_REM_WAKE_WAKEUP_PACKET
)
1158 wakeup
.tcp_match
= true;
1160 if (status
->wake_packet_bufsize
) {
1161 int pktsize
= le32_to_cpu(status
->wake_packet_bufsize
);
1162 int pktlen
= le32_to_cpu(status
->wake_packet_length
);
1163 const u8
*pktdata
= status
->wake_packet
;
1164 struct ieee80211_hdr
*hdr
= (void *)pktdata
;
1165 int truncated
= pktlen
- pktsize
;
1167 /* this would be a firmware bug */
1168 if (WARN_ON_ONCE(truncated
< 0))
1171 if (ieee80211_is_data(hdr
->frame_control
)) {
1172 int hdrlen
= ieee80211_hdrlen(hdr
->frame_control
);
1173 int ivlen
= 0, icvlen
= 4; /* also FCS */
1175 pkt
= alloc_skb(pktsize
, GFP_KERNEL
);
1179 memcpy(skb_put(pkt
, hdrlen
), pktdata
, hdrlen
);
1183 if (ieee80211_has_protected(hdr
->frame_control
)) {
1185 * This is unlocked and using gtk_i(c)vlen,
1186 * but since everything is under RTNL still
1187 * that's not really a problem - changing
1188 * it would be difficult.
1190 if (is_multicast_ether_addr(hdr
->addr1
)) {
1191 ivlen
= mvm
->gtk_ivlen
;
1192 icvlen
+= mvm
->gtk_icvlen
;
1194 ivlen
= mvm
->ptk_ivlen
;
1195 icvlen
+= mvm
->ptk_icvlen
;
1199 /* if truncated, FCS/ICV is (partially) gone */
1200 if (truncated
>= icvlen
) {
1202 truncated
-= icvlen
;
1204 icvlen
-= truncated
;
1208 pktsize
-= ivlen
+ icvlen
;
1211 memcpy(skb_put(pkt
, pktsize
), pktdata
, pktsize
);
1213 if (ieee80211_data_to_8023(pkt
, vif
->addr
, vif
->type
))
1215 wakeup
.packet
= pkt
->data
;
1216 wakeup
.packet_present_len
= pkt
->len
;
1217 wakeup
.packet_len
= pkt
->len
- truncated
;
1218 wakeup
.packet_80211
= false;
1222 if (truncated
>= 4) {
1226 fcslen
-= truncated
;
1230 wakeup
.packet
= status
->wake_packet
;
1231 wakeup
.packet_present_len
= pktsize
;
1232 wakeup
.packet_len
= pktlen
- truncated
;
1233 wakeup
.packet_80211
= true;
1238 ieee80211_report_wowlan_wakeup(vif
, wakeup_report
, GFP_KERNEL
);
1242 /* releases the MVM mutex */
1243 static void iwl_mvm_query_wakeup_reasons(struct iwl_mvm
*mvm
,
1244 struct ieee80211_vif
*vif
)
1246 u32 base
= mvm
->error_event_table
;
1247 struct error_table_start
{
1248 /* cf. struct iwl_error_event_table */
1252 struct iwl_host_cmd cmd
= {
1253 .id
= WOWLAN_GET_STATUSES
,
1254 .flags
= CMD_SYNC
| CMD_WANT_SKB
,
1256 struct iwl_wowlan_status
*status
;
1259 iwl_trans_read_mem_bytes(mvm
->trans
, base
,
1260 &err_info
, sizeof(err_info
));
1262 if (err_info
.valid
) {
1263 IWL_INFO(mvm
, "error table is valid (%d)\n",
1265 if (err_info
.error_id
== RF_KILL_INDICATOR_FOR_WOWLAN
) {
1266 struct cfg80211_wowlan_wakeup wakeup
= {
1267 .rfkill_release
= true,
1269 ieee80211_report_wowlan_wakeup(vif
, &wakeup
,
1275 /* only for tracing for now */
1276 ret
= iwl_mvm_send_cmd_pdu(mvm
, OFFLOADS_QUERY_CMD
, CMD_SYNC
, 0, NULL
);
1278 IWL_ERR(mvm
, "failed to query offload statistics (%d)\n", ret
);
1280 ret
= iwl_mvm_send_cmd(mvm
, &cmd
);
1282 IWL_ERR(mvm
, "failed to query status (%d)\n", ret
);
1286 /* RF-kill already asserted again... */
1290 len
= le32_to_cpu(cmd
.resp_pkt
->len_n_flags
) & FH_RSCSR_FRAME_SIZE_MSK
;
1291 if (len
- sizeof(struct iwl_cmd_header
) < sizeof(*status
)) {
1292 IWL_ERR(mvm
, "Invalid WoWLAN status response!\n");
1296 status
= (void *)cmd
.resp_pkt
->data
;
1298 if (len
- sizeof(struct iwl_cmd_header
) !=
1300 ALIGN(le32_to_cpu(status
->wake_packet_bufsize
), 4)) {
1301 IWL_ERR(mvm
, "Invalid WoWLAN status response!\n");
1305 /* now we have all the data we need, unlock to avoid mac80211 issues */
1306 mutex_unlock(&mvm
->mutex
);
1308 iwl_mvm_report_wakeup_reasons(mvm
, vif
, status
);
1309 iwl_free_resp(&cmd
);
1313 iwl_free_resp(&cmd
);
1315 mutex_unlock(&mvm
->mutex
);
1318 static void iwl_mvm_read_d3_sram(struct iwl_mvm
*mvm
)
1320 #ifdef CONFIG_IWLWIFI_DEBUGFS
1321 const struct fw_img
*img
= &mvm
->fw
->img
[IWL_UCODE_WOWLAN
];
1322 u32 len
= img
->sec
[IWL_UCODE_SECTION_DATA
].len
;
1323 u32 offs
= img
->sec
[IWL_UCODE_SECTION_DATA
].offset
;
1325 if (!mvm
->store_d3_resume_sram
)
1328 if (!mvm
->d3_resume_sram
) {
1329 mvm
->d3_resume_sram
= kzalloc(len
, GFP_KERNEL
);
1330 if (!mvm
->d3_resume_sram
)
1334 iwl_trans_read_mem_bytes(mvm
->trans
, offs
, mvm
->d3_resume_sram
, len
);
1338 static int __iwl_mvm_resume(struct iwl_mvm
*mvm
, bool test
)
1340 struct iwl_d3_iter_data resume_iter_data
= {
1343 struct ieee80211_vif
*vif
= NULL
;
1345 enum iwl_d3_status d3_status
;
1347 mutex_lock(&mvm
->mutex
);
1349 /* get the BSS vif pointer again */
1350 ieee80211_iterate_active_interfaces_atomic(
1351 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1352 iwl_mvm_d3_iface_iterator
, &resume_iter_data
);
1354 if (WARN_ON(resume_iter_data
.error
|| !resume_iter_data
.vif
))
1357 vif
= resume_iter_data
.vif
;
1359 ret
= iwl_trans_d3_resume(mvm
->trans
, &d3_status
, test
);
1363 if (d3_status
!= IWL_D3_STATUS_ALIVE
) {
1364 IWL_INFO(mvm
, "Device was reset during suspend\n");
1368 /* query SRAM first in case we want event logging */
1369 iwl_mvm_read_d3_sram(mvm
);
1371 iwl_mvm_query_wakeup_reasons(mvm
, vif
);
1372 /* has unlocked the mutex, so skip that */
1376 mutex_unlock(&mvm
->mutex
);
1380 ieee80211_resume_disconnect(vif
);
1382 /* return 1 to reconfigure the device */
1383 set_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
1387 int iwl_mvm_resume(struct ieee80211_hw
*hw
)
1389 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1391 return __iwl_mvm_resume(mvm
, false);
1394 void iwl_mvm_set_wakeup(struct ieee80211_hw
*hw
, bool enabled
)
1396 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1398 device_set_wakeup_enable(mvm
->trans
->dev
, enabled
);
1401 #ifdef CONFIG_IWLWIFI_DEBUGFS
1402 static int iwl_mvm_d3_test_open(struct inode
*inode
, struct file
*file
)
1404 struct iwl_mvm
*mvm
= inode
->i_private
;
1407 if (mvm
->d3_test_active
)
1410 file
->private_data
= inode
->i_private
;
1412 ieee80211_stop_queues(mvm
->hw
);
1415 /* start pseudo D3 */
1417 err
= __iwl_mvm_suspend(mvm
->hw
, mvm
->hw
->wiphy
->wowlan_config
, true);
1422 ieee80211_wake_queues(mvm
->hw
);
1425 mvm
->d3_test_active
= true;
1429 static ssize_t
iwl_mvm_d3_test_read(struct file
*file
, char __user
*user_buf
,
1430 size_t count
, loff_t
*ppos
)
1432 struct iwl_mvm
*mvm
= file
->private_data
;
1436 pme_asserted
= iwl_trans_read_mem32(mvm
->trans
,
1437 mvm
->d3_test_pme_ptr
);
1440 if (msleep_interruptible(100))
1447 static void iwl_mvm_d3_test_disconn_work_iter(void *_data
, u8
*mac
,
1448 struct ieee80211_vif
*vif
)
1450 if (vif
->type
== NL80211_IFTYPE_STATION
)
1451 ieee80211_connection_loss(vif
);
1454 static int iwl_mvm_d3_test_release(struct inode
*inode
, struct file
*file
)
1456 struct iwl_mvm
*mvm
= inode
->i_private
;
1457 int remaining_time
= 10;
1459 mvm
->d3_test_active
= false;
1460 __iwl_mvm_resume(mvm
, true);
1461 iwl_abort_notification_waits(&mvm
->notif_wait
);
1462 ieee80211_restart_hw(mvm
->hw
);
1464 /* wait for restart and disconnect all interfaces */
1465 while (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
) &&
1466 remaining_time
> 0) {
1471 if (remaining_time
== 0)
1472 IWL_ERR(mvm
, "Timed out waiting for HW restart to finish!\n");
1474 ieee80211_iterate_active_interfaces_atomic(
1475 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1476 iwl_mvm_d3_test_disconn_work_iter
, NULL
);
1478 ieee80211_wake_queues(mvm
->hw
);
1483 const struct file_operations iwl_dbgfs_d3_test_ops
= {
1484 .llseek
= no_llseek
,
1485 .open
= iwl_mvm_d3_test_open
,
1486 .read
= iwl_mvm_d3_test_read
,
1487 .release
= iwl_mvm_d3_test_release
,