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