xref: /linux/drivers/net/wireless/intel/iwlwifi/mvm/ops.c (revision ba1dc7f273c73b93e0e1dd9707b239ed69eebd70)
1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (C) 2012-2014, 2018-2020 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/vmalloc.h>
9 #include <net/mac80211.h>
10 
11 #include "fw/notif-wait.h"
12 #include "iwl-trans.h"
13 #include "iwl-op-mode.h"
14 #include "fw/img.h"
15 #include "iwl-debug.h"
16 #include "iwl-drv.h"
17 #include "iwl-modparams.h"
18 #include "mvm.h"
19 #include "iwl-phy-db.h"
20 #include "iwl-eeprom-parse.h"
21 #include "iwl-csr.h"
22 #include "iwl-io.h"
23 #include "iwl-prph.h"
24 #include "rs.h"
25 #include "fw/api/scan.h"
26 #include "time-event.h"
27 #include "fw-api.h"
28 #include "fw/acpi.h"
29 
30 #define DRV_DESCRIPTION	"The new Intel(R) wireless AGN driver for Linux"
31 MODULE_DESCRIPTION(DRV_DESCRIPTION);
32 MODULE_AUTHOR(DRV_AUTHOR);
33 MODULE_LICENSE("GPL");
34 
35 static const struct iwl_op_mode_ops iwl_mvm_ops;
36 static const struct iwl_op_mode_ops iwl_mvm_ops_mq;
37 
38 struct iwl_mvm_mod_params iwlmvm_mod_params = {
39 	.power_scheme = IWL_POWER_SCHEME_BPS,
40 	/* rest of fields are 0 by default */
41 };
42 
43 module_param_named(init_dbg, iwlmvm_mod_params.init_dbg, bool, 0444);
44 MODULE_PARM_DESC(init_dbg,
45 		 "set to true to debug an ASSERT in INIT fw (default: false");
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 = 0;
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 	/* SKU control */
93 	reg_val |= CSR_HW_REV_STEP(mvm->trans->hw_rev) <<
94 				CSR_HW_IF_CONFIG_REG_POS_MAC_STEP;
95 	reg_val |= CSR_HW_REV_DASH(mvm->trans->hw_rev) <<
96 				CSR_HW_IF_CONFIG_REG_POS_MAC_DASH;
97 
98 	/* radio configuration */
99 	reg_val |= radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE;
100 	reg_val |= radio_cfg_step << CSR_HW_IF_CONFIG_REG_POS_PHY_STEP;
101 	reg_val |= radio_cfg_dash << CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
102 
103 	WARN_ON((radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE) &
104 		 ~CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE);
105 
106 	/*
107 	 * TODO: Bits 7-8 of CSR in 8000 HW family and higher set the ADC
108 	 * sampling, and shouldn't be set to any non-zero value.
109 	 * The same is supposed to be true of the other HW, but unsetting
110 	 * them (such as the 7260) causes automatic tests to fail on seemingly
111 	 * unrelated errors. Need to further investigate this, but for now
112 	 * we'll separate cases.
113 	 */
114 	if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_8000)
115 		reg_val |= CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI;
116 
117 	if (iwl_fw_dbg_is_d3_debug_enabled(&mvm->fwrt))
118 		reg_val |= CSR_HW_IF_CONFIG_REG_D3_DEBUG;
119 
120 	iwl_trans_set_bits_mask(mvm->trans, CSR_HW_IF_CONFIG_REG,
121 				CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
122 				CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP |
123 				CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
124 				CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
125 				CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH |
126 				CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
127 				CSR_HW_IF_CONFIG_REG_BIT_MAC_SI   |
128 				CSR_HW_IF_CONFIG_REG_D3_DEBUG,
129 				reg_val);
130 
131 	IWL_DEBUG_INFO(mvm, "Radio type=0x%x-0x%x-0x%x\n", radio_cfg_type,
132 		       radio_cfg_step, radio_cfg_dash);
133 
134 	/*
135 	 * W/A : NIC is stuck in a reset state after Early PCIe power off
136 	 * (PCIe power is lost before PERST# is asserted), causing ME FW
137 	 * to lose ownership and not being able to obtain it back.
138 	 */
139 	if (!mvm->trans->cfg->apmg_not_supported)
140 		iwl_set_bits_mask_prph(mvm->trans, APMG_PS_CTRL_REG,
141 				       APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
142 				       ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
143 }
144 
145 static void iwl_mvm_rx_monitor_notif(struct iwl_mvm *mvm,
146 				     struct iwl_rx_cmd_buffer *rxb)
147 {
148 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
149 	struct iwl_datapath_monitor_notif *notif = (void *)pkt->data;
150 	struct ieee80211_supported_band *sband;
151 	const struct ieee80211_sta_he_cap *he_cap;
152 	struct ieee80211_vif *vif;
153 
154 	if (notif->type != cpu_to_le32(IWL_DP_MON_NOTIF_TYPE_EXT_CCA))
155 		return;
156 
157 	vif = iwl_mvm_get_vif_by_macid(mvm, notif->mac_id);
158 	if (!vif || vif->type != NL80211_IFTYPE_STATION)
159 		return;
160 
161 	if (!vif->bss_conf.chandef.chan ||
162 	    vif->bss_conf.chandef.chan->band != NL80211_BAND_2GHZ ||
163 	    vif->bss_conf.chandef.width < NL80211_CHAN_WIDTH_40)
164 		return;
165 
166 	if (!vif->bss_conf.assoc)
167 		return;
168 
169 	/* this shouldn't happen *again*, ignore it */
170 	if (mvm->cca_40mhz_workaround)
171 		return;
172 
173 	/*
174 	 * We'll decrement this on disconnect - so set to 2 since we'll
175 	 * still have to disconnect from the current AP first.
176 	 */
177 	mvm->cca_40mhz_workaround = 2;
178 
179 	/*
180 	 * This capability manipulation isn't really ideal, but it's the
181 	 * easiest choice - otherwise we'd have to do some major changes
182 	 * in mac80211 to support this, which isn't worth it. This does
183 	 * mean that userspace may have outdated information, but that's
184 	 * actually not an issue at all.
185 	 */
186 	sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
187 
188 	WARN_ON(!sband->ht_cap.ht_supported);
189 	WARN_ON(!(sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40));
190 	sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
191 
192 	he_cap = ieee80211_get_he_iftype_cap(sband,
193 					     ieee80211_vif_type_p2p(vif));
194 
195 	if (he_cap) {
196 		/* we know that ours is writable */
197 		struct ieee80211_sta_he_cap *he = (void *)he_cap;
198 
199 		WARN_ON(!he->has_he);
200 		WARN_ON(!(he->he_cap_elem.phy_cap_info[0] &
201 				IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G));
202 		he->he_cap_elem.phy_cap_info[0] &=
203 			~IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
204 	}
205 
206 	ieee80211_disconnect(vif, true);
207 }
208 
209 void iwl_mvm_apply_fw_smps_request(struct ieee80211_vif *vif)
210 {
211 	struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
212 	struct iwl_mvm *mvm = mvmvif->mvm;
213 	enum ieee80211_smps_mode mode = IEEE80211_SMPS_AUTOMATIC;
214 
215 	if (mvm->fw_static_smps_request &&
216 	    vif->bss_conf.chandef.width == NL80211_CHAN_WIDTH_160 &&
217 	    vif->bss_conf.he_support)
218 		mode = IEEE80211_SMPS_STATIC;
219 
220 	iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_FW, mode);
221 }
222 
223 static void iwl_mvm_intf_dual_chain_req(void *data, u8 *mac,
224 					struct ieee80211_vif *vif)
225 {
226 	iwl_mvm_apply_fw_smps_request(vif);
227 }
228 
229 static void iwl_mvm_rx_thermal_dual_chain_req(struct iwl_mvm *mvm,
230 					      struct iwl_rx_cmd_buffer *rxb)
231 {
232 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
233 	struct iwl_thermal_dual_chain_request *req = (void *)pkt->data;
234 
235 	/*
236 	 * We could pass it to the iterator data, but also need to remember
237 	 * it for new interfaces that are added while in this state.
238 	 */
239 	mvm->fw_static_smps_request =
240 		req->event == cpu_to_le32(THERMAL_DUAL_CHAIN_REQ_DISABLE);
241 	ieee80211_iterate_interfaces(mvm->hw, IEEE80211_IFACE_ITER_NORMAL,
242 				     iwl_mvm_intf_dual_chain_req, NULL);
243 }
244 
245 /**
246  * enum iwl_rx_handler_context context for Rx handler
247  * @RX_HANDLER_SYNC : this means that it will be called in the Rx path
248  *	which can't acquire mvm->mutex.
249  * @RX_HANDLER_ASYNC_LOCKED : If the handler needs to hold mvm->mutex
250  *	(and only in this case!), it should be set as ASYNC. In that case,
251  *	it will be called from a worker with mvm->mutex held.
252  * @RX_HANDLER_ASYNC_UNLOCKED : in case the handler needs to lock the
253  *	mutex itself, it will be called from a worker without mvm->mutex held.
254  */
255 enum iwl_rx_handler_context {
256 	RX_HANDLER_SYNC,
257 	RX_HANDLER_ASYNC_LOCKED,
258 	RX_HANDLER_ASYNC_UNLOCKED,
259 };
260 
261 /**
262  * struct iwl_rx_handlers handler for FW notification
263  * @cmd_id: command id
264  * @context: see &iwl_rx_handler_context
265  * @fn: the function is called when notification is received
266  */
267 struct iwl_rx_handlers {
268 	u16 cmd_id, min_size;
269 	enum iwl_rx_handler_context context;
270 	void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
271 };
272 
273 #define RX_HANDLER_NO_SIZE(_cmd_id, _fn, _context)		\
274 	{ .cmd_id = _cmd_id, .fn = _fn, .context = _context, }
275 #define RX_HANDLER_GRP_NO_SIZE(_grp, _cmd, _fn, _context)	\
276 	{ .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn, .context = _context, }
277 #define RX_HANDLER(_cmd_id, _fn, _context, _struct)		\
278 	{ .cmd_id = _cmd_id, .fn = _fn,				\
279 	  .context = _context, .min_size = sizeof(_struct), }
280 #define RX_HANDLER_GRP(_grp, _cmd, _fn, _context, _struct)	\
281 	{ .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn,		\
282 	  .context = _context, .min_size = sizeof(_struct), }
283 
284 /*
285  * Handlers for fw notifications
286  * Convention: RX_HANDLER(CMD_NAME, iwl_mvm_rx_CMD_NAME
287  * This list should be in order of frequency for performance purposes.
288  *
289  * The handler can be one from three contexts, see &iwl_rx_handler_context
290  */
291 static const struct iwl_rx_handlers iwl_mvm_rx_handlers[] = {
292 	RX_HANDLER(TX_CMD, iwl_mvm_rx_tx_cmd, RX_HANDLER_SYNC,
293 		   struct iwl_mvm_tx_resp),
294 	RX_HANDLER(BA_NOTIF, iwl_mvm_rx_ba_notif, RX_HANDLER_SYNC,
295 		   struct iwl_mvm_ba_notif),
296 
297 	RX_HANDLER_GRP(DATA_PATH_GROUP, TLC_MNG_UPDATE_NOTIF,
298 		       iwl_mvm_tlc_update_notif, RX_HANDLER_SYNC,
299 		       struct iwl_tlc_update_notif),
300 
301 	RX_HANDLER(BT_PROFILE_NOTIFICATION, iwl_mvm_rx_bt_coex_notif,
302 		   RX_HANDLER_ASYNC_LOCKED, struct iwl_bt_coex_profile_notif),
303 	RX_HANDLER_NO_SIZE(BEACON_NOTIFICATION, iwl_mvm_rx_beacon_notif,
304 			   RX_HANDLER_ASYNC_LOCKED),
305 	RX_HANDLER_NO_SIZE(STATISTICS_NOTIFICATION, iwl_mvm_rx_statistics,
306 			   RX_HANDLER_ASYNC_LOCKED),
307 
308 	RX_HANDLER(BA_WINDOW_STATUS_NOTIFICATION_ID,
309 		   iwl_mvm_window_status_notif, RX_HANDLER_SYNC,
310 		   struct iwl_ba_window_status_notif),
311 
312 	RX_HANDLER(TIME_EVENT_NOTIFICATION, iwl_mvm_rx_time_event_notif,
313 		   RX_HANDLER_SYNC, struct iwl_time_event_notif),
314 	RX_HANDLER_GRP(MAC_CONF_GROUP, SESSION_PROTECTION_NOTIF,
315 		       iwl_mvm_rx_session_protect_notif, RX_HANDLER_SYNC,
316 		       struct iwl_mvm_session_prot_notif),
317 	RX_HANDLER(MCC_CHUB_UPDATE_CMD, iwl_mvm_rx_chub_update_mcc,
318 		   RX_HANDLER_ASYNC_LOCKED, struct iwl_mcc_chub_notif),
319 
320 	RX_HANDLER(EOSP_NOTIFICATION, iwl_mvm_rx_eosp_notif, RX_HANDLER_SYNC,
321 		   struct iwl_mvm_eosp_notification),
322 
323 	RX_HANDLER(SCAN_ITERATION_COMPLETE,
324 		   iwl_mvm_rx_lmac_scan_iter_complete_notif, RX_HANDLER_SYNC,
325 		   struct iwl_lmac_scan_complete_notif),
326 	RX_HANDLER(SCAN_OFFLOAD_COMPLETE,
327 		   iwl_mvm_rx_lmac_scan_complete_notif,
328 		   RX_HANDLER_ASYNC_LOCKED, struct iwl_periodic_scan_complete),
329 	RX_HANDLER_NO_SIZE(MATCH_FOUND_NOTIFICATION,
330 			   iwl_mvm_rx_scan_match_found,
331 			   RX_HANDLER_SYNC),
332 	RX_HANDLER(SCAN_COMPLETE_UMAC, iwl_mvm_rx_umac_scan_complete_notif,
333 		   RX_HANDLER_ASYNC_LOCKED, struct iwl_umac_scan_complete),
334 	RX_HANDLER(SCAN_ITERATION_COMPLETE_UMAC,
335 		   iwl_mvm_rx_umac_scan_iter_complete_notif, RX_HANDLER_SYNC,
336 		   struct iwl_umac_scan_iter_complete_notif),
337 
338 	RX_HANDLER(CARD_STATE_NOTIFICATION, iwl_mvm_rx_card_state_notif,
339 		   RX_HANDLER_SYNC, struct iwl_card_state_notif),
340 
341 	RX_HANDLER(MISSED_BEACONS_NOTIFICATION, iwl_mvm_rx_missed_beacons_notif,
342 		   RX_HANDLER_SYNC, struct iwl_missed_beacons_notif),
343 
344 	RX_HANDLER(REPLY_ERROR, iwl_mvm_rx_fw_error, RX_HANDLER_SYNC,
345 		   struct iwl_error_resp),
346 	RX_HANDLER(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION,
347 		   iwl_mvm_power_uapsd_misbehaving_ap_notif, RX_HANDLER_SYNC,
348 		   struct iwl_uapsd_misbehaving_ap_notif),
349 	RX_HANDLER_NO_SIZE(DTS_MEASUREMENT_NOTIFICATION, iwl_mvm_temp_notif,
350 			   RX_HANDLER_ASYNC_LOCKED),
351 	RX_HANDLER_GRP_NO_SIZE(PHY_OPS_GROUP, DTS_MEASUREMENT_NOTIF_WIDE,
352 			       iwl_mvm_temp_notif, RX_HANDLER_ASYNC_UNLOCKED),
353 	RX_HANDLER_GRP(PHY_OPS_GROUP, CT_KILL_NOTIFICATION,
354 		       iwl_mvm_ct_kill_notif, RX_HANDLER_SYNC,
355 		       struct ct_kill_notif),
356 
357 	RX_HANDLER(TDLS_CHANNEL_SWITCH_NOTIFICATION, iwl_mvm_rx_tdls_notif,
358 		   RX_HANDLER_ASYNC_LOCKED,
359 		   struct iwl_tdls_channel_switch_notif),
360 	RX_HANDLER(MFUART_LOAD_NOTIFICATION, iwl_mvm_rx_mfuart_notif,
361 		   RX_HANDLER_SYNC, struct iwl_mfuart_load_notif_v1),
362 	RX_HANDLER_GRP(LOCATION_GROUP, TOF_RESPONDER_STATS,
363 		       iwl_mvm_ftm_responder_stats, RX_HANDLER_ASYNC_LOCKED,
364 		       struct iwl_ftm_responder_stats),
365 
366 	RX_HANDLER_GRP_NO_SIZE(LOCATION_GROUP, TOF_RANGE_RESPONSE_NOTIF,
367 			       iwl_mvm_ftm_range_resp, RX_HANDLER_ASYNC_LOCKED),
368 	RX_HANDLER_GRP_NO_SIZE(LOCATION_GROUP, TOF_LC_NOTIF,
369 			       iwl_mvm_ftm_lc_notif, RX_HANDLER_ASYNC_LOCKED),
370 
371 	RX_HANDLER_GRP(DEBUG_GROUP, MFU_ASSERT_DUMP_NTF,
372 		       iwl_mvm_mfu_assert_dump_notif, RX_HANDLER_SYNC,
373 		       struct iwl_mfu_assert_dump_notif),
374 	RX_HANDLER_GRP(PROT_OFFLOAD_GROUP, STORED_BEACON_NTF,
375 		       iwl_mvm_rx_stored_beacon_notif, RX_HANDLER_SYNC,
376 		       struct iwl_stored_beacon_notif_v2),
377 	RX_HANDLER_GRP(DATA_PATH_GROUP, MU_GROUP_MGMT_NOTIF,
378 		       iwl_mvm_mu_mimo_grp_notif, RX_HANDLER_SYNC,
379 		       struct iwl_mu_group_mgmt_notif),
380 	RX_HANDLER_GRP(DATA_PATH_GROUP, STA_PM_NOTIF,
381 		       iwl_mvm_sta_pm_notif, RX_HANDLER_SYNC,
382 		       struct iwl_mvm_pm_state_notification),
383 	RX_HANDLER_GRP(MAC_CONF_GROUP, PROBE_RESPONSE_DATA_NOTIF,
384 		       iwl_mvm_probe_resp_data_notif,
385 		       RX_HANDLER_ASYNC_LOCKED,
386 		       struct iwl_probe_resp_data_notif),
387 	RX_HANDLER_GRP(MAC_CONF_GROUP, CHANNEL_SWITCH_NOA_NOTIF,
388 		       iwl_mvm_channel_switch_noa_notif,
389 		       RX_HANDLER_SYNC, struct iwl_channel_switch_noa_notif),
390 	RX_HANDLER_GRP(DATA_PATH_GROUP, MONITOR_NOTIF,
391 		       iwl_mvm_rx_monitor_notif, RX_HANDLER_ASYNC_LOCKED,
392 		       struct iwl_datapath_monitor_notif),
393 
394 	RX_HANDLER_GRP(DATA_PATH_GROUP, THERMAL_DUAL_CHAIN_REQUEST,
395 		       iwl_mvm_rx_thermal_dual_chain_req,
396 		       RX_HANDLER_ASYNC_LOCKED,
397 		       struct iwl_thermal_dual_chain_request),
398 };
399 #undef RX_HANDLER
400 #undef RX_HANDLER_GRP
401 
402 /* Please keep this array *SORTED* by hex value.
403  * Access is done through binary search
404  */
405 static const struct iwl_hcmd_names iwl_mvm_legacy_names[] = {
406 	HCMD_NAME(UCODE_ALIVE_NTFY),
407 	HCMD_NAME(REPLY_ERROR),
408 	HCMD_NAME(ECHO_CMD),
409 	HCMD_NAME(INIT_COMPLETE_NOTIF),
410 	HCMD_NAME(PHY_CONTEXT_CMD),
411 	HCMD_NAME(DBG_CFG),
412 	HCMD_NAME(SCAN_CFG_CMD),
413 	HCMD_NAME(SCAN_REQ_UMAC),
414 	HCMD_NAME(SCAN_ABORT_UMAC),
415 	HCMD_NAME(SCAN_COMPLETE_UMAC),
416 	HCMD_NAME(BA_WINDOW_STATUS_NOTIFICATION_ID),
417 	HCMD_NAME(ADD_STA_KEY),
418 	HCMD_NAME(ADD_STA),
419 	HCMD_NAME(REMOVE_STA),
420 	HCMD_NAME(FW_GET_ITEM_CMD),
421 	HCMD_NAME(TX_CMD),
422 	HCMD_NAME(SCD_QUEUE_CFG),
423 	HCMD_NAME(TXPATH_FLUSH),
424 	HCMD_NAME(MGMT_MCAST_KEY),
425 	HCMD_NAME(WEP_KEY),
426 	HCMD_NAME(SHARED_MEM_CFG),
427 	HCMD_NAME(TDLS_CHANNEL_SWITCH_CMD),
428 	HCMD_NAME(MAC_CONTEXT_CMD),
429 	HCMD_NAME(TIME_EVENT_CMD),
430 	HCMD_NAME(TIME_EVENT_NOTIFICATION),
431 	HCMD_NAME(BINDING_CONTEXT_CMD),
432 	HCMD_NAME(TIME_QUOTA_CMD),
433 	HCMD_NAME(NON_QOS_TX_COUNTER_CMD),
434 	HCMD_NAME(LEDS_CMD),
435 	HCMD_NAME(LQ_CMD),
436 	HCMD_NAME(FW_PAGING_BLOCK_CMD),
437 	HCMD_NAME(SCAN_OFFLOAD_REQUEST_CMD),
438 	HCMD_NAME(SCAN_OFFLOAD_ABORT_CMD),
439 	HCMD_NAME(HOT_SPOT_CMD),
440 	HCMD_NAME(SCAN_OFFLOAD_PROFILES_QUERY_CMD),
441 	HCMD_NAME(BT_COEX_UPDATE_REDUCED_TXP),
442 	HCMD_NAME(BT_COEX_CI),
443 	HCMD_NAME(PHY_CONFIGURATION_CMD),
444 	HCMD_NAME(CALIB_RES_NOTIF_PHY_DB),
445 	HCMD_NAME(PHY_DB_CMD),
446 	HCMD_NAME(SCAN_OFFLOAD_COMPLETE),
447 	HCMD_NAME(SCAN_OFFLOAD_UPDATE_PROFILES_CMD),
448 	HCMD_NAME(POWER_TABLE_CMD),
449 	HCMD_NAME(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION),
450 	HCMD_NAME(REPLY_THERMAL_MNG_BACKOFF),
451 	HCMD_NAME(DC2DC_CONFIG_CMD),
452 	HCMD_NAME(NVM_ACCESS_CMD),
453 	HCMD_NAME(BEACON_NOTIFICATION),
454 	HCMD_NAME(BEACON_TEMPLATE_CMD),
455 	HCMD_NAME(TX_ANT_CONFIGURATION_CMD),
456 	HCMD_NAME(BT_CONFIG),
457 	HCMD_NAME(STATISTICS_CMD),
458 	HCMD_NAME(STATISTICS_NOTIFICATION),
459 	HCMD_NAME(EOSP_NOTIFICATION),
460 	HCMD_NAME(REDUCE_TX_POWER_CMD),
461 	HCMD_NAME(CARD_STATE_NOTIFICATION),
462 	HCMD_NAME(MISSED_BEACONS_NOTIFICATION),
463 	HCMD_NAME(TDLS_CONFIG_CMD),
464 	HCMD_NAME(MAC_PM_POWER_TABLE),
465 	HCMD_NAME(TDLS_CHANNEL_SWITCH_NOTIFICATION),
466 	HCMD_NAME(MFUART_LOAD_NOTIFICATION),
467 	HCMD_NAME(RSS_CONFIG_CMD),
468 	HCMD_NAME(SCAN_ITERATION_COMPLETE_UMAC),
469 	HCMD_NAME(REPLY_RX_PHY_CMD),
470 	HCMD_NAME(REPLY_RX_MPDU_CMD),
471 	HCMD_NAME(BAR_FRAME_RELEASE),
472 	HCMD_NAME(FRAME_RELEASE),
473 	HCMD_NAME(BA_NOTIF),
474 	HCMD_NAME(MCC_UPDATE_CMD),
475 	HCMD_NAME(MCC_CHUB_UPDATE_CMD),
476 	HCMD_NAME(MARKER_CMD),
477 	HCMD_NAME(BT_PROFILE_NOTIFICATION),
478 	HCMD_NAME(BCAST_FILTER_CMD),
479 	HCMD_NAME(MCAST_FILTER_CMD),
480 	HCMD_NAME(REPLY_SF_CFG_CMD),
481 	HCMD_NAME(REPLY_BEACON_FILTERING_CMD),
482 	HCMD_NAME(D3_CONFIG_CMD),
483 	HCMD_NAME(PROT_OFFLOAD_CONFIG_CMD),
484 	HCMD_NAME(OFFLOADS_QUERY_CMD),
485 	HCMD_NAME(MATCH_FOUND_NOTIFICATION),
486 	HCMD_NAME(DTS_MEASUREMENT_NOTIFICATION),
487 	HCMD_NAME(WOWLAN_PATTERNS),
488 	HCMD_NAME(WOWLAN_CONFIGURATION),
489 	HCMD_NAME(WOWLAN_TSC_RSC_PARAM),
490 	HCMD_NAME(WOWLAN_TKIP_PARAM),
491 	HCMD_NAME(WOWLAN_KEK_KCK_MATERIAL),
492 	HCMD_NAME(WOWLAN_GET_STATUSES),
493 	HCMD_NAME(SCAN_ITERATION_COMPLETE),
494 	HCMD_NAME(D0I3_END_CMD),
495 	HCMD_NAME(LTR_CONFIG),
496 	HCMD_NAME(LDBG_CONFIG_CMD),
497 };
498 
499 /* Please keep this array *SORTED* by hex value.
500  * Access is done through binary search
501  */
502 static const struct iwl_hcmd_names iwl_mvm_system_names[] = {
503 	HCMD_NAME(SHARED_MEM_CFG_CMD),
504 	HCMD_NAME(INIT_EXTENDED_CFG_CMD),
505 	HCMD_NAME(FW_ERROR_RECOVERY_CMD),
506 };
507 
508 /* Please keep this array *SORTED* by hex value.
509  * Access is done through binary search
510  */
511 static const struct iwl_hcmd_names iwl_mvm_mac_conf_names[] = {
512 	HCMD_NAME(CHANNEL_SWITCH_TIME_EVENT_CMD),
513 	HCMD_NAME(SESSION_PROTECTION_CMD),
514 	HCMD_NAME(SESSION_PROTECTION_NOTIF),
515 	HCMD_NAME(CHANNEL_SWITCH_NOA_NOTIF),
516 };
517 
518 /* Please keep this array *SORTED* by hex value.
519  * Access is done through binary search
520  */
521 static const struct iwl_hcmd_names iwl_mvm_phy_names[] = {
522 	HCMD_NAME(CMD_DTS_MEASUREMENT_TRIGGER_WIDE),
523 	HCMD_NAME(CTDP_CONFIG_CMD),
524 	HCMD_NAME(TEMP_REPORTING_THRESHOLDS_CMD),
525 	HCMD_NAME(GEO_TX_POWER_LIMIT),
526 	HCMD_NAME(CT_KILL_NOTIFICATION),
527 	HCMD_NAME(DTS_MEASUREMENT_NOTIF_WIDE),
528 };
529 
530 /* Please keep this array *SORTED* by hex value.
531  * Access is done through binary search
532  */
533 static const struct iwl_hcmd_names iwl_mvm_data_path_names[] = {
534 	HCMD_NAME(DQA_ENABLE_CMD),
535 	HCMD_NAME(UPDATE_MU_GROUPS_CMD),
536 	HCMD_NAME(TRIGGER_RX_QUEUES_NOTIF_CMD),
537 	HCMD_NAME(STA_HE_CTXT_CMD),
538 	HCMD_NAME(RFH_QUEUE_CONFIG_CMD),
539 	HCMD_NAME(TLC_MNG_CONFIG_CMD),
540 	HCMD_NAME(CHEST_COLLECTOR_FILTER_CONFIG_CMD),
541 	HCMD_NAME(MONITOR_NOTIF),
542 	HCMD_NAME(THERMAL_DUAL_CHAIN_REQUEST),
543 	HCMD_NAME(STA_PM_NOTIF),
544 	HCMD_NAME(MU_GROUP_MGMT_NOTIF),
545 	HCMD_NAME(RX_QUEUES_NOTIFICATION),
546 };
547 
548 /* Please keep this array *SORTED* by hex value.
549  * Access is done through binary search
550  */
551 static const struct iwl_hcmd_names iwl_mvm_location_names[] = {
552 	HCMD_NAME(TOF_RANGE_REQ_CMD),
553 	HCMD_NAME(TOF_CONFIG_CMD),
554 	HCMD_NAME(TOF_RANGE_ABORT_CMD),
555 	HCMD_NAME(TOF_RANGE_REQ_EXT_CMD),
556 	HCMD_NAME(TOF_RESPONDER_CONFIG_CMD),
557 	HCMD_NAME(TOF_RESPONDER_DYN_CONFIG_CMD),
558 	HCMD_NAME(TOF_LC_NOTIF),
559 	HCMD_NAME(TOF_RESPONDER_STATS),
560 	HCMD_NAME(TOF_MCSI_DEBUG_NOTIF),
561 	HCMD_NAME(TOF_RANGE_RESPONSE_NOTIF),
562 };
563 
564 /* Please keep this array *SORTED* by hex value.
565  * Access is done through binary search
566  */
567 static const struct iwl_hcmd_names iwl_mvm_prot_offload_names[] = {
568 	HCMD_NAME(STORED_BEACON_NTF),
569 };
570 
571 /* Please keep this array *SORTED* by hex value.
572  * Access is done through binary search
573  */
574 static const struct iwl_hcmd_names iwl_mvm_regulatory_and_nvm_names[] = {
575 	HCMD_NAME(NVM_ACCESS_COMPLETE),
576 	HCMD_NAME(NVM_GET_INFO),
577 	HCMD_NAME(TAS_CONFIG),
578 };
579 
580 static const struct iwl_hcmd_arr iwl_mvm_groups[] = {
581 	[LEGACY_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
582 	[LONG_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),
583 	[SYSTEM_GROUP] = HCMD_ARR(iwl_mvm_system_names),
584 	[MAC_CONF_GROUP] = HCMD_ARR(iwl_mvm_mac_conf_names),
585 	[PHY_OPS_GROUP] = HCMD_ARR(iwl_mvm_phy_names),
586 	[DATA_PATH_GROUP] = HCMD_ARR(iwl_mvm_data_path_names),
587 	[LOCATION_GROUP] = HCMD_ARR(iwl_mvm_location_names),
588 	[PROT_OFFLOAD_GROUP] = HCMD_ARR(iwl_mvm_prot_offload_names),
589 	[REGULATORY_AND_NVM_GROUP] =
590 		HCMD_ARR(iwl_mvm_regulatory_and_nvm_names),
591 };
592 
593 /* this forward declaration can avoid to export the function */
594 static void iwl_mvm_async_handlers_wk(struct work_struct *wk);
595 
596 static u32 iwl_mvm_min_backoff(struct iwl_mvm *mvm)
597 {
598 	const struct iwl_pwr_tx_backoff *backoff = mvm->cfg->pwr_tx_backoffs;
599 	u64 dflt_pwr_limit;
600 
601 	if (!backoff)
602 		return 0;
603 
604 	dflt_pwr_limit = iwl_acpi_get_pwr_limit(mvm->dev);
605 
606 	while (backoff->pwr) {
607 		if (dflt_pwr_limit >= backoff->pwr)
608 			return backoff->backoff;
609 
610 		backoff++;
611 	}
612 
613 	return 0;
614 }
615 
616 static void iwl_mvm_tx_unblock_dwork(struct work_struct *work)
617 {
618 	struct iwl_mvm *mvm =
619 		container_of(work, struct iwl_mvm, cs_tx_unblock_dwork.work);
620 	struct ieee80211_vif *tx_blocked_vif;
621 	struct iwl_mvm_vif *mvmvif;
622 
623 	mutex_lock(&mvm->mutex);
624 
625 	tx_blocked_vif =
626 		rcu_dereference_protected(mvm->csa_tx_blocked_vif,
627 					  lockdep_is_held(&mvm->mutex));
628 
629 	if (!tx_blocked_vif)
630 		goto unlock;
631 
632 	mvmvif = iwl_mvm_vif_from_mac80211(tx_blocked_vif);
633 	iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);
634 	RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);
635 unlock:
636 	mutex_unlock(&mvm->mutex);
637 }
638 
639 static int iwl_mvm_fwrt_dump_start(void *ctx)
640 {
641 	struct iwl_mvm *mvm = ctx;
642 
643 	mutex_lock(&mvm->mutex);
644 
645 	return 0;
646 }
647 
648 static void iwl_mvm_fwrt_dump_end(void *ctx)
649 {
650 	struct iwl_mvm *mvm = ctx;
651 
652 	mutex_unlock(&mvm->mutex);
653 }
654 
655 static bool iwl_mvm_fwrt_fw_running(void *ctx)
656 {
657 	return iwl_mvm_firmware_running(ctx);
658 }
659 
660 static int iwl_mvm_fwrt_send_hcmd(void *ctx, struct iwl_host_cmd *host_cmd)
661 {
662 	struct iwl_mvm *mvm = (struct iwl_mvm *)ctx;
663 	int ret;
664 
665 	mutex_lock(&mvm->mutex);
666 	ret = iwl_mvm_send_cmd(mvm, host_cmd);
667 	mutex_unlock(&mvm->mutex);
668 
669 	return ret;
670 }
671 
672 static bool iwl_mvm_d3_debug_enable(void *ctx)
673 {
674 	return IWL_MVM_D3_DEBUG;
675 }
676 
677 static const struct iwl_fw_runtime_ops iwl_mvm_fwrt_ops = {
678 	.dump_start = iwl_mvm_fwrt_dump_start,
679 	.dump_end = iwl_mvm_fwrt_dump_end,
680 	.fw_running = iwl_mvm_fwrt_fw_running,
681 	.send_hcmd = iwl_mvm_fwrt_send_hcmd,
682 	.d3_debug_enable = iwl_mvm_d3_debug_enable,
683 };
684 
685 static int iwl_mvm_start_get_nvm(struct iwl_mvm *mvm)
686 {
687 	int ret;
688 
689 	mutex_lock(&mvm->mutex);
690 
691 	ret = iwl_run_init_mvm_ucode(mvm);
692 
693 	if (ret && ret != -ERFKILL)
694 		iwl_fw_dbg_error_collect(&mvm->fwrt, FW_DBG_TRIGGER_DRIVER);
695 	if (!ret && iwl_mvm_is_lar_supported(mvm)) {
696 		mvm->hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
697 		ret = iwl_mvm_init_mcc(mvm);
698 	}
699 
700 	if (!iwlmvm_mod_params.init_dbg || !ret)
701 		iwl_mvm_stop_device(mvm);
702 
703 	mutex_unlock(&mvm->mutex);
704 	rtnl_unlock();
705 
706 	if (ret < 0)
707 		IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
708 
709 	return ret;
710 }
711 
712 static int iwl_mvm_start_post_nvm(struct iwl_mvm *mvm)
713 {
714 	int ret;
715 
716 	iwl_mvm_toggle_tx_ant(mvm, &mvm->mgmt_last_antenna_idx);
717 
718 	ret = iwl_mvm_mac_setup_register(mvm);
719 	if (ret)
720 		return ret;
721 	mvm->hw_registered = true;
722 
723 	iwl_mvm_dbgfs_register(mvm);
724 
725 	return 0;
726 }
727 
728 static struct iwl_op_mode *
729 iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
730 		      const struct iwl_fw *fw, struct dentry *dbgfs_dir)
731 {
732 	struct ieee80211_hw *hw;
733 	struct iwl_op_mode *op_mode;
734 	struct iwl_mvm *mvm;
735 	struct iwl_trans_config trans_cfg = {};
736 	static const u8 no_reclaim_cmds[] = {
737 		TX_CMD,
738 	};
739 	int err, scan_size;
740 	u32 min_backoff;
741 	enum iwl_amsdu_size rb_size_default;
742 
743 	/*
744 	 * We use IWL_MVM_STATION_COUNT_MAX to check the validity of the station
745 	 * index all over the driver - check that its value corresponds to the
746 	 * array size.
747 	 */
748 	BUILD_BUG_ON(ARRAY_SIZE(mvm->fw_id_to_mac_id) !=
749 		     IWL_MVM_STATION_COUNT_MAX);
750 
751 	/********************************
752 	 * 1. Allocating and configuring HW data
753 	 ********************************/
754 	hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) +
755 				sizeof(struct iwl_mvm),
756 				&iwl_mvm_hw_ops);
757 	if (!hw)
758 		return NULL;
759 
760 	hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
761 
762 	if (cfg->max_tx_agg_size)
763 		hw->max_tx_aggregation_subframes = cfg->max_tx_agg_size;
764 	else
765 		hw->max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
766 
767 	op_mode = hw->priv;
768 
769 	mvm = IWL_OP_MODE_GET_MVM(op_mode);
770 	mvm->dev = trans->dev;
771 	mvm->trans = trans;
772 	mvm->cfg = cfg;
773 	mvm->fw = fw;
774 	mvm->hw = hw;
775 
776 	iwl_fw_runtime_init(&mvm->fwrt, trans, fw, &iwl_mvm_fwrt_ops, mvm,
777 			    dbgfs_dir);
778 
779 	iwl_mvm_get_acpi_tables(mvm);
780 
781 	mvm->init_status = 0;
782 
783 	if (iwl_mvm_has_new_rx_api(mvm)) {
784 		op_mode->ops = &iwl_mvm_ops_mq;
785 		trans->rx_mpdu_cmd_hdr_size =
786 			(trans->trans_cfg->device_family >=
787 			 IWL_DEVICE_FAMILY_AX210) ?
788 			sizeof(struct iwl_rx_mpdu_desc) :
789 			IWL_RX_DESC_SIZE_V1;
790 	} else {
791 		op_mode->ops = &iwl_mvm_ops;
792 		trans->rx_mpdu_cmd_hdr_size =
793 			sizeof(struct iwl_rx_mpdu_res_start);
794 
795 		if (WARN_ON(trans->num_rx_queues > 1))
796 			goto out_free;
797 	}
798 
799 	mvm->fw_restart = iwlwifi_mod_params.fw_restart ? -1 : 0;
800 
801 	if (iwl_mvm_has_new_tx_api(mvm)) {
802 		/*
803 		 * If we have the new TX/queue allocation API initialize them
804 		 * all to invalid numbers. We'll rewrite the ones that we need
805 		 * later, but that doesn't happen for all of them all of the
806 		 * time (e.g. P2P Device is optional), and if a dynamic queue
807 		 * ends up getting number 2 (IWL_MVM_DQA_P2P_DEVICE_QUEUE) then
808 		 * iwl_mvm_is_static_queue() erroneously returns true, and we
809 		 * might have things getting stuck.
810 		 */
811 		mvm->aux_queue = IWL_MVM_INVALID_QUEUE;
812 		mvm->snif_queue = IWL_MVM_INVALID_QUEUE;
813 		mvm->probe_queue = IWL_MVM_INVALID_QUEUE;
814 		mvm->p2p_dev_queue = IWL_MVM_INVALID_QUEUE;
815 	} else {
816 		mvm->aux_queue = IWL_MVM_DQA_AUX_QUEUE;
817 		mvm->snif_queue = IWL_MVM_DQA_INJECT_MONITOR_QUEUE;
818 		mvm->probe_queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE;
819 		mvm->p2p_dev_queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE;
820 	}
821 
822 	mvm->sf_state = SF_UNINIT;
823 	if (iwl_mvm_has_unified_ucode(mvm))
824 		iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_REGULAR);
825 	else
826 		iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_INIT);
827 	mvm->drop_bcn_ap_mode = true;
828 
829 	mutex_init(&mvm->mutex);
830 	spin_lock_init(&mvm->async_handlers_lock);
831 	INIT_LIST_HEAD(&mvm->time_event_list);
832 	INIT_LIST_HEAD(&mvm->aux_roc_te_list);
833 	INIT_LIST_HEAD(&mvm->async_handlers_list);
834 	spin_lock_init(&mvm->time_event_lock);
835 	INIT_LIST_HEAD(&mvm->ftm_initiator.loc_list);
836 	INIT_LIST_HEAD(&mvm->ftm_initiator.pasn_list);
837 	INIT_LIST_HEAD(&mvm->resp_pasn_list);
838 
839 	INIT_WORK(&mvm->async_handlers_wk, iwl_mvm_async_handlers_wk);
840 	INIT_WORK(&mvm->roc_done_wk, iwl_mvm_roc_done_wk);
841 	INIT_DELAYED_WORK(&mvm->tdls_cs.dwork, iwl_mvm_tdls_ch_switch_work);
842 	INIT_DELAYED_WORK(&mvm->scan_timeout_dwork, iwl_mvm_scan_timeout_wk);
843 	INIT_WORK(&mvm->add_stream_wk, iwl_mvm_add_new_dqa_stream_wk);
844 	INIT_LIST_HEAD(&mvm->add_stream_txqs);
845 
846 	init_waitqueue_head(&mvm->rx_sync_waitq);
847 
848 	mvm->queue_sync_state = 0;
849 
850 	SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev);
851 
852 	spin_lock_init(&mvm->tcm.lock);
853 	INIT_DELAYED_WORK(&mvm->tcm.work, iwl_mvm_tcm_work);
854 	mvm->tcm.ts = jiffies;
855 	mvm->tcm.ll_ts = jiffies;
856 	mvm->tcm.uapsd_nonagg_ts = jiffies;
857 
858 	INIT_DELAYED_WORK(&mvm->cs_tx_unblock_dwork, iwl_mvm_tx_unblock_dwork);
859 
860 	mvm->cmd_ver.d0i3_resp =
861 		iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP, D0I3_END_CMD,
862 					0);
863 	/* we only support version 1 */
864 	if (WARN_ON_ONCE(mvm->cmd_ver.d0i3_resp > 1))
865 		goto out_free;
866 
867 	mvm->cmd_ver.range_resp =
868 		iwl_fw_lookup_notif_ver(mvm->fw, LOCATION_GROUP,
869 					TOF_RANGE_RESPONSE_NOTIF, 5);
870 	/* we only support up to version 8 */
871 	if (WARN_ON_ONCE(mvm->cmd_ver.range_resp > 8))
872 		goto out_free;
873 
874 	/*
875 	 * Populate the state variables that the transport layer needs
876 	 * to know about.
877 	 */
878 	trans_cfg.op_mode = op_mode;
879 	trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
880 	trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
881 
882 	if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
883 		rb_size_default = IWL_AMSDU_2K;
884 	else
885 		rb_size_default = IWL_AMSDU_4K;
886 
887 	switch (iwlwifi_mod_params.amsdu_size) {
888 	case IWL_AMSDU_DEF:
889 		trans_cfg.rx_buf_size = rb_size_default;
890 		break;
891 	case IWL_AMSDU_4K:
892 		trans_cfg.rx_buf_size = IWL_AMSDU_4K;
893 		break;
894 	case IWL_AMSDU_8K:
895 		trans_cfg.rx_buf_size = IWL_AMSDU_8K;
896 		break;
897 	case IWL_AMSDU_12K:
898 		trans_cfg.rx_buf_size = IWL_AMSDU_12K;
899 		break;
900 	default:
901 		pr_err("%s: Unsupported amsdu_size: %d\n", KBUILD_MODNAME,
902 		       iwlwifi_mod_params.amsdu_size);
903 		trans_cfg.rx_buf_size = rb_size_default;
904 	}
905 
906 	trans->wide_cmd_header = true;
907 	trans_cfg.bc_table_dword =
908 		mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_AX210;
909 
910 	trans_cfg.command_groups = iwl_mvm_groups;
911 	trans_cfg.command_groups_size = ARRAY_SIZE(iwl_mvm_groups);
912 
913 	trans_cfg.cmd_queue = IWL_MVM_DQA_CMD_QUEUE;
914 	trans_cfg.cmd_fifo = IWL_MVM_TX_FIFO_CMD;
915 	trans_cfg.scd_set_active = true;
916 
917 	trans_cfg.cb_data_offs = offsetof(struct ieee80211_tx_info,
918 					  driver_data[2]);
919 
920 	/* Set a short watchdog for the command queue */
921 	trans_cfg.cmd_q_wdg_timeout =
922 		iwl_mvm_get_wd_timeout(mvm, NULL, false, true);
923 
924 	snprintf(mvm->hw->wiphy->fw_version,
925 		 sizeof(mvm->hw->wiphy->fw_version),
926 		 "%s", fw->fw_version);
927 
928 	trans_cfg.fw_reset_handshake = fw_has_capa(&mvm->fw->ucode_capa,
929 						   IWL_UCODE_TLV_CAPA_FW_RESET_HANDSHAKE);
930 
931 	/* Configure transport layer */
932 	iwl_trans_configure(mvm->trans, &trans_cfg);
933 
934 	trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
935 	trans->dbg.dest_tlv = mvm->fw->dbg.dest_tlv;
936 	trans->dbg.n_dest_reg = mvm->fw->dbg.n_dest_reg;
937 	memcpy(trans->dbg.conf_tlv, mvm->fw->dbg.conf_tlv,
938 	       sizeof(trans->dbg.conf_tlv));
939 	trans->dbg.trigger_tlv = mvm->fw->dbg.trigger_tlv;
940 
941 	trans->iml = mvm->fw->iml;
942 	trans->iml_len = mvm->fw->iml_len;
943 
944 	/* set up notification wait support */
945 	iwl_notification_wait_init(&mvm->notif_wait);
946 
947 	/* Init phy db */
948 	mvm->phy_db = iwl_phy_db_init(trans);
949 	if (!mvm->phy_db) {
950 		IWL_ERR(mvm, "Cannot init phy_db\n");
951 		goto out_free;
952 	}
953 
954 	IWL_INFO(mvm, "Detected %s, REV=0x%X\n",
955 		 mvm->trans->name, mvm->trans->hw_rev);
956 
957 	if (iwlwifi_mod_params.nvm_file)
958 		mvm->nvm_file_name = iwlwifi_mod_params.nvm_file;
959 	else
960 		IWL_DEBUG_EEPROM(mvm->trans->dev,
961 				 "working without external nvm file\n");
962 
963 	err = iwl_trans_start_hw(mvm->trans);
964 	if (err)
965 		goto out_free;
966 
967 	scan_size = iwl_mvm_scan_size(mvm);
968 
969 	mvm->scan_cmd = kmalloc(scan_size, GFP_KERNEL);
970 	if (!mvm->scan_cmd)
971 		goto out_free;
972 
973 	/* invalidate ids to prevent accidental removal of sta_id 0 */
974 	mvm->aux_sta.sta_id = IWL_MVM_INVALID_STA;
975 	mvm->snif_sta.sta_id = IWL_MVM_INVALID_STA;
976 
977 	/* Set EBS as successful as long as not stated otherwise by the FW. */
978 	mvm->last_ebs_successful = true;
979 
980 	min_backoff = iwl_mvm_min_backoff(mvm);
981 	iwl_mvm_thermal_initialize(mvm, min_backoff);
982 
983 	if (!iwl_mvm_has_new_rx_stats_api(mvm))
984 		memset(&mvm->rx_stats_v3, 0,
985 		       sizeof(struct mvm_statistics_rx_v3));
986 	else
987 		memset(&mvm->rx_stats, 0, sizeof(struct mvm_statistics_rx));
988 
989 	mvm->debugfs_dir = dbgfs_dir;
990 
991 	if (iwl_mvm_start_get_nvm(mvm))
992 		goto out_thermal_exit;
993 
994 	if (iwl_mvm_start_post_nvm(mvm))
995 		goto out_thermal_exit;
996 
997 	return op_mode;
998 
999  out_thermal_exit:
1000 	iwl_mvm_thermal_exit(mvm);
1001  out_free:
1002 	iwl_fw_flush_dumps(&mvm->fwrt);
1003 	iwl_fw_runtime_free(&mvm->fwrt);
1004 
1005 	if (iwlmvm_mod_params.init_dbg)
1006 		return op_mode;
1007 	iwl_phy_db_free(mvm->phy_db);
1008 	kfree(mvm->scan_cmd);
1009 	iwl_trans_op_mode_leave(trans);
1010 
1011 	ieee80211_free_hw(mvm->hw);
1012 	return NULL;
1013 }
1014 
1015 void iwl_mvm_stop_device(struct iwl_mvm *mvm)
1016 {
1017 	lockdep_assert_held(&mvm->mutex);
1018 
1019 	iwl_fw_cancel_timestamp(&mvm->fwrt);
1020 
1021 	clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1022 
1023 	iwl_fw_dbg_stop_sync(&mvm->fwrt);
1024 	iwl_trans_stop_device(mvm->trans);
1025 	iwl_free_fw_paging(&mvm->fwrt);
1026 	iwl_fw_dump_conf_clear(&mvm->fwrt);
1027 }
1028 
1029 static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
1030 {
1031 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1032 	int i;
1033 
1034 	iwl_mvm_leds_exit(mvm);
1035 
1036 	iwl_mvm_thermal_exit(mvm);
1037 
1038 	ieee80211_unregister_hw(mvm->hw);
1039 
1040 	kfree(mvm->scan_cmd);
1041 	kfree(mvm->mcast_filter_cmd);
1042 	mvm->mcast_filter_cmd = NULL;
1043 
1044 	kfree(mvm->error_recovery_buf);
1045 	mvm->error_recovery_buf = NULL;
1046 
1047 	iwl_trans_op_mode_leave(mvm->trans);
1048 
1049 	iwl_phy_db_free(mvm->phy_db);
1050 	mvm->phy_db = NULL;
1051 
1052 	kfree(mvm->nvm_data);
1053 	for (i = 0; i < NVM_MAX_NUM_SECTIONS; i++)
1054 		kfree(mvm->nvm_sections[i].data);
1055 
1056 	cancel_delayed_work_sync(&mvm->tcm.work);
1057 
1058 	iwl_fw_runtime_free(&mvm->fwrt);
1059 	mutex_destroy(&mvm->mutex);
1060 
1061 	ieee80211_free_hw(mvm->hw);
1062 }
1063 
1064 struct iwl_async_handler_entry {
1065 	struct list_head list;
1066 	struct iwl_rx_cmd_buffer rxb;
1067 	enum iwl_rx_handler_context context;
1068 	void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1069 };
1070 
1071 void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm)
1072 {
1073 	struct iwl_async_handler_entry *entry, *tmp;
1074 
1075 	spin_lock_bh(&mvm->async_handlers_lock);
1076 	list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {
1077 		iwl_free_rxb(&entry->rxb);
1078 		list_del(&entry->list);
1079 		kfree(entry);
1080 	}
1081 	spin_unlock_bh(&mvm->async_handlers_lock);
1082 }
1083 
1084 static void iwl_mvm_async_handlers_wk(struct work_struct *wk)
1085 {
1086 	struct iwl_mvm *mvm =
1087 		container_of(wk, struct iwl_mvm, async_handlers_wk);
1088 	struct iwl_async_handler_entry *entry, *tmp;
1089 	LIST_HEAD(local_list);
1090 
1091 	/* Ensure that we are not in stop flow (check iwl_mvm_mac_stop) */
1092 
1093 	/*
1094 	 * Sync with Rx path with a lock. Remove all the entries from this list,
1095 	 * add them to a local one (lock free), and then handle them.
1096 	 */
1097 	spin_lock_bh(&mvm->async_handlers_lock);
1098 	list_splice_init(&mvm->async_handlers_list, &local_list);
1099 	spin_unlock_bh(&mvm->async_handlers_lock);
1100 
1101 	list_for_each_entry_safe(entry, tmp, &local_list, list) {
1102 		if (entry->context == RX_HANDLER_ASYNC_LOCKED)
1103 			mutex_lock(&mvm->mutex);
1104 		entry->fn(mvm, &entry->rxb);
1105 		iwl_free_rxb(&entry->rxb);
1106 		list_del(&entry->list);
1107 		if (entry->context == RX_HANDLER_ASYNC_LOCKED)
1108 			mutex_unlock(&mvm->mutex);
1109 		kfree(entry);
1110 	}
1111 }
1112 
1113 static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm,
1114 					    struct iwl_rx_packet *pkt)
1115 {
1116 	struct iwl_fw_dbg_trigger_tlv *trig;
1117 	struct iwl_fw_dbg_trigger_cmd *cmds_trig;
1118 	int i;
1119 
1120 	trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, NULL,
1121 				     FW_DBG_TRIGGER_FW_NOTIF);
1122 	if (!trig)
1123 		return;
1124 
1125 	cmds_trig = (void *)trig->data;
1126 
1127 	for (i = 0; i < ARRAY_SIZE(cmds_trig->cmds); i++) {
1128 		/* don't collect on CMD 0 */
1129 		if (!cmds_trig->cmds[i].cmd_id)
1130 			break;
1131 
1132 		if (cmds_trig->cmds[i].cmd_id != pkt->hdr.cmd ||
1133 		    cmds_trig->cmds[i].group_id != pkt->hdr.group_id)
1134 			continue;
1135 
1136 		iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
1137 					"CMD 0x%02x.%02x received",
1138 					pkt->hdr.group_id, pkt->hdr.cmd);
1139 		break;
1140 	}
1141 }
1142 
1143 static void iwl_mvm_rx_common(struct iwl_mvm *mvm,
1144 			      struct iwl_rx_cmd_buffer *rxb,
1145 			      struct iwl_rx_packet *pkt)
1146 {
1147 	unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
1148 	int i;
1149 	union iwl_dbg_tlv_tp_data tp_data = { .fw_pkt = pkt };
1150 
1151 	iwl_dbg_tlv_time_point(&mvm->fwrt,
1152 			       IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF, &tp_data);
1153 	iwl_mvm_rx_check_trigger(mvm, pkt);
1154 
1155 	/*
1156 	 * Do the notification wait before RX handlers so
1157 	 * even if the RX handler consumes the RXB we have
1158 	 * access to it in the notification wait entry.
1159 	 */
1160 	iwl_notification_wait_notify(&mvm->notif_wait, pkt);
1161 
1162 	for (i = 0; i < ARRAY_SIZE(iwl_mvm_rx_handlers); i++) {
1163 		const struct iwl_rx_handlers *rx_h = &iwl_mvm_rx_handlers[i];
1164 		struct iwl_async_handler_entry *entry;
1165 
1166 		if (rx_h->cmd_id != WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd))
1167 			continue;
1168 
1169 		if (unlikely(pkt_len < rx_h->min_size))
1170 			return;
1171 
1172 		if (rx_h->context == RX_HANDLER_SYNC) {
1173 			rx_h->fn(mvm, rxb);
1174 			return;
1175 		}
1176 
1177 		entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
1178 		/* we can't do much... */
1179 		if (!entry)
1180 			return;
1181 
1182 		entry->rxb._page = rxb_steal_page(rxb);
1183 		entry->rxb._offset = rxb->_offset;
1184 		entry->rxb._rx_page_order = rxb->_rx_page_order;
1185 		entry->fn = rx_h->fn;
1186 		entry->context = rx_h->context;
1187 		spin_lock(&mvm->async_handlers_lock);
1188 		list_add_tail(&entry->list, &mvm->async_handlers_list);
1189 		spin_unlock(&mvm->async_handlers_lock);
1190 		schedule_work(&mvm->async_handlers_wk);
1191 		break;
1192 	}
1193 }
1194 
1195 static void iwl_mvm_rx(struct iwl_op_mode *op_mode,
1196 		       struct napi_struct *napi,
1197 		       struct iwl_rx_cmd_buffer *rxb)
1198 {
1199 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1200 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1201 	u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
1202 
1203 	if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
1204 		iwl_mvm_rx_rx_mpdu(mvm, napi, rxb);
1205 	else if (cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_PHY_CMD))
1206 		iwl_mvm_rx_rx_phy_cmd(mvm, rxb);
1207 	else
1208 		iwl_mvm_rx_common(mvm, rxb, pkt);
1209 }
1210 
1211 void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,
1212 		   struct napi_struct *napi,
1213 		   struct iwl_rx_cmd_buffer *rxb)
1214 {
1215 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1216 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1217 	u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
1218 
1219 	if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
1220 		iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, 0);
1221 	else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP,
1222 					 RX_QUEUES_NOTIFICATION)))
1223 		iwl_mvm_rx_queue_notif(mvm, napi, rxb, 0);
1224 	else if (cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE))
1225 		iwl_mvm_rx_frame_release(mvm, napi, rxb, 0);
1226 	else if (cmd == WIDE_ID(LEGACY_GROUP, BAR_FRAME_RELEASE))
1227 		iwl_mvm_rx_bar_frame_release(mvm, napi, rxb, 0);
1228 	else if (cmd == WIDE_ID(DATA_PATH_GROUP, RX_NO_DATA_NOTIF))
1229 		iwl_mvm_rx_monitor_no_data(mvm, napi, rxb, 0);
1230 	else
1231 		iwl_mvm_rx_common(mvm, rxb, pkt);
1232 }
1233 
1234 static void iwl_mvm_async_cb(struct iwl_op_mode *op_mode,
1235 			     const struct iwl_device_cmd *cmd)
1236 {
1237 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1238 
1239 	/*
1240 	 * For now, we only set the CMD_WANT_ASYNC_CALLBACK for ADD_STA
1241 	 * commands that need to block the Tx queues.
1242 	 */
1243 	iwl_trans_block_txq_ptrs(mvm->trans, false);
1244 }
1245 
1246 static int iwl_mvm_is_static_queue(struct iwl_mvm *mvm, int queue)
1247 {
1248 	return queue == mvm->aux_queue || queue == mvm->probe_queue ||
1249 		queue == mvm->p2p_dev_queue || queue == mvm->snif_queue;
1250 }
1251 
1252 static void iwl_mvm_queue_state_change(struct iwl_op_mode *op_mode,
1253 				       int hw_queue, bool start)
1254 {
1255 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1256 	struct ieee80211_sta *sta;
1257 	struct ieee80211_txq *txq;
1258 	struct iwl_mvm_txq *mvmtxq;
1259 	int i;
1260 	unsigned long tid_bitmap;
1261 	struct iwl_mvm_sta *mvmsta;
1262 	u8 sta_id;
1263 
1264 	sta_id = iwl_mvm_has_new_tx_api(mvm) ?
1265 		mvm->tvqm_info[hw_queue].sta_id :
1266 		mvm->queue_info[hw_queue].ra_sta_id;
1267 
1268 	if (WARN_ON_ONCE(sta_id >= mvm->fw->ucode_capa.num_stations))
1269 		return;
1270 
1271 	rcu_read_lock();
1272 
1273 	sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1274 	if (IS_ERR_OR_NULL(sta))
1275 		goto out;
1276 	mvmsta = iwl_mvm_sta_from_mac80211(sta);
1277 
1278 	if (iwl_mvm_is_static_queue(mvm, hw_queue)) {
1279 		if (!start)
1280 			ieee80211_stop_queues(mvm->hw);
1281 		else if (mvmsta->sta_state != IEEE80211_STA_NOTEXIST)
1282 			ieee80211_wake_queues(mvm->hw);
1283 
1284 		goto out;
1285 	}
1286 
1287 	if (iwl_mvm_has_new_tx_api(mvm)) {
1288 		int tid = mvm->tvqm_info[hw_queue].txq_tid;
1289 
1290 		tid_bitmap = BIT(tid);
1291 	} else {
1292 		tid_bitmap = mvm->queue_info[hw_queue].tid_bitmap;
1293 	}
1294 
1295 	for_each_set_bit(i, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
1296 		int tid = i;
1297 
1298 		if (tid == IWL_MAX_TID_COUNT)
1299 			tid = IEEE80211_NUM_TIDS;
1300 
1301 		txq = sta->txq[tid];
1302 		mvmtxq = iwl_mvm_txq_from_mac80211(txq);
1303 		mvmtxq->stopped = !start;
1304 
1305 		if (start && mvmsta->sta_state != IEEE80211_STA_NOTEXIST)
1306 			iwl_mvm_mac_itxq_xmit(mvm->hw, txq);
1307 	}
1308 
1309 out:
1310 	rcu_read_unlock();
1311 }
1312 
1313 static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)
1314 {
1315 	iwl_mvm_queue_state_change(op_mode, hw_queue, false);
1316 }
1317 
1318 static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)
1319 {
1320 	iwl_mvm_queue_state_change(op_mode, hw_queue, true);
1321 }
1322 
1323 static void iwl_mvm_set_rfkill_state(struct iwl_mvm *mvm)
1324 {
1325 	bool state = iwl_mvm_is_radio_killed(mvm);
1326 
1327 	if (state)
1328 		wake_up(&mvm->rx_sync_waitq);
1329 
1330 	wiphy_rfkill_set_hw_state(mvm->hw->wiphy, state);
1331 }
1332 
1333 void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state)
1334 {
1335 	if (state)
1336 		set_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1337 	else
1338 		clear_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1339 
1340 	iwl_mvm_set_rfkill_state(mvm);
1341 }
1342 
1343 static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
1344 {
1345 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1346 	bool rfkill_safe_init_done = READ_ONCE(mvm->rfkill_safe_init_done);
1347 	bool unified = iwl_mvm_has_unified_ucode(mvm);
1348 
1349 	if (state)
1350 		set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1351 	else
1352 		clear_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1353 
1354 	iwl_mvm_set_rfkill_state(mvm);
1355 
1356 	 /* iwl_run_init_mvm_ucode is waiting for results, abort it. */
1357 	if (rfkill_safe_init_done)
1358 		iwl_abort_notification_waits(&mvm->notif_wait);
1359 
1360 	/*
1361 	 * Don't ask the transport to stop the firmware. We'll do it
1362 	 * after cfg80211 takes us down.
1363 	 */
1364 	if (unified)
1365 		return false;
1366 
1367 	/*
1368 	 * Stop the device if we run OPERATIONAL firmware or if we are in the
1369 	 * middle of the calibrations.
1370 	 */
1371 	return state && rfkill_safe_init_done;
1372 }
1373 
1374 static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
1375 {
1376 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1377 	struct ieee80211_tx_info *info;
1378 
1379 	info = IEEE80211_SKB_CB(skb);
1380 	iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
1381 	ieee80211_free_txskb(mvm->hw, skb);
1382 }
1383 
1384 struct iwl_mvm_reprobe {
1385 	struct device *dev;
1386 	struct work_struct work;
1387 };
1388 
1389 static void iwl_mvm_reprobe_wk(struct work_struct *wk)
1390 {
1391 	struct iwl_mvm_reprobe *reprobe;
1392 
1393 	reprobe = container_of(wk, struct iwl_mvm_reprobe, work);
1394 	if (device_reprobe(reprobe->dev))
1395 		dev_err(reprobe->dev, "reprobe failed!\n");
1396 	put_device(reprobe->dev);
1397 	kfree(reprobe);
1398 	module_put(THIS_MODULE);
1399 }
1400 
1401 void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error)
1402 {
1403 	iwl_abort_notification_waits(&mvm->notif_wait);
1404 	iwl_dbg_tlv_del_timers(mvm->trans);
1405 
1406 	/*
1407 	 * This is a bit racy, but worst case we tell mac80211 about
1408 	 * a stopped/aborted scan when that was already done which
1409 	 * is not a problem. It is necessary to abort any os scan
1410 	 * here because mac80211 requires having the scan cleared
1411 	 * before restarting.
1412 	 * We'll reset the scan_status to NONE in restart cleanup in
1413 	 * the next start() call from mac80211. If restart isn't called
1414 	 * (no fw restart) scan status will stay busy.
1415 	 */
1416 	iwl_mvm_report_scan_aborted(mvm);
1417 
1418 	/*
1419 	 * If we're restarting already, don't cycle restarts.
1420 	 * If INIT fw asserted, it will likely fail again.
1421 	 * If WoWLAN fw asserted, don't restart either, mac80211
1422 	 * can't recover this since we're already half suspended.
1423 	 */
1424 	if (!mvm->fw_restart && fw_error) {
1425 		iwl_fw_error_collect(&mvm->fwrt, false);
1426 	} else if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1427 		struct iwl_mvm_reprobe *reprobe;
1428 
1429 		IWL_ERR(mvm,
1430 			"Firmware error during reconfiguration - reprobe!\n");
1431 
1432 		/*
1433 		 * get a module reference to avoid doing this while unloading
1434 		 * anyway and to avoid scheduling a work with code that's
1435 		 * being removed.
1436 		 */
1437 		if (!try_module_get(THIS_MODULE)) {
1438 			IWL_ERR(mvm, "Module is being unloaded - abort\n");
1439 			return;
1440 		}
1441 
1442 		reprobe = kzalloc(sizeof(*reprobe), GFP_ATOMIC);
1443 		if (!reprobe) {
1444 			module_put(THIS_MODULE);
1445 			return;
1446 		}
1447 		reprobe->dev = get_device(mvm->trans->dev);
1448 		INIT_WORK(&reprobe->work, iwl_mvm_reprobe_wk);
1449 		schedule_work(&reprobe->work);
1450 	} else if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1451 			    &mvm->status)) {
1452 		IWL_ERR(mvm, "HW restart already requested, but not started\n");
1453 	} else if (mvm->fwrt.cur_fw_img == IWL_UCODE_REGULAR &&
1454 		   mvm->hw_registered &&
1455 		   !test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) {
1456 		/* This should be first thing before trying to collect any
1457 		 * data to avoid endless loops if any HW error happens while
1458 		 * collecting debug data.
1459 		 */
1460 		set_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1461 
1462 		if (mvm->fw->ucode_capa.error_log_size) {
1463 			u32 src_size = mvm->fw->ucode_capa.error_log_size;
1464 			u32 src_addr = mvm->fw->ucode_capa.error_log_addr;
1465 			u8 *recover_buf = kzalloc(src_size, GFP_ATOMIC);
1466 
1467 			if (recover_buf) {
1468 				mvm->error_recovery_buf = recover_buf;
1469 				iwl_trans_read_mem_bytes(mvm->trans,
1470 							 src_addr,
1471 							 recover_buf,
1472 							 src_size);
1473 			}
1474 		}
1475 
1476 		iwl_fw_error_collect(&mvm->fwrt, false);
1477 
1478 		if (fw_error && mvm->fw_restart > 0)
1479 			mvm->fw_restart--;
1480 		ieee80211_restart_hw(mvm->hw);
1481 	}
1482 }
1483 
1484 static void iwl_mvm_nic_error(struct iwl_op_mode *op_mode, bool sync)
1485 {
1486 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1487 
1488 	if (!test_bit(STATUS_TRANS_DEAD, &mvm->trans->status))
1489 		iwl_mvm_dump_nic_error_log(mvm);
1490 
1491 	if (sync) {
1492 		iwl_fw_error_collect(&mvm->fwrt, true);
1493 		/*
1494 		 * Currently, the only case for sync=true is during
1495 		 * shutdown, so just stop in this case. If/when that
1496 		 * changes, we need to be a bit smarter here.
1497 		 */
1498 		return;
1499 	}
1500 
1501 	/*
1502 	 * If the firmware crashes while we're already considering it
1503 	 * to be dead then don't ask for a restart, that cannot do
1504 	 * anything useful anyway.
1505 	 */
1506 	if (!test_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status))
1507 		return;
1508 
1509 	iwl_mvm_nic_restart(mvm, true);
1510 }
1511 
1512 static void iwl_mvm_cmd_queue_full(struct iwl_op_mode *op_mode)
1513 {
1514 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1515 
1516 	WARN_ON(1);
1517 	iwl_mvm_nic_restart(mvm, true);
1518 }
1519 
1520 static void iwl_op_mode_mvm_time_point(struct iwl_op_mode *op_mode,
1521 				       enum iwl_fw_ini_time_point tp_id,
1522 				       union iwl_dbg_tlv_tp_data *tp_data)
1523 {
1524 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1525 
1526 	iwl_dbg_tlv_time_point(&mvm->fwrt, tp_id, tp_data);
1527 }
1528 
1529 #define IWL_MVM_COMMON_OPS					\
1530 	/* these could be differentiated */			\
1531 	.async_cb = iwl_mvm_async_cb,				\
1532 	.queue_full = iwl_mvm_stop_sw_queue,			\
1533 	.queue_not_full = iwl_mvm_wake_sw_queue,		\
1534 	.hw_rf_kill = iwl_mvm_set_hw_rfkill_state,		\
1535 	.free_skb = iwl_mvm_free_skb,				\
1536 	.nic_error = iwl_mvm_nic_error,				\
1537 	.cmd_queue_full = iwl_mvm_cmd_queue_full,		\
1538 	.nic_config = iwl_mvm_nic_config,			\
1539 	/* as we only register one, these MUST be common! */	\
1540 	.start = iwl_op_mode_mvm_start,				\
1541 	.stop = iwl_op_mode_mvm_stop,				\
1542 	.time_point = iwl_op_mode_mvm_time_point
1543 
1544 static const struct iwl_op_mode_ops iwl_mvm_ops = {
1545 	IWL_MVM_COMMON_OPS,
1546 	.rx = iwl_mvm_rx,
1547 };
1548 
1549 static void iwl_mvm_rx_mq_rss(struct iwl_op_mode *op_mode,
1550 			      struct napi_struct *napi,
1551 			      struct iwl_rx_cmd_buffer *rxb,
1552 			      unsigned int queue)
1553 {
1554 	struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1555 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1556 	u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
1557 
1558 	if (unlikely(cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE)))
1559 		iwl_mvm_rx_frame_release(mvm, napi, rxb, queue);
1560 	else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP,
1561 					 RX_QUEUES_NOTIFICATION)))
1562 		iwl_mvm_rx_queue_notif(mvm, napi, rxb, queue);
1563 	else if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
1564 		iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, queue);
1565 }
1566 
1567 static const struct iwl_op_mode_ops iwl_mvm_ops_mq = {
1568 	IWL_MVM_COMMON_OPS,
1569 	.rx = iwl_mvm_rx_mq,
1570 	.rx_rss = iwl_mvm_rx_mq_rss,
1571 };
1572