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 (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 int iwl_mvm_mac_ampdu_action(struct ieee80211_hw
*hw
,
467 struct ieee80211_vif
*vif
,
468 enum ieee80211_ampdu_mlme_action action
,
469 struct ieee80211_sta
*sta
, u16 tid
,
470 u16
*ssn
, u8 buf_size
)
472 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
475 IWL_DEBUG_HT(mvm
, "A-MPDU action on addr %pM tid %d: action %d\n",
476 sta
->addr
, tid
, action
);
478 if (!(mvm
->nvm_data
->sku_cap_11n_enable
))
481 mutex_lock(&mvm
->mutex
);
484 case IEEE80211_AMPDU_RX_START
:
485 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_RXAGG
) {
489 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, *ssn
, true);
491 case IEEE80211_AMPDU_RX_STOP
:
492 ret
= iwl_mvm_sta_rx_agg(mvm
, sta
, tid
, 0, false);
494 case IEEE80211_AMPDU_TX_START
:
495 if (iwlwifi_mod_params
.disable_11n
& IWL_DISABLE_HT_TXAGG
) {
499 ret
= iwl_mvm_sta_tx_agg_start(mvm
, vif
, sta
, tid
, ssn
);
501 case IEEE80211_AMPDU_TX_STOP_CONT
:
502 ret
= iwl_mvm_sta_tx_agg_stop(mvm
, vif
, sta
, tid
);
504 case IEEE80211_AMPDU_TX_STOP_FLUSH
:
505 case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT
:
506 ret
= iwl_mvm_sta_tx_agg_flush(mvm
, vif
, sta
, tid
);
508 case IEEE80211_AMPDU_TX_OPERATIONAL
:
509 ret
= iwl_mvm_sta_tx_agg_oper(mvm
, vif
, sta
, tid
, buf_size
);
516 mutex_unlock(&mvm
->mutex
);
521 static void iwl_mvm_cleanup_iterator(void *data
, u8
*mac
,
522 struct ieee80211_vif
*vif
)
524 struct iwl_mvm
*mvm
= data
;
525 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
527 mvmvif
->uploaded
= false;
528 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
530 /* does this make sense at all? */
533 spin_lock_bh(&mvm
->time_event_lock
);
534 iwl_mvm_te_clear_data(mvm
, &mvmvif
->time_event_data
);
535 spin_unlock_bh(&mvm
->time_event_lock
);
537 mvmvif
->phy_ctxt
= NULL
;
540 static void iwl_mvm_restart_cleanup(struct iwl_mvm
*mvm
)
542 iwl_trans_stop_device(mvm
->trans
);
544 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
546 /* just in case one was running */
547 ieee80211_remain_on_channel_expired(mvm
->hw
);
549 ieee80211_iterate_active_interfaces_atomic(
550 mvm
->hw
, IEEE80211_IFACE_ITER_RESUME_ALL
,
551 iwl_mvm_cleanup_iterator
, mvm
);
553 mvm
->p2p_device_vif
= NULL
;
554 mvm
->d0i3_ap_sta_id
= IWL_MVM_STATION_COUNT
;
556 iwl_mvm_reset_phy_ctxts(mvm
);
557 memset(mvm
->fw_key_table
, 0, sizeof(mvm
->fw_key_table
));
558 memset(mvm
->sta_drained
, 0, sizeof(mvm
->sta_drained
));
560 ieee80211_wake_queues(mvm
->hw
);
562 /* cleanup all stale references (scan, roc), but keep the
563 * ucode_down ref until reconfig is complete */
564 iwl_mvm_unref_all_except(mvm
, IWL_MVM_REF_UCODE_DOWN
);
567 mvm
->rx_ba_sessions
= 0;
570 static int iwl_mvm_mac_start(struct ieee80211_hw
*hw
)
572 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
575 mutex_lock(&mvm
->mutex
);
577 /* Clean up some internal and mac80211 state on restart */
578 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
))
579 iwl_mvm_restart_cleanup(mvm
);
581 ret
= iwl_mvm_up(mvm
);
582 mutex_unlock(&mvm
->mutex
);
587 static void iwl_mvm_mac_restart_complete(struct ieee80211_hw
*hw
)
589 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
592 mutex_lock(&mvm
->mutex
);
594 clear_bit(IWL_MVM_STATUS_IN_HW_RESTART
, &mvm
->status
);
595 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
597 IWL_ERR(mvm
, "Failed to update quotas after restart (%d)\n",
600 /* allow transport/FW low power modes */
601 iwl_mvm_unref(mvm
, IWL_MVM_REF_UCODE_DOWN
);
603 mutex_unlock(&mvm
->mutex
);
606 static void iwl_mvm_mac_stop(struct ieee80211_hw
*hw
)
608 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
610 flush_work(&mvm
->d0i3_exit_work
);
611 flush_work(&mvm
->async_handlers_wk
);
613 mutex_lock(&mvm
->mutex
);
615 /* disallow low power states when the FW is down */
616 iwl_mvm_ref(mvm
, IWL_MVM_REF_UCODE_DOWN
);
618 /* async_handlers_wk is now blocked */
621 * The work item could be running or queued if the
622 * ROC time event stops just as we get here.
624 cancel_work_sync(&mvm
->roc_done_wk
);
626 iwl_trans_stop_device(mvm
->trans
);
628 iwl_mvm_async_handlers_purge(mvm
);
629 /* async_handlers_list is empty and will stay empty: HW is stopped */
631 /* the fw is stopped, the aux sta is dead: clean up driver state */
632 iwl_mvm_dealloc_int_sta(mvm
, &mvm
->aux_sta
);
634 mutex_unlock(&mvm
->mutex
);
637 * The worker might have been waiting for the mutex, let it run and
638 * discover that its list is now empty.
640 cancel_work_sync(&mvm
->async_handlers_wk
);
643 static struct iwl_mvm_phy_ctxt
*iwl_mvm_get_free_phy_ctxt(struct iwl_mvm
*mvm
)
647 lockdep_assert_held(&mvm
->mutex
);
649 for (i
= 0; i
< NUM_PHY_CTX
; i
++)
650 if (!mvm
->phy_ctxts
[i
].ref
)
651 return &mvm
->phy_ctxts
[i
];
653 IWL_ERR(mvm
, "No available PHY context\n");
657 static int iwl_mvm_set_tx_power(struct iwl_mvm
*mvm
, struct ieee80211_vif
*vif
,
660 /* FW is in charge of regulatory enforcement */
661 struct iwl_reduce_tx_power_cmd reduce_txpwr_cmd
= {
662 .mac_context_id
= iwl_mvm_vif_from_mac80211(vif
)->id
,
663 .pwr_restriction
= cpu_to_le16(tx_power
),
666 return iwl_mvm_send_cmd_pdu(mvm
, REDUCE_TX_POWER_CMD
, CMD_SYNC
,
667 sizeof(reduce_txpwr_cmd
),
671 static int iwl_mvm_mac_add_interface(struct ieee80211_hw
*hw
,
672 struct ieee80211_vif
*vif
)
674 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
675 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
679 * Not much to do here. The stack will not allow interface
680 * types or combinations that we didn't advertise, so we
681 * don't really have to check the types.
684 mutex_lock(&mvm
->mutex
);
686 /* Allocate resources for the MAC context, and add it to the fw */
687 ret
= iwl_mvm_mac_ctxt_init(mvm
, vif
);
691 /* Counting number of interfaces is needed for legacy PM */
692 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
696 * The AP binding flow can be done only after the beacon
697 * template is configured (which happens only in the mac80211
698 * start_ap() flow), and adding the broadcast station can happen
699 * only after the binding.
700 * In addition, since modifying the MAC before adding a bcast
701 * station is not allowed by the FW, delay the adding of MAC context to
702 * the point where we can also add the bcast station.
703 * In short: there's not much we can do at this point, other than
704 * allocating resources :)
706 if (vif
->type
== NL80211_IFTYPE_AP
||
707 vif
->type
== NL80211_IFTYPE_ADHOC
) {
708 u32 qmask
= iwl_mvm_mac_get_queues_mask(mvm
, vif
);
709 ret
= iwl_mvm_allocate_int_sta(mvm
, &mvmvif
->bcast_sta
,
711 ieee80211_vif_type_p2p(vif
));
713 IWL_ERR(mvm
, "Failed to allocate bcast sta\n");
717 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
721 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
725 ret
= iwl_mvm_power_update_mac(mvm
, vif
);
729 /* beacon filtering */
730 ret
= iwl_mvm_disable_beacon_filter(mvm
, vif
, CMD_SYNC
);
734 if (!mvm
->bf_allowed_vif
&&
735 vif
->type
== NL80211_IFTYPE_STATION
&& !vif
->p2p
&&
736 mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BF_UPDATED
){
737 mvm
->bf_allowed_vif
= mvmvif
;
738 vif
->driver_flags
|= IEEE80211_VIF_BEACON_FILTER
|
739 IEEE80211_VIF_SUPPORTS_CQM_RSSI
;
743 * P2P_DEVICE interface does not have a channel context assigned to it,
744 * so a dedicated PHY context is allocated to it and the corresponding
745 * MAC context is bound to it at this stage.
747 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
749 mvmvif
->phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
750 if (!mvmvif
->phy_ctxt
) {
755 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
756 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
760 ret
= iwl_mvm_add_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
764 /* Save a pointer to p2p device vif, so it can later be used to
765 * update the p2p device MAC when a GO is started/stopped */
766 mvm
->p2p_device_vif
= vif
;
769 iwl_mvm_vif_dbgfs_register(mvm
, vif
);
773 iwl_mvm_binding_remove_vif(mvm
, vif
);
775 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
777 if (mvm
->bf_allowed_vif
== mvmvif
) {
778 mvm
->bf_allowed_vif
= NULL
;
779 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
780 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
783 mvmvif
->phy_ctxt
= NULL
;
784 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
786 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
789 iwl_mvm_mac_ctxt_release(mvm
, vif
);
791 mutex_unlock(&mvm
->mutex
);
796 static void iwl_mvm_prepare_mac_removal(struct iwl_mvm
*mvm
,
797 struct ieee80211_vif
*vif
)
801 for (ac
= 0; ac
< IEEE80211_NUM_ACS
; ac
++)
802 if (vif
->hw_queue
[ac
] != IEEE80211_INVAL_HW_QUEUE
)
803 tfd_msk
|= BIT(vif
->hw_queue
[ac
]);
805 if (vif
->cab_queue
!= IEEE80211_INVAL_HW_QUEUE
)
806 tfd_msk
|= BIT(vif
->cab_queue
);
809 mutex_lock(&mvm
->mutex
);
810 iwl_mvm_flush_tx_path(mvm
, tfd_msk
, true);
811 mutex_unlock(&mvm
->mutex
);
814 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
816 * Flush the ROC worker which will flush the OFFCHANNEL queue.
817 * We assume here that all the packets sent to the OFFCHANNEL
818 * queue are sent in ROC session.
820 flush_work(&mvm
->roc_done_wk
);
823 * By now, all the AC queues are empty. The AGG queues are
824 * empty too. We already got all the Tx responses for all the
825 * packets in the queues. The drain work can have been
826 * triggered. Flush it.
828 flush_work(&mvm
->sta_drained_wk
);
832 static void iwl_mvm_mac_remove_interface(struct ieee80211_hw
*hw
,
833 struct ieee80211_vif
*vif
)
835 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
836 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
838 iwl_mvm_prepare_mac_removal(mvm
, vif
);
840 mutex_lock(&mvm
->mutex
);
842 if (mvm
->bf_allowed_vif
== mvmvif
) {
843 mvm
->bf_allowed_vif
= NULL
;
844 vif
->driver_flags
&= ~(IEEE80211_VIF_BEACON_FILTER
|
845 IEEE80211_VIF_SUPPORTS_CQM_RSSI
);
848 iwl_mvm_vif_dbgfs_clean(mvm
, vif
);
851 * For AP/GO interface, the tear down of the resources allocated to the
852 * interface is be handled as part of the stop_ap flow.
854 if (vif
->type
== NL80211_IFTYPE_AP
||
855 vif
->type
== NL80211_IFTYPE_ADHOC
) {
856 #ifdef CONFIG_NL80211_TESTMODE
857 if (vif
== mvm
->noa_vif
) {
859 mvm
->noa_duration
= 0;
862 iwl_mvm_dealloc_int_sta(mvm
, &mvmvif
->bcast_sta
);
866 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
867 mvm
->p2p_device_vif
= NULL
;
868 iwl_mvm_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
869 iwl_mvm_binding_remove_vif(mvm
, vif
);
870 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
871 mvmvif
->phy_ctxt
= NULL
;
874 if (mvm
->vif_count
&& vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
)
877 iwl_mvm_power_update_mac(mvm
, vif
);
878 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
881 iwl_mvm_mac_ctxt_release(mvm
, vif
);
882 mutex_unlock(&mvm
->mutex
);
885 static int iwl_mvm_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
890 struct iwl_mvm_mc_iter_data
{
895 static void iwl_mvm_mc_iface_iterator(void *_data
, u8
*mac
,
896 struct ieee80211_vif
*vif
)
898 struct iwl_mvm_mc_iter_data
*data
= _data
;
899 struct iwl_mvm
*mvm
= data
->mvm
;
900 struct iwl_mcast_filter_cmd
*cmd
= mvm
->mcast_filter_cmd
;
903 /* if we don't have free ports, mcast frames will be dropped */
904 if (WARN_ON_ONCE(data
->port_id
>= MAX_PORT_ID_NUM
))
907 if (vif
->type
!= NL80211_IFTYPE_STATION
||
908 !vif
->bss_conf
.assoc
)
911 cmd
->port_id
= data
->port_id
++;
912 memcpy(cmd
->bssid
, vif
->bss_conf
.bssid
, ETH_ALEN
);
913 len
= roundup(sizeof(*cmd
) + cmd
->count
* ETH_ALEN
, 4);
915 ret
= iwl_mvm_send_cmd_pdu(mvm
, MCAST_FILTER_CMD
, CMD_SYNC
, len
, cmd
);
917 IWL_ERR(mvm
, "mcast filter cmd error. ret=%d\n", ret
);
920 static void iwl_mvm_recalc_multicast(struct iwl_mvm
*mvm
)
922 struct iwl_mvm_mc_iter_data iter_data
= {
926 lockdep_assert_held(&mvm
->mutex
);
928 if (WARN_ON_ONCE(!mvm
->mcast_filter_cmd
))
931 ieee80211_iterate_active_interfaces(
932 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
933 iwl_mvm_mc_iface_iterator
, &iter_data
);
936 static u64
iwl_mvm_prepare_multicast(struct ieee80211_hw
*hw
,
937 struct netdev_hw_addr_list
*mc_list
)
939 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
940 struct iwl_mcast_filter_cmd
*cmd
;
941 struct netdev_hw_addr
*addr
;
942 int addr_count
= netdev_hw_addr_list_count(mc_list
);
943 bool pass_all
= false;
946 if (addr_count
> MAX_MCAST_FILTERING_ADDRESSES
) {
951 len
= roundup(sizeof(*cmd
) + addr_count
* ETH_ALEN
, 4);
952 cmd
= kzalloc(len
, GFP_ATOMIC
);
958 return (u64
)(unsigned long)cmd
;
961 netdev_hw_addr_list_for_each(addr
, mc_list
) {
962 IWL_DEBUG_MAC80211(mvm
, "mcast addr (%d): %pM\n",
963 cmd
->count
, addr
->addr
);
964 memcpy(&cmd
->addr_list
[cmd
->count
* ETH_ALEN
],
965 addr
->addr
, ETH_ALEN
);
969 return (u64
)(unsigned long)cmd
;
972 static void iwl_mvm_configure_filter(struct ieee80211_hw
*hw
,
973 unsigned int changed_flags
,
974 unsigned int *total_flags
,
977 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
978 struct iwl_mcast_filter_cmd
*cmd
= (void *)(unsigned long)multicast
;
980 mutex_lock(&mvm
->mutex
);
982 /* replace previous configuration */
983 kfree(mvm
->mcast_filter_cmd
);
984 mvm
->mcast_filter_cmd
= cmd
;
989 iwl_mvm_recalc_multicast(mvm
);
991 mutex_unlock(&mvm
->mutex
);
995 #ifdef CONFIG_IWLWIFI_BCAST_FILTERING
996 struct iwl_bcast_iter_data
{
998 struct iwl_bcast_filter_cmd
*cmd
;
1003 iwl_mvm_set_bcast_filter(struct ieee80211_vif
*vif
,
1004 const struct iwl_fw_bcast_filter
*in_filter
,
1005 struct iwl_fw_bcast_filter
*out_filter
)
1007 struct iwl_fw_bcast_filter_attr
*attr
;
1010 memcpy(out_filter
, in_filter
, sizeof(*out_filter
));
1012 for (i
= 0; i
< ARRAY_SIZE(out_filter
->attrs
); i
++) {
1013 attr
= &out_filter
->attrs
[i
];
1018 switch (attr
->reserved1
) {
1019 case cpu_to_le16(BC_FILTER_MAGIC_IP
):
1020 if (vif
->bss_conf
.arp_addr_cnt
!= 1) {
1025 attr
->val
= vif
->bss_conf
.arp_addr_list
[0];
1027 case cpu_to_le16(BC_FILTER_MAGIC_MAC
):
1028 attr
->val
= *(__be32
*)&vif
->addr
[2];
1033 attr
->reserved1
= 0;
1034 out_filter
->num_attrs
++;
1038 static void iwl_mvm_bcast_filter_iterator(void *_data
, u8
*mac
,
1039 struct ieee80211_vif
*vif
)
1041 struct iwl_bcast_iter_data
*data
= _data
;
1042 struct iwl_mvm
*mvm
= data
->mvm
;
1043 struct iwl_bcast_filter_cmd
*cmd
= data
->cmd
;
1044 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1045 struct iwl_fw_bcast_mac
*bcast_mac
;
1048 if (WARN_ON(mvmvif
->id
>= ARRAY_SIZE(cmd
->macs
)))
1051 bcast_mac
= &cmd
->macs
[mvmvif
->id
];
1053 /* enable filtering only for associated stations */
1054 if (vif
->type
!= NL80211_IFTYPE_STATION
|| !vif
->bss_conf
.assoc
)
1057 bcast_mac
->default_discard
= 1;
1059 /* copy all configured filters */
1060 for (i
= 0; mvm
->bcast_filters
[i
].attrs
[0].mask
; i
++) {
1062 * Make sure we don't exceed our filters limit.
1063 * if there is still a valid filter to be configured,
1064 * be on the safe side and just allow bcast for this mac.
1066 if (WARN_ON_ONCE(data
->current_filter
>=
1067 ARRAY_SIZE(cmd
->filters
))) {
1068 bcast_mac
->default_discard
= 0;
1069 bcast_mac
->attached_filters
= 0;
1073 iwl_mvm_set_bcast_filter(vif
,
1074 &mvm
->bcast_filters
[i
],
1075 &cmd
->filters
[data
->current_filter
]);
1077 /* skip current filter if it contains no attributes */
1078 if (!cmd
->filters
[data
->current_filter
].num_attrs
)
1081 /* attach the filter to current mac */
1082 bcast_mac
->attached_filters
|=
1083 cpu_to_le16(BIT(data
->current_filter
));
1085 data
->current_filter
++;
1089 bool iwl_mvm_bcast_filter_build_cmd(struct iwl_mvm
*mvm
,
1090 struct iwl_bcast_filter_cmd
*cmd
)
1092 struct iwl_bcast_iter_data iter_data
= {
1097 memset(cmd
, 0, sizeof(*cmd
));
1098 cmd
->max_bcast_filters
= ARRAY_SIZE(cmd
->filters
);
1099 cmd
->max_macs
= ARRAY_SIZE(cmd
->macs
);
1101 #ifdef CONFIG_IWLWIFI_DEBUGFS
1102 /* use debugfs filters/macs if override is configured */
1103 if (mvm
->dbgfs_bcast_filtering
.override
) {
1104 memcpy(cmd
->filters
, &mvm
->dbgfs_bcast_filtering
.cmd
.filters
,
1105 sizeof(cmd
->filters
));
1106 memcpy(cmd
->macs
, &mvm
->dbgfs_bcast_filtering
.cmd
.macs
,
1112 /* if no filters are configured, do nothing */
1113 if (!mvm
->bcast_filters
)
1116 /* configure and attach these filters for each associated sta vif */
1117 ieee80211_iterate_active_interfaces(
1118 mvm
->hw
, IEEE80211_IFACE_ITER_NORMAL
,
1119 iwl_mvm_bcast_filter_iterator
, &iter_data
);
1123 static int iwl_mvm_configure_bcast_filter(struct iwl_mvm
*mvm
,
1124 struct ieee80211_vif
*vif
)
1126 struct iwl_bcast_filter_cmd cmd
;
1128 if (!(mvm
->fw
->ucode_capa
.flags
& IWL_UCODE_TLV_FLAGS_BCAST_FILTERING
))
1131 if (!iwl_mvm_bcast_filter_build_cmd(mvm
, &cmd
))
1134 return iwl_mvm_send_cmd_pdu(mvm
, BCAST_FILTER_CMD
, CMD_SYNC
,
1138 static inline int iwl_mvm_configure_bcast_filter(struct iwl_mvm
*mvm
,
1139 struct ieee80211_vif
*vif
)
1145 static void iwl_mvm_bss_info_changed_station(struct iwl_mvm
*mvm
,
1146 struct ieee80211_vif
*vif
,
1147 struct ieee80211_bss_conf
*bss_conf
,
1150 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1154 * Re-calculate the tsf id, as the master-slave relations depend on the
1155 * beacon interval, which was not known when the station interface was
1158 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
)
1159 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm
, vif
);
1161 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
1163 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
1165 if (changes
& BSS_CHANGED_ASSOC
) {
1166 if (bss_conf
->assoc
) {
1167 /* add quota for this interface */
1168 ret
= iwl_mvm_update_quotas(mvm
, vif
);
1170 IWL_ERR(mvm
, "failed to update quotas\n");
1174 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART
,
1177 * If we're restarting then the firmware will
1178 * obviously have lost synchronisation with
1179 * the AP. It will attempt to synchronise by
1180 * itself, but we can make it more reliable by
1181 * scheduling a session protection time event.
1183 * The firmware needs to receive a beacon to
1184 * catch up with synchronisation, use 110% of
1185 * the beacon interval.
1187 * Set a large maximum delay to allow for more
1188 * than a single interface.
1190 u32 dur
= (11 * vif
->bss_conf
.beacon_int
) / 10;
1191 iwl_mvm_protect_session(mvm
, vif
, dur
, dur
,
1195 iwl_mvm_sf_update(mvm
, vif
, false);
1196 iwl_mvm_power_vif_assoc(mvm
, vif
);
1198 iwl_mvm_ref(mvm
, IWL_MVM_REF_P2P_CLIENT
);
1199 } else if (mvmvif
->ap_sta_id
!= IWL_MVM_STATION_COUNT
) {
1201 * If update fails - SF might be running in associated
1202 * mode while disassociated - which is forbidden.
1204 WARN_ONCE(iwl_mvm_sf_update(mvm
, vif
, false),
1205 "Failed to update SF upon disassociation\n");
1207 /* remove AP station now that the MAC is unassoc */
1208 ret
= iwl_mvm_rm_sta_id(mvm
, vif
, mvmvif
->ap_sta_id
);
1210 IWL_ERR(mvm
, "failed to remove AP station\n");
1212 if (mvm
->d0i3_ap_sta_id
== mvmvif
->ap_sta_id
)
1213 mvm
->d0i3_ap_sta_id
= IWL_MVM_STATION_COUNT
;
1214 mvmvif
->ap_sta_id
= IWL_MVM_STATION_COUNT
;
1215 /* remove quota for this interface */
1216 ret
= iwl_mvm_update_quotas(mvm
, NULL
);
1218 IWL_ERR(mvm
, "failed to update quotas\n");
1221 iwl_mvm_unref(mvm
, IWL_MVM_REF_P2P_CLIENT
);
1224 iwl_mvm_recalc_multicast(mvm
);
1225 iwl_mvm_configure_bcast_filter(mvm
, vif
);
1227 /* reset rssi values */
1228 mvmvif
->bf_data
.ave_beacon_signal
= 0;
1230 iwl_mvm_bt_coex_vif_change(mvm
);
1231 iwl_mvm_update_smps(mvm
, vif
, IWL_MVM_SMPS_REQ_TT
,
1232 IEEE80211_SMPS_AUTOMATIC
);
1233 } else if (changes
& BSS_CHANGED_BEACON_INFO
) {
1235 * We received a beacon _after_ association so
1236 * remove the session protection.
1238 iwl_mvm_remove_time_event(mvm
, mvmvif
,
1239 &mvmvif
->time_event_data
);
1240 } else if (changes
& (BSS_CHANGED_PS
| BSS_CHANGED_P2P_PS
|
1242 ret
= iwl_mvm_power_update_mac(mvm
, vif
);
1244 IWL_ERR(mvm
, "failed to update power mode\n");
1246 if (changes
& BSS_CHANGED_TXPOWER
) {
1247 IWL_DEBUG_CALIB(mvm
, "Changing TX Power to %d\n",
1249 iwl_mvm_set_tx_power(mvm
, vif
, bss_conf
->txpower
);
1252 if (changes
& BSS_CHANGED_CQM
) {
1253 IWL_DEBUG_MAC80211(mvm
, "cqm info_changed");
1254 /* reset cqm events tracking */
1255 mvmvif
->bf_data
.last_cqm_event
= 0;
1256 ret
= iwl_mvm_update_beacon_filter(mvm
, vif
, false, CMD_SYNC
);
1258 IWL_ERR(mvm
, "failed to update CQM thresholds\n");
1261 if (changes
& BSS_CHANGED_ARP_FILTER
) {
1262 IWL_DEBUG_MAC80211(mvm
, "arp filter changed");
1263 iwl_mvm_configure_bcast_filter(mvm
, vif
);
1267 static int iwl_mvm_start_ap_ibss(struct ieee80211_hw
*hw
,
1268 struct ieee80211_vif
*vif
)
1270 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1271 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1274 mutex_lock(&mvm
->mutex
);
1276 /* Send the beacon template */
1277 ret
= iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
);
1282 * Re-calculate the tsf id, as the master-slave relations depend on the
1283 * beacon interval, which was not known when the AP interface was added.
1285 if (vif
->type
== NL80211_IFTYPE_AP
)
1286 iwl_mvm_mac_ctxt_recalc_tsf_id(mvm
, vif
);
1288 /* Add the mac context */
1289 ret
= iwl_mvm_mac_ctxt_add(mvm
, vif
);
1293 /* Perform the binding */
1294 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1298 /* Send the bcast station. At this stage the TBTT and DTIM time events
1299 * are added and applied to the scheduler */
1300 ret
= iwl_mvm_send_bcast_sta(mvm
, vif
, &mvmvif
->bcast_sta
);
1304 /* must be set before quota calculations */
1305 mvmvif
->ap_ibss_active
= true;
1307 /* power updated needs to be done before quotas */
1308 iwl_mvm_power_update_mac(mvm
, vif
);
1310 ret
= iwl_mvm_update_quotas(mvm
, vif
);
1312 goto out_quota_failed
;
1314 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1315 if (vif
->p2p
&& mvm
->p2p_device_vif
)
1316 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
1318 iwl_mvm_ref(mvm
, IWL_MVM_REF_AP_IBSS
);
1320 iwl_mvm_bt_coex_vif_change(mvm
);
1322 mutex_unlock(&mvm
->mutex
);
1326 iwl_mvm_power_update_mac(mvm
, vif
);
1327 mvmvif
->ap_ibss_active
= false;
1328 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
1330 iwl_mvm_binding_remove_vif(mvm
, vif
);
1332 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1334 mutex_unlock(&mvm
->mutex
);
1338 static void iwl_mvm_stop_ap_ibss(struct ieee80211_hw
*hw
,
1339 struct ieee80211_vif
*vif
)
1341 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1342 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1344 iwl_mvm_prepare_mac_removal(mvm
, vif
);
1346 mutex_lock(&mvm
->mutex
);
1348 mvmvif
->ap_ibss_active
= false;
1350 iwl_mvm_bt_coex_vif_change(mvm
);
1352 iwl_mvm_unref(mvm
, IWL_MVM_REF_AP_IBSS
);
1354 /* Need to update the P2P Device MAC (only GO, IBSS is single vif) */
1355 if (vif
->p2p
&& mvm
->p2p_device_vif
)
1356 iwl_mvm_mac_ctxt_changed(mvm
, mvm
->p2p_device_vif
);
1358 iwl_mvm_update_quotas(mvm
, NULL
);
1359 iwl_mvm_send_rm_bcast_sta(mvm
, &mvmvif
->bcast_sta
);
1360 iwl_mvm_binding_remove_vif(mvm
, vif
);
1362 iwl_mvm_power_update_mac(mvm
, vif
);
1364 iwl_mvm_mac_ctxt_remove(mvm
, vif
);
1366 mutex_unlock(&mvm
->mutex
);
1370 iwl_mvm_bss_info_changed_ap_ibss(struct iwl_mvm
*mvm
,
1371 struct ieee80211_vif
*vif
,
1372 struct ieee80211_bss_conf
*bss_conf
,
1375 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1377 /* Changes will be applied when the AP/IBSS is started */
1378 if (!mvmvif
->ap_ibss_active
)
1381 if (changes
& (BSS_CHANGED_ERP_CTS_PROT
| BSS_CHANGED_HT
|
1382 BSS_CHANGED_BANDWIDTH
) &&
1383 iwl_mvm_mac_ctxt_changed(mvm
, vif
))
1384 IWL_ERR(mvm
, "failed to update MAC %pM\n", vif
->addr
);
1386 /* Need to send a new beacon template to the FW */
1387 if (changes
& BSS_CHANGED_BEACON
&&
1388 iwl_mvm_mac_ctxt_beacon_changed(mvm
, vif
))
1389 IWL_WARN(mvm
, "Failed updating beacon data\n");
1392 static void iwl_mvm_bss_info_changed(struct ieee80211_hw
*hw
,
1393 struct ieee80211_vif
*vif
,
1394 struct ieee80211_bss_conf
*bss_conf
,
1397 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1399 mutex_lock(&mvm
->mutex
);
1401 switch (vif
->type
) {
1402 case NL80211_IFTYPE_STATION
:
1403 iwl_mvm_bss_info_changed_station(mvm
, vif
, bss_conf
, changes
);
1405 case NL80211_IFTYPE_AP
:
1406 case NL80211_IFTYPE_ADHOC
:
1407 iwl_mvm_bss_info_changed_ap_ibss(mvm
, vif
, bss_conf
, changes
);
1410 /* shouldn't happen */
1414 mutex_unlock(&mvm
->mutex
);
1417 static int iwl_mvm_mac_hw_scan(struct ieee80211_hw
*hw
,
1418 struct ieee80211_vif
*vif
,
1419 struct cfg80211_scan_request
*req
)
1421 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1422 struct iwl_notification_wait wait_scan_done
;
1423 static const u8 scan_done_notif
[] = { SCAN_OFFLOAD_COMPLETE
, };
1426 if (req
->n_channels
== 0 || req
->n_channels
> MAX_NUM_SCAN_CHANNELS
)
1429 mutex_lock(&mvm
->mutex
);
1431 switch (mvm
->scan_status
) {
1432 case IWL_MVM_SCAN_SCHED
:
1433 iwl_init_notification_wait(&mvm
->notif_wait
, &wait_scan_done
,
1435 ARRAY_SIZE(scan_done_notif
),
1437 iwl_mvm_sched_scan_stop(mvm
);
1438 ret
= iwl_wait_notification(&mvm
->notif_wait
,
1439 &wait_scan_done
, HZ
);
1444 /* iwl_mvm_rx_scan_offload_complete_notif() will be called
1445 * soon but will not reset the scan status as it won't be
1446 * IWL_MVM_SCAN_SCHED any more since we queue the next scan
1447 * immediately (below)
1450 case IWL_MVM_SCAN_NONE
:
1457 iwl_mvm_ref(mvm
, IWL_MVM_REF_SCAN
);
1459 ret
= iwl_mvm_scan_request(mvm
, vif
, req
);
1461 iwl_mvm_unref(mvm
, IWL_MVM_REF_SCAN
);
1463 mutex_unlock(&mvm
->mutex
);
1468 static void iwl_mvm_mac_cancel_hw_scan(struct ieee80211_hw
*hw
,
1469 struct ieee80211_vif
*vif
)
1471 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1473 mutex_lock(&mvm
->mutex
);
1475 iwl_mvm_cancel_scan(mvm
);
1477 mutex_unlock(&mvm
->mutex
);
1481 iwl_mvm_mac_allow_buffered_frames(struct ieee80211_hw
*hw
,
1482 struct ieee80211_sta
*sta
, u16 tids
,
1484 enum ieee80211_frame_release_type reason
,
1487 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1489 /* Called when we need to transmit (a) frame(s) from mac80211 */
1491 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
,
1492 tids
, more_data
, false);
1496 iwl_mvm_mac_release_buffered_frames(struct ieee80211_hw
*hw
,
1497 struct ieee80211_sta
*sta
, u16 tids
,
1499 enum ieee80211_frame_release_type reason
,
1502 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1504 /* Called when we need to transmit (a) frame(s) from agg queue */
1506 iwl_mvm_sta_modify_sleep_tx_count(mvm
, sta
, reason
, num_frames
,
1507 tids
, more_data
, true);
1510 static void iwl_mvm_mac_sta_notify(struct ieee80211_hw
*hw
,
1511 struct ieee80211_vif
*vif
,
1512 enum sta_notify_cmd cmd
,
1513 struct ieee80211_sta
*sta
)
1515 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1516 struct iwl_mvm_sta
*mvmsta
= iwl_mvm_sta_from_mac80211(sta
);
1520 case STA_NOTIFY_SLEEP
:
1521 if (atomic_read(&mvm
->pending_frames
[mvmsta
->sta_id
]) > 0)
1522 ieee80211_sta_block_awake(hw
, sta
, true);
1523 spin_lock_bh(&mvmsta
->lock
);
1524 for (tid
= 0; tid
< IWL_MAX_TID_COUNT
; tid
++) {
1525 struct iwl_mvm_tid_data
*tid_data
;
1527 tid_data
= &mvmsta
->tid_data
[tid
];
1528 if (tid_data
->state
!= IWL_AGG_ON
&&
1529 tid_data
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
)
1531 if (iwl_mvm_tid_queued(tid_data
) == 0)
1533 ieee80211_sta_set_buffered(sta
, tid
, true);
1535 spin_unlock_bh(&mvmsta
->lock
);
1537 * The fw updates the STA to be asleep. Tx packets on the Tx
1538 * queues to this station will not be transmitted. The fw will
1539 * send a Tx response with TX_STATUS_FAIL_DEST_PS.
1542 case STA_NOTIFY_AWAKE
:
1543 if (WARN_ON(mvmsta
->sta_id
== IWL_MVM_STATION_COUNT
))
1545 iwl_mvm_sta_modify_ps_wake(mvm
, sta
);
1552 static void iwl_mvm_sta_pre_rcu_remove(struct ieee80211_hw
*hw
,
1553 struct ieee80211_vif
*vif
,
1554 struct ieee80211_sta
*sta
)
1556 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1557 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
1560 * This is called before mac80211 does RCU synchronisation,
1561 * so here we already invalidate our internal RCU-protected
1562 * station pointer. The rest of the code will thus no longer
1563 * be able to find the station this way, and we don't rely
1564 * on further RCU synchronisation after the sta_state()
1565 * callback deleted the station.
1567 mutex_lock(&mvm
->mutex
);
1568 if (sta
== rcu_access_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
]))
1569 rcu_assign_pointer(mvm
->fw_id_to_mac_id
[mvm_sta
->sta_id
],
1571 mutex_unlock(&mvm
->mutex
);
1574 static int iwl_mvm_mac_sta_state(struct ieee80211_hw
*hw
,
1575 struct ieee80211_vif
*vif
,
1576 struct ieee80211_sta
*sta
,
1577 enum ieee80211_sta_state old_state
,
1578 enum ieee80211_sta_state new_state
)
1580 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1581 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1584 IWL_DEBUG_MAC80211(mvm
, "station %pM state change %d->%d\n",
1585 sta
->addr
, old_state
, new_state
);
1587 /* this would be a mac80211 bug ... but don't crash */
1588 if (WARN_ON_ONCE(!mvmvif
->phy_ctxt
))
1591 /* if a STA is being removed, reuse its ID */
1592 flush_work(&mvm
->sta_drained_wk
);
1594 mutex_lock(&mvm
->mutex
);
1595 if (old_state
== IEEE80211_STA_NOTEXIST
&&
1596 new_state
== IEEE80211_STA_NONE
) {
1598 * Firmware bug - it'll crash if the beacon interval is less
1599 * than 16. We can't avoid connecting at all, so refuse the
1600 * station state change, this will cause mac80211 to abandon
1601 * attempts to connect to this AP, and eventually wpa_s will
1602 * blacklist the AP...
1604 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1605 vif
->bss_conf
.beacon_int
< 16) {
1607 "AP %pM beacon interval is %d, refusing due to firmware bug!\n",
1608 sta
->addr
, vif
->bss_conf
.beacon_int
);
1612 ret
= iwl_mvm_add_sta(mvm
, vif
, sta
);
1613 } else if (old_state
== IEEE80211_STA_NONE
&&
1614 new_state
== IEEE80211_STA_AUTH
) {
1616 } else if (old_state
== IEEE80211_STA_AUTH
&&
1617 new_state
== IEEE80211_STA_ASSOC
) {
1618 ret
= iwl_mvm_update_sta(mvm
, vif
, sta
);
1620 iwl_mvm_rs_rate_init(mvm
, sta
,
1621 mvmvif
->phy_ctxt
->channel
->band
,
1623 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1624 new_state
== IEEE80211_STA_AUTHORIZED
) {
1625 /* enable beacon filtering */
1626 WARN_ON(iwl_mvm_enable_beacon_filter(mvm
, vif
, CMD_SYNC
));
1628 } else if (old_state
== IEEE80211_STA_AUTHORIZED
&&
1629 new_state
== IEEE80211_STA_ASSOC
) {
1630 /* disable beacon filtering */
1631 WARN_ON(iwl_mvm_disable_beacon_filter(mvm
, vif
, CMD_SYNC
));
1633 } else if (old_state
== IEEE80211_STA_ASSOC
&&
1634 new_state
== IEEE80211_STA_AUTH
) {
1636 } else if (old_state
== IEEE80211_STA_AUTH
&&
1637 new_state
== IEEE80211_STA_NONE
) {
1639 } else if (old_state
== IEEE80211_STA_NONE
&&
1640 new_state
== IEEE80211_STA_NOTEXIST
) {
1641 ret
= iwl_mvm_rm_sta(mvm
, vif
, sta
);
1646 mutex_unlock(&mvm
->mutex
);
1651 static int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw
*hw
, u32 value
)
1653 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1655 mvm
->rts_threshold
= value
;
1660 static void iwl_mvm_sta_rc_update(struct ieee80211_hw
*hw
,
1661 struct ieee80211_vif
*vif
,
1662 struct ieee80211_sta
*sta
, u32 changed
)
1664 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1666 if (vif
->type
== NL80211_IFTYPE_STATION
&&
1667 changed
& IEEE80211_RC_NSS_CHANGED
)
1668 iwl_mvm_sf_update(mvm
, vif
, false);
1671 static int iwl_mvm_mac_conf_tx(struct ieee80211_hw
*hw
,
1672 struct ieee80211_vif
*vif
, u16 ac
,
1673 const struct ieee80211_tx_queue_params
*params
)
1675 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1676 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1678 mvmvif
->queue_params
[ac
] = *params
;
1681 * No need to update right away, we'll get BSS_CHANGED_QOS
1682 * The exception is P2P_DEVICE interface which needs immediate update.
1684 if (vif
->type
== NL80211_IFTYPE_P2P_DEVICE
) {
1687 mutex_lock(&mvm
->mutex
);
1688 ret
= iwl_mvm_mac_ctxt_changed(mvm
, vif
);
1689 mutex_unlock(&mvm
->mutex
);
1695 static void iwl_mvm_mac_mgd_prepare_tx(struct ieee80211_hw
*hw
,
1696 struct ieee80211_vif
*vif
)
1698 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1699 u32 duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MAX_TIME_MS
,
1700 200 + vif
->bss_conf
.beacon_int
);
1701 u32 min_duration
= min(IWL_MVM_TE_SESSION_PROTECTION_MIN_TIME_MS
,
1702 100 + vif
->bss_conf
.beacon_int
);
1704 if (WARN_ON_ONCE(vif
->bss_conf
.assoc
))
1707 mutex_lock(&mvm
->mutex
);
1708 /* Try really hard to protect the session and hear a beacon */
1709 iwl_mvm_protect_session(mvm
, vif
, duration
, min_duration
, 500);
1710 mutex_unlock(&mvm
->mutex
);
1713 static int iwl_mvm_mac_sched_scan_start(struct ieee80211_hw
*hw
,
1714 struct ieee80211_vif
*vif
,
1715 struct cfg80211_sched_scan_request
*req
,
1716 struct ieee80211_sched_scan_ies
*ies
)
1718 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1721 mutex_lock(&mvm
->mutex
);
1723 if (mvm
->scan_status
!= IWL_MVM_SCAN_NONE
) {
1725 "SCHED SCAN request during internal scan - abort\n");
1730 mvm
->scan_status
= IWL_MVM_SCAN_SCHED
;
1732 ret
= iwl_mvm_config_sched_scan(mvm
, vif
, req
, ies
);
1736 ret
= iwl_mvm_config_sched_scan_profiles(mvm
, req
);
1740 ret
= iwl_mvm_sched_scan_start(mvm
, req
);
1744 mvm
->scan_status
= IWL_MVM_SCAN_NONE
;
1746 mutex_unlock(&mvm
->mutex
);
1750 static void iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw
*hw
,
1751 struct ieee80211_vif
*vif
)
1753 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1755 mutex_lock(&mvm
->mutex
);
1756 iwl_mvm_sched_scan_stop(mvm
);
1757 mutex_unlock(&mvm
->mutex
);
1760 static int iwl_mvm_mac_set_key(struct ieee80211_hw
*hw
,
1761 enum set_key_cmd cmd
,
1762 struct ieee80211_vif
*vif
,
1763 struct ieee80211_sta
*sta
,
1764 struct ieee80211_key_conf
*key
)
1766 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1769 if (iwlwifi_mod_params
.sw_crypto
) {
1770 IWL_DEBUG_MAC80211(mvm
, "leave - hwcrypto disabled\n");
1774 switch (key
->cipher
) {
1775 case WLAN_CIPHER_SUITE_TKIP
:
1776 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_MMIC
;
1778 case WLAN_CIPHER_SUITE_CCMP
:
1779 key
->flags
|= IEEE80211_KEY_FLAG_GENERATE_IV
;
1781 case WLAN_CIPHER_SUITE_AES_CMAC
:
1782 WARN_ON_ONCE(!(hw
->flags
& IEEE80211_HW_MFP_CAPABLE
));
1784 case WLAN_CIPHER_SUITE_WEP40
:
1785 case WLAN_CIPHER_SUITE_WEP104
:
1787 * Support for TX only, at least for now, so accept
1788 * the key and do nothing else. Then mac80211 will
1789 * pass it for TX but we don't have to use it for RX.
1793 /* currently FW supports only one optional cipher scheme */
1794 if (hw
->n_cipher_schemes
&&
1795 hw
->cipher_schemes
->cipher
== key
->cipher
)
1796 key
->flags
|= IEEE80211_KEY_FLAG_PUT_IV_SPACE
;
1801 mutex_lock(&mvm
->mutex
);
1805 if ((vif
->type
== NL80211_IFTYPE_ADHOC
||
1806 vif
->type
== NL80211_IFTYPE_AP
) && !sta
) {
1808 * GTK on AP interface is a TX-only key, return 0;
1809 * on IBSS they're per-station and because we're lazy
1810 * we don't support them for RX, so do the same.
1813 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1817 IWL_DEBUG_MAC80211(mvm
, "set hwcrypto key\n");
1818 ret
= iwl_mvm_set_sta_key(mvm
, vif
, sta
, key
, false);
1820 IWL_WARN(mvm
, "set key failed\n");
1822 * can't add key for RX, but we don't need it
1823 * in the device for TX so still return 0
1825 key
->hw_key_idx
= STA_KEY_IDX_INVALID
;
1831 if (key
->hw_key_idx
== STA_KEY_IDX_INVALID
) {
1836 IWL_DEBUG_MAC80211(mvm
, "disable hwcrypto key\n");
1837 ret
= iwl_mvm_remove_sta_key(mvm
, vif
, sta
, key
);
1843 mutex_unlock(&mvm
->mutex
);
1847 static void iwl_mvm_mac_update_tkip_key(struct ieee80211_hw
*hw
,
1848 struct ieee80211_vif
*vif
,
1849 struct ieee80211_key_conf
*keyconf
,
1850 struct ieee80211_sta
*sta
,
1851 u32 iv32
, u16
*phase1key
)
1853 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1855 if (keyconf
->hw_key_idx
== STA_KEY_IDX_INVALID
)
1858 iwl_mvm_update_tkip_key(mvm
, vif
, keyconf
, sta
, iv32
, phase1key
);
1862 static int iwl_mvm_roc(struct ieee80211_hw
*hw
,
1863 struct ieee80211_vif
*vif
,
1864 struct ieee80211_channel
*channel
,
1866 enum ieee80211_roc_type type
)
1868 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1869 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
1870 struct cfg80211_chan_def chandef
;
1871 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1874 IWL_DEBUG_MAC80211(mvm
, "enter (%d, %d, %d)\n", channel
->hw_value
,
1877 if (vif
->type
!= NL80211_IFTYPE_P2P_DEVICE
) {
1878 IWL_ERR(mvm
, "vif isn't a P2P_DEVICE: %d\n", vif
->type
);
1882 mutex_lock(&mvm
->mutex
);
1884 for (i
= 0; i
< NUM_PHY_CTX
; i
++) {
1885 phy_ctxt
= &mvm
->phy_ctxts
[i
];
1886 if (phy_ctxt
->ref
== 0 || mvmvif
->phy_ctxt
== phy_ctxt
)
1889 if (phy_ctxt
->ref
&& channel
== phy_ctxt
->channel
) {
1891 * Unbind the P2P_DEVICE from the current PHY context,
1892 * and if the PHY context is not used remove it.
1894 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1895 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1898 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1900 /* Bind the P2P_DEVICE to the current PHY Context */
1901 mvmvif
->phy_ctxt
= phy_ctxt
;
1903 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1904 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1907 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1908 goto schedule_time_event
;
1912 /* Need to update the PHY context only if the ROC channel changed */
1913 if (channel
== mvmvif
->phy_ctxt
->channel
)
1914 goto schedule_time_event
;
1916 cfg80211_chandef_create(&chandef
, channel
, NL80211_CHAN_NO_HT
);
1919 * Change the PHY context configuration as it is currently referenced
1920 * only by the P2P Device MAC
1922 if (mvmvif
->phy_ctxt
->ref
== 1) {
1923 ret
= iwl_mvm_phy_ctxt_changed(mvm
, mvmvif
->phy_ctxt
,
1929 * The PHY context is shared with other MACs. Need to remove the
1930 * P2P Device from the binding, allocate an new PHY context and
1931 * create a new binding
1933 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
1939 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &chandef
,
1942 IWL_ERR(mvm
, "Failed to change PHY context\n");
1946 /* Unbind the P2P_DEVICE from the current PHY context */
1947 ret
= iwl_mvm_binding_remove_vif(mvm
, vif
);
1948 if (WARN(ret
, "Failed unbinding P2P_DEVICE\n"))
1951 iwl_mvm_phy_ctxt_unref(mvm
, mvmvif
->phy_ctxt
);
1953 /* Bind the P2P_DEVICE to the new allocated PHY context */
1954 mvmvif
->phy_ctxt
= phy_ctxt
;
1956 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
1957 if (WARN(ret
, "Failed binding P2P_DEVICE\n"))
1960 iwl_mvm_phy_ctxt_ref(mvm
, mvmvif
->phy_ctxt
);
1963 schedule_time_event
:
1964 /* Schedule the time events */
1965 ret
= iwl_mvm_start_p2p_roc(mvm
, vif
, duration
, type
);
1968 mutex_unlock(&mvm
->mutex
);
1969 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1973 static int iwl_mvm_cancel_roc(struct ieee80211_hw
*hw
)
1975 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1977 IWL_DEBUG_MAC80211(mvm
, "enter\n");
1979 mutex_lock(&mvm
->mutex
);
1980 iwl_mvm_stop_p2p_roc(mvm
);
1981 mutex_unlock(&mvm
->mutex
);
1983 IWL_DEBUG_MAC80211(mvm
, "leave\n");
1987 static int iwl_mvm_add_chanctx(struct ieee80211_hw
*hw
,
1988 struct ieee80211_chanctx_conf
*ctx
)
1990 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
1991 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
1992 struct iwl_mvm_phy_ctxt
*phy_ctxt
;
1995 IWL_DEBUG_MAC80211(mvm
, "Add channel context\n");
1997 mutex_lock(&mvm
->mutex
);
1998 phy_ctxt
= iwl_mvm_get_free_phy_ctxt(mvm
);
2004 ret
= iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->min_def
,
2005 ctx
->rx_chains_static
,
2006 ctx
->rx_chains_dynamic
);
2008 IWL_ERR(mvm
, "Failed to add PHY context\n");
2012 iwl_mvm_phy_ctxt_ref(mvm
, phy_ctxt
);
2013 *phy_ctxt_id
= phy_ctxt
->id
;
2015 mutex_unlock(&mvm
->mutex
);
2019 static void iwl_mvm_remove_chanctx(struct ieee80211_hw
*hw
,
2020 struct ieee80211_chanctx_conf
*ctx
)
2022 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2023 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2024 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
2026 mutex_lock(&mvm
->mutex
);
2027 iwl_mvm_phy_ctxt_unref(mvm
, phy_ctxt
);
2028 mutex_unlock(&mvm
->mutex
);
2031 static void iwl_mvm_change_chanctx(struct ieee80211_hw
*hw
,
2032 struct ieee80211_chanctx_conf
*ctx
,
2035 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2036 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2037 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
2039 if (WARN_ONCE((phy_ctxt
->ref
> 1) &&
2040 (changed
& ~(IEEE80211_CHANCTX_CHANGE_WIDTH
|
2041 IEEE80211_CHANCTX_CHANGE_RX_CHAINS
|
2042 IEEE80211_CHANCTX_CHANGE_RADAR
|
2043 IEEE80211_CHANCTX_CHANGE_MIN_WIDTH
)),
2044 "Cannot change PHY. Ref=%d, changed=0x%X\n",
2045 phy_ctxt
->ref
, changed
))
2048 mutex_lock(&mvm
->mutex
);
2049 iwl_mvm_phy_ctxt_changed(mvm
, phy_ctxt
, &ctx
->min_def
,
2050 ctx
->rx_chains_static
,
2051 ctx
->rx_chains_dynamic
);
2052 iwl_mvm_bt_coex_vif_change(mvm
);
2053 mutex_unlock(&mvm
->mutex
);
2056 static int iwl_mvm_assign_vif_chanctx(struct ieee80211_hw
*hw
,
2057 struct ieee80211_vif
*vif
,
2058 struct ieee80211_chanctx_conf
*ctx
)
2060 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2061 u16
*phy_ctxt_id
= (u16
*)ctx
->drv_priv
;
2062 struct iwl_mvm_phy_ctxt
*phy_ctxt
= &mvm
->phy_ctxts
[*phy_ctxt_id
];
2063 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2066 mutex_lock(&mvm
->mutex
);
2068 mvmvif
->phy_ctxt
= phy_ctxt
;
2070 switch (vif
->type
) {
2071 case NL80211_IFTYPE_AP
:
2072 case NL80211_IFTYPE_ADHOC
:
2074 * The AP binding flow is handled as part of the start_ap flow
2075 * (in bss_info_changed), similarly for IBSS.
2079 case NL80211_IFTYPE_STATION
:
2080 case NL80211_IFTYPE_MONITOR
:
2087 ret
= iwl_mvm_binding_add_vif(mvm
, vif
);
2092 * Power state must be updated before quotas,
2093 * otherwise fw will complain.
2095 iwl_mvm_power_update_mac(mvm
, vif
);
2097 /* Setting the quota at this stage is only required for monitor
2098 * interfaces. For the other types, the bss_info changed flow
2099 * will handle quota settings.
2101 if (vif
->type
== NL80211_IFTYPE_MONITOR
) {
2102 mvmvif
->monitor_active
= true;
2103 ret
= iwl_mvm_update_quotas(mvm
, vif
);
2105 goto out_remove_binding
;
2111 iwl_mvm_binding_remove_vif(mvm
, vif
);
2112 iwl_mvm_power_update_mac(mvm
, vif
);
2114 mutex_unlock(&mvm
->mutex
);
2116 mvmvif
->phy_ctxt
= NULL
;
2120 static void iwl_mvm_unassign_vif_chanctx(struct ieee80211_hw
*hw
,
2121 struct ieee80211_vif
*vif
,
2122 struct ieee80211_chanctx_conf
*ctx
)
2124 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2125 struct iwl_mvm_vif
*mvmvif
= iwl_mvm_vif_from_mac80211(vif
);
2127 mutex_lock(&mvm
->mutex
);
2129 iwl_mvm_remove_time_event(mvm
, mvmvif
, &mvmvif
->time_event_data
);
2131 switch (vif
->type
) {
2132 case NL80211_IFTYPE_AP
:
2133 case NL80211_IFTYPE_ADHOC
:
2135 case NL80211_IFTYPE_MONITOR
:
2136 mvmvif
->monitor_active
= false;
2137 iwl_mvm_update_quotas(mvm
, NULL
);
2143 iwl_mvm_binding_remove_vif(mvm
, vif
);
2144 iwl_mvm_power_update_mac(mvm
, vif
);
2147 mvmvif
->phy_ctxt
= NULL
;
2148 mutex_unlock(&mvm
->mutex
);
2151 static int iwl_mvm_set_tim(struct ieee80211_hw
*hw
,
2152 struct ieee80211_sta
*sta
,
2155 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2156 struct iwl_mvm_sta
*mvm_sta
= (void *)sta
->drv_priv
;
2158 if (!mvm_sta
|| !mvm_sta
->vif
) {
2159 IWL_ERR(mvm
, "Station is not associated to a vif\n");
2163 return iwl_mvm_mac_ctxt_beacon_changed(mvm
, mvm_sta
->vif
);
2166 #ifdef CONFIG_NL80211_TESTMODE
2167 static const struct nla_policy iwl_mvm_tm_policy
[IWL_MVM_TM_ATTR_MAX
+ 1] = {
2168 [IWL_MVM_TM_ATTR_CMD
] = { .type
= NLA_U32
},
2169 [IWL_MVM_TM_ATTR_NOA_DURATION
] = { .type
= NLA_U32
},
2170 [IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
] = { .type
= NLA_U32
},
2173 static int __iwl_mvm_mac_testmode_cmd(struct iwl_mvm
*mvm
,
2174 struct ieee80211_vif
*vif
,
2175 void *data
, int len
)
2177 struct nlattr
*tb
[IWL_MVM_TM_ATTR_MAX
+ 1];
2181 err
= nla_parse(tb
, IWL_MVM_TM_ATTR_MAX
, data
, len
, iwl_mvm_tm_policy
);
2185 if (!tb
[IWL_MVM_TM_ATTR_CMD
])
2188 switch (nla_get_u32(tb
[IWL_MVM_TM_ATTR_CMD
])) {
2189 case IWL_MVM_TM_CMD_SET_NOA
:
2190 if (!vif
|| vif
->type
!= NL80211_IFTYPE_AP
|| !vif
->p2p
||
2191 !vif
->bss_conf
.enable_beacon
||
2192 !tb
[IWL_MVM_TM_ATTR_NOA_DURATION
])
2195 noa_duration
= nla_get_u32(tb
[IWL_MVM_TM_ATTR_NOA_DURATION
]);
2196 if (noa_duration
>= vif
->bss_conf
.beacon_int
)
2199 mvm
->noa_duration
= noa_duration
;
2202 return iwl_mvm_update_quotas(mvm
, NULL
);
2203 case IWL_MVM_TM_CMD_SET_BEACON_FILTER
:
2204 /* must be associated client vif - ignore authorized */
2205 if (!vif
|| vif
->type
!= NL80211_IFTYPE_STATION
||
2206 !vif
->bss_conf
.assoc
|| !vif
->bss_conf
.dtim_period
||
2207 !tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
])
2210 if (nla_get_u32(tb
[IWL_MVM_TM_ATTR_BEACON_FILTER_STATE
]))
2211 return iwl_mvm_enable_beacon_filter(mvm
, vif
,
2213 return iwl_mvm_disable_beacon_filter(mvm
, vif
, CMD_SYNC
);
2219 static int iwl_mvm_mac_testmode_cmd(struct ieee80211_hw
*hw
,
2220 struct ieee80211_vif
*vif
,
2221 void *data
, int len
)
2223 struct iwl_mvm
*mvm
= IWL_MAC80211_GET_MVM(hw
);
2226 mutex_lock(&mvm
->mutex
);
2227 err
= __iwl_mvm_mac_testmode_cmd(mvm
, vif
, data
, len
);
2228 mutex_unlock(&mvm
->mutex
);
2234 const struct ieee80211_ops iwl_mvm_hw_ops
= {
2235 .tx
= iwl_mvm_mac_tx
,
2236 .ampdu_action
= iwl_mvm_mac_ampdu_action
,
2237 .start
= iwl_mvm_mac_start
,
2238 .restart_complete
= iwl_mvm_mac_restart_complete
,
2239 .stop
= iwl_mvm_mac_stop
,
2240 .add_interface
= iwl_mvm_mac_add_interface
,
2241 .remove_interface
= iwl_mvm_mac_remove_interface
,
2242 .config
= iwl_mvm_mac_config
,
2243 .prepare_multicast
= iwl_mvm_prepare_multicast
,
2244 .configure_filter
= iwl_mvm_configure_filter
,
2245 .bss_info_changed
= iwl_mvm_bss_info_changed
,
2246 .hw_scan
= iwl_mvm_mac_hw_scan
,
2247 .cancel_hw_scan
= iwl_mvm_mac_cancel_hw_scan
,
2248 .sta_pre_rcu_remove
= iwl_mvm_sta_pre_rcu_remove
,
2249 .sta_state
= iwl_mvm_mac_sta_state
,
2250 .sta_notify
= iwl_mvm_mac_sta_notify
,
2251 .allow_buffered_frames
= iwl_mvm_mac_allow_buffered_frames
,
2252 .release_buffered_frames
= iwl_mvm_mac_release_buffered_frames
,
2253 .set_rts_threshold
= iwl_mvm_mac_set_rts_threshold
,
2254 .sta_rc_update
= iwl_mvm_sta_rc_update
,
2255 .conf_tx
= iwl_mvm_mac_conf_tx
,
2256 .mgd_prepare_tx
= iwl_mvm_mac_mgd_prepare_tx
,
2257 .sched_scan_start
= iwl_mvm_mac_sched_scan_start
,
2258 .sched_scan_stop
= iwl_mvm_mac_sched_scan_stop
,
2259 .set_key
= iwl_mvm_mac_set_key
,
2260 .update_tkip_key
= iwl_mvm_mac_update_tkip_key
,
2261 .remain_on_channel
= iwl_mvm_roc
,
2262 .cancel_remain_on_channel
= iwl_mvm_cancel_roc
,
2263 .add_chanctx
= iwl_mvm_add_chanctx
,
2264 .remove_chanctx
= iwl_mvm_remove_chanctx
,
2265 .change_chanctx
= iwl_mvm_change_chanctx
,
2266 .assign_vif_chanctx
= iwl_mvm_assign_vif_chanctx
,
2267 .unassign_vif_chanctx
= iwl_mvm_unassign_vif_chanctx
,
2269 .start_ap
= iwl_mvm_start_ap_ibss
,
2270 .stop_ap
= iwl_mvm_stop_ap_ibss
,
2271 .join_ibss
= iwl_mvm_start_ap_ibss
,
2272 .leave_ibss
= iwl_mvm_stop_ap_ibss
,
2274 .set_tim
= iwl_mvm_set_tim
,
2276 CFG80211_TESTMODE_CMD(iwl_mvm_mac_testmode_cmd
)
2278 #ifdef CONFIG_PM_SLEEP
2280 .suspend
= iwl_mvm_suspend
,
2281 .resume
= iwl_mvm_resume
,
2282 .set_wakeup
= iwl_mvm_set_wakeup
,
2283 .set_rekey_data
= iwl_mvm_set_rekey_data
,
2284 #if IS_ENABLED(CONFIG_IPV6)
2285 .ipv6_addr_change
= iwl_mvm_ipv6_addr_change
,
2287 .set_default_unicast_key
= iwl_mvm_set_default_unicast_key
,