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