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