1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2018-2022 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 IWL_PPAG_MASK 3
29 #define IWL_PPAG_ETSI_MASK BIT(0)
31 #define IWL_TAS_US_MCC 0x5553
32 #define IWL_TAS_CANADA_MCC 0x4341
34 struct iwl_mvm_alive_data {
39 static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
41 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
42 .valid = cpu_to_le32(valid_tx_ant),
45 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
46 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
47 sizeof(tx_ant_cmd), &tx_ant_cmd);
50 static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm)
53 struct iwl_rss_config_cmd cmd = {
54 .flags = cpu_to_le32(IWL_RSS_ENABLE),
55 .hash_mask = BIT(IWL_RSS_HASH_TYPE_IPV4_TCP) |
56 BIT(IWL_RSS_HASH_TYPE_IPV4_UDP) |
57 BIT(IWL_RSS_HASH_TYPE_IPV4_PAYLOAD) |
58 BIT(IWL_RSS_HASH_TYPE_IPV6_TCP) |
59 BIT(IWL_RSS_HASH_TYPE_IPV6_UDP) |
60 BIT(IWL_RSS_HASH_TYPE_IPV6_PAYLOAD),
63 if (mvm->trans->num_rx_queues == 1)
66 /* Do not direct RSS traffic to Q 0 which is our fallback queue */
67 for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++)
68 cmd.indirection_table[i] =
69 1 + (i % (mvm->trans->num_rx_queues - 1));
70 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
72 return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
75 static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm)
77 struct iwl_dqa_enable_cmd dqa_cmd = {
78 .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE),
80 u32 cmd_id = WIDE_ID(DATA_PATH_GROUP, DQA_ENABLE_CMD);
83 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd);
85 IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret);
87 IWL_DEBUG_FW(mvm, "Working in DQA mode\n");
92 void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
93 struct iwl_rx_cmd_buffer *rxb)
95 struct iwl_rx_packet *pkt = rxb_addr(rxb);
96 struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data;
97 __le32 *dump_data = mfu_dump_notif->data;
98 int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32);
101 if (mfu_dump_notif->index_num == 0)
102 IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n",
103 le32_to_cpu(mfu_dump_notif->assert_id));
105 for (i = 0; i < n_words; i++)
107 "MFUART assert dump, dword %u: 0x%08x\n",
108 le16_to_cpu(mfu_dump_notif->index_num) *
110 le32_to_cpu(dump_data[i]));
113 static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
114 struct iwl_rx_packet *pkt, void *data)
116 unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
117 struct iwl_mvm *mvm =
118 container_of(notif_wait, struct iwl_mvm, notif_wait);
119 struct iwl_mvm_alive_data *alive_data = data;
120 struct iwl_umac_alive *umac;
121 struct iwl_lmac_alive *lmac1;
122 struct iwl_lmac_alive *lmac2 = NULL;
124 u32 lmac_error_event_table, umac_error_table;
125 u32 version = iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
126 UCODE_ALIVE_NTFY, 0);
129 struct iwl_alive_ntf_v6 *palive;
131 if (pkt_len < sizeof(*palive))
134 palive = (void *)pkt->data;
135 mvm->trans->dbg.imr_data.imr_enable =
136 le32_to_cpu(palive->imr.enabled);
137 mvm->trans->dbg.imr_data.imr_size =
138 le32_to_cpu(palive->imr.size);
139 mvm->trans->dbg.imr_data.imr2sram_remainbyte =
140 mvm->trans->dbg.imr_data.imr_size;
141 mvm->trans->dbg.imr_data.imr_base_addr =
142 palive->imr.base_addr;
143 mvm->trans->dbg.imr_data.imr_curr_addr =
144 le64_to_cpu(mvm->trans->dbg.imr_data.imr_base_addr);
145 IWL_DEBUG_FW(mvm, "IMR Enabled: 0x0%x size 0x0%x Address 0x%016llx\n",
146 mvm->trans->dbg.imr_data.imr_enable,
147 mvm->trans->dbg.imr_data.imr_size,
148 le64_to_cpu(mvm->trans->dbg.imr_data.imr_base_addr));
152 struct iwl_alive_ntf_v5 *palive;
154 if (pkt_len < sizeof(*palive))
157 palive = (void *)pkt->data;
158 umac = &palive->umac_data;
159 lmac1 = &palive->lmac_data[0];
160 lmac2 = &palive->lmac_data[1];
161 status = le16_to_cpu(palive->status);
163 mvm->trans->sku_id[0] = le32_to_cpu(palive->sku_id.data[0]);
164 mvm->trans->sku_id[1] = le32_to_cpu(palive->sku_id.data[1]);
165 mvm->trans->sku_id[2] = le32_to_cpu(palive->sku_id.data[2]);
167 IWL_DEBUG_FW(mvm, "Got sku_id: 0x0%x 0x0%x 0x0%x\n",
168 mvm->trans->sku_id[0],
169 mvm->trans->sku_id[1],
170 mvm->trans->sku_id[2]);
171 } else if (iwl_rx_packet_payload_len(pkt) == sizeof(struct iwl_alive_ntf_v4)) {
172 struct iwl_alive_ntf_v4 *palive;
174 if (pkt_len < sizeof(*palive))
177 palive = (void *)pkt->data;
178 umac = &palive->umac_data;
179 lmac1 = &palive->lmac_data[0];
180 lmac2 = &palive->lmac_data[1];
181 status = le16_to_cpu(palive->status);
182 } else if (iwl_rx_packet_payload_len(pkt) ==
183 sizeof(struct iwl_alive_ntf_v3)) {
184 struct iwl_alive_ntf_v3 *palive3;
186 if (pkt_len < sizeof(*palive3))
189 palive3 = (void *)pkt->data;
190 umac = &palive3->umac_data;
191 lmac1 = &palive3->lmac_data;
192 status = le16_to_cpu(palive3->status);
194 WARN(1, "unsupported alive notification (size %d)\n",
195 iwl_rx_packet_payload_len(pkt));
196 /* get timeout later */
200 lmac_error_event_table =
201 le32_to_cpu(lmac1->dbg_ptrs.error_event_table_ptr);
202 iwl_fw_lmac1_set_alive_err_table(mvm->trans, lmac_error_event_table);
205 mvm->trans->dbg.lmac_error_event_table[1] =
206 le32_to_cpu(lmac2->dbg_ptrs.error_event_table_ptr);
208 umac_error_table = le32_to_cpu(umac->dbg_ptrs.error_info_addr) &
209 ~FW_ADDR_CACHE_CONTROL;
211 if (umac_error_table) {
212 if (umac_error_table >=
213 mvm->trans->cfg->min_umac_error_event_table) {
214 iwl_fw_umac_set_alive_err_table(mvm->trans,
218 "Not valid error log pointer 0x%08X for %s uCode\n",
220 (mvm->fwrt.cur_fw_img == IWL_UCODE_INIT) ?
225 alive_data->scd_base_addr = le32_to_cpu(lmac1->dbg_ptrs.scd_base_ptr);
226 alive_data->valid = status == IWL_ALIVE_STATUS_OK;
229 "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n",
230 status, lmac1->ver_type, lmac1->ver_subtype);
233 IWL_DEBUG_FW(mvm, "Alive ucode CDB\n");
236 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
237 le32_to_cpu(umac->umac_major),
238 le32_to_cpu(umac->umac_minor));
240 iwl_fwrt_update_fw_versions(&mvm->fwrt, lmac1, umac);
245 static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait,
246 struct iwl_rx_packet *pkt, void *data)
248 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
253 static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
254 struct iwl_rx_packet *pkt, void *data)
256 struct iwl_phy_db *phy_db = data;
258 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
259 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
263 WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
268 static void iwl_mvm_print_pd_notification(struct iwl_mvm *mvm)
270 struct iwl_trans *trans = mvm->trans;
271 enum iwl_device_family device_family = trans->trans_cfg->device_family;
273 if (device_family < IWL_DEVICE_FAMILY_8000)
276 if (device_family <= IWL_DEVICE_FAMILY_9000)
277 IWL_ERR(mvm, "WFPM_ARC1_PD_NOTIFICATION: 0x%x\n",
278 iwl_read_umac_prph(trans, WFPM_ARC1_PD_NOTIFICATION));
280 IWL_ERR(mvm, "WFPM_LMAC1_PD_NOTIFICATION: 0x%x\n",
281 iwl_read_umac_prph(trans, WFPM_LMAC1_PD_NOTIFICATION));
283 IWL_ERR(mvm, "HPM_SECONDARY_DEVICE_STATE: 0x%x\n",
284 iwl_read_umac_prph(trans, HPM_SECONDARY_DEVICE_STATE));
288 static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
289 enum iwl_ucode_type ucode_type)
291 struct iwl_notification_wait alive_wait;
292 struct iwl_mvm_alive_data alive_data = {};
293 const struct fw_img *fw;
295 enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img;
296 static const u16 alive_cmd[] = { UCODE_ALIVE_NTFY };
298 ucode_type == IWL_UCODE_INIT || iwl_mvm_has_unified_ucode(mvm);
300 if (ucode_type == IWL_UCODE_REGULAR &&
301 iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
302 !(fw_has_capa(&mvm->fw->ucode_capa,
303 IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
304 fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER);
306 fw = iwl_get_ucode_image(mvm->fw, ucode_type);
309 iwl_fw_set_current_image(&mvm->fwrt, ucode_type);
310 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
312 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
313 alive_cmd, ARRAY_SIZE(alive_cmd),
314 iwl_alive_fn, &alive_data);
317 * We want to load the INIT firmware even in RFKILL
318 * For the unified firmware case, the ucode_type is not
319 * INIT, but we still need to run it.
321 ret = iwl_trans_start_fw(mvm->trans, fw, run_in_rfkill);
323 iwl_fw_set_current_image(&mvm->fwrt, old_type);
324 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
329 * Some things may run in the background now, but we
330 * just wait for the ALIVE notification here.
332 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
333 MVM_UCODE_ALIVE_TIMEOUT);
335 struct iwl_trans *trans = mvm->trans;
338 if (trans->trans_cfg->device_family >=
339 IWL_DEVICE_FAMILY_22000) {
341 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
342 iwl_read_umac_prph(trans, UMAG_SB_CPU_1_STATUS),
343 iwl_read_umac_prph(trans,
344 UMAG_SB_CPU_2_STATUS));
345 } else if (trans->trans_cfg->device_family >=
346 IWL_DEVICE_FAMILY_8000) {
348 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
349 iwl_read_prph(trans, SB_CPU_1_STATUS),
350 iwl_read_prph(trans, SB_CPU_2_STATUS));
353 iwl_mvm_print_pd_notification(mvm);
355 /* LMAC/UMAC PC info */
356 if (trans->trans_cfg->device_family >=
357 IWL_DEVICE_FAMILY_9000) {
358 IWL_ERR(mvm, "UMAC PC: 0x%x\n",
359 iwl_read_umac_prph(trans,
360 UREG_UMAC_CURRENT_PC));
361 IWL_ERR(mvm, "LMAC PC: 0x%x\n",
362 iwl_read_umac_prph(trans,
363 UREG_LMAC1_CURRENT_PC));
364 if (iwl_mvm_is_cdb_supported(mvm))
365 IWL_ERR(mvm, "LMAC2 PC: 0x%x\n",
366 iwl_read_umac_prph(trans,
367 UREG_LMAC2_CURRENT_PC));
370 if (ret == -ETIMEDOUT)
371 iwl_fw_dbg_error_collect(&mvm->fwrt,
372 FW_DBG_TRIGGER_ALIVE_TIMEOUT);
374 iwl_fw_set_current_image(&mvm->fwrt, old_type);
378 if (!alive_data.valid) {
379 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
380 iwl_fw_set_current_image(&mvm->fwrt, old_type);
384 ret = iwl_pnvm_load(mvm->trans, &mvm->notif_wait);
386 IWL_ERR(mvm, "Timeout waiting for PNVM load!\n");
387 iwl_fw_set_current_image(&mvm->fwrt, old_type);
391 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
394 * Note: all the queues are enabled as part of the interface
395 * initialization, but in firmware restart scenarios they
396 * could be stopped, so wake them up. In firmware restart,
397 * mac80211 will have the queues stopped as well until the
398 * reconfiguration completes. During normal startup, they
402 memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
404 * Set a 'fake' TID for the command queue, since we use the
405 * hweight() of the tid_bitmap as a refcount now. Not that
406 * we ever even consider the command queue as one we might
407 * want to reuse, but be safe nevertheless.
409 mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].tid_bitmap =
410 BIT(IWL_MAX_TID_COUNT + 2);
412 set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
413 #ifdef CONFIG_IWLWIFI_DEBUGFS
414 iwl_fw_set_dbg_rec_on(&mvm->fwrt);
418 * All the BSSes in the BSS table include the GP2 in the system
419 * at the beacon Rx time, this is of course no longer relevant
420 * since we are resetting the firmware.
421 * Purge all the BSS table.
423 cfg80211_bss_flush(mvm->hw->wiphy);
428 static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm)
430 struct iwl_notification_wait init_wait;
431 struct iwl_nvm_access_complete_cmd nvm_complete = {};
432 struct iwl_init_extended_cfg_cmd init_cfg = {
433 .init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)),
435 static const u16 init_complete[] = {
440 if (mvm->trans->cfg->tx_with_siso_diversity)
441 init_cfg.init_flags |= cpu_to_le32(BIT(IWL_INIT_PHY));
443 lockdep_assert_held(&mvm->mutex);
445 mvm->rfkill_safe_init_done = false;
447 iwl_init_notification_wait(&mvm->notif_wait,
450 ARRAY_SIZE(init_complete),
451 iwl_wait_init_complete,
454 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_EARLY, NULL);
456 /* Will also start the device */
457 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
459 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
462 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_AFTER_ALIVE,
465 /* Send init config command to mark that we are sending NVM access
468 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP,
469 INIT_EXTENDED_CFG_CMD),
471 sizeof(init_cfg), &init_cfg);
473 IWL_ERR(mvm, "Failed to run init config command: %d\n",
478 /* Load NVM to NIC if needed */
479 if (mvm->nvm_file_name) {
480 ret = iwl_read_external_nvm(mvm->trans, mvm->nvm_file_name,
484 ret = iwl_mvm_load_nvm_to_nic(mvm);
489 if (IWL_MVM_PARSE_NVM && !mvm->nvm_data) {
490 ret = iwl_nvm_init(mvm);
492 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
497 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
498 NVM_ACCESS_COMPLETE),
500 sizeof(nvm_complete), &nvm_complete);
502 IWL_ERR(mvm, "Failed to run complete NVM access: %d\n",
507 /* We wait for the INIT complete notification */
508 ret = iwl_wait_notification(&mvm->notif_wait, &init_wait,
509 MVM_UCODE_ALIVE_TIMEOUT);
513 /* Read the NVM only at driver load time, no need to do this twice */
514 if (!IWL_MVM_PARSE_NVM && !mvm->nvm_data) {
515 mvm->nvm_data = iwl_get_nvm(mvm->trans, mvm->fw);
516 if (IS_ERR(mvm->nvm_data)) {
517 ret = PTR_ERR(mvm->nvm_data);
518 mvm->nvm_data = NULL;
519 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
524 mvm->rfkill_safe_init_done = true;
529 iwl_remove_notification(&mvm->notif_wait, &init_wait);
534 static void iwl_mvm_phy_filter_init(struct iwl_mvm *mvm,
535 struct iwl_phy_specific_cfg *phy_filters)
538 * TODO: read specific phy config from BIOS
539 * ACPI table for this feature has not been defined yet,
540 * so for now we use hardcoded values.
543 if (IWL_MVM_PHY_FILTER_CHAIN_A) {
544 phy_filters->filter_cfg_chain_a =
545 cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_A);
547 if (IWL_MVM_PHY_FILTER_CHAIN_B) {
548 phy_filters->filter_cfg_chain_b =
549 cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_B);
551 if (IWL_MVM_PHY_FILTER_CHAIN_C) {
552 phy_filters->filter_cfg_chain_c =
553 cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_C);
555 if (IWL_MVM_PHY_FILTER_CHAIN_D) {
556 phy_filters->filter_cfg_chain_d =
557 cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_D);
560 #else /* CONFIG_ACPI */
562 static void iwl_mvm_phy_filter_init(struct iwl_mvm *mvm,
563 struct iwl_phy_specific_cfg *phy_filters)
566 #endif /* CONFIG_ACPI */
568 #if defined(CONFIG_ACPI) && defined(CONFIG_EFI)
569 static int iwl_mvm_sgom_init(struct iwl_mvm *mvm)
573 struct iwl_host_cmd cmd = {
574 .id = WIDE_ID(REGULATORY_AND_NVM_GROUP,
575 SAR_OFFSET_MAPPING_TABLE_CMD),
577 .data[0] = &mvm->fwrt.sgom_table,
578 .len[0] = sizeof(mvm->fwrt.sgom_table),
579 .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
582 if (!mvm->fwrt.sgom_enabled) {
583 IWL_DEBUG_RADIO(mvm, "SGOM table is disabled\n");
587 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd.id,
588 IWL_FW_CMD_VER_UNKNOWN);
591 IWL_DEBUG_RADIO(mvm, "command version is unsupported. version = %d\n",
596 ret = iwl_mvm_send_cmd(mvm, &cmd);
598 IWL_ERR(mvm, "failed to send SAR_OFFSET_MAPPING_CMD (%d)\n", ret);
604 static int iwl_mvm_sgom_init(struct iwl_mvm *mvm)
610 static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
612 u32 cmd_id = PHY_CONFIGURATION_CMD;
613 struct iwl_phy_cfg_cmd_v3 phy_cfg_cmd;
614 enum iwl_ucode_type ucode_type = mvm->fwrt.cur_fw_img;
615 struct iwl_phy_specific_cfg phy_filters = {};
619 if (iwl_mvm_has_unified_ucode(mvm) &&
620 !mvm->trans->cfg->tx_with_siso_diversity)
623 if (mvm->trans->cfg->tx_with_siso_diversity) {
625 * TODO: currently we don't set the antenna but letting the NIC
626 * to decide which antenna to use. This should come from BIOS.
628 phy_cfg_cmd.phy_cfg =
629 cpu_to_le32(FW_PHY_CFG_CHAIN_SAD_ENABLED);
633 phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
635 /* set flags extra PHY configuration flags from the device's cfg */
636 phy_cfg_cmd.phy_cfg |=
637 cpu_to_le32(mvm->trans->trans_cfg->extra_phy_cfg_flags);
639 phy_cfg_cmd.calib_control.event_trigger =
640 mvm->fw->default_calib[ucode_type].event_trigger;
641 phy_cfg_cmd.calib_control.flow_trigger =
642 mvm->fw->default_calib[ucode_type].flow_trigger;
644 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
645 IWL_FW_CMD_VER_UNKNOWN);
647 iwl_mvm_phy_filter_init(mvm, &phy_filters);
648 memcpy(&phy_cfg_cmd.phy_specific_cfg, &phy_filters,
649 sizeof(struct iwl_phy_specific_cfg));
652 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
653 phy_cfg_cmd.phy_cfg);
654 cmd_size = (cmd_ver == 3) ? sizeof(struct iwl_phy_cfg_cmd_v3) :
655 sizeof(struct iwl_phy_cfg_cmd_v1);
656 return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, cmd_size, &phy_cfg_cmd);
659 int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm)
661 struct iwl_notification_wait calib_wait;
662 static const u16 init_complete[] = {
664 CALIB_RES_NOTIF_PHY_DB
668 if (iwl_mvm_has_unified_ucode(mvm))
669 return iwl_run_unified_mvm_ucode(mvm);
671 lockdep_assert_held(&mvm->mutex);
673 mvm->rfkill_safe_init_done = false;
675 iwl_init_notification_wait(&mvm->notif_wait,
678 ARRAY_SIZE(init_complete),
679 iwl_wait_phy_db_entry,
682 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_EARLY, NULL);
684 /* Will also start the device */
685 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
687 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
691 if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_8000) {
692 ret = iwl_mvm_send_bt_init_conf(mvm);
697 /* Read the NVM only at driver load time, no need to do this twice */
698 if (!mvm->nvm_data) {
699 ret = iwl_nvm_init(mvm);
701 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
706 /* In case we read the NVM from external file, load it to the NIC */
707 if (mvm->nvm_file_name) {
708 ret = iwl_mvm_load_nvm_to_nic(mvm);
713 WARN_ONCE(mvm->nvm_data->nvm_version < mvm->trans->cfg->nvm_ver,
714 "Too old NVM version (0x%0x, required = 0x%0x)",
715 mvm->nvm_data->nvm_version, mvm->trans->cfg->nvm_ver);
718 * abort after reading the nvm in case RF Kill is on, we will complete
719 * the init seq later when RF kill will switch to off
721 if (iwl_mvm_is_radio_hw_killed(mvm)) {
722 IWL_DEBUG_RF_KILL(mvm,
723 "jump over all phy activities due to RF kill\n");
727 mvm->rfkill_safe_init_done = true;
729 /* Send TX valid antennas before triggering calibrations */
730 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
734 ret = iwl_send_phy_cfg_cmd(mvm);
736 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
742 * Some things may run in the background now, but we
743 * just wait for the calibration complete notification.
745 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
746 MVM_UCODE_CALIB_TIMEOUT);
750 if (iwl_mvm_is_radio_hw_killed(mvm)) {
751 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
754 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
761 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
763 mvm->rfkill_safe_init_done = false;
764 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
765 /* we want to debug INIT and we have no NVM - fake */
766 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
767 sizeof(struct ieee80211_channel) +
768 sizeof(struct ieee80211_rate),
772 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
773 mvm->nvm_data->bands[0].n_channels = 1;
774 mvm->nvm_data->bands[0].n_bitrates = 1;
775 mvm->nvm_data->bands[0].bitrates =
776 (void *)(mvm->nvm_data->channels + 1);
777 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
783 static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
785 struct iwl_ltr_config_cmd cmd = {
786 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
789 if (!mvm->trans->ltr_enabled)
792 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
797 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b)
799 u32 cmd_id = REDUCE_TX_POWER_CMD;
800 struct iwl_dev_tx_power_cmd cmd = {
801 .common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
807 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
808 IWL_FW_CMD_VER_UNKNOWN);
811 len = sizeof(cmd.v6);
812 n_subbands = IWL_NUM_SUB_BANDS_V2;
813 per_chain = cmd.v6.per_chain[0][0];
814 } else if (fw_has_api(&mvm->fw->ucode_capa,
815 IWL_UCODE_TLV_API_REDUCE_TX_POWER)) {
816 len = sizeof(cmd.v5);
817 n_subbands = IWL_NUM_SUB_BANDS_V1;
818 per_chain = cmd.v5.per_chain[0][0];
819 } else if (fw_has_capa(&mvm->fw->ucode_capa,
820 IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) {
821 len = sizeof(cmd.v4);
822 n_subbands = IWL_NUM_SUB_BANDS_V1;
823 per_chain = cmd.v4.per_chain[0][0];
825 len = sizeof(cmd.v3);
826 n_subbands = IWL_NUM_SUB_BANDS_V1;
827 per_chain = cmd.v3.per_chain[0][0];
830 /* all structs have the same common part, add it */
831 len += sizeof(cmd.common);
833 ret = iwl_sar_select_profile(&mvm->fwrt, per_chain,
834 IWL_NUM_CHAIN_TABLES,
835 n_subbands, prof_a, prof_b);
837 /* return on error or if the profile is disabled (positive number) */
841 iwl_mei_set_power_limit(per_chain);
843 IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
844 return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd);
847 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
849 union iwl_geo_tx_power_profiles_cmd geo_tx_cmd;
850 struct iwl_geo_tx_power_profiles_resp *resp;
853 struct iwl_host_cmd cmd = {
854 .id = WIDE_ID(PHY_OPS_GROUP, PER_CHAIN_LIMIT_OFFSET_CMD),
855 .flags = CMD_WANT_SKB,
856 .data = { &geo_tx_cmd },
858 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd.id,
859 IWL_FW_CMD_VER_UNKNOWN);
861 /* the ops field is at the same spot for all versions, so set in v1 */
863 cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE);
866 len = sizeof(geo_tx_cmd.v5);
867 else if (cmd_ver == 4)
868 len = sizeof(geo_tx_cmd.v4);
869 else if (cmd_ver == 3)
870 len = sizeof(geo_tx_cmd.v3);
871 else if (fw_has_api(&mvm->fwrt.fw->ucode_capa,
872 IWL_UCODE_TLV_API_SAR_TABLE_VER))
873 len = sizeof(geo_tx_cmd.v2);
875 len = sizeof(geo_tx_cmd.v1);
877 if (!iwl_sar_geo_support(&mvm->fwrt))
882 ret = iwl_mvm_send_cmd(mvm, &cmd);
884 IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret);
888 resp = (void *)cmd.resp_pkt->data;
889 ret = le32_to_cpu(resp->profile_idx);
891 if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES_REV3))
898 static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
900 u32 cmd_id = WIDE_ID(PHY_OPS_GROUP, PER_CHAIN_LIMIT_OFFSET_CMD);
901 union iwl_geo_tx_power_profiles_cmd cmd;
907 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
908 IWL_FW_CMD_VER_UNKNOWN);
910 BUILD_BUG_ON(offsetof(struct iwl_geo_tx_power_profiles_cmd_v1, ops) !=
911 offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, ops) ||
912 offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, ops) !=
913 offsetof(struct iwl_geo_tx_power_profiles_cmd_v3, ops) ||
914 offsetof(struct iwl_geo_tx_power_profiles_cmd_v3, ops) !=
915 offsetof(struct iwl_geo_tx_power_profiles_cmd_v4, ops) ||
916 offsetof(struct iwl_geo_tx_power_profiles_cmd_v4, ops) !=
917 offsetof(struct iwl_geo_tx_power_profiles_cmd_v5, ops));
919 /* the ops field is at the same spot for all versions, so set in v1 */
920 cmd.v1.ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES);
923 len = sizeof(cmd.v5);
924 n_bands = ARRAY_SIZE(cmd.v5.table[0]);
925 n_profiles = ACPI_NUM_GEO_PROFILES_REV3;
926 } else if (cmd_ver == 4) {
927 len = sizeof(cmd.v4);
928 n_bands = ARRAY_SIZE(cmd.v4.table[0]);
929 n_profiles = ACPI_NUM_GEO_PROFILES_REV3;
930 } else if (cmd_ver == 3) {
931 len = sizeof(cmd.v3);
932 n_bands = ARRAY_SIZE(cmd.v3.table[0]);
933 n_profiles = ACPI_NUM_GEO_PROFILES;
934 } else if (fw_has_api(&mvm->fwrt.fw->ucode_capa,
935 IWL_UCODE_TLV_API_SAR_TABLE_VER)) {
936 len = sizeof(cmd.v2);
937 n_bands = ARRAY_SIZE(cmd.v2.table[0]);
938 n_profiles = ACPI_NUM_GEO_PROFILES;
940 len = sizeof(cmd.v1);
941 n_bands = ARRAY_SIZE(cmd.v1.table[0]);
942 n_profiles = ACPI_NUM_GEO_PROFILES;
945 BUILD_BUG_ON(offsetof(struct iwl_geo_tx_power_profiles_cmd_v1, table) !=
946 offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, table) ||
947 offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, table) !=
948 offsetof(struct iwl_geo_tx_power_profiles_cmd_v3, table) ||
949 offsetof(struct iwl_geo_tx_power_profiles_cmd_v3, table) !=
950 offsetof(struct iwl_geo_tx_power_profiles_cmd_v4, table) ||
951 offsetof(struct iwl_geo_tx_power_profiles_cmd_v4, table) !=
952 offsetof(struct iwl_geo_tx_power_profiles_cmd_v5, table));
953 /* the table is at the same position for all versions, so set use v1 */
954 ret = iwl_sar_geo_init(&mvm->fwrt, &cmd.v1.table[0][0],
955 n_bands, n_profiles);
958 * It is a valid scenario to not support SAR, or miss wgds table,
959 * but in that case there is no need to send the command.
964 /* Only set to South Korea if the table revision is 1 */
965 if (mvm->fwrt.geo_rev == 1)
969 * Set the table_revision to South Korea (1) or not (0). The
970 * element name is misleading, as it doesn't contain the table
971 * revision number, but whether the South Korea variation
973 * This must be done after calling iwl_sar_geo_init().
976 cmd.v5.table_revision = cpu_to_le32(sk);
977 else if (cmd_ver == 4)
978 cmd.v4.table_revision = cpu_to_le32(sk);
979 else if (cmd_ver == 3)
980 cmd.v3.table_revision = cpu_to_le32(sk);
981 else if (fw_has_api(&mvm->fwrt.fw->ucode_capa,
982 IWL_UCODE_TLV_API_SAR_TABLE_VER))
983 cmd.v2.table_revision = cpu_to_le32(sk);
985 return iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, len, &cmd);
988 static int iwl_mvm_get_ppag_table(struct iwl_mvm *mvm)
990 union acpi_object *wifi_pkg, *data, *flags;
991 int i, j, ret, tbl_rev, num_sub_bands;
994 mvm->fwrt.ppag_flags = 0;
996 data = iwl_acpi_get_object(mvm->dev, ACPI_PPAG_METHOD);
998 return PTR_ERR(data);
1000 /* try to read ppag table rev 2 or 1 (both have the same data size) */
1001 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
1002 ACPI_PPAG_WIFI_DATA_SIZE_V2, &tbl_rev);
1003 if (!IS_ERR(wifi_pkg)) {
1004 if (tbl_rev == 1 || tbl_rev == 2) {
1005 num_sub_bands = IWL_NUM_SUB_BANDS_V2;
1006 IWL_DEBUG_RADIO(mvm,
1007 "Reading PPAG table v2 (tbl_rev=%d)\n",
1016 /* try to read ppag table revision 0 */
1017 wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
1018 ACPI_PPAG_WIFI_DATA_SIZE_V1, &tbl_rev);
1019 if (!IS_ERR(wifi_pkg)) {
1024 num_sub_bands = IWL_NUM_SUB_BANDS_V1;
1025 IWL_DEBUG_RADIO(mvm, "Reading PPAG table v1 (tbl_rev=0)\n");
1028 ret = PTR_ERR(wifi_pkg);
1032 mvm->fwrt.ppag_ver = tbl_rev;
1033 flags = &wifi_pkg->package.elements[1];
1035 if (flags->type != ACPI_TYPE_INTEGER) {
1040 mvm->fwrt.ppag_flags = flags->integer.value & IWL_PPAG_MASK;
1042 if (!mvm->fwrt.ppag_flags) {
1048 * read, verify gain values and save them into the PPAG table.
1049 * first sub-band (j=0) corresponds to Low-Band (2.4GHz), and the
1050 * following sub-bands to High-Band (5GHz).
1052 for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) {
1053 for (j = 0; j < num_sub_bands; j++) {
1054 union acpi_object *ent;
1056 ent = &wifi_pkg->package.elements[idx++];
1057 if (ent->type != ACPI_TYPE_INTEGER) {
1062 mvm->fwrt.ppag_chains[i].subbands[j] = ent->integer.value;
1065 (mvm->fwrt.ppag_chains[i].subbands[j] > ACPI_PPAG_MAX_LB ||
1066 mvm->fwrt.ppag_chains[i].subbands[j] < ACPI_PPAG_MIN_LB)) ||
1068 (mvm->fwrt.ppag_chains[i].subbands[j] > ACPI_PPAG_MAX_HB ||
1069 mvm->fwrt.ppag_chains[i].subbands[j] < ACPI_PPAG_MIN_HB))) {
1070 mvm->fwrt.ppag_flags = 0;
1083 int iwl_mvm_ppag_send_cmd(struct iwl_mvm *mvm)
1085 union iwl_ppag_table_cmd cmd;
1087 int i, j, ret, num_sub_bands, cmd_size;
1090 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_SET_PPAG)) {
1091 IWL_DEBUG_RADIO(mvm,
1092 "PPAG capability not supported by FW, command not sent.\n");
1095 if (!mvm->fwrt.ppag_flags) {
1096 IWL_DEBUG_RADIO(mvm, "PPAG not enabled, command not sent.\n");
1100 /* The 'flags' field is the same in v1 and in v2 so we can just
1101 * use v1 to access it.
1103 cmd.v1.flags = cpu_to_le32(mvm->fwrt.ppag_flags);
1104 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw,
1105 WIDE_ID(PHY_OPS_GROUP, PER_PLATFORM_ANT_GAIN_CMD),
1106 IWL_FW_CMD_VER_UNKNOWN);
1108 num_sub_bands = IWL_NUM_SUB_BANDS_V1;
1109 gain = cmd.v1.gain[0];
1110 cmd_size = sizeof(cmd.v1);
1111 if (mvm->fwrt.ppag_ver == 1 || mvm->fwrt.ppag_ver == 2) {
1112 IWL_DEBUG_RADIO(mvm,
1113 "PPAG table rev is %d but FW supports v1, sending truncated table\n",
1114 mvm->fwrt.ppag_ver);
1115 cmd.v1.flags &= cpu_to_le32(IWL_PPAG_ETSI_MASK);
1117 } else if (cmd_ver == 2 || cmd_ver == 3) {
1118 num_sub_bands = IWL_NUM_SUB_BANDS_V2;
1119 gain = cmd.v2.gain[0];
1120 cmd_size = sizeof(cmd.v2);
1121 if (mvm->fwrt.ppag_ver == 0) {
1122 IWL_DEBUG_RADIO(mvm,
1123 "PPAG table is v1 but FW supports v2, sending padded table\n");
1124 } else if (cmd_ver == 2 && mvm->fwrt.ppag_ver == 2) {
1125 IWL_DEBUG_RADIO(mvm,
1126 "PPAG table is v3 but FW supports v2, sending partial bitmap.\n");
1127 cmd.v1.flags &= cpu_to_le32(IWL_PPAG_ETSI_MASK);
1130 IWL_DEBUG_RADIO(mvm, "Unsupported PPAG command version\n");
1134 for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) {
1135 for (j = 0; j < num_sub_bands; j++) {
1136 gain[i * num_sub_bands + j] =
1137 mvm->fwrt.ppag_chains[i].subbands[j];
1138 IWL_DEBUG_RADIO(mvm,
1139 "PPAG table: chain[%d] band[%d]: gain = %d\n",
1140 i, j, gain[i * num_sub_bands + j]);
1143 IWL_DEBUG_RADIO(mvm, "Sending PER_PLATFORM_ANT_GAIN_CMD\n");
1144 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(PHY_OPS_GROUP,
1145 PER_PLATFORM_ANT_GAIN_CMD),
1148 IWL_ERR(mvm, "failed to send PER_PLATFORM_ANT_GAIN_CMD (%d)\n",
1154 static const struct dmi_system_id dmi_ppag_approved_list[] = {
1157 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
1160 { .ident = "SAMSUNG",
1162 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD"),
1167 DMI_MATCH(DMI_SYS_VENDOR, "Microsoft Corporation"),
1172 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTek COMPUTER INC."),
1178 static int iwl_mvm_ppag_init(struct iwl_mvm *mvm)
1180 /* no need to read the table, done in INIT stage */
1181 if (!dmi_check_system(dmi_ppag_approved_list)) {
1182 IWL_DEBUG_RADIO(mvm,
1183 "System vendor '%s' is not in the approved list, disabling PPAG.\n",
1184 dmi_get_system_info(DMI_SYS_VENDOR));
1185 mvm->fwrt.ppag_flags = 0;
1189 return iwl_mvm_ppag_send_cmd(mvm);
1192 static const struct dmi_system_id dmi_tas_approved_list[] = {
1195 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
1198 { .ident = "SAMSUNG",
1200 DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD"),
1203 { .ident = "LENOVO",
1205 DMI_MATCH(DMI_SYS_VENDOR, "Lenovo"),
1210 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
1218 static bool iwl_mvm_add_to_tas_block_list(__le32 *list, __le32 *le_size, unsigned int mcc)
1221 u32 size = le32_to_cpu(*le_size);
1223 /* Verify that there is room for another country */
1224 if (size >= IWL_TAS_BLOCK_LIST_MAX)
1227 for (i = 0; i < size; i++) {
1228 if (list[i] == cpu_to_le32(mcc))
1232 list[size++] = cpu_to_le32(mcc);
1233 *le_size = cpu_to_le32(size);
1237 static void iwl_mvm_tas_init(struct iwl_mvm *mvm)
1239 u32 cmd_id = WIDE_ID(REGULATORY_AND_NVM_GROUP, TAS_CONFIG);
1241 union iwl_tas_config_cmd cmd = {};
1242 int cmd_size, fw_ver;
1244 BUILD_BUG_ON(ARRAY_SIZE(cmd.v3.block_list_array) <
1245 APCI_WTAS_BLACK_LIST_MAX);
1247 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TAS_CFG)) {
1248 IWL_DEBUG_RADIO(mvm, "TAS not enabled in FW\n");
1252 fw_ver = iwl_fw_lookup_cmd_ver(mvm->fw, cmd_id,
1253 IWL_FW_CMD_VER_UNKNOWN);
1255 ret = iwl_acpi_get_tas(&mvm->fwrt, &cmd, fw_ver);
1257 IWL_DEBUG_RADIO(mvm,
1258 "TAS table invalid or unavailable. (%d)\n",
1266 if (!dmi_check_system(dmi_tas_approved_list)) {
1267 IWL_DEBUG_RADIO(mvm,
1268 "System vendor '%s' is not in the approved list, disabling TAS in US and Canada.\n",
1269 dmi_get_system_info(DMI_SYS_VENDOR));
1270 if ((!iwl_mvm_add_to_tas_block_list(cmd.v4.block_list_array,
1271 &cmd.v4.block_list_size,
1273 (!iwl_mvm_add_to_tas_block_list(cmd.v4.block_list_array,
1274 &cmd.v4.block_list_size,
1275 IWL_TAS_CANADA_MCC))) {
1276 IWL_DEBUG_RADIO(mvm,
1277 "Unable to add US/Canada to TAS block list, disabling TAS\n");
1282 /* v4 is the same size as v3, so no need to differentiate here */
1283 cmd_size = fw_ver < 3 ?
1284 sizeof(struct iwl_tas_config_cmd_v2) :
1285 sizeof(struct iwl_tas_config_cmd_v3);
1287 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, cmd_size, &cmd);
1289 IWL_DEBUG_RADIO(mvm, "failed to send TAS_CONFIG (%d)\n", ret);
1292 static u8 iwl_mvm_eval_dsm_rfi(struct iwl_mvm *mvm)
1295 int ret = iwl_acpi_get_dsm_u8(mvm->fwrt.dev, 0, DSM_RFI_FUNC_ENABLE,
1296 &iwl_rfi_guid, &value);
1299 IWL_DEBUG_RADIO(mvm, "Failed to get DSM RFI, ret=%d\n", ret);
1301 } else if (value >= DSM_VALUE_RFI_MAX) {
1302 IWL_DEBUG_RADIO(mvm, "DSM RFI got invalid value, ret=%d\n",
1305 } else if (value == DSM_VALUE_RFI_ENABLE) {
1306 IWL_DEBUG_RADIO(mvm, "DSM RFI is evaluated to enable\n");
1307 return DSM_VALUE_RFI_ENABLE;
1310 IWL_DEBUG_RADIO(mvm, "DSM RFI is disabled\n");
1312 /* default behaviour is disabled */
1313 return DSM_VALUE_RFI_DISABLE;
1316 static void iwl_mvm_lari_cfg(struct iwl_mvm *mvm)
1320 struct iwl_lari_config_change_cmd_v6 cmd = {};
1322 cmd.config_bitmap = iwl_acpi_get_lari_config_bitmap(&mvm->fwrt);
1324 ret = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0, DSM_FUNC_11AX_ENABLEMENT,
1327 cmd.oem_11ax_allow_bitmap = cpu_to_le32(value);
1329 ret = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0,
1330 DSM_FUNC_ENABLE_UNII4_CHAN,
1333 cmd.oem_unii4_allow_bitmap = cpu_to_le32(value);
1335 ret = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0,
1336 DSM_FUNC_ACTIVATE_CHANNEL,
1339 cmd.chan_state_active_bitmap = cpu_to_le32(value);
1341 ret = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0,
1345 cmd.oem_uhb_allow_bitmap = cpu_to_le32(value);
1347 ret = iwl_acpi_get_dsm_u32(mvm->fwrt.dev, 0,
1348 DSM_FUNC_FORCE_DISABLE_CHANNELS,
1351 cmd.force_disable_channels_bitmap = cpu_to_le32(value);
1353 if (cmd.config_bitmap ||
1354 cmd.oem_uhb_allow_bitmap ||
1355 cmd.oem_11ax_allow_bitmap ||
1356 cmd.oem_unii4_allow_bitmap ||
1357 cmd.chan_state_active_bitmap ||
1358 cmd.force_disable_channels_bitmap) {
1360 u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw,
1361 WIDE_ID(REGULATORY_AND_NVM_GROUP,
1362 LARI_CONFIG_CHANGE),
1366 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v6);
1369 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v5);
1372 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v4);
1375 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v3);
1378 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v2);
1381 cmd_size = sizeof(struct iwl_lari_config_change_cmd_v1);
1385 IWL_DEBUG_RADIO(mvm,
1386 "sending LARI_CONFIG_CHANGE, config_bitmap=0x%x, oem_11ax_allow_bitmap=0x%x\n",
1387 le32_to_cpu(cmd.config_bitmap),
1388 le32_to_cpu(cmd.oem_11ax_allow_bitmap));
1389 IWL_DEBUG_RADIO(mvm,
1390 "sending LARI_CONFIG_CHANGE, oem_unii4_allow_bitmap=0x%x, chan_state_active_bitmap=0x%x, cmd_ver=%d\n",
1391 le32_to_cpu(cmd.oem_unii4_allow_bitmap),
1392 le32_to_cpu(cmd.chan_state_active_bitmap),
1394 IWL_DEBUG_RADIO(mvm,
1395 "sending LARI_CONFIG_CHANGE, oem_uhb_allow_bitmap=0x%x, force_disable_channels_bitmap=0x%x\n",
1396 le32_to_cpu(cmd.oem_uhb_allow_bitmap),
1397 le32_to_cpu(cmd.force_disable_channels_bitmap));
1398 ret = iwl_mvm_send_cmd_pdu(mvm,
1399 WIDE_ID(REGULATORY_AND_NVM_GROUP,
1400 LARI_CONFIG_CHANGE),
1403 IWL_DEBUG_RADIO(mvm,
1404 "Failed to send LARI_CONFIG_CHANGE (%d)\n",
1409 void iwl_mvm_get_acpi_tables(struct iwl_mvm *mvm)
1413 /* read PPAG table */
1414 ret = iwl_mvm_get_ppag_table(mvm);
1416 IWL_DEBUG_RADIO(mvm,
1417 "PPAG BIOS table invalid or unavailable. (%d)\n",
1421 /* read SAR tables */
1422 ret = iwl_sar_get_wrds_table(&mvm->fwrt);
1424 IWL_DEBUG_RADIO(mvm,
1425 "WRDS SAR BIOS table invalid or unavailable. (%d)\n",
1428 * If not available, don't fail and don't bother with EWRD and
1431 if (!iwl_sar_get_wgds_table(&mvm->fwrt)) {
1433 * If basic SAR is not available, we check for WGDS,
1434 * which should *not* be available either. If it is
1435 * available, issue an error, because we can't use SAR
1436 * Geo without basic SAR.
1438 IWL_ERR(mvm, "BIOS contains WGDS but no WRDS\n");
1442 ret = iwl_sar_get_ewrd_table(&mvm->fwrt);
1443 /* if EWRD is not available, we can still use
1444 * WRDS, so don't fail */
1446 IWL_DEBUG_RADIO(mvm,
1447 "EWRD SAR BIOS table invalid or unavailable. (%d)\n",
1450 /* read geo SAR table */
1451 if (iwl_sar_geo_support(&mvm->fwrt)) {
1452 ret = iwl_sar_get_wgds_table(&mvm->fwrt);
1454 IWL_DEBUG_RADIO(mvm,
1455 "Geo SAR BIOS table invalid or unavailable. (%d)\n",
1457 /* we don't fail if the table is not available */
1461 #else /* CONFIG_ACPI */
1463 inline int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm,
1464 int prof_a, int prof_b)
1469 inline int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
1474 static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
1479 int iwl_mvm_ppag_send_cmd(struct iwl_mvm *mvm)
1484 static int iwl_mvm_ppag_init(struct iwl_mvm *mvm)
1489 static void iwl_mvm_tas_init(struct iwl_mvm *mvm)
1493 static void iwl_mvm_lari_cfg(struct iwl_mvm *mvm)
1497 static u8 iwl_mvm_eval_dsm_rfi(struct iwl_mvm *mvm)
1499 return DSM_VALUE_RFI_DISABLE;
1502 void iwl_mvm_get_acpi_tables(struct iwl_mvm *mvm)
1506 #endif /* CONFIG_ACPI */
1508 void iwl_mvm_send_recovery_cmd(struct iwl_mvm *mvm, u32 flags)
1510 u32 error_log_size = mvm->fw->ucode_capa.error_log_size;
1514 struct iwl_fw_error_recovery_cmd recovery_cmd = {
1515 .flags = cpu_to_le32(flags),
1518 struct iwl_host_cmd host_cmd = {
1519 .id = WIDE_ID(SYSTEM_GROUP, FW_ERROR_RECOVERY_CMD),
1520 .flags = CMD_WANT_SKB,
1521 .data = {&recovery_cmd, },
1522 .len = {sizeof(recovery_cmd), },
1525 /* no error log was defined in TLV */
1526 if (!error_log_size)
1529 if (flags & ERROR_RECOVERY_UPDATE_DB) {
1530 /* no buf was allocated while HW reset */
1531 if (!mvm->error_recovery_buf)
1534 host_cmd.data[1] = mvm->error_recovery_buf;
1535 host_cmd.len[1] = error_log_size;
1536 host_cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
1537 recovery_cmd.buf_size = cpu_to_le32(error_log_size);
1540 ret = iwl_mvm_send_cmd(mvm, &host_cmd);
1541 kfree(mvm->error_recovery_buf);
1542 mvm->error_recovery_buf = NULL;
1545 IWL_ERR(mvm, "Failed to send recovery cmd %d\n", ret);
1549 /* skb respond is only relevant in ERROR_RECOVERY_UPDATE_DB */
1550 if (flags & ERROR_RECOVERY_UPDATE_DB) {
1551 resp = le32_to_cpu(*(__le32 *)host_cmd.resp_pkt->data);
1554 "Failed to send recovery cmd blob was invalid %d\n",
1559 static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
1561 return iwl_mvm_sar_select_profile(mvm, 1, 1);
1564 static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)
1568 if (iwl_mvm_has_unified_ucode(mvm))
1569 return iwl_run_unified_mvm_ucode(mvm);
1571 ret = iwl_run_init_mvm_ucode(mvm);
1574 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
1576 if (iwlmvm_mod_params.init_dbg)
1581 iwl_fw_dbg_stop_sync(&mvm->fwrt);
1582 iwl_trans_stop_device(mvm->trans);
1583 ret = iwl_trans_start_hw(mvm->trans);
1587 mvm->rfkill_safe_init_done = false;
1588 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
1592 mvm->rfkill_safe_init_done = true;
1594 iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_AFTER_ALIVE,
1597 return iwl_init_paging(&mvm->fwrt, mvm->fwrt.cur_fw_img);
1600 int iwl_mvm_up(struct iwl_mvm *mvm)
1603 struct ieee80211_channel *chan;
1604 struct cfg80211_chan_def chandef;
1605 struct ieee80211_supported_band *sband = NULL;
1607 lockdep_assert_held(&mvm->mutex);
1609 ret = iwl_trans_start_hw(mvm->trans);
1613 ret = iwl_mvm_load_rt_fw(mvm);
1615 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
1616 if (ret != -ERFKILL)
1617 iwl_fw_dbg_error_collect(&mvm->fwrt,
1618 FW_DBG_TRIGGER_DRIVER);
1622 iwl_get_shared_mem_conf(&mvm->fwrt);
1624 ret = iwl_mvm_sf_update(mvm, NULL, false);
1626 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
1628 if (!iwl_trans_dbg_ini_valid(mvm->trans)) {
1629 mvm->fwrt.dump.conf = FW_DBG_INVALID;
1630 /* if we have a destination, assume EARLY START */
1631 if (mvm->fw->dbg.dest_tlv)
1632 mvm->fwrt.dump.conf = FW_DBG_START_FROM_ALIVE;
1633 iwl_fw_start_dbg_conf(&mvm->fwrt, FW_DBG_START_FROM_ALIVE);
1636 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
1640 if (!iwl_mvm_has_unified_ucode(mvm)) {
1641 /* Send phy db control command and then phy db calibration */
1642 ret = iwl_send_phy_db_data(mvm->phy_db);
1647 ret = iwl_send_phy_cfg_cmd(mvm);
1651 ret = iwl_mvm_send_bt_init_conf(mvm);
1655 if (fw_has_capa(&mvm->fw->ucode_capa,
1656 IWL_UCODE_TLV_CAPA_SOC_LATENCY_SUPPORT)) {
1657 ret = iwl_set_soc_latency(&mvm->fwrt);
1662 /* Init RSS configuration */
1663 ret = iwl_configure_rxq(&mvm->fwrt);
1667 if (iwl_mvm_has_new_rx_api(mvm)) {
1668 ret = iwl_send_rss_cfg_cmd(mvm);
1670 IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
1676 /* init the fw <-> mac80211 STA mapping */
1677 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++)
1678 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1680 mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
1682 /* reset quota debouncing buffer - 0xff will yield invalid data */
1683 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
1685 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_DQA_SUPPORT)) {
1686 ret = iwl_mvm_send_dqa_cmd(mvm);
1692 * Add auxiliary station for scanning.
1693 * Newer versions of this command implies that the fw uses
1694 * internal aux station for all aux activities that don't
1695 * requires a dedicated data queue.
1697 if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) < 12) {
1699 * In old version the aux station uses mac id like other
1700 * station and not lmac id
1702 ret = iwl_mvm_add_aux_sta(mvm, MAC_INDEX_AUX);
1707 /* Add all the PHY contexts */
1709 while (!sband && i < NUM_NL80211_BANDS)
1710 sband = mvm->hw->wiphy->bands[i++];
1712 if (WARN_ON_ONCE(!sband)) {
1717 chan = &sband->channels[0];
1719 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
1720 for (i = 0; i < NUM_PHY_CTX; i++) {
1722 * The channel used here isn't relevant as it's
1723 * going to be overwritten in the other flows.
1724 * For now use the first channel we have.
1726 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
1732 if (iwl_mvm_is_tt_in_fw(mvm)) {
1733 /* in order to give the responsibility of ct-kill and
1734 * TX backoff to FW we need to send empty temperature reporting
1735 * cmd during init time
1737 iwl_mvm_send_temp_report_ths_cmd(mvm);
1739 /* Initialize tx backoffs to the minimal possible */
1740 iwl_mvm_tt_tx_backoff(mvm, 0);
1743 #ifdef CONFIG_THERMAL
1744 /* TODO: read the budget from BIOS / Platform NVM */
1747 * In case there is no budget from BIOS / Platform NVM the default
1748 * budget should be 2000mW (cooling state 0).
1750 if (iwl_mvm_is_ctdp_supported(mvm)) {
1751 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
1752 mvm->cooling_dev.cur_state);
1758 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_SET_LTR_GEN2))
1759 WARN_ON(iwl_mvm_config_ltr(mvm));
1761 ret = iwl_mvm_power_update_device(mvm);
1765 iwl_mvm_lari_cfg(mvm);
1767 * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
1768 * anyway, so don't init MCC.
1770 if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
1771 ret = iwl_mvm_init_mcc(mvm);
1776 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1777 mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
1778 mvm->hb_scan_type = IWL_SCAN_TYPE_NOT_SET;
1779 ret = iwl_mvm_config_scan(mvm);
1784 if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1785 iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_UPDATE_DB);
1787 if (iwl_acpi_get_eckv(mvm->dev, &mvm->ext_clock_valid))
1788 IWL_DEBUG_INFO(mvm, "ECKV table doesn't exist in BIOS\n");
1790 ret = iwl_mvm_ppag_init(mvm);
1794 ret = iwl_mvm_sar_init(mvm);
1796 ret = iwl_mvm_sar_geo_init(mvm);
1800 ret = iwl_mvm_sgom_init(mvm);
1804 iwl_mvm_tas_init(mvm);
1805 iwl_mvm_leds_sync(mvm);
1807 iwl_mvm_ftm_initiator_smooth_config(mvm);
1809 if (fw_has_capa(&mvm->fw->ucode_capa,
1810 IWL_UCODE_TLV_CAPA_RFIM_SUPPORT)) {
1811 if (iwl_mvm_eval_dsm_rfi(mvm) == DSM_VALUE_RFI_ENABLE)
1812 iwl_rfi_send_config_cmd(mvm, NULL);
1815 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
1818 if (!iwlmvm_mod_params.init_dbg || !ret)
1819 iwl_mvm_stop_device(mvm);
1823 int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
1827 lockdep_assert_held(&mvm->mutex);
1829 ret = iwl_trans_start_hw(mvm->trans);
1833 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
1835 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
1839 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
1843 /* Send phy db control command and then phy db calibration*/
1844 ret = iwl_send_phy_db_data(mvm->phy_db);
1848 ret = iwl_send_phy_cfg_cmd(mvm);
1852 /* init the fw <-> mac80211 STA mapping */
1853 for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++)
1854 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1856 if (iwl_fw_lookup_cmd_ver(mvm->fw, ADD_STA, 0) < 12) {
1858 * Add auxiliary station for scanning.
1859 * Newer versions of this command implies that the fw uses
1860 * internal aux station for all aux activities that don't
1861 * requires a dedicated data queue.
1862 * In old version the aux station uses mac id like other
1863 * station and not lmac id
1865 ret = iwl_mvm_add_aux_sta(mvm, MAC_INDEX_AUX);
1872 iwl_mvm_stop_device(mvm);
1876 void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1877 struct iwl_rx_cmd_buffer *rxb)
1879 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1880 struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
1883 "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
1884 le32_to_cpu(mfuart_notif->installed_ver),
1885 le32_to_cpu(mfuart_notif->external_ver),
1886 le32_to_cpu(mfuart_notif->status),
1887 le32_to_cpu(mfuart_notif->duration));
1889 if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif))
1891 "MFUART: image size: 0x%08x\n",
1892 le32_to_cpu(mfuart_notif->image_size));