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 - 2014 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 - 2014 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 *****************************************************************************/
63 #include <linux/kernel.h>
64 #include <linux/slab.h>
65 #include <linux/skbuff.h>
66 #include <linux/netdevice.h>
67 #include <linux/etherdevice.h>
69 #include <linux/if_arp.h>
70 #include <net/mac80211.h>
71 #include <net/ieee80211_radiotap.h>
74 #include "iwl-op-mode.h"
78 #include "time-event.h"
79 #include "iwl-eeprom-parse.h"
80 #include "fw-api-scan.h"
81 #include "iwl-phy-db.h"
83 #include "iwl-fw-error-dump.h"
86 static const struct ieee80211_iface_limit iwl_mvm_limits
[] = {
89 .types
= BIT(NL80211_IFTYPE_STATION
),
93 .types
= BIT(NL80211_IFTYPE_AP
) |
94 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
95 BIT(NL80211_IFTYPE_P2P_GO
),
99 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
103 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations
[] = {
105 .num_different_channels
= 1,
107 .limits
= iwl_mvm_limits
,
108 .n_limits
= ARRAY_SIZE(iwl_mvm_limits
),
112 #ifdef CONFIG_PM_SLEEP
113 static const struct nl80211_wowlan_tcp_data_token_feature
114 iwl_mvm_wowlan_tcp_token_feature
= {
117 .bufsize
= IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS
,
120 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support
= {
121 .tok
= &iwl_mvm_wowlan_tcp_token_feature
,
122 .data_payload_max
= IWL_WOWLAN_TCP_MAX_PACKET_LEN
-
123 sizeof(struct ethhdr
) -
124 sizeof(struct iphdr
) -
125 sizeof(struct tcphdr
),
126 .data_interval_max
= 65535, /* __le16 in API */
127 .wake_payload_max
= IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN
-
128 sizeof(struct ethhdr
) -
129 sizeof(struct iphdr
) -
130 sizeof(struct tcphdr
),
135 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
137 * Use the reserved field to indicate magic values.
138 * these values will only be used internally by the driver,
139 * and won't make it to the fw (reserved will be 0).
140 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
141 * be the vif's ip address. in case there is not a single
142 * ip address (0, or more than 1), this attribute will
144 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
145 * the LSB bytes of the vif's mac address
148 BC_FILTER_MAGIC_NONE
= 0,
153 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters
[] = {
157 .frame_type
= BCAST_FILTER_FRAME_TYPE_ALL
,
160 /* frame type - arp, hw type - ethernet */
162 BCAST_FILTER_OFFSET_PAYLOAD_START
,
163 .offset
= sizeof(rfc1042_header
),
164 .val
= cpu_to_be32(0x08060001),
165 .mask
= cpu_to_be32(0xffffffff),
170 BCAST_FILTER_OFFSET_PAYLOAD_START
,
171 .offset
= sizeof(rfc1042_header
) + 2 +
172 sizeof(struct arphdr
) +
173 ETH_ALEN
+ sizeof(__be32
) +
175 .mask
= cpu_to_be32(0xffffffff),
176 /* mark it as special field */
177 .reserved1
= cpu_to_le16(BC_FILTER_MAGIC_IP
),
182 /* dhcp offer bcast */
184 .frame_type
= BCAST_FILTER_FRAME_TYPE_IPV4
,
187 /* udp dest port - 68 (bootp client)*/
188 .offset_type
= BCAST_FILTER_OFFSET_IP_END
,
189 .offset
= offsetof(struct udphdr
, dest
),
190 .val
= cpu_to_be32(0x00440000),
191 .mask
= cpu_to_be32(0xffff0000),
194 /* dhcp - lsb bytes of client hw address */
195 .offset_type
= BCAST_FILTER_OFFSET_IP_END
,
197 .mask
= cpu_to_be32(0xffffffff),
198 /* mark it as special field */
199 .reserved1
= cpu_to_le16(BC_FILTER_MAGIC_MAC
),
203 /* last filter must be empty */
208 void iwl_mvm_ref(struct iwl_mvm
*mvm
, enum iwl_mvm_ref_type ref_type
)
210 if (!iwl_mvm_is_d0i3_supported(mvm
))
213 IWL_DEBUG_RPM(mvm
, "Take mvm reference - type %d\n", ref_type
);
214 WARN_ON(test_and_set_bit(ref_type
, mvm
->ref_bitmap
));
215 iwl_trans_ref(mvm
->trans
);
218 void iwl_mvm_unref(struct iwl_mvm
*mvm
, enum iwl_mvm_ref_type ref_type
)
220 if (!iwl_mvm_is_d0i3_supported(mvm
))
223 IWL_DEBUG_RPM(mvm
, "Leave mvm reference - type %d\n", ref_type
);
224 WARN_ON(!test_and_clear_bit(ref_type
, mvm
->ref_bitmap
));
225 iwl_trans_unref(mvm
->trans
);
229 iwl_mvm_unref_all_except(struct iwl_mvm
*mvm
, enum iwl_mvm_ref_type ref
)
233 if (!iwl_mvm_is_d0i3_supported(mvm
))
236 for_each_set_bit(i
, mvm
->ref_bitmap
, IWL_MVM_REF_COUNT
) {
240 IWL_DEBUG_RPM(mvm
, "Cleanup: remove mvm ref type %d\n", i
);
241 clear_bit(i
, mvm
->ref_bitmap
);
242 iwl_trans_unref(mvm
->trans
);
246 static int iwl_mvm_ref_sync(struct iwl_mvm
*mvm
, enum iwl_mvm_ref_type ref_type
)
248 iwl_mvm_ref(mvm
, ref_type
);
250 if (!wait_event_timeout(mvm
->d0i3_exit_waitq
,
251 !test_bit(IWL_MVM_STATUS_IN_D0I3
, &mvm
->status
),
254 iwl_mvm_unref(mvm
, ref_type
);
261 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm
*mvm
)
265 memset(mvm
->phy_ctxts
, 0, sizeof(mvm
->phy_ctxts
));
266 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
267 mvm
->phy_ctxts
[i
].id
= i
;
268 mvm
->phy_ctxts
[i
].ref
= 0;
272 static int iwl_mvm_max_scan_ie_len(struct iwl_mvm
*mvm
)
274 /* we create the 802.11 header and SSID element */
275 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID
)
276 return mvm
->fw
->ucode_capa
.max_probe_length
- 24 - 2;
277 return mvm
->fw
->ucode_capa
.max_probe_length
- 24 - 34;
280 int iwl_mvm_mac_setup_register(struct iwl_mvm
*mvm
)
282 struct ieee80211_hw
*hw
= mvm
->hw
;
285 /* Tell mac80211 our characteristics */
286 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
287 IEEE80211_HW_SPECTRUM_MGMT
|
288 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
289 IEEE80211_HW_QUEUE_CONTROL
|
290 IEEE80211_HW_WANT_MONITOR_VIF
|
291 IEEE80211_HW_SUPPORTS_PS
|
292 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
293 IEEE80211_HW_AMPDU_AGGREGATION
|
294 IEEE80211_HW_TIMING_BEACON_ONLY
|
295 IEEE80211_HW_CONNECTION_MONITOR
|
296 IEEE80211_HW_CHANCTX_STA_CSA
|
297 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
|
298 IEEE80211_HW_SUPPORTS_STATIC_SMPS
;
300 hw
->queues
= mvm
->first_agg_queue
;
301 hw
->offchannel_tx_hw_queue
= IWL_MVM_OFFCHANNEL_QUEUE
;
302 hw
->radiotap_mcs_details
|= IEEE80211_RADIOTAP_MCS_HAVE_FEC
|
303 IEEE80211_RADIOTAP_MCS_HAVE_STBC
;
304 hw
->radiotap_vht_details
|= IEEE80211_RADIOTAP_VHT_KNOWN_STBC
;
305 hw
->rate_control_algorithm
= "iwl-mvm-rs";
308 * Enable 11w if advertised by firmware and software crypto
309 * is not enabled (as the firmware will interpret some mgmt
310 * packets, so enabling it with software crypto isn't safe)
312 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_MFP
&&
313 !iwlwifi_mod_params
.sw_crypto
)
314 hw
->flags
|= IEEE80211_HW_MFP_CAPABLE
;
316 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT
&&
317 IWL_UCODE_API(mvm
->fw
->ucode_ver
) >= 9 &&
318 !iwlwifi_mod_params
.uapsd_disable
) {
319 hw
->flags
|= IEEE80211_HW_SUPPORTS_UAPSD
;
320 hw
->uapsd_queues
= IWL_UAPSD_AC_INFO
;
321 hw
->uapsd_max_sp_len
= IWL_UAPSD_MAX_SP
;
324 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT
&&
325 !iwlwifi_mod_params
.uapsd_disable
) {
326 hw
->flags
|= IEEE80211_HW_SUPPORTS_UAPSD
;
327 hw
->uapsd_queues
= IWL_UAPSD_AC_INFO
;
328 hw
->uapsd_max_sp_len
= IWL_UAPSD_MAX_SP
;
331 if (mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_LMAC_SCAN
)
332 hw
->flags
|= IEEE80211_SINGLE_HW_SCAN_ON_ALL_BANDS
;
334 hw
->sta_data_size
= sizeof(struct iwl_mvm_sta
);
335 hw
->vif_data_size
= sizeof(struct iwl_mvm_vif
);
336 hw
->chanctx_data_size
= sizeof(u16
);
338 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
339 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
340 BIT(NL80211_IFTYPE_AP
) |
341 BIT(NL80211_IFTYPE_P2P_GO
) |
342 BIT(NL80211_IFTYPE_P2P_DEVICE
) |
343 BIT(NL80211_IFTYPE_ADHOC
);
345 hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
346 hw
->wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
|
347 REGULATORY_DISABLE_BEACON_HINTS
;
349 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_GO_UAPSD
)
350 hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
352 if (mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_CSA_FLOW
)
353 hw
->wiphy
->flags
|= WIPHY_FLAG_HAS_CHANNEL_SWITCH
;
355 hw
->wiphy
->iface_combinations
= iwl_mvm_iface_combinations
;
356 hw
->wiphy
->n_iface_combinations
=
357 ARRAY_SIZE(iwl_mvm_iface_combinations
);
359 hw
->wiphy
->max_remain_on_channel_duration
= 10000;
360 hw
->max_listen_interval
= IWL_CONN_MAX_LISTEN_INTERVAL
;
362 /* Extract MAC address */
363 memcpy(mvm
->addresses
[0].addr
, mvm
->nvm_data
->hw_addr
, ETH_ALEN
);
364 hw
->wiphy
->addresses
= mvm
->addresses
;
365 hw
->wiphy
->n_addresses
= 1;
367 /* Extract additional MAC addresses if available */
368 num_mac
= (mvm
->nvm_data
->n_hw_addrs
> 1) ?
369 min(IWL_MVM_MAX_ADDRESSES
, mvm
->nvm_data
->n_hw_addrs
) : 1;
371 for (i
= 1; i
< num_mac
; i
++) {
372 memcpy(mvm
->addresses
[i
].addr
, mvm
->addresses
[i
-1].addr
,
374 mvm
->addresses
[i
].addr
[5]++;
375 hw
->wiphy
->n_addresses
++;
378 iwl_mvm_reset_phy_ctxts(mvm
);
380 hw
->wiphy
->max_scan_ie_len
= iwl_mvm_max_scan_ie_len(mvm
);
382 hw
->wiphy
->max_scan_ssids
= PROBE_OPTION_MAX
;
384 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
385 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
386 &mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
];
387 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
388 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
389 &mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
];
391 hw
->wiphy
->hw_version
= mvm
->trans
->hw_id
;
393 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_CAM
)
394 hw
->wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
;
396 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
398 hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_SCHED_SCAN
;
399 hw
->wiphy
->max_sched_scan_ssids
= PROBE_OPTION_MAX
;
400 hw
->wiphy
->max_match_sets
= IWL_SCAN_MAX_PROFILES
;
401 /* we create the 802.11 header and zero length SSID IE. */
402 hw
->wiphy
->max_sched_scan_ie_len
= SCAN_OFFLOAD_PROBE_REQ_SIZE
- 24 - 2;
404 hw
->wiphy
->features
|= NL80211_FEATURE_P2P_GO_CTWIN
|
405 NL80211_FEATURE_LOW_PRIORITY_SCAN
|
406 NL80211_FEATURE_P2P_GO_OPPPS
;
408 mvm
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
410 /* currently FW API supports only one optional cipher scheme */
411 if (mvm
->fw
->cs
[0].cipher
) {
412 mvm
->hw
->n_cipher_schemes
= 1;
413 mvm
->hw
->cipher_schemes
= &mvm
->fw
->cs
[0];
416 #ifdef CONFIG_PM_SLEEP
417 if (iwl_mvm_is_d0i3_supported(mvm
) &&
418 device_can_wakeup(mvm
->trans
->dev
)) {
419 mvm
->wowlan
.flags
= WIPHY_WOWLAN_ANY
;
420 hw
->wiphy
->wowlan
= &mvm
->wowlan
;
421 } else if (mvm
->fw
->img
[IWL_UCODE_WOWLAN
].sec
[0].len
&&
422 mvm
->trans
->ops
->d3_suspend
&&
423 mvm
->trans
->ops
->d3_resume
&&
424 device_can_wakeup(mvm
->trans
->dev
)) {
425 mvm
->wowlan
.flags
= WIPHY_WOWLAN_MAGIC_PKT
|
426 WIPHY_WOWLAN_DISCONNECT
|
427 WIPHY_WOWLAN_EAP_IDENTITY_REQ
|
428 WIPHY_WOWLAN_RFKILL_RELEASE
;
429 if (!iwlwifi_mod_params
.sw_crypto
)
430 mvm
->wowlan
.flags
|= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
|
431 WIPHY_WOWLAN_GTK_REKEY_FAILURE
|
432 WIPHY_WOWLAN_4WAY_HANDSHAKE
;
434 mvm
->wowlan
.n_patterns
= IWL_WOWLAN_MAX_PATTERNS
;
435 mvm
->wowlan
.pattern_min_len
= IWL_WOWLAN_MIN_PATTERN_LEN
;
436 mvm
->wowlan
.pattern_max_len
= IWL_WOWLAN_MAX_PATTERN_LEN
;
437 mvm
->wowlan
.tcp
= &iwl_mvm_wowlan_tcp_support
;
438 hw
->wiphy
->wowlan
= &mvm
->wowlan
;
442 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
443 /* assign default bcast filtering configuration */
444 mvm
->bcast_filters
= iwl_mvm_default_bcast_filters
;
447 ret
= iwl_mvm_leds_init(mvm
);
451 ret
= ieee80211_register_hw(mvm
->hw
);
453 iwl_mvm_leds_exit(mvm
);
458 static bool iwl_mvm_defer_tx(struct iwl_mvm
*mvm
,
459 struct ieee80211_sta
*sta
,
462 struct iwl_mvm_sta
*mvmsta
;
466 * double check the IN_D0I3 flag both before and after
467 * taking the spinlock, in order to prevent taking
468 * the spinlock when not needed.
470 if (likely(!test_bit(IWL_MVM_STATUS_IN_D0I3
, &mvm
->status
)))
473 spin_lock(&mvm
->d0i3_tx_lock
);
475 * testing the flag again ensures the skb dequeue
476 * loop (on d0i3 exit) hasn't run yet.
478 if (!test_bit(IWL_MVM_STATUS_IN_D0I3
, &mvm
->status
))
481 mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
482 if (mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
||
483 mvmsta
->sta_id
!= mvm
->d0i3_ap_sta_id
)
486 __skb_queue_tail(&mvm
->d0i3_tx
, skb
);
487 ieee80211_stop_queues(mvm
->hw
);
490 iwl_mvm_ref(mvm
, IWL_MVM_REF_TX
);
491 iwl_mvm_unref(mvm
, IWL_MVM_REF_TX
);
495 spin_unlock(&mvm
->d0i3_tx_lock
);
499 static void iwl_mvm_mac_tx(struct ieee80211_hw
*hw
,
500 struct ieee80211_tx_control
*control
,
503 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
504 struct ieee80211_sta
*sta
= control
->sta
;
505 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
506 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
508 if (iwl_mvm_is_radio_killed(mvm
)) {
509 IWL_DEBUG_DROP(mvm
, "Dropping - RF/CT KILL\n");
513 if (IEEE80211_SKB_CB(skb
)->hw_queue
== IWL_MVM_OFFCHANNEL_QUEUE
&&
514 !test_bit(IWL_MVM_STATUS_ROC_RUNNING
, &mvm
->status
))
517 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
518 if (unlikely(info
->flags
& IEEE80211_TX_CTL_NO_PS_BUFFER
&&
519 ieee80211_is_mgmt(hdr
->frame_control
) &&
520 !ieee80211_is_deauth(hdr
->frame_control
) &&
521 !ieee80211_is_disassoc(hdr
->frame_control
) &&
522 !ieee80211_is_action(hdr
->frame_control
)))
526 if (iwl_mvm_defer_tx(mvm
, sta
, skb
))
528 if (iwl_mvm_tx_skb(mvm
, skb
, sta
))
533 if (iwl_mvm_tx_skb_non_sta(mvm
, skb
))
537 ieee80211_free_txskb(hw
, skb
);
540 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg
*cfg
)
542 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_RXAGG
)
547 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg
*cfg
)
549 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_TXAGG
)
551 if (iwlwifi_mod_params
.disable_11n
& IWL_ENABLE_HT_TXAGG
)
554 /* enabled by default */
558 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
559 struct ieee80211_vif
*vif
,
560 enum ieee80211_ampdu_mlme_action action
,
561 struct ieee80211_sta
*sta
, u16 tid
,
562 u16
*ssn
, u8 buf_size
)
564 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
566 bool tx_agg_ref
= false;
568 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
569 sta
->addr
, tid
, action
);
571 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
574 /* return from D0i3 before starting a new Tx aggregation */
576 case IEEE80211_AMPDU_TX_START
:
577 case IEEE80211_AMPDU_TX_STOP_CONT
:
578 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
579 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
580 case IEEE80211_AMPDU_TX_OPERATIONAL
:
582 * for tx start, wait synchronously until D0i3 exit to
583 * get the correct sequence number for the tid.
584 * additionally, some other ampdu actions use direct
585 * target access, which is not handled automatically
586 * by the trans layer (unlike commands), so wait for
587 * d0i3 exit in these cases as well.
589 ret
= iwl_mvm_ref_sync(mvm
, IWL_MVM_REF_TX_AGG
);
599 mutex_lock(&mvm
->mutex
);
602 case IEEE80211_AMPDU_RX_START
:
603 if (!iwl_enable_rx_ampdu(mvm
->cfg
)) {
607 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true);
609 case IEEE80211_AMPDU_RX_STOP
:
610 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false);
612 case IEEE80211_AMPDU_TX_START
:
613 if (!iwl_enable_tx_ampdu(mvm
->cfg
)) {
617 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
619 case IEEE80211_AMPDU_TX_STOP_CONT
:
620 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
622 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
623 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
624 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
626 case IEEE80211_AMPDU_TX_OPERATIONAL
:
627 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
, buf_size
);
634 mutex_unlock(&mvm
->mutex
);
637 * If the tid is marked as started, we won't use it for offloaded
638 * traffic on the next D0i3 entry. It's safe to unref.
641 iwl_mvm_unref(mvm
, IWL_MVM_REF_TX_AGG
);
646 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
647 struct ieee80211_vif
*vif
)
649 struct iwl_mvm
*mvm
= data
;
650 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
652 mvmvif
->uploaded
= false;
653 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
655 /* does this make sense at all? */
658 spin_lock_bh(&mvm
->time_event_lock
);
659 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
660 spin_unlock_bh(&mvm
->time_event_lock
);
662 mvmvif
->phy_ctxt
= NULL
;
665 #ifdef CONFIG_IWLWIFI_DEBUGFS
666 static void iwl_mvm_fw_error_dump(struct iwl_mvm
*mvm
)
668 struct iwl_fw_error_dump_file
*dump_file
;
669 struct iwl_fw_error_dump_data
*dump_data
;
670 struct iwl_fw_error_dump_info
*dump_info
;
671 const struct fw_img
*img
;
672 u32 sram_len
, sram_ofs
;
673 u32 file_len
, rxf_len
;
678 lockdep_assert_held(&mvm
->mutex
);
680 if (mvm
->fw_error_dump
)
683 img
= &mvm
->fw
->img
[mvm
->cur_ucode
];
684 sram_ofs
= img
->sec
[IWL_UCODE_SECTION_DATA
].offset
;
685 sram_len
= img
->sec
[IWL_UCODE_SECTION_DATA
].len
;
687 /* reading buffer size */
688 reg_val
= iwl_trans_read_prph(mvm
->trans
, RXF_SIZE_ADDR
);
689 rxf_len
= (reg_val
& RXF_SIZE_BYTE_CNT_MSK
) >> RXF_SIZE_BYTE_CND_POS
;
691 /* the register holds the value divided by 128 */
692 rxf_len
= rxf_len
<< 7;
694 file_len
= sizeof(*dump_file
) +
695 sizeof(*dump_data
) * 3 +
700 trans_len
= iwl_trans_dump_data(mvm
->trans
, NULL
, 0);
702 file_len
+= trans_len
;
704 dump_file
= vzalloc(file_len
);
708 mvm
->fw_error_dump
= dump_file
;
710 dump_file
->barker
= cpu_to_le32(IWL_FW_ERROR_DUMP_BARKER
);
711 dump_file
->file_len
= cpu_to_le32(file_len
);
712 dump_data
= (void *)dump_file
->data
;
714 dump_data
->type
= cpu_to_le32(IWL_FW_ERROR_DUMP_DEV_FW_INFO
);
715 dump_data
->len
= cpu_to_le32(sizeof(*dump_info
));
716 dump_info
= (void *) dump_data
->data
;
717 dump_info
->device_family
=
718 mvm
->cfg
->device_family
== IWL_DEVICE_FAMILY_7000
?
719 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_7
) :
720 cpu_to_le32(IWL_FW_ERROR_DUMP_FAMILY_8
);
721 memcpy(dump_info
->fw_human_readable
, mvm
->fw
->human_readable
,
722 sizeof(dump_info
->fw_human_readable
));
723 strncpy(dump_info
->dev_human_readable
, mvm
->cfg
->name
,
724 sizeof(dump_info
->dev_human_readable
));
725 strncpy(dump_info
->bus_human_readable
, mvm
->dev
->bus
->name
,
726 sizeof(dump_info
->bus_human_readable
));
728 dump_data
= iwl_fw_error_next_data(dump_data
);
729 dump_data
->type
= cpu_to_le32(IWL_FW_ERROR_DUMP_RXF
);
730 dump_data
->len
= cpu_to_le32(rxf_len
);
732 if (iwl_trans_grab_nic_access(mvm
->trans
, false, &flags
)) {
733 u32
*rxf
= (void *)dump_data
->data
;
736 for (i
= 0; i
< (rxf_len
/ sizeof(u32
)); i
++) {
737 iwl_trans_write_prph(mvm
->trans
,
738 RXF_LD_FENCE_OFFSET_ADDR
,
740 rxf
[i
] = iwl_trans_read_prph(mvm
->trans
,
741 RXF_FIFO_RD_FENCE_ADDR
);
743 iwl_trans_release_nic_access(mvm
->trans
, &flags
);
746 dump_data
= iwl_fw_error_next_data(dump_data
);
747 dump_data
->type
= cpu_to_le32(IWL_FW_ERROR_DUMP_SRAM
);
748 dump_data
->len
= cpu_to_le32(sram_len
);
749 iwl_trans_read_mem_bytes(mvm
->trans
, sram_ofs
, dump_data
->data
,
753 void *buf
= iwl_fw_error_next_data(dump_data
);
754 u32 real_trans_len
= iwl_trans_dump_data(mvm
->trans
, buf
,
756 dump_data
= (void *)((u8
*)buf
+ real_trans_len
);
757 dump_file
->file_len
=
758 cpu_to_le32(file_len
- trans_len
+ real_trans_len
);
763 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
765 #ifdef CONFIG_IWLWIFI_DEBUGFS
766 static char *env
[] = { "DRIVER=iwlwifi", "EVENT=error_dump", NULL
};
768 iwl_mvm_fw_error_dump(mvm
);
770 /* notify the userspace about the error we had */
771 kobject_uevent_env(&mvm
->hw
->wiphy
->dev
.kobj
, KOBJ_CHANGE
, env
);
774 iwl_trans_stop_device(mvm
->trans
);
776 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
778 /* just in case one was running */
779 ieee80211_remain_on_channel_expired(mvm
->hw
);
781 ieee80211_iterate_active_interfaces_atomic(
782 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
783 iwl_mvm_cleanup_iterator
, mvm
);
785 mvm
->p2p_device_vif
= NULL
;
786 mvm
->d0i3_ap_sta_id
= IWL_MVM_STATION_COUNT
;
788 iwl_mvm_reset_phy_ctxts(mvm
);
789 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
790 memset(mvm
->sta_drained
, 0, sizeof(mvm
->sta_drained
));
792 ieee80211_wake_queues(mvm
->hw
);
794 /* cleanup all stale references (scan, roc), but keep the
795 * ucode_down ref until reconfig is complete */
796 iwl_mvm_unref_all_except(mvm
, IWL_MVM_REF_UCODE_DOWN
);
799 mvm
->rx_ba_sessions
= 0;
802 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
804 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
807 mutex_lock(&mvm
->mutex
);
809 /* Clean up some internal and mac80211 state on restart */
810 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
811 iwl_mvm_restart_cleanup(mvm
);
813 ret
= iwl_mvm_up(mvm
);
815 if (ret
&& test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
)) {
816 /* Something went wrong - we need to finish some cleanup
817 * that normally iwl_mvm_mac_restart_complete() below
820 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
821 iwl_mvm_d0i3_enable_tx(mvm
, NULL
);
824 mutex_unlock(&mvm
->mutex
);
829 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw
*hw
)
831 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
834 mutex_lock(&mvm
->mutex
);
836 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
837 iwl_mvm_d0i3_enable_tx(mvm
, NULL
);
838 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
840 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
843 /* allow transport/FW low power modes */
844 iwl_mvm_unref(mvm
, IWL_MVM_REF_UCODE_DOWN
);
846 mutex_unlock(&mvm
->mutex
);
849 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
851 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
853 flush_work(&mvm
->d0i3_exit_work
);
854 flush_work(&mvm
->async_handlers_wk
);
856 mutex_lock(&mvm
->mutex
);
858 /* disallow low power states when the FW is down */
859 iwl_mvm_ref(mvm
, IWL_MVM_REF_UCODE_DOWN
);
861 /* async_handlers_wk is now blocked */
864 * The work item could be running or queued if the
865 * ROC time event stops just as we get here.
867 cancel_work_sync(&mvm
->roc_done_wk
);
869 iwl_trans_stop_device(mvm
->trans
);
871 iwl_mvm_async_handlers_purge(mvm
);
872 /* async_handlers_list is empty and will stay empty: HW is stopped */
874 /* the fw is stopped, the aux sta is dead: clean up driver state */
875 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
877 mutex_unlock(&mvm
->mutex
);
880 * The worker might have been waiting for the mutex, let it run and
881 * discover that its list is now empty.
883 cancel_work_sync(&mvm
->async_handlers_wk
);
886 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
890 lockdep_assert_held(&mvm
->mutex
);
892 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
893 if (!mvm
->phy_ctxts
[i
].ref
)
894 return &mvm
->phy_ctxts
[i
];
896 IWL_ERR(mvm
, "No available PHY context\n");
900 static int iwl_mvm_set_tx_power(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
903 /* FW is in charge of regulatory enforcement */
904 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd
= {
905 .mac_context_id
= iwl_mvm_vif_from_mac80211(vif
)->id
,
906 .pwr_restriction
= cpu_to_le16(tx_power
),
909 return iwl_mvm_send_cmd_pdu(mvm
, REDUCE_TX_POWER_CMD
, 0,
910 sizeof(reduce_txpwr_cmd
),
914 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
915 struct ieee80211_vif
*vif
)
917 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
918 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
922 * make sure D0i3 exit is completed, otherwise a target access
923 * during tx queue configuration could be done when still in
926 ret
= iwl_mvm_ref_sync(mvm
, IWL_MVM_REF_ADD_IF
);
931 * Not much to do here. The stack will not allow interface
932 * types or combinations that we didn't advertise, so we
933 * don't really have to check the types.
936 mutex_lock(&mvm
->mutex
);
938 /* Allocate resources for the MAC context, and add it to the fw */
939 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
943 /* Counting number of interfaces is needed for legacy PM */
944 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
948 * The AP binding flow can be done only after the beacon
949 * template is configured (which happens only in the mac80211
950 * start_ap() flow), and adding the broadcast station can happen
951 * only after the binding.
952 * In addition, since modifying the MAC before adding a bcast
953 * station is not allowed by the FW, delay the adding of MAC context to
954 * the point where we can also add the bcast station.
955 * In short: there's not much we can do at this point, other than
956 * allocating resources :)
958 if (vif
->type
== NL80211_IFTYPE_AP
||
959 vif
->type
== NL80211_IFTYPE_ADHOC
) {
960 u32 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
961 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
,
963 ieee80211_vif_type_p2p(vif
));
965 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
969 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
973 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
977 ret
= iwl_mvm_power_update_mac(mvm
);
981 /* beacon filtering */
982 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, 0);
986 if (!mvm
->bf_allowed_vif
&&
987 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
) {
988 mvm
->bf_allowed_vif
= mvmvif
;
989 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
990 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
994 * P2P_DEVICE interface does not have a channel context assigned to it,
995 * so a dedicated PHY context is allocated to it and the corresponding
996 * MAC context is bound to it at this stage.
998 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1000 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1001 if (!mvmvif
->phy_ctxt
) {
1006 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1007 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1011 ret
= iwl_mvm_add_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
1015 /* Save a pointer to p2p device vif, so it can later be used to
1016 * update the p2p device MAC when a GO is started/stopped */
1017 mvm
->p2p_device_vif
= vif
;
1020 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
1024 iwl_mvm_binding_remove_vif(mvm
, vif
);
1026 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1028 if (mvm
->bf_allowed_vif
== mvmvif
) {
1029 mvm
->bf_allowed_vif
= NULL
;
1030 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
1031 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
1034 mvmvif
->phy_ctxt
= NULL
;
1035 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1037 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
1040 iwl_mvm_mac_ctxt_release(mvm
, vif
);
1042 mutex_unlock(&mvm
->mutex
);
1044 iwl_mvm_unref(mvm
, IWL_MVM_REF_ADD_IF
);
1049 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
1050 struct ieee80211_vif
*vif
)
1052 u32 tfd_msk
= 0, ac
;
1054 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
1055 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
1056 tfd_msk
|= BIT(vif
->hw_queue
[ac
]);
1058 if (vif
->cab_queue
!= IEEE80211_INVAL_HW_QUEUE
)
1059 tfd_msk
|= BIT(vif
->cab_queue
);
1062 mutex_lock(&mvm
->mutex
);
1063 iwl_mvm_flush_tx_path(mvm
, tfd_msk
, true);
1064 mutex_unlock(&mvm
->mutex
);
1067 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1069 * Flush the ROC worker which will flush the OFFCHANNEL queue.
1070 * We assume here that all the packets sent to the OFFCHANNEL
1071 * queue are sent in ROC session.
1073 flush_work(&mvm
->roc_done_wk
);
1076 * By now, all the AC queues are empty. The AGG queues are
1077 * empty too. We already got all the Tx responses for all the
1078 * packets in the queues. The drain work can have been
1079 * triggered. Flush it.
1081 flush_work(&mvm
->sta_drained_wk
);
1085 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
1086 struct ieee80211_vif
*vif
)
1088 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1089 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1091 iwl_mvm_prepare_mac_removal(mvm
, vif
);
1093 mutex_lock(&mvm
->mutex
);
1095 if (mvm
->bf_allowed_vif
== mvmvif
) {
1096 mvm
->bf_allowed_vif
= NULL
;
1097 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
1098 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
1101 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
1104 * For AP/GO interface, the tear down of the resources allocated to the
1105 * interface is be handled as part of the stop_ap flow.
1107 if (vif
->type
== NL80211_IFTYPE_AP
||
1108 vif
->type
== NL80211_IFTYPE_ADHOC
) {
1109 #ifdef CONFIG_NL80211_TESTMODE
1110 if (vif
== mvm
->noa_vif
) {
1111 mvm
->noa_vif
= NULL
;
1112 mvm
->noa_duration
= 0;
1115 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
1119 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1120 mvm
->p2p_device_vif
= NULL
;
1121 iwl_mvm_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
1122 iwl_mvm_binding_remove_vif(mvm
, vif
);
1123 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1124 mvmvif
->phy_ctxt
= NULL
;
1127 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
1130 iwl_mvm_power_update_mac(mvm
);
1131 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1134 iwl_mvm_mac_ctxt_release(mvm
, vif
);
1135 mutex_unlock(&mvm
->mutex
);
1138 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
1143 struct iwl_mvm_mc_iter_data
{
1144 struct iwl_mvm
*mvm
;
1148 static void iwl_mvm_mc_iface_iterator(void *_data
, u8
*mac
,
1149 struct ieee80211_vif
*vif
)
1151 struct iwl_mvm_mc_iter_data
*data
= _data
;
1152 struct iwl_mvm
*mvm
= data
->mvm
;
1153 struct iwl_mcast_filter_cmd
*cmd
= mvm
->mcast_filter_cmd
;
1156 /* if we don't have free ports, mcast frames will be dropped */
1157 if (WARN_ON_ONCE(data
->port_id
>= MAX_PORT_ID_NUM
))
1160 if (vif
->type
!= NL80211_IFTYPE_STATION
||
1161 !vif
->bss_conf
.assoc
)
1164 cmd
->port_id
= data
->port_id
++;
1165 memcpy(cmd
->bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
1166 len
= roundup(sizeof(*cmd
) + cmd
->count
* ETH_ALEN
, 4);
1168 ret
= iwl_mvm_send_cmd_pdu(mvm
, MCAST_FILTER_CMD
, CMD_ASYNC
, len
, cmd
);
1170 IWL_ERR(mvm
, "mcast filter cmd error. ret=%d\n", ret
);
1173 static void iwl_mvm_recalc_multicast(struct iwl_mvm
*mvm
)
1175 struct iwl_mvm_mc_iter_data iter_data
= {
1179 lockdep_assert_held(&mvm
->mutex
);
1181 if (WARN_ON_ONCE(!mvm
->mcast_filter_cmd
))
1184 ieee80211_iterate_active_interfaces_atomic(
1185 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1186 iwl_mvm_mc_iface_iterator
, &iter_data
);
1189 static u64
iwl_mvm_prepare_multicast(struct ieee80211_hw
*hw
,
1190 struct netdev_hw_addr_list
*mc_list
)
1192 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1193 struct iwl_mcast_filter_cmd
*cmd
;
1194 struct netdev_hw_addr
*addr
;
1195 int addr_count
= netdev_hw_addr_list_count(mc_list
);
1196 bool pass_all
= false;
1199 if (addr_count
> MAX_MCAST_FILTERING_ADDRESSES
) {
1204 len
= roundup(sizeof(*cmd
) + addr_count
* ETH_ALEN
, 4);
1205 cmd
= kzalloc(len
, GFP_ATOMIC
);
1211 return (u64
)(unsigned long)cmd
;
1214 netdev_hw_addr_list_for_each(addr
, mc_list
) {
1215 IWL_DEBUG_MAC80211(mvm
, "mcast addr (%d): %pM\n",
1216 cmd
->count
, addr
->addr
);
1217 memcpy(&cmd
->addr_list
[cmd
->count
* ETH_ALEN
],
1218 addr
->addr
, ETH_ALEN
);
1222 return (u64
)(unsigned long)cmd
;
1225 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
1226 unsigned int changed_flags
,
1227 unsigned int *total_flags
,
1230 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1231 struct iwl_mcast_filter_cmd
*cmd
= (void *)(unsigned long)multicast
;
1233 mutex_lock(&mvm
->mutex
);
1235 /* replace previous configuration */
1236 kfree(mvm
->mcast_filter_cmd
);
1237 mvm
->mcast_filter_cmd
= cmd
;
1242 iwl_mvm_recalc_multicast(mvm
);
1244 mutex_unlock(&mvm
->mutex
);
1248 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1249 struct iwl_bcast_iter_data
{
1250 struct iwl_mvm
*mvm
;
1251 struct iwl_bcast_filter_cmd
*cmd
;
1256 iwl_mvm_set_bcast_filter(struct ieee80211_vif
*vif
,
1257 const struct iwl_fw_bcast_filter
*in_filter
,
1258 struct iwl_fw_bcast_filter
*out_filter
)
1260 struct iwl_fw_bcast_filter_attr
*attr
;
1263 memcpy(out_filter
, in_filter
, sizeof(*out_filter
));
1265 for (i
= 0; i
< ARRAY_SIZE(out_filter
->attrs
); i
++) {
1266 attr
= &out_filter
->attrs
[i
];
1271 switch (attr
->reserved1
) {
1272 case cpu_to_le16(BC_FILTER_MAGIC_IP
):
1273 if (vif
->bss_conf
.arp_addr_cnt
!= 1) {
1278 attr
->val
= vif
->bss_conf
.arp_addr_list
[0];
1280 case cpu_to_le16(BC_FILTER_MAGIC_MAC
):
1281 attr
->val
= *(__be32
*)&vif
->addr
[2];
1286 attr
->reserved1
= 0;
1287 out_filter
->num_attrs
++;
1291 static void iwl_mvm_bcast_filter_iterator(void *_data
, u8
*mac
,
1292 struct ieee80211_vif
*vif
)
1294 struct iwl_bcast_iter_data
*data
= _data
;
1295 struct iwl_mvm
*mvm
= data
->mvm
;
1296 struct iwl_bcast_filter_cmd
*cmd
= data
->cmd
;
1297 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1298 struct iwl_fw_bcast_mac
*bcast_mac
;
1301 if (WARN_ON(mvmvif
->id
>= ARRAY_SIZE(cmd
->macs
)))
1304 bcast_mac
= &cmd
->macs
[mvmvif
->id
];
1307 * enable filtering only for associated stations, but not for P2P
1310 if (vif
->type
!= NL80211_IFTYPE_STATION
|| vif
->p2p
||
1311 !vif
->bss_conf
.assoc
)
1314 bcast_mac
->default_discard
= 1;
1316 /* copy all configured filters */
1317 for (i
= 0; mvm
->bcast_filters
[i
].attrs
[0].mask
; i
++) {
1319 * Make sure we don't exceed our filters limit.
1320 * if there is still a valid filter to be configured,
1321 * be on the safe side and just allow bcast for this mac.
1323 if (WARN_ON_ONCE(data
->current_filter
>=
1324 ARRAY_SIZE(cmd
->filters
))) {
1325 bcast_mac
->default_discard
= 0;
1326 bcast_mac
->attached_filters
= 0;
1330 iwl_mvm_set_bcast_filter(vif
,
1331 &mvm
->bcast_filters
[i
],
1332 &cmd
->filters
[data
->current_filter
]);
1334 /* skip current filter if it contains no attributes */
1335 if (!cmd
->filters
[data
->current_filter
].num_attrs
)
1338 /* attach the filter to current mac */
1339 bcast_mac
->attached_filters
|=
1340 cpu_to_le16(BIT(data
->current_filter
));
1342 data
->current_filter
++;
1346 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm
*mvm
,
1347 struct iwl_bcast_filter_cmd
*cmd
)
1349 struct iwl_bcast_iter_data iter_data
= {
1354 memset(cmd
, 0, sizeof(*cmd
));
1355 cmd
->max_bcast_filters
= ARRAY_SIZE(cmd
->filters
);
1356 cmd
->max_macs
= ARRAY_SIZE(cmd
->macs
);
1358 #ifdef CONFIG_IWLWIFI_DEBUGFS
1359 /* use debugfs filters/macs if override is configured */
1360 if (mvm
->dbgfs_bcast_filtering
.override
) {
1361 memcpy(cmd
->filters
, &mvm
->dbgfs_bcast_filtering
.cmd
.filters
,
1362 sizeof(cmd
->filters
));
1363 memcpy(cmd
->macs
, &mvm
->dbgfs_bcast_filtering
.cmd
.macs
,
1369 /* if no filters are configured, do nothing */
1370 if (!mvm
->bcast_filters
)
1373 /* configure and attach these filters for each associated sta vif */
1374 ieee80211_iterate_active_interfaces(
1375 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1376 iwl_mvm_bcast_filter_iterator
, &iter_data
);
1380 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm
*mvm
,
1381 struct ieee80211_vif
*vif
)
1383 struct iwl_bcast_filter_cmd cmd
;
1385 if (!(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BCAST_FILTERING
))
1388 if (!iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
))
1391 return iwl_mvm_send_cmd_pdu(mvm
, BCAST_FILTER_CMD
, 0,
1395 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm
*mvm
,
1396 struct ieee80211_vif
*vif
)
1402 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
1403 struct ieee80211_vif
*vif
,
1404 struct ieee80211_bss_conf
*bss_conf
,
1407 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1411 * Re-calculate the tsf id, as the master-slave relations depend on the
1412 * beacon interval, which was not known when the station interface was
1415 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
)
1416 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm
, vif
);
1418 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
, false);
1420 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
1422 if (changes
& BSS_CHANGED_ASSOC
) {
1423 if (bss_conf
->assoc
) {
1424 /* add quota for this interface */
1425 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
1427 IWL_ERR(mvm
, "failed to update quotas\n");
1431 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
1434 * If we're restarting then the firmware will
1435 * obviously have lost synchronisation with
1436 * the AP. It will attempt to synchronise by
1437 * itself, but we can make it more reliable by
1438 * scheduling a session protection time event.
1440 * The firmware needs to receive a beacon to
1441 * catch up with synchronisation, use 110% of
1442 * the beacon interval.
1444 * Set a large maximum delay to allow for more
1445 * than a single interface.
1447 u32 dur
= (11 * vif
->bss_conf
.beacon_int
) / 10;
1448 iwl_mvm_protect_session(mvm
, vif
, dur
, dur
,
1452 iwl_mvm_sf_update(mvm
, vif
, false);
1453 iwl_mvm_power_vif_assoc(mvm
, vif
);
1455 iwl_mvm_ref(mvm
, IWL_MVM_REF_P2P_CLIENT
);
1456 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
1458 * If update fails - SF might be running in associated
1459 * mode while disassociated - which is forbidden.
1461 WARN_ONCE(iwl_mvm_sf_update(mvm
, vif
, false),
1462 "Failed to update SF upon disassociation\n");
1464 /* remove AP station now that the MAC is unassoc */
1465 ret
= iwl_mvm_rm_sta_id(mvm
, vif
, mvmvif
->ap_sta_id
);
1467 IWL_ERR(mvm
, "failed to remove AP station\n");
1469 if (mvm
->d0i3_ap_sta_id
== mvmvif
->ap_sta_id
)
1470 mvm
->d0i3_ap_sta_id
= IWL_MVM_STATION_COUNT
;
1471 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
1472 /* remove quota for this interface */
1473 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
1475 IWL_ERR(mvm
, "failed to update quotas\n");
1478 iwl_mvm_unref(mvm
, IWL_MVM_REF_P2P_CLIENT
);
1481 iwl_mvm_recalc_multicast(mvm
);
1482 iwl_mvm_configure_bcast_filter(mvm
, vif
);
1484 /* reset rssi values */
1485 mvmvif
->bf_data
.ave_beacon_signal
= 0;
1487 iwl_mvm_bt_coex_vif_change(mvm
);
1488 iwl_mvm_update_smps(mvm
, vif
, IWL_MVM_SMPS_REQ_TT
,
1489 IEEE80211_SMPS_AUTOMATIC
);
1490 } else if (changes
& BSS_CHANGED_BEACON_INFO
) {
1492 * We received a beacon _after_ association so
1493 * remove the session protection.
1495 iwl_mvm_remove_time_event(mvm
, mvmvif
,
1496 &mvmvif
->time_event_data
);
1497 iwl_mvm_sf_update(mvm
, vif
, false);
1498 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
, 0));
1499 } else if (changes
& (BSS_CHANGED_PS
| BSS_CHANGED_P2P_PS
|
1501 ret
= iwl_mvm_power_update_mac(mvm
);
1503 IWL_ERR(mvm
, "failed to update power mode\n");
1505 if (changes
& BSS_CHANGED_TXPOWER
) {
1506 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
1508 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
1511 if (changes
& BSS_CHANGED_CQM
) {
1512 IWL_DEBUG_MAC80211(mvm
, "cqm info_changed\n");
1513 /* reset cqm events tracking */
1514 mvmvif
->bf_data
.last_cqm_event
= 0;
1515 if (mvmvif
->bf_data
.bf_enabled
) {
1516 ret
= iwl_mvm_enable_beacon_filter(mvm
, vif
, 0);
1519 "failed to update CQM thresholds\n");
1523 if (changes
& BSS_CHANGED_ARP_FILTER
) {
1524 IWL_DEBUG_MAC80211(mvm
, "arp filter changed\n");
1525 iwl_mvm_configure_bcast_filter(mvm
, vif
);
1529 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw
*hw
,
1530 struct ieee80211_vif
*vif
)
1532 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1533 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1536 mutex_lock(&mvm
->mutex
);
1538 /* Send the beacon template */
1539 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
1544 * Re-calculate the tsf id, as the master-slave relations depend on the
1545 * beacon interval, which was not known when the AP interface was added.
1547 if (vif
->type
== NL80211_IFTYPE_AP
)
1548 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm
, vif
);
1550 /* Add the mac context */
1551 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
1555 /* Perform the binding */
1556 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1560 /* Send the bcast station. At this stage the TBTT and DTIM time events
1561 * are added and applied to the scheduler */
1562 ret
= iwl_mvm_send_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
1566 /* must be set before quota calculations */
1567 mvmvif
->ap_ibss_active
= true;
1569 /* power updated needs to be done before quotas */
1570 iwl_mvm_power_update_mac(mvm
);
1572 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
1574 goto out_quota_failed
;
1576 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1577 if (vif
->p2p
&& mvm
->p2p_device_vif
)
1578 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
, false);
1580 iwl_mvm_ref(mvm
, IWL_MVM_REF_AP_IBSS
);
1582 iwl_mvm_bt_coex_vif_change(mvm
);
1584 mutex_unlock(&mvm
->mutex
);
1588 iwl_mvm_power_update_mac(mvm
);
1589 mvmvif
->ap_ibss_active
= false;
1590 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
1592 iwl_mvm_binding_remove_vif(mvm
, vif
);
1594 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1596 mutex_unlock(&mvm
->mutex
);
1600 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw
*hw
,
1601 struct ieee80211_vif
*vif
)
1603 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1604 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1606 iwl_mvm_prepare_mac_removal(mvm
, vif
);
1608 mutex_lock(&mvm
->mutex
);
1610 /* Handle AP stop while in CSA */
1611 if (rcu_access_pointer(mvm
->csa_vif
) == vif
) {
1612 iwl_mvm_remove_time_event(mvm
, mvmvif
,
1613 &mvmvif
->time_event_data
);
1614 RCU_INIT_POINTER(mvm
->csa_vif
, NULL
);
1617 mvmvif
->ap_ibss_active
= false;
1618 mvm
->ap_last_beacon_gp2
= 0;
1620 iwl_mvm_bt_coex_vif_change(mvm
);
1622 iwl_mvm_unref(mvm
, IWL_MVM_REF_AP_IBSS
);
1624 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1625 if (vif
->p2p
&& mvm
->p2p_device_vif
)
1626 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
, false);
1628 iwl_mvm_update_quotas(mvm
, NULL
);
1629 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
1630 iwl_mvm_binding_remove_vif(mvm
, vif
);
1632 iwl_mvm_power_update_mac(mvm
);
1634 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1636 mutex_unlock(&mvm
->mutex
);
1640 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm
*mvm
,
1641 struct ieee80211_vif
*vif
,
1642 struct ieee80211_bss_conf
*bss_conf
,
1645 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1647 /* Changes will be applied when the AP/IBSS is started */
1648 if (!mvmvif
->ap_ibss_active
)
1651 if (changes
& (BSS_CHANGED_ERP_CTS_PROT
| BSS_CHANGED_HT
|
1652 BSS_CHANGED_BANDWIDTH
) &&
1653 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false))
1654 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
1656 /* Need to send a new beacon template to the FW */
1657 if (changes
& BSS_CHANGED_BEACON
&&
1658 iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
1659 IWL_WARN(mvm
, "Failed updating beacon data\n");
1662 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
1663 struct ieee80211_vif
*vif
,
1664 struct ieee80211_bss_conf
*bss_conf
,
1667 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1669 mutex_lock(&mvm
->mutex
);
1671 if (changes
& BSS_CHANGED_IDLE
&& !bss_conf
->idle
)
1672 iwl_mvm_scan_offload_stop(mvm
, true);
1674 switch (vif
->type
) {
1675 case NL80211_IFTYPE_STATION
:
1676 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
1678 case NL80211_IFTYPE_AP
:
1679 case NL80211_IFTYPE_ADHOC
:
1680 iwl_mvm_bss_info_changed_ap_ibss(mvm
, vif
, bss_conf
, changes
);
1683 /* shouldn't happen */
1687 mutex_unlock(&mvm
->mutex
);
1690 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
1691 struct ieee80211_vif
*vif
,
1692 struct ieee80211_scan_request
*hw_req
)
1694 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1695 struct cfg80211_scan_request
*req
= &hw_req
->req
;
1698 if (req
->n_channels
== 0 ||
1699 req
->n_channels
> mvm
->fw
->ucode_capa
.n_scan_channels
)
1702 mutex_lock(&mvm
->mutex
);
1704 switch (mvm
->scan_status
) {
1705 case IWL_MVM_SCAN_SCHED
:
1706 ret
= iwl_mvm_scan_offload_stop(mvm
, true);
1712 case IWL_MVM_SCAN_NONE
:
1719 iwl_mvm_ref(mvm
, IWL_MVM_REF_SCAN
);
1721 if (mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_LMAC_SCAN
)
1722 ret
= iwl_mvm_unified_scan_lmac(mvm
, vif
, hw_req
);
1724 ret
= iwl_mvm_scan_request(mvm
, vif
, req
);
1727 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
1729 mutex_unlock(&mvm
->mutex
);
1730 /* make sure to flush the Rx handler before the next scan arrives */
1731 iwl_mvm_wait_for_async_handlers(mvm
);
1735 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
1736 struct ieee80211_vif
*vif
)
1738 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1740 mutex_lock(&mvm
->mutex
);
1742 iwl_mvm_cancel_scan(mvm
);
1744 mutex_unlock(&mvm
->mutex
);
1748 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
1749 struct ieee80211_sta
*sta
, u16 tids
,
1751 enum ieee80211_frame_release_type reason
,
1754 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1756 /* Called when we need to transmit (a) frame(s) from mac80211 */
1758 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
,
1759 tids
, more_data
, false);
1763 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw
*hw
,
1764 struct ieee80211_sta
*sta
, u16 tids
,
1766 enum ieee80211_frame_release_type reason
,
1769 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1771 /* Called when we need to transmit (a) frame(s) from agg queue */
1773 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
,
1774 tids
, more_data
, true);
1777 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
1778 struct ieee80211_vif
*vif
,
1779 enum sta_notify_cmd cmd
,
1780 struct ieee80211_sta
*sta
)
1782 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1783 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1787 case STA_NOTIFY_SLEEP
:
1788 if (atomic_read(&mvm
->pending_frames
[mvmsta
->sta_id
]) > 0)
1789 ieee80211_sta_block_awake(hw
, sta
, true);
1790 spin_lock_bh(&mvmsta
->lock
);
1791 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++) {
1792 struct iwl_mvm_tid_data
*tid_data
;
1794 tid_data
= &mvmsta
->tid_data
[tid
];
1795 if (tid_data
->state
!= IWL_AGG_ON
&&
1796 tid_data
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
)
1798 if (iwl_mvm_tid_queued(tid_data
) == 0)
1800 ieee80211_sta_set_buffered(sta
, tid
, true);
1802 spin_unlock_bh(&mvmsta
->lock
);
1804 * The fw updates the STA to be asleep. Tx packets on the Tx
1805 * queues to this station will not be transmitted. The fw will
1806 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1809 case STA_NOTIFY_AWAKE
:
1810 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
1812 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
1819 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw
*hw
,
1820 struct ieee80211_vif
*vif
,
1821 struct ieee80211_sta
*sta
)
1823 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1824 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
1827 * This is called before mac80211 does RCU synchronisation,
1828 * so here we already invalidate our internal RCU-protected
1829 * station pointer. The rest of the code will thus no longer
1830 * be able to find the station this way, and we don't rely
1831 * on further RCU synchronisation after the sta_state()
1832 * callback deleted the station.
1834 mutex_lock(&mvm
->mutex
);
1835 if (sta
== rcu_access_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
]))
1836 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
1838 mutex_unlock(&mvm
->mutex
);
1841 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
1842 struct ieee80211_vif
*vif
,
1843 struct ieee80211_sta
*sta
,
1844 enum ieee80211_sta_state old_state
,
1845 enum ieee80211_sta_state new_state
)
1847 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1848 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1851 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
1852 sta
->addr
, old_state
, new_state
);
1854 /* this would be a mac80211 bug ... but don't crash */
1855 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
1858 /* if a STA is being removed, reuse its ID */
1859 flush_work(&mvm
->sta_drained_wk
);
1861 mutex_lock(&mvm
->mutex
);
1862 if (old_state
== IEEE80211_STA_NOTEXIST
&&
1863 new_state
== IEEE80211_STA_NONE
) {
1865 * Firmware bug - it'll crash if the beacon interval is less
1866 * than 16. We can't avoid connecting at all, so refuse the
1867 * station state change, this will cause mac80211 to abandon
1868 * attempts to connect to this AP, and eventually wpa_s will
1869 * blacklist the AP...
1871 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1872 vif
->bss_conf
.beacon_int
< 16) {
1874 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1875 sta
->addr
, vif
->bss_conf
.beacon_int
);
1879 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
1880 } else if (old_state
== IEEE80211_STA_NONE
&&
1881 new_state
== IEEE80211_STA_AUTH
) {
1883 * EBS may be disabled due to previous failures reported by FW.
1884 * Reset EBS status here assuming environment has been changed.
1886 mvm
->last_ebs_successful
= true;
1888 } else if (old_state
== IEEE80211_STA_AUTH
&&
1889 new_state
== IEEE80211_STA_ASSOC
) {
1890 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
1892 iwl_mvm_rs_rate_init(mvm
, sta
,
1893 mvmvif
->phy_ctxt
->channel
->band
,
1895 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1896 new_state
== IEEE80211_STA_AUTHORIZED
) {
1897 /* enable beacon filtering */
1898 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
, 0));
1900 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
1901 new_state
== IEEE80211_STA_ASSOC
) {
1902 /* disable beacon filtering */
1903 WARN_ON(iwl_mvm_disable_beacon_filter(mvm
, vif
, 0));
1905 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1906 new_state
== IEEE80211_STA_AUTH
) {
1908 } else if (old_state
== IEEE80211_STA_AUTH
&&
1909 new_state
== IEEE80211_STA_NONE
) {
1911 } else if (old_state
== IEEE80211_STA_NONE
&&
1912 new_state
== IEEE80211_STA_NOTEXIST
) {
1913 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
1918 mutex_unlock(&mvm
->mutex
);
1923 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1925 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1927 mvm
->rts_threshold
= value
;
1932 static void iwl_mvm_sta_rc_update(struct ieee80211_hw
*hw
,
1933 struct ieee80211_vif
*vif
,
1934 struct ieee80211_sta
*sta
, u32 changed
)
1936 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1938 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1939 changed
& IEEE80211_RC_NSS_CHANGED
)
1940 iwl_mvm_sf_update(mvm
, vif
, false);
1943 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
1944 struct ieee80211_vif
*vif
, u16 ac
,
1945 const struct ieee80211_tx_queue_params
*params
)
1947 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1948 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1950 mvmvif
->queue_params
[ac
] = *params
;
1953 * No need to update right away, we'll get BSS_CHANGED_QOS
1954 * The exception is P2P_DEVICE interface which needs immediate update.
1956 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1959 mutex_lock(&mvm
->mutex
);
1960 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
, false);
1961 mutex_unlock(&mvm
->mutex
);
1967 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
1968 struct ieee80211_vif
*vif
)
1970 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1971 u32 duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
,
1972 200 + vif
->bss_conf
.beacon_int
);
1973 u32 min_duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
,
1974 100 + vif
->bss_conf
.beacon_int
);
1976 if (WARN_ON_ONCE(vif
->bss_conf
.assoc
))
1979 mutex_lock(&mvm
->mutex
);
1980 /* Try really hard to protect the session and hear a beacon */
1981 iwl_mvm_protect_session(mvm
, vif
, duration
, min_duration
, 500);
1982 mutex_unlock(&mvm
->mutex
);
1985 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw
*hw
,
1986 struct ieee80211_vif
*vif
,
1987 struct cfg80211_sched_scan_request
*req
,
1988 struct ieee80211_scan_ies
*ies
)
1990 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1993 mutex_lock(&mvm
->mutex
);
1995 if (!iwl_mvm_is_idle(mvm
)) {
2000 switch (mvm
->scan_status
) {
2001 case IWL_MVM_SCAN_OS
:
2002 IWL_DEBUG_SCAN(mvm
, "Stopping previous scan for sched_scan\n");
2003 ret
= iwl_mvm_cancel_scan(mvm
);
2010 * iwl_mvm_rx_scan_complete() will be called soon but will
2011 * not reset the scan status as it won't be IWL_MVM_SCAN_OS
2012 * any more since we queue the next scan immediately (below).
2013 * We make sure it is called before the next scan starts by
2014 * flushing the async-handlers work.
2017 case IWL_MVM_SCAN_NONE
:
2024 mvm
->scan_status
= IWL_MVM_SCAN_SCHED
;
2026 if (!(mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_LMAC_SCAN
)) {
2027 ret
= iwl_mvm_config_sched_scan(mvm
, vif
, req
, ies
);
2032 ret
= iwl_mvm_config_sched_scan_profiles(mvm
, req
);
2036 if (mvm
->fw
->ucode_capa
.api
[0] & IWL_UCODE_TLV_API_LMAC_SCAN
)
2037 ret
= iwl_mvm_unified_sched_scan_lmac(mvm
, vif
, req
, ies
);
2039 ret
= iwl_mvm_sched_scan_start(mvm
, req
);
2044 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
2046 mutex_unlock(&mvm
->mutex
);
2047 /* make sure to flush the Rx handler before the next scan arrives */
2048 iwl_mvm_wait_for_async_handlers(mvm
);
2052 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw
*hw
,
2053 struct ieee80211_vif
*vif
)
2055 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2058 mutex_lock(&mvm
->mutex
);
2059 ret
= iwl_mvm_scan_offload_stop(mvm
, false);
2060 mutex_unlock(&mvm
->mutex
);
2061 iwl_mvm_wait_for_async_handlers(mvm
);
2066 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
2067 enum set_key_cmd cmd
,
2068 struct ieee80211_vif
*vif
,
2069 struct ieee80211_sta
*sta
,
2070 struct ieee80211_key_conf
*key
)
2072 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2075 if (iwlwifi_mod_params
.sw_crypto
) {
2076 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
2080 switch (key
->cipher
) {
2081 case WLAN_CIPHER_SUITE_TKIP
:
2082 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
2084 case WLAN_CIPHER_SUITE_CCMP
:
2085 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
2087 case WLAN_CIPHER_SUITE_AES_CMAC
:
2088 WARN_ON_ONCE(!(hw
->flags
& IEEE80211_HW_MFP_CAPABLE
));
2090 case WLAN_CIPHER_SUITE_WEP40
:
2091 case WLAN_CIPHER_SUITE_WEP104
:
2093 * Support for TX only, at least for now, so accept
2094 * the key and do nothing else. Then mac80211 will
2095 * pass it for TX but we don't have to use it for RX.
2099 /* currently FW supports only one optional cipher scheme */
2100 if (hw
->n_cipher_schemes
&&
2101 hw
->cipher_schemes
->cipher
== key
->cipher
)
2102 key
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
2107 mutex_lock(&mvm
->mutex
);
2111 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
2112 vif
->type
== NL80211_IFTYPE_AP
) && !sta
) {
2114 * GTK on AP interface is a TX-only key, return 0;
2115 * on IBSS they're per-station and because we're lazy
2116 * we don't support them for RX, so do the same.
2119 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
2123 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
2124 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, false);
2126 IWL_WARN(mvm
, "set key failed\n");
2128 * can't add key for RX, but we don't need it
2129 * in the device for TX so still return 0
2131 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
2137 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
2142 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
2143 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
2149 mutex_unlock(&mvm
->mutex
);
2153 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
2154 struct ieee80211_vif
*vif
,
2155 struct ieee80211_key_conf
*keyconf
,
2156 struct ieee80211_sta
*sta
,
2157 u32 iv32
, u16
*phase1key
)
2159 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2161 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
2164 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
2168 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
2169 struct ieee80211_vif
*vif
,
2170 struct ieee80211_channel
*channel
,
2172 enum ieee80211_roc_type type
)
2174 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2175 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2176 struct cfg80211_chan_def chandef
;
2177 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
2180 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
2183 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
) {
2184 IWL_ERR(mvm
, "vif isn't a P2P_DEVICE: %d\n", vif
->type
);
2188 mutex_lock(&mvm
->mutex
);
2190 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
2191 phy_ctxt
= &mvm
->phy_ctxts
[i
];
2192 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
2195 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
2197 * Unbind the P2P_DEVICE from the current PHY context,
2198 * and if the PHY context is not used remove it.
2200 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
2201 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
2204 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
2206 /* Bind the P2P_DEVICE to the current PHY Context */
2207 mvmvif
->phy_ctxt
= phy_ctxt
;
2209 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
2210 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
2213 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
2214 goto schedule_time_event
;
2218 /* Need to update the PHY context only if the ROC channel changed */
2219 if (channel
== mvmvif
->phy_ctxt
->channel
)
2220 goto schedule_time_event
;
2222 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
2225 * Change the PHY context configuration as it is currently referenced
2226 * only by the P2P Device MAC
2228 if (mvmvif
->phy_ctxt
->ref
== 1) {
2229 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
2235 * The PHY context is shared with other MACs. Need to remove the
2236 * P2P Device from the binding, allocate an new PHY context and
2237 * create a new binding
2239 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
2245 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
2248 IWL_ERR(mvm
, "Failed to change PHY context\n");
2252 /* Unbind the P2P_DEVICE from the current PHY context */
2253 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
2254 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
2257 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
2259 /* Bind the P2P_DEVICE to the new allocated PHY context */
2260 mvmvif
->phy_ctxt
= phy_ctxt
;
2262 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
2263 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
2266 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
2269 schedule_time_event
:
2270 /* Schedule the time events */
2271 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
2274 mutex_unlock(&mvm
->mutex
);
2275 IWL_DEBUG_MAC80211(mvm
, "leave\n");
2279 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
)
2281 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2283 IWL_DEBUG_MAC80211(mvm
, "enter\n");
2285 mutex_lock(&mvm
->mutex
);
2286 iwl_mvm_stop_p2p_roc(mvm
);
2287 mutex_unlock(&mvm
->mutex
);
2289 IWL_DEBUG_MAC80211(mvm
, "leave\n");
2293 static int __iwl_mvm_add_chanctx(struct iwl_mvm
*mvm
,
2294 struct ieee80211_chanctx_conf
*ctx
)
2296 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2297 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
2300 lockdep_assert_held(&mvm
->mutex
);
2302 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
2304 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
2310 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->min_def
,
2311 ctx
->rx_chains_static
,
2312 ctx
->rx_chains_dynamic
);
2314 IWL_ERR(mvm
, "Failed to add PHY context\n");
2318 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
2319 *phy_ctxt_id
= phy_ctxt
->id
;
2324 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
2325 struct ieee80211_chanctx_conf
*ctx
)
2327 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2330 mutex_lock(&mvm
->mutex
);
2331 ret
= __iwl_mvm_add_chanctx(mvm
, ctx
);
2332 mutex_unlock(&mvm
->mutex
);
2337 static void __iwl_mvm_remove_chanctx(struct iwl_mvm
*mvm
,
2338 struct ieee80211_chanctx_conf
*ctx
)
2340 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2341 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
2343 lockdep_assert_held(&mvm
->mutex
);
2345 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
2348 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
2349 struct ieee80211_chanctx_conf
*ctx
)
2351 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2353 mutex_lock(&mvm
->mutex
);
2354 __iwl_mvm_remove_chanctx(mvm
, ctx
);
2355 mutex_unlock(&mvm
->mutex
);
2358 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
2359 struct ieee80211_chanctx_conf
*ctx
,
2362 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2363 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2364 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
2366 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
2367 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
2368 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
2369 IEEE80211_CHANCTX_CHANGE_RADAR
|
2370 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH
)),
2371 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2372 phy_ctxt
->ref
, changed
))
2375 mutex_lock(&mvm
->mutex
);
2376 iwl_mvm_bt_coex_vif_change(mvm
);
2377 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->min_def
,
2378 ctx
->rx_chains_static
,
2379 ctx
->rx_chains_dynamic
);
2380 mutex_unlock(&mvm
->mutex
);
2383 static int __iwl_mvm_assign_vif_chanctx(struct iwl_mvm
*mvm
,
2384 struct ieee80211_vif
*vif
,
2385 struct ieee80211_chanctx_conf
*ctx
,
2386 bool switching_chanctx
)
2388 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2389 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
2390 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2393 lockdep_assert_held(&mvm
->mutex
);
2395 mvmvif
->phy_ctxt
= phy_ctxt
;
2397 switch (vif
->type
) {
2398 case NL80211_IFTYPE_AP
:
2399 /* Unless it's a CSA flow we have nothing to do here */
2400 if (vif
->csa_active
) {
2401 mvmvif
->ap_ibss_active
= true;
2404 case NL80211_IFTYPE_ADHOC
:
2406 * The AP binding flow is handled as part of the start_ap flow
2407 * (in bss_info_changed), similarly for IBSS.
2411 case NL80211_IFTYPE_STATION
:
2412 case NL80211_IFTYPE_MONITOR
:
2419 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
2424 * Power state must be updated before quotas,
2425 * otherwise fw will complain.
2427 iwl_mvm_power_update_mac(mvm
);
2429 /* Setting the quota at this stage is only required for monitor
2430 * interfaces. For the other types, the bss_info changed flow
2431 * will handle quota settings.
2433 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
2434 mvmvif
->monitor_active
= true;
2435 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
2437 goto out_remove_binding
;
2440 /* Handle binding during CSA */
2441 if ((vif
->type
== NL80211_IFTYPE_AP
) ||
2442 (switching_chanctx
&& (vif
->type
== NL80211_IFTYPE_STATION
))) {
2443 iwl_mvm_update_quotas(mvm
, NULL
);
2444 iwl_mvm_mac_ctxt_changed(mvm
, vif
, false);
2450 iwl_mvm_binding_remove_vif(mvm
, vif
);
2451 iwl_mvm_power_update_mac(mvm
);
2454 mvmvif
->phy_ctxt
= NULL
;
2457 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
2458 struct ieee80211_vif
*vif
,
2459 struct ieee80211_chanctx_conf
*ctx
)
2461 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2464 mutex_lock(&mvm
->mutex
);
2465 ret
= __iwl_mvm_assign_vif_chanctx(mvm
, vif
, ctx
, false);
2466 mutex_unlock(&mvm
->mutex
);
2471 static void __iwl_mvm_unassign_vif_chanctx(struct iwl_mvm
*mvm
,
2472 struct ieee80211_vif
*vif
,
2473 struct ieee80211_chanctx_conf
*ctx
,
2474 bool switching_chanctx
)
2476 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2477 struct ieee80211_vif
*disabled_vif
= NULL
;
2479 lockdep_assert_held(&mvm
->mutex
);
2481 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
2483 switch (vif
->type
) {
2484 case NL80211_IFTYPE_ADHOC
:
2486 case NL80211_IFTYPE_MONITOR
:
2487 mvmvif
->monitor_active
= false;
2489 case NL80211_IFTYPE_AP
:
2490 /* This part is triggered only during CSA */
2491 if (!vif
->csa_active
|| !mvmvif
->ap_ibss_active
)
2494 mvmvif
->ap_ibss_active
= false;
2496 case NL80211_IFTYPE_STATION
:
2497 if (!switching_chanctx
)
2502 iwl_mvm_mac_ctxt_changed(mvm
, vif
, true);
2508 iwl_mvm_update_quotas(mvm
, disabled_vif
);
2509 iwl_mvm_binding_remove_vif(mvm
, vif
);
2512 mvmvif
->phy_ctxt
= NULL
;
2513 iwl_mvm_power_update_mac(mvm
);
2516 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
2517 struct ieee80211_vif
*vif
,
2518 struct ieee80211_chanctx_conf
*ctx
)
2520 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2522 mutex_lock(&mvm
->mutex
);
2523 __iwl_mvm_unassign_vif_chanctx(mvm
, vif
, ctx
, false);
2524 mutex_unlock(&mvm
->mutex
);
2527 static int iwl_mvm_switch_vif_chanctx(struct ieee80211_hw
*hw
,
2528 struct ieee80211_vif_chanctx_switch
*vifs
,
2530 enum ieee80211_chanctx_switch_mode mode
)
2532 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2535 /* we only support SWAP_CONTEXTS and with a single-vif right now */
2536 if (mode
!= CHANCTX_SWMODE_SWAP_CONTEXTS
|| n_vifs
> 1)
2539 mutex_lock(&mvm
->mutex
);
2540 __iwl_mvm_unassign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].old_ctx
, true);
2541 __iwl_mvm_remove_chanctx(mvm
, vifs
[0].old_ctx
);
2543 ret
= __iwl_mvm_add_chanctx(mvm
, vifs
[0].new_ctx
);
2545 IWL_ERR(mvm
, "failed to add new_ctx during channel switch\n");
2549 ret
= __iwl_mvm_assign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].new_ctx
,
2553 "failed to assign new_ctx during channel switch\n");
2560 __iwl_mvm_remove_chanctx(mvm
, vifs
[0].new_ctx
);
2563 ret
= __iwl_mvm_add_chanctx(mvm
, vifs
[0].old_ctx
);
2565 IWL_ERR(mvm
, "failed to add old_ctx back after failure.\n");
2569 ret
= __iwl_mvm_assign_vif_chanctx(mvm
, vifs
[0].vif
, vifs
[0].old_ctx
,
2572 IWL_ERR(mvm
, "failed to reassign old_ctx after failure.\n");
2579 /* things keep failing, better restart the hw */
2580 iwl_mvm_nic_restart(mvm
, false);
2583 mutex_unlock(&mvm
->mutex
);
2587 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
2588 struct ieee80211_sta
*sta
,
2591 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2592 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
2594 if (!mvm_sta
|| !mvm_sta
->vif
) {
2595 IWL_ERR(mvm
, "Station is not associated to a vif\n");
2599 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
2602 #ifdef CONFIG_NL80211_TESTMODE
2603 static const struct nla_policy iwl_mvm_tm_policy
[IWL_MVM_TM_ATTR_MAX
+ 1] = {
2604 [IWL_MVM_TM_ATTR_CMD
] = { .type
= NLA_U32
},
2605 [IWL_MVM_TM_ATTR_NOA_DURATION
] = { .type
= NLA_U32
},
2606 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
] = { .type
= NLA_U32
},
2609 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm
*mvm
,
2610 struct ieee80211_vif
*vif
,
2611 void *data
, int len
)
2613 struct nlattr
*tb
[IWL_MVM_TM_ATTR_MAX
+ 1];
2617 err
= nla_parse(tb
, IWL_MVM_TM_ATTR_MAX
, data
, len
, iwl_mvm_tm_policy
);
2621 if (!tb
[IWL_MVM_TM_ATTR_CMD
])
2624 switch (nla_get_u32(tb
[IWL_MVM_TM_ATTR_CMD
])) {
2625 case IWL_MVM_TM_CMD_SET_NOA
:
2626 if (!vif
|| vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
||
2627 !vif
->bss_conf
.enable_beacon
||
2628 !tb
[IWL_MVM_TM_ATTR_NOA_DURATION
])
2631 noa_duration
= nla_get_u32(tb
[IWL_MVM_TM_ATTR_NOA_DURATION
]);
2632 if (noa_duration
>= vif
->bss_conf
.beacon_int
)
2635 mvm
->noa_duration
= noa_duration
;
2638 return iwl_mvm_update_quotas(mvm
, NULL
);
2639 case IWL_MVM_TM_CMD_SET_BEACON_FILTER
:
2640 /* must be associated client vif - ignore authorized */
2641 if (!vif
|| vif
->type
!= NL80211_IFTYPE_STATION
||
2642 !vif
->bss_conf
.assoc
|| !vif
->bss_conf
.dtim_period
||
2643 !tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
])
2646 if (nla_get_u32(tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
]))
2647 return iwl_mvm_enable_beacon_filter(mvm
, vif
, 0);
2648 return iwl_mvm_disable_beacon_filter(mvm
, vif
, 0);
2654 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw
*hw
,
2655 struct ieee80211_vif
*vif
,
2656 void *data
, int len
)
2658 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2661 mutex_lock(&mvm
->mutex
);
2662 err
= __iwl_mvm_mac_testmode_cmd(mvm
, vif
, data
, len
);
2663 mutex_unlock(&mvm
->mutex
);
2669 static void iwl_mvm_channel_switch_beacon(struct ieee80211_hw
*hw
,
2670 struct ieee80211_vif
*vif
,
2671 struct cfg80211_chan_def
*chandef
)
2673 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2674 struct ieee80211_vif
*csa_vif
;
2676 mutex_lock(&mvm
->mutex
);
2678 csa_vif
= rcu_dereference_protected(mvm
->csa_vif
,
2679 lockdep_is_held(&mvm
->mutex
));
2680 if (WARN(csa_vif
&& csa_vif
->csa_active
,
2681 "Another CSA is already in progress"))
2684 IWL_DEBUG_MAC80211(mvm
, "CSA started to freq %d\n",
2685 chandef
->center_freq1
);
2686 rcu_assign_pointer(mvm
->csa_vif
, vif
);
2689 mutex_unlock(&mvm
->mutex
);
2692 static void iwl_mvm_mac_flush(struct ieee80211_hw
*hw
,
2693 struct ieee80211_vif
*vif
, u32 queues
, bool drop
)
2695 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2696 struct iwl_mvm_vif
*mvmvif
;
2697 struct iwl_mvm_sta
*mvmsta
;
2699 if (!vif
|| vif
->type
!= NL80211_IFTYPE_STATION
)
2702 mutex_lock(&mvm
->mutex
);
2703 mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2704 mvmsta
= iwl_mvm_sta_from_staid_protected(mvm
, mvmvif
->ap_sta_id
);
2706 if (WARN_ON_ONCE(!mvmsta
))
2710 if (iwl_mvm_flush_tx_path(mvm
, mvmsta
->tfd_queue_msk
, true))
2711 IWL_ERR(mvm
, "flush request fail\n");
2713 iwl_trans_wait_tx_queue_empty(mvm
->trans
,
2714 mvmsta
->tfd_queue_msk
);
2717 mutex_unlock(&mvm
->mutex
);
2720 const struct ieee80211_ops iwl_mvm_hw_ops
= {
2721 .tx
= iwl_mvm_mac_tx
,
2722 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
2723 .start
= iwl_mvm_mac_start
,
2724 .restart_complete
= iwl_mvm_mac_restart_complete
,
2725 .stop
= iwl_mvm_mac_stop
,
2726 .add_interface
= iwl_mvm_mac_add_interface
,
2727 .remove_interface
= iwl_mvm_mac_remove_interface
,
2728 .config
= iwl_mvm_mac_config
,
2729 .prepare_multicast
= iwl_mvm_prepare_multicast
,
2730 .configure_filter
= iwl_mvm_configure_filter
,
2731 .bss_info_changed
= iwl_mvm_bss_info_changed
,
2732 .hw_scan
= iwl_mvm_mac_hw_scan
,
2733 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
2734 .sta_pre_rcu_remove
= iwl_mvm_sta_pre_rcu_remove
,
2735 .sta_state
= iwl_mvm_mac_sta_state
,
2736 .sta_notify
= iwl_mvm_mac_sta_notify
,
2737 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
2738 .release_buffered_frames
= iwl_mvm_mac_release_buffered_frames
,
2739 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
2740 .sta_rc_update
= iwl_mvm_sta_rc_update
,
2741 .conf_tx
= iwl_mvm_mac_conf_tx
,
2742 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
2743 .flush
= iwl_mvm_mac_flush
,
2744 .sched_scan_start
= iwl_mvm_mac_sched_scan_start
,
2745 .sched_scan_stop
= iwl_mvm_mac_sched_scan_stop
,
2746 .set_key
= iwl_mvm_mac_set_key
,
2747 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
2748 .remain_on_channel
= iwl_mvm_roc
,
2749 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
2750 .add_chanctx
= iwl_mvm_add_chanctx
,
2751 .remove_chanctx
= iwl_mvm_remove_chanctx
,
2752 .change_chanctx
= iwl_mvm_change_chanctx
,
2753 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
2754 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
2755 .switch_vif_chanctx
= iwl_mvm_switch_vif_chanctx
,
2757 .start_ap
= iwl_mvm_start_ap_ibss
,
2758 .stop_ap
= iwl_mvm_stop_ap_ibss
,
2759 .join_ibss
= iwl_mvm_start_ap_ibss
,
2760 .leave_ibss
= iwl_mvm_stop_ap_ibss
,
2762 .set_tim
= iwl_mvm_set_tim
,
2764 .channel_switch_beacon
= iwl_mvm_channel_switch_beacon
,
2766 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd
)
2768 #ifdef CONFIG_PM_SLEEP
2770 .suspend
= iwl_mvm_suspend
,
2771 .resume
= iwl_mvm_resume
,
2772 .set_wakeup
= iwl_mvm_set_wakeup
,
2773 .set_rekey_data
= iwl_mvm_set_rekey_data
,
2774 #if IS_ENABLED(CONFIG_IPV6)
2775 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
2777 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,