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