Path: blob/main/sys/contrib/dev/iwlwifi/mvm/ops.c
105932 views
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause1/*2* Copyright (C) 2012-2014, 2018-2025 Intel Corporation3* Copyright (C) 2013-2015 Intel Mobile Communications GmbH4* Copyright (C) 2016-2017 Intel Deutschland GmbH5*/6#if defined(__FreeBSD__)7#define LINUXKPI_PARAM_PREFIX iwlwifi_mvm_8#endif9#include <linux/module.h>10#include <linux/rtnetlink.h>11#include <linux/vmalloc.h>12#include <net/mac80211.h>1314#include "fw/notif-wait.h"15#include "iwl-trans.h"16#include "iwl-op-mode.h"17#include "fw/img.h"18#include "iwl-debug.h"19#include "iwl-drv.h"20#include "iwl-modparams.h"21#include "mvm.h"22#include "iwl-phy-db.h"23#include "iwl-nvm-utils.h"24#include "iwl-csr.h"25#include "iwl-io.h"26#include "iwl-prph.h"27#include "rs.h"28#include "fw/api/scan.h"29#include "fw/api/rfi.h"30#include "time-event.h"31#include "fw-api.h"32#include "fw/acpi.h"33#include "fw/uefi.h"34#include "time-sync.h"3536#if defined(__linux__)37#define DRV_DESCRIPTION "The new Intel(R) wireless AGN driver for Linux"38MODULE_DESCRIPTION(DRV_DESCRIPTION);39MODULE_LICENSE("GPL");40#elif defined(__FreeBSD__)41#define DRV_DESCRIPTION "The new Intel(R) wireless AGN/AC/AX based driver for FreeBSD"42MODULE_DESCRIPTION(DRV_DESCRIPTION);43MODULE_LICENSE("BSD");44#endif45MODULE_IMPORT_NS("IWLWIFI");4647static const struct iwl_op_mode_ops iwl_mvm_ops;48static const struct iwl_op_mode_ops iwl_mvm_ops_mq;4950struct iwl_mvm_mod_params iwlmvm_mod_params = {51#if defined(__linux__)52.power_scheme = IWL_POWER_SCHEME_BPS,53#elif defined(__FreeBSD__)54.power_scheme = IWL_POWER_SCHEME_CAM, /* disable default PS */55#endif56};5758module_param_named(power_scheme, iwlmvm_mod_params.power_scheme, int, 0444);59MODULE_PARM_DESC(power_scheme,60"power management scheme: 1-active, 2-balanced, 3-low power, default: 2");6162/*63* module init and exit functions64*/65static int __init iwl_mvm_init(void)66{67int ret;6869ret = iwl_mvm_rate_control_register();70if (ret) {71pr_err("Unable to register rate control algorithm: %d\n", ret);72return ret;73}7475ret = iwl_opmode_register("iwlmvm", &iwl_mvm_ops);76if (ret) {77pr_err("Unable to register MVM op_mode: %d\n", ret);78iwl_mvm_rate_control_unregister();79}8081return ret;82}83#if defined(__linux__)84module_init(iwl_mvm_init);85#elif defined(__FreeBSD__)86module_init_order(iwl_mvm_init, SI_ORDER_SECOND);87#endif8889static void __exit iwl_mvm_exit(void)90{91iwl_opmode_deregister("iwlmvm");92iwl_mvm_rate_control_unregister();93}94module_exit(iwl_mvm_exit);9596static void iwl_mvm_nic_config(struct iwl_op_mode *op_mode)97{98struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);99u8 radio_cfg_type, radio_cfg_step, radio_cfg_dash;100u32 reg_val;101u32 phy_config = iwl_mvm_get_phy_config(mvm);102103radio_cfg_type = (phy_config & FW_PHY_CFG_RADIO_TYPE) >>104FW_PHY_CFG_RADIO_TYPE_POS;105radio_cfg_step = (phy_config & FW_PHY_CFG_RADIO_STEP) >>106FW_PHY_CFG_RADIO_STEP_POS;107radio_cfg_dash = (phy_config & FW_PHY_CFG_RADIO_DASH) >>108FW_PHY_CFG_RADIO_DASH_POS;109110IWL_DEBUG_INFO(mvm, "Radio type=0x%x-0x%x-0x%x\n", radio_cfg_type,111radio_cfg_step, radio_cfg_dash);112113if (mvm->trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_AX210)114return;115116/* SKU control */117reg_val = CSR_HW_REV_STEP_DASH(mvm->trans->info.hw_rev);118119/* radio configuration */120reg_val |= radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE;121reg_val |= radio_cfg_step << CSR_HW_IF_CONFIG_REG_POS_PHY_STEP;122reg_val |= radio_cfg_dash << CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;123124WARN_ON((radio_cfg_type << CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE) &125~CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE);126127/*128* TODO: Bits 7-8 of CSR in 8000 HW family and higher set the ADC129* sampling, and shouldn't be set to any non-zero value.130* The same is supposed to be true of the other HW, but unsetting131* them (such as the 7260) causes automatic tests to fail on seemingly132* unrelated errors. Need to further investigate this, but for now133* we'll separate cases.134*/135if (mvm->trans->mac_cfg->device_family < IWL_DEVICE_FAMILY_8000)136reg_val |= CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI;137138if (iwl_fw_dbg_is_d3_debug_enabled(&mvm->fwrt))139reg_val |= CSR_HW_IF_CONFIG_REG_D3_DEBUG;140141iwl_trans_set_bits_mask(mvm->trans, CSR_HW_IF_CONFIG_REG,142CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP_DASH |143CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |144CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |145CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH |146CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |147CSR_HW_IF_CONFIG_REG_BIT_MAC_SI |148CSR_HW_IF_CONFIG_REG_D3_DEBUG,149reg_val);150151/*152* W/A : NIC is stuck in a reset state after Early PCIe power off153* (PCIe power is lost before PERST# is asserted), causing ME FW154* to lose ownership and not being able to obtain it back.155*/156if (!mvm->trans->mac_cfg->base->apmg_not_supported)157iwl_set_bits_mask_prph(mvm->trans, APMG_PS_CTRL_REG,158APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,159~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);160}161162static void iwl_mvm_rx_esr_mode_notif(struct iwl_mvm *mvm,163struct iwl_rx_cmd_buffer *rxb)164{165struct iwl_rx_packet *pkt = rxb_addr(rxb);166struct iwl_esr_mode_notif *notif = (void *)pkt->data;167struct ieee80211_vif *vif = iwl_mvm_get_bss_vif(mvm);168169/* FW recommendations is only for entering EMLSR */170if (IS_ERR_OR_NULL(vif) || iwl_mvm_vif_from_mac80211(vif)->esr_active)171return;172173if (le32_to_cpu(notif->action) == ESR_RECOMMEND_ENTER)174iwl_mvm_unblock_esr(mvm, vif, IWL_MVM_ESR_BLOCKED_FW);175else176iwl_mvm_block_esr(mvm, vif, IWL_MVM_ESR_BLOCKED_FW,177iwl_mvm_get_primary_link(vif));178}179180static void iwl_mvm_rx_monitor_notif(struct iwl_mvm *mvm,181struct iwl_rx_cmd_buffer *rxb)182{183struct iwl_rx_packet *pkt = rxb_addr(rxb);184struct iwl_datapath_monitor_notif *notif = (void *)pkt->data;185struct ieee80211_supported_band *sband;186const struct ieee80211_sta_he_cap *he_cap;187struct ieee80211_vif *vif;188189if (notif->type != cpu_to_le32(IWL_DP_MON_NOTIF_TYPE_EXT_CCA))190return;191192/* FIXME: should fetch the link and not the vif */193vif = iwl_mvm_get_vif_by_macid(mvm, notif->link_id);194if (!vif || vif->type != NL80211_IFTYPE_STATION)195return;196197if (!vif->bss_conf.chanreq.oper.chan ||198vif->bss_conf.chanreq.oper.chan->band != NL80211_BAND_2GHZ ||199vif->bss_conf.chanreq.oper.width < NL80211_CHAN_WIDTH_40)200return;201202if (!vif->cfg.assoc)203return;204205/* this shouldn't happen *again*, ignore it */206if (mvm->cca_40mhz_workaround)207return;208209/*210* We'll decrement this on disconnect - so set to 2 since we'll211* still have to disconnect from the current AP first.212*/213mvm->cca_40mhz_workaround = 2;214215/*216* This capability manipulation isn't really ideal, but it's the217* easiest choice - otherwise we'd have to do some major changes218* in mac80211 to support this, which isn't worth it. This does219* mean that userspace may have outdated information, but that's220* actually not an issue at all.221*/222sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];223224WARN_ON(!sband->ht_cap.ht_supported);225WARN_ON(!(sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40));226sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;227228he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif);229230if (he_cap) {231/* we know that ours is writable */232struct ieee80211_sta_he_cap *he = (void *)(uintptr_t)he_cap;233234WARN_ON(!he->has_he);235WARN_ON(!(he->he_cap_elem.phy_cap_info[0] &236IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G));237he->he_cap_elem.phy_cap_info[0] &=238~IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;239}240241ieee80211_disconnect(vif, true);242}243244void iwl_mvm_update_link_smps(struct ieee80211_vif *vif,245struct ieee80211_bss_conf *link_conf)246{247struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);248struct iwl_mvm *mvm = mvmvif->mvm;249enum ieee80211_smps_mode mode = IEEE80211_SMPS_AUTOMATIC;250251if (!link_conf)252return;253254if (mvm->fw_static_smps_request &&255link_conf->chanreq.oper.width == NL80211_CHAN_WIDTH_160 &&256link_conf->he_support)257mode = IEEE80211_SMPS_STATIC;258259iwl_mvm_update_smps(mvm, vif, IWL_MVM_SMPS_REQ_FW, mode,260link_conf->link_id);261}262263static void iwl_mvm_intf_dual_chain_req(void *data, u8 *mac,264struct ieee80211_vif *vif)265{266struct ieee80211_bss_conf *link_conf;267unsigned int link_id;268269rcu_read_lock();270271for_each_vif_active_link(vif, link_conf, link_id)272iwl_mvm_update_link_smps(vif, link_conf);273274rcu_read_unlock();275}276277static void iwl_mvm_rx_thermal_dual_chain_req(struct iwl_mvm *mvm,278struct iwl_rx_cmd_buffer *rxb)279{280struct iwl_rx_packet *pkt = rxb_addr(rxb);281struct iwl_thermal_dual_chain_request *req = (void *)pkt->data;282283/* firmware is expected to handle that in RLC offload mode */284if (IWL_FW_CHECK(mvm, iwl_mvm_has_rlc_offload(mvm),285"Got THERMAL_DUAL_CHAIN_REQUEST (0x%x) in RLC offload mode\n",286req->event))287return;288289/*290* We could pass it to the iterator data, but also need to remember291* it for new interfaces that are added while in this state.292*/293mvm->fw_static_smps_request =294req->event == cpu_to_le32(THERMAL_DUAL_CHAIN_REQ_DISABLE);295ieee80211_iterate_interfaces(mvm->hw,296IEEE80211_IFACE_SKIP_SDATA_NOT_IN_DRIVER,297iwl_mvm_intf_dual_chain_req, NULL);298}299300/**301* enum iwl_rx_handler_context: context for Rx handler302* @RX_HANDLER_SYNC : this means that it will be called in the Rx path303* which can't acquire mvm->mutex.304* @RX_HANDLER_ASYNC_LOCKED : If the handler needs to hold mvm->mutex305* (and only in this case!), it should be set as ASYNC. In that case,306* it will be called from a worker with mvm->mutex held.307* @RX_HANDLER_ASYNC_UNLOCKED : in case the handler needs to lock the308* mutex itself, it will be called from a worker without mvm->mutex held.309* @RX_HANDLER_ASYNC_LOCKED_WIPHY: If the handler needs to hold the wiphy lock310* and mvm->mutex. Will be handled with the wiphy_work queue infra311* instead of regular work queue.312*/313enum iwl_rx_handler_context {314RX_HANDLER_SYNC,315RX_HANDLER_ASYNC_LOCKED,316RX_HANDLER_ASYNC_UNLOCKED,317RX_HANDLER_ASYNC_LOCKED_WIPHY,318};319320/**321* struct iwl_rx_handlers: handler for FW notification322* @cmd_id: command id323* @min_size: minimum size to expect for the notification324* @context: see &iwl_rx_handler_context325* @fn: the function is called when notification is received326*/327struct iwl_rx_handlers {328u16 cmd_id, min_size;329enum iwl_rx_handler_context context;330void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);331};332333#define RX_HANDLER_NO_SIZE(_cmd_id, _fn, _context) \334{ .cmd_id = _cmd_id, .fn = _fn, .context = _context, }335#define RX_HANDLER_GRP_NO_SIZE(_grp, _cmd, _fn, _context) \336{ .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn, .context = _context, }337#define RX_HANDLER(_cmd_id, _fn, _context, _struct) \338{ .cmd_id = _cmd_id, .fn = _fn, \339.context = _context, .min_size = sizeof(_struct), }340#define RX_HANDLER_GRP(_grp, _cmd, _fn, _context, _struct) \341{ .cmd_id = WIDE_ID(_grp, _cmd), .fn = _fn, \342.context = _context, .min_size = sizeof(_struct), }343344/*345* Handlers for fw notifications346* Convention: RX_HANDLER(CMD_NAME, iwl_mvm_rx_CMD_NAME347* This list should be in order of frequency for performance purposes.348*349* The handler can be one from three contexts, see &iwl_rx_handler_context350*/351static const struct iwl_rx_handlers iwl_mvm_rx_handlers[] = {352RX_HANDLER(TX_CMD, iwl_mvm_rx_tx_cmd, RX_HANDLER_SYNC,353struct iwl_tx_resp),354RX_HANDLER(BA_NOTIF, iwl_mvm_rx_ba_notif, RX_HANDLER_SYNC,355struct iwl_mvm_ba_notif),356357RX_HANDLER_GRP(DATA_PATH_GROUP, TLC_MNG_UPDATE_NOTIF,358iwl_mvm_tlc_update_notif, RX_HANDLER_SYNC,359struct iwl_tlc_update_notif),360361RX_HANDLER(BT_PROFILE_NOTIFICATION, iwl_mvm_rx_bt_coex_old_notif,362RX_HANDLER_ASYNC_LOCKED_WIPHY,363struct iwl_bt_coex_prof_old_notif),364RX_HANDLER_GRP(BT_COEX_GROUP, PROFILE_NOTIF, iwl_mvm_rx_bt_coex_notif,365RX_HANDLER_ASYNC_LOCKED_WIPHY,366struct iwl_bt_coex_profile_notif),367RX_HANDLER_NO_SIZE(BEACON_NOTIFICATION, iwl_mvm_rx_beacon_notif,368RX_HANDLER_ASYNC_LOCKED),369RX_HANDLER_NO_SIZE(STATISTICS_NOTIFICATION, iwl_mvm_rx_statistics,370RX_HANDLER_ASYNC_LOCKED),371372RX_HANDLER_GRP(STATISTICS_GROUP, STATISTICS_OPER_NOTIF,373iwl_mvm_handle_rx_system_oper_stats,374RX_HANDLER_ASYNC_LOCKED_WIPHY,375struct iwl_system_statistics_notif_oper),376RX_HANDLER_GRP(STATISTICS_GROUP, STATISTICS_OPER_PART1_NOTIF,377iwl_mvm_handle_rx_system_oper_part1_stats,378RX_HANDLER_ASYNC_LOCKED,379struct iwl_system_statistics_part1_notif_oper),380RX_HANDLER_GRP(SYSTEM_GROUP, SYSTEM_STATISTICS_END_NOTIF,381iwl_mvm_handle_rx_system_end_stats_notif,382RX_HANDLER_ASYNC_LOCKED,383struct iwl_system_statistics_end_notif),384385RX_HANDLER(BA_WINDOW_STATUS_NOTIFICATION_ID,386iwl_mvm_window_status_notif, RX_HANDLER_SYNC,387struct iwl_ba_window_status_notif),388389RX_HANDLER(TIME_EVENT_NOTIFICATION, iwl_mvm_rx_time_event_notif,390RX_HANDLER_SYNC, struct iwl_time_event_notif),391RX_HANDLER_GRP(MAC_CONF_GROUP, SESSION_PROTECTION_NOTIF,392iwl_mvm_rx_session_protect_notif, RX_HANDLER_SYNC,393struct iwl_session_prot_notif),394RX_HANDLER(MCC_CHUB_UPDATE_CMD, iwl_mvm_rx_chub_update_mcc,395RX_HANDLER_ASYNC_LOCKED, struct iwl_mcc_chub_notif),396397RX_HANDLER(EOSP_NOTIFICATION, iwl_mvm_rx_eosp_notif, RX_HANDLER_SYNC,398struct iwl_mvm_eosp_notification),399400RX_HANDLER(SCAN_ITERATION_COMPLETE,401iwl_mvm_rx_lmac_scan_iter_complete_notif, RX_HANDLER_SYNC,402struct iwl_lmac_scan_complete_notif),403RX_HANDLER(SCAN_OFFLOAD_COMPLETE,404iwl_mvm_rx_lmac_scan_complete_notif,405RX_HANDLER_ASYNC_LOCKED, struct iwl_periodic_scan_complete),406RX_HANDLER_NO_SIZE(MATCH_FOUND_NOTIFICATION,407iwl_mvm_rx_scan_match_found,408RX_HANDLER_SYNC),409RX_HANDLER(SCAN_COMPLETE_UMAC, iwl_mvm_rx_umac_scan_complete_notif,410RX_HANDLER_ASYNC_LOCKED,411struct iwl_umac_scan_complete),412RX_HANDLER(SCAN_ITERATION_COMPLETE_UMAC,413iwl_mvm_rx_umac_scan_iter_complete_notif, RX_HANDLER_SYNC,414struct iwl_umac_scan_iter_complete_notif),415416RX_HANDLER(MISSED_BEACONS_NOTIFICATION,417iwl_mvm_rx_missed_beacons_notif_legacy,418RX_HANDLER_ASYNC_LOCKED_WIPHY,419struct iwl_missed_beacons_notif_v4),420421RX_HANDLER_GRP(MAC_CONF_GROUP, MISSED_BEACONS_NOTIF,422iwl_mvm_rx_missed_beacons_notif,423RX_HANDLER_ASYNC_LOCKED_WIPHY,424struct iwl_missed_beacons_notif),425RX_HANDLER(REPLY_ERROR, iwl_mvm_rx_fw_error, RX_HANDLER_SYNC,426struct iwl_error_resp),427RX_HANDLER(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION,428iwl_mvm_power_uapsd_misbehaving_ap_notif, RX_HANDLER_SYNC,429struct iwl_uapsd_misbehaving_ap_notif),430RX_HANDLER_NO_SIZE(DTS_MEASUREMENT_NOTIFICATION, iwl_mvm_temp_notif,431RX_HANDLER_ASYNC_LOCKED),432RX_HANDLER_GRP_NO_SIZE(PHY_OPS_GROUP, DTS_MEASUREMENT_NOTIF_WIDE,433iwl_mvm_temp_notif, RX_HANDLER_ASYNC_UNLOCKED),434RX_HANDLER_GRP(PHY_OPS_GROUP, CT_KILL_NOTIFICATION,435iwl_mvm_ct_kill_notif, RX_HANDLER_SYNC,436struct ct_kill_notif),437438RX_HANDLER(TDLS_CHANNEL_SWITCH_NOTIFICATION, iwl_mvm_rx_tdls_notif,439RX_HANDLER_ASYNC_LOCKED,440struct iwl_tdls_channel_switch_notif),441RX_HANDLER(MFUART_LOAD_NOTIFICATION, iwl_mvm_rx_mfuart_notif,442RX_HANDLER_SYNC, struct iwl_mfuart_load_notif_v1),443RX_HANDLER_GRP(LOCATION_GROUP, TOF_RESPONDER_STATS,444iwl_mvm_ftm_responder_stats, RX_HANDLER_ASYNC_LOCKED,445struct iwl_ftm_responder_stats),446447RX_HANDLER_GRP_NO_SIZE(LOCATION_GROUP, TOF_RANGE_RESPONSE_NOTIF,448iwl_mvm_ftm_range_resp, RX_HANDLER_ASYNC_LOCKED),449RX_HANDLER_GRP_NO_SIZE(LOCATION_GROUP, TOF_LC_NOTIF,450iwl_mvm_ftm_lc_notif, RX_HANDLER_ASYNC_LOCKED),451452RX_HANDLER_GRP(DEBUG_GROUP, MFU_ASSERT_DUMP_NTF,453iwl_mvm_mfu_assert_dump_notif, RX_HANDLER_SYNC,454struct iwl_mfu_assert_dump_notif),455RX_HANDLER_GRP(PROT_OFFLOAD_GROUP, STORED_BEACON_NTF,456iwl_mvm_rx_stored_beacon_notif, RX_HANDLER_SYNC,457struct iwl_stored_beacon_notif_v2),458RX_HANDLER_GRP(DATA_PATH_GROUP, MU_GROUP_MGMT_NOTIF,459iwl_mvm_mu_mimo_grp_notif, RX_HANDLER_SYNC,460struct iwl_mu_group_mgmt_notif),461RX_HANDLER_GRP(DATA_PATH_GROUP, STA_PM_NOTIF,462iwl_mvm_sta_pm_notif, RX_HANDLER_SYNC,463struct iwl_mvm_pm_state_notification),464RX_HANDLER_GRP(MAC_CONF_GROUP, PROBE_RESPONSE_DATA_NOTIF,465iwl_mvm_probe_resp_data_notif,466RX_HANDLER_ASYNC_LOCKED,467struct iwl_probe_resp_data_notif),468RX_HANDLER_GRP(MAC_CONF_GROUP, CHANNEL_SWITCH_START_NOTIF,469iwl_mvm_channel_switch_start_notif,470RX_HANDLER_SYNC, struct iwl_channel_switch_start_notif),471RX_HANDLER_GRP(MAC_CONF_GROUP, CHANNEL_SWITCH_ERROR_NOTIF,472iwl_mvm_channel_switch_error_notif,473RX_HANDLER_ASYNC_UNLOCKED,474struct iwl_channel_switch_error_notif),475476RX_HANDLER_GRP(DATA_PATH_GROUP, ESR_MODE_NOTIF,477iwl_mvm_rx_esr_mode_notif,478RX_HANDLER_ASYNC_LOCKED_WIPHY,479struct iwl_esr_mode_notif),480481RX_HANDLER_GRP(DATA_PATH_GROUP, MONITOR_NOTIF,482iwl_mvm_rx_monitor_notif, RX_HANDLER_ASYNC_LOCKED,483struct iwl_datapath_monitor_notif),484485RX_HANDLER_GRP(DATA_PATH_GROUP, THERMAL_DUAL_CHAIN_REQUEST,486iwl_mvm_rx_thermal_dual_chain_req,487RX_HANDLER_ASYNC_LOCKED,488struct iwl_thermal_dual_chain_request),489490RX_HANDLER_GRP(SYSTEM_GROUP, RFI_DEACTIVATE_NOTIF,491iwl_rfi_deactivate_notif_handler, RX_HANDLER_ASYNC_UNLOCKED,492struct iwl_rfi_deactivate_notif),493494RX_HANDLER_GRP(LEGACY_GROUP,495WNM_80211V_TIMING_MEASUREMENT_NOTIFICATION,496iwl_mvm_time_sync_msmt_event, RX_HANDLER_SYNC,497struct iwl_time_msmt_notify),498RX_HANDLER_GRP(LEGACY_GROUP,499WNM_80211V_TIMING_MEASUREMENT_CONFIRM_NOTIFICATION,500iwl_mvm_time_sync_msmt_confirm_event, RX_HANDLER_SYNC,501struct iwl_time_msmt_cfm_notify),502RX_HANDLER_GRP(MAC_CONF_GROUP, ROC_NOTIF,503iwl_mvm_rx_roc_notif, RX_HANDLER_ASYNC_LOCKED,504struct iwl_roc_notif),505RX_HANDLER_GRP(SCAN_GROUP, CHANNEL_SURVEY_NOTIF,506iwl_mvm_rx_channel_survey_notif, RX_HANDLER_ASYNC_LOCKED,507struct iwl_umac_scan_channel_survey_notif),508RX_HANDLER_GRP(DATA_PATH_GROUP, BEACON_FILTER_IN_NOTIF,509iwl_mvm_rx_beacon_filter_notif,510RX_HANDLER_ASYNC_LOCKED,511/* same size as v1 */512struct iwl_beacon_filter_notif),513};514#undef RX_HANDLER515#undef RX_HANDLER_GRP516517/* Please keep this array *SORTED* by hex value.518* Access is done through binary search519*/520static const struct iwl_hcmd_names iwl_mvm_legacy_names[] = {521HCMD_NAME(UCODE_ALIVE_NTFY),522HCMD_NAME(REPLY_ERROR),523HCMD_NAME(ECHO_CMD),524HCMD_NAME(INIT_COMPLETE_NOTIF),525HCMD_NAME(PHY_CONTEXT_CMD),526HCMD_NAME(DBG_CFG),527HCMD_NAME(SCAN_CFG_CMD),528HCMD_NAME(SCAN_REQ_UMAC),529HCMD_NAME(SCAN_ABORT_UMAC),530HCMD_NAME(SCAN_COMPLETE_UMAC),531HCMD_NAME(BA_WINDOW_STATUS_NOTIFICATION_ID),532HCMD_NAME(ADD_STA_KEY),533HCMD_NAME(ADD_STA),534HCMD_NAME(REMOVE_STA),535HCMD_NAME(TX_CMD),536HCMD_NAME(SCD_QUEUE_CFG),537HCMD_NAME(TXPATH_FLUSH),538HCMD_NAME(MGMT_MCAST_KEY),539HCMD_NAME(WEP_KEY),540HCMD_NAME(SHARED_MEM_CFG),541HCMD_NAME(TDLS_CHANNEL_SWITCH_CMD),542HCMD_NAME(MAC_CONTEXT_CMD),543HCMD_NAME(TIME_EVENT_CMD),544HCMD_NAME(TIME_EVENT_NOTIFICATION),545HCMD_NAME(BINDING_CONTEXT_CMD),546HCMD_NAME(TIME_QUOTA_CMD),547HCMD_NAME(NON_QOS_TX_COUNTER_CMD),548HCMD_NAME(LEDS_CMD),549HCMD_NAME(LQ_CMD),550HCMD_NAME(FW_PAGING_BLOCK_CMD),551HCMD_NAME(SCAN_OFFLOAD_REQUEST_CMD),552HCMD_NAME(SCAN_OFFLOAD_ABORT_CMD),553HCMD_NAME(HOT_SPOT_CMD),554HCMD_NAME(SCAN_OFFLOAD_PROFILES_QUERY_CMD),555HCMD_NAME(BT_COEX_UPDATE_REDUCED_TXP),556HCMD_NAME(BT_COEX_CI),557HCMD_NAME(WNM_80211V_TIMING_MEASUREMENT_NOTIFICATION),558HCMD_NAME(WNM_80211V_TIMING_MEASUREMENT_CONFIRM_NOTIFICATION),559HCMD_NAME(PHY_CONFIGURATION_CMD),560HCMD_NAME(CALIB_RES_NOTIF_PHY_DB),561HCMD_NAME(PHY_DB_CMD),562HCMD_NAME(SCAN_OFFLOAD_COMPLETE),563HCMD_NAME(SCAN_OFFLOAD_UPDATE_PROFILES_CMD),564HCMD_NAME(POWER_TABLE_CMD),565HCMD_NAME(PSM_UAPSD_AP_MISBEHAVING_NOTIFICATION),566HCMD_NAME(REPLY_THERMAL_MNG_BACKOFF),567HCMD_NAME(NVM_ACCESS_CMD),568HCMD_NAME(BEACON_NOTIFICATION),569HCMD_NAME(BEACON_TEMPLATE_CMD),570HCMD_NAME(TX_ANT_CONFIGURATION_CMD),571HCMD_NAME(BT_CONFIG),572HCMD_NAME(STATISTICS_CMD),573HCMD_NAME(STATISTICS_NOTIFICATION),574HCMD_NAME(EOSP_NOTIFICATION),575HCMD_NAME(REDUCE_TX_POWER_CMD),576HCMD_NAME(MISSED_BEACONS_NOTIFICATION),577HCMD_NAME(TDLS_CONFIG_CMD),578HCMD_NAME(MAC_PM_POWER_TABLE),579HCMD_NAME(TDLS_CHANNEL_SWITCH_NOTIFICATION),580HCMD_NAME(MFUART_LOAD_NOTIFICATION),581HCMD_NAME(RSS_CONFIG_CMD),582HCMD_NAME(SCAN_ITERATION_COMPLETE_UMAC),583HCMD_NAME(REPLY_RX_PHY_CMD),584HCMD_NAME(REPLY_RX_MPDU_CMD),585HCMD_NAME(BAR_FRAME_RELEASE),586HCMD_NAME(FRAME_RELEASE),587HCMD_NAME(BA_NOTIF),588HCMD_NAME(MCC_UPDATE_CMD),589HCMD_NAME(MCC_CHUB_UPDATE_CMD),590HCMD_NAME(MARKER_CMD),591HCMD_NAME(BT_PROFILE_NOTIFICATION),592HCMD_NAME(MCAST_FILTER_CMD),593HCMD_NAME(REPLY_SF_CFG_CMD),594HCMD_NAME(REPLY_BEACON_FILTERING_CMD),595HCMD_NAME(D3_CONFIG_CMD),596HCMD_NAME(PROT_OFFLOAD_CONFIG_CMD),597HCMD_NAME(MATCH_FOUND_NOTIFICATION),598HCMD_NAME(DTS_MEASUREMENT_NOTIFICATION),599HCMD_NAME(WOWLAN_PATTERNS),600HCMD_NAME(WOWLAN_CONFIGURATION),601HCMD_NAME(WOWLAN_TSC_RSC_PARAM),602HCMD_NAME(WOWLAN_TKIP_PARAM),603HCMD_NAME(WOWLAN_KEK_KCK_MATERIAL),604HCMD_NAME(WOWLAN_GET_STATUSES),605HCMD_NAME(SCAN_ITERATION_COMPLETE),606HCMD_NAME(D0I3_END_CMD),607HCMD_NAME(LTR_CONFIG),608HCMD_NAME(LDBG_CONFIG_CMD),609HCMD_NAME(DEBUG_LOG_MSG),610};611612/* Please keep this array *SORTED* by hex value.613* Access is done through binary search614*/615static const struct iwl_hcmd_names iwl_mvm_system_names[] = {616HCMD_NAME(SHARED_MEM_CFG_CMD),617HCMD_NAME(SOC_CONFIGURATION_CMD),618HCMD_NAME(INIT_EXTENDED_CFG_CMD),619HCMD_NAME(FW_ERROR_RECOVERY_CMD),620HCMD_NAME(RFI_CONFIG_CMD),621HCMD_NAME(RFI_GET_FREQ_TABLE_CMD),622HCMD_NAME(SYSTEM_FEATURES_CONTROL_CMD),623HCMD_NAME(SYSTEM_STATISTICS_CMD),624HCMD_NAME(SYSTEM_STATISTICS_END_NOTIF),625HCMD_NAME(RFI_DEACTIVATE_NOTIF),626};627628/* Please keep this array *SORTED* by hex value.629* Access is done through binary search630*/631static const struct iwl_hcmd_names iwl_mvm_mac_conf_names[] = {632HCMD_NAME(LOW_LATENCY_CMD),633HCMD_NAME(CHANNEL_SWITCH_TIME_EVENT_CMD),634HCMD_NAME(SESSION_PROTECTION_CMD),635HCMD_NAME(CANCEL_CHANNEL_SWITCH_CMD),636HCMD_NAME(MAC_CONFIG_CMD),637HCMD_NAME(LINK_CONFIG_CMD),638HCMD_NAME(STA_CONFIG_CMD),639HCMD_NAME(AUX_STA_CMD),640HCMD_NAME(STA_REMOVE_CMD),641HCMD_NAME(STA_DISABLE_TX_CMD),642HCMD_NAME(ROC_CMD),643HCMD_NAME(ROC_NOTIF),644HCMD_NAME(CHANNEL_SWITCH_ERROR_NOTIF),645HCMD_NAME(MISSED_VAP_NOTIF),646HCMD_NAME(SESSION_PROTECTION_NOTIF),647HCMD_NAME(PROBE_RESPONSE_DATA_NOTIF),648HCMD_NAME(CHANNEL_SWITCH_START_NOTIF),649};650651/* Please keep this array *SORTED* by hex value.652* Access is done through binary search653*/654static const struct iwl_hcmd_names iwl_mvm_phy_names[] = {655HCMD_NAME(CMD_DTS_MEASUREMENT_TRIGGER_WIDE),656HCMD_NAME(CTDP_CONFIG_CMD),657HCMD_NAME(TEMP_REPORTING_THRESHOLDS_CMD),658HCMD_NAME(PER_CHAIN_LIMIT_OFFSET_CMD),659HCMD_NAME(AP_TX_POWER_CONSTRAINTS_CMD),660HCMD_NAME(CT_KILL_NOTIFICATION),661HCMD_NAME(DTS_MEASUREMENT_NOTIF_WIDE),662};663664/* Please keep this array *SORTED* by hex value.665* Access is done through binary search666*/667static const struct iwl_hcmd_names iwl_mvm_data_path_names[] = {668HCMD_NAME(DQA_ENABLE_CMD),669HCMD_NAME(UPDATE_MU_GROUPS_CMD),670HCMD_NAME(TRIGGER_RX_QUEUES_NOTIF_CMD),671HCMD_NAME(WNM_PLATFORM_PTM_REQUEST_CMD),672HCMD_NAME(WNM_80211V_TIMING_MEASUREMENT_CONFIG_CMD),673HCMD_NAME(STA_HE_CTXT_CMD),674HCMD_NAME(RLC_CONFIG_CMD),675HCMD_NAME(RFH_QUEUE_CONFIG_CMD),676HCMD_NAME(TLC_MNG_CONFIG_CMD),677HCMD_NAME(CHEST_COLLECTOR_FILTER_CONFIG_CMD),678HCMD_NAME(SCD_QUEUE_CONFIG_CMD),679HCMD_NAME(SEC_KEY_CMD),680HCMD_NAME(ESR_MODE_NOTIF),681HCMD_NAME(MONITOR_NOTIF),682HCMD_NAME(THERMAL_DUAL_CHAIN_REQUEST),683HCMD_NAME(BEACON_FILTER_IN_NOTIF),684HCMD_NAME(STA_PM_NOTIF),685HCMD_NAME(MU_GROUP_MGMT_NOTIF),686HCMD_NAME(RX_QUEUES_NOTIFICATION),687};688689/* Please keep this array *SORTED* by hex value.690* Access is done through binary search691*/692static const struct iwl_hcmd_names iwl_mvm_statistics_names[] = {693HCMD_NAME(STATISTICS_OPER_NOTIF),694HCMD_NAME(STATISTICS_OPER_PART1_NOTIF),695};696697/* Please keep this array *SORTED* by hex value.698* Access is done through binary search699*/700static const struct iwl_hcmd_names iwl_mvm_debug_names[] = {701HCMD_NAME(LMAC_RD_WR),702HCMD_NAME(UMAC_RD_WR),703HCMD_NAME(HOST_EVENT_CFG),704HCMD_NAME(DBGC_SUSPEND_RESUME),705HCMD_NAME(BUFFER_ALLOCATION),706HCMD_NAME(GET_TAS_STATUS),707HCMD_NAME(FW_DUMP_COMPLETE_CMD),708HCMD_NAME(FW_CLEAR_BUFFER),709HCMD_NAME(MFU_ASSERT_DUMP_NTF),710};711712/* Please keep this array *SORTED* by hex value.713* Access is done through binary search714*/715static const struct iwl_hcmd_names iwl_mvm_scan_names[] = {716HCMD_NAME(CHANNEL_SURVEY_NOTIF),717HCMD_NAME(OFFLOAD_MATCH_INFO_NOTIF),718};719720/* Please keep this array *SORTED* by hex value.721* Access is done through binary search722*/723static const struct iwl_hcmd_names iwl_mvm_location_names[] = {724HCMD_NAME(TOF_RANGE_REQ_CMD),725HCMD_NAME(TOF_CONFIG_CMD),726HCMD_NAME(TOF_RANGE_ABORT_CMD),727HCMD_NAME(TOF_RANGE_REQ_EXT_CMD),728HCMD_NAME(TOF_RESPONDER_CONFIG_CMD),729HCMD_NAME(TOF_RESPONDER_DYN_CONFIG_CMD),730HCMD_NAME(TOF_LC_NOTIF),731HCMD_NAME(TOF_RESPONDER_STATS),732HCMD_NAME(TOF_MCSI_DEBUG_NOTIF),733HCMD_NAME(TOF_RANGE_RESPONSE_NOTIF),734};735736/* Please keep this array *SORTED* by hex value.737* Access is done through binary search738*/739static const struct iwl_hcmd_names iwl_mvm_prot_offload_names[] = {740HCMD_NAME(WOWLAN_WAKE_PKT_NOTIFICATION),741HCMD_NAME(WOWLAN_INFO_NOTIFICATION),742HCMD_NAME(D3_END_NOTIFICATION),743HCMD_NAME(STORED_BEACON_NTF),744};745746/* Please keep this array *SORTED* by hex value.747* Access is done through binary search748*/749static const struct iwl_hcmd_names iwl_mvm_regulatory_and_nvm_names[] = {750HCMD_NAME(NVM_ACCESS_COMPLETE),751HCMD_NAME(NVM_GET_INFO),752HCMD_NAME(TAS_CONFIG),753};754755/* Please keep this array *SORTED* by hex value.756* Access is done through binary search757*/758static const struct iwl_hcmd_names iwl_mvm_bt_coex_names[] = {759HCMD_NAME(PROFILE_NOTIF),760};761762VISIBLE_IF_IWLWIFI_KUNIT763const struct iwl_hcmd_arr iwl_mvm_groups[] = {764[LEGACY_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),765[LONG_GROUP] = HCMD_ARR(iwl_mvm_legacy_names),766[SYSTEM_GROUP] = HCMD_ARR(iwl_mvm_system_names),767[MAC_CONF_GROUP] = HCMD_ARR(iwl_mvm_mac_conf_names),768[PHY_OPS_GROUP] = HCMD_ARR(iwl_mvm_phy_names),769[DATA_PATH_GROUP] = HCMD_ARR(iwl_mvm_data_path_names),770[SCAN_GROUP] = HCMD_ARR(iwl_mvm_scan_names),771[LOCATION_GROUP] = HCMD_ARR(iwl_mvm_location_names),772[BT_COEX_GROUP] = HCMD_ARR(iwl_mvm_bt_coex_names),773[PROT_OFFLOAD_GROUP] = HCMD_ARR(iwl_mvm_prot_offload_names),774[REGULATORY_AND_NVM_GROUP] =775HCMD_ARR(iwl_mvm_regulatory_and_nvm_names),776[DEBUG_GROUP] = HCMD_ARR(iwl_mvm_debug_names),777[STATISTICS_GROUP] = HCMD_ARR(iwl_mvm_statistics_names),778};779EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mvm_groups);780#if IS_ENABLED(CONFIG_IWLWIFI_KUNIT_TESTS)781const unsigned int iwl_mvm_groups_size = ARRAY_SIZE(iwl_mvm_groups);782EXPORT_SYMBOL_IF_IWLWIFI_KUNIT(iwl_mvm_groups_size);783#endif784785/* this forward declaration can avoid to export the function */786static void iwl_mvm_async_handlers_wk(struct work_struct *wk);787static void iwl_mvm_async_handlers_wiphy_wk(struct wiphy *wiphy,788struct wiphy_work *work);789790static u32 iwl_mvm_min_backoff(struct iwl_mvm *mvm)791{792const struct iwl_pwr_tx_backoff *backoff = mvm->cfg->pwr_tx_backoffs;793u64 dflt_pwr_limit;794795if (!backoff)796return 0;797798iwl_bios_get_pwr_limit(&mvm->fwrt, &dflt_pwr_limit);799800while (backoff->pwr) {801if (dflt_pwr_limit >= backoff->pwr)802return backoff->backoff;803804backoff++;805}806807return 0;808}809810static void iwl_mvm_tx_unblock_dwork(struct work_struct *work)811{812struct iwl_mvm *mvm =813container_of(work, struct iwl_mvm, cs_tx_unblock_dwork.work);814struct ieee80211_vif *tx_blocked_vif;815struct iwl_mvm_vif *mvmvif;816817guard(mvm)(mvm);818819tx_blocked_vif =820rcu_dereference_protected(mvm->csa_tx_blocked_vif,821lockdep_is_held(&mvm->mutex));822823if (!tx_blocked_vif)824return;825826mvmvif = iwl_mvm_vif_from_mac80211(tx_blocked_vif);827iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, false);828RCU_INIT_POINTER(mvm->csa_tx_blocked_vif, NULL);829}830831static void iwl_mvm_fwrt_dump_start(void *ctx)832{833struct iwl_mvm *mvm = ctx;834835mutex_lock(&mvm->mutex);836}837838static void iwl_mvm_fwrt_dump_end(void *ctx)839{840struct iwl_mvm *mvm = ctx;841842mutex_unlock(&mvm->mutex);843}844845static int iwl_mvm_fwrt_send_hcmd(void *ctx, struct iwl_host_cmd *host_cmd)846{847struct iwl_mvm *mvm = (struct iwl_mvm *)ctx;848849guard(mvm)(mvm);850return iwl_mvm_send_cmd(mvm, host_cmd);851}852853static bool iwl_mvm_d3_debug_enable(void *ctx)854{855return IWL_MVM_D3_DEBUG;856}857858static const struct iwl_fw_runtime_ops iwl_mvm_fwrt_ops = {859.dump_start = iwl_mvm_fwrt_dump_start,860.dump_end = iwl_mvm_fwrt_dump_end,861.send_hcmd = iwl_mvm_fwrt_send_hcmd,862.d3_debug_enable = iwl_mvm_d3_debug_enable,863};864865static int iwl_mvm_start_get_nvm(struct iwl_mvm *mvm)866{867struct iwl_trans *trans = mvm->trans;868int ret;869870if (trans->csme_own) {871if (WARN(!mvm->mei_registered,872"csme is owner, but we aren't registered to iwlmei\n"))873goto get_nvm_from_fw;874875mvm->mei_nvm_data = iwl_mei_get_nvm();876if (mvm->mei_nvm_data) {877/*878* mvm->mei_nvm_data is set and because of that,879* we'll load the NVM from the FW when we'll get880* ownership.881*/882mvm->nvm_data =883iwl_parse_mei_nvm_data(trans, trans->cfg,884mvm->mei_nvm_data,885mvm->fw,886mvm->set_tx_ant,887mvm->set_rx_ant);888return 0;889}890891IWL_ERR(mvm,892"Got a NULL NVM from CSME, trying to get it from the device\n");893}894895get_nvm_from_fw:896rtnl_lock();897wiphy_lock(mvm->hw->wiphy);898mutex_lock(&mvm->mutex);899900ret = iwl_trans_start_hw(mvm->trans);901if (ret) {902mutex_unlock(&mvm->mutex);903wiphy_unlock(mvm->hw->wiphy);904rtnl_unlock();905return ret;906}907908ret = iwl_run_init_mvm_ucode(mvm);909if (ret && ret != -ERFKILL)910iwl_fw_dbg_error_collect(&mvm->fwrt, FW_DBG_TRIGGER_DRIVER);911if (!ret && iwl_mvm_is_lar_supported(mvm)) {912mvm->hw->wiphy->regulatory_flags |= REGULATORY_WIPHY_SELF_MANAGED;913ret = iwl_mvm_init_mcc(mvm);914}915916iwl_mvm_stop_device(mvm);917918mutex_unlock(&mvm->mutex);919wiphy_unlock(mvm->hw->wiphy);920rtnl_unlock();921922if (ret)923IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);924925/* no longer need this regardless of failure or not */926mvm->fw_product_reset = false;927928return ret;929}930931static int iwl_mvm_start_post_nvm(struct iwl_mvm *mvm)932{933struct iwl_mvm_csme_conn_info *csme_conn_info __maybe_unused;934int ret;935936iwl_mvm_toggle_tx_ant(mvm, &mvm->mgmt_last_antenna_idx);937938ret = iwl_mvm_mac_setup_register(mvm);939if (ret)940return ret;941942mvm->hw_registered = true;943944iwl_mvm_dbgfs_register(mvm);945946wiphy_rfkill_set_hw_state_reason(mvm->hw->wiphy,947mvm->mei_rfkill_blocked,948RFKILL_HARD_BLOCK_NOT_OWNER);949950iwl_mvm_mei_set_sw_rfkill_state(mvm);951952return 0;953}954955struct iwl_mvm_frob_txf_data {956u8 *buf;957size_t buflen;958};959960static void iwl_mvm_frob_txf_key_iter(struct ieee80211_hw *hw,961struct ieee80211_vif *vif,962struct ieee80211_sta *sta,963struct ieee80211_key_conf *key,964void *data)965{966struct iwl_mvm_frob_txf_data *txf = data;967u8 keylen, match, matchend;968u8 *keydata;969size_t i;970971switch (key->cipher) {972case WLAN_CIPHER_SUITE_CCMP:973keydata = key->key;974keylen = key->keylen;975break;976case WLAN_CIPHER_SUITE_WEP40:977case WLAN_CIPHER_SUITE_WEP104:978case WLAN_CIPHER_SUITE_TKIP:979/*980* WEP has short keys which might show up in the payload,981* and then you can deduce the key, so in this case just982* remove all FIFO data.983* For TKIP, we don't know the phase 2 keys here, so same.984*/985memset(txf->buf, 0xBB, txf->buflen);986return;987default:988return;989}990991/* scan for key material and clear it out */992match = 0;993for (i = 0; i < txf->buflen; i++) {994if (txf->buf[i] != keydata[match]) {995match = 0;996continue;997}998match++;999if (match == keylen) {1000memset(txf->buf + i - keylen, 0xAA, keylen);1001match = 0;1002}1003}10041005/* we're dealing with a FIFO, so check wrapped around data */1006matchend = match;1007for (i = 0; match && i < keylen - match; i++) {1008if (txf->buf[i] != keydata[match])1009break;1010match++;1011if (match == keylen) {1012memset(txf->buf, 0xAA, i + 1);1013memset(txf->buf + txf->buflen - matchend, 0xAA,1014matchend);1015break;1016}1017}1018}10191020static void iwl_mvm_frob_txf(void *ctx, void *buf, size_t buflen)1021{1022struct iwl_mvm_frob_txf_data txf = {1023.buf = buf,1024.buflen = buflen,1025};1026struct iwl_mvm *mvm = ctx;10271028/* embedded key material exists only on old API */1029if (iwl_mvm_has_new_tx_api(mvm))1030return;10311032rcu_read_lock();1033ieee80211_iter_keys_rcu(mvm->hw, NULL, iwl_mvm_frob_txf_key_iter, &txf);1034rcu_read_unlock();1035}10361037static void iwl_mvm_frob_hcmd(void *ctx, void *hcmd, size_t len)1038{1039/* we only use wide headers for commands */1040struct iwl_cmd_header_wide *hdr = hcmd;1041unsigned int frob_start = sizeof(*hdr), frob_end = 0;10421043if (len < sizeof(hdr))1044return;10451046/* all the commands we care about are in LONG_GROUP */1047if (hdr->group_id != LONG_GROUP)1048return;10491050switch (hdr->cmd) {1051case WEP_KEY:1052case WOWLAN_TKIP_PARAM:1053case WOWLAN_KEK_KCK_MATERIAL:1054case ADD_STA_KEY:1055/*1056* blank out everything here, easier than dealing1057* with the various versions of the command1058*/1059frob_end = INT_MAX;1060break;1061case MGMT_MCAST_KEY:1062frob_start = offsetof(struct iwl_mvm_mgmt_mcast_key_cmd, igtk);1063BUILD_BUG_ON(offsetof(struct iwl_mvm_mgmt_mcast_key_cmd, igtk) !=1064offsetof(struct iwl_mvm_mgmt_mcast_key_cmd_v1, igtk));10651066frob_end = offsetofend(struct iwl_mvm_mgmt_mcast_key_cmd, igtk);1067BUILD_BUG_ON(offsetof(struct iwl_mvm_mgmt_mcast_key_cmd, igtk) <1068offsetof(struct iwl_mvm_mgmt_mcast_key_cmd_v1, igtk));1069break;1070}10711072if (frob_start >= frob_end)1073return;10741075if (frob_end > len)1076frob_end = len;10771078memset((u8 *)hcmd + frob_start, 0xAA, frob_end - frob_start);1079}10801081static void iwl_mvm_frob_mem(void *ctx, u32 mem_addr, void *mem, size_t buflen)1082{1083const struct iwl_dump_exclude *excl;1084struct iwl_mvm *mvm = ctx;1085int i;10861087switch (mvm->fwrt.cur_fw_img) {1088case IWL_UCODE_INIT:1089default:1090/* not relevant */1091return;1092case IWL_UCODE_REGULAR:1093case IWL_UCODE_REGULAR_USNIFFER:1094excl = mvm->fw->dump_excl;1095break;1096case IWL_UCODE_WOWLAN:1097excl = mvm->fw->dump_excl_wowlan;1098break;1099}11001101BUILD_BUG_ON(sizeof(mvm->fw->dump_excl) !=1102sizeof(mvm->fw->dump_excl_wowlan));11031104for (i = 0; i < ARRAY_SIZE(mvm->fw->dump_excl); i++) {1105u32 start, end;11061107if (!excl[i].addr || !excl[i].size)1108continue;11091110start = excl[i].addr;1111end = start + excl[i].size;11121113if (end <= mem_addr || start >= mem_addr + buflen)1114continue;11151116if (start < mem_addr)1117start = mem_addr;11181119if (end > mem_addr + buflen)1120end = mem_addr + buflen;11211122memset((u8 *)mem + start - mem_addr, 0xAA, end - start);1123}1124}11251126static const struct iwl_dump_sanitize_ops iwl_mvm_sanitize_ops = {1127.frob_txf = iwl_mvm_frob_txf,1128.frob_hcmd = iwl_mvm_frob_hcmd,1129.frob_mem = iwl_mvm_frob_mem,1130};11311132#if IS_ENABLED(CONFIG_IWLMEI)1133static void iwl_mvm_me_conn_status(void *priv, const struct iwl_mei_conn_info *conn_info)1134{1135struct iwl_mvm *mvm = priv;1136struct iwl_mvm_csme_conn_info *prev_conn_info, *curr_conn_info;11371138/*1139* This is protected by the guarantee that this function will not be1140* called twice on two different threads1141*/1142prev_conn_info = rcu_dereference_protected(mvm->csme_conn_info, true);11431144curr_conn_info = kzalloc(sizeof(*curr_conn_info), GFP_KERNEL);1145if (!curr_conn_info)1146return;11471148curr_conn_info->conn_info = *conn_info;11491150rcu_assign_pointer(mvm->csme_conn_info, curr_conn_info);11511152if (prev_conn_info)1153kfree_rcu(prev_conn_info, rcu_head);1154}11551156static void iwl_mvm_mei_rfkill(void *priv, bool blocked,1157bool csme_taking_ownership)1158{1159struct iwl_mvm *mvm = priv;11601161if (blocked && !csme_taking_ownership)1162return;11631164mvm->mei_rfkill_blocked = blocked;1165if (!mvm->hw_registered)1166return;11671168wiphy_rfkill_set_hw_state_reason(mvm->hw->wiphy,1169mvm->mei_rfkill_blocked,1170RFKILL_HARD_BLOCK_NOT_OWNER);1171}11721173static void iwl_mvm_mei_roaming_forbidden(void *priv, bool forbidden)1174{1175struct iwl_mvm *mvm = priv;11761177if (!mvm->hw_registered || !mvm->csme_vif)1178return;11791180iwl_mvm_send_roaming_forbidden_event(mvm, mvm->csme_vif, forbidden);1181}1182#endif11831184static void iwl_mvm_sap_connected_wk(struct work_struct *wk)1185{1186struct iwl_mvm *mvm =1187container_of(wk, struct iwl_mvm, sap_connected_wk);1188int ret;11891190ret = iwl_mvm_start_get_nvm(mvm);1191if (ret)1192goto out_free;11931194ret = iwl_mvm_start_post_nvm(mvm);1195if (ret)1196goto out_free;11971198return;11991200out_free:1201IWL_ERR(mvm, "Couldn't get started...\n");1202iwl_mei_start_unregister();1203iwl_mei_unregister_complete();1204iwl_fw_flush_dumps(&mvm->fwrt);1205iwl_mvm_thermal_exit(mvm);1206iwl_fw_runtime_free(&mvm->fwrt);1207iwl_phy_db_free(mvm->phy_db);1208kfree(mvm->scan_cmd);1209iwl_trans_op_mode_leave(mvm->trans);1210kfree(mvm->nvm_data);1211kfree(mvm->mei_nvm_data);12121213ieee80211_free_hw(mvm->hw);1214}12151216#if IS_ENABLED(CONFIG_IWLMEI)1217static void iwl_mvm_mei_sap_connected(void *priv)1218{1219struct iwl_mvm *mvm = priv;12201221if (!mvm->hw_registered)1222schedule_work(&mvm->sap_connected_wk);1223}12241225static void iwl_mvm_mei_nic_stolen(void *priv)1226{1227struct iwl_mvm *mvm = priv;12281229rtnl_lock();1230cfg80211_shutdown_all_interfaces(mvm->hw->wiphy);1231rtnl_unlock();1232}12331234static const struct iwl_mei_ops mei_ops = {1235.me_conn_status = iwl_mvm_me_conn_status,1236.rfkill = iwl_mvm_mei_rfkill,1237.roaming_forbidden = iwl_mvm_mei_roaming_forbidden,1238.sap_connected = iwl_mvm_mei_sap_connected,1239.nic_stolen = iwl_mvm_mei_nic_stolen,1240};1241#endif12421243static void iwl_mvm_find_link_selection_vif(void *_data, u8 *mac,1244struct ieee80211_vif *vif)1245{1246struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);12471248if (ieee80211_vif_is_mld(vif) && mvmvif->authorized)1249iwl_mvm_select_links(mvmvif->mvm, vif);1250}12511252static void iwl_mvm_trig_link_selection(struct wiphy *wiphy,1253struct wiphy_work *wk)1254{1255struct iwl_mvm *mvm =1256container_of(wk, struct iwl_mvm, trig_link_selection_wk);12571258mutex_lock(&mvm->mutex);1259ieee80211_iterate_active_interfaces(mvm->hw,1260IEEE80211_IFACE_ITER_NORMAL,1261iwl_mvm_find_link_selection_vif,1262NULL);1263mutex_unlock(&mvm->mutex);1264}12651266static struct iwl_op_mode *1267iwl_op_mode_mvm_start(struct iwl_trans *trans, const struct iwl_rf_cfg *cfg,1268const struct iwl_fw *fw, struct dentry *dbgfs_dir)1269{1270struct ieee80211_hw *hw;1271struct iwl_op_mode *op_mode;1272struct iwl_mvm *mvm;1273static const u8 no_reclaim_cmds[] = {1274TX_CMD,1275};1276u32 max_agg;1277size_t scan_size;1278u32 min_backoff;1279struct iwl_mvm_csme_conn_info *csme_conn_info __maybe_unused;1280int ratecheck;1281int err;12821283/*1284* We use IWL_STATION_COUNT_MAX to check the validity of the station1285* index all over the driver - check that its value corresponds to the1286* array size.1287*/1288BUILD_BUG_ON(ARRAY_SIZE(mvm->fw_id_to_mac_id) !=1289IWL_STATION_COUNT_MAX);12901291/********************************1292* 1. Allocating and configuring HW data1293********************************/1294hw = ieee80211_alloc_hw(sizeof(struct iwl_op_mode) +1295sizeof(struct iwl_mvm),1296iwl_mvm_has_mld_api(fw) ? &iwl_mvm_mld_hw_ops :1297&iwl_mvm_hw_ops);1298if (!hw)1299return ERR_PTR(-ENOMEM);13001301if (trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_BZ)1302max_agg = 512;1303else1304max_agg = IEEE80211_MAX_AMPDU_BUF_HE;13051306hw->max_rx_aggregation_subframes = max_agg;13071308op_mode = hw->priv;13091310mvm = IWL_OP_MODE_GET_MVM(op_mode);1311mvm->dev = trans->dev;1312mvm->trans = trans;1313mvm->cfg = cfg;1314mvm->fw = fw;1315mvm->hw = hw;13161317iwl_fw_runtime_init(&mvm->fwrt, trans, fw, &iwl_mvm_fwrt_ops, mvm,1318&iwl_mvm_sanitize_ops, mvm, dbgfs_dir);13191320iwl_mvm_get_bios_tables(mvm);1321iwl_uefi_get_sgom_table(trans, &mvm->fwrt);1322iwl_uefi_get_step_table(trans);1323iwl_bios_setup_step(trans, &mvm->fwrt);13241325mvm->init_status = 0;13261327/* start with v1 rates */1328mvm->fw_rates_ver = 1;13291330/* check for rates version 2 */1331ratecheck =1332(iwl_fw_lookup_cmd_ver(mvm->fw, TX_CMD, 0) >= 8) +1333(iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP,1334TLC_MNG_UPDATE_NOTIF, 0) >= 3) +1335(iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,1336REPLY_RX_MPDU_CMD, 0) >= 4) +1337(iwl_fw_lookup_notif_ver(mvm->fw, LONG_GROUP, TX_CMD, 0) >= 6);1338if (ratecheck != 0 && ratecheck != 4) {1339IWL_ERR(mvm, "Firmware has inconsistent rates\n");1340err = -EINVAL;1341goto out_free;1342}1343if (ratecheck == 4)1344mvm->fw_rates_ver = 2;13451346/* check for rates version 3 */1347ratecheck =1348(iwl_fw_lookup_cmd_ver(mvm->fw, TX_CMD, 0) >= 11) +1349(iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP,1350TLC_MNG_UPDATE_NOTIF, 0) >= 4) +1351(iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,1352REPLY_RX_MPDU_CMD, 0) >= 6) +1353(iwl_fw_lookup_notif_ver(mvm->fw, DATA_PATH_GROUP,1354RX_NO_DATA_NOTIF, 0) >= 4) +1355(iwl_fw_lookup_notif_ver(mvm->fw, LONG_GROUP, TX_CMD, 0) >= 9);1356if (ratecheck != 0 && ratecheck != 5) {1357IWL_ERR(mvm, "Firmware has inconsistent rates\n");1358err = -EINVAL;1359goto out_free;1360}1361if (ratecheck == 5)1362mvm->fw_rates_ver = 3;13631364trans->conf.rx_mpdu_cmd = REPLY_RX_MPDU_CMD;13651366if (iwl_mvm_has_new_rx_api(mvm)) {1367op_mode->ops = &iwl_mvm_ops_mq;1368trans->conf.rx_mpdu_cmd_hdr_size =1369(trans->mac_cfg->device_family >=1370IWL_DEVICE_FAMILY_AX210) ?1371sizeof(struct iwl_rx_mpdu_desc) :1372IWL_RX_DESC_SIZE_V1;1373} else {1374op_mode->ops = &iwl_mvm_ops;1375trans->conf.rx_mpdu_cmd_hdr_size =1376sizeof(struct iwl_rx_mpdu_res_start);13771378if (WARN_ON(trans->info.num_rxqs > 1)) {1379err = -EINVAL;1380goto out_free;1381}1382}13831384if (iwl_mvm_has_new_tx_api(mvm)) {1385/*1386* If we have the new TX/queue allocation API initialize them1387* all to invalid numbers. We'll rewrite the ones that we need1388* later, but that doesn't happen for all of them all of the1389* time (e.g. P2P Device is optional), and if a dynamic queue1390* ends up getting number 2 (IWL_MVM_DQA_P2P_DEVICE_QUEUE) then1391* iwl_mvm_is_static_queue() erroneously returns true, and we1392* might have things getting stuck.1393*/1394mvm->aux_queue = IWL_MVM_INVALID_QUEUE;1395mvm->snif_queue = IWL_MVM_INVALID_QUEUE;1396mvm->probe_queue = IWL_MVM_INVALID_QUEUE;1397mvm->p2p_dev_queue = IWL_MVM_INVALID_QUEUE;1398} else {1399mvm->aux_queue = IWL_MVM_DQA_AUX_QUEUE;1400mvm->snif_queue = IWL_MVM_DQA_INJECT_MONITOR_QUEUE;1401mvm->probe_queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE;1402mvm->p2p_dev_queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE;1403}14041405mvm->sf_state = SF_UNINIT;1406if (iwl_mvm_has_unified_ucode(mvm))1407iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_REGULAR);1408else1409iwl_fw_set_current_image(&mvm->fwrt, IWL_UCODE_INIT);1410mvm->drop_bcn_ap_mode = true;14111412mutex_init(&mvm->mutex);1413spin_lock_init(&mvm->async_handlers_lock);1414INIT_LIST_HEAD(&mvm->time_event_list);1415INIT_LIST_HEAD(&mvm->aux_roc_te_list);1416INIT_LIST_HEAD(&mvm->async_handlers_list);1417spin_lock_init(&mvm->time_event_lock);1418INIT_LIST_HEAD(&mvm->ftm_initiator.loc_list);1419INIT_LIST_HEAD(&mvm->ftm_initiator.pasn_list);1420INIT_LIST_HEAD(&mvm->resp_pasn_list);14211422INIT_WORK(&mvm->async_handlers_wk, iwl_mvm_async_handlers_wk);1423INIT_WORK(&mvm->roc_done_wk, iwl_mvm_roc_done_wk);1424INIT_WORK(&mvm->sap_connected_wk, iwl_mvm_sap_connected_wk);1425INIT_DELAYED_WORK(&mvm->tdls_cs.dwork, iwl_mvm_tdls_ch_switch_work);1426INIT_DELAYED_WORK(&mvm->scan_timeout_dwork, iwl_mvm_scan_timeout_wk);1427INIT_WORK(&mvm->add_stream_wk, iwl_mvm_add_new_dqa_stream_wk);1428INIT_LIST_HEAD(&mvm->add_stream_txqs);1429spin_lock_init(&mvm->add_stream_lock);14301431wiphy_work_init(&mvm->async_handlers_wiphy_wk,1432iwl_mvm_async_handlers_wiphy_wk);14331434wiphy_work_init(&mvm->trig_link_selection_wk,1435iwl_mvm_trig_link_selection);14361437init_waitqueue_head(&mvm->rx_sync_waitq);14381439mvm->queue_sync_state = 0;14401441SET_IEEE80211_DEV(mvm->hw, mvm->trans->dev);14421443spin_lock_init(&mvm->tcm.lock);1444INIT_DELAYED_WORK(&mvm->tcm.work, iwl_mvm_tcm_work);1445mvm->tcm.ts = jiffies;1446mvm->tcm.ll_ts = jiffies;1447mvm->tcm.uapsd_nonagg_ts = jiffies;14481449INIT_DELAYED_WORK(&mvm->cs_tx_unblock_dwork, iwl_mvm_tx_unblock_dwork);14501451mvm->cmd_ver.range_resp =1452iwl_fw_lookup_notif_ver(mvm->fw, LOCATION_GROUP,1453TOF_RANGE_RESPONSE_NOTIF, 5);1454/* we only support up to version 9 */1455if (WARN_ON_ONCE(mvm->cmd_ver.range_resp > 9)) {1456err = -EINVAL;1457goto out_free;1458}14591460/*1461* Populate the state variables that the transport layer needs1462* to know about.1463*/1464BUILD_BUG_ON(sizeof(no_reclaim_cmds) >1465sizeof(trans->conf.no_reclaim_cmds));1466memcpy(trans->conf.no_reclaim_cmds, no_reclaim_cmds,1467sizeof(no_reclaim_cmds));1468trans->conf.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);14691470trans->conf.rx_buf_size = iwl_amsdu_size_to_rxb_size();14711472trans->conf.wide_cmd_header = true;14731474trans->conf.command_groups = iwl_mvm_groups;1475trans->conf.command_groups_size = ARRAY_SIZE(iwl_mvm_groups);14761477trans->conf.cmd_queue = IWL_MVM_DQA_CMD_QUEUE;1478trans->conf.cmd_fifo = IWL_MVM_TX_FIFO_CMD;1479trans->conf.scd_set_active = true;14801481trans->conf.cb_data_offs = offsetof(struct ieee80211_tx_info,1482driver_data[2]);14831484snprintf(mvm->hw->wiphy->fw_version,1485sizeof(mvm->hw->wiphy->fw_version),1486"%.31s", fw->fw_version);14871488trans->conf.fw_reset_handshake =1489fw_has_capa(&mvm->fw->ucode_capa,1490IWL_UCODE_TLV_CAPA_FW_RESET_HANDSHAKE);14911492trans->conf.queue_alloc_cmd_ver =1493iwl_fw_lookup_cmd_ver(mvm->fw,1494WIDE_ID(DATA_PATH_GROUP,1495SCD_QUEUE_CONFIG_CMD),14960);1497mvm->sta_remove_requires_queue_remove =1498trans->conf.queue_alloc_cmd_ver > 0;14991500mvm->mld_api_is_used = iwl_mvm_has_mld_api(mvm->fw);15011502/* Configure transport layer */1503iwl_trans_op_mode_enter(mvm->trans, op_mode);15041505trans->dbg.dest_tlv = mvm->fw->dbg.dest_tlv;1506trans->dbg.n_dest_reg = mvm->fw->dbg.n_dest_reg;15071508/* set up notification wait support */1509iwl_notification_wait_init(&mvm->notif_wait);15101511/* Init phy db */1512mvm->phy_db = iwl_phy_db_init(trans);1513if (!mvm->phy_db) {1514IWL_ERR(mvm, "Cannot init phy_db\n");1515err = -ENOMEM;1516goto out_free;1517}15181519if (iwlwifi_mod_params.nvm_file)1520mvm->nvm_file_name = iwlwifi_mod_params.nvm_file;1521else1522IWL_DEBUG_EEPROM(mvm->trans->dev,1523"working without external nvm file\n");15241525scan_size = iwl_mvm_scan_size(mvm);15261527mvm->scan_cmd = kmalloc(scan_size, GFP_KERNEL);1528if (!mvm->scan_cmd) {1529err = -ENOMEM;1530goto out_free;1531}1532mvm->scan_cmd_size = scan_size;15331534/* invalidate ids to prevent accidental removal of sta_id 0 */1535mvm->aux_sta.sta_id = IWL_INVALID_STA;1536mvm->snif_sta.sta_id = IWL_INVALID_STA;15371538/* Set EBS as successful as long as not stated otherwise by the FW. */1539mvm->last_ebs_successful = true;15401541min_backoff = iwl_mvm_min_backoff(mvm);1542iwl_mvm_thermal_initialize(mvm, min_backoff);15431544if (!iwl_mvm_has_new_rx_stats_api(mvm))1545memset(&mvm->rx_stats_v3, 0,1546sizeof(struct mvm_statistics_rx_v3));1547else1548memset(&mvm->rx_stats, 0, sizeof(struct mvm_statistics_rx));15491550iwl_mvm_ftm_initiator_smooth_config(mvm);15511552iwl_mvm_init_time_sync(&mvm->time_sync);15531554mvm->debugfs_dir = dbgfs_dir;15551556#if IS_ENABLED(CONFIG_IWLMEI)1557mvm->mei_registered = !iwl_mei_register(mvm, &mei_ops);1558#else1559mvm->mei_registered = false;1560#endif15611562iwl_mvm_mei_scan_filter_init(&mvm->mei_scan_filter);15631564err = iwl_mvm_start_get_nvm(mvm);1565if (err) {1566/*1567* Getting NVM failed while CSME is the owner, but we are1568* registered to MEI, we'll get the NVM later when it'll be1569* possible to get it from CSME.1570*/1571if (trans->csme_own && mvm->mei_registered)1572return op_mode;15731574goto out_thermal_exit;1575}157615771578err = iwl_mvm_start_post_nvm(mvm);1579if (err)1580goto out_thermal_exit;15811582return op_mode;15831584out_thermal_exit:1585iwl_mvm_thermal_exit(mvm);1586if (mvm->mei_registered) {1587iwl_mei_start_unregister();1588iwl_mei_unregister_complete();1589}1590out_free:1591iwl_fw_flush_dumps(&mvm->fwrt);1592iwl_fw_runtime_free(&mvm->fwrt);15931594iwl_phy_db_free(mvm->phy_db);1595kfree(mvm->scan_cmd);1596iwl_trans_op_mode_leave(trans);15971598ieee80211_free_hw(mvm->hw);1599return ERR_PTR(err);1600}16011602void iwl_mvm_stop_device(struct iwl_mvm *mvm)1603{1604lockdep_assert_held(&mvm->mutex);16051606iwl_fw_cancel_timestamp(&mvm->fwrt);16071608clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);16091610iwl_mvm_pause_tcm(mvm, false);16111612iwl_fw_dbg_stop_sync(&mvm->fwrt);1613iwl_trans_stop_device(mvm->trans);1614iwl_free_fw_paging(&mvm->fwrt);1615iwl_fw_dump_conf_clear(&mvm->fwrt);1616iwl_mvm_mei_device_state(mvm, false);1617}16181619static void iwl_op_mode_mvm_stop(struct iwl_op_mode *op_mode)1620{1621struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);1622int i;16231624if (mvm->mei_registered) {1625rtnl_lock();1626iwl_mei_set_netdev(NULL);1627rtnl_unlock();1628iwl_mei_start_unregister();1629}16301631/*1632* After we unregister from mei, the worker can't be scheduled1633* anymore.1634*/1635cancel_work_sync(&mvm->sap_connected_wk);16361637iwl_mvm_leds_exit(mvm);16381639iwl_mvm_thermal_exit(mvm);16401641/*1642* If we couldn't get ownership on the device and we couldn't1643* get the NVM from CSME, we haven't registered to mac80211.1644* In that case, we didn't fail op_mode_start, because we are1645* waiting for CSME to allow us to get the NVM to register to1646* mac80211. If that didn't happen, we haven't registered to1647* mac80211, hence the if below.1648*/1649if (mvm->hw_registered)1650ieee80211_unregister_hw(mvm->hw);16511652kfree(mvm->scan_cmd);1653kfree(mvm->mcast_filter_cmd);1654mvm->mcast_filter_cmd = NULL;16551656kfree(mvm->error_recovery_buf);1657mvm->error_recovery_buf = NULL;16581659iwl_mvm_ptp_remove(mvm);16601661iwl_trans_op_mode_leave(mvm->trans);16621663iwl_phy_db_free(mvm->phy_db);1664mvm->phy_db = NULL;16651666kfree(mvm->nvm_data);1667kfree(mvm->mei_nvm_data);1668kfree(rcu_access_pointer(mvm->csme_conn_info));1669kfree(mvm->temp_nvm_data);1670for (i = 0; i < NVM_MAX_NUM_SECTIONS; i++)1671kfree(mvm->nvm_sections[i].data);1672kfree(mvm->acs_survey);16731674cancel_delayed_work_sync(&mvm->tcm.work);16751676iwl_fw_runtime_free(&mvm->fwrt);1677mutex_destroy(&mvm->mutex);16781679if (mvm->mei_registered)1680iwl_mei_unregister_complete();16811682ieee80211_free_hw(mvm->hw);1683}16841685struct iwl_async_handler_entry {1686struct list_head list;1687struct iwl_rx_cmd_buffer rxb;1688enum iwl_rx_handler_context context;1689void (*fn)(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb);1690};16911692void iwl_mvm_async_handlers_purge(struct iwl_mvm *mvm)1693{1694struct iwl_async_handler_entry *entry, *tmp;16951696spin_lock_bh(&mvm->async_handlers_lock);1697list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {1698iwl_free_rxb(&entry->rxb);1699list_del(&entry->list);1700kfree(entry);1701}1702spin_unlock_bh(&mvm->async_handlers_lock);1703}17041705/*1706* This function receives a bitmap of rx async handler contexts1707* (&iwl_rx_handler_context) to handle, and runs only them1708*/1709static void iwl_mvm_async_handlers_by_context(struct iwl_mvm *mvm,1710u8 contexts)1711{1712struct iwl_async_handler_entry *entry, *tmp;1713LIST_HEAD(local_list);17141715/*1716* Sync with Rx path with a lock. Remove all the entries of the1717* wanted contexts from this list, add them to a local one (lock free),1718* and then handle them.1719*/1720spin_lock_bh(&mvm->async_handlers_lock);1721list_for_each_entry_safe(entry, tmp, &mvm->async_handlers_list, list) {1722if (!(BIT(entry->context) & contexts))1723continue;1724list_del(&entry->list);1725list_add_tail(&entry->list, &local_list);1726}1727spin_unlock_bh(&mvm->async_handlers_lock);17281729list_for_each_entry_safe(entry, tmp, &local_list, list) {1730if (entry->context != RX_HANDLER_ASYNC_UNLOCKED)1731mutex_lock(&mvm->mutex);1732entry->fn(mvm, &entry->rxb);1733iwl_free_rxb(&entry->rxb);1734list_del(&entry->list);1735if (entry->context != RX_HANDLER_ASYNC_UNLOCKED)1736mutex_unlock(&mvm->mutex);1737kfree(entry);1738}1739}17401741static void iwl_mvm_async_handlers_wiphy_wk(struct wiphy *wiphy,1742struct wiphy_work *wk)1743{1744struct iwl_mvm *mvm =1745container_of(wk, struct iwl_mvm, async_handlers_wiphy_wk);1746u8 contexts = BIT(RX_HANDLER_ASYNC_LOCKED_WIPHY);17471748iwl_mvm_async_handlers_by_context(mvm, contexts);1749}17501751static void iwl_mvm_async_handlers_wk(struct work_struct *wk)1752{1753struct iwl_mvm *mvm =1754container_of(wk, struct iwl_mvm, async_handlers_wk);1755u8 contexts = BIT(RX_HANDLER_ASYNC_LOCKED) |1756BIT(RX_HANDLER_ASYNC_UNLOCKED);17571758iwl_mvm_async_handlers_by_context(mvm, contexts);1759}17601761static inline void iwl_mvm_rx_check_trigger(struct iwl_mvm *mvm,1762struct iwl_rx_packet *pkt)1763{1764struct iwl_fw_dbg_trigger_tlv *trig;1765struct iwl_fw_dbg_trigger_cmd *cmds_trig;1766int i;17671768trig = iwl_fw_dbg_trigger_on(&mvm->fwrt, NULL,1769FW_DBG_TRIGGER_FW_NOTIF);1770if (!trig)1771return;17721773cmds_trig = (void *)trig->data;17741775for (i = 0; i < ARRAY_SIZE(cmds_trig->cmds); i++) {1776/* don't collect on CMD 0 */1777if (!cmds_trig->cmds[i].cmd_id)1778break;17791780if (cmds_trig->cmds[i].cmd_id != pkt->hdr.cmd ||1781cmds_trig->cmds[i].group_id != pkt->hdr.group_id)1782continue;17831784iwl_fw_dbg_collect_trig(&mvm->fwrt, trig,1785"CMD 0x%02x.%02x received",1786pkt->hdr.group_id, pkt->hdr.cmd);1787break;1788}1789}17901791static void iwl_mvm_rx_common(struct iwl_mvm *mvm,1792struct iwl_rx_cmd_buffer *rxb,1793struct iwl_rx_packet *pkt)1794{1795unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);1796int i;1797union iwl_dbg_tlv_tp_data tp_data = { .fw_pkt = pkt };17981799iwl_dbg_tlv_time_point(&mvm->fwrt,1800IWL_FW_INI_TIME_POINT_FW_RSP_OR_NOTIF, &tp_data);1801iwl_mvm_rx_check_trigger(mvm, pkt);18021803/*1804* Do the notification wait before RX handlers so1805* even if the RX handler consumes the RXB we have1806* access to it in the notification wait entry.1807*/1808iwl_notification_wait_notify(&mvm->notif_wait, pkt);18091810for (i = 0; i < ARRAY_SIZE(iwl_mvm_rx_handlers); i++) {1811const struct iwl_rx_handlers *rx_h = &iwl_mvm_rx_handlers[i];1812struct iwl_async_handler_entry *entry;18131814if (rx_h->cmd_id != WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd))1815continue;18161817if (IWL_FW_CHECK(mvm, pkt_len < rx_h->min_size,1818"unexpected notification 0x%04x size %d, need %d\n",1819rx_h->cmd_id, pkt_len, rx_h->min_size))1820return;18211822if (rx_h->context == RX_HANDLER_SYNC) {1823rx_h->fn(mvm, rxb);1824return;1825}18261827entry = kzalloc(sizeof(*entry), GFP_ATOMIC);1828/* we can't do much... */1829if (!entry)1830return;18311832entry->rxb._page = rxb_steal_page(rxb);1833entry->rxb._offset = rxb->_offset;1834entry->rxb._rx_page_order = rxb->_rx_page_order;1835entry->fn = rx_h->fn;1836entry->context = rx_h->context;1837spin_lock(&mvm->async_handlers_lock);1838list_add_tail(&entry->list, &mvm->async_handlers_list);1839spin_unlock(&mvm->async_handlers_lock);1840if (rx_h->context == RX_HANDLER_ASYNC_LOCKED_WIPHY)1841wiphy_work_queue(mvm->hw->wiphy,1842&mvm->async_handlers_wiphy_wk);1843else1844schedule_work(&mvm->async_handlers_wk);1845break;1846}1847}18481849static void iwl_mvm_rx(struct iwl_op_mode *op_mode,1850struct napi_struct *napi,1851struct iwl_rx_cmd_buffer *rxb)1852{1853struct iwl_rx_packet *pkt = rxb_addr(rxb);1854struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);1855u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);18561857if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))1858iwl_mvm_rx_rx_mpdu(mvm, napi, rxb);1859else if (cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_PHY_CMD))1860iwl_mvm_rx_rx_phy_cmd(mvm, rxb);1861else1862iwl_mvm_rx_common(mvm, rxb, pkt);1863}18641865void iwl_mvm_rx_mq(struct iwl_op_mode *op_mode,1866struct napi_struct *napi,1867struct iwl_rx_cmd_buffer *rxb)1868{1869struct iwl_rx_packet *pkt = rxb_addr(rxb);1870struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);1871u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);18721873if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))1874iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, 0);1875else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP,1876RX_QUEUES_NOTIFICATION)))1877iwl_mvm_rx_queue_notif(mvm, napi, rxb, 0);1878else if (cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE))1879iwl_mvm_rx_frame_release(mvm, napi, rxb, 0);1880else if (cmd == WIDE_ID(LEGACY_GROUP, BAR_FRAME_RELEASE))1881iwl_mvm_rx_bar_frame_release(mvm, napi, rxb, 0);1882else if (cmd == WIDE_ID(DATA_PATH_GROUP, RX_NO_DATA_NOTIF))1883iwl_mvm_rx_monitor_no_data(mvm, napi, rxb, 0);1884else1885iwl_mvm_rx_common(mvm, rxb, pkt);1886}18871888static int iwl_mvm_is_static_queue(struct iwl_mvm *mvm, int queue)1889{1890return queue == mvm->aux_queue || queue == mvm->probe_queue ||1891queue == mvm->p2p_dev_queue || queue == mvm->snif_queue;1892}18931894static void iwl_mvm_queue_state_change(struct iwl_op_mode *op_mode,1895int hw_queue, bool start)1896{1897struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);1898struct ieee80211_sta *sta;1899struct ieee80211_txq *txq;1900struct iwl_mvm_txq *mvmtxq;1901int i;1902unsigned long tid_bitmap;1903struct iwl_mvm_sta *mvmsta;1904u8 sta_id;19051906sta_id = iwl_mvm_has_new_tx_api(mvm) ?1907mvm->tvqm_info[hw_queue].sta_id :1908mvm->queue_info[hw_queue].ra_sta_id;19091910if (WARN_ON_ONCE(sta_id >= mvm->fw->ucode_capa.num_stations))1911return;19121913rcu_read_lock();19141915sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]);1916if (IS_ERR_OR_NULL(sta))1917goto out;1918mvmsta = iwl_mvm_sta_from_mac80211(sta);19191920if (iwl_mvm_is_static_queue(mvm, hw_queue)) {1921if (!start)1922ieee80211_stop_queues(mvm->hw);1923else if (mvmsta->sta_state != IEEE80211_STA_NOTEXIST)1924ieee80211_wake_queues(mvm->hw);19251926goto out;1927}19281929if (iwl_mvm_has_new_tx_api(mvm)) {1930int tid = mvm->tvqm_info[hw_queue].txq_tid;19311932tid_bitmap = BIT(tid);1933} else {1934tid_bitmap = mvm->queue_info[hw_queue].tid_bitmap;1935}19361937for_each_set_bit(i, &tid_bitmap, IWL_MAX_TID_COUNT + 1) {1938int tid = i;19391940if (tid == IWL_MAX_TID_COUNT)1941tid = IEEE80211_NUM_TIDS;19421943txq = sta->txq[tid];1944mvmtxq = iwl_mvm_txq_from_mac80211(txq);1945if (start)1946clear_bit(IWL_MVM_TXQ_STATE_STOP_FULL, &mvmtxq->state);1947else1948set_bit(IWL_MVM_TXQ_STATE_STOP_FULL, &mvmtxq->state);19491950if (start && mvmsta->sta_state != IEEE80211_STA_NOTEXIST) {1951local_bh_disable();1952iwl_mvm_mac_itxq_xmit(mvm->hw, txq);1953local_bh_enable();1954}1955}19561957out:1958rcu_read_unlock();1959}19601961static void iwl_mvm_stop_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)1962{1963iwl_mvm_queue_state_change(op_mode, hw_queue, false);1964}19651966static void iwl_mvm_wake_sw_queue(struct iwl_op_mode *op_mode, int hw_queue)1967{1968iwl_mvm_queue_state_change(op_mode, hw_queue, true);1969}19701971static void iwl_mvm_set_rfkill_state(struct iwl_mvm *mvm)1972{1973wiphy_rfkill_set_hw_state(mvm->hw->wiphy,1974iwl_mvm_is_radio_killed(mvm));1975}19761977void iwl_mvm_set_hw_ctkill_state(struct iwl_mvm *mvm, bool state)1978{1979if (state)1980set_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);1981else1982clear_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status);19831984iwl_mvm_set_rfkill_state(mvm);1985}19861987struct iwl_mvm_csme_conn_info *iwl_mvm_get_csme_conn_info(struct iwl_mvm *mvm)1988{1989return rcu_dereference_protected(mvm->csme_conn_info,1990lockdep_is_held(&mvm->mutex));1991}19921993static bool iwl_mvm_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)1994{1995struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);1996bool rfkill_safe_init_done = READ_ONCE(mvm->rfkill_safe_init_done);1997bool unified = iwl_mvm_has_unified_ucode(mvm);19981999if (state)2000set_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);2001else2002clear_bit(IWL_MVM_STATUS_HW_RFKILL, &mvm->status);20032004iwl_mvm_set_rfkill_state(mvm);20052006/* iwl_run_init_mvm_ucode is waiting for results, abort it. */2007if (rfkill_safe_init_done)2008iwl_abort_notification_waits(&mvm->notif_wait);20092010/*2011* Don't ask the transport to stop the firmware. We'll do it2012* after cfg80211 takes us down.2013*/2014if (unified)2015return false;20162017/*2018* Stop the device if we run OPERATIONAL firmware or if we are in the2019* middle of the calibrations.2020*/2021return state && rfkill_safe_init_done;2022}20232024static void iwl_mvm_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)2025{2026struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);2027struct ieee80211_tx_info *info;20282029info = IEEE80211_SKB_CB(skb);2030iwl_trans_free_tx_cmd(mvm->trans, info->driver_data[1]);2031ieee80211_free_txskb(mvm->hw, skb);2032}20332034static void iwl_mvm_nic_error(struct iwl_op_mode *op_mode,2035enum iwl_fw_error_type type)2036{2037struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);20382039iwl_abort_notification_waits(&mvm->notif_wait);2040iwl_dbg_tlv_del_timers(mvm->trans);20412042if (type == IWL_ERR_TYPE_CMD_QUEUE_FULL)2043IWL_ERR(mvm, "Command queue full!\n");2044else if (!iwl_trans_is_dead(mvm->trans) &&2045!test_and_clear_bit(IWL_MVM_STATUS_SUPPRESS_ERROR_LOG_ONCE,2046&mvm->status))2047iwl_mvm_dump_nic_error_log(mvm);20482049/*2050* This should be first thing before trying to collect any2051* data to avoid endless loops if any HW error happens while2052* collecting debug data.2053* It might not actually be true that we'll restart, but the2054* setting of the bit doesn't matter if we're going to be2055* unbound either.2056*/2057if (type != IWL_ERR_TYPE_RESET_HS_TIMEOUT)2058set_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status);2059}20602061static void iwl_mvm_dump_error(struct iwl_op_mode *op_mode,2062struct iwl_fw_error_dump_mode *mode)2063{2064struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);20652066/* if we come in from opmode we have the mutex held */2067if (mode->context == IWL_ERR_CONTEXT_FROM_OPMODE) {2068lockdep_assert_held(&mvm->mutex);2069iwl_fw_error_collect(&mvm->fwrt);2070} else {2071mutex_lock(&mvm->mutex);2072if (mode->context != IWL_ERR_CONTEXT_ABORT)2073iwl_fw_error_collect(&mvm->fwrt);2074mutex_unlock(&mvm->mutex);2075}2076}20772078static bool iwl_mvm_sw_reset(struct iwl_op_mode *op_mode,2079enum iwl_fw_error_type type)2080{2081struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);20822083/*2084* If the firmware crashes while we're already considering it2085* to be dead then don't ask for a restart, that cannot do2086* anything useful anyway.2087*/2088if (!test_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status))2089return false;20902091/*2092* This is a bit racy, but worst case we tell mac80211 about2093* a stopped/aborted scan when that was already done which2094* is not a problem. It is necessary to abort any os scan2095* here because mac80211 requires having the scan cleared2096* before restarting.2097* We'll reset the scan_status to NONE in restart cleanup in2098* the next start() call from mac80211. If restart isn't called2099* (no fw restart) scan status will stay busy.2100*/2101iwl_mvm_report_scan_aborted(mvm);21022103/*2104* If INIT fw asserted, it will likely fail again.2105* If WoWLAN fw asserted, don't restart either, mac802112106* can't recover this since we're already half suspended.2107*/2108if (mvm->fwrt.cur_fw_img == IWL_UCODE_REGULAR && mvm->hw_registered) {2109if (mvm->fw->ucode_capa.error_log_size) {2110u32 src_size = mvm->fw->ucode_capa.error_log_size;2111u32 src_addr = mvm->fw->ucode_capa.error_log_addr;2112u8 *recover_buf = kzalloc(src_size, GFP_ATOMIC);21132114if (recover_buf) {2115mvm->error_recovery_buf = recover_buf;2116iwl_trans_read_mem_bytes(mvm->trans,2117src_addr,2118recover_buf,2119src_size);2120}2121}21222123if (mvm->fwrt.trans->dbg.restart_required) {2124IWL_DEBUG_INFO(mvm, "FW restart requested after debug collection\n");2125mvm->fwrt.trans->dbg.restart_required = false;2126ieee80211_restart_hw(mvm->hw);2127return true;2128} else if (mvm->trans->mac_cfg->device_family <= IWL_DEVICE_FAMILY_8000) {2129ieee80211_restart_hw(mvm->hw);2130return true;2131}2132}21332134return false;2135}21362137static void iwl_op_mode_mvm_time_point(struct iwl_op_mode *op_mode,2138enum iwl_fw_ini_time_point tp_id,2139union iwl_dbg_tlv_tp_data *tp_data)2140{2141struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);21422143iwl_dbg_tlv_time_point(&mvm->fwrt, tp_id, tp_data);2144}21452146static void iwl_mvm_dump(struct iwl_op_mode *op_mode)2147{2148struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);2149struct iwl_fw_runtime *fwrt = &mvm->fwrt;21502151if (!iwl_trans_fw_running(fwrt->trans))2152return;21532154iwl_dbg_tlv_time_point(fwrt, IWL_FW_INI_TIME_POINT_USER_TRIGGER, NULL);2155}21562157#ifdef CONFIG_PM_SLEEP2158static void iwl_op_mode_mvm_device_powered_off(struct iwl_op_mode *op_mode)2159{2160struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);21612162mutex_lock(&mvm->mutex);2163clear_bit(IWL_MVM_STATUS_IN_D3, &mvm->status);2164iwl_mvm_stop_device(mvm);2165mvm->fast_resume = false;2166mutex_unlock(&mvm->mutex);2167}2168#else2169static void iwl_op_mode_mvm_device_powered_off(struct iwl_op_mode *op_mode)2170{}2171#endif21722173#define IWL_MVM_COMMON_OPS \2174/* these could be differentiated */ \2175.queue_full = iwl_mvm_stop_sw_queue, \2176.queue_not_full = iwl_mvm_wake_sw_queue, \2177.hw_rf_kill = iwl_mvm_set_hw_rfkill_state, \2178.free_skb = iwl_mvm_free_skb, \2179.nic_error = iwl_mvm_nic_error, \2180.dump_error = iwl_mvm_dump_error, \2181.sw_reset = iwl_mvm_sw_reset, \2182.nic_config = iwl_mvm_nic_config, \2183/* as we only register one, these MUST be common! */ \2184.start = iwl_op_mode_mvm_start, \2185.stop = iwl_op_mode_mvm_stop, \2186.time_point = iwl_op_mode_mvm_time_point, \2187.device_powered_off = iwl_op_mode_mvm_device_powered_off21882189static const struct iwl_op_mode_ops iwl_mvm_ops = {2190IWL_MVM_COMMON_OPS,2191.rx = iwl_mvm_rx,2192};21932194static void iwl_mvm_rx_mq_rss(struct iwl_op_mode *op_mode,2195struct napi_struct *napi,2196struct iwl_rx_cmd_buffer *rxb,2197unsigned int queue)2198{2199struct iwl_mvm *mvm = IWL_OP_MODE_GET_MVM(op_mode);2200struct iwl_rx_packet *pkt = rxb_addr(rxb);2201u16 cmd = WIDE_ID(pkt->hdr.group_id, pkt->hdr.cmd);22022203if (unlikely(queue >= mvm->trans->info.num_rxqs))2204return;22052206if (unlikely(cmd == WIDE_ID(LEGACY_GROUP, FRAME_RELEASE)))2207iwl_mvm_rx_frame_release(mvm, napi, rxb, queue);2208else if (unlikely(cmd == WIDE_ID(DATA_PATH_GROUP,2209RX_QUEUES_NOTIFICATION)))2210iwl_mvm_rx_queue_notif(mvm, napi, rxb, queue);2211else if (likely(cmd == WIDE_ID(LEGACY_GROUP, REPLY_RX_MPDU_CMD)))2212iwl_mvm_rx_mpdu_mq(mvm, napi, rxb, queue);2213}22142215static const struct iwl_op_mode_ops iwl_mvm_ops_mq = {2216IWL_MVM_COMMON_OPS,2217.rx = iwl_mvm_rx_mq,2218.rx_rss = iwl_mvm_rx_mq_rss,2219.dump = iwl_mvm_dump,2220};222122222223