]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/wireless/iwlwifi/mvm/fw.c
iwlwifi: mvm: use only 40 ms for fragmented scan
[mirror_ubuntu-artful-kernel.git] / drivers / net / wireless / 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.
8b4139dc 9 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
8ca151b5
JB
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of version 2 of the GNU General Public License as
13 * published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
23 * USA
24 *
25 * The full GNU General Public License is included in this distribution
410dc5aa 26 * in the file called COPYING.
8ca151b5
JB
27 *
28 * Contact Information:
29 * Intel Linux Wireless <ilw@linux.intel.com>
30 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
31 *
32 * BSD LICENSE
33 *
51368bf7 34 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
8b4139dc 35 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
8ca151b5
JB
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 *
42 * * Redistributions of source code must retain the above copyright
43 * notice, this list of conditions and the following disclaimer.
44 * * Redistributions in binary form must reproduce the above copyright
45 * notice, this list of conditions and the following disclaimer in
46 * the documentation and/or other materials provided with the
47 * distribution.
48 * * Neither the name Intel Corporation nor the names of its
49 * contributors may be used to endorse or promote products derived
50 * from this software without specific prior written permission.
51 *
52 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
53 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
54 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
55 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
56 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
57 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
58 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
59 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
60 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
61 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
62 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *
64 *****************************************************************************/
65#include <net/mac80211.h>
66
67#include "iwl-trans.h"
68#include "iwl-op-mode.h"
69#include "iwl-fw.h"
70#include "iwl-debug.h"
71#include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */
72#include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */
8c23f95c 73#include "iwl-prph.h"
8ca151b5
JB
74#include "iwl-eeprom-parse.h"
75
76#include "mvm.h"
77#include "iwl-phy-db.h"
78
79#define MVM_UCODE_ALIVE_TIMEOUT HZ
80#define MVM_UCODE_CALIB_TIMEOUT (2*HZ)
81
82#define UCODE_VALID_OK cpu_to_le32(0x1)
83
8ca151b5
JB
84struct iwl_mvm_alive_data {
85 bool valid;
86 u32 scd_base_addr;
87};
88
89static inline const struct fw_img *
90iwl_get_ucode_image(struct iwl_mvm *mvm, enum iwl_ucode_type ucode_type)
91{
92 if (ucode_type >= IWL_UCODE_TYPE_MAX)
93 return NULL;
94
95 return &mvm->fw->img[ucode_type];
96}
97
98static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
99{
100 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
101 .valid = cpu_to_le32(valid_tx_ant),
102 };
103
33223542 104 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
a1022927 105 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
8ca151b5
JB
106 sizeof(tx_ant_cmd), &tx_ant_cmd);
107}
108
109static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
110 struct iwl_rx_packet *pkt, void *data)
111{
112 struct iwl_mvm *mvm =
113 container_of(notif_wait, struct iwl_mvm, notif_wait);
114 struct iwl_mvm_alive_data *alive_data = data;
7e1223b5 115 struct mvm_alive_resp_ver1 *palive1;
01a9ca51 116 struct mvm_alive_resp_ver2 *palive2;
7e1223b5 117 struct mvm_alive_resp *palive;
01a9ca51 118
7e1223b5
EG
119 if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive1)) {
120 palive1 = (void *)pkt->data;
01a9ca51
EH
121
122 mvm->support_umac_log = false;
123 mvm->error_event_table =
7e1223b5
EG
124 le32_to_cpu(palive1->error_event_table_ptr);
125 mvm->log_event_table =
126 le32_to_cpu(palive1->log_event_table_ptr);
127 alive_data->scd_base_addr = le32_to_cpu(palive1->scd_base_ptr);
01a9ca51 128
7e1223b5 129 alive_data->valid = le16_to_cpu(palive1->status) ==
01a9ca51
EH
130 IWL_ALIVE_STATUS_OK;
131 IWL_DEBUG_FW(mvm,
132 "Alive VER1 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
7e1223b5
EG
133 le16_to_cpu(palive1->status), palive1->ver_type,
134 palive1->ver_subtype, palive1->flags);
135 } else if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive2)) {
01a9ca51
EH
136 palive2 = (void *)pkt->data;
137
01a9ca51
EH
138 mvm->error_event_table =
139 le32_to_cpu(palive2->error_event_table_ptr);
140 mvm->log_event_table =
141 le32_to_cpu(palive2->log_event_table_ptr);
142 alive_data->scd_base_addr = le32_to_cpu(palive2->scd_base_ptr);
143 mvm->umac_error_event_table =
144 le32_to_cpu(palive2->error_info_addr);
91479b64
EH
145 mvm->sf_space.addr = le32_to_cpu(palive2->st_fwrd_addr);
146 mvm->sf_space.size = le32_to_cpu(palive2->st_fwrd_size);
01a9ca51
EH
147
148 alive_data->valid = le16_to_cpu(palive2->status) ==
149 IWL_ALIVE_STATUS_OK;
ffa70264
EG
150 if (mvm->umac_error_event_table)
151 mvm->support_umac_log = true;
152
01a9ca51
EH
153 IWL_DEBUG_FW(mvm,
154 "Alive VER2 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
155 le16_to_cpu(palive2->status), palive2->ver_type,
156 palive2->ver_subtype, palive2->flags);
157
158 IWL_DEBUG_FW(mvm,
159 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
160 palive2->umac_major, palive2->umac_minor);
7e1223b5
EG
161 } else if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
162 palive = (void *)pkt->data;
163
164 mvm->error_event_table =
165 le32_to_cpu(palive->error_event_table_ptr);
166 mvm->log_event_table =
167 le32_to_cpu(palive->log_event_table_ptr);
168 alive_data->scd_base_addr = le32_to_cpu(palive->scd_base_ptr);
169 mvm->umac_error_event_table =
170 le32_to_cpu(palive->error_info_addr);
171 mvm->sf_space.addr = le32_to_cpu(palive->st_fwrd_addr);
172 mvm->sf_space.size = le32_to_cpu(palive->st_fwrd_size);
173
174 alive_data->valid = le16_to_cpu(palive->status) ==
175 IWL_ALIVE_STATUS_OK;
176 if (mvm->umac_error_event_table)
177 mvm->support_umac_log = true;
178
179 IWL_DEBUG_FW(mvm,
180 "Alive VER3 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
181 le16_to_cpu(palive->status), palive->ver_type,
182 palive->ver_subtype, palive->flags);
183
184 IWL_DEBUG_FW(mvm,
185 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
186 le32_to_cpu(palive->umac_major),
187 le32_to_cpu(palive->umac_minor));
01a9ca51 188 }
8ca151b5
JB
189
190 return true;
191}
192
193static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
194 struct iwl_rx_packet *pkt, void *data)
195{
196 struct iwl_phy_db *phy_db = data;
197
198 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
199 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
200 return true;
201 }
202
203 WARN_ON(iwl_phy_db_set_section(phy_db, pkt, GFP_ATOMIC));
204
205 return false;
206}
207
208static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
209 enum iwl_ucode_type ucode_type)
210{
211 struct iwl_notification_wait alive_wait;
212 struct iwl_mvm_alive_data alive_data;
213 const struct fw_img *fw;
214 int ret, i;
215 enum iwl_ucode_type old_type = mvm->cur_ucode;
216 static const u8 alive_cmd[] = { MVM_ALIVE };
91479b64 217 struct iwl_sf_region st_fwrd_space;
8ca151b5 218
61df750c
EH
219 if (ucode_type == IWL_UCODE_REGULAR &&
220 iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_CUSTOM) &&
221 iwl_fw_dbg_conf_enabled(mvm->fw, FW_DBG_CUSTOM))
222 fw = iwl_get_ucode_image(mvm, IWL_UCODE_REGULAR_USNIFFER);
223 else
224 fw = iwl_get_ucode_image(mvm, ucode_type);
befe9b6f 225 if (WARN_ON(!fw))
8ca151b5 226 return -EINVAL;
befe9b6f
JB
227 mvm->cur_ucode = ucode_type;
228 mvm->ucode_loaded = false;
8ca151b5
JB
229
230 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
231 alive_cmd, ARRAY_SIZE(alive_cmd),
232 iwl_alive_fn, &alive_data);
233
234 ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
235 if (ret) {
236 mvm->cur_ucode = old_type;
237 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
238 return ret;
239 }
240
241 /*
242 * Some things may run in the background now, but we
243 * just wait for the ALIVE notification here.
244 */
245 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
246 MVM_UCODE_ALIVE_TIMEOUT);
247 if (ret) {
248 mvm->cur_ucode = old_type;
249 return ret;
250 }
251
252 if (!alive_data.valid) {
253 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
254 mvm->cur_ucode = old_type;
255 return -EIO;
256 }
257
91479b64
EH
258 /*
259 * update the sdio allocation according to the pointer we get in the
260 * alive notification.
261 */
262 st_fwrd_space.addr = mvm->sf_space.addr;
263 st_fwrd_space.size = mvm->sf_space.size;
264 ret = iwl_trans_update_sf(mvm->trans, &st_fwrd_space);
82e8aea0
ES
265 if (ret) {
266 IWL_ERR(mvm, "Failed to update SF size. ret %d\n", ret);
267 return ret;
268 }
91479b64 269
8ca151b5
JB
270 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
271
272 /*
273 * Note: all the queues are enabled as part of the interface
274 * initialization, but in firmware restart scenarios they
275 * could be stopped, so wake them up. In firmware restart,
276 * mac80211 will have the queues stopped as well until the
277 * reconfiguration completes. During normal startup, they
278 * will be empty.
279 */
280
281 for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
19e737c9 282 if (i < mvm->first_agg_queue && i != IWL_MVM_CMD_QUEUE)
8ca151b5
JB
283 mvm->queue_to_mac80211[i] = i;
284 else
285 mvm->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
8ca151b5
JB
286 }
287
df197c00
JB
288 for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
289 atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
8ca151b5
JB
290
291 mvm->ucode_loaded = true;
292
293 return 0;
294}
8ca151b5
JB
295
296static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
297{
298 struct iwl_phy_cfg_cmd phy_cfg_cmd;
299 enum iwl_ucode_type ucode_type = mvm->cur_ucode;
300
301 /* Set parameters */
a0544272 302 phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
8ca151b5
JB
303 phy_cfg_cmd.calib_control.event_trigger =
304 mvm->fw->default_calib[ucode_type].event_trigger;
305 phy_cfg_cmd.calib_control.flow_trigger =
306 mvm->fw->default_calib[ucode_type].flow_trigger;
307
308 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
309 phy_cfg_cmd.phy_cfg);
310
a1022927 311 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
8ca151b5
JB
312 sizeof(phy_cfg_cmd), &phy_cfg_cmd);
313}
314
8ca151b5
JB
315int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
316{
317 struct iwl_notification_wait calib_wait;
318 static const u8 init_complete[] = {
319 INIT_COMPLETE_NOTIF,
320 CALIB_RES_NOTIF_PHY_DB
321 };
322 int ret;
323
324 lockdep_assert_held(&mvm->mutex);
325
31b8b343 326 if (WARN_ON_ONCE(mvm->init_ucode_complete || mvm->calibrating))
8ca151b5
JB
327 return 0;
328
329 iwl_init_notification_wait(&mvm->notif_wait,
330 &calib_wait,
331 init_complete,
332 ARRAY_SIZE(init_complete),
333 iwl_wait_phy_db_entry,
334 mvm->phy_db);
335
336 /* Will also start the device */
337 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
338 if (ret) {
339 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
340 goto error;
341 }
342
ae397472 343 ret = iwl_send_bt_init_conf(mvm);
931d4160
EG
344 if (ret)
345 goto error;
346
81a67e32 347 /* Read the NVM only at driver load time, no need to do this twice */
8ca151b5
JB
348 if (read_nvm) {
349 /* Read nvm */
14b485f0 350 ret = iwl_nvm_init(mvm, true);
8ca151b5
JB
351 if (ret) {
352 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
353 goto error;
354 }
355 }
356
81a67e32 357 /* In case we read the NVM from external file, load it to the NIC */
e02a9d60 358 if (mvm->nvm_file_name)
81a67e32
EL
359 iwl_mvm_load_nvm_to_nic(mvm);
360
8ca151b5
JB
361 ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans);
362 WARN_ON(ret);
363
4f59334b
EH
364 /*
365 * abort after reading the nvm in case RF Kill is on, we will complete
366 * the init seq later when RF kill will switch to off
367 */
9ee718aa 368 if (iwl_mvm_is_radio_killed(mvm)) {
4f59334b
EH
369 IWL_DEBUG_RF_KILL(mvm,
370 "jump over all phy activities due to RF kill\n");
371 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
a4082843
AN
372 ret = 1;
373 goto out;
4f59334b
EH
374 }
375
31b8b343
EG
376 mvm->calibrating = true;
377
e07cbb53 378 /* Send TX valid antennas before triggering calibrations */
a0544272 379 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
e07cbb53
DS
380 if (ret)
381 goto error;
382
8ca151b5
JB
383 /*
384 * Send phy configurations command to init uCode
385 * to start the 16.0 uCode init image internal calibrations.
386 */
387 ret = iwl_send_phy_cfg_cmd(mvm);
388 if (ret) {
389 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
390 ret);
391 goto error;
392 }
393
394 /*
395 * Some things may run in the background now, but we
396 * just wait for the calibration complete notification.
397 */
398 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
399 MVM_UCODE_CALIB_TIMEOUT);
400 if (!ret)
ff116373 401 mvm->init_ucode_complete = true;
31b8b343
EG
402
403 if (ret && iwl_mvm_is_radio_killed(mvm)) {
404 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
405 ret = 1;
406 }
8ca151b5
JB
407 goto out;
408
409error:
410 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
411out:
31b8b343 412 mvm->calibrating = false;
a4082843 413 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
8ca151b5
JB
414 /* we want to debug INIT and we have no NVM - fake */
415 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
416 sizeof(struct ieee80211_channel) +
417 sizeof(struct ieee80211_rate),
418 GFP_KERNEL);
419 if (!mvm->nvm_data)
420 return -ENOMEM;
8ca151b5
JB
421 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
422 mvm->nvm_data->bands[0].n_channels = 1;
423 mvm->nvm_data->bands[0].n_bitrates = 1;
424 mvm->nvm_data->bands[0].bitrates =
425 (void *)mvm->nvm_data->channels + 1;
426 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
427 }
428
429 return ret;
430}
431
04fd2c28
LK
432static void iwl_mvm_get_shared_mem_conf(struct iwl_mvm *mvm)
433{
434 struct iwl_host_cmd cmd = {
435 .id = SHARED_MEM_CFG,
436 .flags = CMD_WANT_SKB,
437 .data = { NULL, },
438 .len = { 0, },
439 };
440 struct iwl_rx_packet *pkt;
441 struct iwl_shared_mem_cfg *mem_cfg;
442 u32 i;
443
444 lockdep_assert_held(&mvm->mutex);
445
446 if (WARN_ON(iwl_mvm_send_cmd(mvm, &cmd)))
447 return;
448
449 pkt = cmd.resp_pkt;
450 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
451 IWL_ERR(mvm, "Bad return from SHARED_MEM_CFG (0x%08X)\n",
452 pkt->hdr.flags);
453 goto exit;
454 }
455
456 mem_cfg = (void *)pkt->data;
457
458 mvm->shared_mem_cfg.shared_mem_addr =
459 le32_to_cpu(mem_cfg->shared_mem_addr);
460 mvm->shared_mem_cfg.shared_mem_size =
461 le32_to_cpu(mem_cfg->shared_mem_size);
462 mvm->shared_mem_cfg.sample_buff_addr =
463 le32_to_cpu(mem_cfg->sample_buff_addr);
464 mvm->shared_mem_cfg.sample_buff_size =
465 le32_to_cpu(mem_cfg->sample_buff_size);
466 mvm->shared_mem_cfg.txfifo_addr = le32_to_cpu(mem_cfg->txfifo_addr);
467 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++)
468 mvm->shared_mem_cfg.txfifo_size[i] =
469 le32_to_cpu(mem_cfg->txfifo_size[i]);
470 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++)
471 mvm->shared_mem_cfg.rxfifo_size[i] =
472 le32_to_cpu(mem_cfg->rxfifo_size[i]);
473 mvm->shared_mem_cfg.page_buff_addr =
474 le32_to_cpu(mem_cfg->page_buff_addr);
475 mvm->shared_mem_cfg.page_buff_size =
476 le32_to_cpu(mem_cfg->page_buff_size);
477 IWL_DEBUG_INFO(mvm, "SHARED MEM CFG: got memory offsets/sizes\n");
478
479exit:
480 iwl_free_resp(&cmd);
481}
482
8c23f95c
EG
483void iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm)
484{
8c23f95c
EG
485 /* stop recording */
486 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
487 iwl_set_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
488 } else {
489 iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 0);
3c118cdb
EH
490 /* wait before we collect the data till the DBGC stop */
491 udelay(100);
8c23f95c
EG
492 }
493
e66e0b70 494 schedule_work(&mvm->fw_error_dump_wk);
8c23f95c
EG
495}
496
497int iwl_mvm_start_fw_dbg_conf(struct iwl_mvm *mvm, enum iwl_fw_dbg_conf conf_id)
6a951267
LK
498{
499 u8 *ptr;
500 int ret;
501 int i;
502
503 if (WARN_ONCE(conf_id >= ARRAY_SIZE(mvm->fw->dbg_conf_tlv),
504 "Invalid configuration %d\n", conf_id))
505 return -EINVAL;
506
507 if (!mvm->fw->dbg_conf_tlv[conf_id])
508 return -EINVAL;
509
510 if (mvm->fw_dbg_conf != FW_DBG_INVALID)
511 IWL_WARN(mvm, "FW already configured (%d) - re-configuring\n",
512 mvm->fw_dbg_conf);
513
514 /* Send all HCMDs for configuring the FW debug */
515 ptr = (void *)&mvm->fw->dbg_conf_tlv[conf_id]->hcmd;
516 for (i = 0; i < mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds; i++) {
517 struct iwl_fw_dbg_conf_hcmd *cmd = (void *)ptr;
518
519 ret = iwl_mvm_send_cmd_pdu(mvm, cmd->id, 0,
520 le16_to_cpu(cmd->len), cmd->data);
521 if (ret)
522 return ret;
523
524 ptr += sizeof(*cmd);
525 ptr += le16_to_cpu(cmd->len);
526 }
527
528 mvm->fw_dbg_conf = conf_id;
529 return ret;
530}
531
84bfffa9
EG
532static int iwl_mvm_config_ltr_v1(struct iwl_mvm *mvm)
533{
534 struct iwl_ltr_config_cmd_v1 cmd_v1 = {
535 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
536 };
537
538 if (!mvm->trans->ltr_enabled)
539 return 0;
540
541 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
542 sizeof(cmd_v1), &cmd_v1);
543}
544
545static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
546{
547 struct iwl_ltr_config_cmd cmd = {
548 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
549 };
550
551 if (!mvm->trans->ltr_enabled)
552 return 0;
553
554 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_HDC_PHASE_0))
555 return iwl_mvm_config_ltr_v1(mvm);
556
557 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
558 sizeof(cmd), &cmd);
559}
560
8ca151b5
JB
561int iwl_mvm_up(struct iwl_mvm *mvm)
562{
563 int ret, i;
53a9d61e
IP
564 struct ieee80211_channel *chan;
565 struct cfg80211_chan_def chandef;
8ca151b5
JB
566
567 lockdep_assert_held(&mvm->mutex);
568
569 ret = iwl_trans_start_hw(mvm->trans);
570 if (ret)
571 return ret;
572
ff116373
EL
573 /*
574 * If we haven't completed the run of the init ucode during
575 * module loading, load init ucode now
576 * (for example, if we were in RFKILL)
577 */
578 if (!mvm->init_ucode_complete) {
8ca151b5
JB
579 ret = iwl_run_init_mvm_ucode(mvm, false);
580 if (ret && !iwlmvm_mod_params.init_dbg) {
581 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
4f59334b
EH
582 /* this can't happen */
583 if (WARN_ON(ret > 0))
584 ret = -ERFKILL;
8ca151b5
JB
585 goto error;
586 }
a4082843
AN
587 if (!iwlmvm_mod_params.init_dbg) {
588 /*
589 * should stop and start HW since that INIT
590 * image just loaded
591 */
592 iwl_trans_stop_device(mvm->trans);
593 ret = iwl_trans_start_hw(mvm->trans);
594 if (ret)
595 return ret;
596 }
8ca151b5
JB
597 }
598
599 if (iwlmvm_mod_params.init_dbg)
600 return 0;
601
602 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
603 if (ret) {
604 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
605 goto error;
606 }
607
c38740d0
EG
608 if (IWL_UCODE_API(mvm->fw->ucode_ver) >= 10)
609 iwl_mvm_get_shared_mem_conf(mvm);
04fd2c28 610
1f3b0ff8
LE
611 ret = iwl_mvm_sf_update(mvm, NULL, false);
612 if (ret)
613 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
614
6a951267
LK
615 mvm->fw_dbg_conf = FW_DBG_INVALID;
616 iwl_mvm_start_fw_dbg_conf(mvm, FW_DBG_CUSTOM);
617
a0544272 618 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
8ca151b5
JB
619 if (ret)
620 goto error;
621
931d4160
EG
622 ret = iwl_send_bt_init_conf(mvm);
623 if (ret)
624 goto error;
625
8ca151b5
JB
626 /* Send phy db control command and then phy db calibration*/
627 ret = iwl_send_phy_db_data(mvm->phy_db);
628 if (ret)
629 goto error;
630
631 ret = iwl_send_phy_cfg_cmd(mvm);
632 if (ret)
633 goto error;
634
635 /* init the fw <-> mac80211 STA mapping */
636 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
637 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
638
1d3c3f63
AN
639 mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
640
b2b7875b
JB
641 /* reset quota debouncing buffer - 0xff will yield invalid data */
642 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
643
8ca151b5
JB
644 /* Add auxiliary station for scanning */
645 ret = iwl_mvm_add_aux_sta(mvm);
646 if (ret)
647 goto error;
648
53a9d61e
IP
649 /* Add all the PHY contexts */
650 chan = &mvm->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels[0];
651 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
652 for (i = 0; i < NUM_PHY_CTX; i++) {
653 /*
654 * The channel used here isn't relevant as it's
655 * going to be overwritten in the other flows.
656 * For now use the first channel we have.
657 */
658 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
659 &chandef, 1, 1);
660 if (ret)
661 goto error;
662 }
8ca151b5 663
0c0e2c71
IY
664 /* Initialize tx backoffs to the minimal possible */
665 iwl_mvm_tt_tx_backoff(mvm, 0);
666
84bfffa9 667 WARN_ON(iwl_mvm_config_ltr(mvm));
9180ac50 668
c1cb92fc 669 ret = iwl_mvm_power_update_device(mvm);
64b928c4
AB
670 if (ret)
671 goto error;
672
d2496221
DS
673 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
674 ret = iwl_mvm_config_scan(mvm);
675 if (ret)
676 goto error;
677 }
678
7498cf4c
EP
679 /* allow FW/transport low power modes if not during restart */
680 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
681 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
682
53a9d61e 683 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
8ca151b5
JB
684 return 0;
685 error:
686 iwl_trans_stop_device(mvm->trans);
687 return ret;
688}
689
690int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
691{
692 int ret, i;
693
694 lockdep_assert_held(&mvm->mutex);
695
696 ret = iwl_trans_start_hw(mvm->trans);
697 if (ret)
698 return ret;
699
700 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
701 if (ret) {
702 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
703 goto error;
704 }
705
a0544272 706 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
8ca151b5
JB
707 if (ret)
708 goto error;
709
710 /* Send phy db control command and then phy db calibration*/
711 ret = iwl_send_phy_db_data(mvm->phy_db);
712 if (ret)
713 goto error;
714
715 ret = iwl_send_phy_cfg_cmd(mvm);
716 if (ret)
717 goto error;
718
719 /* init the fw <-> mac80211 STA mapping */
720 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
721 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
722
723 /* Add auxiliary station for scanning */
724 ret = iwl_mvm_add_aux_sta(mvm);
725 if (ret)
726 goto error;
727
728 return 0;
729 error:
730 iwl_trans_stop_device(mvm->trans);
731 return ret;
732}
733
734int iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
735 struct iwl_rx_cmd_buffer *rxb,
736 struct iwl_device_cmd *cmd)
737{
738 struct iwl_rx_packet *pkt = rxb_addr(rxb);
739 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
740 u32 flags = le32_to_cpu(card_state_notif->flags);
741
742 IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
743 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
744 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
745 (flags & CT_KILL_CARD_DISABLED) ?
746 "Reached" : "Not reached");
747
8ca151b5
JB
748 return 0;
749}
750
751int iwl_mvm_rx_radio_ver(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
752 struct iwl_device_cmd *cmd)
753{
754 struct iwl_rx_packet *pkt = rxb_addr(rxb);
755 struct iwl_radio_version_notif *radio_version = (void *)pkt->data;
756
757 /* TODO: what to do with that? */
758 IWL_DEBUG_INFO(mvm,
759 "Radio version: flavor: 0x%08x, step 0x%08x, dash 0x%08x\n",
760 le32_to_cpu(radio_version->radio_flavor),
761 le32_to_cpu(radio_version->radio_step),
762 le32_to_cpu(radio_version->radio_dash));
763 return 0;
764}
30269c12
CRI
765
766int iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
767 struct iwl_rx_cmd_buffer *rxb,
768 struct iwl_device_cmd *cmd)
769{
770 struct iwl_rx_packet *pkt = rxb_addr(rxb);
771 struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
772
773 IWL_DEBUG_INFO(mvm,
774 "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
775 le32_to_cpu(mfuart_notif->installed_ver),
776 le32_to_cpu(mfuart_notif->external_ver),
777 le32_to_cpu(mfuart_notif->status),
778 le32_to_cpu(mfuart_notif->duration));
779 return 0;
780}