blob: b4f244f510ed2aaf0917d035667b15a9316183f5 [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
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 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +02008 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +02009 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010010 *
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
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020026 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010027 *
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 *
Emmanuel Grumbach51368bf2013-12-30 13:15:54 +020034 * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved.
Johannes Berg8b4139d2014-07-24 14:05:26 +020035 * Copyright(c) 2013 - 2014 Intel Mobile Communications GmbH
Johannes Berg8ca151b2013-01-24 14:25:36 +010036 * 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 */
73#include "iwl-eeprom-parse.h"
74
75#include "mvm.h"
76#include "iwl-phy-db.h"
77
78#define MVM_UCODE_ALIVE_TIMEOUT HZ
79#define MVM_UCODE_CALIB_TIMEOUT (2*HZ)
80
81#define UCODE_VALID_OK cpu_to_le32(0x1)
82
Johannes Berg8ca151b2013-01-24 14:25:36 +010083struct iwl_mvm_alive_data {
84 bool valid;
85 u32 scd_base_addr;
86};
87
88static inline const struct fw_img *
89iwl_get_ucode_image(struct iwl_mvm *mvm, enum iwl_ucode_type ucode_type)
90{
91 if (ucode_type >= IWL_UCODE_TYPE_MAX)
92 return NULL;
93
94 return &mvm->fw->img[ucode_type];
95}
96
97static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
98{
99 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
100 .valid = cpu_to_le32(valid_tx_ant),
101 };
102
Emmanuel Grumbach33223542013-03-09 20:38:19 +0200103 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300104 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100105 sizeof(tx_ant_cmd), &tx_ant_cmd);
106}
107
108static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
109 struct iwl_rx_packet *pkt, void *data)
110{
111 struct iwl_mvm *mvm =
112 container_of(notif_wait, struct iwl_mvm, notif_wait);
113 struct iwl_mvm_alive_data *alive_data = data;
114 struct mvm_alive_resp *palive;
Eran Harary01a9ca52014-02-03 09:29:57 +0200115 struct mvm_alive_resp_ver2 *palive2;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100116
Eran Harary01a9ca52014-02-03 09:29:57 +0200117 if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
118 palive = (void *)pkt->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100119
Eran Harary01a9ca52014-02-03 09:29:57 +0200120 mvm->support_umac_log = false;
121 mvm->error_event_table =
122 le32_to_cpu(palive->error_event_table_ptr);
123 mvm->log_event_table = le32_to_cpu(palive->log_event_table_ptr);
124 alive_data->scd_base_addr = le32_to_cpu(palive->scd_base_ptr);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100125
Eran Harary01a9ca52014-02-03 09:29:57 +0200126 alive_data->valid = le16_to_cpu(palive->status) ==
127 IWL_ALIVE_STATUS_OK;
128 IWL_DEBUG_FW(mvm,
129 "Alive VER1 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
130 le16_to_cpu(palive->status), palive->ver_type,
131 palive->ver_subtype, palive->flags);
132 } else {
133 palive2 = (void *)pkt->data;
134
Eran Harary01a9ca52014-02-03 09:29:57 +0200135 mvm->error_event_table =
136 le32_to_cpu(palive2->error_event_table_ptr);
137 mvm->log_event_table =
138 le32_to_cpu(palive2->log_event_table_ptr);
139 alive_data->scd_base_addr = le32_to_cpu(palive2->scd_base_ptr);
140 mvm->umac_error_event_table =
141 le32_to_cpu(palive2->error_info_addr);
Eran Harary91479b62014-05-11 08:11:34 +0300142 mvm->sf_space.addr = le32_to_cpu(palive2->st_fwrd_addr);
143 mvm->sf_space.size = le32_to_cpu(palive2->st_fwrd_size);
Eran Harary01a9ca52014-02-03 09:29:57 +0200144
145 alive_data->valid = le16_to_cpu(palive2->status) ==
146 IWL_ALIVE_STATUS_OK;
Emmanuel Grumbachffa70262014-02-11 16:37:34 +0200147 if (mvm->umac_error_event_table)
148 mvm->support_umac_log = true;
149
Eran Harary01a9ca52014-02-03 09:29:57 +0200150 IWL_DEBUG_FW(mvm,
151 "Alive VER2 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
152 le16_to_cpu(palive2->status), palive2->ver_type,
153 palive2->ver_subtype, palive2->flags);
154
155 IWL_DEBUG_FW(mvm,
156 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
157 palive2->umac_major, palive2->umac_minor);
158 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100159
160 return true;
161}
162
163static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
164 struct iwl_rx_packet *pkt, void *data)
165{
166 struct iwl_phy_db *phy_db = data;
167
168 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
169 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
170 return true;
171 }
172
173 WARN_ON(iwl_phy_db_set_section(phy_db, pkt, GFP_ATOMIC));
174
175 return false;
176}
177
178static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
179 enum iwl_ucode_type ucode_type)
180{
181 struct iwl_notification_wait alive_wait;
182 struct iwl_mvm_alive_data alive_data;
183 const struct fw_img *fw;
184 int ret, i;
185 enum iwl_ucode_type old_type = mvm->cur_ucode;
186 static const u8 alive_cmd[] = { MVM_ALIVE };
Eran Harary91479b62014-05-11 08:11:34 +0300187 struct iwl_sf_region st_fwrd_space;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100188
Johannes Berg8ca151b2013-01-24 14:25:36 +0100189 fw = iwl_get_ucode_image(mvm, ucode_type);
Johannes Bergbefe9b62013-10-25 12:32:51 +0200190 if (WARN_ON(!fw))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100191 return -EINVAL;
Johannes Bergbefe9b62013-10-25 12:32:51 +0200192 mvm->cur_ucode = ucode_type;
193 mvm->ucode_loaded = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100194
195 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
196 alive_cmd, ARRAY_SIZE(alive_cmd),
197 iwl_alive_fn, &alive_data);
198
199 ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
200 if (ret) {
201 mvm->cur_ucode = old_type;
202 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
203 return ret;
204 }
205
206 /*
207 * Some things may run in the background now, but we
208 * just wait for the ALIVE notification here.
209 */
210 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
211 MVM_UCODE_ALIVE_TIMEOUT);
212 if (ret) {
213 mvm->cur_ucode = old_type;
214 return ret;
215 }
216
217 if (!alive_data.valid) {
218 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
219 mvm->cur_ucode = old_type;
220 return -EIO;
221 }
222
Eran Harary91479b62014-05-11 08:11:34 +0300223 /*
224 * update the sdio allocation according to the pointer we get in the
225 * alive notification.
226 */
227 st_fwrd_space.addr = mvm->sf_space.addr;
228 st_fwrd_space.size = mvm->sf_space.size;
229 ret = iwl_trans_update_sf(mvm->trans, &st_fwrd_space);
Eyal Shapira82e8aea2014-10-19 14:56:40 +0300230 if (ret) {
231 IWL_ERR(mvm, "Failed to update SF size. ret %d\n", ret);
232 return ret;
233 }
Eran Harary91479b62014-05-11 08:11:34 +0300234
Johannes Berg8ca151b2013-01-24 14:25:36 +0100235 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
236
237 /*
238 * Note: all the queues are enabled as part of the interface
239 * initialization, but in firmware restart scenarios they
240 * could be stopped, so wake them up. In firmware restart,
241 * mac80211 will have the queues stopped as well until the
242 * reconfiguration completes. During normal startup, they
243 * will be empty.
244 */
245
246 for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200247 if (i < mvm->first_agg_queue && i != IWL_MVM_CMD_QUEUE)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100248 mvm->queue_to_mac80211[i] = i;
249 else
250 mvm->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100251 }
252
Johannes Bergdf197c02014-08-01 18:14:45 +0200253 for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
254 atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100255
256 mvm->ucode_loaded = true;
257
258 return 0;
259}
Johannes Berg8ca151b2013-01-24 14:25:36 +0100260
261static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
262{
263 struct iwl_phy_cfg_cmd phy_cfg_cmd;
264 enum iwl_ucode_type ucode_type = mvm->cur_ucode;
265
266 /* Set parameters */
Dor Shaish6221d472013-02-27 15:55:48 +0200267 phy_cfg_cmd.phy_cfg = cpu_to_le32(mvm->fw->phy_config);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100268 phy_cfg_cmd.calib_control.event_trigger =
269 mvm->fw->default_calib[ucode_type].event_trigger;
270 phy_cfg_cmd.calib_control.flow_trigger =
271 mvm->fw->default_calib[ucode_type].flow_trigger;
272
273 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
274 phy_cfg_cmd.phy_cfg);
275
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300276 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100277 sizeof(phy_cfg_cmd), &phy_cfg_cmd);
278}
279
Johannes Berg8ca151b2013-01-24 14:25:36 +0100280int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
281{
282 struct iwl_notification_wait calib_wait;
283 static const u8 init_complete[] = {
284 INIT_COMPLETE_NOTIF,
285 CALIB_RES_NOTIF_PHY_DB
286 };
287 int ret;
288
289 lockdep_assert_held(&mvm->mutex);
290
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200291 if (WARN_ON_ONCE(mvm->init_ucode_complete || mvm->calibrating))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100292 return 0;
293
294 iwl_init_notification_wait(&mvm->notif_wait,
295 &calib_wait,
296 init_complete,
297 ARRAY_SIZE(init_complete),
298 iwl_wait_phy_db_entry,
299 mvm->phy_db);
300
301 /* Will also start the device */
302 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
303 if (ret) {
304 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
305 goto error;
306 }
307
Emmanuel Grumbachae397472014-03-30 16:55:18 +0300308 ret = iwl_send_bt_init_conf(mvm);
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200309 if (ret)
310 goto error;
311
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200312 /* Read the NVM only at driver load time, no need to do this twice */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100313 if (read_nvm) {
314 /* Read nvm */
Eran Harary14b485f2014-04-23 10:46:09 +0300315 ret = iwl_nvm_init(mvm, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100316 if (ret) {
317 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
318 goto error;
319 }
320 }
321
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200322 /* In case we read the NVM from external file, load it to the NIC */
Eran Hararye02a9d62014-05-07 12:27:10 +0300323 if (mvm->nvm_file_name)
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200324 iwl_mvm_load_nvm_to_nic(mvm);
325
Johannes Berg8ca151b2013-01-24 14:25:36 +0100326 ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans);
327 WARN_ON(ret);
328
Eran Harary4f593342013-05-13 07:53:26 +0300329 /*
330 * abort after reading the nvm in case RF Kill is on, we will complete
331 * the init seq later when RF kill will switch to off
332 */
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300333 if (iwl_mvm_is_radio_killed(mvm)) {
Eran Harary4f593342013-05-13 07:53:26 +0300334 IWL_DEBUG_RF_KILL(mvm,
335 "jump over all phy activities due to RF kill\n");
336 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
Arik Nemtsova4082842013-11-24 19:10:46 +0200337 ret = 1;
338 goto out;
Eran Harary4f593342013-05-13 07:53:26 +0300339 }
340
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200341 mvm->calibrating = true;
342
Dor Shaishe07cbb52013-02-27 23:00:27 +0200343 /* Send TX valid antennas before triggering calibrations */
Johannes Berg4ed735e2014-02-12 21:47:44 +0100344 ret = iwl_send_tx_ant_cfg(mvm, mvm->fw->valid_tx_ant);
Dor Shaishe07cbb52013-02-27 23:00:27 +0200345 if (ret)
346 goto error;
347
Johannes Berg8ca151b2013-01-24 14:25:36 +0100348 /*
349 * Send phy configurations command to init uCode
350 * to start the 16.0 uCode init image internal calibrations.
351 */
352 ret = iwl_send_phy_cfg_cmd(mvm);
353 if (ret) {
354 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
355 ret);
356 goto error;
357 }
358
359 /*
360 * Some things may run in the background now, but we
361 * just wait for the calibration complete notification.
362 */
363 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
364 MVM_UCODE_CALIB_TIMEOUT);
365 if (!ret)
Eytan Lifshitzff116372013-09-03 12:06:11 +0300366 mvm->init_ucode_complete = true;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200367
368 if (ret && iwl_mvm_is_radio_killed(mvm)) {
369 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
370 ret = 1;
371 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100372 goto out;
373
374error:
375 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
376out:
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200377 mvm->calibrating = false;
Arik Nemtsova4082842013-11-24 19:10:46 +0200378 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100379 /* we want to debug INIT and we have no NVM - fake */
380 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
381 sizeof(struct ieee80211_channel) +
382 sizeof(struct ieee80211_rate),
383 GFP_KERNEL);
384 if (!mvm->nvm_data)
385 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100386 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
387 mvm->nvm_data->bands[0].n_channels = 1;
388 mvm->nvm_data->bands[0].n_bitrates = 1;
389 mvm->nvm_data->bands[0].bitrates =
390 (void *)mvm->nvm_data->channels + 1;
391 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
392 }
393
394 return ret;
395}
396
Johannes Berg8ca151b2013-01-24 14:25:36 +0100397int iwl_mvm_up(struct iwl_mvm *mvm)
398{
399 int ret, i;
Ilan Peer53a9d612013-04-28 11:55:08 +0300400 struct ieee80211_channel *chan;
401 struct cfg80211_chan_def chandef;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100402
403 lockdep_assert_held(&mvm->mutex);
404
405 ret = iwl_trans_start_hw(mvm->trans);
406 if (ret)
407 return ret;
408
Eytan Lifshitzff116372013-09-03 12:06:11 +0300409 /*
410 * If we haven't completed the run of the init ucode during
411 * module loading, load init ucode now
412 * (for example, if we were in RFKILL)
413 */
414 if (!mvm->init_ucode_complete) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100415 ret = iwl_run_init_mvm_ucode(mvm, false);
416 if (ret && !iwlmvm_mod_params.init_dbg) {
417 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
Eran Harary4f593342013-05-13 07:53:26 +0300418 /* this can't happen */
419 if (WARN_ON(ret > 0))
420 ret = -ERFKILL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100421 goto error;
422 }
Arik Nemtsova4082842013-11-24 19:10:46 +0200423 if (!iwlmvm_mod_params.init_dbg) {
424 /*
425 * should stop and start HW since that INIT
426 * image just loaded
427 */
428 iwl_trans_stop_device(mvm->trans);
429 ret = iwl_trans_start_hw(mvm->trans);
430 if (ret)
431 return ret;
432 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100433 }
434
435 if (iwlmvm_mod_params.init_dbg)
436 return 0;
437
438 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
439 if (ret) {
440 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
441 goto error;
442 }
443
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +0200444 ret = iwl_mvm_sf_update(mvm, NULL, false);
445 if (ret)
446 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
447
Johannes Berg4ed735e2014-02-12 21:47:44 +0100448 ret = iwl_send_tx_ant_cfg(mvm, mvm->fw->valid_tx_ant);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100449 if (ret)
450 goto error;
451
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200452 ret = iwl_send_bt_init_conf(mvm);
453 if (ret)
454 goto error;
455
Johannes Berg8ca151b2013-01-24 14:25:36 +0100456 /* Send phy db control command and then phy db calibration*/
457 ret = iwl_send_phy_db_data(mvm->phy_db);
458 if (ret)
459 goto error;
460
461 ret = iwl_send_phy_cfg_cmd(mvm);
462 if (ret)
463 goto error;
464
465 /* init the fw <-> mac80211 STA mapping */
466 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
467 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
468
Johannes Bergb2b78752014-09-08 16:42:54 +0200469 /* reset quota debouncing buffer - 0xff will yield invalid data */
470 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
471
Johannes Berg8ca151b2013-01-24 14:25:36 +0100472 /* Add auxiliary station for scanning */
473 ret = iwl_mvm_add_aux_sta(mvm);
474 if (ret)
475 goto error;
476
Ilan Peer53a9d612013-04-28 11:55:08 +0300477 /* Add all the PHY contexts */
478 chan = &mvm->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels[0];
479 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
480 for (i = 0; i < NUM_PHY_CTX; i++) {
481 /*
482 * The channel used here isn't relevant as it's
483 * going to be overwritten in the other flows.
484 * For now use the first channel we have.
485 */
486 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
487 &chandef, 1, 1);
488 if (ret)
489 goto error;
490 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100491
Ido Yariv0c0e2c72014-01-16 21:12:02 -0500492 /* Initialize tx backoffs to the minimal possible */
493 iwl_mvm_tt_tx_backoff(mvm, 0);
494
Emmanuel Grumbach9180ac52014-09-23 23:02:41 +0300495 if (mvm->trans->ltr_enabled) {
496 struct iwl_ltr_config_cmd cmd = {
497 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
498 };
499
500 WARN_ON(iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
501 sizeof(cmd), &cmd));
502 }
503
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200504 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300505 if (ret)
506 goto error;
507
David Spinadeld2496222014-05-20 12:46:37 +0300508 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
509 ret = iwl_mvm_config_scan(mvm);
510 if (ret)
511 goto error;
512 }
513
Eliad Peller7498cf42014-01-16 17:10:44 +0200514 /* allow FW/transport low power modes if not during restart */
515 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
516 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
517
Ilan Peer53a9d612013-04-28 11:55:08 +0300518 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100519 return 0;
520 error:
521 iwl_trans_stop_device(mvm->trans);
522 return ret;
523}
524
525int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
526{
527 int ret, i;
528
529 lockdep_assert_held(&mvm->mutex);
530
531 ret = iwl_trans_start_hw(mvm->trans);
532 if (ret)
533 return ret;
534
535 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
536 if (ret) {
537 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
538 goto error;
539 }
540
Johannes Berg4ed735e2014-02-12 21:47:44 +0100541 ret = iwl_send_tx_ant_cfg(mvm, mvm->fw->valid_tx_ant);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100542 if (ret)
543 goto error;
544
545 /* Send phy db control command and then phy db calibration*/
546 ret = iwl_send_phy_db_data(mvm->phy_db);
547 if (ret)
548 goto error;
549
550 ret = iwl_send_phy_cfg_cmd(mvm);
551 if (ret)
552 goto error;
553
554 /* init the fw <-> mac80211 STA mapping */
555 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
556 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
557
558 /* Add auxiliary station for scanning */
559 ret = iwl_mvm_add_aux_sta(mvm);
560 if (ret)
561 goto error;
562
563 return 0;
564 error:
565 iwl_trans_stop_device(mvm->trans);
566 return ret;
567}
568
569int iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
570 struct iwl_rx_cmd_buffer *rxb,
571 struct iwl_device_cmd *cmd)
572{
573 struct iwl_rx_packet *pkt = rxb_addr(rxb);
574 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
575 u32 flags = le32_to_cpu(card_state_notif->flags);
576
577 IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
578 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
579 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
580 (flags & CT_KILL_CARD_DISABLED) ?
581 "Reached" : "Not reached");
582
Johannes Berg8ca151b2013-01-24 14:25:36 +0100583 return 0;
584}
585
586int iwl_mvm_rx_radio_ver(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
587 struct iwl_device_cmd *cmd)
588{
589 struct iwl_rx_packet *pkt = rxb_addr(rxb);
590 struct iwl_radio_version_notif *radio_version = (void *)pkt->data;
591
592 /* TODO: what to do with that? */
593 IWL_DEBUG_INFO(mvm,
594 "Radio version: flavor: 0x%08x, step 0x%08x, dash 0x%08x\n",
595 le32_to_cpu(radio_version->radio_flavor),
596 le32_to_cpu(radio_version->radio_step),
597 le32_to_cpu(radio_version->radio_dash));
598 return 0;
599}