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 */
iwl_mvm_init(void)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
iwl_mvm_exit(void)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
iwl_mvm_nic_config(struct iwl_op_mode * op_mode)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
iwl_mvm_rx_monitor_notif(struct iwl_mvm * mvm,struct iwl_rx_cmd_buffer * rxb)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
iwl_mvm_apply_fw_smps_request(struct ieee80211_vif * vif)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
iwl_mvm_intf_dual_chain_req(void * data,u8 * mac,struct ieee80211_vif * vif)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
iwl_mvm_rx_thermal_dual_chain_req(struct iwl_mvm * mvm,struct iwl_rx_cmd_buffer * rxb)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
iwl_mvm_min_backoff(struct iwl_mvm * mvm)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
iwl_mvm_tx_unblock_dwork(struct work_struct * work)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
iwl_mvm_fwrt_dump_start(void * ctx)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
iwl_mvm_fwrt_dump_end(void * ctx)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
iwl_mvm_fwrt_fw_running(void * ctx)655 static bool iwl_mvm_fwrt_fw_running(void *ctx)
656 {
657 return iwl_mvm_firmware_running(ctx);
658 }
659
iwl_mvm_fwrt_send_hcmd(void * ctx,struct iwl_host_cmd * host_cmd)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
iwl_mvm_d3_debug_enable(void * ctx)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
iwl_mvm_start_get_nvm(struct iwl_mvm * mvm)685 static int iwl_mvm_start_get_nvm(struct iwl_mvm *mvm)
686 {
687 int ret;
688
689 rtnl_lock();
690 mutex_lock(&mvm->mutex);
691
692 ret = iwl_run_init_mvm_ucode(mvm);
693
694 if (ret && ret != -ERFKILL)
695 iwl_fw_dbg_error_collect(&mvm->fwrt, FW_DBG_TRIGGER_DRIVER);
696 if (!ret && iwl_mvm_is_lar_supported(mvm)) {
697 mvm->hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;
698 ret = iwl_mvm_init_mcc(mvm);
699 }
700
701 if (!iwlmvm_mod_params.init_dbg || !ret)
702 iwl_mvm_stop_device(mvm);
703
704 mutex_unlock(&mvm->mutex);
705 rtnl_unlock();
706
707 if (ret < 0)
708 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
709
710 return ret;
711 }
712
iwl_mvm_start_post_nvm(struct iwl_mvm * mvm)713 static int iwl_mvm_start_post_nvm(struct iwl_mvm *mvm)
714 {
715 int ret;
716
717 iwl_mvm_toggle_tx_ant(mvm, &mvm->mgmt_last_antenna_idx);
718
719 ret = iwl_mvm_mac_setup_register(mvm);
720 if (ret)
721 return ret;
722 mvm->hw_registered = true;
723
724 iwl_mvm_dbgfs_register(mvm);
725
726 return 0;
727 }
728
729 static struct iwl_op_mode *
iwl_op_mode_mvm_start(struct iwl_trans * trans,const struct iwl_cfg * cfg,const struct iwl_fw * fw,struct dentry * dbgfs_dir)730 iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_cfg *cfg,
731 const struct iwl_fw *fw, struct dentry *dbgfs_dir)
732 {
733 struct ieee80211_hw *hw;
734 struct iwl_op_mode *op_mode;
735 struct iwl_mvm *mvm;
736 struct iwl_trans_config trans_cfg = {};
737 static const u8 no_reclaim_cmds[] = {
738 TX_CMD,
739 };
740 int err, scan_size;
741 u32 min_backoff;
742 enum iwl_amsdu_size rb_size_default;
743
744 /*
745 * We use IWL_MVM_STATION_COUNT_MAX to check the validity of the station
746 * index all over the driver - check that its value corresponds to the
747 * array size.
748 */
749 BUILD_BUG_ON(ARRAY_SIZE(mvm->fw_id_to_mac_id) !=
750 IWL_MVM_STATION_COUNT_MAX);
751
752 /********************************
753 * 1. Allocating and configuring HW data
754 ********************************/
755 hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) +
756 sizeof(struct iwl_mvm),
757 &iwl_mvm_hw_ops);
758 if (!hw)
759 return NULL;
760
761 hw->max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
762
763 if (cfg->max_tx_agg_size)
764 hw->max_tx_aggregation_subframes = cfg->max_tx_agg_size;
765 else
766 hw->max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
767
768 op_mode = hw->priv;
769
770 mvm = IWL_OP_MODE_GET_MVM(op_mode);
771 mvm->dev = trans->dev;
772 mvm->trans = trans;
773 mvm->cfg = cfg;
774 mvm->fw = fw;
775 mvm->hw = hw;
776
777 iwl_fw_runtime_init(&mvm->fwrt, trans, fw, &iwl_mvm_fwrt_ops, mvm,
778 dbgfs_dir);
779
780 iwl_mvm_get_acpi_tables(mvm);
781
782 mvm->init_status = 0;
783
784 if (iwl_mvm_has_new_rx_api(mvm)) {
785 op_mode->ops = &iwl_mvm_ops_mq;
786 trans->rx_mpdu_cmd_hdr_size =
787 (trans->trans_cfg->device_family >=
788 IWL_DEVICE_FAMILY_AX210) ?
789 sizeof(struct iwl_rx_mpdu_desc) :
790 IWL_RX_DESC_SIZE_V1;
791 } else {
792 op_mode->ops = &iwl_mvm_ops;
793 trans->rx_mpdu_cmd_hdr_size =
794 sizeof(struct iwl_rx_mpdu_res_start);
795
796 if (WARN_ON(trans->num_rx_queues > 1))
797 goto out_free;
798 }
799
800 mvm->fw_restart = iwlwifi_mod_params.fw_restart ? -1 : 0;
801
802 if (iwl_mvm_has_new_tx_api(mvm)) {
803 /*
804 * If we have the new TX/queue allocation API initialize them
805 * all to invalid numbers. We'll rewrite the ones that we need
806 * later, but that doesn't happen for all of them all of the
807 * time (e.g. P2P Device is optional), and if a dynamic queue
808 * ends up getting number 2 (IWL_MVM_DQA_P2P_DEVICE_QUEUE) then
809 * iwl_mvm_is_static_queue() erroneously returns true, and we
810 * might have things getting stuck.
811 */
812 mvm->aux_queue = IWL_MVM_INVALID_QUEUE;
813 mvm->snif_queue = IWL_MVM_INVALID_QUEUE;
814 mvm->probe_queue = IWL_MVM_INVALID_QUEUE;
815 mvm->p2p_dev_queue = IWL_MVM_INVALID_QUEUE;
816 } else {
817 mvm->aux_queue = IWL_MVM_DQA_AUX_QUEUE;
818 mvm->snif_queue = IWL_MVM_DQA_INJECT_MONITOR_QUEUE;
819 mvm->probe_queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE;
820 mvm->p2p_dev_queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE;
821 }
822
823 mvm->sf_state = SF_UNINIT;
824 if (iwl_mvm_has_unified_ucode(mvm))
825 iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_REGULAR);
826 else
827 iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_INIT);
828 mvm->drop_bcn_ap_mode = true;
829
830 mutex_init(&mvm->mutex);
831 spin_lock_init(&mvm->async_handlers_lock);
832 INIT_LIST_HEAD(&mvm->time_event_list);
833 INIT_LIST_HEAD(&mvm->aux_roc_te_list);
834 INIT_LIST_HEAD(&mvm->async_handlers_list);
835 spin_lock_init(&mvm->time_event_lock);
836 INIT_LIST_HEAD(&mvm->ftm_initiator.loc_list);
837 INIT_LIST_HEAD(&mvm->ftm_initiator.pasn_list);
838 INIT_LIST_HEAD(&mvm->resp_pasn_list);
839
840 INIT_WORK(&mvm->async_handlers_wk, iwl_mvm_async_handlers_wk);
841 INIT_WORK(&mvm->roc_done_wk, iwl_mvm_roc_done_wk);
842 INIT_DELAYED_WORK(&mvm->tdls_cs.dwork, iwl_mvm_tdls_ch_switch_work);
843 INIT_DELAYED_WORK(&mvm->scan_timeout_dwork, iwl_mvm_scan_timeout_wk);
844 INIT_WORK(&mvm->add_stream_wk, iwl_mvm_add_new_dqa_stream_wk);
845 INIT_LIST_HEAD(&mvm->add_stream_txqs);
846
847 init_waitqueue_head(&mvm->rx_sync_waitq);
848
849 mvm->queue_sync_state = 0;
850
851 SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev);
852
853 spin_lock_init(&mvm->tcm.lock);
854 INIT_DELAYED_WORK(&mvm->tcm.work, iwl_mvm_tcm_work);
855 mvm->tcm.ts = jiffies;
856 mvm->tcm.ll_ts = jiffies;
857 mvm->tcm.uapsd_nonagg_ts = jiffies;
858
859 INIT_DELAYED_WORK(&mvm->cs_tx_unblock_dwork, iwl_mvm_tx_unblock_dwork);
860
861 mvm->cmd_ver.d0i3_resp =
862 iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP, D0I3_END_CMD,
863 0);
864 /* we only support version 1 */
865 if (WARN_ON_ONCE(mvm->cmd_ver.d0i3_resp > 1))
866 goto out_free;
867
868 mvm->cmd_ver.range_resp =
869 iwl_fw_lookup_notif_ver(mvm->fw, LOCATION_GROUP,
870 TOF_RANGE_RESPONSE_NOTIF, 5);
871 /* we only support up to version 8 */
872 if (WARN_ON_ONCE(mvm->cmd_ver.range_resp > 8))
873 goto out_free;
874
875 /*
876 * Populate the state variables that the transport layer needs
877 * to know about.
878 */
879 trans_cfg.op_mode = op_mode;
880 trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
881 trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
882
883 if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)
884 rb_size_default = IWL_AMSDU_2K;
885 else
886 rb_size_default = IWL_AMSDU_4K;
887
888 switch (iwlwifi_mod_params.amsdu_size) {
889 case IWL_AMSDU_DEF:
890 trans_cfg.rx_buf_size = rb_size_default;
891 break;
892 case IWL_AMSDU_4K:
893 trans_cfg.rx_buf_size = IWL_AMSDU_4K;
894 break;
895 case IWL_AMSDU_8K:
896 trans_cfg.rx_buf_size = IWL_AMSDU_8K;
897 break;
898 case IWL_AMSDU_12K:
899 trans_cfg.rx_buf_size = IWL_AMSDU_12K;
900 break;
901 default:
902 pr_err("%s: Unsupported amsdu_size: %d\n", KBUILD_MODNAME,
903 iwlwifi_mod_params.amsdu_size);
904 trans_cfg.rx_buf_size = rb_size_default;
905 }
906
907 trans->wide_cmd_header = true;
908 trans_cfg.bc_table_dword =
909 mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_AX210;
910
911 trans_cfg.command_groups = iwl_mvm_groups;
912 trans_cfg.command_groups_size = ARRAY_SIZE(iwl_mvm_groups);
913
914 trans_cfg.cmd_queue = IWL_MVM_DQA_CMD_QUEUE;
915 trans_cfg.cmd_fifo = IWL_MVM_TX_FIFO_CMD;
916 trans_cfg.scd_set_active = true;
917
918 trans_cfg.cb_data_offs = offsetof(struct ieee80211_tx_info,
919 driver_data[2]);
920
921 /* Set a short watchdog for the command queue */
922 trans_cfg.cmd_q_wdg_timeout =
923 iwl_mvm_get_wd_timeout(mvm, NULL, false, true);
924
925 snprintf(mvm->hw->wiphy->fw_version,
926 sizeof(mvm->hw->wiphy->fw_version),
927 "%s", fw->fw_version);
928
929 trans_cfg.fw_reset_handshake = fw_has_capa(&mvm->fw->ucode_capa,
930 IWL_UCODE_TLV_CAPA_FW_RESET_HANDSHAKE);
931
932 /* Configure transport layer */
933 iwl_trans_configure(mvm->trans, &trans_cfg);
934
935 trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
936 trans->dbg.dest_tlv = mvm->fw->dbg.dest_tlv;
937 trans->dbg.n_dest_reg = mvm->fw->dbg.n_dest_reg;
938 memcpy(trans->dbg.conf_tlv, mvm->fw->dbg.conf_tlv,
939 sizeof(trans->dbg.conf_tlv));
940 trans->dbg.trigger_tlv = mvm->fw->dbg.trigger_tlv;
941
942 trans->iml = mvm->fw->iml;
943 trans->iml_len = mvm->fw->iml_len;
944
945 /* set up notification wait support */
946 iwl_notification_wait_init(&mvm->notif_wait);
947
948 /* Init phy db */
949 mvm->phy_db = iwl_phy_db_init(trans);
950 if (!mvm->phy_db) {
951 IWL_ERR(mvm, "Cannot init phy_db\n");
952 goto out_free;
953 }
954
955 IWL_INFO(mvm, "Detected %s, REV=0x%X\n",
956 mvm->trans->name, mvm->trans->hw_rev);
957
958 if (iwlwifi_mod_params.nvm_file)
959 mvm->nvm_file_name = iwlwifi_mod_params.nvm_file;
960 else
961 IWL_DEBUG_EEPROM(mvm->trans->dev,
962 "working without external nvm file\n");
963
964 err = iwl_trans_start_hw(mvm->trans);
965 if (err)
966 goto out_free;
967
968 scan_size = iwl_mvm_scan_size(mvm);
969
970 mvm->scan_cmd = kmalloc(scan_size, GFP_KERNEL);
971 if (!mvm->scan_cmd)
972 goto out_free;
973
974 /* invalidate ids to prevent accidental removal of sta_id 0 */
975 mvm->aux_sta.sta_id = IWL_MVM_INVALID_STA;
976 mvm->snif_sta.sta_id = IWL_MVM_INVALID_STA;
977
978 /* Set EBS as successful as long as not stated otherwise by the FW. */
979 mvm->last_ebs_successful = true;
980
981 min_backoff = iwl_mvm_min_backoff(mvm);
982 iwl_mvm_thermal_initialize(mvm, min_backoff);
983
984 if (!iwl_mvm_has_new_rx_stats_api(mvm))
985 memset(&mvm->rx_stats_v3, 0,
986 sizeof(struct mvm_statistics_rx_v3));
987 else
988 memset(&mvm->rx_stats, 0, sizeof(struct mvm_statistics_rx));
989
990 mvm->debugfs_dir = dbgfs_dir;
991
992 if (iwl_mvm_start_get_nvm(mvm))
993 goto out_thermal_exit;
994
995 if (iwl_mvm_start_post_nvm(mvm))
996 goto out_thermal_exit;
997
998 return op_mode;
999
1000 out_thermal_exit:
1001 iwl_mvm_thermal_exit(mvm);
1002 out_free:
1003 iwl_fw_flush_dumps(&mvm->fwrt);
1004 iwl_fw_runtime_free(&mvm->fwrt);
1005
1006 if (iwlmvm_mod_params.init_dbg)
1007 return op_mode;
1008 iwl_phy_db_free(mvm->phy_db);
1009 kfree(mvm->scan_cmd);
1010 iwl_trans_op_mode_leave(trans);
1011
1012 ieee80211_free_hw(mvm->hw);
1013 return NULL;
1014 }
1015
iwl_mvm_stop_device(struct iwl_mvm * mvm)1016 void iwl_mvm_stop_device(struct iwl_mvm *mvm)
1017 {
1018 lockdep_assert_held(&mvm->mutex);
1019
1020 iwl_fw_cancel_timestamp(&mvm->fwrt);
1021
1022 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
1023
1024 iwl_fw_dbg_stop_sync(&mvm->fwrt);
1025 iwl_trans_stop_device(mvm->trans);
1026 iwl_free_fw_paging(&mvm->fwrt);
1027 iwl_fw_dump_conf_clear(&mvm->fwrt);
1028 }
1029
iwl_op_mode_mvm_stop(struct iwl_op_mode * op_mode)1030 static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)
1031 {
1032 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1033 int i;
1034
1035 iwl_mvm_leds_exit(mvm);
1036
1037 iwl_mvm_thermal_exit(mvm);
1038
1039 ieee80211_unregister_hw(mvm->hw);
1040
1041 kfree(mvm->scan_cmd);
1042 kfree(mvm->mcast_filter_cmd);
1043 mvm->mcast_filter_cmd = NULL;
1044
1045 kfree(mvm->error_recovery_buf);
1046 mvm->error_recovery_buf = NULL;
1047
1048 iwl_trans_op_mode_leave(mvm->trans);
1049
1050 iwl_phy_db_free(mvm->phy_db);
1051 mvm->phy_db = NULL;
1052
1053 kfree(mvm->nvm_data);
1054 for (i = 0; i < NVM_MAX_NUM_SECTIONS; i++)
1055 kfree(mvm->nvm_sections[i].data);
1056
1057 cancel_delayed_work_sync(&mvm->tcm.work);
1058
1059 iwl_fw_runtime_free(&mvm->fwrt);
1060 mutex_destroy(&mvm->mutex);
1061
1062 ieee80211_free_hw(mvm->hw);
1063 }
1064
1065 struct iwl_async_handler_entry {
1066 struct list_head list;
1067 struct iwl_rx_cmd_buffer rxb;
1068 enum iwl_rx_handler_context context;
1069 void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);
1070 };
1071
iwl_mvm_async_handlers_purge(struct iwl_mvm * mvm)1072 void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm)
1073 {
1074 struct iwl_async_handler_entry *entry, *tmp;
1075
1076 spin_lock_bh(&mvm->async_handlers_lock);
1077 list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {
1078 iwl_free_rxb(&entry->rxb);
1079 list_del(&entry->list);
1080 kfree(entry);
1081 }
1082 spin_unlock_bh(&mvm->async_handlers_lock);
1083 }
1084
iwl_mvm_async_handlers_wk(struct work_struct * wk)1085 static void iwl_mvm_async_handlers_wk(struct work_struct *wk)
1086 {
1087 struct iwl_mvm *mvm =
1088 container_of(wk, struct iwl_mvm, async_handlers_wk);
1089 struct iwl_async_handler_entry *entry, *tmp;
1090 LIST_HEAD(local_list);
1091
1092 /* Ensure that we are not in stop flow (check iwl_mvm_mac_stop) */
1093
1094 /*
1095 * Sync with Rx path with a lock. Remove all the entries from this list,
1096 * add them to a local one (lock free), and then handle them.
1097 */
1098 spin_lock_bh(&mvm->async_handlers_lock);
1099 list_splice_init(&mvm->async_handlers_list, &local_list);
1100 spin_unlock_bh(&mvm->async_handlers_lock);
1101
1102 list_for_each_entry_safe(entry, tmp, &local_list, list) {
1103 if (entry->context == RX_HANDLER_ASYNC_LOCKED)
1104 mutex_lock(&mvm->mutex);
1105 entry->fn(mvm, &entry->rxb);
1106 iwl_free_rxb(&entry->rxb);
1107 list_del(&entry->list);
1108 if (entry->context == RX_HANDLER_ASYNC_LOCKED)
1109 mutex_unlock(&mvm->mutex);
1110 kfree(entry);
1111 }
1112 }
1113
iwl_mvm_rx_check_trigger(struct iwl_mvm * mvm,struct iwl_rx_packet * pkt)1114 static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm,
1115 struct iwl_rx_packet *pkt)
1116 {
1117 struct iwl_fw_dbg_trigger_tlv *trig;
1118 struct iwl_fw_dbg_trigger_cmd *cmds_trig;
1119 int i;
1120
1121 trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, NULL,
1122 FW_DBG_TRIGGER_FW_NOTIF);
1123 if (!trig)
1124 return;
1125
1126 cmds_trig = (void *)trig->data;
1127
1128 for (i = 0; i < ARRAY_SIZE(cmds_trig->cmds); i++) {
1129 /* don't collect on CMD 0 */
1130 if (!cmds_trig->cmds[i].cmd_id)
1131 break;
1132
1133 if (cmds_trig->cmds[i].cmd_id != pkt->hdr.cmd ||
1134 cmds_trig->cmds[i].group_id != pkt->hdr.group_id)
1135 continue;
1136
1137 iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,
1138 "CMD 0x%02x.%02x received",
1139 pkt->hdr.group_id, pkt->hdr.cmd);
1140 break;
1141 }
1142 }
1143
iwl_mvm_rx_common(struct iwl_mvm * mvm,struct iwl_rx_cmd_buffer * rxb,struct iwl_rx_packet * pkt)1144 static void iwl_mvm_rx_common(struct iwl_mvm *mvm,
1145 struct iwl_rx_cmd_buffer *rxb,
1146 struct iwl_rx_packet *pkt)
1147 {
1148 unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
1149 int i;
1150 union iwl_dbg_tlv_tp_data tp_data = { .fw_pkt = pkt };
1151
1152 iwl_dbg_tlv_time_point(&mvm->fwrt,
1153 IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF, &tp_data);
1154 iwl_mvm_rx_check_trigger(mvm, pkt);
1155
1156 /*
1157 * Do the notification wait before RX handlers so
1158 * even if the RX handler consumes the RXB we have
1159 * access to it in the notification wait entry.
1160 */
1161 iwl_notification_wait_notify(&mvm->notif_wait, pkt);
1162
1163 for (i = 0; i < ARRAY_SIZE(iwl_mvm_rx_handlers); i++) {
1164 const struct iwl_rx_handlers *rx_h = &iwl_mvm_rx_handlers[i];
1165 struct iwl_async_handler_entry *entry;
1166
1167 if (rx_h->cmd_id != WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd))
1168 continue;
1169
1170 if (unlikely(pkt_len < rx_h->min_size))
1171 return;
1172
1173 if (rx_h->context == RX_HANDLER_SYNC) {
1174 rx_h->fn(mvm, rxb);
1175 return;
1176 }
1177
1178 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
1179 /* we can't do much... */
1180 if (!entry)
1181 return;
1182
1183 entry->rxb._page = rxb_steal_page(rxb);
1184 entry->rxb._offset = rxb->_offset;
1185 entry->rxb._rx_page_order = rxb->_rx_page_order;
1186 entry->fn = rx_h->fn;
1187 entry->context = rx_h->context;
1188 spin_lock(&mvm->async_handlers_lock);
1189 list_add_tail(&entry->list, &mvm->async_handlers_list);
1190 spin_unlock(&mvm->async_handlers_lock);
1191 schedule_work(&mvm->async_handlers_wk);
1192 break;
1193 }
1194 }
1195
iwl_mvm_rx(struct iwl_op_mode * op_mode,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb)1196 static void iwl_mvm_rx(struct iwl_op_mode *op_mode,
1197 struct napi_struct *napi,
1198 struct iwl_rx_cmd_buffer *rxb)
1199 {
1200 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1201 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1202 u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
1203
1204 if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
1205 iwl_mvm_rx_rx_mpdu(mvm, napi, rxb);
1206 else if (cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_PHY_CMD))
1207 iwl_mvm_rx_rx_phy_cmd(mvm, rxb);
1208 else
1209 iwl_mvm_rx_common(mvm, rxb, pkt);
1210 }
1211
iwl_mvm_rx_mq(struct iwl_op_mode * op_mode,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb)1212 void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,
1213 struct napi_struct *napi,
1214 struct iwl_rx_cmd_buffer *rxb)
1215 {
1216 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1217 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1218 u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
1219
1220 if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
1221 iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, 0);
1222 else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP,
1223 RX_QUEUES_NOTIFICATION)))
1224 iwl_mvm_rx_queue_notif(mvm, napi, rxb, 0);
1225 else if (cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE))
1226 iwl_mvm_rx_frame_release(mvm, napi, rxb, 0);
1227 else if (cmd == WIDE_ID(LEGACY_GROUP, BAR_FRAME_RELEASE))
1228 iwl_mvm_rx_bar_frame_release(mvm, napi, rxb, 0);
1229 else if (cmd == WIDE_ID(DATA_PATH_GROUP, RX_NO_DATA_NOTIF))
1230 iwl_mvm_rx_monitor_no_data(mvm, napi, rxb, 0);
1231 else
1232 iwl_mvm_rx_common(mvm, rxb, pkt);
1233 }
1234
iwl_mvm_async_cb(struct iwl_op_mode * op_mode,const struct iwl_device_cmd * cmd)1235 static void iwl_mvm_async_cb(struct iwl_op_mode *op_mode,
1236 const struct iwl_device_cmd *cmd)
1237 {
1238 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1239
1240 /*
1241 * For now, we only set the CMD_WANT_ASYNC_CALLBACK for ADD_STA
1242 * commands that need to block the Tx queues.
1243 */
1244 iwl_trans_block_txq_ptrs(mvm->trans, false);
1245 }
1246
iwl_mvm_is_static_queue(struct iwl_mvm * mvm,int queue)1247 static int iwl_mvm_is_static_queue(struct iwl_mvm *mvm, int queue)
1248 {
1249 return queue == mvm->aux_queue || queue == mvm->probe_queue ||
1250 queue == mvm->p2p_dev_queue || queue == mvm->snif_queue;
1251 }
1252
iwl_mvm_queue_state_change(struct iwl_op_mode * op_mode,int hw_queue,bool start)1253 static void iwl_mvm_queue_state_change(struct iwl_op_mode *op_mode,
1254 int hw_queue, bool start)
1255 {
1256 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1257 struct ieee80211_sta *sta;
1258 struct ieee80211_txq *txq;
1259 struct iwl_mvm_txq *mvmtxq;
1260 int i;
1261 unsigned long tid_bitmap;
1262 struct iwl_mvm_sta *mvmsta;
1263 u8 sta_id;
1264
1265 sta_id = iwl_mvm_has_new_tx_api(mvm) ?
1266 mvm->tvqm_info[hw_queue].sta_id :
1267 mvm->queue_info[hw_queue].ra_sta_id;
1268
1269 if (WARN_ON_ONCE(sta_id >= mvm->fw->ucode_capa.num_stations))
1270 return;
1271
1272 rcu_read_lock();
1273
1274 sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);
1275 if (IS_ERR_OR_NULL(sta))
1276 goto out;
1277 mvmsta = iwl_mvm_sta_from_mac80211(sta);
1278
1279 if (iwl_mvm_is_static_queue(mvm, hw_queue)) {
1280 if (!start)
1281 ieee80211_stop_queues(mvm->hw);
1282 else if (mvmsta->sta_state != IEEE80211_STA_NOTEXIST)
1283 ieee80211_wake_queues(mvm->hw);
1284
1285 goto out;
1286 }
1287
1288 if (iwl_mvm_has_new_tx_api(mvm)) {
1289 int tid = mvm->tvqm_info[hw_queue].txq_tid;
1290
1291 tid_bitmap = BIT(tid);
1292 } else {
1293 tid_bitmap = mvm->queue_info[hw_queue].tid_bitmap;
1294 }
1295
1296 for_each_set_bit(i, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {
1297 int tid = i;
1298
1299 if (tid == IWL_MAX_TID_COUNT)
1300 tid = IEEE80211_NUM_TIDS;
1301
1302 txq = sta->txq[tid];
1303 mvmtxq = iwl_mvm_txq_from_mac80211(txq);
1304 mvmtxq->stopped = !start;
1305
1306 if (start && mvmsta->sta_state != IEEE80211_STA_NOTEXIST)
1307 iwl_mvm_mac_itxq_xmit(mvm->hw, txq);
1308 }
1309
1310 out:
1311 rcu_read_unlock();
1312 }
1313
iwl_mvm_stop_sw_queue(struct iwl_op_mode * op_mode,int hw_queue)1314 static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)
1315 {
1316 iwl_mvm_queue_state_change(op_mode, hw_queue, false);
1317 }
1318
iwl_mvm_wake_sw_queue(struct iwl_op_mode * op_mode,int hw_queue)1319 static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)
1320 {
1321 iwl_mvm_queue_state_change(op_mode, hw_queue, true);
1322 }
1323
iwl_mvm_set_rfkill_state(struct iwl_mvm * mvm)1324 static void iwl_mvm_set_rfkill_state(struct iwl_mvm *mvm)
1325 {
1326 bool state = iwl_mvm_is_radio_killed(mvm);
1327
1328 if (state)
1329 wake_up(&mvm->rx_sync_waitq);
1330
1331 wiphy_rfkill_set_hw_state(mvm->hw->wiphy, state);
1332 }
1333
iwl_mvm_set_hw_ctkill_state(struct iwl_mvm * mvm,bool state)1334 void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state)
1335 {
1336 if (state)
1337 set_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1338 else
1339 clear_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);
1340
1341 iwl_mvm_set_rfkill_state(mvm);
1342 }
1343
iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode * op_mode,bool state)1344 static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
1345 {
1346 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1347 bool rfkill_safe_init_done = READ_ONCE(mvm->rfkill_safe_init_done);
1348 bool unified = iwl_mvm_has_unified_ucode(mvm);
1349
1350 if (state)
1351 set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1352 else
1353 clear_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);
1354
1355 iwl_mvm_set_rfkill_state(mvm);
1356
1357 /* iwl_run_init_mvm_ucode is waiting for results, abort it. */
1358 if (rfkill_safe_init_done)
1359 iwl_abort_notification_waits(&mvm->notif_wait);
1360
1361 /*
1362 * Don't ask the transport to stop the firmware. We'll do it
1363 * after cfg80211 takes us down.
1364 */
1365 if (unified)
1366 return false;
1367
1368 /*
1369 * Stop the device if we run OPERATIONAL firmware or if we are in the
1370 * middle of the calibrations.
1371 */
1372 return state && rfkill_safe_init_done;
1373 }
1374
iwl_mvm_free_skb(struct iwl_op_mode * op_mode,struct sk_buff * skb)1375 static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
1376 {
1377 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1378 struct ieee80211_tx_info *info;
1379
1380 info = IEEE80211_SKB_CB(skb);
1381 iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);
1382 ieee80211_free_txskb(mvm->hw, skb);
1383 }
1384
1385 struct iwl_mvm_reprobe {
1386 struct device *dev;
1387 struct work_struct work;
1388 };
1389
iwl_mvm_reprobe_wk(struct work_struct * wk)1390 static void iwl_mvm_reprobe_wk(struct work_struct *wk)
1391 {
1392 struct iwl_mvm_reprobe *reprobe;
1393
1394 reprobe = container_of(wk, struct iwl_mvm_reprobe, work);
1395 if (device_reprobe(reprobe->dev))
1396 dev_err(reprobe->dev, "reprobe failed!\n");
1397 put_device(reprobe->dev);
1398 kfree(reprobe);
1399 module_put(THIS_MODULE);
1400 }
1401
iwl_mvm_nic_restart(struct iwl_mvm * mvm,bool fw_error)1402 void iwl_mvm_nic_restart(struct iwl_mvm *mvm, bool fw_error)
1403 {
1404 iwl_abort_notification_waits(&mvm->notif_wait);
1405 iwl_dbg_tlv_del_timers(mvm->trans);
1406
1407 /*
1408 * This is a bit racy, but worst case we tell mac80211 about
1409 * a stopped/aborted scan when that was already done which
1410 * is not a problem. It is necessary to abort any os scan
1411 * here because mac80211 requires having the scan cleared
1412 * before restarting.
1413 * We'll reset the scan_status to NONE in restart cleanup in
1414 * the next start() call from mac80211. If restart isn't called
1415 * (no fw restart) scan status will stay busy.
1416 */
1417 iwl_mvm_report_scan_aborted(mvm);
1418
1419 /*
1420 * If we're restarting already, don't cycle restarts.
1421 * If INIT fw asserted, it will likely fail again.
1422 * If WoWLAN fw asserted, don't restart either, mac80211
1423 * can't recover this since we're already half suspended.
1424 */
1425 if (!mvm->fw_restart && fw_error) {
1426 iwl_fw_error_collect(&mvm->fwrt, false);
1427 } else if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) {
1428 struct iwl_mvm_reprobe *reprobe;
1429
1430 IWL_ERR(mvm,
1431 "Firmware error during reconfiguration - reprobe!\n");
1432
1433 /*
1434 * get a module reference to avoid doing this while unloading
1435 * anyway and to avoid scheduling a work with code that's
1436 * being removed.
1437 */
1438 if (!try_module_get(THIS_MODULE)) {
1439 IWL_ERR(mvm, "Module is being unloaded - abort\n");
1440 return;
1441 }
1442
1443 reprobe = kzalloc(sizeof(*reprobe), GFP_ATOMIC);
1444 if (!reprobe) {
1445 module_put(THIS_MODULE);
1446 return;
1447 }
1448 reprobe->dev = get_device(mvm->trans->dev);
1449 INIT_WORK(&reprobe->work, iwl_mvm_reprobe_wk);
1450 schedule_work(&reprobe->work);
1451 } else if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
1452 &mvm->status)) {
1453 IWL_ERR(mvm, "HW restart already requested, but not started\n");
1454 } else if (mvm->fwrt.cur_fw_img == IWL_UCODE_REGULAR &&
1455 mvm->hw_registered &&
1456 !test_bit(STATUS_TRANS_DEAD, &mvm->trans->status)) {
1457 /* This should be first thing before trying to collect any
1458 * data to avoid endless loops if any HW error happens while
1459 * collecting debug data.
1460 */
1461 set_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);
1462
1463 if (mvm->fw->ucode_capa.error_log_size) {
1464 u32 src_size = mvm->fw->ucode_capa.error_log_size;
1465 u32 src_addr = mvm->fw->ucode_capa.error_log_addr;
1466 u8 *recover_buf = kzalloc(src_size, GFP_ATOMIC);
1467
1468 if (recover_buf) {
1469 mvm->error_recovery_buf = recover_buf;
1470 iwl_trans_read_mem_bytes(mvm->trans,
1471 src_addr,
1472 recover_buf,
1473 src_size);
1474 }
1475 }
1476
1477 iwl_fw_error_collect(&mvm->fwrt, false);
1478
1479 if (fw_error && mvm->fw_restart > 0)
1480 mvm->fw_restart--;
1481 ieee80211_restart_hw(mvm->hw);
1482 }
1483 }
1484
iwl_mvm_nic_error(struct iwl_op_mode * op_mode,bool sync)1485 static void iwl_mvm_nic_error(struct iwl_op_mode *op_mode, bool sync)
1486 {
1487 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1488
1489 if (!test_bit(STATUS_TRANS_DEAD, &mvm->trans->status))
1490 iwl_mvm_dump_nic_error_log(mvm);
1491
1492 if (sync) {
1493 iwl_fw_error_collect(&mvm->fwrt, true);
1494 /*
1495 * Currently, the only case for sync=true is during
1496 * shutdown, so just stop in this case. If/when that
1497 * changes, we need to be a bit smarter here.
1498 */
1499 return;
1500 }
1501
1502 /*
1503 * If the firmware crashes while we're already considering it
1504 * to be dead then don't ask for a restart, that cannot do
1505 * anything useful anyway.
1506 */
1507 if (!test_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status))
1508 return;
1509
1510 iwl_mvm_nic_restart(mvm, true);
1511 }
1512
iwl_mvm_cmd_queue_full(struct iwl_op_mode * op_mode)1513 static void iwl_mvm_cmd_queue_full(struct iwl_op_mode *op_mode)
1514 {
1515 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1516
1517 WARN_ON(1);
1518 iwl_mvm_nic_restart(mvm, true);
1519 }
1520
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)1521 static void iwl_op_mode_mvm_time_point(struct iwl_op_mode *op_mode,
1522 enum iwl_fw_ini_time_point tp_id,
1523 union iwl_dbg_tlv_tp_data *tp_data)
1524 {
1525 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1526
1527 iwl_dbg_tlv_time_point(&mvm->fwrt, tp_id, tp_data);
1528 }
1529
1530 #define IWL_MVM_COMMON_OPS \
1531 /* these could be differentiated */ \
1532 .async_cb = iwl_mvm_async_cb, \
1533 .queue_full = iwl_mvm_stop_sw_queue, \
1534 .queue_not_full = iwl_mvm_wake_sw_queue, \
1535 .hw_rf_kill = iwl_mvm_set_hw_rfkill_state, \
1536 .free_skb = iwl_mvm_free_skb, \
1537 .nic_error = iwl_mvm_nic_error, \
1538 .cmd_queue_full = iwl_mvm_cmd_queue_full, \
1539 .nic_config = iwl_mvm_nic_config, \
1540 /* as we only register one, these MUST be common! */ \
1541 .start = iwl_op_mode_mvm_start, \
1542 .stop = iwl_op_mode_mvm_stop, \
1543 .time_point = iwl_op_mode_mvm_time_point
1544
1545 static const struct iwl_op_mode_ops iwl_mvm_ops = {
1546 IWL_MVM_COMMON_OPS,
1547 .rx = iwl_mvm_rx,
1548 };
1549
iwl_mvm_rx_mq_rss(struct iwl_op_mode * op_mode,struct napi_struct * napi,struct iwl_rx_cmd_buffer * rxb,unsigned int queue)1550 static void iwl_mvm_rx_mq_rss(struct iwl_op_mode *op_mode,
1551 struct napi_struct *napi,
1552 struct iwl_rx_cmd_buffer *rxb,
1553 unsigned int queue)
1554 {
1555 struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);
1556 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1557 u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);
1558
1559 if (unlikely(cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE)))
1560 iwl_mvm_rx_frame_release(mvm, napi, rxb, queue);
1561 else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP,
1562 RX_QUEUES_NOTIFICATION)))
1563 iwl_mvm_rx_queue_notif(mvm, napi, rxb, queue);
1564 else if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))
1565 iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, queue);
1566 }
1567
1568 static const struct iwl_op_mode_ops iwl_mvm_ops_mq = {
1569 IWL_MVM_COMMON_OPS,
1570 .rx = iwl_mvm_rx_mq,
1571 .rx_rss = iwl_mvm_rx_mq_rss,
1572 };
1573