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