xref: /linux/drivers/net/wireless/intel/iwlwifi/mvm/ops.c (revision d40981350844c2cfa437abfc80596e10ea8f1149)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (C) 2012-2014, 2018-2024 Intel Corporation
4  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5  * Copyright (C) 2016-2017 Intel Deutschland GmbH
6  */
7 #include <linux/module.h>
8 #include <linux/rtnetlink.h>
9 #include <linux/vmalloc.h>
10 #include <net/mac80211.h>
11 
12 #include "fw/notif-wait.h"
13 #include "iwl-trans.h"
14 #include "iwl-op-mode.h"
15 #include "fw/img.h"
16 #include "iwl-debug.h"
17 #include "iwl-drv.h"
18 #include "iwl-modparams.h"
19 #include "mvm.h"
20 #include "iwl-phy-db.h"
21 #include "iwl-nvm-utils.h"
22 #include "iwl-csr.h"
23 #include "iwl-io.h"
24 #include "iwl-prph.h"
25 #include "rs.h"
26 #include "fw/api/scan.h"
27 #include "fw/api/rfi.h"
28 #include "time-event.h"
29 #include "fw-api.h"
30 #include "fw/acpi.h"
31 #include "fw/uefi.h"
32 #include "time-sync.h"
33 
34 #define DRV_DESCRIPTION	"The new Intel(R) wireless AGN driver for Linux"
35 MODULE_DESCRIPTION(DRV_DESCRIPTION);
36 MODULE_LICENSE("GPL");
37 MODULE_IMPORT_NS(IWLWIFI);
38 
39 static const struct iwl_op_mode_ops iwl_mvm_ops;
40 static const struct iwl_op_mode_ops iwl_mvm_ops_mq;
41 
42 struct iwl_mvm_mod_params iwlmvm_mod_params = {
43 	.power_scheme = IWL_POWER_SCHEME_BPS,
44 };
45 
46 module_param_named(power_scheme, iwlmvm_mod_params.power_scheme, int, 0444);
47 MODULE_PARM_DESC(power_scheme,
48 		 "power management scheme: 1-active, 2-balanced, 3-low power, default: 2");
49 
50 /*
51  * module init and exit functions
52  */
53 static int __init iwl_mvm_init(void)
54 {
55 	int ret;
56 
57 	ret = iwl_mvm_rate_control_register();
58 	if (ret) {
59 		pr_err("Unable to register rate control algorithm: %d\n", ret);
60 		return ret;
61 	}
62 
63 	ret = iwl_opmode_register("iwlmvm", &iwl_mvm_ops);
64 	if (ret)
65 		pr_err("Unable to register MVM op_mode: %d\n", ret);
66 
67 	return ret;
68 }
69 module_init(iwl_mvm_init);
70 
71 static void __exit iwl_mvm_exit(void)
72 {
73 	iwl_opmode_deregister("iwlmvm");
74 	iwl_mvm_rate_control_unregister();
75 }
76 module_exit(iwl_mvm_exit);
77 
78 static void iwl_mvm_nic_config(struct iwl_op_mode *op_mode)
79 {
80 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
81 	u8 radio_cfg_type, radio_cfg_step, radio_cfg_dash;
82 	u32 reg_val;
83 	u32 phy_config = iwl_mvm_get_phy_config(mvm);
84 
85 	radio_cfg_type = (phy_config & FW_PHY_CFG_RADIO_TYPE) >>
86 			 FW_PHY_CFG_RADIO_TYPE_POS;
87 	radio_cfg_step = (phy_config & FW_PHY_CFG_RADIO_STEP) >>
88 			 FW_PHY_CFG_RADIO_STEP_POS;
89 	radio_cfg_dash = (phy_config & FW_PHY_CFG_RADIO_DASH) >>
90 			 FW_PHY_CFG_RADIO_DASH_POS;
91 
92 	IWL_DEBUG_INFO(mvm, "Radio type=0x%x-0x%x-0x%x\n", radio_cfg_type,
93 		       radio_cfg_step, radio_cfg_dash);
94 
95 	if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
96 		return;
97 
98 	/* SKU control */
99 	reg_val = CSR_HW_REV_STEP_DASH(mvm->trans->hw_rev);
100 
101 	/* radio configuration */
102 	reg_val |= radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE;
103 	reg_val |= radio_cfg_step << CSR_HW_IF_CONFIG_REG_POS_PHY_STEP;
104 	reg_val |= radio_cfg_dash << CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
105 
106 	WARN_ON((radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE) &
107 		 ~CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE);
108 
109 	/*
110 	 * TODO: Bits 7-8 of CSR in 8000 HW family and higher set the ADC
111 	 * sampling, and shouldn't be set to any non-zero value.
112 	 * The same is supposed to be true of the other HW, but unsetting
113 	 * them (such as the 7260) causes automatic tests to fail on seemingly
114 	 * unrelated errors. Need to further investigate this, but for now
115 	 * we'll separate cases.
116 	 */
117 	if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_8000)
118 		reg_val |= CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI;
119 
120 	if (iwl_fw_dbg_is_d3_debug_enabled(&mvm->fwrt))
121 		reg_val |= CSR_HW_IF_CONFIG_REG_D3_DEBUG;
122 
123 	iwl_trans_set_bits_mask(mvm->trans, CSR_HW_IF_CONFIG_REG,
124 				CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP_DASH |
125 				CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
126 				CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
127 				CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH |
128 				CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
129 				CSR_HW_IF_CONFIG_REG_BIT_MAC_SI   |
130 				CSR_HW_IF_CONFIG_REG_D3_DEBUG,
131 				reg_val);
132 
133 	/*
134 	 * W/A : NIC is stuck in a reset state after Early PCIe power off
135 	 * (PCIe power is lost before PERST# is asserted), causing ME FW
136 	 * to lose ownership and not being able to obtain it back.
137 	 */
138 	if (!mvm->trans->cfg->apmg_not_supported)
139 		iwl_set_bits_mask_prph(mvm->trans, APMG_PS_CTRL_REG,
140 				       APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
141 				       ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
142 }
143 
144 static void iwl_mvm_rx_esr_mode_notif(struct iwl_mvm *mvm,
145 				      struct iwl_rx_cmd_buffer *rxb)
146 {
147 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
148 	struct iwl_mvm_esr_mode_notif *notif = (void *)pkt->data;
149 	struct ieee80211_vif *vif = iwl_mvm_get_bss_vif(mvm);
150 
151 	/* FW recommendations is only for entering EMLSR */
152 	if (IS_ERR_OR_NULL(vif) || iwl_mvm_vif_from_mac80211(vif)->esr_active)
153 		return;
154 
155 	if (le32_to_cpu(notif->action) == ESR_RECOMMEND_ENTER)
156 		iwl_mvm_unblock_esr(mvm, vif, IWL_MVM_ESR_BLOCKED_FW);
157 	else
158 		iwl_mvm_block_esr(mvm, vif, IWL_MVM_ESR_BLOCKED_FW,
159 				  iwl_mvm_get_primary_link(vif));
160 }
161 
162 static void iwl_mvm_rx_monitor_notif(struct iwl_mvm *mvm,
163 				     struct iwl_rx_cmd_buffer *rxb)
164 {
165 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
166 	struct iwl_datapath_monitor_notif *notif = (void *)pkt->data;
167 	struct ieee80211_supported_band *sband;
168 	const struct ieee80211_sta_he_cap *he_cap;
169 	struct ieee80211_vif *vif;
170 
171 	if (notif->type != cpu_to_le32(IWL_DP_MON_NOTIF_TYPE_EXT_CCA))
172 		return;
173 
174 	vif = iwl_mvm_get_vif_by_macid(mvm, notif->mac_id);
175 	if (!vif || vif->type != NL80211_IFTYPE_STATION)
176 		return;
177 
178 	if (!vif->bss_conf.chanreq.oper.chan ||
179 	    vif->bss_conf.chanreq.oper.chan->band != NL80211_BAND_2GHZ ||
180 	    vif->bss_conf.chanreq.oper.width < NL80211_CHAN_WIDTH_40)
181 		return;
182 
183 	if (!vif->cfg.assoc)
184 		return;
185 
186 	/* this shouldn't happen *again*, ignore it */
187 	if (mvm->cca_40mhz_workaround)
188 		return;
189 
190 	/*
191 	 * We'll decrement this on disconnect - so set to 2 since we'll
192 	 * still have to disconnect from the current AP first.
193 	 */
194 	mvm->cca_40mhz_workaround = 2;
195 
196 	/*
197 	 * This capability manipulation isn't really ideal, but it's the
198 	 * easiest choice - otherwise we'd have to do some major changes
199 	 * in mac80211 to support this, which isn't worth it. This does
200 	 * mean that userspace may have outdated information, but that's
201 	 * actually not an issue at all.
202 	 */
203 	sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
204 
205 	WARN_ON(!sband->ht_cap.ht_supported);
206 	WARN_ON(!(sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40));
207 	sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
208 
209 	he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif);
210 
211 	if (he_cap) {
212 		/* we know that ours is writable */
213 		struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap;
214 
215 		WARN_ON(!he->has_he);
216 		WARN_ON(!(he->he_cap_elem.phy_cap_info[0] &
217 				IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G));
218 		he->he_cap_elem.phy_cap_info[0] &=
219 			~IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
220 	}
221 
222 	ieee80211_disconnect(vif, true);
223 }
224 
225 void iwl_mvm_update_link_smps(struct ieee80211_vif *vif,
226 			      struct ieee80211_bss_conf *link_conf)
227 {
228 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
229 	struct iwl_mvm *mvm = mvmvif->mvm;
230 	enum ieee80211_smps_mode mode = IEEE80211_SMPS_AUTOMATIC;
231 
232 	if (!link_conf)
233 		return;
234 
235 	if (mvm->fw_static_smps_request &&
236 	    link_conf->chanreq.oper.width == NL80211_CHAN_WIDTH_160 &&
237 	    link_conf->he_support)
238 		mode = IEEE80211_SMPS_STATIC;
239 
240 	iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_FW, mode,
241 			    link_conf->link_id);
242 }
243 
244 static void iwl_mvm_intf_dual_chain_req(void *data, u8 *mac,
245 					struct ieee80211_vif *vif)
246 {
247 	struct ieee80211_bss_conf *link_conf;
248 	unsigned int link_id;
249 
250 	rcu_read_lock();
251 
252 	for_each_vif_active_link(vif, link_conf, link_id)
253 		iwl_mvm_update_link_smps(vif, link_conf);
254 
255 	rcu_read_unlock();
256 }
257 
258 static void iwl_mvm_rx_thermal_dual_chain_req(struct iwl_mvm *mvm,
259 					      struct iwl_rx_cmd_buffer *rxb)
260 {
261 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
262 	struct iwl_thermal_dual_chain_request *req = (void *)pkt->data;
263 
264 	/*
265 	 * We could pass it to the iterator data, but also need to remember
266 	 * it for new interfaces that are added while in this state.
267 	 */
268 	mvm->fw_static_smps_request =
269 		req->event == cpu_to_le32(THERMAL_DUAL_CHAIN_REQ_DISABLE);
270 	ieee80211_iterate_interfaces(mvm->hw,
271 				     IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER,
272 				     iwl_mvm_intf_dual_chain_req, NULL);
273 }
274 
275 /**
276  * enum iwl_rx_handler_context: context for Rx handler
277  * @RX_HANDLER_SYNC : this means that it will be called in the Rx path
278  *	which can't acquire mvm->mutex.
279  * @RX_HANDLER_ASYNC_LOCKED : If the handler needs to hold mvm->mutex
280  *	(and only in this case!), it should be set as ASYNC. In that case,
281  *	it will be called from a worker with mvm->mutex held.
282  * @RX_HANDLER_ASYNC_UNLOCKED : in case the handler needs to lock the
283  *	mutex itself, it will be called from a worker without mvm->mutex held.
284  * @RX_HANDLER_ASYNC_LOCKED_WIPHY: If the handler needs to hold the wiphy lock
285  *	and mvm->mutex. Will be handled with the wiphy_work queue infra
286  *	instead of regular work queue.
287  */
288 enum iwl_rx_handler_context {
289 	RX_HANDLER_SYNC,
290 	RX_HANDLER_ASYNC_LOCKED,
291 	RX_HANDLER_ASYNC_UNLOCKED,
292 	RX_HANDLER_ASYNC_LOCKED_WIPHY,
293 };
294 
295 /**
296  * struct iwl_rx_handlers: handler for FW notification
297  * @cmd_id: command id
298  * @min_size: minimum size to expect for the notification
299  * @context: see &iwl_rx_handler_context
300  * @fn: the function is called when notification is received
301  */
302 struct iwl_rx_handlers {
303 	u16 cmd_id, min_size;
304 	enum iwl_rx_handler_context context;
305 	void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
306 };
307 
308 #define RX_HANDLER_NO_SIZE(_cmd_id, _fn, _context)		\
309 	{ .cmd_id = _cmd_id, .fn = _fn, .context = _context, }
310 #define RX_HANDLER_GRP_NO_SIZE(_grp, _cmd, _fn, _context)	\
311 	{ .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn, .context = _context, }
312 #define RX_HANDLER(_cmd_id, _fn, _context, _struct)		\
313 	{ .cmd_id = _cmd_id, .fn = _fn,				\
314 	  .context = _context, .min_size = sizeof(_struct), }
315 #define RX_HANDLER_GRP(_grp, _cmd, _fn, _context, _struct)	\
316 	{ .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn,		\
317 	  .context = _context, .min_size = sizeof(_struct), }
318 
319 /*
320  * Handlers for fw notifications
321  * Convention: RX_HANDLER(CMD_NAME, iwl_mvm_rx_CMD_NAME
322  * This list should be in order of frequency for performance purposes.
323  *
324  * The handler can be one from three contexts, see &iwl_rx_handler_context
325  */
326 static const struct iwl_rx_handlers iwl_mvm_rx_handlers[] = {
327 	RX_HANDLER(TX_CMD, iwl_mvm_rx_tx_cmd, RX_HANDLER_SYNC,
328 		   struct iwl_mvm_tx_resp),
329 	RX_HANDLER(BA_NOTIF, iwl_mvm_rx_ba_notif, RX_HANDLER_SYNC,
330 		   struct iwl_mvm_ba_notif),
331 
332 	RX_HANDLER_GRP(DATA_PATH_GROUP, TLC_MNG_UPDATE_NOTIF,
333 		       iwl_mvm_tlc_update_notif, RX_HANDLER_SYNC,
334 		       struct iwl_tlc_update_notif),
335 
336 	RX_HANDLER(BT_PROFILE_NOTIFICATION, iwl_mvm_rx_bt_coex_notif,
337 		   RX_HANDLER_ASYNC_LOCKED_WIPHY,
338 		   struct iwl_bt_coex_profile_notif),
339 	RX_HANDLER_NO_SIZE(BEACON_NOTIFICATION, iwl_mvm_rx_beacon_notif,
340 			   RX_HANDLER_ASYNC_LOCKED),
341 	RX_HANDLER_NO_SIZE(STATISTICS_NOTIFICATION, iwl_mvm_rx_statistics,
342 			   RX_HANDLER_ASYNC_LOCKED),
343 
344 	RX_HANDLER_GRP(STATISTICS_GROUP, STATISTICS_OPER_NOTIF,
345 		       iwl_mvm_handle_rx_system_oper_stats,
346 		       RX_HANDLER_ASYNC_LOCKED_WIPHY,
347 		       struct iwl_system_statistics_notif_oper),
348 	RX_HANDLER_GRP(STATISTICS_GROUP, STATISTICS_OPER_PART1_NOTIF,
349 		       iwl_mvm_handle_rx_system_oper_part1_stats,
350 		       RX_HANDLER_ASYNC_LOCKED,
351 		       struct iwl_system_statistics_part1_notif_oper),
352 	RX_HANDLER_GRP(SYSTEM_GROUP, SYSTEM_STATISTICS_END_NOTIF,
353 		       iwl_mvm_handle_rx_system_end_stats_notif,
354 		       RX_HANDLER_ASYNC_LOCKED,
355 		       struct iwl_system_statistics_end_notif),
356 
357 	RX_HANDLER(BA_WINDOW_STATUS_NOTIFICATION_ID,
358 		   iwl_mvm_window_status_notif, RX_HANDLER_SYNC,
359 		   struct iwl_ba_window_status_notif),
360 
361 	RX_HANDLER(TIME_EVENT_NOTIFICATION, iwl_mvm_rx_time_event_notif,
362 		   RX_HANDLER_SYNC, struct iwl_time_event_notif),
363 	RX_HANDLER_GRP(MAC_CONF_GROUP, SESSION_PROTECTION_NOTIF,
364 		       iwl_mvm_rx_session_protect_notif, RX_HANDLER_SYNC,
365 		       struct iwl_mvm_session_prot_notif),
366 	RX_HANDLER(MCC_CHUB_UPDATE_CMD, iwl_mvm_rx_chub_update_mcc,
367 		   RX_HANDLER_ASYNC_LOCKED, struct iwl_mcc_chub_notif),
368 
369 	RX_HANDLER(EOSP_NOTIFICATION, iwl_mvm_rx_eosp_notif, RX_HANDLER_SYNC,
370 		   struct iwl_mvm_eosp_notification),
371 
372 	RX_HANDLER(SCAN_ITERATION_COMPLETE,
373 		   iwl_mvm_rx_lmac_scan_iter_complete_notif, RX_HANDLER_SYNC,
374 		   struct iwl_lmac_scan_complete_notif),
375 	RX_HANDLER(SCAN_OFFLOAD_COMPLETE,
376 		   iwl_mvm_rx_lmac_scan_complete_notif,
377 		   RX_HANDLER_ASYNC_LOCKED, struct iwl_periodic_scan_complete),
378 	RX_HANDLER_NO_SIZE(MATCH_FOUND_NOTIFICATION,
379 			   iwl_mvm_rx_scan_match_found,
380 			   RX_HANDLER_SYNC),
381 	RX_HANDLER(SCAN_COMPLETE_UMAC, iwl_mvm_rx_umac_scan_complete_notif,
382 		   RX_HANDLER_ASYNC_LOCKED,
383 		   struct iwl_umac_scan_complete),
384 	RX_HANDLER(SCAN_ITERATION_COMPLETE_UMAC,
385 		   iwl_mvm_rx_umac_scan_iter_complete_notif, RX_HANDLER_SYNC,
386 		   struct iwl_umac_scan_iter_complete_notif),
387 
388 	RX_HANDLER(MISSED_BEACONS_NOTIFICATION, iwl_mvm_rx_missed_beacons_notif,
389 		   RX_HANDLER_ASYNC_LOCKED_WIPHY,
390 		   struct iwl_missed_beacons_notif),
391 
392 	RX_HANDLER(REPLY_ERROR, iwl_mvm_rx_fw_error, RX_HANDLER_SYNC,
393 		   struct iwl_error_resp),
394 	RX_HANDLER(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION,
395 		   iwl_mvm_power_uapsd_misbehaving_ap_notif, RX_HANDLER_SYNC,
396 		   struct iwl_uapsd_misbehaving_ap_notif),
397 	RX_HANDLER_NO_SIZE(DTS_MEASUREMENT_NOTIFICATION, iwl_mvm_temp_notif,
398 			   RX_HANDLER_ASYNC_LOCKED),
399 	RX_HANDLER_GRP_NO_SIZE(PHY_OPS_GROUP, DTS_MEASUREMENT_NOTIF_WIDE,
400 			       iwl_mvm_temp_notif, RX_HANDLER_ASYNC_UNLOCKED),
401 	RX_HANDLER_GRP(PHY_OPS_GROUP, CT_KILL_NOTIFICATION,
402 		       iwl_mvm_ct_kill_notif, RX_HANDLER_SYNC,
403 		       struct ct_kill_notif),
404 
405 	RX_HANDLER(TDLS_CHANNEL_SWITCH_NOTIFICATION, iwl_mvm_rx_tdls_notif,
406 		   RX_HANDLER_ASYNC_LOCKED,
407 		   struct iwl_tdls_channel_switch_notif),
408 	RX_HANDLER(MFUART_LOAD_NOTIFICATION, iwl_mvm_rx_mfuart_notif,
409 		   RX_HANDLER_SYNC, struct iwl_mfuart_load_notif_v1),
410 	RX_HANDLER_GRP(LOCATION_GROUP, TOF_RESPONDER_STATS,
411 		       iwl_mvm_ftm_responder_stats, RX_HANDLER_ASYNC_LOCKED,
412 		       struct iwl_ftm_responder_stats),
413 
414 	RX_HANDLER_GRP_NO_SIZE(LOCATION_GROUP, TOF_RANGE_RESPONSE_NOTIF,
415 			       iwl_mvm_ftm_range_resp, RX_HANDLER_ASYNC_LOCKED),
416 	RX_HANDLER_GRP_NO_SIZE(LOCATION_GROUP, TOF_LC_NOTIF,
417 			       iwl_mvm_ftm_lc_notif, RX_HANDLER_ASYNC_LOCKED),
418 
419 	RX_HANDLER_GRP(DEBUG_GROUP, MFU_ASSERT_DUMP_NTF,
420 		       iwl_mvm_mfu_assert_dump_notif, RX_HANDLER_SYNC,
421 		       struct iwl_mfu_assert_dump_notif),
422 	RX_HANDLER_GRP(PROT_OFFLOAD_GROUP, STORED_BEACON_NTF,
423 		       iwl_mvm_rx_stored_beacon_notif, RX_HANDLER_SYNC,
424 		       struct iwl_stored_beacon_notif_v2),
425 	RX_HANDLER_GRP(DATA_PATH_GROUP, MU_GROUP_MGMT_NOTIF,
426 		       iwl_mvm_mu_mimo_grp_notif, RX_HANDLER_SYNC,
427 		       struct iwl_mu_group_mgmt_notif),
428 	RX_HANDLER_GRP(DATA_PATH_GROUP, STA_PM_NOTIF,
429 		       iwl_mvm_sta_pm_notif, RX_HANDLER_SYNC,
430 		       struct iwl_mvm_pm_state_notification),
431 	RX_HANDLER_GRP(MAC_CONF_GROUP, PROBE_RESPONSE_DATA_NOTIF,
432 		       iwl_mvm_probe_resp_data_notif,
433 		       RX_HANDLER_ASYNC_LOCKED,
434 		       struct iwl_probe_resp_data_notif),
435 	RX_HANDLER_GRP(MAC_CONF_GROUP, CHANNEL_SWITCH_START_NOTIF,
436 		       iwl_mvm_channel_switch_start_notif,
437 		       RX_HANDLER_SYNC, struct iwl_channel_switch_start_notif),
438 	RX_HANDLER_GRP(MAC_CONF_GROUP, CHANNEL_SWITCH_ERROR_NOTIF,
439 		       iwl_mvm_channel_switch_error_notif,
440 		       RX_HANDLER_ASYNC_UNLOCKED,
441 		       struct iwl_channel_switch_error_notif),
442 
443 	RX_HANDLER_GRP(DATA_PATH_GROUP, ESR_MODE_NOTIF,
444 		       iwl_mvm_rx_esr_mode_notif,
445 		       RX_HANDLER_ASYNC_LOCKED_WIPHY,
446 		       struct iwl_mvm_esr_mode_notif),
447 
448 	RX_HANDLER_GRP(DATA_PATH_GROUP, MONITOR_NOTIF,
449 		       iwl_mvm_rx_monitor_notif, RX_HANDLER_ASYNC_LOCKED,
450 		       struct iwl_datapath_monitor_notif),
451 
452 	RX_HANDLER_GRP(DATA_PATH_GROUP, THERMAL_DUAL_CHAIN_REQUEST,
453 		       iwl_mvm_rx_thermal_dual_chain_req,
454 		       RX_HANDLER_ASYNC_LOCKED,
455 		       struct iwl_thermal_dual_chain_request),
456 
457 	RX_HANDLER_GRP(SYSTEM_GROUP, RFI_DEACTIVATE_NOTIF,
458 		       iwl_rfi_deactivate_notif_handler, RX_HANDLER_ASYNC_UNLOCKED,
459 		       struct iwl_rfi_deactivate_notif),
460 
461 	RX_HANDLER_GRP(LEGACY_GROUP,
462 		       WNM_80211V_TIMING_MEASUREMENT_NOTIFICATION,
463 		       iwl_mvm_time_sync_msmt_event, RX_HANDLER_SYNC,
464 		       struct iwl_time_msmt_notify),
465 	RX_HANDLER_GRP(LEGACY_GROUP,
466 		       WNM_80211V_TIMING_MEASUREMENT_CONFIRM_NOTIFICATION,
467 		       iwl_mvm_time_sync_msmt_confirm_event, RX_HANDLER_SYNC,
468 		       struct iwl_time_msmt_cfm_notify),
469 	RX_HANDLER_GRP(MAC_CONF_GROUP, ROC_NOTIF,
470 		       iwl_mvm_rx_roc_notif, RX_HANDLER_ASYNC_LOCKED,
471 		       struct iwl_roc_notif),
472 	RX_HANDLER_GRP(SCAN_GROUP, CHANNEL_SURVEY_NOTIF,
473 		       iwl_mvm_rx_channel_survey_notif, RX_HANDLER_ASYNC_LOCKED,
474 		       struct iwl_umac_scan_channel_survey_notif),
475 };
476 #undef RX_HANDLER
477 #undef RX_HANDLER_GRP
478 
479 /* Please keep this array *SORTED* by hex value.
480  * Access is done through binary search
481  */
482 static const struct iwl_hcmd_names iwl_mvm_legacy_names[] = {
483 	HCMD_NAME(UCODE_ALIVE_NTFY),
484 	HCMD_NAME(REPLY_ERROR),
485 	HCMD_NAME(ECHO_CMD),
486 	HCMD_NAME(INIT_COMPLETE_NOTIF),
487 	HCMD_NAME(PHY_CONTEXT_CMD),
488 	HCMD_NAME(DBG_CFG),
489 	HCMD_NAME(SCAN_CFG_CMD),
490 	HCMD_NAME(SCAN_REQ_UMAC),
491 	HCMD_NAME(SCAN_ABORT_UMAC),
492 	HCMD_NAME(SCAN_COMPLETE_UMAC),
493 	HCMD_NAME(BA_WINDOW_STATUS_NOTIFICATION_ID),
494 	HCMD_NAME(ADD_STA_KEY),
495 	HCMD_NAME(ADD_STA),
496 	HCMD_NAME(REMOVE_STA),
497 	HCMD_NAME(TX_CMD),
498 	HCMD_NAME(SCD_QUEUE_CFG),
499 	HCMD_NAME(TXPATH_FLUSH),
500 	HCMD_NAME(MGMT_MCAST_KEY),
501 	HCMD_NAME(WEP_KEY),
502 	HCMD_NAME(SHARED_MEM_CFG),
503 	HCMD_NAME(TDLS_CHANNEL_SWITCH_CMD),
504 	HCMD_NAME(MAC_CONTEXT_CMD),
505 	HCMD_NAME(TIME_EVENT_CMD),
506 	HCMD_NAME(TIME_EVENT_NOTIFICATION),
507 	HCMD_NAME(BINDING_CONTEXT_CMD),
508 	HCMD_NAME(TIME_QUOTA_CMD),
509 	HCMD_NAME(NON_QOS_TX_COUNTER_CMD),
510 	HCMD_NAME(LEDS_CMD),
511 	HCMD_NAME(LQ_CMD),
512 	HCMD_NAME(FW_PAGING_BLOCK_CMD),
513 	HCMD_NAME(SCAN_OFFLOAD_REQUEST_CMD),
514 	HCMD_NAME(SCAN_OFFLOAD_ABORT_CMD),
515 	HCMD_NAME(HOT_SPOT_CMD),
516 	HCMD_NAME(SCAN_OFFLOAD_PROFILES_QUERY_CMD),
517 	HCMD_NAME(BT_COEX_UPDATE_REDUCED_TXP),
518 	HCMD_NAME(BT_COEX_CI),
519 	HCMD_NAME(WNM_80211V_TIMING_MEASUREMENT_NOTIFICATION),
520 	HCMD_NAME(WNM_80211V_TIMING_MEASUREMENT_CONFIRM_NOTIFICATION),
521 	HCMD_NAME(PHY_CONFIGURATION_CMD),
522 	HCMD_NAME(CALIB_RES_NOTIF_PHY_DB),
523 	HCMD_NAME(PHY_DB_CMD),
524 	HCMD_NAME(SCAN_OFFLOAD_COMPLETE),
525 	HCMD_NAME(SCAN_OFFLOAD_UPDATE_PROFILES_CMD),
526 	HCMD_NAME(POWER_TABLE_CMD),
527 	HCMD_NAME(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION),
528 	HCMD_NAME(REPLY_THERMAL_MNG_BACKOFF),
529 	HCMD_NAME(NVM_ACCESS_CMD),
530 	HCMD_NAME(BEACON_NOTIFICATION),
531 	HCMD_NAME(BEACON_TEMPLATE_CMD),
532 	HCMD_NAME(TX_ANT_CONFIGURATION_CMD),
533 	HCMD_NAME(BT_CONFIG),
534 	HCMD_NAME(STATISTICS_CMD),
535 	HCMD_NAME(STATISTICS_NOTIFICATION),
536 	HCMD_NAME(EOSP_NOTIFICATION),
537 	HCMD_NAME(REDUCE_TX_POWER_CMD),
538 	HCMD_NAME(MISSED_BEACONS_NOTIFICATION),
539 	HCMD_NAME(TDLS_CONFIG_CMD),
540 	HCMD_NAME(MAC_PM_POWER_TABLE),
541 	HCMD_NAME(TDLS_CHANNEL_SWITCH_NOTIFICATION),
542 	HCMD_NAME(MFUART_LOAD_NOTIFICATION),
543 	HCMD_NAME(RSS_CONFIG_CMD),
544 	HCMD_NAME(SCAN_ITERATION_COMPLETE_UMAC),
545 	HCMD_NAME(REPLY_RX_PHY_CMD),
546 	HCMD_NAME(REPLY_RX_MPDU_CMD),
547 	HCMD_NAME(BAR_FRAME_RELEASE),
548 	HCMD_NAME(FRAME_RELEASE),
549 	HCMD_NAME(BA_NOTIF),
550 	HCMD_NAME(MCC_UPDATE_CMD),
551 	HCMD_NAME(MCC_CHUB_UPDATE_CMD),
552 	HCMD_NAME(MARKER_CMD),
553 	HCMD_NAME(BT_PROFILE_NOTIFICATION),
554 	HCMD_NAME(MCAST_FILTER_CMD),
555 	HCMD_NAME(REPLY_SF_CFG_CMD),
556 	HCMD_NAME(REPLY_BEACON_FILTERING_CMD),
557 	HCMD_NAME(D3_CONFIG_CMD),
558 	HCMD_NAME(PROT_OFFLOAD_CONFIG_CMD),
559 	HCMD_NAME(MATCH_FOUND_NOTIFICATION),
560 	HCMD_NAME(DTS_MEASUREMENT_NOTIFICATION),
561 	HCMD_NAME(WOWLAN_PATTERNS),
562 	HCMD_NAME(WOWLAN_CONFIGURATION),
563 	HCMD_NAME(WOWLAN_TSC_RSC_PARAM),
564 	HCMD_NAME(WOWLAN_TKIP_PARAM),
565 	HCMD_NAME(WOWLAN_KEK_KCK_MATERIAL),
566 	HCMD_NAME(WOWLAN_GET_STATUSES),
567 	HCMD_NAME(SCAN_ITERATION_COMPLETE),
568 	HCMD_NAME(D0I3_END_CMD),
569 	HCMD_NAME(LTR_CONFIG),
570 	HCMD_NAME(LDBG_CONFIG_CMD),
571 	HCMD_NAME(DEBUG_LOG_MSG),
572 };
573 
574 /* Please keep this array *SORTED* by hex value.
575  * Access is done through binary search
576  */
577 static const struct iwl_hcmd_names iwl_mvm_system_names[] = {
578 	HCMD_NAME(SHARED_MEM_CFG_CMD),
579 	HCMD_NAME(SOC_CONFIGURATION_CMD),
580 	HCMD_NAME(INIT_EXTENDED_CFG_CMD),
581 	HCMD_NAME(FW_ERROR_RECOVERY_CMD),
582 	HCMD_NAME(RFI_CONFIG_CMD),
583 	HCMD_NAME(RFI_GET_FREQ_TABLE_CMD),
584 	HCMD_NAME(SYSTEM_FEATURES_CONTROL_CMD),
585 	HCMD_NAME(SYSTEM_STATISTICS_CMD),
586 	HCMD_NAME(SYSTEM_STATISTICS_END_NOTIF),
587 	HCMD_NAME(RFI_DEACTIVATE_NOTIF),
588 };
589 
590 /* Please keep this array *SORTED* by hex value.
591  * Access is done through binary search
592  */
593 static const struct iwl_hcmd_names iwl_mvm_mac_conf_names[] = {
594 	HCMD_NAME(LOW_LATENCY_CMD),
595 	HCMD_NAME(CHANNEL_SWITCH_TIME_EVENT_CMD),
596 	HCMD_NAME(SESSION_PROTECTION_CMD),
597 	HCMD_NAME(CANCEL_CHANNEL_SWITCH_CMD),
598 	HCMD_NAME(MAC_CONFIG_CMD),
599 	HCMD_NAME(LINK_CONFIG_CMD),
600 	HCMD_NAME(STA_CONFIG_CMD),
601 	HCMD_NAME(AUX_STA_CMD),
602 	HCMD_NAME(STA_REMOVE_CMD),
603 	HCMD_NAME(STA_DISABLE_TX_CMD),
604 	HCMD_NAME(ROC_CMD),
605 	HCMD_NAME(ROC_NOTIF),
606 	HCMD_NAME(CHANNEL_SWITCH_ERROR_NOTIF),
607 	HCMD_NAME(MISSED_VAP_NOTIF),
608 	HCMD_NAME(SESSION_PROTECTION_NOTIF),
609 	HCMD_NAME(PROBE_RESPONSE_DATA_NOTIF),
610 	HCMD_NAME(CHANNEL_SWITCH_START_NOTIF),
611 };
612 
613 /* Please keep this array *SORTED* by hex value.
614  * Access is done through binary search
615  */
616 static const struct iwl_hcmd_names iwl_mvm_phy_names[] = {
617 	HCMD_NAME(CMD_DTS_MEASUREMENT_TRIGGER_WIDE),
618 	HCMD_NAME(CTDP_CONFIG_CMD),
619 	HCMD_NAME(TEMP_REPORTING_THRESHOLDS_CMD),
620 	HCMD_NAME(PER_CHAIN_LIMIT_OFFSET_CMD),
621 	HCMD_NAME(AP_TX_POWER_CONSTRAINTS_CMD),
622 	HCMD_NAME(CT_KILL_NOTIFICATION),
623 	HCMD_NAME(DTS_MEASUREMENT_NOTIF_WIDE),
624 };
625 
626 /* Please keep this array *SORTED* by hex value.
627  * Access is done through binary search
628  */
629 static const struct iwl_hcmd_names iwl_mvm_data_path_names[] = {
630 	HCMD_NAME(DQA_ENABLE_CMD),
631 	HCMD_NAME(UPDATE_MU_GROUPS_CMD),
632 	HCMD_NAME(TRIGGER_RX_QUEUES_NOTIF_CMD),
633 	HCMD_NAME(WNM_PLATFORM_PTM_REQUEST_CMD),
634 	HCMD_NAME(WNM_80211V_TIMING_MEASUREMENT_CONFIG_CMD),
635 	HCMD_NAME(STA_HE_CTXT_CMD),
636 	HCMD_NAME(RLC_CONFIG_CMD),
637 	HCMD_NAME(RFH_QUEUE_CONFIG_CMD),
638 	HCMD_NAME(TLC_MNG_CONFIG_CMD),
639 	HCMD_NAME(CHEST_COLLECTOR_FILTER_CONFIG_CMD),
640 	HCMD_NAME(SCD_QUEUE_CONFIG_CMD),
641 	HCMD_NAME(SEC_KEY_CMD),
642 	HCMD_NAME(ESR_MODE_NOTIF),
643 	HCMD_NAME(MONITOR_NOTIF),
644 	HCMD_NAME(THERMAL_DUAL_CHAIN_REQUEST),
645 	HCMD_NAME(STA_PM_NOTIF),
646 	HCMD_NAME(MU_GROUP_MGMT_NOTIF),
647 	HCMD_NAME(RX_QUEUES_NOTIFICATION),
648 };
649 
650 /* Please keep this array *SORTED* by hex value.
651  * Access is done through binary search
652  */
653 static const struct iwl_hcmd_names iwl_mvm_statistics_names[] = {
654 	HCMD_NAME(STATISTICS_OPER_NOTIF),
655 	HCMD_NAME(STATISTICS_OPER_PART1_NOTIF),
656 };
657 
658 /* Please keep this array *SORTED* by hex value.
659  * Access is done through binary search
660  */
661 static const struct iwl_hcmd_names iwl_mvm_debug_names[] = {
662 	HCMD_NAME(LMAC_RD_WR),
663 	HCMD_NAME(UMAC_RD_WR),
664 	HCMD_NAME(HOST_EVENT_CFG),
665 	HCMD_NAME(DBGC_SUSPEND_RESUME),
666 	HCMD_NAME(BUFFER_ALLOCATION),
667 	HCMD_NAME(GET_TAS_STATUS),
668 	HCMD_NAME(FW_DUMP_COMPLETE_CMD),
669 	HCMD_NAME(FW_CLEAR_BUFFER),
670 	HCMD_NAME(MFU_ASSERT_DUMP_NTF),
671 };
672 
673 /* Please keep this array *SORTED* by hex value.
674  * Access is done through binary search
675  */
676 static const struct iwl_hcmd_names iwl_mvm_scan_names[] = {
677 	HCMD_NAME(CHANNEL_SURVEY_NOTIF),
678 	HCMD_NAME(OFFLOAD_MATCH_INFO_NOTIF),
679 };
680 
681 /* Please keep this array *SORTED* by hex value.
682  * Access is done through binary search
683  */
684 static const struct iwl_hcmd_names iwl_mvm_location_names[] = {
685 	HCMD_NAME(TOF_RANGE_REQ_CMD),
686 	HCMD_NAME(TOF_CONFIG_CMD),
687 	HCMD_NAME(TOF_RANGE_ABORT_CMD),
688 	HCMD_NAME(TOF_RANGE_REQ_EXT_CMD),
689 	HCMD_NAME(TOF_RESPONDER_CONFIG_CMD),
690 	HCMD_NAME(TOF_RESPONDER_DYN_CONFIG_CMD),
691 	HCMD_NAME(TOF_LC_NOTIF),
692 	HCMD_NAME(TOF_RESPONDER_STATS),
693 	HCMD_NAME(TOF_MCSI_DEBUG_NOTIF),
694 	HCMD_NAME(TOF_RANGE_RESPONSE_NOTIF),
695 };
696 
697 /* Please keep this array *SORTED* by hex value.
698  * Access is done through binary search
699  */
700 static const struct iwl_hcmd_names iwl_mvm_prot_offload_names[] = {
701 	HCMD_NAME(WOWLAN_WAKE_PKT_NOTIFICATION),
702 	HCMD_NAME(WOWLAN_INFO_NOTIFICATION),
703 	HCMD_NAME(D3_END_NOTIFICATION),
704 	HCMD_NAME(STORED_BEACON_NTF),
705 };
706 
707 /* Please keep this array *SORTED* by hex value.
708  * Access is done through binary search
709  */
710 static const struct iwl_hcmd_names iwl_mvm_regulatory_and_nvm_names[] = {
711 	HCMD_NAME(NVM_ACCESS_COMPLETE),
712 	HCMD_NAME(NVM_GET_INFO),
713 	HCMD_NAME(TAS_CONFIG),
714 };
715 
716 static const struct iwl_hcmd_arr iwl_mvm_groups[] = {
717 	[LEGACY_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
718 	[LONG_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
719 	[SYSTEM_GROUP] = HCMD_ARR(iwl_mvm_system_names),
720 	[MAC_CONF_GROUP] = HCMD_ARR(iwl_mvm_mac_conf_names),
721 	[PHY_OPS_GROUP] = HCMD_ARR(iwl_mvm_phy_names),
722 	[DATA_PATH_GROUP] = HCMD_ARR(iwl_mvm_data_path_names),
723 	[SCAN_GROUP] = HCMD_ARR(iwl_mvm_scan_names),
724 	[LOCATION_GROUP] = HCMD_ARR(iwl_mvm_location_names),
725 	[PROT_OFFLOAD_GROUP] = HCMD_ARR(iwl_mvm_prot_offload_names),
726 	[REGULATORY_AND_NVM_GROUP] =
727 		HCMD_ARR(iwl_mvm_regulatory_and_nvm_names),
728 	[DEBUG_GROUP] = HCMD_ARR(iwl_mvm_debug_names),
729 	[STATISTICS_GROUP] = HCMD_ARR(iwl_mvm_statistics_names),
730 };
731 
732 /* this forward declaration can avoid to export the function */
733 static void iwl_mvm_async_handlers_wk(struct work_struct *wk);
734 static void iwl_mvm_async_handlers_wiphy_wk(struct wiphy *wiphy,
735 					    struct wiphy_work *work);
736 
737 static u32 iwl_mvm_min_backoff(struct iwl_mvm *mvm)
738 {
739 	const struct iwl_pwr_tx_backoff *backoff = mvm->cfg->pwr_tx_backoffs;
740 	u64 dflt_pwr_limit;
741 
742 	if (!backoff)
743 		return 0;
744 
745 	iwl_bios_get_pwr_limit(&mvm->fwrt, &dflt_pwr_limit);
746 
747 	while (backoff->pwr) {
748 		if (dflt_pwr_limit >= backoff->pwr)
749 			return backoff->backoff;
750 
751 		backoff++;
752 	}
753 
754 	return 0;
755 }
756 
757 static void iwl_mvm_tx_unblock_dwork(struct work_struct *work)
758 {
759 	struct iwl_mvm *mvm =
760 		container_of(work, struct iwl_mvm, cs_tx_unblock_dwork.work);
761 	struct ieee80211_vif *tx_blocked_vif;
762 	struct iwl_mvm_vif *mvmvif;
763 
764 	guard(mvm)(mvm);
765 
766 	tx_blocked_vif =
767 		rcu_dereference_protected(mvm->csa_tx_blocked_vif,
768 					  lockdep_is_held(&mvm->mutex));
769 
770 	if (!tx_blocked_vif)
771 		return;
772 
773 	mvmvif = iwl_mvm_vif_from_mac80211(tx_blocked_vif);
774 	iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
775 	RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
776 }
777 
778 static void iwl_mvm_fwrt_dump_start(void *ctx)
779 {
780 	struct iwl_mvm *mvm = ctx;
781 
782 	mutex_lock(&mvm->mutex);
783 }
784 
785 static void iwl_mvm_fwrt_dump_end(void *ctx)
786 {
787 	struct iwl_mvm *mvm = ctx;
788 
789 	mutex_unlock(&mvm->mutex);
790 }
791 
792 static int iwl_mvm_fwrt_send_hcmd(void *ctx, struct iwl_host_cmd *host_cmd)
793 {
794 	struct iwl_mvm *mvm = (struct iwl_mvm *)ctx;
795 
796 	guard(mvm)(mvm);
797 	return iwl_mvm_send_cmd(mvm, host_cmd);
798 }
799 
800 static bool iwl_mvm_d3_debug_enable(void *ctx)
801 {
802 	return IWL_MVM_D3_DEBUG;
803 }
804 
805 static const struct iwl_fw_runtime_ops iwl_mvm_fwrt_ops = {
806 	.dump_start = iwl_mvm_fwrt_dump_start,
807 	.dump_end = iwl_mvm_fwrt_dump_end,
808 	.send_hcmd = iwl_mvm_fwrt_send_hcmd,
809 	.d3_debug_enable = iwl_mvm_d3_debug_enable,
810 };
811 
812 static int iwl_mvm_start_get_nvm(struct iwl_mvm *mvm)
813 {
814 	struct iwl_trans *trans = mvm->trans;
815 	int ret;
816 
817 	if (trans->csme_own) {
818 		if (WARN(!mvm->mei_registered,
819 			 "csme is owner, but we aren't registered to iwlmei\n"))
820 			goto get_nvm_from_fw;
821 
822 		mvm->mei_nvm_data = iwl_mei_get_nvm();
823 		if (mvm->mei_nvm_data) {
824 			/*
825 			 * mvm->mei_nvm_data is set and because of that,
826 			 * we'll load the NVM from the FW when we'll get
827 			 * ownership.
828 			 */
829 			mvm->nvm_data =
830 				iwl_parse_mei_nvm_data(trans, trans->cfg,
831 						       mvm->mei_nvm_data,
832 						       mvm->fw,
833 						       mvm->set_tx_ant,
834 						       mvm->set_rx_ant);
835 			return 0;
836 		}
837 
838 		IWL_ERR(mvm,
839 			"Got a NULL NVM from CSME, trying to get it from the device\n");
840 	}
841 
842 get_nvm_from_fw:
843 	rtnl_lock();
844 	wiphy_lock(mvm->hw->wiphy);
845 	mutex_lock(&mvm->mutex);
846 
847 	ret = iwl_trans_start_hw(mvm->trans);
848 	if (ret) {
849 		mutex_unlock(&mvm->mutex);
850 		wiphy_unlock(mvm->hw->wiphy);
851 		rtnl_unlock();
852 		return ret;
853 	}
854 
855 	ret = iwl_run_init_mvm_ucode(mvm);
856 	if (ret && ret != -ERFKILL)
857 		iwl_fw_dbg_error_collect(&mvm->fwrt, FW_DBG_TRIGGER_DRIVER);
858 	if (!ret && iwl_mvm_is_lar_supported(mvm)) {
859 		mvm->hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
860 		ret = iwl_mvm_init_mcc(mvm);
861 	}
862 
863 	iwl_mvm_stop_device(mvm);
864 
865 	mutex_unlock(&mvm->mutex);
866 	wiphy_unlock(mvm->hw->wiphy);
867 	rtnl_unlock();
868 
869 	if (ret)
870 		IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
871 
872 	/* no longer need this regardless of failure or not */
873 	mvm->fw_product_reset = false;
874 
875 	return ret;
876 }
877 
878 static int iwl_mvm_start_post_nvm(struct iwl_mvm *mvm)
879 {
880 	struct iwl_mvm_csme_conn_info *csme_conn_info __maybe_unused;
881 	int ret;
882 
883 	iwl_mvm_toggle_tx_ant(mvm, &mvm->mgmt_last_antenna_idx);
884 
885 	ret = iwl_mvm_mac_setup_register(mvm);
886 	if (ret)
887 		return ret;
888 
889 	mvm->hw_registered = true;
890 
891 	iwl_mvm_dbgfs_register(mvm);
892 
893 	wiphy_rfkill_set_hw_state_reason(mvm->hw->wiphy,
894 					 mvm->mei_rfkill_blocked,
895 					 RFKILL_HARD_BLOCK_NOT_OWNER);
896 
897 	iwl_mvm_mei_set_sw_rfkill_state(mvm);
898 
899 	return 0;
900 }
901 
902 struct iwl_mvm_frob_txf_data {
903 	u8 *buf;
904 	size_t buflen;
905 };
906 
907 static void iwl_mvm_frob_txf_key_iter(struct ieee80211_hw *hw,
908 				      struct ieee80211_vif *vif,
909 				      struct ieee80211_sta *sta,
910 				      struct ieee80211_key_conf *key,
911 				      void *data)
912 {
913 	struct iwl_mvm_frob_txf_data *txf = data;
914 	u8 keylen, match, matchend;
915 	u8 *keydata;
916 	size_t i;
917 
918 	switch (key->cipher) {
919 	case WLAN_CIPHER_SUITE_CCMP:
920 		keydata = key->key;
921 		keylen = key->keylen;
922 		break;
923 	case WLAN_CIPHER_SUITE_WEP40:
924 	case WLAN_CIPHER_SUITE_WEP104:
925 	case WLAN_CIPHER_SUITE_TKIP:
926 		/*
927 		 * WEP has short keys which might show up in the payload,
928 		 * and then you can deduce the key, so in this case just
929 		 * remove all FIFO data.
930 		 * For TKIP, we don't know the phase 2 keys here, so same.
931 		 */
932 		memset(txf->buf, 0xBB, txf->buflen);
933 		return;
934 	default:
935 		return;
936 	}
937 
938 	/* scan for key material and clear it out */
939 	match = 0;
940 	for (i = 0; i < txf->buflen; i++) {
941 		if (txf->buf[i] != keydata[match]) {
942 			match = 0;
943 			continue;
944 		}
945 		match++;
946 		if (match == keylen) {
947 			memset(txf->buf + i - keylen, 0xAA, keylen);
948 			match = 0;
949 		}
950 	}
951 
952 	/* we're dealing with a FIFO, so check wrapped around data */
953 	matchend = match;
954 	for (i = 0; match && i < keylen - match; i++) {
955 		if (txf->buf[i] != keydata[match])
956 			break;
957 		match++;
958 		if (match == keylen) {
959 			memset(txf->buf, 0xAA, i + 1);
960 			memset(txf->buf + txf->buflen - matchend, 0xAA,
961 			       matchend);
962 			break;
963 		}
964 	}
965 }
966 
967 static void iwl_mvm_frob_txf(void *ctx, void *buf, size_t buflen)
968 {
969 	struct iwl_mvm_frob_txf_data txf = {
970 		.buf = buf,
971 		.buflen = buflen,
972 	};
973 	struct iwl_mvm *mvm = ctx;
974 
975 	/* embedded key material exists only on old API */
976 	if (iwl_mvm_has_new_tx_api(mvm))
977 		return;
978 
979 	rcu_read_lock();
980 	ieee80211_iter_keys_rcu(mvm->hw, NULL, iwl_mvm_frob_txf_key_iter, &txf);
981 	rcu_read_unlock();
982 }
983 
984 static void iwl_mvm_frob_hcmd(void *ctx, void *hcmd, size_t len)
985 {
986 	/* we only use wide headers for commands */
987 	struct iwl_cmd_header_wide *hdr = hcmd;
988 	unsigned int frob_start = sizeof(*hdr), frob_end = 0;
989 
990 	if (len < sizeof(hdr))
991 		return;
992 
993 	/* all the commands we care about are in LONG_GROUP */
994 	if (hdr->group_id != LONG_GROUP)
995 		return;
996 
997 	switch (hdr->cmd) {
998 	case WEP_KEY:
999 	case WOWLAN_TKIP_PARAM:
1000 	case WOWLAN_KEK_KCK_MATERIAL:
1001 	case ADD_STA_KEY:
1002 		/*
1003 		 * blank out everything here, easier than dealing
1004 		 * with the various versions of the command
1005 		 */
1006 		frob_end = INT_MAX;
1007 		break;
1008 	case MGMT_MCAST_KEY:
1009 		frob_start = offsetof(struct iwl_mvm_mgmt_mcast_key_cmd, igtk);
1010 		BUILD_BUG_ON(offsetof(struct iwl_mvm_mgmt_mcast_key_cmd, igtk) !=
1011 			     offsetof(struct iwl_mvm_mgmt_mcast_key_cmd_v1, igtk));
1012 
1013 		frob_end = offsetofend(struct iwl_mvm_mgmt_mcast_key_cmd, igtk);
1014 		BUILD_BUG_ON(offsetof(struct iwl_mvm_mgmt_mcast_key_cmd, igtk) <
1015 			     offsetof(struct iwl_mvm_mgmt_mcast_key_cmd_v1, igtk));
1016 		break;
1017 	}
1018 
1019 	if (frob_start >= frob_end)
1020 		return;
1021 
1022 	if (frob_end > len)
1023 		frob_end = len;
1024 
1025 	memset((u8 *)hcmd + frob_start, 0xAA, frob_end - frob_start);
1026 }
1027 
1028 static void iwl_mvm_frob_mem(void *ctx, u32 mem_addr, void *mem, size_t buflen)
1029 {
1030 	const struct iwl_dump_exclude *excl;
1031 	struct iwl_mvm *mvm = ctx;
1032 	int i;
1033 
1034 	switch (mvm->fwrt.cur_fw_img) {
1035 	case IWL_UCODE_INIT:
1036 	default:
1037 		/* not relevant */
1038 		return;
1039 	case IWL_UCODE_REGULAR:
1040 	case IWL_UCODE_REGULAR_USNIFFER:
1041 		excl = mvm->fw->dump_excl;
1042 		break;
1043 	case IWL_UCODE_WOWLAN:
1044 		excl = mvm->fw->dump_excl_wowlan;
1045 		break;
1046 	}
1047 
1048 	BUILD_BUG_ON(sizeof(mvm->fw->dump_excl) !=
1049 		     sizeof(mvm->fw->dump_excl_wowlan));
1050 
1051 	for (i = 0; i < ARRAY_SIZE(mvm->fw->dump_excl); i++) {
1052 		u32 start, end;
1053 
1054 		if (!excl[i].addr || !excl[i].size)
1055 			continue;
1056 
1057 		start = excl[i].addr;
1058 		end = start + excl[i].size;
1059 
1060 		if (end <= mem_addr || start >= mem_addr + buflen)
1061 			continue;
1062 
1063 		if (start < mem_addr)
1064 			start = mem_addr;
1065 
1066 		if (end > mem_addr + buflen)
1067 			end = mem_addr + buflen;
1068 
1069 		memset((u8 *)mem + start - mem_addr, 0xAA, end - start);
1070 	}
1071 }
1072 
1073 static const struct iwl_dump_sanitize_ops iwl_mvm_sanitize_ops = {
1074 	.frob_txf = iwl_mvm_frob_txf,
1075 	.frob_hcmd = iwl_mvm_frob_hcmd,
1076 	.frob_mem = iwl_mvm_frob_mem,
1077 };
1078 
1079 static void iwl_mvm_me_conn_status(void *priv, const struct iwl_mei_conn_info *conn_info)
1080 {
1081 	struct iwl_mvm *mvm = priv;
1082 	struct iwl_mvm_csme_conn_info *prev_conn_info, *curr_conn_info;
1083 
1084 	/*
1085 	 * This is protected by the guarantee that this function will not be
1086 	 * called twice on two different threads
1087 	 */
1088 	prev_conn_info = rcu_dereference_protected(mvm->csme_conn_info, true);
1089 
1090 	curr_conn_info = kzalloc(sizeof(*curr_conn_info), GFP_KERNEL);
1091 	if (!curr_conn_info)
1092 		return;
1093 
1094 	curr_conn_info->conn_info = *conn_info;
1095 
1096 	rcu_assign_pointer(mvm->csme_conn_info, curr_conn_info);
1097 
1098 	if (prev_conn_info)
1099 		kfree_rcu(prev_conn_info, rcu_head);
1100 }
1101 
1102 static void iwl_mvm_mei_rfkill(void *priv, bool blocked,
1103 			       bool csme_taking_ownership)
1104 {
1105 	struct iwl_mvm *mvm = priv;
1106 
1107 	if (blocked && !csme_taking_ownership)
1108 		return;
1109 
1110 	mvm->mei_rfkill_blocked = blocked;
1111 	if (!mvm->hw_registered)
1112 		return;
1113 
1114 	wiphy_rfkill_set_hw_state_reason(mvm->hw->wiphy,
1115 					 mvm->mei_rfkill_blocked,
1116 					 RFKILL_HARD_BLOCK_NOT_OWNER);
1117 }
1118 
1119 static void iwl_mvm_mei_roaming_forbidden(void *priv, bool forbidden)
1120 {
1121 	struct iwl_mvm *mvm = priv;
1122 
1123 	if (!mvm->hw_registered || !mvm->csme_vif)
1124 		return;
1125 
1126 	iwl_mvm_send_roaming_forbidden_event(mvm, mvm->csme_vif, forbidden);
1127 }
1128 
1129 static void iwl_mvm_sap_connected_wk(struct work_struct *wk)
1130 {
1131 	struct iwl_mvm *mvm =
1132 		container_of(wk, struct iwl_mvm, sap_connected_wk);
1133 	int ret;
1134 
1135 	ret = iwl_mvm_start_get_nvm(mvm);
1136 	if (ret)
1137 		goto out_free;
1138 
1139 	ret = iwl_mvm_start_post_nvm(mvm);
1140 	if (ret)
1141 		goto out_free;
1142 
1143 	return;
1144 
1145 out_free:
1146 	IWL_ERR(mvm, "Couldn't get started...\n");
1147 	iwl_mei_start_unregister();
1148 	iwl_mei_unregister_complete();
1149 	iwl_fw_flush_dumps(&mvm->fwrt);
1150 	iwl_mvm_thermal_exit(mvm);
1151 	iwl_fw_runtime_free(&mvm->fwrt);
1152 	iwl_phy_db_free(mvm->phy_db);
1153 	kfree(mvm->scan_cmd);
1154 	iwl_trans_op_mode_leave(mvm->trans);
1155 	kfree(mvm->nvm_data);
1156 	kfree(mvm->mei_nvm_data);
1157 
1158 	ieee80211_free_hw(mvm->hw);
1159 }
1160 
1161 static void iwl_mvm_mei_sap_connected(void *priv)
1162 {
1163 	struct iwl_mvm *mvm = priv;
1164 
1165 	if (!mvm->hw_registered)
1166 		schedule_work(&mvm->sap_connected_wk);
1167 }
1168 
1169 static void iwl_mvm_mei_nic_stolen(void *priv)
1170 {
1171 	struct iwl_mvm *mvm = priv;
1172 
1173 	rtnl_lock();
1174 	cfg80211_shutdown_all_interfaces(mvm->hw->wiphy);
1175 	rtnl_unlock();
1176 }
1177 
1178 static const struct iwl_mei_ops mei_ops = {
1179 	.me_conn_status = iwl_mvm_me_conn_status,
1180 	.rfkill = iwl_mvm_mei_rfkill,
1181 	.roaming_forbidden = iwl_mvm_mei_roaming_forbidden,
1182 	.sap_connected = iwl_mvm_mei_sap_connected,
1183 	.nic_stolen = iwl_mvm_mei_nic_stolen,
1184 };
1185 
1186 static void iwl_mvm_find_link_selection_vif(void *_data, u8 *mac,
1187 					    struct ieee80211_vif *vif)
1188 {
1189 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
1190 
1191 	if (ieee80211_vif_is_mld(vif) && mvmvif->authorized)
1192 		iwl_mvm_select_links(mvmvif->mvm, vif);
1193 }
1194 
1195 static void iwl_mvm_trig_link_selection(struct wiphy *wiphy,
1196 					struct wiphy_work *wk)
1197 {
1198 	struct iwl_mvm *mvm =
1199 		container_of(wk, struct iwl_mvm, trig_link_selection_wk);
1200 
1201 	ieee80211_iterate_active_interfaces(mvm->hw,
1202 					    IEEE80211_IFACE_ITER_NORMAL,
1203 					    iwl_mvm_find_link_selection_vif,
1204 					    NULL);
1205 }
1206 
1207 static struct iwl_op_mode *
1208 iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
1209 		      const struct iwl_fw *fw, struct dentry *dbgfs_dir)
1210 {
1211 	struct ieee80211_hw *hw;
1212 	struct iwl_op_mode *op_mode;
1213 	struct iwl_mvm *mvm;
1214 	struct iwl_trans_config trans_cfg = {};
1215 	static const u8 no_reclaim_cmds[] = {
1216 		TX_CMD,
1217 	};
1218 	u32 max_agg;
1219 	size_t scan_size;
1220 	u32 min_backoff;
1221 	struct iwl_mvm_csme_conn_info *csme_conn_info __maybe_unused;
1222 
1223 	/*
1224 	 * We use IWL_MVM_STATION_COUNT_MAX to check the validity of the station
1225 	 * index all over the driver - check that its value corresponds to the
1226 	 * array size.
1227 	 */
1228 	BUILD_BUG_ON(ARRAY_SIZE(mvm->fw_id_to_mac_id) !=
1229 		     IWL_MVM_STATION_COUNT_MAX);
1230 
1231 	/********************************
1232 	 * 1. Allocating and configuring HW data
1233 	 ********************************/
1234 	hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) +
1235 				sizeof(struct iwl_mvm),
1236 				iwl_mvm_has_mld_api(fw) ? &iwl_mvm_mld_hw_ops :
1237 				&iwl_mvm_hw_ops);
1238 	if (!hw)
1239 		return NULL;
1240 
1241 	if (trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_BZ)
1242 		max_agg = 512;
1243 	else
1244 		max_agg = IEEE80211_MAX_AMPDU_BUF_HE;
1245 
1246 	hw->max_rx_aggregation_subframes = max_agg;
1247 
1248 	if (cfg->max_tx_agg_size)
1249 		hw->max_tx_aggregation_subframes = cfg->max_tx_agg_size;
1250 	else
1251 		hw->max_tx_aggregation_subframes = max_agg;
1252 
1253 	op_mode = hw->priv;
1254 
1255 	mvm = IWL_OP_MODE_GET_MVM(op_mode);
1256 	mvm->dev = trans->dev;
1257 	mvm->trans = trans;
1258 	mvm->cfg = cfg;
1259 	mvm->fw = fw;
1260 	mvm->hw = hw;
1261 
1262 	iwl_fw_runtime_init(&mvm->fwrt, trans, fw, &iwl_mvm_fwrt_ops, mvm,
1263 			    &iwl_mvm_sanitize_ops, mvm, dbgfs_dir);
1264 
1265 	iwl_mvm_get_bios_tables(mvm);
1266 	iwl_uefi_get_sgom_table(trans, &mvm->fwrt);
1267 	iwl_uefi_get_step_table(trans);
1268 
1269 	mvm->init_status = 0;
1270 
1271 	if (iwl_mvm_has_new_rx_api(mvm)) {
1272 		op_mode->ops = &iwl_mvm_ops_mq;
1273 		trans->rx_mpdu_cmd_hdr_size =
1274 			(trans->trans_cfg->device_family >=
1275 			 IWL_DEVICE_FAMILY_AX210) ?
1276 			sizeof(struct iwl_rx_mpdu_desc) :
1277 			IWL_RX_DESC_SIZE_V1;
1278 	} else {
1279 		op_mode->ops = &iwl_mvm_ops;
1280 		trans->rx_mpdu_cmd_hdr_size =
1281 			sizeof(struct iwl_rx_mpdu_res_start);
1282 
1283 		if (WARN_ON(trans->num_rx_queues > 1))
1284 			goto out_free;
1285 	}
1286 
1287 	mvm->fw_restart = iwlwifi_mod_params.fw_restart ? -1 : 0;
1288 
1289 	if (iwl_mvm_has_new_tx_api(mvm)) {
1290 		/*
1291 		 * If we have the new TX/queue allocation API initialize them
1292 		 * all to invalid numbers. We'll rewrite the ones that we need
1293 		 * later, but that doesn't happen for all of them all of the
1294 		 * time (e.g. P2P Device is optional), and if a dynamic queue
1295 		 * ends up getting number 2 (IWL_MVM_DQA_P2P_DEVICE_QUEUE) then
1296 		 * iwl_mvm_is_static_queue() erroneously returns true, and we
1297 		 * might have things getting stuck.
1298 		 */
1299 		mvm->aux_queue = IWL_MVM_INVALID_QUEUE;
1300 		mvm->snif_queue = IWL_MVM_INVALID_QUEUE;
1301 		mvm->probe_queue = IWL_MVM_INVALID_QUEUE;
1302 		mvm->p2p_dev_queue = IWL_MVM_INVALID_QUEUE;
1303 	} else {
1304 		mvm->aux_queue = IWL_MVM_DQA_AUX_QUEUE;
1305 		mvm->snif_queue = IWL_MVM_DQA_INJECT_MONITOR_QUEUE;
1306 		mvm->probe_queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE;
1307 		mvm->p2p_dev_queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE;
1308 	}
1309 
1310 	mvm->sf_state = SF_UNINIT;
1311 	if (iwl_mvm_has_unified_ucode(mvm))
1312 		iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_REGULAR);
1313 	else
1314 		iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_INIT);
1315 	mvm->drop_bcn_ap_mode = true;
1316 
1317 	mutex_init(&mvm->mutex);
1318 	spin_lock_init(&mvm->async_handlers_lock);
1319 	INIT_LIST_HEAD(&mvm->time_event_list);
1320 	INIT_LIST_HEAD(&mvm->aux_roc_te_list);
1321 	INIT_LIST_HEAD(&mvm->async_handlers_list);
1322 	spin_lock_init(&mvm->time_event_lock);
1323 	INIT_LIST_HEAD(&mvm->ftm_initiator.loc_list);
1324 	INIT_LIST_HEAD(&mvm->ftm_initiator.pasn_list);
1325 	INIT_LIST_HEAD(&mvm->resp_pasn_list);
1326 
1327 	INIT_WORK(&mvm->async_handlers_wk, iwl_mvm_async_handlers_wk);
1328 	INIT_WORK(&mvm->roc_done_wk, iwl_mvm_roc_done_wk);
1329 	INIT_WORK(&mvm->sap_connected_wk, iwl_mvm_sap_connected_wk);
1330 	INIT_DELAYED_WORK(&mvm->tdls_cs.dwork, iwl_mvm_tdls_ch_switch_work);
1331 	INIT_DELAYED_WORK(&mvm->scan_timeout_dwork, iwl_mvm_scan_timeout_wk);
1332 	INIT_WORK(&mvm->add_stream_wk, iwl_mvm_add_new_dqa_stream_wk);
1333 	INIT_LIST_HEAD(&mvm->add_stream_txqs);
1334 	spin_lock_init(&mvm->add_stream_lock);
1335 
1336 	wiphy_work_init(&mvm->async_handlers_wiphy_wk,
1337 			iwl_mvm_async_handlers_wiphy_wk);
1338 
1339 	wiphy_work_init(&mvm->trig_link_selection_wk,
1340 			iwl_mvm_trig_link_selection);
1341 
1342 	init_waitqueue_head(&mvm->rx_sync_waitq);
1343 
1344 	mvm->queue_sync_state = 0;
1345 
1346 	SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev);
1347 
1348 	spin_lock_init(&mvm->tcm.lock);
1349 	INIT_DELAYED_WORK(&mvm->tcm.work, iwl_mvm_tcm_work);
1350 	mvm->tcm.ts = jiffies;
1351 	mvm->tcm.ll_ts = jiffies;
1352 	mvm->tcm.uapsd_nonagg_ts = jiffies;
1353 
1354 	INIT_DELAYED_WORK(&mvm->cs_tx_unblock_dwork, iwl_mvm_tx_unblock_dwork);
1355 
1356 	mvm->cmd_ver.range_resp =
1357 		iwl_fw_lookup_notif_ver(mvm->fw, LOCATION_GROUP,
1358 					TOF_RANGE_RESPONSE_NOTIF, 5);
1359 	/* we only support up to version 9 */
1360 	if (WARN_ON_ONCE(mvm->cmd_ver.range_resp > 9))
1361 		goto out_free;
1362 
1363 	/*
1364 	 * Populate the state variables that the transport layer needs
1365 	 * to know about.
1366 	 */
1367 	trans_cfg.op_mode = op_mode;
1368 	trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
1369 	trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
1370 
1371 	trans_cfg.rx_buf_size = iwl_amsdu_size_to_rxb_size();
1372 
1373 	trans->wide_cmd_header = true;
1374 	trans_cfg.bc_table_dword =
1375 		mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_AX210;
1376 
1377 	trans_cfg.command_groups = iwl_mvm_groups;
1378 	trans_cfg.command_groups_size = ARRAY_SIZE(iwl_mvm_groups);
1379 
1380 	trans_cfg.cmd_queue = IWL_MVM_DQA_CMD_QUEUE;
1381 	trans_cfg.cmd_fifo = IWL_MVM_TX_FIFO_CMD;
1382 	trans_cfg.scd_set_active = true;
1383 
1384 	trans_cfg.cb_data_offs = offsetof(struct ieee80211_tx_info,
1385 					  driver_data[2]);
1386 
1387 	/* Set a short watchdog for the command queue */
1388 	trans_cfg.cmd_q_wdg_timeout =
1389 		iwl_mvm_get_wd_timeout(mvm, NULL, false, true);
1390 
1391 	snprintf(mvm->hw->wiphy->fw_version,
1392 		 sizeof(mvm->hw->wiphy->fw_version),
1393 		 "%.31s", fw->fw_version);
1394 
1395 	trans_cfg.fw_reset_handshake = fw_has_capa(&mvm->fw->ucode_capa,
1396 						   IWL_UCODE_TLV_CAPA_FW_RESET_HANDSHAKE);
1397 
1398 	trans_cfg.queue_alloc_cmd_ver =
1399 		iwl_fw_lookup_cmd_ver(mvm->fw,
1400 				      WIDE_ID(DATA_PATH_GROUP,
1401 					      SCD_QUEUE_CONFIG_CMD),
1402 				      0);
1403 	mvm->sta_remove_requires_queue_remove =
1404 		trans_cfg.queue_alloc_cmd_ver > 0;
1405 
1406 	mvm->mld_api_is_used = iwl_mvm_has_mld_api(mvm->fw);
1407 
1408 	/* Configure transport layer */
1409 	iwl_trans_configure(mvm->trans, &trans_cfg);
1410 
1411 	trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
1412 	trans->dbg.dest_tlv = mvm->fw->dbg.dest_tlv;
1413 	trans->dbg.n_dest_reg = mvm->fw->dbg.n_dest_reg;
1414 	memcpy(trans->dbg.conf_tlv, mvm->fw->dbg.conf_tlv,
1415 	       sizeof(trans->dbg.conf_tlv));
1416 	trans->dbg.trigger_tlv = mvm->fw->dbg.trigger_tlv;
1417 
1418 	trans->iml = mvm->fw->iml;
1419 	trans->iml_len = mvm->fw->iml_len;
1420 
1421 	/* set up notification wait support */
1422 	iwl_notification_wait_init(&mvm->notif_wait);
1423 
1424 	/* Init phy db */
1425 	mvm->phy_db = iwl_phy_db_init(trans);
1426 	if (!mvm->phy_db) {
1427 		IWL_ERR(mvm, "Cannot init phy_db\n");
1428 		goto out_free;
1429 	}
1430 
1431 	if (iwlwifi_mod_params.nvm_file)
1432 		mvm->nvm_file_name = iwlwifi_mod_params.nvm_file;
1433 	else
1434 		IWL_DEBUG_EEPROM(mvm->trans->dev,
1435 				 "working without external nvm file\n");
1436 
1437 	scan_size = iwl_mvm_scan_size(mvm);
1438 
1439 	mvm->scan_cmd = kmalloc(scan_size, GFP_KERNEL);
1440 	if (!mvm->scan_cmd)
1441 		goto out_free;
1442 	mvm->scan_cmd_size = scan_size;
1443 
1444 	/* invalidate ids to prevent accidental removal of sta_id 0 */
1445 	mvm->aux_sta.sta_id = IWL_MVM_INVALID_STA;
1446 	mvm->snif_sta.sta_id = IWL_MVM_INVALID_STA;
1447 
1448 	/* Set EBS as successful as long as not stated otherwise by the FW. */
1449 	mvm->last_ebs_successful = true;
1450 
1451 	min_backoff = iwl_mvm_min_backoff(mvm);
1452 	iwl_mvm_thermal_initialize(mvm, min_backoff);
1453 
1454 	if (!iwl_mvm_has_new_rx_stats_api(mvm))
1455 		memset(&mvm->rx_stats_v3, 0,
1456 		       sizeof(struct mvm_statistics_rx_v3));
1457 	else
1458 		memset(&mvm->rx_stats, 0, sizeof(struct mvm_statistics_rx));
1459 
1460 	iwl_mvm_ftm_initiator_smooth_config(mvm);
1461 
1462 	iwl_mvm_init_time_sync(&mvm->time_sync);
1463 
1464 	mvm->debugfs_dir = dbgfs_dir;
1465 
1466 	mvm->mei_registered = !iwl_mei_register(mvm, &mei_ops);
1467 
1468 	iwl_mvm_mei_scan_filter_init(&mvm->mei_scan_filter);
1469 
1470 	if (iwl_mvm_start_get_nvm(mvm)) {
1471 		/*
1472 		 * Getting NVM failed while CSME is the owner, but we are
1473 		 * registered to MEI, we'll get the NVM later when it'll be
1474 		 * possible to get it from CSME.
1475 		 */
1476 		if (trans->csme_own && mvm->mei_registered)
1477 			return op_mode;
1478 
1479 		goto out_thermal_exit;
1480 	}
1481 
1482 
1483 	if (iwl_mvm_start_post_nvm(mvm))
1484 		goto out_thermal_exit;
1485 
1486 	return op_mode;
1487 
1488  out_thermal_exit:
1489 	iwl_mvm_thermal_exit(mvm);
1490 	if (mvm->mei_registered) {
1491 		iwl_mei_start_unregister();
1492 		iwl_mei_unregister_complete();
1493 	}
1494  out_free:
1495 	iwl_fw_flush_dumps(&mvm->fwrt);
1496 	iwl_fw_runtime_free(&mvm->fwrt);
1497 
1498 	iwl_phy_db_free(mvm->phy_db);
1499 	kfree(mvm->scan_cmd);
1500 	iwl_trans_op_mode_leave(trans);
1501 
1502 	ieee80211_free_hw(mvm->hw);
1503 	return NULL;
1504 }
1505 
1506 void iwl_mvm_stop_device(struct iwl_mvm *mvm)
1507 {
1508 	lockdep_assert_held(&mvm->mutex);
1509 
1510 	iwl_fw_cancel_timestamp(&mvm->fwrt);
1511 
1512 	clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1513 
1514 	iwl_fw_dbg_stop_sync(&mvm->fwrt);
1515 	iwl_trans_stop_device(mvm->trans);
1516 	iwl_free_fw_paging(&mvm->fwrt);
1517 	iwl_fw_dump_conf_clear(&mvm->fwrt);
1518 	iwl_mvm_mei_device_state(mvm, false);
1519 }
1520 
1521 static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
1522 {
1523 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1524 	int i;
1525 
1526 	if (mvm->mei_registered) {
1527 		rtnl_lock();
1528 		iwl_mei_set_netdev(NULL);
1529 		rtnl_unlock();
1530 		iwl_mei_start_unregister();
1531 	}
1532 
1533 	/*
1534 	 * After we unregister from mei, the worker can't be scheduled
1535 	 * anymore.
1536 	 */
1537 	cancel_work_sync(&mvm->sap_connected_wk);
1538 
1539 	iwl_mvm_leds_exit(mvm);
1540 
1541 	iwl_mvm_thermal_exit(mvm);
1542 
1543 	/*
1544 	 * If we couldn't get ownership on the device and we couldn't
1545 	 * get the NVM from CSME, we haven't registered to mac80211.
1546 	 * In that case, we didn't fail op_mode_start, because we are
1547 	 * waiting for CSME to allow us to get the NVM to register to
1548 	 * mac80211. If that didn't happen, we haven't registered to
1549 	 * mac80211, hence the if below.
1550 	 */
1551 	if (mvm->hw_registered)
1552 		ieee80211_unregister_hw(mvm->hw);
1553 
1554 	kfree(mvm->scan_cmd);
1555 	kfree(mvm->mcast_filter_cmd);
1556 	mvm->mcast_filter_cmd = NULL;
1557 
1558 	kfree(mvm->error_recovery_buf);
1559 	mvm->error_recovery_buf = NULL;
1560 
1561 	iwl_mvm_ptp_remove(mvm);
1562 
1563 	iwl_trans_op_mode_leave(mvm->trans);
1564 
1565 	iwl_phy_db_free(mvm->phy_db);
1566 	mvm->phy_db = NULL;
1567 
1568 	kfree(mvm->nvm_data);
1569 	kfree(mvm->mei_nvm_data);
1570 	kfree(rcu_access_pointer(mvm->csme_conn_info));
1571 	kfree(mvm->temp_nvm_data);
1572 	for (i = 0; i < NVM_MAX_NUM_SECTIONS; i++)
1573 		kfree(mvm->nvm_sections[i].data);
1574 	kfree(mvm->acs_survey);
1575 
1576 	cancel_delayed_work_sync(&mvm->tcm.work);
1577 
1578 	iwl_fw_runtime_free(&mvm->fwrt);
1579 	mutex_destroy(&mvm->mutex);
1580 
1581 	if (mvm->mei_registered)
1582 		iwl_mei_unregister_complete();
1583 
1584 	ieee80211_free_hw(mvm->hw);
1585 }
1586 
1587 struct iwl_async_handler_entry {
1588 	struct list_head list;
1589 	struct iwl_rx_cmd_buffer rxb;
1590 	enum iwl_rx_handler_context context;
1591 	void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1592 };
1593 
1594 void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm)
1595 {
1596 	struct iwl_async_handler_entry *entry, *tmp;
1597 
1598 	spin_lock_bh(&mvm->async_handlers_lock);
1599 	list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {
1600 		iwl_free_rxb(&entry->rxb);
1601 		list_del(&entry->list);
1602 		kfree(entry);
1603 	}
1604 	spin_unlock_bh(&mvm->async_handlers_lock);
1605 }
1606 
1607 /*
1608  * This function receives a bitmap of rx async handler contexts
1609  * (&iwl_rx_handler_context) to handle, and runs only them
1610  */
1611 static void iwl_mvm_async_handlers_by_context(struct iwl_mvm *mvm,
1612 					      u8 contexts)
1613 {
1614 	struct iwl_async_handler_entry *entry, *tmp;
1615 	LIST_HEAD(local_list);
1616 
1617 	/*
1618 	 * Sync with Rx path with a lock. Remove all the entries of the
1619 	 * wanted contexts from this list, add them to a local one (lock free),
1620 	 * and then handle them.
1621 	 */
1622 	spin_lock_bh(&mvm->async_handlers_lock);
1623 	list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {
1624 		if (!(BIT(entry->context) & contexts))
1625 			continue;
1626 		list_del(&entry->list);
1627 		list_add_tail(&entry->list, &local_list);
1628 	}
1629 	spin_unlock_bh(&mvm->async_handlers_lock);
1630 
1631 	list_for_each_entry_safe(entry, tmp, &local_list, list) {
1632 		if (entry->context != RX_HANDLER_ASYNC_UNLOCKED)
1633 			mutex_lock(&mvm->mutex);
1634 		entry->fn(mvm, &entry->rxb);
1635 		iwl_free_rxb(&entry->rxb);
1636 		list_del(&entry->list);
1637 		if (entry->context != RX_HANDLER_ASYNC_UNLOCKED)
1638 			mutex_unlock(&mvm->mutex);
1639 		kfree(entry);
1640 	}
1641 }
1642 
1643 static void iwl_mvm_async_handlers_wiphy_wk(struct wiphy *wiphy,
1644 					    struct wiphy_work *wk)
1645 {
1646 	struct iwl_mvm *mvm =
1647 		container_of(wk, struct iwl_mvm, async_handlers_wiphy_wk);
1648 	u8 contexts = BIT(RX_HANDLER_ASYNC_LOCKED_WIPHY);
1649 
1650 	iwl_mvm_async_handlers_by_context(mvm, contexts);
1651 }
1652 
1653 static void iwl_mvm_async_handlers_wk(struct work_struct *wk)
1654 {
1655 	struct iwl_mvm *mvm =
1656 		container_of(wk, struct iwl_mvm, async_handlers_wk);
1657 	u8 contexts = BIT(RX_HANDLER_ASYNC_LOCKED) |
1658 		      BIT(RX_HANDLER_ASYNC_UNLOCKED);
1659 
1660 	iwl_mvm_async_handlers_by_context(mvm, contexts);
1661 }
1662 
1663 static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm,
1664 					    struct iwl_rx_packet *pkt)
1665 {
1666 	struct iwl_fw_dbg_trigger_tlv *trig;
1667 	struct iwl_fw_dbg_trigger_cmd *cmds_trig;
1668 	int i;
1669 
1670 	trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, NULL,
1671 				     FW_DBG_TRIGGER_FW_NOTIF);
1672 	if (!trig)
1673 		return;
1674 
1675 	cmds_trig = (void *)trig->data;
1676 
1677 	for (i = 0; i < ARRAY_SIZE(cmds_trig->cmds); i++) {
1678 		/* don't collect on CMD 0 */
1679 		if (!cmds_trig->cmds[i].cmd_id)
1680 			break;
1681 
1682 		if (cmds_trig->cmds[i].cmd_id != pkt->hdr.cmd ||
1683 		    cmds_trig->cmds[i].group_id != pkt->hdr.group_id)
1684 			continue;
1685 
1686 		iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
1687 					"CMD 0x%02x.%02x received",
1688 					pkt->hdr.group_id, pkt->hdr.cmd);
1689 		break;
1690 	}
1691 }
1692 
1693 static void iwl_mvm_rx_common(struct iwl_mvm *mvm,
1694 			      struct iwl_rx_cmd_buffer *rxb,
1695 			      struct iwl_rx_packet *pkt)
1696 {
1697 	unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
1698 	int i;
1699 	union iwl_dbg_tlv_tp_data tp_data = { .fw_pkt = pkt };
1700 
1701 	iwl_dbg_tlv_time_point(&mvm->fwrt,
1702 			       IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF, &tp_data);
1703 	iwl_mvm_rx_check_trigger(mvm, pkt);
1704 
1705 	/*
1706 	 * Do the notification wait before RX handlers so
1707 	 * even if the RX handler consumes the RXB we have
1708 	 * access to it in the notification wait entry.
1709 	 */
1710 	iwl_notification_wait_notify(&mvm->notif_wait, pkt);
1711 
1712 	for (i = 0; i < ARRAY_SIZE(iwl_mvm_rx_handlers); i++) {
1713 		const struct iwl_rx_handlers *rx_h = &iwl_mvm_rx_handlers[i];
1714 		struct iwl_async_handler_entry *entry;
1715 
1716 		if (rx_h->cmd_id != WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd))
1717 			continue;
1718 
1719 		if (IWL_FW_CHECK(mvm, pkt_len < rx_h->min_size,
1720 				 "unexpected notification 0x%04x size %d, need %d\n",
1721 				 rx_h->cmd_id, pkt_len, rx_h->min_size))
1722 			return;
1723 
1724 		if (rx_h->context == RX_HANDLER_SYNC) {
1725 			rx_h->fn(mvm, rxb);
1726 			return;
1727 		}
1728 
1729 		entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
1730 		/* we can't do much... */
1731 		if (!entry)
1732 			return;
1733 
1734 		entry->rxb._page = rxb_steal_page(rxb);
1735 		entry->rxb._offset = rxb->_offset;
1736 		entry->rxb._rx_page_order = rxb->_rx_page_order;
1737 		entry->fn = rx_h->fn;
1738 		entry->context = rx_h->context;
1739 		spin_lock(&mvm->async_handlers_lock);
1740 		list_add_tail(&entry->list, &mvm->async_handlers_list);
1741 		spin_unlock(&mvm->async_handlers_lock);
1742 		if (rx_h->context == RX_HANDLER_ASYNC_LOCKED_WIPHY)
1743 			wiphy_work_queue(mvm->hw->wiphy,
1744 					 &mvm->async_handlers_wiphy_wk);
1745 		else
1746 			schedule_work(&mvm->async_handlers_wk);
1747 		break;
1748 	}
1749 }
1750 
1751 static void iwl_mvm_rx(struct iwl_op_mode *op_mode,
1752 		       struct napi_struct *napi,
1753 		       struct iwl_rx_cmd_buffer *rxb)
1754 {
1755 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1756 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1757 	u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
1758 
1759 	if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
1760 		iwl_mvm_rx_rx_mpdu(mvm, napi, rxb);
1761 	else if (cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_PHY_CMD))
1762 		iwl_mvm_rx_rx_phy_cmd(mvm, rxb);
1763 	else
1764 		iwl_mvm_rx_common(mvm, rxb, pkt);
1765 }
1766 
1767 void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,
1768 		   struct napi_struct *napi,
1769 		   struct iwl_rx_cmd_buffer *rxb)
1770 {
1771 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1772 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1773 	u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
1774 
1775 	if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
1776 		iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, 0);
1777 	else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP,
1778 					 RX_QUEUES_NOTIFICATION)))
1779 		iwl_mvm_rx_queue_notif(mvm, napi, rxb, 0);
1780 	else if (cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE))
1781 		iwl_mvm_rx_frame_release(mvm, napi, rxb, 0);
1782 	else if (cmd == WIDE_ID(LEGACY_GROUP, BAR_FRAME_RELEASE))
1783 		iwl_mvm_rx_bar_frame_release(mvm, napi, rxb, 0);
1784 	else if (cmd == WIDE_ID(DATA_PATH_GROUP, RX_NO_DATA_NOTIF))
1785 		iwl_mvm_rx_monitor_no_data(mvm, napi, rxb, 0);
1786 	else
1787 		iwl_mvm_rx_common(mvm, rxb, pkt);
1788 }
1789 
1790 static int iwl_mvm_is_static_queue(struct iwl_mvm *mvm, int queue)
1791 {
1792 	return queue == mvm->aux_queue || queue == mvm->probe_queue ||
1793 		queue == mvm->p2p_dev_queue || queue == mvm->snif_queue;
1794 }
1795 
1796 static void iwl_mvm_queue_state_change(struct iwl_op_mode *op_mode,
1797 				       int hw_queue, bool start)
1798 {
1799 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1800 	struct ieee80211_sta *sta;
1801 	struct ieee80211_txq *txq;
1802 	struct iwl_mvm_txq *mvmtxq;
1803 	int i;
1804 	unsigned long tid_bitmap;
1805 	struct iwl_mvm_sta *mvmsta;
1806 	u8 sta_id;
1807 
1808 	sta_id = iwl_mvm_has_new_tx_api(mvm) ?
1809 		mvm->tvqm_info[hw_queue].sta_id :
1810 		mvm->queue_info[hw_queue].ra_sta_id;
1811 
1812 	if (WARN_ON_ONCE(sta_id >= mvm->fw->ucode_capa.num_stations))
1813 		return;
1814 
1815 	rcu_read_lock();
1816 
1817 	sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1818 	if (IS_ERR_OR_NULL(sta))
1819 		goto out;
1820 	mvmsta = iwl_mvm_sta_from_mac80211(sta);
1821 
1822 	if (iwl_mvm_is_static_queue(mvm, hw_queue)) {
1823 		if (!start)
1824 			ieee80211_stop_queues(mvm->hw);
1825 		else if (mvmsta->sta_state != IEEE80211_STA_NOTEXIST)
1826 			ieee80211_wake_queues(mvm->hw);
1827 
1828 		goto out;
1829 	}
1830 
1831 	if (iwl_mvm_has_new_tx_api(mvm)) {
1832 		int tid = mvm->tvqm_info[hw_queue].txq_tid;
1833 
1834 		tid_bitmap = BIT(tid);
1835 	} else {
1836 		tid_bitmap = mvm->queue_info[hw_queue].tid_bitmap;
1837 	}
1838 
1839 	for_each_set_bit(i, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
1840 		int tid = i;
1841 
1842 		if (tid == IWL_MAX_TID_COUNT)
1843 			tid = IEEE80211_NUM_TIDS;
1844 
1845 		txq = sta->txq[tid];
1846 		mvmtxq = iwl_mvm_txq_from_mac80211(txq);
1847 		if (start)
1848 			clear_bit(IWL_MVM_TXQ_STATE_STOP_FULL, &mvmtxq->state);
1849 		else
1850 			set_bit(IWL_MVM_TXQ_STATE_STOP_FULL, &mvmtxq->state);
1851 
1852 		if (start && mvmsta->sta_state != IEEE80211_STA_NOTEXIST) {
1853 			local_bh_disable();
1854 			iwl_mvm_mac_itxq_xmit(mvm->hw, txq);
1855 			local_bh_enable();
1856 		}
1857 	}
1858 
1859 out:
1860 	rcu_read_unlock();
1861 }
1862 
1863 static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)
1864 {
1865 	iwl_mvm_queue_state_change(op_mode, hw_queue, false);
1866 }
1867 
1868 static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)
1869 {
1870 	iwl_mvm_queue_state_change(op_mode, hw_queue, true);
1871 }
1872 
1873 static void iwl_mvm_set_rfkill_state(struct iwl_mvm *mvm)
1874 {
1875 	wiphy_rfkill_set_hw_state(mvm->hw->wiphy,
1876 				  iwl_mvm_is_radio_killed(mvm));
1877 }
1878 
1879 void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state)
1880 {
1881 	if (state)
1882 		set_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1883 	else
1884 		clear_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1885 
1886 	iwl_mvm_set_rfkill_state(mvm);
1887 }
1888 
1889 struct iwl_mvm_csme_conn_info *iwl_mvm_get_csme_conn_info(struct iwl_mvm *mvm)
1890 {
1891 	return rcu_dereference_protected(mvm->csme_conn_info,
1892 					 lockdep_is_held(&mvm->mutex));
1893 }
1894 
1895 static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
1896 {
1897 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1898 	bool rfkill_safe_init_done = READ_ONCE(mvm->rfkill_safe_init_done);
1899 	bool unified = iwl_mvm_has_unified_ucode(mvm);
1900 
1901 	if (state)
1902 		set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1903 	else
1904 		clear_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1905 
1906 	iwl_mvm_set_rfkill_state(mvm);
1907 
1908 	 /* iwl_run_init_mvm_ucode is waiting for results, abort it. */
1909 	if (rfkill_safe_init_done)
1910 		iwl_abort_notification_waits(&mvm->notif_wait);
1911 
1912 	/*
1913 	 * Don't ask the transport to stop the firmware. We'll do it
1914 	 * after cfg80211 takes us down.
1915 	 */
1916 	if (unified)
1917 		return false;
1918 
1919 	/*
1920 	 * Stop the device if we run OPERATIONAL firmware or if we are in the
1921 	 * middle of the calibrations.
1922 	 */
1923 	return state && rfkill_safe_init_done;
1924 }
1925 
1926 static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
1927 {
1928 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1929 	struct ieee80211_tx_info *info;
1930 
1931 	info = IEEE80211_SKB_CB(skb);
1932 	iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
1933 	ieee80211_free_txskb(mvm->hw, skb);
1934 }
1935 
1936 struct iwl_mvm_reprobe {
1937 	struct device *dev;
1938 	struct work_struct work;
1939 };
1940 
1941 static void iwl_mvm_reprobe_wk(struct work_struct *wk)
1942 {
1943 	struct iwl_mvm_reprobe *reprobe;
1944 
1945 	reprobe = container_of(wk, struct iwl_mvm_reprobe, work);
1946 	if (device_reprobe(reprobe->dev))
1947 		dev_err(reprobe->dev, "reprobe failed!\n");
1948 	put_device(reprobe->dev);
1949 	kfree(reprobe);
1950 	module_put(THIS_MODULE);
1951 }
1952 
1953 void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error)
1954 {
1955 	iwl_abort_notification_waits(&mvm->notif_wait);
1956 	iwl_dbg_tlv_del_timers(mvm->trans);
1957 
1958 	/*
1959 	 * This is a bit racy, but worst case we tell mac80211 about
1960 	 * a stopped/aborted scan when that was already done which
1961 	 * is not a problem. It is necessary to abort any os scan
1962 	 * here because mac80211 requires having the scan cleared
1963 	 * before restarting.
1964 	 * We'll reset the scan_status to NONE in restart cleanup in
1965 	 * the next start() call from mac80211. If restart isn't called
1966 	 * (no fw restart) scan status will stay busy.
1967 	 */
1968 	iwl_mvm_report_scan_aborted(mvm);
1969 
1970 	/*
1971 	 * If we're restarting already, don't cycle restarts.
1972 	 * If INIT fw asserted, it will likely fail again.
1973 	 * If WoWLAN fw asserted, don't restart either, mac80211
1974 	 * can't recover this since we're already half suspended.
1975 	 */
1976 	if (!mvm->fw_restart && fw_error) {
1977 		iwl_fw_error_collect(&mvm->fwrt, false);
1978 	} else if (test_bit(IWL_MVM_STATUS_STARTING,
1979 			    &mvm->status)) {
1980 		IWL_ERR(mvm, "Starting mac, retry will be triggered anyway\n");
1981 	} else if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1982 		struct iwl_mvm_reprobe *reprobe;
1983 
1984 		IWL_ERR(mvm,
1985 			"Firmware error during reconfiguration - reprobe!\n");
1986 
1987 		/*
1988 		 * get a module reference to avoid doing this while unloading
1989 		 * anyway and to avoid scheduling a work with code that's
1990 		 * being removed.
1991 		 */
1992 		if (!try_module_get(THIS_MODULE)) {
1993 			IWL_ERR(mvm, "Module is being unloaded - abort\n");
1994 			return;
1995 		}
1996 
1997 		reprobe = kzalloc(sizeof(*reprobe), GFP_ATOMIC);
1998 		if (!reprobe) {
1999 			module_put(THIS_MODULE);
2000 			return;
2001 		}
2002 		reprobe->dev = get_device(mvm->trans->dev);
2003 		INIT_WORK(&reprobe->work, iwl_mvm_reprobe_wk);
2004 		schedule_work(&reprobe->work);
2005 	} else if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
2006 			    &mvm->status)) {
2007 		IWL_ERR(mvm, "HW restart already requested, but not started\n");
2008 	} else if (mvm->fwrt.cur_fw_img == IWL_UCODE_REGULAR &&
2009 		   mvm->hw_registered &&
2010 		   !test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) {
2011 		/* This should be first thing before trying to collect any
2012 		 * data to avoid endless loops if any HW error happens while
2013 		 * collecting debug data.
2014 		 */
2015 		set_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
2016 
2017 		if (mvm->fw->ucode_capa.error_log_size) {
2018 			u32 src_size = mvm->fw->ucode_capa.error_log_size;
2019 			u32 src_addr = mvm->fw->ucode_capa.error_log_addr;
2020 			u8 *recover_buf = kzalloc(src_size, GFP_ATOMIC);
2021 
2022 			if (recover_buf) {
2023 				mvm->error_recovery_buf = recover_buf;
2024 				iwl_trans_read_mem_bytes(mvm->trans,
2025 							 src_addr,
2026 							 recover_buf,
2027 							 src_size);
2028 			}
2029 		}
2030 
2031 		iwl_fw_error_collect(&mvm->fwrt, false);
2032 
2033 		if (fw_error && mvm->fw_restart > 0) {
2034 			mvm->fw_restart--;
2035 			ieee80211_restart_hw(mvm->hw);
2036 		} else if (mvm->fwrt.trans->dbg.restart_required) {
2037 			IWL_DEBUG_INFO(mvm, "FW restart requested after debug collection\n");
2038 			mvm->fwrt.trans->dbg.restart_required = false;
2039 			ieee80211_restart_hw(mvm->hw);
2040 		} else if (mvm->trans->trans_cfg->device_family <= IWL_DEVICE_FAMILY_8000) {
2041 			ieee80211_restart_hw(mvm->hw);
2042 		}
2043 	}
2044 }
2045 
2046 static void iwl_mvm_nic_error(struct iwl_op_mode *op_mode, bool sync)
2047 {
2048 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
2049 
2050 	if (!test_bit(STATUS_TRANS_DEAD, &mvm->trans->status) &&
2051 	    !test_and_clear_bit(IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE,
2052 				&mvm->status))
2053 		iwl_mvm_dump_nic_error_log(mvm);
2054 
2055 	if (sync) {
2056 		iwl_fw_error_collect(&mvm->fwrt, true);
2057 		/*
2058 		 * Currently, the only case for sync=true is during
2059 		 * shutdown, so just stop in this case. If/when that
2060 		 * changes, we need to be a bit smarter here.
2061 		 */
2062 		return;
2063 	}
2064 
2065 	/*
2066 	 * If the firmware crashes while we're already considering it
2067 	 * to be dead then don't ask for a restart, that cannot do
2068 	 * anything useful anyway.
2069 	 */
2070 	if (!test_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status))
2071 		return;
2072 
2073 	iwl_mvm_nic_restart(mvm, false);
2074 }
2075 
2076 static void iwl_mvm_cmd_queue_full(struct iwl_op_mode *op_mode)
2077 {
2078 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
2079 
2080 	WARN_ON(1);
2081 	iwl_mvm_nic_restart(mvm, true);
2082 }
2083 
2084 static void iwl_op_mode_mvm_time_point(struct iwl_op_mode *op_mode,
2085 				       enum iwl_fw_ini_time_point tp_id,
2086 				       union iwl_dbg_tlv_tp_data *tp_data)
2087 {
2088 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
2089 
2090 	iwl_dbg_tlv_time_point(&mvm->fwrt, tp_id, tp_data);
2091 }
2092 
2093 #define IWL_MVM_COMMON_OPS					\
2094 	/* these could be differentiated */			\
2095 	.queue_full = iwl_mvm_stop_sw_queue,			\
2096 	.queue_not_full = iwl_mvm_wake_sw_queue,		\
2097 	.hw_rf_kill = iwl_mvm_set_hw_rfkill_state,		\
2098 	.free_skb = iwl_mvm_free_skb,				\
2099 	.nic_error = iwl_mvm_nic_error,				\
2100 	.cmd_queue_full = iwl_mvm_cmd_queue_full,		\
2101 	.nic_config = iwl_mvm_nic_config,			\
2102 	/* as we only register one, these MUST be common! */	\
2103 	.start = iwl_op_mode_mvm_start,				\
2104 	.stop = iwl_op_mode_mvm_stop,				\
2105 	.time_point = iwl_op_mode_mvm_time_point
2106 
2107 static const struct iwl_op_mode_ops iwl_mvm_ops = {
2108 	IWL_MVM_COMMON_OPS,
2109 	.rx = iwl_mvm_rx,
2110 };
2111 
2112 static void iwl_mvm_rx_mq_rss(struct iwl_op_mode *op_mode,
2113 			      struct napi_struct *napi,
2114 			      struct iwl_rx_cmd_buffer *rxb,
2115 			      unsigned int queue)
2116 {
2117 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
2118 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
2119 	u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
2120 
2121 	if (unlikely(queue >= mvm->trans->num_rx_queues))
2122 		return;
2123 
2124 	if (unlikely(cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE)))
2125 		iwl_mvm_rx_frame_release(mvm, napi, rxb, queue);
2126 	else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP,
2127 					 RX_QUEUES_NOTIFICATION)))
2128 		iwl_mvm_rx_queue_notif(mvm, napi, rxb, queue);
2129 	else if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
2130 		iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, queue);
2131 }
2132 
2133 static const struct iwl_op_mode_ops iwl_mvm_ops_mq = {
2134 	IWL_MVM_COMMON_OPS,
2135 	.rx = iwl_mvm_rx_mq,
2136 	.rx_rss = iwl_mvm_rx_mq_rss,
2137 };
2138