xref: /openbmc/linux/net/mac80211/main.c (revision ecc23d0a422a3118fcf6e4f0a46e17a6c2047b02)
1d2912cb1SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
22c8dccc7SJohannes Berg /*
32c8dccc7SJohannes Berg  * Copyright 2002-2005, Instant802 Networks, Inc.
42c8dccc7SJohannes Berg  * Copyright 2005-2006, Devicescape Software, Inc.
52c8dccc7SJohannes Berg  * Copyright 2006-2007	Jiri Benc <jbenc@suse.cz>
6d98ad83eSJohannes Berg  * Copyright 2013-2014  Intel Mobile Communications GmbH
741cbb0f5SLuca Coelho  * Copyright (C) 2017     Intel Deutschland GmbH
815ddba5fSAnjaneyulu  * Copyright (C) 2018-2023 Intel Corporation
92c8dccc7SJohannes Berg  */
102c8dccc7SJohannes Berg 
112c8dccc7SJohannes Berg #include <net/mac80211.h>
122c8dccc7SJohannes Berg #include <linux/module.h>
135fdb3735SArd Biesheuvel #include <linux/fips.h>
142c8dccc7SJohannes Berg #include <linux/init.h>
152c8dccc7SJohannes Berg #include <linux/netdevice.h>
162c8dccc7SJohannes Berg #include <linux/types.h>
172c8dccc7SJohannes Berg #include <linux/slab.h>
182c8dccc7SJohannes Berg #include <linux/skbuff.h>
192c8dccc7SJohannes Berg #include <linux/etherdevice.h>
202c8dccc7SJohannes Berg #include <linux/if_arp.h>
212c8dccc7SJohannes Berg #include <linux/rtnetlink.h>
222c8dccc7SJohannes Berg #include <linux/bitmap.h>
2368542962SJuuso Oikarinen #include <linux/inetdevice.h>
242c8dccc7SJohannes Berg #include <net/net_namespace.h>
25baa951a1SJohannes Berg #include <net/dropreason.h>
262c8dccc7SJohannes Berg #include <net/cfg80211.h>
27a65240c1SJohannes Berg #include <net/addrconf.h>
282c8dccc7SJohannes Berg 
292c8dccc7SJohannes Berg #include "ieee80211_i.h"
3024487981SJohannes Berg #include "driver-ops.h"
312c8dccc7SJohannes Berg #include "rate.h"
322c8dccc7SJohannes Berg #include "mesh.h"
332c8dccc7SJohannes Berg #include "wep.h"
342c8dccc7SJohannes Berg #include "led.h"
352c8dccc7SJohannes Berg #include "debugfs.h"
362c8dccc7SJohannes Berg 
ieee80211_configure_filter(struct ieee80211_local * local)370d143fe1SJohannes Berg void ieee80211_configure_filter(struct ieee80211_local *local)
382c8dccc7SJohannes Berg {
393ac64beeSJohannes Berg 	u64 mc;
402c8dccc7SJohannes Berg 	unsigned int changed_flags;
412c8dccc7SJohannes Berg 	unsigned int new_flags = 0;
422c8dccc7SJohannes Berg 
432c8dccc7SJohannes Berg 	if (atomic_read(&local->iff_allmultis))
442c8dccc7SJohannes Berg 		new_flags |= FIF_ALLMULTI;
452c8dccc7SJohannes Berg 
468a690674SBen Greear 	if (local->monitors || test_bit(SCAN_SW_SCANNING, &local->scanning) ||
478a690674SBen Greear 	    test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning))
482c8dccc7SJohannes Berg 		new_flags |= FIF_BCN_PRBRESP_PROMISC;
492c8dccc7SJohannes Berg 
507be5086dSJohannes Berg 	if (local->fif_probe_req || local->probe_req_reg)
517be5086dSJohannes Berg 		new_flags |= FIF_PROBE_REQ;
527be5086dSJohannes Berg 
532c8dccc7SJohannes Berg 	if (local->fif_fcsfail)
542c8dccc7SJohannes Berg 		new_flags |= FIF_FCSFAIL;
552c8dccc7SJohannes Berg 
562c8dccc7SJohannes Berg 	if (local->fif_plcpfail)
572c8dccc7SJohannes Berg 		new_flags |= FIF_PLCPFAIL;
582c8dccc7SJohannes Berg 
592c8dccc7SJohannes Berg 	if (local->fif_control)
602c8dccc7SJohannes Berg 		new_flags |= FIF_CONTROL;
612c8dccc7SJohannes Berg 
622c8dccc7SJohannes Berg 	if (local->fif_other_bss)
632c8dccc7SJohannes Berg 		new_flags |= FIF_OTHER_BSS;
642c8dccc7SJohannes Berg 
65e3b90ca2SIgor Perminov 	if (local->fif_pspoll)
66e3b90ca2SIgor Perminov 		new_flags |= FIF_PSPOLL;
67e3b90ca2SIgor Perminov 
68873b1cf6SJouni Malinen 	if (local->rx_mcast_action_reg)
69873b1cf6SJouni Malinen 		new_flags |= FIF_MCAST_ACTION;
70873b1cf6SJouni Malinen 
713ac64beeSJohannes Berg 	spin_lock_bh(&local->filter_lock);
722c8dccc7SJohannes Berg 	changed_flags = local->filter_flags ^ new_flags;
732c8dccc7SJohannes Berg 
7422bedad3SJiri Pirko 	mc = drv_prepare_multicast(local, &local->mc_list);
753ac64beeSJohannes Berg 	spin_unlock_bh(&local->filter_lock);
763ac64beeSJohannes Berg 
772c8dccc7SJohannes Berg 	/* be a bit nasty */
782c8dccc7SJohannes Berg 	new_flags |= (1<<31);
792c8dccc7SJohannes Berg 
803ac64beeSJohannes Berg 	drv_configure_filter(local, changed_flags, &new_flags, mc);
812c8dccc7SJohannes Berg 
822c8dccc7SJohannes Berg 	WARN_ON(new_flags & (1<<31));
832c8dccc7SJohannes Berg 
842c8dccc7SJohannes Berg 	local->filter_flags = new_flags & ~(1<<31);
852c8dccc7SJohannes Berg }
862c8dccc7SJohannes Berg 
ieee80211_reconfig_filter(struct work_struct * work)873ac64beeSJohannes Berg static void ieee80211_reconfig_filter(struct work_struct *work)
883ac64beeSJohannes Berg {
893ac64beeSJohannes Berg 	struct ieee80211_local *local =
903ac64beeSJohannes Berg 		container_of(work, struct ieee80211_local, reconfig_filter);
913ac64beeSJohannes Berg 
923ac64beeSJohannes Berg 	ieee80211_configure_filter(local);
933ac64beeSJohannes Berg }
943ac64beeSJohannes Berg 
ieee80211_hw_conf_chan(struct ieee80211_local * local)9555de908aSJohannes Berg static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
962c8dccc7SJohannes Berg {
971ea6f9c0SJohannes Berg 	struct ieee80211_sub_if_data *sdata;
98675a0b04SKarl Beldan 	struct cfg80211_chan_def chandef = {};
9955de908aSJohannes Berg 	u32 changed = 0;
100e8975581SJohannes Berg 	int power;
101ffd2778bSFelix Fietkau 	u32 offchannel_flag;
1022c8dccc7SJohannes Berg 
103ffd2778bSFelix Fietkau 	offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
104675a0b04SKarl Beldan 
1057ca15a0aSSimon Wunderlich 	if (local->scan_chandef.chan) {
1067ca15a0aSSimon Wunderlich 		chandef = local->scan_chandef;
107675a0b04SKarl Beldan 	} else if (local->tmp_channel) {
108675a0b04SKarl Beldan 		chandef.chan = local->tmp_channel;
109675a0b04SKarl Beldan 		chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
110675a0b04SKarl Beldan 		chandef.center_freq1 = chandef.chan->center_freq;
111b6011960SThomas Pedersen 		chandef.freq1_offset = chandef.chan->freq_offset;
112675a0b04SKarl Beldan 	} else
113675a0b04SKarl Beldan 		chandef = local->_oper_chandef;
114b23b025fSBen Greear 
115675a0b04SKarl Beldan 	WARN(!cfg80211_chandef_valid(&chandef),
116b6011960SThomas Pedersen 	     "control:%d.%03d MHz width:%d center: %d.%03d/%d MHz",
117b6011960SThomas Pedersen 	     chandef.chan->center_freq, chandef.chan->freq_offset,
118b6011960SThomas Pedersen 	     chandef.width, chandef.center_freq1, chandef.freq1_offset,
119b6011960SThomas Pedersen 	     chandef.center_freq2);
120675a0b04SKarl Beldan 
121675a0b04SKarl Beldan 	if (!cfg80211_chandef_identical(&chandef, &local->_oper_chandef))
122b23b025fSBen Greear 		local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
123b23b025fSBen Greear 	else
124b23b025fSBen Greear 		local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
125b23b025fSBen Greear 
126ffd2778bSFelix Fietkau 	offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
127e8975581SJohannes Berg 
128675a0b04SKarl Beldan 	if (offchannel_flag ||
129675a0b04SKarl Beldan 	    !cfg80211_chandef_identical(&local->hw.conf.chandef,
130675a0b04SKarl Beldan 					&local->_oper_chandef)) {
131675a0b04SKarl Beldan 		local->hw.conf.chandef = chandef;
13272bdcf34SJouni Malinen 		changed |= IEEE80211_CONF_CHANGE_CHANNEL;
13372bdcf34SJouni Malinen 	}
1342c8dccc7SJohannes Berg 
1350f78231bSJohannes Berg 	if (!conf_is_ht(&local->hw.conf)) {
1360f78231bSJohannes Berg 		/*
1370f78231bSJohannes Berg 		 * mac80211.h documents that this is only valid
1380f78231bSJohannes Berg 		 * when the channel is set to an HT type, and
1390f78231bSJohannes Berg 		 * that otherwise STATIC is used.
1400f78231bSJohannes Berg 		 */
1410f78231bSJohannes Berg 		local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
1420f78231bSJohannes Berg 	} else if (local->hw.conf.smps_mode != local->smps_mode) {
1430f78231bSJohannes Berg 		local->hw.conf.smps_mode = local->smps_mode;
1440f78231bSJohannes Berg 		changed |= IEEE80211_CONF_CHANGE_SMPS;
1450f78231bSJohannes Berg 	}
1460f78231bSJohannes Berg 
1470430c883SSimon Wunderlich 	power = ieee80211_chandef_max_power(&chandef);
148*24fa3e94SBen Greear 	if (local->user_power_level != IEEE80211_UNSET_POWER_LEVEL)
149*24fa3e94SBen Greear 		power = min(local->user_power_level, power);
150a8302de9SVasanthakumar Thiagarajan 
1511ea6f9c0SJohannes Berg 	rcu_read_lock();
1521ea6f9c0SJohannes Berg 	list_for_each_entry_rcu(sdata, &local->interfaces, list) {
153d0a9123eSJohannes Berg 		if (!rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf))
1541ea6f9c0SJohannes Berg 			continue;
155764152ffSFelix Fietkau 		if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
156764152ffSFelix Fietkau 			continue;
157db6d9e9eSBen Greear 		if (sdata->vif.bss_conf.txpower == INT_MIN)
158db6d9e9eSBen Greear 			continue;
1591ea6f9c0SJohannes Berg 		power = min(power, sdata->vif.bss_conf.txpower);
1601ea6f9c0SJohannes Berg 	}
1611ea6f9c0SJohannes Berg 	rcu_read_unlock();
162a8302de9SVasanthakumar Thiagarajan 
163e8975581SJohannes Berg 	if (local->hw.conf.power_level != power) {
164e8975581SJohannes Berg 		changed |= IEEE80211_CONF_CHANGE_POWER;
165e8975581SJohannes Berg 		local->hw.conf.power_level = power;
166e8975581SJohannes Berg 	}
1672c8dccc7SJohannes Berg 
16855de908aSJohannes Berg 	return changed;
16955de908aSJohannes Berg }
17055de908aSJohannes Berg 
ieee80211_hw_config(struct ieee80211_local * local,u32 changed)17155de908aSJohannes Berg int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
17255de908aSJohannes Berg {
17355de908aSJohannes Berg 	int ret = 0;
17455de908aSJohannes Berg 
17555de908aSJohannes Berg 	might_sleep();
17655de908aSJohannes Berg 
17755de908aSJohannes Berg 	if (!local->use_chanctx)
17855de908aSJohannes Berg 		changed |= ieee80211_hw_conf_chan(local);
17955de908aSJohannes Berg 	else
18055de908aSJohannes Berg 		changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
181a503a953SJohannes Berg 			     IEEE80211_CONF_CHANGE_POWER |
182a503a953SJohannes Berg 			     IEEE80211_CONF_CHANGE_SMPS);
18355de908aSJohannes Berg 
184e8975581SJohannes Berg 	if (changed && local->open_count) {
18524487981SJohannes Berg 		ret = drv_config(local, changed);
186d73782fdSJohannes Berg 		/*
187447107fbSReinette Chatre 		 * Goal:
188d73782fdSJohannes Berg 		 * HW reconfiguration should never fail, the driver has told
189d73782fdSJohannes Berg 		 * us what it can support so it should live up to that promise.
190447107fbSReinette Chatre 		 *
191447107fbSReinette Chatre 		 * Current status:
192447107fbSReinette Chatre 		 * rfkill is not integrated with mac80211 and a
193447107fbSReinette Chatre 		 * configuration command can thus fail if hardware rfkill
194447107fbSReinette Chatre 		 * is enabled
195447107fbSReinette Chatre 		 *
196447107fbSReinette Chatre 		 * FIXME: integrate rfkill with mac80211 and then add this
197447107fbSReinette Chatre 		 * WARN_ON() back
198447107fbSReinette Chatre 		 *
199d73782fdSJohannes Berg 		 */
200447107fbSReinette Chatre 		/* WARN_ON(ret); */
201d73782fdSJohannes Berg 	}
2022c8dccc7SJohannes Berg 
2032c8dccc7SJohannes Berg 	return ret;
2042c8dccc7SJohannes Berg }
2052c8dccc7SJohannes Berg 
2067b7090b4SJohannes Berg #define BSS_CHANGED_VIF_CFG_FLAGS (BSS_CHANGED_ASSOC |\
2077b7090b4SJohannes Berg 				   BSS_CHANGED_IDLE |\
208a3b8008dSJohannes Berg 				   BSS_CHANGED_PS |\
2097b7090b4SJohannes Berg 				   BSS_CHANGED_IBSS |\
2107b7090b4SJohannes Berg 				   BSS_CHANGED_ARP_FILTER |\
2117b7090b4SJohannes Berg 				   BSS_CHANGED_SSID)
2127b7090b4SJohannes Berg 
ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data * sdata,u64 changed)2132c8dccc7SJohannes Berg void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
2147b7090b4SJohannes Berg 				      u64 changed)
2152c8dccc7SJohannes Berg {
2162c8dccc7SJohannes Berg 	struct ieee80211_local *local = sdata->local;
2172c8dccc7SJohannes Berg 
2187b7090b4SJohannes Berg 	might_sleep();
2197b7090b4SJohannes Berg 
220e51077adSJohannes Berg 	WARN_ON_ONCE(ieee80211_vif_is_mld(&sdata->vif));
221e51077adSJohannes Berg 
222990baec0SFelix Fietkau 	if (!changed || sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2232c8dccc7SJohannes Berg 		return;
2242c8dccc7SJohannes Berg 
2257b7090b4SJohannes Berg 	if (WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
2267b7090b4SJohannes Berg 				    BSS_CHANGED_BEACON_ENABLED) &&
2277b7090b4SJohannes Berg 			 sdata->vif.type != NL80211_IFTYPE_AP &&
2287b7090b4SJohannes Berg 			 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2297b7090b4SJohannes Berg 			 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
2307b7090b4SJohannes Berg 			 sdata->vif.type != NL80211_IFTYPE_OCB))
2317b7090b4SJohannes Berg 		return;
2327b7090b4SJohannes Berg 
2337b7090b4SJohannes Berg 	if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
2347b7090b4SJohannes Berg 			 sdata->vif.type == NL80211_IFTYPE_NAN ||
2357b7090b4SJohannes Berg 			 (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
2367b7090b4SJohannes Berg 			  !sdata->vif.bss_conf.mu_mimo_owner &&
2377b7090b4SJohannes Berg 			  !(changed & BSS_CHANGED_TXPOWER))))
2387b7090b4SJohannes Berg 		return;
2397b7090b4SJohannes Berg 
2407b7090b4SJohannes Berg 	if (!check_sdata_in_driver(sdata))
2417b7090b4SJohannes Berg 		return;
2427b7090b4SJohannes Berg 
2437b7090b4SJohannes Berg 	if (changed & BSS_CHANGED_VIF_CFG_FLAGS) {
2447b7090b4SJohannes Berg 		u64 ch = changed & BSS_CHANGED_VIF_CFG_FLAGS;
2457b7090b4SJohannes Berg 
2467b7090b4SJohannes Berg 		trace_drv_vif_cfg_changed(local, sdata, changed);
2477b7090b4SJohannes Berg 		if (local->ops->vif_cfg_changed)
2487b7090b4SJohannes Berg 			local->ops->vif_cfg_changed(&local->hw, &sdata->vif, ch);
2497b7090b4SJohannes Berg 	}
2507b7090b4SJohannes Berg 
2517b7090b4SJohannes Berg 	if (changed & ~BSS_CHANGED_VIF_CFG_FLAGS) {
2527b7090b4SJohannes Berg 		u64 ch = changed & ~BSS_CHANGED_VIF_CFG_FLAGS;
2537b7090b4SJohannes Berg 
254d8675a63SJohannes Berg 		trace_drv_link_info_changed(local, sdata, &sdata->vif.bss_conf,
2557840bd46SGregory Greenman 					    changed);
2567b7090b4SJohannes Berg 		if (local->ops->link_info_changed)
2577b7090b4SJohannes Berg 			local->ops->link_info_changed(&local->hw, &sdata->vif,
2587840bd46SGregory Greenman 						      &sdata->vif.bss_conf, ch);
2597b7090b4SJohannes Berg 	}
2607b7090b4SJohannes Berg 
2617b7090b4SJohannes Berg 	if (local->ops->bss_info_changed)
2627b7090b4SJohannes Berg 		local->ops->bss_info_changed(&local->hw, &sdata->vif,
2637b7090b4SJohannes Berg 					     &sdata->vif.bss_conf, changed);
2647b7090b4SJohannes Berg 	trace_drv_return_void(local);
2657b7090b4SJohannes Berg }
2667b7090b4SJohannes Berg 
ieee80211_vif_cfg_change_notify(struct ieee80211_sub_if_data * sdata,u64 changed)2677b7090b4SJohannes Berg void ieee80211_vif_cfg_change_notify(struct ieee80211_sub_if_data *sdata,
2687b7090b4SJohannes Berg 				     u64 changed)
2697b7090b4SJohannes Berg {
2707b7090b4SJohannes Berg 	struct ieee80211_local *local = sdata->local;
2717b7090b4SJohannes Berg 
2727b7090b4SJohannes Berg 	WARN_ON_ONCE(changed & ~BSS_CHANGED_VIF_CFG_FLAGS);
2737b7090b4SJohannes Berg 
2747b7090b4SJohannes Berg 	if (!changed || sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2757b7090b4SJohannes Berg 		return;
2767b7090b4SJohannes Berg 
2777b7090b4SJohannes Berg 	drv_vif_cfg_changed(local, sdata, changed);
2787b7090b4SJohannes Berg }
2797b7090b4SJohannes Berg 
ieee80211_link_info_change_notify(struct ieee80211_sub_if_data * sdata,struct ieee80211_link_data * link,u64 changed)2807b7090b4SJohannes Berg void ieee80211_link_info_change_notify(struct ieee80211_sub_if_data *sdata,
281d8675a63SJohannes Berg 				       struct ieee80211_link_data *link,
282d8675a63SJohannes Berg 				       u64 changed)
2837b7090b4SJohannes Berg {
2847b7090b4SJohannes Berg 	struct ieee80211_local *local = sdata->local;
2857b7090b4SJohannes Berg 
2867b7090b4SJohannes Berg 	WARN_ON_ONCE(changed & BSS_CHANGED_VIF_CFG_FLAGS);
2877b7090b4SJohannes Berg 
2887b7090b4SJohannes Berg 	if (!changed || sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
2897b7090b4SJohannes Berg 		return;
2907b7090b4SJohannes Berg 
291591e73eeSJohannes Berg 	if (!check_sdata_in_driver(sdata))
292591e73eeSJohannes Berg 		return;
293591e73eeSJohannes Berg 
294d8675a63SJohannes Berg 	drv_link_info_changed(local, sdata, link->conf, link->link_id, changed);
2952c8dccc7SJohannes Berg }
2962c8dccc7SJohannes Berg 
ieee80211_reset_erp_info(struct ieee80211_sub_if_data * sdata)29715ddba5fSAnjaneyulu u64 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
2982c8dccc7SJohannes Berg {
299bda3933aSJohannes Berg 	sdata->vif.bss_conf.use_cts_prot = false;
300bda3933aSJohannes Berg 	sdata->vif.bss_conf.use_short_preamble = false;
301bda3933aSJohannes Berg 	sdata->vif.bss_conf.use_short_slot = false;
3027a5158efSJohannes Berg 	return BSS_CHANGED_ERP_CTS_PROT |
3037a5158efSJohannes Berg 	       BSS_CHANGED_ERP_PREAMBLE |
3047a5158efSJohannes Berg 	       BSS_CHANGED_ERP_SLOT;
3052c8dccc7SJohannes Berg }
3062c8dccc7SJohannes Berg 
307ba780cb0SJohannes Berg /* context: requires softirqs disabled */
ieee80211_handle_queued_frames(struct ieee80211_local * local)30892df1422SJohannes Berg void ieee80211_handle_queued_frames(struct ieee80211_local *local)
3092c8dccc7SJohannes Berg {
3102c8dccc7SJohannes Berg 	struct sk_buff *skb;
3112c8dccc7SJohannes Berg 
3122c8dccc7SJohannes Berg 	while ((skb = skb_dequeue(&local->skb_queue)) ||
3132c8dccc7SJohannes Berg 	       (skb = skb_dequeue(&local->skb_queue_unreliable))) {
3142c8dccc7SJohannes Berg 		switch (skb->pkt_type) {
3152c8dccc7SJohannes Berg 		case IEEE80211_RX_MSG:
3162c8dccc7SJohannes Berg 			/* Clear skb->pkt_type in order to not confuse kernel
3172c8dccc7SJohannes Berg 			 * netstack. */
3182c8dccc7SJohannes Berg 			skb->pkt_type = 0;
319005e472bSJohannes Berg 			ieee80211_rx(&local->hw, skb);
3202c8dccc7SJohannes Berg 			break;
3212c8dccc7SJohannes Berg 		case IEEE80211_TX_STATUS_MSG:
3222c8dccc7SJohannes Berg 			skb->pkt_type = 0;
323005e472bSJohannes Berg 			ieee80211_tx_status(&local->hw, skb);
3242c8dccc7SJohannes Berg 			break;
325f4ea83ddSJohannes Berg 		default:
3265e3f3089SLarry Finger 			WARN(1, "mac80211: Packet is of unknown type %d\n",
3275e3f3089SLarry Finger 			     skb->pkt_type);
3282c8dccc7SJohannes Berg 			dev_kfree_skb(skb);
3292c8dccc7SJohannes Berg 			break;
3302c8dccc7SJohannes Berg 		}
3312c8dccc7SJohannes Berg 	}
3322c8dccc7SJohannes Berg }
3332c8dccc7SJohannes Berg 
ieee80211_tasklet_handler(struct tasklet_struct * t)33492df1422SJohannes Berg static void ieee80211_tasklet_handler(struct tasklet_struct *t)
33592df1422SJohannes Berg {
33692df1422SJohannes Berg 	struct ieee80211_local *local = from_tasklet(local, t, tasklet);
33792df1422SJohannes Berg 
33892df1422SJohannes Berg 	ieee80211_handle_queued_frames(local);
33992df1422SJohannes Berg }
34092df1422SJohannes Berg 
ieee80211_restart_work(struct work_struct * work)341f2753ddbSJohannes Berg static void ieee80211_restart_work(struct work_struct *work)
342f2753ddbSJohannes Berg {
343f2753ddbSJohannes Berg 	struct ieee80211_local *local =
344f2753ddbSJohannes Berg 		container_of(work, struct ieee80211_local, restart_work);
345ab499db8SMichal Kazior 	struct ieee80211_sub_if_data *sdata;
346f5baf287SJohannes Berg 	int ret;
347f2753ddbSJohannes Berg 
348bc86863dSStanislaw Gruszka 	flush_workqueue(local->workqueue);
34945daaa13SIlan Peer 
35045daaa13SIlan Peer 	rtnl_lock();
351276e189fSJohannes Berg 	/* we might do interface manipulations, so need both */
352276e189fSJohannes Berg 	wiphy_lock(local->hw.wiphy);
353bc86863dSStanislaw Gruszka 
354d43c6b6eSDavid Spinadel 	WARN(test_bit(SCAN_HW_SCANNING, &local->scanning),
355bc86863dSStanislaw Gruszka 	     "%s called with hardware scan in progress\n", __func__);
356bc86863dSStanislaw Gruszka 
357f3ffb6c3SEmmanuel Grumbach 	list_for_each_entry(sdata, &local->interfaces, list) {
358f3ffb6c3SEmmanuel Grumbach 		/*
359f3ffb6c3SEmmanuel Grumbach 		 * XXX: there may be more work for other vif types and even
360f3ffb6c3SEmmanuel Grumbach 		 * for station mode: a good thing would be to run most of
361f3ffb6c3SEmmanuel Grumbach 		 * the iface type's dependent _stop (ieee80211_mg_stop,
362f3ffb6c3SEmmanuel Grumbach 		 * ieee80211_ibss_stop) etc...
363f3ffb6c3SEmmanuel Grumbach 		 * For now, fix only the specific bug that was seen: race
364f3ffb6c3SEmmanuel Grumbach 		 * between csa_connection_drop_work and us.
365f3ffb6c3SEmmanuel Grumbach 		 */
366f3ffb6c3SEmmanuel Grumbach 		if (sdata->vif.type == NL80211_IFTYPE_STATION) {
367f3ffb6c3SEmmanuel Grumbach 			/*
368f3ffb6c3SEmmanuel Grumbach 			 * This worker is scheduled from the iface worker that
369f3ffb6c3SEmmanuel Grumbach 			 * runs on mac80211's workqueue, so we can't be
370f3ffb6c3SEmmanuel Grumbach 			 * scheduling this worker after the cancel right here.
371f3ffb6c3SEmmanuel Grumbach 			 * The exception is ieee80211_chswitch_done.
372f3ffb6c3SEmmanuel Grumbach 			 * Then we can have a race...
373f3ffb6c3SEmmanuel Grumbach 			 */
3744b8d43f1SJohannes Berg 			wiphy_work_cancel(local->hw.wiphy,
3754b8d43f1SJohannes Berg 					  &sdata->u.mgd.csa_connection_drop_work);
376d0a9123eSJohannes Berg 			if (sdata->vif.bss_conf.csa_active) {
3777dd231ebSNaftali Goldstein 				sdata_lock(sdata);
3787dd231ebSNaftali Goldstein 				ieee80211_sta_connection_lost(sdata,
37953da4c45SJohannes Berg 							      WLAN_REASON_UNSPECIFIED,
38053da4c45SJohannes Berg 							      false);
3817dd231ebSNaftali Goldstein 				sdata_unlock(sdata);
3827dd231ebSNaftali Goldstein 			}
383f3ffb6c3SEmmanuel Grumbach 		}
384ab499db8SMichal Kazior 		flush_delayed_work(&sdata->dec_tailroom_needed_wk);
385f3ffb6c3SEmmanuel Grumbach 	}
386bc86863dSStanislaw Gruszka 	ieee80211_scan_cancel(local);
387470f4d61SEliad Peller 
388470f4d61SEliad Peller 	/* make sure any new ROC will consider local->in_reconfig */
38956dd205fSJohannes Berg 	wiphy_delayed_work_flush(local->hw.wiphy, &local->roc_work);
39056dd205fSJohannes Berg 	wiphy_work_flush(local->hw.wiphy, &local->hw_roc_done);
391470f4d61SEliad Peller 
3922316380fSSara Sharon 	/* wait for all packet processing to be done */
3932316380fSSara Sharon 	synchronize_net();
3942316380fSSara Sharon 
395f5baf287SJohannes Berg 	ret = ieee80211_reconfig(local);
396a05829a7SJohannes Berg 	wiphy_unlock(local->hw.wiphy);
397f5baf287SJohannes Berg 
398f5baf287SJohannes Berg 	if (ret)
399f5baf287SJohannes Berg 		cfg80211_shutdown_all_interfaces(local->hw.wiphy);
400f5baf287SJohannes Berg 
401f2753ddbSJohannes Berg 	rtnl_unlock();
402f2753ddbSJohannes Berg }
403f2753ddbSJohannes Berg 
ieee80211_restart_hw(struct ieee80211_hw * hw)404f2753ddbSJohannes Berg void ieee80211_restart_hw(struct ieee80211_hw *hw)
405f2753ddbSJohannes Berg {
406f2753ddbSJohannes Berg 	struct ieee80211_local *local = hw_to_local(hw);
407f2753ddbSJohannes Berg 
408b5878a2dSJohannes Berg 	trace_api_restart_hw(local);
409b5878a2dSJohannes Berg 
410b196d031SMichael Buesch 	wiphy_info(hw->wiphy,
411b196d031SMichael Buesch 		   "Hardware restart was requested\n");
412b196d031SMichael Buesch 
41318145c69SJohn W. Linville 	/* use this reason, ieee80211_reconfig will unblock it */
414445ea4e8SJohannes Berg 	ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
415cca07b00SLuciano Coelho 					IEEE80211_QUEUE_STOP_REASON_SUSPEND,
416cca07b00SLuciano Coelho 					false);
417f2753ddbSJohannes Berg 
41804800adaSArik Nemtsov 	/*
41904800adaSArik Nemtsov 	 * Stop all Rx during the reconfig. We don't want state changes
42004800adaSArik Nemtsov 	 * or driver callbacks while this is in progress.
42104800adaSArik Nemtsov 	 */
42204800adaSArik Nemtsov 	local->in_reconfig = true;
42304800adaSArik Nemtsov 	barrier();
42404800adaSArik Nemtsov 
42543d6df00SEliad Peller 	queue_work(system_freezable_wq, &local->restart_work);
426f2753ddbSJohannes Berg }
427f2753ddbSJohannes Berg EXPORT_SYMBOL(ieee80211_restart_hw);
428f2753ddbSJohannes Berg 
42926b36cfeSJohn W. Linville #ifdef CONFIG_INET
ieee80211_ifa_changed(struct notifier_block * nb,unsigned long data,void * arg)4302b2c009eSJuuso Oikarinen static int ieee80211_ifa_changed(struct notifier_block *nb,
4312b2c009eSJuuso Oikarinen 				 unsigned long data, void *arg)
4322b2c009eSJuuso Oikarinen {
4332b2c009eSJuuso Oikarinen 	struct in_ifaddr *ifa = arg;
4342b2c009eSJuuso Oikarinen 	struct ieee80211_local *local =
4352b2c009eSJuuso Oikarinen 		container_of(nb, struct ieee80211_local,
4362b2c009eSJuuso Oikarinen 			     ifa_notifier);
4372b2c009eSJuuso Oikarinen 	struct net_device *ndev = ifa->ifa_dev->dev;
4382b2c009eSJuuso Oikarinen 	struct wireless_dev *wdev = ndev->ieee80211_ptr;
43968542962SJuuso Oikarinen 	struct in_device *idev;
4402b2c009eSJuuso Oikarinen 	struct ieee80211_sub_if_data *sdata;
441f276e20bSJohannes Berg 	struct ieee80211_vif_cfg *vif_cfg;
4422b2c009eSJuuso Oikarinen 	struct ieee80211_if_managed *ifmgd;
44368542962SJuuso Oikarinen 	int c = 0;
4442b2c009eSJuuso Oikarinen 
4452b2c009eSJuuso Oikarinen 	/* Make sure it's our interface that got changed */
4462b2c009eSJuuso Oikarinen 	if (!wdev)
4472b2c009eSJuuso Oikarinen 		return NOTIFY_DONE;
4482b2c009eSJuuso Oikarinen 
449f34056c3SJohannes Berg 	if (wdev->wiphy != local->hw.wiphy || !wdev->registered)
4502b2c009eSJuuso Oikarinen 		return NOTIFY_DONE;
4512b2c009eSJuuso Oikarinen 
4522b2c009eSJuuso Oikarinen 	sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
453f276e20bSJohannes Berg 	vif_cfg = &sdata->vif.cfg;
4542b2c009eSJuuso Oikarinen 
4552b2c009eSJuuso Oikarinen 	/* ARP filtering is only supported in managed mode */
4562b2c009eSJuuso Oikarinen 	if (sdata->vif.type != NL80211_IFTYPE_STATION)
4572b2c009eSJuuso Oikarinen 		return NOTIFY_DONE;
4582b2c009eSJuuso Oikarinen 
45995ae6b22SEric Dumazet 	idev = __in_dev_get_rtnl(sdata->dev);
46068542962SJuuso Oikarinen 	if (!idev)
46168542962SJuuso Oikarinen 		return NOTIFY_DONE;
46268542962SJuuso Oikarinen 
4632b2c009eSJuuso Oikarinen 	ifmgd = &sdata->u.mgd;
464f34056c3SJohannes Berg 
465f34056c3SJohannes Berg 	/*
466f34056c3SJohannes Berg 	 * The nested here is needed to convince lockdep that this is
467f34056c3SJohannes Berg 	 * all OK. Yes, we lock the wiphy mutex here while we already
468f34056c3SJohannes Berg 	 * hold the notifier rwsem, that's the normal case. And yes,
469f34056c3SJohannes Berg 	 * we also acquire the notifier rwsem again when unregistering
470f34056c3SJohannes Berg 	 * a netdev while we already hold the wiphy mutex, so it does
471f34056c3SJohannes Berg 	 * look like a typical ABBA deadlock.
472f34056c3SJohannes Berg 	 *
473f34056c3SJohannes Berg 	 * However, both of these things happen with the RTNL held
474f34056c3SJohannes Berg 	 * already. Therefore, they can't actually happen, since the
475f34056c3SJohannes Berg 	 * lock orders really are ABC and ACB, which is fine due to
476f34056c3SJohannes Berg 	 * the RTNL (A).
477f34056c3SJohannes Berg 	 *
478f34056c3SJohannes Berg 	 * We still need to prevent recursion, which is accomplished
479f34056c3SJohannes Berg 	 * by the !wdev->registered check above.
480f34056c3SJohannes Berg 	 */
481f34056c3SJohannes Berg 	mutex_lock_nested(&local->hw.wiphy->mtx, 1);
482f34056c3SJohannes Berg 	__acquire(&local->hw.wiphy->mtx);
4838d61ffa5SJohannes Berg 	sdata_lock(sdata);
48468542962SJuuso Oikarinen 
485f276e20bSJohannes Berg 	/* Copy the addresses to the vif config list */
4862638eb8bSFlorian Westphal 	ifa = rtnl_dereference(idev->ifa_list);
4870f19b41eSJohannes Berg 	while (ifa) {
4880f19b41eSJohannes Berg 		if (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN)
489f276e20bSJohannes Berg 			vif_cfg->arp_addr_list[c] = ifa->ifa_address;
4902638eb8bSFlorian Westphal 		ifa = rtnl_dereference(ifa->ifa_next);
49168542962SJuuso Oikarinen 		c++;
49268542962SJuuso Oikarinen 	}
49368542962SJuuso Oikarinen 
494f276e20bSJohannes Berg 	vif_cfg->arp_addr_cnt = c;
49568542962SJuuso Oikarinen 
49653d69c39SEliad Peller 	/* Configure driver only if associated (which also implies it is up) */
4970f19b41eSJohannes Berg 	if (ifmgd->associated)
4987b7090b4SJohannes Berg 		ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_ARP_FILTER);
49968542962SJuuso Oikarinen 
5008d61ffa5SJohannes Berg 	sdata_unlock(sdata);
501f34056c3SJohannes Berg 	wiphy_unlock(local->hw.wiphy);
5022b2c009eSJuuso Oikarinen 
5038bd811aaSZhao, Gang 	return NOTIFY_OK;
5042b2c009eSJuuso Oikarinen }
50526b36cfeSJohn W. Linville #endif
5062b2c009eSJuuso Oikarinen 
507a65240c1SJohannes Berg #if IS_ENABLED(CONFIG_IPV6)
ieee80211_ifa6_changed(struct notifier_block * nb,unsigned long data,void * arg)508a65240c1SJohannes Berg static int ieee80211_ifa6_changed(struct notifier_block *nb,
509a65240c1SJohannes Berg 				  unsigned long data, void *arg)
510a65240c1SJohannes Berg {
511a65240c1SJohannes Berg 	struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg;
512a65240c1SJohannes Berg 	struct inet6_dev *idev = ifa->idev;
513a65240c1SJohannes Berg 	struct net_device *ndev = ifa->idev->dev;
514a65240c1SJohannes Berg 	struct ieee80211_local *local =
515a65240c1SJohannes Berg 		container_of(nb, struct ieee80211_local, ifa6_notifier);
516a65240c1SJohannes Berg 	struct wireless_dev *wdev = ndev->ieee80211_ptr;
517a65240c1SJohannes Berg 	struct ieee80211_sub_if_data *sdata;
518a65240c1SJohannes Berg 
519a65240c1SJohannes Berg 	/* Make sure it's our interface that got changed */
520a65240c1SJohannes Berg 	if (!wdev || wdev->wiphy != local->hw.wiphy)
521a65240c1SJohannes Berg 		return NOTIFY_DONE;
522a65240c1SJohannes Berg 
523a65240c1SJohannes Berg 	sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
524a65240c1SJohannes Berg 
525a65240c1SJohannes Berg 	/*
526a65240c1SJohannes Berg 	 * For now only support station mode. This is mostly because
527a65240c1SJohannes Berg 	 * doing AP would have to handle AP_VLAN in some way ...
528a65240c1SJohannes Berg 	 */
529a65240c1SJohannes Berg 	if (sdata->vif.type != NL80211_IFTYPE_STATION)
530a65240c1SJohannes Berg 		return NOTIFY_DONE;
531a65240c1SJohannes Berg 
532a65240c1SJohannes Berg 	drv_ipv6_addr_change(local, sdata, idev);
533a65240c1SJohannes Berg 
5348bd811aaSZhao, Gang 	return NOTIFY_OK;
535a65240c1SJohannes Berg }
536a65240c1SJohannes Berg #endif
537a65240c1SJohannes Berg 
5382e161f78SJohannes Berg /* There isn't a lot of sense in it, but you can transmit anything you like */
5392e161f78SJohannes Berg static const struct ieee80211_txrx_stypes
5402e161f78SJohannes Berg ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
5412e161f78SJohannes Berg 	[NL80211_IFTYPE_ADHOC] = {
5422e161f78SJohannes Berg 		.tx = 0xffff,
5433bfda62cSWill Hawkins 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5443bfda62cSWill Hawkins 			BIT(IEEE80211_STYPE_AUTH >> 4) |
54541e31b8bSAntonio Quartulli 			BIT(IEEE80211_STYPE_DEAUTH >> 4) |
54641e31b8bSAntonio Quartulli 			BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
5472e161f78SJohannes Berg 	},
5482e161f78SJohannes Berg 	[NL80211_IFTYPE_STATION] = {
5492e161f78SJohannes Berg 		.tx = 0xffff,
550ff74c51eSIlan Peer 		/*
551ff74c51eSIlan Peer 		 * To support Pre Association Security Negotiation (PASN) while
552ff74c51eSIlan Peer 		 * already associated to one AP, allow user space to register to
553ff74c51eSIlan Peer 		 * Rx authentication frames, so that the user space logic would
554ff74c51eSIlan Peer 		 * be able to receive/handle authentication frames from a
555ff74c51eSIlan Peer 		 * different AP as part of PASN.
556ff74c51eSIlan Peer 		 * It is expected that user space would intelligently register
557ff74c51eSIlan Peer 		 * for Rx authentication frames, i.e., only when PASN is used
558ff74c51eSIlan Peer 		 * and configure a match filter only for PASN authentication
559ff74c51eSIlan Peer 		 * algorithm, as otherwise the MLME functionality of mac80211
560ff74c51eSIlan Peer 		 * would be broken.
561ff74c51eSIlan Peer 		 */
5622e161f78SJohannes Berg 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
563ff74c51eSIlan Peer 			BIT(IEEE80211_STYPE_AUTH >> 4) |
5642e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
5652e161f78SJohannes Berg 	},
5662e161f78SJohannes Berg 	[NL80211_IFTYPE_AP] = {
5672e161f78SJohannes Berg 		.tx = 0xffff,
5682e161f78SJohannes Berg 		.rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5692e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5702e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5712e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5722e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_AUTH >> 4) |
5732e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_DEAUTH >> 4) |
5742e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_ACTION >> 4),
5752e161f78SJohannes Berg 	},
5762e161f78SJohannes Berg 	[NL80211_IFTYPE_AP_VLAN] = {
5772e161f78SJohannes Berg 		/* copy AP */
5782e161f78SJohannes Berg 		.tx = 0xffff,
5792e161f78SJohannes Berg 		.rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5802e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5812e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5822e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5832e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_AUTH >> 4) |
5842e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_DEAUTH >> 4) |
5852e161f78SJohannes Berg 			BIT(IEEE80211_STYPE_ACTION >> 4),
5862e161f78SJohannes Berg 	},
5872ca27bcfSJohannes Berg 	[NL80211_IFTYPE_P2P_CLIENT] = {
5882ca27bcfSJohannes Berg 		.tx = 0xffff,
5892ca27bcfSJohannes Berg 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
5902ca27bcfSJohannes Berg 			BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
5912ca27bcfSJohannes Berg 	},
5922ca27bcfSJohannes Berg 	[NL80211_IFTYPE_P2P_GO] = {
5932ca27bcfSJohannes Berg 		.tx = 0xffff,
5942ca27bcfSJohannes Berg 		.rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
5952ca27bcfSJohannes Berg 			BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
5962ca27bcfSJohannes Berg 			BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
5972ca27bcfSJohannes Berg 			BIT(IEEE80211_STYPE_DISASSOC >> 4) |
5982ca27bcfSJohannes Berg 			BIT(IEEE80211_STYPE_AUTH >> 4) |
5992ca27bcfSJohannes Berg 			BIT(IEEE80211_STYPE_DEAUTH >> 4) |
6002ca27bcfSJohannes Berg 			BIT(IEEE80211_STYPE_ACTION >> 4),
6012ca27bcfSJohannes Berg 	},
602c7108a71SJavier Cardona 	[NL80211_IFTYPE_MESH_POINT] = {
603c7108a71SJavier Cardona 		.tx = 0xffff,
60471839121SJavier Cardona 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
60571839121SJavier Cardona 			BIT(IEEE80211_STYPE_AUTH >> 4) |
60671839121SJavier Cardona 			BIT(IEEE80211_STYPE_DEAUTH >> 4),
607c7108a71SJavier Cardona 	},
608f142c6b9SJohannes Berg 	[NL80211_IFTYPE_P2P_DEVICE] = {
609f142c6b9SJohannes Berg 		.tx = 0xffff,
610f142c6b9SJohannes Berg 		.rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
611f142c6b9SJohannes Berg 			BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
612f142c6b9SJohannes Berg 	},
6132e161f78SJohannes Berg };
6142e161f78SJohannes Berg 
615ef96a842SBen Greear static const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
616ef96a842SBen Greear 	.ampdu_params_info = IEEE80211_HT_AMPDU_PARM_FACTOR |
617ef96a842SBen Greear 			     IEEE80211_HT_AMPDU_PARM_DENSITY,
618ef96a842SBen Greear 
619ef96a842SBen Greear 	.cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
620ef96a842SBen Greear 				IEEE80211_HT_CAP_MAX_AMSDU |
621bc0784d9SBen Greear 				IEEE80211_HT_CAP_SGI_20 |
622a2e7495dSPawel Kulakowski 				IEEE80211_HT_CAP_SGI_40 |
623d9bb4108SSergey Matyukevich 				IEEE80211_HT_CAP_TX_STBC |
624d9bb4108SSergey Matyukevich 				IEEE80211_HT_CAP_RX_STBC |
6259a07bf50SJouni Malinen 				IEEE80211_HT_CAP_LDPC_CODING |
6269a07bf50SJouni Malinen 				IEEE80211_HT_CAP_40MHZ_INTOLERANT),
627ef96a842SBen Greear 	.mcs = {
628ef96a842SBen Greear 		.rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
629ef96a842SBen Greear 			     0xff, 0xff, 0xff, 0xff, 0xff, },
630ef96a842SBen Greear 	},
631ef96a842SBen Greear };
632ef96a842SBen Greear 
633dd5ecfeaSJohannes Berg static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
634dd5ecfeaSJohannes Berg 	.vht_cap_info =
635dd5ecfeaSJohannes Berg 		cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC |
636dd5ecfeaSJohannes Berg 			    IEEE80211_VHT_CAP_SHORT_GI_80 |
637dd5ecfeaSJohannes Berg 			    IEEE80211_VHT_CAP_SHORT_GI_160 |
63867d1ba8aSDanek Duvall 			    IEEE80211_VHT_CAP_RXSTBC_MASK |
639dd5ecfeaSJohannes Berg 			    IEEE80211_VHT_CAP_TXSTBC |
640dd5ecfeaSJohannes Berg 			    IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
641dd5ecfeaSJohannes Berg 			    IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
642dd5ecfeaSJohannes Berg 			    IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
643dd5ecfeaSJohannes Berg 			    IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
644dd5ecfeaSJohannes Berg 			    IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
645dd5ecfeaSJohannes Berg 	.supp_mcs = {
646dd5ecfeaSJohannes Berg 		.rx_mcs_map = cpu_to_le16(~0),
647dd5ecfeaSJohannes Berg 		.tx_mcs_map = cpu_to_le16(~0),
648dd5ecfeaSJohannes Berg 	},
649dd5ecfeaSJohannes Berg };
650dd5ecfeaSJohannes Berg 
ieee80211_alloc_hw_nm(size_t priv_data_len,const struct ieee80211_ops * ops,const char * requested_name)651ad28757eSBen Greear struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,
652ad28757eSBen Greear 					   const struct ieee80211_ops *ops,
653ad28757eSBen Greear 					   const char *requested_name)
6542c8dccc7SJohannes Berg {
6552c8dccc7SJohannes Berg 	struct ieee80211_local *local;
65696f5e66eSJohannes Berg 	int priv_size, i;
6572c8dccc7SJohannes Berg 	struct wiphy *wiphy;
658fe57d9f5SJohannes Berg 	bool use_chanctx;
6592c8dccc7SJohannes Berg 
660c0af0734SJohannes Berg 	if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config ||
661c0af0734SJohannes Berg 		    !ops->add_interface || !ops->remove_interface ||
662107395f9SAlexander Wetzel 		    !ops->configure_filter || !ops->wake_tx_queue))
663c0af0734SJohannes Berg 		return NULL;
664c0af0734SJohannes Berg 
665f09603a2SJohannes Berg 	if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
666f09603a2SJohannes Berg 		return NULL;
667f09603a2SJohannes Berg 
6687b7090b4SJohannes Berg 	if (WARN_ON(!!ops->link_info_changed != !!ops->vif_cfg_changed ||
6697b7090b4SJohannes Berg 		    (ops->link_info_changed && ops->bss_info_changed)))
6707b7090b4SJohannes Berg 		return NULL;
6717b7090b4SJohannes Berg 
672e269d860SJohannes Berg 	/* check all or no channel context operations exist */
673e269d860SJohannes Berg 	i = !!ops->add_chanctx + !!ops->remove_chanctx +
674e269d860SJohannes Berg 	    !!ops->change_chanctx + !!ops->assign_vif_chanctx +
675e269d860SJohannes Berg 	    !!ops->unassign_vif_chanctx;
676e269d860SJohannes Berg 	if (WARN_ON(i != 0 && i != 5))
677e269d860SJohannes Berg 		return NULL;
678fe57d9f5SJohannes Berg 	use_chanctx = i == 5;
679e269d860SJohannes Berg 
6802c8dccc7SJohannes Berg 	/* Ensure 32-byte alignment of our private data and hw private data.
6812c8dccc7SJohannes Berg 	 * We use the wiphy priv data for both our ieee80211_local and for
6822c8dccc7SJohannes Berg 	 * the driver's private data
6832c8dccc7SJohannes Berg 	 *
6842c8dccc7SJohannes Berg 	 * In memory it'll be like this:
6852c8dccc7SJohannes Berg 	 *
6862c8dccc7SJohannes Berg 	 * +-------------------------+
6872c8dccc7SJohannes Berg 	 * | struct wiphy	    |
6882c8dccc7SJohannes Berg 	 * +-------------------------+
6892c8dccc7SJohannes Berg 	 * | struct ieee80211_local  |
6902c8dccc7SJohannes Berg 	 * +-------------------------+
6912c8dccc7SJohannes Berg 	 * | driver's private data   |
6922c8dccc7SJohannes Berg 	 * +-------------------------+
6932c8dccc7SJohannes Berg 	 *
6942c8dccc7SJohannes Berg 	 */
6951ce8e7b5SEric Dumazet 	priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
6962c8dccc7SJohannes Berg 
697ad28757eSBen Greear 	wiphy = wiphy_new_nm(&mac80211_config_ops, priv_size, requested_name);
6982c8dccc7SJohannes Berg 
6992c8dccc7SJohannes Berg 	if (!wiphy)
7002c8dccc7SJohannes Berg 		return NULL;
7012c8dccc7SJohannes Berg 
7022e161f78SJohannes Berg 	wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
7032e161f78SJohannes Berg 
704207aba60SJohannes Berg 	wiphy->privid = mac80211_wiphy_privid;
705207aba60SJohannes Berg 
7069bc383deSJohannes Berg 	wiphy->flags |= WIPHY_FLAG_NETNS_OK |
7079bc383deSJohannes Berg 			WIPHY_FLAG_4ADDR_AP |
708ee971924SJohannes Berg 			WIPHY_FLAG_4ADDR_STATION |
7097c4ef712SJohannes Berg 			WIPHY_FLAG_REPORTS_OBSS |
71081ddbb5cSJohannes Berg 			WIPHY_FLAG_OFFCHAN_TX;
71181ddbb5cSJohannes Berg 
7128fa180bbSYan-Hsuan Chuang 	if (!use_chanctx || ops->remain_on_channel)
71381ddbb5cSJohannes Berg 		wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
714207aba60SJohannes Berg 
715b292219fSJohannes Berg 	wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
7166b8ece3aSJouni Malinen 			   NL80211_FEATURE_SAE |
7171ea6f9c0SJohannes Berg 			   NL80211_FEATURE_HT_IBSS |
718a6dad6a2SThomas Pedersen 			   NL80211_FEATURE_VIF_TXPOWER |
719b5dfae02SBen Greear 			   NL80211_FEATURE_MAC_ON_CREATE |
72090f9ba9bSJohannes Berg 			   NL80211_FEATURE_USERSPACE_MPM |
72190f9ba9bSJohannes Berg 			   NL80211_FEATURE_FULL_AP_CLIENT_STATE;
722f3ca52aaSJouni Malinen 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_STA);
723018f6fbfSDenis Kenzior 	wiphy_ext_feature_set(wiphy,
724018f6fbfSDenis Kenzior 			      NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211);
7257f3f96ceSMarkus Theil 	wiphy_ext_feature_set(wiphy,
7267f3f96ceSMarkus Theil 			      NL80211_EXT_FEATURE_CONTROL_PORT_NO_PREAUTH);
7272032f3b2SThomas Pedersen 	wiphy_ext_feature_set(wiphy,
728a7528198SMarkus Theil 			      NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211_TX_STATUS);
729a7528198SMarkus Theil 	wiphy_ext_feature_set(wiphy,
7302032f3b2SThomas Pedersen 			      NL80211_EXT_FEATURE_SCAN_FREQ_KHZ);
7313c06e91bSJames Prestwood 	wiphy_ext_feature_set(wiphy,
7323c06e91bSJames Prestwood 			      NL80211_EXT_FEATURE_POWERED_ADDR_CHANGE);
733a729cff8SJohannes Berg 
734b9771d41SJohannes Berg 	if (!ops->hw_scan) {
7355c95b940SAntonio Quartulli 		wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
7365c95b940SAntonio Quartulli 				   NL80211_FEATURE_AP_SCAN;
737b9771d41SJohannes Berg 		/*
738b9771d41SJohannes Berg 		 * if the driver behaves correctly using the probe request
739b9771d41SJohannes Berg 		 * (template) from mac80211, then both of these should be
740b9771d41SJohannes Berg 		 * supported even with hw scan - but let drivers opt in.
741b9771d41SJohannes Berg 		 */
742b9771d41SJohannes Berg 		wiphy_ext_feature_set(wiphy,
743b9771d41SJohannes Berg 				      NL80211_EXT_FEATURE_SCAN_RANDOM_SN);
744b9771d41SJohannes Berg 		wiphy_ext_feature_set(wiphy,
745b9771d41SJohannes Berg 				      NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT);
746b9771d41SJohannes Berg 	}
747cd2bb512SSam Leffler 
748207aba60SJohannes Berg 	if (!ops->set_key)
749207aba60SJohannes Berg 		wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
75018a83659SJohannes Berg 
7512fe4a29aSToke Høiland-Jørgensen 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_TXQS);
752f278ce4fSEmmanuel Grumbach 	wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_RRM);
753f278ce4fSEmmanuel Grumbach 
7540c1ad2caSJohannes Berg 	wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
7552c8dccc7SJohannes Berg 
7562c8dccc7SJohannes Berg 	local = wiphy_priv(wiphy);
757de95a54bSJohannes Berg 
7587bedd0cfSJohannes Berg 	if (sta_info_init(local))
7597bedd0cfSJohannes Berg 		goto err_free;
7607bedd0cfSJohannes Berg 
7612c8dccc7SJohannes Berg 	local->hw.wiphy = wiphy;
7622c8dccc7SJohannes Berg 
7631ce8e7b5SEric Dumazet 	local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
7642c8dccc7SJohannes Berg 
7652c8dccc7SJohannes Berg 	local->ops = ops;
766fe57d9f5SJohannes Berg 	local->use_chanctx = use_chanctx;
7672c8dccc7SJohannes Berg 
76870e53669SWen Gong 	/*
76970e53669SWen Gong 	 * We need a bit of data queued to build aggregates properly, so
77070e53669SWen Gong 	 * instruct the TCP stack to allow more than a single ms of data
77170e53669SWen Gong 	 * to be queued in the stack. The value is a bit-shift of 1
7725c14a4d0SToke Høiland-Jørgensen 	 * second, so 7 is ~8ms of queued data. Only affects local TCP
77370e53669SWen Gong 	 * sockets.
77470e53669SWen Gong 	 * This is the default, anyhow - drivers may need to override it
77570e53669SWen Gong 	 * for local reasons (longer buffers, longer completion time, or
77670e53669SWen Gong 	 * similar).
77770e53669SWen Gong 	 */
7785c14a4d0SToke Høiland-Jørgensen 	local->hw.tx_sk_pacing_shift = 7;
77970e53669SWen Gong 
780e6a9854bSJohannes Berg 	/* set up some defaults */
781e6a9854bSJohannes Berg 	local->hw.queues = 1;
782e6a9854bSJohannes Berg 	local->hw.max_rates = 1;
78378be49ecSHelmut Schaa 	local->hw.max_report_rates = 0;
784b8042b3dSJohannes Berg 	local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HT;
785b8042b3dSJohannes Berg 	local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HT;
7863a25a8c8SJohannes Berg 	local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
787b9a5f8caSJouni Malinen 	local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
788b9a5f8caSJouni Malinen 	local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
789ac55d2feSJohannes Berg 	local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
790ac55d2feSJohannes Berg 					 IEEE80211_RADIOTAP_MCS_HAVE_GI |
791ac55d2feSJohannes Berg 					 IEEE80211_RADIOTAP_MCS_HAVE_BW;
79251648921SJohannes Berg 	local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
79351648921SJohannes Berg 					 IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
794219c3867SAlexander Bondar 	local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
795219c3867SAlexander Bondar 	local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
79606354665SWen Gong 	local->hw.max_mtu = IEEE80211_MAX_DATA_LEN;
7971ea6f9c0SJohannes Berg 	local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
798ef96a842SBen Greear 	wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
799dd5ecfeaSJohannes Berg 	wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
8002c8dccc7SJohannes Berg 
801e9a21949SLuciano Coelho 	local->ext_capa[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF;
802e9a21949SLuciano Coelho 
803e9a21949SLuciano Coelho 	wiphy->extended_capabilities = local->ext_capa;
804e9a21949SLuciano Coelho 	wiphy->extended_capabilities_mask = local->ext_capa;
805e9a21949SLuciano Coelho 	wiphy->extended_capabilities_len =
806e9a21949SLuciano Coelho 		ARRAY_SIZE(local->ext_capa);
807e9a21949SLuciano Coelho 
8082c8dccc7SJohannes Berg 	INIT_LIST_HEAD(&local->interfaces);
809f64331d5SJohannes Berg 	INIT_LIST_HEAD(&local->mon_list);
8102f787b0bSYOSHIFUJI Hideaki / 吉藤英明 
8112f787b0bSYOSHIFUJI Hideaki / 吉藤英明 	__hw_addr_init(&local->mc_list);
8122f787b0bSYOSHIFUJI Hideaki / 吉藤英明 
813c771c9d8SJohannes Berg 	mutex_init(&local->iflist_mtx);
814a1699b75SJohannes Berg 	mutex_init(&local->mtx);
8152c8dccc7SJohannes Berg 
816ad0e2b5aSJohannes Berg 	mutex_init(&local->key_mtx);
8173b8d81e0SJohannes Berg 	spin_lock_init(&local->filter_lock);
818f9e124fbSChristian Lamparter 	spin_lock_init(&local->rx_path_lock);
819ce7c9111SKalle Valo 	spin_lock_init(&local->queue_stop_reason_lock);
820ce7c9111SKalle Valo 
82118667600SToke Høiland-Jørgensen 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
822942741daSFelix Fietkau 		INIT_LIST_HEAD(&local->active_txqs[i]);
823942741daSFelix Fietkau 		spin_lock_init(&local->active_txq_lock[i]);
824942741daSFelix Fietkau 		local->aql_txq_limit_low[i] = IEEE80211_DEFAULT_AQL_TXQ_LIMIT_L;
825942741daSFelix Fietkau 		local->aql_txq_limit_high[i] =
8263ace10f5SKan Yan 			IEEE80211_DEFAULT_AQL_TXQ_LIMIT_H;
8278e4bac06SFelix Fietkau 		atomic_set(&local->aql_ac_pending_airtime[i], 0);
82818667600SToke Høiland-Jørgensen 	}
8293ace10f5SKan Yan 
830911bde0fSToke Høiland-Jørgensen 	local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX;
8313ace10f5SKan Yan 	local->aql_threshold = IEEE80211_AQL_THRESHOLD;
8323ace10f5SKan Yan 	atomic_set(&local->aql_total_pending_airtime, 0);
83318667600SToke Høiland-Jørgensen 
834007ae9b2SAlexander Wetzel 	spin_lock_init(&local->handle_wake_tx_queue_lock);
835007ae9b2SAlexander Wetzel 
836d01a1e65SMichal Kazior 	INIT_LIST_HEAD(&local->chanctx_list);
837d01a1e65SMichal Kazior 	mutex_init(&local->chanctx_mtx);
838d01a1e65SMichal Kazior 
839d69c7a4eSJohannes Berg 	wiphy_delayed_work_init(&local->scan_work, ieee80211_scan_work);
8402c8dccc7SJohannes Berg 
841f2753ddbSJohannes Berg 	INIT_WORK(&local->restart_work, ieee80211_restart_work);
842f2753ddbSJohannes Berg 
84374d64f0aSJohannes Berg 	wiphy_work_init(&local->radar_detected_work,
844164eb02dSSimon Wunderlich 			ieee80211_dfs_radar_detected_work);
845164eb02dSSimon Wunderlich 
8463ac64beeSJohannes Berg 	INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
8470f78231bSJohannes Berg 	local->smps_mode = IEEE80211_SMPS_OFF;
8483ac64beeSJohannes Berg 
849520eb820SKalle Valo 	INIT_WORK(&local->dynamic_ps_enable_work,
850520eb820SKalle Valo 		  ieee80211_dynamic_ps_enable_work);
851520eb820SKalle Valo 	INIT_WORK(&local->dynamic_ps_disable_work,
852520eb820SKalle Valo 		  ieee80211_dynamic_ps_disable_work);
85334f11cd3SKees Cook 	timer_setup(&local->dynamic_ps_timer, ieee80211_dynamic_ps_timer, 0);
854520eb820SKalle Valo 
855e114cad7SJohannes Berg 	wiphy_work_init(&local->sched_scan_stopped_work,
85685a9994aSLuciano Coelho 			ieee80211_sched_scan_stopped_work);
85785a9994aSLuciano Coelho 
858a729cff8SJohannes Berg 	spin_lock_init(&local->ack_status_lock);
859a729cff8SJohannes Berg 	idr_init(&local->ack_status_frames);
860a729cff8SJohannes Berg 
861a6a67db2SJohannes Berg 	for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
8622a577d98SJohannes Berg 		skb_queue_head_init(&local->pending[i]);
863a6a67db2SJohannes Berg 		atomic_set(&local->agg_queue_stop[i], 0);
864a6a67db2SJohannes Berg 	}
865da1cad73SAllen Pais 	tasklet_setup(&local->tx_pending_tasklet, ieee80211_tx_pending);
866da1cad73SAllen Pais 	tasklet_setup(&local->wake_txqs_tasklet, ieee80211_wake_txqs);
867da1cad73SAllen Pais 	tasklet_setup(&local->tasklet, ieee80211_tasklet_handler);
8682c8dccc7SJohannes Berg 
8692c8dccc7SJohannes Berg 	skb_queue_head_init(&local->skb_queue);
8702c8dccc7SJohannes Berg 	skb_queue_head_init(&local->skb_queue_unreliable);
8712c8dccc7SJohannes Berg 
8728d5c2585SJohannes Berg 	ieee80211_alloc_led_names(local);
873fe67c913SJohannes Berg 
8742eb278e0SJohannes Berg 	ieee80211_roc_setup(local);
87521f83589SJohannes Berg 
87699ee7caeSJohannes Berg 	local->hw.radiotap_timestamp.units_pos = -1;
87799ee7caeSJohannes Berg 	local->hw.radiotap_timestamp.accuracy = -1;
87899ee7caeSJohannes Berg 
879005e472bSJohannes Berg 	return &local->hw;
8807bedd0cfSJohannes Berg  err_free:
8817bedd0cfSJohannes Berg 	wiphy_free(wiphy);
8827bedd0cfSJohannes Berg 	return NULL;
8832c8dccc7SJohannes Berg }
884ad28757eSBen Greear EXPORT_SYMBOL(ieee80211_alloc_hw_nm);
8852c8dccc7SJohannes Berg 
ieee80211_init_cipher_suites(struct ieee80211_local * local)8862475b1ccSMax Stepanov static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
8872c8dccc7SJohannes Berg {
8885fdb3735SArd Biesheuvel 	bool have_wep = !fips_enabled; /* FIPS does not permit the use of RC4 */
88930686bf7SJohannes Berg 	bool have_mfp = ieee80211_hw_check(&local->hw, MFP_CAPABLE);
89023a5f0afSJohannes Berg 	int r = 0, w = 0;
8912475b1ccSMax Stepanov 	u32 *suites;
89225e47c18SJohannes Berg 	static const u32 cipher_suites[] = {
8935daa8a8eSJohannes Berg 		/* keep WEP first, it may be removed below */
89425e47c18SJohannes Berg 		WLAN_CIPHER_SUITE_WEP40,
89525e47c18SJohannes Berg 		WLAN_CIPHER_SUITE_WEP104,
89625e47c18SJohannes Berg 		WLAN_CIPHER_SUITE_TKIP,
89725e47c18SJohannes Berg 		WLAN_CIPHER_SUITE_CCMP,
8982b2ba0dbSJouni Malinen 		WLAN_CIPHER_SUITE_CCMP_256,
89900b9cfa3SJouni Malinen 		WLAN_CIPHER_SUITE_GCMP,
90000b9cfa3SJouni Malinen 		WLAN_CIPHER_SUITE_GCMP_256,
90125e47c18SJohannes Berg 
90225e47c18SJohannes Berg 		/* keep last -- depends on hw flags! */
90356c52da2SJouni Malinen 		WLAN_CIPHER_SUITE_AES_CMAC,
90456c52da2SJouni Malinen 		WLAN_CIPHER_SUITE_BIP_CMAC_256,
9058ade538bSJouni Malinen 		WLAN_CIPHER_SUITE_BIP_GMAC_128,
9068ade538bSJouni Malinen 		WLAN_CIPHER_SUITE_BIP_GMAC_256,
90725e47c18SJohannes Berg 	};
9082c8dccc7SJohannes Berg 
90930686bf7SJohannes Berg 	if (ieee80211_hw_check(&local->hw, SW_CRYPTO_CONTROL) ||
910fa7e1fbcSJohannes Berg 	    local->hw.wiphy->cipher_suites) {
911fa7e1fbcSJohannes Berg 		/* If the driver advertises, or doesn't support SW crypto,
912fa7e1fbcSJohannes Berg 		 * we only need to remove WEP if necessary.
913fa7e1fbcSJohannes Berg 		 */
914fa7e1fbcSJohannes Berg 		if (have_wep)
9152475b1ccSMax Stepanov 			return 0;
9162475b1ccSMax Stepanov 
917fa7e1fbcSJohannes Berg 		/* well if it has _no_ ciphers ... fine */
918fa7e1fbcSJohannes Berg 		if (!local->hw.wiphy->n_cipher_suites)
919fa7e1fbcSJohannes Berg 			return 0;
920fa7e1fbcSJohannes Berg 
921fa7e1fbcSJohannes Berg 		/* Driver provides cipher suites, but we need to exclude WEP */
922fa7e1fbcSJohannes Berg 		suites = kmemdup(local->hw.wiphy->cipher_suites,
923fa7e1fbcSJohannes Berg 				 sizeof(u32) * local->hw.wiphy->n_cipher_suites,
924fa7e1fbcSJohannes Berg 				 GFP_KERNEL);
925fa7e1fbcSJohannes Berg 		if (!suites)
926fa7e1fbcSJohannes Berg 			return -ENOMEM;
927fa7e1fbcSJohannes Berg 
928fa7e1fbcSJohannes Berg 		for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
929fa7e1fbcSJohannes Berg 			u32 suite = local->hw.wiphy->cipher_suites[r];
930fa7e1fbcSJohannes Berg 
931fa7e1fbcSJohannes Berg 			if (suite == WLAN_CIPHER_SUITE_WEP40 ||
932fa7e1fbcSJohannes Berg 			    suite == WLAN_CIPHER_SUITE_WEP104)
933fa7e1fbcSJohannes Berg 				continue;
934fa7e1fbcSJohannes Berg 			suites[w++] = suite;
935fa7e1fbcSJohannes Berg 		}
93623a5f0afSJohannes Berg 	} else {
93723a5f0afSJohannes Berg 		/* assign the (software supported and perhaps offloaded)
93823a5f0afSJohannes Berg 		 * cipher suites
939fa7e1fbcSJohannes Berg 		 */
9402475b1ccSMax Stepanov 		local->hw.wiphy->cipher_suites = cipher_suites;
9412475b1ccSMax Stepanov 		local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
9422475b1ccSMax Stepanov 
9432475b1ccSMax Stepanov 		if (!have_mfp)
9448ade538bSJouni Malinen 			local->hw.wiphy->n_cipher_suites -= 4;
9452475b1ccSMax Stepanov 
9462475b1ccSMax Stepanov 		if (!have_wep) {
9472475b1ccSMax Stepanov 			local->hw.wiphy->cipher_suites += 2;
9482475b1ccSMax Stepanov 			local->hw.wiphy->n_cipher_suites -= 2;
9492475b1ccSMax Stepanov 		}
9502475b1ccSMax Stepanov 
951fa7e1fbcSJohannes Berg 		/* not dynamically allocated, so just return */
9522475b1ccSMax Stepanov 		return 0;
95394c78cb4SJohannes Berg 	}
9542475b1ccSMax Stepanov 
9552475b1ccSMax Stepanov 	local->hw.wiphy->cipher_suites = suites;
9562475b1ccSMax Stepanov 	local->hw.wiphy->n_cipher_suites = w;
9572475b1ccSMax Stepanov 	local->wiphy_ciphers_allocated = true;
9582475b1ccSMax Stepanov 
9592475b1ccSMax Stepanov 	return 0;
9602475b1ccSMax Stepanov }
9612475b1ccSMax Stepanov 
ieee80211_register_hw(struct ieee80211_hw * hw)9622475b1ccSMax Stepanov int ieee80211_register_hw(struct ieee80211_hw *hw)
9632475b1ccSMax Stepanov {
9642475b1ccSMax Stepanov 	struct ieee80211_local *local = hw_to_local(hw);
9652475b1ccSMax Stepanov 	int result, i;
96657fbcce3SJohannes Berg 	enum nl80211_band band;
9672475b1ccSMax Stepanov 	int channels, max_bitrates;
968820acc81SIlan Peer 	bool supp_ht, supp_vht, supp_he, supp_eht;
9692475b1ccSMax Stepanov 	struct cfg80211_chan_def dflt_chandef = {};
9702475b1ccSMax Stepanov 
97130686bf7SJohannes Berg 	if (ieee80211_hw_check(hw, QUEUE_CONTROL) &&
9723a25a8c8SJohannes Berg 	    (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
9733a25a8c8SJohannes Berg 	     local->hw.offchannel_tx_hw_queue >= local->hw.queues))
9743a25a8c8SJohannes Berg 		return -EINVAL;
9753a25a8c8SJohannes Berg 
976a7a6bdd0SArik Nemtsov 	if ((hw->wiphy->features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) &&
977a7a6bdd0SArik Nemtsov 	    (!local->ops->tdls_channel_switch ||
9788a4d32f3SArik Nemtsov 	     !local->ops->tdls_cancel_channel_switch ||
9798a4d32f3SArik Nemtsov 	     !local->ops->tdls_recv_channel_switch))
980a7a6bdd0SArik Nemtsov 		return -EOPNOTSUPP;
981a7a6bdd0SArik Nemtsov 
982f3fe4e93SSara Sharon 	if (WARN_ON(ieee80211_hw_check(hw, SUPPORTS_TX_FRAG) &&
983f3fe4e93SSara Sharon 		    !local->ops->set_frag_threshold))
984f3fe4e93SSara Sharon 		return -EINVAL;
985f3fe4e93SSara Sharon 
986708d50edSAyala Beker 	if (WARN_ON(local->hw.wiphy->interface_modes &
987708d50edSAyala Beker 			BIT(NL80211_IFTYPE_NAN) &&
988708d50edSAyala Beker 		    (!local->ops->start_nan || !local->ops->stop_nan)))
989708d50edSAyala Beker 		return -EINVAL;
990708d50edSAyala Beker 
991762623a6SJohannes Berg 	if (hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) {
992762623a6SJohannes Berg 		/*
993762623a6SJohannes Berg 		 * For drivers capable of doing MLO, assume modern driver
994762623a6SJohannes Berg 		 * or firmware facilities, so software doesn't have to do
995762623a6SJohannes Berg 		 * as much, e.g. monitoring beacons would be hard if we
996762623a6SJohannes Berg 		 * might not even know which link is active at which time.
997762623a6SJohannes Berg 		 */
998762623a6SJohannes Berg 		if (WARN_ON(!local->use_chanctx))
999762623a6SJohannes Berg 			return -EINVAL;
1000762623a6SJohannes Berg 
1001762623a6SJohannes Berg 		if (WARN_ON(!local->ops->link_info_changed))
1002762623a6SJohannes Berg 			return -EINVAL;
1003762623a6SJohannes Berg 
1004762623a6SJohannes Berg 		if (WARN_ON(!ieee80211_hw_check(hw, HAS_RATE_CONTROL)))
1005762623a6SJohannes Berg 			return -EINVAL;
1006762623a6SJohannes Berg 
1007762623a6SJohannes Berg 		if (WARN_ON(!ieee80211_hw_check(hw, AMPDU_AGGREGATION)))
1008762623a6SJohannes Berg 			return -EINVAL;
1009762623a6SJohannes Berg 
1010762623a6SJohannes Berg 		if (WARN_ON(ieee80211_hw_check(hw, HOST_BROADCAST_PS_BUFFERING)))
1011762623a6SJohannes Berg 			return -EINVAL;
1012762623a6SJohannes Berg 
1013762623a6SJohannes Berg 		if (WARN_ON(ieee80211_hw_check(hw, SUPPORTS_PS) &&
10148c7c6b58SJohannes Berg 			    (!ieee80211_hw_check(hw, SUPPORTS_DYNAMIC_PS) ||
10158c7c6b58SJohannes Berg 			     ieee80211_hw_check(hw, PS_NULLFUNC_STACK))))
1016762623a6SJohannes Berg 			return -EINVAL;
1017762623a6SJohannes Berg 
1018762623a6SJohannes Berg 		if (WARN_ON(!ieee80211_hw_check(hw, MFP_CAPABLE)))
1019762623a6SJohannes Berg 			return -EINVAL;
1020762623a6SJohannes Berg 
1021762623a6SJohannes Berg 		if (WARN_ON(!ieee80211_hw_check(hw, CONNECTION_MONITOR)))
1022762623a6SJohannes Berg 			return -EINVAL;
1023762623a6SJohannes Berg 
1024762623a6SJohannes Berg 		if (WARN_ON(ieee80211_hw_check(hw, NEED_DTIM_BEFORE_ASSOC)))
1025762623a6SJohannes Berg 			return -EINVAL;
1026762623a6SJohannes Berg 
1027762623a6SJohannes Berg 		if (WARN_ON(ieee80211_hw_check(hw, TIMING_BEACON_ONLY)))
1028762623a6SJohannes Berg 			return -EINVAL;
1029762623a6SJohannes Berg 
1030762623a6SJohannes Berg 		if (WARN_ON(!ieee80211_hw_check(hw, AP_LINK_PS)))
1031762623a6SJohannes Berg 			return -EINVAL;
103219343659SJohannes Berg 
103319343659SJohannes Berg 		if (WARN_ON(ieee80211_hw_check(hw, DEAUTH_NEED_MGD_TX_PREP)))
103419343659SJohannes Berg 			return -EINVAL;
1035762623a6SJohannes Berg 	}
1036762623a6SJohannes Berg 
103738bb3e9dSLarry Finger #ifdef CONFIG_PM
1038964dc9e2SJohannes Berg 	if (hw->wiphy->wowlan && (!local->ops->suspend || !local->ops->resume))
1039eecc4800SJohannes Berg 		return -EINVAL;
1040dfb89c56SJohannes Berg #endif
1041eecc4800SJohannes Berg 
1042fe57d9f5SJohannes Berg 	if (!local->use_chanctx) {
1043fe57d9f5SJohannes Berg 		for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
1044fe57d9f5SJohannes Berg 			const struct ieee80211_iface_combination *comb;
1045fe57d9f5SJohannes Berg 
1046fe57d9f5SJohannes Berg 			comb = &local->hw.wiphy->iface_combinations[i];
1047fe57d9f5SJohannes Berg 
1048fe57d9f5SJohannes Berg 			if (comb->num_different_channels > 1)
1049fe57d9f5SJohannes Berg 				return -EINVAL;
1050fe57d9f5SJohannes Berg 		}
1051746a3365SJohannes Berg 	} else {
1052486cf4c0SMichal Kazior 		/* DFS is not supported with multi-channel combinations yet */
1053164eb02dSSimon Wunderlich 		for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
1054164eb02dSSimon Wunderlich 			const struct ieee80211_iface_combination *comb;
1055164eb02dSSimon Wunderlich 
1056164eb02dSSimon Wunderlich 			comb = &local->hw.wiphy->iface_combinations[i];
1057164eb02dSSimon Wunderlich 
1058486cf4c0SMichal Kazior 			if (comb->radar_detect_widths &&
1059486cf4c0SMichal Kazior 			    comb->num_different_channels > 1)
1060164eb02dSSimon Wunderlich 				return -EINVAL;
1061164eb02dSSimon Wunderlich 		}
1062fe57d9f5SJohannes Berg 	}
1063fe57d9f5SJohannes Berg 
106472d78728SArik Nemtsov 	/* Only HW csum features are currently compatible with mac80211 */
106507b83d2eSJohannes Berg 	if (WARN_ON(hw->netdev_features & ~MAC80211_SUPPORTED_FEATURES))
106672d78728SArik Nemtsov 		return -EINVAL;
106772d78728SArik Nemtsov 
106878be49ecSHelmut Schaa 	if (hw->max_report_rates == 0)
106978be49ecSHelmut Schaa 		hw->max_report_rates = hw->max_rates;
107078be49ecSHelmut Schaa 
107104ecd257SJohannes Berg 	local->rx_chains = 1;
107204ecd257SJohannes Berg 
10732c8dccc7SJohannes Berg 	/*
10742c8dccc7SJohannes Berg 	 * generic code guarantees at least one band,
10752c8dccc7SJohannes Berg 	 * set this very early because much code assumes
10762c8dccc7SJohannes Berg 	 * that hw.conf.channel is assigned
10772c8dccc7SJohannes Berg 	 */
10782a519311SJohannes Berg 	channels = 0;
1079de95a54bSJohannes Berg 	max_bitrates = 0;
10805ef2d41aSJohannes Berg 	supp_ht = false;
1081ba0afa2fSMahesh Palivela 	supp_vht = false;
108241cbb0f5SLuca Coelho 	supp_he = false;
1083820acc81SIlan Peer 	supp_eht = false;
108457fbcce3SJohannes Berg 	for (band = 0; band < NUM_NL80211_BANDS; band++) {
10852c8dccc7SJohannes Berg 		struct ieee80211_supported_band *sband;
10862c8dccc7SJohannes Berg 
10872c8dccc7SJohannes Berg 		sband = local->hw.wiphy->bands[band];
1088de95a54bSJohannes Berg 		if (!sband)
1089de95a54bSJohannes Berg 			continue;
1090fffa4b1cSKarl Beldan 
1091fffa4b1cSKarl Beldan 		if (!dflt_chandef.chan) {
1092041c881aSKarthikeyan Kathirvel 			/*
1093041c881aSKarthikeyan Kathirvel 			 * Assign the first enabled channel to dflt_chandef
1094041c881aSKarthikeyan Kathirvel 			 * from the list of channels
1095041c881aSKarthikeyan Kathirvel 			 */
1096041c881aSKarthikeyan Kathirvel 			for (i = 0; i < sband->n_channels; i++)
1097041c881aSKarthikeyan Kathirvel 				if (!(sband->channels[i].flags &
1098041c881aSKarthikeyan Kathirvel 						IEEE80211_CHAN_DISABLED))
1099041c881aSKarthikeyan Kathirvel 					break;
1100041c881aSKarthikeyan Kathirvel 			/* if none found then use the first anyway */
1101041c881aSKarthikeyan Kathirvel 			if (i == sband->n_channels)
1102041c881aSKarthikeyan Kathirvel 				i = 0;
1103fffa4b1cSKarl Beldan 			cfg80211_chandef_create(&dflt_chandef,
1104041c881aSKarthikeyan Kathirvel 						&sband->channels[i],
11054bf88530SJohannes Berg 						NL80211_CHAN_NO_HT);
1106fffa4b1cSKarl Beldan 			/* init channel we're on */
1107fffa4b1cSKarl Beldan 			if (!local->use_chanctx && !local->_oper_chandef.chan) {
1108fffa4b1cSKarl Beldan 				local->hw.conf.chandef = dflt_chandef;
1109fffa4b1cSKarl Beldan 				local->_oper_chandef = dflt_chandef;
1110fffa4b1cSKarl Beldan 			}
1111fffa4b1cSKarl Beldan 			local->monitor_chandef = dflt_chandef;
1112fffa4b1cSKarl Beldan 		}
1113fffa4b1cSKarl Beldan 
11142a519311SJohannes Berg 		channels += sband->n_channels;
1115de95a54bSJohannes Berg 
111669e0d04eSJohannes Berg 		/*
111769e0d04eSJohannes Berg 		 * Due to the way the aggregation code handles this and it
111869e0d04eSJohannes Berg 		 * being an HT capability, we can't really support delayed
111969e0d04eSJohannes Berg 		 * BA in MLO (yet).
112069e0d04eSJohannes Berg 		 */
112169e0d04eSJohannes Berg 		if (WARN_ON(sband->ht_cap.ht_supported &&
112269e0d04eSJohannes Berg 			    (sband->ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA) &&
112369e0d04eSJohannes Berg 			    hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
112469e0d04eSJohannes Berg 			return -EINVAL;
112569e0d04eSJohannes Berg 
1126de95a54bSJohannes Berg 		if (max_bitrates < sband->n_bitrates)
1127de95a54bSJohannes Berg 			max_bitrates = sband->n_bitrates;
11285ef2d41aSJohannes Berg 		supp_ht = supp_ht || sband->ht_cap.ht_supported;
1129ba0afa2fSMahesh Palivela 		supp_vht = supp_vht || sband->vht_cap.vht_supported;
113004ecd257SJohannes Berg 
1131bac2fd3dSJohannes Berg 		for (i = 0; i < sband->n_iftype_data; i++) {
1132bac2fd3dSJohannes Berg 			const struct ieee80211_sband_iftype_data *iftd;
1133bac2fd3dSJohannes Berg 
1134bac2fd3dSJohannes Berg 			iftd = &sband->iftype_data[i];
1135bac2fd3dSJohannes Berg 
11364a11174dSDan Carpenter 			supp_he = supp_he || iftd->he_cap.has_he;
1137820acc81SIlan Peer 			supp_eht = supp_eht || iftd->eht_cap.has_eht;
1138bac2fd3dSJohannes Berg 		}
113941cbb0f5SLuca Coelho 
114075e296e9SJohannes Berg 		/* HT, VHT, HE require QoS, thus >= 4 queues */
114175e296e9SJohannes Berg 		if (WARN_ON(local->hw.queues < IEEE80211_NUM_ACS &&
114275e296e9SJohannes Berg 			    (supp_ht || supp_vht || supp_he)))
114375e296e9SJohannes Berg 			return -EINVAL;
114475e296e9SJohannes Berg 
1145820acc81SIlan Peer 		/* EHT requires HE support */
1146820acc81SIlan Peer 		if (WARN_ON(supp_eht && !supp_he))
1147820acc81SIlan Peer 			return -EINVAL;
1148820acc81SIlan Peer 
114943071d8fSFelix Fietkau 		if (!sband->ht_cap.ht_supported)
115043071d8fSFelix Fietkau 			continue;
115143071d8fSFelix Fietkau 
115243071d8fSFelix Fietkau 		/* TODO: consider VHT for RX chains, hopefully it's the same */
115304ecd257SJohannes Berg 		local->rx_chains =
115404ecd257SJohannes Berg 			max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
115504ecd257SJohannes Berg 			    local->rx_chains);
115604ecd257SJohannes Berg 
115743071d8fSFelix Fietkau 		/* no need to mask, SM_PS_DISABLED has all bits set */
115843071d8fSFelix Fietkau 		sband->ht_cap.cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
115943071d8fSFelix Fietkau 			             IEEE80211_HT_CAP_SM_PS_SHIFT;
11602c8dccc7SJohannes Berg 	}
11612c8dccc7SJohannes Berg 
1162db3bdcb9SManikanta Pubbisetty 	/* if low-level driver supports AP, we also support VLAN.
1163db3bdcb9SManikanta Pubbisetty 	 * drivers advertising SW_CRYPTO_CONTROL should enable AP_VLAN
1164db3bdcb9SManikanta Pubbisetty 	 * based on their support to transmit SW encrypted packets.
1165db3bdcb9SManikanta Pubbisetty 	 */
1166db3bdcb9SManikanta Pubbisetty 	if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP) &&
1167db3bdcb9SManikanta Pubbisetty 	    !ieee80211_hw_check(&local->hw, SW_CRYPTO_CONTROL)) {
11687527a782SJohannes Berg 		hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
11697527a782SJohannes Berg 		hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
11707527a782SJohannes Berg 	}
1171f59ac048SLuis R. Rodriguez 
1172f59ac048SLuis R. Rodriguez 	/* mac80211 always supports monitor */
11737527a782SJohannes Berg 	hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
11747527a782SJohannes Berg 	hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
11757527a782SJohannes Berg 
117655de908aSJohannes Berg 	/* mac80211 doesn't support more than one IBSS interface right now */
11778e621fc9SJohannes Berg 	for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
11788e621fc9SJohannes Berg 		const struct ieee80211_iface_combination *c;
11798e621fc9SJohannes Berg 		int j;
11808e621fc9SJohannes Berg 
11818e621fc9SJohannes Berg 		c = &hw->wiphy->iface_combinations[i];
11828e621fc9SJohannes Berg 
11838e621fc9SJohannes Berg 		for (j = 0; j < c->n_limits; j++)
11848e621fc9SJohannes Berg 			if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
11858e621fc9SJohannes Berg 			    c->limits[j].max > 1)
11868e621fc9SJohannes Berg 				return -EINVAL;
11878e621fc9SJohannes Berg 	}
11888e621fc9SJohannes Berg 
11895b0ec94fSJohannes Berg 	local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
11905b0ec94fSJohannes Berg 				      sizeof(void *) * channels, GFP_KERNEL);
11915b0ec94fSJohannes Berg 	if (!local->int_scan_req)
11925b0ec94fSJohannes Berg 		return -ENOMEM;
11935b0ec94fSJohannes Berg 
11949beed8deSJohannes Berg 	eth_broadcast_addr(local->int_scan_req->bssid);
11959beed8deSJohannes Berg 
119657fbcce3SJohannes Berg 	for (band = 0; band < NUM_NL80211_BANDS; band++) {
11975b0ec94fSJohannes Berg 		if (!local->hw.wiphy->bands[band])
11985b0ec94fSJohannes Berg 			continue;
11995b0ec94fSJohannes Berg 		local->int_scan_req->rates[band] = (u32) -1;
12005b0ec94fSJohannes Berg 	}
12015b0ec94fSJohannes Berg 
12025eb5a52dSJohannes Berg #ifndef CONFIG_MAC80211_MESH
12035eb5a52dSJohannes Berg 	/* mesh depends on Kconfig, but drivers should set it if they want */
12045eb5a52dSJohannes Berg 	local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
12055eb5a52dSJohannes Berg #endif
12065eb5a52dSJohannes Berg 
12071570ca59SJavier Cardona 	/* if the underlying driver supports mesh, mac80211 will (at least)
12081570ca59SJavier Cardona 	 * provide routing of mesh authentication frames to userspace */
12091570ca59SJavier Cardona 	if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
12101570ca59SJavier Cardona 		local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
12111570ca59SJavier Cardona 
1212a621fa4dSJohannes Berg 	/* mac80211 supports control port protocol changing */
1213a621fa4dSJohannes Berg 	local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
1214a621fa4dSJohannes Berg 
121530686bf7SJohannes Berg 	if (ieee80211_hw_check(&local->hw, SIGNAL_DBM)) {
121677965c97SJohannes Berg 		local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
121730686bf7SJohannes Berg 	} else if (ieee80211_hw_check(&local->hw, SIGNAL_UNSPEC)) {
121877965c97SJohannes Berg 		local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
121952512072Sandrea merello 		if (hw->max_signal <= 0) {
122052512072Sandrea merello 			result = -EINVAL;
122152e04b4cSSumit Garg 			goto fail_workqueue;
122252512072Sandrea merello 		}
122352512072Sandrea merello 	}
122477965c97SJohannes Berg 
12253e47bf1cSAlexander Wetzel 	/* Mac80211 and therefore all drivers using SW crypto only
12263e47bf1cSAlexander Wetzel 	 * are able to handle PTK rekeys and Extended Key ID.
1227622fce81SAlexander Wetzel 	 */
12283e47bf1cSAlexander Wetzel 	if (!local->ops->set_key) {
1229387bc002SAlexander Wetzel 		wiphy_ext_feature_set(local->hw.wiphy,
1230387bc002SAlexander Wetzel 				      NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
12313e47bf1cSAlexander Wetzel 		wiphy_ext_feature_set(local->hw.wiphy,
12323e47bf1cSAlexander Wetzel 				      NL80211_EXT_FEATURE_EXT_KEY_ID);
12333e47bf1cSAlexander Wetzel 	}
1234387bc002SAlexander Wetzel 
1235a916062aSNicolas Cavallari 	if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_ADHOC))
1236a916062aSNicolas Cavallari 		wiphy_ext_feature_set(local->hw.wiphy,
1237a916062aSNicolas Cavallari 				      NL80211_EXT_FEATURE_DEL_IBSS_STA);
1238a916062aSNicolas Cavallari 
1239de95a54bSJohannes Berg 	/*
1240de95a54bSJohannes Berg 	 * Calculate scan IE length -- we need this to alloc
1241de95a54bSJohannes Berg 	 * memory and to subtract from the driver limit. It
1242dc9f48ceSJouni Malinen 	 * includes the DS Params, (extended) supported rates, and HT
1243de95a54bSJohannes Berg 	 * information -- SSID is the driver's responsibility.
1244de95a54bSJohannes Berg 	 */
1245dc9f48ceSJouni Malinen 	local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
1246dc9f48ceSJouni Malinen 		3 /* DS Params */;
12475ef2d41aSJohannes Berg 	if (supp_ht)
12485ef2d41aSJohannes Berg 		local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
1249de95a54bSJohannes Berg 
1250d0e6c21aSKarl Beldan 	if (supp_vht)
1251ba0afa2fSMahesh Palivela 		local->scan_ies_len +=
1252d4950281SMahesh Palivela 			2 + sizeof(struct ieee80211_vht_cap);
1253ba0afa2fSMahesh Palivela 
125441cbb0f5SLuca Coelho 	/*
1255cee04f3cSIlan Peer 	 * HE cap element is variable in size - set len to allow max size */
1256cee04f3cSIlan Peer 	if (supp_he) {
125741cbb0f5SLuca Coelho 		local->scan_ies_len +=
1258cee04f3cSIlan Peer 			3 + sizeof(struct ieee80211_he_cap_elem) +
125941cbb0f5SLuca Coelho 			sizeof(struct ieee80211_he_mcs_nss_supp) +
1260cee04f3cSIlan Peer 			IEEE80211_HE_PPE_THRES_MAX_LEN;
1261820acc81SIlan Peer 
1262820acc81SIlan Peer 		if (supp_eht)
1263820acc81SIlan Peer 			local->scan_ies_len +=
1264820acc81SIlan Peer 				3 + sizeof(struct ieee80211_eht_cap_elem) +
1265820acc81SIlan Peer 				sizeof(struct ieee80211_eht_mcs_nss_supp) +
1266820acc81SIlan Peer 				IEEE80211_EHT_PPE_THRES_MAX_LEN;
1267cee04f3cSIlan Peer 	}
126841cbb0f5SLuca Coelho 
1269de95a54bSJohannes Berg 	if (!local->ops->hw_scan) {
1270de95a54bSJohannes Berg 		/* For hw_scan, driver needs to set these up. */
1271de95a54bSJohannes Berg 		local->hw.wiphy->max_scan_ssids = 4;
1272de95a54bSJohannes Berg 		local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
1273de95a54bSJohannes Berg 	}
1274de95a54bSJohannes Berg 
1275de95a54bSJohannes Berg 	/*
1276de95a54bSJohannes Berg 	 * If the driver supports any scan IEs, then assume the
1277de95a54bSJohannes Berg 	 * limit includes the IEs mac80211 will add, otherwise
1278de95a54bSJohannes Berg 	 * leave it at zero and let the driver sort it out; we
1279de95a54bSJohannes Berg 	 * still pass our IEs to the driver but userspace will
1280de95a54bSJohannes Berg 	 * not be allowed to in that case.
1281de95a54bSJohannes Berg 	 */
1282de95a54bSJohannes Berg 	if (local->hw.wiphy->max_scan_ie_len)
1283de95a54bSJohannes Berg 		local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
1284de95a54bSJohannes Berg 
12852475b1ccSMax Stepanov 	result = ieee80211_init_cipher_suites(local);
12862475b1ccSMax Stepanov 	if (result < 0)
128752e04b4cSSumit Garg 		goto fail_workqueue;
128825e47c18SJohannes Berg 
128921f83589SJohannes Berg 	if (!local->ops->remain_on_channel)
1290a293911dSJohannes Berg 		local->hw.wiphy->max_remain_on_channel_duration = 5000;
1291a293911dSJohannes Berg 
1292dfe018bfSArik Nemtsov 	/* mac80211 based drivers don't support internal TDLS setup */
1293dfe018bfSArik Nemtsov 	if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
1294dfe018bfSArik Nemtsov 		local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
1295dfe018bfSArik Nemtsov 
1296e9a21949SLuciano Coelho 	/* mac80211 supports eCSA, if the driver supports STA CSA at all */
129730686bf7SJohannes Berg 	if (ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA))
1298e9a21949SLuciano Coelho 		local->ext_capa[0] |= WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING;
1299e9a21949SLuciano Coelho 
1300caf56338SSara Sharon 	/* mac80211 supports multi BSSID, if the driver supports it */
1301caf56338SSara Sharon 	if (ieee80211_hw_check(&local->hw, SUPPORTS_MULTI_BSSID)) {
1302caf56338SSara Sharon 		local->hw.wiphy->support_mbssid = true;
1303caf56338SSara Sharon 		if (ieee80211_hw_check(&local->hw,
1304caf56338SSara Sharon 				       SUPPORTS_ONLY_HE_MULTI_BSSID))
1305caf56338SSara Sharon 			local->hw.wiphy->support_only_he_mbssid = true;
1306caf56338SSara Sharon 		else
1307caf56338SSara Sharon 			local->ext_capa[2] |=
1308caf56338SSara Sharon 				WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
1309caf56338SSara Sharon 	}
1310caf56338SSara Sharon 
13118552a434SJohn Crispin 	local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CNTDWN_COUNTERS_NUM;
13120d06d9baSAndrei Otcheretianski 
1313e2530083SJohannes Berg 	/*
1314e2530083SJohannes Berg 	 * We use the number of queues for feature tests (QoS, HT) internally
1315e2530083SJohannes Berg 	 * so restrict them appropriately.
1316e2530083SJohannes Berg 	 */
1317e2530083SJohannes Berg 	if (hw->queues > IEEE80211_MAX_QUEUES)
1318e2530083SJohannes Berg 		hw->queues = IEEE80211_MAX_QUEUES;
1319e2530083SJohannes Berg 
132042935ecaSLuis R. Rodriguez 	local->workqueue =
1321d8537548SKees Cook 		alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
132242935ecaSLuis R. Rodriguez 	if (!local->workqueue) {
13232c8dccc7SJohannes Berg 		result = -ENOMEM;
13242c8dccc7SJohannes Berg 		goto fail_workqueue;
13252c8dccc7SJohannes Berg 	}
13262c8dccc7SJohannes Berg 
13272c8dccc7SJohannes Berg 	/*
13282c8dccc7SJohannes Berg 	 * The hardware needs headroom for sending the frame,
13292c8dccc7SJohannes Berg 	 * and we need some headroom for passing the frame to monitor
13302c8dccc7SJohannes Berg 	 * interfaces, but never both at the same time.
13312c8dccc7SJohannes Berg 	 */
13322c8dccc7SJohannes Berg 	local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
1333a2fe8166SHelmut Schaa 				   IEEE80211_TX_STATUS_HEADROOM);
13342c8dccc7SJohannes Berg 
1335b446918bSHelmut Schaa 	/*
1336b446918bSHelmut Schaa 	 * if the driver doesn't specify a max listen interval we
1337b446918bSHelmut Schaa 	 * use 5 which should be a safe default
1338b446918bSHelmut Schaa 	 */
1339ea95bba4STomas Winkler 	if (local->hw.max_listen_interval == 0)
1340b446918bSHelmut Schaa 		local->hw.max_listen_interval = 5;
1341ea95bba4STomas Winkler 
1342ea95bba4STomas Winkler 	local->hw.conf.listen_interval = local->hw.max_listen_interval;
1343ea95bba4STomas Winkler 
1344ff616381SJuuso Oikarinen 	local->dynamic_ps_forced_timeout = -1;
1345195e294dSJuuso Oikarinen 
1346167e33f4SAyala Beker 	if (!local->hw.max_nan_de_entries)
1347167e33f4SAyala Beker 		local->hw.max_nan_de_entries = IEEE80211_MAX_NAN_INSTANCE_ID;
1348167e33f4SAyala Beker 
1349b4809e94SToke Høiland-Jørgensen 	if (!local->hw.weight_multiplier)
1350b4809e94SToke Høiland-Jørgensen 		local->hw.weight_multiplier = 1;
1351b4809e94SToke Høiland-Jørgensen 
13524a65cc24SLuca Coelho 	ieee80211_wep_init(local);
1353d4c4a9a1SAlan Jenkins 
135424d47300SKarl Beldan 	local->hw.conf.flags = IEEE80211_CONF_IDLE;
135524d47300SKarl Beldan 
1356b57e6b56SMohammed Shafi Shajakhan 	ieee80211_led_init(local);
1357b57e6b56SMohammed Shafi Shajakhan 
1358dc8b274fSToke Høiland-Jørgensen 	result = ieee80211_txq_setup_flows(local);
1359dc8b274fSToke Høiland-Jørgensen 	if (result)
1360dc8b274fSToke Høiland-Jørgensen 		goto fail_flows;
1361dc8b274fSToke Høiland-Jørgensen 
13622c8dccc7SJohannes Berg 	rtnl_lock();
13632c8dccc7SJohannes Berg 	result = ieee80211_init_rate_ctrl_alg(local,
13642c8dccc7SJohannes Berg 					      hw->rate_control_algorithm);
136552e04b4cSSumit Garg 	rtnl_unlock();
13662c8dccc7SJohannes Berg 	if (result < 0) {
13670fb9a9ecSJoe Perches 		wiphy_debug(local->hw.wiphy,
13680fb9a9ecSJoe Perches 			    "Failed to initialize rate control algorithm\n");
13692c8dccc7SJohannes Berg 		goto fail_rate;
13702c8dccc7SJohannes Berg 	}
13712c8dccc7SJohannes Berg 
137209b4a4faSJohannes Berg 	if (local->rate_ctrl) {
137309b4a4faSJohannes Berg 		clear_bit(IEEE80211_HW_SUPPORTS_VHT_EXT_NSS_BW, hw->flags);
137409b4a4faSJohannes Berg 		if (local->rate_ctrl->ops->capa & RATE_CTRL_CAPA_VHT_EXT_NSS_BW)
137509b4a4faSJohannes Berg 			ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
137609b4a4faSJohannes Berg 	}
137709b4a4faSJohannes Berg 
137809b4a4faSJohannes Berg 	/*
137909b4a4faSJohannes Berg 	 * If the VHT capabilities don't have IEEE80211_VHT_EXT_NSS_BW_CAPABLE,
138009b4a4faSJohannes Berg 	 * or have it when we don't, copy the sband structure and set/clear it.
138109b4a4faSJohannes Berg 	 * This is necessary because rate scaling algorithms could be switched
138209b4a4faSJohannes Berg 	 * and have different support values.
138309b4a4faSJohannes Berg 	 * Print a message so that in the common case the reallocation can be
138409b4a4faSJohannes Berg 	 * avoided.
138509b4a4faSJohannes Berg 	 */
138609b4a4faSJohannes Berg 	BUILD_BUG_ON(NUM_NL80211_BANDS > 8 * sizeof(local->sband_allocated));
138709b4a4faSJohannes Berg 	for (band = 0; band < NUM_NL80211_BANDS; band++) {
138809b4a4faSJohannes Berg 		struct ieee80211_supported_band *sband;
138909b4a4faSJohannes Berg 		bool local_cap, ie_cap;
139009b4a4faSJohannes Berg 
139109b4a4faSJohannes Berg 		local_cap = ieee80211_hw_check(hw, SUPPORTS_VHT_EXT_NSS_BW);
139209b4a4faSJohannes Berg 
139309b4a4faSJohannes Berg 		sband = local->hw.wiphy->bands[band];
139409b4a4faSJohannes Berg 		if (!sband || !sband->vht_cap.vht_supported)
139509b4a4faSJohannes Berg 			continue;
139609b4a4faSJohannes Berg 
139709b4a4faSJohannes Berg 		ie_cap = !!(sband->vht_cap.vht_mcs.tx_highest &
139809b4a4faSJohannes Berg 			    cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE));
139909b4a4faSJohannes Berg 
140009b4a4faSJohannes Berg 		if (local_cap == ie_cap)
140109b4a4faSJohannes Berg 			continue;
140209b4a4faSJohannes Berg 
140309b4a4faSJohannes Berg 		sband = kmemdup(sband, sizeof(*sband), GFP_KERNEL);
140448f3b9e9SWei Yongjun 		if (!sband) {
140548f3b9e9SWei Yongjun 			result = -ENOMEM;
140609b4a4faSJohannes Berg 			goto fail_rate;
140748f3b9e9SWei Yongjun 		}
140809b4a4faSJohannes Berg 
140909b4a4faSJohannes Berg 		wiphy_dbg(hw->wiphy, "copying sband (band %d) due to VHT EXT NSS BW flag\n",
141009b4a4faSJohannes Berg 			  band);
141109b4a4faSJohannes Berg 
141209b4a4faSJohannes Berg 		sband->vht_cap.vht_mcs.tx_highest ^=
141309b4a4faSJohannes Berg 			cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE);
141409b4a4faSJohannes Berg 
141509b4a4faSJohannes Berg 		local->hw.wiphy->bands[band] = sband;
141609b4a4faSJohannes Berg 		local->sband_allocated |= BIT(band);
141709b4a4faSJohannes Berg 	}
141809b4a4faSJohannes Berg 
141952e04b4cSSumit Garg 	result = wiphy_register(local->hw.wiphy);
142052e04b4cSSumit Garg 	if (result < 0)
142152e04b4cSSumit Garg 		goto fail_wiphy_register;
142252e04b4cSSumit Garg 
14236cb5f3eaSJohannes Berg 	debugfs_hw_add(local);
14246cb5f3eaSJohannes Berg 	rate_control_add_debugfs(local);
14256cb5f3eaSJohannes Berg 
142652e04b4cSSumit Garg 	rtnl_lock();
1427a05829a7SJohannes Berg 	wiphy_lock(hw->wiphy);
142852e04b4cSSumit Garg 
14298dffff21SJohannes Berg 	/* add one default STA interface if supported */
1430e27513fbSBen Greear 	if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION) &&
143130686bf7SJohannes Berg 	    !ieee80211_hw_check(hw, NO_AUTO_VIF)) {
1432dd665d23SJohannes Berg 		struct vif_params params = {0};
1433dd665d23SJohannes Berg 
14346bab2e19STom Gundersen 		result = ieee80211_if_add(local, "wlan%d", NET_NAME_ENUM, NULL,
1435dd665d23SJohannes Berg 					  NL80211_IFTYPE_STATION, &params);
14362c8dccc7SJohannes Berg 		if (result)
14370fb9a9ecSJoe Perches 			wiphy_warn(local->hw.wiphy,
14380fb9a9ecSJoe Perches 				   "Failed to add default virtual iface\n");
14398dffff21SJohannes Berg 	}
14402c8dccc7SJohannes Berg 
1441a05829a7SJohannes Berg 	wiphy_unlock(hw->wiphy);
14422c8dccc7SJohannes Berg 	rtnl_unlock();
14432c8dccc7SJohannes Berg 
144426b36cfeSJohn W. Linville #ifdef CONFIG_INET
14452b2c009eSJuuso Oikarinen 	local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
14462b2c009eSJuuso Oikarinen 	result = register_inetaddr_notifier(&local->ifa_notifier);
14472b2c009eSJuuso Oikarinen 	if (result)
14482b2c009eSJuuso Oikarinen 		goto fail_ifa;
144926b36cfeSJohn W. Linville #endif
14502b2c009eSJuuso Oikarinen 
1451a65240c1SJohannes Berg #if IS_ENABLED(CONFIG_IPV6)
1452a65240c1SJohannes Berg 	local->ifa6_notifier.notifier_call = ieee80211_ifa6_changed;
1453a65240c1SJohannes Berg 	result = register_inet6addr_notifier(&local->ifa6_notifier);
1454a65240c1SJohannes Berg 	if (result)
1455a65240c1SJohannes Berg 		goto fail_ifa6;
1456a65240c1SJohannes Berg #endif
1457a65240c1SJohannes Berg 
14582c8dccc7SJohannes Berg 	return 0;
14592c8dccc7SJohannes Berg 
1460a65240c1SJohannes Berg #if IS_ENABLED(CONFIG_IPV6)
1461a65240c1SJohannes Berg  fail_ifa6:
146293c08c32SJuuso Oikarinen #ifdef CONFIG_INET
1463a65240c1SJohannes Berg 	unregister_inetaddr_notifier(&local->ifa_notifier);
1464a65240c1SJohannes Berg #endif
1465a65240c1SJohannes Berg #endif
1466a65240c1SJohannes Berg #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
14672b2c009eSJuuso Oikarinen  fail_ifa:
146893c08c32SJuuso Oikarinen #endif
146952e04b4cSSumit Garg 	wiphy_unregister(local->hw.wiphy);
147052e04b4cSSumit Garg  fail_wiphy_register:
147154330bf6SJohannes Berg 	rtnl_lock();
147254330bf6SJohannes Berg 	rate_control_deinitialize(local);
147310f644a4SJohannes Berg 	ieee80211_remove_interfaces(local);
14742c8dccc7SJohannes Berg 	rtnl_unlock();
147552e04b4cSSumit Garg  fail_rate:
1476dc8b274fSToke Høiland-Jørgensen  fail_flows:
14776dd47d97SJohannes Berg 	ieee80211_led_exit(local);
147842935ecaSLuis R. Rodriguez 	destroy_workqueue(local->workqueue);
14792c8dccc7SJohannes Berg  fail_workqueue:
148050b2e871Staozhang 	if (local->wiphy_ciphers_allocated) {
14813ffc2a90SJohannes Berg 		kfree(local->hw.wiphy->cipher_suites);
148250b2e871Staozhang 		local->wiphy_ciphers_allocated = false;
148350b2e871Staozhang 	}
148411ba964dSJohannes Berg 	kfree(local->int_scan_req);
14852c8dccc7SJohannes Berg 	return result;
14862c8dccc7SJohannes Berg }
14872c8dccc7SJohannes Berg EXPORT_SYMBOL(ieee80211_register_hw);
14882c8dccc7SJohannes Berg 
ieee80211_unregister_hw(struct ieee80211_hw * hw)14892c8dccc7SJohannes Berg void ieee80211_unregister_hw(struct ieee80211_hw *hw)
14902c8dccc7SJohannes Berg {
14912c8dccc7SJohannes Berg 	struct ieee80211_local *local = hw_to_local(hw);
14922c8dccc7SJohannes Berg 
14932c8dccc7SJohannes Berg 	tasklet_kill(&local->tx_pending_tasklet);
14942c8dccc7SJohannes Berg 	tasklet_kill(&local->tasklet);
14952c8dccc7SJohannes Berg 
149626b36cfeSJohn W. Linville #ifdef CONFIG_INET
14972b2c009eSJuuso Oikarinen 	unregister_inetaddr_notifier(&local->ifa_notifier);
149826b36cfeSJohn W. Linville #endif
1499a65240c1SJohannes Berg #if IS_ENABLED(CONFIG_IPV6)
1500a65240c1SJohannes Berg 	unregister_inet6addr_notifier(&local->ifa6_notifier);
1501a65240c1SJohannes Berg #endif
150210f644a4SJohannes Berg 
15032c8dccc7SJohannes Berg 	rtnl_lock();
15042c8dccc7SJohannes Berg 
15052c8dccc7SJohannes Berg 	/*
15062c8dccc7SJohannes Berg 	 * At this point, interface list manipulations are fine
15072c8dccc7SJohannes Berg 	 * because the driver cannot be handing us frames any
15082c8dccc7SJohannes Berg 	 * more and the tasklet is killed.
15092c8dccc7SJohannes Berg 	 */
151075636525SJohannes Berg 	ieee80211_remove_interfaces(local);
15112c8dccc7SJohannes Berg 
151274d64f0aSJohannes Berg 	wiphy_lock(local->hw.wiphy);
151356dd205fSJohannes Berg 	wiphy_delayed_work_cancel(local->hw.wiphy, &local->roc_work);
1514e114cad7SJohannes Berg 	wiphy_work_cancel(local->hw.wiphy, &local->sched_scan_stopped_work);
151574d64f0aSJohannes Berg 	wiphy_work_cancel(local->hw.wiphy, &local->radar_detected_work);
151674d64f0aSJohannes Berg 	wiphy_unlock(local->hw.wiphy);
15172c8dccc7SJohannes Berg 	rtnl_unlock();
15182c8dccc7SJohannes Berg 
1519258086a4SChristian Lamparter 	cancel_work_sync(&local->restart_work);
15203ac64beeSJohannes Berg 	cancel_work_sync(&local->reconfig_filter);
15213ac64beeSJohannes Berg 
15222c8dccc7SJohannes Berg 	ieee80211_clear_tx_pending(local);
15232c8dccc7SJohannes Berg 	rate_control_deinitialize(local);
15242c8dccc7SJohannes Berg 
1525f64f9e71SJoe Perches 	if (skb_queue_len(&local->skb_queue) ||
1526f64f9e71SJoe Perches 	    skb_queue_len(&local->skb_queue_unreliable))
15270fb9a9ecSJoe Perches 		wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
15282c8dccc7SJohannes Berg 	skb_queue_purge(&local->skb_queue);
15292c8dccc7SJohannes Berg 	skb_queue_purge(&local->skb_queue_unreliable);
15302c8dccc7SJohannes Berg 
15312c8dccc7SJohannes Berg 	wiphy_unregister(local->hw.wiphy);
153252e04b4cSSumit Garg 	destroy_workqueue(local->workqueue);
15332c8dccc7SJohannes Berg 	ieee80211_led_exit(local);
15345ba63533SJohannes Berg 	kfree(local->int_scan_req);
15352c8dccc7SJohannes Berg }
15362c8dccc7SJohannes Berg EXPORT_SYMBOL(ieee80211_unregister_hw);
15372c8dccc7SJohannes Berg 
ieee80211_free_ack_frame(int id,void * p,void * data)1538a729cff8SJohannes Berg static int ieee80211_free_ack_frame(int id, void *p, void *data)
1539a729cff8SJohannes Berg {
1540a729cff8SJohannes Berg 	WARN_ONCE(1, "Have pending ack frames!\n");
1541a729cff8SJohannes Berg 	kfree_skb(p);
1542a729cff8SJohannes Berg 	return 0;
1543a729cff8SJohannes Berg }
1544a729cff8SJohannes Berg 
ieee80211_free_hw(struct ieee80211_hw * hw)15452c8dccc7SJohannes Berg void ieee80211_free_hw(struct ieee80211_hw *hw)
15462c8dccc7SJohannes Berg {
15472c8dccc7SJohannes Berg 	struct ieee80211_local *local = hw_to_local(hw);
154809b4a4faSJohannes Berg 	enum nl80211_band band;
15492c8dccc7SJohannes Berg 
1550c771c9d8SJohannes Berg 	mutex_destroy(&local->iflist_mtx);
1551a1699b75SJohannes Berg 	mutex_destroy(&local->mtx);
1552c771c9d8SJohannes Berg 
155350b2e871Staozhang 	if (local->wiphy_ciphers_allocated) {
15543ffc2a90SJohannes Berg 		kfree(local->hw.wiphy->cipher_suites);
155550b2e871Staozhang 		local->wiphy_ciphers_allocated = false;
155650b2e871Staozhang 	}
15573ffc2a90SJohannes Berg 
1558a729cff8SJohannes Berg 	idr_for_each(&local->ack_status_frames,
1559a729cff8SJohannes Berg 		     ieee80211_free_ack_frame, NULL);
1560a729cff8SJohannes Berg 	idr_destroy(&local->ack_status_frames);
1561a729cff8SJohannes Berg 
156254330bf6SJohannes Berg 	sta_info_stop(local);
156354330bf6SJohannes Berg 
15648d5c2585SJohannes Berg 	ieee80211_free_led_names(local);
15658d5c2585SJohannes Berg 
156609b4a4faSJohannes Berg 	for (band = 0; band < NUM_NL80211_BANDS; band++) {
156709b4a4faSJohannes Berg 		if (!(local->sband_allocated & BIT(band)))
156809b4a4faSJohannes Berg 			continue;
156909b4a4faSJohannes Berg 		kfree(local->hw.wiphy->bands[band]);
157009b4a4faSJohannes Berg 	}
157109b4a4faSJohannes Berg 
15722c8dccc7SJohannes Berg 	wiphy_free(local->hw.wiphy);
15732c8dccc7SJohannes Berg }
15742c8dccc7SJohannes Berg EXPORT_SYMBOL(ieee80211_free_hw);
15752c8dccc7SJohannes Berg 
1576baa951a1SJohannes Berg static const char * const drop_reasons_monitor[] = {
1577baa951a1SJohannes Berg #define V(x)	#x,
1578baa951a1SJohannes Berg 	[0] = "RX_DROP_MONITOR",
1579baa951a1SJohannes Berg 	MAC80211_DROP_REASONS_MONITOR(V)
1580baa951a1SJohannes Berg };
1581baa951a1SJohannes Berg 
1582baa951a1SJohannes Berg static struct drop_reason_list drop_reason_list_monitor = {
1583baa951a1SJohannes Berg 	.reasons = drop_reasons_monitor,
1584baa951a1SJohannes Berg 	.n_reasons = ARRAY_SIZE(drop_reasons_monitor),
1585baa951a1SJohannes Berg };
1586baa951a1SJohannes Berg 
1587baa951a1SJohannes Berg static const char * const drop_reasons_unusable[] = {
1588baa951a1SJohannes Berg 	[0] = "RX_DROP_UNUSABLE",
1589baa951a1SJohannes Berg 	MAC80211_DROP_REASONS_UNUSABLE(V)
1590baa951a1SJohannes Berg #undef V
1591baa951a1SJohannes Berg };
1592baa951a1SJohannes Berg 
1593baa951a1SJohannes Berg static struct drop_reason_list drop_reason_list_unusable = {
1594baa951a1SJohannes Berg 	.reasons = drop_reasons_unusable,
1595baa951a1SJohannes Berg 	.n_reasons = ARRAY_SIZE(drop_reasons_unusable),
1596baa951a1SJohannes Berg };
1597baa951a1SJohannes Berg 
ieee80211_init(void)15982c8dccc7SJohannes Berg static int __init ieee80211_init(void)
15992c8dccc7SJohannes Berg {
16002c8dccc7SJohannes Berg 	struct sk_buff *skb;
16012c8dccc7SJohannes Berg 	int ret;
16022c8dccc7SJohannes Berg 
1603e039fa4aSJohannes Berg 	BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
1604e039fa4aSJohannes Berg 	BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
1605e039fa4aSJohannes Berg 		     IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
16062c8dccc7SJohannes Berg 
1607cccf129fSFelix Fietkau 	ret = rc80211_minstrel_init();
1608cccf129fSFelix Fietkau 	if (ret)
1609cccf129fSFelix Fietkau 		return ret;
1610cccf129fSFelix Fietkau 
161147846c9bSJohannes Berg 	ret = ieee80211_iface_init();
161247846c9bSJohannes Berg 	if (ret)
161347846c9bSJohannes Berg 		goto err_netdev;
16142c8dccc7SJohannes Berg 
1615baa951a1SJohannes Berg 	drop_reasons_register_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR,
1616baa951a1SJohannes Berg 				     &drop_reason_list_monitor);
1617baa951a1SJohannes Berg 	drop_reasons_register_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE,
1618baa951a1SJohannes Berg 				     &drop_reason_list_unusable);
1619baa951a1SJohannes Berg 
16202c8dccc7SJohannes Berg 	return 0;
162147846c9bSJohannes Berg  err_netdev:
162247846c9bSJohannes Berg 	rc80211_minstrel_exit();
162347846c9bSJohannes Berg 
162447846c9bSJohannes Berg 	return ret;
16252c8dccc7SJohannes Berg }
16262c8dccc7SJohannes Berg 
ieee80211_exit(void)16272c8dccc7SJohannes Berg static void __exit ieee80211_exit(void)
16282c8dccc7SJohannes Berg {
1629cccf129fSFelix Fietkau 	rc80211_minstrel_exit();
16302c8dccc7SJohannes Berg 
16312c8dccc7SJohannes Berg 	ieee80211s_stop();
16322c8dccc7SJohannes Berg 
163347846c9bSJohannes Berg 	ieee80211_iface_exit();
1634d07c7cf4SJohannes Berg 
1635baa951a1SJohannes Berg 	drop_reasons_unregister_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR);
1636baa951a1SJohannes Berg 	drop_reasons_unregister_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE);
1637baa951a1SJohannes Berg 
1638d07c7cf4SJohannes Berg 	rcu_barrier();
16392c8dccc7SJohannes Berg }
16402c8dccc7SJohannes Berg 
16412c8dccc7SJohannes Berg 
16422c8dccc7SJohannes Berg subsys_initcall(ieee80211_init);
16432c8dccc7SJohannes Berg module_exit(ieee80211_exit);
16442c8dccc7SJohannes Berg 
16452c8dccc7SJohannes Berg MODULE_DESCRIPTION("IEEE 802.11 subsystem");
16462c8dccc7SJohannes Berg MODULE_LICENSE("GPL");
1647