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"
84 static const struct ieee80211_iface_limit iwl_mvm_limits
[] = {
87 .types
= BIT(NL80211_IFTYPE_STATION
),
91 .types
= BIT(NL80211_IFTYPE_AP
) |
92 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
93 BIT(NL80211_IFTYPE_P2P_GO
),
97 .types
= BIT(NL80211_IFTYPE_P2P_DEVICE
),
101 static const struct ieee80211_iface_combination iwl_mvm_iface_combinations
[] = {
103 .num_different_channels
= 1,
105 .limits
= iwl_mvm_limits
,
106 .n_limits
= ARRAY_SIZE(iwl_mvm_limits
),
110 #ifdef CONFIG_PM_SLEEP
111 static const struct nl80211_wowlan_tcp_data_token_feature
112 iwl_mvm_wowlan_tcp_token_feature
= {
115 .bufsize
= IWL_WOWLAN_REMOTE_WAKE_MAX_TOKENS
,
118 static const struct wiphy_wowlan_tcp_support iwl_mvm_wowlan_tcp_support
= {
119 .tok
= &iwl_mvm_wowlan_tcp_token_feature
,
120 .data_payload_max
= IWL_WOWLAN_TCP_MAX_PACKET_LEN
-
121 sizeof(struct ethhdr
) -
122 sizeof(struct iphdr
) -
123 sizeof(struct tcphdr
),
124 .data_interval_max
= 65535, /* __le16 in API */
125 .wake_payload_max
= IWL_WOWLAN_REMOTE_WAKE_MAX_PACKET_LEN
-
126 sizeof(struct ethhdr
) -
127 sizeof(struct iphdr
) -
128 sizeof(struct tcphdr
),
133 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
135 * Use the reserved field to indicate magic values.
136 * these values will only be used internally by the driver,
137 * and won't make it to the fw (reserved will be 0).
138 * BC_FILTER_MAGIC_IP - configure the val of this attribute to
139 * be the vif's ip address. in case there is not a single
140 * ip address (0, or more than 1), this attribute will
142 * BC_FILTER_MAGIC_MAC - set the val of this attribute to
143 * the LSB bytes of the vif's mac address
146 BC_FILTER_MAGIC_NONE
= 0,
151 static const struct iwl_fw_bcast_filter iwl_mvm_default_bcast_filters
[] = {
155 .frame_type
= BCAST_FILTER_FRAME_TYPE_ALL
,
158 /* frame type - arp, hw type - ethernet */
160 BCAST_FILTER_OFFSET_PAYLOAD_START
,
161 .offset
= sizeof(rfc1042_header
),
162 .val
= cpu_to_be32(0x08060001),
163 .mask
= cpu_to_be32(0xffffffff),
168 BCAST_FILTER_OFFSET_PAYLOAD_START
,
169 .offset
= sizeof(rfc1042_header
) + 2 +
170 sizeof(struct arphdr
) +
171 ETH_ALEN
+ sizeof(__be32
) +
173 .mask
= cpu_to_be32(0xffffffff),
174 /* mark it as special field */
175 .reserved1
= cpu_to_le16(BC_FILTER_MAGIC_IP
),
180 /* dhcp offer bcast */
182 .frame_type
= BCAST_FILTER_FRAME_TYPE_IPV4
,
185 /* udp dest port - 68 (bootp client)*/
186 .offset_type
= BCAST_FILTER_OFFSET_IP_END
,
187 .offset
= offsetof(struct udphdr
, dest
),
188 .val
= cpu_to_be32(0x00440000),
189 .mask
= cpu_to_be32(0xffff0000),
192 /* dhcp - lsb bytes of client hw address */
193 .offset_type
= BCAST_FILTER_OFFSET_IP_END
,
195 .mask
= cpu_to_be32(0xffffffff),
196 /* mark it as special field */
197 .reserved1
= cpu_to_le16(BC_FILTER_MAGIC_MAC
),
201 /* last filter must be empty */
206 void iwl_mvm_ref(struct iwl_mvm
*mvm
, enum iwl_mvm_ref_type ref_type
)
208 if (!mvm
->trans
->cfg
->d0i3
)
211 IWL_DEBUG_RPM(mvm
, "Take mvm reference - type %d\n", ref_type
);
212 WARN_ON(test_and_set_bit(ref_type
, mvm
->ref_bitmap
));
213 iwl_trans_ref(mvm
->trans
);
216 void iwl_mvm_unref(struct iwl_mvm
*mvm
, enum iwl_mvm_ref_type ref_type
)
218 if (!mvm
->trans
->cfg
->d0i3
)
221 IWL_DEBUG_RPM(mvm
, "Leave mvm reference - type %d\n", ref_type
);
222 WARN_ON(!test_and_clear_bit(ref_type
, mvm
->ref_bitmap
));
223 iwl_trans_unref(mvm
->trans
);
227 iwl_mvm_unref_all_except(struct iwl_mvm
*mvm
, enum iwl_mvm_ref_type ref
)
231 if (!mvm
->trans
->cfg
->d0i3
)
234 for_each_set_bit(i
, mvm
->ref_bitmap
, IWL_MVM_REF_COUNT
) {
238 IWL_DEBUG_RPM(mvm
, "Cleanup: remove mvm ref type %d\n", i
);
239 clear_bit(i
, mvm
->ref_bitmap
);
240 iwl_trans_unref(mvm
->trans
);
244 static void iwl_mvm_reset_phy_ctxts(struct iwl_mvm
*mvm
)
248 memset(mvm
->phy_ctxts
, 0, sizeof(mvm
->phy_ctxts
));
249 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
250 mvm
->phy_ctxts
[i
].id
= i
;
251 mvm
->phy_ctxts
[i
].ref
= 0;
255 static int iwl_mvm_max_scan_ie_len(struct iwl_mvm
*mvm
)
257 /* we create the 802.11 header and SSID element */
258 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_NO_BASIC_SSID
)
259 return mvm
->fw
->ucode_capa
.max_probe_length
- 24 - 2;
260 return mvm
->fw
->ucode_capa
.max_probe_length
- 24 - 34;
263 int iwl_mvm_mac_setup_register(struct iwl_mvm
*mvm
)
265 struct ieee80211_hw
*hw
= mvm
->hw
;
268 /* Tell mac80211 our characteristics */
269 hw
->flags
= IEEE80211_HW_SIGNAL_DBM
|
270 IEEE80211_HW_SPECTRUM_MGMT
|
271 IEEE80211_HW_REPORTS_TX_ACK_STATUS
|
272 IEEE80211_HW_QUEUE_CONTROL
|
273 IEEE80211_HW_WANT_MONITOR_VIF
|
274 IEEE80211_HW_SUPPORTS_PS
|
275 IEEE80211_HW_SUPPORTS_DYNAMIC_PS
|
276 IEEE80211_HW_AMPDU_AGGREGATION
|
277 IEEE80211_HW_TIMING_BEACON_ONLY
|
278 IEEE80211_HW_CONNECTION_MONITOR
|
279 IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS
|
280 IEEE80211_HW_SUPPORTS_STATIC_SMPS
;
282 hw
->queues
= mvm
->first_agg_queue
;
283 hw
->offchannel_tx_hw_queue
= IWL_MVM_OFFCHANNEL_QUEUE
;
284 hw
->radiotap_mcs_details
|= IEEE80211_RADIOTAP_MCS_HAVE_FEC
|
285 IEEE80211_RADIOTAP_MCS_HAVE_STBC
;
286 hw
->radiotap_vht_details
|= IEEE80211_RADIOTAP_VHT_KNOWN_STBC
;
287 hw
->rate_control_algorithm
= "iwl-mvm-rs";
290 * Enable 11w if advertised by firmware and software crypto
291 * is not enabled (as the firmware will interpret some mgmt
292 * packets, so enabling it with software crypto isn't safe)
294 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_MFP
&&
295 !iwlwifi_mod_params
.sw_crypto
)
296 hw
->flags
|= IEEE80211_HW_MFP_CAPABLE
;
298 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_UAPSD_SUPPORT
) {
299 hw
->flags
|= IEEE80211_HW_SUPPORTS_UAPSD
;
300 hw
->uapsd_queues
= IWL_UAPSD_AC_INFO
;
301 hw
->uapsd_max_sp_len
= IWL_UAPSD_MAX_SP
;
304 hw
->sta_data_size
= sizeof(struct iwl_mvm_sta
);
305 hw
->vif_data_size
= sizeof(struct iwl_mvm_vif
);
306 hw
->chanctx_data_size
= sizeof(u16
);
308 hw
->wiphy
->interface_modes
= BIT(NL80211_IFTYPE_STATION
) |
309 BIT(NL80211_IFTYPE_P2P_CLIENT
) |
310 BIT(NL80211_IFTYPE_AP
) |
311 BIT(NL80211_IFTYPE_P2P_GO
) |
312 BIT(NL80211_IFTYPE_P2P_DEVICE
);
314 /* IBSS has bugs in older versions */
315 if (IWL_UCODE_API(mvm
->fw
->ucode_ver
) >= 8)
316 hw
->wiphy
->interface_modes
|= BIT(NL80211_IFTYPE_ADHOC
);
318 hw
->wiphy
->flags
|= WIPHY_FLAG_IBSS_RSN
;
319 hw
->wiphy
->regulatory_flags
|= REGULATORY_CUSTOM_REG
|
320 REGULATORY_DISABLE_BEACON_HINTS
;
322 if (mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_GO_UAPSD
)
323 hw
->wiphy
->flags
|= WIPHY_FLAG_AP_UAPSD
;
325 hw
->wiphy
->iface_combinations
= iwl_mvm_iface_combinations
;
326 hw
->wiphy
->n_iface_combinations
=
327 ARRAY_SIZE(iwl_mvm_iface_combinations
);
329 hw
->wiphy
->max_remain_on_channel_duration
= 10000;
330 hw
->max_listen_interval
= IWL_CONN_MAX_LISTEN_INTERVAL
;
332 /* Extract MAC address */
333 memcpy(mvm
->addresses
[0].addr
, mvm
->nvm_data
->hw_addr
, ETH_ALEN
);
334 hw
->wiphy
->addresses
= mvm
->addresses
;
335 hw
->wiphy
->n_addresses
= 1;
337 /* Extract additional MAC addresses if available */
338 num_mac
= (mvm
->nvm_data
->n_hw_addrs
> 1) ?
339 min(IWL_MVM_MAX_ADDRESSES
, mvm
->nvm_data
->n_hw_addrs
) : 1;
341 for (i
= 1; i
< num_mac
; i
++) {
342 memcpy(mvm
->addresses
[i
].addr
, mvm
->addresses
[i
-1].addr
,
344 mvm
->addresses
[i
].addr
[5]++;
345 hw
->wiphy
->n_addresses
++;
348 iwl_mvm_reset_phy_ctxts(mvm
);
350 hw
->wiphy
->max_scan_ie_len
= iwl_mvm_max_scan_ie_len(mvm
);
352 hw
->wiphy
->max_scan_ssids
= PROBE_OPTION_MAX
;
354 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
].n_channels
)
355 hw
->wiphy
->bands
[IEEE80211_BAND_2GHZ
] =
356 &mvm
->nvm_data
->bands
[IEEE80211_BAND_2GHZ
];
357 if (mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
].n_channels
)
358 hw
->wiphy
->bands
[IEEE80211_BAND_5GHZ
] =
359 &mvm
->nvm_data
->bands
[IEEE80211_BAND_5GHZ
];
361 hw
->wiphy
->hw_version
= mvm
->trans
->hw_id
;
363 if (iwlmvm_mod_params
.power_scheme
!= IWL_POWER_SCHEME_CAM
)
364 hw
->wiphy
->flags
|= WIPHY_FLAG_PS_ON_BY_DEFAULT
;
366 hw
->wiphy
->flags
&= ~WIPHY_FLAG_PS_ON_BY_DEFAULT
;
368 if (0 && mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_SCHED_SCAN
) {
369 hw
->wiphy
->flags
|= WIPHY_FLAG_SUPPORTS_SCHED_SCAN
;
370 hw
->wiphy
->max_sched_scan_ssids
= PROBE_OPTION_MAX
;
371 hw
->wiphy
->max_match_sets
= IWL_SCAN_MAX_PROFILES
;
372 /* we create the 802.11 header and zero length SSID IE. */
373 hw
->wiphy
->max_sched_scan_ie_len
=
374 SCAN_OFFLOAD_PROBE_REQ_SIZE
- 24 - 2;
377 hw
->wiphy
->features
|= NL80211_FEATURE_P2P_GO_CTWIN
|
378 NL80211_FEATURE_P2P_GO_OPPPS
|
379 NL80211_FEATURE_LOW_PRIORITY_SCAN
;
381 mvm
->rts_threshold
= IEEE80211_MAX_RTS_THRESHOLD
;
383 /* currently FW API supports only one optional cipher scheme */
384 if (mvm
->fw
->cs
[0].cipher
) {
385 mvm
->hw
->n_cipher_schemes
= 1;
386 mvm
->hw
->cipher_schemes
= &mvm
->fw
->cs
[0];
389 #ifdef CONFIG_PM_SLEEP
390 if (mvm
->fw
->img
[IWL_UCODE_WOWLAN
].sec
[0].len
&&
391 mvm
->trans
->ops
->d3_suspend
&&
392 mvm
->trans
->ops
->d3_resume
&&
393 device_can_wakeup(mvm
->trans
->dev
)) {
394 mvm
->wowlan
.flags
= WIPHY_WOWLAN_MAGIC_PKT
|
395 WIPHY_WOWLAN_DISCONNECT
|
396 WIPHY_WOWLAN_EAP_IDENTITY_REQ
|
397 WIPHY_WOWLAN_RFKILL_RELEASE
;
398 if (!iwlwifi_mod_params
.sw_crypto
)
399 mvm
->wowlan
.flags
|= WIPHY_WOWLAN_SUPPORTS_GTK_REKEY
|
400 WIPHY_WOWLAN_GTK_REKEY_FAILURE
|
401 WIPHY_WOWLAN_4WAY_HANDSHAKE
;
403 mvm
->wowlan
.n_patterns
= IWL_WOWLAN_MAX_PATTERNS
;
404 mvm
->wowlan
.pattern_min_len
= IWL_WOWLAN_MIN_PATTERN_LEN
;
405 mvm
->wowlan
.pattern_max_len
= IWL_WOWLAN_MAX_PATTERN_LEN
;
406 mvm
->wowlan
.tcp
= &iwl_mvm_wowlan_tcp_support
;
407 hw
->wiphy
->wowlan
= &mvm
->wowlan
;
411 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
412 /* assign default bcast filtering configuration */
413 mvm
->bcast_filters
= iwl_mvm_default_bcast_filters
;
416 ret
= iwl_mvm_leds_init(mvm
);
420 ret
= ieee80211_register_hw(mvm
->hw
);
422 iwl_mvm_leds_exit(mvm
);
427 static void iwl_mvm_mac_tx(struct ieee80211_hw
*hw
,
428 struct ieee80211_tx_control
*control
,
431 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
432 struct ieee80211_sta
*sta
= control
->sta
;
433 struct ieee80211_tx_info
*info
= IEEE80211_SKB_CB(skb
);
434 struct ieee80211_hdr
*hdr
= (void *)skb
->data
;
436 if (iwl_mvm_is_radio_killed(mvm
)) {
437 IWL_DEBUG_DROP(mvm
, "Dropping - RF/CT KILL\n");
441 if (IEEE80211_SKB_CB(skb
)->hw_queue
== IWL_MVM_OFFCHANNEL_QUEUE
&&
442 !test_bit(IWL_MVM_STATUS_ROC_RUNNING
, &mvm
->status
))
445 /* treat non-bufferable MMPDUs as broadcast if sta is sleeping */
446 if (unlikely(info
->flags
& IEEE80211_TX_CTL_NO_PS_BUFFER
&&
447 ieee80211_is_mgmt(hdr
->frame_control
) &&
448 !ieee80211_is_deauth(hdr
->frame_control
) &&
449 !ieee80211_is_disassoc(hdr
->frame_control
) &&
450 !ieee80211_is_action(hdr
->frame_control
)))
454 if (iwl_mvm_tx_skb(mvm
, skb
, sta
))
459 if (iwl_mvm_tx_skb_non_sta(mvm
, skb
))
463 ieee80211_free_txskb(hw
, skb
);
466 static inline bool iwl_enable_rx_ampdu(const struct iwl_cfg
*cfg
)
468 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_RXAGG
)
473 static inline bool iwl_enable_tx_ampdu(const struct iwl_cfg
*cfg
)
475 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_TXAGG
)
477 if (iwlwifi_mod_params
.disable_11n
& IWL_ENABLE_HT_TXAGG
)
480 /* enabled by default */
484 static int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
485 struct ieee80211_vif
*vif
,
486 enum ieee80211_ampdu_mlme_action action
,
487 struct ieee80211_sta
*sta
, u16 tid
,
488 u16
*ssn
, u8 buf_size
)
490 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
493 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
494 sta
->addr
, tid
, action
);
496 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
499 mutex_lock(&mvm
->mutex
);
502 case IEEE80211_AMPDU_RX_START
:
503 if (!iwl_enable_rx_ampdu(mvm
->cfg
)) {
507 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true);
509 case IEEE80211_AMPDU_RX_STOP
:
510 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false);
512 case IEEE80211_AMPDU_TX_START
:
513 if (!iwl_enable_tx_ampdu(mvm
->cfg
)) {
517 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
519 case IEEE80211_AMPDU_TX_STOP_CONT
:
520 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
522 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
523 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
524 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
526 case IEEE80211_AMPDU_TX_OPERATIONAL
:
527 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
, buf_size
);
534 mutex_unlock(&mvm
->mutex
);
539 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
540 struct ieee80211_vif
*vif
)
542 struct iwl_mvm
*mvm
= data
;
543 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
545 mvmvif
->uploaded
= false;
546 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
548 /* does this make sense at all? */
551 spin_lock_bh(&mvm
->time_event_lock
);
552 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
553 spin_unlock_bh(&mvm
->time_event_lock
);
555 mvmvif
->phy_ctxt
= NULL
;
558 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
560 iwl_trans_stop_device(mvm
->trans
);
562 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
564 /* just in case one was running */
565 ieee80211_remain_on_channel_expired(mvm
->hw
);
567 ieee80211_iterate_active_interfaces_atomic(
568 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
569 iwl_mvm_cleanup_iterator
, mvm
);
571 mvm
->p2p_device_vif
= NULL
;
572 mvm
->d0i3_ap_sta_id
= IWL_MVM_STATION_COUNT
;
574 iwl_mvm_reset_phy_ctxts(mvm
);
575 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
576 memset(mvm
->sta_drained
, 0, sizeof(mvm
->sta_drained
));
578 ieee80211_wake_queues(mvm
->hw
);
580 /* cleanup all stale references (scan, roc), but keep the
581 * ucode_down ref until reconfig is complete */
582 iwl_mvm_unref_all_except(mvm
, IWL_MVM_REF_UCODE_DOWN
);
585 mvm
->rx_ba_sessions
= 0;
588 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
590 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
593 mutex_lock(&mvm
->mutex
);
595 /* Clean up some internal and mac80211 state on restart */
596 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
597 iwl_mvm_restart_cleanup(mvm
);
599 ret
= iwl_mvm_up(mvm
);
600 mutex_unlock(&mvm
->mutex
);
605 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw
*hw
)
607 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
610 mutex_lock(&mvm
->mutex
);
612 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
613 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
615 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
618 /* allow transport/FW low power modes */
619 iwl_mvm_unref(mvm
, IWL_MVM_REF_UCODE_DOWN
);
621 mutex_unlock(&mvm
->mutex
);
624 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
626 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
628 flush_work(&mvm
->d0i3_exit_work
);
629 flush_work(&mvm
->async_handlers_wk
);
631 mutex_lock(&mvm
->mutex
);
633 /* disallow low power states when the FW is down */
634 iwl_mvm_ref(mvm
, IWL_MVM_REF_UCODE_DOWN
);
636 /* async_handlers_wk is now blocked */
639 * The work item could be running or queued if the
640 * ROC time event stops just as we get here.
642 cancel_work_sync(&mvm
->roc_done_wk
);
644 iwl_trans_stop_device(mvm
->trans
);
646 iwl_mvm_async_handlers_purge(mvm
);
647 /* async_handlers_list is empty and will stay empty: HW is stopped */
649 /* the fw is stopped, the aux sta is dead: clean up driver state */
650 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
652 mutex_unlock(&mvm
->mutex
);
655 * The worker might have been waiting for the mutex, let it run and
656 * discover that its list is now empty.
658 cancel_work_sync(&mvm
->async_handlers_wk
);
661 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
665 lockdep_assert_held(&mvm
->mutex
);
667 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
668 if (!mvm
->phy_ctxts
[i
].ref
)
669 return &mvm
->phy_ctxts
[i
];
671 IWL_ERR(mvm
, "No available PHY context\n");
675 static int iwl_mvm_set_tx_power(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
678 /* FW is in charge of regulatory enforcement */
679 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd
= {
680 .mac_context_id
= iwl_mvm_vif_from_mac80211(vif
)->id
,
681 .pwr_restriction
= cpu_to_le16(tx_power
),
684 return iwl_mvm_send_cmd_pdu(mvm
, REDUCE_TX_POWER_CMD
, CMD_SYNC
,
685 sizeof(reduce_txpwr_cmd
),
689 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
690 struct ieee80211_vif
*vif
)
692 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
693 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
697 * Not much to do here. The stack will not allow interface
698 * types or combinations that we didn't advertise, so we
699 * don't really have to check the types.
702 mutex_lock(&mvm
->mutex
);
704 /* Allocate resources for the MAC context, and add it to the fw */
705 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
709 /* Counting number of interfaces is needed for legacy PM */
710 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
714 * The AP binding flow can be done only after the beacon
715 * template is configured (which happens only in the mac80211
716 * start_ap() flow), and adding the broadcast station can happen
717 * only after the binding.
718 * In addition, since modifying the MAC before adding a bcast
719 * station is not allowed by the FW, delay the adding of MAC context to
720 * the point where we can also add the bcast station.
721 * In short: there's not much we can do at this point, other than
722 * allocating resources :)
724 if (vif
->type
== NL80211_IFTYPE_AP
||
725 vif
->type
== NL80211_IFTYPE_ADHOC
) {
726 u32 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
727 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
,
729 ieee80211_vif_type_p2p(vif
));
731 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
735 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
739 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
743 ret
= iwl_mvm_power_update_mac(mvm
, vif
);
747 /* beacon filtering */
748 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, CMD_SYNC
);
752 if (!mvm
->bf_allowed_vif
&&
753 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
&&
754 mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BF_UPDATED
){
755 mvm
->bf_allowed_vif
= mvmvif
;
756 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
757 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
761 * P2P_DEVICE interface does not have a channel context assigned to it,
762 * so a dedicated PHY context is allocated to it and the corresponding
763 * MAC context is bound to it at this stage.
765 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
767 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
768 if (!mvmvif
->phy_ctxt
) {
773 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
774 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
778 ret
= iwl_mvm_add_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
782 /* Save a pointer to p2p device vif, so it can later be used to
783 * update the p2p device MAC when a GO is started/stopped */
784 mvm
->p2p_device_vif
= vif
;
787 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
791 iwl_mvm_binding_remove_vif(mvm
, vif
);
793 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
795 if (mvm
->bf_allowed_vif
== mvmvif
) {
796 mvm
->bf_allowed_vif
= NULL
;
797 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
798 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
801 mvmvif
->phy_ctxt
= NULL
;
802 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
804 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
807 iwl_mvm_mac_ctxt_release(mvm
, vif
);
809 mutex_unlock(&mvm
->mutex
);
814 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
815 struct ieee80211_vif
*vif
)
819 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
820 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
821 tfd_msk
|= BIT(vif
->hw_queue
[ac
]);
823 if (vif
->cab_queue
!= IEEE80211_INVAL_HW_QUEUE
)
824 tfd_msk
|= BIT(vif
->cab_queue
);
827 mutex_lock(&mvm
->mutex
);
828 iwl_mvm_flush_tx_path(mvm
, tfd_msk
, true);
829 mutex_unlock(&mvm
->mutex
);
832 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
834 * Flush the ROC worker which will flush the OFFCHANNEL queue.
835 * We assume here that all the packets sent to the OFFCHANNEL
836 * queue are sent in ROC session.
838 flush_work(&mvm
->roc_done_wk
);
841 * By now, all the AC queues are empty. The AGG queues are
842 * empty too. We already got all the Tx responses for all the
843 * packets in the queues. The drain work can have been
844 * triggered. Flush it.
846 flush_work(&mvm
->sta_drained_wk
);
850 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
851 struct ieee80211_vif
*vif
)
853 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
854 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
856 iwl_mvm_prepare_mac_removal(mvm
, vif
);
858 mutex_lock(&mvm
->mutex
);
860 if (mvm
->bf_allowed_vif
== mvmvif
) {
861 mvm
->bf_allowed_vif
= NULL
;
862 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
863 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
866 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
869 * For AP/GO interface, the tear down of the resources allocated to the
870 * interface is be handled as part of the stop_ap flow.
872 if (vif
->type
== NL80211_IFTYPE_AP
||
873 vif
->type
== NL80211_IFTYPE_ADHOC
) {
874 #ifdef CONFIG_NL80211_TESTMODE
875 if (vif
== mvm
->noa_vif
) {
877 mvm
->noa_duration
= 0;
880 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
884 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
885 mvm
->p2p_device_vif
= NULL
;
886 iwl_mvm_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
887 iwl_mvm_binding_remove_vif(mvm
, vif
);
888 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
889 mvmvif
->phy_ctxt
= NULL
;
892 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
895 iwl_mvm_power_update_mac(mvm
, vif
);
896 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
899 iwl_mvm_mac_ctxt_release(mvm
, vif
);
900 mutex_unlock(&mvm
->mutex
);
903 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
908 struct iwl_mvm_mc_iter_data
{
913 static void iwl_mvm_mc_iface_iterator(void *_data
, u8
*mac
,
914 struct ieee80211_vif
*vif
)
916 struct iwl_mvm_mc_iter_data
*data
= _data
;
917 struct iwl_mvm
*mvm
= data
->mvm
;
918 struct iwl_mcast_filter_cmd
*cmd
= mvm
->mcast_filter_cmd
;
921 /* if we don't have free ports, mcast frames will be dropped */
922 if (WARN_ON_ONCE(data
->port_id
>= MAX_PORT_ID_NUM
))
925 if (vif
->type
!= NL80211_IFTYPE_STATION
||
926 !vif
->bss_conf
.assoc
)
929 cmd
->port_id
= data
->port_id
++;
930 memcpy(cmd
->bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
931 len
= roundup(sizeof(*cmd
) + cmd
->count
* ETH_ALEN
, 4);
933 ret
= iwl_mvm_send_cmd_pdu(mvm
, MCAST_FILTER_CMD
, CMD_SYNC
, len
, cmd
);
935 IWL_ERR(mvm
, "mcast filter cmd error. ret=%d\n", ret
);
938 static void iwl_mvm_recalc_multicast(struct iwl_mvm
*mvm
)
940 struct iwl_mvm_mc_iter_data iter_data
= {
944 lockdep_assert_held(&mvm
->mutex
);
946 if (WARN_ON_ONCE(!mvm
->mcast_filter_cmd
))
949 ieee80211_iterate_active_interfaces(
950 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
951 iwl_mvm_mc_iface_iterator
, &iter_data
);
954 static u64
iwl_mvm_prepare_multicast(struct ieee80211_hw
*hw
,
955 struct netdev_hw_addr_list
*mc_list
)
957 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
958 struct iwl_mcast_filter_cmd
*cmd
;
959 struct netdev_hw_addr
*addr
;
960 int addr_count
= netdev_hw_addr_list_count(mc_list
);
961 bool pass_all
= false;
964 if (addr_count
> MAX_MCAST_FILTERING_ADDRESSES
) {
969 len
= roundup(sizeof(*cmd
) + addr_count
* ETH_ALEN
, 4);
970 cmd
= kzalloc(len
, GFP_ATOMIC
);
976 return (u64
)(unsigned long)cmd
;
979 netdev_hw_addr_list_for_each(addr
, mc_list
) {
980 IWL_DEBUG_MAC80211(mvm
, "mcast addr (%d): %pM\n",
981 cmd
->count
, addr
->addr
);
982 memcpy(&cmd
->addr_list
[cmd
->count
* ETH_ALEN
],
983 addr
->addr
, ETH_ALEN
);
987 return (u64
)(unsigned long)cmd
;
990 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
991 unsigned int changed_flags
,
992 unsigned int *total_flags
,
995 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
996 struct iwl_mcast_filter_cmd
*cmd
= (void *)(unsigned long)multicast
;
998 mutex_lock(&mvm
->mutex
);
1000 /* replace previous configuration */
1001 kfree(mvm
->mcast_filter_cmd
);
1002 mvm
->mcast_filter_cmd
= cmd
;
1007 iwl_mvm_recalc_multicast(mvm
);
1009 mutex_unlock(&mvm
->mutex
);
1013 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
1014 struct iwl_bcast_iter_data
{
1015 struct iwl_mvm
*mvm
;
1016 struct iwl_bcast_filter_cmd
*cmd
;
1021 iwl_mvm_set_bcast_filter(struct ieee80211_vif
*vif
,
1022 const struct iwl_fw_bcast_filter
*in_filter
,
1023 struct iwl_fw_bcast_filter
*out_filter
)
1025 struct iwl_fw_bcast_filter_attr
*attr
;
1028 memcpy(out_filter
, in_filter
, sizeof(*out_filter
));
1030 for (i
= 0; i
< ARRAY_SIZE(out_filter
->attrs
); i
++) {
1031 attr
= &out_filter
->attrs
[i
];
1036 switch (attr
->reserved1
) {
1037 case cpu_to_le16(BC_FILTER_MAGIC_IP
):
1038 if (vif
->bss_conf
.arp_addr_cnt
!= 1) {
1043 attr
->val
= vif
->bss_conf
.arp_addr_list
[0];
1045 case cpu_to_le16(BC_FILTER_MAGIC_MAC
):
1046 attr
->val
= *(__be32
*)&vif
->addr
[2];
1051 attr
->reserved1
= 0;
1052 out_filter
->num_attrs
++;
1056 static void iwl_mvm_bcast_filter_iterator(void *_data
, u8
*mac
,
1057 struct ieee80211_vif
*vif
)
1059 struct iwl_bcast_iter_data
*data
= _data
;
1060 struct iwl_mvm
*mvm
= data
->mvm
;
1061 struct iwl_bcast_filter_cmd
*cmd
= data
->cmd
;
1062 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1063 struct iwl_fw_bcast_mac
*bcast_mac
;
1066 if (WARN_ON(mvmvif
->id
>= ARRAY_SIZE(cmd
->macs
)))
1069 bcast_mac
= &cmd
->macs
[mvmvif
->id
];
1071 /* enable filtering only for associated stations */
1072 if (vif
->type
!= NL80211_IFTYPE_STATION
|| !vif
->bss_conf
.assoc
)
1075 bcast_mac
->default_discard
= 1;
1077 /* copy all configured filters */
1078 for (i
= 0; mvm
->bcast_filters
[i
].attrs
[0].mask
; i
++) {
1080 * Make sure we don't exceed our filters limit.
1081 * if there is still a valid filter to be configured,
1082 * be on the safe side and just allow bcast for this mac.
1084 if (WARN_ON_ONCE(data
->current_filter
>=
1085 ARRAY_SIZE(cmd
->filters
))) {
1086 bcast_mac
->default_discard
= 0;
1087 bcast_mac
->attached_filters
= 0;
1091 iwl_mvm_set_bcast_filter(vif
,
1092 &mvm
->bcast_filters
[i
],
1093 &cmd
->filters
[data
->current_filter
]);
1095 /* skip current filter if it contains no attributes */
1096 if (!cmd
->filters
[data
->current_filter
].num_attrs
)
1099 /* attach the filter to current mac */
1100 bcast_mac
->attached_filters
|=
1101 cpu_to_le16(BIT(data
->current_filter
));
1103 data
->current_filter
++;
1107 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm
*mvm
,
1108 struct iwl_bcast_filter_cmd
*cmd
)
1110 struct iwl_bcast_iter_data iter_data
= {
1115 memset(cmd
, 0, sizeof(*cmd
));
1116 cmd
->max_bcast_filters
= ARRAY_SIZE(cmd
->filters
);
1117 cmd
->max_macs
= ARRAY_SIZE(cmd
->macs
);
1119 #ifdef CONFIG_IWLWIFI_DEBUGFS
1120 /* use debugfs filters/macs if override is configured */
1121 if (mvm
->dbgfs_bcast_filtering
.override
) {
1122 memcpy(cmd
->filters
, &mvm
->dbgfs_bcast_filtering
.cmd
.filters
,
1123 sizeof(cmd
->filters
));
1124 memcpy(cmd
->macs
, &mvm
->dbgfs_bcast_filtering
.cmd
.macs
,
1130 /* if no filters are configured, do nothing */
1131 if (!mvm
->bcast_filters
)
1134 /* configure and attach these filters for each associated sta vif */
1135 ieee80211_iterate_active_interfaces(
1136 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1137 iwl_mvm_bcast_filter_iterator
, &iter_data
);
1141 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm
*mvm
,
1142 struct ieee80211_vif
*vif
)
1144 struct iwl_bcast_filter_cmd cmd
;
1146 if (!(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BCAST_FILTERING
))
1149 if (!iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
))
1152 return iwl_mvm_send_cmd_pdu(mvm
, BCAST_FILTER_CMD
, CMD_SYNC
,
1156 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm
*mvm
,
1157 struct ieee80211_vif
*vif
)
1163 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
1164 struct ieee80211_vif
*vif
,
1165 struct ieee80211_bss_conf
*bss_conf
,
1168 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1172 * Re-calculate the tsf id, as the master-slave relations depend on the
1173 * beacon interval, which was not known when the station interface was
1176 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
)
1177 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm
, vif
);
1179 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
1181 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
1183 if (changes
& BSS_CHANGED_ASSOC
) {
1184 if (bss_conf
->assoc
) {
1185 /* add quota for this interface */
1186 ret
= iwl_mvm_update_quotas(mvm
, vif
);
1188 IWL_ERR(mvm
, "failed to update quotas\n");
1192 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
1195 * If we're restarting then the firmware will
1196 * obviously have lost synchronisation with
1197 * the AP. It will attempt to synchronise by
1198 * itself, but we can make it more reliable by
1199 * scheduling a session protection time event.
1201 * The firmware needs to receive a beacon to
1202 * catch up with synchronisation, use 110% of
1203 * the beacon interval.
1205 * Set a large maximum delay to allow for more
1206 * than a single interface.
1208 u32 dur
= (11 * vif
->bss_conf
.beacon_int
) / 10;
1209 iwl_mvm_protect_session(mvm
, vif
, dur
, dur
,
1213 iwl_mvm_sf_update(mvm
, vif
, false);
1214 iwl_mvm_power_vif_assoc(mvm
, vif
);
1216 iwl_mvm_ref(mvm
, IWL_MVM_REF_P2P_CLIENT
);
1217 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
1219 * If update fails - SF might be running in associated
1220 * mode while disassociated - which is forbidden.
1222 WARN_ONCE(iwl_mvm_sf_update(mvm
, vif
, false),
1223 "Failed to update SF upon disassociation\n");
1225 /* remove AP station now that the MAC is unassoc */
1226 ret
= iwl_mvm_rm_sta_id(mvm
, vif
, mvmvif
->ap_sta_id
);
1228 IWL_ERR(mvm
, "failed to remove AP station\n");
1230 if (mvm
->d0i3_ap_sta_id
== mvmvif
->ap_sta_id
)
1231 mvm
->d0i3_ap_sta_id
= IWL_MVM_STATION_COUNT
;
1232 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
1233 /* remove quota for this interface */
1234 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
1236 IWL_ERR(mvm
, "failed to update quotas\n");
1239 iwl_mvm_unref(mvm
, IWL_MVM_REF_P2P_CLIENT
);
1242 iwl_mvm_recalc_multicast(mvm
);
1243 iwl_mvm_configure_bcast_filter(mvm
, vif
);
1245 /* reset rssi values */
1246 mvmvif
->bf_data
.ave_beacon_signal
= 0;
1248 iwl_mvm_bt_coex_vif_change(mvm
);
1249 iwl_mvm_update_smps(mvm
, vif
, IWL_MVM_SMPS_REQ_TT
,
1250 IEEE80211_SMPS_AUTOMATIC
);
1251 } else if (changes
& BSS_CHANGED_BEACON_INFO
) {
1253 * We received a beacon _after_ association so
1254 * remove the session protection.
1256 iwl_mvm_remove_time_event(mvm
, mvmvif
,
1257 &mvmvif
->time_event_data
);
1258 } else if (changes
& (BSS_CHANGED_PS
| BSS_CHANGED_P2P_PS
|
1260 ret
= iwl_mvm_power_update_mac(mvm
, vif
);
1262 IWL_ERR(mvm
, "failed to update power mode\n");
1264 if (changes
& BSS_CHANGED_TXPOWER
) {
1265 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
1267 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
1270 if (changes
& BSS_CHANGED_CQM
) {
1271 IWL_DEBUG_MAC80211(mvm
, "cqm info_changed");
1272 /* reset cqm events tracking */
1273 mvmvif
->bf_data
.last_cqm_event
= 0;
1274 ret
= iwl_mvm_update_beacon_filter(mvm
, vif
, false, CMD_SYNC
);
1276 IWL_ERR(mvm
, "failed to update CQM thresholds\n");
1279 if (changes
& BSS_CHANGED_ARP_FILTER
) {
1280 IWL_DEBUG_MAC80211(mvm
, "arp filter changed");
1281 iwl_mvm_configure_bcast_filter(mvm
, vif
);
1285 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw
*hw
,
1286 struct ieee80211_vif
*vif
)
1288 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1289 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1292 mutex_lock(&mvm
->mutex
);
1294 /* Send the beacon template */
1295 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
1300 * Re-calculate the tsf id, as the master-slave relations depend on the
1301 * beacon interval, which was not known when the AP interface was added.
1303 if (vif
->type
== NL80211_IFTYPE_AP
)
1304 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm
, vif
);
1306 /* Add the mac context */
1307 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
1311 /* Perform the binding */
1312 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1316 /* Send the bcast station. At this stage the TBTT and DTIM time events
1317 * are added and applied to the scheduler */
1318 ret
= iwl_mvm_send_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
1322 /* must be set before quota calculations */
1323 mvmvif
->ap_ibss_active
= true;
1325 /* power updated needs to be done before quotas */
1326 iwl_mvm_power_update_mac(mvm
, vif
);
1328 ret
= iwl_mvm_update_quotas(mvm
, vif
);
1330 goto out_quota_failed
;
1332 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1333 if (vif
->p2p
&& mvm
->p2p_device_vif
)
1334 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
1336 iwl_mvm_ref(mvm
, IWL_MVM_REF_AP_IBSS
);
1338 iwl_mvm_bt_coex_vif_change(mvm
);
1340 mutex_unlock(&mvm
->mutex
);
1344 iwl_mvm_power_update_mac(mvm
, vif
);
1345 mvmvif
->ap_ibss_active
= false;
1346 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
1348 iwl_mvm_binding_remove_vif(mvm
, vif
);
1350 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1352 mutex_unlock(&mvm
->mutex
);
1356 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw
*hw
,
1357 struct ieee80211_vif
*vif
)
1359 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1360 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1362 iwl_mvm_prepare_mac_removal(mvm
, vif
);
1364 mutex_lock(&mvm
->mutex
);
1366 mvmvif
->ap_ibss_active
= false;
1368 iwl_mvm_bt_coex_vif_change(mvm
);
1370 iwl_mvm_unref(mvm
, IWL_MVM_REF_AP_IBSS
);
1372 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1373 if (vif
->p2p
&& mvm
->p2p_device_vif
)
1374 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
1376 iwl_mvm_update_quotas(mvm
, NULL
);
1377 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
1378 iwl_mvm_binding_remove_vif(mvm
, vif
);
1380 iwl_mvm_power_update_mac(mvm
, vif
);
1382 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1384 mutex_unlock(&mvm
->mutex
);
1388 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm
*mvm
,
1389 struct ieee80211_vif
*vif
,
1390 struct ieee80211_bss_conf
*bss_conf
,
1393 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1395 /* Changes will be applied when the AP/IBSS is started */
1396 if (!mvmvif
->ap_ibss_active
)
1399 if (changes
& (BSS_CHANGED_ERP_CTS_PROT
| BSS_CHANGED_HT
|
1400 BSS_CHANGED_BANDWIDTH
) &&
1401 iwl_mvm_mac_ctxt_changed(mvm
, vif
))
1402 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
1404 /* Need to send a new beacon template to the FW */
1405 if (changes
& BSS_CHANGED_BEACON
&&
1406 iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
1407 IWL_WARN(mvm
, "Failed updating beacon data\n");
1410 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
1411 struct ieee80211_vif
*vif
,
1412 struct ieee80211_bss_conf
*bss_conf
,
1415 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1417 mutex_lock(&mvm
->mutex
);
1419 switch (vif
->type
) {
1420 case NL80211_IFTYPE_STATION
:
1421 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
1423 case NL80211_IFTYPE_AP
:
1424 case NL80211_IFTYPE_ADHOC
:
1425 iwl_mvm_bss_info_changed_ap_ibss(mvm
, vif
, bss_conf
, changes
);
1428 /* shouldn't happen */
1432 mutex_unlock(&mvm
->mutex
);
1435 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
1436 struct ieee80211_vif
*vif
,
1437 struct cfg80211_scan_request
*req
)
1439 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1440 struct iwl_notification_wait wait_scan_done
;
1441 static const u8 scan_done_notif
[] = { SCAN_OFFLOAD_COMPLETE
, };
1444 if (req
->n_channels
== 0 || req
->n_channels
> MAX_NUM_SCAN_CHANNELS
)
1447 mutex_lock(&mvm
->mutex
);
1449 switch (mvm
->scan_status
) {
1450 case IWL_MVM_SCAN_SCHED
:
1451 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_scan_done
,
1453 ARRAY_SIZE(scan_done_notif
),
1455 iwl_mvm_sched_scan_stop(mvm
);
1456 ret
= iwl_wait_notification(&mvm
->notif_wait
,
1457 &wait_scan_done
, HZ
);
1462 /* iwl_mvm_rx_scan_offload_complete_notif() will be called
1463 * soon but will not reset the scan status as it won't be
1464 * IWL_MVM_SCAN_SCHED any more since we queue the next scan
1465 * immediately (below)
1468 case IWL_MVM_SCAN_NONE
:
1475 iwl_mvm_ref(mvm
, IWL_MVM_REF_SCAN
);
1477 ret
= iwl_mvm_scan_request(mvm
, vif
, req
);
1479 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
1481 mutex_unlock(&mvm
->mutex
);
1486 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
1487 struct ieee80211_vif
*vif
)
1489 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1491 mutex_lock(&mvm
->mutex
);
1493 iwl_mvm_cancel_scan(mvm
);
1495 mutex_unlock(&mvm
->mutex
);
1499 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
1500 struct ieee80211_sta
*sta
, u16 tids
,
1502 enum ieee80211_frame_release_type reason
,
1505 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1507 /* Called when we need to transmit (a) frame(s) from mac80211 */
1509 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
,
1510 tids
, more_data
, false);
1514 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw
*hw
,
1515 struct ieee80211_sta
*sta
, u16 tids
,
1517 enum ieee80211_frame_release_type reason
,
1520 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1522 /* Called when we need to transmit (a) frame(s) from agg queue */
1524 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
,
1525 tids
, more_data
, true);
1528 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
1529 struct ieee80211_vif
*vif
,
1530 enum sta_notify_cmd cmd
,
1531 struct ieee80211_sta
*sta
)
1533 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1534 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1538 case STA_NOTIFY_SLEEP
:
1539 if (atomic_read(&mvm
->pending_frames
[mvmsta
->sta_id
]) > 0)
1540 ieee80211_sta_block_awake(hw
, sta
, true);
1541 spin_lock_bh(&mvmsta
->lock
);
1542 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++) {
1543 struct iwl_mvm_tid_data
*tid_data
;
1545 tid_data
= &mvmsta
->tid_data
[tid
];
1546 if (tid_data
->state
!= IWL_AGG_ON
&&
1547 tid_data
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
)
1549 if (iwl_mvm_tid_queued(tid_data
) == 0)
1551 ieee80211_sta_set_buffered(sta
, tid
, true);
1553 spin_unlock_bh(&mvmsta
->lock
);
1555 * The fw updates the STA to be asleep. Tx packets on the Tx
1556 * queues to this station will not be transmitted. The fw will
1557 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1560 case STA_NOTIFY_AWAKE
:
1561 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
1563 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
1570 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw
*hw
,
1571 struct ieee80211_vif
*vif
,
1572 struct ieee80211_sta
*sta
)
1574 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1575 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
1578 * This is called before mac80211 does RCU synchronisation,
1579 * so here we already invalidate our internal RCU-protected
1580 * station pointer. The rest of the code will thus no longer
1581 * be able to find the station this way, and we don't rely
1582 * on further RCU synchronisation after the sta_state()
1583 * callback deleted the station.
1585 mutex_lock(&mvm
->mutex
);
1586 if (sta
== rcu_access_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
]))
1587 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
1589 mutex_unlock(&mvm
->mutex
);
1592 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
1593 struct ieee80211_vif
*vif
,
1594 struct ieee80211_sta
*sta
,
1595 enum ieee80211_sta_state old_state
,
1596 enum ieee80211_sta_state new_state
)
1598 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1599 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1602 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
1603 sta
->addr
, old_state
, new_state
);
1605 /* this would be a mac80211 bug ... but don't crash */
1606 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
1609 /* if a STA is being removed, reuse its ID */
1610 flush_work(&mvm
->sta_drained_wk
);
1612 mutex_lock(&mvm
->mutex
);
1613 if (old_state
== IEEE80211_STA_NOTEXIST
&&
1614 new_state
== IEEE80211_STA_NONE
) {
1616 * Firmware bug - it'll crash if the beacon interval is less
1617 * than 16. We can't avoid connecting at all, so refuse the
1618 * station state change, this will cause mac80211 to abandon
1619 * attempts to connect to this AP, and eventually wpa_s will
1620 * blacklist the AP...
1622 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1623 vif
->bss_conf
.beacon_int
< 16) {
1625 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1626 sta
->addr
, vif
->bss_conf
.beacon_int
);
1630 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
1631 } else if (old_state
== IEEE80211_STA_NONE
&&
1632 new_state
== IEEE80211_STA_AUTH
) {
1634 } else if (old_state
== IEEE80211_STA_AUTH
&&
1635 new_state
== IEEE80211_STA_ASSOC
) {
1636 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
1638 iwl_mvm_rs_rate_init(mvm
, sta
,
1639 mvmvif
->phy_ctxt
->channel
->band
,
1641 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1642 new_state
== IEEE80211_STA_AUTHORIZED
) {
1643 /* enable beacon filtering */
1644 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
, CMD_SYNC
));
1646 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
1647 new_state
== IEEE80211_STA_ASSOC
) {
1648 /* disable beacon filtering */
1649 WARN_ON(iwl_mvm_disable_beacon_filter(mvm
, vif
, CMD_SYNC
));
1651 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1652 new_state
== IEEE80211_STA_AUTH
) {
1654 } else if (old_state
== IEEE80211_STA_AUTH
&&
1655 new_state
== IEEE80211_STA_NONE
) {
1657 } else if (old_state
== IEEE80211_STA_NONE
&&
1658 new_state
== IEEE80211_STA_NOTEXIST
) {
1659 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
1664 mutex_unlock(&mvm
->mutex
);
1669 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1671 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1673 mvm
->rts_threshold
= value
;
1678 static void iwl_mvm_sta_rc_update(struct ieee80211_hw
*hw
,
1679 struct ieee80211_vif
*vif
,
1680 struct ieee80211_sta
*sta
, u32 changed
)
1682 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1684 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1685 changed
& IEEE80211_RC_NSS_CHANGED
)
1686 iwl_mvm_sf_update(mvm
, vif
, false);
1689 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
1690 struct ieee80211_vif
*vif
, u16 ac
,
1691 const struct ieee80211_tx_queue_params
*params
)
1693 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1694 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1696 mvmvif
->queue_params
[ac
] = *params
;
1699 * No need to update right away, we'll get BSS_CHANGED_QOS
1700 * The exception is P2P_DEVICE interface which needs immediate update.
1702 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1705 mutex_lock(&mvm
->mutex
);
1706 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
1707 mutex_unlock(&mvm
->mutex
);
1713 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
1714 struct ieee80211_vif
*vif
)
1716 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1717 u32 duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
,
1718 200 + vif
->bss_conf
.beacon_int
);
1719 u32 min_duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
,
1720 100 + vif
->bss_conf
.beacon_int
);
1722 if (WARN_ON_ONCE(vif
->bss_conf
.assoc
))
1725 mutex_lock(&mvm
->mutex
);
1726 /* Try really hard to protect the session and hear a beacon */
1727 iwl_mvm_protect_session(mvm
, vif
, duration
, min_duration
, 500);
1728 mutex_unlock(&mvm
->mutex
);
1731 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw
*hw
,
1732 struct ieee80211_vif
*vif
,
1733 struct cfg80211_sched_scan_request
*req
,
1734 struct ieee80211_sched_scan_ies
*ies
)
1736 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1739 mutex_lock(&mvm
->mutex
);
1741 if (mvm
->scan_status
!= IWL_MVM_SCAN_NONE
) {
1743 "SCHED SCAN request during internal scan - abort\n");
1748 mvm
->scan_status
= IWL_MVM_SCAN_SCHED
;
1750 ret
= iwl_mvm_config_sched_scan(mvm
, vif
, req
, ies
);
1754 ret
= iwl_mvm_config_sched_scan_profiles(mvm
, req
);
1758 ret
= iwl_mvm_sched_scan_start(mvm
, req
);
1762 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
1764 mutex_unlock(&mvm
->mutex
);
1768 static int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw
*hw
,
1769 struct ieee80211_vif
*vif
)
1771 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1773 mutex_lock(&mvm
->mutex
);
1774 iwl_mvm_sched_scan_stop(mvm
);
1775 mutex_unlock(&mvm
->mutex
);
1780 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
1781 enum set_key_cmd cmd
,
1782 struct ieee80211_vif
*vif
,
1783 struct ieee80211_sta
*sta
,
1784 struct ieee80211_key_conf
*key
)
1786 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1789 if (iwlwifi_mod_params
.sw_crypto
) {
1790 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
1794 switch (key
->cipher
) {
1795 case WLAN_CIPHER_SUITE_TKIP
:
1796 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1798 case WLAN_CIPHER_SUITE_CCMP
:
1799 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1801 case WLAN_CIPHER_SUITE_AES_CMAC
:
1802 WARN_ON_ONCE(!(hw
->flags
& IEEE80211_HW_MFP_CAPABLE
));
1804 case WLAN_CIPHER_SUITE_WEP40
:
1805 case WLAN_CIPHER_SUITE_WEP104
:
1807 * Support for TX only, at least for now, so accept
1808 * the key and do nothing else. Then mac80211 will
1809 * pass it for TX but we don't have to use it for RX.
1813 /* currently FW supports only one optional cipher scheme */
1814 if (hw
->n_cipher_schemes
&&
1815 hw
->cipher_schemes
->cipher
== key
->cipher
)
1816 key
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
1821 mutex_lock(&mvm
->mutex
);
1825 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1826 vif
->type
== NL80211_IFTYPE_AP
) && !sta
) {
1828 * GTK on AP interface is a TX-only key, return 0;
1829 * on IBSS they're per-station and because we're lazy
1830 * we don't support them for RX, so do the same.
1833 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1837 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
1838 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, false);
1840 IWL_WARN(mvm
, "set key failed\n");
1842 * can't add key for RX, but we don't need it
1843 * in the device for TX so still return 0
1845 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1851 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
1856 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
1857 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
1863 mutex_unlock(&mvm
->mutex
);
1867 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
1868 struct ieee80211_vif
*vif
,
1869 struct ieee80211_key_conf
*keyconf
,
1870 struct ieee80211_sta
*sta
,
1871 u32 iv32
, u16
*phase1key
)
1873 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1875 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
1878 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
1882 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
1883 struct ieee80211_vif
*vif
,
1884 struct ieee80211_channel
*channel
,
1886 enum ieee80211_roc_type type
)
1888 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1889 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1890 struct cfg80211_chan_def chandef
;
1891 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1894 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
1897 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
) {
1898 IWL_ERR(mvm
, "vif isn't a P2P_DEVICE: %d\n", vif
->type
);
1902 mutex_lock(&mvm
->mutex
);
1904 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
1905 phy_ctxt
= &mvm
->phy_ctxts
[i
];
1906 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
1909 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
1911 * Unbind the P2P_DEVICE from the current PHY context,
1912 * and if the PHY context is not used remove it.
1914 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1915 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1918 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1920 /* Bind the P2P_DEVICE to the current PHY Context */
1921 mvmvif
->phy_ctxt
= phy_ctxt
;
1923 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1924 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1927 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1928 goto schedule_time_event
;
1932 /* Need to update the PHY context only if the ROC channel changed */
1933 if (channel
== mvmvif
->phy_ctxt
->channel
)
1934 goto schedule_time_event
;
1936 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
1939 * Change the PHY context configuration as it is currently referenced
1940 * only by the P2P Device MAC
1942 if (mvmvif
->phy_ctxt
->ref
== 1) {
1943 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
1949 * The PHY context is shared with other MACs. Need to remove the
1950 * P2P Device from the binding, allocate an new PHY context and
1951 * create a new binding
1953 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1959 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
1962 IWL_ERR(mvm
, "Failed to change PHY context\n");
1966 /* Unbind the P2P_DEVICE from the current PHY context */
1967 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1968 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1971 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1973 /* Bind the P2P_DEVICE to the new allocated PHY context */
1974 mvmvif
->phy_ctxt
= phy_ctxt
;
1976 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1977 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1980 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1983 schedule_time_event
:
1984 /* Schedule the time events */
1985 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
1988 mutex_unlock(&mvm
->mutex
);
1989 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1993 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
)
1995 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1997 IWL_DEBUG_MAC80211(mvm
, "enter\n");
1999 mutex_lock(&mvm
->mutex
);
2000 iwl_mvm_stop_p2p_roc(mvm
);
2001 mutex_unlock(&mvm
->mutex
);
2003 IWL_DEBUG_MAC80211(mvm
, "leave\n");
2007 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
2008 struct ieee80211_chanctx_conf
*ctx
)
2010 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2011 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2012 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
2015 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
2017 mutex_lock(&mvm
->mutex
);
2018 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
2024 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->min_def
,
2025 ctx
->rx_chains_static
,
2026 ctx
->rx_chains_dynamic
);
2028 IWL_ERR(mvm
, "Failed to add PHY context\n");
2032 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
2033 *phy_ctxt_id
= phy_ctxt
->id
;
2035 mutex_unlock(&mvm
->mutex
);
2039 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
2040 struct ieee80211_chanctx_conf
*ctx
)
2042 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2043 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2044 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
2046 mutex_lock(&mvm
->mutex
);
2047 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
2048 mutex_unlock(&mvm
->mutex
);
2051 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
2052 struct ieee80211_chanctx_conf
*ctx
,
2055 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2056 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2057 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
2059 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
2060 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
2061 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
2062 IEEE80211_CHANCTX_CHANGE_RADAR
|
2063 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH
)),
2064 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2065 phy_ctxt
->ref
, changed
))
2068 mutex_lock(&mvm
->mutex
);
2069 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->min_def
,
2070 ctx
->rx_chains_static
,
2071 ctx
->rx_chains_dynamic
);
2072 iwl_mvm_bt_coex_vif_change(mvm
);
2073 mutex_unlock(&mvm
->mutex
);
2076 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
2077 struct ieee80211_vif
*vif
,
2078 struct ieee80211_chanctx_conf
*ctx
)
2080 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2081 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2082 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
2083 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2086 mutex_lock(&mvm
->mutex
);
2088 mvmvif
->phy_ctxt
= phy_ctxt
;
2090 switch (vif
->type
) {
2091 case NL80211_IFTYPE_AP
:
2092 case NL80211_IFTYPE_ADHOC
:
2094 * The AP binding flow is handled as part of the start_ap flow
2095 * (in bss_info_changed), similarly for IBSS.
2099 case NL80211_IFTYPE_STATION
:
2100 case NL80211_IFTYPE_MONITOR
:
2107 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
2112 * Power state must be updated before quotas,
2113 * otherwise fw will complain.
2115 iwl_mvm_power_update_mac(mvm
, vif
);
2117 /* Setting the quota at this stage is only required for monitor
2118 * interfaces. For the other types, the bss_info changed flow
2119 * will handle quota settings.
2121 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
2122 mvmvif
->monitor_active
= true;
2123 ret
= iwl_mvm_update_quotas(mvm
, vif
);
2125 goto out_remove_binding
;
2131 iwl_mvm_binding_remove_vif(mvm
, vif
);
2132 iwl_mvm_power_update_mac(mvm
, vif
);
2134 mutex_unlock(&mvm
->mutex
);
2136 mvmvif
->phy_ctxt
= NULL
;
2140 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
2141 struct ieee80211_vif
*vif
,
2142 struct ieee80211_chanctx_conf
*ctx
)
2144 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2145 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2147 mutex_lock(&mvm
->mutex
);
2149 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
2151 switch (vif
->type
) {
2152 case NL80211_IFTYPE_AP
:
2153 case NL80211_IFTYPE_ADHOC
:
2155 case NL80211_IFTYPE_MONITOR
:
2156 mvmvif
->monitor_active
= false;
2157 iwl_mvm_update_quotas(mvm
, NULL
);
2163 iwl_mvm_binding_remove_vif(mvm
, vif
);
2164 iwl_mvm_power_update_mac(mvm
, vif
);
2167 mvmvif
->phy_ctxt
= NULL
;
2168 mutex_unlock(&mvm
->mutex
);
2171 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
2172 struct ieee80211_sta
*sta
,
2175 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2176 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
2178 if (!mvm_sta
|| !mvm_sta
->vif
) {
2179 IWL_ERR(mvm
, "Station is not associated to a vif\n");
2183 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
2186 #ifdef CONFIG_NL80211_TESTMODE
2187 static const struct nla_policy iwl_mvm_tm_policy
[IWL_MVM_TM_ATTR_MAX
+ 1] = {
2188 [IWL_MVM_TM_ATTR_CMD
] = { .type
= NLA_U32
},
2189 [IWL_MVM_TM_ATTR_NOA_DURATION
] = { .type
= NLA_U32
},
2190 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
] = { .type
= NLA_U32
},
2193 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm
*mvm
,
2194 struct ieee80211_vif
*vif
,
2195 void *data
, int len
)
2197 struct nlattr
*tb
[IWL_MVM_TM_ATTR_MAX
+ 1];
2201 err
= nla_parse(tb
, IWL_MVM_TM_ATTR_MAX
, data
, len
, iwl_mvm_tm_policy
);
2205 if (!tb
[IWL_MVM_TM_ATTR_CMD
])
2208 switch (nla_get_u32(tb
[IWL_MVM_TM_ATTR_CMD
])) {
2209 case IWL_MVM_TM_CMD_SET_NOA
:
2210 if (!vif
|| vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
||
2211 !vif
->bss_conf
.enable_beacon
||
2212 !tb
[IWL_MVM_TM_ATTR_NOA_DURATION
])
2215 noa_duration
= nla_get_u32(tb
[IWL_MVM_TM_ATTR_NOA_DURATION
]);
2216 if (noa_duration
>= vif
->bss_conf
.beacon_int
)
2219 mvm
->noa_duration
= noa_duration
;
2222 return iwl_mvm_update_quotas(mvm
, NULL
);
2223 case IWL_MVM_TM_CMD_SET_BEACON_FILTER
:
2224 /* must be associated client vif - ignore authorized */
2225 if (!vif
|| vif
->type
!= NL80211_IFTYPE_STATION
||
2226 !vif
->bss_conf
.assoc
|| !vif
->bss_conf
.dtim_period
||
2227 !tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
])
2230 if (nla_get_u32(tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
]))
2231 return iwl_mvm_enable_beacon_filter(mvm
, vif
,
2233 return iwl_mvm_disable_beacon_filter(mvm
, vif
, CMD_SYNC
);
2239 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw
*hw
,
2240 struct ieee80211_vif
*vif
,
2241 void *data
, int len
)
2243 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2246 mutex_lock(&mvm
->mutex
);
2247 err
= __iwl_mvm_mac_testmode_cmd(mvm
, vif
, data
, len
);
2248 mutex_unlock(&mvm
->mutex
);
2254 const struct ieee80211_ops iwl_mvm_hw_ops
= {
2255 .tx
= iwl_mvm_mac_tx
,
2256 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
2257 .start
= iwl_mvm_mac_start
,
2258 .restart_complete
= iwl_mvm_mac_restart_complete
,
2259 .stop
= iwl_mvm_mac_stop
,
2260 .add_interface
= iwl_mvm_mac_add_interface
,
2261 .remove_interface
= iwl_mvm_mac_remove_interface
,
2262 .config
= iwl_mvm_mac_config
,
2263 .prepare_multicast
= iwl_mvm_prepare_multicast
,
2264 .configure_filter
= iwl_mvm_configure_filter
,
2265 .bss_info_changed
= iwl_mvm_bss_info_changed
,
2266 .hw_scan
= iwl_mvm_mac_hw_scan
,
2267 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
2268 .sta_pre_rcu_remove
= iwl_mvm_sta_pre_rcu_remove
,
2269 .sta_state
= iwl_mvm_mac_sta_state
,
2270 .sta_notify
= iwl_mvm_mac_sta_notify
,
2271 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
2272 .release_buffered_frames
= iwl_mvm_mac_release_buffered_frames
,
2273 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
2274 .sta_rc_update
= iwl_mvm_sta_rc_update
,
2275 .conf_tx
= iwl_mvm_mac_conf_tx
,
2276 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
2277 .sched_scan_start
= iwl_mvm_mac_sched_scan_start
,
2278 .sched_scan_stop
= iwl_mvm_mac_sched_scan_stop
,
2279 .set_key
= iwl_mvm_mac_set_key
,
2280 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
2281 .remain_on_channel
= iwl_mvm_roc
,
2282 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
2283 .add_chanctx
= iwl_mvm_add_chanctx
,
2284 .remove_chanctx
= iwl_mvm_remove_chanctx
,
2285 .change_chanctx
= iwl_mvm_change_chanctx
,
2286 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
2287 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
2289 .start_ap
= iwl_mvm_start_ap_ibss
,
2290 .stop_ap
= iwl_mvm_stop_ap_ibss
,
2291 .join_ibss
= iwl_mvm_start_ap_ibss
,
2292 .leave_ibss
= iwl_mvm_stop_ap_ibss
,
2294 .set_tim
= iwl_mvm_set_tim
,
2296 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd
)
2298 #ifdef CONFIG_PM_SLEEP
2300 .suspend
= iwl_mvm_suspend
,
2301 .resume
= iwl_mvm_resume
,
2302 .set_wakeup
= iwl_mvm_set_wakeup
,
2303 .set_rekey_data
= iwl_mvm_set_rekey_data
,
2304 #if IS_ENABLED(CONFIG_IPV6)
2305 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
2307 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,