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