1 /****************************************************************************** 2 * 3 * This file is provided under a dual BSD/GPLv2 license. When using or 4 * redistributing this file, you may do so under either license. 5 * 6 * GPL LICENSE SUMMARY 7 * 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 11 * Copyright(c) 2018 Intel Corporation 12 * 13 * This program is free software; you can redistribute it and/or modify 14 * it under the terms of version 2 of the GNU General Public License as 15 * published by the Free Software Foundation. 16 * 17 * This program is distributed in the hope that it will be useful, but 18 * WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 20 * General Public License for more details. 21 * 22 * The full GNU General Public License is included in this distribution 23 * in the file called COPYING. 24 * 25 * Contact Information: 26 * Intel Linux Wireless <linuxwifi@intel.com> 27 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 28 * 29 * BSD LICENSE 30 * 31 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. 32 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 33 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH 34 * Copyright(c) 2018 Intel Corporation 35 * All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 41 * * Redistributions of source code must retain the above copyright 42 * notice, this list of conditions and the following disclaimer. 43 * * Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in 45 * the documentation and/or other materials provided with the 46 * distribution. 47 * * Neither the name Intel Corporation nor the names of its 48 * contributors may be used to endorse or promote products derived 49 * from this software without specific prior written permission. 50 * 51 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 52 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 53 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 54 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 55 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 56 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 57 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 58 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 59 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 60 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 61 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 62 * 63 *****************************************************************************/ 64 #include <net/mac80211.h> 65 #include <linux/netdevice.h> 66 67 #include "iwl-trans.h" 68 #include "iwl-op-mode.h" 69 #include "fw/img.h" 70 #include "iwl-debug.h" 71 #include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */ 72 #include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */ 73 #include "iwl-prph.h" 74 #include "fw/acpi.h" 75 76 #include "mvm.h" 77 #include "fw/dbg.h" 78 #include "iwl-phy-db.h" 79 #include "iwl-modparams.h" 80 #include "iwl-nvm-parse.h" 81 82 #define MVM_UCODE_ALIVE_TIMEOUT HZ 83 #define MVM_UCODE_CALIB_TIMEOUT (2*HZ) 84 85 #define UCODE_VALID_OK cpu_to_le32(0x1) 86 87 struct iwl_mvm_alive_data { 88 bool valid; 89 u32 scd_base_addr; 90 }; 91 92 static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant) 93 { 94 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = { 95 .valid = cpu_to_le32(valid_tx_ant), 96 }; 97 98 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant); 99 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0, 100 sizeof(tx_ant_cmd), &tx_ant_cmd); 101 } 102 103 static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm) 104 { 105 int i; 106 struct iwl_rss_config_cmd cmd = { 107 .flags = cpu_to_le32(IWL_RSS_ENABLE), 108 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP | 109 IWL_RSS_HASH_TYPE_IPV4_UDP | 110 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD | 111 IWL_RSS_HASH_TYPE_IPV6_TCP | 112 IWL_RSS_HASH_TYPE_IPV6_UDP | 113 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD, 114 }; 115 116 if (mvm->trans->num_rx_queues == 1) 117 return 0; 118 119 /* Do not direct RSS traffic to Q 0 which is our fallback queue */ 120 for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++) 121 cmd.indirection_table[i] = 122 1 + (i % (mvm->trans->num_rx_queues - 1)); 123 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key)); 124 125 return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd); 126 } 127 128 static int iwl_configure_rxq(struct iwl_mvm *mvm) 129 { 130 int i, num_queues, size; 131 struct iwl_rfh_queue_config *cmd; 132 133 /* Do not configure default queue, it is configured via context info */ 134 num_queues = mvm->trans->num_rx_queues - 1; 135 136 size = sizeof(*cmd) + num_queues * sizeof(struct iwl_rfh_queue_data); 137 138 cmd = kzalloc(size, GFP_KERNEL); 139 if (!cmd) 140 return -ENOMEM; 141 142 cmd->num_queues = num_queues; 143 144 for (i = 0; i < num_queues; i++) { 145 struct iwl_trans_rxq_dma_data data; 146 147 cmd->data[i].q_num = i + 1; 148 iwl_trans_get_rxq_dma_data(mvm->trans, i + 1, &data); 149 150 cmd->data[i].fr_bd_cb = cpu_to_le64(data.fr_bd_cb); 151 cmd->data[i].urbd_stts_wrptr = 152 cpu_to_le64(data.urbd_stts_wrptr); 153 cmd->data[i].ur_bd_cb = cpu_to_le64(data.ur_bd_cb); 154 cmd->data[i].fr_bd_wid = cpu_to_le32(data.fr_bd_wid); 155 } 156 157 return iwl_mvm_send_cmd_pdu(mvm, 158 WIDE_ID(DATA_PATH_GROUP, 159 RFH_QUEUE_CONFIG_CMD), 160 0, size, cmd); 161 } 162 163 static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm) 164 { 165 struct iwl_dqa_enable_cmd dqa_cmd = { 166 .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE), 167 }; 168 u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0); 169 int ret; 170 171 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd); 172 if (ret) 173 IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret); 174 else 175 IWL_DEBUG_FW(mvm, "Working in DQA mode\n"); 176 177 return ret; 178 } 179 180 void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm, 181 struct iwl_rx_cmd_buffer *rxb) 182 { 183 struct iwl_rx_packet *pkt = rxb_addr(rxb); 184 struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data; 185 __le32 *dump_data = mfu_dump_notif->data; 186 int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32); 187 int i; 188 189 if (mfu_dump_notif->index_num == 0) 190 IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n", 191 le32_to_cpu(mfu_dump_notif->assert_id)); 192 193 for (i = 0; i < n_words; i++) 194 IWL_DEBUG_INFO(mvm, 195 "MFUART assert dump, dword %u: 0x%08x\n", 196 le16_to_cpu(mfu_dump_notif->index_num) * 197 n_words + i, 198 le32_to_cpu(dump_data[i])); 199 } 200 201 static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait, 202 struct iwl_rx_packet *pkt, void *data) 203 { 204 struct iwl_mvm *mvm = 205 container_of(notif_wait, struct iwl_mvm, notif_wait); 206 struct iwl_mvm_alive_data *alive_data = data; 207 struct mvm_alive_resp_v3 *palive3; 208 struct mvm_alive_resp *palive; 209 struct iwl_umac_alive *umac; 210 struct iwl_lmac_alive *lmac1; 211 struct iwl_lmac_alive *lmac2 = NULL; 212 u16 status; 213 u32 umac_error_event_table; 214 215 if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) { 216 palive = (void *)pkt->data; 217 umac = &palive->umac_data; 218 lmac1 = &palive->lmac_data[0]; 219 lmac2 = &palive->lmac_data[1]; 220 status = le16_to_cpu(palive->status); 221 } else { 222 palive3 = (void *)pkt->data; 223 umac = &palive3->umac_data; 224 lmac1 = &palive3->lmac_data; 225 status = le16_to_cpu(palive3->status); 226 } 227 228 mvm->error_event_table[0] = le32_to_cpu(lmac1->error_event_table_ptr); 229 if (lmac2) 230 mvm->error_event_table[1] = 231 le32_to_cpu(lmac2->error_event_table_ptr); 232 mvm->log_event_table = le32_to_cpu(lmac1->log_event_table_ptr); 233 234 umac_error_event_table = le32_to_cpu(umac->error_info_addr); 235 236 if (!umac_error_event_table) { 237 mvm->support_umac_log = false; 238 } else if (umac_error_event_table >= 239 mvm->trans->cfg->min_umac_error_event_table) { 240 mvm->support_umac_log = true; 241 mvm->umac_error_event_table = umac_error_event_table; 242 } else { 243 IWL_ERR(mvm, 244 "Not valid error log pointer 0x%08X for %s uCode\n", 245 mvm->umac_error_event_table, 246 (mvm->fwrt.cur_fw_img == IWL_UCODE_INIT) ? 247 "Init" : "RT"); 248 mvm->support_umac_log = false; 249 } 250 251 alive_data->scd_base_addr = le32_to_cpu(lmac1->scd_base_ptr); 252 alive_data->valid = status == IWL_ALIVE_STATUS_OK; 253 254 IWL_DEBUG_FW(mvm, 255 "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n", 256 status, lmac1->ver_type, lmac1->ver_subtype); 257 258 if (lmac2) 259 IWL_DEBUG_FW(mvm, "Alive ucode CDB\n"); 260 261 IWL_DEBUG_FW(mvm, 262 "UMAC version: Major - 0x%x, Minor - 0x%x\n", 263 le32_to_cpu(umac->umac_major), 264 le32_to_cpu(umac->umac_minor)); 265 266 return true; 267 } 268 269 static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait, 270 struct iwl_rx_packet *pkt, void *data) 271 { 272 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF); 273 274 return true; 275 } 276 277 static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait, 278 struct iwl_rx_packet *pkt, void *data) 279 { 280 struct iwl_phy_db *phy_db = data; 281 282 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) { 283 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF); 284 return true; 285 } 286 287 WARN_ON(iwl_phy_db_set_section(phy_db, pkt)); 288 289 return false; 290 } 291 292 static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm, 293 enum iwl_ucode_type ucode_type) 294 { 295 struct iwl_notification_wait alive_wait; 296 struct iwl_mvm_alive_data alive_data; 297 const struct fw_img *fw; 298 int ret, i; 299 enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img; 300 static const u16 alive_cmd[] = { MVM_ALIVE }; 301 302 set_bit(IWL_FWRT_STATUS_WAIT_ALIVE, &mvm->fwrt.status); 303 if (ucode_type == IWL_UCODE_REGULAR && 304 iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) && 305 !(fw_has_capa(&mvm->fw->ucode_capa, 306 IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED))) 307 fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER); 308 else 309 fw = iwl_get_ucode_image(mvm->fw, ucode_type); 310 if (WARN_ON(!fw)) 311 return -EINVAL; 312 iwl_fw_set_current_image(&mvm->fwrt, ucode_type); 313 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); 314 315 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait, 316 alive_cmd, ARRAY_SIZE(alive_cmd), 317 iwl_alive_fn, &alive_data); 318 319 ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT); 320 if (ret) { 321 iwl_fw_set_current_image(&mvm->fwrt, old_type); 322 iwl_remove_notification(&mvm->notif_wait, &alive_wait); 323 return ret; 324 } 325 326 /* 327 * Some things may run in the background now, but we 328 * just wait for the ALIVE notification here. 329 */ 330 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait, 331 MVM_UCODE_ALIVE_TIMEOUT); 332 if (ret) { 333 struct iwl_trans *trans = mvm->trans; 334 335 if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000) 336 IWL_ERR(mvm, 337 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n", 338 iwl_read_prph(trans, UMAG_SB_CPU_1_STATUS), 339 iwl_read_prph(trans, UMAG_SB_CPU_2_STATUS)); 340 else if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000) 341 IWL_ERR(mvm, 342 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n", 343 iwl_read_prph(trans, SB_CPU_1_STATUS), 344 iwl_read_prph(trans, SB_CPU_2_STATUS)); 345 iwl_fw_set_current_image(&mvm->fwrt, old_type); 346 return ret; 347 } 348 349 if (!alive_data.valid) { 350 IWL_ERR(mvm, "Loaded ucode is not valid!\n"); 351 iwl_fw_set_current_image(&mvm->fwrt, old_type); 352 return -EIO; 353 } 354 355 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr); 356 357 /* 358 * Note: all the queues are enabled as part of the interface 359 * initialization, but in firmware restart scenarios they 360 * could be stopped, so wake them up. In firmware restart, 361 * mac80211 will have the queues stopped as well until the 362 * reconfiguration completes. During normal startup, they 363 * will be empty. 364 */ 365 366 memset(&mvm->queue_info, 0, sizeof(mvm->queue_info)); 367 mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1; 368 369 for (i = 0; i < IEEE80211_MAX_QUEUES; i++) 370 atomic_set(&mvm->mac80211_queue_stop_count[i], 0); 371 372 set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status); 373 clear_bit(IWL_FWRT_STATUS_WAIT_ALIVE, &mvm->fwrt.status); 374 375 return 0; 376 } 377 378 static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm) 379 { 380 struct iwl_notification_wait init_wait; 381 struct iwl_nvm_access_complete_cmd nvm_complete = {}; 382 struct iwl_init_extended_cfg_cmd init_cfg = { 383 .init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)), 384 }; 385 static const u16 init_complete[] = { 386 INIT_COMPLETE_NOTIF, 387 }; 388 int ret; 389 390 lockdep_assert_held(&mvm->mutex); 391 392 iwl_init_notification_wait(&mvm->notif_wait, 393 &init_wait, 394 init_complete, 395 ARRAY_SIZE(init_complete), 396 iwl_wait_init_complete, 397 NULL); 398 399 /* Will also start the device */ 400 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR); 401 if (ret) { 402 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret); 403 goto error; 404 } 405 406 /* Send init config command to mark that we are sending NVM access 407 * commands 408 */ 409 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP, 410 INIT_EXTENDED_CFG_CMD), 0, 411 sizeof(init_cfg), &init_cfg); 412 if (ret) { 413 IWL_ERR(mvm, "Failed to run init config command: %d\n", 414 ret); 415 goto error; 416 } 417 418 /* Load NVM to NIC if needed */ 419 if (mvm->nvm_file_name) { 420 iwl_read_external_nvm(mvm->trans, mvm->nvm_file_name, 421 mvm->nvm_sections); 422 iwl_mvm_load_nvm_to_nic(mvm); 423 } 424 425 if (IWL_MVM_PARSE_NVM && read_nvm) { 426 ret = iwl_nvm_init(mvm); 427 if (ret) { 428 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret); 429 goto error; 430 } 431 } 432 433 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP, 434 NVM_ACCESS_COMPLETE), 0, 435 sizeof(nvm_complete), &nvm_complete); 436 if (ret) { 437 IWL_ERR(mvm, "Failed to run complete NVM access: %d\n", 438 ret); 439 goto error; 440 } 441 442 /* We wait for the INIT complete notification */ 443 ret = iwl_wait_notification(&mvm->notif_wait, &init_wait, 444 MVM_UCODE_ALIVE_TIMEOUT); 445 if (ret) 446 return ret; 447 448 /* Read the NVM only at driver load time, no need to do this twice */ 449 if (!IWL_MVM_PARSE_NVM && read_nvm) { 450 mvm->nvm_data = iwl_get_nvm(mvm->trans, mvm->fw); 451 if (IS_ERR(mvm->nvm_data)) { 452 ret = PTR_ERR(mvm->nvm_data); 453 mvm->nvm_data = NULL; 454 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret); 455 return ret; 456 } 457 } 458 459 return 0; 460 461 error: 462 iwl_remove_notification(&mvm->notif_wait, &init_wait); 463 return ret; 464 } 465 466 static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm) 467 { 468 struct iwl_phy_cfg_cmd phy_cfg_cmd; 469 enum iwl_ucode_type ucode_type = mvm->fwrt.cur_fw_img; 470 471 /* Set parameters */ 472 phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm)); 473 474 /* set flags extra PHY configuration flags from the device's cfg */ 475 phy_cfg_cmd.phy_cfg |= cpu_to_le32(mvm->cfg->extra_phy_cfg_flags); 476 477 phy_cfg_cmd.calib_control.event_trigger = 478 mvm->fw->default_calib[ucode_type].event_trigger; 479 phy_cfg_cmd.calib_control.flow_trigger = 480 mvm->fw->default_calib[ucode_type].flow_trigger; 481 482 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n", 483 phy_cfg_cmd.phy_cfg); 484 485 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0, 486 sizeof(phy_cfg_cmd), &phy_cfg_cmd); 487 } 488 489 int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm) 490 { 491 struct iwl_notification_wait calib_wait; 492 static const u16 init_complete[] = { 493 INIT_COMPLETE_NOTIF, 494 CALIB_RES_NOTIF_PHY_DB 495 }; 496 int ret; 497 498 if (iwl_mvm_has_unified_ucode(mvm)) 499 return iwl_run_unified_mvm_ucode(mvm, true); 500 501 lockdep_assert_held(&mvm->mutex); 502 503 if (WARN_ON_ONCE(mvm->calibrating)) 504 return 0; 505 506 iwl_init_notification_wait(&mvm->notif_wait, 507 &calib_wait, 508 init_complete, 509 ARRAY_SIZE(init_complete), 510 iwl_wait_phy_db_entry, 511 mvm->phy_db); 512 513 /* Will also start the device */ 514 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT); 515 if (ret) { 516 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret); 517 goto remove_notif; 518 } 519 520 if (mvm->cfg->device_family < IWL_DEVICE_FAMILY_8000) { 521 ret = iwl_mvm_send_bt_init_conf(mvm); 522 if (ret) 523 goto remove_notif; 524 } 525 526 /* Read the NVM only at driver load time, no need to do this twice */ 527 if (read_nvm) { 528 ret = iwl_nvm_init(mvm); 529 if (ret) { 530 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret); 531 goto remove_notif; 532 } 533 } 534 535 /* In case we read the NVM from external file, load it to the NIC */ 536 if (mvm->nvm_file_name) 537 iwl_mvm_load_nvm_to_nic(mvm); 538 539 WARN_ON(iwl_nvm_check_version(mvm->nvm_data, mvm->trans)); 540 541 /* 542 * abort after reading the nvm in case RF Kill is on, we will complete 543 * the init seq later when RF kill will switch to off 544 */ 545 if (iwl_mvm_is_radio_hw_killed(mvm)) { 546 IWL_DEBUG_RF_KILL(mvm, 547 "jump over all phy activities due to RF kill\n"); 548 goto remove_notif; 549 } 550 551 mvm->calibrating = true; 552 553 /* Send TX valid antennas before triggering calibrations */ 554 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm)); 555 if (ret) 556 goto remove_notif; 557 558 ret = iwl_send_phy_cfg_cmd(mvm); 559 if (ret) { 560 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n", 561 ret); 562 goto remove_notif; 563 } 564 565 /* 566 * Some things may run in the background now, but we 567 * just wait for the calibration complete notification. 568 */ 569 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait, 570 MVM_UCODE_CALIB_TIMEOUT); 571 if (!ret) 572 goto out; 573 574 if (iwl_mvm_is_radio_hw_killed(mvm)) { 575 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n"); 576 ret = 0; 577 } else { 578 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n", 579 ret); 580 } 581 582 goto out; 583 584 remove_notif: 585 iwl_remove_notification(&mvm->notif_wait, &calib_wait); 586 out: 587 mvm->calibrating = false; 588 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) { 589 /* we want to debug INIT and we have no NVM - fake */ 590 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) + 591 sizeof(struct ieee80211_channel) + 592 sizeof(struct ieee80211_rate), 593 GFP_KERNEL); 594 if (!mvm->nvm_data) 595 return -ENOMEM; 596 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels; 597 mvm->nvm_data->bands[0].n_channels = 1; 598 mvm->nvm_data->bands[0].n_bitrates = 1; 599 mvm->nvm_data->bands[0].bitrates = 600 (void *)mvm->nvm_data->channels + 1; 601 mvm->nvm_data->bands[0].bitrates->hw_value = 10; 602 } 603 604 return ret; 605 } 606 607 static int iwl_mvm_config_ltr(struct iwl_mvm *mvm) 608 { 609 struct iwl_ltr_config_cmd cmd = { 610 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE), 611 }; 612 613 if (!mvm->trans->ltr_enabled) 614 return 0; 615 616 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0, 617 sizeof(cmd), &cmd); 618 } 619 620 #ifdef CONFIG_ACPI 621 static int iwl_mvm_sar_set_profile(struct iwl_mvm *mvm, 622 union acpi_object *table, 623 struct iwl_mvm_sar_profile *profile, 624 bool enabled) 625 { 626 int i; 627 628 profile->enabled = enabled; 629 630 for (i = 0; i < ACPI_SAR_TABLE_SIZE; i++) { 631 if ((table[i].type != ACPI_TYPE_INTEGER) || 632 (table[i].integer.value > U8_MAX)) 633 return -EINVAL; 634 635 profile->table[i] = table[i].integer.value; 636 } 637 638 return 0; 639 } 640 641 static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm) 642 { 643 union acpi_object *wifi_pkg, *table, *data; 644 bool enabled; 645 int ret; 646 647 data = iwl_acpi_get_object(mvm->dev, ACPI_WRDS_METHOD); 648 if (IS_ERR(data)) 649 return PTR_ERR(data); 650 651 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data, 652 ACPI_WRDS_WIFI_DATA_SIZE); 653 if (IS_ERR(wifi_pkg)) { 654 ret = PTR_ERR(wifi_pkg); 655 goto out_free; 656 } 657 658 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) { 659 ret = -EINVAL; 660 goto out_free; 661 } 662 663 enabled = !!(wifi_pkg->package.elements[1].integer.value); 664 665 /* position of the actual table */ 666 table = &wifi_pkg->package.elements[2]; 667 668 /* The profile from WRDS is officially profile 1, but goes 669 * into sar_profiles[0] (because we don't have a profile 0). 670 */ 671 ret = iwl_mvm_sar_set_profile(mvm, table, &mvm->sar_profiles[0], 672 enabled); 673 out_free: 674 kfree(data); 675 return ret; 676 } 677 678 static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm) 679 { 680 union acpi_object *wifi_pkg, *data; 681 bool enabled; 682 int i, n_profiles, ret; 683 684 data = iwl_acpi_get_object(mvm->dev, ACPI_EWRD_METHOD); 685 if (IS_ERR(data)) 686 return PTR_ERR(data); 687 688 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data, 689 ACPI_EWRD_WIFI_DATA_SIZE); 690 if (IS_ERR(wifi_pkg)) { 691 ret = PTR_ERR(wifi_pkg); 692 goto out_free; 693 } 694 695 if ((wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) || 696 (wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER)) { 697 ret = -EINVAL; 698 goto out_free; 699 } 700 701 enabled = !!(wifi_pkg->package.elements[1].integer.value); 702 n_profiles = wifi_pkg->package.elements[2].integer.value; 703 704 /* 705 * Check the validity of n_profiles. The EWRD profiles start 706 * from index 1, so the maximum value allowed here is 707 * ACPI_SAR_PROFILES_NUM - 1. 708 */ 709 if (n_profiles <= 0 || n_profiles >= ACPI_SAR_PROFILE_NUM) { 710 ret = -EINVAL; 711 goto out_free; 712 } 713 714 for (i = 0; i < n_profiles; i++) { 715 /* the tables start at element 3 */ 716 static int pos = 3; 717 718 /* The EWRD profiles officially go from 2 to 4, but we 719 * save them in sar_profiles[1-3] (because we don't 720 * have profile 0). So in the array we start from 1. 721 */ 722 ret = iwl_mvm_sar_set_profile(mvm, 723 &wifi_pkg->package.elements[pos], 724 &mvm->sar_profiles[i + 1], 725 enabled); 726 if (ret < 0) 727 break; 728 729 /* go to the next table */ 730 pos += ACPI_SAR_TABLE_SIZE; 731 } 732 733 out_free: 734 kfree(data); 735 return ret; 736 } 737 738 static int iwl_mvm_sar_get_wgds_table(struct iwl_mvm *mvm) 739 { 740 union acpi_object *wifi_pkg, *data; 741 int i, j, ret; 742 int idx = 1; 743 744 data = iwl_acpi_get_object(mvm->dev, ACPI_WGDS_METHOD); 745 if (IS_ERR(data)) 746 return PTR_ERR(data); 747 748 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data, 749 ACPI_WGDS_WIFI_DATA_SIZE); 750 if (IS_ERR(wifi_pkg)) { 751 ret = PTR_ERR(wifi_pkg); 752 goto out_free; 753 } 754 755 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) { 756 for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) { 757 union acpi_object *entry; 758 759 entry = &wifi_pkg->package.elements[idx++]; 760 if ((entry->type != ACPI_TYPE_INTEGER) || 761 (entry->integer.value > U8_MAX)) { 762 ret = -EINVAL; 763 goto out_free; 764 } 765 766 mvm->geo_profiles[i].values[j] = entry->integer.value; 767 } 768 } 769 ret = 0; 770 out_free: 771 kfree(data); 772 return ret; 773 } 774 775 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b) 776 { 777 union { 778 struct iwl_dev_tx_power_cmd v5; 779 struct iwl_dev_tx_power_cmd_v4 v4; 780 } cmd; 781 int i, j, idx; 782 int profs[ACPI_SAR_NUM_CHAIN_LIMITS] = { prof_a, prof_b }; 783 int len; 784 785 BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS < 2); 786 BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS * ACPI_SAR_NUM_SUB_BANDS != 787 ACPI_SAR_TABLE_SIZE); 788 789 cmd.v5.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS); 790 791 if (fw_has_api(&mvm->fw->ucode_capa, 792 IWL_UCODE_TLV_API_REDUCE_TX_POWER)) 793 len = sizeof(cmd.v5); 794 else if (fw_has_capa(&mvm->fw->ucode_capa, 795 IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) 796 len = sizeof(cmd.v4); 797 else 798 len = sizeof(cmd.v4.v3); 799 800 for (i = 0; i < ACPI_SAR_NUM_CHAIN_LIMITS; i++) { 801 struct iwl_mvm_sar_profile *prof; 802 803 /* don't allow SAR to be disabled (profile 0 means disable) */ 804 if (profs[i] == 0) 805 return -EPERM; 806 807 /* we are off by one, so allow up to ACPI_SAR_PROFILE_NUM */ 808 if (profs[i] > ACPI_SAR_PROFILE_NUM) 809 return -EINVAL; 810 811 /* profiles go from 1 to 4, so decrement to access the array */ 812 prof = &mvm->sar_profiles[profs[i] - 1]; 813 814 /* if the profile is disabled, do nothing */ 815 if (!prof->enabled) { 816 IWL_DEBUG_RADIO(mvm, "SAR profile %d is disabled.\n", 817 profs[i]); 818 /* if one of the profiles is disabled, we fail all */ 819 return -ENOENT; 820 } 821 822 IWL_DEBUG_RADIO(mvm, " Chain[%d]:\n", i); 823 for (j = 0; j < ACPI_SAR_NUM_SUB_BANDS; j++) { 824 idx = (i * ACPI_SAR_NUM_SUB_BANDS) + j; 825 cmd.v5.v3.per_chain_restriction[i][j] = 826 cpu_to_le16(prof->table[idx]); 827 IWL_DEBUG_RADIO(mvm, " Band[%d] = %d * .125dBm\n", 828 j, prof->table[idx]); 829 } 830 } 831 832 IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n"); 833 834 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd); 835 } 836 837 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm) 838 { 839 struct iwl_geo_tx_power_profiles_resp *resp; 840 int ret; 841 842 struct iwl_geo_tx_power_profiles_cmd geo_cmd = { 843 .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE), 844 }; 845 struct iwl_host_cmd cmd = { 846 .id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT), 847 .len = { sizeof(geo_cmd), }, 848 .flags = CMD_WANT_SKB, 849 .data = { &geo_cmd }, 850 }; 851 852 ret = iwl_mvm_send_cmd(mvm, &cmd); 853 if (ret) { 854 IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret); 855 return ret; 856 } 857 858 resp = (void *)cmd.resp_pkt->data; 859 ret = le32_to_cpu(resp->profile_idx); 860 if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES)) { 861 ret = -EIO; 862 IWL_WARN(mvm, "Invalid geographic profile idx (%d)\n", ret); 863 } 864 865 iwl_free_resp(&cmd); 866 return ret; 867 } 868 869 static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm) 870 { 871 struct iwl_geo_tx_power_profiles_cmd cmd = { 872 .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES), 873 }; 874 int ret, i, j; 875 u16 cmd_wide_id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT); 876 877 ret = iwl_mvm_sar_get_wgds_table(mvm); 878 if (ret < 0) { 879 IWL_DEBUG_RADIO(mvm, 880 "Geo SAR BIOS table invalid or unavailable. (%d)\n", 881 ret); 882 /* we don't fail if the table is not available */ 883 return 0; 884 } 885 886 IWL_DEBUG_RADIO(mvm, "Sending GEO_TX_POWER_LIMIT\n"); 887 888 BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES * ACPI_WGDS_NUM_BANDS * 889 ACPI_WGDS_TABLE_SIZE != ACPI_WGDS_WIFI_DATA_SIZE); 890 891 BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES > IWL_NUM_GEO_PROFILES); 892 893 for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) { 894 struct iwl_per_chain_offset *chain = 895 (struct iwl_per_chain_offset *)&cmd.table[i]; 896 897 for (j = 0; j < ACPI_WGDS_NUM_BANDS; j++) { 898 u8 *value; 899 900 value = &mvm->geo_profiles[i].values[j * 901 ACPI_GEO_PER_CHAIN_SIZE]; 902 chain[j].max_tx_power = cpu_to_le16(value[0]); 903 chain[j].chain_a = value[1]; 904 chain[j].chain_b = value[2]; 905 IWL_DEBUG_RADIO(mvm, 906 "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n", 907 i, j, value[1], value[2], value[0]); 908 } 909 } 910 return iwl_mvm_send_cmd_pdu(mvm, cmd_wide_id, 0, sizeof(cmd), &cmd); 911 } 912 913 #else /* CONFIG_ACPI */ 914 static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm) 915 { 916 return -ENOENT; 917 } 918 919 static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm) 920 { 921 return -ENOENT; 922 } 923 924 static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm) 925 { 926 return 0; 927 } 928 929 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, 930 int prof_b) 931 { 932 return -ENOENT; 933 } 934 935 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm) 936 { 937 return -ENOENT; 938 } 939 #endif /* CONFIG_ACPI */ 940 941 static int iwl_mvm_sar_init(struct iwl_mvm *mvm) 942 { 943 int ret; 944 945 ret = iwl_mvm_sar_get_wrds_table(mvm); 946 if (ret < 0) { 947 IWL_DEBUG_RADIO(mvm, 948 "WRDS SAR BIOS table invalid or unavailable. (%d)\n", 949 ret); 950 /* if not available, don't fail and don't bother with EWRD */ 951 return 0; 952 } 953 954 ret = iwl_mvm_sar_get_ewrd_table(mvm); 955 /* if EWRD is not available, we can still use WRDS, so don't fail */ 956 if (ret < 0) 957 IWL_DEBUG_RADIO(mvm, 958 "EWRD SAR BIOS table invalid or unavailable. (%d)\n", 959 ret); 960 961 /* choose profile 1 (WRDS) as default for both chains */ 962 ret = iwl_mvm_sar_select_profile(mvm, 1, 1); 963 964 /* if we don't have profile 0 from BIOS, just skip it */ 965 if (ret == -ENOENT) 966 return 0; 967 968 return ret; 969 } 970 971 static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm) 972 { 973 int ret; 974 975 if (iwl_mvm_has_unified_ucode(mvm)) 976 return iwl_run_unified_mvm_ucode(mvm, false); 977 978 ret = iwl_run_init_mvm_ucode(mvm, false); 979 980 if (ret) { 981 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret); 982 983 if (iwlmvm_mod_params.init_dbg) 984 return 0; 985 return ret; 986 } 987 988 /* 989 * Stop and start the transport without entering low power 990 * mode. This will save the state of other components on the 991 * device that are triggered by the INIT firwmare (MFUART). 992 */ 993 _iwl_trans_stop_device(mvm->trans, false); 994 ret = _iwl_trans_start_hw(mvm->trans, false); 995 if (ret) 996 return ret; 997 998 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR); 999 if (ret) 1000 return ret; 1001 1002 return iwl_init_paging(&mvm->fwrt, mvm->fwrt.cur_fw_img); 1003 } 1004 1005 int iwl_mvm_up(struct iwl_mvm *mvm) 1006 { 1007 int ret, i; 1008 struct ieee80211_channel *chan; 1009 struct cfg80211_chan_def chandef; 1010 1011 lockdep_assert_held(&mvm->mutex); 1012 1013 ret = iwl_trans_start_hw(mvm->trans); 1014 if (ret) 1015 return ret; 1016 1017 ret = iwl_mvm_load_rt_fw(mvm); 1018 if (ret) { 1019 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret); 1020 goto error; 1021 } 1022 1023 iwl_get_shared_mem_conf(&mvm->fwrt); 1024 1025 ret = iwl_mvm_sf_update(mvm, NULL, false); 1026 if (ret) 1027 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n"); 1028 1029 mvm->fwrt.dump.conf = FW_DBG_INVALID; 1030 /* if we have a destination, assume EARLY START */ 1031 if (mvm->fw->dbg.dest_tlv) 1032 mvm->fwrt.dump.conf = FW_DBG_START_FROM_ALIVE; 1033 iwl_fw_start_dbg_conf(&mvm->fwrt, FW_DBG_START_FROM_ALIVE); 1034 1035 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm)); 1036 if (ret) 1037 goto error; 1038 1039 if (!iwl_mvm_has_unified_ucode(mvm)) { 1040 /* Send phy db control command and then phy db calibration */ 1041 ret = iwl_send_phy_db_data(mvm->phy_db); 1042 if (ret) 1043 goto error; 1044 1045 ret = iwl_send_phy_cfg_cmd(mvm); 1046 if (ret) 1047 goto error; 1048 } 1049 1050 ret = iwl_mvm_send_bt_init_conf(mvm); 1051 if (ret) 1052 goto error; 1053 1054 /* Init RSS configuration */ 1055 if (mvm->trans->cfg->device_family >= IWL_DEVICE_FAMILY_22000) { 1056 ret = iwl_configure_rxq(mvm); 1057 if (ret) { 1058 IWL_ERR(mvm, "Failed to configure RX queues: %d\n", 1059 ret); 1060 goto error; 1061 } 1062 } 1063 1064 if (iwl_mvm_has_new_rx_api(mvm)) { 1065 ret = iwl_send_rss_cfg_cmd(mvm); 1066 if (ret) { 1067 IWL_ERR(mvm, "Failed to configure RSS queues: %d\n", 1068 ret); 1069 goto error; 1070 } 1071 } 1072 1073 /* init the fw <-> mac80211 STA mapping */ 1074 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) 1075 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL); 1076 1077 mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA; 1078 1079 /* reset quota debouncing buffer - 0xff will yield invalid data */ 1080 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd)); 1081 1082 ret = iwl_mvm_send_dqa_cmd(mvm); 1083 if (ret) 1084 goto error; 1085 1086 /* Add auxiliary station for scanning */ 1087 ret = iwl_mvm_add_aux_sta(mvm); 1088 if (ret) 1089 goto error; 1090 1091 /* Add all the PHY contexts */ 1092 chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0]; 1093 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT); 1094 for (i = 0; i < NUM_PHY_CTX; i++) { 1095 /* 1096 * The channel used here isn't relevant as it's 1097 * going to be overwritten in the other flows. 1098 * For now use the first channel we have. 1099 */ 1100 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i], 1101 &chandef, 1, 1); 1102 if (ret) 1103 goto error; 1104 } 1105 1106 #ifdef CONFIG_THERMAL 1107 if (iwl_mvm_is_tt_in_fw(mvm)) { 1108 /* in order to give the responsibility of ct-kill and 1109 * TX backoff to FW we need to send empty temperature reporting 1110 * cmd during init time 1111 */ 1112 iwl_mvm_send_temp_report_ths_cmd(mvm); 1113 } else { 1114 /* Initialize tx backoffs to the minimal possible */ 1115 iwl_mvm_tt_tx_backoff(mvm, 0); 1116 } 1117 1118 /* TODO: read the budget from BIOS / Platform NVM */ 1119 1120 /* 1121 * In case there is no budget from BIOS / Platform NVM the default 1122 * budget should be 2000mW (cooling state 0). 1123 */ 1124 if (iwl_mvm_is_ctdp_supported(mvm)) { 1125 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START, 1126 mvm->cooling_dev.cur_state); 1127 if (ret) 1128 goto error; 1129 } 1130 #else 1131 /* Initialize tx backoffs to the minimal possible */ 1132 iwl_mvm_tt_tx_backoff(mvm, 0); 1133 #endif 1134 1135 WARN_ON(iwl_mvm_config_ltr(mvm)); 1136 1137 ret = iwl_mvm_power_update_device(mvm); 1138 if (ret) 1139 goto error; 1140 1141 /* 1142 * RTNL is not taken during Ct-kill, but we don't need to scan/Tx 1143 * anyway, so don't init MCC. 1144 */ 1145 if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) { 1146 ret = iwl_mvm_init_mcc(mvm); 1147 if (ret) 1148 goto error; 1149 } 1150 1151 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { 1152 mvm->scan_type = IWL_SCAN_TYPE_NOT_SET; 1153 mvm->hb_scan_type = IWL_SCAN_TYPE_NOT_SET; 1154 ret = iwl_mvm_config_scan(mvm); 1155 if (ret) 1156 goto error; 1157 } 1158 1159 /* allow FW/transport low power modes if not during restart */ 1160 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1161 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN); 1162 1163 ret = iwl_mvm_sar_init(mvm); 1164 if (ret) 1165 goto error; 1166 1167 ret = iwl_mvm_sar_geo_init(mvm); 1168 if (ret) 1169 goto error; 1170 1171 iwl_mvm_leds_sync(mvm); 1172 1173 IWL_DEBUG_INFO(mvm, "RT uCode started.\n"); 1174 return 0; 1175 error: 1176 if (!iwlmvm_mod_params.init_dbg || !ret) 1177 iwl_mvm_stop_device(mvm); 1178 return ret; 1179 } 1180 1181 int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm) 1182 { 1183 int ret, i; 1184 1185 lockdep_assert_held(&mvm->mutex); 1186 1187 ret = iwl_trans_start_hw(mvm->trans); 1188 if (ret) 1189 return ret; 1190 1191 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN); 1192 if (ret) { 1193 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret); 1194 goto error; 1195 } 1196 1197 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm)); 1198 if (ret) 1199 goto error; 1200 1201 /* Send phy db control command and then phy db calibration*/ 1202 ret = iwl_send_phy_db_data(mvm->phy_db); 1203 if (ret) 1204 goto error; 1205 1206 ret = iwl_send_phy_cfg_cmd(mvm); 1207 if (ret) 1208 goto error; 1209 1210 /* init the fw <-> mac80211 STA mapping */ 1211 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) 1212 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL); 1213 1214 /* Add auxiliary station for scanning */ 1215 ret = iwl_mvm_add_aux_sta(mvm); 1216 if (ret) 1217 goto error; 1218 1219 return 0; 1220 error: 1221 iwl_mvm_stop_device(mvm); 1222 return ret; 1223 } 1224 1225 void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm, 1226 struct iwl_rx_cmd_buffer *rxb) 1227 { 1228 struct iwl_rx_packet *pkt = rxb_addr(rxb); 1229 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data; 1230 u32 flags = le32_to_cpu(card_state_notif->flags); 1231 1232 IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n", 1233 (flags & HW_CARD_DISABLED) ? "Kill" : "On", 1234 (flags & SW_CARD_DISABLED) ? "Kill" : "On", 1235 (flags & CT_KILL_CARD_DISABLED) ? 1236 "Reached" : "Not reached"); 1237 } 1238 1239 void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm, 1240 struct iwl_rx_cmd_buffer *rxb) 1241 { 1242 struct iwl_rx_packet *pkt = rxb_addr(rxb); 1243 struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data; 1244 1245 IWL_DEBUG_INFO(mvm, 1246 "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n", 1247 le32_to_cpu(mfuart_notif->installed_ver), 1248 le32_to_cpu(mfuart_notif->external_ver), 1249 le32_to_cpu(mfuart_notif->status), 1250 le32_to_cpu(mfuart_notif->duration)); 1251 1252 if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif)) 1253 IWL_DEBUG_INFO(mvm, 1254 "MFUART: image size: 0x%08x\n", 1255 le32_to_cpu(mfuart_notif->image_size)); 1256 } 1257