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 	u32 umac_error_event_table;
180 
181 	if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
182 		palive = (void *)pkt->data;
183 		umac = &palive->umac_data;
184 		lmac1 = &palive->lmac_data[0];
185 		lmac2 = &palive->lmac_data[1];
186 		status = le16_to_cpu(palive->status);
187 	} else {
188 		palive3 = (void *)pkt->data;
189 		umac = &palive3->umac_data;
190 		lmac1 = &palive3->lmac_data;
191 		status = le16_to_cpu(palive3->status);
192 	}
193 
194 	mvm->error_event_table[0] = le32_to_cpu(lmac1->error_event_table_ptr);
195 	if (lmac2)
196 		mvm->error_event_table[1] =
197 			le32_to_cpu(lmac2->error_event_table_ptr);
198 	mvm->log_event_table = le32_to_cpu(lmac1->log_event_table_ptr);
199 
200 	umac_error_event_table = le32_to_cpu(umac->error_info_addr);
201 
202 	if (!umac_error_event_table) {
203 		mvm->support_umac_log = false;
204 	} else if (umac_error_event_table >=
205 		   mvm->trans->cfg->min_umac_error_event_table) {
206 		mvm->support_umac_log = true;
207 		mvm->umac_error_event_table = umac_error_event_table;
208 	} else {
209 		IWL_ERR(mvm,
210 			"Not valid error log pointer 0x%08X for %s uCode\n",
211 			mvm->umac_error_event_table,
212 			(mvm->fwrt.cur_fw_img == IWL_UCODE_INIT) ?
213 			"Init" : "RT");
214 		mvm->support_umac_log = false;
215 	}
216 
217 	alive_data->scd_base_addr = le32_to_cpu(lmac1->scd_base_ptr);
218 	alive_data->valid = status == IWL_ALIVE_STATUS_OK;
219 
220 	IWL_DEBUG_FW(mvm,
221 		     "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n",
222 		     status, lmac1->ver_type, lmac1->ver_subtype);
223 
224 	if (lmac2)
225 		IWL_DEBUG_FW(mvm, "Alive ucode CDB\n");
226 
227 	IWL_DEBUG_FW(mvm,
228 		     "UMAC version: Major - 0x%x, Minor - 0x%x\n",
229 		     le32_to_cpu(umac->umac_major),
230 		     le32_to_cpu(umac->umac_minor));
231 
232 	return true;
233 }
234 
235 static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait,
236 				   struct iwl_rx_packet *pkt, void *data)
237 {
238 	WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
239 
240 	return true;
241 }
242 
243 static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
244 				  struct iwl_rx_packet *pkt, void *data)
245 {
246 	struct iwl_phy_db *phy_db = data;
247 
248 	if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
249 		WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
250 		return true;
251 	}
252 
253 	WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
254 
255 	return false;
256 }
257 
258 static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
259 					 enum iwl_ucode_type ucode_type)
260 {
261 	struct iwl_notification_wait alive_wait;
262 	struct iwl_mvm_alive_data alive_data;
263 	const struct fw_img *fw;
264 	int ret, i;
265 	enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img;
266 	static const u16 alive_cmd[] = { MVM_ALIVE };
267 
268 	if (ucode_type == IWL_UCODE_REGULAR &&
269 	    iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
270 	    !(fw_has_capa(&mvm->fw->ucode_capa,
271 			  IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
272 		fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER);
273 	else
274 		fw = iwl_get_ucode_image(mvm->fw, ucode_type);
275 	if (WARN_ON(!fw))
276 		return -EINVAL;
277 	iwl_fw_set_current_image(&mvm->fwrt, ucode_type);
278 	clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
279 
280 	iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
281 				   alive_cmd, ARRAY_SIZE(alive_cmd),
282 				   iwl_alive_fn, &alive_data);
283 
284 	ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
285 	if (ret) {
286 		iwl_fw_set_current_image(&mvm->fwrt, old_type);
287 		iwl_remove_notification(&mvm->notif_wait, &alive_wait);
288 		return ret;
289 	}
290 
291 	/*
292 	 * Some things may run in the background now, but we
293 	 * just wait for the ALIVE notification here.
294 	 */
295 	ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
296 				    MVM_UCODE_ALIVE_TIMEOUT);
297 	if (ret) {
298 		struct iwl_trans *trans = mvm->trans;
299 
300 		if (trans->cfg->device_family == IWL_DEVICE_FAMILY_22000)
301 			IWL_ERR(mvm,
302 				"SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
303 				iwl_read_prph(trans, UMAG_SB_CPU_1_STATUS),
304 				iwl_read_prph(trans, UMAG_SB_CPU_2_STATUS));
305 		else if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
306 			IWL_ERR(mvm,
307 				"SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
308 				iwl_read_prph(trans, SB_CPU_1_STATUS),
309 				iwl_read_prph(trans, SB_CPU_2_STATUS));
310 		iwl_fw_set_current_image(&mvm->fwrt, old_type);
311 		return ret;
312 	}
313 
314 	if (!alive_data.valid) {
315 		IWL_ERR(mvm, "Loaded ucode is not valid!\n");
316 		iwl_fw_set_current_image(&mvm->fwrt, old_type);
317 		return -EIO;
318 	}
319 
320 	iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
321 
322 	/*
323 	 * Note: all the queues are enabled as part of the interface
324 	 * initialization, but in firmware restart scenarios they
325 	 * could be stopped, so wake them up. In firmware restart,
326 	 * mac80211 will have the queues stopped as well until the
327 	 * reconfiguration completes. During normal startup, they
328 	 * will be empty.
329 	 */
330 
331 	memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
332 	mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1;
333 
334 	for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
335 		atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
336 
337 	set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
338 
339 	return 0;
340 }
341 
342 static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
343 {
344 	struct iwl_notification_wait init_wait;
345 	struct iwl_nvm_access_complete_cmd nvm_complete = {};
346 	struct iwl_init_extended_cfg_cmd init_cfg = {
347 		.init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)),
348 	};
349 	static const u16 init_complete[] = {
350 		INIT_COMPLETE_NOTIF,
351 	};
352 	int ret;
353 
354 	lockdep_assert_held(&mvm->mutex);
355 
356 	iwl_init_notification_wait(&mvm->notif_wait,
357 				   &init_wait,
358 				   init_complete,
359 				   ARRAY_SIZE(init_complete),
360 				   iwl_wait_init_complete,
361 				   NULL);
362 
363 	/* Will also start the device */
364 	ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
365 	if (ret) {
366 		IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
367 		goto error;
368 	}
369 
370 	/* Send init config command to mark that we are sending NVM access
371 	 * commands
372 	 */
373 	ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP,
374 						INIT_EXTENDED_CFG_CMD), 0,
375 				   sizeof(init_cfg), &init_cfg);
376 	if (ret) {
377 		IWL_ERR(mvm, "Failed to run init config command: %d\n",
378 			ret);
379 		goto error;
380 	}
381 
382 	/* Load NVM to NIC if needed */
383 	if (mvm->nvm_file_name) {
384 		iwl_mvm_read_external_nvm(mvm);
385 		iwl_mvm_load_nvm_to_nic(mvm);
386 	}
387 
388 	if (IWL_MVM_PARSE_NVM && read_nvm) {
389 		ret = iwl_nvm_init(mvm);
390 		if (ret) {
391 			IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
392 			goto error;
393 		}
394 	}
395 
396 	ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
397 						NVM_ACCESS_COMPLETE), 0,
398 				   sizeof(nvm_complete), &nvm_complete);
399 	if (ret) {
400 		IWL_ERR(mvm, "Failed to run complete NVM access: %d\n",
401 			ret);
402 		goto error;
403 	}
404 
405 	/* We wait for the INIT complete notification */
406 	ret = iwl_wait_notification(&mvm->notif_wait, &init_wait,
407 				    MVM_UCODE_ALIVE_TIMEOUT);
408 	if (ret)
409 		return ret;
410 
411 	/* Read the NVM only at driver load time, no need to do this twice */
412 	if (!IWL_MVM_PARSE_NVM && read_nvm) {
413 		mvm->nvm_data = iwl_fw_get_nvm(&mvm->fwrt);
414 		if (IS_ERR(mvm->nvm_data)) {
415 			ret = PTR_ERR(mvm->nvm_data);
416 			mvm->nvm_data = NULL;
417 			IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
418 			return ret;
419 		}
420 	}
421 
422 	return 0;
423 
424 error:
425 	iwl_remove_notification(&mvm->notif_wait, &init_wait);
426 	return ret;
427 }
428 
429 static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
430 {
431 	struct iwl_phy_cfg_cmd phy_cfg_cmd;
432 	enum iwl_ucode_type ucode_type = mvm->fwrt.cur_fw_img;
433 
434 	/* Set parameters */
435 	phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
436 	phy_cfg_cmd.calib_control.event_trigger =
437 		mvm->fw->default_calib[ucode_type].event_trigger;
438 	phy_cfg_cmd.calib_control.flow_trigger =
439 		mvm->fw->default_calib[ucode_type].flow_trigger;
440 
441 	IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
442 		       phy_cfg_cmd.phy_cfg);
443 
444 	return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
445 				    sizeof(phy_cfg_cmd), &phy_cfg_cmd);
446 }
447 
448 int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
449 {
450 	struct iwl_notification_wait calib_wait;
451 	static const u16 init_complete[] = {
452 		INIT_COMPLETE_NOTIF,
453 		CALIB_RES_NOTIF_PHY_DB
454 	};
455 	int ret;
456 
457 	if (iwl_mvm_has_unified_ucode(mvm))
458 		return iwl_run_unified_mvm_ucode(mvm, true);
459 
460 	lockdep_assert_held(&mvm->mutex);
461 
462 	if (WARN_ON_ONCE(mvm->calibrating))
463 		return 0;
464 
465 	iwl_init_notification_wait(&mvm->notif_wait,
466 				   &calib_wait,
467 				   init_complete,
468 				   ARRAY_SIZE(init_complete),
469 				   iwl_wait_phy_db_entry,
470 				   mvm->phy_db);
471 
472 	/* Will also start the device */
473 	ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
474 	if (ret) {
475 		IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
476 		goto remove_notif;
477 	}
478 
479 	if (mvm->cfg->device_family < IWL_DEVICE_FAMILY_8000) {
480 		ret = iwl_mvm_send_bt_init_conf(mvm);
481 		if (ret)
482 			goto remove_notif;
483 	}
484 
485 	/* Read the NVM only at driver load time, no need to do this twice */
486 	if (read_nvm) {
487 		ret = iwl_nvm_init(mvm);
488 		if (ret) {
489 			IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
490 			goto remove_notif;
491 		}
492 	}
493 
494 	/* In case we read the NVM from external file, load it to the NIC */
495 	if (mvm->nvm_file_name)
496 		iwl_mvm_load_nvm_to_nic(mvm);
497 
498 	WARN_ON(iwl_nvm_check_version(mvm->nvm_data, mvm->trans));
499 
500 	/*
501 	 * abort after reading the nvm in case RF Kill is on, we will complete
502 	 * the init seq later when RF kill will switch to off
503 	 */
504 	if (iwl_mvm_is_radio_hw_killed(mvm)) {
505 		IWL_DEBUG_RF_KILL(mvm,
506 				  "jump over all phy activities due to RF kill\n");
507 		goto remove_notif;
508 	}
509 
510 	mvm->calibrating = true;
511 
512 	/* Send TX valid antennas before triggering calibrations */
513 	ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
514 	if (ret)
515 		goto remove_notif;
516 
517 	ret = iwl_send_phy_cfg_cmd(mvm);
518 	if (ret) {
519 		IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
520 			ret);
521 		goto remove_notif;
522 	}
523 
524 	/*
525 	 * Some things may run in the background now, but we
526 	 * just wait for the calibration complete notification.
527 	 */
528 	ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
529 				    MVM_UCODE_CALIB_TIMEOUT);
530 	if (!ret)
531 		goto out;
532 
533 	if (iwl_mvm_is_radio_hw_killed(mvm)) {
534 		IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
535 		ret = 0;
536 	} else {
537 		IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
538 			ret);
539 	}
540 
541 	goto out;
542 
543 remove_notif:
544 	iwl_remove_notification(&mvm->notif_wait, &calib_wait);
545 out:
546 	mvm->calibrating = false;
547 	if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
548 		/* we want to debug INIT and we have no NVM - fake */
549 		mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
550 					sizeof(struct ieee80211_channel) +
551 					sizeof(struct ieee80211_rate),
552 					GFP_KERNEL);
553 		if (!mvm->nvm_data)
554 			return -ENOMEM;
555 		mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
556 		mvm->nvm_data->bands[0].n_channels = 1;
557 		mvm->nvm_data->bands[0].n_bitrates = 1;
558 		mvm->nvm_data->bands[0].bitrates =
559 			(void *)mvm->nvm_data->channels + 1;
560 		mvm->nvm_data->bands[0].bitrates->hw_value = 10;
561 	}
562 
563 	return ret;
564 }
565 
566 static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
567 {
568 	struct iwl_ltr_config_cmd cmd = {
569 		.flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
570 	};
571 
572 	if (!mvm->trans->ltr_enabled)
573 		return 0;
574 
575 	return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
576 				    sizeof(cmd), &cmd);
577 }
578 
579 #ifdef CONFIG_ACPI
580 static int iwl_mvm_sar_set_profile(struct iwl_mvm *mvm,
581 				   union acpi_object *table,
582 				   struct iwl_mvm_sar_profile *profile,
583 				   bool enabled)
584 {
585 	int i;
586 
587 	profile->enabled = enabled;
588 
589 	for (i = 0; i < ACPI_SAR_TABLE_SIZE; i++) {
590 		if ((table[i].type != ACPI_TYPE_INTEGER) ||
591 		    (table[i].integer.value > U8_MAX))
592 			return -EINVAL;
593 
594 		profile->table[i] = table[i].integer.value;
595 	}
596 
597 	return 0;
598 }
599 
600 static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
601 {
602 	union acpi_object *wifi_pkg, *table, *data;
603 	bool enabled;
604 	int ret;
605 
606 	data = iwl_acpi_get_object(mvm->dev, ACPI_WRDS_METHOD);
607 	if (IS_ERR(data))
608 		return PTR_ERR(data);
609 
610 	wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
611 					 ACPI_WRDS_WIFI_DATA_SIZE);
612 	if (IS_ERR(wifi_pkg)) {
613 		ret = PTR_ERR(wifi_pkg);
614 		goto out_free;
615 	}
616 
617 	if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
618 		ret = -EINVAL;
619 		goto out_free;
620 	}
621 
622 	enabled = !!(wifi_pkg->package.elements[1].integer.value);
623 
624 	/* position of the actual table */
625 	table = &wifi_pkg->package.elements[2];
626 
627 	/* The profile from WRDS is officially profile 1, but goes
628 	 * into sar_profiles[0] (because we don't have a profile 0).
629 	 */
630 	ret = iwl_mvm_sar_set_profile(mvm, table, &mvm->sar_profiles[0],
631 				      enabled);
632 out_free:
633 	kfree(data);
634 	return ret;
635 }
636 
637 static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
638 {
639 	union acpi_object *wifi_pkg, *data;
640 	bool enabled;
641 	int i, n_profiles, ret;
642 
643 	data = iwl_acpi_get_object(mvm->dev, ACPI_EWRD_METHOD);
644 	if (IS_ERR(data))
645 		return PTR_ERR(data);
646 
647 	wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
648 					 ACPI_EWRD_WIFI_DATA_SIZE);
649 	if (IS_ERR(wifi_pkg)) {
650 		ret = PTR_ERR(wifi_pkg);
651 		goto out_free;
652 	}
653 
654 	if ((wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) ||
655 	    (wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER)) {
656 		ret = -EINVAL;
657 		goto out_free;
658 	}
659 
660 	enabled = !!(wifi_pkg->package.elements[1].integer.value);
661 	n_profiles = wifi_pkg->package.elements[2].integer.value;
662 
663 	/* in case of BIOS bug */
664 	if (n_profiles <= 0) {
665 		ret = -EINVAL;
666 		goto out_free;
667 	}
668 
669 	for (i = 0; i < n_profiles; i++) {
670 		/* the tables start at element 3 */
671 		static int pos = 3;
672 
673 		/* The EWRD profiles officially go from 2 to 4, but we
674 		 * save them in sar_profiles[1-3] (because we don't
675 		 * have profile 0).  So in the array we start from 1.
676 		 */
677 		ret = iwl_mvm_sar_set_profile(mvm,
678 					      &wifi_pkg->package.elements[pos],
679 					      &mvm->sar_profiles[i + 1],
680 					      enabled);
681 		if (ret < 0)
682 			break;
683 
684 		/* go to the next table */
685 		pos += ACPI_SAR_TABLE_SIZE;
686 	}
687 
688 out_free:
689 	kfree(data);
690 	return ret;
691 }
692 
693 static int iwl_mvm_sar_get_wgds_table(struct iwl_mvm *mvm)
694 {
695 	union acpi_object *wifi_pkg, *data;
696 	int i, j, ret;
697 	int idx = 1;
698 
699 	data = iwl_acpi_get_object(mvm->dev, ACPI_WGDS_METHOD);
700 	if (IS_ERR(data))
701 		return PTR_ERR(data);
702 
703 	wifi_pkg = iwl_acpi_get_wifi_pkg(mvm->dev, data,
704 					 ACPI_WGDS_WIFI_DATA_SIZE);
705 	if (IS_ERR(wifi_pkg)) {
706 		ret = PTR_ERR(wifi_pkg);
707 		goto out_free;
708 	}
709 
710 	for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
711 		for (j = 0; j < ACPI_GEO_TABLE_SIZE; j++) {
712 			union acpi_object *entry;
713 
714 			entry = &wifi_pkg->package.elements[idx++];
715 			if ((entry->type != ACPI_TYPE_INTEGER) ||
716 			    (entry->integer.value > U8_MAX)) {
717 				ret = -EINVAL;
718 				goto out_free;
719 			}
720 
721 			mvm->geo_profiles[i].values[j] = entry->integer.value;
722 		}
723 	}
724 	ret = 0;
725 out_free:
726 	kfree(data);
727 	return ret;
728 }
729 
730 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b)
731 {
732 	struct iwl_dev_tx_power_cmd cmd = {
733 		.v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
734 	};
735 	int i, j, idx;
736 	int profs[ACPI_SAR_NUM_CHAIN_LIMITS] = { prof_a, prof_b };
737 	int len = sizeof(cmd);
738 
739 	BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS < 2);
740 	BUILD_BUG_ON(ACPI_SAR_NUM_CHAIN_LIMITS * ACPI_SAR_NUM_SUB_BANDS !=
741 		     ACPI_SAR_TABLE_SIZE);
742 
743 	if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
744 		len = sizeof(cmd.v3);
745 
746 	for (i = 0; i < ACPI_SAR_NUM_CHAIN_LIMITS; i++) {
747 		struct iwl_mvm_sar_profile *prof;
748 
749 		/* don't allow SAR to be disabled (profile 0 means disable) */
750 		if (profs[i] == 0)
751 			return -EPERM;
752 
753 		/* we are off by one, so allow up to ACPI_SAR_PROFILE_NUM */
754 		if (profs[i] > ACPI_SAR_PROFILE_NUM)
755 			return -EINVAL;
756 
757 		/* profiles go from 1 to 4, so decrement to access the array */
758 		prof = &mvm->sar_profiles[profs[i] - 1];
759 
760 		/* if the profile is disabled, do nothing */
761 		if (!prof->enabled) {
762 			IWL_DEBUG_RADIO(mvm, "SAR profile %d is disabled.\n",
763 					profs[i]);
764 			/* if one of the profiles is disabled, we fail all */
765 			return -ENOENT;
766 		}
767 
768 		IWL_DEBUG_RADIO(mvm, "  Chain[%d]:\n", i);
769 		for (j = 0; j < ACPI_SAR_NUM_SUB_BANDS; j++) {
770 			idx = (i * ACPI_SAR_NUM_SUB_BANDS) + j;
771 			cmd.v3.per_chain_restriction[i][j] =
772 				cpu_to_le16(prof->table[idx]);
773 			IWL_DEBUG_RADIO(mvm, "    Band[%d] = %d * .125dBm\n",
774 					j, prof->table[idx]);
775 		}
776 	}
777 
778 	IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
779 
780 	return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
781 }
782 
783 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
784 {
785 	struct iwl_geo_tx_power_profiles_resp *resp;
786 	int ret;
787 
788 	struct iwl_geo_tx_power_profiles_cmd geo_cmd = {
789 		.ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE),
790 	};
791 	struct iwl_host_cmd cmd = {
792 		.id =  WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT),
793 		.len = { sizeof(geo_cmd), },
794 		.flags = CMD_WANT_SKB,
795 		.data = { &geo_cmd },
796 	};
797 
798 	ret = iwl_mvm_send_cmd(mvm, &cmd);
799 	if (ret) {
800 		IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret);
801 		return ret;
802 	}
803 
804 	resp = (void *)cmd.resp_pkt->data;
805 	ret = le32_to_cpu(resp->profile_idx);
806 	if (WARN_ON(ret > ACPI_NUM_GEO_PROFILES)) {
807 		ret = -EIO;
808 		IWL_WARN(mvm, "Invalid geographic profile idx (%d)\n", ret);
809 	}
810 
811 	iwl_free_resp(&cmd);
812 	return ret;
813 }
814 
815 static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
816 {
817 	struct iwl_geo_tx_power_profiles_cmd cmd = {
818 		.ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES),
819 	};
820 	int ret, i, j;
821 	u16 cmd_wide_id =  WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT);
822 
823 	ret = iwl_mvm_sar_get_wgds_table(mvm);
824 	if (ret < 0) {
825 		IWL_DEBUG_RADIO(mvm,
826 				"Geo SAR BIOS table invalid or unavailable. (%d)\n",
827 				ret);
828 		/* we don't fail if the table is not available */
829 		return 0;
830 	}
831 
832 	IWL_DEBUG_RADIO(mvm, "Sending GEO_TX_POWER_LIMIT\n");
833 
834 	BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES * ACPI_WGDS_NUM_BANDS *
835 		     ACPI_WGDS_TABLE_SIZE !=  ACPI_WGDS_WIFI_DATA_SIZE);
836 
837 	BUILD_BUG_ON(ACPI_NUM_GEO_PROFILES > IWL_NUM_GEO_PROFILES);
838 
839 	for (i = 0; i < ACPI_NUM_GEO_PROFILES; i++) {
840 		struct iwl_per_chain_offset *chain =
841 			(struct iwl_per_chain_offset *)&cmd.table[i];
842 
843 		for (j = 0; j < ACPI_WGDS_NUM_BANDS; j++) {
844 			u8 *value;
845 
846 			value = &mvm->geo_profiles[i].values[j *
847 				ACPI_GEO_PER_CHAIN_SIZE];
848 			chain[j].max_tx_power = cpu_to_le16(value[0]);
849 			chain[j].chain_a = value[1];
850 			chain[j].chain_b = value[2];
851 			IWL_DEBUG_RADIO(mvm,
852 					"SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
853 					i, j, value[1], value[2], value[0]);
854 		}
855 	}
856 	return iwl_mvm_send_cmd_pdu(mvm, cmd_wide_id, 0, sizeof(cmd), &cmd);
857 }
858 
859 #else /* CONFIG_ACPI */
860 static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
861 {
862 	return -ENOENT;
863 }
864 
865 static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
866 {
867 	return -ENOENT;
868 }
869 
870 static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
871 {
872 	return 0;
873 }
874 
875 int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a,
876 			       int prof_b)
877 {
878 	return -ENOENT;
879 }
880 
881 int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
882 {
883 	return -ENOENT;
884 }
885 #endif /* CONFIG_ACPI */
886 
887 static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
888 {
889 	int ret;
890 
891 	ret = iwl_mvm_sar_get_wrds_table(mvm);
892 	if (ret < 0) {
893 		IWL_DEBUG_RADIO(mvm,
894 				"WRDS SAR BIOS table invalid or unavailable. (%d)\n",
895 				ret);
896 		/* if not available, don't fail and don't bother with EWRD */
897 		return 0;
898 	}
899 
900 	ret = iwl_mvm_sar_get_ewrd_table(mvm);
901 	/* if EWRD is not available, we can still use WRDS, so don't fail */
902 	if (ret < 0)
903 		IWL_DEBUG_RADIO(mvm,
904 				"EWRD SAR BIOS table invalid or unavailable. (%d)\n",
905 				ret);
906 
907 	/* choose profile 1 (WRDS) as default for both chains */
908 	ret = iwl_mvm_sar_select_profile(mvm, 1, 1);
909 
910 	/* if we don't have profile 0 from BIOS, just skip it */
911 	if (ret == -ENOENT)
912 		return 0;
913 
914 	return ret;
915 }
916 
917 static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)
918 {
919 	int ret;
920 
921 	if (iwl_mvm_has_unified_ucode(mvm))
922 		return iwl_run_unified_mvm_ucode(mvm, false);
923 
924 	ret = iwl_run_init_mvm_ucode(mvm, false);
925 
926 	if (ret) {
927 		IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
928 
929 		if (iwlmvm_mod_params.init_dbg)
930 			return 0;
931 		return ret;
932 	}
933 
934 	/*
935 	 * Stop and start the transport without entering low power
936 	 * mode. This will save the state of other components on the
937 	 * device that are triggered by the INIT firwmare (MFUART).
938 	 */
939 	_iwl_trans_stop_device(mvm->trans, false);
940 	ret = _iwl_trans_start_hw(mvm->trans, false);
941 	if (ret)
942 		return ret;
943 
944 	ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
945 	if (ret)
946 		return ret;
947 
948 	return iwl_init_paging(&mvm->fwrt, mvm->fwrt.cur_fw_img);
949 }
950 
951 int iwl_mvm_up(struct iwl_mvm *mvm)
952 {
953 	int ret, i;
954 	struct ieee80211_channel *chan;
955 	struct cfg80211_chan_def chandef;
956 
957 	lockdep_assert_held(&mvm->mutex);
958 
959 	ret = iwl_trans_start_hw(mvm->trans);
960 	if (ret)
961 		return ret;
962 
963 	ret = iwl_mvm_load_rt_fw(mvm);
964 	if (ret) {
965 		IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
966 		goto error;
967 	}
968 
969 	iwl_get_shared_mem_conf(&mvm->fwrt);
970 
971 	ret = iwl_mvm_sf_update(mvm, NULL, false);
972 	if (ret)
973 		IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
974 
975 	mvm->fwrt.dump.conf = FW_DBG_INVALID;
976 	/* if we have a destination, assume EARLY START */
977 	if (mvm->fw->dbg_dest_tlv)
978 		mvm->fwrt.dump.conf = FW_DBG_START_FROM_ALIVE;
979 	iwl_fw_start_dbg_conf(&mvm->fwrt, FW_DBG_START_FROM_ALIVE);
980 
981 	ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
982 	if (ret)
983 		goto error;
984 
985 	if (!iwl_mvm_has_unified_ucode(mvm)) {
986 		/* Send phy db control command and then phy db calibration */
987 		ret = iwl_send_phy_db_data(mvm->phy_db);
988 		if (ret)
989 			goto error;
990 
991 		ret = iwl_send_phy_cfg_cmd(mvm);
992 		if (ret)
993 			goto error;
994 	}
995 
996 	ret = iwl_mvm_send_bt_init_conf(mvm);
997 	if (ret)
998 		goto error;
999 
1000 	/* Init RSS configuration */
1001 	/* TODO - remove 22000 disablement when we have RXQ config API */
1002 	if (iwl_mvm_has_new_rx_api(mvm) &&
1003 	    mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_22000) {
1004 		ret = iwl_send_rss_cfg_cmd(mvm);
1005 		if (ret) {
1006 			IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
1007 				ret);
1008 			goto error;
1009 		}
1010 	}
1011 
1012 	/* init the fw <-> mac80211 STA mapping */
1013 	for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
1014 		RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1015 
1016 	mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
1017 
1018 	/* reset quota debouncing buffer - 0xff will yield invalid data */
1019 	memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
1020 
1021 	ret = iwl_mvm_send_dqa_cmd(mvm);
1022 	if (ret)
1023 		goto error;
1024 
1025 	/* Add auxiliary station for scanning */
1026 	ret = iwl_mvm_add_aux_sta(mvm);
1027 	if (ret)
1028 		goto error;
1029 
1030 	/* Add all the PHY contexts */
1031 	chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0];
1032 	cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
1033 	for (i = 0; i < NUM_PHY_CTX; i++) {
1034 		/*
1035 		 * The channel used here isn't relevant as it's
1036 		 * going to be overwritten in the other flows.
1037 		 * For now use the first channel we have.
1038 		 */
1039 		ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
1040 					   &chandef, 1, 1);
1041 		if (ret)
1042 			goto error;
1043 	}
1044 
1045 #ifdef CONFIG_THERMAL
1046 	if (iwl_mvm_is_tt_in_fw(mvm)) {
1047 		/* in order to give the responsibility of ct-kill and
1048 		 * TX backoff to FW we need to send empty temperature reporting
1049 		 * cmd during init time
1050 		 */
1051 		iwl_mvm_send_temp_report_ths_cmd(mvm);
1052 	} else {
1053 		/* Initialize tx backoffs to the minimal possible */
1054 		iwl_mvm_tt_tx_backoff(mvm, 0);
1055 	}
1056 
1057 	/* TODO: read the budget from BIOS / Platform NVM */
1058 
1059 	/*
1060 	 * In case there is no budget from BIOS / Platform NVM the default
1061 	 * budget should be 2000mW (cooling state 0).
1062 	 */
1063 	if (iwl_mvm_is_ctdp_supported(mvm)) {
1064 		ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
1065 					   mvm->cooling_dev.cur_state);
1066 		if (ret)
1067 			goto error;
1068 	}
1069 #else
1070 	/* Initialize tx backoffs to the minimal possible */
1071 	iwl_mvm_tt_tx_backoff(mvm, 0);
1072 #endif
1073 
1074 	WARN_ON(iwl_mvm_config_ltr(mvm));
1075 
1076 	ret = iwl_mvm_power_update_device(mvm);
1077 	if (ret)
1078 		goto error;
1079 
1080 	/*
1081 	 * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
1082 	 * anyway, so don't init MCC.
1083 	 */
1084 	if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
1085 		ret = iwl_mvm_init_mcc(mvm);
1086 		if (ret)
1087 			goto error;
1088 	}
1089 
1090 	if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
1091 		mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
1092 		ret = iwl_mvm_config_scan(mvm);
1093 		if (ret)
1094 			goto error;
1095 	}
1096 
1097 	/* allow FW/transport low power modes if not during restart */
1098 	if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1099 		iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1100 
1101 	ret = iwl_mvm_sar_init(mvm);
1102 	if (ret)
1103 		goto error;
1104 
1105 	ret = iwl_mvm_sar_geo_init(mvm);
1106 	if (ret)
1107 		goto error;
1108 
1109 	iwl_mvm_leds_sync(mvm);
1110 
1111 	IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
1112 	return 0;
1113  error:
1114 	if (!iwlmvm_mod_params.init_dbg || !ret)
1115 		iwl_mvm_stop_device(mvm);
1116 	return ret;
1117 }
1118 
1119 int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
1120 {
1121 	int ret, i;
1122 
1123 	lockdep_assert_held(&mvm->mutex);
1124 
1125 	ret = iwl_trans_start_hw(mvm->trans);
1126 	if (ret)
1127 		return ret;
1128 
1129 	ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
1130 	if (ret) {
1131 		IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
1132 		goto error;
1133 	}
1134 
1135 	ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
1136 	if (ret)
1137 		goto error;
1138 
1139 	/* Send phy db control command and then phy db calibration*/
1140 	ret = iwl_send_phy_db_data(mvm->phy_db);
1141 	if (ret)
1142 		goto error;
1143 
1144 	ret = iwl_send_phy_cfg_cmd(mvm);
1145 	if (ret)
1146 		goto error;
1147 
1148 	/* init the fw <-> mac80211 STA mapping */
1149 	for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
1150 		RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1151 
1152 	/* Add auxiliary station for scanning */
1153 	ret = iwl_mvm_add_aux_sta(mvm);
1154 	if (ret)
1155 		goto error;
1156 
1157 	return 0;
1158  error:
1159 	iwl_mvm_stop_device(mvm);
1160 	return ret;
1161 }
1162 
1163 void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
1164 				 struct iwl_rx_cmd_buffer *rxb)
1165 {
1166 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1167 	struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
1168 	u32 flags = le32_to_cpu(card_state_notif->flags);
1169 
1170 	IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
1171 			  (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1172 			  (flags & SW_CARD_DISABLED) ? "Kill" : "On",
1173 			  (flags & CT_KILL_CARD_DISABLED) ?
1174 			  "Reached" : "Not reached");
1175 }
1176 
1177 void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1178 			     struct iwl_rx_cmd_buffer *rxb)
1179 {
1180 	struct iwl_rx_packet *pkt = rxb_addr(rxb);
1181 	struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
1182 
1183 	IWL_DEBUG_INFO(mvm,
1184 		       "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
1185 		       le32_to_cpu(mfuart_notif->installed_ver),
1186 		       le32_to_cpu(mfuart_notif->external_ver),
1187 		       le32_to_cpu(mfuart_notif->status),
1188 		       le32_to_cpu(mfuart_notif->duration));
1189 
1190 	if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif))
1191 		IWL_DEBUG_INFO(mvm,
1192 			       "MFUART: image size: 0x%08x\n",
1193 			       le32_to_cpu(mfuart_notif->image_size));
1194 }
1195