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