iwlwifi: mvm: remove the corunning support
[linux-2.6-block.git] / drivers / net / wireless / intel / iwlwifi / mvm / fw.c
CommitLineData
8ca151b5
JB
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 *
51368bf7 8 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8d193ca2 9 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
bdccdb85 10 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
8ca151b5
JB
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
410dc5aa 27 * in the file called COPYING.
8ca151b5
JB
28 *
29 * Contact Information:
cb2f8277 30 * Intel Linux Wireless <linuxwifi@intel.com>
8ca151b5
JB
31 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
32 *
33 * BSD LICENSE
34 *
51368bf7 35 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8d193ca2 36 * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH
bdccdb85 37 * Copyright(c) 2016 - 2017 Intel Deutschland GmbH
8ca151b5
JB
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>
854d773e 68#include <linux/netdevice.h>
da2830ac 69#include <linux/acpi.h>
8ca151b5
JB
70
71#include "iwl-trans.h"
72#include "iwl-op-mode.h"
d962f9b1 73#include "fw/img.h"
8ca151b5
JB
74#include "iwl-debug.h"
75#include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */
76#include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */
8c23f95c 77#include "iwl-prph.h"
8ca151b5
JB
78#include "iwl-eeprom-parse.h"
79
80#include "mvm.h"
7174beb6 81#include "fw/dbg.h"
8ca151b5
JB
82#include "iwl-phy-db.h"
83
84#define MVM_UCODE_ALIVE_TIMEOUT HZ
85#define MVM_UCODE_CALIB_TIMEOUT (2*HZ)
86
87#define UCODE_VALID_OK cpu_to_le32(0x1)
88
8ca151b5
JB
89struct iwl_mvm_alive_data {
90 bool valid;
91 u32 scd_base_addr;
92};
93
8ca151b5
JB
94static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
95{
96 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
97 .valid = cpu_to_le32(valid_tx_ant),
98 };
99
33223542 100 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
a1022927 101 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
8ca151b5
JB
102 sizeof(tx_ant_cmd), &tx_ant_cmd);
103}
104
43413a97
SS
105static int iwl_send_rss_cfg_cmd(struct iwl_mvm *mvm)
106{
107 int i;
108 struct iwl_rss_config_cmd cmd = {
109 .flags = cpu_to_le32(IWL_RSS_ENABLE),
110 .hash_mask = IWL_RSS_HASH_TYPE_IPV4_TCP |
854d773e 111 IWL_RSS_HASH_TYPE_IPV4_UDP |
43413a97
SS
112 IWL_RSS_HASH_TYPE_IPV4_PAYLOAD |
113 IWL_RSS_HASH_TYPE_IPV6_TCP |
854d773e 114 IWL_RSS_HASH_TYPE_IPV6_UDP |
43413a97
SS
115 IWL_RSS_HASH_TYPE_IPV6_PAYLOAD,
116 };
117
f43495fd
SS
118 if (mvm->trans->num_rx_queues == 1)
119 return 0;
120
854d773e 121 /* Do not direct RSS traffic to Q 0 which is our fallback queue */
43413a97 122 for (i = 0; i < ARRAY_SIZE(cmd.indirection_table); i++)
854d773e
SS
123 cmd.indirection_table[i] =
124 1 + (i % (mvm->trans->num_rx_queues - 1));
125 netdev_rss_key_fill(cmd.secret_key, sizeof(cmd.secret_key));
43413a97
SS
126
127 return iwl_mvm_send_cmd_pdu(mvm, RSS_CONFIG_CMD, 0, sizeof(cmd), &cmd);
128}
129
97d5be7e
LK
130static int iwl_mvm_send_dqa_cmd(struct iwl_mvm *mvm)
131{
132 struct iwl_dqa_enable_cmd dqa_cmd = {
133 .cmd_queue = cpu_to_le32(IWL_MVM_DQA_CMD_QUEUE),
134 };
135 u32 cmd_id = iwl_cmd_id(DQA_ENABLE_CMD, DATA_PATH_GROUP, 0);
136 int ret;
137
138 ret = iwl_mvm_send_cmd_pdu(mvm, cmd_id, 0, sizeof(dqa_cmd), &dqa_cmd);
139 if (ret)
140 IWL_ERR(mvm, "Failed to send DQA enabling command: %d\n", ret);
141 else
142 IWL_DEBUG_FW(mvm, "Working in DQA mode\n");
143
144 return ret;
145}
146
bdccdb85
GBA
147void iwl_mvm_mfu_assert_dump_notif(struct iwl_mvm *mvm,
148 struct iwl_rx_cmd_buffer *rxb)
149{
150 struct iwl_rx_packet *pkt = rxb_addr(rxb);
151 struct iwl_mfu_assert_dump_notif *mfu_dump_notif = (void *)pkt->data;
152 __le32 *dump_data = mfu_dump_notif->data;
153 int n_words = le32_to_cpu(mfu_dump_notif->data_size) / sizeof(__le32);
154 int i;
155
156 if (mfu_dump_notif->index_num == 0)
157 IWL_INFO(mvm, "MFUART assert id 0x%x occurred\n",
158 le32_to_cpu(mfu_dump_notif->assert_id));
159
160 for (i = 0; i < n_words; i++)
161 IWL_DEBUG_INFO(mvm,
162 "MFUART assert dump, dword %u: 0x%08x\n",
163 le16_to_cpu(mfu_dump_notif->index_num) *
164 n_words + i,
165 le32_to_cpu(dump_data[i]));
166}
167
8ca151b5
JB
168static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
169 struct iwl_rx_packet *pkt, void *data)
170{
171 struct iwl_mvm *mvm =
172 container_of(notif_wait, struct iwl_mvm, notif_wait);
173 struct iwl_mvm_alive_data *alive_data = data;
5c228d63 174 struct mvm_alive_resp_v3 *palive3;
7e1223b5 175 struct mvm_alive_resp *palive;
5c228d63
SS
176 struct iwl_umac_alive *umac;
177 struct iwl_lmac_alive *lmac1;
178 struct iwl_lmac_alive *lmac2 = NULL;
179 u16 status;
01a9ca51 180
5c228d63
SS
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 }
01a9ca51 193
5c228d63
SS
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 mvm->sf_space.addr = le32_to_cpu(lmac1->st_fwrd_addr);
200 mvm->sf_space.size = le32_to_cpu(lmac1->st_fwrd_size);
ffa70264 201
5c228d63 202 mvm->umac_error_event_table = le32_to_cpu(umac->error_info_addr);
01a9ca51 203
5c228d63
SS
204 alive_data->scd_base_addr = le32_to_cpu(lmac1->scd_base_ptr);
205 alive_data->valid = status == IWL_ALIVE_STATUS_OK;
206 if (mvm->umac_error_event_table)
207 mvm->support_umac_log = true;
7e1223b5 208
5c228d63
SS
209 IWL_DEBUG_FW(mvm,
210 "Alive ucode status 0x%04x revision 0x%01X 0x%01X\n",
211 status, lmac1->ver_type, lmac1->ver_subtype);
7e1223b5 212
5c228d63
SS
213 if (lmac2)
214 IWL_DEBUG_FW(mvm, "Alive ucode CDB\n");
7e1223b5 215
5c228d63
SS
216 IWL_DEBUG_FW(mvm,
217 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
218 le32_to_cpu(umac->umac_major),
219 le32_to_cpu(umac->umac_minor));
8ca151b5
JB
220
221 return true;
222}
223
1f370650
SS
224static bool iwl_wait_init_complete(struct iwl_notif_wait_data *notif_wait,
225 struct iwl_rx_packet *pkt, void *data)
226{
227 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
228
229 return true;
230}
231
8ca151b5
JB
232static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
233 struct iwl_rx_packet *pkt, void *data)
234{
235 struct iwl_phy_db *phy_db = data;
236
237 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
238 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
239 return true;
240 }
241
ce1f2778 242 WARN_ON(iwl_phy_db_set_section(phy_db, pkt));
8ca151b5
JB
243
244 return false;
245}
246
247static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
248 enum iwl_ucode_type ucode_type)
249{
250 struct iwl_notification_wait alive_wait;
251 struct iwl_mvm_alive_data alive_data;
252 const struct fw_img *fw;
253 int ret, i;
702e975d 254 enum iwl_ucode_type old_type = mvm->fwrt.cur_fw_img;
6eb031d2 255 static const u16 alive_cmd[] = { MVM_ALIVE };
91479b64 256 struct iwl_sf_region st_fwrd_space;
8ca151b5 257
61df750c 258 if (ucode_type == IWL_UCODE_REGULAR &&
3d2d4422
GBA
259 iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_START_FROM_ALIVE) &&
260 !(fw_has_capa(&mvm->fw->ucode_capa,
261 IWL_UCODE_TLV_CAPA_USNIFFER_UNIFIED)))
612da1ef 262 fw = iwl_get_ucode_image(mvm->fw, IWL_UCODE_REGULAR_USNIFFER);
61df750c 263 else
612da1ef 264 fw = iwl_get_ucode_image(mvm->fw, ucode_type);
befe9b6f 265 if (WARN_ON(!fw))
8ca151b5 266 return -EINVAL;
702e975d 267 iwl_fw_set_current_image(&mvm->fwrt, ucode_type);
65b280fe 268 clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
8ca151b5
JB
269
270 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
271 alive_cmd, ARRAY_SIZE(alive_cmd),
272 iwl_alive_fn, &alive_data);
273
274 ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
275 if (ret) {
702e975d 276 iwl_fw_set_current_image(&mvm->fwrt, old_type);
8ca151b5
JB
277 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
278 return ret;
279 }
280
281 /*
282 * Some things may run in the background now, but we
283 * just wait for the ALIVE notification here.
284 */
285 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
286 MVM_UCODE_ALIVE_TIMEOUT);
287 if (ret) {
d6be9c1d
SS
288 struct iwl_trans *trans = mvm->trans;
289
6e584873 290 if (trans->cfg->device_family == IWL_DEVICE_FAMILY_A000)
d6be9c1d
SS
291 IWL_ERR(mvm,
292 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
293 iwl_read_prph(trans, UMAG_SB_CPU_1_STATUS),
294 iwl_read_prph(trans, UMAG_SB_CPU_2_STATUS));
6e584873 295 else if (trans->cfg->device_family >= IWL_DEVICE_FAMILY_8000)
192de2b4
DS
296 IWL_ERR(mvm,
297 "SecBoot CPU1 Status: 0x%x, CPU2 Status: 0x%x\n",
d6be9c1d
SS
298 iwl_read_prph(trans, SB_CPU_1_STATUS),
299 iwl_read_prph(trans, SB_CPU_2_STATUS));
702e975d 300 iwl_fw_set_current_image(&mvm->fwrt, old_type);
8ca151b5
JB
301 return ret;
302 }
303
304 if (!alive_data.valid) {
305 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
702e975d 306 iwl_fw_set_current_image(&mvm->fwrt, old_type);
8ca151b5
JB
307 return -EIO;
308 }
309
91479b64
EH
310 /*
311 * update the sdio allocation according to the pointer we get in the
312 * alive notification.
313 */
314 st_fwrd_space.addr = mvm->sf_space.addr;
315 st_fwrd_space.size = mvm->sf_space.size;
316 ret = iwl_trans_update_sf(mvm->trans, &st_fwrd_space);
82e8aea0
ES
317 if (ret) {
318 IWL_ERR(mvm, "Failed to update SF size. ret %d\n", ret);
319 return ret;
320 }
91479b64 321
8ca151b5
JB
322 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
323
324 /*
325 * Note: all the queues are enabled as part of the interface
326 * initialization, but in firmware restart scenarios they
327 * could be stopped, so wake them up. In firmware restart,
328 * mac80211 will have the queues stopped as well until the
329 * reconfiguration completes. During normal startup, they
330 * will be empty.
331 */
332
4ecafae9 333 memset(&mvm->queue_info, 0, sizeof(mvm->queue_info));
c8f54701 334 mvm->queue_info[IWL_MVM_DQA_CMD_QUEUE].hw_queue_refcount = 1;
8ca151b5 335
df197c00
JB
336 for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
337 atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
8ca151b5 338
65b280fe 339 set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
8ca151b5
JB
340
341 return 0;
342}
8ca151b5 343
8c5f47b1
JB
344static int iwl_run_unified_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
345{
346 struct iwl_notification_wait init_wait;
347 struct iwl_nvm_access_complete_cmd nvm_complete = {};
348 struct iwl_init_extended_cfg_cmd init_cfg = {
349 .init_flags = cpu_to_le32(BIT(IWL_INIT_NVM)),
350 };
351 static const u16 init_complete[] = {
352 INIT_COMPLETE_NOTIF,
353 };
354 int ret;
355
356 lockdep_assert_held(&mvm->mutex);
357
358 iwl_init_notification_wait(&mvm->notif_wait,
359 &init_wait,
360 init_complete,
361 ARRAY_SIZE(init_complete),
362 iwl_wait_init_complete,
363 NULL);
364
365 /* Will also start the device */
366 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
367 if (ret) {
368 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
369 goto error;
370 }
371
372 /* Send init config command to mark that we are sending NVM access
373 * commands
374 */
375 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(SYSTEM_GROUP,
376 INIT_EXTENDED_CFG_CMD), 0,
377 sizeof(init_cfg), &init_cfg);
378 if (ret) {
379 IWL_ERR(mvm, "Failed to run init config command: %d\n",
380 ret);
381 goto error;
382 }
383
e9e1ba3d
SS
384 /* Load NVM to NIC if needed */
385 if (mvm->nvm_file_name) {
386 iwl_mvm_read_external_nvm(mvm);
8c5f47b1 387 iwl_mvm_load_nvm_to_nic(mvm);
e9e1ba3d 388 }
8c5f47b1 389
d4f3695e
SS
390 if (IWL_MVM_PARSE_NVM && read_nvm) {
391 ret = iwl_nvm_init(mvm, true);
392 if (ret) {
393 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
394 goto error;
395 }
396 }
397
8c5f47b1
JB
398 ret = iwl_mvm_send_cmd_pdu(mvm, WIDE_ID(REGULATORY_AND_NVM_GROUP,
399 NVM_ACCESS_COMPLETE), 0,
400 sizeof(nvm_complete), &nvm_complete);
401 if (ret) {
402 IWL_ERR(mvm, "Failed to run complete NVM access: %d\n",
403 ret);
404 goto error;
405 }
406
407 /* We wait for the INIT complete notification */
e9e1ba3d
SS
408 ret = iwl_wait_notification(&mvm->notif_wait, &init_wait,
409 MVM_UCODE_ALIVE_TIMEOUT);
410 if (ret)
411 return ret;
412
413 /* Read the NVM only at driver load time, no need to do this twice */
d4f3695e 414 if (!IWL_MVM_PARSE_NVM && read_nvm) {
c135cb56
ST
415 mvm->nvm_data = iwl_fw_get_nvm(&mvm->fwrt);
416 if (IS_ERR(mvm->nvm_data)) {
417 ret = PTR_ERR(mvm->nvm_data);
418 mvm->nvm_data = NULL;
e9e1ba3d
SS
419 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
420 return ret;
421 }
422 }
423
424 return 0;
8c5f47b1
JB
425
426error:
427 iwl_remove_notification(&mvm->notif_wait, &init_wait);
428 return ret;
429}
430
8ca151b5
JB
431static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
432{
433 struct iwl_phy_cfg_cmd phy_cfg_cmd;
702e975d 434 enum iwl_ucode_type ucode_type = mvm->fwrt.cur_fw_img;
8ca151b5
JB
435
436 /* Set parameters */
a0544272 437 phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
8ca151b5
JB
438 phy_cfg_cmd.calib_control.event_trigger =
439 mvm->fw->default_calib[ucode_type].event_trigger;
440 phy_cfg_cmd.calib_control.flow_trigger =
441 mvm->fw->default_calib[ucode_type].flow_trigger;
442
443 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
444 phy_cfg_cmd.phy_cfg);
445
a1022927 446 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
8ca151b5
JB
447 sizeof(phy_cfg_cmd), &phy_cfg_cmd);
448}
449
8ca151b5
JB
450int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
451{
452 struct iwl_notification_wait calib_wait;
6eb031d2 453 static const u16 init_complete[] = {
8ca151b5
JB
454 INIT_COMPLETE_NOTIF,
455 CALIB_RES_NOTIF_PHY_DB
456 };
457 int ret;
458
7d6222e2 459 if (iwl_mvm_has_unified_ucode(mvm))
8c5f47b1
JB
460 return iwl_run_unified_mvm_ucode(mvm, true);
461
8ca151b5
JB
462 lockdep_assert_held(&mvm->mutex);
463
8d193ca2 464 if (WARN_ON_ONCE(mvm->calibrating))
8ca151b5
JB
465 return 0;
466
467 iwl_init_notification_wait(&mvm->notif_wait,
468 &calib_wait,
469 init_complete,
470 ARRAY_SIZE(init_complete),
471 iwl_wait_phy_db_entry,
472 mvm->phy_db);
473
474 /* Will also start the device */
475 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
476 if (ret) {
477 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
478 goto error;
479 }
480
b3de3ef4
EG
481 if (mvm->cfg->device_family < IWL_DEVICE_FAMILY_8000) {
482 ret = iwl_mvm_send_bt_init_conf(mvm);
483 if (ret)
484 goto error;
485 }
931d4160 486
81a67e32 487 /* Read the NVM only at driver load time, no need to do this twice */
8ca151b5
JB
488 if (read_nvm) {
489 /* Read nvm */
14b485f0 490 ret = iwl_nvm_init(mvm, true);
8ca151b5
JB
491 if (ret) {
492 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
493 goto error;
494 }
495 }
496
81a67e32 497 /* In case we read the NVM from external file, load it to the NIC */
e02a9d60 498 if (mvm->nvm_file_name)
81a67e32
EL
499 iwl_mvm_load_nvm_to_nic(mvm);
500
8ca151b5
JB
501 ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans);
502 WARN_ON(ret);
503
4f59334b
EH
504 /*
505 * abort after reading the nvm in case RF Kill is on, we will complete
506 * the init seq later when RF kill will switch to off
507 */
1a3fe0b2 508 if (iwl_mvm_is_radio_hw_killed(mvm)) {
4f59334b
EH
509 IWL_DEBUG_RF_KILL(mvm,
510 "jump over all phy activities due to RF kill\n");
511 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
a4082843
AN
512 ret = 1;
513 goto out;
4f59334b
EH
514 }
515
31b8b343
EG
516 mvm->calibrating = true;
517
e07cbb53 518 /* Send TX valid antennas before triggering calibrations */
a0544272 519 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
e07cbb53
DS
520 if (ret)
521 goto error;
522
8ca151b5
JB
523 /*
524 * Send phy configurations command to init uCode
525 * to start the 16.0 uCode init image internal calibrations.
526 */
527 ret = iwl_send_phy_cfg_cmd(mvm);
528 if (ret) {
529 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
530 ret);
531 goto error;
532 }
533
534 /*
535 * Some things may run in the background now, but we
536 * just wait for the calibration complete notification.
537 */
538 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
539 MVM_UCODE_CALIB_TIMEOUT);
31b8b343 540
1a3fe0b2 541 if (ret && iwl_mvm_is_radio_hw_killed(mvm)) {
31b8b343
EG
542 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
543 ret = 1;
544 }
8ca151b5
JB
545 goto out;
546
547error:
548 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
549out:
31b8b343 550 mvm->calibrating = false;
a4082843 551 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
8ca151b5
JB
552 /* we want to debug INIT and we have no NVM - fake */
553 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
554 sizeof(struct ieee80211_channel) +
555 sizeof(struct ieee80211_rate),
556 GFP_KERNEL);
557 if (!mvm->nvm_data)
558 return -ENOMEM;
8ca151b5
JB
559 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
560 mvm->nvm_data->bands[0].n_channels = 1;
561 mvm->nvm_data->bands[0].n_bitrates = 1;
562 mvm->nvm_data->bands[0].bitrates =
563 (void *)mvm->nvm_data->channels + 1;
564 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
565 }
566
567 return ret;
568}
569
84bfffa9
EG
570static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
571{
572 struct iwl_ltr_config_cmd cmd = {
573 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
574 };
575
576 if (!mvm->trans->ltr_enabled)
577 return 0;
578
84bfffa9
EG
579 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
580 sizeof(cmd), &cmd);
581}
582
c386dacb
HD
583#ifdef CONFIG_ACPI
584#define ACPI_WRDS_METHOD "WRDS"
69964905 585#define ACPI_EWRD_METHOD "EWRD"
a6bff3cb 586#define ACPI_WGDS_METHOD "WGDS"
69964905 587#define ACPI_WIFI_DOMAIN (0x07)
c386dacb 588#define ACPI_WRDS_WIFI_DATA_SIZE (IWL_MVM_SAR_TABLE_SIZE + 2)
69964905
LC
589#define ACPI_EWRD_WIFI_DATA_SIZE ((IWL_MVM_SAR_PROFILE_NUM - 1) * \
590 IWL_MVM_SAR_TABLE_SIZE + 3)
a6bff3cb
HD
591#define ACPI_WGDS_WIFI_DATA_SIZE 18
592#define ACPI_WGDS_NUM_BANDS 2
593#define ACPI_WGDS_TABLE_SIZE 3
c386dacb
HD
594
595static int iwl_mvm_sar_set_profile(struct iwl_mvm *mvm,
596 union acpi_object *table,
597 struct iwl_mvm_sar_profile *profile,
598 bool enabled)
599{
600 int i;
da2830ac 601
c386dacb 602 profile->enabled = enabled;
da2830ac 603
c386dacb
HD
604 for (i = 0; i < IWL_MVM_SAR_TABLE_SIZE; i++) {
605 if ((table[i].type != ACPI_TYPE_INTEGER) ||
606 (table[i].integer.value > U8_MAX))
607 return -EINVAL;
608
609 profile->table[i] = table[i].integer.value;
610 }
611
612 return 0;
613}
614
615static union acpi_object *iwl_mvm_sar_find_wifi_pkg(struct iwl_mvm *mvm,
616 union acpi_object *data,
617 int data_size)
da2830ac 618{
46d4b68f 619 union acpi_object *wifi_pkg = NULL;
c386dacb 620 int i;
da2830ac 621
c386dacb
HD
622 /*
623 * We need at least two packages, one for the revision and one
da2830ac
LC
624 * for the data itself. Also check that the revision is valid
625 * (i.e. it is an integer set to 0).
c386dacb
HD
626 */
627 if (data->type != ACPI_TYPE_PACKAGE ||
628 data->package.count < 2 ||
629 data->package.elements[0].type != ACPI_TYPE_INTEGER ||
630 data->package.elements[0].integer.value != 0) {
631 IWL_DEBUG_RADIO(mvm, "Unsupported packages structure\n");
632 return ERR_PTR(-EINVAL);
da2830ac
LC
633 }
634
635 /* loop through all the packages to find the one for WiFi */
c386dacb 636 for (i = 1; i < data->package.count; i++) {
da2830ac
LC
637 union acpi_object *domain;
638
c386dacb 639 wifi_pkg = &data->package.elements[i];
da2830ac
LC
640
641 /* Skip anything that is not a package with the right
642 * amount of elements (i.e. domain_type,
c386dacb 643 * enabled/disabled plus the actual data size.
da2830ac 644 */
c386dacb
HD
645 if (wifi_pkg->type != ACPI_TYPE_PACKAGE ||
646 wifi_pkg->package.count != data_size)
da2830ac
LC
647 continue;
648
c386dacb 649 domain = &wifi_pkg->package.elements[0];
da2830ac 650 if (domain->type == ACPI_TYPE_INTEGER &&
69964905 651 domain->integer.value == ACPI_WIFI_DOMAIN)
da2830ac
LC
652 break;
653
c386dacb 654 wifi_pkg = NULL;
da2830ac
LC
655 }
656
c386dacb
HD
657 if (!wifi_pkg)
658 return ERR_PTR(-ENOENT);
da2830ac 659
c386dacb 660 return wifi_pkg;
da2830ac
LC
661}
662
c386dacb 663static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
da2830ac 664{
c386dacb 665 union acpi_object *wifi_pkg, *table;
da2830ac
LC
666 acpi_handle root_handle;
667 acpi_handle handle;
668 struct acpi_buffer wrds = {ACPI_ALLOCATE_BUFFER, NULL};
669 acpi_status status;
c386dacb 670 bool enabled;
da2830ac
LC
671 int ret;
672
673 root_handle = ACPI_HANDLE(mvm->dev);
674 if (!root_handle) {
675 IWL_DEBUG_RADIO(mvm,
676 "Could not retrieve root port ACPI handle\n");
677 return -ENOENT;
678 }
679
680 /* Get the method's handle */
681 status = acpi_get_handle(root_handle, (acpi_string)ACPI_WRDS_METHOD,
682 &handle);
683 if (ACPI_FAILURE(status)) {
684 IWL_DEBUG_RADIO(mvm, "WRDS method not found\n");
685 return -ENOENT;
686 }
687
688 /* Call WRDS with no arguments */
689 status = acpi_evaluate_object(handle, NULL, NULL, &wrds);
690 if (ACPI_FAILURE(status)) {
691 IWL_DEBUG_RADIO(mvm, "WRDS invocation failed (0x%x)\n", status);
692 return -ENOENT;
693 }
694
c386dacb
HD
695 wifi_pkg = iwl_mvm_sar_find_wifi_pkg(mvm, wrds.pointer,
696 ACPI_WRDS_WIFI_DATA_SIZE);
697 if (IS_ERR(wifi_pkg)) {
698 ret = PTR_ERR(wifi_pkg);
699 goto out_free;
700 }
701
702 if (wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) {
703 ret = -EINVAL;
704 goto out_free;
705 }
706
707 enabled = !!(wifi_pkg->package.elements[1].integer.value);
da2830ac 708
c386dacb
HD
709 /* position of the actual table */
710 table = &wifi_pkg->package.elements[2];
711
712 /* The profile from WRDS is officially profile 1, but goes
713 * into sar_profiles[0] (because we don't have a profile 0).
714 */
715 ret = iwl_mvm_sar_set_profile(mvm, table, &mvm->sar_profiles[0],
716 enabled);
717
718out_free:
719 kfree(wrds.pointer);
da2830ac
LC
720 return ret;
721}
da2830ac 722
69964905
LC
723static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
724{
725 union acpi_object *wifi_pkg;
726 acpi_handle root_handle;
727 acpi_handle handle;
728 struct acpi_buffer ewrd = {ACPI_ALLOCATE_BUFFER, NULL};
729 acpi_status status;
730 bool enabled;
731 int i, n_profiles, ret;
732
733 root_handle = ACPI_HANDLE(mvm->dev);
734 if (!root_handle) {
735 IWL_DEBUG_RADIO(mvm,
736 "Could not retrieve root port ACPI handle\n");
737 return -ENOENT;
738 }
739
740 /* Get the method's handle */
741 status = acpi_get_handle(root_handle, (acpi_string)ACPI_EWRD_METHOD,
742 &handle);
743 if (ACPI_FAILURE(status)) {
744 IWL_DEBUG_RADIO(mvm, "EWRD method not found\n");
745 return -ENOENT;
746 }
747
748 /* Call EWRD with no arguments */
749 status = acpi_evaluate_object(handle, NULL, NULL, &ewrd);
750 if (ACPI_FAILURE(status)) {
751 IWL_DEBUG_RADIO(mvm, "EWRD invocation failed (0x%x)\n", status);
752 return -ENOENT;
753 }
754
755 wifi_pkg = iwl_mvm_sar_find_wifi_pkg(mvm, ewrd.pointer,
756 ACPI_EWRD_WIFI_DATA_SIZE);
757 if (IS_ERR(wifi_pkg)) {
758 ret = PTR_ERR(wifi_pkg);
759 goto out_free;
760 }
761
762 if ((wifi_pkg->package.elements[1].type != ACPI_TYPE_INTEGER) ||
763 (wifi_pkg->package.elements[2].type != ACPI_TYPE_INTEGER)) {
764 ret = -EINVAL;
765 goto out_free;
766 }
767
768 enabled = !!(wifi_pkg->package.elements[1].integer.value);
769 n_profiles = wifi_pkg->package.elements[2].integer.value;
770
e2ef1476
SD
771 /* in case of BIOS bug */
772 if (n_profiles <= 0) {
773 ret = -EINVAL;
774 goto out_free;
775 }
776
69964905
LC
777 for (i = 0; i < n_profiles; i++) {
778 /* the tables start at element 3 */
779 static int pos = 3;
780
781 /* The EWRD profiles officially go from 2 to 4, but we
782 * save them in sar_profiles[1-3] (because we don't
783 * have profile 0). So in the array we start from 1.
784 */
785 ret = iwl_mvm_sar_set_profile(mvm,
786 &wifi_pkg->package.elements[pos],
787 &mvm->sar_profiles[i + 1],
788 enabled);
789 if (ret < 0)
790 break;
791
792 /* go to the next table */
793 pos += IWL_MVM_SAR_TABLE_SIZE;
794 }
795
796out_free:
797 kfree(ewrd.pointer);
798 return ret;
799}
800
7fe90e0e 801static int iwl_mvm_sar_get_wgds_table(struct iwl_mvm *mvm)
a6bff3cb
HD
802{
803 union acpi_object *wifi_pkg;
804 acpi_handle root_handle;
805 acpi_handle handle;
806 struct acpi_buffer wgds = {ACPI_ALLOCATE_BUFFER, NULL};
807 acpi_status status;
7fe90e0e
HD
808 int i, j, ret;
809 int idx = 1;
a6bff3cb
HD
810
811 root_handle = ACPI_HANDLE(mvm->dev);
812 if (!root_handle) {
813 IWL_DEBUG_RADIO(mvm,
814 "Could not retrieve root port ACPI handle\n");
815 return -ENOENT;
816 }
817
818 /* Get the method's handle */
819 status = acpi_get_handle(root_handle, (acpi_string)ACPI_WGDS_METHOD,
820 &handle);
821 if (ACPI_FAILURE(status)) {
822 IWL_DEBUG_RADIO(mvm, "WGDS method not found\n");
823 return -ENOENT;
824 }
825
826 /* Call WGDS with no arguments */
827 status = acpi_evaluate_object(handle, NULL, NULL, &wgds);
828 if (ACPI_FAILURE(status)) {
829 IWL_DEBUG_RADIO(mvm, "WGDS invocation failed (0x%x)\n", status);
830 return -ENOENT;
831 }
832
833 wifi_pkg = iwl_mvm_sar_find_wifi_pkg(mvm, wgds.pointer,
834 ACPI_WGDS_WIFI_DATA_SIZE);
835 if (IS_ERR(wifi_pkg)) {
836 ret = PTR_ERR(wifi_pkg);
837 goto out_free;
838 }
839
7fe90e0e
HD
840 for (i = 0; i < IWL_NUM_GEO_PROFILES; i++) {
841 for (j = 0; j < IWL_MVM_GEO_TABLE_SIZE; j++) {
842 union acpi_object *entry;
a6bff3cb 843
7fe90e0e
HD
844 entry = &wifi_pkg->package.elements[idx++];
845 if ((entry->type != ACPI_TYPE_INTEGER) ||
846 (entry->integer.value > U8_MAX))
847 return -EINVAL;
a6bff3cb 848
7fe90e0e
HD
849 mvm->geo_profiles[i].values[j] = entry->integer.value;
850 }
a6bff3cb
HD
851 }
852 ret = 0;
853out_free:
854 kfree(wgds.pointer);
855 return ret;
856}
857
42ce76d6 858int iwl_mvm_sar_select_profile(struct iwl_mvm *mvm, int prof_a, int prof_b)
da2830ac 859{
da2830ac 860 struct iwl_dev_tx_power_cmd cmd = {
4b87e5af 861 .v3.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_CHAINS),
da2830ac 862 };
42ce76d6
LC
863 int i, j, idx;
864 int profs[IWL_NUM_CHAIN_LIMITS] = { prof_a, prof_b };
55bfa4b9 865 int len = sizeof(cmd);
da2830ac 866
42ce76d6
LC
867 BUILD_BUG_ON(IWL_NUM_CHAIN_LIMITS < 2);
868 BUILD_BUG_ON(IWL_NUM_CHAIN_LIMITS * IWL_NUM_SUB_BANDS !=
869 IWL_MVM_SAR_TABLE_SIZE);
870
55bfa4b9
LC
871 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
872 len = sizeof(cmd.v3);
873
42ce76d6
LC
874 for (i = 0; i < IWL_NUM_CHAIN_LIMITS; i++) {
875 struct iwl_mvm_sar_profile *prof;
da2830ac 876
42ce76d6
LC
877 /* don't allow SAR to be disabled (profile 0 means disable) */
878 if (profs[i] == 0)
879 return -EPERM;
da2830ac 880
42ce76d6
LC
881 /* we are off by one, so allow up to IWL_MVM_SAR_PROFILE_NUM */
882 if (profs[i] > IWL_MVM_SAR_PROFILE_NUM)
883 return -EINVAL;
da2830ac 884
42ce76d6
LC
885 /* profiles go from 1 to 4, so decrement to access the array */
886 prof = &mvm->sar_profiles[profs[i] - 1];
887
888 /* if the profile is disabled, do nothing */
889 if (!prof->enabled) {
890 IWL_DEBUG_RADIO(mvm, "SAR profile %d is disabled.\n",
891 profs[i]);
892 /* if one of the profiles is disabled, we fail all */
893 return -ENOENT;
894 }
da2830ac 895
da2830ac
LC
896 IWL_DEBUG_RADIO(mvm, " Chain[%d]:\n", i);
897 for (j = 0; j < IWL_NUM_SUB_BANDS; j++) {
898 idx = (i * IWL_NUM_SUB_BANDS) + j;
55bfa4b9 899 cmd.v3.per_chain_restriction[i][j] =
42ce76d6 900 cpu_to_le16(prof->table[idx]);
da2830ac 901 IWL_DEBUG_RADIO(mvm, " Band[%d] = %d * .125dBm\n",
42ce76d6 902 j, prof->table[idx]);
da2830ac
LC
903 }
904 }
905
42ce76d6
LC
906 IWL_DEBUG_RADIO(mvm, "Sending REDUCE_TX_POWER_CMD per chain\n");
907
908 return iwl_mvm_send_cmd_pdu(mvm, REDUCE_TX_POWER_CMD, 0, len, &cmd);
909}
910
7fe90e0e
HD
911int iwl_mvm_get_sar_geo_profile(struct iwl_mvm *mvm)
912{
913 struct iwl_geo_tx_power_profiles_resp *resp;
914 int ret;
915
916 struct iwl_geo_tx_power_profiles_cmd geo_cmd = {
917 .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_GET_CURRENT_TABLE),
918 };
919 struct iwl_host_cmd cmd = {
920 .id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT),
921 .len = { sizeof(geo_cmd), },
922 .flags = CMD_WANT_SKB,
923 .data = { &geo_cmd },
924 };
925
926 ret = iwl_mvm_send_cmd(mvm, &cmd);
927 if (ret) {
928 IWL_ERR(mvm, "Failed to get geographic profile info %d\n", ret);
929 return ret;
930 }
931
932 resp = (void *)cmd.resp_pkt->data;
933 ret = le32_to_cpu(resp->profile_idx);
934 if (WARN_ON(ret > IWL_NUM_GEO_PROFILES)) {
935 ret = -EIO;
936 IWL_WARN(mvm, "Invalid geographic profile idx (%d)\n", ret);
937 }
938
939 iwl_free_resp(&cmd);
940 return ret;
941}
942
a6bff3cb
HD
943static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
944{
a6bff3cb
HD
945 struct iwl_geo_tx_power_profiles_cmd cmd = {
946 .ops = cpu_to_le32(IWL_PER_CHAIN_OFFSET_SET_TABLES),
947 };
7fe90e0e 948 int ret, i, j;
a6bff3cb
HD
949 u16 cmd_wide_id = WIDE_ID(PHY_OPS_GROUP, GEO_TX_POWER_LIMIT);
950
7fe90e0e 951 ret = iwl_mvm_sar_get_wgds_table(mvm);
a6bff3cb
HD
952 if (ret < 0) {
953 IWL_DEBUG_RADIO(mvm,
954 "Geo SAR BIOS table invalid or unavailable. (%d)\n",
955 ret);
956 /* we don't fail if the table is not available */
957 return 0;
958 }
959
960 IWL_DEBUG_RADIO(mvm, "Sending GEO_TX_POWER_LIMIT\n");
961
962 BUILD_BUG_ON(IWL_NUM_GEO_PROFILES * ACPI_WGDS_NUM_BANDS *
963 ACPI_WGDS_TABLE_SIZE != ACPI_WGDS_WIFI_DATA_SIZE);
964
965 for (i = 0; i < IWL_NUM_GEO_PROFILES; i++) {
966 struct iwl_per_chain_offset *chain =
967 (struct iwl_per_chain_offset *)&cmd.table[i];
968
969 for (j = 0; j < ACPI_WGDS_NUM_BANDS; j++) {
970 u8 *value;
971
7fe90e0e
HD
972 value = &mvm->geo_profiles[i].values[j *
973 IWL_GEO_PER_CHAIN_SIZE];
a6bff3cb
HD
974 chain[j].max_tx_power = cpu_to_le16(value[0]);
975 chain[j].chain_a = value[1];
976 chain[j].chain_b = value[2];
977 IWL_DEBUG_RADIO(mvm,
978 "SAR geographic profile[%d] Band[%d]: chain A = %d chain B = %d max_tx_power = %d\n",
979 i, j, value[1], value[2], value[0]);
980 }
981 }
982 return iwl_mvm_send_cmd_pdu(mvm, cmd_wide_id, 0, sizeof(cmd), &cmd);
983}
984
69964905
LC
985#else /* CONFIG_ACPI */
986static int iwl_mvm_sar_get_wrds_table(struct iwl_mvm *mvm)
987{
988 return -ENOENT;
989}
990
991static int iwl_mvm_sar_get_ewrd_table(struct iwl_mvm *mvm)
992{
993 return -ENOENT;
994}
a6bff3cb
HD
995
996static int iwl_mvm_sar_geo_init(struct iwl_mvm *mvm)
997{
998 return 0;
999}
69964905
LC
1000#endif /* CONFIG_ACPI */
1001
42ce76d6
LC
1002static int iwl_mvm_sar_init(struct iwl_mvm *mvm)
1003{
1004 int ret;
1005
1006 ret = iwl_mvm_sar_get_wrds_table(mvm);
1007 if (ret < 0) {
1008 IWL_DEBUG_RADIO(mvm,
69964905 1009 "WRDS SAR BIOS table invalid or unavailable. (%d)\n",
42ce76d6 1010 ret);
69964905 1011 /* if not available, don't fail and don't bother with EWRD */
42ce76d6
LC
1012 return 0;
1013 }
1014
69964905
LC
1015 ret = iwl_mvm_sar_get_ewrd_table(mvm);
1016 /* if EWRD is not available, we can still use WRDS, so don't fail */
1017 if (ret < 0)
1018 IWL_DEBUG_RADIO(mvm,
1019 "EWRD SAR BIOS table invalid or unavailable. (%d)\n",
1020 ret);
1021
42ce76d6
LC
1022 /* choose profile 1 (WRDS) as default for both chains */
1023 ret = iwl_mvm_sar_select_profile(mvm, 1, 1);
1024
1025 /* if we don't have profile 0 from BIOS, just skip it */
1026 if (ret == -ENOENT)
1027 return 0;
da2830ac
LC
1028
1029 return ret;
1030}
1031
1f370650 1032static int iwl_mvm_load_rt_fw(struct iwl_mvm *mvm)
8ca151b5 1033{
1f370650 1034 int ret;
8ca151b5 1035
7d6222e2 1036 if (iwl_mvm_has_unified_ucode(mvm))
1f370650 1037 return iwl_run_unified_mvm_ucode(mvm, false);
8ca151b5 1038
8d193ca2 1039 ret = iwl_run_init_mvm_ucode(mvm, false);
f2082a53
SS
1040
1041 if (iwlmvm_mod_params.init_dbg)
1042 return 0;
1043
1044 if (ret) {
8d193ca2
EH
1045 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
1046 /* this can't happen */
1047 if (WARN_ON(ret > 0))
1048 ret = -ERFKILL;
1f370650 1049 return ret;
8d193ca2 1050 }
8ca151b5 1051
f2082a53
SS
1052 /*
1053 * Stop and start the transport without entering low power
1054 * mode. This will save the state of other components on the
1055 * device that are triggered by the INIT firwmare (MFUART).
1056 */
1057 _iwl_trans_stop_device(mvm->trans, false);
1058 ret = _iwl_trans_start_hw(mvm->trans, false);
1059 if (ret)
1f370650 1060 return ret;
8ca151b5
JB
1061
1062 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
1f370650
SS
1063 if (ret)
1064 return ret;
1065
702e975d 1066 return iwl_init_paging(&mvm->fwrt, mvm->fwrt.cur_fw_img);
1f370650
SS
1067}
1068
1069int iwl_mvm_up(struct iwl_mvm *mvm)
1070{
1071 int ret, i;
1072 struct ieee80211_channel *chan;
1073 struct cfg80211_chan_def chandef;
1074
1075 lockdep_assert_held(&mvm->mutex);
1076
1077 ret = iwl_trans_start_hw(mvm->trans);
1078 if (ret)
1079 return ret;
1080
1081 ret = iwl_mvm_load_rt_fw(mvm);
8ca151b5
JB
1082 if (ret) {
1083 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
1084 goto error;
1085 }
1086
d0b813fc 1087 iwl_get_shared_mem_conf(&mvm->fwrt);
04fd2c28 1088
1f3b0ff8
LE
1089 ret = iwl_mvm_sf_update(mvm, NULL, false);
1090 if (ret)
1091 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
1092
7174beb6 1093 mvm->fwrt.dump.conf = FW_DBG_INVALID;
945d4202
EG
1094 /* if we have a destination, assume EARLY START */
1095 if (mvm->fw->dbg_dest_tlv)
7174beb6
JB
1096 mvm->fwrt.dump.conf = FW_DBG_START_FROM_ALIVE;
1097 iwl_fw_start_dbg_conf(&mvm->fwrt, FW_DBG_START_FROM_ALIVE);
6a951267 1098
a0544272 1099 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
8ca151b5
JB
1100 if (ret)
1101 goto error;
1102
7d6222e2
JB
1103 if (!iwl_mvm_has_unified_ucode(mvm)) {
1104 /* Send phy db control command and then phy db calibration */
1f370650
SS
1105 ret = iwl_send_phy_db_data(mvm->phy_db);
1106 if (ret)
1107 goto error;
8ca151b5 1108
1f370650
SS
1109 ret = iwl_send_phy_cfg_cmd(mvm);
1110 if (ret)
1111 goto error;
1112 }
8ca151b5 1113
b3de3ef4
EG
1114 ret = iwl_mvm_send_bt_init_conf(mvm);
1115 if (ret)
1116 goto error;
1117
43413a97 1118 /* Init RSS configuration */
09a2e25d 1119 /* TODO - remove a000 disablement when we have RXQ config API */
c8c017a6
JB
1120 if (iwl_mvm_has_new_rx_api(mvm) &&
1121 mvm->trans->cfg->device_family != IWL_DEVICE_FAMILY_A000) {
43413a97
SS
1122 ret = iwl_send_rss_cfg_cmd(mvm);
1123 if (ret) {
1124 IWL_ERR(mvm, "Failed to configure RSS queues: %d\n",
1125 ret);
1126 goto error;
1127 }
1128 }
1129
8ca151b5 1130 /* init the fw <-> mac80211 STA mapping */
0ae98812 1131 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
8ca151b5
JB
1132 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1133
0ae98812 1134 mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA;
1d3c3f63 1135
b2b7875b
JB
1136 /* reset quota debouncing buffer - 0xff will yield invalid data */
1137 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
1138
c8f54701
JB
1139 ret = iwl_mvm_send_dqa_cmd(mvm);
1140 if (ret)
1141 goto error;
97d5be7e 1142
8ca151b5
JB
1143 /* Add auxiliary station for scanning */
1144 ret = iwl_mvm_add_aux_sta(mvm);
1145 if (ret)
1146 goto error;
1147
53a9d61e 1148 /* Add all the PHY contexts */
57fbcce3 1149 chan = &mvm->hw->wiphy->bands[NL80211_BAND_2GHZ]->channels[0];
53a9d61e
IP
1150 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
1151 for (i = 0; i < NUM_PHY_CTX; i++) {
1152 /*
1153 * The channel used here isn't relevant as it's
1154 * going to be overwritten in the other flows.
1155 * For now use the first channel we have.
1156 */
1157 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
1158 &chandef, 1, 1);
1159 if (ret)
1160 goto error;
1161 }
8ca151b5 1162
c221daf2
CRI
1163#ifdef CONFIG_THERMAL
1164 if (iwl_mvm_is_tt_in_fw(mvm)) {
1165 /* in order to give the responsibility of ct-kill and
1166 * TX backoff to FW we need to send empty temperature reporting
1167 * cmd during init time
1168 */
1169 iwl_mvm_send_temp_report_ths_cmd(mvm);
1170 } else {
1171 /* Initialize tx backoffs to the minimal possible */
1172 iwl_mvm_tt_tx_backoff(mvm, 0);
1173 }
5c89e7bc
CRI
1174
1175 /* TODO: read the budget from BIOS / Platform NVM */
944eafc2
CRI
1176
1177 /*
1178 * In case there is no budget from BIOS / Platform NVM the default
1179 * budget should be 2000mW (cooling state 0).
1180 */
1181 if (iwl_mvm_is_ctdp_supported(mvm)) {
5c89e7bc
CRI
1182 ret = iwl_mvm_ctdp_command(mvm, CTDP_CMD_OPERATION_START,
1183 mvm->cooling_dev.cur_state);
75cfe338
LC
1184 if (ret)
1185 goto error;
1186 }
c221daf2 1187#else
0c0e2c71
IY
1188 /* Initialize tx backoffs to the minimal possible */
1189 iwl_mvm_tt_tx_backoff(mvm, 0);
c221daf2 1190#endif
0c0e2c71 1191
84bfffa9 1192 WARN_ON(iwl_mvm_config_ltr(mvm));
9180ac50 1193
c1cb92fc 1194 ret = iwl_mvm_power_update_device(mvm);
64b928c4
AB
1195 if (ret)
1196 goto error;
1197
35af15d1
AN
1198 /*
1199 * RTNL is not taken during Ct-kill, but we don't need to scan/Tx
1200 * anyway, so don't init MCC.
1201 */
1202 if (!test_bit(IWL_MVM_STATUS_HW_CTKILL, &mvm->status)) {
1203 ret = iwl_mvm_init_mcc(mvm);
1204 if (ret)
1205 goto error;
1206 }
90d4f7db 1207
859d914c 1208 if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) {
4ca87a5f 1209 mvm->scan_type = IWL_SCAN_TYPE_NOT_SET;
d2496221
DS
1210 ret = iwl_mvm_config_scan(mvm);
1211 if (ret)
1212 goto error;
1213 }
1214
7498cf4c
EP
1215 /* allow FW/transport low power modes if not during restart */
1216 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
1217 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
1218
da2830ac
LC
1219 ret = iwl_mvm_sar_init(mvm);
1220 if (ret)
1221 goto error;
1222
a6bff3cb
HD
1223 ret = iwl_mvm_sar_geo_init(mvm);
1224 if (ret)
1225 goto error;
1226
7089ae63
JB
1227 iwl_mvm_leds_sync(mvm);
1228
53a9d61e 1229 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
8ca151b5
JB
1230 return 0;
1231 error:
de8ba41b
LK
1232 if (!iwlmvm_mod_params.init_dbg)
1233 iwl_mvm_stop_device(mvm);
8ca151b5
JB
1234 return ret;
1235}
1236
1237int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
1238{
1239 int ret, i;
1240
1241 lockdep_assert_held(&mvm->mutex);
1242
1243 ret = iwl_trans_start_hw(mvm->trans);
1244 if (ret)
1245 return ret;
1246
1247 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
1248 if (ret) {
1249 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
1250 goto error;
1251 }
1252
a0544272 1253 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
8ca151b5
JB
1254 if (ret)
1255 goto error;
1256
1257 /* Send phy db control command and then phy db calibration*/
1258 ret = iwl_send_phy_db_data(mvm->phy_db);
1259 if (ret)
1260 goto error;
1261
1262 ret = iwl_send_phy_cfg_cmd(mvm);
1263 if (ret)
1264 goto error;
1265
1266 /* init the fw <-> mac80211 STA mapping */
0ae98812 1267 for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++)
8ca151b5
JB
1268 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
1269
1270 /* Add auxiliary station for scanning */
1271 ret = iwl_mvm_add_aux_sta(mvm);
1272 if (ret)
1273 goto error;
1274
1275 return 0;
1276 error:
fcb6b92a 1277 iwl_mvm_stop_device(mvm);
8ca151b5
JB
1278 return ret;
1279}
1280
0416841d
JB
1281void iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
1282 struct iwl_rx_cmd_buffer *rxb)
8ca151b5
JB
1283{
1284 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1285 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
1286 u32 flags = le32_to_cpu(card_state_notif->flags);
1287
1288 IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
1289 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1290 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
1291 (flags & CT_KILL_CARD_DISABLED) ?
1292 "Reached" : "Not reached");
8ca151b5
JB
1293}
1294
0416841d
JB
1295void iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
1296 struct iwl_rx_cmd_buffer *rxb)
30269c12
CRI
1297{
1298 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1299 struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
1300
0c8d0a47
GBA
1301 IWL_DEBUG_INFO(mvm,
1302 "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
1303 le32_to_cpu(mfuart_notif->installed_ver),
1304 le32_to_cpu(mfuart_notif->external_ver),
1305 le32_to_cpu(mfuart_notif->status),
1306 le32_to_cpu(mfuart_notif->duration));
1307
19f63c53
GBA
1308 if (iwl_rx_packet_payload_len(pkt) == sizeof(*mfuart_notif))
1309 IWL_DEBUG_INFO(mvm,
0c8d0a47 1310 "MFUART: image size: 0x%08x\n",
19f63c53 1311 le32_to_cpu(mfuart_notif->image_size));
30269c12 1312}