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