blob: a322a5e3d31b8e5e4323f98fc6c24d16074dfb97 [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 */
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +020073#include "iwl-prph.h"
Johannes Berg8ca151b2013-01-24 14:25:36 +010074#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
Johannes Berg8ca151b2013-01-24 14:25:36 +010084struct 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
Emmanuel Grumbach33223542013-03-09 20:38:19 +0200104 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300105 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100106 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;
115 struct mvm_alive_resp *palive;
Eran Harary01a9ca52014-02-03 09:29:57 +0200116 struct mvm_alive_resp_ver2 *palive2;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100117
Eran Harary01a9ca52014-02-03 09:29:57 +0200118 if (iwl_rx_packet_payload_len(pkt) == sizeof(*palive)) {
119 palive = (void *)pkt->data;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100120
Eran Harary01a9ca52014-02-03 09:29:57 +0200121 mvm->support_umac_log = false;
122 mvm->error_event_table =
123 le32_to_cpu(palive->error_event_table_ptr);
124 mvm->log_event_table = le32_to_cpu(palive->log_event_table_ptr);
125 alive_data->scd_base_addr = le32_to_cpu(palive->scd_base_ptr);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100126
Eran Harary01a9ca52014-02-03 09:29:57 +0200127 alive_data->valid = le16_to_cpu(palive->status) ==
128 IWL_ALIVE_STATUS_OK;
129 IWL_DEBUG_FW(mvm,
130 "Alive VER1 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
131 le16_to_cpu(palive->status), palive->ver_type,
132 palive->ver_subtype, palive->flags);
133 } else {
134 palive2 = (void *)pkt->data;
135
Eran Harary01a9ca52014-02-03 09:29:57 +0200136 mvm->error_event_table =
137 le32_to_cpu(palive2->error_event_table_ptr);
138 mvm->log_event_table =
139 le32_to_cpu(palive2->log_event_table_ptr);
140 alive_data->scd_base_addr = le32_to_cpu(palive2->scd_base_ptr);
141 mvm->umac_error_event_table =
142 le32_to_cpu(palive2->error_info_addr);
Eran Harary91479b62014-05-11 08:11:34 +0300143 mvm->sf_space.addr = le32_to_cpu(palive2->st_fwrd_addr);
144 mvm->sf_space.size = le32_to_cpu(palive2->st_fwrd_size);
Eran Harary01a9ca52014-02-03 09:29:57 +0200145
146 alive_data->valid = le16_to_cpu(palive2->status) ==
147 IWL_ALIVE_STATUS_OK;
Emmanuel Grumbachffa70262014-02-11 16:37:34 +0200148 if (mvm->umac_error_event_table)
149 mvm->support_umac_log = true;
150
Eran Harary01a9ca52014-02-03 09:29:57 +0200151 IWL_DEBUG_FW(mvm,
152 "Alive VER2 ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
153 le16_to_cpu(palive2->status), palive2->ver_type,
154 palive2->ver_subtype, palive2->flags);
155
156 IWL_DEBUG_FW(mvm,
157 "UMAC version: Major - 0x%x, Minor - 0x%x\n",
158 palive2->umac_major, palive2->umac_minor);
159 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100160
161 return true;
162}
163
164static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
165 struct iwl_rx_packet *pkt, void *data)
166{
167 struct iwl_phy_db *phy_db = data;
168
169 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
170 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
171 return true;
172 }
173
174 WARN_ON(iwl_phy_db_set_section(phy_db, pkt, GFP_ATOMIC));
175
176 return false;
177}
178
179static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
180 enum iwl_ucode_type ucode_type)
181{
182 struct iwl_notification_wait alive_wait;
183 struct iwl_mvm_alive_data alive_data;
184 const struct fw_img *fw;
185 int ret, i;
186 enum iwl_ucode_type old_type = mvm->cur_ucode;
187 static const u8 alive_cmd[] = { MVM_ALIVE };
Eran Harary91479b62014-05-11 08:11:34 +0300188 struct iwl_sf_region st_fwrd_space;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100189
Eran Harary61df7502014-12-01 17:40:37 +0200190 if (ucode_type == IWL_UCODE_REGULAR &&
191 iwl_fw_dbg_conf_usniffer(mvm->fw, FW_DBG_CUSTOM) &&
192 iwl_fw_dbg_conf_enabled(mvm->fw, FW_DBG_CUSTOM))
193 fw = iwl_get_ucode_image(mvm, IWL_UCODE_REGULAR_USNIFFER);
194 else
195 fw = iwl_get_ucode_image(mvm, ucode_type);
Johannes Bergbefe9b62013-10-25 12:32:51 +0200196 if (WARN_ON(!fw))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100197 return -EINVAL;
Johannes Bergbefe9b62013-10-25 12:32:51 +0200198 mvm->cur_ucode = ucode_type;
199 mvm->ucode_loaded = false;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100200
201 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
202 alive_cmd, ARRAY_SIZE(alive_cmd),
203 iwl_alive_fn, &alive_data);
204
205 ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
206 if (ret) {
207 mvm->cur_ucode = old_type;
208 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
209 return ret;
210 }
211
212 /*
213 * Some things may run in the background now, but we
214 * just wait for the ALIVE notification here.
215 */
216 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
217 MVM_UCODE_ALIVE_TIMEOUT);
218 if (ret) {
219 mvm->cur_ucode = old_type;
220 return ret;
221 }
222
223 if (!alive_data.valid) {
224 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
225 mvm->cur_ucode = old_type;
226 return -EIO;
227 }
228
Eran Harary91479b62014-05-11 08:11:34 +0300229 /*
230 * update the sdio allocation according to the pointer we get in the
231 * alive notification.
232 */
233 st_fwrd_space.addr = mvm->sf_space.addr;
234 st_fwrd_space.size = mvm->sf_space.size;
235 ret = iwl_trans_update_sf(mvm->trans, &st_fwrd_space);
Eyal Shapira82e8aea2014-10-19 14:56:40 +0300236 if (ret) {
237 IWL_ERR(mvm, "Failed to update SF size. ret %d\n", ret);
238 return ret;
239 }
Eran Harary91479b62014-05-11 08:11:34 +0300240
Johannes Berg8ca151b2013-01-24 14:25:36 +0100241 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
242
243 /*
244 * Note: all the queues are enabled as part of the interface
245 * initialization, but in firmware restart scenarios they
246 * could be stopped, so wake them up. In firmware restart,
247 * mac80211 will have the queues stopped as well until the
248 * reconfiguration completes. During normal startup, they
249 * will be empty.
250 */
251
252 for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
Eytan Lifshitz19e737c2013-09-09 13:30:15 +0200253 if (i < mvm->first_agg_queue && i != IWL_MVM_CMD_QUEUE)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100254 mvm->queue_to_mac80211[i] = i;
255 else
256 mvm->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100257 }
258
Johannes Bergdf197c02014-08-01 18:14:45 +0200259 for (i = 0; i < IEEE80211_MAX_QUEUES; i++)
260 atomic_set(&mvm->mac80211_queue_stop_count[i], 0);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100261
262 mvm->ucode_loaded = true;
263
264 return 0;
265}
Johannes Berg8ca151b2013-01-24 14:25:36 +0100266
267static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
268{
269 struct iwl_phy_cfg_cmd phy_cfg_cmd;
270 enum iwl_ucode_type ucode_type = mvm->cur_ucode;
271
272 /* Set parameters */
Moshe Harela0544272014-12-08 21:13:14 +0200273 phy_cfg_cmd.phy_cfg = cpu_to_le32(iwl_mvm_get_phy_config(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100274 phy_cfg_cmd.calib_control.event_trigger =
275 mvm->fw->default_calib[ucode_type].event_trigger;
276 phy_cfg_cmd.calib_control.flow_trigger =
277 mvm->fw->default_calib[ucode_type].flow_trigger;
278
279 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
280 phy_cfg_cmd.phy_cfg);
281
Emmanuel Grumbacha1022922014-05-12 11:36:41 +0300282 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, 0,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100283 sizeof(phy_cfg_cmd), &phy_cfg_cmd);
284}
285
Johannes Berg8ca151b2013-01-24 14:25:36 +0100286int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
287{
288 struct iwl_notification_wait calib_wait;
289 static const u8 init_complete[] = {
290 INIT_COMPLETE_NOTIF,
291 CALIB_RES_NOTIF_PHY_DB
292 };
293 int ret;
294
295 lockdep_assert_held(&mvm->mutex);
296
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200297 if (WARN_ON_ONCE(mvm->init_ucode_complete || mvm->calibrating))
Johannes Berg8ca151b2013-01-24 14:25:36 +0100298 return 0;
299
300 iwl_init_notification_wait(&mvm->notif_wait,
301 &calib_wait,
302 init_complete,
303 ARRAY_SIZE(init_complete),
304 iwl_wait_phy_db_entry,
305 mvm->phy_db);
306
307 /* Will also start the device */
308 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
309 if (ret) {
310 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
311 goto error;
312 }
313
Emmanuel Grumbachae397472014-03-30 16:55:18 +0300314 ret = iwl_send_bt_init_conf(mvm);
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200315 if (ret)
316 goto error;
317
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200318 /* Read the NVM only at driver load time, no need to do this twice */
Johannes Berg8ca151b2013-01-24 14:25:36 +0100319 if (read_nvm) {
320 /* Read nvm */
Eran Harary14b485f2014-04-23 10:46:09 +0300321 ret = iwl_nvm_init(mvm, true);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100322 if (ret) {
323 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
324 goto error;
325 }
326 }
327
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200328 /* In case we read the NVM from external file, load it to the NIC */
Eran Hararye02a9d62014-05-07 12:27:10 +0300329 if (mvm->nvm_file_name)
Eytan Lifshitz81a67e32013-09-11 12:39:18 +0200330 iwl_mvm_load_nvm_to_nic(mvm);
331
Johannes Berg8ca151b2013-01-24 14:25:36 +0100332 ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans);
333 WARN_ON(ret);
334
Eran Harary4f593342013-05-13 07:53:26 +0300335 /*
336 * abort after reading the nvm in case RF Kill is on, we will complete
337 * the init seq later when RF kill will switch to off
338 */
Eytan Lifshitz9ee718a2013-05-19 19:14:41 +0300339 if (iwl_mvm_is_radio_killed(mvm)) {
Eran Harary4f593342013-05-13 07:53:26 +0300340 IWL_DEBUG_RF_KILL(mvm,
341 "jump over all phy activities due to RF kill\n");
342 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
Arik Nemtsova4082842013-11-24 19:10:46 +0200343 ret = 1;
344 goto out;
Eran Harary4f593342013-05-13 07:53:26 +0300345 }
346
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200347 mvm->calibrating = true;
348
Dor Shaishe07cbb52013-02-27 23:00:27 +0200349 /* Send TX valid antennas before triggering calibrations */
Moshe Harela0544272014-12-08 21:13:14 +0200350 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Dor Shaishe07cbb52013-02-27 23:00:27 +0200351 if (ret)
352 goto error;
353
Johannes Berg8ca151b2013-01-24 14:25:36 +0100354 /*
355 * Send phy configurations command to init uCode
356 * to start the 16.0 uCode init image internal calibrations.
357 */
358 ret = iwl_send_phy_cfg_cmd(mvm);
359 if (ret) {
360 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
361 ret);
362 goto error;
363 }
364
365 /*
366 * Some things may run in the background now, but we
367 * just wait for the calibration complete notification.
368 */
369 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
370 MVM_UCODE_CALIB_TIMEOUT);
371 if (!ret)
Eytan Lifshitzff116372013-09-03 12:06:11 +0300372 mvm->init_ucode_complete = true;
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200373
374 if (ret && iwl_mvm_is_radio_killed(mvm)) {
375 IWL_DEBUG_RF_KILL(mvm, "RFKILL while calibrating.\n");
376 ret = 1;
377 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100378 goto out;
379
380error:
381 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
382out:
Emmanuel Grumbach31b8b342014-11-02 15:48:09 +0200383 mvm->calibrating = false;
Arik Nemtsova4082842013-11-24 19:10:46 +0200384 if (iwlmvm_mod_params.init_dbg && !mvm->nvm_data) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100385 /* we want to debug INIT and we have no NVM - fake */
386 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
387 sizeof(struct ieee80211_channel) +
388 sizeof(struct ieee80211_rate),
389 GFP_KERNEL);
390 if (!mvm->nvm_data)
391 return -ENOMEM;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100392 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
393 mvm->nvm_data->bands[0].n_channels = 1;
394 mvm->nvm_data->bands[0].n_bitrates = 1;
395 mvm->nvm_data->bands[0].bitrates =
396 (void *)mvm->nvm_data->channels + 1;
397 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
398 }
399
400 return ret;
401}
402
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200403static void iwl_mvm_get_shared_mem_conf(struct iwl_mvm *mvm)
404{
405 struct iwl_host_cmd cmd = {
406 .id = SHARED_MEM_CFG,
407 .flags = CMD_WANT_SKB,
408 .data = { NULL, },
409 .len = { 0, },
410 };
411 struct iwl_rx_packet *pkt;
412 struct iwl_shared_mem_cfg *mem_cfg;
413 u32 i;
414
415 lockdep_assert_held(&mvm->mutex);
416
417 if (WARN_ON(iwl_mvm_send_cmd(mvm, &cmd)))
418 return;
419
420 pkt = cmd.resp_pkt;
421 if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) {
422 IWL_ERR(mvm, "Bad return from SHARED_MEM_CFG (0x%08X)\n",
423 pkt->hdr.flags);
424 goto exit;
425 }
426
427 mem_cfg = (void *)pkt->data;
428
429 mvm->shared_mem_cfg.shared_mem_addr =
430 le32_to_cpu(mem_cfg->shared_mem_addr);
431 mvm->shared_mem_cfg.shared_mem_size =
432 le32_to_cpu(mem_cfg->shared_mem_size);
433 mvm->shared_mem_cfg.sample_buff_addr =
434 le32_to_cpu(mem_cfg->sample_buff_addr);
435 mvm->shared_mem_cfg.sample_buff_size =
436 le32_to_cpu(mem_cfg->sample_buff_size);
437 mvm->shared_mem_cfg.txfifo_addr = le32_to_cpu(mem_cfg->txfifo_addr);
438 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.txfifo_size); i++)
439 mvm->shared_mem_cfg.txfifo_size[i] =
440 le32_to_cpu(mem_cfg->txfifo_size[i]);
441 for (i = 0; i < ARRAY_SIZE(mvm->shared_mem_cfg.rxfifo_size); i++)
442 mvm->shared_mem_cfg.rxfifo_size[i] =
443 le32_to_cpu(mem_cfg->rxfifo_size[i]);
444 mvm->shared_mem_cfg.page_buff_addr =
445 le32_to_cpu(mem_cfg->page_buff_addr);
446 mvm->shared_mem_cfg.page_buff_size =
447 le32_to_cpu(mem_cfg->page_buff_size);
448 IWL_DEBUG_INFO(mvm, "SHARED MEM CFG: got memory offsets/sizes\n");
449
450exit:
451 iwl_free_resp(&cmd);
452}
453
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +0200454void iwl_mvm_fw_dbg_collect(struct iwl_mvm *mvm)
455{
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +0200456 /* stop recording */
457 if (mvm->cfg->device_family == IWL_DEVICE_FAMILY_7000) {
458 iwl_set_bits_prph(mvm->trans, MON_BUFF_SAMPLE_CTL, 0x100);
459 } else {
460 iwl_write_prph(mvm->trans, DBGC_IN_SAMPLE, 0);
461 iwl_write_prph(mvm->trans, DBGC_OUT_CTRL, 0);
462 }
463
Emmanuel Grumbache66e0b72014-12-29 09:42:37 +0200464 schedule_work(&mvm->fw_error_dump_wk);
Emmanuel Grumbach8c23f952014-12-04 10:07:47 +0200465}
466
467int iwl_mvm_start_fw_dbg_conf(struct iwl_mvm *mvm, enum iwl_fw_dbg_conf conf_id)
Liad Kaufman6a951262014-11-17 11:36:21 +0200468{
469 u8 *ptr;
470 int ret;
471 int i;
472
473 if (WARN_ONCE(conf_id >= ARRAY_SIZE(mvm->fw->dbg_conf_tlv),
474 "Invalid configuration %d\n", conf_id))
475 return -EINVAL;
476
477 if (!mvm->fw->dbg_conf_tlv[conf_id])
478 return -EINVAL;
479
480 if (mvm->fw_dbg_conf != FW_DBG_INVALID)
481 IWL_WARN(mvm, "FW already configured (%d) - re-configuring\n",
482 mvm->fw_dbg_conf);
483
484 /* Send all HCMDs for configuring the FW debug */
485 ptr = (void *)&mvm->fw->dbg_conf_tlv[conf_id]->hcmd;
486 for (i = 0; i < mvm->fw->dbg_conf_tlv[conf_id]->num_of_hcmds; i++) {
487 struct iwl_fw_dbg_conf_hcmd *cmd = (void *)ptr;
488
489 ret = iwl_mvm_send_cmd_pdu(mvm, cmd->id, 0,
490 le16_to_cpu(cmd->len), cmd->data);
491 if (ret)
492 return ret;
493
494 ptr += sizeof(*cmd);
495 ptr += le16_to_cpu(cmd->len);
496 }
497
498 mvm->fw_dbg_conf = conf_id;
499 return ret;
500}
501
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +0200502static int iwl_mvm_config_ltr_v1(struct iwl_mvm *mvm)
503{
504 struct iwl_ltr_config_cmd_v1 cmd_v1 = {
505 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
506 };
507
508 if (!mvm->trans->ltr_enabled)
509 return 0;
510
511 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
512 sizeof(cmd_v1), &cmd_v1);
513}
514
515static int iwl_mvm_config_ltr(struct iwl_mvm *mvm)
516{
517 struct iwl_ltr_config_cmd cmd = {
518 .flags = cpu_to_le32(LTR_CFG_FLAG_FEATURE_ENABLE),
519 };
520
521 if (!mvm->trans->ltr_enabled)
522 return 0;
523
524 if (!(mvm->fw->ucode_capa.api[0] & IWL_UCODE_TLV_API_HDC_PHASE_0))
525 return iwl_mvm_config_ltr_v1(mvm);
526
527 return iwl_mvm_send_cmd_pdu(mvm, LTR_CONFIG, 0,
528 sizeof(cmd), &cmd);
529}
530
Johannes Berg8ca151b2013-01-24 14:25:36 +0100531int iwl_mvm_up(struct iwl_mvm *mvm)
532{
533 int ret, i;
Ilan Peer53a9d612013-04-28 11:55:08 +0300534 struct ieee80211_channel *chan;
535 struct cfg80211_chan_def chandef;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100536
537 lockdep_assert_held(&mvm->mutex);
538
539 ret = iwl_trans_start_hw(mvm->trans);
540 if (ret)
541 return ret;
542
Eytan Lifshitzff116372013-09-03 12:06:11 +0300543 /*
544 * If we haven't completed the run of the init ucode during
545 * module loading, load init ucode now
546 * (for example, if we were in RFKILL)
547 */
548 if (!mvm->init_ucode_complete) {
Johannes Berg8ca151b2013-01-24 14:25:36 +0100549 ret = iwl_run_init_mvm_ucode(mvm, false);
550 if (ret && !iwlmvm_mod_params.init_dbg) {
551 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
Eran Harary4f593342013-05-13 07:53:26 +0300552 /* this can't happen */
553 if (WARN_ON(ret > 0))
554 ret = -ERFKILL;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100555 goto error;
556 }
Arik Nemtsova4082842013-11-24 19:10:46 +0200557 if (!iwlmvm_mod_params.init_dbg) {
558 /*
559 * should stop and start HW since that INIT
560 * image just loaded
561 */
562 iwl_trans_stop_device(mvm->trans);
563 ret = iwl_trans_start_hw(mvm->trans);
564 if (ret)
565 return ret;
566 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100567 }
568
569 if (iwlmvm_mod_params.init_dbg)
570 return 0;
571
572 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
573 if (ret) {
574 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
575 goto error;
576 }
577
Liad Kaufman04fd2c22014-12-15 17:54:16 +0200578 iwl_mvm_get_shared_mem_conf(mvm);
579
Lilach Edelstein1f3b0ff2013-10-06 13:03:32 +0200580 ret = iwl_mvm_sf_update(mvm, NULL, false);
581 if (ret)
582 IWL_ERR(mvm, "Failed to initialize Smart Fifo\n");
583
Liad Kaufman6a951262014-11-17 11:36:21 +0200584 mvm->fw_dbg_conf = FW_DBG_INVALID;
585 iwl_mvm_start_fw_dbg_conf(mvm, FW_DBG_CUSTOM);
586
Moshe Harela0544272014-12-08 21:13:14 +0200587 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100588 if (ret)
589 goto error;
590
Emmanuel Grumbach931d4162013-01-17 09:42:25 +0200591 ret = iwl_send_bt_init_conf(mvm);
592 if (ret)
593 goto error;
594
Johannes Berg8ca151b2013-01-24 14:25:36 +0100595 /* Send phy db control command and then phy db calibration*/
596 ret = iwl_send_phy_db_data(mvm->phy_db);
597 if (ret)
598 goto error;
599
600 ret = iwl_send_phy_cfg_cmd(mvm);
601 if (ret)
602 goto error;
603
604 /* init the fw <-> mac80211 STA mapping */
605 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
606 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
607
Arik Nemtsov1d3c3f62014-10-23 18:03:10 +0300608 mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT;
609
Johannes Bergb2b78752014-09-08 16:42:54 +0200610 /* reset quota debouncing buffer - 0xff will yield invalid data */
611 memset(&mvm->last_quota_cmd, 0xff, sizeof(mvm->last_quota_cmd));
612
Johannes Berg8ca151b2013-01-24 14:25:36 +0100613 /* Add auxiliary station for scanning */
614 ret = iwl_mvm_add_aux_sta(mvm);
615 if (ret)
616 goto error;
617
Ilan Peer53a9d612013-04-28 11:55:08 +0300618 /* Add all the PHY contexts */
619 chan = &mvm->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels[0];
620 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
621 for (i = 0; i < NUM_PHY_CTX; i++) {
622 /*
623 * The channel used here isn't relevant as it's
624 * going to be overwritten in the other flows.
625 * For now use the first channel we have.
626 */
627 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
628 &chandef, 1, 1);
629 if (ret)
630 goto error;
631 }
Johannes Berg8ca151b2013-01-24 14:25:36 +0100632
Ido Yariv0c0e2c72014-01-16 21:12:02 -0500633 /* Initialize tx backoffs to the minimal possible */
634 iwl_mvm_tt_tx_backoff(mvm, 0);
635
Emmanuel Grumbach84bfffa2015-01-13 10:16:30 +0200636 WARN_ON(iwl_mvm_config_ltr(mvm));
Emmanuel Grumbach9180ac52014-09-23 23:02:41 +0300637
Emmanuel Grumbachc1cb92f2014-01-28 10:17:18 +0200638 ret = iwl_mvm_power_update_device(mvm);
Alexander Bondar64b928c2013-09-03 14:18:03 +0300639 if (ret)
640 goto error;
641
David Spinadeld2496222014-05-20 12:46:37 +0300642 if (mvm->fw->ucode_capa.capa[0] & IWL_UCODE_TLV_CAPA_UMAC_SCAN) {
643 ret = iwl_mvm_config_scan(mvm);
644 if (ret)
645 goto error;
646 }
647
Eliad Peller7498cf42014-01-16 17:10:44 +0200648 /* allow FW/transport low power modes if not during restart */
649 if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
650 iwl_mvm_unref(mvm, IWL_MVM_REF_UCODE_DOWN);
651
Ilan Peer53a9d612013-04-28 11:55:08 +0300652 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
Johannes Berg8ca151b2013-01-24 14:25:36 +0100653 return 0;
654 error:
655 iwl_trans_stop_device(mvm->trans);
656 return ret;
657}
658
659int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
660{
661 int ret, i;
662
663 lockdep_assert_held(&mvm->mutex);
664
665 ret = iwl_trans_start_hw(mvm->trans);
666 if (ret)
667 return ret;
668
669 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
670 if (ret) {
671 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
672 goto error;
673 }
674
Moshe Harela0544272014-12-08 21:13:14 +0200675 ret = iwl_send_tx_ant_cfg(mvm, iwl_mvm_get_valid_tx_ant(mvm));
Johannes Berg8ca151b2013-01-24 14:25:36 +0100676 if (ret)
677 goto error;
678
679 /* Send phy db control command and then phy db calibration*/
680 ret = iwl_send_phy_db_data(mvm->phy_db);
681 if (ret)
682 goto error;
683
684 ret = iwl_send_phy_cfg_cmd(mvm);
685 if (ret)
686 goto error;
687
688 /* init the fw <-> mac80211 STA mapping */
689 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
690 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
691
692 /* Add auxiliary station for scanning */
693 ret = iwl_mvm_add_aux_sta(mvm);
694 if (ret)
695 goto error;
696
697 return 0;
698 error:
699 iwl_trans_stop_device(mvm->trans);
700 return ret;
701}
702
703int iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
704 struct iwl_rx_cmd_buffer *rxb,
705 struct iwl_device_cmd *cmd)
706{
707 struct iwl_rx_packet *pkt = rxb_addr(rxb);
708 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
709 u32 flags = le32_to_cpu(card_state_notif->flags);
710
711 IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
712 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
713 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
714 (flags & CT_KILL_CARD_DISABLED) ?
715 "Reached" : "Not reached");
716
Johannes Berg8ca151b2013-01-24 14:25:36 +0100717 return 0;
718}
719
720int iwl_mvm_rx_radio_ver(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
721 struct iwl_device_cmd *cmd)
722{
723 struct iwl_rx_packet *pkt = rxb_addr(rxb);
724 struct iwl_radio_version_notif *radio_version = (void *)pkt->data;
725
726 /* TODO: what to do with that? */
727 IWL_DEBUG_INFO(mvm,
728 "Radio version: flavor: 0x%08x, step 0x%08x, dash 0x%08x\n",
729 le32_to_cpu(radio_version->radio_flavor),
730 le32_to_cpu(radio_version->radio_step),
731 le32_to_cpu(radio_version->radio_dash));
732 return 0;
733}
Chaya Rachel Ivgy30269c12014-11-15 21:08:29 +0200734
735int iwl_mvm_rx_mfuart_notif(struct iwl_mvm *mvm,
736 struct iwl_rx_cmd_buffer *rxb,
737 struct iwl_device_cmd *cmd)
738{
739 struct iwl_rx_packet *pkt = rxb_addr(rxb);
740 struct iwl_mfuart_load_notif *mfuart_notif = (void *)pkt->data;
741
742 IWL_DEBUG_INFO(mvm,
743 "MFUART: installed ver: 0x%08x, external ver: 0x%08x, status: 0x%08x, duration: 0x%08x\n",
744 le32_to_cpu(mfuart_notif->installed_ver),
745 le32_to_cpu(mfuart_notif->external_ver),
746 le32_to_cpu(mfuart_notif->status),
747 le32_to_cpu(mfuart_notif->duration));
748 return 0;
749}