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