1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /*
3  * Copyright (C) 2012-2014, 2018-2020 Intel Corporation
4  * Copyright (C) 2013-2015 Intel Mobile Communications GmbH
5  * Copyright (C) 2016-2017 Intel Deutschland GmbH
6  */
7 #include <net/mac80211.h>
8 #include <linux/netdevice.h>
9 
10 #include "iwl-trans.h"
11 #include "iwl-op-mode.h"
12 #include "fw/img.h"
13 #include "iwl-debug.h"
14 #include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */
15 #include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */
16 #include "iwl-prph.h"
17 #include "fw/acpi.h"
18 #include "fw/pnvm.h"
19 
20 #include "mvm.h"
21 #include "fw/dbg.h"
22 #include "iwl-phy-db.h"
23 #include "iwl-modparams.h"
24 #include "iwl-nvm-parse.h"
25 
26 #define MVM_UCODE_ALIVE_TIMEOUT	(HZ)
27 #define MVM_UCODE_CALIB_TIMEOUT	(2 * HZ)
28 
29 #define UCODE_VALID_OK	cpu_to_le32(0x1)
30 
31 struct iwl_mvm_alive_data {
32 	bool valid;
33 	u32 scd_base_addr;
34 };
35 
36 static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
37 {
38 	struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
39 		.valid = cpu_to_le32(valid_tx_ant),
40 	};
41 
42 	IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
43 	return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
44 				    sizeof(tx_ant_cmd), &tx_ant_cmd);
45 }
46 
47 static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm)
48 {
49 	int i;
50 	struct iwl_rss_config_cmd cmd = {
51 		.flags = cpu_to_le32(IWL_RSS_ENABLE),
52 		.hash_mask = BIT(IWL_RSS_HASH_TYPE_IPV4_TCP) |
53 			     BIT(IWL_RSS_HASH_TYPE_IPV4_UDP) |
54 			     BIT(IWL_RSS_HASH_TYPE_IPV4_PAYLOAD) |
55 			     BIT(IWL_RSS_HASH_TYPE_IPV6_TCP) |
56 			     BIT(IWL_RSS_HASH_TYPE_IPV6_UDP) |
57 			     BIT(IWL_RSS_HASH_TYPE_IPV6_PAYLOAD),
58 	};
59 
60 	if (mvm->trans->num_rx_queues == 1)
61 		return 0;
62 
63 	/* Do not direct RSS traffic to Q 0 which is our fallback queue */
64 	for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++)
65 		cmd.indirection_table[i] =
66 			1 + (i % (mvm->trans->num_rx_queues - 1));
67 	netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
68 
69 	return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
70 }
71 
72 static int iwl_configure_rxq(struct iwl_mvm *mvm)
73 {
74 	int i, num_queues, size, ret;
75 	struct iwl_rfh_queue_config *cmd;
76 	struct iwl_host_cmd hcmd = {
77 		.id = WIDE_ID(DATA_PATH_GROUP, RFH_QUEUE_CONFIG_CMD),
78 		.dataflags[0] = IWL_HCMD_DFL_NOCOPY,
79 	};
80 
81 	/*
82 	 * The default queue is configured via context info, so if we
83 	 * have a single queue, there's nothing to do here.
84 	 */
85 	if (mvm->trans->num_rx_queues == 1)
86 		return 0;
87 
88 	/* skip the default queue */
89 	num_queues = mvm->trans->num_rx_queues - 1;
90 
91 	size = struct_size(cmd, data, num_queues);
92 
93 	cmd = kzalloc(size, GFP_KERNEL);
94 	if (!cmd)
95 		return -ENOMEM;
96 
97 	cmd->num_queues = num_queues;
98 
99 	for (i = 0; i < num_queues; i++) {
100 		struct iwl_trans_rxq_dma_data data;
101 
102 		cmd->data[i].q_num = i + 1;
103 		iwl_trans_get_rxq_dma_data(mvm->trans, i + 1, &data);
104 
105 		cmd->data[i].fr_bd_cb = cpu_to_le64(data.fr_bd_cb);
106 		cmd->data[i].urbd_stts_wrptr =
107 			cpu_to_le64(data.urbd_stts_wrptr);
108 		cmd->data[i].ur_bd_cb = cpu_to_le64(data.ur_bd_cb);
109 		cmd->data[i].fr_bd_wid = cpu_to_le32(data.fr_bd_wid);
110 	}
111 
112 	hcmd.data[0] = cmd;
113 	hcmd.len[0] = size;
114 
115 	ret = iwl_mvm_send_cmd(mvm, &hcmd);
116 
117 	kfree(cmd);
118 
119 	return ret;
120 }
121 
122 static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm)
123 {
124 	struct iwl_dqa_enable_cmd dqa_cmd = {
125 		.cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE),
126 	};
127 	u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0);
128 	int ret;
129 
130 	ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd);
131 	if (ret)
132 		IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret);
133 	else
134 		IWL_DEBUG_FW(mvm, "Working in DQA mode\n");
135 
136 	return ret;
137 }
138 
139 void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
140 				   struct iwl_rx_cmd_buffer *rxb)
141 {
142 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
143 	struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data;
144 	__le32 *dump_data = mfu_dump_notif->data;
145 	int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32);
146 	int i;
147 
148 	if (mfu_dump_notif->index_num == 0)
149 		IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n",
150 			 le32_to_cpu(mfu_dump_notif->assert_id));
151 
152 	for (i = 0; i < n_words; i++)
153 		IWL_DEBUG_INFO(mvm,
154 			       "MFUART assert dump, dword %u: 0x%08x\n",
155 			       le16_to_cpu(mfu_dump_notif->index_num) *
156 			       n_words + i,
157 			       le32_to_cpu(dump_data[i]));
158 }
159 
160 static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
161 			 struct iwl_rx_packet *pkt, void *data)
162 {
163 	unsigned int pkt_len = iwl_rx_packet_payload_len(pkt);
164 	struct iwl_mvm *mvm =
165 		container_of(notif_wait, struct iwl_mvm, notif_wait);
166 	struct iwl_mvm_alive_data *alive_data = data;
167 	struct iwl_umac_alive *umac;
168 	struct iwl_lmac_alive *lmac1;
169 	struct iwl_lmac_alive *lmac2 = NULL;
170 	u16 status;
171 	u32 lmac_error_event_table, umac_error_table;
172 
173 	/*
174 	 * For v5 and above, we can check the version, for older
175 	 * versions we need to check the size.
176 	 */
177 	if (iwl_fw_lookup_notif_ver(mvm->fw, LEGACY_GROUP,
178 				    UCODE_ALIVE_NTFY, 0) == 5) {
179 		struct iwl_alive_ntf_v5 *palive;
180 
181 		if (pkt_len < sizeof(*palive))
182 			return false;
183 
184 		palive = (void *)pkt->data;
185 		umac = &palive->umac_data;
186 		lmac1 = &palive->lmac_data[0];
187 		lmac2 = &palive->lmac_data[1];
188 		status = le16_to_cpu(palive->status);
189 
190 		mvm->trans->sku_id[0] = le32_to_cpu(palive->sku_id.data[0]);
191 		mvm->trans->sku_id[1] = le32_to_cpu(palive->sku_id.data[1]);
192 		mvm->trans->sku_id[2] = le32_to_cpu(palive->sku_id.data[2]);
193 
194 		IWL_DEBUG_FW(mvm, "Got sku_id: 0x0%x 0x0%x 0x0%x\n",
195 			     mvm->trans->sku_id[0],
196 			     mvm->trans->sku_id[1],
197 			     mvm->trans->sku_id[2]);
198 	} else if (iwl_rx_packet_payload_len(pkt) == sizeof(struct iwl_alive_ntf_v4)) {
199 		struct iwl_alive_ntf_v4 *palive;
200 
201 		if (pkt_len < sizeof(*palive))
202 			return false;
203 
204 		palive = (void *)pkt->data;
205 		umac = &palive->umac_data;
206 		lmac1 = &palive->lmac_data[0];
207 		lmac2 = &palive->lmac_data[1];
208 		status = le16_to_cpu(palive->status);
209 	} else if (iwl_rx_packet_payload_len(pkt) ==
210 		   sizeof(struct iwl_alive_ntf_v3)) {
211 		struct iwl_alive_ntf_v3 *palive3;
212 
213 		if (pkt_len < sizeof(*palive3))
214 			return false;
215 
216 		palive3 = (void *)pkt->data;
217 		umac = &palive3->umac_data;
218 		lmac1 = &palive3->lmac_data;
219 		status = le16_to_cpu(palive3->status);
220 	} else {
221 		WARN(1, "unsupported alive notification (size %d)\n",
222 		     iwl_rx_packet_payload_len(pkt));
223 		/* get timeout later */
224 		return false;
225 	}
226 
227 	lmac_error_event_table =
228 		le32_to_cpu(lmac1->dbg_ptrs.error_event_table_ptr);
229 	iwl_fw_lmac1_set_alive_err_table(mvm->trans, lmac_error_event_table);
230 
231 	if (lmac2)
232 		mvm->trans->dbg.lmac_error_event_table[1] =
233 			le32_to_cpu(lmac2->dbg_ptrs.error_event_table_ptr);
234 
235 	umac_error_table = le32_to_cpu(umac->dbg_ptrs.error_info_addr);
236 
237 	if (umac_error_table) {
238 		if (umac_error_table >=
239 		    mvm->trans->cfg->min_umac_error_event_table) {
240 			iwl_fw_umac_set_alive_err_table(mvm->trans,
241 							umac_error_table);
242 		} else {
243 			IWL_ERR(mvm,
244 				"Not valid error log pointer 0x%08X for %s uCode\n",
245 				umac_error_table,
246 				(mvm->fwrt.cur_fw_img == IWL_UCODE_INIT) ?
247 				"Init" : "RT");
248 		}
249 	}
250 
251 	alive_data->scd_base_addr = le32_to_cpu(lmac1->dbg_ptrs.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 	iwl_fwrt_update_fw_versions(&mvm->fwrt, lmac1, umac);
267 
268 	return true;
269 }
270 
271 static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait,
272 				   struct iwl_rx_packet *pkt, void *data)
273 {
274 	WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
275 
276 	return true;
277 }
278 
279 static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
280 				  struct iwl_rx_packet *pkt, void *data)
281 {
282 	struct iwl_phy_db *phy_db = data;
283 
284 	if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
285 		WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
286 		return true;
287 	}
288 
289 	WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
290 
291 	return false;
292 }
293 
294 static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
295 					 enum iwl_ucode_type ucode_type)
296 {
297 	struct iwl_notification_wait alive_wait;
298 	struct iwl_mvm_alive_data alive_data = {};
299 	const struct fw_img *fw;
300 	int ret;
301 	enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img;
302 	static const u16 alive_cmd[] = { UCODE_ALIVE_NTFY };
303 	bool run_in_rfkill =
304 		ucode_type == IWL_UCODE_INIT || iwl_mvm_has_unified_ucode(mvm);
305 
306 	if (ucode_type == IWL_UCODE_REGULAR &&
307 	    iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
308 	    !(fw_has_capa(&mvm->fw->ucode_capa,
309 			  IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
310 		fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER);
311 	else
312 		fw = iwl_get_ucode_image(mvm->fw, ucode_type);
313 	if (WARN_ON(!fw))
314 		return -EINVAL;
315 	iwl_fw_set_current_image(&mvm->fwrt, ucode_type);
316 	clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
317 
318 	iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
319 				   alive_cmd, ARRAY_SIZE(alive_cmd),
320 				   iwl_alive_fn, &alive_data);
321 
322 	/*
323 	 * We want to load the INIT firmware even in RFKILL
324 	 * For the unified firmware case, the ucode_type is not
325 	 * INIT, but we still need to run it.
326 	 */
327 	ret = iwl_trans_start_fw(mvm->trans, fw, run_in_rfkill);
328 	if (ret) {
329 		iwl_fw_set_current_image(&mvm->fwrt, old_type);
330 		iwl_remove_notification(&mvm->notif_wait, &alive_wait);
331 		return ret;
332 	}
333 
334 	/*
335 	 * Some things may run in the background now, but we
336 	 * just wait for the ALIVE notification here.
337 	 */
338 	ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
339 				    MVM_UCODE_ALIVE_TIMEOUT);
340 	if (ret) {
341 		struct iwl_trans *trans = mvm->trans;
342 
343 		if (trans->trans_cfg->device_family >=
344 					IWL_DEVICE_FAMILY_22000) {
345 			IWL_ERR(mvm,
346 				"SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
347 				iwl_read_umac_prph(trans, UMAG_SB_CPU_1_STATUS),
348 				iwl_read_umac_prph(trans,
349 						   UMAG_SB_CPU_2_STATUS));
350 			IWL_ERR(mvm, "UMAC PC: 0x%x\n",
351 				iwl_read_umac_prph(trans,
352 						   UREG_UMAC_CURRENT_PC));
353 			IWL_ERR(mvm, "LMAC PC: 0x%x\n",
354 				iwl_read_umac_prph(trans,
355 						   UREG_LMAC1_CURRENT_PC));
356 			if (iwl_mvm_is_cdb_supported(mvm))
357 				IWL_ERR(mvm, "LMAC2 PC: 0x%x\n",
358 					iwl_read_umac_prph(trans,
359 						UREG_LMAC2_CURRENT_PC));
360 		} else if (trans->trans_cfg->device_family >=
361 			   IWL_DEVICE_FAMILY_8000) {
362 			IWL_ERR(mvm,
363 				"SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
364 				iwl_read_prph(trans, SB_CPU_1_STATUS),
365 				iwl_read_prph(trans, SB_CPU_2_STATUS));
366 		}
367 
368 		if (ret == -ETIMEDOUT)
369 			iwl_fw_dbg_error_collect(&mvm->fwrt,
370 						 FW_DBG_TRIGGER_ALIVE_TIMEOUT);
371 
372 		iwl_fw_set_current_image(&mvm->fwrt, old_type);
373 		return ret;
374 	}
375 
376 	if (!alive_data.valid) {
377 		IWL_ERR(mvm, "Loaded ucode is not valid!\n");
378 		iwl_fw_set_current_image(&mvm->fwrt, old_type);
379 		return -EIO;
380 	}
381 
382 	ret = iwl_pnvm_load(mvm->trans, &mvm->notif_wait);
383 	if (ret) {
384 		IWL_ERR(mvm, "Timeout waiting for PNVM load!\n");
385 		iwl_fw_set_current_image(&mvm->fwrt, old_type);
386 		return ret;
387 	}
388 
389 	iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
390 
391 	/*
392 	 * Note: all the queues are enabled as part of the interface
393 	 * initialization, but in firmware restart scenarios they
394 	 * could be stopped, so wake them up. In firmware restart,
395 	 * mac80211 will have the queues stopped as well until the
396 	 * reconfiguration completes. During normal startup, they
397 	 * will be empty.
398 	 */
399 
400 	memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
401 	/*
402 	 * Set a 'fake' TID for the command queue, since we use the
403 	 * hweight() of the tid_bitmap as a refcount now. Not that
404 	 * we ever even consider the command queue as one we might
405 	 * want to reuse, but be safe nevertheless.
406 	 */
407 	mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].tid_bitmap =
408 		BIT(IWL_MAX_TID_COUNT + 2);
409 
410 	set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
411 #ifdef CONFIG_IWLWIFI_DEBUGFS
412 	iwl_fw_set_dbg_rec_on(&mvm->fwrt);
413 #endif
414 
415 	/*
416 	 * All the BSSes in the BSS table include the GP2 in the system
417 	 * at the beacon Rx time, this is of course no longer relevant
418 	 * since we are resetting the firmware.
419 	 * Purge all the BSS table.
420 	 */
421 	cfg80211_bss_flush(mvm->hw->wiphy);
422 
423 	return 0;
424 }
425 
426 static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm)
427 {
428 	struct iwl_notification_wait init_wait;
429 	struct iwl_nvm_access_complete_cmd nvm_complete = {};
430 	struct iwl_init_extended_cfg_cmd init_cfg = {
431 		.init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)),
432 	};
433 	static const u16 init_complete[] = {
434 		INIT_COMPLETE_NOTIF,
435 	};
436 	int ret;
437 
438 	if (mvm->trans->cfg->tx_with_siso_diversity)
439 		init_cfg.init_flags |= cpu_to_le32(BIT(IWL_INIT_PHY));
440 
441 	lockdep_assert_held(&mvm->mutex);
442 
443 	mvm->rfkill_safe_init_done = false;
444 
445 	iwl_init_notification_wait(&mvm->notif_wait,
446 				   &init_wait,
447 				   init_complete,
448 				   ARRAY_SIZE(init_complete),
449 				   iwl_wait_init_complete,
450 				   NULL);
451 
452 	iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_EARLY, NULL);
453 
454 	/* Will also start the device */
455 	ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
456 	if (ret) {
457 		IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
458 		goto error;
459 	}
460 	iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_AFTER_ALIVE,
461 			       NULL);
462 
463 	/* Send init config command to mark that we are sending NVM access
464 	 * commands
465 	 */
466 	ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP,
467 						INIT_EXTENDED_CFG_CMD),
468 				   CMD_SEND_IN_RFKILL,
469 				   sizeof(init_cfg), &init_cfg);
470 	if (ret) {
471 		IWL_ERR(mvm, "Failed to run init config command: %d\n",
472 			ret);
473 		goto error;
474 	}
475 
476 	/* Load NVM to NIC if needed */
477 	if (mvm->nvm_file_name) {
478 		iwl_read_external_nvm(mvm->trans, mvm->nvm_file_name,
479 				      mvm->nvm_sections);
480 		iwl_mvm_load_nvm_to_nic(mvm);
481 	}
482 
483 	if (IWL_MVM_PARSE_NVM && !mvm->nvm_data) {
484 		ret = iwl_nvm_init(mvm);
485 		if (ret) {
486 			IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
487 			goto error;
488 		}
489 	}
490 
491 	ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
492 						NVM_ACCESS_COMPLETE),
493 				   CMD_SEND_IN_RFKILL,
494 				   sizeof(nvm_complete), &nvm_complete);
495 	if (ret) {
496 		IWL_ERR(mvm, "Failed to run complete NVM access: %d\n",
497 			ret);
498 		goto error;
499 	}
500 
501 	/* We wait for the INIT complete notification */
502 	ret = iwl_wait_notification(&mvm->notif_wait, &init_wait,
503 				    MVM_UCODE_ALIVE_TIMEOUT);
504 	if (ret)
505 		return ret;
506 
507 	/* Read the NVM only at driver load time, no need to do this twice */
508 	if (!IWL_MVM_PARSE_NVM && !mvm->nvm_data) {
509 		mvm->nvm_data = iwl_get_nvm(mvm->trans, mvm->fw);
510 		if (IS_ERR(mvm->nvm_data)) {
511 			ret = PTR_ERR(mvm->nvm_data);
512 			mvm->nvm_data = NULL;
513 			IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
514 			return ret;
515 		}
516 	}
517 
518 	mvm->rfkill_safe_init_done = true;
519 
520 	return 0;
521 
522 error:
523 	iwl_remove_notification(&mvm->notif_wait, &init_wait);
524 	return ret;
525 }
526 
527 #ifdef CONFIG_ACPI
528 static void iwl_mvm_phy_filter_init(struct iwl_mvm *mvm,
529 				    struct iwl_phy_specific_cfg *phy_filters)
530 {
531 	/*
532 	 * TODO: read specific phy config from BIOS
533 	 * ACPI table for this feature has not been defined yet,
534 	 * so for now we use hardcoded values.
535 	 */
536 
537 	if (IWL_MVM_PHY_FILTER_CHAIN_A) {
538 		phy_filters->filter_cfg_chain_a =
539 			cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_A);
540 	}
541 	if (IWL_MVM_PHY_FILTER_CHAIN_B) {
542 		phy_filters->filter_cfg_chain_b =
543 			cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_B);
544 	}
545 	if (IWL_MVM_PHY_FILTER_CHAIN_C) {
546 		phy_filters->filter_cfg_chain_c =
547 			cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_C);
548 	}
549 	if (IWL_MVM_PHY_FILTER_CHAIN_D) {
550 		phy_filters->filter_cfg_chain_d =
551 			cpu_to_le32(IWL_MVM_PHY_FILTER_CHAIN_D);
552 	}
553 }
554 
555 #else /* CONFIG_ACPI */
556 
557 static void iwl_mvm_phy_filter_init(struct iwl_mvm *mvm,
558 				    struct iwl_phy_specific_cfg *phy_filters)
559 {
560 }
561 #endif /* CONFIG_ACPI */
562 
563 static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
564 {
565 	struct iwl_phy_cfg_cmd_v3 phy_cfg_cmd;
566 	enum iwl_ucode_type ucode_type = mvm->fwrt.cur_fw_img;
567 	struct iwl_phy_specific_cfg phy_filters = {};
568 	u8 cmd_ver;
569 	size_t cmd_size;
570 
571 	if (iwl_mvm_has_unified_ucode(mvm) &&
572 	    !mvm->trans->cfg->tx_with_siso_diversity)
573 		return 0;
574 
575 	if (mvm->trans->cfg->tx_with_siso_diversity) {
576 		/*
577 		 * TODO: currently we don't set the antenna but letting the NIC
578 		 * to decide which antenna to use. This should come from BIOS.
579 		 */
580 		phy_cfg_cmd.phy_cfg =
581 			cpu_to_le32(FW_PHY_CFG_CHAIN_SAD_ENABLED);
582 	}
583 
584 	/* Set parameters */
585 	phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
586 
587 	/* set flags extra PHY configuration flags from the device's cfg */
588 	phy_cfg_cmd.phy_cfg |=
589 		cpu_to_le32(mvm->trans->trans_cfg->extra_phy_cfg_flags);
590 
591 	phy_cfg_cmd.calib_control.event_trigger =
592 		mvm->fw->default_calib[ucode_type].event_trigger;
593 	phy_cfg_cmd.calib_control.flow_trigger =
594 		mvm->fw->default_calib[ucode_type].flow_trigger;
595 
596 	cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, IWL_ALWAYS_LONG_GROUP,
597 					PHY_CONFIGURATION_CMD,
598 					IWL_FW_CMD_VER_UNKNOWN);
599 	if (cmd_ver == 3) {
600 		iwl_mvm_phy_filter_init(mvm, &phy_filters);
601 		memcpy(&phy_cfg_cmd.phy_specific_cfg, &phy_filters,
602 		       sizeof(struct iwl_phy_specific_cfg));
603 	}
604 
605 	IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
606 		       phy_cfg_cmd.phy_cfg);
607 	cmd_size = (cmd_ver == 3) ? sizeof(struct iwl_phy_cfg_cmd_v3) :
608 				    sizeof(struct iwl_phy_cfg_cmd_v1);
609 	return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
610 				    cmd_size, &phy_cfg_cmd);
611 }
612 
613 int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm)
614 {
615 	struct iwl_notification_wait calib_wait;
616 	static const u16 init_complete[] = {
617 		INIT_COMPLETE_NOTIF,
618 		CALIB_RES_NOTIF_PHY_DB
619 	};
620 	int ret;
621 
622 	if (iwl_mvm_has_unified_ucode(mvm))
623 		return iwl_run_unified_mvm_ucode(mvm);
624 
625 	lockdep_assert_held(&mvm->mutex);
626 
627 	mvm->rfkill_safe_init_done = false;
628 
629 	iwl_init_notification_wait(&mvm->notif_wait,
630 				   &calib_wait,
631 				   init_complete,
632 				   ARRAY_SIZE(init_complete),
633 				   iwl_wait_phy_db_entry,
634 				   mvm->phy_db);
635 
636 	/* Will also start the device */
637 	ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
638 	if (ret) {
639 		IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
640 		goto remove_notif;
641 	}
642 
643 	if (mvm->trans->trans_cfg->device_family < IWL_DEVICE_FAMILY_8000) {
644 		ret = iwl_mvm_send_bt_init_conf(mvm);
645 		if (ret)
646 			goto remove_notif;
647 	}
648 
649 	/* Read the NVM only at driver load time, no need to do this twice */
650 	if (!mvm->nvm_data) {
651 		ret = iwl_nvm_init(mvm);
652 		if (ret) {
653 			IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
654 			goto remove_notif;
655 		}
656 	}
657 
658 	/* In case we read the NVM from external file, load it to the NIC */
659 	if (mvm->nvm_file_name)
660 		iwl_mvm_load_nvm_to_nic(mvm);
661 
662 	WARN_ONCE(mvm->nvm_data->nvm_version < mvm->trans->cfg->nvm_ver,
663 		  "Too old NVM version (0x%0x, required = 0x%0x)",
664 		  mvm->nvm_data->nvm_version, mvm->trans->cfg->nvm_ver);
665 
666 	/*
667 	 * abort after reading the nvm in case RF Kill is on, we will complete
668 	 * the init seq later when RF kill will switch to off
669 	 */
670 	if (iwl_mvm_is_radio_hw_killed(mvm)) {
671 		IWL_DEBUG_RF_KILL(mvm,
672 				  "jump over all phy activities due to RF kill\n");
673 		goto remove_notif;
674 	}
675 
676 	mvm->rfkill_safe_init_done = true;
677 
678 	/* Send TX valid antennas before triggering calibrations */
679 	ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
680 	if (ret)
681 		goto remove_notif;
682 
683 	ret = iwl_send_phy_cfg_cmd(mvm);
684 	if (ret) {
685 		IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
686 			ret);
687 		goto remove_notif;
688 	}
689 
690 	/*
691 	 * Some things may run in the background now, but we
692 	 * just wait for the calibration complete notification.
693 	 */
694 	ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
695 				    MVM_UCODE_CALIB_TIMEOUT);
696 	if (!ret)
697 		goto out;
698 
699 	if (iwl_mvm_is_radio_hw_killed(mvm)) {
700 		IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
701 		ret = 0;
702 	} else {
703 		IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
704 			ret);
705 	}
706 
707 	goto out;
708 
709 remove_notif:
710 	iwl_remove_notification(&mvm->notif_wait, &calib_wait);
711 out:
712 	mvm->rfkill_safe_init_done = false;
713 	if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
714 		/* we want to debug INIT and we have no NVM - fake */
715 		mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
716 					sizeof(struct ieee80211_channel) +
717 					sizeof(struct ieee80211_rate),
718 					GFP_KERNEL);
719 		if (!mvm->nvm_data)
720 			return -ENOMEM;
721 		mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
722 		mvm->nvm_data->bands[0].n_channels = 1;
723 		mvm->nvm_data->bands[0].n_bitrates = 1;
724 		mvm->nvm_data->bands[0].bitrates =
725 			(void *)mvm->nvm_data->channels + 1;
726 		mvm->nvm_data->bands[0].bitrates->hw_value = 10;
727 	}
728 
729 	return ret;
730 }
731 
732 static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
733 {
734 	struct iwl_ltr_config_cmd cmd = {
735 		.flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
736 	};
737 
738 	if (!mvm->trans->ltr_enabled)
739 		return 0;
740 
741 	return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
742 				    sizeof(cmd), &cmd);
743 }
744 
745 #ifdef CONFIG_ACPI
746 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b)
747 {
748 	struct iwl_dev_tx_power_cmd cmd = {
749 		.common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
750 	};
751 	__le16 *per_chain;
752 	int ret;
753 	u16 len = 0;
754 	u32 n_subbands;
755 	u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
756 					   REDUCE_TX_POWER_CMD,
757 					   IWL_FW_CMD_VER_UNKNOWN);
758 
759 	if (cmd_ver == 6) {
760 		len = sizeof(cmd.v6);
761 		n_subbands = IWL_NUM_SUB_BANDS_V2;
762 		per_chain = cmd.v6.per_chain[0][0];
763 	} else if (fw_has_api(&mvm->fw->ucode_capa,
764 			      IWL_UCODE_TLV_API_REDUCE_TX_POWER)) {
765 		len = sizeof(cmd.v5);
766 		n_subbands = IWL_NUM_SUB_BANDS;
767 		per_chain = cmd.v5.per_chain[0][0];
768 	} else if (fw_has_capa(&mvm->fw->ucode_capa,
769 			       IWL_UCODE_TLV_CAPA_TX_POWER_ACK)) {
770 		len = sizeof(cmd.v4);
771 		n_subbands = IWL_NUM_SUB_BANDS;
772 		per_chain = cmd.v4.per_chain[0][0];
773 	} else {
774 		len = sizeof(cmd.v3);
775 		n_subbands = IWL_NUM_SUB_BANDS;
776 		per_chain = cmd.v3.per_chain[0][0];
777 	}
778 
779 	/* all structs have the same common part, add it */
780 	len += sizeof(cmd.common);
781 
782 	ret = iwl_sar_select_profile(&mvm->fwrt, per_chain, ACPI_SAR_NUM_TABLES,
783 				     n_subbands, prof_a, prof_b);
784 
785 	/* return on error or if the profile is disabled (positive number) */
786 	if (ret)
787 		return ret;
788 
789 	IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
790 	return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
791 }
792 
793 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
794 {
795 	union iwl_geo_tx_power_profiles_cmd geo_tx_cmd;
796 	struct iwl_geo_tx_power_profiles_resp *resp;
797 	u16 len;
798 	int ret;
799 	struct iwl_host_cmd cmd;
800 	u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, PHY_OPS_GROUP,
801 					   GEO_TX_POWER_LIMIT,
802 					   IWL_FW_CMD_VER_UNKNOWN);
803 
804 	/* the ops field is at the same spot for all versions, so set in v1 */
805 	geo_tx_cmd.v1.ops =
806 		cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE);
807 
808 	if (cmd_ver == 3)
809 		len = sizeof(geo_tx_cmd.v3);
810 	else if (fw_has_api(&mvm->fwrt.fw->ucode_capa,
811 			    IWL_UCODE_TLV_API_SAR_TABLE_VER))
812 		len = sizeof(geo_tx_cmd.v2);
813 	else
814 		len = sizeof(geo_tx_cmd.v1);
815 
816 	if (!iwl_sar_geo_support(&mvm->fwrt))
817 		return -EOPNOTSUPP;
818 
819 	cmd = (struct iwl_host_cmd){
820 		.id =  WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT),
821 		.len = { len, },
822 		.flags = CMD_WANT_SKB,
823 		.data = { &geo_tx_cmd },
824 	};
825 
826 	ret = iwl_mvm_send_cmd(mvm, &cmd);
827 	if (ret) {
828 		IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret);
829 		return ret;
830 	}
831 
832 	resp = (void *)cmd.resp_pkt->data;
833 	ret = le32_to_cpu(resp->profile_idx);
834 
835 	if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES))
836 		ret = -EIO;
837 
838 	iwl_free_resp(&cmd);
839 	return ret;
840 }
841 
842 static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
843 {
844 	union iwl_geo_tx_power_profiles_cmd cmd;
845 	u16 len;
846 	u32 n_bands;
847 	int ret;
848 	u8 cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, PHY_OPS_GROUP,
849 					   GEO_TX_POWER_LIMIT,
850 					   IWL_FW_CMD_VER_UNKNOWN);
851 
852 	BUILD_BUG_ON(offsetof(struct iwl_geo_tx_power_profiles_cmd_v1, ops) !=
853 		     offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, ops) ||
854 		     offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, ops) !=
855 		     offsetof(struct iwl_geo_tx_power_profiles_cmd_v3, ops));
856 	/* the ops field is at the same spot for all versions, so set in v1 */
857 	cmd.v1.ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES);
858 
859 	if (cmd_ver == 3) {
860 		len = sizeof(cmd.v3);
861 		n_bands = ARRAY_SIZE(cmd.v3.table[0]);
862 		cmd.v3.table_revision = cpu_to_le32(mvm->fwrt.geo_rev);
863 	} else if (fw_has_api(&mvm->fwrt.fw->ucode_capa,
864 			      IWL_UCODE_TLV_API_SAR_TABLE_VER)) {
865 		len = sizeof(cmd.v2);
866 		n_bands = ARRAY_SIZE(cmd.v2.table[0]);
867 		cmd.v2.table_revision = cpu_to_le32(mvm->fwrt.geo_rev);
868 	} else {
869 		len = sizeof(cmd.v1);
870 		n_bands = ARRAY_SIZE(cmd.v1.table[0]);
871 	}
872 
873 	BUILD_BUG_ON(offsetof(struct iwl_geo_tx_power_profiles_cmd_v1, table) !=
874 		     offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, table) ||
875 		     offsetof(struct iwl_geo_tx_power_profiles_cmd_v2, table) !=
876 		     offsetof(struct iwl_geo_tx_power_profiles_cmd_v3, table));
877 	/* the table is at the same position for all versions, so set use v1 */
878 	ret = iwl_sar_geo_init(&mvm->fwrt, &cmd.v1.table[0][0], n_bands);
879 
880 	/*
881 	 * It is a valid scenario to not support SAR, or miss wgds table,
882 	 * but in that case there is no need to send the command.
883 	 */
884 	if (ret)
885 		return 0;
886 
887 	return iwl_mvm_send_cmd_pdu(mvm,
888 				    WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT),
889 				    0, len, &cmd);
890 }
891 
892 static int iwl_mvm_get_ppag_table(struct iwl_mvm *mvm)
893 {
894 	union acpi_object *wifi_pkg, *data, *enabled;
895 	union iwl_ppag_table_cmd ppag_table;
896 	int i, j, ret, tbl_rev, num_sub_bands;
897 	int idx = 2;
898 	s8 *gain;
899 
900 	/*
901 	 * The 'enabled' field is the same in v1 and v2 so we can just
902 	 * use v1 to access it.
903 	 */
904 	mvm->fwrt.ppag_table.v1.enabled = cpu_to_le32(0);
905 	data = iwl_acpi_get_object(mvm->dev, ACPI_PPAG_METHOD);
906 	if (IS_ERR(data))
907 		return PTR_ERR(data);
908 
909 	/* try to read ppag table revision 1 */
910 	wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
911 					 ACPI_PPAG_WIFI_DATA_SIZE_V2, &tbl_rev);
912 	if (!IS_ERR(wifi_pkg)) {
913 		if (tbl_rev != 1) {
914 			ret = -EINVAL;
915 			goto out_free;
916 		}
917 		num_sub_bands = IWL_NUM_SUB_BANDS_V2;
918 		gain = mvm->fwrt.ppag_table.v2.gain[0];
919 		mvm->fwrt.ppag_ver = 2;
920 		IWL_DEBUG_RADIO(mvm, "Reading PPAG table v2 (tbl_rev=1)\n");
921 		goto read_table;
922 	}
923 
924 	/* try to read ppag table revision 0 */
925 	wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
926 					 ACPI_PPAG_WIFI_DATA_SIZE, &tbl_rev);
927 	if (!IS_ERR(wifi_pkg)) {
928 		if (tbl_rev != 0) {
929 			ret = -EINVAL;
930 			goto out_free;
931 		}
932 		num_sub_bands = IWL_NUM_SUB_BANDS;
933 		gain = mvm->fwrt.ppag_table.v1.gain[0];
934 		mvm->fwrt.ppag_ver = 1;
935 		IWL_DEBUG_RADIO(mvm, "Reading PPAG table v1 (tbl_rev=0)\n");
936 		goto read_table;
937 	}
938 	ret = PTR_ERR(wifi_pkg);
939 	goto out_free;
940 
941 read_table:
942 	enabled = &wifi_pkg->package.elements[1];
943 	if (enabled->type != ACPI_TYPE_INTEGER ||
944 	    (enabled->integer.value != 0 && enabled->integer.value != 1)) {
945 		ret = -EINVAL;
946 		goto out_free;
947 	}
948 
949 	ppag_table.v1.enabled = cpu_to_le32(enabled->integer.value);
950 	if (!ppag_table.v1.enabled) {
951 		ret = 0;
952 		goto out_free;
953 	}
954 
955 	/*
956 	 * read, verify gain values and save them into the PPAG table.
957 	 * first sub-band (j=0) corresponds to Low-Band (2.4GHz), and the
958 	 * following sub-bands to High-Band (5GHz).
959 	 */
960 	for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) {
961 		for (j = 0; j < num_sub_bands; j++) {
962 			union acpi_object *ent;
963 
964 			ent = &wifi_pkg->package.elements[idx++];
965 			if (ent->type != ACPI_TYPE_INTEGER ||
966 			    (j == 0 && ent->integer.value > ACPI_PPAG_MAX_LB) ||
967 			    (j == 0 && ent->integer.value < ACPI_PPAG_MIN_LB) ||
968 			    (j != 0 && ent->integer.value > ACPI_PPAG_MAX_HB) ||
969 			    (j != 0 && ent->integer.value < ACPI_PPAG_MIN_HB)) {
970 				ppag_table.v1.enabled = cpu_to_le32(0);
971 				ret = -EINVAL;
972 				goto out_free;
973 			}
974 			gain[i * num_sub_bands + j] = ent->integer.value;
975 		}
976 	}
977 	ret = 0;
978 out_free:
979 	kfree(data);
980 	return ret;
981 }
982 
983 int iwl_mvm_ppag_send_cmd(struct iwl_mvm *mvm)
984 {
985 	u8 cmd_ver;
986 	int i, j, ret, num_sub_bands, cmd_size;
987 	union iwl_ppag_table_cmd ppag_table;
988 	s8 *gain;
989 
990 	if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_SET_PPAG)) {
991 		IWL_DEBUG_RADIO(mvm,
992 				"PPAG capability not supported by FW, command not sent.\n");
993 		return 0;
994 	}
995 	if (!mvm->fwrt.ppag_table.v1.enabled) {
996 		IWL_DEBUG_RADIO(mvm, "PPAG not enabled, command not sent.\n");
997 		return 0;
998 	}
999 
1000 	cmd_ver = iwl_fw_lookup_cmd_ver(mvm->fw, PHY_OPS_GROUP,
1001 					PER_PLATFORM_ANT_GAIN_CMD,
1002 					IWL_FW_CMD_VER_UNKNOWN);
1003 	if (cmd_ver == 1) {
1004 		num_sub_bands = IWL_NUM_SUB_BANDS;
1005 		gain = mvm->fwrt.ppag_table.v1.gain[0];
1006 		cmd_size = sizeof(ppag_table.v1);
1007 		if (mvm->fwrt.ppag_ver == 2) {
1008 			IWL_DEBUG_RADIO(mvm,
1009 					"PPAG table is v2 but FW supports v1, sending truncated table\n");
1010 		}
1011 	} else if (cmd_ver == 2) {
1012 		num_sub_bands = IWL_NUM_SUB_BANDS_V2;
1013 		gain = mvm->fwrt.ppag_table.v2.gain[0];
1014 		cmd_size = sizeof(ppag_table.v2);
1015 		if (mvm->fwrt.ppag_ver == 1) {
1016 			IWL_DEBUG_RADIO(mvm,
1017 					"PPAG table is v1 but FW supports v2, sending padded table\n");
1018 		}
1019 	} else {
1020 		IWL_DEBUG_RADIO(mvm, "Unsupported PPAG command version\n");
1021 		return 0;
1022 	}
1023 
1024 	for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) {
1025 		for (j = 0; j < num_sub_bands; j++) {
1026 			IWL_DEBUG_RADIO(mvm,
1027 					"PPAG table: chain[%d] band[%d]: gain = %d\n",
1028 					i, j, gain[i * num_sub_bands + j]);
1029 		}
1030 	}
1031 	IWL_DEBUG_RADIO(mvm, "Sending PER_PLATFORM_ANT_GAIN_CMD\n");
1032 	ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(PHY_OPS_GROUP,
1033 						PER_PLATFORM_ANT_GAIN_CMD),
1034 				   0, cmd_size, &ppag_table);
1035 	if (ret < 0)
1036 		IWL_ERR(mvm, "failed to send PER_PLATFORM_ANT_GAIN_CMD (%d)\n",
1037 			ret);
1038 
1039 	return ret;
1040 }
1041 
1042 static int iwl_mvm_ppag_init(struct iwl_mvm *mvm)
1043 {
1044 	int ret;
1045 
1046 	ret = iwl_mvm_get_ppag_table(mvm);
1047 	if (ret < 0) {
1048 		IWL_DEBUG_RADIO(mvm,
1049 				"PPAG BIOS table invalid or unavailable. (%d)\n",
1050 				ret);
1051 		return 0;
1052 	}
1053 	return iwl_mvm_ppag_send_cmd(mvm);
1054 }
1055 
1056 static void iwl_mvm_tas_init(struct iwl_mvm *mvm)
1057 {
1058 	int ret;
1059 	struct iwl_tas_config_cmd cmd = {};
1060 	int list_size;
1061 
1062 	BUILD_BUG_ON(ARRAY_SIZE(cmd.block_list_array) <
1063 		     APCI_WTAS_BLACK_LIST_MAX);
1064 
1065 	if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TAS_CFG)) {
1066 		IWL_DEBUG_RADIO(mvm, "TAS not enabled in FW\n");
1067 		return;
1068 	}
1069 
1070 	ret = iwl_acpi_get_tas(&mvm->fwrt, cmd.block_list_array, &list_size);
1071 	if (ret < 0) {
1072 		IWL_DEBUG_RADIO(mvm,
1073 				"TAS table invalid or unavailable. (%d)\n",
1074 				ret);
1075 		return;
1076 	}
1077 
1078 	if (list_size < 0)
1079 		return;
1080 
1081 	/* list size if TAS enabled can only be non-negative */
1082 	cmd.block_list_size = cpu_to_le32((u32)list_size);
1083 
1084 	ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
1085 						TAS_CONFIG),
1086 				   0, sizeof(cmd), &cmd);
1087 	if (ret < 0)
1088 		IWL_DEBUG_RADIO(mvm, "failed to send TAS_CONFIG (%d)\n", ret);
1089 }
1090 
1091 static u8 iwl_mvm_eval_dsm_indonesia_5g2(struct iwl_mvm *mvm)
1092 {
1093 	int ret = iwl_acpi_get_dsm_u8((&mvm->fwrt)->dev, 0,
1094 				      DSM_FUNC_ENABLE_INDONESIA_5G2);
1095 
1096 	if (ret < 0)
1097 		IWL_DEBUG_RADIO(mvm,
1098 				"Failed to evaluate DSM function ENABLE_INDONESIA_5G2, ret=%d\n",
1099 				ret);
1100 
1101 	else if (ret >= DSM_VALUE_INDONESIA_MAX)
1102 		IWL_DEBUG_RADIO(mvm,
1103 				"DSM function ENABLE_INDONESIA_5G2 return invalid value, ret=%d\n",
1104 				ret);
1105 
1106 	else if (ret == DSM_VALUE_INDONESIA_ENABLE) {
1107 		IWL_DEBUG_RADIO(mvm,
1108 				"Evaluated DSM function ENABLE_INDONESIA_5G2: Enabling 5g2\n");
1109 		return DSM_VALUE_INDONESIA_ENABLE;
1110 	}
1111 	/* default behaviour is disabled */
1112 	return DSM_VALUE_INDONESIA_DISABLE;
1113 }
1114 
1115 static u8 iwl_mvm_eval_dsm_disable_srd(struct iwl_mvm *mvm)
1116 {
1117 	int ret = iwl_acpi_get_dsm_u8((&mvm->fwrt)->dev, 0,
1118 				      DSM_FUNC_DISABLE_SRD);
1119 
1120 	if (ret < 0)
1121 		IWL_DEBUG_RADIO(mvm,
1122 				"Failed to evaluate DSM function DISABLE_SRD, ret=%d\n",
1123 				ret);
1124 
1125 	else if (ret >= DSM_VALUE_SRD_MAX)
1126 		IWL_DEBUG_RADIO(mvm,
1127 				"DSM function DISABLE_SRD return invalid value, ret=%d\n",
1128 				ret);
1129 
1130 	else if (ret == DSM_VALUE_SRD_PASSIVE) {
1131 		IWL_DEBUG_RADIO(mvm,
1132 				"Evaluated DSM function DISABLE_SRD: setting SRD to passive\n");
1133 		return DSM_VALUE_SRD_PASSIVE;
1134 
1135 	} else if (ret == DSM_VALUE_SRD_DISABLE) {
1136 		IWL_DEBUG_RADIO(mvm,
1137 				"Evaluated DSM function DISABLE_SRD: disabling SRD\n");
1138 		return DSM_VALUE_SRD_DISABLE;
1139 	}
1140 	/* default behaviour is active */
1141 	return DSM_VALUE_SRD_ACTIVE;
1142 }
1143 
1144 static void iwl_mvm_lari_cfg(struct iwl_mvm *mvm)
1145 {
1146 	u8 ret;
1147 	int cmd_ret;
1148 	struct iwl_lari_config_change_cmd cmd = {};
1149 
1150 	if (iwl_mvm_eval_dsm_indonesia_5g2(mvm) == DSM_VALUE_INDONESIA_ENABLE)
1151 		cmd.config_bitmap |=
1152 			cpu_to_le32(LARI_CONFIG_ENABLE_5G2_IN_INDONESIA_MSK);
1153 
1154 	ret = iwl_mvm_eval_dsm_disable_srd(mvm);
1155 	if (ret == DSM_VALUE_SRD_PASSIVE)
1156 		cmd.config_bitmap |=
1157 			cpu_to_le32(LARI_CONFIG_CHANGE_ETSI_TO_PASSIVE_MSK);
1158 
1159 	else if (ret == DSM_VALUE_SRD_DISABLE)
1160 		cmd.config_bitmap |=
1161 			cpu_to_le32(LARI_CONFIG_CHANGE_ETSI_TO_DISABLED_MSK);
1162 
1163 	/* apply more config masks here */
1164 
1165 	if (cmd.config_bitmap) {
1166 		IWL_DEBUG_RADIO(mvm, "sending LARI_CONFIG_CHANGE\n");
1167 		cmd_ret = iwl_mvm_send_cmd_pdu(mvm,
1168 					       WIDE_ID(REGULATORY_AND_NVM_GROUP,
1169 						       LARI_CONFIG_CHANGE),
1170 					       0, sizeof(cmd), &cmd);
1171 		if (cmd_ret < 0)
1172 			IWL_DEBUG_RADIO(mvm,
1173 					"Failed to send LARI_CONFIG_CHANGE (%d)\n",
1174 					cmd_ret);
1175 	}
1176 }
1177 #else /* CONFIG_ACPI */
1178 
1179 inline int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm,
1180 				      int prof_a, int prof_b)
1181 {
1182 	return -ENOENT;
1183 }
1184 
1185 inline int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
1186 {
1187 	return -ENOENT;
1188 }
1189 
1190 static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
1191 {
1192 	return 0;
1193 }
1194 
1195 int iwl_mvm_ppag_send_cmd(struct iwl_mvm *mvm)
1196 {
1197 	return -ENOENT;
1198 }
1199 
1200 static int iwl_mvm_ppag_init(struct iwl_mvm *mvm)
1201 {
1202 	return 0;
1203 }
1204 
1205 static void iwl_mvm_tas_init(struct iwl_mvm *mvm)
1206 {
1207 }
1208 
1209 static void iwl_mvm_lari_cfg(struct iwl_mvm *mvm)
1210 {
1211 }
1212 #endif /* CONFIG_ACPI */
1213 
1214 void iwl_mvm_send_recovery_cmd(struct iwl_mvm *mvm, u32 flags)
1215 {
1216 	u32 error_log_size = mvm->fw->ucode_capa.error_log_size;
1217 	int ret;
1218 	u32 resp;
1219 
1220 	struct iwl_fw_error_recovery_cmd recovery_cmd = {
1221 		.flags = cpu_to_le32(flags),
1222 		.buf_size = 0,
1223 	};
1224 	struct iwl_host_cmd host_cmd = {
1225 		.id = WIDE_ID(SYSTEM_GROUP, FW_ERROR_RECOVERY_CMD),
1226 		.flags = CMD_WANT_SKB,
1227 		.data = {&recovery_cmd, },
1228 		.len = {sizeof(recovery_cmd), },
1229 	};
1230 
1231 	/* no error log was defined in TLV */
1232 	if (!error_log_size)
1233 		return;
1234 
1235 	if (flags & ERROR_RECOVERY_UPDATE_DB) {
1236 		/* no buf was allocated while HW reset */
1237 		if (!mvm->error_recovery_buf)
1238 			return;
1239 
1240 		host_cmd.data[1] = mvm->error_recovery_buf;
1241 		host_cmd.len[1] =  error_log_size;
1242 		host_cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
1243 		recovery_cmd.buf_size = cpu_to_le32(error_log_size);
1244 	}
1245 
1246 	ret = iwl_mvm_send_cmd(mvm, &host_cmd);
1247 	kfree(mvm->error_recovery_buf);
1248 	mvm->error_recovery_buf = NULL;
1249 
1250 	if (ret) {
1251 		IWL_ERR(mvm, "Failed to send recovery cmd %d\n", ret);
1252 		return;
1253 	}
1254 
1255 	/* skb respond is only relevant in ERROR_RECOVERY_UPDATE_DB */
1256 	if (flags & ERROR_RECOVERY_UPDATE_DB) {
1257 		resp = le32_to_cpu(*(__le32 *)host_cmd.resp_pkt->data);
1258 		if (resp)
1259 			IWL_ERR(mvm,
1260 				"Failed to send recovery cmd blob was invalid %d\n",
1261 				resp);
1262 	}
1263 }
1264 
1265 static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
1266 {
1267 	int ret;
1268 
1269 	ret = iwl_sar_get_wrds_table(&mvm->fwrt);
1270 	if (ret < 0) {
1271 		IWL_DEBUG_RADIO(mvm,
1272 				"WRDS SAR BIOS table invalid or unavailable. (%d)\n",
1273 				ret);
1274 		/*
1275 		 * If not available, don't fail and don't bother with EWRD.
1276 		 * Return 1 to tell that we can't use WGDS either.
1277 		 */
1278 		return 1;
1279 	}
1280 
1281 	ret = iwl_sar_get_ewrd_table(&mvm->fwrt);
1282 	/* if EWRD is not available, we can still use WRDS, so don't fail */
1283 	if (ret < 0)
1284 		IWL_DEBUG_RADIO(mvm,
1285 				"EWRD SAR BIOS table invalid or unavailable. (%d)\n",
1286 				ret);
1287 
1288 	return iwl_mvm_sar_select_profile(mvm, 1, 1);
1289 }
1290 
1291 static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)
1292 {
1293 	int ret;
1294 
1295 	if (iwl_mvm_has_unified_ucode(mvm))
1296 		return iwl_run_unified_mvm_ucode(mvm);
1297 
1298 	WARN_ON(!mvm->nvm_data);
1299 	ret = iwl_run_init_mvm_ucode(mvm);
1300 
1301 	if (ret) {
1302 		IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
1303 
1304 		if (iwlmvm_mod_params.init_dbg)
1305 			return 0;
1306 		return ret;
1307 	}
1308 
1309 	iwl_fw_dbg_stop_sync(&mvm->fwrt);
1310 	iwl_trans_stop_device(mvm->trans);
1311 	ret = iwl_trans_start_hw(mvm->trans);
1312 	if (ret)
1313 		return ret;
1314 
1315 	iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_EARLY, NULL);
1316 
1317 	mvm->rfkill_safe_init_done = false;
1318 	ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
1319 	if (ret)
1320 		return ret;
1321 
1322 	mvm->rfkill_safe_init_done = true;
1323 
1324 	iwl_dbg_tlv_time_point(&mvm->fwrt, IWL_FW_INI_TIME_POINT_AFTER_ALIVE,
1325 			       NULL);
1326 
1327 	return iwl_init_paging(&mvm->fwrt, mvm->fwrt.cur_fw_img);
1328 }
1329 
1330 int iwl_mvm_up(struct iwl_mvm *mvm)
1331 {
1332 	int ret, i;
1333 	struct ieee80211_channel *chan;
1334 	struct cfg80211_chan_def chandef;
1335 	struct ieee80211_supported_band *sband = NULL;
1336 
1337 	lockdep_assert_held(&mvm->mutex);
1338 
1339 	ret = iwl_trans_start_hw(mvm->trans);
1340 	if (ret)
1341 		return ret;
1342 
1343 	ret = iwl_mvm_load_rt_fw(mvm);
1344 	if (ret) {
1345 		IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
1346 		if (ret != -ERFKILL)
1347 			iwl_fw_dbg_error_collect(&mvm->fwrt,
1348 						 FW_DBG_TRIGGER_DRIVER);
1349 		goto error;
1350 	}
1351 
1352 	iwl_get_shared_mem_conf(&mvm->fwrt);
1353 
1354 	ret = iwl_mvm_sf_update(mvm, NULL, false);
1355 	if (ret)
1356 		IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
1357 
1358 	if (!iwl_trans_dbg_ini_valid(mvm->trans)) {
1359 		mvm->fwrt.dump.conf = FW_DBG_INVALID;
1360 		/* if we have a destination, assume EARLY START */
1361 		if (mvm->fw->dbg.dest_tlv)
1362 			mvm->fwrt.dump.conf = FW_DBG_START_FROM_ALIVE;
1363 		iwl_fw_start_dbg_conf(&mvm->fwrt, FW_DBG_START_FROM_ALIVE);
1364 	}
1365 
1366 	ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
1367 	if (ret)
1368 		goto error;
1369 
1370 	if (!iwl_mvm_has_unified_ucode(mvm)) {
1371 		/* Send phy db control command and then phy db calibration */
1372 		ret = iwl_send_phy_db_data(mvm->phy_db);
1373 		if (ret)
1374 			goto error;
1375 	}
1376 
1377 	ret = iwl_send_phy_cfg_cmd(mvm);
1378 	if (ret)
1379 		goto error;
1380 
1381 	ret = iwl_mvm_send_bt_init_conf(mvm);
1382 	if (ret)
1383 		goto error;
1384 
1385 	if (fw_has_capa(&mvm->fw->ucode_capa,
1386 			IWL_UCODE_TLV_CAPA_SOC_LATENCY_SUPPORT)) {
1387 		ret = iwl_set_soc_latency(&mvm->fwrt);
1388 		if (ret)
1389 			goto error;
1390 	}
1391 
1392 	/* Init RSS configuration */
1393 	if (mvm->trans->trans_cfg->device_family >= IWL_DEVICE_FAMILY_22000) {
1394 		ret = iwl_configure_rxq(mvm);
1395 		if (ret) {
1396 			IWL_ERR(mvm, "Failed to configure RX queues: %d\n",
1397 				ret);
1398 			goto error;
1399 		}
1400 	}
1401 
1402 	if (iwl_mvm_has_new_rx_api(mvm)) {
1403 		ret = iwl_send_rss_cfg_cmd(mvm);
1404 		if (ret) {
1405 			IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
1406 				ret);
1407 			goto error;
1408 		}
1409 	}
1410 
1411 	/* init the fw <-> mac80211 STA mapping */
1412 	for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++)
1413 		RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1414 
1415 	mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
1416 
1417 	/* reset quota debouncing buffer - 0xff will yield invalid data */
1418 	memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
1419 
1420 	if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_DQA_SUPPORT)) {
1421 		ret = iwl_mvm_send_dqa_cmd(mvm);
1422 		if (ret)
1423 			goto error;
1424 	}
1425 
1426 	/*
1427 	 * Add auxiliary station for scanning.
1428 	 * Newer versions of this command implies that the fw uses
1429 	 * internal aux station for all aux activities that don't
1430 	 * requires a dedicated data queue.
1431 	 */
1432 	if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
1433 				  ADD_STA,
1434 				  0) < 12) {
1435 		 /*
1436 		  * In old version the aux station uses mac id like other
1437 		  * station and not lmac id
1438 		  */
1439 		ret = iwl_mvm_add_aux_sta(mvm, MAC_INDEX_AUX);
1440 		if (ret)
1441 			goto error;
1442 	}
1443 
1444 	/* Add all the PHY contexts */
1445 	i = 0;
1446 	while (!sband && i < NUM_NL80211_BANDS)
1447 		sband = mvm->hw->wiphy->bands[i++];
1448 
1449 	if (WARN_ON_ONCE(!sband))
1450 		goto error;
1451 
1452 	chan = &sband->channels[0];
1453 
1454 	cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
1455 	for (i = 0; i < NUM_PHY_CTX; i++) {
1456 		/*
1457 		 * The channel used here isn't relevant as it's
1458 		 * going to be overwritten in the other flows.
1459 		 * For now use the first channel we have.
1460 		 */
1461 		ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
1462 					   &chandef, 1, 1);
1463 		if (ret)
1464 			goto error;
1465 	}
1466 
1467 	if (iwl_mvm_is_tt_in_fw(mvm)) {
1468 		/* in order to give the responsibility of ct-kill and
1469 		 * TX backoff to FW we need to send empty temperature reporting
1470 		 * cmd during init time
1471 		 */
1472 		iwl_mvm_send_temp_report_ths_cmd(mvm);
1473 	} else {
1474 		/* Initialize tx backoffs to the minimal possible */
1475 		iwl_mvm_tt_tx_backoff(mvm, 0);
1476 	}
1477 
1478 #ifdef CONFIG_THERMAL
1479 	/* TODO: read the budget from BIOS / Platform NVM */
1480 
1481 	/*
1482 	 * In case there is no budget from BIOS / Platform NVM the default
1483 	 * budget should be 2000mW (cooling state 0).
1484 	 */
1485 	if (iwl_mvm_is_ctdp_supported(mvm)) {
1486 		ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
1487 					   mvm->cooling_dev.cur_state);
1488 		if (ret)
1489 			goto error;
1490 	}
1491 #endif
1492 
1493 	if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_SET_LTR_GEN2))
1494 		WARN_ON(iwl_mvm_config_ltr(mvm));
1495 
1496 	ret = iwl_mvm_power_update_device(mvm);
1497 	if (ret)
1498 		goto error;
1499 
1500 	iwl_mvm_lari_cfg(mvm);
1501 	/*
1502 	 * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
1503 	 * anyway, so don't init MCC.
1504 	 */
1505 	if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
1506 		ret = iwl_mvm_init_mcc(mvm);
1507 		if (ret)
1508 			goto error;
1509 	}
1510 
1511 	if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1512 		mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
1513 		mvm->hb_scan_type = IWL_SCAN_TYPE_NOT_SET;
1514 		ret = iwl_mvm_config_scan(mvm);
1515 		if (ret)
1516 			goto error;
1517 	}
1518 
1519 	if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1520 		iwl_mvm_send_recovery_cmd(mvm, ERROR_RECOVERY_UPDATE_DB);
1521 
1522 	if (iwl_acpi_get_eckv(mvm->dev, &mvm->ext_clock_valid))
1523 		IWL_DEBUG_INFO(mvm, "ECKV table doesn't exist in BIOS\n");
1524 
1525 	ret = iwl_mvm_ppag_init(mvm);
1526 	if (ret)
1527 		goto error;
1528 
1529 	ret = iwl_mvm_sar_init(mvm);
1530 	if (ret == 0) {
1531 		ret = iwl_mvm_sar_geo_init(mvm);
1532 	} else if (ret == -ENOENT && !iwl_sar_get_wgds_table(&mvm->fwrt)) {
1533 		/*
1534 		 * If basic SAR is not available, we check for WGDS,
1535 		 * which should *not* be available either.  If it is
1536 		 * available, issue an error, because we can't use SAR
1537 		 * Geo without basic SAR.
1538 		 */
1539 		IWL_ERR(mvm, "BIOS contains WGDS but no WRDS\n");
1540 	}
1541 
1542 	if (ret < 0)
1543 		goto error;
1544 
1545 	iwl_mvm_tas_init(mvm);
1546 	iwl_mvm_leds_sync(mvm);
1547 
1548 	iwl_mvm_ftm_initiator_smooth_config(mvm);
1549 
1550 	IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
1551 	return 0;
1552  error:
1553 	if (!iwlmvm_mod_params.init_dbg || !ret)
1554 		iwl_mvm_stop_device(mvm);
1555 	return ret;
1556 }
1557 
1558 int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
1559 {
1560 	int ret, i;
1561 
1562 	lockdep_assert_held(&mvm->mutex);
1563 
1564 	ret = iwl_trans_start_hw(mvm->trans);
1565 	if (ret)
1566 		return ret;
1567 
1568 	ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
1569 	if (ret) {
1570 		IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
1571 		goto error;
1572 	}
1573 
1574 	ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
1575 	if (ret)
1576 		goto error;
1577 
1578 	/* Send phy db control command and then phy db calibration*/
1579 	ret = iwl_send_phy_db_data(mvm->phy_db);
1580 	if (ret)
1581 		goto error;
1582 
1583 	ret = iwl_send_phy_cfg_cmd(mvm);
1584 	if (ret)
1585 		goto error;
1586 
1587 	/* init the fw <-> mac80211 STA mapping */
1588 	for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++)
1589 		RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1590 
1591 	if (iwl_fw_lookup_cmd_ver(mvm->fw, LONG_GROUP,
1592 				  ADD_STA,
1593 				  0) < 12) {
1594 		/*
1595 		 * Add auxiliary station for scanning.
1596 		 * Newer versions of this command implies that the fw uses
1597 		 * internal aux station for all aux activities that don't
1598 		 * requires a dedicated data queue.
1599 		 * In old version the aux station uses mac id like other
1600 		 * station and not lmac id
1601 		 */
1602 		ret = iwl_mvm_add_aux_sta(mvm, MAC_INDEX_AUX);
1603 		if (ret)
1604 			goto error;
1605 	}
1606 
1607 	return 0;
1608  error:
1609 	iwl_mvm_stop_device(mvm);
1610 	return ret;
1611 }
1612 
1613 void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
1614 				 struct iwl_rx_cmd_buffer *rxb)
1615 {
1616 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1617 	struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
1618 	u32 flags = le32_to_cpu(card_state_notif->flags);
1619 
1620 	IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
1621 			  (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1622 			  (flags & SW_CARD_DISABLED) ? "Kill" : "On",
1623 			  (flags & CT_KILL_CARD_DISABLED) ?
1624 			  "Reached" : "Not reached");
1625 }
1626 
1627 void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1628 			     struct iwl_rx_cmd_buffer *rxb)
1629 {
1630 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1631 	struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
1632 
1633 	IWL_DEBUG_INFO(mvm,
1634 		       "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
1635 		       le32_to_cpu(mfuart_notif->installed_ver),
1636 		       le32_to_cpu(mfuart_notif->external_ver),
1637 		       le32_to_cpu(mfuart_notif->status),
1638 		       le32_to_cpu(mfuart_notif->duration));
1639 
1640 	if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif))
1641 		IWL_DEBUG_INFO(mvm,
1642 			       "MFUART: image size: 0x%08x\n",
1643 			       le32_to_cpu(mfuart_notif->image_size));
1644 }
1645