1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2018-2021 Intel Corporation
4 * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5 * Copyright (C) 2016-2017 Intel Deutschland GmbH
7 #include <net/mac80211.h>
8 #include <linux/netdevice.h>
11 #include "iwl-trans.h"
12 #include "iwl-op-mode.h"
14 #include "iwl-debug.h"
21 #include "iwl-phy-db.h"
22 #include "iwl-modparams.h"
23 #include "iwl-nvm-parse.h"
25 #define MVM_UCODE_ALIVE_TIMEOUT (HZ)
26 #define MVM_UCODE_CALIB_TIMEOUT (2 * HZ)
28 #define UCODE_VALID_OK cpu_to_le32(0x1)
30 #define IWL_PPAG_MASK 3
31 #define IWL_PPAG_ETSI_MASK BIT(0)
33 #define IWL_TAS_US_MCC 0x5553
34 #define IWL_TAS_CANADA_MCC 0x4341
36 struct iwl_mvm_alive_data {
41 static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
43 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
44 .valid = cpu_to_le32(valid_tx_ant),
47 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
48 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
49 sizeof(tx_ant_cmd), &tx_ant_cmd);
52 static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm)
55 struct iwl_rss_config_cmd cmd = {
56 .flags = cpu_to_le32(IWL_RSS_ENABLE),
57 .hash_mask = BIT(IWL_RSS_HASH_TYPE_IPV4_TCP) |
58 BIT(IWL_RSS_HASH_TYPE_IPV4_UDP) |
59 BIT(IWL_RSS_HASH_TYPE_IPV4_PAYLOAD) |
60 BIT(IWL_RSS_HASH_TYPE_IPV6_TCP) |
61 BIT(IWL_RSS_HASH_TYPE_IPV6_UDP) |
62 BIT(IWL_RSS_HASH_TYPE_IPV6_PAYLOAD),
65 if (mvm->trans->num_rx_queues == 1)
68 /* Do not direct RSS traffic to Q 0 which is our fallback queue */
69 for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++)
70 cmd.indirection_table[i] =
71 1 + (i % (mvm->trans->num_rx_queues - 1));
72 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
74 return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
77 static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm)
79 struct iwl_dqa_enable_cmd dqa_cmd = {
80 .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE),
82 u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0);
85 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd);
87 IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret);
89 IWL_DEBUG_FW(mvm, "Working in DQA mode\n");
94 void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
95 struct iwl_rx_cmd_buffer *rxb)
97 struct iwl_rx_packet *pkt = rxb_addr(rxb);
98 struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data;
99 __le32 *dump_data = mfu_dump_notif->data;
100 int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32);
103 if (mfu_dump_notif->index_num == 0)
104 IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n",
105 le32_to_cpu(mfu_dump_notif->assert_id));
107 for (i = 0; i < n_words; i++)
109 "MFUART assert dump, dword %u: 0x%08x\n",
110 le16_to_cpu(mfu_dump_notif->index_num) *
112 le32_to_cpu(dump_data[i]));
115 static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
116 struct iwl_rx_packet *pkt, void *data)
118 unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
119 struct iwl_mvm *mvm =
120 container_of(notif_wait, struct iwl_mvm, notif_wait);
121 struct iwl_mvm_alive_data *alive_data = data;
122 struct iwl_umac_alive *umac;
123 struct iwl_lmac_alive *lmac1;
124 struct iwl_lmac_alive *lmac2 = NULL;
126 u32 lmac_error_event_table, umac_error_table;
127 u32 version = iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
128 UCODE_ALIVE_NTFY, 0);
131 * For v5 and above, we can check the version, for older
132 * versions we need to check the size.
134 if (version == 5 || version == 6) {
135 /* v5 and v6 are compatible (only IMR addition) */
136 struct iwl_alive_ntf_v5 *palive;
138 if (pkt_len < sizeof(*palive))
141 palive = (void *)pkt->data;
142 umac = &palive->umac_data;
143 lmac1 = &palive->lmac_data[0];
144 lmac2 = &palive->lmac_data[1];
145 status = le16_to_cpu(palive->status);
147 mvm->trans->sku_id[0] = le32_to_cpu(palive->sku_id.data[0]);
148 mvm->trans->sku_id[1] = le32_to_cpu(palive->sku_id.data[1]);
149 mvm->trans->sku_id[2] = le32_to_cpu(palive->sku_id.data[2]);
151 IWL_DEBUG_FW(mvm, "Got sku_id: 0x0%x 0x0%x 0x0%x\n",
152 mvm->trans->sku_id[0],
153 mvm->trans->sku_id[1],
154 mvm->trans->sku_id[2]);
155 } else if (iwl_rx_packet_payload_len(pkt) == sizeof(struct iwl_alive_ntf_v4)) {
156 struct iwl_alive_ntf_v4 *palive;
158 if (pkt_len < sizeof(*palive))
161 palive = (void *)pkt->data;
162 umac = &palive->umac_data;
163 lmac1 = &palive->lmac_data[0];
164 lmac2 = &palive->lmac_data[1];
165 status = le16_to_cpu(palive->status);
166 } else if (iwl_rx_packet_payload_len(pkt) ==
167 sizeof(struct iwl_alive_ntf_v3)) {
168 struct iwl_alive_ntf_v3 *palive3;
170 if (pkt_len < sizeof(*palive3))
173 palive3 = (void *)pkt->data;
174 umac = &palive3->umac_data;
175 lmac1 = &palive3->lmac_data;
176 status = le16_to_cpu(palive3->status);
178 WARN(1, "unsupported alive notification (size %d)\n",
179 iwl_rx_packet_payload_len(pkt));
180 /* get timeout later */
184 lmac_error_event_table =
185 le32_to_cpu(lmac1->dbg_ptrs.error_event_table_ptr);
186 iwl_fw_lmac1_set_alive_err_table(mvm->trans, lmac_error_event_table);
189 mvm->trans->dbg.lmac_error_event_table[1] =
190 le32_to_cpu(lmac2->dbg_ptrs.error_event_table_ptr);
192 umac_error_table = le32_to_cpu(umac->dbg_ptrs.error_info_addr) &
193 ~FW_ADDR_CACHE_CONTROL;
195 if (umac_error_table) {
196 if (umac_error_table >=
197 mvm->trans->cfg->min_umac_error_event_table) {
198 iwl_fw_umac_set_alive_err_table(mvm->trans,
202 "Not valid error log pointer 0x%08X for %s uCode\n",
204 (mvm->fwrt.cur_fw_img == IWL_UCODE_INIT) ?
209 alive_data->scd_base_addr = le32_to_cpu(lmac1->dbg_ptrs.scd_base_ptr);
210 alive_data->valid = status == IWL_ALIVE_STATUS_OK;
213 "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n",
214 status, lmac1->ver_type, lmac1->ver_subtype);
217 IWL_DEBUG_FW(mvm, "Alive ucode CDB\n");
220 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
221 le32_to_cpu(umac->umac_major),
222 le32_to_cpu(umac->umac_minor));
224 iwl_fwrt_update_fw_versions(&mvm->fwrt, lmac1, umac);
229 static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait,
230 struct iwl_rx_packet *pkt, void *data)
232 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
237 static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
238 struct iwl_rx_packet *pkt, void *data)
240 struct iwl_phy_db *phy_db = data;
242 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
243 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
247 WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
252 static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
253 enum iwl_ucode_type ucode_type)
255 struct iwl_notification_wait alive_wait;
256 struct iwl_mvm_alive_data alive_data = {};
257 const struct fw_img *fw;
259 enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img;
260 static const u16 alive_cmd[] = { UCODE_ALIVE_NTFY };
262 ucode_type == IWL_UCODE_INIT || iwl_mvm_has_unified_ucode(mvm);
264 if (ucode_type == IWL_UCODE_REGULAR &&
265 iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
266 !(fw_has_capa(&mvm->fw->ucode_capa,
267 IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
268 fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER);
270 fw = iwl_get_ucode_image(mvm->fw, ucode_type);
273 iwl_fw_set_current_image(&mvm->fwrt, ucode_type);
274 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
276 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
277 alive_cmd, ARRAY_SIZE(alive_cmd),
278 iwl_alive_fn, &alive_data);
281 * We want to load the INIT firmware even in RFKILL
282 * For the unified firmware case, the ucode_type is not
283 * INIT, but we still need to run it.
285 ret = iwl_trans_start_fw(mvm->trans, fw, run_in_rfkill);
287 iwl_fw_set_current_image(&mvm->fwrt, old_type);
288 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
293 * Some things may run in the background now, but we
294 * just wait for the ALIVE notification here.
296 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
297 MVM_UCODE_ALIVE_TIMEOUT);
299 struct iwl_trans *trans = mvm->trans;
302 if (trans->trans_cfg->device_family >=
303 IWL_DEVICE_FAMILY_22000) {
305 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
306 iwl_read_umac_prph(trans, UMAG_SB_CPU_1_STATUS),
307 iwl_read_umac_prph(trans,
308 UMAG_SB_CPU_2_STATUS));
309 } else if (trans->trans_cfg->device_family >=
310 IWL_DEVICE_FAMILY_8000) {
312 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
313 iwl_read_prph(trans, SB_CPU_1_STATUS),
314 iwl_read_prph(trans, SB_CPU_2_STATUS));
317 /* LMAC/UMAC PC info */
318 if (trans->trans_cfg->device_family >=
319 IWL_DEVICE_FAMILY_9000) {
320 IWL_ERR(mvm, "UMAC PC: 0x%x\n",
321 iwl_read_umac_prph(trans,
322 UREG_UMAC_CURRENT_PC));
323 IWL_ERR(mvm, "LMAC PC: 0x%x\n",
324 iwl_read_umac_prph(trans,
325 UREG_LMAC1_CURRENT_PC));
326 if (iwl_mvm_is_cdb_supported(mvm))
327 IWL_ERR(mvm, "LMAC2 PC: 0x%x\n",
328 iwl_read_umac_prph(trans,
329 UREG_LMAC2_CURRENT_PC));
332 if (ret == -ETIMEDOUT)
333 iwl_fw_dbg_error_collect(&mvm->fwrt,
334 FW_DBG_TRIGGER_ALIVE_TIMEOUT);
336 iwl_fw_set_current_image(&mvm->fwrt, old_type);
340 if (!alive_data.valid) {
341 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
342 iwl_fw_set_current_image(&mvm->fwrt, old_type);
346 ret = iwl_pnvm_load(mvm->trans, &mvm->notif_wait);
348 IWL_ERR(mvm, "Timeout waiting for PNVM load!\n");
349 iwl_fw_set_current_image(&mvm->fwrt, old_type);
353 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
356 * Note: all the queues are enabled as part of the interface
357 * initialization, but in firmware restart scenarios they
358 * could be stopped, so wake them up. In firmware restart,
359 * mac80211 will have the queues stopped as well until the
360 * reconfiguration completes. During normal startup, they
364 memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
366 * Set a 'fake' TID for the command queue, since we use the
367 * hweight() of the tid_bitmap as a refcount now. Not that
368 * we ever even consider the command queue as one we might
369 * want to reuse, but be safe nevertheless.
371 mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].tid_bitmap =
372 BIT(IWL_MAX_TID_COUNT + 2);
374 set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
375 #ifdef CONFIG_IWLWIFI_DEBUGFS
376 iwl_fw_set_dbg_rec_on(&mvm->fwrt);
380 * All the BSSes in the BSS table include the GP2 in the system
381 * at the beacon Rx time, this is of course no longer relevant
382 * since we are resetting the firmware.
383 * Purge all the BSS table.
385 cfg80211_bss_flush(mvm->hw->wiphy);
390 static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm)
392 struct iwl_notification_wait init_wait;
393 struct iwl_nvm_access_complete_cmd nvm_complete = {};
394 struct iwl_init_extended_cfg_cmd init_cfg = {
395 .init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)),
397 static const u16 init_complete[] = {
402 if (mvm->trans->cfg->tx_with_siso_diversity)
403 init_cfg.init_flags |= cpu_to_le32(BIT(IWL_INIT_PHY));
405 lockdep_assert_held(&mvm->mutex);
407 mvm->rfkill_safe_init_done = false;
409 iwl_init_notification_wait(&mvm->notif_wait,
412 ARRAY_SIZE(init_complete),
413 iwl_wait_init_complete,
416 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_EARLY, NULL);
418 /* Will also start the device */
419 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
421 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
424 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_AFTER_ALIVE,
427 /* Send init config command to mark that we are sending NVM access
430 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP,
431 INIT_EXTENDED_CFG_CMD),
433 sizeof(init_cfg), &init_cfg);
435 IWL_ERR(mvm, "Failed to run init config command: %d\n",
440 /* Load NVM to NIC if needed */
441 if (mvm->nvm_file_name) {
442 ret = iwl_read_external_nvm(mvm->trans, mvm->nvm_file_name,
446 ret = iwl_mvm_load_nvm_to_nic(mvm);
451 if (IWL_MVM_PARSE_NVM && !mvm->nvm_data) {
452 ret = iwl_nvm_init(mvm);
454 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
459 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
460 NVM_ACCESS_COMPLETE),
462 sizeof(nvm_complete), &nvm_complete);
464 IWL_ERR(mvm, "Failed to run complete NVM access: %d\n",
469 /* We wait for the INIT complete notification */
470 ret = iwl_wait_notification(&mvm->notif_wait, &init_wait,
471 MVM_UCODE_ALIVE_TIMEOUT);
475 /* Read the NVM only at driver load time, no need to do this twice */
476 if (!IWL_MVM_PARSE_NVM && !mvm->nvm_data) {
477 mvm->nvm_data = iwl_get_nvm(mvm->trans, mvm->fw);
478 if (IS_ERR(mvm->nvm_data)) {
479 ret = PTR_ERR(mvm->nvm_data);
480 mvm->nvm_data = NULL;
481 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
486 mvm->rfkill_safe_init_done = true;
491 iwl_remove_notification(&mvm->notif_wait, &init_wait);
496 static void iwl_mvm_phy_filter_init(struct iwl_mvm *mvm,
497 struct iwl_phy_specific_cfg *phy_filters)
500 * TODO: read specific phy config from BIOS
501 * ACPI table for this feature has not been defined yet,
502 * so for now we use hardcoded values.
505 if (IWL_MVM_PHY_FILTER_CHAIN_A) {
506 phy_filters->filter_cfg_chain_a =
507 cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_A);
509 if (IWL_MVM_PHY_FILTER_CHAIN_B) {
510 phy_filters->filter_cfg_chain_b =
511 cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_B);
513 if (IWL_MVM_PHY_FILTER_CHAIN_C) {
514 phy_filters->filter_cfg_chain_c =
515 cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_C);
517 if (IWL_MVM_PHY_FILTER_CHAIN_D) {
518 phy_filters->filter_cfg_chain_d =
519 cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_D);
522 #else /* CONFIG_ACPI */
524 static void iwl_mvm_phy_filter_init(struct iwl_mvm *mvm,
525 struct iwl_phy_specific_cfg *phy_filters)
528 #endif /* CONFIG_ACPI */
530 #if defined(CONFIG_ACPI) && defined(CONFIG_EFI)
531 static int iwl_mvm_sgom_init(struct iwl_mvm *mvm)
535 struct iwl_host_cmd cmd = {
536 .id = WIDE_ID(REGULATORY_AND_NVM_GROUP,
537 SAR_OFFSET_MAPPING_TABLE_CMD),
539 .data[0] = &mvm->fwrt.sgom_table,
540 .len[0] = sizeof(mvm->fwrt.sgom_table),
541 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
544 if (!mvm->fwrt.sgom_enabled) {
545 IWL_DEBUG_RADIO(mvm, "SGOM table is disabled\n");
549 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, REGULATORY_AND_NVM_GROUP,
550 SAR_OFFSET_MAPPING_TABLE_CMD,
551 IWL_FW_CMD_VER_UNKNOWN);
554 IWL_DEBUG_RADIO(mvm, "command version is unsupported. version = %d\n",
559 ret = iwl_mvm_send_cmd(mvm, &cmd);
561 IWL_ERR(mvm, "failed to send SAR_OFFSET_MAPPING_CMD (%d)\n", ret);
567 static int iwl_mvm_sgom_init(struct iwl_mvm *mvm)
573 static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
575 struct iwl_phy_cfg_cmd_v3 phy_cfg_cmd;
576 enum iwl_ucode_type ucode_type = mvm->fwrt.cur_fw_img;
577 struct iwl_phy_specific_cfg phy_filters = {};
581 if (iwl_mvm_has_unified_ucode(mvm) &&
582 !mvm->trans->cfg->tx_with_siso_diversity)
585 if (mvm->trans->cfg->tx_with_siso_diversity) {
587 * TODO: currently we don't set the antenna but letting the NIC
588 * to decide which antenna to use. This should come from BIOS.
590 phy_cfg_cmd.phy_cfg =
591 cpu_to_le32(FW_PHY_CFG_CHAIN_SAD_ENABLED);
595 phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
597 /* set flags extra PHY configuration flags from the device's cfg */
598 phy_cfg_cmd.phy_cfg |=
599 cpu_to_le32(mvm->trans->trans_cfg->extra_phy_cfg_flags);
601 phy_cfg_cmd.calib_control.event_trigger =
602 mvm->fw->default_calib[ucode_type].event_trigger;
603 phy_cfg_cmd.calib_control.flow_trigger =
604 mvm->fw->default_calib[ucode_type].flow_trigger;
606 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
607 PHY_CONFIGURATION_CMD,
608 IWL_FW_CMD_VER_UNKNOWN);
610 iwl_mvm_phy_filter_init(mvm, &phy_filters);
611 memcpy(&phy_cfg_cmd.phy_specific_cfg, &phy_filters,
612 sizeof(struct iwl_phy_specific_cfg));
615 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
616 phy_cfg_cmd.phy_cfg);
617 cmd_size = (cmd_ver == 3) ? sizeof(struct iwl_phy_cfg_cmd_v3) :
618 sizeof(struct iwl_phy_cfg_cmd_v1);
619 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
620 cmd_size, &phy_cfg_cmd);
623 int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm)
625 struct iwl_notification_wait calib_wait;
626 static const u16 init_complete[] = {
628 CALIB_RES_NOTIF_PHY_DB
632 if (iwl_mvm_has_unified_ucode(mvm))
633 return iwl_run_unified_mvm_ucode(mvm);
635 lockdep_assert_held(&mvm->mutex);
637 mvm->rfkill_safe_init_done = false;
639 iwl_init_notification_wait(&mvm->notif_wait,
642 ARRAY_SIZE(init_complete),
643 iwl_wait_phy_db_entry,
646 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_EARLY, NULL);
648 /* Will also start the device */
649 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
651 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
655 if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_8000) {
656 ret = iwl_mvm_send_bt_init_conf(mvm);
661 /* Read the NVM only at driver load time, no need to do this twice */
662 if (!mvm->nvm_data) {
663 ret = iwl_nvm_init(mvm);
665 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
670 /* In case we read the NVM from external file, load it to the NIC */
671 if (mvm->nvm_file_name) {
672 ret = iwl_mvm_load_nvm_to_nic(mvm);
677 WARN_ONCE(mvm->nvm_data->nvm_version < mvm->trans->cfg->nvm_ver,
678 "Too old NVM version (0x%0x, required = 0x%0x)",
679 mvm->nvm_data->nvm_version, mvm->trans->cfg->nvm_ver);
682 * abort after reading the nvm in case RF Kill is on, we will complete
683 * the init seq later when RF kill will switch to off
685 if (iwl_mvm_is_radio_hw_killed(mvm)) {
686 IWL_DEBUG_RF_KILL(mvm,
687 "jump over all phy activities due to RF kill\n");
691 mvm->rfkill_safe_init_done = true;
693 /* Send TX valid antennas before triggering calibrations */
694 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
698 ret = iwl_send_phy_cfg_cmd(mvm);
700 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
706 * Some things may run in the background now, but we
707 * just wait for the calibration complete notification.
709 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
710 MVM_UCODE_CALIB_TIMEOUT);
714 if (iwl_mvm_is_radio_hw_killed(mvm)) {
715 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
718 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
725 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
727 mvm->rfkill_safe_init_done = false;
728 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
729 /* we want to debug INIT and we have no NVM - fake */
730 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
731 sizeof(struct ieee80211_channel) +
732 sizeof(struct ieee80211_rate),
736 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
737 mvm->nvm_data->bands[0].n_channels = 1;
738 mvm->nvm_data->bands[0].n_bitrates = 1;
739 mvm->nvm_data->bands[0].bitrates =
740 (void *)mvm->nvm_data->channels + 1;
741 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
747 static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
749 struct iwl_ltr_config_cmd cmd = {
750 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
753 if (!mvm->trans->ltr_enabled)
756 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
761 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b)
763 struct iwl_dev_tx_power_cmd cmd = {
764 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
770 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
772 IWL_FW_CMD_VER_UNKNOWN);
775 len = sizeof(cmd.v6);
776 n_subbands = IWL_NUM_SUB_BANDS_V2;
777 per_chain = cmd.v6.per_chain[0][0];
778 } else if (fw_has_api(&mvm->fw->ucode_capa,
779 IWL_UCODE_TLV_API_REDUCE_TX_POWER)) {
780 len = sizeof(cmd.v5);
781 n_subbands = IWL_NUM_SUB_BANDS_V1;
782 per_chain = cmd.v5.per_chain[0][0];
783 } else if (fw_has_capa(&mvm->fw->ucode_capa,
784 IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) {
785 len = sizeof(cmd.v4);
786 n_subbands = IWL_NUM_SUB_BANDS_V1;
787 per_chain = cmd.v4.per_chain[0][0];
789 len = sizeof(cmd.v3);
790 n_subbands = IWL_NUM_SUB_BANDS_V1;
791 per_chain = cmd.v3.per_chain[0][0];
794 /* all structs have the same common part, add it */
795 len += sizeof(cmd.common);
797 ret = iwl_sar_select_profile(&mvm->fwrt, per_chain,
798 IWL_NUM_CHAIN_TABLES,
799 n_subbands, prof_a, prof_b);
801 /* return on error or if the profile is disabled (positive number) */
805 iwl_mei_set_power_limit(per_chain);
807 IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
808 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
811 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
813 union iwl_geo_tx_power_profiles_cmd geo_tx_cmd;
814 struct iwl_geo_tx_power_profiles_resp *resp;
817 struct iwl_host_cmd cmd;
818 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, PHY_OPS_GROUP,
819 PER_CHAIN_LIMIT_OFFSET_CMD,
820 IWL_FW_CMD_VER_UNKNOWN);
822 /* the ops field is at the same spot for all versions, so set in v1 */
824 cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE);
827 len = sizeof(geo_tx_cmd.v5);
828 else if (cmd_ver == 4)
829 len = sizeof(geo_tx_cmd.v4);
830 else if (cmd_ver == 3)
831 len = sizeof(geo_tx_cmd.v3);
832 else if (fw_has_api(&mvm->fwrt.fw->ucode_capa,
833 IWL_UCODE_TLV_API_SAR_TABLE_VER))
834 len = sizeof(geo_tx_cmd.v2);
836 len = sizeof(geo_tx_cmd.v1);
838 if (!iwl_sar_geo_support(&mvm->fwrt))
841 cmd = (struct iwl_host_cmd){
842 .id = WIDE_ID(PHY_OPS_GROUP, PER_CHAIN_LIMIT_OFFSET_CMD),
844 .flags = CMD_WANT_SKB,
845 .data = { &geo_tx_cmd },
848 ret = iwl_mvm_send_cmd(mvm, &cmd);
850 IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret);
854 resp = (void *)cmd.resp_pkt->data;
855 ret = le32_to_cpu(resp->profile_idx);
857 if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES_REV3))
864 static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
866 union iwl_geo_tx_power_profiles_cmd cmd;
872 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, PHY_OPS_GROUP,
873 PER_CHAIN_LIMIT_OFFSET_CMD,
874 IWL_FW_CMD_VER_UNKNOWN);
876 BUILD_BUG_ON(offsetof(struct iwl_geo_tx_power_profiles_cmd_v1, ops) !=
877 offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, ops) ||
878 offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, ops) !=
879 offsetof(struct iwl_geo_tx_power_profiles_cmd_v3, ops) ||
880 offsetof(struct iwl_geo_tx_power_profiles_cmd_v3, ops) !=
881 offsetof(struct iwl_geo_tx_power_profiles_cmd_v4, ops) ||
882 offsetof(struct iwl_geo_tx_power_profiles_cmd_v4, ops) !=
883 offsetof(struct iwl_geo_tx_power_profiles_cmd_v5, ops));
885 /* the ops field is at the same spot for all versions, so set in v1 */
886 cmd.v1.ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES);
889 len = sizeof(cmd.v5);
890 n_bands = ARRAY_SIZE(cmd.v5.table[0]);
891 n_profiles = ACPI_NUM_GEO_PROFILES_REV3;
892 } else if (cmd_ver == 4) {
893 len = sizeof(cmd.v4);
894 n_bands = ARRAY_SIZE(cmd.v4.table[0]);
895 n_profiles = ACPI_NUM_GEO_PROFILES_REV3;
896 } else if (cmd_ver == 3) {
897 len = sizeof(cmd.v3);
898 n_bands = ARRAY_SIZE(cmd.v3.table[0]);
899 n_profiles = ACPI_NUM_GEO_PROFILES;
900 } else if (fw_has_api(&mvm->fwrt.fw->ucode_capa,
901 IWL_UCODE_TLV_API_SAR_TABLE_VER)) {
902 len = sizeof(cmd.v2);
903 n_bands = ARRAY_SIZE(cmd.v2.table[0]);
904 n_profiles = ACPI_NUM_GEO_PROFILES;
906 len = sizeof(cmd.v1);
907 n_bands = ARRAY_SIZE(cmd.v1.table[0]);
908 n_profiles = ACPI_NUM_GEO_PROFILES;
911 BUILD_BUG_ON(offsetof(struct iwl_geo_tx_power_profiles_cmd_v1, table) !=
912 offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, table) ||
913 offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, table) !=
914 offsetof(struct iwl_geo_tx_power_profiles_cmd_v3, table) ||
915 offsetof(struct iwl_geo_tx_power_profiles_cmd_v3, table) !=
916 offsetof(struct iwl_geo_tx_power_profiles_cmd_v4, table) ||
917 offsetof(struct iwl_geo_tx_power_profiles_cmd_v4, table) !=
918 offsetof(struct iwl_geo_tx_power_profiles_cmd_v5, table));
919 /* the table is at the same position for all versions, so set use v1 */
920 ret = iwl_sar_geo_init(&mvm->fwrt, &cmd.v1.table[0][0],
921 n_bands, n_profiles);
924 * It is a valid scenario to not support SAR, or miss wgds table,
925 * but in that case there is no need to send the command.
930 /* Only set to South Korea if the table revision is 1 */
931 if (mvm->fwrt.geo_rev == 1)
935 * Set the table_revision to South Korea (1) or not (0). The
936 * element name is misleading, as it doesn't contain the table
937 * revision number, but whether the South Korea variation
939 * This must be done after calling iwl_sar_geo_init().
942 cmd.v5.table_revision = cpu_to_le32(sk);
943 else if (cmd_ver == 4)
944 cmd.v4.table_revision = cpu_to_le32(sk);
945 else if (cmd_ver == 3)
946 cmd.v3.table_revision = cpu_to_le32(sk);
947 else if (fw_has_api(&mvm->fwrt.fw->ucode_capa,
948 IWL_UCODE_TLV_API_SAR_TABLE_VER))
949 cmd.v2.table_revision = cpu_to_le32(sk);
951 return iwl_mvm_send_cmd_pdu(mvm,
952 WIDE_ID(PHY_OPS_GROUP,
953 PER_CHAIN_LIMIT_OFFSET_CMD),
957 static int iwl_mvm_get_ppag_table(struct iwl_mvm *mvm)
959 union acpi_object *wifi_pkg, *data, *flags;
960 int i, j, ret, tbl_rev, num_sub_bands;
963 mvm->fwrt.ppag_flags = 0;
965 data = iwl_acpi_get_object(mvm->dev, ACPI_PPAG_METHOD);
967 return PTR_ERR(data);
969 /* try to read ppag table rev 2 or 1 (both have the same data size) */
970 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
971 ACPI_PPAG_WIFI_DATA_SIZE_V2, &tbl_rev);
972 if (!IS_ERR(wifi_pkg)) {
973 if (tbl_rev == 1 || tbl_rev == 2) {
974 num_sub_bands = IWL_NUM_SUB_BANDS_V2;
976 "Reading PPAG table v2 (tbl_rev=%d)\n",
985 /* try to read ppag table revision 0 */
986 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
987 ACPI_PPAG_WIFI_DATA_SIZE_V1, &tbl_rev);
988 if (!IS_ERR(wifi_pkg)) {
993 num_sub_bands = IWL_NUM_SUB_BANDS_V1;
994 IWL_DEBUG_RADIO(mvm, "Reading PPAG table v1 (tbl_rev=0)\n");
997 ret = PTR_ERR(wifi_pkg);
1001 mvm->fwrt.ppag_ver = tbl_rev;
1002 flags = &wifi_pkg->package.elements[1];
1004 if (flags->type != ACPI_TYPE_INTEGER) {
1009 mvm->fwrt.ppag_flags = flags->integer.value & IWL_PPAG_MASK;
1011 if (!mvm->fwrt.ppag_flags) {
1017 * read, verify gain values and save them into the PPAG table.
1018 * first sub-band (j=0) corresponds to Low-Band (2.4GHz), and the
1019 * following sub-bands to High-Band (5GHz).
1021 for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) {
1022 for (j = 0; j < num_sub_bands; j++) {
1023 union acpi_object *ent;
1025 ent = &wifi_pkg->package.elements[idx++];
1026 if (ent->type != ACPI_TYPE_INTEGER) {
1031 mvm->fwrt.ppag_chains[i].subbands[j] = ent->integer.value;
1034 (mvm->fwrt.ppag_chains[i].subbands[j] > ACPI_PPAG_MAX_LB ||
1035 mvm->fwrt.ppag_chains[i].subbands[j] < ACPI_PPAG_MIN_LB)) ||
1037 (mvm->fwrt.ppag_chains[i].subbands[j] > ACPI_PPAG_MAX_HB ||
1038 mvm->fwrt.ppag_chains[i].subbands[j] < ACPI_PPAG_MIN_HB))) {
1039 mvm->fwrt.ppag_flags = 0;
1052 int iwl_mvm_ppag_send_cmd(struct iwl_mvm *mvm)
1054 union iwl_ppag_table_cmd cmd;
1056 int i, j, ret, num_sub_bands, cmd_size;
1059 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_SET_PPAG)) {
1060 IWL_DEBUG_RADIO(mvm,
1061 "PPAG capability not supported by FW, command not sent.\n");
1064 if (!mvm->fwrt.ppag_flags) {
1065 IWL_DEBUG_RADIO(mvm, "PPAG not enabled, command not sent.\n");
1069 /* The 'flags' field is the same in v1 and in v2 so we can just
1070 * use v1 to access it.
1072 cmd.v1.flags = cpu_to_le32(mvm->fwrt.ppag_flags);
1073 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, PHY_OPS_GROUP,
1074 PER_PLATFORM_ANT_GAIN_CMD,
1075 IWL_FW_CMD_VER_UNKNOWN);
1077 num_sub_bands = IWL_NUM_SUB_BANDS_V1;
1078 gain = cmd.v1.gain[0];
1079 cmd_size = sizeof(cmd.v1);
1080 if (mvm->fwrt.ppag_ver == 1 || mvm->fwrt.ppag_ver == 2) {
1081 IWL_DEBUG_RADIO(mvm,
1082 "PPAG table rev is %d but FW supports v1, sending truncated table\n",
1083 mvm->fwrt.ppag_ver);
1084 cmd.v1.flags &= cpu_to_le32(IWL_PPAG_ETSI_MASK);
1086 } else if (cmd_ver == 2 || cmd_ver == 3) {
1087 num_sub_bands = IWL_NUM_SUB_BANDS_V2;
1088 gain = cmd.v2.gain[0];
1089 cmd_size = sizeof(cmd.v2);
1090 if (mvm->fwrt.ppag_ver == 0) {
1091 IWL_DEBUG_RADIO(mvm,
1092 "PPAG table is v1 but FW supports v2, sending padded table\n");
1093 } else if (cmd_ver == 2 && mvm->fwrt.ppag_ver == 2) {
1094 IWL_DEBUG_RADIO(mvm,
1095 "PPAG table is v3 but FW supports v2, sending partial bitmap.\n");
1096 cmd.v1.flags &= cpu_to_le32(IWL_PPAG_ETSI_MASK);
1099 IWL_DEBUG_RADIO(mvm, "Unsupported PPAG command version\n");
1103 for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) {
1104 for (j = 0; j < num_sub_bands; j++) {
1105 gain[i * num_sub_bands + j] =
1106 mvm->fwrt.ppag_chains[i].subbands[j];
1107 IWL_DEBUG_RADIO(mvm,
1108 "PPAG table: chain[%d] band[%d]: gain = %d\n",
1109 i, j, gain[i * num_sub_bands + j]);
1112 IWL_DEBUG_RADIO(mvm, "Sending PER_PLATFORM_ANT_GAIN_CMD\n");
1113 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(PHY_OPS_GROUP,
1114 PER_PLATFORM_ANT_GAIN_CMD),
1117 IWL_ERR(mvm, "failed to send PER_PLATFORM_ANT_GAIN_CMD (%d)\n",
1123 static const struct dmi_system_id dmi_ppag_approved_list[] = {
1126 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
1129 { .ident = "SAMSUNG",
1131 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD"),
1136 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
1141 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTek COMPUTER INC."),
1147 static int iwl_mvm_ppag_init(struct iwl_mvm *mvm)
1149 /* no need to read the table, done in INIT stage */
1150 if (!dmi_check_system(dmi_ppag_approved_list)) {
1151 IWL_DEBUG_RADIO(mvm,
1152 "System vendor '%s' is not in the approved list, disabling PPAG.\n",
1153 dmi_get_system_info(DMI_SYS_VENDOR));
1154 mvm->fwrt.ppag_flags = 0;
1158 return iwl_mvm_ppag_send_cmd(mvm);
1161 static const struct dmi_system_id dmi_tas_approved_list[] = {
1164 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
1167 { .ident = "SAMSUNG",
1169 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD"),
1172 { .ident = "LENOVO",
1174 DMI_MATCH(DMI_SYS_VENDOR, "Lenovo"),
1179 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1187 static bool iwl_mvm_add_to_tas_block_list(__le32 *list, __le32 *le_size, unsigned int mcc)
1190 u32 size = le32_to_cpu(*le_size);
1192 /* Verify that there is room for another country */
1193 if (size >= IWL_TAS_BLOCK_LIST_MAX)
1196 for (i = 0; i < size; i++) {
1197 if (list[i] == cpu_to_le32(mcc))
1201 list[size++] = cpu_to_le32(mcc);
1202 *le_size = cpu_to_le32(size);
1206 static void iwl_mvm_tas_init(struct iwl_mvm *mvm)
1209 struct iwl_tas_config_cmd_v3 cmd = {};
1212 BUILD_BUG_ON(ARRAY_SIZE(cmd.block_list_array) <
1213 APCI_WTAS_BLACK_LIST_MAX);
1215 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TAS_CFG)) {
1216 IWL_DEBUG_RADIO(mvm, "TAS not enabled in FW\n");
1220 ret = iwl_acpi_get_tas(&mvm->fwrt, &cmd);
1222 IWL_DEBUG_RADIO(mvm,
1223 "TAS table invalid or unavailable. (%d)\n",
1231 if (!dmi_check_system(dmi_tas_approved_list)) {
1232 IWL_DEBUG_RADIO(mvm,
1233 "System vendor '%s' is not in the approved list, disabling TAS in US and Canada.\n",
1234 dmi_get_system_info(DMI_SYS_VENDOR));
1235 if ((!iwl_mvm_add_to_tas_block_list(cmd.block_list_array,
1236 &cmd.block_list_size, IWL_TAS_US_MCC)) ||
1237 (!iwl_mvm_add_to_tas_block_list(cmd.block_list_array,
1238 &cmd.block_list_size, IWL_TAS_CANADA_MCC))) {
1239 IWL_DEBUG_RADIO(mvm,
1240 "Unable to add US/Canada to TAS block list, disabling TAS\n");
1245 cmd_size = iwl_fw_lookup_cmd_ver(mvm->fw, REGULATORY_AND_NVM_GROUP,
1247 IWL_FW_CMD_VER_UNKNOWN) < 3 ?
1248 sizeof(struct iwl_tas_config_cmd_v2) :
1249 sizeof(struct iwl_tas_config_cmd_v3);
1251 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
1255 IWL_DEBUG_RADIO(mvm, "failed to send TAS_CONFIG (%d)\n", ret);
1258 static u8 iwl_mvm_eval_dsm_rfi(struct iwl_mvm *mvm)
1261 int ret = iwl_acpi_get_dsm_u8(mvm->fwrt.dev, 0, DSM_RFI_FUNC_ENABLE,
1262 &iwl_rfi_guid, &value);
1265 IWL_DEBUG_RADIO(mvm, "Failed to get DSM RFI, ret=%d\n", ret);
1267 } else if (value >= DSM_VALUE_RFI_MAX) {
1268 IWL_DEBUG_RADIO(mvm, "DSM RFI got invalid value, ret=%d\n",
1271 } else if (value == DSM_VALUE_RFI_ENABLE) {
1272 IWL_DEBUG_RADIO(mvm, "DSM RFI is evaluated to enable\n");
1273 return DSM_VALUE_RFI_ENABLE;
1276 IWL_DEBUG_RADIO(mvm, "DSM RFI is disabled\n");
1278 /* default behaviour is disabled */
1279 return DSM_VALUE_RFI_DISABLE;
1282 static void iwl_mvm_lari_cfg(struct iwl_mvm *mvm)
1286 struct iwl_lari_config_change_cmd_v5 cmd = {};
1288 cmd.config_bitmap = iwl_acpi_get_lari_config_bitmap(&mvm->fwrt);
1290 ret = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0, DSM_FUNC_11AX_ENABLEMENT,
1293 cmd.oem_11ax_allow_bitmap = cpu_to_le32(value);
1295 ret = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0,
1296 DSM_FUNC_ENABLE_UNII4_CHAN,
1299 cmd.oem_unii4_allow_bitmap = cpu_to_le32(value);
1301 ret = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0,
1302 DSM_FUNC_ACTIVATE_CHANNEL,
1305 cmd.chan_state_active_bitmap = cpu_to_le32(value);
1307 ret = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0,
1311 cmd.oem_uhb_allow_bitmap = cpu_to_le32(value);
1313 if (cmd.config_bitmap ||
1314 cmd.oem_uhb_allow_bitmap ||
1315 cmd.oem_11ax_allow_bitmap ||
1316 cmd.oem_unii4_allow_bitmap ||
1317 cmd.chan_state_active_bitmap) {
1319 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw,
1320 REGULATORY_AND_NVM_GROUP,
1321 LARI_CONFIG_CHANGE, 1);
1323 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v5);
1324 else if (cmd_ver == 4)
1325 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v4);
1326 else if (cmd_ver == 3)
1327 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v3);
1328 else if (cmd_ver == 2)
1329 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v2);
1331 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v1);
1333 IWL_DEBUG_RADIO(mvm,
1334 "sending LARI_CONFIG_CHANGE, config_bitmap=0x%x, oem_11ax_allow_bitmap=0x%x\n",
1335 le32_to_cpu(cmd.config_bitmap),
1336 le32_to_cpu(cmd.oem_11ax_allow_bitmap));
1337 IWL_DEBUG_RADIO(mvm,
1338 "sending LARI_CONFIG_CHANGE, oem_unii4_allow_bitmap=0x%x, chan_state_active_bitmap=0x%x, cmd_ver=%d\n",
1339 le32_to_cpu(cmd.oem_unii4_allow_bitmap),
1340 le32_to_cpu(cmd.chan_state_active_bitmap),
1342 IWL_DEBUG_RADIO(mvm,
1343 "sending LARI_CONFIG_CHANGE, oem_uhb_allow_bitmap=0x%x\n",
1344 le32_to_cpu(cmd.oem_uhb_allow_bitmap));
1345 ret = iwl_mvm_send_cmd_pdu(mvm,
1346 WIDE_ID(REGULATORY_AND_NVM_GROUP,
1347 LARI_CONFIG_CHANGE),
1350 IWL_DEBUG_RADIO(mvm,
1351 "Failed to send LARI_CONFIG_CHANGE (%d)\n",
1356 void iwl_mvm_get_acpi_tables(struct iwl_mvm *mvm)
1360 /* read PPAG table */
1361 ret = iwl_mvm_get_ppag_table(mvm);
1363 IWL_DEBUG_RADIO(mvm,
1364 "PPAG BIOS table invalid or unavailable. (%d)\n",
1368 /* read SAR tables */
1369 ret = iwl_sar_get_wrds_table(&mvm->fwrt);
1371 IWL_DEBUG_RADIO(mvm,
1372 "WRDS SAR BIOS table invalid or unavailable. (%d)\n",
1375 * If not available, don't fail and don't bother with EWRD and
1378 if (!iwl_sar_get_wgds_table(&mvm->fwrt)) {
1380 * If basic SAR is not available, we check for WGDS,
1381 * which should *not* be available either. If it is
1382 * available, issue an error, because we can't use SAR
1383 * Geo without basic SAR.
1385 IWL_ERR(mvm, "BIOS contains WGDS but no WRDS\n");
1389 ret = iwl_sar_get_ewrd_table(&mvm->fwrt);
1390 /* if EWRD is not available, we can still use
1391 * WRDS, so don't fail */
1393 IWL_DEBUG_RADIO(mvm,
1394 "EWRD SAR BIOS table invalid or unavailable. (%d)\n",
1397 /* read geo SAR table */
1398 if (iwl_sar_geo_support(&mvm->fwrt)) {
1399 ret = iwl_sar_get_wgds_table(&mvm->fwrt);
1401 IWL_DEBUG_RADIO(mvm,
1402 "Geo SAR BIOS table invalid or unavailable. (%d)\n",
1404 /* we don't fail if the table is not available */
1408 #else /* CONFIG_ACPI */
1410 inline int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm,
1411 int prof_a, int prof_b)
1416 inline int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
1421 static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
1426 int iwl_mvm_ppag_send_cmd(struct iwl_mvm *mvm)
1431 static int iwl_mvm_ppag_init(struct iwl_mvm *mvm)
1436 static void iwl_mvm_tas_init(struct iwl_mvm *mvm)
1440 static void iwl_mvm_lari_cfg(struct iwl_mvm *mvm)
1444 static u8 iwl_mvm_eval_dsm_rfi(struct iwl_mvm *mvm)
1446 return DSM_VALUE_RFI_DISABLE;
1449 void iwl_mvm_get_acpi_tables(struct iwl_mvm *mvm)
1453 #endif /* CONFIG_ACPI */
1455 void iwl_mvm_send_recovery_cmd(struct iwl_mvm *mvm, u32 flags)
1457 u32 error_log_size = mvm->fw->ucode_capa.error_log_size;
1461 struct iwl_fw_error_recovery_cmd recovery_cmd = {
1462 .flags = cpu_to_le32(flags),
1465 struct iwl_host_cmd host_cmd = {
1466 .id = WIDE_ID(SYSTEM_GROUP, FW_ERROR_RECOVERY_CMD),
1467 .flags = CMD_WANT_SKB,
1468 .data = {&recovery_cmd, },
1469 .len = {sizeof(recovery_cmd), },
1472 /* no error log was defined in TLV */
1473 if (!error_log_size)
1476 if (flags & ERROR_RECOVERY_UPDATE_DB) {
1477 /* no buf was allocated while HW reset */
1478 if (!mvm->error_recovery_buf)
1481 host_cmd.data[1] = mvm->error_recovery_buf;
1482 host_cmd.len[1] = error_log_size;
1483 host_cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
1484 recovery_cmd.buf_size = cpu_to_le32(error_log_size);
1487 ret = iwl_mvm_send_cmd(mvm, &host_cmd);
1488 kfree(mvm->error_recovery_buf);
1489 mvm->error_recovery_buf = NULL;
1492 IWL_ERR(mvm, "Failed to send recovery cmd %d\n", ret);
1496 /* skb respond is only relevant in ERROR_RECOVERY_UPDATE_DB */
1497 if (flags & ERROR_RECOVERY_UPDATE_DB) {
1498 resp = le32_to_cpu(*(__le32 *)host_cmd.resp_pkt->data);
1501 "Failed to send recovery cmd blob was invalid %d\n",
1506 static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
1508 return iwl_mvm_sar_select_profile(mvm, 1, 1);
1511 static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)
1515 if (iwl_mvm_has_unified_ucode(mvm))
1516 return iwl_run_unified_mvm_ucode(mvm);
1518 ret = iwl_run_init_mvm_ucode(mvm);
1521 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
1523 if (iwlmvm_mod_params.init_dbg)
1528 iwl_fw_dbg_stop_sync(&mvm->fwrt);
1529 iwl_trans_stop_device(mvm->trans);
1530 ret = iwl_trans_start_hw(mvm->trans);
1534 mvm->rfkill_safe_init_done = false;
1535 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
1539 mvm->rfkill_safe_init_done = true;
1541 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_AFTER_ALIVE,
1544 return iwl_init_paging(&mvm->fwrt, mvm->fwrt.cur_fw_img);
1547 int iwl_mvm_up(struct iwl_mvm *mvm)
1550 struct ieee80211_channel *chan;
1551 struct cfg80211_chan_def chandef;
1552 struct ieee80211_supported_band *sband = NULL;
1554 lockdep_assert_held(&mvm->mutex);
1556 ret = iwl_trans_start_hw(mvm->trans);
1560 ret = iwl_mvm_load_rt_fw(mvm);
1562 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
1563 if (ret != -ERFKILL)
1564 iwl_fw_dbg_error_collect(&mvm->fwrt,
1565 FW_DBG_TRIGGER_DRIVER);
1569 iwl_get_shared_mem_conf(&mvm->fwrt);
1571 ret = iwl_mvm_sf_update(mvm, NULL, false);
1573 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
1575 if (!iwl_trans_dbg_ini_valid(mvm->trans)) {
1576 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1577 /* if we have a destination, assume EARLY START */
1578 if (mvm->fw->dbg.dest_tlv)
1579 mvm->fwrt.dump.conf = FW_DBG_START_FROM_ALIVE;
1580 iwl_fw_start_dbg_conf(&mvm->fwrt, FW_DBG_START_FROM_ALIVE);
1583 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
1587 if (!iwl_mvm_has_unified_ucode(mvm)) {
1588 /* Send phy db control command and then phy db calibration */
1589 ret = iwl_send_phy_db_data(mvm->phy_db);
1594 ret = iwl_send_phy_cfg_cmd(mvm);
1598 ret = iwl_mvm_send_bt_init_conf(mvm);
1602 if (fw_has_capa(&mvm->fw->ucode_capa,
1603 IWL_UCODE_TLV_CAPA_SOC_LATENCY_SUPPORT)) {
1604 ret = iwl_set_soc_latency(&mvm->fwrt);
1609 /* Init RSS configuration */
1610 ret = iwl_configure_rxq(&mvm->fwrt);
1614 if (iwl_mvm_has_new_rx_api(mvm)) {
1615 ret = iwl_send_rss_cfg_cmd(mvm);
1617 IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
1623 /* init the fw <-> mac80211 STA mapping */
1624 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++)
1625 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1627 mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
1629 /* reset quota debouncing buffer - 0xff will yield invalid data */
1630 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
1632 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_DQA_SUPPORT)) {
1633 ret = iwl_mvm_send_dqa_cmd(mvm);
1639 * Add auxiliary station for scanning.
1640 * Newer versions of this command implies that the fw uses
1641 * internal aux station for all aux activities that don't
1642 * requires a dedicated data queue.
1644 if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
1648 * In old version the aux station uses mac id like other
1649 * station and not lmac id
1651 ret = iwl_mvm_add_aux_sta(mvm, MAC_INDEX_AUX);
1656 /* Add all the PHY contexts */
1658 while (!sband && i < NUM_NL80211_BANDS)
1659 sband = mvm->hw->wiphy->bands[i++];
1661 if (WARN_ON_ONCE(!sband))
1664 chan = &sband->channels[0];
1666 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
1667 for (i = 0; i < NUM_PHY_CTX; i++) {
1669 * The channel used here isn't relevant as it's
1670 * going to be overwritten in the other flows.
1671 * For now use the first channel we have.
1673 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
1679 if (iwl_mvm_is_tt_in_fw(mvm)) {
1680 /* in order to give the responsibility of ct-kill and
1681 * TX backoff to FW we need to send empty temperature reporting
1682 * cmd during init time
1684 iwl_mvm_send_temp_report_ths_cmd(mvm);
1686 /* Initialize tx backoffs to the minimal possible */
1687 iwl_mvm_tt_tx_backoff(mvm, 0);
1690 #ifdef CONFIG_THERMAL
1691 /* TODO: read the budget from BIOS / Platform NVM */
1694 * In case there is no budget from BIOS / Platform NVM the default
1695 * budget should be 2000mW (cooling state 0).
1697 if (iwl_mvm_is_ctdp_supported(mvm)) {
1698 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
1699 mvm->cooling_dev.cur_state);
1705 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_SET_LTR_GEN2))
1706 WARN_ON(iwl_mvm_config_ltr(mvm));
1708 ret = iwl_mvm_power_update_device(mvm);
1712 iwl_mvm_lari_cfg(mvm);
1714 * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
1715 * anyway, so don't init MCC.
1717 if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
1718 ret = iwl_mvm_init_mcc(mvm);
1723 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1724 mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
1725 mvm->hb_scan_type = IWL_SCAN_TYPE_NOT_SET;
1726 ret = iwl_mvm_config_scan(mvm);
1731 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1732 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_UPDATE_DB);
1734 if (iwl_acpi_get_eckv(mvm->dev, &mvm->ext_clock_valid))
1735 IWL_DEBUG_INFO(mvm, "ECKV table doesn't exist in BIOS\n");
1737 ret = iwl_mvm_ppag_init(mvm);
1741 ret = iwl_mvm_sar_init(mvm);
1743 ret = iwl_mvm_sar_geo_init(mvm);
1747 ret = iwl_mvm_sgom_init(mvm);
1751 iwl_mvm_tas_init(mvm);
1752 iwl_mvm_leds_sync(mvm);
1754 iwl_mvm_ftm_initiator_smooth_config(mvm);
1756 if (fw_has_capa(&mvm->fw->ucode_capa,
1757 IWL_UCODE_TLV_CAPA_RFIM_SUPPORT)) {
1758 if (iwl_mvm_eval_dsm_rfi(mvm) == DSM_VALUE_RFI_ENABLE)
1759 iwl_rfi_send_config_cmd(mvm, NULL);
1762 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
1765 if (!iwlmvm_mod_params.init_dbg || !ret)
1766 iwl_mvm_stop_device(mvm);
1770 int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
1774 lockdep_assert_held(&mvm->mutex);
1776 ret = iwl_trans_start_hw(mvm->trans);
1780 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
1782 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
1786 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
1790 /* Send phy db control command and then phy db calibration*/
1791 ret = iwl_send_phy_db_data(mvm->phy_db);
1795 ret = iwl_send_phy_cfg_cmd(mvm);
1799 /* init the fw <-> mac80211 STA mapping */
1800 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++)
1801 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1803 if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
1807 * Add auxiliary station for scanning.
1808 * Newer versions of this command implies that the fw uses
1809 * internal aux station for all aux activities that don't
1810 * requires a dedicated data queue.
1811 * In old version the aux station uses mac id like other
1812 * station and not lmac id
1814 ret = iwl_mvm_add_aux_sta(mvm, MAC_INDEX_AUX);
1821 iwl_mvm_stop_device(mvm);
1825 void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1826 struct iwl_rx_cmd_buffer *rxb)
1828 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1829 struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
1832 "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
1833 le32_to_cpu(mfuart_notif->installed_ver),
1834 le32_to_cpu(mfuart_notif->external_ver),
1835 le32_to_cpu(mfuart_notif->status),
1836 le32_to_cpu(mfuart_notif->duration));
1838 if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif))
1840 "MFUART: image size: 0x%08x\n",
1841 le32_to_cpu(mfuart_notif->image_size));