]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/net/wireless/iwlwifi/mvm/fw.c
iwlwifi: pcie: restart the driver when a command times out
[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 *
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
410dc5aa 25 * in the file called COPYING.
8ca151b5
JB
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63#include <net/mac80211.h>
64
65#include "iwl-trans.h"
66#include "iwl-op-mode.h"
67#include "iwl-fw.h"
68#include "iwl-debug.h"
69#include "iwl-csr.h" /* for iwl_mvm_rx_card_state_notif */
70#include "iwl-io.h" /* for iwl_mvm_rx_card_state_notif */
71#include "iwl-eeprom-parse.h"
72
73#include "mvm.h"
74#include "iwl-phy-db.h"
75
76#define MVM_UCODE_ALIVE_TIMEOUT HZ
77#define MVM_UCODE_CALIB_TIMEOUT (2*HZ)
78
79#define UCODE_VALID_OK cpu_to_le32(0x1)
80
8ca151b5
JB
81struct iwl_mvm_alive_data {
82 bool valid;
83 u32 scd_base_addr;
84};
85
86static inline const struct fw_img *
87iwl_get_ucode_image(struct iwl_mvm *mvm, enum iwl_ucode_type ucode_type)
88{
89 if (ucode_type >= IWL_UCODE_TYPE_MAX)
90 return NULL;
91
92 return &mvm->fw->img[ucode_type];
93}
94
95static int iwl_send_tx_ant_cfg(struct iwl_mvm *mvm, u8 valid_tx_ant)
96{
97 struct iwl_tx_ant_cfg_cmd tx_ant_cmd = {
98 .valid = cpu_to_le32(valid_tx_ant),
99 };
100
33223542 101 IWL_DEBUG_FW(mvm, "select valid tx ant: %u\n", valid_tx_ant);
8ca151b5
JB
102 return iwl_mvm_send_cmd_pdu(mvm, TX_ANT_CONFIGURATION_CMD, CMD_SYNC,
103 sizeof(tx_ant_cmd), &tx_ant_cmd);
104}
105
106static bool iwl_alive_fn(struct iwl_notif_wait_data *notif_wait,
107 struct iwl_rx_packet *pkt, void *data)
108{
109 struct iwl_mvm *mvm =
110 container_of(notif_wait, struct iwl_mvm, notif_wait);
111 struct iwl_mvm_alive_data *alive_data = data;
112 struct mvm_alive_resp *palive;
113
114 palive = (void *)pkt->data;
115
116 mvm->error_event_table = le32_to_cpu(palive->error_event_table_ptr);
117 mvm->log_event_table = le32_to_cpu(palive->log_event_table_ptr);
118 alive_data->scd_base_addr = le32_to_cpu(palive->scd_base_ptr);
119
120 alive_data->valid = le16_to_cpu(palive->status) == IWL_ALIVE_STATUS_OK;
1b53f218
EG
121 IWL_DEBUG_FW(mvm,
122 "Alive ucode status 0x%04x revision 0x%01X 0x%01X flags 0x%01X\n",
8ca151b5 123 le16_to_cpu(palive->status), palive->ver_type,
1b53f218 124 palive->ver_subtype, palive->flags);
8ca151b5
JB
125
126 return true;
127}
128
129static bool iwl_wait_phy_db_entry(struct iwl_notif_wait_data *notif_wait,
130 struct iwl_rx_packet *pkt, void *data)
131{
132 struct iwl_phy_db *phy_db = data;
133
134 if (pkt->hdr.cmd != CALIB_RES_NOTIF_PHY_DB) {
135 WARN_ON(pkt->hdr.cmd != INIT_COMPLETE_NOTIF);
136 return true;
137 }
138
139 WARN_ON(iwl_phy_db_set_section(phy_db, pkt, GFP_ATOMIC));
140
141 return false;
142}
143
144static int iwl_mvm_load_ucode_wait_alive(struct iwl_mvm *mvm,
145 enum iwl_ucode_type ucode_type)
146{
147 struct iwl_notification_wait alive_wait;
148 struct iwl_mvm_alive_data alive_data;
149 const struct fw_img *fw;
150 int ret, i;
151 enum iwl_ucode_type old_type = mvm->cur_ucode;
152 static const u8 alive_cmd[] = { MVM_ALIVE };
153
154 mvm->cur_ucode = ucode_type;
155 fw = iwl_get_ucode_image(mvm, ucode_type);
156
157 mvm->ucode_loaded = false;
158
159 if (!fw)
160 return -EINVAL;
161
162 iwl_init_notification_wait(&mvm->notif_wait, &alive_wait,
163 alive_cmd, ARRAY_SIZE(alive_cmd),
164 iwl_alive_fn, &alive_data);
165
166 ret = iwl_trans_start_fw(mvm->trans, fw, ucode_type == IWL_UCODE_INIT);
167 if (ret) {
168 mvm->cur_ucode = old_type;
169 iwl_remove_notification(&mvm->notif_wait, &alive_wait);
170 return ret;
171 }
172
173 /*
174 * Some things may run in the background now, but we
175 * just wait for the ALIVE notification here.
176 */
177 ret = iwl_wait_notification(&mvm->notif_wait, &alive_wait,
178 MVM_UCODE_ALIVE_TIMEOUT);
179 if (ret) {
180 mvm->cur_ucode = old_type;
181 return ret;
182 }
183
184 if (!alive_data.valid) {
185 IWL_ERR(mvm, "Loaded ucode is not valid!\n");
186 mvm->cur_ucode = old_type;
187 return -EIO;
188 }
189
190 iwl_trans_fw_alive(mvm->trans, alive_data.scd_base_addr);
191
192 /*
193 * Note: all the queues are enabled as part of the interface
194 * initialization, but in firmware restart scenarios they
195 * could be stopped, so wake them up. In firmware restart,
196 * mac80211 will have the queues stopped as well until the
197 * reconfiguration completes. During normal startup, they
198 * will be empty.
199 */
200
201 for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
202 if (i < IWL_MVM_FIRST_AGG_QUEUE && i != IWL_MVM_CMD_QUEUE)
203 mvm->queue_to_mac80211[i] = i;
204 else
205 mvm->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
206 atomic_set(&mvm->queue_stop_count[i], 0);
207 }
208
209 mvm->transport_queue_stop = 0;
210
211 mvm->ucode_loaded = true;
212
213 return 0;
214}
8ca151b5
JB
215
216static int iwl_send_phy_cfg_cmd(struct iwl_mvm *mvm)
217{
218 struct iwl_phy_cfg_cmd phy_cfg_cmd;
219 enum iwl_ucode_type ucode_type = mvm->cur_ucode;
220
221 /* Set parameters */
6221d47c 222 phy_cfg_cmd.phy_cfg = cpu_to_le32(mvm->fw->phy_config);
8ca151b5
JB
223 phy_cfg_cmd.calib_control.event_trigger =
224 mvm->fw->default_calib[ucode_type].event_trigger;
225 phy_cfg_cmd.calib_control.flow_trigger =
226 mvm->fw->default_calib[ucode_type].flow_trigger;
227
228 IWL_DEBUG_INFO(mvm, "Sending Phy CFG command: 0x%x\n",
229 phy_cfg_cmd.phy_cfg);
230
231 return iwl_mvm_send_cmd_pdu(mvm, PHY_CONFIGURATION_CMD, CMD_SYNC,
232 sizeof(phy_cfg_cmd), &phy_cfg_cmd);
233}
234
8ca151b5
JB
235int iwl_run_init_mvm_ucode(struct iwl_mvm *mvm, bool read_nvm)
236{
237 struct iwl_notification_wait calib_wait;
238 static const u8 init_complete[] = {
239 INIT_COMPLETE_NOTIF,
240 CALIB_RES_NOTIF_PHY_DB
241 };
242 int ret;
243
244 lockdep_assert_held(&mvm->mutex);
245
ff116373 246 if (mvm->init_ucode_complete)
8ca151b5
JB
247 return 0;
248
249 iwl_init_notification_wait(&mvm->notif_wait,
250 &calib_wait,
251 init_complete,
252 ARRAY_SIZE(init_complete),
253 iwl_wait_phy_db_entry,
254 mvm->phy_db);
255
256 /* Will also start the device */
257 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_INIT);
258 if (ret) {
259 IWL_ERR(mvm, "Failed to start INIT ucode: %d\n", ret);
260 goto error;
261 }
262
931d4160
EG
263 ret = iwl_send_bt_prio_tbl(mvm);
264 if (ret)
265 goto error;
266
8ca151b5
JB
267 if (read_nvm) {
268 /* Read nvm */
269 ret = iwl_nvm_init(mvm);
270 if (ret) {
271 IWL_ERR(mvm, "Failed to read NVM: %d\n", ret);
272 goto error;
273 }
274 }
275
276 ret = iwl_nvm_check_version(mvm->nvm_data, mvm->trans);
277 WARN_ON(ret);
278
4f59334b
EH
279 /*
280 * abort after reading the nvm in case RF Kill is on, we will complete
281 * the init seq later when RF kill will switch to off
282 */
9ee718aa 283 if (iwl_mvm_is_radio_killed(mvm)) {
4f59334b
EH
284 IWL_DEBUG_RF_KILL(mvm,
285 "jump over all phy activities due to RF kill\n");
286 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
287 return 1;
288 }
289
e07cbb53 290 /* Send TX valid antennas before triggering calibrations */
33223542 291 ret = iwl_send_tx_ant_cfg(mvm, iwl_fw_valid_tx_ant(mvm->fw));
e07cbb53
DS
292 if (ret)
293 goto error;
294
8ca151b5
JB
295 /*
296 * Send phy configurations command to init uCode
297 * to start the 16.0 uCode init image internal calibrations.
298 */
299 ret = iwl_send_phy_cfg_cmd(mvm);
300 if (ret) {
301 IWL_ERR(mvm, "Failed to run INIT calibrations: %d\n",
302 ret);
303 goto error;
304 }
305
306 /*
307 * Some things may run in the background now, but we
308 * just wait for the calibration complete notification.
309 */
310 ret = iwl_wait_notification(&mvm->notif_wait, &calib_wait,
311 MVM_UCODE_CALIB_TIMEOUT);
312 if (!ret)
ff116373 313 mvm->init_ucode_complete = true;
8ca151b5
JB
314 goto out;
315
316error:
317 iwl_remove_notification(&mvm->notif_wait, &calib_wait);
318out:
319 if (!iwlmvm_mod_params.init_dbg) {
320 iwl_trans_stop_device(mvm->trans);
321 } else if (!mvm->nvm_data) {
322 /* we want to debug INIT and we have no NVM - fake */
323 mvm->nvm_data = kzalloc(sizeof(struct iwl_nvm_data) +
324 sizeof(struct ieee80211_channel) +
325 sizeof(struct ieee80211_rate),
326 GFP_KERNEL);
327 if (!mvm->nvm_data)
328 return -ENOMEM;
329 mvm->nvm_data->valid_rx_ant = 1;
330 mvm->nvm_data->valid_tx_ant = 1;
331 mvm->nvm_data->bands[0].channels = mvm->nvm_data->channels;
332 mvm->nvm_data->bands[0].n_channels = 1;
333 mvm->nvm_data->bands[0].n_bitrates = 1;
334 mvm->nvm_data->bands[0].bitrates =
335 (void *)mvm->nvm_data->channels + 1;
336 mvm->nvm_data->bands[0].bitrates->hw_value = 10;
337 }
338
339 return ret;
340}
341
342#define UCODE_CALIB_TIMEOUT (2*HZ)
343
344int iwl_mvm_up(struct iwl_mvm *mvm)
345{
346 int ret, i;
53a9d61e
IP
347 struct ieee80211_channel *chan;
348 struct cfg80211_chan_def chandef;
8ca151b5
JB
349
350 lockdep_assert_held(&mvm->mutex);
351
352 ret = iwl_trans_start_hw(mvm->trans);
353 if (ret)
354 return ret;
355
ff116373
EL
356 /*
357 * If we haven't completed the run of the init ucode during
358 * module loading, load init ucode now
359 * (for example, if we were in RFKILL)
360 */
361 if (!mvm->init_ucode_complete) {
8ca151b5
JB
362 ret = iwl_run_init_mvm_ucode(mvm, false);
363 if (ret && !iwlmvm_mod_params.init_dbg) {
364 IWL_ERR(mvm, "Failed to run INIT ucode: %d\n", ret);
4f59334b
EH
365 /* this can't happen */
366 if (WARN_ON(ret > 0))
367 ret = -ERFKILL;
8ca151b5
JB
368 goto error;
369 }
4f59334b
EH
370 /* should stop & start HW since that INIT image just loaded */
371 iwl_trans_stop_hw(mvm->trans, false);
372 ret = iwl_trans_start_hw(mvm->trans);
373 if (ret)
374 return ret;
8ca151b5
JB
375 }
376
377 if (iwlmvm_mod_params.init_dbg)
378 return 0;
379
380 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_REGULAR);
381 if (ret) {
382 IWL_ERR(mvm, "Failed to start RT ucode: %d\n", ret);
383 goto error;
384 }
385
33223542 386 ret = iwl_send_tx_ant_cfg(mvm, iwl_fw_valid_tx_ant(mvm->fw));
8ca151b5
JB
387 if (ret)
388 goto error;
389
931d4160
EG
390 ret = iwl_send_bt_prio_tbl(mvm);
391 if (ret)
392 goto error;
393
394 ret = iwl_send_bt_init_conf(mvm);
395 if (ret)
396 goto error;
397
8ca151b5
JB
398 /* Send phy db control command and then phy db calibration*/
399 ret = iwl_send_phy_db_data(mvm->phy_db);
400 if (ret)
401 goto error;
402
403 ret = iwl_send_phy_cfg_cmd(mvm);
404 if (ret)
405 goto error;
406
407 /* init the fw <-> mac80211 STA mapping */
408 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
409 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
410
411 /* Add auxiliary station for scanning */
412 ret = iwl_mvm_add_aux_sta(mvm);
413 if (ret)
414 goto error;
415
53a9d61e
IP
416 /* Add all the PHY contexts */
417 chan = &mvm->hw->wiphy->bands[IEEE80211_BAND_2GHZ]->channels[0];
418 cfg80211_chandef_create(&chandef, chan, NL80211_CHAN_NO_HT);
419 for (i = 0; i < NUM_PHY_CTX; i++) {
420 /*
421 * The channel used here isn't relevant as it's
422 * going to be overwritten in the other flows.
423 * For now use the first channel we have.
424 */
425 ret = iwl_mvm_phy_ctxt_add(mvm, &mvm->phy_ctxts[i],
426 &chandef, 1, 1);
427 if (ret)
428 goto error;
429 }
8ca151b5 430
53a9d61e 431 IWL_DEBUG_INFO(mvm, "RT uCode started.\n");
8ca151b5
JB
432 return 0;
433 error:
434 iwl_trans_stop_device(mvm->trans);
435 return ret;
436}
437
438int iwl_mvm_load_d3_fw(struct iwl_mvm *mvm)
439{
440 int ret, i;
441
442 lockdep_assert_held(&mvm->mutex);
443
444 ret = iwl_trans_start_hw(mvm->trans);
445 if (ret)
446 return ret;
447
448 ret = iwl_mvm_load_ucode_wait_alive(mvm, IWL_UCODE_WOWLAN);
449 if (ret) {
450 IWL_ERR(mvm, "Failed to start WoWLAN firmware: %d\n", ret);
451 goto error;
452 }
453
33223542 454 ret = iwl_send_tx_ant_cfg(mvm, iwl_fw_valid_tx_ant(mvm->fw));
8ca151b5
JB
455 if (ret)
456 goto error;
457
458 /* Send phy db control command and then phy db calibration*/
459 ret = iwl_send_phy_db_data(mvm->phy_db);
460 if (ret)
461 goto error;
462
463 ret = iwl_send_phy_cfg_cmd(mvm);
464 if (ret)
465 goto error;
466
467 /* init the fw <-> mac80211 STA mapping */
468 for (i = 0; i < IWL_MVM_STATION_COUNT; i++)
469 RCU_INIT_POINTER(mvm->fw_id_to_mac_id[i], NULL);
470
471 /* Add auxiliary station for scanning */
472 ret = iwl_mvm_add_aux_sta(mvm);
473 if (ret)
474 goto error;
475
476 return 0;
477 error:
478 iwl_trans_stop_device(mvm->trans);
479 return ret;
480}
481
482int iwl_mvm_rx_card_state_notif(struct iwl_mvm *mvm,
483 struct iwl_rx_cmd_buffer *rxb,
484 struct iwl_device_cmd *cmd)
485{
486 struct iwl_rx_packet *pkt = rxb_addr(rxb);
487 struct iwl_card_state_notif *card_state_notif = (void *)pkt->data;
488 u32 flags = le32_to_cpu(card_state_notif->flags);
489
490 IWL_DEBUG_RF_KILL(mvm, "Card state received: HW:%s SW:%s CT:%s\n",
491 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
492 (flags & SW_CARD_DISABLED) ? "Kill" : "On",
493 (flags & CT_KILL_CARD_DISABLED) ?
494 "Reached" : "Not reached");
495
8ca151b5
JB
496 return 0;
497}
498
499int iwl_mvm_rx_radio_ver(struct iwl_mvm *mvm, struct iwl_rx_cmd_buffer *rxb,
500 struct iwl_device_cmd *cmd)
501{
502 struct iwl_rx_packet *pkt = rxb_addr(rxb);
503 struct iwl_radio_version_notif *radio_version = (void *)pkt->data;
504
505 /* TODO: what to do with that? */
506 IWL_DEBUG_INFO(mvm,
507 "Radio version: flavor: 0x%08x, step 0x%08x, dash 0x%08x\n",
508 le32_to_cpu(radio_version->radio_flavor),
509 le32_to_cpu(radio_version->radio_step),
510 le32_to_cpu(radio_version->radio_dash));
511 return 0;
512}