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